Skip to content

Commit

Permalink
Merge pull request #2427 from SomMeri/nested-mixin-changing-important…
Browse files Browse the repository at this point in the history
…-2421

Nested mixin changing important 2421
  • Loading branch information
lukeapage committed Feb 1, 2015
2 parents 4972d47 + 2e579cf commit 4f60ab1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
13 changes: 12 additions & 1 deletion lib/less/tree/mixin-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};
Expand All @@ -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;
};
Expand Down
10 changes: 6 additions & 4 deletions lib/less/tree/ruleset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} 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
Expand Down
6 changes: 6 additions & 0 deletions test/css/mixins-important.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@
.when-calling-nested-with-param-issue-2394 {
width: 10px !important;
}
.class1-2421 {
margin: 5px !important;
}
.class2-2421 {
margin: 5px;
}
18 changes: 17 additions & 1 deletion test/less/mixins-important.less
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,20 @@
}
.when-calling-nested-with-param-issue-2394 {
.size(10px) !important;
}
}
.testMixin-2421 () {
.topCheck-2421 () {
.nestedCheck-2421() {
margin: 5px;
}
.nestedCheck-2421();
}
.topCheck-2421();
}
.class1-2421 {
.testMixin-2421() !important;
}
.class2-2421 {
.testMixin-2421();
}

0 comments on commit 4f60ab1

Please sign in to comment.