Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Make themeToVar reusable
  • Loading branch information
RobinMalfait committed Oct 16, 2024
commit 5163a9b910d4e1c69e04cbdaf47d57f6a52c82d9
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { toKeyPath } from '../../../../tailwindcss/src/utils/to-key-path'
import * as ValueParser from '../../../../tailwindcss/src/value-parser'
import { printCandidate } from '../candidates'

enum Convert {
export enum Convert {
All = 0,
MigrateModifier = 1 << 0,
MigrateThemeOnly = 1 << 1,
Expand All @@ -23,6 +23,8 @@ export function themeToVar(
_userConfig: Config,
rawCandidate: string,
): string {
let convert = createConverter(designSystem)

for (let candidate of parseCandidate(rawCandidate, designSystem)) {
let clone = structuredClone(candidate)
let changed = false
Expand Down Expand Up @@ -75,6 +77,10 @@ export function themeToVar(
return changed ? printCandidate(designSystem, clone) : rawCandidate
}

return rawCandidate
}

export function createConverter(designSystem: DesignSystem) {
function convert(input: string, options = Convert.All): [string, CandidateModifier | null] {
let ast = ValueParser.parse(input)

Expand Down Expand Up @@ -209,7 +215,7 @@ export function themeToVar(
return fallback ? `theme(${variable}${modifier}, ${fallback})` : `theme(${variable}${modifier})`
}

return rawCandidate
return convert
}

function substituteFunctionsInValue(
Expand Down