Skip to content

Commit 5c76de7

Browse files
Require matching prefix when detecting negatives (#8121)
* Require matching prefix when detecting negatives * Update changelog
1 parent 206f1d6 commit 5c76de7

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Types: allow for arbitrary theme values (for 3rd party plugins) ([#7926](https://github.com/tailwindlabs/tailwindcss/pull/7926))
1313
- Don’t split vars with numbers in them inside arbitrary values ([#8091](https://github.com/tailwindlabs/tailwindcss/pull/8091))
14+
- Require matching prefix when detecting negatives ([#8121](https://github.com/tailwindlabs/tailwindcss/pull/8121))
1415

1516
### Added
1617

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 =
387+
candidatePrefix.startsWith(twConfigPrefix) || 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)