Skip to content

Commit eba67de

Browse files
committed
Merge branch 'property-interp-fix-2' of https://github.com/seven-phases-max/less.js
Conflicts: lib/less/parser.js
2 parents 4923696 + bca1f99 commit eba67de

File tree

4 files changed

+53
-19
lines changed

4 files changed

+53
-19
lines changed

lib/less/parser.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,8 +1500,9 @@ less.Parser = function Parser(env) {
15001500
important = this.important();
15011501

15021502
// a name returned by this.ruleProperty() is always an array of the form:
1503-
// ["", "string-1", ..., "string-n", ""] or ["", "string-1", ..., "string-n", "+"]
1504-
merge = name.pop && (name.pop() === "+");
1503+
// [string-1, ..., string-n, ""] or [string-1, ..., string-n, "+"]
1504+
// where each item is a tree.Keyword or tree.Variable
1505+
merge = name.pop && (name.pop().value === "+");
15051506

15061507
if (value && this.end()) {
15071508
return new (tree.Rule)(name, value, important, merge, memo, env.currentFileInfo);
@@ -1929,7 +1930,7 @@ less.Parser = function Parser(env) {
19291930
}
19301931
},
19311932
ruleProperty: function () {
1932-
var c = current, name = [], index = [], length = 0;
1933+
var c = current, name = [], index = [], length = 0, s, k;
19331934

19341935
function match(re) {
19351936
var a = re.exec(c);
@@ -1945,13 +1946,18 @@ less.Parser = function Parser(env) {
19451946
while (match(/^((?:[\w-]+)|(?:@\{[\w-]+\}))/)); // !
19461947
if ((name.length > 1) && match(/^\s*(\+?)\s*:/)) {
19471948
// at last, we have the complete match now. move forward,
1948-
// convert @{var}s to tree.Variable(s) and return:
1949+
// convert name particles to tree objects and return:
19491950
skipWhitespace(length);
1950-
for (var k=0; k < name.length; k++) {
1951-
if (name[k].charAt(0) === '@') {
1952-
name[k] = new tree.Variable('@' + name[k].slice(2, -1),
1951+
if (name[0] === '') {
1952+
name.shift();
1953+
index.shift();
1954+
}
1955+
for (k = 0; k < name.length; k++) {
1956+
s = name[k];
1957+
name[k] = (s.charAt(0) !== '@')
1958+
? new(tree.Keyword)(s)
1959+
: new(tree.Variable)('@' + s.slice(2, -1),
19531960
index[k], env.currentFileInfo);
1954-
}
19551961
}
19561962
return name;
19571963
}

lib/less/tree/rule.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ tree.Rule.prototype = {
3030
},
3131
toCSS: tree.toCSS,
3232
eval: function (env) {
33-
var strictMathBypass = false;
34-
var name = this.name.map ?
35-
this.name.map( function(v) {
36-
return v.eval ? v.eval(env).value : v;
37-
}).join('') : this.name;
33+
var strictMathBypass = false, name = this.name;
34+
if (typeof name !== "string") {
35+
// expand 'primitive' name directly to get
36+
// things faster (~10% for benchmark.less):
37+
name = (name.length === 1)
38+
&& (name[0] instanceof tree.Keyword)
39+
? name[0].value : evalName(env, name);
40+
}
3841
if (name === "font" && !env.strictMath) {
3942
strictMathBypass = true;
4043
env.strictMath = true;
@@ -47,9 +50,7 @@ tree.Rule.prototype = {
4750
this.index, this.currentFileInfo, this.inline);
4851
}
4952
catch(e) {
50-
if (e.index === undefined) {
51-
e.index = this.index;
52-
}
53+
e.index = e.index || this.index;
5354
throw e;
5455
}
5556
finally {
@@ -67,4 +68,13 @@ tree.Rule.prototype = {
6768
}
6869
};
6970

71+
function evalName(env, name) {
72+
var value = "", i, n = name.length,
73+
output = {add: function (s) {value += s;}};
74+
for (i = 0; i < n; i++) {
75+
name[i].eval(env).genCSS(env, output);
76+
}
77+
return value;
78+
}
79+
7080
})(require('../tree'));

test/css/property-name-interp.css

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
test {
1+
pi-test {
22
border: 0;
33
ufo-width: 50%;
44
*-z-border: 1px dashed blue;
@@ -8,7 +8,13 @@ test {
88
border-top-red-radius-: 3pt;
99
global-local-mixer-property: strong;
1010
}
11-
test-merge {
11+
pi-test-merge {
1212
pre-property-ish: high, middle, low, base;
1313
pre-property-ish+: nice try dude;
1414
}
15+
pi-indirect-vars {
16+
auto: auto;
17+
}
18+
pi-complex-values {
19+
3px rgba(255, 255, 0, 0.5), 3.141592653589793 /* foo */3px rgba(255, 255, 0, 0.5), 3.141592653589793 /* foo */: none;
20+
}

test/less/property-name-interp.less

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
test {
2+
pi-test {
33
@prefix: ufo-;
44
@a: border;
55
@bb: top;
@@ -39,3 +39,15 @@ test {
3939
pre-property-ish@{subterfuge}: nice try dude;
4040
}
4141
}
42+
43+
pi-indirect-vars {
44+
@{p}: @p;
45+
@p: @@a;
46+
@a: b;
47+
@b: auto;
48+
}
49+
50+
pi-complex-values {
51+
@{p}@{p}: none;
52+
@p: (1 + 2px) fadeout(#ff0, 50%), pi() /* foo */;
53+
}

0 commit comments

Comments
 (0)