Skip to content

Commit 0b5736f

Browse files
Remove whitespace around , separator (#14838)
This PR is an improvement/fix by making sure that whitespace around the `,` separator is removed when printing arbitrary values. Before: ```diff - <div class="grid-cols-[min(50%,theme(spacing.80))_auto]"></div> + <div class="grid-cols-[min(50%,_var(--spacing-80))_auto]"></div> ``` After: ```diff - <div class="grid-cols-[min(50%,theme(spacing.80))_auto]"></div> + <div class="grid-cols-[min(50%,var(--spacing-80))_auto]"></div> ``` --------- Co-authored-by: Jordan Pittman <jordan@cryptica.me>
1 parent 92007a5 commit 0b5736f

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Detect classes in new files when using `@tailwindcss/postcss` ([#14829](https://github.com/tailwindlabs/tailwindcss/pull/14829))
1313
- Fix crash when using `@source` containing `..` ([#14831](https://github.com/tailwindlabs/tailwindcss/pull/14831))
1414
- _Upgrade (experimental)_: Install `@tailwindcss/postcss` next to `tailwindcss` ([#14830](https://github.com/tailwindlabs/tailwindcss/pull/14830))
15+
- _Upgrade (experimental)_: Remove whitespace around `,` separator when print arbitrary values ([#14838](https://github.com/tailwindlabs/tailwindcss/pull/14838))
1516

1617
## [4.0.0-alpha.31] - 2024-10-29
1718

packages/@tailwindcss-upgrade/src/template/candidates.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ const candidates = [
123123
['bg-[no-repeat_url(/image_13.png)]', 'bg-[no-repeat_url(/image_13.png)]'],
124124
[
125125
'bg-[var(--spacing-0_5,_var(--spacing-1_5,_3rem))]',
126-
'bg-[var(--spacing-0_5,_var(--spacing-1_5,_3rem))]',
126+
'bg-[var(--spacing-0_5,var(--spacing-1_5,3rem))]',
127127
],
128128
]
129129

packages/@tailwindcss-upgrade/src/template/candidates.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ function printArbitraryValue(input: string) {
176176
drop.add(node)
177177
}
178178
}
179+
180+
// Whitespace around `,` separators can be removed.
181+
// E.g.: `min(1px , 2px)` -> `min(1px,2px)`
182+
else if (node.kind === 'separator' && node.value.trim() === ',') {
183+
node.value = ','
184+
}
179185
})
180186

181187
if (drop.size > 0) {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test.each([
1717
['bg-[size:theme(spacing.4)]', 'bg-[size:var(--spacing-4)]'], // Arbitrary value + data type hint
1818

1919
// Convert to `var(…)` if we can resolve the path, but keep fallback values
20-
['bg-[theme(colors.red.500,red)]', 'bg-[var(--color-red-500,_red)]'],
20+
['bg-[theme(colors.red.500,red)]', 'bg-[var(--color-red-500,red)]'],
2121

2222
// Keep `theme(…)` if we can't resolve the path
2323
['bg-[theme(colors.foo.1000)]', 'bg-[theme(colors.foo.1000)]'],
@@ -41,11 +41,11 @@ test.each([
4141
// to a candidate modifier _if_ all `theme(…)` calls use the same modifier.
4242
[
4343
'[color:theme(colors.red.500/50,theme(colors.blue.500/50))]',
44-
'[color:theme(--color-red-500/50,_theme(--color-blue-500/50))]',
44+
'[color:theme(--color-red-500/50,theme(--color-blue-500/50))]',
4545
],
4646
[
4747
'[color:theme(colors.red.500/50,theme(colors.blue.500/50))]/50',
48-
'[color:theme(--color-red-500/50,_theme(--color-blue-500/50))]/50',
48+
'[color:theme(--color-red-500/50,theme(--color-blue-500/50))]/50',
4949
],
5050

5151
// Convert the `theme(…)`, but try to move the inline modifier (e.g. `50%`),
@@ -83,6 +83,10 @@ test.each([
8383
// that this doesn't end up as the modifier in the candidate itself.
8484
['max-[theme(spacing.4/50)]:flex', 'max-[theme(--spacing-4/50)]:flex'],
8585

86+
// `theme(…)` calls in another CSS function is replaced correctly.
87+
// Additionally we remove unnecessary whitespace.
88+
['grid-cols-[min(50%_,_theme(spacing.80))_auto]', 'grid-cols-[min(50%,var(--spacing-80))_auto]'],
89+
8690
// `theme(…)` calls valid in v3, but not in v4 should still be converted.
8791
['[--foo:theme(fontWeight.semibold)]', '[--foo:theme(fontWeight.semibold)]'],
8892

0 commit comments

Comments
 (0)