Skip to content

Commit 1b357f9

Browse files
committed
Require matching prefix when detecting negatives
1 parent 206f1d6 commit 1b357f9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/lib/generateRules.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,11 @@ function* resolveMatchedPlugins(classCandidate, context) {
382382
const twConfigPrefix = context.tailwindConfig.prefix
383383

384384
const twConfigPrefixLen = twConfigPrefix.length
385-
if (candidatePrefix[twConfigPrefixLen] === '-') {
385+
386+
const hasMatchingPrefix = candidatePrefix.startsWith(twConfigPrefix)
387+
|| candidatePrefix.startsWith(`-${twConfigPrefix}`)
388+
389+
if (candidatePrefix[twConfigPrefixLen] === '-' && hasMatchingPrefix) {
386390
negative = true
387391
candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1)
388392
}

tests/prefix.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,19 @@ it('prefix with negative values and variants in the safelist', async () => {
358358
}
359359
`)
360360
})
361+
362+
it('prefix does not detect and generate unnecessary classes', async () => {
363+
let config = {
364+
prefix: 'tw-_',
365+
content: [{ raw: html`-aaa-filter aaaa-table aaaa-hidden` }],
366+
corePlugins: { preflight: false },
367+
}
368+
369+
let input = css`
370+
@tailwind utilities;
371+
`
372+
373+
const result = await run(input, config)
374+
375+
expect(result.css).toMatchFormattedCss(css``)
376+
})

0 commit comments

Comments
 (0)