Skip to content

Commit 45801b4

Browse files
committed
replacing import with value as well
1 parent acb75ba commit 45801b4

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

lib/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ var createImportedName = options && options.createImportedName || function (impo
2626
};
2727

2828
exports['default'] = function (css) {
29-
/* Find any local let rules and store them*/
29+
/* Find any @value statements that define locals */
3030
var translations = {};
31-
css.walkAtRules(/^value$/, function (atRule) {
31+
css.walkAtRules('value', function (atRule) {
32+
if (matchImports.exec(atRule.params)) return;
3233
var matches = undefined;
3334
while (matches = matchLet.exec(atRule.params)) {
3435
var _matches = matches;
@@ -54,9 +55,9 @@ exports['default'] = function (css) {
5455
});
5556
});
5657

57-
/* Find imports and insert ICSS tmp vars */
58+
/* Treat @value statements that import them as defining ICSS tmp vars */
5859
var importAliases = [];
59-
css.walkAtRules(/^import(-value)?$/, function (atRule) {
60+
css.walkAtRules('value', function (atRule) {
6061
var matches = matchImports.exec(atRule.params);
6162
if (matches) {
6263
var _matches3 = _slicedToArray(matches, 3);

src/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ let importIndex = 0
99
let createImportedName = options && options.createImportedName || ((importName/*, path*/) => `i__const_${importName.replace(/\W/g, '_')}_${importIndex++}`)
1010

1111
export default css => {
12-
/* Find any local let rules and store them*/
12+
/* Find any @value statements that define locals */
1313
let translations = {}
14-
css.walkAtRules(/^value$/, atRule => {
14+
css.walkAtRules('value', atRule => {
15+
if (matchImports.exec(atRule.params)) return
1516
let matches
1617
while (matches = matchLet.exec(atRule.params)) {
1718
let [/*match*/, key, value] = matches
@@ -29,9 +30,9 @@ export default css => {
2930
_autoprefixerDisabled: true
3031
}))
3132

32-
/* Find imports and insert ICSS tmp vars */
33+
/* Treat @value statements that import them as defining ICSS tmp vars */
3334
let importAliases = []
34-
css.walkAtRules(/^import(-value)?$/, atRule => {
35+
css.walkAtRules('value', atRule => {
3536
let matches = matchImports.exec(atRule.params)
3637
if (matches) {
3738
let [/*match*/, aliases, path] = matches

test/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ describe('constants', () => {
2828
})
2929

3030
it('should import a simple constant', () => {
31-
test('@import red from "./colors.css";', ':import("./colors.css") {\n i__const_red_0: red\n}')
31+
test('@value red from "./colors.css";', ':import("./colors.css") {\n i__const_red_0: red\n}')
3232
})
3333

3434
it('should import a simple constant and replace usages', () => {
35-
test('@import red from "./colors.css"; .foo { color: red; }', ':import("./colors.css") {\n i__const_red_1: red;\n}\n.foo { color: i__const_red_1; }')
35+
test('@value red from "./colors.css"; .foo { color: red; }', ':import("./colors.css") {\n i__const_red_1: red;\n}\n.foo { color: i__const_red_1; }')
3636
})
3737

3838
it('should import and alias a constant and replace usages', () => {
39-
test('@import blue as red from "./colors.css"; .foo { color: red; }', ':import("./colors.css") {\n i__const_red_2: blue;\n}\n.foo { color: i__const_red_2; }')
39+
test('@value blue as red from "./colors.css"; .foo { color: red; }', ':import("./colors.css") {\n i__const_red_2: blue;\n}\n.foo { color: i__const_red_2; }')
4040
})
4141

4242
it('should import multiple from a single file', () => {
4343
test(
44-
`@import blue, red from "./colors.css";
44+
`@value blue, red from "./colors.css";
4545
.foo { color: red; }
4646
.bar { color: blue }`,
4747
`:import("./colors.css") {
@@ -54,14 +54,14 @@ describe('constants', () => {
5454

5555
it('should import from a definition', () => {
5656
test(
57-
'@value colors: "./colors.css"; @import red from colors;',
57+
'@value colors: "./colors.css"; @value red from colors;',
5858
':export {\n colors: "./colors.css"\n}\n' +
5959
':import("./colors.css") {\n i__const_red_5: red\n}'
6060
)
6161
})
6262

6363
it('should import a simple constant with import-value', () => {
64-
test('@import-value red from "./colors.css";', ':import("./colors.css") {\n i__const_red_6: red\n}')
64+
test('@value red from "./colors.css";', ':import("./colors.css") {\n i__const_red_6: red\n}')
6565
})
6666
})
6767

0 commit comments

Comments
 (0)