Skip to content

Commit ac3f1aa

Browse files
committed
Improve: Enhance feature comparison sorting to handle numeric values correctly
1 parent 4d0227d commit ac3f1aa

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

packages/core/src/utils/compare-rule-priority.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function calcRulePriority(rule: SyntaxRule): RulePriority {
8686
}
8787
if (rule.atRules?.media) extractFeatures(rule.atRules.media)
8888
if (rule.atRules?.container) extractFeatures(rule.atRules.container)
89-
features.sort(([a], [b]) => a.localeCompare(b))
89+
features.sort(([a], [b]) => a.localeCompare(b, undefined, { numeric: true }))
9090
const selector = extractSelectorPriority(rule.selectorNodes ?? [])
9191
return {
9292
features,
@@ -106,7 +106,7 @@ function compareFeatureTuples(
106106
if (!bb) return 1
107107
const [nameA, minA, maxA] = aa
108108
const [nameB, minB, maxB] = bb
109-
const nameCmp = nameA.localeCompare(nameB)
109+
const nameCmp = nameA.localeCompare(nameB, undefined, { numeric: true })
110110
if (nameCmp !== 0) return nameCmp
111111
const rangeA = maxA - minA
112112
const rangeB = maxB - minB
@@ -149,5 +149,5 @@ export default function compareRulePriority(a: SyntaxRule, b: SyntaxRule): numbe
149149
if (typeCmp !== 0) return typeCmp
150150

151151
// 4. fallback: name
152-
return a.name.localeCompare(b.name)
152+
return a.name.localeCompare(b.name, undefined, { numeric: true })
153153
}

0 commit comments

Comments
 (0)