Skip to content

Commit e8345f9

Browse files
committed
[fixes css-modules#2] more complex transitive values allowed
1 parent 80abf64 commit e8345f9

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

lib/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ exports['default'] = function (css) {
3939
var /*match*/key = _matches2[1];
4040
var value = _matches2[2];
4141

42-
// Values can refer to each other
43-
if (definitions[value]) value = definitions[value];
44-
definitions[key] = value;
42+
// Add to the definitions, knowing that values can refer to each other
43+
definitions[key] = (0, _icssReplaceSymbols.replaceAll)(definitions, value);
4544
atRule.remove();
4645
}
4746
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"standard": "^5.3.1"
3535
},
3636
"dependencies": {
37-
"icss-replace-symbols": "^1.0.1",
37+
"icss-replace-symbols": "^1.0.2",
3838
"postcss": "^5.0.10"
3939
}
4040
}

src/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import postcss from 'postcss'
2-
import replaceSymbols from 'icss-replace-symbols'
2+
import replaceSymbols, { replaceAll } from 'icss-replace-symbols'
33

44
const matchImports = /^(.+?)\s+from\s+("[^"]*"|'[^']*'|[\w-]+)$/
55
const matchLet = /(?:,\s+|^)([\w-]+):?\s+("[^"]*"|'[^']*'|[^,]+)\s?/g
@@ -16,9 +16,8 @@ export default css => {
1616
let matches
1717
while (matches = matchLet.exec(atRule.params)) {
1818
let [/*match*/, key, value] = matches
19-
// Values can refer to each other
20-
if (definitions[value]) value = definitions[value]
21-
definitions[key] = value
19+
// Add to the definitions, knowing that values can refer to each other
20+
definitions[key] = replaceAll(definitions, value)
2221
atRule.remove()
2322
}
2423
}

test/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,12 @@ describe('constants', () => {
7878
':export {\n aaa: red;\n bbb: red;\n}\n.a { color: red; }'
7979
)
8080
})
81+
82+
it('should allow transitive values within calc', () => {
83+
test(
84+
'@value base: 10px;\n@value large: calc(base * 2);\n.a { margin: large; }',
85+
':export {\n base: 10px;\n large: calc(10px * 2);\n}\n.a { margin: calc(10px * 2); }'
86+
)
87+
})
8188
})
8289

0 commit comments

Comments
 (0)