Skip to content

Commit

Permalink
Fix candidate detection in .slim templates
Browse files Browse the repository at this point in the history
  • Loading branch information
thecrypticace committed Jun 9, 2022
1 parent 4a99a9c commit 3f1fbf9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/lib/defaultExtractor.js
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions tests/default-extractor.test.js
Expand Up @@ -415,28 +415,24 @@ test('with single quotes array within template literal', async () => {
const extractions = defaultExtractor(`<div class=\`\${['pr-1.5']}\`></div>`)

expect(extractions).toContain('pr-1.5')
expect(extractions).not.toContain('pr-1')
})

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

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 () => {
Expand All @@ -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')
})

0 comments on commit 3f1fbf9

Please sign in to comment.