From 9e48c1e33b8718eb9b9ffb44e2f7b88ef5bfcf55 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Fri, 1 Dec 2023 10:05:13 -0500 Subject: [PATCH] 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..625a84042c82 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``) + }) })