Home / File/ migrate-modernize-arbitrary-values.ts — tailwindcss Source File

migrate-modernize-arbitrary-values.ts — tailwindcss Source File

Architecture documentation for migrate-modernize-arbitrary-values.ts, a typescript file in the tailwindcss codebase. 11 imports, 2 dependents.

File typescript CommandLineInterface Codemods 11 imports 2 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  5d3b10aa_da00_02c8_3f52_47b3ae3aa06e["migrate-modernize-arbitrary-values.ts"]
  ba6fca27_7720_5839_0f92_bc2abb8db636["candidate.ts"]
  5d3b10aa_da00_02c8_3f52_47b3ae3aa06e --> ba6fca27_7720_5839_0f92_bc2abb8db636
  23c6e5a0_eac4_e9dd_7fcf_1e5c71d28310["cloneCandidate"]
  5d3b10aa_da00_02c8_3f52_47b3ae3aa06e --> 23c6e5a0_eac4_e9dd_7fcf_1e5c71d28310
  7d328a86_10c6_b5c1_6390_36f4fffe9c14["parseCandidate"]
  5d3b10aa_da00_02c8_3f52_47b3ae3aa06e --> 7d328a86_10c6_b5c1_6390_36f4fffe9c14
  da5d1116_ab2a_437a_6b13_c1429fd546fa["plugin-api.ts"]
  5d3b10aa_da00_02c8_3f52_47b3ae3aa06e --> da5d1116_ab2a_437a_6b13_c1429fd546fa
  0255ffc0_a3d5_e883_5143_99660766448f["Config"]
  5d3b10aa_da00_02c8_3f52_47b3ae3aa06e --> 0255ffc0_a3d5_e883_5143_99660766448f
  bdedd2f6_da4b_69dc_e990_0814b59fbe6e["design-system.ts"]
  5d3b10aa_da00_02c8_3f52_47b3ae3aa06e --> bdedd2f6_da4b_69dc_e990_0814b59fbe6e
  665aa4ed_d86e_30e5_80d5_cd56b8ca8b62["DesignSystem"]
  5d3b10aa_da00_02c8_3f52_47b3ae3aa06e --> 665aa4ed_d86e_30e5_80d5_cd56b8ca8b62
  cb055289_b1a4_fdf0_beff_09232c521413["replace-object.ts"]
  5d3b10aa_da00_02c8_3f52_47b3ae3aa06e --> cb055289_b1a4_fdf0_beff_09232c521413
  38b866f2_6f5f_ed0c_8931_4489835420d2["replaceObject"]
  5d3b10aa_da00_02c8_3f52_47b3ae3aa06e --> 38b866f2_6f5f_ed0c_8931_4489835420d2
  9ff6caab_a6b5_8ba2_418e_e53a6c69b3cb["walk-variants.ts"]
  5d3b10aa_da00_02c8_3f52_47b3ae3aa06e --> 9ff6caab_a6b5_8ba2_418e_e53a6c69b3cb
  abd55297_2562_3a6c_6827_3710e8d45c54["walkVariants"]
  5d3b10aa_da00_02c8_3f52_47b3ae3aa06e --> abd55297_2562_3a6c_6827_3710e8d45c54
  80bb9840_1d91_d6ca_549c_09209ffc25a6["migrate-modernize-arbitrary-values.test.ts"]
  80bb9840_1d91_d6ca_549c_09209ffc25a6 --> 5d3b10aa_da00_02c8_3f52_47b3ae3aa06e
  e39bed3f_bfbf_a8c6_90a0_aa2ce3be1ef4["migrate.ts"]
  e39bed3f_bfbf_a8c6_90a0_aa2ce3be1ef4 --> 5d3b10aa_da00_02c8_3f52_47b3ae3aa06e
  style 5d3b10aa_da00_02c8_3f52_47b3ae3aa06e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { cloneCandidate, parseCandidate } from '../../../../tailwindcss/src/candidate'
import type { Config } from '../../../../tailwindcss/src/compat/plugin-api'
import type { DesignSystem } from '../../../../tailwindcss/src/design-system'
import { replaceObject } from '../../../../tailwindcss/src/utils/replace-object'
import { walkVariants } from '../../utils/walk-variants'

export function migrateModernizeArbitraryValues(
  designSystem: DesignSystem,
  _userConfig: Config | null,
  rawCandidate: string,
): string {
  for (let candidate of parseCandidate(rawCandidate, designSystem)) {
    let clone = cloneCandidate(candidate)
    let changed = false

    for (let [variant] of walkVariants(clone)) {
      // Forward modifier from the root to the compound variant
      if (
        variant.kind === 'compound' &&
        (variant.root === 'has' || variant.root === 'not' || variant.root === 'in')
      ) {
        if (variant.modifier !== null) {
          if ('modifier' in variant.variant) {
            variant.variant.modifier = variant.modifier
            variant.modifier = null
          }
        }
      }

      // Promote `group-[]:flex` to `in-[.group]:flex`
      //                ^^ Yes, this is empty
      // Promote `group-[]/name:flex` to `in-[.group\/name]:flex`
      if (
        variant.kind === 'compound' &&
        variant.root === 'group' &&
        variant.variant.kind === 'arbitrary' &&
        variant.variant.selector === '&'
      ) {
        // `group-[]`
        if (variant.modifier === null) {
          changed = true
          replaceObject(
            variant,
            designSystem.parseVariant(
              designSystem.theme.prefix
                ? `in-[.${designSystem.theme.prefix}\\:group]`
                : 'in-[.group]',
            ),
          )
        }

        // `group-[]/name`
        else if (variant.modifier.kind === 'named') {
          changed = true
          replaceObject(
            variant,
            designSystem.parseVariant(
              designSystem.theme.prefix
                ? `in-[.${designSystem.theme.prefix}\\:group\\/${variant.modifier.value}]`
                : `in-[.group\\/${variant.modifier.value}]`,
            ),
          )
        }
        continue
      }
    }

    return changed ? designSystem.printCandidate(clone) : rawCandidate
  }

  return rawCandidate
}

Subdomains

Frequently Asked Questions

What does migrate-modernize-arbitrary-values.ts do?
migrate-modernize-arbitrary-values.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-modernize-arbitrary-values.ts?
migrate-modernize-arbitrary-values.ts defines 1 function(s): migrateModernizeArbitraryValues.
What does migrate-modernize-arbitrary-values.ts depend on?
migrate-modernize-arbitrary-values.ts imports 11 module(s): Config, DesignSystem, candidate.ts, cloneCandidate, design-system.ts, parseCandidate, plugin-api.ts, replace-object.ts, and 3 more.
What files import migrate-modernize-arbitrary-values.ts?
migrate-modernize-arbitrary-values.ts is imported by 2 file(s): migrate-modernize-arbitrary-values.test.ts, migrate.ts.
Where is migrate-modernize-arbitrary-values.ts in the architecture?
migrate-modernize-arbitrary-values.ts is located at packages/@tailwindcss-upgrade/src/codemods/template/migrate-modernize-arbitrary-values.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