Skip to content

Commit

Permalink
Require matching prefix when detecting negatives
Browse files Browse the repository at this point in the history
  • Loading branch information
thecrypticace committed Apr 15, 2022
1 parent 206f1d6 commit 1b357f9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/generateRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,11 @@ function* resolveMatchedPlugins(classCandidate, context) {
const twConfigPrefix = context.tailwindConfig.prefix

const twConfigPrefixLen = twConfigPrefix.length
if (candidatePrefix[twConfigPrefixLen] === '-') {

const hasMatchingPrefix = candidatePrefix.startsWith(twConfigPrefix)
|| candidatePrefix.startsWith(`-${twConfigPrefix}`)

if (candidatePrefix[twConfigPrefixLen] === '-' && hasMatchingPrefix) {
negative = true
candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1)
}
Expand Down
16 changes: 16 additions & 0 deletions tests/prefix.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,19 @@ it('prefix with negative values and variants in the safelist', async () => {
}
`)
})

it('prefix does not detect and generate unnecessary classes', async () => {
let config = {
prefix: 'tw-_',
content: [{ raw: html`-aaa-filter aaaa-table aaaa-hidden` }],
corePlugins: { preflight: false },
}

let input = css`
@tailwind utilities;
`

const result = await run(input, config)

expect(result.css).toMatchFormattedCss(css``)
})

0 comments on commit 1b357f9

Please sign in to comment.