From 36383dc89b2eecd06349fefc005dd33cb8b1e629 Mon Sep 17 00:00:00 2001 From: seven-phases-max Date: Tue, 2 Sep 2014 00:02:49 +0400 Subject: [PATCH] Fix property interpolation for `@*` values --- lib/less/tree/rule.js | 11 +++++++---- test/css/property-name-interp.css | 1 + test/less/property-name-interp.less | 5 ++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/less/tree/rule.js b/lib/less/tree/rule.js index 4e1ccde69..8e62c4071 100644 --- a/lib/less/tree/rule.js +++ b/lib/less/tree/rule.js @@ -1,6 +1,6 @@ (function (tree) { -tree.Rule = function (name, value, important, merge, index, currentFileInfo, inline) { +tree.Rule = function (name, value, important, merge, index, currentFileInfo, inline, variable) { this.name = name; this.value = (value instanceof tree.Value || value instanceof tree.Ruleset) ? value : new(tree.Value)([value]); this.important = important ? ' ' + important.trim() : ''; @@ -8,7 +8,8 @@ tree.Rule = function (name, value, important, merge, index, currentFileInfo, inl this.index = index; this.currentFileInfo = currentFileInfo; this.inline = inline || false; - this.variable = name.charAt && (name.charAt(0) === '@'); + this.variable = (variable !== undefined) ? variable + : (name.charAt && (name.charAt(0) === '@')); }; tree.Rule.prototype = { @@ -30,13 +31,14 @@ tree.Rule.prototype = { }, toCSS: tree.toCSS, eval: function (env) { - var strictMathBypass = false, name = this.name, evaldValue; + var strictMathBypass = false, name = this.name, variable = this.variable, evaldValue; if (typeof name !== "string") { // expand 'primitive' name directly to get // things faster (~10% for benchmark.less): name = (name.length === 1) && (name[0] instanceof tree.Keyword) ? name[0].value : evalName(env, name); + variable = false; // never treat expanded interpolation as new variable name } if (name === "font" && !env.strictMath) { strictMathBypass = true; @@ -54,7 +56,8 @@ tree.Rule.prototype = { evaldValue, this.important, this.merge, - this.index, this.currentFileInfo, this.inline); + this.index, this.currentFileInfo, this.inline, + variable); } catch(e) { if (typeof e.index !== 'number') { diff --git a/test/css/property-name-interp.css b/test/css/property-name-interp.css index 2082b8197..315815e3f 100644 --- a/test/css/property-name-interp.css +++ b/test/css/property-name-interp.css @@ -1,5 +1,6 @@ pi-test { border: 0; + @not-variable: @not-variable; ufo-width: 50%; *-z-border: 1px dashed blue; -www-border-top: 2px; diff --git a/test/less/property-name-interp.less b/test/less/property-name-interp.less index 9886e65fe..46e337913 100644 --- a/test/less/property-name-interp.less +++ b/test/less/property-name-interp.less @@ -6,8 +6,11 @@ pi-test { @c_c: left; @d-d4: radius; @-: -; - + + @var: ~'@not-variable'; + @{a}: 0; + @{var}: @var; @{prefix}width: 50%; *-z-@{a} :1px dashed blue; -www-@{a}-@{bb}: 2px;