Home / Function/ migrateArbitraryVariants() — tailwindcss Function Reference

migrateArbitraryVariants() — tailwindcss Function Reference

Architecture documentation for the migrateArbitraryVariants() function in migrate-arbitrary-variants.ts from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  c0ed9081_e732_ecfa_0427_6bc0211bcee4["migrateArbitraryVariants()"]
  20406e7c_6ee8_4626_dbef_5b37708f4d30["prepareDesignSystemStorage()"]
  c0ed9081_e732_ecfa_0427_6bc0211bcee4 -->|calls| 20406e7c_6ee8_4626_dbef_5b37708f4d30
  6aa3d960_a2f2_03a4_9eb3_642a5598b141["cloneCandidate()"]
  c0ed9081_e732_ecfa_0427_6bc0211bcee4 -->|calls| 6aa3d960_a2f2_03a4_9eb3_642a5598b141
  49c38785_1012_962e_d353_b5b1d6858132["printVariant()"]
  c0ed9081_e732_ecfa_0427_6bc0211bcee4 -->|calls| 49c38785_1012_962e_d353_b5b1d6858132
  ca76ae68_c9c0_d977_a6d8_8ba86685bf25["parseVariant()"]
  c0ed9081_e732_ecfa_0427_6bc0211bcee4 -->|calls| ca76ae68_c9c0_d977_a6d8_8ba86685bf25
  2d70e77d_ce8f_238d_2b32_a8b4190f2628["replaceObject()"]
  c0ed9081_e732_ecfa_0427_6bc0211bcee4 -->|calls| 2d70e77d_ce8f_238d_2b32_a8b4190f2628
  ec55634f_f6e4_3b8b_1267_0b251c4dade1["printCandidate()"]
  c0ed9081_e732_ecfa_0427_6bc0211bcee4 -->|calls| ec55634f_f6e4_3b8b_1267_0b251c4dade1
  style c0ed9081_e732_ecfa_0427_6bc0211bcee4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/@tailwindcss-upgrade/src/codemods/template/migrate-arbitrary-variants.ts lines 13–51

export function migrateArbitraryVariants(
  baseDesignSystem: DesignSystem,
  _userConfig: Config | null,
  rawCandidate: string,
): string {
  let designSystem = prepareDesignSystemStorage(baseDesignSystem)
  let signatures = designSystem.storage[VARIANT_SIGNATURE_KEY]
  let variants = designSystem.storage[PRE_COMPUTED_VARIANTS_KEY]

  for (let readonlyCandidate of designSystem.parseCandidate(rawCandidate)) {
    // We are only interested in the variants
    if (readonlyCandidate.variants.length <= 0) return rawCandidate

    // The below logic makes use of mutation. Since candidates in the
    // DesignSystem are cached, we can't mutate them directly.
    let candidate = cloneCandidate(readonlyCandidate) as Writable<typeof readonlyCandidate>

    for (let [variant] of walkVariants(candidate)) {
      if (variant.kind === 'compound') continue

      let targetString = designSystem.printVariant(variant)
      let targetSignature = signatures.get(targetString)
      if (typeof targetSignature !== 'string') continue

      let foundVariants = variants.get(targetSignature)
      if (foundVariants.length !== 1) continue

      let foundVariant = foundVariants[0]
      let parsedVariant = designSystem.parseVariant(foundVariant)
      if (parsedVariant === null) continue

      replaceObject(variant, parsedVariant)
    }

    return designSystem.printCandidate(candidate)
  }

  return rawCandidate
}

Subdomains

Frequently Asked Questions

What does migrateArbitraryVariants() do?
migrateArbitraryVariants() is a function in the tailwindcss codebase.
What does migrateArbitraryVariants() call?
migrateArbitraryVariants() calls 6 function(s): cloneCandidate, parseVariant, prepareDesignSystemStorage, printCandidate, printVariant, replaceObject.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free