Skip to content

Commit

Permalink
Don't crash when given applying a variant to a negated version of a s…
Browse files Browse the repository at this point in the history
…imple utility
  • Loading branch information
thecrypticace committed Dec 1, 2023
1 parent dac9cf2 commit 9e48c1e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib/generateRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions tests/negative-prefix.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`<div class="hover:-top-lg"></div>` }],
plugins: [
({ addUtilities }) => {
addUtilities({
'.top-lg': {
top: '6rem',
},
})
},
]
}

let result = await run('@tailwind utilities', config)

expect(result.css).toMatchCss(css``)
})
})

0 comments on commit 9e48c1e

Please sign in to comment.