Skip to content

Commit 0eb1802

Browse files
fix issue with @supports --css rule + skip duplicates in mq
1 parent 7827b5d commit 0eb1802

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

index.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -231,24 +231,23 @@ module.exports = postcss.plugin('postcss-css-variables', function(options) {
231231
// Collect all the rules that have declarations that use variables
232232
var rulesThatHaveDeclarationsWithVariablesList = [];
233233
css.walkRules(function(rule) {
234-
if(ruleIsInCssSupportsRule(rule)) {
235-
return false;
236-
}
237-
var doesRuleUseVariables = rule.nodes.some(function(node) {
238-
if(node.type === 'decl') {
239-
var decl = node;
240-
// If it uses variables
241-
// and is not a variable declarations that we may be preserving from earlier
242-
if(resolveValue.RE_VAR_FUNC.test(decl.value) && !RE_VAR_PROP.test(decl.prop)) {
243-
return true;
234+
if(!ruleIsInCssSupportsRule(rule)) {
235+
var doesRuleUseVariables = rule.nodes.some(function(node) {
236+
if(node.type === 'decl') {
237+
var decl = node;
238+
// If it uses variables
239+
// and is not a variable declarations that we may be preserving from earlier
240+
if(resolveValue.RE_VAR_FUNC.test(decl.value) && !RE_VAR_PROP.test(decl.prop)) {
241+
return true;
242+
}
244243
}
245-
}
246244

247-
return false;
248-
});
245+
return false;
246+
});
249247

250-
if(doesRuleUseVariables) {
251-
rulesThatHaveDeclarationsWithVariablesList.push(rule);
248+
if(doesRuleUseVariables) {
249+
rulesThatHaveDeclarationsWithVariablesList.push(rule);
250+
}
252251
}
253252
});
254253

lib/resolve-decl.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var cloneSpliceParentOntoNodeWhen = require('./clone-splice-parent-onto-node-whe
1414
function eachMapItemDependencyOfDecl(variablesUsedList, map, decl, cb) {
1515
// Now find any at-rule declarations that pertains to each rule
1616
// Loop through the variables used
17+
var previousDecl = '';
1718
variablesUsedList.forEach(function(variableUsedName) {
1819

1920
// Find anything in the map that corresponds to that variable
@@ -60,7 +61,11 @@ function eachMapItemDependencyOfDecl(variablesUsedList, map, decl, cb) {
6061
// If it is under the proper scope,
6162
// we need to check because we are iterating over all map entries
6263
if(mimicDecl && isNodeUnderScope(mimicDecl, mapItem.parent, true)) {
63-
cb(mimicDecl, mapItem);
64+
//double check the declaration is not exactly the same as the previous one -> prevent diplicated blocks in mq
65+
if( previousDecl != JSON.stringify(mimicDecl) ) {
66+
cb(mimicDecl, mapItem);
67+
}
68+
previousDecl = JSON.stringify(mimicDecl);
6469
}
6570
});
6671
});

0 commit comments

Comments
 (0)