Skip to content

Commit b2b37e0

Browse files
Don't crash when given applying a variant to a negated version of a simple utility (#12514)
* Don't crash when given applying a variant to a negated version of a simple utility * Update changelog
1 parent dac9cf2 commit b2b37e0

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Don't emit `@config` in CSS when watching via the CLI ([#12327](https://github.com/tailwindlabs/tailwindcss/pull/12327))
1515
- Ensure configured `font-feature-settings` for `mono` are included in Preflight ([#12342](https://github.com/tailwindlabs/tailwindcss/pull/12342))
1616
- Improve candidate detection in minified JS arrays (without spaces) ([#12396](https://github.com/tailwindlabs/tailwindcss/pull/12396))
17+
- Don't crash when given applying a variant to a negated version of a simple utility ([#12514](https://github.com/tailwindlabs/tailwindcss/pull/12514))
1718
- [Oxide] Remove `autoprefixer` dependency ([#11315](https://github.com/tailwindlabs/tailwindcss/pull/11315))
1819
- [Oxide] Fix source maps issue resulting in a crash ([#11319](https://github.com/tailwindlabs/tailwindcss/pull/11319))
1920
- [Oxide] Fallback to RegEx based parser when using custom transformers or extractors ([#11335](https://github.com/tailwindlabs/tailwindcss/pull/11335))

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)