Skip to content

Commit 3f1fbf9

Browse files
committed
Fix candidate detection in .slim templates
1 parent 4a99a9c commit 3f1fbf9

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/lib/defaultExtractor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function* buildRegExps(context) {
9191
])
9292

9393
// 5. Inner matches
94-
// yield /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g
94+
yield /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g
9595
}
9696

9797
// We want to capture any "special" characters

tests/default-extractor.test.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,28 +415,24 @@ test('with single quotes array within template literal', async () => {
415415
const extractions = defaultExtractor(`<div class=\`\${['pr-1.5']}\`></div>`)
416416

417417
expect(extractions).toContain('pr-1.5')
418-
expect(extractions).not.toContain('pr-1')
419418
})
420419

421420
test('with double quotes array within template literal', async () => {
422421
const extractions = defaultExtractor(`<div class=\`\${["pr-1.5"]}\`></div>`)
423422

424423
expect(extractions).toContain('pr-1.5')
425-
expect(extractions).not.toContain('pr-1')
426424
})
427425

428426
test('with single quotes array within function', async () => {
429427
const extractions = defaultExtractor(`document.body.classList.add(['pl-1.5'].join(" "));`)
430428

431429
expect(extractions).toContain('pl-1.5')
432-
expect(extractions).not.toContain('pl-1')
433430
})
434431

435432
test('with double quotes array within function', async () => {
436433
const extractions = defaultExtractor(`document.body.classList.add(["pl-1.5"].join(" "));`)
437434

438435
expect(extractions).toContain('pl-1.5')
439-
expect(extractions).not.toContain('pl-1')
440436
})
441437

442438
test('with angle brackets', async () => {
@@ -458,3 +454,17 @@ test('markdown code fences', async () => {
458454
expect(extractions).not.toContain('.font-bold')
459455
expect(extractions).not.toContain('.font-normal')
460456
})
457+
458+
test('classes in slim templates', async () => {
459+
const extractions = defaultExtractor(`
460+
p.bg-red-500.text-sm
461+
'This is a paragraph
462+
small.italic.text-gray-500
463+
'(Look mom, no closing tag!)
464+
`)
465+
466+
expect(extractions).toContain('bg-red-500')
467+
expect(extractions).toContain('text-sm')
468+
expect(extractions).toContain('italic')
469+
expect(extractions).toContain('text-gray-500')
470+
})

0 commit comments

Comments
 (0)