transform-aschild.ts — ui Source File
Architecture documentation for transform-aschild.ts, a typescript file in the ui codebase. 2 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 596d8028_0c11_1eb9_f95e_135ad1aeb663["transform-aschild.ts"] e69863ed_3e2f_ef94_648a_ef0155c386ef["transformers"] 596d8028_0c11_1eb9_f95e_135ad1aeb663 --> e69863ed_3e2f_ef94_648a_ef0155c386ef 4f6f7e78_23ff_4f5f_c723_474454f64c85["ts-morph"] 596d8028_0c11_1eb9_f95e_135ad1aeb663 --> 4f6f7e78_23ff_4f5f_c723_474454f64c85 style 596d8028_0c11_1eb9_f95e_135ad1aeb663 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { Transformer } from "@/src/utils/transformers"
import { JsxElement, SyntaxKind } from "ts-morph"
// Elements that require nativeButton={false} when used as render prop.
// These are non-button elements that don't have native button semantics.
const ELEMENTS_REQUIRING_NATIVE_BUTTON_FALSE = [
"a",
"span",
"div",
"Link",
"label",
"Label",
]
interface TransformInfo {
parentElement: JsxElement
parentTagName: string
childTagName: string
childProps: string
childChildren: string
needsNativeButton: boolean
}
export const transformAsChild: Transformer = async ({ sourceFile, config }) => {
// Only run for base- styles.
if (!config.style?.startsWith("base-")) {
return sourceFile
}
// Collect all transformations first, then apply them in reverse order.
// This prevents issues with invalidated nodes when modifying the tree.
const transformations: TransformInfo[] = []
// Find all JSX elements with asChild attribute.
const jsxElements = sourceFile.getDescendantsOfKind(SyntaxKind.JsxElement)
for (const jsxElement of jsxElements) {
const openingElement = jsxElement.getOpeningElement()
const asChildAttr = openingElement.getAttribute("asChild")
if (!asChildAttr) {
continue
}
const parentTagName = openingElement.getTagNameNode().getText()
const children = jsxElement.getJsxChildren()
// Find the first JSX element child (skip whitespace/text).
const childElement = children.find(
(child) =>
child.getKind() === SyntaxKind.JsxElement ||
child.getKind() === SyntaxKind.JsxSelfClosingElement
)
if (!childElement) {
// No child element found, just remove asChild.
asChildAttr.remove()
continue
}
// ... (86 more lines)
Domain
Subdomains
Functions
Types
Dependencies
- transformers
- ts-morph
Source
Frequently Asked Questions
What does transform-aschild.ts do?
transform-aschild.ts is a source file in the ui codebase, written in typescript. It belongs to the FrameworkTooling domain, TemplateSync subdomain.
What functions are defined in transform-aschild.ts?
transform-aschild.ts defines 1 function(s): transformAsChild.
What does transform-aschild.ts depend on?
transform-aschild.ts imports 2 module(s): transformers, ts-morph.
Where is transform-aschild.ts in the architecture?
transform-aschild.ts is located at packages/shadcn/src/utils/transformers/transform-aschild.ts (domain: FrameworkTooling, subdomain: TemplateSync, 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