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
  7a380dd4_2f8e_5aa7_b4ee_bf219cb7807f["migrateArbitraryVariants()"]
  fd9821c7_1a1a_545c_2d82_048fc3c3d870["migrate-arbitrary-variants.ts"]
  7a380dd4_2f8e_5aa7_b4ee_bf219cb7807f -->|defined in| fd9821c7_1a1a_545c_2d82_048fc3c3d870
  26169039_1fd2_e320_1f63_11ec10a6fc52["prepareDesignSystemStorage()"]
  7a380dd4_2f8e_5aa7_b4ee_bf219cb7807f -->|calls| 26169039_1fd2_e320_1f63_11ec10a6fc52
  23c6e5a0_eac4_e9dd_7fcf_1e5c71d28310["cloneCandidate()"]
  7a380dd4_2f8e_5aa7_b4ee_bf219cb7807f -->|calls| 23c6e5a0_eac4_e9dd_7fcf_1e5c71d28310
  fe10eff5_7df3_1553_1351_7802a9ea48a5["printVariant()"]
  7a380dd4_2f8e_5aa7_b4ee_bf219cb7807f -->|calls| fe10eff5_7df3_1553_1351_7802a9ea48a5
  5719096b_0f51_ab16_7fbd_4455f835804c["parseVariant()"]
  7a380dd4_2f8e_5aa7_b4ee_bf219cb7807f -->|calls| 5719096b_0f51_ab16_7fbd_4455f835804c
  38b866f2_6f5f_ed0c_8931_4489835420d2["replaceObject()"]
  7a380dd4_2f8e_5aa7_b4ee_bf219cb7807f -->|calls| 38b866f2_6f5f_ed0c_8931_4489835420d2
  2de86ba2_90a4_8c2d_db18_154bb1a1564f["printCandidate()"]
  7a380dd4_2f8e_5aa7_b4ee_bf219cb7807f -->|calls| 2de86ba2_90a4_8c2d_db18_154bb1a1564f
  bafed062_abf8_7e47_4942_385b21bd9b04["parseCandidate()"]
  7a380dd4_2f8e_5aa7_b4ee_bf219cb7807f -->|calls| bafed062_abf8_7e47_4942_385b21bd9b04
  abd55297_2562_3a6c_6827_3710e8d45c54["walkVariants()"]
  7a380dd4_2f8e_5aa7_b4ee_bf219cb7807f -->|calls| abd55297_2562_3a6c_6827_3710e8d45c54
  style 7a380dd4_2f8e_5aa7_b4ee_bf219cb7807f 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, defined in packages/@tailwindcss-upgrade/src/codemods/template/migrate-arbitrary-variants.ts.
Where is migrateArbitraryVariants() defined?
migrateArbitraryVariants() is defined in packages/@tailwindcss-upgrade/src/codemods/template/migrate-arbitrary-variants.ts at line 13.
What does migrateArbitraryVariants() call?
migrateArbitraryVariants() calls 8 function(s): cloneCandidate, parseCandidate, parseVariant, prepareDesignSystemStorage, printCandidate, printVariant, replaceObject, walkVariants.

Analyze Your Own Codebase

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

Try Supermodel Free