Repository navigation
Keep declarations after nested rules inside at-rules - #180
Open
wahidrizka wants to merge 1 commit into
Open
wahidrizka wants to merge 1 commit into
wahidrizka wants to merge 1 commit into
Conversation
Inside a bubbled at-rule, all declarations were moved into one rule
before the nested rules, so `.a { @media x { color: red; & { color:
blue } color: green } }` made the element blue, while Sass and native
CSS nesting keep the order and make it green. Outside at-rules,
declarations after a nested rule already get their own rule (postcss#92), so
do the same inside.
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.
Outside at-rules, declarations after a nested rule keep their place (#92), but inside a bubbled at-rule they are all moved into one rule before the nested rules:
atruleChilds()collected every declaration of the at-rule into one clone of the parent rule and prepended it. Now it starts a new clone after each nested rule and puts each one where its declarations were, likeRule()does outside at-rules. This covers@media,@supports,@layer,@containerand@at-root (without: media). Declarations around a nested at-rule stay together, as in Sass, and unwrapped at-rules like@font-facedo not change.To check it, I compared main (9.0.0) and this branch with Sass on 4,000 distinct generated nested rules. 226 more now match Sass and none stopped matching; the 56 that had the same rules in another order are among them. Of the 293 that still differ, 56 changed: 54 are closer to Sass, and in the other 2 only the known
:is(&)selectors differ. In Chrome 154, the output now gives the same color as native nesting for@media,@supportsand a:where(.dark) &rule, where main differed in all three. The only changed output without a Sass reference is@at-rootwithout a selector, which Sass rejects when it has declarations; it now keeps their order too.The new test fails on main.
bnt --coverage 100,oxlintandoxfmt --checkpass.