Skip to content

fix: preserve empty namespace boundaries in lossy selectors - #383

Open
Boulea7 wants to merge 1 commit into
postcss:mainfrom
Boulea7:ln-cx/fix-lossy-empty-namespace
Open

Boulea7 wants to merge 1 commit into
postcss:mainfrom
Boulea7:ln-cx/fix-lossy-empty-namespace

Conversation

@Boulea7

@Boulea7 Boulea7 commented Dec 2, 2026

Copy link
Copy Markdown

Lossy selector processing can remove a meaningful space before an empty namespace prefix. This changes which elements are matched after minification.

import parser from 'postcss-selector-parser';

parser().processSync('section |input', { lossless: false });
// Before: "section|input"
// After:  "section |input"

In an XML DOM fixture with the prefix section bound to urn:postcss-fixture:section, the original selector matched a no-namespace <input> inside the <section> element. The old output matched an unrelated <section:input> outside it. The fixed output matched the intended descendant again. This was verified independently with cssselect2 0.10.1.

Keep a separator before the bare prefix in lossy output, including after an explicit combinator, so the tokenizer can still distinguish the combinator and prefix on a second pass. The regression tests cover descendant tags, universal selectors, explicit child combinators, and comments.

On macOS, Node 22.23.5 and 26.13.1 each passed 1,161 unit tests and five property groups. Actual PostCSS minification output remained stable on repeated processing. Typecheck and formatting of the changed tests passed. Hosted platform checks remain pending.

Implemented and tested with OpenAI Codex (gpt-6.2-sol).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant