@tanstack/router-plugin 1.159.10 → 1.159.12

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.
@@ -1 +1 @@
1
- {"version":3,"file":"compilers.cjs","sources":["../../../../src/core/code-splitter/compilers.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport babel from '@babel/core'\nimport * as template from '@babel/template'\nimport {\n deadCodeElimination,\n findReferencedIdentifiers,\n generateFromAst,\n parseAst,\n} from '@tanstack/router-utils'\nimport { tsrSplit } from '../constants'\nimport { routeHmrStatement } from '../route-hmr-statement'\nimport { createIdentifier } from './path-ids'\nimport { getFrameworkOptions } from './framework-options'\nimport type { GeneratorResult, ParseAstOptions } from '@tanstack/router-utils'\nimport type { CodeSplitGroupings, SplitRouteIdentNodes } from '../constants'\nimport type { Config, DeletableNodes } from '../config'\n\ntype SplitNodeMeta = {\n routeIdent: SplitRouteIdentNodes\n splitStrategy: 'lazyFn' | 'lazyRouteComponent'\n localImporterIdent: string\n exporterIdent: string\n localExporterIdent: string\n}\nconst SPLIT_NODES_CONFIG = new Map<SplitRouteIdentNodes, SplitNodeMeta>([\n [\n 'loader',\n {\n routeIdent: 'loader',\n localImporterIdent: '$$splitLoaderImporter', // const $$splitLoaderImporter = () => import('...')\n splitStrategy: 'lazyFn',\n localExporterIdent: 'SplitLoader', // const SplitLoader = ...\n exporterIdent: 'loader', // export { SplitLoader as loader }\n },\n ],\n [\n 'component',\n {\n routeIdent: 'component',\n localImporterIdent: '$$splitComponentImporter', // const $$splitComponentImporter = () => import('...')\n splitStrategy: 'lazyRouteComponent',\n localExporterIdent: 'SplitComponent', // const SplitComponent = ...\n exporterIdent: 'component', // export { SplitComponent as component }\n },\n ],\n [\n 'pendingComponent',\n {\n routeIdent: 'pendingComponent',\n localImporterIdent: '$$splitPendingComponentImporter', // const $$splitPendingComponentImporter = () => import('...')\n splitStrategy: 'lazyRouteComponent',\n localExporterIdent: 'SplitPendingComponent', // const SplitPendingComponent = ...\n exporterIdent: 'pendingComponent', // export { SplitPendingComponent as pendingComponent }\n },\n ],\n [\n 'errorComponent',\n {\n routeIdent: 'errorComponent',\n localImporterIdent: '$$splitErrorComponentImporter', // const $$splitErrorComponentImporter = () => import('...')\n splitStrategy: 'lazyRouteComponent',\n localExporterIdent: 'SplitErrorComponent', // const SplitErrorComponent = ...\n exporterIdent: 'errorComponent', // export { SplitErrorComponent as errorComponent }\n },\n ],\n [\n 'notFoundComponent',\n {\n routeIdent: 'notFoundComponent',\n localImporterIdent: '$$splitNotFoundComponentImporter', // const $$splitNotFoundComponentImporter = () => import('...')\n splitStrategy: 'lazyRouteComponent',\n localExporterIdent: 'SplitNotFoundComponent', // const SplitNotFoundComponent = ...\n exporterIdent: 'notFoundComponent', // export { SplitNotFoundComponent as notFoundComponent }\n },\n ],\n])\nconst KNOWN_SPLIT_ROUTE_IDENTS = [...SPLIT_NODES_CONFIG.keys()] as const\n\nfunction addSplitSearchParamToFilename(\n filename: string,\n grouping: Array<string>,\n) {\n const [bareFilename] = filename.split('?')\n\n const params = new URLSearchParams()\n params.append(tsrSplit, createIdentifier(grouping))\n\n const result = `${bareFilename}?${params.toString()}`\n return result\n}\n\nfunction removeSplitSearchParamFromFilename(filename: string) {\n const [bareFilename] = filename.split('?')\n return bareFilename!\n}\n\nconst splittableCreateRouteFns = ['createFileRoute']\nconst unsplittableCreateRouteFns = [\n 'createRootRoute',\n 'createRootRouteWithContext',\n]\nconst allCreateRouteFns = [\n ...splittableCreateRouteFns,\n ...unsplittableCreateRouteFns,\n]\n\nexport function compileCodeSplitReferenceRoute(\n opts: ParseAstOptions & {\n codeSplitGroupings: CodeSplitGroupings\n deleteNodes?: Set<DeletableNodes>\n targetFramework: Config['target']\n filename: string\n id: string\n addHmr?: boolean\n },\n): GeneratorResult | null {\n const ast = parseAst(opts)\n\n const refIdents = findReferencedIdentifiers(ast)\n\n const knownExportedIdents = new Set<string>()\n\n function findIndexForSplitNode(str: string) {\n return opts.codeSplitGroupings.findIndex((group) =>\n group.includes(str as any),\n )\n }\n\n const frameworkOptions = getFrameworkOptions(opts.targetFramework)\n const PACKAGE = frameworkOptions.package\n const LAZY_ROUTE_COMPONENT_IDENT = frameworkOptions.idents.lazyRouteComponent\n const LAZY_FN_IDENT = frameworkOptions.idents.lazyFn\n\n let createRouteFn: string\n\n let modified = false as boolean\n let hmrAdded = false as boolean\n babel.traverse(ast, {\n Program: {\n enter(programPath) {\n /**\n * If the component for the route is being imported from\n * another file, this is to track the path to that file\n * the path itself doesn't matter, we just need to keep\n * track of it so that we can remove it from the imports\n * list if it's not being used like:\n *\n * `import '../shared/imported'`\n */\n const removableImportPaths = new Set<string>([])\n\n programPath.traverse({\n CallExpression: (path) => {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n\n if (!allCreateRouteFns.includes(path.node.callee.name)) {\n return\n }\n\n createRouteFn = path.node.callee.name\n\n function babelHandleReference(routeOptions: t.Node | undefined) {\n const hasImportedOrDefinedIdentifier = (name: string) => {\n return programPath.scope.hasBinding(name)\n }\n\n if (t.isObjectExpression(routeOptions)) {\n if (opts.deleteNodes && opts.deleteNodes.size > 0) {\n routeOptions.properties = routeOptions.properties.filter(\n (prop) => {\n if (t.isObjectProperty(prop)) {\n if (t.isIdentifier(prop.key)) {\n if (opts.deleteNodes!.has(prop.key.name as any)) {\n modified = true\n return false\n }\n }\n }\n return true\n },\n )\n }\n if (!splittableCreateRouteFns.includes(createRouteFn)) {\n // we can't split this route but we still add HMR handling if enabled\n if (opts.addHmr && !hmrAdded) {\n programPath.pushContainer('body', routeHmrStatement)\n modified = true\n hmrAdded = true\n }\n // exit traversal so this route is not split\n return programPath.stop()\n }\n routeOptions.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n if (t.isIdentifier(prop.key)) {\n const key = prop.key.name\n\n // If the user has not specified a split grouping for this key\n // then we should not split it\n const codeSplitGroupingByKey = findIndexForSplitNode(key)\n if (codeSplitGroupingByKey === -1) {\n return\n }\n const codeSplitGroup = [\n ...new Set(\n opts.codeSplitGroupings[codeSplitGroupingByKey],\n ),\n ]\n\n // find key in nodeSplitConfig\n const isNodeConfigAvailable = SPLIT_NODES_CONFIG.has(\n key as any,\n )\n\n if (!isNodeConfigAvailable) {\n return\n }\n\n // Exit early if the value is a boolean, null, or undefined.\n // These values mean \"don't use this component, fallback to parent\"\n // No code splitting needed to preserve fallback behavior\n if (\n t.isBooleanLiteral(prop.value) ||\n t.isNullLiteral(prop.value) ||\n (t.isIdentifier(prop.value) &&\n prop.value.name === 'undefined')\n ) {\n return\n }\n\n const splitNodeMeta = SPLIT_NODES_CONFIG.get(key as any)!\n\n // We need to extract the existing search params from the filename, if any\n // and add the relevant codesplitPrefix to them, then write them back to the filename\n const splitUrl = addSplitSearchParamToFilename(\n opts.filename,\n codeSplitGroup,\n )\n\n if (\n splitNodeMeta.splitStrategy === 'lazyRouteComponent'\n ) {\n const value = prop.value\n\n let shouldSplit = true\n\n if (t.isIdentifier(value)) {\n const existingImportPath =\n getImportSpecifierAndPathFromLocalName(\n programPath,\n value.name,\n ).path\n if (existingImportPath) {\n removableImportPaths.add(existingImportPath)\n }\n\n // exported identifiers should not be split\n // since they are already being imported\n // and need to be retained in the compiled file\n const isExported = hasExport(ast, value)\n if (isExported) {\n knownExportedIdents.add(value.name)\n }\n shouldSplit = !isExported\n\n if (shouldSplit) {\n removeIdentifierLiteral(path, value)\n }\n }\n\n if (!shouldSplit) {\n return\n }\n\n modified = true\n\n // Prepend the import statement to the program along with the importer function\n // Check to see if lazyRouteComponent is already imported before attempting\n // to import it again\n if (\n !hasImportedOrDefinedIdentifier(\n LAZY_ROUTE_COMPONENT_IDENT,\n )\n ) {\n programPath.unshiftContainer('body', [\n template.statement(\n `import { ${LAZY_ROUTE_COMPONENT_IDENT} } from '${PACKAGE}'`,\n )(),\n ])\n }\n\n // Check to see if the importer function is already defined\n // If not, define it with the dynamic import statement\n if (\n !hasImportedOrDefinedIdentifier(\n splitNodeMeta.localImporterIdent,\n )\n ) {\n programPath.unshiftContainer('body', [\n template.statement(\n `const ${splitNodeMeta.localImporterIdent} = () => import('${splitUrl}')`,\n )(),\n ])\n }\n\n prop.value = template.expression(\n `${LAZY_ROUTE_COMPONENT_IDENT}(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}')`,\n )()\n\n // add HMR handling\n if (opts.addHmr && !hmrAdded) {\n programPath.pushContainer('body', routeHmrStatement)\n modified = true\n hmrAdded = true\n }\n } else {\n // if (splitNodeMeta.splitStrategy === 'lazyFn') {\n const value = prop.value\n\n let shouldSplit = true\n\n if (t.isIdentifier(value)) {\n const existingImportPath =\n getImportSpecifierAndPathFromLocalName(\n programPath,\n value.name,\n ).path\n if (existingImportPath) {\n removableImportPaths.add(existingImportPath)\n }\n\n // exported identifiers should not be split\n // since they are already being imported\n // and need to be retained in the compiled file\n const isExported = hasExport(ast, value)\n if (isExported) {\n knownExportedIdents.add(value.name)\n }\n shouldSplit = !isExported\n\n if (shouldSplit) {\n removeIdentifierLiteral(path, value)\n }\n }\n\n if (!shouldSplit) {\n return\n }\n modified = true\n\n // Prepend the import statement to the program along with the importer function\n if (!hasImportedOrDefinedIdentifier(LAZY_FN_IDENT)) {\n programPath.unshiftContainer(\n 'body',\n template.smart(\n `import { ${LAZY_FN_IDENT} } from '${PACKAGE}'`,\n )(),\n )\n }\n\n // Check to see if the importer function is already defined\n // If not, define it with the dynamic import statement\n if (\n !hasImportedOrDefinedIdentifier(\n splitNodeMeta.localImporterIdent,\n )\n ) {\n programPath.unshiftContainer('body', [\n template.statement(\n `const ${splitNodeMeta.localImporterIdent} = () => import('${splitUrl}')`,\n )(),\n ])\n }\n\n // Add the lazyFn call with the dynamic import to the prop value\n prop.value = template.expression(\n `${LAZY_FN_IDENT}(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}')`,\n )()\n }\n }\n }\n\n programPath.scope.crawl()\n })\n }\n }\n\n if (t.isCallExpression(path.parentPath.node)) {\n // createFileRoute('/')({ ... })\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n babelHandleReference(options)\n } else if (t.isVariableDeclarator(path.parentPath.node)) {\n // createFileRoute({ ... })\n const caller = resolveIdentifier(path, path.parentPath.node.init)\n\n if (t.isCallExpression(caller)) {\n const options = resolveIdentifier(path, caller.arguments[0])\n babelHandleReference(options)\n }\n }\n },\n })\n\n /**\n * If the component for the route is being imported,\n * and it's not being used, remove the import statement\n * from the program, by checking that the import has no\n * specifiers\n */\n if (removableImportPaths.size > 0) {\n modified = true\n programPath.traverse({\n ImportDeclaration(path) {\n if (path.node.specifiers.length > 0) return\n if (removableImportPaths.has(path.node.source.value)) {\n path.remove()\n }\n },\n })\n }\n },\n },\n })\n\n if (!modified) {\n return null\n }\n\n deadCodeElimination(ast, refIdents)\n\n // if there are exported identifiers, then we need to add a warning\n // to the file to let the user know that the exported identifiers\n // will not in the split file but in the original file, therefore\n // increasing the bundle size\n if (knownExportedIdents.size > 0) {\n const warningMessage = createNotExportableMessage(\n opts.filename,\n knownExportedIdents,\n )\n console.warn(warningMessage)\n\n // append this warning to the file using a template\n if (process.env.NODE_ENV !== 'production') {\n const warningTemplate = template.statement(\n `console.warn(${JSON.stringify(warningMessage)})`,\n )()\n ast.program.body.unshift(warningTemplate)\n }\n }\n\n return generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: opts.filename,\n filename: opts.filename,\n })\n}\n\nexport function compileCodeSplitVirtualRoute(\n opts: ParseAstOptions & {\n splitTargets: Array<SplitRouteIdentNodes>\n filename: string\n },\n): GeneratorResult {\n const ast = parseAst(opts)\n const refIdents = findReferencedIdentifiers(ast)\n\n const intendedSplitNodes = new Set(opts.splitTargets)\n\n const knownExportedIdents = new Set<string>()\n\n babel.traverse(ast, {\n Program: {\n enter(programPath) {\n const trackedNodesToSplitByType: Record<\n SplitRouteIdentNodes,\n { node: t.Node | undefined; meta: SplitNodeMeta } | undefined\n > = {\n component: undefined,\n loader: undefined,\n pendingComponent: undefined,\n errorComponent: undefined,\n notFoundComponent: undefined,\n }\n\n // Find and track all the known split-able nodes\n programPath.traverse({\n CallExpression: (path) => {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n\n if (!splittableCreateRouteFns.includes(path.node.callee.name)) {\n return\n }\n\n function babelHandleVirtual(options: t.Node | undefined) {\n if (t.isObjectExpression(options)) {\n options.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n // do not use `intendedSplitNodes` here\n // since we have special considerations that need\n // to be accounted for like (not splitting exported identifiers)\n KNOWN_SPLIT_ROUTE_IDENTS.forEach((splitType) => {\n if (\n !t.isIdentifier(prop.key) ||\n prop.key.name !== splitType\n ) {\n return\n }\n\n const value = prop.value\n\n // If the value for the `key` is `undefined`, then we don't need to include it\n // in the split file, so we can just return, since it will kept in-place in the\n // reference file\n // This is useful for cases like: `createFileRoute('/')({ component: undefined })`\n if (t.isIdentifier(value) && value.name === 'undefined') {\n return\n }\n\n let isExported = false\n if (t.isIdentifier(value)) {\n isExported = hasExport(ast, value)\n if (isExported) {\n knownExportedIdents.add(value.name)\n }\n }\n\n // If the node is exported, we need to remove\n // the export from the split file\n if (isExported && t.isIdentifier(value)) {\n removeExports(ast, value)\n } else {\n const meta = SPLIT_NODES_CONFIG.get(splitType)!\n trackedNodesToSplitByType[splitType] = {\n node: prop.value,\n meta,\n }\n }\n })\n }\n })\n\n // Remove all of the options\n options.properties = []\n }\n }\n\n if (t.isCallExpression(path.parentPath.node)) {\n // createFileRoute('/')({ ... })\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n babelHandleVirtual(options)\n } else if (t.isVariableDeclarator(path.parentPath.node)) {\n // createFileRoute({ ... })\n const caller = resolveIdentifier(path, path.parentPath.node.init)\n\n if (t.isCallExpression(caller)) {\n const options = resolveIdentifier(path, caller.arguments[0])\n babelHandleVirtual(options)\n }\n }\n },\n })\n\n // Start the transformation to only exported the intended split nodes\n intendedSplitNodes.forEach((SPLIT_TYPE) => {\n const splitKey = trackedNodesToSplitByType[SPLIT_TYPE]\n\n if (!splitKey) {\n return\n }\n\n let splitNode = splitKey.node\n const splitMeta = { ...splitKey.meta, shouldRemoveNode: true }\n\n while (t.isIdentifier(splitNode)) {\n const binding = programPath.scope.getBinding(splitNode.name)\n splitNode = binding?.path.node\n }\n\n // Add the node to the program\n if (splitNode) {\n if (t.isFunctionDeclaration(splitNode)) {\n // an anonymous function declaration should only happen for `export default function() {...}`\n // so we should never get here\n if (!splitNode.id) {\n throw new Error(\n `Function declaration for \"${SPLIT_TYPE}\" must have an identifier.`,\n )\n }\n splitMeta.shouldRemoveNode = false\n splitMeta.localExporterIdent = splitNode.id.name\n } else if (\n t.isFunctionExpression(splitNode) ||\n t.isArrowFunctionExpression(splitNode)\n ) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n splitNode as any,\n ),\n ]),\n )\n } else if (\n t.isImportSpecifier(splitNode) ||\n t.isImportDefaultSpecifier(splitNode)\n ) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n splitNode.local,\n ),\n ]),\n )\n } else if (t.isVariableDeclarator(splitNode)) {\n if (t.isIdentifier(splitNode.id)) {\n splitMeta.localExporterIdent = splitNode.id.name\n splitMeta.shouldRemoveNode = false\n } else {\n throw new Error(\n `Unexpected splitNode type ☝️: ${splitNode.type}`,\n )\n }\n } else if (t.isCallExpression(splitNode)) {\n const outputSplitNodeCode = generateFromAst(splitNode).code\n const splitNodeAst = babel.parse(outputSplitNodeCode)\n\n if (!splitNodeAst) {\n throw new Error(\n `Failed to parse the generated code for \"${SPLIT_TYPE}\" in the node type \"${splitNode.type}\"`,\n )\n }\n\n const statement = splitNodeAst.program.body[0]\n\n if (!statement) {\n throw new Error(\n `Failed to parse the generated code for \"${SPLIT_TYPE}\" in the node type \"${splitNode.type}\" as no statement was found in the program body`,\n )\n }\n\n if (t.isExpressionStatement(statement)) {\n const expression = statement.expression\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n expression,\n ),\n ]),\n )\n } else {\n throw new Error(\n `Unexpected expression type encounter for \"${SPLIT_TYPE}\" in the node type \"${splitNode.type}\"`,\n )\n }\n } else if (t.isConditionalExpression(splitNode)) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n splitNode,\n ),\n ]),\n )\n } else if (t.isTSAsExpression(splitNode)) {\n // remove the type assertion\n splitNode = splitNode.expression\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n splitNode,\n ),\n ]),\n )\n } else if (t.isBooleanLiteral(splitNode)) {\n // Handle boolean literals\n // This exits early here, since this value will be kept in the reference file\n return\n } else if (t.isNullLiteral(splitNode)) {\n // Handle null literals\n // This exits early here, since this value will be kept in the reference file\n return\n } else {\n console.info('Unexpected splitNode type:', splitNode)\n throw new Error(`Unexpected splitNode type ☝️: ${splitNode.type}`)\n }\n }\n\n if (splitMeta.shouldRemoveNode) {\n // If the splitNode exists at the top of the program\n // then we need to remove that copy\n programPath.node.body = programPath.node.body.filter((node) => {\n return node !== splitNode\n })\n }\n\n // Export the node\n programPath.pushContainer('body', [\n t.exportNamedDeclaration(null, [\n t.exportSpecifier(\n t.identifier(splitMeta.localExporterIdent), // local variable name\n t.identifier(splitMeta.exporterIdent), // as what name it should be exported as\n ),\n ]),\n ])\n })\n\n // convert exports to imports from the original file\n programPath.traverse({\n ExportNamedDeclaration(path) {\n // e.g. export const x = 1 or export { x }\n // becomes\n // import { x } from '${opts.id}'\n\n if (path.node.declaration) {\n if (t.isVariableDeclaration(path.node.declaration)) {\n const importDecl = t.importDeclaration(\n path.node.declaration.declarations.map((decl) =>\n t.importSpecifier(\n t.identifier((decl.id as any).name),\n t.identifier((decl.id as any).name),\n ),\n ),\n t.stringLiteral(\n removeSplitSearchParamFromFilename(opts.filename),\n ),\n )\n\n path.replaceWith(importDecl)\n\n // Track the imported identifier paths so deadCodeElimination can remove them if unused\n // We need to traverse the newly created import to get the identifier paths\n path.traverse({\n Identifier(identPath) {\n // Only track the local binding identifiers (the imported names)\n if (\n identPath.parentPath.isImportSpecifier() &&\n identPath.key === 'local'\n ) {\n refIdents.add(identPath)\n }\n },\n })\n }\n }\n },\n })\n },\n },\n })\n\n deadCodeElimination(ast, refIdents)\n\n return generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: opts.filename,\n filename: opts.filename,\n })\n}\n\n/**\n * This function should read get the options from by searching for the key `codeSplitGroupings`\n * on createFileRoute and return it's values if it exists, else return undefined\n */\nexport function detectCodeSplitGroupingsFromRoute(opts: ParseAstOptions): {\n groupings: CodeSplitGroupings | undefined\n} {\n const ast = parseAst(opts)\n\n let codeSplitGroupings: CodeSplitGroupings | undefined = undefined\n\n babel.traverse(ast, {\n Program: {\n enter(programPath) {\n programPath.traverse({\n CallExpression(path) {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n\n if (\n !(\n path.node.callee.name === 'createRoute' ||\n path.node.callee.name === 'createFileRoute'\n )\n ) {\n return\n }\n\n function babelHandleSplittingGroups(\n routeOptions: t.Node | undefined,\n ) {\n if (t.isObjectExpression(routeOptions)) {\n routeOptions.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n if (t.isIdentifier(prop.key)) {\n if (prop.key.name === 'codeSplitGroupings') {\n const value = prop.value\n\n if (t.isArrayExpression(value)) {\n codeSplitGroupings = value.elements.map((group) => {\n if (t.isArrayExpression(group)) {\n return group.elements.map((node) => {\n if (!t.isStringLiteral(node)) {\n throw new Error(\n 'You must provide a string literal for the codeSplitGroupings',\n )\n }\n\n return node.value\n }) as Array<SplitRouteIdentNodes>\n }\n\n throw new Error(\n 'You must provide arrays with codeSplitGroupings options.',\n )\n })\n } else {\n throw new Error(\n 'You must provide an array of arrays for the codeSplitGroupings.',\n )\n }\n }\n }\n }\n })\n }\n }\n\n // Extracting the codeSplitGroupings\n if (t.isCallExpression(path.parentPath.node)) {\n // createFileRoute('/')({ ... })\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n babelHandleSplittingGroups(options)\n } else if (t.isVariableDeclarator(path.parentPath.node)) {\n // createFileRoute({ ... })\n const caller = resolveIdentifier(path, path.parentPath.node.init)\n\n if (t.isCallExpression(caller)) {\n const options = resolveIdentifier(path, caller.arguments[0])\n babelHandleSplittingGroups(options)\n }\n }\n },\n })\n },\n },\n })\n\n return { groupings: codeSplitGroupings }\n}\n\nfunction createNotExportableMessage(\n filename: string,\n idents: Set<string>,\n): string {\n const list = Array.from(idents).map((d) => `- ${d}`)\n\n const message = [\n `[tanstack-router] These exports from \"${filename}\" will not be code-split and will increase your bundle size:`,\n ...list,\n 'For the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file.',\n ].join('\\n')\n\n return message\n}\n\nfunction getImportSpecifierAndPathFromLocalName(\n programPath: babel.NodePath<t.Program>,\n name: string,\n): {\n specifier:\n | t.ImportSpecifier\n | t.ImportDefaultSpecifier\n | t.ImportNamespaceSpecifier\n | null\n path: string | null\n} {\n let specifier:\n | t.ImportSpecifier\n | t.ImportDefaultSpecifier\n | t.ImportNamespaceSpecifier\n | null = null\n let path: string | null = null\n\n programPath.traverse({\n ImportDeclaration(importPath) {\n const found = importPath.node.specifiers.find(\n (targetSpecifier) => targetSpecifier.local.name === name,\n )\n if (found) {\n specifier = found\n path = importPath.node.source.value\n }\n },\n })\n\n return { specifier, path }\n}\n\n// Reusable function to get literal value or resolve variable to literal\nfunction resolveIdentifier(path: any, node: any): t.Node | undefined {\n if (t.isIdentifier(node)) {\n const binding = path.scope.getBinding(node.name)\n if (\n binding\n // && binding.kind === 'const'\n ) {\n const declarator = binding.path.node\n if (t.isObjectExpression(declarator.init)) {\n return declarator.init\n } else if (t.isFunctionDeclaration(declarator.init)) {\n return declarator.init\n }\n }\n return undefined\n }\n\n return node\n}\n\nfunction removeIdentifierLiteral(path: babel.NodePath, node: t.Identifier) {\n const binding = path.scope.getBinding(node.name)\n if (binding) {\n binding.path.remove()\n }\n}\n\nfunction hasExport(ast: t.File, node: t.Identifier): boolean {\n let found = false\n\n babel.traverse(ast, {\n ExportNamedDeclaration(path) {\n if (path.node.declaration) {\n // declared as `const loaderFn = () => {}`\n if (t.isVariableDeclaration(path.node.declaration)) {\n path.node.declaration.declarations.forEach((decl) => {\n if (t.isVariableDeclarator(decl)) {\n if (t.isIdentifier(decl.id)) {\n if (decl.id.name === node.name) {\n found = true\n }\n }\n }\n })\n }\n\n // declared as `function loaderFn() {}`\n if (t.isFunctionDeclaration(path.node.declaration)) {\n if (t.isIdentifier(path.node.declaration.id)) {\n if (path.node.declaration.id.name === node.name) {\n found = true\n }\n }\n }\n }\n },\n ExportDefaultDeclaration(path) {\n // declared as `export default loaderFn`\n if (t.isIdentifier(path.node.declaration)) {\n if (path.node.declaration.name === node.name) {\n found = true\n }\n }\n\n // declared as `export default function loaderFn() {}`\n if (t.isFunctionDeclaration(path.node.declaration)) {\n if (t.isIdentifier(path.node.declaration.id)) {\n if (path.node.declaration.id.name === node.name) {\n found = true\n }\n }\n }\n },\n })\n\n return found\n}\n\nfunction removeExports(ast: t.File, node: t.Identifier): boolean {\n let removed = false\n\n // The checks use sequential if/else if statements since it\n // directly mutates the AST and as such doing normal checks\n // (using only if statements) could lead to a situation where\n // `path.node` is null since it has been already removed from\n // the program tree but typescript doesn't know that.\n babel.traverse(ast, {\n ExportNamedDeclaration(path) {\n if (path.node.declaration) {\n if (t.isVariableDeclaration(path.node.declaration)) {\n // declared as `const loaderFn = () => {}`\n path.node.declaration.declarations.forEach((decl) => {\n if (t.isVariableDeclarator(decl)) {\n if (t.isIdentifier(decl.id)) {\n if (decl.id.name === node.name) {\n path.remove()\n removed = true\n }\n }\n }\n })\n } else if (t.isFunctionDeclaration(path.node.declaration)) {\n // declared as `export const loaderFn = () => {}`\n if (t.isIdentifier(path.node.declaration.id)) {\n if (path.node.declaration.id.name === node.name) {\n path.remove()\n removed = true\n }\n }\n }\n }\n },\n ExportDefaultDeclaration(path) {\n // declared as `export default loaderFn`\n if (t.isIdentifier(path.node.declaration)) {\n if (path.node.declaration.name === node.name) {\n path.remove()\n removed = true\n }\n } else if (t.isFunctionDeclaration(path.node.declaration)) {\n // declared as `export default function loaderFn() {}`\n if (t.isIdentifier(path.node.declaration.id)) {\n if (path.node.declaration.id.name === node.name) {\n path.remove()\n removed = true\n }\n }\n }\n },\n })\n\n return removed\n}\n"],"names":["tsrSplit","createIdentifier","parseAst","findReferencedIdentifiers","frameworkOptions","getFrameworkOptions","t","routeHmrStatement","template","deadCodeElimination","generateFromAst"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,yCAAyB,IAAyC;AAAA,EACtE;AAAA,IACE;AAAA,IACA;AAAA,MACE,YAAY;AAAA,MACZ,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA,MACf,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA;AAAA,IAAA;AAAA,EACjB;AAAA,EAEF;AAAA,IACE;AAAA,IACA;AAAA,MACE,YAAY;AAAA,MACZ,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA,MACf,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA;AAAA,IAAA;AAAA,EACjB;AAAA,EAEF;AAAA,IACE;AAAA,IACA;AAAA,MACE,YAAY;AAAA,MACZ,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA,MACf,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA;AAAA,IAAA;AAAA,EACjB;AAAA,EAEF;AAAA,IACE;AAAA,IACA;AAAA,MACE,YAAY;AAAA,MACZ,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA,MACf,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA;AAAA,I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,CACD;AAED,SAAO;AACT;;;;"}
1
+ {"version":3,"file":"compilers.cjs","sources":["../../../../src/core/code-splitter/compilers.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport babel from '@babel/core'\nimport * as template from '@babel/template'\nimport {\n deadCodeElimination,\n findReferencedIdentifiers,\n generateFromAst,\n parseAst,\n} from '@tanstack/router-utils'\nimport { tsrShared, tsrSplit } from '../constants'\nimport { routeHmrStatement } from '../route-hmr-statement'\nimport { createIdentifier } from './path-ids'\nimport { getFrameworkOptions } from './framework-options'\nimport type { GeneratorResult, ParseAstOptions } from '@tanstack/router-utils'\nimport type { CodeSplitGroupings, SplitRouteIdentNodes } from '../constants'\nimport type { Config, DeletableNodes } from '../config'\n\ntype SplitNodeMeta = {\n routeIdent: SplitRouteIdentNodes\n splitStrategy: 'lazyFn' | 'lazyRouteComponent'\n localImporterIdent: string\n exporterIdent: string\n localExporterIdent: string\n}\nconst SPLIT_NODES_CONFIG = new Map<SplitRouteIdentNodes, SplitNodeMeta>([\n [\n 'loader',\n {\n routeIdent: 'loader',\n localImporterIdent: '$$splitLoaderImporter', // const $$splitLoaderImporter = () => import('...')\n splitStrategy: 'lazyFn',\n localExporterIdent: 'SplitLoader', // const SplitLoader = ...\n exporterIdent: 'loader', // export { SplitLoader as loader }\n },\n ],\n [\n 'component',\n {\n routeIdent: 'component',\n localImporterIdent: '$$splitComponentImporter', // const $$splitComponentImporter = () => import('...')\n splitStrategy: 'lazyRouteComponent',\n localExporterIdent: 'SplitComponent', // const SplitComponent = ...\n exporterIdent: 'component', // export { SplitComponent as component }\n },\n ],\n [\n 'pendingComponent',\n {\n routeIdent: 'pendingComponent',\n localImporterIdent: '$$splitPendingComponentImporter', // const $$splitPendingComponentImporter = () => import('...')\n splitStrategy: 'lazyRouteComponent',\n localExporterIdent: 'SplitPendingComponent', // const SplitPendingComponent = ...\n exporterIdent: 'pendingComponent', // export { SplitPendingComponent as pendingComponent }\n },\n ],\n [\n 'errorComponent',\n {\n routeIdent: 'errorComponent',\n localImporterIdent: '$$splitErrorComponentImporter', // const $$splitErrorComponentImporter = () => import('...')\n splitStrategy: 'lazyRouteComponent',\n localExporterIdent: 'SplitErrorComponent', // const SplitErrorComponent = ...\n exporterIdent: 'errorComponent', // export { SplitErrorComponent as errorComponent }\n },\n ],\n [\n 'notFoundComponent',\n {\n routeIdent: 'notFoundComponent',\n localImporterIdent: '$$splitNotFoundComponentImporter', // const $$splitNotFoundComponentImporter = () => import('...')\n splitStrategy: 'lazyRouteComponent',\n localExporterIdent: 'SplitNotFoundComponent', // const SplitNotFoundComponent = ...\n exporterIdent: 'notFoundComponent', // export { SplitNotFoundComponent as notFoundComponent }\n },\n ],\n])\nconst KNOWN_SPLIT_ROUTE_IDENTS = [...SPLIT_NODES_CONFIG.keys()] as const\n\nfunction addSplitSearchParamToFilename(\n filename: string,\n grouping: Array<string>,\n) {\n const [bareFilename] = filename.split('?')\n\n const params = new URLSearchParams()\n params.append(tsrSplit, createIdentifier(grouping))\n\n const result = `${bareFilename}?${params.toString()}`\n return result\n}\n\nfunction removeSplitSearchParamFromFilename(filename: string) {\n const [bareFilename] = filename.split('?')\n return bareFilename!\n}\n\nexport function addSharedSearchParamToFilename(filename: string) {\n const [bareFilename] = filename.split('?')\n return `${bareFilename}?${tsrShared}=1`\n}\n\nconst splittableCreateRouteFns = ['createFileRoute']\nconst unsplittableCreateRouteFns = [\n 'createRootRoute',\n 'createRootRouteWithContext',\n]\nconst allCreateRouteFns = [\n ...splittableCreateRouteFns,\n ...unsplittableCreateRouteFns,\n]\n\n/**\n * Recursively walk an AST node and collect referenced identifier-like names.\n * Much cheaper than babel.traverse — no path/scope overhead.\n *\n * Notes:\n * - Uses @babel/types `isReferenced` to avoid collecting non-references like\n * object keys, member expression properties, or binding identifiers.\n * - Also handles JSX identifiers for component references.\n */\nexport function collectIdentifiersFromNode(node: t.Node): Set<string> {\n const ids = new Set<string>()\n\n ;(function walk(\n n: t.Node | null | undefined,\n parent?: t.Node,\n grandparent?: t.Node,\n parentKey?: string,\n ) {\n if (!n) return\n\n if (t.isIdentifier(n)) {\n // When we don't have parent info (node passed in isolation), treat as referenced.\n if (!parent || t.isReferenced(n, parent, grandparent)) {\n ids.add(n.name)\n }\n return\n }\n\n if (t.isJSXIdentifier(n)) {\n // Skip attribute names: <div data-testid=\"x\" />\n if (parent && t.isJSXAttribute(parent) && parentKey === 'name') {\n return\n }\n\n // Skip member properties: <Foo.Bar /> should count Foo, not Bar\n if (\n parent &&\n t.isJSXMemberExpression(parent) &&\n parentKey === 'property'\n ) {\n return\n }\n\n // Intrinsic elements (lowercase) are not identifiers\n const first = n.name[0]\n if (first && first === first.toLowerCase()) {\n return\n }\n\n ids.add(n.name)\n return\n }\n\n for (const key of t.VISITOR_KEYS[n.type] || []) {\n const child = (n as any)[key]\n if (Array.isArray(child)) {\n for (const c of child) {\n if (c && typeof c.type === 'string') {\n walk(c, n, parent, key)\n }\n }\n } else if (child && typeof child.type === 'string') {\n walk(child, n, parent, key)\n }\n }\n })(node)\n\n return ids\n}\n\n/**\n * Build a map from binding name → declaration AST node for all\n * locally-declared module-level bindings. Built once, O(1) lookup.\n */\nexport function buildDeclarationMap(ast: t.File): Map<string, t.Node> {\n const map = new Map<string, t.Node>()\n for (const stmt of ast.program.body) {\n const decl =\n t.isExportNamedDeclaration(stmt) && stmt.declaration\n ? stmt.declaration\n : stmt\n\n if (t.isVariableDeclaration(decl)) {\n for (const declarator of decl.declarations) {\n for (const name of collectIdentifiersFromPattern(declarator.id)) {\n map.set(name, declarator)\n }\n }\n } else if (t.isFunctionDeclaration(decl) && decl.id) {\n map.set(decl.id.name, decl)\n } else if (t.isClassDeclaration(decl) && decl.id) {\n map.set(decl.id.name, decl)\n }\n }\n return map\n}\n\n/**\n * Build a dependency graph: for each local binding, the set of other local\n * bindings its declaration references. Built once via simple node walking.\n */\nexport function buildDependencyGraph(\n declMap: Map<string, t.Node>,\n localBindings: Set<string>,\n): Map<string, Set<string>> {\n const graph = new Map<string, Set<string>>()\n for (const [name, declNode] of declMap) {\n if (!localBindings.has(name)) continue\n const allIds = collectIdentifiersFromNode(declNode)\n const deps = new Set<string>()\n for (const id of allIds) {\n if (id !== name && localBindings.has(id)) deps.add(id)\n }\n graph.set(name, deps)\n }\n return graph\n}\n\n/**\n * Computes module-level bindings that are shared between split and non-split\n * route properties. These bindings need to be extracted into a shared virtual\n * module to avoid double-initialization.\n *\n * A binding is \"shared\" if it is referenced by at least one split property\n * AND at least one non-split property. Only locally-declared module-level\n * bindings are candidates (not imports — bundlers dedupe those).\n */\nexport function computeSharedBindings(opts: {\n code: string\n codeSplitGroupings: CodeSplitGroupings\n}): Set<string> {\n const ast = parseAst(opts)\n\n // Early bailout: collect all module-level locally-declared binding names.\n // This is a cheap loop over program.body (no traversal). If the file has\n // no local bindings (aside from `Route`), nothing can be shared — skip\n // the expensive babel.traverse entirely.\n const localModuleLevelBindings = new Set<string>()\n for (const node of ast.program.body) {\n collectLocalBindingsFromStatement(node, localModuleLevelBindings)\n }\n\n // File-based routes always export a route config binding (usually `Route`).\n // This must never be extracted into the shared module.\n localModuleLevelBindings.delete('Route')\n\n if (localModuleLevelBindings.size === 0) {\n return new Set()\n }\n\n function findIndexForSplitNode(str: string) {\n return opts.codeSplitGroupings.findIndex((group) =>\n group.includes(str as any),\n )\n }\n\n // Find the route options object — needs babel.traverse for scope resolution\n let routeOptions: t.ObjectExpression | undefined\n\n babel.traverse(ast, {\n CallExpression(path) {\n if (!t.isIdentifier(path.node.callee)) return\n if (!splittableCreateRouteFns.includes(path.node.callee.name)) return\n\n if (t.isCallExpression(path.parentPath.node)) {\n const opts = resolveIdentifier(path, path.parentPath.node.arguments[0])\n if (t.isObjectExpression(opts)) routeOptions = opts\n } else if (t.isVariableDeclarator(path.parentPath.node)) {\n const caller = resolveIdentifier(path, path.parentPath.node.init)\n if (t.isCallExpression(caller)) {\n const opts = resolveIdentifier(path, caller.arguments[0])\n if (t.isObjectExpression(opts)) routeOptions = opts\n }\n }\n },\n })\n\n if (!routeOptions) return new Set()\n\n // Fast path: if fewer than 2 distinct groups are referenced by route options,\n // nothing can be shared and we can skip the rest of the work.\n const splitGroupsPresent = new Set<number>()\n let hasNonSplit = false\n for (const prop of routeOptions.properties) {\n if (!t.isObjectProperty(prop) || !t.isIdentifier(prop.key)) continue\n if (prop.key.name === 'codeSplitGroupings') continue\n if (t.isIdentifier(prop.value) && prop.value.name === 'undefined') continue\n const groupIndex = findIndexForSplitNode(prop.key.name) // -1 if non-split\n if (groupIndex === -1) {\n hasNonSplit = true\n } else {\n splitGroupsPresent.add(groupIndex)\n }\n }\n\n if (!hasNonSplit && splitGroupsPresent.size < 2) return new Set()\n\n // Build dependency graph up front — needed for transitive expansion per-property.\n // This graph excludes `Route` (deleted above) so group attribution works correctly.\n const declMap = buildDeclarationMap(ast)\n const depGraph = buildDependencyGraph(declMap, localModuleLevelBindings)\n\n // Build a second dependency graph that includes `Route` so we can detect\n // bindings that transitively depend on it. Such bindings must NOT be\n // extracted into the shared module because they would drag the Route\n // singleton with them, duplicating it across modules.\n const allLocalBindings = new Set(localModuleLevelBindings)\n allLocalBindings.add('Route')\n const fullDepGraph = buildDependencyGraph(declMap, allLocalBindings)\n\n // For each route property, track which \"group\" it belongs to.\n // Non-split properties get group index -1.\n // Split properties get their codeSplitGroupings index (0, 1, ...).\n // A binding is \"shared\" if it appears in 2+ distinct groups.\n // We expand each property's refs transitively BEFORE comparing groups,\n // so indirect refs (e.g., component: MyComp where MyComp uses `shared`)\n // are correctly attributed.\n const refsByGroup = new Map<string, Set<number>>()\n\n for (const prop of routeOptions.properties) {\n if (!t.isObjectProperty(prop) || !t.isIdentifier(prop.key)) continue\n const key = prop.key.name\n\n if (key === 'codeSplitGroupings') continue\n\n const groupIndex = findIndexForSplitNode(key) // -1 if non-split\n\n const directRefs = collectModuleLevelRefsFromNode(\n prop.value,\n localModuleLevelBindings,\n )\n\n // Expand transitively: if component references SharedComp which references\n // `shared`, then `shared` is also attributed to component's group.\n const allRefs = new Set(directRefs)\n expandTransitively(allRefs, depGraph)\n\n for (const ref of allRefs) {\n let groups = refsByGroup.get(ref)\n if (!groups) {\n groups = new Set()\n refsByGroup.set(ref, groups)\n }\n groups.add(groupIndex)\n }\n }\n\n // Shared = bindings appearing in 2+ distinct groups\n const shared = new Set<string>()\n for (const [name, groups] of refsByGroup) {\n if (groups.size >= 2) shared.add(name)\n }\n\n // Destructured declarators (e.g. `const { a, b } = fn()`) must be treated\n // as a single initialization unit. Even if each binding is referenced by\n // only one group, if *different* bindings from the same declarator are\n // referenced by different groups, the declarator must be extracted to the\n // shared module to avoid double initialization.\n expandSharedDestructuredDeclarators(ast, refsByGroup, shared)\n\n if (shared.size === 0) return shared\n\n // If any binding from a destructured declaration is shared,\n // all bindings from that declaration must be shared\n expandDestructuredDeclarations(ast, shared)\n\n // Remove shared bindings that transitively depend on `Route`.\n // The Route singleton must stay in the reference file; extracting a\n // binding that references it would duplicate Route in the shared module.\n removeBindingsDependingOnRoute(shared, fullDepGraph)\n\n return shared\n}\n\n/**\n * If bindings from the same destructured declarator are referenced by\n * different groups, mark all bindings from that declarator as shared.\n */\nexport function expandSharedDestructuredDeclarators(\n ast: t.File,\n refsByGroup: Map<string, Set<number>>,\n shared: Set<string>,\n) {\n for (const stmt of ast.program.body) {\n const decl =\n t.isExportNamedDeclaration(stmt) && stmt.declaration\n ? stmt.declaration\n : stmt\n\n if (!t.isVariableDeclaration(decl)) continue\n\n for (const declarator of decl.declarations) {\n if (!t.isObjectPattern(declarator.id) && !t.isArrayPattern(declarator.id))\n continue\n\n const names = collectIdentifiersFromPattern(declarator.id)\n\n const usedGroups = new Set<number>()\n for (const name of names) {\n const groups = refsByGroup.get(name)\n if (!groups) continue\n for (const g of groups) usedGroups.add(g)\n }\n\n if (usedGroups.size >= 2) {\n for (const name of names) {\n shared.add(name)\n }\n }\n }\n }\n}\n\n/**\n * Collect locally-declared module-level binding names from a statement.\n * Pure node inspection, no traversal.\n */\nexport function collectLocalBindingsFromStatement(\n node: t.Statement | t.ModuleDeclaration,\n bindings: Set<string>,\n) {\n const decl =\n t.isExportNamedDeclaration(node) && node.declaration\n ? node.declaration\n : node\n\n if (t.isVariableDeclaration(decl)) {\n for (const declarator of decl.declarations) {\n for (const name of collectIdentifiersFromPattern(declarator.id)) {\n bindings.add(name)\n }\n }\n } else if (t.isFunctionDeclaration(decl) && decl.id) {\n bindings.add(decl.id.name)\n } else if (t.isClassDeclaration(decl) && decl.id) {\n bindings.add(decl.id.name)\n }\n}\n\n/**\n * Collect direct module-level binding names referenced from a given AST node.\n * Uses a simple recursive walk instead of babel.traverse.\n */\nexport function collectModuleLevelRefsFromNode(\n node: t.Node,\n localModuleLevelBindings: Set<string>,\n): Set<string> {\n const allIds = collectIdentifiersFromNode(node)\n const refs = new Set<string>()\n for (const name of allIds) {\n if (localModuleLevelBindings.has(name)) refs.add(name)\n }\n return refs\n}\n\n/**\n * Expand the shared set transitively using a prebuilt dependency graph.\n * No AST traversals — pure graph BFS.\n */\nexport function expandTransitively(\n shared: Set<string>,\n depGraph: Map<string, Set<string>>,\n) {\n const queue = [...shared]\n const visited = new Set<string>()\n\n while (queue.length > 0) {\n const name = queue.pop()!\n if (visited.has(name)) continue\n visited.add(name)\n\n const deps = depGraph.get(name)\n if (!deps) continue\n\n for (const dep of deps) {\n if (!shared.has(dep)) {\n shared.add(dep)\n queue.push(dep)\n }\n }\n }\n}\n\n/**\n * Remove any bindings from `shared` that transitively depend on `Route`.\n * The Route singleton must remain in the reference file; if a shared binding\n * references it (directly or transitively), extracting that binding would\n * duplicate Route in the shared module.\n *\n * Uses `depGraph` which must include `Route` as a node so the dependency\n * chain is visible.\n */\nexport function removeBindingsDependingOnRoute(\n shared: Set<string>,\n depGraph: Map<string, Set<string>>,\n) {\n const reverseGraph = new Map<string, Set<string>>()\n for (const [name, deps] of depGraph) {\n for (const dep of deps) {\n let parents = reverseGraph.get(dep)\n if (!parents) {\n parents = new Set<string>()\n reverseGraph.set(dep, parents)\n }\n parents.add(name)\n }\n }\n\n // Walk backwards from Route to find all bindings that can reach it.\n const visited = new Set<string>()\n const queue = ['Route']\n while (queue.length > 0) {\n const cur = queue.pop()!\n if (visited.has(cur)) continue\n visited.add(cur)\n\n const parents = reverseGraph.get(cur)\n if (!parents) continue\n for (const parent of parents) {\n if (!visited.has(parent)) queue.push(parent)\n }\n }\n\n for (const name of [...shared]) {\n if (visited.has(name)) {\n shared.delete(name)\n }\n }\n}\n\n/**\n * If any binding from a destructured declaration is shared,\n * ensure all bindings from that same declaration are also shared.\n * Pure node inspection of program.body, no traversal.\n */\nexport function expandDestructuredDeclarations(\n ast: t.File,\n shared: Set<string>,\n) {\n for (const stmt of ast.program.body) {\n const decl =\n t.isExportNamedDeclaration(stmt) && stmt.declaration\n ? stmt.declaration\n : stmt\n\n if (!t.isVariableDeclaration(decl)) continue\n\n for (const declarator of decl.declarations) {\n if (!t.isObjectPattern(declarator.id) && !t.isArrayPattern(declarator.id))\n continue\n\n const names = collectIdentifiersFromPattern(declarator.id)\n const hasShared = names.some((n) => shared.has(n))\n if (hasShared) {\n for (const n of names) {\n shared.add(n)\n }\n }\n }\n }\n}\n\n/**\n * Find which shared bindings are user-exported in the original source.\n * These need to be re-exported from the shared module.\n */\nfunction findExportedSharedBindings(\n ast: t.File,\n sharedBindings: Set<string>,\n): Set<string> {\n const exported = new Set<string>()\n for (const stmt of ast.program.body) {\n if (!t.isExportNamedDeclaration(stmt) || !stmt.declaration) continue\n\n if (t.isVariableDeclaration(stmt.declaration)) {\n for (const decl of stmt.declaration.declarations) {\n for (const name of collectIdentifiersFromPattern(decl.id)) {\n if (sharedBindings.has(name)) exported.add(name)\n }\n }\n } else if (\n t.isFunctionDeclaration(stmt.declaration) &&\n stmt.declaration.id\n ) {\n if (sharedBindings.has(stmt.declaration.id.name))\n exported.add(stmt.declaration.id.name)\n } else if (t.isClassDeclaration(stmt.declaration) && stmt.declaration.id) {\n if (sharedBindings.has(stmt.declaration.id.name))\n exported.add(stmt.declaration.id.name)\n }\n }\n return exported\n}\n\n/**\n * Remove declarations of shared bindings from the AST.\n * Handles both plain and exported declarations, including destructured patterns.\n * Removes the entire statement if all bindings in it are shared.\n */\nfunction removeSharedDeclarations(ast: t.File, sharedBindings: Set<string>) {\n ast.program.body = ast.program.body.filter((stmt) => {\n const decl =\n t.isExportNamedDeclaration(stmt) && stmt.declaration\n ? stmt.declaration\n : stmt\n\n if (t.isVariableDeclaration(decl)) {\n // Filter out declarators where all bound names are shared\n decl.declarations = decl.declarations.filter((declarator) => {\n const names = collectIdentifiersFromPattern(declarator.id)\n return !names.every((n) => sharedBindings.has(n))\n })\n // If no declarators remain, remove the entire statement\n if (decl.declarations.length === 0) return false\n } else if (t.isFunctionDeclaration(decl) && decl.id) {\n if (sharedBindings.has(decl.id.name)) return false\n } else if (t.isClassDeclaration(decl) && decl.id) {\n if (sharedBindings.has(decl.id.name)) return false\n }\n\n return true\n })\n}\n\nexport function compileCodeSplitReferenceRoute(\n opts: ParseAstOptions & {\n codeSplitGroupings: CodeSplitGroupings\n deleteNodes?: Set<DeletableNodes>\n targetFramework: Config['target']\n filename: string\n id: string\n addHmr?: boolean\n sharedBindings?: Set<string>\n },\n): GeneratorResult | null {\n const ast = parseAst(opts)\n\n const refIdents = findReferencedIdentifiers(ast)\n\n const knownExportedIdents = new Set<string>()\n\n function findIndexForSplitNode(str: string) {\n return opts.codeSplitGroupings.findIndex((group) =>\n group.includes(str as any),\n )\n }\n\n const frameworkOptions = getFrameworkOptions(opts.targetFramework)\n const PACKAGE = frameworkOptions.package\n const LAZY_ROUTE_COMPONENT_IDENT = frameworkOptions.idents.lazyRouteComponent\n const LAZY_FN_IDENT = frameworkOptions.idents.lazyFn\n\n let createRouteFn: string\n\n let modified = false as boolean\n let hmrAdded = false as boolean\n let sharedExportedNames: Set<string> | undefined\n babel.traverse(ast, {\n Program: {\n enter(programPath) {\n /**\n * If the component for the route is being imported from\n * another file, this is to track the path to that file\n * the path itself doesn't matter, we just need to keep\n * track of it so that we can remove it from the imports\n * list if it's not being used like:\n *\n * `import '../shared/imported'`\n */\n const removableImportPaths = new Set<string>([])\n\n programPath.traverse({\n CallExpression: (path) => {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n\n if (!allCreateRouteFns.includes(path.node.callee.name)) {\n return\n }\n\n createRouteFn = path.node.callee.name\n\n function babelHandleReference(routeOptions: t.Node | undefined) {\n const hasImportedOrDefinedIdentifier = (name: string) => {\n return programPath.scope.hasBinding(name)\n }\n\n if (t.isObjectExpression(routeOptions)) {\n if (opts.deleteNodes && opts.deleteNodes.size > 0) {\n routeOptions.properties = routeOptions.properties.filter(\n (prop) => {\n if (t.isObjectProperty(prop)) {\n if (t.isIdentifier(prop.key)) {\n if (opts.deleteNodes!.has(prop.key.name as any)) {\n modified = true\n return false\n }\n }\n }\n return true\n },\n )\n }\n if (!splittableCreateRouteFns.includes(createRouteFn)) {\n // we can't split this route but we still add HMR handling if enabled\n if (opts.addHmr && !hmrAdded) {\n programPath.pushContainer('body', routeHmrStatement)\n modified = true\n hmrAdded = true\n }\n // exit traversal so this route is not split\n return programPath.stop()\n }\n routeOptions.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n if (t.isIdentifier(prop.key)) {\n const key = prop.key.name\n\n // If the user has not specified a split grouping for this key\n // then we should not split it\n const codeSplitGroupingByKey = findIndexForSplitNode(key)\n if (codeSplitGroupingByKey === -1) {\n return\n }\n const codeSplitGroup = [\n ...new Set(\n opts.codeSplitGroupings[codeSplitGroupingByKey],\n ),\n ]\n\n // find key in nodeSplitConfig\n const isNodeConfigAvailable = SPLIT_NODES_CONFIG.has(\n key as any,\n )\n\n if (!isNodeConfigAvailable) {\n return\n }\n\n // Exit early if the value is a boolean, null, or undefined.\n // These values mean \"don't use this component, fallback to parent\"\n // No code splitting needed to preserve fallback behavior\n if (\n t.isBooleanLiteral(prop.value) ||\n t.isNullLiteral(prop.value) ||\n (t.isIdentifier(prop.value) &&\n prop.value.name === 'undefined')\n ) {\n return\n }\n\n const splitNodeMeta = SPLIT_NODES_CONFIG.get(key as any)!\n\n // We need to extract the existing search params from the filename, if any\n // and add the relevant codesplitPrefix to them, then write them back to the filename\n const splitUrl = addSplitSearchParamToFilename(\n opts.filename,\n codeSplitGroup,\n )\n\n if (\n splitNodeMeta.splitStrategy === 'lazyRouteComponent'\n ) {\n const value = prop.value\n\n let shouldSplit = true\n\n if (t.isIdentifier(value)) {\n const existingImportPath =\n getImportSpecifierAndPathFromLocalName(\n programPath,\n value.name,\n ).path\n if (existingImportPath) {\n removableImportPaths.add(existingImportPath)\n }\n\n // exported identifiers should not be split\n // since they are already being imported\n // and need to be retained in the compiled file\n const isExported = hasExport(ast, value)\n if (isExported) {\n knownExportedIdents.add(value.name)\n }\n shouldSplit = !isExported\n\n if (shouldSplit) {\n removeIdentifierLiteral(path, value)\n }\n }\n\n if (!shouldSplit) {\n return\n }\n\n modified = true\n\n // Prepend the import statement to the program along with the importer function\n // Check to see if lazyRouteComponent is already imported before attempting\n // to import it again\n if (\n !hasImportedOrDefinedIdentifier(\n LAZY_ROUTE_COMPONENT_IDENT,\n )\n ) {\n programPath.unshiftContainer('body', [\n template.statement(\n `import { ${LAZY_ROUTE_COMPONENT_IDENT} } from '${PACKAGE}'`,\n )(),\n ])\n }\n\n // Check to see if the importer function is already defined\n // If not, define it with the dynamic import statement\n if (\n !hasImportedOrDefinedIdentifier(\n splitNodeMeta.localImporterIdent,\n )\n ) {\n programPath.unshiftContainer('body', [\n template.statement(\n `const ${splitNodeMeta.localImporterIdent} = () => import('${splitUrl}')`,\n )(),\n ])\n }\n\n prop.value = template.expression(\n `${LAZY_ROUTE_COMPONENT_IDENT}(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}')`,\n )()\n\n // add HMR handling\n if (opts.addHmr && !hmrAdded) {\n programPath.pushContainer('body', routeHmrStatement)\n modified = true\n hmrAdded = true\n }\n } else {\n // if (splitNodeMeta.splitStrategy === 'lazyFn') {\n const value = prop.value\n\n let shouldSplit = true\n\n if (t.isIdentifier(value)) {\n const existingImportPath =\n getImportSpecifierAndPathFromLocalName(\n programPath,\n value.name,\n ).path\n if (existingImportPath) {\n removableImportPaths.add(existingImportPath)\n }\n\n // exported identifiers should not be split\n // since they are already being imported\n // and need to be retained in the compiled file\n const isExported = hasExport(ast, value)\n if (isExported) {\n knownExportedIdents.add(value.name)\n }\n shouldSplit = !isExported\n\n if (shouldSplit) {\n removeIdentifierLiteral(path, value)\n }\n }\n\n if (!shouldSplit) {\n return\n }\n modified = true\n\n // Prepend the import statement to the program along with the importer function\n if (!hasImportedOrDefinedIdentifier(LAZY_FN_IDENT)) {\n programPath.unshiftContainer(\n 'body',\n template.smart(\n `import { ${LAZY_FN_IDENT} } from '${PACKAGE}'`,\n )(),\n )\n }\n\n // Check to see if the importer function is already defined\n // If not, define it with the dynamic import statement\n if (\n !hasImportedOrDefinedIdentifier(\n splitNodeMeta.localImporterIdent,\n )\n ) {\n programPath.unshiftContainer('body', [\n template.statement(\n `const ${splitNodeMeta.localImporterIdent} = () => import('${splitUrl}')`,\n )(),\n ])\n }\n\n // Add the lazyFn call with the dynamic import to the prop value\n prop.value = template.expression(\n `${LAZY_FN_IDENT}(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}')`,\n )()\n }\n }\n }\n\n programPath.scope.crawl()\n })\n }\n }\n\n if (t.isCallExpression(path.parentPath.node)) {\n // createFileRoute('/')({ ... })\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n babelHandleReference(options)\n } else if (t.isVariableDeclarator(path.parentPath.node)) {\n // createFileRoute({ ... })\n const caller = resolveIdentifier(path, path.parentPath.node.init)\n\n if (t.isCallExpression(caller)) {\n const options = resolveIdentifier(path, caller.arguments[0])\n babelHandleReference(options)\n }\n }\n },\n })\n\n /**\n * If the component for the route is being imported,\n * and it's not being used, remove the import statement\n * from the program, by checking that the import has no\n * specifiers\n */\n if (removableImportPaths.size > 0) {\n modified = true\n programPath.traverse({\n ImportDeclaration(path) {\n if (path.node.specifiers.length > 0) return\n if (removableImportPaths.has(path.node.source.value)) {\n path.remove()\n }\n },\n })\n }\n\n // Handle shared bindings inside the Program visitor so we have\n // access to programPath for cheap refIdents registration.\n if (opts.sharedBindings && opts.sharedBindings.size > 0) {\n sharedExportedNames = findExportedSharedBindings(\n ast,\n opts.sharedBindings,\n )\n removeSharedDeclarations(ast, opts.sharedBindings)\n\n const sharedModuleUrl = addSharedSearchParamToFilename(opts.filename)\n\n const sharedImportSpecifiers = [...opts.sharedBindings].map((name) =>\n t.importSpecifier(t.identifier(name), t.identifier(name)),\n )\n const [sharedImportPath] = programPath.unshiftContainer(\n 'body',\n t.importDeclaration(\n sharedImportSpecifiers,\n t.stringLiteral(sharedModuleUrl),\n ),\n )\n\n // Register import specifier locals in refIdents so DCE can remove unused ones\n sharedImportPath.traverse({\n Identifier(identPath) {\n if (\n identPath.parentPath.isImportSpecifier() &&\n identPath.key === 'local'\n ) {\n refIdents.add(identPath)\n }\n },\n })\n\n // Re-export user-exported shared bindings from the shared module\n if (sharedExportedNames.size > 0) {\n const reExportSpecifiers = [...sharedExportedNames].map((name) =>\n t.exportSpecifier(t.identifier(name), t.identifier(name)),\n )\n programPath.pushContainer(\n 'body',\n t.exportNamedDeclaration(\n null,\n reExportSpecifiers,\n t.stringLiteral(sharedModuleUrl),\n ),\n )\n }\n }\n },\n },\n })\n\n if (!modified) {\n return null\n }\n\n deadCodeElimination(ast, refIdents)\n\n // if there are exported identifiers, then we need to add a warning\n // to the file to let the user know that the exported identifiers\n // will not in the split file but in the original file, therefore\n // increasing the bundle size\n if (knownExportedIdents.size > 0) {\n const warningMessage = createNotExportableMessage(\n opts.filename,\n knownExportedIdents,\n )\n console.warn(warningMessage)\n\n // append this warning to the file using a template\n if (process.env.NODE_ENV !== 'production') {\n const warningTemplate = template.statement(\n `console.warn(${JSON.stringify(warningMessage)})`,\n )()\n ast.program.body.unshift(warningTemplate)\n }\n }\n\n return generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: opts.filename,\n filename: opts.filename,\n })\n}\n\nexport function compileCodeSplitVirtualRoute(\n opts: ParseAstOptions & {\n splitTargets: Array<SplitRouteIdentNodes>\n filename: string\n sharedBindings?: Set<string>\n },\n): GeneratorResult {\n const ast = parseAst(opts)\n const refIdents = findReferencedIdentifiers(ast)\n\n // Remove shared declarations BEFORE babel.traverse so the scope never sees\n // conflicting bindings (avoids checkBlockScopedCollisions crash in DCE)\n if (opts.sharedBindings && opts.sharedBindings.size > 0) {\n removeSharedDeclarations(ast, opts.sharedBindings)\n }\n\n const intendedSplitNodes = new Set(opts.splitTargets)\n\n const knownExportedIdents = new Set<string>()\n\n babel.traverse(ast, {\n Program: {\n enter(programPath) {\n const trackedNodesToSplitByType: Record<\n SplitRouteIdentNodes,\n { node: t.Node | undefined; meta: SplitNodeMeta } | undefined\n > = {\n component: undefined,\n loader: undefined,\n pendingComponent: undefined,\n errorComponent: undefined,\n notFoundComponent: undefined,\n }\n\n // Find and track all the known split-able nodes\n programPath.traverse({\n CallExpression: (path) => {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n\n if (!splittableCreateRouteFns.includes(path.node.callee.name)) {\n return\n }\n\n function babelHandleVirtual(options: t.Node | undefined) {\n if (t.isObjectExpression(options)) {\n options.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n // do not use `intendedSplitNodes` here\n // since we have special considerations that need\n // to be accounted for like (not splitting exported identifiers)\n KNOWN_SPLIT_ROUTE_IDENTS.forEach((splitType) => {\n if (\n !t.isIdentifier(prop.key) ||\n prop.key.name !== splitType\n ) {\n return\n }\n\n const value = prop.value\n\n // If the value for the `key` is `undefined`, then we don't need to include it\n // in the split file, so we can just return, since it will kept in-place in the\n // reference file\n // This is useful for cases like: `createFileRoute('/')({ component: undefined })`\n if (t.isIdentifier(value) && value.name === 'undefined') {\n return\n }\n\n let isExported = false\n if (t.isIdentifier(value)) {\n isExported = hasExport(ast, value)\n if (isExported) {\n knownExportedIdents.add(value.name)\n }\n }\n\n // If the node is exported, we need to remove\n // the export from the split file\n if (isExported && t.isIdentifier(value)) {\n removeExports(ast, value)\n } else {\n const meta = SPLIT_NODES_CONFIG.get(splitType)!\n trackedNodesToSplitByType[splitType] = {\n node: prop.value,\n meta,\n }\n }\n })\n }\n })\n\n // Remove all of the options\n options.properties = []\n }\n }\n\n if (t.isCallExpression(path.parentPath.node)) {\n // createFileRoute('/')({ ... })\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n babelHandleVirtual(options)\n } else if (t.isVariableDeclarator(path.parentPath.node)) {\n // createFileRoute({ ... })\n const caller = resolveIdentifier(path, path.parentPath.node.init)\n\n if (t.isCallExpression(caller)) {\n const options = resolveIdentifier(path, caller.arguments[0])\n babelHandleVirtual(options)\n }\n }\n },\n })\n\n // Start the transformation to only exported the intended split nodes\n intendedSplitNodes.forEach((SPLIT_TYPE) => {\n const splitKey = trackedNodesToSplitByType[SPLIT_TYPE]\n\n if (!splitKey) {\n return\n }\n\n let splitNode = splitKey.node\n const splitMeta = { ...splitKey.meta, shouldRemoveNode: true }\n\n // Track the original identifier name before resolving through bindings,\n // needed for destructured patterns where the binding resolves to the\n // entire VariableDeclarator (ObjectPattern) rather than the specific binding\n let originalIdentName: string | undefined\n if (t.isIdentifier(splitNode)) {\n originalIdentName = splitNode.name\n }\n\n while (t.isIdentifier(splitNode)) {\n const binding = programPath.scope.getBinding(splitNode.name)\n splitNode = binding?.path.node\n }\n\n // Add the node to the program\n if (splitNode) {\n if (t.isFunctionDeclaration(splitNode)) {\n // an anonymous function declaration should only happen for `export default function() {...}`\n // so we should never get here\n if (!splitNode.id) {\n throw new Error(\n `Function declaration for \"${SPLIT_TYPE}\" must have an identifier.`,\n )\n }\n splitMeta.shouldRemoveNode = false\n splitMeta.localExporterIdent = splitNode.id.name\n } else if (\n t.isFunctionExpression(splitNode) ||\n t.isArrowFunctionExpression(splitNode)\n ) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n splitNode as any,\n ),\n ]),\n )\n } else if (\n t.isImportSpecifier(splitNode) ||\n t.isImportDefaultSpecifier(splitNode)\n ) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n splitNode.local,\n ),\n ]),\n )\n } else if (t.isVariableDeclarator(splitNode)) {\n if (t.isIdentifier(splitNode.id)) {\n splitMeta.localExporterIdent = splitNode.id.name\n splitMeta.shouldRemoveNode = false\n } else if (t.isObjectPattern(splitNode.id)) {\n // Destructured binding like `const { component: MyComp } = createBits()`\n // Use the original identifier name that was tracked before resolving\n if (originalIdentName) {\n splitMeta.localExporterIdent = originalIdentName\n }\n splitMeta.shouldRemoveNode = false\n } else {\n throw new Error(\n `Unexpected splitNode type ☝️: ${splitNode.type}`,\n )\n }\n } else if (t.isCallExpression(splitNode)) {\n const outputSplitNodeCode = generateFromAst(splitNode).code\n const splitNodeAst = babel.parse(outputSplitNodeCode)\n\n if (!splitNodeAst) {\n throw new Error(\n `Failed to parse the generated code for \"${SPLIT_TYPE}\" in the node type \"${splitNode.type}\"`,\n )\n }\n\n const statement = splitNodeAst.program.body[0]\n\n if (!statement) {\n throw new Error(\n `Failed to parse the generated code for \"${SPLIT_TYPE}\" in the node type \"${splitNode.type}\" as no statement was found in the program body`,\n )\n }\n\n if (t.isExpressionStatement(statement)) {\n const expression = statement.expression\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n expression,\n ),\n ]),\n )\n } else {\n throw new Error(\n `Unexpected expression type encounter for \"${SPLIT_TYPE}\" in the node type \"${splitNode.type}\"`,\n )\n }\n } else if (t.isConditionalExpression(splitNode)) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n splitNode,\n ),\n ]),\n )\n } else if (t.isTSAsExpression(splitNode)) {\n // remove the type assertion\n splitNode = splitNode.expression\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n splitNode,\n ),\n ]),\n )\n } else if (t.isBooleanLiteral(splitNode)) {\n // Handle boolean literals\n // This exits early here, since this value will be kept in the reference file\n return\n } else if (t.isNullLiteral(splitNode)) {\n // Handle null literals\n // This exits early here, since this value will be kept in the reference file\n return\n } else {\n console.info('Unexpected splitNode type:', splitNode)\n throw new Error(`Unexpected splitNode type ☝️: ${splitNode.type}`)\n }\n }\n\n if (splitMeta.shouldRemoveNode) {\n // If the splitNode exists at the top of the program\n // then we need to remove that copy\n programPath.node.body = programPath.node.body.filter((node) => {\n return node !== splitNode\n })\n }\n\n // Export the node\n programPath.pushContainer('body', [\n t.exportNamedDeclaration(null, [\n t.exportSpecifier(\n t.identifier(splitMeta.localExporterIdent), // local variable name\n t.identifier(splitMeta.exporterIdent), // as what name it should be exported as\n ),\n ]),\n ])\n })\n\n // convert exports to imports from the original file\n programPath.traverse({\n ExportNamedDeclaration(path) {\n // e.g. export const x = 1 or export { x }\n // becomes\n // import { x } from '${opts.id}'\n\n if (path.node.declaration) {\n if (t.isVariableDeclaration(path.node.declaration)) {\n const specifiers = path.node.declaration.declarations.flatMap(\n (decl) => {\n if (t.isIdentifier(decl.id)) {\n return [\n t.importSpecifier(\n t.identifier(decl.id.name),\n t.identifier(decl.id.name),\n ),\n ]\n }\n\n if (t.isObjectPattern(decl.id)) {\n return collectIdentifiersFromPattern(decl.id).map(\n (name) =>\n t.importSpecifier(\n t.identifier(name),\n t.identifier(name),\n ),\n )\n }\n\n if (t.isArrayPattern(decl.id)) {\n return collectIdentifiersFromPattern(decl.id).map(\n (name) =>\n t.importSpecifier(\n t.identifier(name),\n t.identifier(name),\n ),\n )\n }\n\n return []\n },\n )\n\n if (specifiers.length === 0) {\n path.remove()\n return\n }\n\n const importDecl = t.importDeclaration(\n specifiers,\n t.stringLiteral(\n removeSplitSearchParamFromFilename(opts.filename),\n ),\n )\n\n path.replaceWith(importDecl)\n\n // Track the imported identifier paths so deadCodeElimination can remove them if unused\n // We need to traverse the newly created import to get the identifier paths\n path.traverse({\n Identifier(identPath) {\n // Only track the local binding identifiers (the imported names)\n if (\n identPath.parentPath.isImportSpecifier() &&\n identPath.key === 'local'\n ) {\n refIdents.add(identPath)\n }\n },\n })\n }\n }\n },\n })\n\n // Add shared bindings import, registering specifiers in refIdents\n // so DCE can remove unused ones (same pattern as import replacements above).\n if (opts.sharedBindings && opts.sharedBindings.size > 0) {\n const sharedImportSpecifiers = [...opts.sharedBindings].map((name) =>\n t.importSpecifier(t.identifier(name), t.identifier(name)),\n )\n const sharedModuleUrl = addSharedSearchParamToFilename(\n removeSplitSearchParamFromFilename(opts.filename),\n )\n const [sharedImportPath] = programPath.unshiftContainer(\n 'body',\n t.importDeclaration(\n sharedImportSpecifiers,\n t.stringLiteral(sharedModuleUrl),\n ),\n )\n\n sharedImportPath.traverse({\n Identifier(identPath) {\n if (\n identPath.parentPath.isImportSpecifier() &&\n identPath.key === 'local'\n ) {\n refIdents.add(identPath)\n }\n },\n })\n }\n },\n },\n })\n\n deadCodeElimination(ast, refIdents)\n\n // Strip top-level expression statements that reference no locally-bound names.\n // DCE only removes unused declarations; bare side-effect statements like\n // `console.log(...)` survive even when the virtual file has no exports.\n {\n const locallyBound = new Set<string>()\n for (const stmt of ast.program.body) {\n collectLocalBindingsFromStatement(stmt, locallyBound)\n }\n ast.program.body = ast.program.body.filter((stmt) => {\n if (!t.isExpressionStatement(stmt)) return true\n const refs = collectIdentifiersFromNode(stmt)\n // Keep if it references at least one locally-bound identifier\n return [...refs].some((name) => locallyBound.has(name))\n })\n }\n\n // If the body is empty after DCE, strip directive prologues too.\n // A file containing only `'use client'` with no real code is useless.\n if (ast.program.body.length === 0) {\n ast.program.directives = []\n }\n\n return generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: opts.filename,\n filename: opts.filename,\n })\n}\n\n/**\n * Compile the shared virtual module (`?tsr-shared=1`).\n * Keeps only shared binding declarations, their transitive dependencies,\n * and imports they need. Exports all shared bindings.\n */\nexport function compileCodeSplitSharedRoute(\n opts: ParseAstOptions & {\n sharedBindings: Set<string>\n filename: string\n },\n): GeneratorResult {\n const ast = parseAst(opts)\n const refIdents = findReferencedIdentifiers(ast)\n\n // Collect all names that need to stay: shared bindings + their transitive deps\n const localBindings = new Set<string>()\n for (const node of ast.program.body) {\n collectLocalBindingsFromStatement(node, localBindings)\n }\n\n // Route must never be extracted into the shared module.\n // Excluding it from the dep graph prevents expandTransitively from\n // pulling it in as a transitive dependency of a shared binding.\n localBindings.delete('Route')\n\n const declMap = buildDeclarationMap(ast)\n const depGraph = buildDependencyGraph(declMap, localBindings)\n\n // Start with shared bindings and expand transitively\n const keepBindings = new Set(opts.sharedBindings)\n keepBindings.delete('Route')\n expandTransitively(keepBindings, depGraph)\n\n // Remove all statements except:\n // - Import declarations (needed for deps; DCE will clean unused ones)\n // - Declarations of bindings in keepBindings\n ast.program.body = ast.program.body.filter((stmt) => {\n // Always keep imports — DCE will remove unused ones\n if (t.isImportDeclaration(stmt)) return true\n\n const decl =\n t.isExportNamedDeclaration(stmt) && stmt.declaration\n ? stmt.declaration\n : stmt\n\n if (t.isVariableDeclaration(decl)) {\n // Keep declarators where at least one binding is in keepBindings\n decl.declarations = decl.declarations.filter((declarator) => {\n const names = collectIdentifiersFromPattern(declarator.id)\n return names.some((n) => keepBindings.has(n))\n })\n if (decl.declarations.length === 0) return false\n\n // Strip the `export` wrapper — shared module controls its own exports\n if (t.isExportNamedDeclaration(stmt) && stmt.declaration) {\n return true // keep for now, we'll convert below\n }\n return true\n } else if (t.isFunctionDeclaration(decl) && decl.id) {\n return keepBindings.has(decl.id.name)\n } else if (t.isClassDeclaration(decl) && decl.id) {\n return keepBindings.has(decl.id.name)\n }\n\n // Remove everything else (expression statements, other exports, etc.)\n return false\n })\n\n // Convert `export const/function/class` to plain declarations\n // (we'll add our own export statement at the end)\n ast.program.body = ast.program.body.map((stmt) => {\n if (t.isExportNamedDeclaration(stmt) && stmt.declaration) {\n return stmt.declaration\n }\n return stmt\n })\n\n // Export all shared bindings (sorted for deterministic output)\n const exportNames = [...opts.sharedBindings].sort((a, b) =>\n a.localeCompare(b),\n )\n const exportSpecifiers = exportNames.map((name) =>\n t.exportSpecifier(t.identifier(name), t.identifier(name)),\n )\n if (exportSpecifiers.length > 0) {\n const exportDecl = t.exportNamedDeclaration(null, exportSpecifiers)\n ast.program.body.push(exportDecl)\n\n // Register export specifier locals in refIdents so DCE doesn't treat\n // the exported bindings as unreferenced.\n babel.traverse(ast, {\n Program(programPath) {\n const bodyPaths = programPath.get('body')\n const last = bodyPaths[bodyPaths.length - 1]\n if (last && last.isExportNamedDeclaration()) {\n last.traverse({\n Identifier(identPath) {\n if (\n identPath.parentPath.isExportSpecifier() &&\n identPath.key === 'local'\n ) {\n refIdents.add(identPath)\n }\n },\n })\n }\n programPath.stop()\n },\n })\n }\n\n deadCodeElimination(ast, refIdents)\n\n // If the body is empty after DCE, strip directive prologues too.\n if (ast.program.body.length === 0) {\n ast.program.directives = []\n }\n\n return generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: opts.filename,\n filename: opts.filename,\n })\n}\n\n/**\n * This function should read get the options from by searching for the key `codeSplitGroupings`\n * on createFileRoute and return it's values if it exists, else return undefined\n */\nexport function detectCodeSplitGroupingsFromRoute(opts: ParseAstOptions): {\n groupings: CodeSplitGroupings | undefined\n} {\n const ast = parseAst(opts)\n\n let codeSplitGroupings: CodeSplitGroupings | undefined = undefined\n\n babel.traverse(ast, {\n Program: {\n enter(programPath) {\n programPath.traverse({\n CallExpression(path) {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n\n if (\n !(\n path.node.callee.name === 'createRoute' ||\n path.node.callee.name === 'createFileRoute'\n )\n ) {\n return\n }\n\n function babelHandleSplittingGroups(\n routeOptions: t.Node | undefined,\n ) {\n if (t.isObjectExpression(routeOptions)) {\n routeOptions.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n if (t.isIdentifier(prop.key)) {\n if (prop.key.name === 'codeSplitGroupings') {\n const value = prop.value\n\n if (t.isArrayExpression(value)) {\n codeSplitGroupings = value.elements.map((group) => {\n if (t.isArrayExpression(group)) {\n return group.elements.map((node) => {\n if (!t.isStringLiteral(node)) {\n throw new Error(\n 'You must provide a string literal for the codeSplitGroupings',\n )\n }\n\n return node.value\n }) as Array<SplitRouteIdentNodes>\n }\n\n throw new Error(\n 'You must provide arrays with codeSplitGroupings options.',\n )\n })\n } else {\n throw new Error(\n 'You must provide an array of arrays for the codeSplitGroupings.',\n )\n }\n }\n }\n }\n })\n }\n }\n\n // Extracting the codeSplitGroupings\n if (t.isCallExpression(path.parentPath.node)) {\n // createFileRoute('/')({ ... })\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n babelHandleSplittingGroups(options)\n } else if (t.isVariableDeclarator(path.parentPath.node)) {\n // createFileRoute({ ... })\n const caller = resolveIdentifier(path, path.parentPath.node.init)\n\n if (t.isCallExpression(caller)) {\n const options = resolveIdentifier(path, caller.arguments[0])\n babelHandleSplittingGroups(options)\n }\n }\n },\n })\n },\n },\n })\n\n return { groupings: codeSplitGroupings }\n}\n\nfunction createNotExportableMessage(\n filename: string,\n idents: Set<string>,\n): string {\n const list = Array.from(idents).map((d) => `- ${d}`)\n\n const message = [\n `[tanstack-router] These exports from \"${filename}\" will not be code-split and will increase your bundle size:`,\n ...list,\n 'For the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file.',\n ].join('\\n')\n\n return message\n}\n\nfunction getImportSpecifierAndPathFromLocalName(\n programPath: babel.NodePath<t.Program>,\n name: string,\n): {\n specifier:\n | t.ImportSpecifier\n | t.ImportDefaultSpecifier\n | t.ImportNamespaceSpecifier\n | null\n path: string | null\n} {\n let specifier:\n | t.ImportSpecifier\n | t.ImportDefaultSpecifier\n | t.ImportNamespaceSpecifier\n | null = null\n let path: string | null = null\n\n programPath.traverse({\n ImportDeclaration(importPath) {\n const found = importPath.node.specifiers.find(\n (targetSpecifier) => targetSpecifier.local.name === name,\n )\n if (found) {\n specifier = found\n path = importPath.node.source.value\n }\n },\n })\n\n return { specifier, path }\n}\n\n/**\n * Recursively collects all identifier names from a destructuring pattern\n * (ObjectPattern, ArrayPattern, AssignmentPattern, RestElement).\n */\nfunction collectIdentifiersFromPattern(\n node: t.LVal | t.Node | null | undefined,\n): Array<string> {\n if (!node) {\n return []\n }\n\n if (t.isIdentifier(node)) {\n return [node.name]\n }\n\n if (t.isAssignmentPattern(node)) {\n return collectIdentifiersFromPattern(node.left)\n }\n\n if (t.isRestElement(node)) {\n return collectIdentifiersFromPattern(node.argument)\n }\n\n if (t.isObjectPattern(node)) {\n return node.properties.flatMap((prop) => {\n if (t.isObjectProperty(prop)) {\n return collectIdentifiersFromPattern(prop.value as t.LVal)\n }\n if (t.isRestElement(prop)) {\n return collectIdentifiersFromPattern(prop.argument)\n }\n return []\n })\n }\n\n if (t.isArrayPattern(node)) {\n return node.elements.flatMap((element) =>\n collectIdentifiersFromPattern(element),\n )\n }\n\n return []\n}\n\n// Reusable function to get literal value or resolve variable to literal\nfunction resolveIdentifier(path: any, node: any): t.Node | undefined {\n if (t.isIdentifier(node)) {\n const binding = path.scope.getBinding(node.name)\n if (\n binding\n // && binding.kind === 'const'\n ) {\n const declarator = binding.path.node\n if (t.isObjectExpression(declarator.init)) {\n return declarator.init\n } else if (t.isFunctionDeclaration(declarator.init)) {\n return declarator.init\n }\n }\n return undefined\n }\n\n return node\n}\n\nfunction removeIdentifierLiteral(path: babel.NodePath, node: t.Identifier) {\n const binding = path.scope.getBinding(node.name)\n if (binding) {\n // If the binding is a destructured property from an ObjectPattern,\n // only remove that property instead of the entire declaration\n if (\n t.isVariableDeclarator(binding.path.node) &&\n t.isObjectPattern(binding.path.node.id)\n ) {\n const objectPattern = binding.path.node.id\n objectPattern.properties = objectPattern.properties.filter((prop) => {\n if (!t.isObjectProperty(prop)) {\n return true\n }\n\n if (t.isIdentifier(prop.value) && prop.value.name === node.name) {\n return false\n }\n\n if (\n t.isAssignmentPattern(prop.value) &&\n t.isIdentifier(prop.value.left) &&\n prop.value.left.name === node.name\n ) {\n return false\n }\n\n return true\n })\n\n // If no properties remain, remove the entire declaration\n if (objectPattern.properties.length === 0) {\n binding.path.remove()\n }\n\n return\n }\n\n binding.path.remove()\n }\n}\n\nfunction hasExport(ast: t.File, node: t.Identifier): boolean {\n let found = false\n\n babel.traverse(ast, {\n ExportNamedDeclaration(path) {\n if (path.node.declaration) {\n // declared as `const loaderFn = () => {}`\n if (t.isVariableDeclaration(path.node.declaration)) {\n path.node.declaration.declarations.forEach((decl) => {\n if (t.isVariableDeclarator(decl)) {\n if (t.isIdentifier(decl.id)) {\n if (decl.id.name === node.name) {\n found = true\n }\n } else if (\n t.isObjectPattern(decl.id) ||\n t.isArrayPattern(decl.id)\n ) {\n // Handle destructured exports like `export const { a, b } = fn()`\n const names = collectIdentifiersFromPattern(decl.id)\n if (names.includes(node.name)) {\n found = true\n }\n }\n }\n })\n }\n\n // declared as `function loaderFn() {}`\n if (t.isFunctionDeclaration(path.node.declaration)) {\n if (t.isIdentifier(path.node.declaration.id)) {\n if (path.node.declaration.id.name === node.name) {\n found = true\n }\n }\n }\n }\n },\n ExportDefaultDeclaration(path) {\n // declared as `export default loaderFn`\n if (t.isIdentifier(path.node.declaration)) {\n if (path.node.declaration.name === node.name) {\n found = true\n }\n }\n\n // declared as `export default function loaderFn() {}`\n if (t.isFunctionDeclaration(path.node.declaration)) {\n if (t.isIdentifier(path.node.declaration.id)) {\n if (path.node.declaration.id.name === node.name) {\n found = true\n }\n }\n }\n },\n })\n\n return found\n}\n\nfunction removeExports(ast: t.File, node: t.Identifier): boolean {\n let removed = false\n\n // The checks use sequential if/else if statements since it\n // directly mutates the AST and as such doing normal checks\n // (using only if statements) could lead to a situation where\n // `path.node` is null since it has been already removed from\n // the program tree but typescript doesn't know that.\n babel.traverse(ast, {\n ExportNamedDeclaration(path) {\n if (path.node.declaration) {\n if (t.isVariableDeclaration(path.node.declaration)) {\n // declared as `const loaderFn = () => {}`\n path.node.declaration.declarations.forEach((decl) => {\n if (t.isVariableDeclarator(decl)) {\n if (t.isIdentifier(decl.id)) {\n if (decl.id.name === node.name) {\n path.remove()\n removed = true\n }\n } else if (\n t.isObjectPattern(decl.id) ||\n t.isArrayPattern(decl.id)\n ) {\n // Handle destructured exports like `export const { a, b } = fn()`\n const names = collectIdentifiersFromPattern(decl.id)\n if (names.includes(node.name)) {\n path.remove()\n removed = true\n }\n }\n }\n })\n } else if (t.isFunctionDeclaration(path.node.declaration)) {\n // declared as `export const loaderFn = () => {}`\n if (t.isIdentifier(path.node.declaration.id)) {\n if (path.node.declaration.id.name === node.name) {\n path.remove()\n removed = true\n }\n }\n }\n }\n },\n ExportDefaultDeclaration(path) {\n // declared as `export default loaderFn`\n if (t.isIdentifier(path.node.declaration)) {\n if (path.node.declaration.name === node.name) {\n path.remove()\n removed = true\n }\n } else if (t.isFunctionDeclaration(path.node.declaration)) {\n // declared as `export default function loaderFn() {}`\n if (t.isIdentifier(path.node.declaration.id)) {\n if (path.node.declaration.id.name === node.name) {\n path.remove()\n removed = true\n }\n }\n }\n },\n })\n\n return removed\n}\n"],"names":["tsrSplit","createIdentifier","tsrShared","t","parseAst","opts","findReferencedIdentifiers","frameworkOptions","getFrameworkOptions","routeHmrStatement","template","deadCodeElimination","generateFromAst"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,yCAAyB,IAAyC;AAAA,EACtE;AAAA,IACE;AAAA,IACA;AAAA,MACE,YAAY;AAAA,MACZ,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA,MACf,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA;AAAA,IAAA;AAAA,EACjB;AAAA,EAEF;AAAA,IACE;AAAA,IACA;AAA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WAAW,GAAG;AAEzD,cAAIA,aAAE,aAAa,KAAK,KAAK,YAAY,EAAE,GAAG;AAC5C,gBAAI,KAAK,KAAK,YAAY,GAAG,SAAS,KAAK,MAAM;AAC/C,mBAAK,OAAA;AACL,wBAAU;AAAA,YACZ;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,yBAAyB,MAAM;AAE7B,UAAIA,aAAE,aAAa,KAAK,KAAK,WAAW,GAAG;AACzC,YAAI,KAAK,KAAK,YAAY,SAAS,KAAK,MAAM;AAC5C,eAAK,OAAA;AACL,oBAAU;AAAA,QACZ;AAAA,MACF,WAAWA,aAAE,sBAAsB,KAAK,KAAK,WAAW,GAAG;AAEzD,YAAIA,aAAE,aAAa,KAAK,KAAK,YAAY,EAAE,GAAG;AAC5C,cAAI,KAAK,KAAK,YAAY,GAAG,SAAS,KAAK,MAAM;AAC/C,iBAAK,OAAA;AACL,sBAAU;AAAA,UACZ;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EAAA,CACD;AAED,SAAO;AACT;;;;;;;;;;;;;;;;"}
@@ -1,6 +1,77 @@
1
1
  import { GeneratorResult, ParseAstOptions } from '@tanstack/router-utils';
2
2
  import { CodeSplitGroupings, SplitRouteIdentNodes } from '../constants.cjs';
3
3
  import { Config, DeletableNodes } from '../config.cjs';
4
+ import * as t from '@babel/types';
5
+ export declare function addSharedSearchParamToFilename(filename: string): string;
6
+ /**
7
+ * Recursively walk an AST node and collect referenced identifier-like names.
8
+ * Much cheaper than babel.traverse — no path/scope overhead.
9
+ *
10
+ * Notes:
11
+ * - Uses @babel/types `isReferenced` to avoid collecting non-references like
12
+ * object keys, member expression properties, or binding identifiers.
13
+ * - Also handles JSX identifiers for component references.
14
+ */
15
+ export declare function collectIdentifiersFromNode(node: t.Node): Set<string>;
16
+ /**
17
+ * Build a map from binding name → declaration AST node for all
18
+ * locally-declared module-level bindings. Built once, O(1) lookup.
19
+ */
20
+ export declare function buildDeclarationMap(ast: t.File): Map<string, t.Node>;
21
+ /**
22
+ * Build a dependency graph: for each local binding, the set of other local
23
+ * bindings its declaration references. Built once via simple node walking.
24
+ */
25
+ export declare function buildDependencyGraph(declMap: Map<string, t.Node>, localBindings: Set<string>): Map<string, Set<string>>;
26
+ /**
27
+ * Computes module-level bindings that are shared between split and non-split
28
+ * route properties. These bindings need to be extracted into a shared virtual
29
+ * module to avoid double-initialization.
30
+ *
31
+ * A binding is "shared" if it is referenced by at least one split property
32
+ * AND at least one non-split property. Only locally-declared module-level
33
+ * bindings are candidates (not imports — bundlers dedupe those).
34
+ */
35
+ export declare function computeSharedBindings(opts: {
36
+ code: string;
37
+ codeSplitGroupings: CodeSplitGroupings;
38
+ }): Set<string>;
39
+ /**
40
+ * If bindings from the same destructured declarator are referenced by
41
+ * different groups, mark all bindings from that declarator as shared.
42
+ */
43
+ export declare function expandSharedDestructuredDeclarators(ast: t.File, refsByGroup: Map<string, Set<number>>, shared: Set<string>): void;
44
+ /**
45
+ * Collect locally-declared module-level binding names from a statement.
46
+ * Pure node inspection, no traversal.
47
+ */
48
+ export declare function collectLocalBindingsFromStatement(node: t.Statement | t.ModuleDeclaration, bindings: Set<string>): void;
49
+ /**
50
+ * Collect direct module-level binding names referenced from a given AST node.
51
+ * Uses a simple recursive walk instead of babel.traverse.
52
+ */
53
+ export declare function collectModuleLevelRefsFromNode(node: t.Node, localModuleLevelBindings: Set<string>): Set<string>;
54
+ /**
55
+ * Expand the shared set transitively using a prebuilt dependency graph.
56
+ * No AST traversals — pure graph BFS.
57
+ */
58
+ export declare function expandTransitively(shared: Set<string>, depGraph: Map<string, Set<string>>): void;
59
+ /**
60
+ * Remove any bindings from `shared` that transitively depend on `Route`.
61
+ * The Route singleton must remain in the reference file; if a shared binding
62
+ * references it (directly or transitively), extracting that binding would
63
+ * duplicate Route in the shared module.
64
+ *
65
+ * Uses `depGraph` which must include `Route` as a node so the dependency
66
+ * chain is visible.
67
+ */
68
+ export declare function removeBindingsDependingOnRoute(shared: Set<string>, depGraph: Map<string, Set<string>>): void;
69
+ /**
70
+ * If any binding from a destructured declaration is shared,
71
+ * ensure all bindings from that same declaration are also shared.
72
+ * Pure node inspection of program.body, no traversal.
73
+ */
74
+ export declare function expandDestructuredDeclarations(ast: t.File, shared: Set<string>): void;
4
75
  export declare function compileCodeSplitReferenceRoute(opts: ParseAstOptions & {
5
76
  codeSplitGroupings: CodeSplitGroupings;
6
77
  deleteNodes?: Set<DeletableNodes>;
@@ -8,10 +79,21 @@ export declare function compileCodeSplitReferenceRoute(opts: ParseAstOptions & {
8
79
  filename: string;
9
80
  id: string;
10
81
  addHmr?: boolean;
82
+ sharedBindings?: Set<string>;
11
83
  }): GeneratorResult | null;
12
84
  export declare function compileCodeSplitVirtualRoute(opts: ParseAstOptions & {
13
85
  splitTargets: Array<SplitRouteIdentNodes>;
14
86
  filename: string;
87
+ sharedBindings?: Set<string>;
88
+ }): GeneratorResult;
89
+ /**
90
+ * Compile the shared virtual module (`?tsr-shared=1`).
91
+ * Keeps only shared binding declarations, their transitive dependencies,
92
+ * and imports they need. Exports all shared bindings.
93
+ */
94
+ export declare function compileCodeSplitSharedRoute(opts: ParseAstOptions & {
95
+ sharedBindings: Set<string>;
96
+ filename: string;
15
97
  }): GeneratorResult;
16
98
  /**
17
99
  * This function should read get the options from by searching for the key `codeSplitGroupings`
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const tsrSplit = "tsr-split";
4
+ const tsrShared = "tsr-shared";
4
5
  const splitRouteIdentNodes = [
5
6
  "loader",
6
7
  "component",
@@ -15,5 +16,6 @@ const defaultCodeSplitGroupings = [
15
16
  ];
16
17
  exports.defaultCodeSplitGroupings = defaultCodeSplitGroupings;
17
18
  exports.splitRouteIdentNodes = splitRouteIdentNodes;
19
+ exports.tsrShared = tsrShared;
18
20
  exports.tsrSplit = tsrSplit;
19
21
  //# sourceMappingURL=constants.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.cjs","sources":["../../../src/core/constants.ts"],"sourcesContent":["export const tsrSplit = 'tsr-split'\n\nexport const splitRouteIdentNodes = [\n 'loader',\n 'component',\n 'pendingComponent',\n 'errorComponent',\n 'notFoundComponent',\n] as const\nexport type SplitRouteIdentNodes = (typeof splitRouteIdentNodes)[number]\nexport type CodeSplitGroupings = Array<Array<SplitRouteIdentNodes>>\n\nexport const defaultCodeSplitGroupings: CodeSplitGroupings = [\n ['component'],\n ['errorComponent'],\n ['notFoundComponent'],\n]\n"],"names":[],"mappings":";;AAAO,MAAM,WAAW;AAEjB,MAAM,uBAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAIO,MAAM,4BAAgD;AAAA,EAC3D,CAAC,WAAW;AAAA,EACZ,CAAC,gBAAgB;AAAA,EACjB,CAAC,mBAAmB;AACtB;;;;"}
1
+ {"version":3,"file":"constants.cjs","sources":["../../../src/core/constants.ts"],"sourcesContent":["export const tsrSplit = 'tsr-split'\nexport const tsrShared = 'tsr-shared'\n\nexport const splitRouteIdentNodes = [\n 'loader',\n 'component',\n 'pendingComponent',\n 'errorComponent',\n 'notFoundComponent',\n] as const\nexport type SplitRouteIdentNodes = (typeof splitRouteIdentNodes)[number]\nexport type CodeSplitGroupings = Array<Array<SplitRouteIdentNodes>>\n\nexport const defaultCodeSplitGroupings: CodeSplitGroupings = [\n ['component'],\n ['errorComponent'],\n ['notFoundComponent'],\n]\n"],"names":[],"mappings":";;AAAO,MAAM,WAAW;AACjB,MAAM,YAAY;AAElB,MAAM,uBAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAIO,MAAM,4BAAgD;AAAA,EAC3D,CAAC,WAAW;AAAA,EACZ,CAAC,gBAAgB;AAAA,EACjB,CAAC,mBAAmB;AACtB;;;;;"}
@@ -1,4 +1,5 @@
1
1
  export declare const tsrSplit = "tsr-split";
2
+ export declare const tsrShared = "tsr-shared";
2
3
  export declare const splitRouteIdentNodes: readonly ["loader", "component", "pendingComponent", "errorComponent", "notFoundComponent"];
3
4
  export type SplitRouteIdentNodes = (typeof splitRouteIdentNodes)[number];
4
5
  export type CodeSplitGroupings = Array<Array<SplitRouteIdentNodes>>;
@@ -49,6 +49,7 @@ const unpluginRouterCodeSplitterFactory = (options = {}, { framework: _framework
49
49
  }
50
50
  }
51
51
  const isProduction = process.env.NODE_ENV === "production";
52
+ const sharedBindingsMap = /* @__PURE__ */ new Map();
52
53
  const getGlobalCodeSplitGroupings = () => {
53
54
  return userConfig.codeSplittingOptions?.defaultBehavior || constants.defaultCodeSplitGroupings;
54
55
  };
@@ -85,6 +86,15 @@ ${message}`
85
86
  }
86
87
  }
87
88
  const splitGroupings = fromCode.groupings || pluginSplitBehavior || getGlobalCodeSplitGroupings();
89
+ const sharedBindings = compilers.computeSharedBindings({
90
+ code,
91
+ codeSplitGroupings: splitGroupings
92
+ });
93
+ if (sharedBindings.size > 0) {
94
+ sharedBindingsMap.set(id, sharedBindings);
95
+ } else {
96
+ sharedBindingsMap.delete(id);
97
+ }
88
98
  const compiledReferenceRoute = compilers.compileCodeSplitReferenceRoute({
89
99
  code,
90
100
  codeSplitGroupings: splitGroupings,
@@ -92,7 +102,8 @@ ${message}`
92
102
  filename: id,
93
103
  id,
94
104
  deleteNodes: userConfig.codeSplittingOptions?.deleteNodes ? new Set(userConfig.codeSplittingOptions.deleteNodes) : void 0,
95
- addHmr: (userConfig.codeSplittingOptions?.addHmr ?? true) && !isProduction
105
+ addHmr: (userConfig.codeSplittingOptions?.addHmr ?? true) && !isProduction,
106
+ sharedBindings: sharedBindings.size > 0 ? sharedBindings : void 0
96
107
  });
97
108
  if (compiledReferenceRoute === null) {
98
109
  if (utils.debug) {
@@ -122,10 +133,13 @@ ${message}`
122
133
  const grouping = [...new Set(rawGrouping)].filter(
123
134
  (p) => constants.splitRouteIdentNodes.includes(p)
124
135
  );
136
+ const baseId = id.split("?")[0];
137
+ const resolvedSharedBindings = sharedBindingsMap.get(baseId);
125
138
  const result = compilers.compileCodeSplitVirtualRoute({
126
139
  code,
127
140
  filename: id,
128
- splitTargets: grouping
141
+ splitTargets: grouping,
142
+ sharedBindings: resolvedSharedBindings
129
143
  });
130
144
  if (utils.debug) {
131
145
  routerUtils.logDiff(code, result.code);
@@ -145,7 +159,7 @@ ${message}`
145
159
  transform: {
146
160
  filter: {
147
161
  id: {
148
- exclude: constants.tsrSplit,
162
+ exclude: [constants.tsrSplit, constants.tsrShared],
149
163
  // this is necessary for webpack / rspack to avoid matching .html files
150
164
  include: /\.(m|c)?(j|t)sx?$/
151
165
  },
@@ -236,6 +250,51 @@ Please update your Vite config:
236
250
  const normalizedId = utils.normalizePath(node_url.fileURLToPath(url));
237
251
  return handleCompilingVirtualFile(code, normalizedId);
238
252
  }
253
+ },
254
+ vite: {
255
+ applyToEnvironment(environment) {
256
+ if (userConfig.plugin?.vite?.environmentName) {
257
+ return userConfig.plugin.vite.environmentName === environment.name;
258
+ }
259
+ return true;
260
+ }
261
+ }
262
+ },
263
+ {
264
+ name: "tanstack-router:code-splitter:compile-shared-file",
265
+ enforce: "pre",
266
+ transform: {
267
+ filter: {
268
+ id: /tsr-shared/
269
+ },
270
+ handler(code, id) {
271
+ const url = node_url.pathToFileURL(id);
272
+ url.searchParams.delete("v");
273
+ const normalizedId = utils.normalizePath(node_url.fileURLToPath(url));
274
+ const [baseId] = normalizedId.split("?");
275
+ if (!baseId) return null;
276
+ const sharedBindings = sharedBindingsMap.get(baseId);
277
+ if (!sharedBindings || sharedBindings.size === 0) return null;
278
+ if (utils.debug) console.info("Compiling Shared Module: ", id);
279
+ const result = compilers.compileCodeSplitSharedRoute({
280
+ code,
281
+ sharedBindings,
282
+ filename: normalizedId
283
+ });
284
+ if (utils.debug) {
285
+ routerUtils.logDiff(code, result.code);
286
+ console.log("Output:\n", result.code + "\n\n");
287
+ }
288
+ return result;
289
+ }
290
+ },
291
+ vite: {
292
+ applyToEnvironment(environment) {
293
+ if (userConfig.plugin?.vite?.environmentName) {
294
+ return userConfig.plugin.vite.environmentName === environment.name;
295
+ }
296
+ return true;
297
+ }
239
298
  }
240
299
  }
241
300
  ];