Skip to content

Commit bc9f3b5

Browse files
authored
Merge pull request #185 from adamwathan/purge-classes-beginning-with-numbers
Ensure classes beginning with numbers are properly purged
2 parents fbac428 + f2d37bc commit bc9f3b5

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

__tests__/purgecss.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ describe('special characters, with custom Extractor', () => {
317317
it('finds tailwind class', () => {
318318
expect(purgecssResult.includes('md\\:w-1\\/3')).toBe(true)
319319
})
320+
321+
it('discards unused class beginning with number', () => {
322+
expect(purgecssResult.includes('\\32 -panel')).toBe(false)
323+
})
320324
})
321325

322326
describe('special characters, with custom Extractor as a function', () => {

__tests__/test_examples/special_characters/special_characters.css

+4
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99
.md\:w-1\/3 {
1010
color: green;
1111
}
12+
13+
.\32 -panels {
14+
color: red;
15+
}

src/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ class Purgecss {
300300
return
301301
}
302302

303+
if (node.parent && node.parent.type === 'atrule' && node.parent.name === 'keyframes') {
304+
return
305+
}
306+
303307
let keepSelector = true
304308
node.selector = selectorParser(selectorsParsed => {
305309
selectorsParsed.walk(selector => {
@@ -316,8 +320,7 @@ class Purgecss {
316320
for (const { type, value } of selector.nodes) {
317321
if (
318322
SELECTOR_STANDARD_TYPES.includes(type) &&
319-
typeof value !== 'undefined' &&
320-
/^\d/g.test(value) === false
323+
typeof value !== 'undefined'
321324
) {
322325
selectorsInRule.push(value)
323326
} else if (

0 commit comments

Comments
 (0)