@tanstack/router-plugin 1.120.5 → 1.121.0-alpha.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.
- package/dist/cjs/core/code-splitter/compilers.cjs +195 -194
- package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/compilers.d.cts +3 -0
- package/dist/cjs/core/code-splitter/framework-options.cjs +4 -8
- package/dist/cjs/core/code-splitter/framework-options.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/framework-options.d.cts +0 -2
- package/dist/cjs/core/config.d.cts +31 -40
- package/dist/cjs/core/route-autoimport-plugin.cjs +98 -0
- package/dist/cjs/core/route-autoimport-plugin.cjs.map +1 -0
- package/dist/cjs/core/route-autoimport-plugin.d.cts +6 -0
- package/dist/cjs/core/route-hmr-statement.cjs +33 -0
- package/dist/cjs/core/route-hmr-statement.cjs.map +1 -0
- package/dist/cjs/core/route-hmr-statement.d.cts +1 -0
- package/dist/cjs/core/router-code-splitter-plugin.cjs +11 -20
- package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-composed-plugin.cjs +19 -5
- package/dist/cjs/core/router-composed-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-generator-plugin.cjs +8 -2
- package/dist/cjs/core/router-generator-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-hmr-plugin.cjs +51 -0
- package/dist/cjs/core/router-hmr-plugin.cjs.map +1 -0
- package/dist/cjs/core/router-hmr-plugin.d.cts +8 -0
- package/dist/cjs/core/utils.cjs +12 -0
- package/dist/cjs/core/utils.cjs.map +1 -0
- package/dist/cjs/core/utils.d.cts +2 -0
- package/dist/cjs/esbuild.cjs +2 -0
- package/dist/cjs/esbuild.cjs.map +1 -1
- package/dist/cjs/esbuild.d.cts +53 -27
- package/dist/cjs/rspack.cjs +2 -0
- package/dist/cjs/rspack.cjs.map +1 -1
- package/dist/cjs/rspack.d.cts +53 -27
- package/dist/cjs/vite.cjs +2 -0
- package/dist/cjs/vite.cjs.map +1 -1
- package/dist/cjs/vite.d.cts +52 -26
- package/dist/cjs/webpack.cjs +2 -0
- package/dist/cjs/webpack.cjs.map +1 -1
- package/dist/cjs/webpack.d.cts +53 -27
- package/dist/esm/core/code-splitter/compilers.d.ts +3 -0
- package/dist/esm/core/code-splitter/compilers.js +195 -194
- package/dist/esm/core/code-splitter/compilers.js.map +1 -1
- package/dist/esm/core/code-splitter/framework-options.d.ts +0 -2
- package/dist/esm/core/code-splitter/framework-options.js +4 -8
- package/dist/esm/core/code-splitter/framework-options.js.map +1 -1
- package/dist/esm/core/config.d.ts +31 -40
- package/dist/esm/core/route-autoimport-plugin.d.ts +6 -0
- package/dist/esm/core/route-autoimport-plugin.js +81 -0
- package/dist/esm/core/route-autoimport-plugin.js.map +1 -0
- package/dist/esm/core/route-hmr-statement.d.ts +1 -0
- package/dist/esm/core/route-hmr-statement.js +16 -0
- package/dist/esm/core/route-hmr-statement.js.map +1 -0
- package/dist/esm/core/router-code-splitter-plugin.js +5 -14
- package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
- package/dist/esm/core/router-composed-plugin.js +19 -5
- package/dist/esm/core/router-composed-plugin.js.map +1 -1
- package/dist/esm/core/router-generator-plugin.js +8 -2
- package/dist/esm/core/router-generator-plugin.js.map +1 -1
- package/dist/esm/core/router-hmr-plugin.d.ts +8 -0
- package/dist/esm/core/router-hmr-plugin.js +51 -0
- package/dist/esm/core/router-hmr-plugin.js.map +1 -0
- package/dist/esm/core/utils.d.ts +2 -0
- package/dist/esm/core/utils.js +12 -0
- package/dist/esm/core/utils.js.map +1 -0
- package/dist/esm/esbuild.d.ts +53 -27
- package/dist/esm/esbuild.js +3 -1
- package/dist/esm/esbuild.js.map +1 -1
- package/dist/esm/rspack.d.ts +53 -27
- package/dist/esm/rspack.js +3 -1
- package/dist/esm/rspack.js.map +1 -1
- package/dist/esm/vite.d.ts +52 -26
- package/dist/esm/vite.js +3 -1
- package/dist/esm/vite.js.map +1 -1
- package/dist/esm/webpack.d.ts +53 -27
- package/dist/esm/webpack.js +3 -1
- package/dist/esm/webpack.js.map +1 -1
- package/package.json +6 -6
- package/src/core/code-splitter/compilers.ts +265 -277
- package/src/core/code-splitter/framework-options.ts +0 -6
- package/src/core/route-autoimport-plugin.ts +102 -0
- package/src/core/route-hmr-statement.ts +13 -0
- package/src/core/router-code-splitter-plugin.ts +3 -23
- package/src/core/router-composed-plugin.ts +20 -10
- package/src/core/router-generator-plugin.ts +12 -1
- package/src/core/router-hmr-plugin.ts +65 -0
- package/src/core/utils.ts +18 -0
- package/src/esbuild.ts +3 -2
- package/src/rspack.ts +3 -2
- package/src/vite.ts +3 -0
- package/src/webpack.ts +3 -1
|
@@ -6,6 +6,7 @@ const template = require("@babel/template");
|
|
|
6
6
|
const babelDeadCodeElimination = require("babel-dead-code-elimination");
|
|
7
7
|
const routerUtils = require("@tanstack/router-utils");
|
|
8
8
|
const constants = require("../constants.cjs");
|
|
9
|
+
const routeHmrStatement = require("../route-hmr-statement.cjs");
|
|
9
10
|
const pathIds = require("./path-ids.cjs");
|
|
10
11
|
const frameworkOptions = require("./framework-options.cjs");
|
|
11
12
|
function _interopNamespaceDefault(e) {
|
|
@@ -26,7 +27,6 @@ function _interopNamespaceDefault(e) {
|
|
|
26
27
|
}
|
|
27
28
|
const t__namespace = /* @__PURE__ */ _interopNamespaceDefault(t);
|
|
28
29
|
const template__namespace = /* @__PURE__ */ _interopNamespaceDefault(template);
|
|
29
|
-
process.env.TSR_VITE_DEBUG;
|
|
30
30
|
const SPLIT_NODES_CONFIG = /* @__PURE__ */ new Map([
|
|
31
31
|
[
|
|
32
32
|
"loader",
|
|
@@ -119,164 +119,160 @@ function compileCodeSplitReferenceRoute(opts) {
|
|
|
119
119
|
const LAZY_FN_IDENT = frameworkOptions$1.idents.lazyFn;
|
|
120
120
|
babel.traverse(ast, {
|
|
121
121
|
Program: {
|
|
122
|
-
enter(programPath
|
|
123
|
-
const state = programState;
|
|
122
|
+
enter(programPath) {
|
|
124
123
|
const removableImportPaths = /* @__PURE__ */ new Set([]);
|
|
125
|
-
programPath.traverse(
|
|
126
|
-
{
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
)
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
124
|
+
programPath.traverse({
|
|
125
|
+
CallExpression: (path) => {
|
|
126
|
+
if (!t__namespace.isIdentifier(path.node.callee)) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (!(path.node.callee.name === "createRoute" || path.node.callee.name === "createFileRoute")) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
function babelHandleReference(routeOptions) {
|
|
133
|
+
const hasImportedOrDefinedIdentifier = (name) => {
|
|
134
|
+
return programPath.scope.hasBinding(name);
|
|
135
|
+
};
|
|
136
|
+
if (t__namespace.isObjectExpression(routeOptions)) {
|
|
137
|
+
routeOptions.properties.forEach((prop) => {
|
|
138
|
+
if (t__namespace.isObjectProperty(prop)) {
|
|
139
|
+
if (t__namespace.isIdentifier(prop.key)) {
|
|
140
|
+
const codeSplitGroupingByKey = findIndexForSplitNode(
|
|
141
|
+
prop.key.name
|
|
142
|
+
);
|
|
143
|
+
if (codeSplitGroupingByKey === -1) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const codeSplitGroup = [
|
|
147
|
+
...new Set(
|
|
148
|
+
opts.codeSplitGroupings[codeSplitGroupingByKey]
|
|
149
|
+
)
|
|
150
|
+
];
|
|
151
|
+
const key = prop.key.name;
|
|
152
|
+
const isNodeConfigAvailable = SPLIT_NODES_CONFIG.has(
|
|
153
|
+
key
|
|
154
|
+
);
|
|
155
|
+
if (!isNodeConfigAvailable) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const splitNodeMeta = SPLIT_NODES_CONFIG.get(key);
|
|
159
|
+
const splitUrl = addSplitSearchParamToFilename(
|
|
160
|
+
opts.filename,
|
|
161
|
+
codeSplitGroup
|
|
162
|
+
);
|
|
163
|
+
if (splitNodeMeta.splitStrategy === "lazyRouteComponent") {
|
|
164
|
+
const value = prop.value;
|
|
165
|
+
let shouldSplit = true;
|
|
166
|
+
if (t__namespace.isIdentifier(value)) {
|
|
167
|
+
const existingImportPath = getImportSpecifierAndPathFromLocalName(
|
|
168
|
+
programPath,
|
|
169
|
+
value.name
|
|
170
|
+
).path;
|
|
171
|
+
if (existingImportPath) {
|
|
172
|
+
removableImportPaths.add(existingImportPath);
|
|
173
|
+
}
|
|
174
|
+
const isExported = hasExport(ast, value);
|
|
175
|
+
shouldSplit = !isExported;
|
|
176
|
+
if (shouldSplit) {
|
|
177
|
+
removeIdentifierLiteral(path, value);
|
|
178
|
+
}
|
|
151
179
|
}
|
|
152
|
-
|
|
153
|
-
...new Set(
|
|
154
|
-
opts.codeSplitGroupings[codeSplitGroupingByKey]
|
|
155
|
-
)
|
|
156
|
-
];
|
|
157
|
-
const key = prop.key.name;
|
|
158
|
-
const isNodeConfigAvailable = SPLIT_NODES_CONFIG.has(
|
|
159
|
-
key
|
|
160
|
-
);
|
|
161
|
-
if (!isNodeConfigAvailable) {
|
|
180
|
+
if (!shouldSplit) {
|
|
162
181
|
return;
|
|
163
182
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
)
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const value = prop.value;
|
|
173
|
-
let shouldSplit = true;
|
|
174
|
-
if (t__namespace.isIdentifier(value)) {
|
|
175
|
-
const existingImportPath = getImportSpecifierAndPathFromLocalName(
|
|
176
|
-
programPath,
|
|
177
|
-
value.name
|
|
178
|
-
).path;
|
|
179
|
-
if (existingImportPath) {
|
|
180
|
-
removableImportPaths.add(existingImportPath);
|
|
181
|
-
}
|
|
182
|
-
const isExported = hasExport(ast, value);
|
|
183
|
-
shouldSplit = !isExported;
|
|
184
|
-
if (shouldSplit) {
|
|
185
|
-
removeIdentifierLiteral(path, value);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
if (!shouldSplit) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
if (!hasImportedOrDefinedIdentifier(
|
|
192
|
-
LAZY_ROUTE_COMPONENT_IDENT
|
|
193
|
-
)) {
|
|
194
|
-
programPath.unshiftContainer("body", [
|
|
195
|
-
template__namespace.statement(
|
|
196
|
-
`import { ${LAZY_ROUTE_COMPONENT_IDENT} } from '${PACKAGE}'`
|
|
197
|
-
)()
|
|
198
|
-
]);
|
|
199
|
-
}
|
|
200
|
-
if (!hasImportedOrDefinedIdentifier(
|
|
201
|
-
splitNodeMeta.localImporterIdent
|
|
202
|
-
)) {
|
|
203
|
-
programPath.unshiftContainer("body", [
|
|
204
|
-
template__namespace.statement(
|
|
205
|
-
`const ${splitNodeMeta.localImporterIdent} = () => import('${splitUrl}')`
|
|
206
|
-
)()
|
|
207
|
-
]);
|
|
208
|
-
}
|
|
209
|
-
if (key === "component") {
|
|
210
|
-
prop.value = template__namespace.expression(
|
|
211
|
-
`${LAZY_ROUTE_COMPONENT_IDENT}(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}', () => Route.ssr)`
|
|
212
|
-
)();
|
|
213
|
-
} else {
|
|
214
|
-
prop.value = template__namespace.expression(
|
|
215
|
-
`${LAZY_ROUTE_COMPONENT_IDENT}(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}')`
|
|
216
|
-
)();
|
|
217
|
-
}
|
|
218
|
-
if (opts.runtimeEnv !== "prod" && // only in development
|
|
219
|
-
!hasImportedOrDefinedIdentifier(
|
|
220
|
-
frameworkOptions$1.idents.dummyHMRComponent
|
|
221
|
-
)) {
|
|
222
|
-
programPath.pushContainer("body", [
|
|
223
|
-
template__namespace.statement(
|
|
224
|
-
frameworkOptions$1.dummyHMRComponent
|
|
225
|
-
)()
|
|
226
|
-
]);
|
|
227
|
-
}
|
|
183
|
+
if (!hasImportedOrDefinedIdentifier(
|
|
184
|
+
LAZY_ROUTE_COMPONENT_IDENT
|
|
185
|
+
)) {
|
|
186
|
+
programPath.unshiftContainer("body", [
|
|
187
|
+
template__namespace.statement(
|
|
188
|
+
`import { ${LAZY_ROUTE_COMPONENT_IDENT} } from '${PACKAGE}'`
|
|
189
|
+
)()
|
|
190
|
+
]);
|
|
228
191
|
}
|
|
229
|
-
if (
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
const isExported = hasExport(ast, value);
|
|
241
|
-
shouldSplit = !isExported;
|
|
242
|
-
if (shouldSplit) {
|
|
243
|
-
removeIdentifierLiteral(path, value);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
if (!shouldSplit) {
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
if (!hasImportedOrDefinedIdentifier(LAZY_FN_IDENT)) {
|
|
250
|
-
programPath.unshiftContainer(
|
|
251
|
-
"body",
|
|
252
|
-
template__namespace.smart(
|
|
253
|
-
`import { ${LAZY_FN_IDENT} } from '${PACKAGE}'`
|
|
254
|
-
)()
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
if (!hasImportedOrDefinedIdentifier(
|
|
258
|
-
splitNodeMeta.localImporterIdent
|
|
259
|
-
)) {
|
|
260
|
-
programPath.unshiftContainer("body", [
|
|
261
|
-
template__namespace.statement(
|
|
262
|
-
`const ${splitNodeMeta.localImporterIdent} = () => import('${splitUrl}')`
|
|
263
|
-
)()
|
|
264
|
-
]);
|
|
265
|
-
}
|
|
192
|
+
if (!hasImportedOrDefinedIdentifier(
|
|
193
|
+
splitNodeMeta.localImporterIdent
|
|
194
|
+
)) {
|
|
195
|
+
programPath.unshiftContainer("body", [
|
|
196
|
+
template__namespace.statement(
|
|
197
|
+
`const ${splitNodeMeta.localImporterIdent} = () => import('${splitUrl}')`
|
|
198
|
+
)()
|
|
199
|
+
]);
|
|
200
|
+
}
|
|
201
|
+
if (key === "component") {
|
|
266
202
|
prop.value = template__namespace.expression(
|
|
267
|
-
`${
|
|
203
|
+
`${LAZY_ROUTE_COMPONENT_IDENT}(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}', () => Route.ssr)`
|
|
268
204
|
)();
|
|
205
|
+
} else {
|
|
206
|
+
prop.value = template__namespace.expression(
|
|
207
|
+
`${LAZY_ROUTE_COMPONENT_IDENT}(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}')`
|
|
208
|
+
)();
|
|
209
|
+
}
|
|
210
|
+
if (opts.runtimeEnv !== "prod") {
|
|
211
|
+
programPath.pushContainer("body", routeHmrStatement.routeHmrStatement);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (splitNodeMeta.splitStrategy === "lazyFn") {
|
|
215
|
+
const value = prop.value;
|
|
216
|
+
let shouldSplit = true;
|
|
217
|
+
if (t__namespace.isIdentifier(value)) {
|
|
218
|
+
const existingImportPath = getImportSpecifierAndPathFromLocalName(
|
|
219
|
+
programPath,
|
|
220
|
+
value.name
|
|
221
|
+
).path;
|
|
222
|
+
if (existingImportPath) {
|
|
223
|
+
removableImportPaths.add(existingImportPath);
|
|
224
|
+
}
|
|
225
|
+
const isExported = hasExport(ast, value);
|
|
226
|
+
shouldSplit = !isExported;
|
|
227
|
+
if (shouldSplit) {
|
|
228
|
+
removeIdentifierLiteral(path, value);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (!shouldSplit) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (!hasImportedOrDefinedIdentifier(LAZY_FN_IDENT)) {
|
|
235
|
+
programPath.unshiftContainer(
|
|
236
|
+
"body",
|
|
237
|
+
template__namespace.smart(
|
|
238
|
+
`import { ${LAZY_FN_IDENT} } from '${PACKAGE}'`
|
|
239
|
+
)()
|
|
240
|
+
);
|
|
269
241
|
}
|
|
242
|
+
if (!hasImportedOrDefinedIdentifier(
|
|
243
|
+
splitNodeMeta.localImporterIdent
|
|
244
|
+
)) {
|
|
245
|
+
programPath.unshiftContainer("body", [
|
|
246
|
+
template__namespace.statement(
|
|
247
|
+
`const ${splitNodeMeta.localImporterIdent} = () => import('${splitUrl}')`
|
|
248
|
+
)()
|
|
249
|
+
]);
|
|
250
|
+
}
|
|
251
|
+
prop.value = template__namespace.expression(
|
|
252
|
+
`${LAZY_FN_IDENT}(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}')`
|
|
253
|
+
)();
|
|
270
254
|
}
|
|
271
255
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
256
|
+
}
|
|
257
|
+
programPath.scope.crawl();
|
|
258
|
+
});
|
|
275
259
|
}
|
|
276
260
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
261
|
+
if (t__namespace.isCallExpression(path.parentPath.node)) {
|
|
262
|
+
const options = resolveIdentifier(
|
|
263
|
+
path,
|
|
264
|
+
path.parentPath.node.arguments[0]
|
|
265
|
+
);
|
|
266
|
+
babelHandleReference(options);
|
|
267
|
+
} else if (t__namespace.isVariableDeclarator(path.parentPath.node)) {
|
|
268
|
+
const caller = resolveIdentifier(path, path.parentPath.node.init);
|
|
269
|
+
if (t__namespace.isCallExpression(caller)) {
|
|
270
|
+
const options = resolveIdentifier(path, caller.arguments[0]);
|
|
271
|
+
babelHandleReference(options);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
});
|
|
280
276
|
if (removableImportPaths.size > 0) {
|
|
281
277
|
programPath.traverse({
|
|
282
278
|
ImportDeclaration(path) {
|
|
@@ -304,8 +300,7 @@ function compileCodeSplitVirtualRoute(opts) {
|
|
|
304
300
|
const knownExportedIdents = /* @__PURE__ */ new Set();
|
|
305
301
|
babel.traverse(ast, {
|
|
306
302
|
Program: {
|
|
307
|
-
enter(programPath
|
|
308
|
-
const state = programState;
|
|
303
|
+
enter(programPath) {
|
|
309
304
|
const trackedNodesToSplitByType = {
|
|
310
305
|
component: void 0,
|
|
311
306
|
loader: void 0,
|
|
@@ -313,54 +308,60 @@ function compileCodeSplitVirtualRoute(opts) {
|
|
|
313
308
|
errorComponent: void 0,
|
|
314
309
|
notFoundComponent: void 0
|
|
315
310
|
};
|
|
316
|
-
programPath.traverse(
|
|
317
|
-
{
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
if (t__namespace.
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
let isExported = false;
|
|
339
|
-
if (t__namespace.isIdentifier(value)) {
|
|
340
|
-
isExported = hasExport(ast, value);
|
|
341
|
-
if (isExported) {
|
|
342
|
-
knownExportedIdents.add(value.name);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
if (isExported && t__namespace.isIdentifier(value)) {
|
|
346
|
-
removeExports(ast, value);
|
|
347
|
-
} else {
|
|
348
|
-
const meta = SPLIT_NODES_CONFIG.get(splitType);
|
|
349
|
-
trackedNodesToSplitByType[splitType] = {
|
|
350
|
-
node: prop.value,
|
|
351
|
-
meta
|
|
352
|
-
};
|
|
311
|
+
programPath.traverse({
|
|
312
|
+
CallExpression: (path) => {
|
|
313
|
+
if (!t__namespace.isIdentifier(path.node.callee)) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
if (!(path.node.callee.name === "createRoute" || path.node.callee.name === "createFileRoute")) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
function babelHandleVirtual(options) {
|
|
320
|
+
if (t__namespace.isObjectExpression(options)) {
|
|
321
|
+
options.properties.forEach((prop) => {
|
|
322
|
+
if (t__namespace.isObjectProperty(prop)) {
|
|
323
|
+
KNOWN_SPLIT_ROUTE_IDENTS.forEach((splitType) => {
|
|
324
|
+
if (!t__namespace.isIdentifier(prop.key) || prop.key.name !== splitType) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const value = prop.value;
|
|
328
|
+
let isExported = false;
|
|
329
|
+
if (t__namespace.isIdentifier(value)) {
|
|
330
|
+
isExported = hasExport(ast, value);
|
|
331
|
+
if (isExported) {
|
|
332
|
+
knownExportedIdents.add(value.name);
|
|
353
333
|
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
334
|
+
}
|
|
335
|
+
if (isExported && t__namespace.isIdentifier(value)) {
|
|
336
|
+
removeExports(ast, value);
|
|
337
|
+
} else {
|
|
338
|
+
const meta = SPLIT_NODES_CONFIG.get(splitType);
|
|
339
|
+
trackedNodesToSplitByType[splitType] = {
|
|
340
|
+
node: prop.value,
|
|
341
|
+
meta
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
options.properties = [];
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (t__namespace.isCallExpression(path.parentPath.node)) {
|
|
351
|
+
const options = resolveIdentifier(
|
|
352
|
+
path,
|
|
353
|
+
path.parentPath.node.arguments[0]
|
|
354
|
+
);
|
|
355
|
+
babelHandleVirtual(options);
|
|
356
|
+
} else if (t__namespace.isVariableDeclarator(path.parentPath.node)) {
|
|
357
|
+
const caller = resolveIdentifier(path, path.parentPath.node.init);
|
|
358
|
+
if (t__namespace.isCallExpression(caller)) {
|
|
359
|
+
const options = resolveIdentifier(path, caller.arguments[0]);
|
|
360
|
+
babelHandleVirtual(options);
|
|
359
361
|
}
|
|
360
362
|
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
364
365
|
intendedSplitNodes.forEach((SPLIT_TYPE) => {
|
|
365
366
|
const splitKey = trackedNodesToSplitByType[SPLIT_TYPE];
|
|
366
367
|
if (!splitKey) {
|