Home / File/ migrate-arbitrary-variants.ts — tailwindcss Source File

migrate-arbitrary-variants.ts — tailwindcss Source File

Architecture documentation for migrate-arbitrary-variants.ts, a typescript file in the tailwindcss codebase. 11 imports, 1 dependents.

File typescript UpgradeToolkit Codemods 11 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  dfcf938d_abe9_684f_720a_29a0a1797759["migrate-arbitrary-variants.ts"]
  669e6a28_c71f_3c5e_9c53_915cede7da78["candidate.ts"]
  dfcf938d_abe9_684f_720a_29a0a1797759 --> 669e6a28_c71f_3c5e_9c53_915cede7da78
  f29ee016_da0a_a564_1658_fedaaac680b6["cloneCandidate"]
  dfcf938d_abe9_684f_720a_29a0a1797759 --> f29ee016_da0a_a564_1658_fedaaac680b6
  7d350d81_5de1_f9f3_5b2c_19ec8fd3c37e["canonicalize-candidates.ts"]
  dfcf938d_abe9_684f_720a_29a0a1797759 --> 7d350d81_5de1_f9f3_5b2c_19ec8fd3c37e
  81ec8f98_1fb2_d7c3_dd65_3a9e51b3be39["prepareDesignSystemStorage"]
  dfcf938d_abe9_684f_720a_29a0a1797759 --> 81ec8f98_1fb2_d7c3_dd65_3a9e51b3be39
  af1a6ece_0432_a556_fd63_8cb4a91f12ad["plugin-api.ts"]
  dfcf938d_abe9_684f_720a_29a0a1797759 --> af1a6ece_0432_a556_fd63_8cb4a91f12ad
  7fd72d4c_e95c_d849_1002_1e1c9d8aca1a["design-system.ts"]
  dfcf938d_abe9_684f_720a_29a0a1797759 --> 7fd72d4c_e95c_d849_1002_1e1c9d8aca1a
  85d6ae08_36c8_19d7_3202_a198cb21ed1e["types.ts"]
  dfcf938d_abe9_684f_720a_29a0a1797759 --> 85d6ae08_36c8_19d7_3202_a198cb21ed1e
  de65aaee_2caa_4757_c9fa_c7fb4bc23fc0["replace-object.ts"]
  dfcf938d_abe9_684f_720a_29a0a1797759 --> de65aaee_2caa_4757_c9fa_c7fb4bc23fc0
  171d2039_b637_0b5d_5082_71ca42e05d86["replaceObject"]
  dfcf938d_abe9_684f_720a_29a0a1797759 --> 171d2039_b637_0b5d_5082_71ca42e05d86
  c6ac3022_ad0f_45f7_f22a_19fe600e967a["walk-variants.ts"]
  dfcf938d_abe9_684f_720a_29a0a1797759 --> c6ac3022_ad0f_45f7_f22a_19fe600e967a
  ca4a0b1a_7c06_9648_ae90_2860010811a5["walkVariants"]
  dfcf938d_abe9_684f_720a_29a0a1797759 --> ca4a0b1a_7c06_9648_ae90_2860010811a5
  ee1d35bf_4335_a131_a900_1f9f4b90a0e1["migrate-modernize-arbitrary-values.test.ts"]
  ee1d35bf_4335_a131_a900_1f9f4b90a0e1 --> dfcf938d_abe9_684f_720a_29a0a1797759
  style dfcf938d_abe9_684f_720a_29a0a1797759 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { cloneCandidate } from '../../../../tailwindcss/src/candidate'
import {
  PRE_COMPUTED_VARIANTS_KEY,
  prepareDesignSystemStorage,
  VARIANT_SIGNATURE_KEY,
} from '../../../../tailwindcss/src/canonicalize-candidates'
import type { Config } from '../../../../tailwindcss/src/compat/plugin-api'
import type { DesignSystem } from '../../../../tailwindcss/src/design-system'
import type { Writable } from '../../../../tailwindcss/src/types'
import { replaceObject } from '../../../../tailwindcss/src/utils/replace-object'
import { walkVariants } from '../../utils/walk-variants'

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 migrate-arbitrary-variants.ts do?
migrate-arbitrary-variants.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the UpgradeToolkit domain, Codemods subdomain.
What functions are defined in migrate-arbitrary-variants.ts?
migrate-arbitrary-variants.ts defines 1 function(s): migrateArbitraryVariants.
What does migrate-arbitrary-variants.ts depend on?
migrate-arbitrary-variants.ts imports 11 module(s): candidate.ts, canonicalize-candidates.ts, cloneCandidate, design-system.ts, plugin-api.ts, prepareDesignSystemStorage, replace-object.ts, replaceObject, and 3 more.
What files import migrate-arbitrary-variants.ts?
migrate-arbitrary-variants.ts is imported by 1 file(s): migrate-modernize-arbitrary-values.test.ts.
Where is migrate-arbitrary-variants.ts in the architecture?
migrate-arbitrary-variants.ts is located at packages/@tailwindcss-upgrade/src/codemods/template/migrate-arbitrary-variants.ts (domain: UpgradeToolkit, 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