lib/less/js/lib/less/tree/ruleset.js in less-2.5.1 vs lib/less/js/lib/less/tree/ruleset.js in less-2.6.0
- old
+ new
@@ -18,21 +18,28 @@
this.rules = visitor.visitArray(this.rules);
}
},
eval: function (env) {
var thisSelectors = this.selectors, selectors,
- selCnt, i, defaultFunc = tree.defaultFunc;
+ selCnt, selector, i, defaultFunc = tree.defaultFunc, hasOnePassingSelector = false;
+
if (thisSelectors && (selCnt = thisSelectors.length)) {
selectors = [];
defaultFunc.error({
type: "Syntax",
message: "it is currently only allowed in parametric mixin guards,"
});
for (i = 0; i < selCnt; i++) {
- selectors.push(thisSelectors[i].eval(env));
+ selector = thisSelectors[i].eval(env);
+ selectors.push(selector);
+ if (selector.evaldCondition) {
+ hasOnePassingSelector = true;
+ }
}
defaultFunc.reset();
+ } else {
+ hasOnePassingSelector = true;
}
var rules = this.rules ? this.rules.slice(0) : null,
ruleset = new(tree.Ruleset)(selectors, rules, this.strictImports),
rule, subRule;
@@ -43,10 +50,14 @@
ruleset.allowImports = this.allowImports;
if(this.debugInfo) {
ruleset.debugInfo = this.debugInfo;
}
+
+ if (!hasOnePassingSelector) {
+ rules.length = 0;
+ }
// push the current ruleset to the frames stack
var envFrames = env.frames;
envFrames.unshift(ruleset);
@@ -64,12 +75,12 @@
// Store the frames around mixin definitions,
// so they can be evaluated like closures when the time comes.
var rsRules = ruleset.rules, rsRuleCnt = rsRules ? rsRules.length : 0;
for (i = 0; i < rsRuleCnt; i++) {
- if (rsRules[i] instanceof tree.mixin.Definition) {
- rsRules[i].frames = envFrames.slice(0);
+ if (rsRules[i] instanceof tree.mixin.Definition || rsRules[i] instanceof tree.DetachedRuleset) {
+ rsRules[i] = rsRules[i].eval(env);
}
}
var mediaBlockCount = (env.mediaBlocks && env.mediaBlocks.length) || 0;
@@ -88,33 +99,48 @@
});
rsRules.splice.apply(rsRules, [i, 1].concat(rules));
rsRuleCnt += rules.length - 1;
i += rules.length-1;
ruleset.resetCache();
+ } else if (rsRules[i] instanceof tree.RulesetCall) {
+ /*jshint loopfunc:true */
+ rules = rsRules[i].eval(env).rules.filter(function(r) {
+ if ((r instanceof tree.Rule) && r.variable) {
+ // do not pollute the scope at all
+ return false;
+ }
+ return true;
+ });
+ rsRules.splice.apply(rsRules, [i, 1].concat(rules));
+ rsRuleCnt += rules.length - 1;
+ i += rules.length-1;
+ ruleset.resetCache();
}
}
// Evaluate everything else
for (i = 0; i < rsRules.length; i++) {
rule = rsRules[i];
- if (! (rule instanceof tree.mixin.Definition)) {
+ if (! (rule instanceof tree.mixin.Definition || rule instanceof tree.DetachedRuleset)) {
rsRules[i] = rule = rule.eval ? rule.eval(env) : rule;
- // for rulesets, check if it is a css guard and can be removed
- if (rule instanceof tree.Ruleset && rule.selectors && rule.selectors.length === 1) {
- // check if it can be folded in (e.g. & where)
- if (rule.selectors[0].isJustParentSelector()) {
- rsRules.splice(i--, 1);
- // cannot call if there is no selector, so we can just continue
- if (!rule.selectors[0].evaldCondition) {
- continue;
+ }
+ }
+
+ // Evaluate everything else
+ for (i = 0; i < rsRules.length; i++) {
+ rule = rsRules[i];
+ // for rulesets, check if it is a css guard and can be removed
+ if (rule instanceof tree.Ruleset && rule.selectors && rule.selectors.length === 1) {
+ // check if it can be folded in (e.g. & where)
+ if (rule.selectors[0].isJustParentSelector()) {
+ rsRules.splice(i--, 1);
+
+ for(var j = 0; j < rule.rules.length; j++) {
+ subRule = rule.rules[j];
+ if (!(subRule instanceof tree.Rule) || !subRule.variable) {
+ rsRules.splice(++i, 0, subRule);
}
- for(var j = 0; j < rule.rules.length; j++) {
- subRule = rule.rules[j];
- if (!(subRule instanceof tree.Rule) || !subRule.variable) {
- rsRules.splice(++i, 0, subRule);
- }
- }
}
}
}
}
@@ -343,9 +369,12 @@
},
toCSS: tree.toCSS,
markReferenced: function () {
+ if (!this.selectors) {
+ return;
+ }
for (var s = 0; s < this.selectors.length; s++) {
this.selectors[s].markReferenced();
}
},