Skip to content

Commit 6a1ae3a

Browse files
committed
Perform same check for (…) too
1 parent 7f24a5d commit 6a1ae3a

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

packages/tailwindcss/src/candidate.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,30 @@ it('should not parse invalid arbitrary values in variants', () => {
864864

865865
'data-foo-[var(--value)]:flex!',
866866
'data-foo[var(--value)]:flex!',
867+
868+
'data-foo-(color:--value):flex',
869+
'data-foo(color:--value):flex',
870+
871+
'data-foo-(color:--value)/50:flex',
872+
'data-foo(color:--value)/50:flex',
873+
874+
'data-foo-(color:--value)/(--mod):flex',
875+
'data-foo(color:--value)/(--mod):flex',
876+
877+
'data-foo-(color:--value)/(number:--mod):flex',
878+
'data-foo(color:--value)/(number:--mod):flex',
879+
880+
'data-foo-(--value):flex',
881+
'data-foo(--value):flex',
882+
883+
'data-foo-(--value)/50:flex',
884+
'data-foo(--value)/50:flex',
885+
886+
'data-foo-(--value)/(--mod):flex',
887+
'data-foo(--value)/(--mod):flex',
888+
889+
'data-foo-(--value)/(number:--mod):flex',
890+
'data-foo(--value)/(number:--mod):flex',
867891
]) {
868892
expect(run(candidate, { utilities, variants })).toEqual([])
869893
}

packages/tailwindcss/src/candidate.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -591,24 +591,6 @@ export function parseVariant(variant: string, designSystem: DesignSystem): Varia
591591
})
592592

593593
for (let [root, value] of roots) {
594-
let kind = designSystem.variants.kind(root)
595-
596-
// Compound variants e.g. not-in-[#foo] are ultimately split like so:
597-
// - root: not
598-
// - value: in-[#foo]
599-
// - root: in
600-
// - value: [#foo]
601-
//
602-
// However, other variants don't have this behavior, so we can skip
603-
// over this possible variant if the root is not a compound variant
604-
// and it contains an arbitrary value _after_ some other value
605-
// e.g. `supports-display-[color:red]` is invalid
606-
if (value && kind !== 'compound') {
607-
if (value[value.length - 1] === ']' && value[0] !== '[') {
608-
continue
609-
}
610-
}
611-
612594
switch (designSystem.variants.kind(root)) {
613595
case 'static': {
614596
// Static variants do not have a value
@@ -656,6 +638,11 @@ export function parseVariant(variant: string, designSystem: DesignSystem): Varia
656638
}
657639
}
658640

641+
// Discard values like `foo-[#bar]` or `foo-(#bar)`
642+
if (value[0] !== '[' && value[value.length - 1] === ']') {
643+
continue
644+
}
645+
659646
if (value[0] === '(' && value[value.length - 1] === ')') {
660647
let arbitraryValue = decodeArbitraryValue(value.slice(1, -1))
661648

@@ -674,6 +661,11 @@ export function parseVariant(variant: string, designSystem: DesignSystem): Varia
674661
}
675662
}
676663

664+
// Discard values like `foo-[#bar]` or `foo-(#bar)`
665+
if (value[0] !== '(' && value[value.length - 1] === ')') {
666+
continue
667+
}
668+
677669
return {
678670
kind: 'functional',
679671
root,

0 commit comments

Comments
 (0)