Skip to content

Commit 9615d83

Browse files
committed
BOOM got export token replacement running!
1 parent afa88fa commit 9615d83

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ export default {
2121
load( sourceString, sourcePath, pathFetcher ) {
2222
let parser = new Parser( pathFetcher )
2323

24-
console.log("PROCESSING " + sourcePath)
2524
return postcss( this.plugins.concat( [parser.plugin] ) )
2625
.process( sourceString, { from: "/" + sourcePath } )
2726
.then( result => {
28-
console.log("GOT RESULT " + sourcePath)
2927
return { injectableSource: result.css, exportTokens: parser.exportTokens }
3028
} )
3129
}

src/parser.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ export default class Parser {
99
}
1010

1111
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 ) )
1714
}
1815

1916
fetchAllImports( css ) {
@@ -26,9 +23,18 @@ export default class Parser {
2623
return imports
2724
}
2825

26+
extractExports( css ) {
27+
css.each( node => {
28+
if ( node.type == "rule" && node.selector == ":export" ) this.handleExport( node )
29+
} )
30+
}
31+
2932
handleExport( exportNode ) {
3033
exportNode.each( decl => {
3134
if ( decl.type == 'decl' ) {
35+
Object.keys(this.translations).forEach( translation => {
36+
decl.value = decl.value.replace(translation, this.translations[translation])
37+
} )
3238
this.exportTokens[decl.prop] = decl.value
3339
}
3440
} )
@@ -37,10 +43,13 @@ export default class Parser {
3743

3844
fetchImport( importNode, relativeTo ) {
3945
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 ) )
4554
}
4655
}

0 commit comments

Comments
 (0)