From 25dbfb177aeed2cd4e427ff489db711659475517 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Thu, 22 Apr 2010 13:07:41 -0400 Subject: [PATCH] Fix dynamic mixins with nested rules Dynamic mixins with more than one level of nesting wouldn't work. This is now fixed. Also refactored mixin.definition.eval a little. --- lib/less/tree/mixin.js | 9 ++------- lib/less/tree/rule.js | 4 ++++ lib/less/tree/ruleset.js | 6 ++++++ test/css/mixins-nested.css | 6 ++++++ test/less/mixins-nested.less | 13 +++++++++++++ 5 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 test/css/mixins-nested.css create mode 100644 test/less/mixins-nested.less diff --git a/lib/less/tree/mixin.js b/lib/less/tree/mixin.js index 27712630..190e1be8 100644 --- a/lib/less/tree/mixin.js +++ b/lib/less/tree/mixin.js @@ -45,13 +45,8 @@ tree.mixin.Definition.prototype = { context = { frames: [this, frame].concat(env.frames) }; return new(tree.Ruleset)(null, this.rules.map(function (rule) { - if (rule.rules) { - return new(tree.Ruleset)(rule.selectors, rule.rules.map(function (r) { - return new(tree.Rule)(r.name, r.value.eval(context)); - })); - } else { - return new(tree.Rule)(rule.name, rule.value.eval(context)); - } + if (rule.evalRules) return rule.evalRules(context); + else return rule.eval(context); })); } }; diff --git a/lib/less/tree/rule.js b/lib/less/tree/rule.js index 86d9f43d..563363d3 100644 --- a/lib/less/tree/rule.js +++ b/lib/less/tree/rule.js @@ -16,6 +16,10 @@ tree.Rule.prototype.toCSS = function (env) { } }; +tree.Rule.prototype.eval = function (context) { + return new(tree.Rule)(this.name, this.value.eval(context)); +}; + tree.Value = function Value(value) { this.value = value; this.is = 'value'; diff --git a/lib/less/tree/ruleset.js b/lib/less/tree/ruleset.js index c71cc60d..44fa86cb 100644 --- a/lib/less/tree/ruleset.js +++ b/lib/less/tree/ruleset.js @@ -7,6 +7,12 @@ 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); + })); + }, variables: function () { if (this._variables) { return this._variables } else { diff --git a/test/css/mixins-nested.css b/test/css/mixins-nested.css new file mode 100644 index 00000000..5a678864 --- /dev/null +++ b/test/css/mixins-nested.css @@ -0,0 +1,6 @@ +.class .inner { + height: 300; +} +.class .inner .innest { + width: 30; +} diff --git a/test/less/mixins-nested.less b/test/less/mixins-nested.less new file mode 100644 index 00000000..0015807d --- /dev/null +++ b/test/less/mixins-nested.less @@ -0,0 +1,13 @@ +.mix (@a: 10) { + .inner { + height: @a * 10; + + .innest { + width: @a; + } + } +} + +.class { + .mix(30); +}