@@ -9,11 +9,8 @@ export default class Parser {
9
9
}
10
10
11
11
plugin ( css , result ) {
12
- return Promise . all ( this . fetchAllImports ( css ) ) . then ( _ => {
13
- css . each ( node => {
14
- if ( node . type == "rule" && node . selector == ":export" ) this . handleExport ( node )
15
- } )
16
- } )
12
+ return Promise . all ( this . fetchAllImports ( css ) )
13
+ . then ( _ => this . extractExports ( css ) )
17
14
}
18
15
19
16
fetchAllImports ( css ) {
@@ -26,9 +23,18 @@ export default class Parser {
26
23
return imports
27
24
}
28
25
26
+ extractExports ( css ) {
27
+ css . each ( node => {
28
+ if ( node . type == "rule" && node . selector == ":export" ) this . handleExport ( node )
29
+ } )
30
+ }
31
+
29
32
handleExport ( exportNode ) {
30
33
exportNode . each ( decl => {
31
34
if ( decl . type == 'decl' ) {
35
+ Object . keys ( this . translations ) . forEach ( translation => {
36
+ decl . value = decl . value . replace ( translation , this . translations [ translation ] )
37
+ } )
32
38
this . exportTokens [ decl . prop ] = decl . value
33
39
}
34
40
} )
@@ -37,10 +43,13 @@ export default class Parser {
37
43
38
44
fetchImport ( importNode , relativeTo ) {
39
45
let file = importNode . selector . match ( importRegexp ) [ 1 ]
40
- importNode . removeSelf ( )
41
- return this . pathFetcher ( file , relativeTo ) . then ( exports => {
42
- console . log ( "got export" )
43
- console . log ( exports )
44
- } , err => console . log ( err ) )
46
+ return this . pathFetcher ( file , relativeTo ) . then ( exports => {
47
+ importNode . each ( decl => {
48
+ if ( decl . type == 'decl' ) {
49
+ this . translations [ decl . value ] = exports [ decl . prop ]
50
+ }
51
+ } )
52
+ importNode . removeSelf ( )
53
+ } , err => console . log ( err ) )
45
54
}
46
55
}
0 commit comments