Skip to content

Commit

Permalink
Fix a small scope issue with mixins when using parent selectors, intr…
Browse files Browse the repository at this point in the history
…oduced in 1.6.2. Fixes #1877
  • Loading branch information
lukeapage committed Feb 21, 2014
1 parent bf9c590 commit 7c90aca
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 14 deletions.
33 changes: 19 additions & 14 deletions lib/less/tree/ruleset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/css/scope.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@
scope: 'top level';
sub-scope-only: 'inside';
}
#parentSelectorScope {
prop: #ffffff;
}
9 changes: 9 additions & 0 deletions test/less/errors/mixin-not-visible-in-scope-1.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.something {
& {
.a {value: a}
}

& {
.b {.a} // was Err. before 1.6.2
}
}
4 changes: 4 additions & 0 deletions test/less/errors/mixin-not-visible-in-scope-1.txt
Original file line number Diff line number Diff line change
@@ -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 }
25 changes: 25 additions & 0 deletions test/less/scope.less
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

0 comments on commit 7c90aca

Please sign in to comment.