Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Don’t crash when scanning candidate matching the prefix
  • Loading branch information
thecrypticace committed Oct 3, 2024
commit b45838bc671d0ecabe55c82ee443bc5ea10a56b7
2 changes: 1 addition & 1 deletion packages/tailwindcss/src/candidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export function* parseCandidate(input: string, designSystem: DesignSystem): Iter
// A prefix is a special variant used to prefix all utilities. When present,
// all utilities must start with that variant which we will then remove from
// the variant list so no other part of the codebase has to know about it.
if (designSystem.theme.prefix) {
if (designSystem.theme.prefix && rawVariants.length > 1) {
if (rawVariants[0] !== designSystem.theme.prefix) return null

rawVariants.shift()
Expand Down
16 changes: 16 additions & 0 deletions packages/tailwindcss/src/prefix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,19 @@ test('a prefix must be letters only', async () => {
`[Error: The prefix "__" is invalid. Prefixes must be lowercase ASCII letters (a-z) only.]`,
)
})

test('a candidate matching the prefix does not crash', async () => {
let input = css`
@theme reference prefix(tomato);
@tailwind utilities;
`

let compiler = await compile(input)

expect(compiler.build(['tomato', 'tomato:flex'])).toMatchInlineSnapshot(`
".tomato\\:flex {
display: flex;
}
"
`)
})