Skip to content

Commit fd8315b

Browse files
Migrate from, via, and to arbitrary values to bare values (#14725)
This PR migrates arbitrary values for the `from-*`, `via-*` and `to-*` utilities to bare values. Input: ```html <div class="from-[28%]"></div> <div class="via-[28%]"></div> <div class="to-[28%]"></div> ``` Output: ```html <div class="from-28%"></div> <div class="via-28%"></div> <div class="to-28%"></div> ``` --------- Co-authored-by: Adam Wathan <[email protected]> Co-authored-by: Adam Wathan <[email protected]>
1 parent 2abf228 commit fd8315b

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Allow spaces spaces around operators in attribute selector variants ([#14703](https://github.com/tailwindlabs/tailwindcss/pull/14703))
1717
- _Upgrade (experimental)_: Migrate `flex-grow` to `grow` and `flex-shrink` to `shrink` ([#14721](https://github.com/tailwindlabs/tailwindcss/pull/14721))
1818
- _Upgrade (experimental)_: Minify arbitrary values when printing candidates ([#14720](https://github.com/tailwindlabs/tailwindcss/pull/14720))
19+
- _Upgrade (experimental)_: Migrate arbitrary values to bare values for the `from-*`, `via-*`, and `to-*` utilities ([#14725](https://github.com/tailwindlabs/tailwindcss/pull/14725))
1920

2021
### Changed
2122

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ test.each([
1717
// Should stay as-is
1818
['font-stretch-[1/2]', 'font-stretch-[1/2]'],
1919

20+
// Bare value with % is valid for these utilities
21+
['from-[28%]', 'from-28%'],
22+
['via-[28%]', 'via-28%'],
23+
['to-[28%]', 'to-28%'],
24+
['from-[28.5%]', 'from-[28.5%]'],
25+
['via-[28.5%]', 'via-[28.5%]'],
26+
['to-[28.5%]', 'to-[28.5%]'],
27+
2028
// This test in itself is a bit flawed because `text-[1/2]` currently
2129
// generates something. Converting it to `text-1/2` doesn't produce anything.
2230
['text-[1/2]', 'text-[1/2]'],

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,24 @@ export function arbitraryValueToBareValue(
1414
let clone = structuredClone(candidate)
1515
let changed = false
1616

17-
// Convert font-stretch-* utilities
17+
// Convert utilities that accept bare values ending in %
1818
if (
1919
clone.kind === 'functional' &&
2020
clone.value?.kind === 'arbitrary' &&
2121
clone.value.dataType === null &&
22-
clone.root === 'font-stretch'
22+
(clone.root === 'from' ||
23+
clone.root === 'via' ||
24+
clone.root === 'to' ||
25+
clone.root === 'font-stretch')
2326
) {
2427
if (clone.value.value.endsWith('%') && isPositiveInteger(clone.value.value.slice(0, -1))) {
2528
let percentage = parseInt(clone.value.value)
26-
if (percentage >= 50 && percentage <= 200) {
29+
if (
30+
clone.root === 'from' ||
31+
clone.root === 'via' ||
32+
clone.root === 'to' ||
33+
(clone.root === 'font-stretch' && percentage >= 50 && percentage <= 200)
34+
) {
2735
changed = true
2836
clone.value = {
2937
kind: 'named',

0 commit comments

Comments
 (0)