Skip to content

Commit 0bfae7a

Browse files
committed
only convert theme(…) to --theme(…) for new syntax
1 parent 891df08 commit 0bfae7a

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

packages/@tailwindcss-upgrade/src/template/codemods/theme-to-var.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test.each([
1414
['[--value:theme(spacing[1.25])]', '[--value:--spacing(1.25)]'],
1515

1616
// Should not convert invalid spacing values to calc
17-
['[--value:theme(spacing[1.1])]', '[--value:--theme(spacing[1.1])]'],
17+
['[--value:theme(spacing[1.1])]', '[--value:theme(spacing[1.1])]'],
1818

1919
// Convert to `var(…)` if we can resolve the path
2020
['[color:theme(colors.red.500)]', '[color:var(--color-red-500)]'], // Arbitrary property
@@ -26,13 +26,13 @@ test.each([
2626
['bg-[theme(colors.red.500,red)]', 'bg-(--color-red-500,red)'],
2727

2828
// Keep `theme(…)` if we can't resolve the path
29-
['bg-[theme(colors.foo.1000)]', 'bg-[--theme(colors.foo.1000)]'],
29+
['bg-[theme(colors.foo.1000)]', 'bg-[theme(colors.foo.1000)]'],
3030

3131
// Keep `theme(…)` if we can't resolve the path, but still try to convert the
3232
// fallback value.
3333
[
3434
'bg-[theme(colors.foo.1000,theme(colors.red.500))]',
35-
'bg-[--theme(colors.foo.1000,var(--color-red-500))]',
35+
'bg-[theme(colors.foo.1000,var(--color-red-500))]',
3636
],
3737

3838
// Use `theme(…)` (deeply nested) inside of a `calc(…)` function
@@ -92,35 +92,35 @@ test.each([
9292
// still upgrade the `theme(…)` to the modern syntax.
9393
['max-[theme(screens.lg)]:flex', 'max-[--theme(--breakpoint-lg)]:flex'],
9494
// There are no variables for `--spacing` multiples, so we can't convert this
95-
['max-[theme(spacing.4)]:flex', 'max-[--theme(spacing.4)]:flex'],
95+
['max-[theme(spacing.4)]:flex', 'max-[theme(spacing.4)]:flex'],
9696

9797
// This test in itself doesn't make much sense. But we need to make sure
9898
// that this doesn't end up as the modifier in the candidate itself.
99-
['max-[theme(spacing.4/50)]:flex', 'max-[--theme(spacing.4/50)]:flex'],
99+
['max-[theme(spacing.4/50)]:flex', 'max-[theme(spacing.4/50)]:flex'],
100100

101101
// `theme(…)` calls in another CSS function is replaced correctly.
102102
// Additionally we remove unnecessary whitespace.
103103
['grid-cols-[min(50%_,_theme(spacing.80))_auto]', 'grid-cols-[min(50%,--spacing(80))_auto]'],
104104

105105
// `theme(…)` calls valid in v3, but not in v4 should still be converted.
106-
['[--foo:theme(transitionDuration.500)]', '[--foo:--theme(transitionDuration.500)]'],
106+
['[--foo:theme(transitionDuration.500)]', '[--foo:theme(transitionDuration.500)]'],
107107

108108
// Renamed theme keys
109109
['max-w-[theme(screens.md)]', 'max-w-(--breakpoint-md)'],
110110
['w-[theme(maxWidth.md)]', 'w-(--container-md)'],
111111

112112
// Invalid cases
113-
['[--foo:theme(colors.red.500/50/50)]', '[--foo:--theme(colors.red.500/50/50)]'],
114-
['[--foo:theme(colors.red.500/50/50)]/50', '[--foo:--theme(colors.red.500/50/50)]/50'],
113+
['[--foo:theme(colors.red.500/50/50)]', '[--foo:theme(colors.red.500/50/50)]'],
114+
['[--foo:theme(colors.red.500/50/50)]/50', '[--foo:theme(colors.red.500/50/50)]/50'],
115115

116116
// Partially invalid cases
117117
[
118118
'[--foo:theme(colors.red.500/50/50)_theme(colors.blue.200)]',
119-
'[--foo:--theme(colors.red.500/50/50)_var(--color-blue-200)]',
119+
'[--foo:theme(colors.red.500/50/50)_var(--color-blue-200)]',
120120
],
121121
[
122122
'[--foo:theme(colors.red.500/50/50)_theme(colors.blue.200)]/50',
123-
'[--foo:--theme(colors.red.500/50/50)_var(--color-blue-200)]/50',
123+
'[--foo:theme(colors.red.500/50/50)_var(--color-blue-200)]/50',
124124
],
125125
])('%s => %s', async (candidate, result) => {
126126
let designSystem = await __unstable__loadDesignSystem(
@@ -158,7 +158,7 @@ test('extended space scale converts to var or calc', async () => {
158158
'[--value:var(--spacing-miami)]',
159159
)
160160
expect(themeToVar(designSystem, {}, '[--value:theme(spacing.nyc)]')).toEqual(
161-
'[--value:--theme(spacing.nyc)]',
161+
'[--value:theme(spacing.nyc)]',
162162
)
163163
})
164164

@@ -183,6 +183,6 @@ test('custom space scale converts to var', async () => {
183183
'[--value:var(--spacing-2)]',
184184
)
185185
expect(themeToVar(designSystem, {}, '[--value:theme(spacing.3)]')).toEqual(
186-
'[--value:--theme(spacing.3)]',
186+
'[--value:theme(spacing.3)]',
187187
)
188188
})

packages/@tailwindcss-upgrade/src/template/codemods/theme-to-var.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,6 @@ function substituteFunctionsInValue(
239239
) {
240240
ValueParser.walk(ast, (node, { replaceWith }) => {
241241
if (node.kind === 'function' && node.value === 'theme') {
242-
node.value = '--theme'
243-
244242
if (node.nodes.length < 1) return
245243

246244
// Ignore whitespace before the first argument

packages/tailwindcss/src/compat/container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function buildCustomContainerUtilityRules(
6060
let [key] = breakpoints[0]
6161
// Unset all default breakpoints
6262
rules.push(
63-
atRule('@media', `(width >= theme(--breakpoint-${key}))`, [decl('max-width', 'none')]),
63+
atRule('@media', `(width >= --theme(--breakpoint-${key}))`, [decl('max-width', 'none')]),
6464
)
6565
}
6666

0 commit comments

Comments
 (0)