@tanstack/router-plugin 1.98.0 → 1.98.2

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.
@@ -38,6 +38,35 @@ function removeSplitSearchParamFromFilename(filename) {
38
38
  const [bareFilename] = filename.split("?");
39
39
  return bareFilename;
40
40
  }
41
+ const SPLIT_NOES_CONFIG = /* @__PURE__ */ new Map([
42
+ [
43
+ "component",
44
+ {
45
+ routeIdent: "component",
46
+ localImporterIdent: "$$splitComponentImporter",
47
+ // const $$splitComponentImporter = () => import('...')
48
+ splitStrategy: "react-component",
49
+ localExporterIdent: "SplitComponent",
50
+ // const SplitComponent = ...
51
+ exporterIdent: "component"
52
+ // export { SplitComponent as component }
53
+ }
54
+ ],
55
+ [
56
+ "loader",
57
+ {
58
+ routeIdent: "loader",
59
+ localImporterIdent: "$$splitLoaderImporter",
60
+ // const $$splitLoaderImporter = () => import('...')
61
+ splitStrategy: "normal",
62
+ localExporterIdent: "SplitLoader",
63
+ // const SplitLoader = ...
64
+ exporterIdent: "loader"
65
+ // export { SplitLoader as loader }
66
+ }
67
+ ]
68
+ ]);
69
+ const SPLIT_ROUTE_IDENT_NODES = [...SPLIT_NOES_CONFIG.keys()];
41
70
  function compileCodeSplitReferenceRoute(opts) {
42
71
  const ast$1 = ast.parseAst(opts);
43
72
  babel.traverse(ast$1, {
@@ -61,7 +90,6 @@ function compileCodeSplitReferenceRoute(opts) {
61
90
  path,
62
91
  path.parentPath.node.arguments[0]
63
92
  );
64
- let found = false;
65
93
  const hasImportedOrDefinedIdentifier = (name) => {
66
94
  return programPath.scope.hasBinding(name);
67
95
  };
@@ -69,7 +97,15 @@ function compileCodeSplitReferenceRoute(opts) {
69
97
  options.properties.forEach((prop) => {
70
98
  if (t__namespace.isObjectProperty(prop)) {
71
99
  if (t__namespace.isIdentifier(prop.key)) {
72
- if (prop.key.name === "component") {
100
+ const key = prop.key.name;
101
+ const isNodeConfigAvailable = SPLIT_NOES_CONFIG.has(
102
+ key
103
+ );
104
+ if (!isNodeConfigAvailable) {
105
+ return;
106
+ }
107
+ const splitNodeMeta = SPLIT_NOES_CONFIG.get(key);
108
+ if (splitNodeMeta.splitStrategy === "react-component") {
73
109
  const value = prop.value;
74
110
  let shouldSplit = true;
75
111
  if (t__namespace.isIdentifier(value)) {
@@ -83,36 +119,45 @@ function compileCodeSplitReferenceRoute(opts) {
83
119
  removeIdentifierLiteral(path, value);
84
120
  }
85
121
  }
86
- if (shouldSplit) {
87
- if (!hasImportedOrDefinedIdentifier(
88
- "lazyRouteComponent"
89
- )) {
90
- programPath.unshiftContainer("body", [
91
- template__namespace.statement(
92
- `import { lazyRouteComponent } from '@tanstack/react-router'`
93
- )()
94
- ]);
95
- }
96
- if (!hasImportedOrDefinedIdentifier(
97
- "$$splitComponentImporter"
98
- )) {
99
- programPath.unshiftContainer("body", [
100
- template__namespace.statement(
101
- `const $$splitComponentImporter = () => import('${splitUrl}')`
102
- )()
103
- ]);
104
- }
122
+ if (!shouldSplit) {
123
+ return;
124
+ }
125
+ if (!hasImportedOrDefinedIdentifier(
126
+ "lazyRouteComponent"
127
+ )) {
128
+ programPath.unshiftContainer("body", [
129
+ template__namespace.statement(
130
+ `import { lazyRouteComponent } from '@tanstack/react-router'`
131
+ )()
132
+ ]);
133
+ }
134
+ if (!hasImportedOrDefinedIdentifier(
135
+ splitNodeMeta.localImporterIdent
136
+ )) {
137
+ programPath.unshiftContainer("body", [
138
+ template__namespace.statement(
139
+ `const ${splitNodeMeta.localImporterIdent} = () => import('${splitUrl}')`
140
+ )()
141
+ ]);
142
+ }
143
+ if (key === "component") {
144
+ prop.value = template__namespace.expression(
145
+ `lazyRouteComponent(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}', () => Route.ssr)`
146
+ )();
147
+ } else {
105
148
  prop.value = template__namespace.expression(
106
- `lazyRouteComponent($$splitComponentImporter, 'component', () => Route.ssr)`
149
+ `lazyRouteComponent(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}')`
107
150
  )();
151
+ }
152
+ if (!hasImportedOrDefinedIdentifier("TSRDummyComponent")) {
108
153
  programPath.pushContainer("body", [
109
154
  template__namespace.statement(
110
- `function DummyComponent() { return null }`
155
+ `export function TSRDummyComponent() { return null }`
111
156
  )()
112
157
  ]);
113
- found = true;
114
158
  }
115
- } else if (prop.key.name === "loader") {
159
+ }
160
+ if (splitNodeMeta.splitStrategy === "normal") {
116
161
  const value = prop.value;
117
162
  let shouldSplit = true;
118
163
  if (t__namespace.isIdentifier(value)) {
@@ -126,39 +171,35 @@ function compileCodeSplitReferenceRoute(opts) {
126
171
  removeIdentifierLiteral(path, value);
127
172
  }
128
173
  }
129
- if (shouldSplit) {
130
- if (!hasImportedOrDefinedIdentifier("lazyFn")) {
131
- programPath.unshiftContainer("body", [
132
- template__namespace.smart(
133
- `import { lazyFn } from '@tanstack/react-router'`
134
- )()
135
- ]);
136
- }
137
- if (!hasImportedOrDefinedIdentifier(
138
- "$$splitLoaderImporter"
139
- )) {
140
- programPath.unshiftContainer("body", [
141
- template__namespace.statement(
142
- `const $$splitLoaderImporter = () => import('${splitUrl}')`
143
- )()
144
- ]);
145
- }
146
- prop.value = template__namespace.expression(
147
- `lazyFn($$splitLoaderImporter, 'loader')`
148
- )();
149
- found = true;
174
+ if (!shouldSplit) {
175
+ return;
176
+ }
177
+ if (!hasImportedOrDefinedIdentifier("lazyFn")) {
178
+ programPath.unshiftContainer(
179
+ "body",
180
+ template__namespace.smart(
181
+ `import { lazyFn } from '@tanstack/react-router'`
182
+ )()
183
+ );
150
184
  }
185
+ if (!hasImportedOrDefinedIdentifier(
186
+ splitNodeMeta.localImporterIdent
187
+ )) {
188
+ programPath.unshiftContainer("body", [
189
+ template__namespace.statement(
190
+ `const ${splitNodeMeta.localImporterIdent} = () => import('${splitUrl}')`
191
+ )()
192
+ ]);
193
+ }
194
+ prop.value = template__namespace.expression(
195
+ `lazyFn(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}')`
196
+ )();
151
197
  }
152
198
  }
153
199
  }
154
200
  programPath.scope.crawl();
155
201
  });
156
202
  }
157
- if (found) {
158
- programPath.pushContainer("body", [
159
- template__namespace.statement(`function TSR_Dummy_Component() {}`)()
160
- ]);
161
- }
162
203
  }
163
204
  }
164
205
  },
@@ -183,7 +224,6 @@ function compileCodeSplitReferenceRoute(opts) {
183
224
  sourceFileName: opts.filename
184
225
  });
185
226
  }
186
- const splitNodeTypes = ["component", "loader"];
187
227
  function compileCodeSplitVirtualRoute(opts) {
188
228
  const ast$1 = ast.parseAst(opts);
189
229
  const knownExportedIdents = /* @__PURE__ */ new Set();
@@ -191,7 +231,7 @@ function compileCodeSplitVirtualRoute(opts) {
191
231
  Program: {
192
232
  enter(programPath, programState) {
193
233
  const state = programState;
194
- const splitNodesByType = {
234
+ const trackedNodesToSplitByType = {
195
235
  component: void 0,
196
236
  loader: void 0
197
237
  };
@@ -212,7 +252,7 @@ function compileCodeSplitVirtualRoute(opts) {
212
252
  if (t__namespace.isObjectExpression(options)) {
213
253
  options.properties.forEach((prop) => {
214
254
  if (t__namespace.isObjectProperty(prop)) {
215
- splitNodeTypes.forEach((splitType) => {
255
+ SPLIT_ROUTE_IDENT_NODES.forEach((splitType) => {
216
256
  if (!t__namespace.isIdentifier(prop.key) || prop.key.name !== splitType) {
217
257
  return;
218
258
  }
@@ -227,7 +267,11 @@ function compileCodeSplitVirtualRoute(opts) {
227
267
  if (isExported && t__namespace.isIdentifier(value)) {
228
268
  removeExports(ast$1, value);
229
269
  } else {
230
- splitNodesByType[splitType] = prop.value;
270
+ const meta = SPLIT_NOES_CONFIG.get(splitType);
271
+ trackedNodesToSplitByType[splitType] = {
272
+ node: prop.value,
273
+ meta
274
+ };
231
275
  }
232
276
  });
233
277
  }
@@ -239,11 +283,13 @@ function compileCodeSplitVirtualRoute(opts) {
239
283
  },
240
284
  state
241
285
  );
242
- splitNodeTypes.forEach((splitType) => {
243
- let splitNode = splitNodesByType[splitType];
244
- if (!splitNode) {
286
+ SPLIT_ROUTE_IDENT_NODES.forEach((SPLIT_TYPE) => {
287
+ const splitKey = trackedNodesToSplitByType[SPLIT_TYPE];
288
+ if (!splitKey) {
245
289
  return;
246
290
  }
291
+ let splitNode = splitKey.node;
292
+ const splitMeta = splitKey.meta;
247
293
  while (t__namespace.isIdentifier(splitNode)) {
248
294
  const binding = programPath.scope.getBinding(splitNode.name);
249
295
  splitNode = binding == null ? void 0 : binding.path.node;
@@ -254,7 +300,7 @@ function compileCodeSplitVirtualRoute(opts) {
254
300
  "body",
255
301
  t__namespace.variableDeclaration("const", [
256
302
  t__namespace.variableDeclarator(
257
- t__namespace.identifier(splitType),
303
+ t__namespace.identifier(splitMeta.localExporterIdent),
258
304
  t__namespace.functionExpression(
259
305
  splitNode.id || null,
260
306
  // Anonymize the function expression
@@ -271,7 +317,7 @@ function compileCodeSplitVirtualRoute(opts) {
271
317
  "body",
272
318
  t__namespace.variableDeclaration("const", [
273
319
  t__namespace.variableDeclarator(
274
- t__namespace.identifier(splitType),
320
+ t__namespace.identifier(splitMeta.localExporterIdent),
275
321
  splitNode
276
322
  )
277
323
  ])
@@ -281,7 +327,7 @@ function compileCodeSplitVirtualRoute(opts) {
281
327
  "body",
282
328
  t__namespace.variableDeclaration("const", [
283
329
  t__namespace.variableDeclarator(
284
- t__namespace.identifier(splitType),
330
+ t__namespace.identifier(splitMeta.localExporterIdent),
285
331
  splitNode.local
286
332
  )
287
333
  ])
@@ -290,7 +336,10 @@ function compileCodeSplitVirtualRoute(opts) {
290
336
  programPath.pushContainer(
291
337
  "body",
292
338
  t__namespace.variableDeclaration("const", [
293
- t__namespace.variableDeclarator(t__namespace.identifier(splitType), splitNode.init)
339
+ t__namespace.variableDeclarator(
340
+ t__namespace.identifier(splitMeta.localExporterIdent),
341
+ splitNode.init
342
+ )
294
343
  ])
295
344
  );
296
345
  } else if (t__namespace.isCallExpression(splitNode)) {
@@ -298,13 +347,13 @@ function compileCodeSplitVirtualRoute(opts) {
298
347
  const splitNodeAst = babel.parse(outputSplitNodeCode);
299
348
  if (!splitNodeAst) {
300
349
  throw new Error(
301
- `Failed to parse the generated code for "${splitType}" in the node type "${splitNode.type}"`
350
+ `Failed to parse the generated code for "${SPLIT_TYPE}" in the node type "${splitNode.type}"`
302
351
  );
303
352
  }
304
353
  const statement = splitNodeAst.program.body[0];
305
354
  if (!statement) {
306
355
  throw new Error(
307
- `Failed to parse the generated code for "${splitType}" in the node type "${splitNode.type}" as no statement was found in the program body`
356
+ `Failed to parse the generated code for "${SPLIT_TYPE}" in the node type "${splitNode.type}" as no statement was found in the program body`
308
357
  );
309
358
  }
310
359
  if (t__namespace.isExpressionStatement(statement)) {
@@ -312,12 +361,15 @@ function compileCodeSplitVirtualRoute(opts) {
312
361
  programPath.pushContainer(
313
362
  "body",
314
363
  t__namespace.variableDeclaration("const", [
315
- t__namespace.variableDeclarator(t__namespace.identifier(splitType), expression)
364
+ t__namespace.variableDeclarator(
365
+ t__namespace.identifier(splitMeta.localExporterIdent),
366
+ expression
367
+ )
316
368
  ])
317
369
  );
318
370
  } else {
319
371
  throw new Error(
320
- `Unexpected expression type encounter for "${splitType}" in the node type "${splitNode.type}"`
372
+ `Unexpected expression type encounter for "${SPLIT_TYPE}" in the node type "${splitNode.type}"`
321
373
  );
322
374
  }
323
375
  } else {
@@ -331,8 +383,10 @@ function compileCodeSplitVirtualRoute(opts) {
331
383
  programPath.pushContainer("body", [
332
384
  t__namespace.exportNamedDeclaration(null, [
333
385
  t__namespace.exportSpecifier(
334
- t__namespace.identifier(splitType),
335
- t__namespace.identifier(splitType)
386
+ t__namespace.identifier(splitMeta.localExporterIdent),
387
+ // local variable name
388
+ t__namespace.identifier(splitMeta.exporterIdent)
389
+ // as what name it should be exported as
336
390
  )
337
391
  ])
338
392
  ]);
@@ -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 _generate from '@babel/generator'\nimport * as template from '@babel/template'\nimport { deadCodeElimination } from 'babel-dead-code-elimination'\n\nimport { splitPrefix } from '../constants'\nimport { parseAst } from './ast'\nimport type { ParseAstOptions } from './ast'\n\nconst debug = process.env.TSR_VITE_DEBUG\n\n// Babel is a CJS package and uses `default` as named binding (`exports.default =`).\n// https://github.com/babel/babel/issues/15269.\nlet generate = (_generate as any)['default'] as typeof _generate\n\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\nif (!generate) {\n generate = _generate\n}\n\ntype SplitModulesById = Record<\n string,\n { id: string; node: t.FunctionExpression }\n>\n\ninterface State {\n filename: string\n opts: {\n minify: boolean\n root: string\n }\n imported: Record<string, boolean>\n refs: Set<any>\n serverIndex: number\n splitIndex: number\n splitModulesById: SplitModulesById\n}\n\nfunction addSplitSearchParamToFilename(filename: string) {\n const [bareFilename] = filename.split('?')\n return `${bareFilename}?${splitPrefix}`\n}\n\nfunction removeSplitSearchParamFromFilename(filename: string) {\n const [bareFilename] = filename.split('?')\n return bareFilename!\n}\n\nexport function compileCodeSplitReferenceRoute(opts: ParseAstOptions) {\n const ast = parseAst(opts)\n\n babel.traverse(ast, {\n Program: {\n enter(programPath, programState) {\n const state = programState as unknown as State\n\n // We need to extract the existing search params from the filename, if any\n // and add the splitPrefix to them, then write them back to the filename\n const splitUrl = addSplitSearchParamToFilename(opts.filename)\n\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 let existingCompImportPath: string | null = null\n let existingLoaderImportPath: string | null = null\n\n programPath.traverse(\n {\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 if (t.isCallExpression(path.parentPath.node)) {\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n let found = false\n\n const hasImportedOrDefinedIdentifier = (name: string) => {\n return programPath.scope.hasBinding(name)\n }\n\n if (t.isObjectExpression(options)) {\n options.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n if (t.isIdentifier(prop.key)) {\n if (prop.key.name === 'component') {\n const value = prop.value\n\n let shouldSplit = true\n\n if (t.isIdentifier(value)) {\n existingCompImportPath =\n getImportSpecifierAndPathFromLocalName(\n programPath,\n value.name,\n ).path\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 shouldSplit = !isExported\n\n if (shouldSplit) {\n removeIdentifierLiteral(path, value)\n }\n }\n\n if (shouldSplit) {\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\n if (\n !hasImportedOrDefinedIdentifier(\n 'lazyRouteComponent',\n )\n ) {\n programPath.unshiftContainer('body', [\n template.statement(\n `import { lazyRouteComponent } from '@tanstack/react-router'`,\n )(),\n ])\n }\n\n if (\n !hasImportedOrDefinedIdentifier(\n '$$splitComponentImporter',\n )\n ) {\n programPath.unshiftContainer('body', [\n template.statement(\n `const $$splitComponentImporter = () => import('${splitUrl}')`,\n )(),\n ])\n }\n\n prop.value = template.expression(\n `lazyRouteComponent($$splitComponentImporter, 'component', () => Route.ssr)`,\n )()\n\n programPath.pushContainer('body', [\n template.statement(\n `function DummyComponent() { return null }`,\n )(),\n ])\n\n found = true\n }\n } else if (prop.key.name === 'loader') {\n const value = prop.value\n\n let shouldSplit = true\n\n if (t.isIdentifier(value)) {\n existingLoaderImportPath =\n getImportSpecifierAndPathFromLocalName(\n programPath,\n value.name,\n ).path\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 shouldSplit = !isExported\n\n if (shouldSplit) {\n removeIdentifierLiteral(path, value)\n }\n }\n\n if (shouldSplit) {\n // Prepend the import statement to the program along with the importer function\n if (!hasImportedOrDefinedIdentifier('lazyFn')) {\n programPath.unshiftContainer('body', [\n template.smart(\n `import { lazyFn } from '@tanstack/react-router'`,\n )() as t.Statement,\n ])\n }\n\n if (\n !hasImportedOrDefinedIdentifier(\n '$$splitLoaderImporter',\n )\n ) {\n programPath.unshiftContainer('body', [\n template.statement(\n `const $$splitLoaderImporter = () => import('${splitUrl}')`,\n )(),\n ])\n }\n\n prop.value = template.expression(\n `lazyFn($$splitLoaderImporter, 'loader')`,\n )()\n\n found = true\n }\n }\n }\n }\n\n programPath.scope.crawl()\n })\n }\n\n if (found as boolean) {\n programPath.pushContainer('body', [\n template.statement(`function TSR_Dummy_Component() {}`)(),\n ])\n }\n }\n },\n },\n state,\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 (\n (existingCompImportPath as string | null) ||\n (existingLoaderImportPath as string | null)\n ) {\n programPath.traverse({\n ImportDeclaration(path) {\n if (path.node.specifiers.length > 0) return\n if (\n path.node.source.value === existingCompImportPath ||\n path.node.source.value === existingLoaderImportPath\n ) {\n path.remove()\n }\n },\n })\n }\n },\n },\n })\n\n deadCodeElimination(ast)\n\n return generate(ast, {\n sourceMaps: true,\n sourceFileName: opts.filename,\n })\n}\n\nconst splitNodeTypes = ['component', 'loader'] as const\ntype SplitNodeType = (typeof splitNodeTypes)[number]\n\nexport function compileCodeSplitVirtualRoute(opts: ParseAstOptions) {\n const ast = parseAst(opts)\n\n const knownExportedIdents = new Set<string>()\n\n babel.traverse(ast, {\n Program: {\n enter(programPath, programState) {\n const state = programState as unknown as State\n\n const splitNodesByType: Record<SplitNodeType, t.Node | undefined> = {\n component: undefined,\n loader: undefined,\n }\n\n // Find the node\n programPath.traverse(\n {\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 if (t.isCallExpression(path.parentPath.node)) {\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n if (t.isObjectExpression(options)) {\n options.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n splitNodeTypes.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 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 splitNodesByType[splitType] = prop.value\n }\n })\n }\n })\n\n // Remove all of the options\n options.properties = []\n }\n }\n },\n },\n state,\n )\n\n splitNodeTypes.forEach((splitType) => {\n let splitNode = splitNodesByType[splitType]\n\n if (!splitNode) {\n return\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 programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitType),\n t.functionExpression(\n splitNode.id || null, // Anonymize the function expression\n splitNode.params,\n splitNode.body,\n splitNode.generator,\n splitNode.async,\n ),\n ),\n ]),\n )\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(splitType),\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(splitType),\n splitNode.local,\n ),\n ]),\n )\n } else if (t.isVariableDeclarator(splitNode)) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(t.identifier(splitType), splitNode.init),\n ]),\n )\n } else if (t.isCallExpression(splitNode)) {\n const outputSplitNodeCode = generate(splitNode).code\n const splitNodeAst = babel.parse(outputSplitNodeCode)\n\n if (!splitNodeAst) {\n throw new Error(\n `Failed to parse the generated code for \"${splitType}\" 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 \"${splitType}\" 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(t.identifier(splitType), expression),\n ]),\n )\n } else {\n throw new Error(\n `Unexpected expression type encounter for \"${splitType}\" in the node type \"${splitNode.type}\"`,\n )\n }\n } else {\n console.info('Unexpected splitNode type:', splitNode)\n throw new Error(`Unexpected splitNode type ☝️: ${splitNode.type}`)\n }\n }\n\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 // Export the node\n programPath.pushContainer('body', [\n t.exportNamedDeclaration(null, [\n t.exportSpecifier(\n t.identifier(splitType),\n t.identifier(splitType),\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 path.replaceWith(\n 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 }\n }\n },\n })\n },\n },\n })\n\n deadCodeElimination(ast)\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 list = Array.from(knownExportedIdents).reduce((str, ident) => {\n str += `\\n- ${ident}`\n return str\n }, '')\n\n const warningMessage = `These exports from \"${opts.filename.replace('?' + splitPrefix, '')}\" are not being code-split and will increase your bundle size: ${list}\\nThese should either have their export statements removed or be imported from another file that is not a route.`\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 generate(ast, {\n sourceMaps: true,\n sourceFileName: opts.filename,\n })\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) {\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: any, node: any) {\n if (t.isIdentifier(node)) {\n const binding = path.scope.getBinding(node.name)\n if (binding) {\n binding.path.remove()\n }\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 if (t.isIdentifier(path.node.declaration)) {\n if (path.node.declaration.name === node.name) {\n found = true\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 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 path.remove()\n removed = true\n }\n }\n }\n })\n } else if (t.isFunctionDeclaration(path.node.declaration)) {\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 if (t.isIdentifier(path.node.declaration)) {\n if (path.node.declaration.name === node.name) {\n path.remove()\n removed = true\n }\n }\n },\n })\n\n return removed\n}\n"],"names":["splitPrefix","ast","parseAst","t","template","deadCodeElimination"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAUc,QAAQ,IAAI;AAI1B,IAAI,WAAY,UAAkB,SAAS;AAG3C,IAAI,CAAC,UAAU;AACF,aAAA;AACb;AAoBA,SAAS,8BAA8B,UAAkB;AACvD,QAAM,CAAC,YAAY,IA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":["import * as t from '@babel/types'\nimport babel from '@babel/core'\nimport _generate from '@babel/generator'\nimport * as template from '@babel/template'\nimport { deadCodeElimination } from 'babel-dead-code-elimination'\n\nimport { splitPrefix } from '../constants'\nimport { parseAst } from './ast'\nimport type { ParseAstOptions } from './ast'\n\nconst debug = process.env.TSR_VITE_DEBUG\n\n// Babel is a CJS package and uses `default` as named binding (`exports.default =`).\n// https://github.com/babel/babel/issues/15269.\nlet generate = (_generate as any)['default'] as typeof _generate\n\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\nif (!generate) {\n generate = _generate\n}\n\ntype SplitModulesById = Record<\n string,\n { id: string; node: t.FunctionExpression }\n>\n\ninterface State {\n filename: string\n opts: {\n minify: boolean\n root: string\n }\n imported: Record<string, boolean>\n refs: Set<any>\n serverIndex: number\n splitIndex: number\n splitModulesById: SplitModulesById\n}\n\nfunction addSplitSearchParamToFilename(filename: string) {\n const [bareFilename] = filename.split('?')\n return `${bareFilename}?${splitPrefix}`\n}\n\nfunction removeSplitSearchParamFromFilename(filename: string) {\n const [bareFilename] = filename.split('?')\n return bareFilename!\n}\n\ntype SplitRouteIdentNodes = 'component' | 'loader'\ntype SplitNodeMeta = {\n routeIdent: SplitRouteIdentNodes\n splitStrategy: 'normal' | 'react-component'\n localImporterIdent: string\n exporterIdent: string\n localExporterIdent: string\n}\nconst SPLIT_NOES_CONFIG = new Map<SplitRouteIdentNodes, SplitNodeMeta>([\n [\n 'component',\n {\n routeIdent: 'component',\n localImporterIdent: '$$splitComponentImporter', // const $$splitComponentImporter = () => import('...')\n splitStrategy: 'react-component',\n localExporterIdent: 'SplitComponent', // const SplitComponent = ...\n exporterIdent: 'component', // export { SplitComponent as component }\n },\n ],\n [\n 'loader',\n {\n routeIdent: 'loader',\n localImporterIdent: '$$splitLoaderImporter', // const $$splitLoaderImporter = () => import('...')\n splitStrategy: 'normal',\n localExporterIdent: 'SplitLoader', // const SplitLoader = ...\n exporterIdent: 'loader', // export { SplitLoader as loader }\n },\n ],\n])\nconst SPLIT_ROUTE_IDENT_NODES = [...SPLIT_NOES_CONFIG.keys()] as const\n\nexport function compileCodeSplitReferenceRoute(opts: ParseAstOptions) {\n const ast = parseAst(opts)\n\n babel.traverse(ast, {\n Program: {\n enter(programPath, programState) {\n const state = programState as unknown as State\n\n // We need to extract the existing search params from the filename, if any\n // and add the splitPrefix to them, then write them back to the filename\n const splitUrl = addSplitSearchParamToFilename(opts.filename)\n\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 let existingCompImportPath: string | null = null\n let existingLoaderImportPath: string | null = null\n\n programPath.traverse(\n {\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 if (t.isCallExpression(path.parentPath.node)) {\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n const hasImportedOrDefinedIdentifier = (name: string) => {\n return programPath.scope.hasBinding(name)\n }\n\n if (t.isObjectExpression(options)) {\n options.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n if (t.isIdentifier(prop.key)) {\n const key = prop.key.name\n // find key in nodeSplitConfig\n const isNodeConfigAvailable = SPLIT_NOES_CONFIG.has(\n key as any,\n )\n\n if (!isNodeConfigAvailable) {\n return\n }\n\n const splitNodeMeta = SPLIT_NOES_CONFIG.get(key as any)!\n\n if (splitNodeMeta.splitStrategy === 'react-component') {\n const value = prop.value\n\n let shouldSplit = true\n\n if (t.isIdentifier(value)) {\n existingCompImportPath =\n getImportSpecifierAndPathFromLocalName(\n programPath,\n value.name,\n ).path\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 shouldSplit = !isExported\n\n if (shouldSplit) {\n removeIdentifierLiteral(path, value)\n }\n }\n\n if (!shouldSplit) {\n return\n }\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\n if (\n !hasImportedOrDefinedIdentifier(\n 'lazyRouteComponent',\n )\n ) {\n programPath.unshiftContainer('body', [\n template.statement(\n `import { lazyRouteComponent } from '@tanstack/react-router'`,\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 // If it's a component, we need to pass the function to check the Route.ssr value\n if (key === 'component') {\n prop.value = template.expression(\n `lazyRouteComponent(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}', () => Route.ssr)`,\n )()\n } else {\n prop.value = template.expression(\n `lazyRouteComponent(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}')`,\n )()\n }\n\n // If the TSRDummyComponent is not defined, define it\n if (\n !hasImportedOrDefinedIdentifier('TSRDummyComponent')\n ) {\n programPath.pushContainer('body', [\n template.statement(\n `export function TSRDummyComponent() { return null }`,\n )(),\n ])\n }\n }\n\n if (splitNodeMeta.splitStrategy === 'normal') {\n const value = prop.value\n\n let shouldSplit = true\n\n if (t.isIdentifier(value)) {\n existingLoaderImportPath =\n getImportSpecifierAndPathFromLocalName(\n programPath,\n value.name,\n ).path\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 shouldSplit = !isExported\n\n if (shouldSplit) {\n removeIdentifierLiteral(path, value)\n }\n }\n\n if (!shouldSplit) {\n return\n }\n\n // Prepend the import statement to the program along with the importer function\n if (!hasImportedOrDefinedIdentifier('lazyFn')) {\n programPath.unshiftContainer(\n 'body',\n template.smart(\n `import { lazyFn } from '@tanstack/react-router'`,\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 `lazyFn(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}')`,\n )()\n }\n }\n }\n\n programPath.scope.crawl()\n })\n }\n }\n },\n },\n state,\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 (\n (existingCompImportPath as string | null) ||\n (existingLoaderImportPath as string | null)\n ) {\n programPath.traverse({\n ImportDeclaration(path) {\n if (path.node.specifiers.length > 0) return\n if (\n path.node.source.value === existingCompImportPath ||\n path.node.source.value === existingLoaderImportPath\n ) {\n path.remove()\n }\n },\n })\n }\n },\n },\n })\n\n deadCodeElimination(ast)\n\n return generate(ast, {\n sourceMaps: true,\n sourceFileName: opts.filename,\n })\n}\n\nexport function compileCodeSplitVirtualRoute(opts: ParseAstOptions) {\n const ast = parseAst(opts)\n\n const knownExportedIdents = new Set<string>()\n\n babel.traverse(ast, {\n Program: {\n enter(programPath, programState) {\n const state = programState as unknown as State\n\n const trackedNodesToSplitByType: Record<\n SplitRouteIdentNodes,\n { node: t.Node | undefined; meta: SplitNodeMeta } | undefined\n > = {\n component: undefined,\n loader: undefined,\n }\n\n // Find the node\n programPath.traverse(\n {\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 if (t.isCallExpression(path.parentPath.node)) {\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n if (t.isObjectExpression(options)) {\n options.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n SPLIT_ROUTE_IDENT_NODES.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 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_NOES_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 },\n state,\n )\n\n SPLIT_ROUTE_IDENT_NODES.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\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 programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n t.functionExpression(\n splitNode.id || null, // Anonymize the function expression\n splitNode.params,\n splitNode.body,\n splitNode.generator,\n splitNode.async,\n ),\n ),\n ]),\n )\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 programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n splitNode.init,\n ),\n ]),\n )\n } else if (t.isCallExpression(splitNode)) {\n const outputSplitNodeCode = generate(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 {\n console.info('Unexpected splitNode type:', splitNode)\n throw new Error(`Unexpected splitNode type ☝️: ${splitNode.type}`)\n }\n }\n\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 // 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 path.replaceWith(\n 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 }\n }\n },\n })\n },\n },\n })\n\n deadCodeElimination(ast)\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 list = Array.from(knownExportedIdents).reduce((str, ident) => {\n str += `\\n- ${ident}`\n return str\n }, '')\n\n const warningMessage = `These exports from \"${opts.filename.replace('?' + splitPrefix, '')}\" are not being code-split and will increase your bundle size: ${list}\\nThese should either have their export statements removed or be imported from another file that is not a route.`\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 generate(ast, {\n sourceMaps: true,\n sourceFileName: opts.filename,\n })\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) {\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: any, node: any) {\n if (t.isIdentifier(node)) {\n const binding = path.scope.getBinding(node.name)\n if (binding) {\n binding.path.remove()\n }\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 if (t.isIdentifier(path.node.declaration)) {\n if (path.node.declaration.name === node.name) {\n found = true\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 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 path.remove()\n removed = true\n }\n }\n }\n })\n } else if (t.isFunctionDeclaration(path.node.declaration)) {\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 if (t.isIdentifier(path.node.declaration)) {\n if (path.node.declaration.name === node.name) {\n path.remove()\n removed = true\n }\n }\n },\n })\n\n return removed\n}\n"],"names":["splitPrefix","ast","parseAst","t","template","deadCodeElimination"],"mappings":";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