@tanstack/start-plugin-core 1.169.9 → 1.169.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,6 +19,16 @@ function getStringLiteralValueStart(node) {
19
19
  if (typeof raw === "string" && (raw.startsWith("'") || raw.startsWith("\""))) return node.start + 1;
20
20
  return node.start;
21
21
  }
22
+ function isTypeOnlyImportDeclaration(node) {
23
+ if (node.importKind === "type") return true;
24
+ if (node.specifiers.length === 0) return false;
25
+ return node.specifiers.every((specifier) => t.isImportSpecifier(specifier) && specifier.importKind === "type");
26
+ }
27
+ function isTypeOnlyExportNamedDeclaration(node) {
28
+ if (node.exportKind === "type") return true;
29
+ if (!node.source || node.declaration || node.specifiers.length === 0) return false;
30
+ return node.specifiers.every((specifier) => t.isExportSpecifier(specifier) && specifier.exportKind === "type");
31
+ }
22
32
  function collectIdentifiersFromPattern(pattern, add) {
23
33
  if (t.isIdentifier(pattern)) add(pattern.name);
24
34
  else if (t.isObjectPattern(pattern)) for (const prop of pattern.properties) if (t.isRestElement(prop)) collectIdentifiersFromPattern(prop.argument, add);
@@ -66,8 +76,8 @@ function buildImportAnalysis(result) {
66
76
  };
67
77
  const visit = (node) => {
68
78
  if (t.isImportDeclaration(node)) {
69
- addSpecifierLocation(node.source);
70
- if (node.importKind !== "type") {
79
+ if (!isTypeOnlyImportDeclaration(node)) {
80
+ addSpecifierLocation(node.source);
71
81
  const source = node.source.value;
72
82
  const bindingInfo = getBindingInfo(source);
73
83
  for (const specifier of node.specifiers) {
@@ -89,8 +99,9 @@ function buildImportAnalysis(result) {
89
99
  }
90
100
  }
91
101
  } else if (t.isExportNamedDeclaration(node)) {
92
- if (node.source && t.isStringLiteral(node.source)) addSpecifierLocation(node.source);
93
- if (node.exportKind !== "type" && node.source?.value) {
102
+ const isTypeOnly = isTypeOnlyExportNamedDeclaration(node);
103
+ if (!isTypeOnly && node.source && t.isStringLiteral(node.source)) addSpecifierLocation(node.source);
104
+ if (!isTypeOnly && node.source?.value) {
94
105
  const source = node.source.value;
95
106
  for (const specifier of node.specifiers) {
96
107
  if (!t.isExportSpecifier(specifier)) continue;
@@ -98,7 +109,7 @@ function buildImportAnalysis(result) {
98
109
  addMockName(source, getModuleExportName(specifier.local));
99
110
  }
100
111
  }
101
- if (node.exportKind !== "type") {
112
+ if (!isTypeOnly) {
102
113
  if (node.declaration) {
103
114
  const decl = node.declaration;
104
115
  if (t.isFunctionDeclaration(decl) || t.isClassDeclaration(decl)) {
@@ -111,8 +122,9 @@ function buildImportAnalysis(result) {
111
122
  addNamedExport(getModuleExportName(specifier.exported));
112
123
  }
113
124
  }
114
- } else if (t.isExportAllDeclaration(node)) addSpecifierLocation(node.source);
115
- else if (t.isImportExpression(node)) {
125
+ } else if (t.isExportAllDeclaration(node)) {
126
+ if (node.exportKind !== "type") addSpecifierLocation(node.source);
127
+ } else if (t.isImportExpression(node)) {
116
128
  if (t.isStringLiteral(node.source)) addSpecifierLocation(node.source);
117
129
  } else if (t.isCallExpression(node) && t.isImport(node.callee)) {
118
130
  const sourceNode = node.arguments[0];
@@ -1 +1 @@
1
- {"version":3,"file":"analysis.js","names":[],"sources":["../../../src/import-protection/analysis.ts"],"sourcesContent":["import * as t from '@babel/types'\n\nimport { parseImportProtectionAst } from './ast'\nimport { buildLineIndex } from './sourceLocation'\nimport { getOrCreate } from './utils'\nimport type { LineIndex, TransformResult } from './sourceLocation'\nimport type { ParsedAst } from './ast'\n\nexport type UsagePos = { line: number; column0: number }\n\ntype BoundaryEnv = 'client' | 'server'\n\ntype ImportBindingInfo = {\n importedLocalNames: Set<string>\n memberBindingToSource: Map<string, string>\n}\n\ntype UsageCacheKey = `${BoundaryEnv | 'post'}::${string}`\n\nexport type ImportAnalysis = {\n ast: ParsedAst\n lineIndex: LineIndex\n importSourcesInOrder: Array<string>\n importSpecifierLocationIndex: Map<string, number>\n importBindingsBySource: Map<string, ImportBindingInfo>\n mockExportNamesBySource: Map<string, Array<string>>\n namedExports: Array<string>\n usageByKey: Map<UsageCacheKey, UsagePos | null>\n}\n\nfunction makeTransientResult(code: string): TransformResult {\n return {\n code,\n map: undefined,\n originalCode: undefined,\n }\n}\n\nfunction getModuleExportName(node: t.Identifier | t.StringLiteral): string {\n return t.isIdentifier(node) ? node.name : node.value\n}\n\nfunction getStringLiteralValueStart(node: t.StringLiteral): number {\n if (node.start == null) {\n return -1\n }\n\n const raw = node.extra?.raw\n if (typeof raw === 'string' && (raw.startsWith(\"'\") || raw.startsWith('\"'))) {\n return node.start + 1\n }\n\n return node.start\n}\n\nfunction collectIdentifiersFromPattern(\n pattern: t.LVal,\n add: (name: string) => void,\n): void {\n if (t.isIdentifier(pattern)) {\n add(pattern.name)\n } else if (t.isObjectPattern(pattern)) {\n for (const prop of pattern.properties) {\n if (t.isRestElement(prop)) {\n collectIdentifiersFromPattern(prop.argument as t.LVal, add)\n } else {\n collectIdentifiersFromPattern(prop.value as t.LVal, add)\n }\n }\n } else if (t.isArrayPattern(pattern)) {\n for (const elem of pattern.elements) {\n if (elem) collectIdentifiersFromPattern(elem as t.LVal, add)\n }\n } else if (t.isAssignmentPattern(pattern)) {\n collectIdentifiersFromPattern(pattern.left, add)\n } else if (t.isRestElement(pattern)) {\n collectIdentifiersFromPattern(pattern.argument as t.LVal, add)\n }\n}\n\nexport function isValidExportName(name: string): boolean {\n if (name === 'default' || name.length === 0) return false\n const first = name.charCodeAt(0)\n if (\n !(\n (first >= 65 && first <= 90) ||\n (first >= 97 && first <= 122) ||\n first === 95 ||\n first === 36\n )\n )\n return false\n for (let i = 1; i < name.length; i++) {\n const ch = name.charCodeAt(i)\n if (\n !(\n (ch >= 65 && ch <= 90) ||\n (ch >= 97 && ch <= 122) ||\n (ch >= 48 && ch <= 57) ||\n ch === 95 ||\n ch === 36\n )\n )\n return false\n }\n return true\n}\n\nfunction buildImportAnalysis(result: TransformResult): ImportAnalysis {\n const ast = result.parsedAst ?? parseImportProtectionAst(result.code)\n result.parsedAst = ast\n\n const importSourcesInOrder: Array<string> = []\n const importSpecifierLocationIndex = new Map<string, number>()\n const importBindingsBySource = new Map<string, ImportBindingInfo>()\n const mockNamesBySource = new Map<string, Set<string>>()\n const namedExports = new Set<string>()\n\n const getBindingInfo = (source: string): ImportBindingInfo =>\n getOrCreate(importBindingsBySource, source, () => ({\n importedLocalNames: new Set<string>(),\n memberBindingToSource: new Map<string, string>(),\n }))\n\n const addSpecifierLocation = (node: t.StringLiteral) => {\n importSourcesInOrder.push(node.value)\n\n const index = getStringLiteralValueStart(node)\n if (index === -1) {\n return\n }\n\n const prev = importSpecifierLocationIndex.get(node.value)\n if (prev == null || index < prev) {\n importSpecifierLocationIndex.set(node.value, index)\n }\n }\n\n const addMockName = (source: string, name: string) => {\n if (name === 'default' || name.length === 0) return\n getOrCreate(mockNamesBySource, source, () => new Set<string>()).add(name)\n }\n\n const addNamedExport = (name: string) => {\n if (name !== 'default' && name.length > 0) {\n namedExports.add(name)\n }\n }\n\n const visit = (node: t.Node): void => {\n if (t.isImportDeclaration(node)) {\n addSpecifierLocation(node.source)\n if (node.importKind !== 'type') {\n const source = node.source.value\n const bindingInfo = getBindingInfo(source)\n for (const specifier of node.specifiers) {\n if (t.isImportNamespaceSpecifier(specifier)) {\n bindingInfo.importedLocalNames.add(specifier.local.name)\n bindingInfo.memberBindingToSource.set(specifier.local.name, source)\n continue\n }\n\n if (t.isImportDefaultSpecifier(specifier)) {\n bindingInfo.importedLocalNames.add(specifier.local.name)\n bindingInfo.memberBindingToSource.set(specifier.local.name, source)\n continue\n }\n\n if (!t.isImportSpecifier(specifier)) continue\n if (specifier.importKind === 'type') continue\n\n bindingInfo.importedLocalNames.add(specifier.local.name)\n const importedName = getModuleExportName(specifier.imported)\n if (importedName !== 'default') {\n addMockName(source, importedName)\n }\n }\n }\n } else if (t.isExportNamedDeclaration(node)) {\n if (node.source && t.isStringLiteral(node.source)) {\n addSpecifierLocation(node.source)\n }\n\n if (node.exportKind !== 'type' && node.source?.value) {\n const source = node.source.value\n for (const specifier of node.specifiers) {\n if (!t.isExportSpecifier(specifier)) continue\n if (specifier.exportKind === 'type') continue\n addMockName(source, getModuleExportName(specifier.local))\n }\n }\n\n if (node.exportKind !== 'type') {\n if (node.declaration) {\n const decl = node.declaration\n if (t.isFunctionDeclaration(decl) || t.isClassDeclaration(decl)) {\n if (decl.id?.name) addNamedExport(decl.id.name)\n } else if (t.isVariableDeclaration(decl)) {\n for (const d of decl.declarations) {\n collectIdentifiersFromPattern(d.id as t.LVal, addNamedExport)\n }\n }\n }\n\n for (const specifier of node.specifiers) {\n if (!t.isExportSpecifier(specifier)) continue\n if (specifier.exportKind === 'type') continue\n const exportedName = getModuleExportName(specifier.exported)\n addNamedExport(exportedName)\n }\n }\n } else if (t.isExportAllDeclaration(node)) {\n addSpecifierLocation(node.source)\n } else if (t.isImportExpression(node)) {\n if (t.isStringLiteral(node.source)) {\n addSpecifierLocation(node.source)\n }\n } else if (t.isCallExpression(node) && t.isImport(node.callee)) {\n const sourceNode = node.arguments[0]\n if (t.isStringLiteral(sourceNode)) {\n addSpecifierLocation(sourceNode)\n }\n } else if (\n t.isMemberExpression(node) ||\n t.isOptionalMemberExpression(node)\n ) {\n const object = node.object\n if (t.isIdentifier(object)) {\n for (const [source, bindingInfo] of importBindingsBySource) {\n if (!bindingInfo.memberBindingToSource.has(object.name)) {\n continue\n }\n\n const property = node.property\n if (!node.computed && t.isIdentifier(property)) {\n addMockName(source, property.name)\n } else if (node.computed && t.isStringLiteral(property)) {\n addMockName(source, property.value)\n }\n }\n }\n }\n\n const keys = t.VISITOR_KEYS[node.type]\n if (!keys) return\n for (const key of keys) {\n const child = (node as unknown as Record<string, unknown>)[key]\n if (Array.isArray(child)) {\n for (const item of child) {\n if (item && typeof item === 'object' && 'type' in item) {\n visit(item as t.Node)\n }\n }\n } else if (child && typeof child === 'object' && 'type' in child) {\n visit(child as t.Node)\n }\n }\n }\n\n visit(ast.program)\n\n const mockExportNamesBySource = new Map<string, Array<string>>()\n for (const [source, names] of mockNamesBySource) {\n mockExportNamesBySource.set(source, Array.from(names).sort())\n }\n\n const lineIndex = result.lineIndex ?? buildLineIndex(result.code)\n result.lineIndex = lineIndex\n\n const analysis = {\n ast,\n lineIndex,\n importSourcesInOrder,\n importSpecifierLocationIndex,\n importBindingsBySource,\n mockExportNamesBySource,\n namedExports: Array.from(namedExports).sort(),\n usageByKey: new Map(),\n }\n\n return analysis\n}\n\nexport function getOrCreateImportAnalysis(\n result: TransformResult,\n): ImportAnalysis {\n if (!result.analysis) {\n result.analysis = buildImportAnalysis(result)\n }\n\n return result.analysis\n}\n\nexport function getImportSourcesFromResult(\n result: TransformResult,\n): Array<string> {\n return getOrCreateImportAnalysis(result).importSourcesInOrder\n}\n\nexport function getImportSources(code: string): Array<string> {\n return getImportSourcesFromResult(makeTransientResult(code))\n}\n\nexport function getImportSpecifierLocationFromResult(\n result: TransformResult,\n source: string,\n): number {\n return (\n getOrCreateImportAnalysis(result).importSpecifierLocationIndex.get(\n source,\n ) ?? -1\n )\n}\n\nexport function getMockExportNamesBySourceFromResult(\n result: TransformResult,\n): Map<string, Array<string>> {\n return getOrCreateImportAnalysis(result).mockExportNamesBySource\n}\n\nexport function getMockExportNamesBySource(\n code: string,\n): Map<string, Array<string>> {\n return getMockExportNamesBySourceFromResult(makeTransientResult(code))\n}\n\nexport function getNamedExportsFromResult(\n result: TransformResult,\n): Array<string> {\n return getOrCreateImportAnalysis(result).namedExports\n}\n\nexport function getNamedExports(code: string): Array<string> {\n return getNamedExportsFromResult(makeTransientResult(code))\n}\n\nfunction isCompilerSafeBoundaryCall(\n call: t.CallExpression,\n fnNode: t.Function,\n envType: BoundaryEnv,\n): boolean {\n const directArgument = call.arguments.some((arg) => arg === fnNode)\n if (!directArgument) {\n return false\n }\n\n const callee = call.callee\n\n if (t.isIdentifier(callee)) {\n return envType === 'client'\n ? callee.name === 'createServerOnlyFn'\n : callee.name === 'createClientOnlyFn'\n }\n\n if (!t.isMemberExpression(callee) || callee.computed) {\n return false\n }\n\n if (!t.isIdentifier(callee.property)) {\n return false\n }\n\n const prop = callee.property.name\n const rootName = getCalleeRootName(callee.object)\n\n if (envType === 'client') {\n if (prop === 'handler') {\n return rootName === 'createServerFn' || /ServerFn$/.test(rootName ?? '')\n }\n\n if (prop === 'server') {\n return (\n rootName === 'createMiddleware' ||\n rootName === 'createIsomorphicFn' ||\n /Middleware$/.test(rootName ?? '')\n )\n }\n\n return false\n }\n\n if (prop === 'client') {\n return rootName === 'createIsomorphicFn'\n }\n\n return false\n}\n\nfunction getCalleeRootName(\n node: t.Expression | t.Super | t.V8IntrinsicIdentifier,\n): string | undefined {\n if (t.isIdentifier(node)) {\n return node.name\n }\n\n if (t.isCallExpression(node)) {\n return getCalleeRootName(node.callee)\n }\n\n if (t.isMemberExpression(node)) {\n return getCalleeRootName(node.object)\n }\n\n return undefined\n}\n\nfunction getBoundNamesFromPattern(pattern: t.LVal, out: Set<string>): void {\n if (t.isIdentifier(pattern)) {\n out.add(pattern.name)\n } else if (t.isObjectPattern(pattern)) {\n for (const prop of pattern.properties) {\n if (t.isRestElement(prop)) {\n getBoundNamesFromPattern(prop.argument as t.LVal, out)\n } else {\n getBoundNamesFromPattern(prop.value as t.LVal, out)\n }\n }\n } else if (t.isArrayPattern(pattern)) {\n for (const elem of pattern.elements) {\n if (elem) getBoundNamesFromPattern(elem as t.LVal, out)\n }\n } else if (t.isAssignmentPattern(pattern)) {\n getBoundNamesFromPattern(pattern.left, out)\n } else if (t.isRestElement(pattern)) {\n getBoundNamesFromPattern(pattern.argument as t.LVal, out)\n }\n}\n\nfunction addPatternBindingsIfTracked(\n pattern: t.LVal,\n tracked: Set<string>,\n out: Set<string>,\n): void {\n const names = new Set<string>()\n getBoundNamesFromPattern(pattern, names)\n for (const name of names) {\n if (tracked.has(name)) {\n out.add(name)\n }\n }\n}\n\nfunction collectHoistedVarBindings(\n node: t.Node,\n tracked: Set<string>,\n out: Set<string>,\n isRoot = true,\n): void {\n if (!isRoot && t.isFunction(node)) {\n return\n }\n\n if (t.isVariableDeclaration(node) && node.kind === 'var') {\n for (const decl of node.declarations) {\n addPatternBindingsIfTracked(decl.id as t.LVal, tracked, out)\n }\n }\n\n const keys = t.VISITOR_KEYS[node.type]\n if (!keys) return\n for (const key of keys) {\n const child = (node as unknown as Record<string, unknown>)[key]\n if (Array.isArray(child)) {\n for (const item of child) {\n if (item && typeof item === 'object' && 'type' in item) {\n collectHoistedVarBindings(item as t.Node, tracked, out, false)\n }\n }\n } else if (child && typeof child === 'object' && 'type' in child) {\n collectHoistedVarBindings(child as t.Node, tracked, out, false)\n }\n }\n}\n\nfunction collectProgramBindings(\n program: t.Program,\n tracked: Set<string>,\n): Set<string> {\n const bindings = new Set<string>()\n\n for (const node of program.body) {\n if (t.isVariableDeclaration(node)) {\n for (const decl of node.declarations) {\n addPatternBindingsIfTracked(decl.id as t.LVal, tracked, bindings)\n }\n continue\n }\n\n if (t.isFunctionDeclaration(node) || t.isClassDeclaration(node)) {\n if (node.id && tracked.has(node.id.name)) {\n bindings.add(node.id.name)\n }\n }\n }\n\n return bindings\n}\n\nfunction collectBlockBindings(\n block: t.BlockStatement,\n tracked: Set<string>,\n): Set<string> {\n const bindings = new Set<string>()\n\n for (const node of block.body) {\n if (t.isVariableDeclaration(node) && node.kind !== 'var') {\n for (const decl of node.declarations) {\n addPatternBindingsIfTracked(decl.id as t.LVal, tracked, bindings)\n }\n continue\n }\n\n if (t.isFunctionDeclaration(node) || t.isClassDeclaration(node)) {\n if (node.id && tracked.has(node.id.name)) {\n bindings.add(node.id.name)\n }\n }\n }\n\n return bindings\n}\n\nfunction collectFunctionBindings(\n fn: t.Function,\n tracked: Set<string>,\n): Set<string> {\n const bindings = new Set<string>()\n\n if (\n (t.isFunctionDeclaration(fn) || t.isFunctionExpression(fn)) &&\n fn.id &&\n tracked.has(fn.id.name)\n ) {\n bindings.add(fn.id.name)\n }\n\n for (const param of fn.params) {\n addPatternBindingsIfTracked(param as t.LVal, tracked, bindings)\n }\n\n if (t.isBlockStatement(fn.body)) {\n collectHoistedVarBindings(fn.body, tracked, bindings)\n }\n\n return bindings\n}\n\ntype UsageWalkContext = {\n parents: Array<t.Node>\n scopeStack: Array<Set<string>>\n}\n\nfunction isShadowedByScope(\n name: string,\n scopeStack: Array<Set<string>>,\n): boolean {\n for (let i = scopeStack.length - 1; i >= 0; i--) {\n if (scopeStack[i]?.has(name)) {\n return true\n }\n }\n return false\n}\n\nfunction isBindingIdentifierInParent(\n node: t.Identifier,\n parent: t.Node | undefined,\n): boolean {\n if (!parent) return false\n\n if (t.isImportSpecifier(parent) || t.isImportDefaultSpecifier(parent)) {\n return parent.local === node\n }\n if (t.isImportNamespaceSpecifier(parent)) {\n return parent.local === node\n }\n if (t.isFunctionDeclaration(parent) || t.isFunctionExpression(parent)) {\n return (\n parent.id === node || parent.params.includes(node as unknown as t.Pattern)\n )\n }\n if (t.isArrowFunctionExpression(parent)) {\n return parent.params.includes(node as unknown as t.Pattern)\n }\n if (t.isClassDeclaration(parent) || t.isClassExpression(parent)) {\n return parent.id === node\n }\n if (t.isVariableDeclarator(parent)) {\n return parent.id === node\n }\n if (t.isCatchClause(parent)) {\n return parent.param === node\n }\n\n return false\n}\n\nfunction isInsideCompilerSafeBoundaryNodes(\n parents: Array<t.Node>,\n envType: BoundaryEnv,\n): boolean {\n for (let i = parents.length - 1; i >= 0; i--) {\n const node = parents[i]!\n if (!t.isFunction(node)) {\n continue\n }\n\n const call = parents[i - 1]\n if (\n call &&\n t.isCallExpression(call) &&\n isCompilerSafeBoundaryCall(call, node, envType)\n ) {\n return true\n }\n }\n\n return false\n}\n\nfunction findUsagePosInAnalysis(\n result: TransformResult,\n source: string,\n envType?: BoundaryEnv,\n): UsagePos | undefined {\n const analysis = getOrCreateImportAnalysis(result)\n const cacheKey: UsageCacheKey = `${envType ?? 'post'}::${source}`\n if (analysis.usageByKey.has(cacheKey)) {\n return analysis.usageByKey.get(cacheKey) ?? undefined\n }\n\n const imported =\n analysis.importBindingsBySource.get(source)?.importedLocalNames\n if (!imported || imported.size === 0) {\n analysis.usageByKey.set(cacheKey, null)\n return undefined\n }\n\n let preferred: UsagePos | undefined\n let anyUsage: UsagePos | undefined\n\n const visit = (node: t.Node, ctx: UsageWalkContext): void => {\n if (preferred && anyUsage) {\n return\n }\n\n if (t.isProgram(node)) {\n const nextCtx = {\n parents: [...ctx.parents, node],\n scopeStack: [...ctx.scopeStack, collectProgramBindings(node, imported)],\n }\n for (const child of node.body) {\n visit(child, nextCtx)\n }\n return\n }\n\n if (t.isFunction(node)) {\n const functionCtx = {\n parents: [...ctx.parents, node],\n scopeStack: [\n ...ctx.scopeStack,\n collectFunctionBindings(node, imported),\n ],\n }\n\n visit(node.body, functionCtx)\n return\n }\n\n if (t.isBlockStatement(node)) {\n const nextCtx = {\n parents: [...ctx.parents, node],\n scopeStack: [...ctx.scopeStack, collectBlockBindings(node, imported)],\n }\n for (const child of node.body) {\n visit(child, nextCtx)\n }\n return\n }\n\n if (t.isCatchClause(node)) {\n const bindings = new Set<string>()\n if (node.param) {\n addPatternBindingsIfTracked(node.param as t.LVal, imported, bindings)\n }\n const nextCtx = {\n parents: [...ctx.parents, node],\n scopeStack: bindings.size\n ? [...ctx.scopeStack, bindings]\n : ctx.scopeStack,\n }\n visit(node.body, nextCtx)\n return\n }\n\n if (\n t.isForStatement(node) &&\n t.isVariableDeclaration(node.init) &&\n node.init.kind !== 'var'\n ) {\n const bindings = new Set<string>()\n for (const decl of node.init.declarations) {\n addPatternBindingsIfTracked(decl.id as t.LVal, imported, bindings)\n }\n const nextCtx = {\n parents: [...ctx.parents, node],\n scopeStack: bindings.size\n ? [...ctx.scopeStack, bindings]\n : ctx.scopeStack,\n }\n visit(node.init, nextCtx)\n if (node.test) visit(node.test, nextCtx)\n if (node.update) visit(node.update, nextCtx)\n visit(node.body, nextCtx)\n return\n }\n\n if (\n (t.isForInStatement(node) || t.isForOfStatement(node)) &&\n t.isVariableDeclaration(node.left) &&\n node.left.kind !== 'var'\n ) {\n const bindings = new Set<string>()\n for (const decl of node.left.declarations) {\n addPatternBindingsIfTracked(decl.id as t.LVal, imported, bindings)\n }\n const nextCtx = {\n parents: [...ctx.parents, node],\n scopeStack: bindings.size\n ? [...ctx.scopeStack, bindings]\n : ctx.scopeStack,\n }\n visit(node.left, nextCtx)\n visit(node.right, nextCtx)\n visit(node.body, nextCtx)\n return\n }\n\n const nextParents = [...ctx.parents, node]\n\n if (t.isIdentifier(node)) {\n const parent = ctx.parents[ctx.parents.length - 1]\n if (imported.has(node.name)) {\n if (!isBindingIdentifierInParent(node, parent)) {\n if (\n !(\n t.isObjectProperty(parent) &&\n parent.key === node &&\n !parent.computed &&\n !parent.shorthand\n ) &&\n !(\n t.isObjectMethod(parent) &&\n parent.key === node &&\n !parent.computed\n ) &&\n !(t.isExportSpecifier(parent) && parent.exported === node) &&\n !isShadowedByScope(node.name, ctx.scopeStack) &&\n !(\n envType && isInsideCompilerSafeBoundaryNodes(ctx.parents, envType)\n )\n ) {\n const loc = node.loc?.start\n if (loc) {\n const pos: UsagePos = { line: loc.line, column0: loc.column }\n const isPreferred =\n (t.isCallExpression(parent) && parent.callee === node) ||\n (t.isNewExpression(parent) && parent.callee === node) ||\n ((t.isMemberExpression(parent) ||\n t.isOptionalMemberExpression(parent)) &&\n parent.object === node)\n\n if (isPreferred) {\n preferred ||= pos\n } else {\n anyUsage ||= pos\n }\n }\n }\n }\n }\n }\n\n if (t.isImportDeclaration(node)) {\n return\n }\n\n const keys = t.VISITOR_KEYS[node.type]\n if (!keys) return\n for (const key of keys) {\n const child = (node as unknown as Record<string, unknown>)[key]\n if (Array.isArray(child)) {\n for (const item of child) {\n if (item && typeof item === 'object' && 'type' in item) {\n visit(item as t.Node, {\n parents: nextParents,\n scopeStack: ctx.scopeStack,\n })\n }\n }\n } else if (child && typeof child === 'object' && 'type' in child) {\n visit(child as t.Node, {\n parents: nextParents,\n scopeStack: ctx.scopeStack,\n })\n }\n }\n }\n\n visit(analysis.ast.program, {\n parents: [],\n scopeStack: [],\n })\n\n const pos = preferred ?? anyUsage ?? null\n analysis.usageByKey.set(cacheKey, pos)\n return pos ?? undefined\n}\n\nexport function findPostCompileUsagePosFromResult(\n result: TransformResult,\n source: string,\n): UsagePos | undefined {\n return findUsagePosInAnalysis(result, source)\n}\n\nexport function findPostCompileUsagePos(\n code: string,\n source: string,\n): UsagePos | undefined {\n return findPostCompileUsagePosFromResult(makeTransientResult(code), source)\n}\n\nexport function findOriginalUnsafeUsagePosFromResult(\n result: TransformResult,\n source: string,\n envType: BoundaryEnv,\n): UsagePos | undefined {\n return findUsagePosInAnalysis(result, source, envType)\n}\n\nexport function findOriginalUnsafeUsagePos(\n code: string,\n source: string,\n envType: BoundaryEnv,\n): UsagePos | undefined {\n return findOriginalUnsafeUsagePosFromResult(\n makeTransientResult(code),\n source,\n envType,\n )\n}\n"],"mappings":";;;;;AA8BA,SAAS,oBAAoB,MAA+B;AAC1D,QAAO;EACL;EACA,KAAK,KAAA;EACL,cAAc,KAAA;EACf;;AAGH,SAAS,oBAAoB,MAA8C;AACzE,QAAO,EAAE,aAAa,KAAK,GAAG,KAAK,OAAO,KAAK;;AAGjD,SAAS,2BAA2B,MAA+B;AACjE,KAAI,KAAK,SAAS,KAChB,QAAO;CAGT,MAAM,MAAM,KAAK,OAAO;AACxB,KAAI,OAAO,QAAQ,aAAa,IAAI,WAAW,IAAI,IAAI,IAAI,WAAW,KAAI,EACxE,QAAO,KAAK,QAAQ;AAGtB,QAAO,KAAK;;AAGd,SAAS,8BACP,SACA,KACM;AACN,KAAI,EAAE,aAAa,QAAQ,CACzB,KAAI,QAAQ,KAAK;UACR,EAAE,gBAAgB,QAAQ,CACnC,MAAK,MAAM,QAAQ,QAAQ,WACzB,KAAI,EAAE,cAAc,KAAK,CACvB,+BAA8B,KAAK,UAAoB,IAAI;KAE3D,+BAA8B,KAAK,OAAiB,IAAI;UAGnD,EAAE,eAAe,QAAQ;OAC7B,MAAM,QAAQ,QAAQ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AAM;GACtB,MAAM,QAAS,KAA4C;AAC3D,OAAI,MAAM,QAAQ,MAAM;SACjB,MAAM,QAAQ,MACjB,KAAI,QAAQ,OAAO,SAAS,YAAY,UAAU,KAChD,OAAM,MAAgB;KACpB,SAAS;KACT,YAAY,IAAI;KACjB,CAAC;cAGG,SAAS,OAAO,UAAU,YAAY,UAAU,MACzD,OAAM,OAAiB;IACrB,SAAS;IACT,YAAY,IAAI;IACjB,CAAC;;;AAKR,OAAM,SAAS,IAAI,SAAS;EAC1B,SAAS,EAAE;EACX,YAAY,EAAE;EACf,CAAC;CAEF,MAAM,MAAM,aAAa,YAAY;AACrC,UAAS,WAAW,IAAI,UAAU,IAAI;AACtC,QAAO,OAAO,KAAA;;AAGhB,SAAgB,kCACd,QACA,QACsB;AACtB,QAAO,uBAAuB,QAAQ,OAAO;;AAU/C,SAAgB,qCACd,QACA,QACA,SACsB;AACtB,QAAO,uBAAuB,QAAQ,QAAQ,QAAQ"}
1
+ {"version":3,"file":"analysis.js","names":[],"sources":["../../../src/import-protection/analysis.ts"],"sourcesContent":["import * as t from '@babel/types'\n\nimport { parseImportProtectionAst } from './ast'\nimport { buildLineIndex } from './sourceLocation'\nimport { getOrCreate } from './utils'\nimport type { LineIndex, TransformResult } from './sourceLocation'\nimport type { ParsedAst } from './ast'\n\nexport type UsagePos = { line: number; column0: number }\n\ntype BoundaryEnv = 'client' | 'server'\n\ntype ImportBindingInfo = {\n importedLocalNames: Set<string>\n memberBindingToSource: Map<string, string>\n}\n\ntype UsageCacheKey = `${BoundaryEnv | 'post'}::${string}`\n\nexport type ImportAnalysis = {\n ast: ParsedAst\n lineIndex: LineIndex\n importSourcesInOrder: Array<string>\n importSpecifierLocationIndex: Map<string, number>\n importBindingsBySource: Map<string, ImportBindingInfo>\n mockExportNamesBySource: Map<string, Array<string>>\n namedExports: Array<string>\n usageByKey: Map<UsageCacheKey, UsagePos | null>\n}\n\nfunction makeTransientResult(code: string): TransformResult {\n return {\n code,\n map: undefined,\n originalCode: undefined,\n }\n}\n\nfunction getModuleExportName(node: t.Identifier | t.StringLiteral): string {\n return t.isIdentifier(node) ? node.name : node.value\n}\n\nfunction getStringLiteralValueStart(node: t.StringLiteral): number {\n if (node.start == null) {\n return -1\n }\n\n const raw = node.extra?.raw\n if (typeof raw === 'string' && (raw.startsWith(\"'\") || raw.startsWith('\"'))) {\n return node.start + 1\n }\n\n return node.start\n}\n\nfunction isTypeOnlyImportDeclaration(node: t.ImportDeclaration): boolean {\n if (node.importKind === 'type') return true\n if (node.specifiers.length === 0) return false\n\n return node.specifiers.every(\n (specifier) =>\n t.isImportSpecifier(specifier) && specifier.importKind === 'type',\n )\n}\n\nfunction isTypeOnlyExportNamedDeclaration(\n node: t.ExportNamedDeclaration,\n): boolean {\n if (node.exportKind === 'type') return true\n if (!node.source || node.declaration || node.specifiers.length === 0) {\n return false\n }\n\n return node.specifiers.every(\n (specifier) =>\n t.isExportSpecifier(specifier) && specifier.exportKind === 'type',\n )\n}\n\nfunction collectIdentifiersFromPattern(\n pattern: t.LVal,\n add: (name: string) => void,\n): void {\n if (t.isIdentifier(pattern)) {\n add(pattern.name)\n } else if (t.isObjectPattern(pattern)) {\n for (const prop of pattern.properties) {\n if (t.isRestElement(prop)) {\n collectIdentifiersFromPattern(prop.argument as t.LVal, add)\n } else {\n collectIdentifiersFromPattern(prop.value as t.LVal, add)\n }\n }\n } else if (t.isArrayPattern(pattern)) {\n for (const elem of pattern.elements) {\n if (elem) collectIdentifiersFromPattern(elem as t.LVal, add)\n }\n } else if (t.isAssignmentPattern(pattern)) {\n collectIdentifiersFromPattern(pattern.left, add)\n } else if (t.isRestElement(pattern)) {\n collectIdentifiersFromPattern(pattern.argument as t.LVal, add)\n }\n}\n\nexport function isValidExportName(name: string): boolean {\n if (name === 'default' || name.length === 0) return false\n const first = name.charCodeAt(0)\n if (\n !(\n (first >= 65 && first <= 90) ||\n (first >= 97 && first <= 122) ||\n first === 95 ||\n first === 36\n )\n )\n return false\n for (let i = 1; i < name.length; i++) {\n const ch = name.charCodeAt(i)\n if (\n !(\n (ch >= 65 && ch <= 90) ||\n (ch >= 97 && ch <= 122) ||\n (ch >= 48 && ch <= 57) ||\n ch === 95 ||\n ch === 36\n )\n )\n return false\n }\n return true\n}\n\nfunction buildImportAnalysis(result: TransformResult): ImportAnalysis {\n const ast = result.parsedAst ?? parseImportProtectionAst(result.code)\n result.parsedAst = ast\n\n const importSourcesInOrder: Array<string> = []\n const importSpecifierLocationIndex = new Map<string, number>()\n const importBindingsBySource = new Map<string, ImportBindingInfo>()\n const mockNamesBySource = new Map<string, Set<string>>()\n const namedExports = new Set<string>()\n\n const getBindingInfo = (source: string): ImportBindingInfo =>\n getOrCreate(importBindingsBySource, source, () => ({\n importedLocalNames: new Set<string>(),\n memberBindingToSource: new Map<string, string>(),\n }))\n\n const addSpecifierLocation = (node: t.StringLiteral) => {\n importSourcesInOrder.push(node.value)\n\n const index = getStringLiteralValueStart(node)\n if (index === -1) {\n return\n }\n\n const prev = importSpecifierLocationIndex.get(node.value)\n if (prev == null || index < prev) {\n importSpecifierLocationIndex.set(node.value, index)\n }\n }\n\n const addMockName = (source: string, name: string) => {\n if (name === 'default' || name.length === 0) return\n getOrCreate(mockNamesBySource, source, () => new Set<string>()).add(name)\n }\n\n const addNamedExport = (name: string) => {\n if (name !== 'default' && name.length > 0) {\n namedExports.add(name)\n }\n }\n\n const visit = (node: t.Node): void => {\n if (t.isImportDeclaration(node)) {\n const isTypeOnly = isTypeOnlyImportDeclaration(node)\n if (!isTypeOnly) {\n addSpecifierLocation(node.source)\n const source = node.source.value\n const bindingInfo = getBindingInfo(source)\n for (const specifier of node.specifiers) {\n if (t.isImportNamespaceSpecifier(specifier)) {\n bindingInfo.importedLocalNames.add(specifier.local.name)\n bindingInfo.memberBindingToSource.set(specifier.local.name, source)\n continue\n }\n\n if (t.isImportDefaultSpecifier(specifier)) {\n bindingInfo.importedLocalNames.add(specifier.local.name)\n bindingInfo.memberBindingToSource.set(specifier.local.name, source)\n continue\n }\n\n if (!t.isImportSpecifier(specifier)) continue\n if (specifier.importKind === 'type') continue\n\n bindingInfo.importedLocalNames.add(specifier.local.name)\n const importedName = getModuleExportName(specifier.imported)\n if (importedName !== 'default') {\n addMockName(source, importedName)\n }\n }\n }\n } else if (t.isExportNamedDeclaration(node)) {\n const isTypeOnly = isTypeOnlyExportNamedDeclaration(node)\n if (!isTypeOnly && node.source && t.isStringLiteral(node.source)) {\n addSpecifierLocation(node.source)\n }\n\n if (!isTypeOnly && node.source?.value) {\n const source = node.source.value\n for (const specifier of node.specifiers) {\n if (!t.isExportSpecifier(specifier)) continue\n if (specifier.exportKind === 'type') continue\n addMockName(source, getModuleExportName(specifier.local))\n }\n }\n\n if (!isTypeOnly) {\n if (node.declaration) {\n const decl = node.declaration\n if (t.isFunctionDeclaration(decl) || t.isClassDeclaration(decl)) {\n if (decl.id?.name) addNamedExport(decl.id.name)\n } else if (t.isVariableDeclaration(decl)) {\n for (const d of decl.declarations) {\n collectIdentifiersFromPattern(d.id as t.LVal, addNamedExport)\n }\n }\n }\n\n for (const specifier of node.specifiers) {\n if (!t.isExportSpecifier(specifier)) continue\n if (specifier.exportKind === 'type') continue\n const exportedName = getModuleExportName(specifier.exported)\n addNamedExport(exportedName)\n }\n }\n } else if (t.isExportAllDeclaration(node)) {\n if (node.exportKind !== 'type') {\n addSpecifierLocation(node.source)\n }\n } else if (t.isImportExpression(node)) {\n if (t.isStringLiteral(node.source)) {\n addSpecifierLocation(node.source)\n }\n } else if (t.isCallExpression(node) && t.isImport(node.callee)) {\n const sourceNode = node.arguments[0]\n if (t.isStringLiteral(sourceNode)) {\n addSpecifierLocation(sourceNode)\n }\n } else if (\n t.isMemberExpression(node) ||\n t.isOptionalMemberExpression(node)\n ) {\n const object = node.object\n if (t.isIdentifier(object)) {\n for (const [source, bindingInfo] of importBindingsBySource) {\n if (!bindingInfo.memberBindingToSource.has(object.name)) {\n continue\n }\n\n const property = node.property\n if (!node.computed && t.isIdentifier(property)) {\n addMockName(source, property.name)\n } else if (node.computed && t.isStringLiteral(property)) {\n addMockName(source, property.value)\n }\n }\n }\n }\n\n const keys = t.VISITOR_KEYS[node.type]\n if (!keys) return\n for (const key of keys) {\n const child = (node as unknown as Record<string, unknown>)[key]\n if (Array.isArray(child)) {\n for (const item of child) {\n if (item && typeof item === 'object' && 'type' in item) {\n visit(item as t.Node)\n }\n }\n } else if (child && typeof child === 'object' && 'type' in child) {\n visit(child as t.Node)\n }\n }\n }\n\n visit(ast.program)\n\n const mockExportNamesBySource = new Map<string, Array<string>>()\n for (const [source, names] of mockNamesBySource) {\n mockExportNamesBySource.set(source, Array.from(names).sort())\n }\n\n const lineIndex = result.lineIndex ?? buildLineIndex(result.code)\n result.lineIndex = lineIndex\n\n const analysis = {\n ast,\n lineIndex,\n importSourcesInOrder,\n importSpecifierLocationIndex,\n importBindingsBySource,\n mockExportNamesBySource,\n namedExports: Array.from(namedExports).sort(),\n usageByKey: new Map(),\n }\n\n return analysis\n}\n\nexport function getOrCreateImportAnalysis(\n result: TransformResult,\n): ImportAnalysis {\n if (!result.analysis) {\n result.analysis = buildImportAnalysis(result)\n }\n\n return result.analysis\n}\n\nexport function getImportSourcesFromResult(\n result: TransformResult,\n): Array<string> {\n return getOrCreateImportAnalysis(result).importSourcesInOrder\n}\n\nexport function getImportSources(code: string): Array<string> {\n return getImportSourcesFromResult(makeTransientResult(code))\n}\n\nexport function getImportSpecifierLocationFromResult(\n result: TransformResult,\n source: string,\n): number {\n return (\n getOrCreateImportAnalysis(result).importSpecifierLocationIndex.get(\n source,\n ) ?? -1\n )\n}\n\nexport function getMockExportNamesBySourceFromResult(\n result: TransformResult,\n): Map<string, Array<string>> {\n return getOrCreateImportAnalysis(result).mockExportNamesBySource\n}\n\nexport function getMockExportNamesBySource(\n code: string,\n): Map<string, Array<string>> {\n return getMockExportNamesBySourceFromResult(makeTransientResult(code))\n}\n\nexport function getNamedExportsFromResult(\n result: TransformResult,\n): Array<string> {\n return getOrCreateImportAnalysis(result).namedExports\n}\n\nexport function getNamedExports(code: string): Array<string> {\n return getNamedExportsFromResult(makeTransientResult(code))\n}\n\nfunction isCompilerSafeBoundaryCall(\n call: t.CallExpression,\n fnNode: t.Function,\n envType: BoundaryEnv,\n): boolean {\n const directArgument = call.arguments.some((arg) => arg === fnNode)\n if (!directArgument) {\n return false\n }\n\n const callee = call.callee\n\n if (t.isIdentifier(callee)) {\n return envType === 'client'\n ? callee.name === 'createServerOnlyFn'\n : callee.name === 'createClientOnlyFn'\n }\n\n if (!t.isMemberExpression(callee) || callee.computed) {\n return false\n }\n\n if (!t.isIdentifier(callee.property)) {\n return false\n }\n\n const prop = callee.property.name\n const rootName = getCalleeRootName(callee.object)\n\n if (envType === 'client') {\n if (prop === 'handler') {\n return rootName === 'createServerFn' || /ServerFn$/.test(rootName ?? '')\n }\n\n if (prop === 'server') {\n return (\n rootName === 'createMiddleware' ||\n rootName === 'createIsomorphicFn' ||\n /Middleware$/.test(rootName ?? '')\n )\n }\n\n return false\n }\n\n if (prop === 'client') {\n return rootName === 'createIsomorphicFn'\n }\n\n return false\n}\n\nfunction getCalleeRootName(\n node: t.Expression | t.Super | t.V8IntrinsicIdentifier,\n): string | undefined {\n if (t.isIdentifier(node)) {\n return node.name\n }\n\n if (t.isCallExpression(node)) {\n return getCalleeRootName(node.callee)\n }\n\n if (t.isMemberExpression(node)) {\n return getCalleeRootName(node.object)\n }\n\n return undefined\n}\n\nfunction getBoundNamesFromPattern(pattern: t.LVal, out: Set<string>): void {\n if (t.isIdentifier(pattern)) {\n out.add(pattern.name)\n } else if (t.isObjectPattern(pattern)) {\n for (const prop of pattern.properties) {\n if (t.isRestElement(prop)) {\n getBoundNamesFromPattern(prop.argument as t.LVal, out)\n } else {\n getBoundNamesFromPattern(prop.value as t.LVal, out)\n }\n }\n } else if (t.isArrayPattern(pattern)) {\n for (const elem of pattern.elements) {\n if (elem) getBoundNamesFromPattern(elem as t.LVal, out)\n }\n } else if (t.isAssignmentPattern(pattern)) {\n getBoundNamesFromPattern(pattern.left, out)\n } else if (t.isRestElement(pattern)) {\n getBoundNamesFromPattern(pattern.argument as t.LVal, out)\n }\n}\n\nfunction addPatternBindingsIfTracked(\n pattern: t.LVal,\n tracked: Set<string>,\n out: Set<string>,\n): void {\n const names = new Set<string>()\n getBoundNamesFromPattern(pattern, names)\n for (const name of names) {\n if (tracked.has(name)) {\n out.add(name)\n }\n }\n}\n\nfunction collectHoistedVarBindings(\n node: t.Node,\n tracked: Set<string>,\n out: Set<string>,\n isRoot = true,\n): void {\n if (!isRoot && t.isFunction(node)) {\n return\n }\n\n if (t.isVariableDeclaration(node) && node.kind === 'var') {\n for (const decl of node.declarations) {\n addPatternBindingsIfTracked(decl.id as t.LVal, tracked, out)\n }\n }\n\n const keys = t.VISITOR_KEYS[node.type]\n if (!keys) return\n for (const key of keys) {\n const child = (node as unknown as Record<string, unknown>)[key]\n if (Array.isArray(child)) {\n for (const item of child) {\n if (item && typeof item === 'object' && 'type' in item) {\n collectHoistedVarBindings(item as t.Node, tracked, out, false)\n }\n }\n } else if (child && typeof child === 'object' && 'type' in child) {\n collectHoistedVarBindings(child as t.Node, tracked, out, false)\n }\n }\n}\n\nfunction collectProgramBindings(\n program: t.Program,\n tracked: Set<string>,\n): Set<string> {\n const bindings = new Set<string>()\n\n for (const node of program.body) {\n if (t.isVariableDeclaration(node)) {\n for (const decl of node.declarations) {\n addPatternBindingsIfTracked(decl.id as t.LVal, tracked, bindings)\n }\n continue\n }\n\n if (t.isFunctionDeclaration(node) || t.isClassDeclaration(node)) {\n if (node.id && tracked.has(node.id.name)) {\n bindings.add(node.id.name)\n }\n }\n }\n\n return bindings\n}\n\nfunction collectBlockBindings(\n block: t.BlockStatement,\n tracked: Set<string>,\n): Set<string> {\n const bindings = new Set<string>()\n\n for (const node of block.body) {\n if (t.isVariableDeclaration(node) && node.kind !== 'var') {\n for (const decl of node.declarations) {\n addPatternBindingsIfTracked(decl.id as t.LVal, tracked, bindings)\n }\n continue\n }\n\n if (t.isFunctionDeclaration(node) || t.isClassDeclaration(node)) {\n if (node.id && tracked.has(node.id.name)) {\n bindings.add(node.id.name)\n }\n }\n }\n\n return bindings\n}\n\nfunction collectFunctionBindings(\n fn: t.Function,\n tracked: Set<string>,\n): Set<string> {\n const bindings = new Set<string>()\n\n if (\n (t.isFunctionDeclaration(fn) || t.isFunctionExpression(fn)) &&\n fn.id &&\n tracked.has(fn.id.name)\n ) {\n bindings.add(fn.id.name)\n }\n\n for (const param of fn.params) {\n addPatternBindingsIfTracked(param as t.LVal, tracked, bindings)\n }\n\n if (t.isBlockStatement(fn.body)) {\n collectHoistedVarBindings(fn.body, tracked, bindings)\n }\n\n return bindings\n}\n\ntype UsageWalkContext = {\n parents: Array<t.Node>\n scopeStack: Array<Set<string>>\n}\n\nfunction isShadowedByScope(\n name: string,\n scopeStack: Array<Set<string>>,\n): boolean {\n for (let i = scopeStack.length - 1; i >= 0; i--) {\n if (scopeStack[i]?.has(name)) {\n return true\n }\n }\n return false\n}\n\nfunction isBindingIdentifierInParent(\n node: t.Identifier,\n parent: t.Node | undefined,\n): boolean {\n if (!parent) return false\n\n if (t.isImportSpecifier(parent) || t.isImportDefaultSpecifier(parent)) {\n return parent.local === node\n }\n if (t.isImportNamespaceSpecifier(parent)) {\n return parent.local === node\n }\n if (t.isFunctionDeclaration(parent) || t.isFunctionExpression(parent)) {\n return (\n parent.id === node || parent.params.includes(node as unknown as t.Pattern)\n )\n }\n if (t.isArrowFunctionExpression(parent)) {\n return parent.params.includes(node as unknown as t.Pattern)\n }\n if (t.isClassDeclaration(parent) || t.isClassExpression(parent)) {\n return parent.id === node\n }\n if (t.isVariableDeclarator(parent)) {\n return parent.id === node\n }\n if (t.isCatchClause(parent)) {\n return parent.param === node\n }\n\n return false\n}\n\nfunction isInsideCompilerSafeBoundaryNodes(\n parents: Array<t.Node>,\n envType: BoundaryEnv,\n): boolean {\n for (let i = parents.length - 1; i >= 0; i--) {\n const node = parents[i]!\n if (!t.isFunction(node)) {\n continue\n }\n\n const call = parents[i - 1]\n if (\n call &&\n t.isCallExpression(call) &&\n isCompilerSafeBoundaryCall(call, node, envType)\n ) {\n return true\n }\n }\n\n return false\n}\n\nfunction findUsagePosInAnalysis(\n result: TransformResult,\n source: string,\n envType?: BoundaryEnv,\n): UsagePos | undefined {\n const analysis = getOrCreateImportAnalysis(result)\n const cacheKey: UsageCacheKey = `${envType ?? 'post'}::${source}`\n if (analysis.usageByKey.has(cacheKey)) {\n return analysis.usageByKey.get(cacheKey) ?? undefined\n }\n\n const imported =\n analysis.importBindingsBySource.get(source)?.importedLocalNames\n if (!imported || imported.size === 0) {\n analysis.usageByKey.set(cacheKey, null)\n return undefined\n }\n\n let preferred: UsagePos | undefined\n let anyUsage: UsagePos | undefined\n\n const visit = (node: t.Node, ctx: UsageWalkContext): void => {\n if (preferred && anyUsage) {\n return\n }\n\n if (t.isProgram(node)) {\n const nextCtx = {\n parents: [...ctx.parents, node],\n scopeStack: [...ctx.scopeStack, collectProgramBindings(node, imported)],\n }\n for (const child of node.body) {\n visit(child, nextCtx)\n }\n return\n }\n\n if (t.isFunction(node)) {\n const functionCtx = {\n parents: [...ctx.parents, node],\n scopeStack: [\n ...ctx.scopeStack,\n collectFunctionBindings(node, imported),\n ],\n }\n\n visit(node.body, functionCtx)\n return\n }\n\n if (t.isBlockStatement(node)) {\n const nextCtx = {\n parents: [...ctx.parents, node],\n scopeStack: [...ctx.scopeStack, collectBlockBindings(node, imported)],\n }\n for (const child of node.body) {\n visit(child, nextCtx)\n }\n return\n }\n\n if (t.isCatchClause(node)) {\n const bindings = new Set<string>()\n if (node.param) {\n addPatternBindingsIfTracked(node.param as t.LVal, imported, bindings)\n }\n const nextCtx = {\n parents: [...ctx.parents, node],\n scopeStack: bindings.size\n ? [...ctx.scopeStack, bindings]\n : ctx.scopeStack,\n }\n visit(node.body, nextCtx)\n return\n }\n\n if (\n t.isForStatement(node) &&\n t.isVariableDeclaration(node.init) &&\n node.init.kind !== 'var'\n ) {\n const bindings = new Set<string>()\n for (const decl of node.init.declarations) {\n addPatternBindingsIfTracked(decl.id as t.LVal, imported, bindings)\n }\n const nextCtx = {\n parents: [...ctx.parents, node],\n scopeStack: bindings.size\n ? [...ctx.scopeStack, bindings]\n : ctx.scopeStack,\n }\n visit(node.init, nextCtx)\n if (node.test) visit(node.test, nextCtx)\n if (node.update) visit(node.update, nextCtx)\n visit(node.body, nextCtx)\n return\n }\n\n if (\n (t.isForInStatement(node) || t.isForOfStatement(node)) &&\n t.isVariableDeclaration(node.left) &&\n node.left.kind !== 'var'\n ) {\n const bindings = new Set<string>()\n for (const decl of node.left.declarations) {\n addPatternBindingsIfTracked(decl.id as t.LVal, imported, bindings)\n }\n const nextCtx = {\n parents: [...ctx.parents, node],\n scopeStack: bindings.size\n ? [...ctx.scopeStack, bindings]\n : ctx.scopeStack,\n }\n visit(node.left, nextCtx)\n visit(node.right, nextCtx)\n visit(node.body, nextCtx)\n return\n }\n\n const nextParents = [...ctx.parents, node]\n\n if (t.isIdentifier(node)) {\n const parent = ctx.parents[ctx.parents.length - 1]\n if (imported.has(node.name)) {\n if (!isBindingIdentifierInParent(node, parent)) {\n if (\n !(\n t.isObjectProperty(parent) &&\n parent.key === node &&\n !parent.computed &&\n !parent.shorthand\n ) &&\n !(\n t.isObjectMethod(parent) &&\n parent.key === node &&\n !parent.computed\n ) &&\n !(t.isExportSpecifier(parent) && parent.exported === node) &&\n !isShadowedByScope(node.name, ctx.scopeStack) &&\n !(\n envType && isInsideCompilerSafeBoundaryNodes(ctx.parents, envType)\n )\n ) {\n const loc = node.loc?.start\n if (loc) {\n const pos: UsagePos = { line: loc.line, column0: loc.column }\n const isPreferred =\n (t.isCallExpression(parent) && parent.callee === node) ||\n (t.isNewExpression(parent) && parent.callee === node) ||\n ((t.isMemberExpression(parent) ||\n t.isOptionalMemberExpression(parent)) &&\n parent.object === node)\n\n if (isPreferred) {\n preferred ||= pos\n } else {\n anyUsage ||= pos\n }\n }\n }\n }\n }\n }\n\n if (t.isImportDeclaration(node)) {\n return\n }\n\n const keys = t.VISITOR_KEYS[node.type]\n if (!keys) return\n for (const key of keys) {\n const child = (node as unknown as Record<string, unknown>)[key]\n if (Array.isArray(child)) {\n for (const item of child) {\n if (item && typeof item === 'object' && 'type' in item) {\n visit(item as t.Node, {\n parents: nextParents,\n scopeStack: ctx.scopeStack,\n })\n }\n }\n } else if (child && typeof child === 'object' && 'type' in child) {\n visit(child as t.Node, {\n parents: nextParents,\n scopeStack: ctx.scopeStack,\n })\n }\n }\n }\n\n visit(analysis.ast.program, {\n parents: [],\n scopeStack: [],\n })\n\n const pos = preferred ?? anyUsage ?? null\n analysis.usageByKey.set(cacheKey, pos)\n return pos ?? undefined\n}\n\nexport function findPostCompileUsagePosFromResult(\n result: TransformResult,\n source: string,\n): UsagePos | undefined {\n return findUsagePosInAnalysis(result, source)\n}\n\nexport function findPostCompileUsagePos(\n code: string,\n source: string,\n): UsagePos | undefined {\n return findPostCompileUsagePosFromResult(makeTransientResult(code), source)\n}\n\nexport function findOriginalUnsafeUsagePosFromResult(\n result: TransformResult,\n source: string,\n envType: BoundaryEnv,\n): UsagePos | undefined {\n return findUsagePosInAnalysis(result, source, envType)\n}\n\nexport function findOriginalUnsafeUsagePos(\n code: string,\n source: string,\n envType: BoundaryEnv,\n): UsagePos | undefined {\n return findOriginalUnsafeUsagePosFromResult(\n makeTransientResult(code),\n source,\n envType,\n )\n}\n"],"mappings":";;;;;AA8BA,SAAS,oBAAoB,MAA+B;AAC1D,QAAO;EACL;EACA,KAAK,KAAA;EACL,cAAc,KAAA;EACf;;AAGH,SAAS,oBAAoB,MAA8C;AACzE,QAAO,EAAE,aAAa,KAAK,GAAG,KAAK,OAAO,KAAK;;AAGjD,SAAS,2BAA2B,MAA+B;AACjE,KAAI,KAAK,SAAS,KAChB,QAAO;CAGT,MAAM,MAAM,KAAK,OAAO;AACxB,KAAI,OAAO,QAAQ,aAAa,IAAI,WAAW,IAAI,IAAI,IA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AO,OAAO,KAAA;;AAGhB,SAAgB,kCACd,QACA,QACsB;AACtB,QAAO,uBAAuB,QAAQ,OAAO;;AAU/C,SAAgB,qCACd,QACA,QACA,SACsB;AACtB,QAAO,uBAAuB,QAAQ,QAAQ,QAAQ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/start-plugin-core",
3
- "version": "1.169.9",
3
+ "version": "1.169.10",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -86,9 +86,9 @@
86
86
  "vitefu": "^1.1.1",
87
87
  "xmlbuilder2": "^4.0.3",
88
88
  "zod": "^3.24.2",
89
- "@tanstack/router-core": "1.169.0",
90
89
  "@tanstack/router-generator": "1.166.38",
91
90
  "@tanstack/router-plugin": "1.167.30",
91
+ "@tanstack/router-core": "1.169.0",
92
92
  "@tanstack/router-utils": "1.161.7",
93
93
  "@tanstack/start-client-core": "1.167.22",
94
94
  "@tanstack/start-server-core": "1.167.24"
@@ -53,6 +53,30 @@ function getStringLiteralValueStart(node: t.StringLiteral): number {
53
53
  return node.start
54
54
  }
55
55
 
56
+ function isTypeOnlyImportDeclaration(node: t.ImportDeclaration): boolean {
57
+ if (node.importKind === 'type') return true
58
+ if (node.specifiers.length === 0) return false
59
+
60
+ return node.specifiers.every(
61
+ (specifier) =>
62
+ t.isImportSpecifier(specifier) && specifier.importKind === 'type',
63
+ )
64
+ }
65
+
66
+ function isTypeOnlyExportNamedDeclaration(
67
+ node: t.ExportNamedDeclaration,
68
+ ): boolean {
69
+ if (node.exportKind === 'type') return true
70
+ if (!node.source || node.declaration || node.specifiers.length === 0) {
71
+ return false
72
+ }
73
+
74
+ return node.specifiers.every(
75
+ (specifier) =>
76
+ t.isExportSpecifier(specifier) && specifier.exportKind === 'type',
77
+ )
78
+ }
79
+
56
80
  function collectIdentifiersFromPattern(
57
81
  pattern: t.LVal,
58
82
  add: (name: string) => void,
@@ -149,8 +173,9 @@ function buildImportAnalysis(result: TransformResult): ImportAnalysis {
149
173
 
150
174
  const visit = (node: t.Node): void => {
151
175
  if (t.isImportDeclaration(node)) {
152
- addSpecifierLocation(node.source)
153
- if (node.importKind !== 'type') {
176
+ const isTypeOnly = isTypeOnlyImportDeclaration(node)
177
+ if (!isTypeOnly) {
178
+ addSpecifierLocation(node.source)
154
179
  const source = node.source.value
155
180
  const bindingInfo = getBindingInfo(source)
156
181
  for (const specifier of node.specifiers) {
@@ -177,11 +202,12 @@ function buildImportAnalysis(result: TransformResult): ImportAnalysis {
177
202
  }
178
203
  }
179
204
  } else if (t.isExportNamedDeclaration(node)) {
180
- if (node.source && t.isStringLiteral(node.source)) {
205
+ const isTypeOnly = isTypeOnlyExportNamedDeclaration(node)
206
+ if (!isTypeOnly && node.source && t.isStringLiteral(node.source)) {
181
207
  addSpecifierLocation(node.source)
182
208
  }
183
209
 
184
- if (node.exportKind !== 'type' && node.source?.value) {
210
+ if (!isTypeOnly && node.source?.value) {
185
211
  const source = node.source.value
186
212
  for (const specifier of node.specifiers) {
187
213
  if (!t.isExportSpecifier(specifier)) continue
@@ -190,7 +216,7 @@ function buildImportAnalysis(result: TransformResult): ImportAnalysis {
190
216
  }
191
217
  }
192
218
 
193
- if (node.exportKind !== 'type') {
219
+ if (!isTypeOnly) {
194
220
  if (node.declaration) {
195
221
  const decl = node.declaration
196
222
  if (t.isFunctionDeclaration(decl) || t.isClassDeclaration(decl)) {
@@ -210,7 +236,9 @@ function buildImportAnalysis(result: TransformResult): ImportAnalysis {
210
236
  }
211
237
  }
212
238
  } else if (t.isExportAllDeclaration(node)) {
213
- addSpecifierLocation(node.source)
239
+ if (node.exportKind !== 'type') {
240
+ addSpecifierLocation(node.source)
241
+ }
214
242
  } else if (t.isImportExpression(node)) {
215
243
  if (t.isStringLiteral(node.source)) {
216
244
  addSpecifierLocation(node.source)