@@ -9,7 +9,7 @@ export default class Parser {
9
9
}
10
10
11
11
plugin ( css , result ) {
12
- return Promise . all ( this . fetchAllImports ( css ) )
12
+ return this . fetchAllImports ( css )
13
13
. then ( _ => this . extractExports ( css ) )
14
14
}
15
15
@@ -20,7 +20,13 @@ export default class Parser {
20
20
imports . push ( this . fetchImport ( node , css . source . input . from ) )
21
21
}
22
22
} )
23
- return imports
23
+ return Promise . all ( imports )
24
+ . then ( fetchedState => {
25
+ return Promise . all ( fetchedState . map (
26
+ ( { loaderData, propResolver} ) =>
27
+ this . pathFetcher . load ( loaderData ) . then ( propResolver )
28
+ ) )
29
+ } )
24
30
}
25
31
26
32
extractExports ( css ) {
@@ -32,8 +38,8 @@ export default class Parser {
32
38
handleExport ( exportNode ) {
33
39
exportNode . each ( decl => {
34
40
if ( decl . type == 'decl' ) {
35
- Object . keys ( this . translations ) . forEach ( translation => {
36
- decl . value = decl . value . replace ( translation , this . translations [ translation ] )
41
+ Object . keys ( this . translations ) . forEach ( translation => {
42
+ decl . value = decl . value . replace ( translation , this . translations [ translation ] )
37
43
} )
38
44
this . exportTokens [ decl . prop ] = decl . value
39
45
}
@@ -43,13 +49,19 @@ export default class Parser {
43
49
44
50
fetchImport ( importNode , relativeTo ) {
45
51
let file = importNode . selector . match ( importRegexp ) [ 1 ]
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 ]
52
+ console . log ( "FETCHING " + file )
53
+ return this . pathFetcher . fetch ( file , relativeTo )
54
+ . then ( loaderData => ( {
55
+ loaderData,
56
+ propResolver : exports => {
57
+ console . log ( "RESOLVING " + file )
58
+ importNode . each ( decl => {
59
+ if ( decl . type == 'decl' ) {
60
+ this . translations [ decl . value ] = exports [ decl . prop ]
61
+ }
62
+ } )
63
+ importNode . removeSelf ( )
50
64
}
51
- } )
52
- importNode . removeSelf ( )
53
- } , err => console . log ( err ) )
65
+ } ) )
54
66
}
55
67
}
0 commit comments