Skip to content

Fix dropping @media rules with nested not conditions - #498

Open
dyk1454683243-sudo wants to merge 1 commit into
css:masterfrom
dyk1454683243-sudo:cursor/fix-media-not-dropped-1e6b
Open

dyk1454683243-sudo wants to merge 1 commit into
css:masterfrom
dyk1454683243-sudo:cursor/fix-media-not-dropped-1e6b

Conversation

@dyk1454683243-sudo

Copy link
Copy Markdown

Problem

Media rules with Media Queries Level 4 nested not conditions are silently dropped:

@media (max-width: 701px) and (not (any-pointer: fine)) {
  .a { color: red; }
}

CSSO currently minifies this to empty CSS and emits no warning.

Classic MQ3 forms such as @media not screen already work.

Root cause

css-tree 2.x cannot parse MQ4 nested conditions (and (not ...), (not (color)), and similar). The prelude becomes a Raw node. Raw has no children list, so hasNoChildren(prelude) is always true and cleanAtrule removes the entire at-rule.

Fix

Treat a non-empty Raw prelude as present for @charset / @media / @supports / @keyframes. Empty @media rules and empty blocks are still dropped. Parsed preludes are unchanged.

The unparsed query text is preserved as-is (it cannot be safely recompressed). Adjacent identical queries still merge.

Tests

Added fixtures/compress/atrules/media-not-nested.css covering:

Fixes #476

Related: #464 (range syntax) and #483 (calc() in features) fail for the same Raw-prelude reason.

css-tree 2.x cannot parse Media Queries Level 4 nested conditions such as
`and (not ...)`, so the prelude becomes a Raw node. Raw has no children
list, and cleanAtrule treated that as an empty prelude and silently
removed the whole at-rule.

Treat a non-empty Raw prelude as present so valid `not` / nested media
conditions are preserved. Empty @media blocks are still dropped.

Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
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.

Silently removes @media blocks containing "and (not ...)"

2 participants