Home / File/ migrate-camelcase-in-named-value.ts — tailwindcss Source File

migrate-camelcase-in-named-value.ts — tailwindcss Source File

Architecture documentation for migrate-camelcase-in-named-value.ts, a typescript file in the tailwindcss codebase. 5 imports, 2 dependents.

File typescript UpgradeToolkit Codemods 5 imports 2 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  a3d633ca_ef21_d7dc_7d06_b552764f0d5f["migrate-camelcase-in-named-value.ts"]
  669e6a28_c71f_3c5e_9c53_915cede7da78["candidate.ts"]
  a3d633ca_ef21_d7dc_7d06_b552764f0d5f --> 669e6a28_c71f_3c5e_9c53_915cede7da78
  f29ee016_da0a_a564_1658_fedaaac680b6["cloneCandidate"]
  a3d633ca_ef21_d7dc_7d06_b552764f0d5f --> f29ee016_da0a_a564_1658_fedaaac680b6
  af1a6ece_0432_a556_fd63_8cb4a91f12ad["plugin-api.ts"]
  a3d633ca_ef21_d7dc_7d06_b552764f0d5f --> af1a6ece_0432_a556_fd63_8cb4a91f12ad
  7fd72d4c_e95c_d849_1002_1e1c9d8aca1a["design-system.ts"]
  a3d633ca_ef21_d7dc_7d06_b552764f0d5f --> 7fd72d4c_e95c_d849_1002_1e1c9d8aca1a
  fff09679_e13c_392d_23bb_cebc04ddb008["version.ts"]
  a3d633ca_ef21_d7dc_7d06_b552764f0d5f --> fff09679_e13c_392d_23bb_cebc04ddb008
  e295a71c_3b67_dd42_3cf7_c583c04aa2ee["migrate-camelcase-in-named-value.test.ts"]
  e295a71c_3b67_dd42_3cf7_c583c04aa2ee --> a3d633ca_ef21_d7dc_7d06_b552764f0d5f
  75ba60a9_2614_1c57_ad40_3663d4315f3b["migrate.ts"]
  75ba60a9_2614_1c57_ad40_3663d4315f3b --> a3d633ca_ef21_d7dc_7d06_b552764f0d5f
  style a3d633ca_ef21_d7dc_7d06_b552764f0d5f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { cloneCandidate } from '../../../../tailwindcss/src/candidate'
import type { Config } from '../../../../tailwindcss/src/compat/plugin-api'
import type { DesignSystem } from '../../../../tailwindcss/src/design-system'
import * as version from '../../utils/version'

// Converts named values to use kebab-case. This is necessary because the
// upgrade tool also renames the theme values to kebab-case, so `text-superRed`
// will have its theme value renamed to `--color-super-red` and thus the utility
// will be renamed to `text-super-red`.
export function migrateCamelcaseInNamedValue(
  designSystem: DesignSystem,
  _userConfig: Config | null,
  rawCandidate: string,
): string {
  if (!version.isMajor(3)) return rawCandidate

  for (let candidate of designSystem.parseCandidate(rawCandidate)) {
    if (candidate.kind !== 'functional') continue
    let clone = cloneCandidate(candidate)
    let didChange = false

    if (
      candidate.value &&
      clone.value &&
      candidate.value.kind === 'named' &&
      clone.value.kind === 'named' &&
      candidate.value.value.match(/[A-Z]/)
    ) {
      clone.value.value = camelToKebab(candidate.value.value)
      didChange = true
    }

    if (
      candidate.modifier &&
      clone.modifier &&
      candidate.modifier.kind === 'named' &&
      clone.modifier.kind === 'named' &&
      candidate.modifier.value.match(/[A-Z]/)
    ) {
      clone.modifier.value = camelToKebab(candidate.modifier.value)
      didChange = true
    }

    if (didChange) {
      return designSystem.printCandidate(clone)
    }
  }

  return rawCandidate
}

function camelToKebab(str: string): string {
  return str.replace(/([A-Z])/g, '-$1').toLowerCase()
}

Subdomains

Frequently Asked Questions

What does migrate-camelcase-in-named-value.ts do?
migrate-camelcase-in-named-value.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-camelcase-in-named-value.ts?
migrate-camelcase-in-named-value.ts defines 2 function(s): camelToKebab, migrateCamelcaseInNamedValue.
What does migrate-camelcase-in-named-value.ts depend on?
migrate-camelcase-in-named-value.ts imports 5 module(s): candidate.ts, cloneCandidate, design-system.ts, plugin-api.ts, version.ts.
What files import migrate-camelcase-in-named-value.ts?
migrate-camelcase-in-named-value.ts is imported by 2 file(s): migrate-camelcase-in-named-value.test.ts, migrate.ts.
Where is migrate-camelcase-in-named-value.ts in the architecture?
migrate-camelcase-in-named-value.ts is located at packages/@tailwindcss-upgrade/src/codemods/template/migrate-camelcase-in-named-value.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