Skip to content

Commit

Permalink
Fix extracting utilities from slim/pug templates (#14006)
Browse files Browse the repository at this point in the history
A class name starting with number like `2xl:bg-red-500` must not be removed.

Resolves #14005
  • Loading branch information
ledermann authored Jul 16, 2024
1 parent a0dbb3d commit ae6a8d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/defaultExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function defaultExtractor(context) {
// If the next segment is a number, discard both, for example seeing
// `px-1` and `5` means the real candidate was `px-1.5` which is already
// captured.
let next = parseInt(segments[idx + 1])
let next = Number(segments[idx + 1])
if (isNaN(next)) {
results.push(segment)
} else {
Expand Down
10 changes: 10 additions & 0 deletions tests/default-extractor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,16 @@ test('classes in slim templates', async () => {
expect(extractions).toContain('text-gray-500')
})

test('classes in slim templates starting with number', async () => {
const extractions = defaultExtractor(`
.bg-green-300.2xl:bg-red-300
'(Look mom, no closing tag!)
`)

expect(extractions).toContain('bg-green-300')
expect(extractions).toContain('2xl:bg-red-300')
})

test("classes with fractional numeric values don't also generate the whole number utility", async () => {
const extractions = defaultExtractor(`
<div class="px-1.5 py-2.75">Hello world!</div>
Expand Down

0 comments on commit ae6a8d5

Please sign in to comment.