Fix dropping @media rules with nested not conditions - #498
Open
dyk1454683243-sudo wants to merge 1 commit into
Open
dyk1454683243-sudo wants to merge 1 commit into
dyk1454683243-sudo wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Media rules with Media Queries Level 4 nested
notconditions are silently dropped:CSSO currently minifies this to empty CSS and emits no warning.
Classic MQ3 forms such as
@media not screenalready work.Root cause
css-tree 2.x cannot parse MQ4 nested conditions (
and (not ...),(not (color)), and similar). The prelude becomes aRawnode.Rawhas nochildrenlist, sohasNoChildren(prelude)is always true andcleanAtruleremoves the entire at-rule.Fix
Treat a non-empty
Rawprelude as present for@charset/@media/@supports/@keyframes. Empty@mediarules 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.csscovering:(max-width: 701px) and (not (any-pointer: fine)))(not (color))notnot screen(already parsed)Fixes #476
Related: #464 (range syntax) and #483 (
calc()in features) fail for the same Raw-prelude reason.