Skip to content

Commit

Permalink
Sort class to end of list (#334)
Browse files Browse the repository at this point in the history
This isn’t a real class but an artifact of how we want to do sorting
  • Loading branch information
thecrypticace authored Dec 9, 2024
1 parent cdbc764 commit 90b0253
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/sorting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ function reorderClasses(classList: string[], { env }: { env: TransformerEnv }) {
? env.context.getClassOrder(classList)
: getClassOrderPolyfill(classList, { env })

return orderedClasses.sort(([, a], [, z]) => {
return orderedClasses.sort(([nameA, a], [nameZ, z]) => {
// Move `...` to the end of the list
if (nameA === '...' || nameA === '…') return 1
if (nameZ === '...' || nameZ === '…') return -1

if (a === z) return 0
if (a === null) return -1
if (z === null) return 1
Expand Down
8 changes: 8 additions & 0 deletions tests/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ let html: TestEntry[] = [
tailwindPreserveDuplicates: true,
},
],

// … is moved to the end of the list
['<div class="... sm:p-0 p-0"></div>', '<div class="p-0 sm:p-0 ..."></div>'],
['<div class="… sm:p-0 p-0"></div>', '<div class="p-0 sm:p-0 …"></div>'],
['<div class="sm:p-0 ... p-0"></div>', '<div class="p-0 sm:p-0 ..."></div>'],
['<div class="sm:p-0 … p-0"></div>', '<div class="p-0 sm:p-0 …"></div>'],
['<div class="sm:p-0 p-0 ..."></div>', '<div class="p-0 sm:p-0 ..."></div>'],
['<div class="sm:p-0 p-0 …"></div>', '<div class="p-0 sm:p-0 …"></div>'],
]

let css: TestEntry[] = [
Expand Down

0 comments on commit 90b0253

Please sign in to comment.