Skip to content

Commit 8c6b6d0

Browse files
committed
Merge branch 'selector-match-fixes' of https://github.com/seven-phases-max/less.js
2 parents 7869d46 + a1c97f3 commit 8c6b6d0

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

lib/less/tree/ruleset.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ tree.Ruleset.prototype = {
170170
if (rule !== self) {
171171
for (var j = 0; j < rule.selectors.length; j++) {
172172
if (match = selector.match(rule.selectors[j])) {
173-
if (selector.elements.length > rule.selectors[j].elements.length) {
173+
if (selector.elements.length > match) {
174174
Array.prototype.push.apply(rules, rule.find(
175-
new(tree.Selector)(selector.elements.slice(1)), self));
175+
new(tree.Selector)(selector.elements.slice(match)), self));
176176
} else {
177177
rules.push(rule);
178178
}

lib/less/tree/selector.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ tree.Selector.prototype = {
3535
max = Math.min(len, olen);
3636

3737
if (olen === 0 || len < olen) {
38-
return false;
38+
return 0;
3939
} else {
4040
for (i = 0; i < max; i++) {
4141
if (elements[i].value !== oelements[i].value) {
42-
return false;
42+
return 0;
4343
}
4444
}
4545
}
46-
return true;
46+
return max; // return number of matched selectors
4747
},
4848
eval: function (env) {
4949
var evaldCondition = this.condition && this.condition.eval(env);

test/css/mixins.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,31 @@
6464
.amp.support {
6565
color: orange;
6666
}
67+
.amp.support .higher {
68+
top: 0px;
69+
}
70+
.amp.support.deeper {
71+
height: auto;
72+
}
6773
.extended {
6874
width: 100%;
6975
border: 1px;
7076
background: none;
7177
color: orange;
78+
top: 0px;
79+
height: auto;
80+
}
81+
.extended .higher {
82+
top: 0px;
83+
}
84+
.extended.deeper {
85+
height: auto;
86+
}
87+
.do .re .mi .fa .sol .la .si {
88+
color: cyan;
89+
}
90+
.mutli-selector-parents {
91+
color: cyan;
7292
}
7393
.foo .bar {
7494
width: 100%;

test/less/mixins.less

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,30 @@
6161
.amp {
6262
&.support {
6363
color: orange;
64+
.higher {
65+
top: 0px;
66+
}
67+
&.deeper {
68+
height: auto;
69+
}
6470
}
6571
}
6672
.extended {
6773
.bo;
6874
.jo.ki;
6975
.amp.support;
76+
.amp.support.higher;
77+
.amp.support.deeper;
78+
}
79+
.do .re .mi .fa {
80+
.sol .la {
81+
.si {
82+
color: cyan;
83+
}
84+
}
85+
}
86+
.mutli-selector-parents {
87+
.do.re.mi.fa.sol.la.si;
7088
}
7189
.foo .bar {
7290
.bar;

0 commit comments

Comments
 (0)