{"version":3,"file":"transform.cjs","names":[],"sources":["../../../src/transform/transform.ts"],"sourcesContent":["import MagicString from 'magic-string'\nimport * as t from '@babel/types'\nimport { parseAst } from '@tanstack/router-utils'\nimport type { TransformOptions, TransformResult } from './types'\n\nconst routeConstructors = ['createFileRoute', 'createLazyFileRoute'] as const\n\ntype RouteConstructorName = (typeof routeConstructors)[number]\ntype SupportedRouteId = t.StringLiteral | t.TemplateLiteral\ntype NamedImport = {\n  imported: string\n  local: string\n  importKind?: 'type' | 'typeof' | 'value'\n}\n\ntype ParsedImportDeclaration = {\n  declaration: t.ImportDeclaration\n  defaultImport?: string\n  namespace?: string\n  named: Array<NamedImport>\n  moduleName: string\n  quote: '\"' | \"'\"\n  semicolon: boolean\n}\n\ntype RouteImportAnalysis =\n  | { kind: 'ok' }\n  | {\n      kind: 'rename'\n      imported: t.Identifier\n      local: t.Identifier\n      next: RouteConstructorName\n    }\n  | { kind: 'normalize' }\n\ntype RouteCall = {\n  callee: t.Identifier & { name: RouteConstructorName }\n  routeIdArg: SupportedRouteId\n  optionsArg: t.CallExpression['arguments'][number] | undefined\n}\n\ntype RouteCallAnalysis = {\n  calls: Array<RouteCall>\n  hasUnsupportedRouteId: boolean\n  hasMalformedRouteCall: boolean\n}\n\nexport function transform({\n  ctx,\n  source,\n  filename,\n  node,\n}: TransformOptions): TransformResult {\n  let ast: ReturnType<typeof parseAst>\n\n  try {\n    ast = parseAst({ code: source, filename })\n  } catch (error) {\n    return {\n      result: 'error',\n      error,\n    }\n  }\n\n  const exportedRouteNames = getExportedRouteNames(ast.program.body)\n\n  if (exportedRouteNames.size === 0) {\n    return { result: 'no-route-export' }\n  }\n\n  const {\n    calls: routeCalls,\n    hasUnsupportedRouteId,\n    hasMalformedRouteCall,\n  } = findExportedRouteCalls(ast.program.body, exportedRouteNames)\n\n  if (routeCalls.length === 0 && hasMalformedRouteCall) {\n    return {\n      result: 'error',\n      error: new Error(\n        `expected Route export in ${ctx.routeId} to use createFileRoute('/path')({...}) or createLazyFileRoute('/path')({...})`,\n      ),\n    }\n  }\n\n  if (routeCalls.length === 0 && hasUnsupportedRouteId) {\n    return {\n      result: 'error',\n      error: new Error(\n        `expected route id to be a string literal or plain template literal in ${ctx.routeId}`,\n      ),\n    }\n  }\n\n  if (routeCalls.length === 0) {\n    return { result: 'not-modified' }\n  }\n\n  if (routeCalls.length > 1) {\n    return {\n      result: 'error',\n      error: new Error(\n        `expected exactly one createFileRoute/createLazyFileRoute call in ${ctx.routeId}`,\n      ),\n    }\n  }\n\n  const routeCall = routeCalls[0]!\n  const routeIdQuote = getRouteIdQuote(source, routeCall.routeIdArg)\n\n  const createFileRouteProps = getCreateFileRouteProps(routeCall.optionsArg)\n  if (createFileRouteProps) {\n    node.createFileRouteProps = createFileRouteProps\n  }\n\n  const expectedCallee = getExpectedRouteConstructor(ctx.lazy)\n  const expectedRouteId = `${routeIdQuote}${ctx.routeId}${routeIdQuote}`\n  const currentRouteId = source.slice(\n    routeCall.routeIdArg.start!,\n    routeCall.routeIdArg.end!,\n  )\n  const targetModule = `@tanstack/${ctx.target}-router`\n  const imports = parseTargetImports(ast.program.body, source, targetModule)\n\n  const s = new MagicString(source)\n  let modified = false\n\n  if (routeCall.callee.name !== expectedCallee) {\n    s.update(routeCall.callee.start!, routeCall.callee.end!, expectedCallee)\n    modified = true\n  }\n\n  if (currentRouteId !== expectedRouteId) {\n    s.update(\n      routeCall.routeIdArg.start!,\n      routeCall.routeIdArg.end!,\n      expectedRouteId,\n    )\n    modified = true\n  }\n\n  if (\n    updateRouteImports({\n      imports,\n      source,\n      s,\n      targetModule,\n      required: expectedCallee,\n      lineEnding: getLineEnding(source),\n    })\n  ) {\n    modified = true\n  }\n\n  if (!modified) {\n    return { result: 'not-modified' }\n  }\n\n  return {\n    result: 'modified',\n    output: s.toString(),\n  }\n}\n\nfunction getExportedRouteNames(body: Array<t.Statement>) {\n  const exportedRouteNames = new Set<string>()\n\n  for (const statement of body) {\n    if (!t.isExportNamedDeclaration(statement) || statement.source) {\n      continue\n    }\n\n    if (t.isVariableDeclaration(statement.declaration)) {\n      for (const declarator of statement.declaration.declarations) {\n        if (t.isIdentifier(declarator.id) && declarator.id.name === 'Route') {\n          exportedRouteNames.add('Route')\n        }\n      }\n    }\n\n    for (const specifier of statement.specifiers) {\n      if (\n        !t.isExportSpecifier(specifier) ||\n        getExportedName(specifier.exported) !== 'Route'\n      ) {\n        continue\n      }\n\n      const localName = getLocalBindingName(specifier.local)\n      if (localName) {\n        exportedRouteNames.add(localName)\n      }\n    }\n  }\n\n  return exportedRouteNames\n}\n\nfunction findExportedRouteCalls(\n  body: Array<t.Statement>,\n  exportedRouteNames: Set<string>,\n): RouteCallAnalysis {\n  const calls: Array<RouteCall> = []\n  let hasUnsupportedRouteId = false\n  let hasMalformedRouteCall = false\n\n  for (const statement of body) {\n    const declaration = getVariableDeclaration(statement)\n    if (!declaration) {\n      continue\n    }\n\n    for (const declarator of declaration.declarations) {\n      if (\n        !t.isIdentifier(declarator.id) ||\n        !exportedRouteNames.has(declarator.id.name)\n      ) {\n        continue\n      }\n\n      const init = getRouteConstructorInit(declarator.init)\n      if (!init) {\n        if (isDirectRouteConstructorCall(declarator.init)) {\n          hasMalformedRouteCall = true\n        }\n        continue\n      }\n\n      const routeIdArg = init.innerCall.arguments[0]\n      if (isSupportedRouteId(routeIdArg)) {\n        calls.push({\n          callee: init.callee,\n          routeIdArg,\n          optionsArg: init.outerCall.arguments[0],\n        })\n      } else {\n        hasUnsupportedRouteId = true\n      }\n    }\n  }\n\n  return { calls, hasUnsupportedRouteId, hasMalformedRouteCall }\n}\n\nfunction getVariableDeclaration(statement: t.Statement) {\n  const declaration = t.isExportNamedDeclaration(statement)\n    ? statement.declaration\n    : statement\n\n  return t.isVariableDeclaration(declaration) ? declaration : null\n}\n\nfunction getExportedName(node: t.Identifier | t.StringLiteral) {\n  return t.isIdentifier(node) ? node.name : node.value\n}\n\nfunction getLocalBindingName(node: t.Identifier | t.StringLiteral) {\n  return t.isIdentifier(node) ? node.name : null\n}\n\nfunction getRouteConstructorInit(expression: t.Expression | null | undefined) {\n  if (!expression || !t.isCallExpression(expression)) {\n    return null\n  }\n\n  if (!t.isCallExpression(expression.callee)) {\n    return null\n  }\n\n  const innerCall = expression.callee\n\n  if (\n    !t.isIdentifier(innerCall.callee) ||\n    !isRouteConstructor(innerCall.callee)\n  ) {\n    return null\n  }\n\n  return {\n    callee: innerCall.callee,\n    outerCall: expression,\n    innerCall,\n  }\n}\n\nfunction isDirectRouteConstructorCall(\n  expression: t.Expression | null | undefined,\n) {\n  return (\n    !!expression &&\n    t.isCallExpression(expression) &&\n    t.isIdentifier(expression.callee) &&\n    isRouteConstructor(expression.callee)\n  )\n}\n\nfunction isRouteConstructor(callee: t.Identifier): callee is t.Identifier & {\n  name: RouteConstructorName\n} {\n  return routeConstructors.includes(callee.name as RouteConstructorName)\n}\n\nfunction isSupportedRouteId(\n  arg: t.CallExpression['arguments'][number] | undefined,\n): arg is SupportedRouteId {\n  return (\n    !!arg &&\n    (t.isStringLiteral(arg) ||\n      (t.isTemplateLiteral(arg) && arg.expressions.length === 0))\n  )\n}\n\nfunction getRouteIdQuote(\n  source: string,\n  arg: SupportedRouteId,\n): '\"' | \"'\" | '`' {\n  const raw = source.slice(arg.start!, arg.end!)\n\n  if (raw.startsWith(\"'\")) return \"'\"\n  if (raw.startsWith('\"')) return '\"'\n  return '`'\n}\n\nfunction getCreateFileRouteProps(\n  arg: t.CallExpression['arguments'][number] | undefined,\n) {\n  if (!arg || !t.isObjectExpression(arg)) {\n    return undefined\n  }\n\n  const props = new Set<string>()\n\n  for (const property of arg.properties) {\n    if (!t.isObjectProperty(property) || property.computed) {\n      continue\n    }\n\n    if (t.isIdentifier(property.key)) {\n      props.add(property.key.name)\n      continue\n    }\n\n    if (t.isStringLiteral(property.key)) {\n      props.add(property.key.value)\n    }\n  }\n\n  return props\n}\n\nfunction parseTargetImports(\n  body: Array<t.Statement>,\n  source: string,\n  targetModule: string,\n) {\n  const imports: Array<ParsedImportDeclaration> = []\n\n  for (const statement of body) {\n    if (\n      !t.isImportDeclaration(statement) ||\n      statement.importKind === 'type' ||\n      statement.source.value !== targetModule\n    ) {\n      continue\n    }\n\n    const rawSource = source.slice(\n      statement.source.start!,\n      statement.source.end!,\n    )\n    const importStatement = source.slice(statement.start!, statement.end!)\n\n    imports.push({\n      declaration: statement,\n      defaultImport: statement.specifiers.find((specifier) =>\n        t.isImportDefaultSpecifier(specifier),\n      )?.local.name,\n      namespace: statement.specifiers.find((specifier) =>\n        t.isImportNamespaceSpecifier(specifier),\n      )?.local.name,\n      named: statement.specifiers\n        .filter((specifier): specifier is t.ImportSpecifier =>\n          t.isImportSpecifier(specifier),\n        )\n        .map((specifier) => ({\n          imported: t.isIdentifier(specifier.imported)\n            ? specifier.imported.name\n            : specifier.imported.value,\n          local: specifier.local.name,\n          importKind: specifier.importKind ?? undefined,\n        })),\n      moduleName: statement.source.value,\n      quote: rawSource[0] as '\"' | \"'\",\n      semicolon: importStatement.trimEnd().endsWith(';'),\n    })\n  }\n\n  return imports\n}\n\nfunction updateRouteImports({\n  imports,\n  source,\n  s,\n  targetModule,\n  required,\n  lineEnding,\n}: {\n  imports: Array<ParsedImportDeclaration>\n  source: string\n  s: MagicString\n  targetModule: string\n  required: RouteConstructorName\n  lineEnding: '\\r\\n' | '\\n' | '\\r'\n}) {\n  const analysis = analyzeRouteImports(imports, required)\n\n  if (analysis.kind === 'ok') {\n    return false\n  }\n\n  if (analysis.kind === 'rename') {\n    s.update(analysis.imported.start!, analysis.imported.end!, analysis.next)\n    s.update(analysis.local.start!, analysis.local.end!, analysis.next)\n    return true\n  }\n\n  return normalizeRouteImports({\n    imports,\n    source,\n    s,\n    targetModule,\n    required,\n    lineEnding,\n  })\n}\n\nfunction analyzeRouteImports(\n  imports: Array<ParsedImportDeclaration>,\n  required: RouteConstructorName,\n): RouteImportAnalysis {\n  const opposite = getOtherRouteConstructor(required)\n  let requiredCount = 0\n  let oppositeCount = 0\n  let renameCandidate:\n    | {\n        imported: t.Identifier\n        local: t.Identifier\n        next: RouteConstructorName\n      }\n    | undefined\n\n  for (const declaration of imports) {\n    for (const specifier of declaration.declaration.specifiers) {\n      if (!t.isImportSpecifier(specifier)) {\n        continue\n      }\n\n      const imported = specifier.imported\n      if (!t.isIdentifier(imported)) {\n        return { kind: 'normalize' }\n      }\n\n      if (!isRouteConstructorName(imported.name)) {\n        continue\n      }\n\n      if (specifier.local.name !== imported.name) {\n        return { kind: 'normalize' }\n      }\n\n      if (imported.name === required) {\n        requiredCount++\n        continue\n      }\n\n      if (imported.name === opposite) {\n        oppositeCount++\n        renameCandidate = {\n          imported,\n          local: specifier.local,\n          next: required,\n        }\n      }\n    }\n  }\n\n  if (requiredCount === 1 && oppositeCount === 0) {\n    return { kind: 'ok' }\n  }\n\n  if (requiredCount === 0 && oppositeCount === 1 && renameCandidate) {\n    return {\n      kind: 'rename',\n      ...renameCandidate,\n    }\n  }\n\n  return { kind: 'normalize' }\n}\n\nfunction normalizeRouteImports({\n  imports,\n  source,\n  s,\n  targetModule,\n  required,\n  lineEnding,\n}: {\n  imports: Array<ParsedImportDeclaration>\n  source: string\n  s: MagicString\n  targetModule: string\n  required: RouteConstructorName\n  lineEnding: '\\r\\n' | '\\n' | '\\r'\n}) {\n  const owner =\n    imports.find((declaration) =>\n      hasNamedImport(declaration.named, required),\n    ) ?? imports.find((declaration) => !declaration.namespace)\n\n  let modified = false\n\n  for (const declaration of imports) {\n    const named = normalizeNamedImports({\n      named: declaration.named,\n      required,\n      isOwner: declaration === owner,\n    })\n\n    if (sameNamedImports(declaration.named, named)) {\n      continue\n    }\n\n    const replacement = renderImportDeclaration({\n      ...declaration,\n      named,\n    })\n\n    if (replacement === null) {\n      s.remove(\n        declaration.declaration.start!,\n        getRemovalEnd(source, declaration.declaration.end!),\n      )\n      modified = true\n      continue\n    }\n\n    s.update(\n      declaration.declaration.start!,\n      declaration.declaration.end!,\n      replacement,\n    )\n    modified = true\n  }\n\n  if (!owner) {\n    const quote = imports[0]?.quote ?? \"'\"\n    const semicolon = imports[0]?.semicolon ?? false\n    s.prepend(\n      `import { ${required} } from ${quote}${targetModule}${quote}${semicolon ? ';' : ''}${lineEnding}`,\n    )\n    modified = true\n  }\n\n  return modified\n}\n\nfunction normalizeNamedImports({\n  named,\n  required,\n  isOwner,\n}: {\n  named: Array<NamedImport>\n  required: RouteConstructorName\n  isOwner: boolean\n}) {\n  const banned = getOtherRouteConstructor(required)\n  const nextNamed: Array<NamedImport> = []\n  const seen = new Set<string>()\n\n  for (const specifier of named) {\n    if (specifier.imported === banned) {\n      continue\n    }\n\n    if (\n      specifier.local === required &&\n      (specifier.imported !== required || !isOwner)\n    ) {\n      continue\n    }\n\n    const key = `${specifier.importKind ?? 'value'}:${specifier.imported}:${specifier.local}`\n    if (seen.has(key)) {\n      continue\n    }\n\n    seen.add(key)\n    nextNamed.push(specifier)\n  }\n\n  if (isOwner && !hasNamedImport(nextNamed, required)) {\n    nextNamed.push({ imported: required, local: required })\n  }\n\n  return nextNamed\n}\n\nfunction getExpectedRouteConstructor(lazy: boolean): RouteConstructorName {\n  return lazy ? 'createLazyFileRoute' : 'createFileRoute'\n}\n\nfunction getOtherRouteConstructor(\n  constructor: RouteConstructorName,\n): RouteConstructorName {\n  return constructor === 'createFileRoute'\n    ? 'createLazyFileRoute'\n    : 'createFileRoute'\n}\n\nfunction hasNamedImport(\n  named: Array<NamedImport>,\n  required: RouteConstructorName,\n) {\n  return named.some(\n    (specifier) =>\n      specifier.imported === required &&\n      specifier.local === required &&\n      specifier.importKind !== 'type',\n  )\n}\n\nfunction sameNamedImports(left: Array<NamedImport>, right: Array<NamedImport>) {\n  return (\n    left.length === right.length &&\n    left.every(\n      (specifier, index) =>\n        specifier.imported === right[index]!.imported &&\n        specifier.local === right[index]!.local &&\n        specifier.importKind === right[index]!.importKind,\n    )\n  )\n}\n\nfunction isRouteConstructorName(value: string): value is RouteConstructorName {\n  return routeConstructors.includes(value as RouteConstructorName)\n}\n\nfunction renderImportDeclaration(importDeclaration: {\n  defaultImport?: string\n  namespace?: string\n  named: Array<NamedImport>\n  moduleName: string\n  quote: '\"' | \"'\"\n  semicolon: boolean\n}) {\n  const parts: Array<string> = []\n\n  if (importDeclaration.defaultImport) {\n    parts.push(importDeclaration.defaultImport)\n  }\n\n  if (importDeclaration.namespace) {\n    parts.push(`* as ${importDeclaration.namespace}`)\n  }\n\n  if (importDeclaration.named.length > 0) {\n    parts.push(\n      `{ ${importDeclaration.named\n        .map(\n          (specifier) =>\n            `${specifier.importKind === 'type' ? 'type ' : ''}${specifier.imported === specifier.local ? specifier.imported : `${specifier.imported} as ${specifier.local}`}`,\n        )\n        .join(', ')} }`,\n    )\n  }\n\n  if (parts.length === 0) {\n    return null\n  }\n\n  return `import ${parts.join(', ')} from ${importDeclaration.quote}${importDeclaration.moduleName}${importDeclaration.quote}${importDeclaration.semicolon ? ';' : ''}`\n}\n\nfunction getLineEnding(source: string): '\\r\\n' | '\\n' | '\\r' {\n  if (source.includes('\\r\\n')) {\n    return '\\r\\n'\n  }\n\n  if (source.includes('\\n')) {\n    return '\\n'\n  }\n\n  if (source.includes('\\r')) {\n    return '\\r'\n  }\n\n  return '\\n'\n}\n\nfunction getRemovalEnd(source: string, end: number) {\n  let pos = end\n  while (pos < source.length && (source[pos] === ' ' || source[pos] === '\\t')) {\n    pos++\n  }\n\n  if (source[pos] === '\\r' && source[pos + 1] === '\\n') {\n    return pos + 2\n  }\n\n  if (source[pos] === '\\n' || source[pos] === '\\r') {\n    return pos + 1\n  }\n\n  return end\n}\n"],"mappings":";;;;;;;AAKA,IAAM,oBAAoB,CAAC,mBAAmB,qBAAqB;AA0CnE,SAAgB,UAAU,EACxB,KACA,QACA,UACA,QACoC;CACpC,IAAI;CAEJ,IAAI;EACF,OAAA,GAAA,uBAAA,UAAe;GAAE,MAAM;GAAQ;EAAS,CAAC;CAC3C,SAAS,OAAO;EACd,OAAO;GACL,QAAQ;GACR;EACF;CACF;CAE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