Skip to content

Commit

Permalink
fix issue #92
Browse files Browse the repository at this point in the history
Value between rounded brackets for nth-child and nth-of-type pseudo-class gets purged if it starts with 'n' or '-n'
  • Loading branch information
Ffloriel committed Jul 29, 2018
1 parent b63e50a commit 9b637bd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
12 changes: 12 additions & 0 deletions __tests__/purgecss.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,18 @@ describe('pseudo selectors', () => {
expect(purgecssResult.includes('some-item:nth-child(2n + 1)')).toBe(true)
})

it('finds some-item:nth-of-type(n+3)', () => {
expect(purgecssResult.includes('some-item:nth-of-type(n+3)')).toBe(true)
})

it('finds some-item:nth-of-type(-1n+6)', () => {
expect(purgecssResult.includes('some-item:nth-of-type(-1n+6)')).toBe(true)
})

it('finds some-item:nth-of-type(-n+6)', () => {
expect(purgecssResult.includes('some-item:nth-of-type(-n+6)')).toBe(true)
})

it('removes unused:only-child()', () => {
expect(purgecssResult.includes('unused:only-child()')).toBe(false)
})
Expand Down
12 changes: 12 additions & 0 deletions __tests__/test_examples/pseudo_selector/pseudo_selector.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
font-size: 1rem;
}

.some-item:nth-of-type(n+3) {
color: goldenrod;
}

.some-item:nth-of-type(-1n+6) {
color: brown;
}

.some-item:nth-of-type(-n+6) {
color: brown;
}

.unused:only-child() {
color: red;
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class Purgecss {
selectorsInRule.push(value)
} else if (
type === 'tag' &&
!/[+]|(even)|(odd)|^from$|^to$|^\d/.test(value)
!/[+]|n|-|(even)|(odd)|^from$|^to$|^\d/.test(value)
) {
// test if we do not have a pseudo class parameter (e.g. 2n in :nth-child(2n))
selectorsInRule.push(value)
Expand Down

0 comments on commit 9b637bd

Please sign in to comment.