From 26da0b938d5c3d7e5c82267d66238f553b3dde59 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Fri, 18 Oct 2024 22:39:57 +0200 Subject: [PATCH 1/4] migrate `from`, `via`, and `to` arbitrary values to bare values --- .../codemods/arbitrary-value-to-bare-value.test.ts | 5 +++++ .../codemods/arbitrary-value-to-bare-value.ts | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/@tailwindcss-upgrade/src/template/codemods/arbitrary-value-to-bare-value.test.ts b/packages/@tailwindcss-upgrade/src/template/codemods/arbitrary-value-to-bare-value.test.ts index 411f0eb9ee3a..8e8ef970904b 100644 --- a/packages/@tailwindcss-upgrade/src/template/codemods/arbitrary-value-to-bare-value.test.ts +++ b/packages/@tailwindcss-upgrade/src/template/codemods/arbitrary-value-to-bare-value.test.ts @@ -17,6 +17,11 @@ test.each([ // Should stay as-is ['font-stretch-[1/2]', 'font-stretch-[1/2]'], + // Bare value with % is valid for these utilities + ['from-[28%]', 'from-28%'], + ['via-[28%]', 'via-28%'], + ['to-[28%]', 'to-28%'], + // This test in itself is a bit flawed because `text-[1/2]` currently // generates something. Converting it to `text-1/2` doesn't produce anything. ['text-[1/2]', 'text-[1/2]'], diff --git a/packages/@tailwindcss-upgrade/src/template/codemods/arbitrary-value-to-bare-value.ts b/packages/@tailwindcss-upgrade/src/template/codemods/arbitrary-value-to-bare-value.ts index 44aa2675db83..52f3dc4c05c4 100644 --- a/packages/@tailwindcss-upgrade/src/template/codemods/arbitrary-value-to-bare-value.ts +++ b/packages/@tailwindcss-upgrade/src/template/codemods/arbitrary-value-to-bare-value.ts @@ -14,16 +14,24 @@ export function arbitraryValueToBareValue( let clone = structuredClone(candidate) let changed = false - // Convert font-stretch-* utilities + // Convert utilities that accept bare values ending in % if ( clone.kind === 'functional' && clone.value?.kind === 'arbitrary' && clone.value.dataType === null && - clone.root === 'font-stretch' + (clone.root === 'from' || + clone.root === 'via' || + clone.root === 'to' || + clone.root === 'font-stretch') ) { if (clone.value.value.endsWith('%') && isPositiveInteger(clone.value.value.slice(0, -1))) { let percentage = parseInt(clone.value.value) - if (percentage >= 50 && percentage <= 200) { + if ( + clone.root === 'from' || + clone.root === 'via' || + clone.root === 'to' || + (clone.root === 'font-stretch' && percentage >= 50 && percentage <= 200) + ) { changed = true clone.value = { kind: 'named', From 4f8bb3b929d7757d39cbdbdcfeac41aed6d5abbd Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Fri, 18 Oct 2024 22:45:31 +0200 Subject: [PATCH 2/4] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bbc4667aa93..64f3152fefce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Allow spaces spaces around operators in attribute selector variants ([#14703](https://github.com/tailwindlabs/tailwindcss/pull/14703)) - _Upgrade (experimental)_: Migrate `flex-grow` to `grow` and `flex-shrink` to `shrink` ([#14721](https://github.com/tailwindlabs/tailwindcss/pull/14721)) - _Upgrade (experimental)_: Minify arbitrary values when printing candidates ([#14720](https://github.com/tailwindlabs/tailwindcss/pull/14720)) +- _Upgrade (experimental)_: Migrate arbitrary values to bare values for the `from-*`, `via-*`, and `to-*` utilities ([robin/m](https://github.com/tailwindlabs/tailwindcss/commit/26da0b938d5c3d7e5c82267d66238f553b3dde59)) ### Changed From fd13d433ca7ad8d8bea24857403f0948ad15730f Mon Sep 17 00:00:00 2001 From: Adam Wathan <4323180+adamwathan@users.noreply.github.com> Date: Sat, 19 Oct 2024 08:16:17 -0400 Subject: [PATCH 3/4] Add tests for non-whole numbers --- .../template/codemods/arbitrary-value-to-bare-value.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/@tailwindcss-upgrade/src/template/codemods/arbitrary-value-to-bare-value.test.ts b/packages/@tailwindcss-upgrade/src/template/codemods/arbitrary-value-to-bare-value.test.ts index 8e8ef970904b..273d8114f5e8 100644 --- a/packages/@tailwindcss-upgrade/src/template/codemods/arbitrary-value-to-bare-value.test.ts +++ b/packages/@tailwindcss-upgrade/src/template/codemods/arbitrary-value-to-bare-value.test.ts @@ -21,6 +21,9 @@ test.each([ ['from-[28%]', 'from-28%'], ['via-[28%]', 'via-28%'], ['to-[28%]', 'to-28%'], + ['from-[28.5%]', 'from-[28.5%]'], + ['via-[28.5%]', 'via-[28.5%]'], + ['to-[28.5%]', 'to-[28.5%]'], // This test in itself is a bit flawed because `text-[1/2]` currently // generates something. Converting it to `text-1/2` doesn't produce anything. From e7ff42d2a3f2ef9e647769837a81f5a4af94e84a Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Sat, 19 Oct 2024 09:05:06 -0400 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64f3152fefce..e4ab8ed4103c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Allow spaces spaces around operators in attribute selector variants ([#14703](https://github.com/tailwindlabs/tailwindcss/pull/14703)) - _Upgrade (experimental)_: Migrate `flex-grow` to `grow` and `flex-shrink` to `shrink` ([#14721](https://github.com/tailwindlabs/tailwindcss/pull/14721)) - _Upgrade (experimental)_: Minify arbitrary values when printing candidates ([#14720](https://github.com/tailwindlabs/tailwindcss/pull/14720)) -- _Upgrade (experimental)_: Migrate arbitrary values to bare values for the `from-*`, `via-*`, and `to-*` utilities ([robin/m](https://github.com/tailwindlabs/tailwindcss/commit/26da0b938d5c3d7e5c82267d66238f553b3dde59)) +- _Upgrade (experimental)_: Migrate arbitrary values to bare values for the `from-*`, `via-*`, and `to-*` utilities ([#14725](https://github.com/tailwindlabs/tailwindcss/pull/14725)) ### Changed