@@ -5,6 +5,7 @@ import type { Config } from 'tailwindcss'
55import type { DesignSystem } from '../../../../tailwindcss/src/design-system'
66import { DefaultMap } from '../../../../tailwindcss/src/utils/default-map'
77import { printCandidate } from '../candidates'
8+ import { isSafeMigration } from '../is-safe-migration'
89
910const __filename = url . fileURLToPath ( import . meta. url )
1011const __dirname = path . dirname ( __filename )
@@ -56,6 +57,11 @@ export async function legacyClasses(
5657 designSystem : DesignSystem ,
5758 _userConfig : Config ,
5859 rawCandidate : string ,
60+ location ?: {
61+ contents : string
62+ start : number
63+ end : number
64+ } ,
5965) : Promise < string > {
6066 // Ensure the "old" classes exist as static utilities to make the migration
6167 // easier because the "root" will point to the full class.
@@ -70,13 +76,14 @@ export async function legacyClasses(
7076
7177 for ( let candidate of designSystem . parseCandidate ( rawCandidate ) ) {
7278 if ( candidate . kind === 'static' && Object . hasOwn ( LEGACY_CLASS_MAP , candidate . root ) ) {
79+ let newRoot = LEGACY_CLASS_MAP [ candidate . root as keyof typeof LEGACY_CLASS_MAP ]
80+
81+ if ( location && ! candidate . root . includes ( '-' ) && ! isSafeMigration ( location ) ) {
82+ continue
83+ }
84+
7385 let fromThemeKey = THEME_KEYS [ candidate . root as keyof typeof THEME_KEYS ]
74- let toThemeKey =
75- THEME_KEYS [
76- LEGACY_CLASS_MAP [
77- candidate . root as keyof typeof LEGACY_CLASS_MAP
78- ] as keyof typeof THEME_KEYS
79- ]
86+ let toThemeKey = THEME_KEYS [ newRoot as keyof typeof THEME_KEYS ]
8087
8188 if ( fromThemeKey && toThemeKey ) {
8289 // Migrating something that resolves to a value in the theme.
@@ -104,7 +111,7 @@ export async function legacyClasses(
104111
105112 return printCandidate ( designSystem , {
106113 ...candidate ,
107- root : LEGACY_CLASS_MAP [ candidate . root as keyof typeof LEGACY_CLASS_MAP ] ,
114+ root : newRoot ,
108115 } )
109116 }
110117 }
0 commit comments