10000 extends recognise attributes. Fixes #1295 · browserstack/less.js@4997ce9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4997ce9

Browse files
committed
extends recognise attributes. Fixes less#1295
1 parent 747cac4 commit 4997ce9

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

lib/less/extend-visitor.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@
233233
//
234234
var haystackSelectorIndex, hackstackSelector, hackstackElementIndex, haystackElement,
235235
targetCombinator, i,
236+
extendVisitor = this,
236237
needleElements = extend.selector.elements,
237238
potentialMatches = [], potentialMatch, matches = [];
238239

@@ -261,7 +262,7 @@
261262
}
262263

263264
// if we don't match, null our match to indicate failure
264-
if (needleElements[potentialMatch.matched].value !== haystackElement.value ||
265+
if (!extendVisitor.isElementValuesEqual(needleElements[potentialMatch.matched].value, haystackElement.value) ||
265266
(potentialMatch.matched > 0 && needleElements[potentialMatch.matched].combinator.value !== targetCombinator)) {
266267
potentialMatch = null;
267268
} else {
@@ -294,6 +295,26 @@
294295
}
295296
return matches;
296297
},
298+
isElementValuesEqual: function(elementValue1, elementValue2) {
299+
if (typeof elementValue1 === "string" || typeof elementValue2 === "string") {
300+
return elementValue1 === elementValue2;
301+
}
302+
if (elementValue1 instanceof tree.Attribute) {
303+
if (elementValue1.op !== elementValue2.op || elementValue1.key !== elementValue2.key) {
304+
return false;
305+
}
306+
if (!elementValue1.value || !elementValue2.value) {
307+
if (elementValue1.value || elementValue2.value) {
308+
return false;
309+
}
310+
return true;
311+
}
312+
elementValue1 = elementValue1.value.value || elementValue1.value;
313+
elementValue2 = elementValue2.value.value || elementValue2.value;
314+
return elementValue1 === elementValue2;
315+
}
316+
return false;
317+
},
297318
extendSelector:function (matches, selectorPath, replacementSelector) {
298319

299320
//for a set of matches, replace each match with the replacement selector

test/css/extend-selector.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,15 @@ div.ext7,
5858
.c.rep_ace + .rep_ace .c {
5959
prop: copy-paste-replace;
6060
}
61+
.attributes [data="test"],
62+
.attributes .attributes .attribute-test {
63+
extend: attributes;
64+
}
65+
.attributes [data],
66+
.attributes .attributes .attribute-test2 {
67+
extend: attributes2;
68+
}
69+
.attributes [data="test3"],
70+
.attributes .attributes .attribute-test {
71+
extend: attributes2;
72+
}

test/less/extend-selector.less

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,25 @@ div.ext5,
6060
}
6161
}
6262
.rep_ace:extend(.replace all) {}
63+
64+
.attributes {
65+
[data="test"] {
66+
extend: attributes;
67+
}
68+
.attribute-test {
69+
&:extend([data="test"] all);
70+
}
71+
[data] {
72+
extend: attributes2;
73+
}
74+
.attribute-test2 {
75+
&:extend([data] all); //you could argue it should match [data="test"]... not for now though...
76+
}
77+
@attr-data: "test3";
78+
[data=@{attr-data}] {
79+
extend: attributes2;
80+
}
81+
.attribute-test {
82+
&:extend([data="test3"] all);
83+
}
84+
}

0 commit comments

Comments
 (0)
0