Skip to content

Commit 84c37f0

Browse files
committed
got replacement working in the CSSI tests, breaks the others
1 parent 1b08b3e commit 84c37f0

File tree

9 files changed

+43
-9
lines changed

9 files changed

+43
-9
lines changed

src/parser.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default class Parser {
1111

1212
plugin( css, result ) {
1313
return Promise.all( this.fetchAllImports( css ) )
14+
.then( _ => this.linkImportedSymbols( css ) )
1415
.then( _ => this.extractExports( css ) )
1516
}
1617

@@ -24,6 +25,14 @@ export default class Parser {
2425
return imports
2526
}
2627

28+
linkImportedSymbols( css ) {
29+
css.eachDecl( decl => {
30+
Object.keys(this.translations).forEach( translation => {
31+
decl.value = decl.value.replace(translation, this.translations[translation])
32+
} )
33+
})
34+
}
35+
2736
extractExports( css ) {
2837
css.each( node => {
2938
if ( node.type == "rule" && node.selector == ":export" ) this.handleExport( node )
@@ -48,7 +57,7 @@ export default class Parser {
4857
return this.pathFetcher( file, relativeTo, depTrace ).then( exports => {
4958
importNode.each( decl => {
5059
if ( decl.type == 'decl' ) {
51-
this.translations[decl.value] = exports[decl.prop]
60+
this.translations[decl.prop] = exports[decl.value]
5261
}
5362
} )
5463
importNode.removeSelf()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
:export {
2-
blackShadow: _single_import_export_source__localName;
2+
blackShadow: x__single_import_export_colors__blackShadow;
33
}
44

5-
._single_import_export_colors__blackShadow {
5+
.x__single_import_export_colors__blackShadow {
66
box-shadow: 0 0 10px -2px black;
77
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
._single_import_export_colors__blackShadow {
1+
.x__single_import_export_colors__blackShadow {
22
box-shadow: 0 0 10px -2px black;
33
}
4-
._single_import_export_source__localName {
4+
.x__single_import_export_source__localName {
55
color: red;
66
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"localName": "_single_import_export_source__localName __tmp_import_djhgdsag"
2+
"localName": "x__single_import_export_source__localName x__single_import_export_colors__blackShadow"
33
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
:import("./colors.css") {
2-
__tmp_import_djhgdsag: blackShadow;
2+
i__tmp_import_djhgdsag: blackShadow;
33
}
44

55
:export {
6-
localName: _single_import_export_source__localName __tmp_import_djhgdsag;
6+
localName: x__single_import_export_source__localName i__tmp_import_djhgdsag;
77
}
88

9-
._single_import_export_source__localName {
9+
.x__single_import_export_source__localName {
1010
color: red;
1111
}

test/cssi/pseudo-variables/colors.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:export {
2+
black: #222;
3+
white: #ddd;
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
.x__lol {
3+
color: #222;
4+
background: #ddd;
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"lol": "x__lol"
3+
}

test/cssi/pseudo-variables/source.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
:import("./colors.css") {
2+
i__black: black;
3+
i__white: white;
4+
}
5+
6+
:export {
7+
lol: x__lol;
8+
}
9+
10+
.x__lol {
11+
color: i__black;
12+
background: i__white;
13+
}

0 commit comments

Comments
 (0)