migrate-theme-to-var.ts — tailwindcss Source File
Architecture documentation for migrate-theme-to-var.ts, a typescript file in the tailwindcss codebase. 15 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR c36efdeb_7fd2_0935_2c28_bf15095a9dd9["migrate-theme-to-var.ts"] ba6fca27_7720_5839_0f92_bc2abb8db636["candidate.ts"] c36efdeb_7fd2_0935_2c28_bf15095a9dd9 --> ba6fca27_7720_5839_0f92_bc2abb8db636 8d84257d_f3b2_cdf8_542f_835967da0481["apply-config-to-theme.ts"] c36efdeb_7fd2_0935_2c28_bf15095a9dd9 --> 8d84257d_f3b2_cdf8_542f_835967da0481 1767219e_c38a_227c_492b_5d47634d54a4["keyPathToCssProperty"] c36efdeb_7fd2_0935_2c28_bf15095a9dd9 --> 1767219e_c38a_227c_492b_5d47634d54a4 bdedd2f6_da4b_69dc_e990_0814b59fbe6e["design-system.ts"] c36efdeb_7fd2_0935_2c28_bf15095a9dd9 --> bdedd2f6_da4b_69dc_e990_0814b59fbe6e 665aa4ed_d86e_30e5_80d5_cd56b8ca8b62["DesignSystem"] c36efdeb_7fd2_0935_2c28_bf15095a9dd9 --> 665aa4ed_d86e_30e5_80d5_cd56b8ca8b62 43fe4735_10e8_ed1d_6f4f_74b2008c1b00["infer-data-type.ts"] c36efdeb_7fd2_0935_2c28_bf15095a9dd9 --> 43fe4735_10e8_ed1d_6f4f_74b2008c1b00 09df19e7_0346_145d_40c4_e93ff14a2ff9["isValidSpacingMultiplier"] c36efdeb_7fd2_0935_2c28_bf15095a9dd9 --> 09df19e7_0346_145d_40c4_e93ff14a2ff9 bb9924cc_8308_a1f9_0e30_76de45a64970["segment.ts"] c36efdeb_7fd2_0935_2c28_bf15095a9dd9 --> bb9924cc_8308_a1f9_0e30_76de45a64970 c58cbb33_f3cc_0b4f_844a_15bf66a1dc61["segment"] c36efdeb_7fd2_0935_2c28_bf15095a9dd9 --> c58cbb33_f3cc_0b4f_844a_15bf66a1dc61 1f643124_89df_1d95_f8fd_e4036c7301de["to-key-path.ts"] c36efdeb_7fd2_0935_2c28_bf15095a9dd9 --> 1f643124_89df_1d95_f8fd_e4036c7301de 05d44181_6631_c1fa_4a63_96653e28f99c["toKeyPath"] c36efdeb_7fd2_0935_2c28_bf15095a9dd9 --> 05d44181_6631_c1fa_4a63_96653e28f99c d9175aea_5971_a6c1_773d_004ce3789372["value-parser.ts"] c36efdeb_7fd2_0935_2c28_bf15095a9dd9 --> d9175aea_5971_a6c1_773d_004ce3789372 1b8f1c54_b1e9_e18d_0719_b7ad92808185["walk.ts"] c36efdeb_7fd2_0935_2c28_bf15095a9dd9 --> 1b8f1c54_b1e9_e18d_0719_b7ad92808185 4982d9ce_98d4_85d9_44af_7cc47b93c482["walk"] c36efdeb_7fd2_0935_2c28_bf15095a9dd9 --> 4982d9ce_98d4_85d9_44af_7cc47b93c482 style c36efdeb_7fd2_0935_2c28_bf15095a9dd9 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { type CandidateModifier } from '../../../../tailwindcss/src/candidate'
import { keyPathToCssProperty } from '../../../../tailwindcss/src/compat/apply-config-to-theme'
import type { DesignSystem } from '../../../../tailwindcss/src/design-system'
import { isValidSpacingMultiplier } from '../../../../tailwindcss/src/utils/infer-data-type'
import { segment } from '../../../../tailwindcss/src/utils/segment'
import { toKeyPath } from '../../../../tailwindcss/src/utils/to-key-path'
import * as ValueParser from '../../../../tailwindcss/src/value-parser'
import { walk, WalkAction } from '../../../../tailwindcss/src/walk'
export const enum Convert {
All = 0,
MigrateModifier = 1 << 0,
MigrateThemeOnly = 1 << 1,
}
export function createConverter(designSystem: DesignSystem, { prettyPrint = false } = {}) {
function convert(input: string, options = Convert.All): [string, CandidateModifier | null] {
let ast = ValueParser.parse(input)
// In some scenarios (e.g.: variants), we can't migrate to `var(…)` if it
// ends up in the `@media (…)` part. In this case we only have to migrate to
// the new `theme(…)` notation.
if (options & Convert.MigrateThemeOnly) {
return [substituteFunctionsInValue(ast, toTheme), null]
}
let themeUsageCount = 0
let themeModifierCount = 0
// Analyze AST
walk(ast, (node) => {
if (node.kind !== 'function') return
if (node.value !== 'theme') return
// We are only interested in the `theme` function
themeUsageCount += 1
// Figure out if a modifier is used
walk(node.nodes, (child) => {
// If we see a `,`, it means that we have a fallback value
if (child.kind === 'separator' && child.value.includes(',')) {
return WalkAction.Stop
}
// If we see a `/`, we have a modifier
else if (child.kind === 'word' && child.value === '/') {
themeModifierCount += 1
return WalkAction.Stop
}
return WalkAction.Skip
})
})
// No `theme(…)` calls, nothing to do
if (themeUsageCount === 0) {
return [input, null]
}
// No `theme(…)` with modifiers, we can migrate to `var(…)`
// ... (211 more lines)
Domain
Subdomains
Types
Dependencies
Source
Frequently Asked Questions
What does migrate-theme-to-var.ts do?
migrate-theme-to-var.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the CommandLineInterface domain, Codemods subdomain.
What functions are defined in migrate-theme-to-var.ts?
migrate-theme-to-var.ts defines 3 function(s): createConverter, eventuallyUnquote, substituteFunctionsInValue.
What does migrate-theme-to-var.ts depend on?
migrate-theme-to-var.ts imports 15 module(s): DesignSystem, WalkAction, apply-config-to-theme.ts, candidate.ts, design-system.ts, infer-data-type.ts, isValidSpacingMultiplier, keyPathToCssProperty, and 7 more.
What files import migrate-theme-to-var.ts?
migrate-theme-to-var.ts is imported by 1 file(s): migrate-theme-to-var.ts.
Where is migrate-theme-to-var.ts in the architecture?
migrate-theme-to-var.ts is located at packages/@tailwindcss-upgrade/src/codemods/template/migrate-theme-to-var.ts (domain: CommandLineInterface, subdomain: Codemods, directory: packages/@tailwindcss-upgrade/src/codemods/template).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free