Home / Function/ processNamedImports() — ui Function Reference

processNamedImports() — ui Function Reference

Architecture documentation for the processNamedImports() function in migrate-radix.ts from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  6298a932_872d_8bef_9e0f_e76cde4157c6["processNamedImports()"]
  f076b937_a1ba_1850_79d6_842fd49f9d02["migrate-radix.ts"]
  6298a932_872d_8bef_9e0f_e76cde4157c6 -->|defined in| f076b937_a1ba_1850_79d6_842fd49f9d02
  e943b775_1b94_05b2_d4e6_b95d2e09ee63["migrateRadixFile()"]
  e943b775_1b94_05b2_d4e6_b95d2e09ee63 -->|calls| 6298a932_872d_8bef_9e0f_e76cde4157c6
  style 6298a932_872d_8bef_9e0f_e76cde4157c6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/shadcn/src/migrations/migrate-radix.ts lines 19–99

function processNamedImports(
  namedImports: string,
  isTypeOnly: boolean,
  imports: Array<{ name: string; alias?: string; isType?: boolean }>,
  packageName: string
) {
  // Clean up multi-line imports.
  // Remove comments and whitespace.
  const cleanedImports = namedImports
    .replace(/\/\/.*$/gm, "")
    .replace(/\/\*[\s\S]*?\*\//g, "")
    .replace(/\s+/g, " ")
    .trim()

  const namedImportList = cleanedImports
    .split(",")
    .map((importItem) => importItem.trim())
    .filter(Boolean)

  for (const importItem of namedImportList) {
    const inlineTypeMatch = importItem.match(/^type\s+(\w+)(?:\s+as\s+(\w+))?$/)
    const aliasMatch = importItem.match(/^(\w+)\s+as\s+(\w+)$/)

    if (inlineTypeMatch) {
      // Inline type: "type DialogProps" or "type DialogProps as Props"
      const importName = inlineTypeMatch[1]
      const importAlias = inlineTypeMatch[2]

      if (packageName === "slot" && importName === "Slot" && !importAlias) {
        imports.push({
          name: "Slot",
          alias: "SlotPrimitive",
          isType: true,
        })
      } else {
        imports.push({
          name: importName,
          alias: importAlias,
          isType: true,
        })
      }
    } else if (aliasMatch) {
      // Regular import with alias: "Root as DialogRoot"
      const importName = aliasMatch[1]
      const importAlias = aliasMatch[2]

      if (
        packageName === "slot" &&
        importName === "Slot" &&
        importAlias === "Slot"
      ) {
        imports.push({
          name: "Slot",
          alias: "SlotPrimitive",
          isType: isTypeOnly,
        })
      } else {
        imports.push({
          name: importName,
          alias: importAlias,
          isType: isTypeOnly,
        })
      }
    } else {
      // Simple import: "Root"
      // Special handling for Slot: always alias it as SlotPrimitive
      if (packageName === "slot" && importItem === "Slot") {
        imports.push({
          name: "Slot",
          alias: "SlotPrimitive",
          isType: isTypeOnly,
        })
      } else {
        imports.push({
          name: importItem,
          isType: isTypeOnly,
        })
      }
    }
  }
}

Subdomains

Called By

Frequently Asked Questions

What does processNamedImports() do?
processNamedImports() is a function in the ui codebase, defined in packages/shadcn/src/migrations/migrate-radix.ts.
Where is processNamedImports() defined?
processNamedImports() is defined in packages/shadcn/src/migrations/migrate-radix.ts at line 19.
What calls processNamedImports()?
processNamedImports() is called by 1 function(s): migrateRadixFile.

Analyze Your Own Codebase

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

Try Supermodel Free