Skip to content

Commit e25d2dc

Browse files
committed
ensure migrating invalid candidates with empty [] work
1 parent fae6f42 commit e25d2dc

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

packages/@tailwindcss-upgrade/src/template/codemods/modernize-arbitrary-values.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ export function modernizeArbitraryValues(
1818
_userConfig: Config,
1919
rawCandidate: string,
2020
): string {
21+
// Empty arbitrary values don't parse anymore. This is a little bit of a hack
22+
// to work around that behavior so we can still perform the migration:
23+
if (rawCandidate.includes('group-')) {
24+
rawCandidate = rawCandidate.replaceAll('-[]:', '-[--tw-custom-placeholder]:') // End of variant
25+
rawCandidate = rawCandidate.replaceAll('-[]/', '-[--tw-custom-placeholder]/') // With modifier
26+
rawCandidate = rawCandidate.replaceAll('/[]:', '/[--tw-custom-placeholder]:') // Empty modifier
27+
}
28+
2129
for (let candidate of parseCandidate(rawCandidate, designSystem)) {
2230
let clone = structuredClone(candidate)
2331
let changed = false
@@ -43,7 +51,7 @@ export function modernizeArbitraryValues(
4351
variant.kind === 'compound' &&
4452
variant.root === 'group' &&
4553
variant.variant.kind === 'arbitrary' &&
46-
variant.variant.selector === '&:is()'
54+
variant.variant.selector === '&:is(--tw-custom-placeholder)'
4755
) {
4856
// `group-[]`
4957
if (variant.modifier === null) {
@@ -378,7 +386,16 @@ export function modernizeArbitraryValues(
378386
}
379387
}
380388

381-
return changed ? printCandidate(designSystem, clone) : rawCandidate
389+
let newCandidate = changed ? printCandidate(designSystem, clone) : rawCandidate
390+
391+
// Empty arbitrary values don't parse anymore. This is a little bit of a hack
392+
// to work around that behavior so we can still perform the migration:
393+
if (newCandidate.includes('group-')) {
394+
newCandidate = newCandidate.replaceAll('-[--tw-custom-placeholder]:', '-[]:') // End of variant
395+
newCandidate = newCandidate.replaceAll('-[--tw-custom-placeholder]/', '-[]/') // With modifier
396+
newCandidate = newCandidate.replaceAll('/[--tw-custom-placeholder]:', '/[]:') // Empty modifier
397+
}
398+
return newCandidate
382399
}
383400

384401
return rawCandidate

packages/@tailwindcss-upgrade/src/template/codemods/prefix.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ export function prefix(
1111
): string {
1212
if (!designSystem.theme.prefix) return rawCandidate
1313

14+
// Empty arbitrary values don't parse anymore. This is a little bit of a hack
15+
// to work around that behavior so we can still perform the migration:
16+
if (rawCandidate.includes('group-')) {
17+
rawCandidate = rawCandidate.replaceAll('-[]:', '-[--tw-custom-placeholder]:') // End of variant
18+
rawCandidate = rawCandidate.replaceAll('-[]/', '-[--tw-custom-placeholder]/') // With modifier
19+
rawCandidate = rawCandidate.replaceAll('/[]:', '/[--tw-custom-placeholder]:') // Empty modifier
20+
}
21+
1422
let v3Base = extractV3Base(designSystem, userConfig, rawCandidate)
1523

1624
if (!v3Base) return rawCandidate

0 commit comments

Comments
 (0)