mirror of
https://github.com/less/less.js.git
synced 2026-04-09 03:00:20 -04:00
make mixin definitions have similar coding style to detached rulesets for grabbing frames
This commit is contained in:
@@ -10,12 +10,11 @@ tree.DetachedRuleset.prototype = {
|
||||
this.ruleset = visitor.visit(this.ruleset);
|
||||
},
|
||||
eval: function (env) {
|
||||
// TODO - handle mixin definition like this
|
||||
var frames = this.frames || env.frames.slice(0);
|
||||
return new tree.DetachedRuleset(this.ruleset, frames);
|
||||
},
|
||||
callEval: function (env) {
|
||||
return this.ruleset.eval(new(tree.evalEnv)(env, this.frames.concat(env.frames)));
|
||||
return this.ruleset.eval(this.frames ? new(tree.evalEnv)(env, this.frames.concat(env.frames)) : env);
|
||||
}
|
||||
};
|
||||
})(require('../tree'));
|
||||
|
||||
@@ -103,7 +103,7 @@ tree.mixin.Call.prototype = {
|
||||
mixin.originalRuleset = mixins[m].originalRuleset || mixins[m];
|
||||
}
|
||||
Array.prototype.push.apply(
|
||||
rules, mixin.eval(env, args, this.important).rules);
|
||||
rules, mixin.evalCall(env, args, this.important).rules);
|
||||
} catch (e) {
|
||||
throw { message: e.message, index: this.index, filename: this.currentFileInfo.filename, stack: e.stack };
|
||||
}
|
||||
@@ -150,7 +150,7 @@ tree.mixin.Call.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
tree.mixin.Definition = function (name, params, rules, condition, variadic) {
|
||||
tree.mixin.Definition = function (name, params, rules, condition, variadic, frames) {
|
||||
this.name = name;
|
||||
this.selectors = [new(tree.Selector)([new(tree.Element)(null, name, this.index, this.currentFileInfo)])];
|
||||
this.params = params;
|
||||
@@ -164,7 +164,7 @@ tree.mixin.Definition = function (name, params, rules, condition, variadic) {
|
||||
else { return count; }
|
||||
}, 0);
|
||||
this.parent = tree.Ruleset.prototype;
|
||||
this.frames = [];
|
||||
this.frames = frames;
|
||||
};
|
||||
tree.mixin.Definition.prototype = {
|
||||
type: "MixinDefinition",
|
||||
@@ -258,9 +258,12 @@ tree.mixin.Definition.prototype = {
|
||||
|
||||
return frame;
|
||||
},
|
||||
eval: function (env, args, important) {
|
||||
eval: function (env) {
|
||||
return new tree.mixin.Definition(this.name, this.params, this.rules, this.condition, this.variadic, this.frames || env.frames.slice(0));
|
||||
},
|
||||
evalCall: function (env, args, important) {
|
||||
var _arguments = [],
|
||||
mixinFrames = this.frames.concat(env.frames),
|
||||
mixinFrames = this.frames ? this.frames.concat(env.frames) : env.frames,
|
||||
frame = this.evalParams(env, new(tree.evalEnv)(env, mixinFrames), args, _arguments),
|
||||
rules, ruleset;
|
||||
|
||||
|
||||
@@ -66,8 +66,8 @@ tree.Ruleset.prototype = {
|
||||
// so they can be evaluated like closures when the time comes.
|
||||
var rsRules = ruleset.rules, rsRuleCnt = rsRules ? rsRules.length : 0;
|
||||
for (i = 0; i < rsRuleCnt; i++) {
|
||||
if (rsRules[i] instanceof tree.mixin.Definition) {
|
||||
rsRules[i].frames = envFrames.slice(0);
|
||||
if (rsRules[i] instanceof tree.mixin.Definition || rsRules[i] instanceof tree.DetachedRuleset) {
|
||||
rsRules[i] = rsRules[i].eval(env);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ tree.Ruleset.prototype = {
|
||||
// Evaluate everything else
|
||||
for (i = 0; i < rsRules.length; i++) {
|
||||
rule = rsRules[i];
|
||||
if (! (rule instanceof tree.mixin.Definition)) {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user