Skip to content

Commit 73c30f5

Browse files
committed
ensure we migrate theme(spacing.1) correctly
`theme(spacing.1)` wasn't converted because we generated `--spacing-` and that doesn't exist therefore we kept it as-is.
1 parent 2abf228 commit 73c30f5

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ test.each([
66
// Keep candidates that don't contain `theme(…)` or `theme(…, …)`
77
['[color:red]', '[color:red]'],
88

9+
// Handle special cases around `.1` in the `theme(…)`
10+
['[--value:theme(spacing.1)]', '[--value:var(--spacing-1)]'],
11+
['[--value:theme(fontSize.xs.1.lineHeight)]', '[--value:var(--font-size-xs--line-height)]'],
12+
913
// Convert to `var(…)` if we can resolve the path
1014
['[color:theme(colors.red.500)]', '[color:var(--color-red-500)]'], // Arbitrary property
1115
['[color:theme(colors.red.500)]/50', '[color:var(--color-red-500)]/50'], // Arbitrary property + modifier

packages/tailwindcss/src/compat/apply-config-to-theme.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ export function keyPathToCssProperty(path: string[]) {
142142
// [1] should move into the nested object tuple. To create the CSS variable
143143
// name for this, we replace it with an empty string that will result in two
144144
// subsequent dashes when joined.
145-
.map((path) => (path === '1' ? '' : path))
145+
//
146+
// E.g.:
147+
// - `fontSize.xs.1.lineHeight` -> `font-size-xs--line-height`
148+
// - `spacing.1` -> `--spacing-1`
149+
.map((path, idx, all) => (path === '1' && idx !== all.length - 1 ? '' : path))
146150

147151
// Resolve the key path to a CSS variable segment
148152
.map((part) =>

0 commit comments

Comments
 (0)