mirror of
https://github.com/less/less.js.git
synced 2026-01-21 05:08:10 -05:00
Fix dynamic mixins with nested rules
Dynamic mixins with more than one level of nesting wouldn't work. This is now fixed. Also refactored mixin.definition.eval a little.
This commit is contained in:
@@ -45,13 +45,8 @@ tree.mixin.Definition.prototype = {
|
||||
context = { frames: [this, frame].concat(env.frames) };
|
||||
|
||||
return new(tree.Ruleset)(null, this.rules.map(function (rule) {
|
||||
if (rule.rules) {
|
||||
return new(tree.Ruleset)(rule.selectors, rule.rules.map(function (r) {
|
||||
return new(tree.Rule)(r.name, r.value.eval(context));
|
||||
}));
|
||||
} else {
|
||||
return new(tree.Rule)(rule.name, rule.value.eval(context));
|
||||
}
|
||||
if (rule.evalRules) return rule.evalRules(context);
|
||||
else return rule.eval(context);
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -16,6 +16,10 @@ tree.Rule.prototype.toCSS = function (env) {
|
||||
}
|
||||
};
|
||||
|
||||
tree.Rule.prototype.eval = function (context) {
|
||||
return new(tree.Rule)(this.name, this.value.eval(context));
|
||||
};
|
||||
|
||||
tree.Value = function Value(value) {
|
||||
this.value = value;
|
||||
this.is = 'value';
|
||||
|
||||
@@ -7,6 +7,12 @@ tree.Ruleset = function Ruleset(selectors, rules) {
|
||||
};
|
||||
tree.Ruleset.prototype = {
|
||||
eval: function () { return this },
|
||||
evalRules: function (context) {
|
||||
return new(tree.Ruleset)(this.selectors, this.rules.map(function (r) {
|
||||
if (r.evalRules) return r.evalRules(context);
|
||||
else return r.eval(context);
|
||||
}));
|
||||
},
|
||||
variables: function () {
|
||||
if (this._variables) { return this._variables }
|
||||
else {
|
||||
|
||||
6
test/css/mixins-nested.css
Normal file
6
test/css/mixins-nested.css
Normal file
@@ -0,0 +1,6 @@
|
||||
.class .inner {
|
||||
height: 300;
|
||||
}
|
||||
.class .inner .innest {
|
||||
width: 30;
|
||||
}
|
||||
13
test/less/mixins-nested.less
Normal file
13
test/less/mixins-nested.less
Normal file
@@ -0,0 +1,13 @@
|
||||
.mix (@a: 10) {
|
||||
.inner {
|
||||
height: @a * 10;
|
||||
|
||||
.innest {
|
||||
width: @a;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.class {
|
||||
.mix(30);
|
||||
}
|
||||
Reference in New Issue
Block a user