Skip to content

Commit 29687e0

Browse files
Discard candidates with an empty data type (#19172)
Fixes tailwindlabs/tailwindcss-intellisense#1479 Maybe should close tailwindlabs/tailwindcss-intellisense#1480 — perhaps we can find a workaround there for older versions? We're building up a class name in code to validate if something is a valid variant: `{variant}:[color:red]` if `{variant}` got replaced with `bg-[` then we'd produce `bg-[:[color:red]` and this parsed as a valid candidate: ``` bg-[:[color:red] ^^ root: `bg` ^ data type: `` (empty string) — this should be invalid ^^^^^^^^^^ value: `[color:red` ``` The value isn't valid _but_ the syntax for arbitrary values is pretty lax in core. Oxide already won't pick something like this up though so no problem there. Only a problem for something like IntelliSense or clients using the compile() API directly.
1 parent 56e7f3b commit 29687e0

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- _Experimental_: Add `@container-size` utility ([#18901](https://github.com/tailwindlabs/tailwindcss/pull/18901))
1313

14+
### Fixed
15+
16+
- Discard candidates with an empty data type ([#19172](https://github.com/tailwindlabs/tailwindcss/pull/19172))
17+
1418
## [4.1.15] - 2025-10-20
1519

1620
### Fixed

packages/tailwindcss/src/candidate.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,14 @@ it('should not parse compound group with a non-compoundable variant', () => {
17761776
expect(run('group-*:flex', { utilities, variants })).toMatchInlineSnapshot(`[]`)
17771777
})
17781778

1779+
it('empty data types are invalid', () => {
1780+
let utilities = new Utilities()
1781+
utilities.functional('bg', () => [])
1782+
let variants = new Variants()
1783+
1784+
expect(run('bg-[:foo]', { utilities, variants })).toMatchInlineSnapshot(`[]`)
1785+
})
1786+
17791787
it('should parse a variant containing an arbitrary string with unbalanced parens, brackets, curlies and other quotes', () => {
17801788
let utilities = new Utilities()
17811789
utilities.static('flex', () => [])

packages/tailwindcss/src/candidate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ export function* parseCandidate(input: string, designSystem: DesignSystem): Iter
554554
if (!isValidArbitrary(arbitraryValue)) continue
555555

556556
// Extract an explicit typehint if present, e.g. `bg-[color:var(--my-var)])`
557-
let typehint = ''
557+
let typehint: string | null = null
558558
for (let i = 0; i < arbitraryValue.length; i++) {
559559
let code = arbitraryValue.charCodeAt(i)
560560

@@ -580,6 +580,8 @@ export function* parseCandidate(input: string, designSystem: DesignSystem): Iter
580580
continue
581581
}
582582

583+
if (typehint === '') continue
584+
583585
candidate.value = {
584586
kind: 'arbitrary',
585587
dataType: typehint || null,

0 commit comments

Comments
 (0)