From 8f70df59f4925224f32734088508e0f8e9094742 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Fri, 15 Apr 2022 11:50:44 -0400 Subject: [PATCH 1/2] Require matching prefix when detecting negatives --- src/lib/generateRules.js | 6 +++++- tests/prefix.test.js | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/lib/generateRules.js b/src/lib/generateRules.js index fc9a6bbd6ec1..bbed6812eb48 100644 --- a/src/lib/generateRules.js +++ b/src/lib/generateRules.js @@ -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) } diff --git a/tests/prefix.test.js b/tests/prefix.test.js index 9124fd5b64c0..a82b98624ace 100644 --- a/tests/prefix.test.js +++ b/tests/prefix.test.js @@ -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``) +}) From 8e5345f001e9cf2c720b32e54ce7fe12617f3c8e Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Fri, 15 Apr 2022 11:52:42 -0400 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae4fc61fa214..1e94446bec2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Types: allow for arbitrary theme values (for 3rd party plugins) ([#7926](https://github.com/tailwindlabs/tailwindcss/pull/7926)) - Don’t split vars with numbers in them inside arbitrary values ([#8091](https://github.com/tailwindlabs/tailwindcss/pull/8091)) +- Require matching prefix when detecting negatives ([#8121](https://github.com/tailwindlabs/tailwindcss/pull/8121)) ### Added