Skip to content

Commit 7827b5d

Browse files
skip decls/rules if they are inside a @supports(--)
1 parent fedabe9 commit 7827b5d

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

index.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,35 @@ var RE_VAR_PROP = (/(--(.+))/);
2525
function eachCssVariableDeclaration(css, cb) {
2626
// Loop through all of the declarations and grab the variables and put them in the map
2727
css.walkDecls(function(decl) {
28+
var isUnderSupportsCss = declIsInCssSupportsRule(decl);
2829
// If declaration is a variable
29-
if(RE_VAR_PROP.test(decl.prop)) {
30+
if(RE_VAR_PROP.test(decl.prop) && !isUnderSupportsCss) {
3031
cb(decl);
3132
}
3233
});
3334
}
3435

36+
function declIsInCssSupportsRule(decl) {
37+
if(decl.parent && decl.parent.parent) {
38+
return checkIsCssSupportsRule(decl.parent.parent);
39+
}
40+
return false;
41+
};
42+
43+
function ruleIsInCssSupportsRule(rule) {
44+
if(rule.parent) {
45+
return checkIsCssSupportsRule(rule.parent);
46+
}
47+
return false;
48+
};
49+
50+
function checkIsCssSupportsRule(node) {
51+
if(node.type == 'atrule' && node.name === 'supports' && [].concat(node.params)[0].indexOf('--') > -1) {
52+
return true;
53+
}
54+
return false;
55+
};
56+
3557

3658

3759
function cleanUpNode(node) {
@@ -209,6 +231,9 @@ module.exports = postcss.plugin('postcss-css-variables', function(options) {
209231
// Collect all the rules that have declarations that use variables
210232
var rulesThatHaveDeclarationsWithVariablesList = [];
211233
css.walkRules(function(rule) {
234+
if(ruleIsInCssSupportsRule(rule)) {
235+
return false;
236+
}
212237
var doesRuleUseVariables = rule.nodes.some(function(node) {
213238
if(node.type === 'decl') {
214239
var decl = node;

0 commit comments

Comments
 (0)