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. 14 imports, 1 dependents.

File typescript CommandLineInterface Codemods 14 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  fd9821c7_1a1a_545c_2d82_048fc3c3d870["migrate-arbitrary-variants.ts"]
  ba6fca27_7720_5839_0f92_bc2abb8db636["candidate.ts"]
  fd9821c7_1a1a_545c_2d82_048fc3c3d870 --> ba6fca27_7720_5839_0f92_bc2abb8db636
  23c6e5a0_eac4_e9dd_7fcf_1e5c71d28310["cloneCandidate"]
  fd9821c7_1a1a_545c_2d82_048fc3c3d870 --> 23c6e5a0_eac4_e9dd_7fcf_1e5c71d28310
  f6c14bbb_2e42_58cc_18f1_c89a243da9c0["canonicalize-candidates.ts"]
  fd9821c7_1a1a_545c_2d82_048fc3c3d870 --> f6c14bbb_2e42_58cc_18f1_c89a243da9c0
  26169039_1fd2_e320_1f63_11ec10a6fc52["prepareDesignSystemStorage"]
  fd9821c7_1a1a_545c_2d82_048fc3c3d870 --> 26169039_1fd2_e320_1f63_11ec10a6fc52
  da5d1116_ab2a_437a_6b13_c1429fd546fa["plugin-api.ts"]
  fd9821c7_1a1a_545c_2d82_048fc3c3d870 --> da5d1116_ab2a_437a_6b13_c1429fd546fa
  0255ffc0_a3d5_e883_5143_99660766448f["Config"]
  fd9821c7_1a1a_545c_2d82_048fc3c3d870 --> 0255ffc0_a3d5_e883_5143_99660766448f
  bdedd2f6_da4b_69dc_e990_0814b59fbe6e["design-system.ts"]
  fd9821c7_1a1a_545c_2d82_048fc3c3d870 --> bdedd2f6_da4b_69dc_e990_0814b59fbe6e
  665aa4ed_d86e_30e5_80d5_cd56b8ca8b62["DesignSystem"]
  fd9821c7_1a1a_545c_2d82_048fc3c3d870 --> 665aa4ed_d86e_30e5_80d5_cd56b8ca8b62
  0e933f20_08fb_5942_ec42_6626eaae653a["types.ts"]
  fd9821c7_1a1a_545c_2d82_048fc3c3d870 --> 0e933f20_08fb_5942_ec42_6626eaae653a
  d273a025_e48e_2770_95aa_3a966ac7fbec["Writable"]
  fd9821c7_1a1a_545c_2d82_048fc3c3d870 --> d273a025_e48e_2770_95aa_3a966ac7fbec
  cb055289_b1a4_fdf0_beff_09232c521413["replace-object.ts"]
  fd9821c7_1a1a_545c_2d82_048fc3c3d870 --> cb055289_b1a4_fdf0_beff_09232c521413
  38b866f2_6f5f_ed0c_8931_4489835420d2["replaceObject"]
  fd9821c7_1a1a_545c_2d82_048fc3c3d870 --> 38b866f2_6f5f_ed0c_8931_4489835420d2
  9ff6caab_a6b5_8ba2_418e_e53a6c69b3cb["walk-variants.ts"]
  fd9821c7_1a1a_545c_2d82_048fc3c3d870 --> 9ff6caab_a6b5_8ba2_418e_e53a6c69b3cb
  abd55297_2562_3a6c_6827_3710e8d45c54["walkVariants"]
  fd9821c7_1a1a_545c_2d82_048fc3c3d870 --> abd55297_2562_3a6c_6827_3710e8d45c54
  style fd9821c7_1a1a_545c_2d82_048fc3c3d870 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 CommandLineInterface 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 14 module(s): Config, DesignSystem, Writable, candidate.ts, canonicalize-candidates.ts, cloneCandidate, design-system.ts, plugin-api.ts, and 6 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: CommandLineInterface, 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