Skip to content

Commit b815e83

Browse files
calebdwilliamsromainmenke
authored andcommitted
fix: plugin will parse fallback until it finds a known value (postcss/postcss-custom-properties#240)
1 parent 5834dd6 commit b815e83

File tree

6 files changed

+1514
-1495
lines changed

6 files changed

+1514
-1495
lines changed

plugins/postcss-custom-properties/src/lib/transform-properties.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@ export default (root, customProperties, opts) => {
99
if (isTransformableDecl(decl) && !isRuleIgnored(decl)) {
1010
const originalValue = decl.value;
1111
const valueAST = parse(originalValue);
12-
const value = String(transformValueAST(valueAST, customProperties));
12+
let value = String(transformValueAST(valueAST, customProperties));
13+
14+
// protect against circular references
15+
const valueSet = new Set();
16+
17+
while (customPropertiesRegExp.test(value) && !valueSet.has(value)) {
18+
valueSet.add(value);
19+
const parsedValueAST = parse(valueAST);
20+
value = String(transformValueAST(parsedValueAST, customProperties));
21+
}
1322

1423
// conditionally transform values that have changed
1524
if (value !== originalValue) {

plugins/postcss-custom-properties/test/basic.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ html {
3838

3939
.test {
4040
--skip: gray;
41-
color: var(--color);
41+
color: var(--override, var(--color));
4242
}
4343

4444
.test--color_spacing {

plugins/postcss-custom-properties/test/basic.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ html {
4141
.test {
4242
--skip: gray;
4343
color: rgb(255, 0, 0);
44-
color: var(--color);
44+
color: var(--override, var(--color));
4545
}
4646

4747
.test--color_spacing {

plugins/postcss-custom-properties/test/basic.import-is-empty.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ html {
4141
.test {
4242
--skip: gray;
4343
color: rgb(255, 0, 0);
44-
color: var(--color);
44+
color: var(--override, var(--color));
4545
}
4646

4747
.test--color_spacing {

plugins/postcss-custom-properties/test/basic.import.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ html {
4141
.test {
4242
--skip: gray;
4343
color: rgb(255, 0, 0);
44-
color: var(--color);
44+
color: var(--override, var(--color));
4545
}
4646

4747
.test--color_spacing {

0 commit comments

Comments
 (0)