Skip to content

Remove at-rules left empty by @at-root escape - #183

Merged
ai merged 1 commit into
postcss:mainfrom
minilan677-netizen:fix/at-root-empty-at-rules
Dec 4, 2026
Merged

ai merged 1 commit into
postcss:mainfrom
minilan677-netizen:fix/at-root-empty-at-rules

Conversation

@minilan677-netizen

Copy link
Copy Markdown
Contributor

Fixes #182

When @at-root (without: …) escaped from an at-rule that had nothing else in it, the at-rule stayed in the output empty: @media x { a { @at-root (without: media) { b {} } } } gave @media x {} a b {}.

Root cause: unwrapRootRule() moves the content after the top escaped at-rule and then removes the @at-root node, but its parent at-rules can be empty at that point.

Fix: after removing the @at-root node, walk up its parents and remove every at-rule that is now empty. This only runs for (with: …)/(without: …), so a plain @at-root and at-rules that still have content (e.g. declarations after the @at-root) are unchanged.

Tests: added at-root removes at-rules left empty after escaping with four cases (without: media, with declarations left after it, nested @media/@supports, without: all). All four fail on main.

Checks: pnpm test (node:test with 100% line coverage, oxlint) passes, and oxfmt --check is clean.

@ai
ai merged commit a935b46 into postcss:main Dec 4, 2026
3 checks passed
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.

@at-root (without: …) leaves empty at-rules behind

2 participants