mirror of
https://github.com/less/less.js.git
synced 2026-04-09 03:00:20 -04:00
Fix a small scope issue with mixins when using parent selectors, introduced in 1.6.2. Fixes #1877
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,3 +33,6 @@
|
||||
scope: 'top level';
|
||||
sub-scope-only: 'inside';
|
||||
}
|
||||
#parentSelectorScope {
|
||||
prop: #ffffff;
|
||||
}
|
||||
|
||||
9
test/less/errors/mixin-not-visible-in-scope-1.less
Normal file
9
test/less/errors/mixin-not-visible-in-scope-1.less
Normal file
@@ -0,0 +1,9 @@
|
||||
.something {
|
||||
& {
|
||||
.a {value: a}
|
||||
}
|
||||
|
||||
& {
|
||||
.b {.a} // was Err. before 1.6.2
|
||||
}
|
||||
}
|
||||
4
test/less/errors/mixin-not-visible-in-scope-1.txt
Normal file
4
test/less/errors/mixin-not-visible-in-scope-1.txt
Normal 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 }
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user