fix: avoid wrapping pseudo-element selectors in :is() during nesting compilation#1156
fix: avoid wrapping pseudo-element selectors in :is() during nesting compilation#1156donlion wants to merge 1 commit intoparcel-bundler:masterfrom
Conversation
…compilation When compiling nested selectors like `.parent &` where the parent selector contains a pseudo-element (e.g., `.element::after`), the code was incorrectly wrapping the parent in `:is()`, producing invalid CSS like `.parent :is(.element:after)`. The :is() pseudo-class cannot contain pseudo-elements per CSS specification. This fix adds a check to serialize pseudo-element selectors directly instead.
|
what happens if there are multiple selectors? .foo, .element::after {
.parent & {
color: red;
}
}doing this without |
|
Good point, I’ll see if I can come up with something. |
|
Essentially, the current CSS specification does not permit nesting |
|
We need to ensure that the CSS in this WPT test case, after being compiled by lightningcss, still displays entirely in green. |
Aha! That's news to me. What’s your thoughts? |
Summary
When compiling nested selectors like
.parent &where the parent selector contains a pseudo-element (e.g.,.element::after), the code was incorrectly wrapping the parent in:is(), producing invalid CSS.Input:
Before (incorrect):
After (correct):
Root Cause
The
is_simple()function returnsfalsefor selectors with pseudo-elements because they internally contain aCombinator::PseudoElementcomponent. This caused the nesting serialization to fall back to using:is(), which cannot contain pseudo-elements per CSS specification.Fix
Added a check in
serialize_nestingto detect when the parent selector contains a pseudo-element. In that case, we serialize the selector directly instead of wrapping it in:is().Related Issues
:is()wrapping of pseudo-elements + nested media query produces invalid CSS #975 to handle the.parent &case (where&is not at the start)Test Plan
cargo test)