@tanstack/start-plugin-core 1.169.12 → 1.169.14
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/esm/index.d.ts +1 -1
- package/dist/esm/rsbuild/index.d.ts +1 -0
- package/dist/esm/rsbuild/plugin.js +2 -0
- package/dist/esm/rsbuild/plugin.js.map +1 -1
- package/dist/esm/rsbuild/schema.d.ts +27 -27
- package/dist/esm/rsbuild/start-compiler-host.d.ts +3 -1
- package/dist/esm/rsbuild/start-compiler-host.js +6 -2
- package/dist/esm/rsbuild/start-compiler-host.js.map +1 -1
- package/dist/esm/rsbuild/start-router-plugin.d.ts +0 -2
- package/dist/esm/rsbuild/start-router-plugin.js +21 -24
- package/dist/esm/rsbuild/start-router-plugin.js.map +1 -1
- package/dist/esm/schema.d.ts +51 -51
- package/dist/esm/start-compiler/compiler.d.ts +21 -5
- package/dist/esm/start-compiler/compiler.js +197 -48
- package/dist/esm/start-compiler/compiler.js.map +1 -1
- package/dist/esm/start-compiler/config.d.ts +7 -3
- package/dist/esm/start-compiler/config.js +19 -7
- package/dist/esm/start-compiler/config.js.map +1 -1
- package/dist/esm/start-compiler/handleCreateServerFn.js +12 -0
- package/dist/esm/start-compiler/handleCreateServerFn.js.map +1 -1
- package/dist/esm/start-compiler/host.d.ts +3 -1
- package/dist/esm/start-compiler/host.js +5 -3
- package/dist/esm/start-compiler/host.js.map +1 -1
- package/dist/esm/start-compiler/types.d.ts +4 -13
- package/dist/esm/types.d.ts +33 -0
- package/dist/esm/vite/index.d.ts +1 -0
- package/dist/esm/vite/plugin.js +2 -0
- package/dist/esm/vite/plugin.js.map +1 -1
- package/dist/esm/vite/schema.d.ts +27 -27
- package/dist/esm/vite/start-compiler-plugin/plugin.d.ts +3 -1
- package/dist/esm/vite/start-compiler-plugin/plugin.js +6 -2
- package/dist/esm/vite/start-compiler-plugin/plugin.js.map +1 -1
- package/dist/esm/vite/start-router-plugin/plugin.js +5 -3
- package/dist/esm/vite/start-router-plugin/plugin.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +6 -1
- package/src/rsbuild/index.ts +5 -0
- package/src/rsbuild/plugin.ts +3 -0
- package/src/rsbuild/start-compiler-host.ts +22 -3
- package/src/rsbuild/start-router-plugin.ts +20 -21
- package/src/start-compiler/compiler.ts +389 -70
- package/src/start-compiler/config.ts +43 -6
- package/src/start-compiler/handleCreateServerFn.ts +29 -0
- package/src/start-compiler/host.ts +13 -3
- package/src/start-compiler/types.ts +5 -14
- package/src/types.ts +44 -0
- package/src/vite/index.ts +5 -0
- package/src/vite/plugin.ts +3 -0
- package/src/vite/start-compiler-plugin/plugin.ts +22 -3
- package/src/vite/start-router-plugin/plugin.ts +6 -3
|
@@ -10,9 +10,20 @@ import crypto from "node:crypto";
|
|
|
10
10
|
import babel from "@babel/core";
|
|
11
11
|
//#region src/start-compiler/compiler.ts
|
|
12
12
|
function isLookupKind(kind) {
|
|
13
|
-
return kind in
|
|
13
|
+
return kind in BuiltInLookupSetup || isExternalLookupKind(kind);
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
function getExternalLookupKind(transform) {
|
|
16
|
+
return `External:${transform.name}`;
|
|
17
|
+
}
|
|
18
|
+
function isExternalLookupKind(kind) {
|
|
19
|
+
return typeof kind === "string" && kind.startsWith("External:");
|
|
20
|
+
}
|
|
21
|
+
function isCompilerTransformEnabledForEnv(transform, env) {
|
|
22
|
+
if (!transform.environment) return true;
|
|
23
|
+
if (Array.isArray(transform.environment)) return transform.environment.includes(env);
|
|
24
|
+
return transform.environment === env;
|
|
25
|
+
}
|
|
26
|
+
var BuiltInLookupSetup = {
|
|
16
27
|
ServerFn: {
|
|
17
28
|
type: "methodChain",
|
|
18
29
|
candidateCallIdentifier: new Set(["handler"])
|
|
@@ -31,11 +42,11 @@ var LookupSetup = {
|
|
|
31
42
|
},
|
|
32
43
|
ServerOnlyFn: {
|
|
33
44
|
type: "directCall",
|
|
34
|
-
|
|
45
|
+
factoryNames: new Set(["createServerOnlyFn"])
|
|
35
46
|
},
|
|
36
47
|
ClientOnlyFn: {
|
|
37
48
|
type: "directCall",
|
|
38
|
-
|
|
49
|
+
factoryNames: new Set(["createClientOnlyFn"])
|
|
39
50
|
},
|
|
40
51
|
ClientOnlyJSX: {
|
|
41
52
|
type: "jsx",
|
|
@@ -66,31 +77,47 @@ var LookupKindsPerEnv = {
|
|
|
66
77
|
"ClientOnlyJSX"
|
|
67
78
|
])
|
|
68
79
|
};
|
|
80
|
+
function getLookupKindsForEnv(env, opts) {
|
|
81
|
+
const kinds = new Set(LookupKindsPerEnv[env]);
|
|
82
|
+
for (const transform of opts?.compilerTransforms ?? []) if (isCompilerTransformEnabledForEnv(transform, env)) kinds.add(getExternalLookupKind(transform));
|
|
83
|
+
return kinds;
|
|
84
|
+
}
|
|
69
85
|
/**
|
|
70
86
|
* Registry mapping each LookupKind to its handler function.
|
|
71
87
|
* When adding a new kind, add its handler here.
|
|
72
88
|
*/
|
|
73
|
-
var
|
|
89
|
+
var BuiltInKindHandlers = {
|
|
74
90
|
ServerFn: handleCreateServerFn,
|
|
75
91
|
Middleware: handleCreateMiddleware,
|
|
76
92
|
IsomorphicFn: handleCreateIsomorphicFn,
|
|
77
93
|
ServerOnlyFn: handleEnvOnlyFn,
|
|
78
94
|
ClientOnlyFn: handleEnvOnlyFn
|
|
79
95
|
};
|
|
80
|
-
var
|
|
96
|
+
var BuiltInKindHandlerOrder = [
|
|
97
|
+
"ServerFn",
|
|
98
|
+
"Middleware",
|
|
99
|
+
"IsomorphicFn",
|
|
100
|
+
"ServerOnlyFn",
|
|
101
|
+
"ClientOnlyFn"
|
|
102
|
+
];
|
|
103
|
+
var AllBuiltInLookupKinds = Object.keys(BuiltInLookupSetup);
|
|
81
104
|
/**
|
|
82
105
|
* Detects which LookupKinds are present in the code using string matching.
|
|
83
106
|
* This is a fast pre-scan before AST parsing to limit the work done during compilation.
|
|
84
107
|
*/
|
|
85
|
-
function detectKindsInCode(code, env) {
|
|
108
|
+
function detectKindsInCode(code, env, opts) {
|
|
86
109
|
const detected = /* @__PURE__ */ new Set();
|
|
87
|
-
const validForEnv =
|
|
88
|
-
for (const kind of
|
|
110
|
+
const validForEnv = getLookupKindsForEnv(env, opts);
|
|
111
|
+
for (const kind of AllBuiltInLookupKinds) if (validForEnv.has(kind) && KindDetectionPatterns[kind].test(code)) detected.add(kind);
|
|
112
|
+
for (const transform of opts?.compilerTransforms ?? []) {
|
|
113
|
+
if (!isCompilerTransformEnabledForEnv(transform, env)) continue;
|
|
114
|
+
if (transform.detect.test(code)) detected.add(getExternalLookupKind(transform));
|
|
115
|
+
}
|
|
89
116
|
return detected;
|
|
90
117
|
}
|
|
91
118
|
var IdentifierToKinds = /* @__PURE__ */ new Map();
|
|
92
|
-
for (const kind of
|
|
93
|
-
const setup =
|
|
119
|
+
for (const kind of AllBuiltInLookupKinds) {
|
|
120
|
+
const setup = BuiltInLookupSetup[kind];
|
|
94
121
|
if (setup.type === "methodChain") for (const id of setup.candidateCallIdentifier) {
|
|
95
122
|
let kinds = IdentifierToKinds.get(id);
|
|
96
123
|
if (!kinds) {
|
|
@@ -100,18 +127,9 @@ for (const kind of AllLookupKinds) {
|
|
|
100
127
|
kinds.add(kind);
|
|
101
128
|
}
|
|
102
129
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (setup.type === "directCall") DirectCallFactoryNames.add(setup.factoryName);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Computes whether any file kinds need direct-call candidate detection.
|
|
110
|
-
* This applies to directCall types (ServerOnlyFn, ClientOnlyFn).
|
|
111
|
-
*/
|
|
112
|
-
function needsDirectCallDetection(kinds) {
|
|
113
|
-
for (const kind of kinds) if (LookupSetup[kind].type === "directCall") return true;
|
|
114
|
-
return false;
|
|
130
|
+
function getLookupSetup(kind, externalLookupSetup) {
|
|
131
|
+
if (kind in BuiltInLookupSetup) return BuiltInLookupSetup[kind];
|
|
132
|
+
if (isExternalLookupKind(kind)) return externalLookupSetup?.get(kind);
|
|
115
133
|
}
|
|
116
134
|
/**
|
|
117
135
|
* Checks if all kinds in the set are guaranteed to be top-level only.
|
|
@@ -125,8 +143,8 @@ function areAllKindsTopLevelOnly(kinds) {
|
|
|
125
143
|
/**
|
|
126
144
|
* Checks if we need to detect JSX elements (e.g., <ClientOnly>).
|
|
127
145
|
*/
|
|
128
|
-
function needsJSXDetection(kinds) {
|
|
129
|
-
for (const kind of kinds) if (
|
|
146
|
+
function needsJSXDetection(kinds, externalLookupSetup) {
|
|
147
|
+
for (const kind of kinds) if (getLookupSetup(kind, externalLookupSetup)?.type === "jsx") return true;
|
|
130
148
|
return false;
|
|
131
149
|
}
|
|
132
150
|
/**
|
|
@@ -135,11 +153,17 @@ function needsJSXDetection(kinds) {
|
|
|
135
153
|
* This is stricter than top-level detection because we need to filter out
|
|
136
154
|
* invocations of existing server functions (e.g., `myServerFn()`).
|
|
137
155
|
*/
|
|
138
|
-
function isNestedDirectCallCandidate(node) {
|
|
156
|
+
function isNestedDirectCallCandidate(node, lookupKinds, externalLookupSetup) {
|
|
139
157
|
let calleeName;
|
|
140
158
|
if (t.isIdentifier(node.callee)) calleeName = node.callee.name;
|
|
141
159
|
else if (t.isMemberExpression(node.callee) && t.isIdentifier(node.callee.property)) calleeName = node.callee.property.name;
|
|
142
|
-
|
|
160
|
+
if (!calleeName) return false;
|
|
161
|
+
for (const kind of lookupKinds) {
|
|
162
|
+
if (isExternalLookupKind(kind)) continue;
|
|
163
|
+
const setup = getLookupSetup(kind, externalLookupSetup);
|
|
164
|
+
if (setup?.type === "directCall" && setup.factoryNames.has(calleeName)) return true;
|
|
165
|
+
}
|
|
166
|
+
return false;
|
|
143
167
|
}
|
|
144
168
|
function isSimpleDirectCallExpression(node) {
|
|
145
169
|
return t.isIdentifier(node.callee) || t.isMemberExpression(node.callee) && t.isIdentifier(node.callee.object) && t.isIdentifier(node.callee.property);
|
|
@@ -163,13 +187,43 @@ function isTopLevelDirectCallCandidate(path) {
|
|
|
163
187
|
if (!t.isVariableDeclaration(grandParent)) return false;
|
|
164
188
|
return t.isProgram(path.parentPath.parentPath?.parent);
|
|
165
189
|
}
|
|
166
|
-
function isDirectCallCandidateForKind(kind) {
|
|
167
|
-
return
|
|
190
|
+
function isDirectCallCandidateForKind(kind, externalLookupSetup) {
|
|
191
|
+
return getLookupSetup(kind, externalLookupSetup)?.type === "directCall";
|
|
192
|
+
}
|
|
193
|
+
function hasBuiltInDirectCallKinds(kinds) {
|
|
194
|
+
for (const kind of kinds) {
|
|
195
|
+
if (isExternalLookupKind(kind)) continue;
|
|
196
|
+
if (BuiltInLookupSetup[kind].type === "directCall") return true;
|
|
197
|
+
}
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
function hasExternalLookupKinds(kinds) {
|
|
201
|
+
for (const kind of kinds) if (isExternalLookupKind(kind)) return true;
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
function hasExternalDirectCallCandidates(candidates) {
|
|
205
|
+
return candidates.identifiers.size > 0 || candidates.namespaces.size > 0;
|
|
206
|
+
}
|
|
207
|
+
function getExternalDirectCallCandidateKind(path, candidates) {
|
|
208
|
+
const node = path.node;
|
|
209
|
+
if (t.isIdentifier(node.callee)) {
|
|
210
|
+
const kind = candidates.identifiers.get(node.callee.name);
|
|
211
|
+
if (!kind) return void 0;
|
|
212
|
+
return path.scope.getBinding(node.callee.name)?.path.isImportSpecifier() ? kind : void 0;
|
|
213
|
+
}
|
|
214
|
+
if (t.isMemberExpression(node.callee) && t.isIdentifier(node.callee.object) && t.isIdentifier(node.callee.property)) {
|
|
215
|
+
const kind = candidates.namespaces.get(node.callee.object.name)?.get(node.callee.property.name);
|
|
216
|
+
if (!kind) return void 0;
|
|
217
|
+
return path.scope.getBinding(node.callee.object.name)?.path.isImportNamespaceSpecifier() ? kind : void 0;
|
|
218
|
+
}
|
|
168
219
|
}
|
|
169
220
|
var StartCompiler = class {
|
|
170
221
|
moduleCache = /* @__PURE__ */ new Map();
|
|
171
222
|
initialized = false;
|
|
172
223
|
validLookupKinds;
|
|
224
|
+
externalTransformsByKind = /* @__PURE__ */ new Map();
|
|
225
|
+
externalLookupSetup = /* @__PURE__ */ new Map();
|
|
226
|
+
externalDirectCallKindsBySource = /* @__PURE__ */ new Map();
|
|
173
227
|
resolveIdCache = /* @__PURE__ */ new Map();
|
|
174
228
|
exportResolutionCache = /* @__PURE__ */ new Map();
|
|
175
229
|
knownRootImports = /* @__PURE__ */ new Map();
|
|
@@ -178,6 +232,25 @@ var StartCompiler = class {
|
|
|
178
232
|
constructor(options) {
|
|
179
233
|
this.options = options;
|
|
180
234
|
this.validLookupKinds = options.lookupKinds;
|
|
235
|
+
for (const transform of options.compilerTransforms ?? []) {
|
|
236
|
+
const kind = getExternalLookupKind(transform);
|
|
237
|
+
if (!this.validLookupKinds.has(kind)) continue;
|
|
238
|
+
this.externalTransformsByKind.set(kind, transform);
|
|
239
|
+
const factoryNames = /* @__PURE__ */ new Set();
|
|
240
|
+
for (const entry of transform.imports) {
|
|
241
|
+
factoryNames.add(entry.rootExport);
|
|
242
|
+
let rootExports = this.externalDirectCallKindsBySource.get(entry.libName);
|
|
243
|
+
if (!rootExports) {
|
|
244
|
+
rootExports = /* @__PURE__ */ new Map();
|
|
245
|
+
this.externalDirectCallKindsBySource.set(entry.libName, rootExports);
|
|
246
|
+
}
|
|
247
|
+
rootExports.set(entry.rootExport, kind);
|
|
248
|
+
}
|
|
249
|
+
this.externalLookupSetup.set(kind, {
|
|
250
|
+
type: "directCall",
|
|
251
|
+
factoryNames
|
|
252
|
+
});
|
|
253
|
+
}
|
|
181
254
|
}
|
|
182
255
|
/**
|
|
183
256
|
* Generates a unique function ID for a server function.
|
|
@@ -223,6 +296,31 @@ var StartCompiler = class {
|
|
|
223
296
|
get mode() {
|
|
224
297
|
return this.options.mode ?? "dev";
|
|
225
298
|
}
|
|
299
|
+
getExternalDirectCallCandidates(kinds, moduleInfo) {
|
|
300
|
+
const identifiers = /* @__PURE__ */ new Map();
|
|
301
|
+
const namespaces = /* @__PURE__ */ new Map();
|
|
302
|
+
if (this.externalDirectCallKindsBySource.size === 0) return {
|
|
303
|
+
identifiers,
|
|
304
|
+
namespaces
|
|
305
|
+
};
|
|
306
|
+
for (const [localName, binding] of moduleInfo.bindings) {
|
|
307
|
+
if (binding.type !== "import") continue;
|
|
308
|
+
const rootExports = this.externalDirectCallKindsBySource.get(binding.source);
|
|
309
|
+
if (!rootExports) continue;
|
|
310
|
+
if (binding.importedName === "*") {
|
|
311
|
+
const namespaceExports = /* @__PURE__ */ new Map();
|
|
312
|
+
for (const [rootExport, kind] of rootExports) if (kinds.has(kind)) namespaceExports.set(rootExport, kind);
|
|
313
|
+
if (namespaceExports.size > 0) namespaces.set(localName, namespaceExports);
|
|
314
|
+
} else {
|
|
315
|
+
const kind = rootExports.get(binding.importedName);
|
|
316
|
+
if (kind && kinds.has(kind)) identifiers.set(localName, kind);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return {
|
|
320
|
+
identifiers,
|
|
321
|
+
namespaces
|
|
322
|
+
};
|
|
323
|
+
}
|
|
226
324
|
async resolveIdCached(id, importer) {
|
|
227
325
|
if (this.mode === "dev") return this.options.resolveId(id, importer);
|
|
228
326
|
const cacheKey = importer ? `${importer}::${id}` : id;
|
|
@@ -259,7 +357,7 @@ var StartCompiler = class {
|
|
|
259
357
|
}
|
|
260
358
|
libExports.set(config.rootExport, config.kind);
|
|
261
359
|
if (config.kind !== "Root") {
|
|
262
|
-
if (
|
|
360
|
+
if (getLookupSetup(config.kind, this.externalLookupSetup)?.type === "jsx") continue;
|
|
263
361
|
}
|
|
264
362
|
const libId = config.libName;
|
|
265
363
|
let rootModule = this.moduleCache.get(libId);
|
|
@@ -422,7 +520,8 @@ var StartCompiler = class {
|
|
|
422
520
|
if (!this.initialized) await this.init();
|
|
423
521
|
const fileKinds = detectedKinds ? new Set([...detectedKinds].filter((k) => this.validLookupKinds.has(k))) : this.validLookupKinds;
|
|
424
522
|
if (fileKinds.size === 0) return null;
|
|
425
|
-
const
|
|
523
|
+
const hasExternalKinds = hasExternalLookupKinds(fileKinds);
|
|
524
|
+
const checkDirectCalls = hasBuiltInDirectCallKinds(fileKinds) || fileKinds.has("ServerFn") && !hasExternalKinds && hasBuiltInDirectCallKinds(this.validLookupKinds);
|
|
426
525
|
const canUseFastPath = areAllKindsTopLevelOnly(fileKinds);
|
|
427
526
|
const { ast } = this.ingestModule({
|
|
428
527
|
code,
|
|
@@ -431,8 +530,10 @@ var StartCompiler = class {
|
|
|
431
530
|
const candidatePaths = [];
|
|
432
531
|
const chainCallPaths = /* @__PURE__ */ new Map();
|
|
433
532
|
const jsxCandidatePaths = [];
|
|
434
|
-
const checkJSX = needsJSXDetection(fileKinds);
|
|
533
|
+
const checkJSX = needsJSXDetection(fileKinds, this.externalLookupSetup);
|
|
435
534
|
const moduleInfo = this.moduleCache.get(id);
|
|
535
|
+
const externalDirectCallCandidates = this.getExternalDirectCallCandidates(fileKinds, moduleInfo);
|
|
536
|
+
const checkExternalDirectCalls = hasExternalDirectCallCandidates(externalDirectCallCandidates);
|
|
436
537
|
if (canUseFastPath) {
|
|
437
538
|
const candidateIndices = [];
|
|
438
539
|
for (let i = 0; i < ast.program.body.length; i++) {
|
|
@@ -444,7 +545,7 @@ var StartCompiler = class {
|
|
|
444
545
|
}
|
|
445
546
|
if (declarations) {
|
|
446
547
|
for (const decl of declarations) if (decl.init && t.isCallExpression(decl.init)) {
|
|
447
|
-
if (isMethodChainCandidate(decl.init, fileKinds) || isTopLevelDirectCallCandidateNode(decl.init)) {
|
|
548
|
+
if (isMethodChainCandidate(decl.init, fileKinds) || checkDirectCalls && isTopLevelDirectCallCandidateNode(decl.init)) {
|
|
448
549
|
candidateIndices.push(i);
|
|
449
550
|
break;
|
|
450
551
|
}
|
|
@@ -465,10 +566,20 @@ var StartCompiler = class {
|
|
|
465
566
|
return;
|
|
466
567
|
}
|
|
467
568
|
if (isMethodChainCandidate(node, fileKinds)) {
|
|
468
|
-
candidatePaths.push(path);
|
|
569
|
+
candidatePaths.push({ path });
|
|
469
570
|
return;
|
|
470
571
|
}
|
|
471
|
-
if (
|
|
572
|
+
if (checkExternalDirectCalls) {
|
|
573
|
+
const kind = getExternalDirectCallCandidateKind(path, externalDirectCallCandidates);
|
|
574
|
+
if (kind) {
|
|
575
|
+
candidatePaths.push({
|
|
576
|
+
path,
|
|
577
|
+
kind
|
|
578
|
+
});
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
if (isTopLevelDirectCallCandidate(path)) candidatePaths.push({ path });
|
|
472
583
|
} });
|
|
473
584
|
}
|
|
474
585
|
programPath.stop();
|
|
@@ -482,15 +593,28 @@ var StartCompiler = class {
|
|
|
482
593
|
return;
|
|
483
594
|
}
|
|
484
595
|
if (isMethodChainCandidate(node, fileKinds)) {
|
|
485
|
-
candidatePaths.push(path);
|
|
596
|
+
candidatePaths.push({ path });
|
|
486
597
|
return;
|
|
487
598
|
}
|
|
488
|
-
if (
|
|
489
|
-
|
|
599
|
+
if (checkExternalDirectCalls) {
|
|
600
|
+
const kind = getExternalDirectCallCandidateKind(path, externalDirectCallCandidates);
|
|
601
|
+
if (kind) {
|
|
602
|
+
candidatePaths.push({
|
|
603
|
+
path,
|
|
604
|
+
kind
|
|
605
|
+
});
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
if (checkDirectCalls && isTopLevelDirectCallCandidate(path)) {
|
|
610
|
+
candidatePaths.push({ path });
|
|
490
611
|
return;
|
|
491
612
|
}
|
|
492
613
|
if (checkDirectCalls) {
|
|
493
|
-
if (isNestedDirectCallCandidate(node))
|
|
614
|
+
if (isNestedDirectCallCandidate(node, fileKinds, this.externalLookupSetup)) {
|
|
615
|
+
candidatePaths.push({ path });
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
494
618
|
}
|
|
495
619
|
},
|
|
496
620
|
JSXElement: (path) => {
|
|
@@ -507,12 +631,20 @@ var StartCompiler = class {
|
|
|
507
631
|
}
|
|
508
632
|
});
|
|
509
633
|
if (candidatePaths.length === 0 && jsxCandidatePaths.length === 0) return null;
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
634
|
+
const resolvedCandidates = [];
|
|
635
|
+
const unresolvedCandidates = [];
|
|
636
|
+
for (const candidate of candidatePaths) if (candidate.kind) resolvedCandidates.push({
|
|
637
|
+
path: candidate.path,
|
|
638
|
+
kind: candidate.kind
|
|
639
|
+
});
|
|
640
|
+
else unresolvedCandidates.push(candidate);
|
|
641
|
+
if (unresolvedCandidates.length > 0) resolvedCandidates.push(...await Promise.all(unresolvedCandidates.map(async (candidate) => ({
|
|
642
|
+
path: candidate.path,
|
|
643
|
+
kind: await this.resolveExprKind(candidate.path.node, id)
|
|
644
|
+
}))));
|
|
645
|
+
const validCandidates = resolvedCandidates.filter(({ path, kind }) => {
|
|
514
646
|
if (!this.validLookupKinds.has(kind)) return false;
|
|
515
|
-
if (isLookupKind(kind) && kind !== "ClientOnlyJSX" && !isMethodChainCandidate(path.node, fileKinds)) return isDirectCallCandidateForKind(kind);
|
|
647
|
+
if (isLookupKind(kind) && kind !== "ClientOnlyJSX" && !isMethodChainCandidate(path.node, fileKinds)) return isDirectCallCandidateForKind(kind, this.externalLookupSetup);
|
|
516
648
|
return true;
|
|
517
649
|
});
|
|
518
650
|
if (validCandidates.length === 0 && jsxCandidatePaths.length === 0) return null;
|
|
@@ -565,8 +697,11 @@ var StartCompiler = class {
|
|
|
565
697
|
root: this.options.root,
|
|
566
698
|
framework: this.options.framework,
|
|
567
699
|
providerEnvName: this.options.providerEnvName,
|
|
700
|
+
types: t,
|
|
701
|
+
parseExpression: (expressionCode) => babel.template.expression(expressionCode, { placeholderPattern: false })(),
|
|
568
702
|
generateFunctionId: (opts) => this.generateFunctionId(opts),
|
|
569
703
|
getKnownServerFns: this.options.getKnownServerFns,
|
|
704
|
+
serverFnProviderModuleDirectives: this.options.serverFnProviderModuleDirectives,
|
|
570
705
|
onServerFnsById: this.options.onServerFnsById
|
|
571
706
|
};
|
|
572
707
|
const candidatesByKind = /* @__PURE__ */ new Map();
|
|
@@ -579,10 +714,14 @@ var StartCompiler = class {
|
|
|
579
714
|
if (existing) existing.push(candidate);
|
|
580
715
|
else candidatesByKind.set(kind, [candidate]);
|
|
581
716
|
}
|
|
582
|
-
|
|
583
|
-
|
|
717
|
+
this.runExternalTransforms("pre", candidatesByKind, context);
|
|
718
|
+
for (const kind of BuiltInKindHandlerOrder) {
|
|
719
|
+
const candidates = candidatesByKind.get(kind);
|
|
720
|
+
if (!candidates) continue;
|
|
721
|
+
const handler = BuiltInKindHandlers[kind];
|
|
584
722
|
handler(candidates, context, kind);
|
|
585
723
|
}
|
|
724
|
+
this.runExternalTransforms("post", candidatesByKind, context);
|
|
586
725
|
for (const jsxPath of jsxCandidatePaths) handleClientOnlyJSX(jsxPath, { env: "server" });
|
|
587
726
|
deadCodeElimination(ast, refIdents);
|
|
588
727
|
const result = generateFromAst(ast, {
|
|
@@ -593,6 +732,14 @@ var StartCompiler = class {
|
|
|
593
732
|
if (result.map) result.map.sourcesContent = [code];
|
|
594
733
|
return result;
|
|
595
734
|
}
|
|
735
|
+
runExternalTransforms(order, candidatesByKind, context) {
|
|
736
|
+
for (const [kind, transform] of this.externalTransformsByKind) {
|
|
737
|
+
if ((transform.order ?? "pre") !== order) continue;
|
|
738
|
+
const candidates = candidatesByKind.get(kind);
|
|
739
|
+
if (!candidates) continue;
|
|
740
|
+
transform.transform(candidates, context);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
596
743
|
async resolveIdentifierKind(ident, id, visited = /* @__PURE__ */ new Set()) {
|
|
597
744
|
const binding = (await this.getModuleInfo(id)).bindings.get(ident);
|
|
598
745
|
if (!binding) return "None";
|
|
@@ -669,7 +816,7 @@ var StartCompiler = class {
|
|
|
669
816
|
return resolvedKind;
|
|
670
817
|
}
|
|
671
818
|
const resolvedKind = await this.resolveExprKind(binding.init, fileId, visited);
|
|
672
|
-
if (isLookupKind(resolvedKind) &&
|
|
819
|
+
if (isLookupKind(resolvedKind) && getLookupSetup(resolvedKind, this.externalLookupSetup)?.type === "directCall" && binding.init && t.isCallExpression(binding.init)) {
|
|
673
820
|
binding.resolvedKind = "None";
|
|
674
821
|
return "None";
|
|
675
822
|
}
|
|
@@ -715,6 +862,8 @@ var StartCompiler = class {
|
|
|
715
862
|
if (t.isIdentifier(callee.object)) {
|
|
716
863
|
const binding = (await this.getModuleInfo(fileId)).bindings.get(callee.object.name);
|
|
717
864
|
if (binding && binding.type === "import" && binding.importedName === "*") {
|
|
865
|
+
const knownKind = this.knownRootImports.get(binding.source)?.get(callee.property.name);
|
|
866
|
+
if (knownKind) return knownKind;
|
|
718
867
|
const targetModuleId = await this.resolveIdCached(binding.source, fileId);
|
|
719
868
|
if (targetModuleId) {
|
|
720
869
|
const targetModule = await this.getModuleInfo(targetModuleId);
|
|
@@ -753,6 +902,6 @@ function isMethodChainCandidate(node, lookupKinds) {
|
|
|
753
902
|
return false;
|
|
754
903
|
}
|
|
755
904
|
//#endregion
|
|
756
|
-
export { KindDetectionPatterns,
|
|
905
|
+
export { KindDetectionPatterns, StartCompiler, detectKindsInCode, getExternalLookupKind, getLookupKindsForEnv, isCompilerTransformEnabledForEnv };
|
|
757
906
|
|
|
758
907
|
//# sourceMappingURL=compiler.js.map
|