postcss-css-variables
Advanced tools
Comparing version
@@ -0,1 +1,6 @@ | ||
# v0.19.0 - 2023-04-12 | ||
- Fix nesting edge case with comma separated selectors | ||
- Thank you to [@marapper](https://github.com/marapper) for the [contribution](https://github.com/MadLittleMods/postcss-css-variables/pull/131) | ||
# v0.18.0 - 2021-05-11 | ||
@@ -2,0 +7,0 @@ |
56
index.js
@@ -237,3 +237,18 @@ // PostCSS CSS Variables (postcss-css-variables) | ||
if (doesRuleUseVariables) { | ||
rulesThatHaveDeclarationsWithVariablesList.push(rule); | ||
if (rule.type === "rule" && rule.selectors.length > 1) { | ||
// Split out the rule into each comma separated selector piece | ||
// We only need to split if it's actually a Rule with multiple selectors (comma separated) | ||
// duplicate rules would be probably merged with cssnano (cannot be sure about nested) | ||
rule.selectors.reverse().forEach(function(selector) { | ||
var ruleClone = rule.cloneAfter(); | ||
ruleClone.selector = selector; | ||
return ruleClone; | ||
}); | ||
// Rules will be added to list in the next traverse | ||
rule.remove(); | ||
} else { | ||
rulesThatHaveDeclarationsWithVariablesList.push(rule); | ||
} | ||
} | ||
@@ -243,31 +258,14 @@ }); | ||
rulesThatHaveDeclarationsWithVariablesList.forEach(function(rule) { | ||
var rulesToWorkOn = [].concat(rule); | ||
// Split out the rule into each comma separated selector piece | ||
// We only need to split if it's actually a Rule with multiple selectors (comma separated) | ||
if (rule.type === "rule" && rule.selectors.length > 1) { | ||
// Reverse the selectors so that we can cloneAfter in the same comma separated order | ||
rulesToWorkOn = rule.selectors.reverse().map(function(selector) { | ||
var ruleClone = rule.cloneAfter(); | ||
ruleClone.selector = selector; | ||
return ruleClone; | ||
}); | ||
rule.remove(); | ||
} | ||
// Resolve the declarations | ||
rulesToWorkOn.forEach(function(ruleToWorkOn) { | ||
ruleToWorkOn.nodes.slice(0).forEach(function(node) { | ||
if (node.type === "decl") { | ||
var decl = node; | ||
resolveDecl( | ||
decl, | ||
map, | ||
opts.preserve, | ||
opts.preserveAtRulesOrder, | ||
logResolveValueResult | ||
); | ||
} | ||
}); | ||
rule.nodes.slice(0).forEach(function(node) { | ||
if (node.type === "decl") { | ||
var decl = node; | ||
resolveDecl( | ||
decl, | ||
map, | ||
opts.preserve, | ||
opts.preserveAtRulesOrder, | ||
logResolveValueResult | ||
); | ||
} | ||
}); | ||
@@ -274,0 +272,0 @@ }); |
{ | ||
"name": "postcss-css-variables", | ||
"version": "0.18.0", | ||
"version": "0.19.0", | ||
"description": "PostCSS plugin to transform CSS Custom Properties(CSS variables) syntax into a static representation", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
62527
0.29%924
-0.11%