diff --git a/lib/less/tree/mixin.js b/lib/less/tree/mixin.js index d0496e1b..17a4e672 100644 --- a/lib/less/tree/mixin.js +++ b/lib/less/tree/mixin.js @@ -10,7 +10,7 @@ tree.mixin.Call = function (elements, args, index, filename, important) { }; tree.mixin.Call.prototype = { eval: function (env) { - var mixins, args, rules = [], match = false, i, m, f, isRecursive, isOneFound; + var mixins, mixin, args, rules = [], match = false, i, m, f, isRecursive, isOneFound; args = this.arguments && this.arguments.map(function (a) { return { name: a.name, value: a.value.eval(env) }; @@ -20,9 +20,10 @@ tree.mixin.Call.prototype = { if ((mixins = env.frames[i].find(this.selector)).length > 0) { isOneFound = true; for (m = 0; m < mixins.length; m++) { + mixin = mixins[m]; isRecursive = false; for(f = 0; f < env.frames.length; f++) { - if ((!(mixins[m] instanceof tree.mixin.Definition)) && mixins[m] === (env.frames[f].originalRuleset || env.frames[f])) { + if ((!(mixin instanceof tree.mixin.Definition)) && mixin === (env.frames[f].originalRuleset || env.frames[f])) { isRecursive = true; break; } @@ -30,14 +31,16 @@ tree.mixin.Call.prototype = { if (isRecursive) { continue; } - if (mixins[m].match(args, env)) { - try { - Array.prototype.push.apply( - rules, mixins[m].eval(env, this.arguments, this.important).rules); - match = true; - } catch (e) { - throw { message: e.message, index: this.index, filename: this.filename, stack: e.stack }; + if (mixin.matchArgs(args, env)) { + if (!mixin.matchCondition || mixin.matchCondition(args, env)) { + try { + Array.prototype.push.apply( + rules, mixin.eval(env, this.arguments, this.important).rules); + } catch (e) { + throw { message: e.message, index: this.index, filename: this.filename, stack: e.stack }; + } } + match = true; } } if (match) { @@ -167,7 +170,13 @@ tree.mixin.Definition.prototype = { ruleset.originalRuleset = this; return ruleset; }, - match: function (args, env) { + matchCondition: function (args, env) { + if (this.condition && !this.condition.eval({ + frames: [this.evalParams(env, args, [])].concat(env.frames) + })) { return false } + return true; + }, + matchArgs: function (args, env) { var argsLength = (args && args.length) || 0, len, frame; if (! this.variadic) { @@ -176,10 +185,6 @@ tree.mixin.Definition.prototype = { if ((this.required > 0) && (argsLength > this.params.length)) { return false } } - if (this.condition && !this.condition.eval({ - frames: [this.evalParams(env, args, [])].concat(env.frames) - })) { return false } - len = Math.min(argsLength, this.arity); for (var i = 0; i < len; i++) { diff --git a/lib/less/tree/ruleset.js b/lib/less/tree/ruleset.js index 71402aac..8ac4811a 100644 --- a/lib/less/tree/ruleset.js +++ b/lib/less/tree/ruleset.js @@ -85,7 +85,7 @@ tree.Ruleset.prototype = { } }), this.strictImports); }, - match: function (args) { + matchArgs: function (args) { return !args || args.length === 0; }, variables: function () { diff --git a/test/less/mixins-guards.less b/test/less/mixins-guards.less index c92b34d5..4414e326 100644 --- a/test/less/mixins-guards.less +++ b/test/less/mixins-guards.less @@ -99,8 +99,6 @@ .equality-unit-test(@num) when (@num = 2) { test: pass; } -.equality-unit-test(@num) { -} .equality-units { .equality-unit-test(1px); .equality-unit-test(2px);