Skip to content

Commit

Permalink
Merge pull request #2173 from seven-phases-max/master
Browse files Browse the repository at this point in the history
Property interpolation fix for `@*` values
  • Loading branch information
lukeapage committed Sep 2, 2014
2 parents e045362 + 36383dc commit 6f7676a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
11 changes: 7 additions & 4 deletions lib/less/tree/rule.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
(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() : '';
this.merge = merge;
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 = {
Expand All @@ -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;
Expand All @@ -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') {
Expand Down
1 change: 1 addition & 0 deletions test/css/property-name-interp.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pi-test {
border: 0;
@not-variable: @not-variable;
ufo-width: 50%;
*-z-border: 1px dashed blue;
-www-border-top: 2px;
Expand Down
5 changes: 4 additions & 1 deletion test/less/property-name-interp.less
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6f7676a

Please sign in to comment.