Skip to content

Commit eb19ae4

Browse files
committed
Fix bug with css guards. Fixes #1750. Fixes #1613. Fixes #1813
1 parent eba67de commit eb19ae4

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

lib/less/tree/mixin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ tree.mixin.Call.prototype = {
5959
}
6060
if (conditionResult[0] || conditionResult[1]) {
6161
if (conditionResult[0] != conditionResult[1]) {
62-
candidate.group = conditionResult[1]
63-
? defTrue : defFalse;
62+
candidate.group = conditionResult[1] ?
63+
defTrue : defFalse;
6464
}
6565

6666
candidates.push(candidate);

lib/less/tree/ruleset.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ tree.Ruleset.prototype = {
144144
},
145145
matchCondition: function (args, env) {
146146
var lastSelector = this.selectors[this.selectors.length-1];
147+
if (!lastSelector.evaldCondition) {
148+
return false;
149+
}
147150
if (lastSelector.condition &&
148151
!lastSelector.condition.eval(
149152
new(tree.evalEnv)(env,

lib/less/tree/selector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ tree.Selector.prototype = {
2525
},
2626
createDerived: function(elements, extendList, evaldCondition) {
2727
evaldCondition = (evaldCondition != null) ? evaldCondition : this.evaldCondition;
28-
var newSelector = new(tree.Selector)(elements, extendList || this.extendList, this.condition, this.index, this.currentFileInfo, this.isReferenced);
28+
var newSelector = new(tree.Selector)(elements, extendList || this.extendList, null, this.index, this.currentFileInfo, this.isReferenced);
2929
newSelector.evaldCondition = evaldCondition;
3030
return newSelector;
3131
},

test/css/css-guards.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
color: green;
33
}
44
.see-the {
5-
color: orange;
5+
color: green;
66
}
77
.hide-the {
88
color: green;
@@ -16,3 +16,6 @@
1616
.inheritance:hover {
1717
color: pink;
1818
}
19+
.clsWithGuard {
20+
dispaly: none;
21+
}

test/less/css-guards.less

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@a: #ddd;
99

1010
.see-the {
11-
@a: #444; // this mirrors what mixins do - they evaluate guards at the point of execution
11+
@a: #444; // this mirrors what mixins do - they evaluate the guards at the point of definition
1212
.light();
1313
.dark();
1414
}
@@ -61,4 +61,13 @@
6161
.hideme {
6262
color: red;
6363
}
64-
}
64+
}
65+
66+
.mixin-with-guard-inside(@colWidth) {
67+
// selector with guard (applies also to & when() ...)
68+
.clsWithGuard when (@colWidth <= 0) {
69+
dispaly: none;
70+
}
71+
}
72+
73+
.mixin-with-guard-inside(0px);

0 commit comments

Comments
 (0)