Skip to content

Commit 3da9d61

Browse files
authored
Correctly migrate leading-* classes (#16004)
This PR fixes the upgrade tool by properly migrating the `leading-[<number>]` classes. The issue is that `leading-[<number>]` maps to the number directly, but if you use a bare value, then it's a multiplier for based on the `--spacing` value. E.g.: *leading-[2]*: ```css .leading-\[2\] { --tw-leading: 2; line-height: 2; } @Property --tw-leading { syntax: "*"; inherits: false; } ``` *leading-2*: ```css .leading-2 { --tw-leading: calc(var(--spacing) * 2); line-height: calc(var(--spacing) * 2); } @Property --tw-leading { syntax: "*"; inherits: false; } ``` This PR will now prevent migrating arbitrary values to bare values for `leading-*` utilities. That said, this does introduce a small improvement where `leading-[1]` is migrated to `leading-none`. Fixes: #15924
1 parent 125c089 commit 3da9d61

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2828
- Ensure that `@tailwindcss/browser` does not pollute the global namespace ([#15978](https://github.com/tailwindlabs/tailwindcss/pull/15978))
2929
- Fix crash when project lives in the `/` directory ([#15988](https://github.com/tailwindlabs/tailwindcss/pull/15988))
3030
- _Upgrade_: Ensure JavaScript config files on different drives are correctly migrated ([#15927](https://github.com/tailwindlabs/tailwindcss/pull/15927))
31+
- _Upgrade_: Migrate `leading-[1]` to `leading-none` ([#16004](https://github.com/tailwindlabs/tailwindcss/pull/16004))
32+
- _Upgrade_: Do not migrate arbitrary leading utilities to bare utilities ([#16004](https://github.com/tailwindlabs/tailwindcss/pull/16004))
3133

3234
## [4.0.0] - 2025-01-21
3335

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ test.each([
3232
// generates something. Converting it to `text-1/2` doesn't produce anything.
3333
['text-[1/2]', 'text-[1/2]'],
3434

35+
// Leading is special, because `leading-[123]` is the direct value of 123, but
36+
// `leading-123` maps to `calc(--spacing(123))`.
37+
['leading-[1]', 'leading-none'],
38+
['leading-[123]', 'leading-[123]'],
39+
3540
['data-[selected]:flex', 'data-selected:flex'],
3641
['data-[foo=bar]:flex', 'data-[foo=bar]:flex'],
3742

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,23 @@ export function arbitraryValueToBareValue(
6464
clone.value?.kind === 'arbitrary' &&
6565
clone.value.dataType === null
6666
) {
67+
if (clone.root === 'leading') {
68+
// leading-[1] -> leading-none
69+
if (clone.value.value === '1') {
70+
changed = true
71+
clone.value = {
72+
kind: 'named',
73+
value: 'none',
74+
fraction: null,
75+
}
76+
}
77+
78+
// Keep leading-[<number>] as leading-[<number>]
79+
else {
80+
continue
81+
}
82+
}
83+
6784
let parts = segment(clone.value.value, '/')
6885
if (parts.every((part) => isPositiveInteger(part))) {
6986
changed = true

0 commit comments

Comments
 (0)