Skip to content

Commit 464b5d8

Browse files
committed
ICSS test case passing!
1 parent abe7bf9 commit 464b5d8

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

src/parser.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,18 @@ export default class Parser {
2626
}
2727

2828
linkImportedSymbols( css ) {
29-
css.eachDecl( decl => {
30-
Object.keys(this.translations).forEach( translation => {
31-
decl.value = decl.value.replace(translation, this.translations[translation])
32-
} )
29+
css.eachInside( node => {
30+
if ( node.type === "decl" ) {
31+
this.replaceOccurrences( node, "value" )
32+
} else if ( node.type === "atrule" && node.name === "custom-media" ) {
33+
this.replaceOccurrences( node, "params" )
34+
}
35+
})
36+
}
37+
38+
replaceOccurrences( node, prop ) {
39+
Object.keys(this.translations).forEach(translation => {
40+
node[prop] = node[prop].replace(translation, this.translations[translation])
3341
})
3442
}
3543

@@ -57,7 +65,7 @@ export default class Parser {
5765
return this.pathFetcher( file, relativeTo, depTrace ).then( exports => {
5866
importNode.each( decl => {
5967
if ( decl.type == 'decl' ) {
60-
this.translations[decl.prop] = exports[decl.value]
68+
this.translations[decl.prop] = exports[decl.value].replace(/^['"]|['"]$/g,'')
6169
}
6270
} )
6371
importNode.removeSelf()

test/cssi/media-queries/breakpoints.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
:exports {
1+
:export {
22
--small: "(max-width: 30em)";
33
--medium: "(max-width: 60em)";
44
--large: "(max-width: 90em)";

test/cssi/media-queries/expected.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
@custom-media --small (max-width: 30em);
22
@custom-media --medium (max-width: 60em);
33
@custom-media --large (max-width: 90em);
4+
@custom-media --small (max-width: 30em);
5+
@custom-media --medium (max-width: 60em);
6+
@custom-media --large (max-width: 90em);
47

58
.exported-red {
69
color: red;

test/cssi/media-queries/expected.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"--small": "--x__source__small",
3-
"--medium": "--x__source__medium",
4-
"--large": "--x__source__large"
2+
"--small": "(max-width: 30em)",
3+
"--medium": "(max-width: 60em)",
4+
"--large": "(max-width: 90em)",
5+
"red": "exported-red"
56
}

0 commit comments

Comments
 (0)