mirror of
https://github.com/less/less.js.git
synced 2026-01-21 21:27:59 -05:00
Fixed mixin calls not working from dynamic mixins
Dynamic mixins aren't treated enough like Rulesets. There is some code duplication which needs to be cleaned up, ideally they should share a prototype.
This commit is contained in:
@@ -27,10 +27,13 @@ tree.mixin.Definition = function MixinDefinition(name, params, rules) {
|
||||
this.selectors = [new(tree.Selector)([new(tree.Element)(null, name)])];
|
||||
this.params = params;
|
||||
this.rules = rules;
|
||||
this._lookups = {};
|
||||
};
|
||||
tree.mixin.Definition.prototype = {
|
||||
toCSS: function () { return "" },
|
||||
variables: function () { return tree.Ruleset.prototype.variables.apply(this) },
|
||||
find: function () { return tree.Ruleset.prototype.find.apply(this, arguments) },
|
||||
rulesets: function () { return tree.Ruleset.prototype.rulesets.apply(this) },
|
||||
|
||||
eval: function (args, env) {
|
||||
var frame = new(tree.Ruleset)(null, []), context;
|
||||
@@ -44,9 +47,17 @@ tree.mixin.Definition.prototype = {
|
||||
}
|
||||
context = { frames: [this, frame].concat(env.frames) };
|
||||
|
||||
return new(tree.Ruleset)(null, this.rules.map(function (rule) {
|
||||
if (rule.evalRules) return rule.evalRules(context);
|
||||
else return rule.eval(context);
|
||||
}));
|
||||
var rules = [];
|
||||
|
||||
this.rules.forEach(function (rule) {
|
||||
if (rule.evalRules) {
|
||||
rules.push(rule.evalRules(context));
|
||||
} else if (rule instanceof tree.mixin.Call) {
|
||||
Array.prototype.push.apply(rules, rule.eval(context));
|
||||
} else {
|
||||
rules.push(rule.eval(context));
|
||||
}
|
||||
});
|
||||
return new(tree.Ruleset)(null, rules);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,10 +8,18 @@ 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);
|
||||
}));
|
||||
var rules = [];
|
||||
|
||||
this.rules.forEach(function (rule) {
|
||||
if (rule.evalRules) {
|
||||
rules.push(rule.evalRules(context));
|
||||
} else if (rule instanceof tree.mixin.Call) {
|
||||
Array.prototype.push.apply(rules, rule.eval(context));
|
||||
} else {
|
||||
rules.push(rule.eval(context));
|
||||
}
|
||||
});
|
||||
return new(tree.Ruleset)(this.selectors, rules);
|
||||
},
|
||||
variables: function () {
|
||||
if (this._variables) { return this._variables }
|
||||
|
||||
@@ -3,4 +3,5 @@
|
||||
}
|
||||
.class .inner .innest {
|
||||
width: 30;
|
||||
border-width: 60;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
.mix-inner (@var) {
|
||||
border-width: @var;
|
||||
}
|
||||
|
||||
.mix (@a: 10) {
|
||||
.inner {
|
||||
height: @a * 10;
|
||||
|
||||
.innest {
|
||||
width: @a;
|
||||
.mix-inner(@a * 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user