Skip to content

Commit

Permalink
Merge pull request #185 from adamwathan/purge-classes-beginning-with-…
Browse files Browse the repository at this point in the history
…numbers

Ensure classes beginning with numbers are properly purged
  • Loading branch information
Ffloriel authored May 9, 2019
2 parents fbac428 + f2d37bc commit bc9f3b5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions __tests__/purgecss.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ describe('special characters, with custom Extractor', () => {
it('finds tailwind class', () => {
expect(purgecssResult.includes('md\\:w-1\\/3')).toBe(true)
})

it('discards unused class beginning with number', () => {
expect(purgecssResult.includes('\\32 -panel')).toBe(false)
})
})

describe('special characters, with custom Extractor as a function', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
.md\:w-1\/3 {
color: green;
}

.\32 -panels {
color: red;
}
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ class Purgecss {
return
}

if (node.parent && node.parent.type === 'atrule' && node.parent.name === 'keyframes') {
return
}

let keepSelector = true
node.selector = selectorParser(selectorsParsed => {
selectorsParsed.walk(selector => {
Expand All @@ -316,8 +320,7 @@ class Purgecss {
for (const { type, value } of selector.nodes) {
if (
SELECTOR_STANDARD_TYPES.includes(type) &&
typeof value !== 'undefined' &&
/^\d/g.test(value) === false
typeof value !== 'undefined'
) {
selectorsInRule.push(value)
} else if (
Expand Down

0 comments on commit bc9f3b5

Please sign in to comment.