Home / File/ transform-cleanup.ts — ui Source File

transform-cleanup.ts — ui Source File

Architecture documentation for transform-cleanup.ts, a typescript file in the ui codebase. 2 imports, 2 dependents.

File typescript FrameworkTooling CLICore 2 imports 2 dependents 6 functions

Entity Profile

Dependency Diagram

graph LR
  e5d28271_9de7_c6c9_1240_13894663e9ec["transform-cleanup.ts"]
  e69863ed_3e2f_ef94_648a_ef0155c386ef["transformers"]
  e5d28271_9de7_c6c9_1240_13894663e9ec --> e69863ed_3e2f_ef94_648a_ef0155c386ef
  4f6f7e78_23ff_4f5f_c723_474454f64c85["ts-morph"]
  e5d28271_9de7_c6c9_1240_13894663e9ec --> 4f6f7e78_23ff_4f5f_c723_474454f64c85
  646bd874_990a_e30f_0d03_073229dd52ad["index.ts"]
  646bd874_990a_e30f_0d03_073229dd52ad --> e5d28271_9de7_c6c9_1240_13894663e9ec
  84d5040c_6b1a_ee5d_e967_8ff170c2d22b["transform-cleanup.test.ts"]
  84d5040c_6b1a_ee5d_e967_8ff170c2d22b --> e5d28271_9de7_c6c9_1240_13894663e9ec
  style e5d28271_9de7_c6c9_1240_13894663e9ec fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { Transformer } from "@/src/utils/transformers"
import {
  NoSubstitutionTemplateLiteral,
  Node,
  Project,
  ScriptKind,
  SourceFile,
  StringLiteral,
  SyntaxKind,
} from "ts-morph"

// Regex to match cn-* marker classes (e.g., cn-rtl-flip, cn-logical-sides).
const CN_MARKER_REGEX = /\bcn-[a-z-]+\b/
const CN_MARKER_REGEX_GLOBAL = /\bcn-[a-z-]+\b/g

// Helper to strip all cn-* marker classes from a className string.
export function stripCnMarkers(className: string) {
  return className
    .replace(CN_MARKER_REGEX_GLOBAL, "")
    .replace(/\s+/g, " ")
    .trim()
}

type StringLikeLiteral = StringLiteral | NoSubstitutionTemplateLiteral

// Processes a string-like literal and strips cn-* markers.
function processStringLiteral(node: StringLikeLiteral) {
  const currentValue = node.getLiteralValue()
  if (!CN_MARKER_REGEX.test(currentValue)) {
    return
  }

  const newValue = stripCnMarkers(currentValue)
  if (newValue !== currentValue) {
    node.setLiteralValue(newValue)
  }
}

function processStringLiterals(node: Node) {
  for (const stringLit of node.getDescendantsOfKind(SyntaxKind.StringLiteral)) {
    processStringLiteral(stringLit)
  }

  for (const templateLit of node.getDescendantsOfKind(
    SyntaxKind.NoSubstitutionTemplateLiteral
  )) {
    processStringLiteral(templateLit)
  }
}

// Apply cleanup to a SourceFile directly (used by transformDirection).
export function applyCleanup(sourceFile: SourceFile) {
  // Collect attributes to remove (can't remove while iterating).
  const attributesToRemove: ReturnType<
    typeof sourceFile.getDescendantsOfKind<typeof SyntaxKind.JsxAttribute>
  > = []

  // Process all JSX className attributes.
  for (const attr of sourceFile.getDescendantsOfKind(SyntaxKind.JsxAttribute)) {
    const attrName = attr.getNameNode().getText()
// ... (87 more lines)

Subdomains

Dependencies

  • transformers
  • ts-morph

Frequently Asked Questions

What does transform-cleanup.ts do?
transform-cleanup.ts is a source file in the ui codebase, written in typescript. It belongs to the FrameworkTooling domain, CLICore subdomain.
What functions are defined in transform-cleanup.ts?
transform-cleanup.ts defines 6 function(s): applyCleanup, cleanupMarkers, processStringLiteral, processStringLiterals, stripCnMarkers, transformCleanup.
What does transform-cleanup.ts depend on?
transform-cleanup.ts imports 2 module(s): transformers, ts-morph.
What files import transform-cleanup.ts?
transform-cleanup.ts is imported by 2 file(s): index.ts, transform-cleanup.test.ts.
Where is transform-cleanup.ts in the architecture?
transform-cleanup.ts is located at packages/shadcn/src/utils/transformers/transform-cleanup.ts (domain: FrameworkTooling, subdomain: CLICore, directory: packages/shadcn/src/utils/transformers).

Analyze Your Own Codebase

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

Try Supermodel Free