Skip to content

Commit 6c1f2f3

Browse files
committed
fix: issue less#4313 selector with comma
* Fix an issue where selector with comma would not expand correctly.
1 parent 55f7448 commit 6c1f2f3

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

packages/less/src/less/tree/ruleset.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,12 +748,32 @@ Ruleset.prototype = Object.assign(new Node(), {
748748
const replacementSelector = createSelector(createParenthesis(nestedPaths[k], el), el);
749749
addAllReplacementsIntoPath(newSelectors, [replacementSelector], el, inSelector, replacedNewSelectors);
750750
}
751+
newSelectors = replacedNewSelectors;
752+
currentElements = [];
753+
} else if (el instanceof Selector) {
754+
const nestedSelector = el;
755+
756+
// merge the current list of non parent selector elements
757+
// on to the current list of selectors to add
758+
mergeElementsOnToSelectors(currentElements, newSelectors);
759+
760+
const nestedPaths = [];
761+
let replaced;
762+
let replacedNewSelectors = [];
763+
replaced = replaceParentSelector(nestedPaths, context, nestedSelector);
764+
hadParentSelector = hadParentSelector || replaced;
765+
766+
for (k = 0; k < nestedPaths.length; k++) {
767+
const replacementSelector = nestedPaths[k][0];
768+
addAllReplacementsIntoPath(newSelectors, [replacementSelector], el.elements[0], inSelector, replacedNewSelectors);
769+
replacedNewSelectors = [replacedNewSelectors[0]]
770+
}
771+
751772
newSelectors = replacedNewSelectors;
752773
currentElements = [];
753774
} else {
754775
currentElements.push(el);
755776
}
756-
757777
} else {
758778
hadParentSelector = true;
759779
// the new list of selectors to add

packages/test-data/css/_main/selectors.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,15 @@ a:is(.b, :is(.c)) {
189189
a:is(.b, :is(.c), :has(div)) {
190190
color: red;
191191
}
192+
.multiple-not-by-comma:not(.multiple-not-by-comma--a, .multiple-not-by-comma--b):not(.multiple-not-by-comma--c, .multiple-not-by-comma--d):hover {
193+
background-color: green;
194+
}
195+
.multiple-not-by-comma2 {
196+
color: red;
197+
}
198+
.multiple-not-by-comma2:not(.multiple-not-by-comma2--a, .multiple-not-by-comma2--b):not(.multiple-not-by-comma2--c):hover {
199+
background-color: blue;
200+
}
201+
.multiple-not:not(.multiple-not--a):not(.multiple-not--b):hover {
202+
background-color: yellow;
203+
}

packages/test-data/less/_main/selectors.less

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,23 @@ a:is(.b, :is(.c)) {
208208
a:is(.b, :is(.c), :has(div)) {
209209
color: red;
210210
}
211+
212+
.multiple-not-by-comma {
213+
&:not(&--a, &--b):not(&--c, &--d):hover {
214+
background-color: green;
215+
}
216+
}
217+
218+
.multiple-not-by-comma2 {
219+
color: red;
220+
221+
&:not(&--a, &--b):not(&--c):hover {
222+
background-color: blue;
223+
}
224+
}
225+
226+
.multiple-not {
227+
&:not(&--a):not(&--b):hover {
228+
background-color: yellow;
229+
}
230+
}

0 commit comments

Comments
 (0)