From baed3aabe21bd0fad8e54955c0bdcebd128bb3d8 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Fri, 1 Nov 2024 21:25:53 +0100 Subject: [PATCH] Migrate `grid-cols-[subgrid]` and `grid-rows-[subgrid]` to `grid-cols-subgrid` and `grid-rows-subgrid` (#14840) This PR adds a migration to convert `grid-cols-[subgrid]` to `grid-cols-subgrid` and `grid-rows-[subgrid]` to `grid-rows-subgrid`. --- CHANGELOG.md | 4 ++++ .../arbitrary-value-to-bare-value.test.ts | 3 +++ .../codemods/arbitrary-value-to-bare-value.ts | 15 +++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0df2544b9b59..53e8562893da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- _Upgrade (experimental)_: Migrate `grid-cols-[subgrid]` and `grid-rows-[subgrid]` to `grid-cols-subgrid` and `grid-rows-subgrid` ([#14840](https://github.com/tailwindlabs/tailwindcss/pull/14840)) + ### Fixed - Detect classes in new files when using `@tailwindcss/postcss` ([#14829](https://github.com/tailwindlabs/tailwindcss/pull/14829)) 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 273d8114f5e8..62355dc6f3f1 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 @@ -8,6 +8,9 @@ test.each([ ['col-start-[7]', 'col-start-7'], ['flex-[2]', 'flex-2'], // `flex` is implemented as static and functional utilities + ['grid-cols-[subgrid]', 'grid-cols-subgrid'], + ['grid-rows-[subgrid]', 'grid-rows-subgrid'], + // Only 50-200% (inclusive) are valid: // https://developer.mozilla.org/en-US/docs/Web/CSS/font-stretch#percentage ['font-stretch-[50%]', 'font-stretch-50%'], 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 52f3dc4c05c4..fb3d1b6025e0 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,6 +14,21 @@ export function arbitraryValueToBareValue( let clone = structuredClone(candidate) let changed = false + // Convert [subgrid] to subgrid + if ( + clone.kind === 'functional' && + clone.value?.kind === 'arbitrary' && + clone.value.value === 'subgrid' && + (clone.root === 'grid-cols' || clone.root == 'grid-rows') + ) { + changed = true + clone.value = { + kind: 'named', + value: 'subgrid', + fraction: null, + } + } + // Convert utilities that accept bare values ending in % if ( clone.kind === 'functional' &&