Skip to content

Commit 15d662a

Browse files
committed
Fix element to selector list conversion, passing all tests!
1 parent c383326 commit 15d662a

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

lib/less/tree/ruleset.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Ruleset.prototype.eval = function (context) {
5454
var removeSelector = false;
5555
for (var j = 0; j < selector.elements.length; j++) {
5656
var el = selector.elements[j];
57+
// If selector elements were variables, re-parse to see if they are actually selectors
5758
if (el.isVariable && typeof el.value.value === 'string') {
5859
this.parse.parseNode(
5960
el.value.value,
@@ -64,25 +65,28 @@ Ruleset.prototype.eval = function (context) {
6465
el.isVariable = false;
6566
if (result) {
6667
result = utils.flattenArray(result);
67-
that.selectors = that.selectors.slice(0, i + 1)
68-
.concat(result, that.selectors.slice(i + 1));
69-
selCnt += result.length;
70-
removeSelector = true;
68+
// If the parsed element matches itself, it's still an element
69+
if (result.length !== 1 || el.value.value !== result[0].elements[0].value) {
70+
that.selectors = that.selectors.slice(0, i + 1)
71+
.concat(result, that.selectors.slice(i + 1));
72+
selCnt += result.length;
73+
removeSelector = true;
74+
}
7175
}
7276
});
7377
}
74-
// if (el.isVariable && selector._fileInfo.filename.indexOf('parse-') > -1) {
75-
// console.log(el);
76-
// }
7778
}
7879
if (removeSelector) {
7980
selCnt -= 1;
8081
this.selectors.splice(i, 1);
82+
i -= 1;
8183
continue;
8284
}
83-
selectors[i] = selector;
84-
if (selector.evaldCondition) {
85-
hasOnePassingSelector = true;
85+
else {
86+
selectors[i] = selector;
87+
if (selector.evaldCondition) {
88+
hasOnePassingSelector = true;
89+
}
8690
}
8791
}
8892
defaultFunc.reset();

test/css/parse-interpolation.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
input[type=text]:focus,
2-
input[type=email]:focus,
3-
input[type=password]:focus,
1+
input[type=text]:focus,
2+
input[type=email]:focus,
3+
input[type=password]:focus,
44
textarea:focus {
55
foo: bar;
6-
}
6+
}

0 commit comments

Comments
 (0)