From ae6a8d532b225ad7f62ecaecd5769582544f2084 Mon Sep 17 00:00:00 2001 From: Georg Ledermann Date: Tue, 16 Jul 2024 15:34:20 +0200 Subject: [PATCH] Fix extracting utilities from slim/pug templates (#14006) A class name starting with number like `2xl:bg-red-500` must not be removed. Resolves #14005 --- src/lib/defaultExtractor.js | 2 +- tests/default-extractor.test.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lib/defaultExtractor.js b/src/lib/defaultExtractor.js index fdcd8dd5d214..8f89596313ce 100644 --- a/src/lib/defaultExtractor.js +++ b/src/lib/defaultExtractor.js @@ -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 { diff --git a/tests/default-extractor.test.js b/tests/default-extractor.test.js index d99069197d60..0cac75d0c299 100644 --- a/tests/default-extractor.test.js +++ b/tests/default-extractor.test.js @@ -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(`
Hello world!