fix: preserve parentheses around "or" in @media with type#4406
Open
veeceey wants to merge 1 commit intoevanw:mainfrom
Open
fix: preserve parentheses around "or" in @media with type#4406veeceey wants to merge 1 commit intoevanw:mainfrom
veeceey wants to merge 1 commit intoevanw:mainfrom
Conversation
The CSS minifier was dropping grouping parentheses around "or" expressions when they appeared after a media type + "and", producing invalid CSS. For example: @media screen and ((min-width: 10px) or (min-height: 10px)) was being minified to: @media screen and (min-width:10px)or (min-height:10px) This is invalid because CSS does not allow mixing "and" and "or" at the same nesting level. The spec requires the "or" group to be wrapped in parentheses as a <media-in-parens> production. The fix passes mqNeedsParens when printing the condition from an MQType node if the condition is an "or" binary, ensuring the outer parentheses are preserved. Fixes evanw#4395
Author
Test ResultsAll tests pass: Manual verification: /* Input */
@media screen and ((min-width: 10px) or (min-height: 10px)) { .test { color: blue } }
/* --minify output (before fix) */
@media screen and (min-width:10px)or (min-height:10px){.test{color:#00f}}
/* --minify output (after fix) */
@media screen and ((min-width:10px)or (min-height:10px)){.test{color:#00f}}Also verified no regression for regular "and" chains: /* Input */
@media screen and (min-width: 10px) and (min-height: 10px) { .test { color: blue } }
/* --minify (no extra parens) */
@media screen and (min-width:10px)and (min-height:10px){.test{color:#00f}} |
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.
The CSS minifier was dropping necessary grouping parentheses around "or" expressions when they appeared after a media type with "and". For example:
Per the CSS spec,
<media-condition-without-or>only allows<media-in-parens> [and <media-in-parens>]*, so an "or" group must be wrapped in parentheses. The printer was passingflags=0when printing the condition fromMQType, soMQBinary{Op: Or}didn't get its outer parens. The fix passesmqNeedsParenswhen the condition is an "or" binary.Verified that regular "and" chains after media types still produce minimal output without extra wrapping.
Tests pass:
Fixes #4395