Skip to content

Commit 85f1a07

Browse files
committed
migrate supports-[foo] to supports-foo if we can
1 parent 0d73ea9 commit 85f1a07

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

packages/@tailwindcss-upgrade/src/template/codemods/arbitrary-value-to-bare-value.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ test.each([
66
['data-[selected]:flex', 'data-selected:flex'],
77
['data-[foo=bar]:flex', 'data-[foo=bar]:flex'],
88

9+
['supports-[gap]:flex', 'supports-gap:flex'],
10+
['supports-[display:grid]:flex', 'supports-[display:grid]:flex'],
11+
912
['group-data-[selected]:flex', 'group-data-selected:flex'],
1013
['group-data-[foo=bar]:flex', 'group-data-[foo=bar]:flex'],
1114
['group-has-data-[selected]:flex', 'group-has-data-selected:flex'],

packages/@tailwindcss-upgrade/src/template/codemods/arbitrary-value-to-bare-value.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ export function arbitraryValueToBareValue(
5858
value: variant.value.value.slice(0, variant.value.value.indexOf('=')),
5959
}
6060
}
61+
62+
// Convert `supports-[gap]` to `supports-gap`
63+
else if (
64+
variant.kind === 'functional' &&
65+
variant.root === 'supports' &&
66+
variant.value?.kind === 'arbitrary' &&
67+
/^[a-z-][a-z0-9-]*$/i.test(variant.value.value)
68+
) {
69+
changed = true
70+
variant.value = {
71+
kind: 'named',
72+
value: variant.value.value,
73+
}
74+
}
6175
}
6276

6377
return changed ? printCandidate(designSystem, clone) : rawCandidate

0 commit comments

Comments
 (0)