Fix a small scope issue with mixins when using parent selectors, introduced in 1.6.2. Fixes #1877

This commit is contained in:
Luke Page
2014-02-21 11:22:42 +00:00
parent bf9c59025b
commit 7c90acaae6
5 changed files with 60 additions and 14 deletions

View File

@@ -111,20 +111,25 @@ tree.Ruleset.prototype = {
rule = rsRules[i];
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;
}
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);
}
}
}
// 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);
// cannot call if there is no selector, so we can just continue
if (!rule.selectors[0].evaldCondition) {
continue;
}
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);
}
}
}

View File

@@ -33,3 +33,6 @@
scope: 'top level';
sub-scope-only: 'inside';
}
#parentSelectorScope {
prop: #ffffff;
}

View File

@@ -0,0 +1,9 @@
.something {
& {
.a {value: a}
}
& {
.b {.a} // was Err. before 1.6.2
}
}

View File

@@ -0,0 +1,4 @@
NameError: .a is undefined in {path}mixin-not-visible-in-scope-1.less on line 7, column 13:
6 & {
7 .b {.a} // was Err. before 1.6.2
8 }

View File

@@ -76,4 +76,29 @@
@subScopeOnly: 'inside';
//use the mixin
.mixinNoParam();
}
#parentSelectorScope {
@col: white;
& {
@col: black;
}
prop: @col;
& {
@col: black;
}
}
.test-empty-mixin() {
}
#parentSelectorScopeMixins {
& {
.test-empty-mixin() {
should: never seee 1;
}
}
.test-empty-mixin();
& {
.test-empty-mixin() {
should: never seee 2;
}
}
}