Skip to content

Commit bbfb5a3

Browse files
committed
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 3713207 commit bbfb5a3

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
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Don't emit `@config` in CSS when watching via the CLI ([#12327](https://github.com/tailwindlabs/tailwindcss/pull/12327))
1414
- Improve types for `resolveConfig` ([#12272](https://github.com/tailwindlabs/tailwindcss/pull/12272))
1515
- Ensure configured `font-feature-settings` for `mono` are included in Preflight ([#12342](https://github.com/tailwindlabs/tailwindcss/pull/12342))
16+
- Don't crash when given applying a variant to a negated version of a simple utility ([#12514](https://github.com/tailwindlabs/tailwindcss/pull/12514))
1617

1718
## [3.3.5] - 2023-10-25
1819

src/lib/generateRules.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,11 @@ function applyFinalFormat(match, { context, candidate }) {
845845
return null
846846
}
847847

848+
// If all rules have been eliminated we can skip this candidate entirely
849+
if (container.nodes.length === 0) {
850+
return null
851+
}
852+
848853
match[1] = container.nodes[0]
849854

850855
return match

tests/negative-prefix.test.js

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

0 commit comments

Comments
 (0)