parcel-bundler / parcel-bundler/lightningcss

Incorrect compilation of nested CSS appends type selector after subclass selectors

Open
#489 3 comments 0 reactions 1 assignee View on GitHub

@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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.