Home / Function/ migratePrefix() — tailwindcss Function Reference

migratePrefix() — tailwindcss Function Reference

Architecture documentation for the migratePrefix() function in migrate-prefix.ts from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  7a457be5_eaef_02ce_7bc4_4e0317ecd8ce["migratePrefix()"]
  e4e5ac2c_0d58_689d_0ad6_7086823787f1["migrate-prefix.ts"]
  7a457be5_eaef_02ce_7bc4_4e0317ecd8ce -->|defined in| e4e5ac2c_0d58_689d_0ad6_7086823787f1
  6cf757d4_aaad_b18d_cf21_ade24c6e2a77["isMajor()"]
  7a457be5_eaef_02ce_7bc4_4e0317ecd8ce -->|calls| 6cf757d4_aaad_b18d_cf21_ade24c6e2a77
  1369a6dc_e395_347d_5d24_b88e22c5446d["decl()"]
  7a457be5_eaef_02ce_7bc4_4e0317ecd8ce -->|calls| 1369a6dc_e395_347d_5d24_b88e22c5446d
  a5786cf3_5b2e_711a_6639_a1d182cf427d["extractV3Base()"]
  7a457be5_eaef_02ce_7bc4_4e0317ecd8ce -->|calls| a5786cf3_5b2e_711a_6639_a1d182cf427d
  7d328a86_10c6_b5c1_6390_36f4fffe9c14["parseCandidate()"]
  7a457be5_eaef_02ce_7bc4_4e0317ecd8ce -->|calls| 7d328a86_10c6_b5c1_6390_36f4fffe9c14
  2de86ba2_90a4_8c2d_db18_154bb1a1564f["printCandidate()"]
  7a457be5_eaef_02ce_7bc4_4e0317ecd8ce -->|calls| 2de86ba2_90a4_8c2d_db18_154bb1a1564f
  style 7a457be5_eaef_02ce_7bc4_4e0317ecd8ce fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/@tailwindcss-upgrade/src/codemods/template/migrate-prefix.ts lines 10–62

export function migratePrefix(
  designSystem: DesignSystem,
  userConfig: Config | null,
  rawCandidate: string,
): string {
  if (!designSystem.theme.prefix) return rawCandidate
  if (!userConfig) return rawCandidate
  if (!version.isMajor(3)) return rawCandidate

  if (!seenDesignSystems.has(designSystem)) {
    designSystem.utilities.functional('group', (value) => [
      // To ensure that `@apply group` works when computing a signature
      decl('--phantom-class', 'group'),
      // To ensure `group` and `group/foo` are considered different classes
      decl('--phantom-modifier', value.modifier?.value),
    ])
    designSystem.utilities.functional('peer', (value) => [
      // To ensure that `@apply peer` works when computing a signature
      decl('--phantom-class', 'peer'),
      // To ensure `peer` and `peer/foo` are considered different classes
      decl('--phantom-modifier', value.modifier?.value),
    ])
    seenDesignSystems.add(designSystem)
  }

  let v3Base = extractV3Base(designSystem, userConfig, rawCandidate)

  if (!v3Base) return rawCandidate

  // Only migrate candidates which are valid in v4
  let originalPrefix = designSystem.theme.prefix
  let candidate: Candidate | null = null
  try {
    designSystem.theme.prefix = null

    let unprefixedCandidate =
      rawCandidate.slice(0, v3Base.start) + v3Base.base + rawCandidate.slice(v3Base.end)

    // Note: This is not a valid candidate in the original DesignSystem, so we
    // can not use the `DesignSystem#parseCandidate` API here or otherwise this
    // invalid candidate will be cached.
    let candidates = [...parseCandidate(unprefixedCandidate, designSystem)]
    if (candidates.length > 0) {
      candidate = candidates[0]
    }
  } finally {
    designSystem.theme.prefix = originalPrefix
  }

  if (!candidate) return rawCandidate

  return designSystem.printCandidate(candidate)
}

Subdomains

Frequently Asked Questions

What does migratePrefix() do?
migratePrefix() is a function in the tailwindcss codebase, defined in packages/@tailwindcss-upgrade/src/codemods/template/migrate-prefix.ts.
Where is migratePrefix() defined?
migratePrefix() is defined in packages/@tailwindcss-upgrade/src/codemods/template/migrate-prefix.ts at line 10.
What does migratePrefix() call?
migratePrefix() calls 5 function(s): decl, extractV3Base, isMajor, parseCandidate, printCandidate.

Analyze Your Own Codebase

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

Try Supermodel Free