Skip to content

Commit

Permalink
Change pseudo-selector sorting to take priority over shorthand sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
dddlr committed Oct 23, 2024
1 parent 60d50a5 commit 8b6edba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ describe('sort shorthand vs. longhand declarations', () => {

it('sorts a variety of different shorthand properties used together', () => {
const actual = transform(outdent`
@media all {
.f {
display: block;
Expand Down Expand Up @@ -314,9 +315,6 @@ describe('sort shorthand vs. longhand declarations', () => {
.c {
border-block-start: none;
}
.d:active {
border-block-start: none;
}
.j {
margin-bottom: 6px;
Expand All @@ -333,7 +331,11 @@ describe('sort shorthand vs. longhand declarations', () => {
}
.e:hover {
border-block-start-color: transparent;
}@media all {
}
.d:active {
border-block-start: none;
}
@media all {
.a {
all: unset;
}
Expand Down Expand Up @@ -471,13 +473,13 @@ describe('sort shorthand vs. longhand declarations', () => {
expect(actual).toMatchInlineSnapshot(`
"
._abcd1234 { border: none }
._abcd1234:hover { border: none }
._abcd1234:active { border: none }
._abcd1234 { border-top: 1px solid }
._abcd1234:hover { border-top: 1px solid }
._abcd1234:active { border-top: 1px solid }
._abcd1234 { border-top-color: red }
._abcd1234:hover { border: none }
._abcd1234:hover { border-top: 1px solid }
._abcd1234:hover { border-top-color: red }
._abcd1234:active { border: none }
._abcd1234:active { border-top: 1px solid }
._abcd1234:active { border-top-color: red }
@media (max-width: 150px) { ._abcd1234 { border: none } }
@media (max-width: 120px) {
Expand Down
12 changes: 8 additions & 4 deletions packages/css/src/plugins/sort-atomic-style-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ export const sortAtomicStyleSheet = (config: {
}
});

if (sortShorthandEnabled) {
sortShorthandDeclarations(catchAll);
sortShorthandDeclarations(rules);
sortShorthandDeclarations(atRules.map((atRule) => atRule.node));
}

// Pseudo-selector and at-rule sorting takes priority over shorthand
// property sorting.
sortPseudoSelectors(rules);
if (sortAtRulesEnabled) {
atRules.sort(sortAtRules);
Expand All @@ -101,10 +109,6 @@ export const sortAtomicStyleSheet = (config: {
}

root.nodes = [...catchAll, ...rules, ...atRules.map((atRule) => atRule.node)];

if (sortShorthandEnabled) {
sortShorthandDeclarations(root.nodes);
}
},
};
};
Expand Down

0 comments on commit 8b6edba

Please sign in to comment.