Misleading warning: "'empty' not recognized as a valid pseudo-class" on `::part(foo):not(:empty)`

Author: johannespfrang-h-dCreated Sep 21, 2026Updated Sep 21, 2026

When a pseudo-class that lightningcss knows about is not allowed in a given position (a pseudo-class chained after a pseudo-element, directly or inside :not()), the warning is:

'empty' is not recognized as a valid pseudo-class. Did you mean '::empty' (pseudo-element) or is this a typo?

:empty is a well-known pseudo-class; the message claims it is unrecognized, which is not the case — the point is that it is not allowed in that position. The rule is kept in the output (not dropped), so this is a diagnostic-quality bug, not a parsing bug, but the existence of the warning breaks our Turbopack build, which errors out on lightningcss warnings.

Reproduction (lightningcss 1.33.0; same on every release tested 1.29.3–1.33.0)

javascript
import { transform } from "lightningcss";
const r = await transform({
  filename: "t.css",
  code: Buffer.from("a::part(foo):not(:empty) { color: red; }"),
});
console.log(r.warnings);
// → [ { message: "'empty' is not recognized as a valid pseudo-class. Did you mean '::empty' (pseudo-element) or is this a typo?" } ]

The same message class appears for other tree-structural pseudo-classes in the same position, e.g. a::part(foo):not(:first-child) { … } → 'first-child' is not recognized …, and inside nested selectors, e.g. a:has(> ::part(foo):not(:empty)) { … }.

Context

  • Distinct from #1292: that one is the hard error Invalid pseudo class after pseudo element, only user action pseudo classes (e.g. :hover, :active) are allowed for ::picker():not(:popover-open) (rule dropped under error recovery). This one is the UnsupportedPseudoClass warning path (rule kept).
  • In browsers (verified Chromium 153/154, WebKit 26.6) such selectors parse but match nothing — only user-action pseudo-classes apply after ::part(). So keeping the rule is the right behavior; only the message is wrong. Suggested wording along the lines of: :empty is not allowed after ::part() (only user action pseudo-classes such as :hover, :active, :focus may follow a pseudo-element).
  • Mechanism (for the fix): in the selectors crate, the AFTER_PART state survives into the argument of :not(), which gates out recognition of tree-structural pseudo-classes; those names then fall into the main crate’s unknown-name fallback, which emits UnsupportedPseudoClass.

Source: parcel-bundler/lightningcss