Home / Function/ applyRtlTransformToSourceFile() — ui Function Reference

applyRtlTransformToSourceFile() — ui Function Reference

Architecture documentation for the applyRtlTransformToSourceFile() function in transform-rtl.ts from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  1c2c6582_0b98_c637_71b3_268008d4d10c["applyRtlTransformToSourceFile()"]
  800d6a7b_126c_42b5_bf8e_f313b0852251["transform-rtl.ts"]
  1c2c6582_0b98_c637_71b3_268008d4d10c -->|defined in| 800d6a7b_126c_42b5_bf8e_f313b0852251
  0f7c4c2a_9a83_527f_4a25_a54cc1e6c65d["transformRtl()"]
  0f7c4c2a_9a83_527f_4a25_a54cc1e6c65d -->|calls| 1c2c6582_0b98_c637_71b3_268008d4d10c
  7f810649_4c06_02fa_4309_35dc67791e41["transformDirection()"]
  7f810649_4c06_02fa_4309_35dc67791e41 -->|calls| 1c2c6582_0b98_c637_71b3_268008d4d10c
  fcd38b0b_e1eb_3e41_c063_65e5902b5c47["transformStringLiteralNode()"]
  1c2c6582_0b98_c637_71b3_268008d4d10c -->|calls| fcd38b0b_e1eb_3e41_c063_65e5902b5c47
  04328911_88b5_0d91_43c5_3258d113d876["stripQuotes()"]
  1c2c6582_0b98_c637_71b3_268008d4d10c -->|calls| 04328911_88b5_0d91_43c5_3258d113d876
  style 1c2c6582_0b98_c637_71b3_268008d4d10c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/shadcn/src/utils/transformers/transform-rtl.ts lines 251–459

function applyRtlTransformToSourceFile(sourceFile: SourceFile) {
  // Find the cva function calls.
  sourceFile
    .getDescendantsOfKind(SyntaxKind.CallExpression)
    .filter((node) => node.getExpression().getText() === "cva")
    .forEach((node) => {
      // cva(base, ...).
      const firstArg = node.getArguments()[0]
      if (firstArg?.isKind(SyntaxKind.StringLiteral)) {
        transformStringLiteralNode(firstArg)
      }

      // cva(..., { variants: { ... } }).
      if (node.getArguments()[1]?.isKind(SyntaxKind.ObjectLiteralExpression)) {
        node
          .getArguments()[1]
          ?.getDescendantsOfKind(SyntaxKind.PropertyAssignment)
          .find((node) => node.getName() === "variants")
          ?.getDescendantsOfKind(SyntaxKind.PropertyAssignment)
          .forEach((node) => {
            node
              .getDescendantsOfKind(SyntaxKind.PropertyAssignment)
              .forEach((prop) => {
                const classNames = prop.getInitializerIfKind(
                  SyntaxKind.StringLiteral
                )
                if (classNames) {
                  transformStringLiteralNode(classNames)
                }
              })
          })
      }
    })

  // Find all jsx attributes with the name className.
  sourceFile.getDescendantsOfKind(SyntaxKind.JsxAttribute).forEach((node) => {
    if (node.getNameNode().getText() === "className") {
      // className="...".
      const initializer = node.getInitializer()
      if (initializer?.isKind(SyntaxKind.StringLiteral)) {
        transformStringLiteralNode(initializer)
      }

      // className={...}.
      if (node.getInitializer()?.isKind(SyntaxKind.JsxExpression)) {
        // Check if it's a call to cn().
        const callExpression = node
          .getInitializer()
          ?.getDescendantsOfKind(SyntaxKind.CallExpression)
          .find((node) => node.getExpression().getText() === "cn")
        if (callExpression) {
          callExpression.getArguments().forEach((arg) => {
            if (
              arg.isKind(SyntaxKind.ConditionalExpression) ||
              arg.isKind(SyntaxKind.BinaryExpression)
            ) {
              arg
                .getChildrenOfKind(SyntaxKind.StringLiteral)
                .forEach(transformStringLiteralNode)
            }
            if (arg.isKind(SyntaxKind.StringLiteral)) {
              transformStringLiteralNode(arg)
            }
          })
        }
      }
    }

    // classNames={...}.
    if (node.getNameNode().getText() === "classNames") {
      if (node.getInitializer()?.isKind(SyntaxKind.JsxExpression)) {
        node
          .getDescendantsOfKind(SyntaxKind.PropertyAssignment)
          .forEach((node) => {
            if (node.getInitializer()?.isKind(SyntaxKind.CallExpression)) {
              const callExpression = node.getInitializerIfKind(
                SyntaxKind.CallExpression
              )
              if (callExpression) {
                callExpression.getArguments().forEach((arg) => {
                  if (arg.isKind(SyntaxKind.ConditionalExpression)) {

Subdomains

Frequently Asked Questions

What does applyRtlTransformToSourceFile() do?
applyRtlTransformToSourceFile() is a function in the ui codebase, defined in packages/shadcn/src/utils/transformers/transform-rtl.ts.
Where is applyRtlTransformToSourceFile() defined?
applyRtlTransformToSourceFile() is defined in packages/shadcn/src/utils/transformers/transform-rtl.ts at line 251.
What does applyRtlTransformToSourceFile() call?
applyRtlTransformToSourceFile() calls 2 function(s): stripQuotes, transformStringLiteralNode.
What calls applyRtlTransformToSourceFile()?
applyRtlTransformToSourceFile() is called by 2 function(s): transformDirection, transformRtl.

Analyze Your Own Codebase

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

Try Supermodel Free