Skip to content

Commit df62457

Browse files
committed
move migrate-arbitrary-value-to-bare-value to core
1 parent 848dec8 commit df62457

File tree

5 files changed

+239
-252
lines changed

5 files changed

+239
-252
lines changed

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

Lines changed: 0 additions & 68 deletions
This file was deleted.

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

Lines changed: 0 additions & 180 deletions
This file was deleted.

packages/@tailwindcss-upgrade/src/codemods/template/migrate.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { DefaultMap } from '../../../../tailwindcss/src/utils/default-map'
77
import { spliceChangesIntoString, type StringChange } from '../../utils/splice-changes-into-string'
88
import { extractRawCandidates } from './candidates'
99
import { isSafeMigration } from './is-safe-migration'
10-
import { migrateArbitraryValueToBareValue } from './migrate-arbitrary-value-to-bare-value'
1110
import { migrateAutomaticVarInjection } from './migrate-automatic-var-injection'
1211
import { migrateCamelcaseInNamedValue } from './migrate-camelcase-in-named-value'
1312
import { migrateCanonicalizeCandidate } from './migrate-canonicalize-candidate'
@@ -39,7 +38,6 @@ export const DEFAULT_MIGRATIONS: Migration[] = [
3938
migrateAutomaticVarInjection, // sync, v3 → v4
4039
migrateLegacyArbitraryValues, // sync, v3 → v4 (could also consider it a v4 optimization)
4140
migrateModernizeArbitraryValues, // sync, v3 and v4 optimizations, split up?
42-
migrateArbitraryValueToBareValue, // sync, v4 (optimization)
4341
migrateOptimizeModifier, // sync, v4 (optimization)
4442
]
4543

packages/tailwindcss/src/canonicalize-candidates.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,72 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
660660
await expectCanonicalization(input, candidate, expected)
661661
})
662662
})
663+
664+
describe('arbitrary value to bare value', () => {
665+
test.each([
666+
['aspect-[12/34]', 'aspect-12/34'],
667+
['aspect-[1.2/34]', 'aspect-[1.2/34]'],
668+
['col-start-[7]', 'col-start-7'],
669+
['flex-[2]', 'flex-2'], // `flex` is implemented as static and functional utilities
670+
671+
['grid-cols-[subgrid]', 'grid-cols-subgrid'],
672+
['grid-rows-[subgrid]', 'grid-rows-subgrid'],
673+
674+
// Only 50-200% (inclusive) are valid:
675+
// https://developer.mozilla.org/en-US/docs/Web/CSS/font-stretch#percentage
676+
['font-stretch-[50%]', 'font-stretch-50%'],
677+
['font-stretch-[50.5%]', 'font-stretch-[50.5%]'],
678+
['font-stretch-[201%]', 'font-stretch-[201%]'],
679+
['font-stretch-[49%]', 'font-stretch-[49%]'],
680+
// Should stay as-is
681+
['font-stretch-[1/2]', 'font-stretch-[1/2]'],
682+
683+
// Bare value with % is valid for these utilities
684+
['from-[28%]', 'from-28%'],
685+
['via-[28%]', 'via-28%'],
686+
['to-[28%]', 'to-28%'],
687+
['from-[28.5%]', 'from-[28.5%]'],
688+
['via-[28.5%]', 'via-[28.5%]'],
689+
['to-[28.5%]', 'to-[28.5%]'],
690+
691+
// This test in itself is a bit flawed because `text-[1/2]` currently
692+
// generates something. Converting it to `text-1/2` doesn't produce anything.
693+
['text-[1/2]', 'text-[1/2]'],
694+
695+
// Leading is special, because `leading-[123]` is the direct value of 123, but
696+
// `leading-123` maps to `calc(--spacing(123))`.
697+
['leading-[123]', 'leading-[123]'],
698+
699+
['data-[selected]:flex', 'data-selected:flex'],
700+
['data-[foo=bar]:flex', 'data-[foo=bar]:flex'],
701+
702+
['supports-[gap]:flex', 'supports-gap:flex'],
703+
['supports-[display:grid]:flex', 'supports-[display:grid]:flex'],
704+
705+
['group-data-[selected]:flex', 'group-data-selected:flex'],
706+
['group-data-[foo=bar]:flex', 'group-data-[foo=bar]:flex'],
707+
['group-has-data-[selected]:flex', 'group-has-data-selected:flex'],
708+
709+
['aria-[selected]:flex', 'aria-[selected]:flex'],
710+
['aria-[selected="true"]:flex', 'aria-selected:flex'],
711+
['aria-[selected*="true"]:flex', 'aria-[selected*="true"]:flex'],
712+
713+
['group-aria-[selected]:flex', 'group-aria-[selected]:flex'],
714+
['group-aria-[selected="true"]:flex', 'group-aria-selected:flex'],
715+
['group-has-aria-[selected]:flex', 'group-has-aria-[selected]:flex'],
716+
717+
['max-lg:hover:data-[selected]:flex!', 'max-lg:hover:data-selected:flex!'],
718+
[
719+
'data-[selected]:aria-[selected="true"]:aspect-[12/34]',
720+
'data-selected:aria-selected:aspect-12/34',
721+
],
722+
])(testName, async (candidate, expected) => {
723+
let input = css`
724+
@import 'tailwindcss';
725+
`
726+
await expectCanonicalization(input, candidate, expected)
727+
})
728+
})
663729
})
664730

665731
describe('theme to var', () => {

0 commit comments

Comments
 (0)