migrateLegacyClasses() — tailwindcss Function Reference
Architecture documentation for the migrateLegacyClasses() function in migrate-legacy-classes.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD e23cd15e_fdc1_d590_bce2_3d2a9c41fd9f["migrateLegacyClasses()"] b221facd_4d62_d2ce_4a2c_e77999b7a5ae["migrate-legacy-classes.ts"] e23cd15e_fdc1_d590_bce2_3d2a9c41fd9f -->|defined in| b221facd_4d62_d2ce_4a2c_e77999b7a5ae 6cf757d4_aaad_b18d_cf21_ade24c6e2a77["isMajor()"] e23cd15e_fdc1_d590_bce2_3d2a9c41fd9f -->|calls| 6cf757d4_aaad_b18d_cf21_ade24c6e2a77 2820372c_b982_9e06_fc23_f8f4ac308d00["get()"] e23cd15e_fdc1_d590_bce2_3d2a9c41fd9f -->|calls| 2820372c_b982_9e06_fc23_f8f4ac308d00 38a143bb_9140_60f2_b4a1_d6d91e416924["baseCandidate()"] e23cd15e_fdc1_d590_bce2_3d2a9c41fd9f -->|calls| 38a143bb_9140_60f2_b4a1_d6d91e416924 2de86ba2_90a4_8c2d_db18_154bb1a1564f["printCandidate()"] e23cd15e_fdc1_d590_bce2_3d2a9c41fd9f -->|calls| 2de86ba2_90a4_8c2d_db18_154bb1a1564f 23c6e5a0_eac4_e9dd_7fcf_1e5c71d28310["cloneCandidate()"] e23cd15e_fdc1_d590_bce2_3d2a9c41fd9f -->|calls| 23c6e5a0_eac4_e9dd_7fcf_1e5c71d28310 6d639fbb_ba96_11f9_311c_de088fe027c4["parseCandidate()"] e23cd15e_fdc1_d590_bce2_3d2a9c41fd9f -->|calls| 6d639fbb_ba96_11f9_311c_de088fe027c4 style e23cd15e_fdc1_d590_bce2_3d2a9c41fd9f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/@tailwindcss-upgrade/src/codemods/template/migrate-legacy-classes.ts lines 70–144
export async function migrateLegacyClasses(
designSystem: DesignSystem,
_userConfig: Config | null,
rawCandidate: string,
): Promise<string> {
// These migrations are only safe when migrating from v3 to v4.
//
// Migrating from `rounded` to `rounded-sm` once is fine (v3 -> v4). But if we
// migrate again (v4 -> v4), then `rounded-sm` would be migrated to
// `rounded-xs` which is incorrect because we already migrated this.
if (!version.isMajor(3)) {
return rawCandidate
}
let defaultDesignSystem = await DESIGN_SYSTEMS.get(__dirname)
function* migrate(rawCandidate: string) {
for (let candidate of designSystem.parseCandidate(rawCandidate)) {
// Create a base candidate string from the candidate.
// E.g.: `hover:blur!` -> `blur`
let base = baseCandidate(candidate)
let baseCandidateString = designSystem.printCandidate(base)
// Find the new base candidate string. `blur` -> `blur-sm`
let newBaseCandidateString = LEGACY_CLASS_MAP.get(baseCandidateString)
if (!newBaseCandidateString) continue
// Parse the new base candidate string into an actual candidate AST.
let [newBaseCandidate] = designSystem.parseCandidate(newBaseCandidateString)
if (!newBaseCandidate) continue
// Re-apply the variants and important flag from the original candidate.
// E.g.: `hover:blur!` -> `blur` -> `blur-sm` -> `hover:blur-sm!`
let newCandidate = cloneCandidate(newBaseCandidate) as Candidate
newCandidate.variants = candidate.variants
newCandidate.important = candidate.important
yield [
newCandidate,
THEME_KEYS.get(baseCandidateString),
THEME_KEYS.get(newBaseCandidateString),
] as const
}
}
for (let [toCandidate, fromThemeKey, toThemeKey] of migrate(rawCandidate)) {
if (fromThemeKey && toThemeKey) {
// Migrating something that resolves to a value in the theme.
let customFrom = designSystem.resolveThemeValue(fromThemeKey, true)
let defaultFrom = defaultDesignSystem.resolveThemeValue(fromThemeKey, true)
let customTo = designSystem.resolveThemeValue(toThemeKey, true)
let defaultTo = defaultDesignSystem.resolveThemeValue(toThemeKey)
// The new theme value is not defined, which means we can't safely
// migrate the utility.
if (customTo === undefined && defaultTo !== undefined) {
continue
}
// The "from" theme value changed compared to the default theme value.
if (customFrom !== defaultFrom) {
continue
}
// The "to" theme value changed compared to the default theme value.
if (customTo !== defaultTo) {
continue
}
}
return designSystem.printCandidate(toCandidate)
}
return rawCandidate
}
Domain
Subdomains
Source
Frequently Asked Questions
What does migrateLegacyClasses() do?
migrateLegacyClasses() is a function in the tailwindcss codebase, defined in packages/@tailwindcss-upgrade/src/codemods/template/migrate-legacy-classes.ts.
Where is migrateLegacyClasses() defined?
migrateLegacyClasses() is defined in packages/@tailwindcss-upgrade/src/codemods/template/migrate-legacy-classes.ts at line 70.
What does migrateLegacyClasses() call?
migrateLegacyClasses() calls 6 function(s): baseCandidate, cloneCandidate, get, isMajor, parseCandidate, printCandidate.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free