From 996947d2f69b60c1322612db1acb1531f020d4b0 Mon Sep 17 00:00:00 2001 From: jurcovicovam Date: Sun, 1 Feb 2015 15:32:58 +0100 Subject: [PATCH 1/2] Fixing `makeImportant` on mixins and rulesets: #2421 1.) Rulesets `makeImportant` must create a new ruleset. 2.) Mixin-definition `makeImportant` must create a new mixin definition. It must NOT convert mixin into ruleset. --- lib/less/tree/mixin-definition.js | 13 ++++++++++++- lib/less/tree/ruleset.js | 12 +++++++----- test/css/mixins-important.css | 6 ++++++ test/less/mixins-important.less | 18 +++++++++++++++++- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/lib/less/tree/mixin-definition.js b/lib/less/tree/mixin-definition.js index 7afd2bffd..b81dd4eb8 100644 --- a/lib/less/tree/mixin-definition.js +++ b/lib/less/tree/mixin-definition.js @@ -112,6 +112,17 @@ Definition.prototype.evalParams = function (context, mixinEnv, args, evaldArgume return frame; }; +Definition.prototype.makeImportant = function() { + var rules = !this.rules ? this.rules : this.rules.map(function (r) { + if (r.makeImportant) { + return r.makeImportant(true); + } else { + return r; + } + }); + var result = new Definition (this.name, this.params, rules, this.condition, this.variadic, this.frames); + return result; +}; Definition.prototype.eval = function (context) { return new Definition(this.name, this.params, this.rules, this.condition, this.variadic, this.frames || context.frames.slice(0)); }; @@ -129,7 +140,7 @@ Definition.prototype.evalCall = function (context, args, important) { ruleset.originalRuleset = this; ruleset = ruleset.eval(new contexts.Eval(context, [this, frame].concat(mixinFrames))); if (important) { - ruleset = this.makeImportant.apply(ruleset); + ruleset = ruleset.makeImportant(); } return ruleset; }; diff --git a/lib/less/tree/ruleset.js b/lib/less/tree/ruleset.js index 33936b780..39a66cf29 100644 --- a/lib/less/tree/ruleset.js +++ b/lib/less/tree/ruleset.js @@ -183,15 +183,17 @@ Ruleset.prototype.evalImports = function(context) { } }; Ruleset.prototype.makeImportant = function() { - this.rules = this.rules.map(function (r) { + var result = new Ruleset(this.selectors, this.rules.map(function (r) { if (r.makeImportant) { - return r.makeImportant(); + return r.makeImportant(true); } else { return r; } - }); - return this; -};Ruleset.prototype.matchArgs = function (args) { + }), this.strictImports); + + return result; +}; +Ruleset.prototype.matchArgs = function (args) { return !args || args.length === 0; }; // lets you call a css selector with a guard diff --git a/test/css/mixins-important.css b/test/css/mixins-important.css index 1b9faa1e4..3d53d431c 100644 --- a/test/css/mixins-important.css +++ b/test/css/mixins-important.css @@ -49,3 +49,9 @@ .when-calling-nested-with-param-issue-2394 { width: 10px !important; } +.class1-2421 { + margin: 5px !important; +} +.class2-2421 { + margin: 5px; +} diff --git a/test/less/mixins-important.less b/test/less/mixins-important.less index 0a1ff180d..9f60efff9 100644 --- a/test/less/mixins-important.less +++ b/test/less/mixins-important.less @@ -34,4 +34,20 @@ } .when-calling-nested-with-param-issue-2394 { .size(10px) !important; -} \ No newline at end of file +} +.testMixin-2421 () { + .topCheck-2421 () { + .nestedCheck-2421() { + margin: 5px; + } + .nestedCheck-2421(); + } + .topCheck-2421(); +} +.class1-2421 { + .testMixin-2421() !important; +} +.class2-2421 { + .testMixin-2421(); +} + From 2e579cf42afdc15b9783235c646bb884217c1faf Mon Sep 17 00:00:00 2001 From: jurcovicovam Date: Sun, 1 Feb 2015 15:39:33 +0100 Subject: [PATCH 2/2] cleaning up forgotten debug help --- lib/less/tree/ruleset.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/less/tree/ruleset.js b/lib/less/tree/ruleset.js index 39a66cf29..9e55c5bf0 100644 --- a/lib/less/tree/ruleset.js +++ b/lib/less/tree/ruleset.js @@ -185,7 +185,7 @@ Ruleset.prototype.evalImports = function(context) { Ruleset.prototype.makeImportant = function() { var result = new Ruleset(this.selectors, this.rules.map(function (r) { if (r.makeImportant) { - return r.makeImportant(true); + return r.makeImportant(); } else { return r; }