createConverterCache() — tailwindcss Function Reference
Architecture documentation for the createConverterCache() function in canonicalize-candidates.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD 77acef4a_feff_6e9f_7c6b_2b6942c9ad63["createConverterCache()"] 7d350d81_5de1_f9f3_5b2c_19ec8fd3c37e["canonicalize-candidates.ts"] 77acef4a_feff_6e9f_7c6b_2b6942c9ad63 -->|defined in| 7d350d81_5de1_f9f3_5b2c_19ec8fd3c37e 81ec8f98_1fb2_d7c3_dd65_3a9e51b3be39["prepareDesignSystemStorage()"] 81ec8f98_1fb2_d7c3_dd65_3a9e51b3be39 -->|calls| 77acef4a_feff_6e9f_7c6b_2b6942c9ad63 80648867_f6ce_78f3_6e5a_59822ca19561["substituteFunctionsInValue()"] 77acef4a_feff_6e9f_7c6b_2b6942c9ad63 -->|calls| 80648867_f6ce_78f3_6e5a_59822ca19561 f712ed47_45d4_4e5a_dd73_fdefa1da71da["segment()"] 77acef4a_feff_6e9f_7c6b_2b6942c9ad63 -->|calls| f712ed47_45d4_4e5a_dd73_fdefa1da71da ae20c4fb_29d7_ca79_3c49_ca02c45d5369["keyPathToCssProperty()"] 77acef4a_feff_6e9f_7c6b_2b6942c9ad63 -->|calls| ae20c4fb_29d7_ca79_3c49_ca02c45d5369 1b250eae_0bea_d404_ca9e_42da26c56b45["toKeyPath()"] 77acef4a_feff_6e9f_7c6b_2b6942c9ad63 -->|calls| 1b250eae_0bea_d404_ca9e_42da26c56b45 a15b3c4a_76ff_0090_fc86_bac24f0a4135["isValidSpacingMultiplier()"] 77acef4a_feff_6e9f_7c6b_2b6942c9ad63 -->|calls| a15b3c4a_76ff_0090_fc86_bac24f0a4135 ed78da58_8727_ad98_120c_61f35cea357a["walk()"] 77acef4a_feff_6e9f_7c6b_2b6942c9ad63 -->|calls| ed78da58_8727_ad98_120c_61f35cea357a 5bcf4886_1230_a8ff_7302_a26cc5a9a525["get()"] 77acef4a_feff_6e9f_7c6b_2b6942c9ad63 -->|calls| 5bcf4886_1230_a8ff_7302_a26cc5a9a525 b9517e77_a36f_4751_899c_27d813f3dbb3["parse()"] 77acef4a_feff_6e9f_7c6b_2b6942c9ad63 -->|calls| b9517e77_a36f_4751_899c_27d813f3dbb3 style 77acef4a_feff_6e9f_7c6b_2b6942c9ad63 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/tailwindcss/src/canonicalize-candidates.ts lines 640–799
function createConverterCache(
designSystem: DesignSystem,
): DesignSystem['storage'][typeof CONVERTER_KEY] {
return createConverter(designSystem)
function createConverter(designSystem: DesignSystem) {
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(…)`
if (themeModifierCount === 0) {
return [substituteFunctionsInValue(ast, toVar), null]
}
// Multiple modifiers which means that there are multiple `theme(…/…)`
// values. In this case, we can't convert the modifier to a candidate
// modifier.
//
// We also can't migrate to `var(…)` because that would lose the modifier.
//
// Try to convert each `theme(…)` call to the modern syntax.
if (themeModifierCount > 1) {
return [substituteFunctionsInValue(ast, toTheme), null]
}
// Only a single `theme(…)` with a modifier left, that modifier will be
// migrated to a candidate modifier.
let modifier: CandidateModifier | null = null
let result = substituteFunctionsInValue(ast, (path, fallback) => {
let parts = segment(path, '/').map((part) => part.trim())
// Multiple `/` separators, which makes this an invalid path
if (parts.length > 2) return null
// The path contains a `/`, which means that there is a modifier such as
// `theme(colors.red.500/50%)`.
//
// Currently, we are assuming that this is only being used for colors,
// which means that we can typically convert them to a modifier on the
// candidate itself.
//
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does createConverterCache() do?
createConverterCache() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/canonicalize-candidates.ts.
Where is createConverterCache() defined?
createConverterCache() is defined in packages/tailwindcss/src/canonicalize-candidates.ts at line 640.
What does createConverterCache() call?
createConverterCache() calls 8 function(s): get, isValidSpacingMultiplier, keyPathToCssProperty, parse, segment, substituteFunctionsInValue, toKeyPath, walk.
What calls createConverterCache()?
createConverterCache() is called by 1 function(s): prepareDesignSystemStorage.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free