Skip to content

Commit cc8c069

Browse files
Further improve natural sorting of classes (#13532)
* skip initial character we just saw Thanks Richard for noticing! Co-authored-by: Richard van Velzen <[email protected]> * prevent calling `charCodeAt()` if we already computed the value * update changelog --------- Co-authored-by: Richard van Velzen <[email protected]>
1 parent cd0c308 commit cc8c069

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
## Changed
1515

1616
- Use `rem` units for breakpoints by default instead of `px` ([#13469](https://github.com/tailwindlabs/tailwindcss/pull/13469))
17-
- Use natural sorting when sorting classes ([#13507](https://github.com/tailwindlabs/tailwindcss/pull/13507))
17+
- Use natural sorting when sorting classes ([#13507](https://github.com/tailwindlabs/tailwindcss/pull/13507), [#13532](https://github.com/tailwindlabs/tailwindcss/pull/13532))
1818

1919
## [4.0.0-alpha.14] - 2024-04-09
2020

packages/tailwindcss/src/utils/compare.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ export function compare(a: string, z: string) {
2020
// If both are numbers, compare them as numbers instead of strings.
2121
if (aCode >= ZERO && aCode <= NINE && zCode >= ZERO && zCode <= NINE) {
2222
let aStart = i
23-
let aEnd = i
23+
let aEnd = i + 1
2424
let zStart = i
25-
let zEnd = i
25+
let zEnd = i + 1
2626

2727
// Consume the number
28-
while (a.charCodeAt(aEnd) >= ZERO && a.charCodeAt(aEnd) <= NINE) aEnd++
28+
aCode = a.charCodeAt(aEnd)
29+
while (aCode >= ZERO && aCode <= NINE) aCode = a.charCodeAt(++aEnd)
2930

3031
// Consume the number
31-
while (z.charCodeAt(zEnd) >= ZERO && z.charCodeAt(zEnd) <= NINE) zEnd++
32+
zCode = z.charCodeAt(zEnd)
33+
while (zCode >= ZERO && zCode <= NINE) zCode = z.charCodeAt(++zEnd)
3234

3335
let aNumber = a.slice(aStart, aEnd)
3436
let zNumber = z.slice(zStart, zEnd)

0 commit comments

Comments
 (0)