Home / Function/ migrateVariantOrder() — tailwindcss Function Reference

migrateVariantOrder() — tailwindcss Function Reference

Architecture documentation for the migrateVariantOrder() function in migrate-variant-order.ts from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  52b790cf_9f93_aadf_60b7_6333be12e6cb["migrateVariantOrder()"]
  db7731f5_f3e0_5e90_b5d1_de4eda8ce9d2["isMajor()"]
  52b790cf_9f93_aadf_60b7_6333be12e6cb -->|calls| db7731f5_f3e0_5e90_b5d1_de4eda8ce9d2
  0bec5ca9_74c8_dcc7_ec12_6404fb6493bd["parseCandidate()"]
  52b790cf_9f93_aadf_60b7_6333be12e6cb -->|calls| 0bec5ca9_74c8_dcc7_ec12_6404fb6493bd
  45938768_ab74_2591_e445_87844f1f028d["isAtRuleVariant()"]
  52b790cf_9f93_aadf_60b7_6333be12e6cb -->|calls| 45938768_ab74_2591_e445_87844f1f028d
  aedbc52b_e5fc_aa81_5ba7_14133c26db65["isEndOfSelectorPseudoElement()"]
  52b790cf_9f93_aadf_60b7_6333be12e6cb -->|calls| aedbc52b_e5fc_aa81_5ba7_14133c26db65
  ae400e34_4c55_4748_93ac_d3a4a0034c44["isCombinatorVariant()"]
  52b790cf_9f93_aadf_60b7_6333be12e6cb -->|calls| ae400e34_4c55_4748_93ac_d3a4a0034c44
  88a62277_79c8_6938_521f_410b61dfc76c["orderMatches()"]
  52b790cf_9f93_aadf_60b7_6333be12e6cb -->|calls| 88a62277_79c8_6938_521f_410b61dfc76c
  4c29981d_a61a_00fb_b3b5_5a69228c4fff["printCandidate()"]
  52b790cf_9f93_aadf_60b7_6333be12e6cb -->|calls| 4c29981d_a61a_00fb_b3b5_5a69228c4fff
  style 52b790cf_9f93_aadf_60b7_6333be12e6cb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/@tailwindcss-upgrade/src/codemods/template/migrate-variant-order.ts lines 8–62

export function migrateVariantOrder(
  designSystem: DesignSystem,
  _userConfig: Config | null,
  rawCandidate: string,
): string {
  // This migration is only needed for Tailwind CSS v3
  //
  // Changing the variant order when migrating from v3 to v4 is fine, but
  // migrating v4 to v4 would make it unsafe because the variant order would
  // flip-flop every time you run the migration.
  if (!version.isMajor(3)) {
    return rawCandidate
  }

  for (let candidate of designSystem.parseCandidate(rawCandidate)) {
    if (candidate.variants.length <= 1) {
      continue
    }

    let atRuleVariants = []
    let regularVariants = []
    let pseudoElementVariants = []

    let originalOrder = candidate.variants

    for (let variant of candidate.variants) {
      if (isAtRuleVariant(designSystem, variant)) {
        atRuleVariants.push(variant)
      } else if (isEndOfSelectorPseudoElement(designSystem, variant)) {
        pseudoElementVariants.push(variant)
      } else {
        regularVariants.push(variant)
      }
    }

    // We only need to reorder regular variants if order is important
    let regularVariantsNeedReordering = regularVariants.some((v) =>
      isCombinatorVariant(designSystem, v),
    )

    // The candidate list in the AST need to be in reverse order
    let newOrder = [
      ...pseudoElementVariants,
      ...(regularVariantsNeedReordering ? regularVariants.reverse() : regularVariants),
      ...atRuleVariants,
    ]

    if (orderMatches(originalOrder, newOrder)) {
      continue
    }

    return designSystem.printCandidate({ ...candidate, variants: newOrder })
  }
  return rawCandidate
}

Domain

Subdomains

Frequently Asked Questions

What does migrateVariantOrder() do?
migrateVariantOrder() is a function in the tailwindcss codebase.
What does migrateVariantOrder() call?
migrateVariantOrder() calls 7 function(s): isAtRuleVariant, isCombinatorVariant, isEndOfSelectorPseudoElement, isMajor, orderMatches, parseCandidate, printCandidate.

Analyze Your Own Codebase

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

Try Supermodel Free