Skip to content

Commit e1255ec

Browse files
authored
Merge pull request #3220 from less/revert-3217-bugfix-1241
Revert "Fixes #1421 - re-parses variable-interpolated elements to selectors"
2 parents 468b532 + 85a716c commit e1255ec

File tree

10 files changed

+40
-179
lines changed

10 files changed

+40
-179
lines changed

lib/less/parser/parser.js

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ var Parser = function Parser(context, imports, fileInfo) {
810810
if (!e) {
811811
break;
812812
}
813-
elem = new(tree.Element)(c, e, false, elemIndex, fileInfo);
813+
elem = new(tree.Element)(c, e, elemIndex, fileInfo);
814814
if (elements) {
815815
elements.push(elem);
816816
} else {
@@ -1097,7 +1097,7 @@ var Parser = function Parser(context, imports, fileInfo) {
10971097
}
10981098
}
10991099

1100-
if (e) { return new(tree.Element)(c, e, e instanceof tree.Variable, index, fileInfo); }
1100+
if (e) { return new(tree.Element)(c, e, index, fileInfo); }
11011101
},
11021102

11031103
//
@@ -1177,30 +1177,6 @@ var Parser = function Parser(context, imports, fileInfo) {
11771177
if (elements) { return new(tree.Selector)(elements, allExtends, condition, index, fileInfo); }
11781178
if (allExtends) { error("Extend must be used to extend a selector, it cannot be used on its own"); }
11791179
},
1180-
selectors: function () {
1181-
var s, selectors;
1182-
while (true) {
1183-
s = this.selector();
1184-
if (!s) {
1185-
break;
1186-
}
1187-
if (selectors) {
1188-
selectors.push(s);
1189-
} else {
1190-
selectors = [ s ];
1191-
}
1192-
parserInput.commentStore.length = 0;
1193-
if (s.condition && selectors.length > 1) {
1194-
error("Guards are only currently allowed on a single selector.");
1195-
}
1196-
if (!parserInput.$char(',')) { break; }
1197-
if (s.condition) {
1198-
error("Guards are only currently allowed on a single selector.");
1199-
}
1200-
parserInput.commentStore.length = 0;
1201-
}
1202-
return selectors;
1203-
},
12041180
attribute: function () {
12051181
if (!parserInput.$char('[')) { return; }
12061182

@@ -1252,15 +1228,34 @@ var Parser = function Parser(context, imports, fileInfo) {
12521228
// div, .class, body > p {...}
12531229
//
12541230
ruleset: function () {
1255-
var selectors, rules, debugInfo;
1231+
var selectors, s, rules, debugInfo;
12561232

12571233
parserInput.save();
12581234

12591235
if (context.dumpLineNumbers) {
12601236
debugInfo = getDebugInfo(parserInput.i);
12611237
}
12621238

1263-
selectors = this.selectors();
1239+
while (true) {
1240+
s = this.selector();
1241+
if (!s) {
1242+
break;
1243+
}
1244+
if (selectors) {
1245+
selectors.push(s);
1246+
} else {
1247+
selectors = [ s ];
1248+
}
1249+
parserInput.commentStore.length = 0;
1250+
if (s.condition && selectors.length > 1) {
1251+
error("Guards are only currently allowed on a single selector.");
1252+
}
1253+
if (!parserInput.$char(',')) { break; }
1254+
if (s.condition) {
1255+
error("Guards are only currently allowed on a single selector.");
1256+
}
1257+
parserInput.commentStore.length = 0;
1258+
}
12641259

12651260
if (selectors && (rules = this.block())) {
12661261
parserInput.forget();

lib/less/tree/element.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var Node = require("./node"),
22
Paren = require("./paren"),
33
Combinator = require("./combinator");
44

5-
var Element = function (combinator, value, isVariable, index, currentFileInfo, visibilityInfo) {
5+
var Element = function (combinator, value, index, currentFileInfo, visibilityInfo) {
66
this.combinator = combinator instanceof Combinator ?
77
combinator : new Combinator(combinator);
88

@@ -13,7 +13,6 @@ var Element = function (combinator, value, isVariable, index, currentFileInfo, v
1313
} else {
1414
this.value = "";
1515
}
16-
this.isVariable = isVariable;
1716
this._index = index;
1817
this._fileInfo = currentFileInfo;
1918
this.copyVisibilityInfo(visibilityInfo);
@@ -31,14 +30,12 @@ Element.prototype.accept = function (visitor) {
3130
Element.prototype.eval = function (context) {
3231
return new Element(this.combinator,
3332
this.value.eval ? this.value.eval(context) : this.value,
34-
this.isVariable,
3533
this.getIndex(),
3634
this.fileInfo(), this.visibilityInfo());
3735
};
3836
Element.prototype.clone = function () {
3937
return new Element(this.combinator,
4038
this.value,
41-
this.isVariable,
4239
this.getIndex(),
4340
this.fileInfo(), this.visibilityInfo());
4441
};

lib/less/tree/mixin-definition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var Selector = require("./selector"),
88

99
var Definition = function (name, params, rules, condition, variadic, frames, visibilityInfo) {
1010
this.name = name;
11-
this.selectors = [new Selector([new Element(null, name, false, this._index, this._fileInfo)])];
11+
this.selectors = [new Selector([new Element(null, name, this._index, this._fileInfo)])];
1212
this.params = params;
1313
this.condition = condition;
1414
this.variadic = variadic;

lib/less/tree/ruleset.js

Lines changed: 12 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -41,72 +41,20 @@ Ruleset.prototype.accept = function (visitor) {
4141
}
4242
};
4343
Ruleset.prototype.eval = function (context) {
44-
var that = this, selectors, selCnt, selector, i, hasOnePassingSelector = false;
44+
var thisSelectors = this.selectors, selectors,
45+
selCnt, selector, i, hasOnePassingSelector = false;
4546

46-
if (this.selectors && (selCnt = this.selectors.length)) {
47+
if (thisSelectors && (selCnt = thisSelectors.length)) {
4748
selectors = new Array(selCnt);
4849
defaultFunc.error({
4950
type: "Syntax",
5051
message: "it is currently only allowed in parametric mixin guards,"
5152
});
5253
for (i = 0; i < selCnt; i++) {
53-
selector = this.selectors[i].eval(context);
54-
var removeSelector = false;
55-
for (var j = 0; j < selector.elements.length; j++) {
56-
var el = selector.elements[j];
57-
// If selector elements were variables, re-parse to see if they are actually selectors
58-
if (el.isVariable) {
59-
var selectorsToInsert;
60-
if (Array.isArray(el.value.value)) {
61-
// Convert var evaluated to list as list of selectors
62-
selectorsToInsert = new Array(el.value.value.length);
63-
el.value.value.forEach(function(val, k) {
64-
selectorsToInsert[k] = new Selector(
65-
[new Element(
66-
null,
67-
val.value,
68-
false,
69-
el.getIndex(),
70-
el.fileInfo()
71-
)]
72-
);
73-
})
74-
} else if (typeof el.value.value === 'string') {
75-
this.parse.parseNode(
76-
el.value.value,
77-
["selectors"],
78-
el.getIndex(),
79-
el.fileInfo(),
80-
function(err, result) {
81-
el.isVariable = false;
82-
if (result) {
83-
result = utils.flattenArray(result);
84-
// If the parsed element matches itself, it's still an element
85-
if (result.length !== 1 || el.value.value !== result[0].elements[0].value) {
86-
selectorsToInsert = result;
87-
}
88-
}
89-
});
90-
}
91-
if (selectorsToInsert) {
92-
this.selectors = this.selectors.slice(0, i + 1)
93-
.concat(selectorsToInsert, this.selectors.slice(i + 1));
94-
selCnt += selectorsToInsert.length;
95-
removeSelector = true;
96-
}
97-
}
98-
}
99-
if (removeSelector) {
100-
selCnt -= 1;
101-
this.selectors.splice(i, 1);
102-
i -= 1;
103-
continue;
104-
}
105-
else {
106-
selectors[i] = selector;
107-
if (selector.evaldCondition) {
108-
hasOnePassingSelector = true;
109-
}
54+
selector = thisSelectors[i].eval(context);
55+
selectors[i] = selector;
56+
if (selector.evaldCondition) {
57+
hasOnePassingSelector = true;
11058
}
11159
}
11260
defaultFunc.reset();
@@ -214,7 +162,7 @@ Ruleset.prototype.eval = function (context) {
214162
// for rulesets, check if it is a css guard and can be removed
215163
if (rule instanceof Ruleset && rule.selectors && rule.selectors.length === 1) {
216164
// check if it can be folded in (e.g. & where)
217-
if (rule.selectors[0] && rule.selectors[0].isJustParentSelector()) {
165+
if (rule.selectors[0].isJustParentSelector()) {
218166
rsRules.splice(i--, 1);
219167

220168
for (var j = 0; (subRule = rule.rules[j]); j++) {
@@ -563,13 +511,7 @@ Ruleset.prototype.joinSelector = function (paths, context, selector) {
563511
} else {
564512
var insideParent = new Array(elementsToPak.length);
565513
for (j = 0; j < elementsToPak.length; j++) {
566-
insideParent[j] = new Element(
567-
null,
568-
elementsToPak[j],
569-
originalElement.isVariable,
570-
originalElement._index,
571-
originalElement._fileInfo
572-
);
514+
insideParent[j] = new Element(null, elementsToPak[j], originalElement._index, originalElement._fileInfo);
573515
}
574516
replacementParen = new Paren(new Selector(insideParent));
575517
}
@@ -578,7 +520,7 @@ Ruleset.prototype.joinSelector = function (paths, context, selector) {
578520

579521
function createSelector(containedElement, originalElement) {
580522
var element, selector;
581-
element = new Element(null, containedElement, originalElement.isVariable, originalElement._index, originalElement._fileInfo);
523+
element = new Element(null, containedElement, originalElement._index, originalElement._fileInfo);
582524
selector = new Selector([element]);
583525
return selector;
584526
}
@@ -612,13 +554,7 @@ Ruleset.prototype.joinSelector = function (paths, context, selector) {
612554
combinator = parentEl.combinator;
613555
}
614556
// join the elements so far with the first part of the parent
615-
newJoinedSelector.elements.push(new Element(
616-
combinator,
617-
parentEl.value,
618-
replacedElement.isVariable,
619-
replacedElement._index,
620-
replacedElement._fileInfo
621-
));
557+
newJoinedSelector.elements.push(new Element(combinator, parentEl.value, replacedElement._index, replacedElement._fileInfo));
622558
newJoinedSelector.elements = newJoinedSelector.elements.concat(addPath[0].elements.slice(1));
623559
}
624560

@@ -752,7 +688,7 @@ Ruleset.prototype.joinSelector = function (paths, context, selector) {
752688
// the combinator used on el should now be applied to the next element instead so that
753689
// it is not lost
754690
if (sel.length > 0) {
755-
sel[0].elements.push(new Element(el.combinator, '', el.isVariable, el._index, el._fileInfo));
691+
sel[0].elements.push(new Element(el.combinator, '', el._index, el._fileInfo));
756692
}
757693
selectorsMultiplied.push(sel);
758694
}

lib/less/tree/selector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Selector.prototype.getElements = function(els) {
5454
return els;
5555
};
5656
Selector.prototype.createEmptySelectors = function() {
57-
var el = new Element('', '&', false, this._index, this._fileInfo),
57+
var el = new Element('', '&', this._index, this._fileInfo),
5858
sels = [new Selector([el], null, null, this._index, this._fileInfo)];
5959
sels[0].mediaEmpty = true;
6060
return sels;

lib/less/utils.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* jshint proto: true */
2-
var utils = {
2+
module.exports = {
33
getLocation: function(index, inputStream) {
44
var n = index + 1,
55
line = null,
@@ -65,21 +65,5 @@ var utils = {
6565
}
6666
}
6767
return obj1;
68-
},
69-
flattenArray: function(arr, result) {
70-
result = result || [];
71-
for (var i = 0, length = arr.length; i < length; i++) {
72-
var value = arr[i];
73-
if (Array.isArray(value)) {
74-
utils.flattenArray(value, result);
75-
} else {
76-
if (value !== undefined) {
77-
result.push(value);
78-
}
79-
}
80-
}
81-
return result;
8268
}
8369
};
84-
85-
module.exports = utils;

lib/less/visitors/extend-visitor.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@ ProcessExtendsVisitor.prototype = {
385385
firstElement = new tree.Element(
386386
match.initialCombinator,
387387
replacementSelector.elements[0].value,
388-
replacementSelector.elements[0].isVariable,
389388
replacementSelector.elements[0].getIndex(),
390389
replacementSelector.elements[0].fileInfo()
391390
);

test/css/parse-interpolation.css

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/less-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = function() {
1414
var oneTestOnly = process.argv[2],
1515
isFinished = false;
1616

17-
var isVerbose = process.env.npm_config_loglevel !== 'concise';
17+
var isVerbose = process.env.npm_config_loglevel === 'verbose';
1818

1919
var normalFolder = 'test/less';
2020
var bomFolder = 'test/less-bom';

test/less/parse-interpolation.less

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)