Skip to content

Commit 9e48c1e

Browse files
committed
Don't crash when given applying a variant to a negated version of a simple utility
1 parent dac9cf2 commit 9e48c1e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/lib/generateRules.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,11 @@ function applyFinalFormat(match, { context, candidate }) {
840840
return null
841841
}
842842

843+
// If all rules have been eliminated we can skip this candidate entirely
844+
if (container.nodes.length === 0) {
845+
return null
846+
}
847+
843848
match[1] = container.nodes[0]
844849

845850
return match

tests/negative-prefix.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,4 +339,24 @@ test('arbitrary value keywords should be ignored', () => {
339339
return run('@tailwind utilities', config).then((result) => {
340340
return expect(result.css).toMatchFormattedCss(css``)
341341
})
342+
343+
// This is a weird test but it used to crash because the negative prefix + variant used to cause an undefined utility to be generated
344+
test('addUtilities without negative prefix + variant + negative prefix in content should not crash', async () => {
345+
let config = {
346+
content: [{ raw: html`<div class="hover:-top-lg"></div>` }],
347+
plugins: [
348+
({ addUtilities }) => {
349+
addUtilities({
350+
'.top-lg': {
351+
top: '6rem',
352+
},
353+
})
354+
},
355+
]
356+
}
357+
358+
let result = await run('@tailwind utilities', config)
359+
360+
expect(result.css).toMatchCss(css``)
361+
})
342362
})

0 commit comments

Comments
 (0)