parcel-bundler / parcel-bundler/lightningcss
Incorrect compilation of nested CSS appends type selector after subclass selectors
@yisibl is already working on this.
Since Sep 4, 2026.
- Dominant language
- Rust
- Stars
- 7.7k
- Forks
- 302
- PR merge metrics
- No merged PRs in 30d
Description
Input:
.foo {
> &a,
+ &b {
color: red;
}
}
Output from Lightning CSS (playground link):
.foo > .fooa, .foo + .foob {
color: red;
}
Expected output:
.foo > a.foo, .foo + b.foo {
color: red;
}
The problem is that the type selector must be prepended to avoid creating an invalid compound selector, but Lightning CSS appends it instead. Other similar problem cases to .foo are #foo, :foo, and even foo.
I recently fixed a similar issue in esbuild and Lightning CSS has the same bug, so I figured I'd report it here too. FWIW my fix was a hack: I just moved the & token after the type selector when converting the nested selector to a token stream so that the later substitution of & ends up in the right place (so &a is basically changed to a& internally). I didn't do any big changes to token substitution itself such as re-parsing the token stream.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.