From 394e5a7322f583210ef75df61a1df7b3395e1556 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Fri, 1 Dec 2023 10:05:13 -0500 Subject: [PATCH 1/2] Don't crash when given applying a variant to a negated version of a simple utility --- src/lib/generateRules.js | 5 +++++ tests/negative-prefix.test.js | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/lib/generateRules.js b/src/lib/generateRules.js index ff838190bf67..ac9fbb11926e 100644 --- a/src/lib/generateRules.js +++ b/src/lib/generateRules.js @@ -840,6 +840,11 @@ function applyFinalFormat(match, { context, candidate }) { return null } + // If all rules have been eliminated we can skip this candidate entirely + if (container.nodes.length === 0) { + return null + } + match[1] = container.nodes[0] return match diff --git a/tests/negative-prefix.test.js b/tests/negative-prefix.test.js index 615558807391..edd5b7aaa4f6 100644 --- a/tests/negative-prefix.test.js +++ b/tests/negative-prefix.test.js @@ -339,4 +339,24 @@ test('arbitrary value keywords should be ignored', () => { return run('@tailwind utilities', config).then((result) => { return expect(result.css).toMatchFormattedCss(css``) }) + + // This is a weird test but it used to crash because the negative prefix + variant used to cause an undefined utility to be generated + test('addUtilities without negative prefix + variant + negative prefix in content should not crash', async () => { + let config = { + content: [{ raw: html`
` }], + plugins: [ + ({ addUtilities }) => { + addUtilities({ + '.top-lg': { + top: '6rem', + }, + }) + }, + ], + } + + let result = await run('@tailwind utilities', config) + + expect(result.css).toMatchCss(css``) + }) }) From 5e4cb4750a777b7c94e0443ffd45267571189bb9 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Fri, 1 Dec 2023 10:08:06 -0500 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ec3e7812580..180fad7acdb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Don't emit `@config` in CSS when watching via the CLI ([#12327](https://github.com/tailwindlabs/tailwindcss/pull/12327)) - Ensure configured `font-feature-settings` for `mono` are included in Preflight ([#12342](https://github.com/tailwindlabs/tailwindcss/pull/12342)) - Improve candidate detection in minified JS arrays (without spaces) ([#12396](https://github.com/tailwindlabs/tailwindcss/pull/12396)) +- Don't crash when given applying a variant to a negated version of a simple utility ([#12514](https://github.com/tailwindlabs/tailwindcss/pull/12514)) - [Oxide] Remove `autoprefixer` dependency ([#11315](https://github.com/tailwindlabs/tailwindcss/pull/11315)) - [Oxide] Fix source maps issue resulting in a crash ([#11319](https://github.com/tailwindlabs/tailwindcss/pull/11319)) - [Oxide] Fallback to RegEx based parser when using custom transformers or extractors ([#11335](https://github.com/tailwindlabs/tailwindcss/pull/11335))