Repository navigation
Combine every & with each parent selector - #176
Conversation
A nested selector with more than one & got the same parent selector for
every &, so `.a, .b { & + & {} }` gave `.a + .a, .b + .b` and dropped
`.a + .b` and `.b + .a`. Sass and native CSS nesting match all four.
|
Seems like it is breaking changes. Let's combine all changes together.
Tell me more about it. And how CSS nesting is working in that case? |
|
.a, .b {
.x:not(&) { color: red }
}/* postcss-nested */
.x:not(.a), .x:not(.b) { color: red }/* Sass 1.105.1 */
.x:not(.a, .b) {
color: red;
}Native CSS nesting replaces In Chrome 154 with
|
|
yes, please prepare PR |
A nested selector with more than one
&gets the same parent selector for every&, so with a selector list as the parent some combinations are dropped:Native CSS nesting reads
&as:is(.a, .b), so it matches the same four. In Chrome 154, with.a,.b,.a,.bsiblings, the native rule and the Sass output style the last three, and the postcss-nested output styles none of them. The same happens with& ~ &,& &and three&.mergeSelectors()already loops over the parent selectors for the first&. Now, when a selector has more than one&at its top level, every&after the first one takes each parent selector in turn. Selectors with one&keep the old path, so their output does not change.To check it, I compared postcss-nested with Sass on generated nested rules that Sass accepts. On 2,537 rules whose selectors have two or three
&, 1,440 gave a different set of selectors on main and none do now. On 4,000 more general rules (2,967 of them accepted by Sass), 178 more now match Sass and none stopped matching.:not(&)with a selector list also differs from Sass (:not(.a) .x, :not(.b) .xinstead of:not(.a, .b) .x, which matches different elements). I left it out; I can send it separately if you want.The new test fails on main.
pnpm testpasses.