Skip to content

Commit 2805827

Browse files
committed
match multiple classes as the extend target
1 parent 1970be7 commit 2805827

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

lib/less/extend-visitor.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
.slice(0, match.index)
113113
.concat([firstElement])
114114
.concat(selfSelector.elements.slice(1))
115-
.concat(selector.elements.slice(match.index + 1))
115+
.concat(selector.elements.slice(match.index + match.length))
116116
));
117117
});
118118
}
@@ -121,11 +121,17 @@
121121
rulesetNode.selectors = rulesetNode.selectors.concat(selectorsToAdd);
122122
},
123123
findMatch: function (extend, selector) {
124-
var j = 0, element;
125-
for(j = 0; j < selector.elements.length; j++) {
126-
element = selector.elements[j];
127-
if (extend.selector.elements[0].value === element.value) {
128-
return {index: j, initialCombinator: element.combinator};
124+
var i, j, element, hasMatch;
125+
for(i = 0; i <= (selector.elements.length - extend.selector.elements.length); i++) {
126+
hasMatch = true;
127+
for(j = 0; j < extend.selector.elements.length; j++) {
128+
if (extend.selector.elements[j].value !== selector.elements[i+j].value) {
129+
hasMatch = false;
130+
break;
131+
}
132+
}
133+
if (hasMatch) {
134+
return {index: i, initialCombinator: selector.elements[i].combinator, length: extend.selector.elements.length};
129135
}
130136
}
131137
return null;

lib/less/parser.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -795,9 +795,9 @@ less.Parser = function Parser(env) {
795795
while (true) {
796796
option = $(/^(any|deep|all)(?=\s*\))/);
797797
if (option) { break; }
798-
e = $(/^[#.](?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+/);
798+
e = $(this.element);
799799
if (!e) { break; }
800-
elements.push(new(tree.Element)(null, e, i));
800+
elements.push(e);
801801
}
802802

803803
expect(/^\)/);
@@ -1052,8 +1052,7 @@ less.Parser = function Parser(env) {
10521052

10531053
if (! e) {
10541054
if ($('(')) {
1055-
if ((v = (//$(this.entities.variableCurly) ||
1056-
$(this.selector))) &&
1055+
if ((v = ($(this.selector))) &&
10571056
$(')')) {
10581057
e = new(tree.Paren)(v);
10591058
}

test/css/extend.css

+7
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,10 @@ div.ext7,
3333
.ext6 > .ext7 {
3434
width: 100px;
3535
}
36+
.ext8.ext9,
37+
.foo {
38+
result: pick-up-both;
39+
}
40+
.ext8.nomatch {
41+
result: none;
42+
}

test/less/extend.less

+9
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,12 @@ div.ext5,
3636
.ext7 {
3737
&:extend(.ext5 all);
3838
}
39+
40+
.ext8.ext9 {
41+
result: pick-up-both;
42+
}
43+
.ext8.nomatch {
44+
result: none;
45+
}
46+
47+
.foo:extend(.ext8.ext9 all) {}

0 commit comments

Comments
 (0)