From 3f1fbf9b64853194a4b13fb93fd6374b4bc29c54 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 9 Jun 2022 16:49:09 -0400 Subject: [PATCH] Fix candidate detection in `.slim` templates --- src/lib/defaultExtractor.js | 2 +- tests/default-extractor.test.js | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/lib/defaultExtractor.js b/src/lib/defaultExtractor.js index 170d13cc9da6..c3e5b642cc3f 100644 --- a/src/lib/defaultExtractor.js +++ b/src/lib/defaultExtractor.js @@ -91,7 +91,7 @@ function* buildRegExps(context) { ]) // 5. Inner matches - // yield /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g + yield /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g } // We want to capture any "special" characters diff --git a/tests/default-extractor.test.js b/tests/default-extractor.test.js index ea7f90dc69d3..75abf4caebfd 100644 --- a/tests/default-extractor.test.js +++ b/tests/default-extractor.test.js @@ -415,28 +415,24 @@ test('with single quotes array within template literal', async () => { const extractions = defaultExtractor(`
`) expect(extractions).toContain('pr-1.5') - expect(extractions).not.toContain('pr-1') }) test('with double quotes array within template literal', async () => { const extractions = defaultExtractor(`
`) expect(extractions).toContain('pr-1.5') - expect(extractions).not.toContain('pr-1') }) test('with single quotes array within function', async () => { const extractions = defaultExtractor(`document.body.classList.add(['pl-1.5'].join(" "));`) expect(extractions).toContain('pl-1.5') - expect(extractions).not.toContain('pl-1') }) test('with double quotes array within function', async () => { const extractions = defaultExtractor(`document.body.classList.add(["pl-1.5"].join(" "));`) expect(extractions).toContain('pl-1.5') - expect(extractions).not.toContain('pl-1') }) test('with angle brackets', async () => { @@ -458,3 +454,17 @@ test('markdown code fences', async () => { expect(extractions).not.toContain('.font-bold') expect(extractions).not.toContain('.font-normal') }) + +test('classes in slim templates', async () => { + const extractions = defaultExtractor(` + p.bg-red-500.text-sm + 'This is a paragraph + small.italic.text-gray-500 + '(Look mom, no closing tag!) + `) + + expect(extractions).toContain('bg-red-500') + expect(extractions).toContain('text-sm') + expect(extractions).toContain('italic') + expect(extractions).toContain('text-gray-500') +})