@bleedingdev/modern-js-code-tools 3.9.0-ultramodern.9 → 3.9.3-ultramodern.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/bin/modern-api-check-files.mjs +4 -1
- package/bin/modern-api-check.mjs +1 -1
- package/bin/modern-i18n-check.mjs +4 -0
- package/dist/cjs/cli/microvertical-api-check.cjs +36 -7
- package/dist/cjs/cli/workspace-source-check.cjs +90 -17
- package/dist/cjs/microvertical-api-baseline.cjs +81 -244
- package/dist/cjs/microvertical-api-boundary.cjs +352 -64
- package/dist/cjs/microvertical-api-owner.cjs +5 -2
- package/dist/cjs/module-graph.cjs +1862 -0
- package/dist/cjs/oxlint-plugin/rules/strict-effect-api-boundaries.cjs +1 -1
- package/dist/cjs/source-analysis.cjs +108 -0
- package/dist/cjs/strict-effect-runtime.cjs +75 -57
- package/dist/esm/cli/microvertical-api-check.js +26 -7
- package/dist/esm/cli/workspace-source-check.js +86 -13
- package/dist/esm/microvertical-api-baseline.js +66 -214
- package/dist/esm/microvertical-api-boundary.js +350 -65
- package/dist/esm/microvertical-api-owner.js +5 -2
- package/dist/esm/module-graph.js +1804 -0
- package/dist/esm/oxlint-plugin/rules/strict-effect-api-boundaries.js +1 -1
- package/dist/esm/source-analysis.js +48 -0
- package/dist/esm/strict-effect-runtime.js +75 -56
- package/dist/esm-node/cli/microvertical-api-check.js +26 -7
- package/dist/esm-node/cli/workspace-source-check.js +86 -13
- package/dist/esm-node/microvertical-api-baseline.js +66 -214
- package/dist/esm-node/microvertical-api-boundary.js +350 -65
- package/dist/esm-node/microvertical-api-owner.js +5 -2
- package/dist/esm-node/module-graph.js +1805 -0
- package/dist/esm-node/oxlint-plugin/rules/strict-effect-api-boundaries.js +1 -1
- package/dist/esm-node/source-analysis.js +49 -0
- package/dist/esm-node/strict-effect-runtime.js +75 -56
- package/dist/types/cli/microvertical-api-check.d.ts +1 -1
- package/dist/types/cli/workspace-source-check.d.ts +1 -1
- package/dist/types/microvertical-api-baseline.d.ts +0 -5
- package/dist/types/microvertical-api-boundary.d.ts +17 -2
- package/dist/types/microvertical-api-owner.d.ts +1 -1
- package/dist/types/module-graph.d.ts +100 -0
- package/dist/types/source-analysis.d.ts +13 -0
- package/package.json +17 -13
|
@@ -0,0 +1,1804 @@
|
|
|
1
|
+
import node_fs from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import node_path from "node:path";
|
|
4
|
+
import { exports as external_resolve_exports_exports } from "resolve.exports";
|
|
5
|
+
import { SourceSyntaxError, parseSource, traverseSource, unwrapExpression } from "./source-analysis.js";
|
|
6
|
+
import * as __rspack_external__babel_types_6e8337dd from "@babel/types";
|
|
7
|
+
const MAX_LOOKUPS = 4096;
|
|
8
|
+
const MAX_DEPTH = 192;
|
|
9
|
+
const MAX_ALIASES = 512;
|
|
10
|
+
const staticKey = (node)=>{
|
|
11
|
+
const key = 'property' in node ? node.property : node.key;
|
|
12
|
+
return !node.computed || __rspack_external__babel_types_6e8337dd.isStringLiteral(key) || __rspack_external__babel_types_6e8337dd.isNumericLiteral(key) ? propertyName(key) : void 0;
|
|
13
|
+
};
|
|
14
|
+
const writeTarget = (node)=>{
|
|
15
|
+
let names = [];
|
|
16
|
+
let dynamic = false;
|
|
17
|
+
let depth = 0;
|
|
18
|
+
let current = unwrapExpression(node, true);
|
|
19
|
+
while(__rspack_external__babel_types_6e8337dd.isMemberExpression(current) || __rspack_external__babel_types_6e8337dd.isOptionalMemberExpression(current)){
|
|
20
|
+
const name = staticKey(current);
|
|
21
|
+
depth += 1;
|
|
22
|
+
if (void 0 === name) {
|
|
23
|
+
names = [];
|
|
24
|
+
dynamic = true;
|
|
25
|
+
} else names.unshift(name);
|
|
26
|
+
current = unwrapExpression(current.object, true);
|
|
27
|
+
}
|
|
28
|
+
return __rspack_external__babel_types_6e8337dd.isIdentifier(current) ? {
|
|
29
|
+
root: current,
|
|
30
|
+
path: names,
|
|
31
|
+
dynamic,
|
|
32
|
+
depth
|
|
33
|
+
} : void 0;
|
|
34
|
+
};
|
|
35
|
+
const OPAQUE_RECEIVER = {};
|
|
36
|
+
const opaqueReceiver = (target, scope)=>{
|
|
37
|
+
let current = unwrapExpression(target, true);
|
|
38
|
+
if (!__rspack_external__babel_types_6e8337dd.isMemberExpression(current) && !__rspack_external__babel_types_6e8337dd.isOptionalMemberExpression(current)) return false;
|
|
39
|
+
let depth = 0;
|
|
40
|
+
while(__rspack_external__babel_types_6e8337dd.isMemberExpression(current) || __rspack_external__babel_types_6e8337dd.isOptionalMemberExpression(current)){
|
|
41
|
+
depth += 1;
|
|
42
|
+
current = unwrapExpression(current.object, true);
|
|
43
|
+
}
|
|
44
|
+
if (__rspack_external__babel_types_6e8337dd.isThisExpression(current)) {
|
|
45
|
+
if (depth > 1) return true;
|
|
46
|
+
let owner = scope.getFunctionParent();
|
|
47
|
+
while(owner && __rspack_external__babel_types_6e8337dd.isArrowFunctionExpression(owner.block))owner = owner.parent?.getFunctionParent() ?? null;
|
|
48
|
+
return !(__rspack_external__babel_types_6e8337dd.isClassMethod(owner?.block) && 'constructor' === owner.block.kind);
|
|
49
|
+
}
|
|
50
|
+
return !(__rspack_external__babel_types_6e8337dd.isIdentifier(current) || __rspack_external__babel_types_6e8337dd.isSuper(current));
|
|
51
|
+
};
|
|
52
|
+
const CONTAINER_EXTRACTORS = new Set([
|
|
53
|
+
'at',
|
|
54
|
+
'concat',
|
|
55
|
+
'copyWithin',
|
|
56
|
+
'entries',
|
|
57
|
+
'every',
|
|
58
|
+
'fill',
|
|
59
|
+
'filter',
|
|
60
|
+
'find',
|
|
61
|
+
'findIndex',
|
|
62
|
+
'findLast',
|
|
63
|
+
'findLastIndex',
|
|
64
|
+
'flat',
|
|
65
|
+
'flatMap',
|
|
66
|
+
'forEach',
|
|
67
|
+
'get',
|
|
68
|
+
'map',
|
|
69
|
+
'pop',
|
|
70
|
+
'reduce',
|
|
71
|
+
'reduceRight',
|
|
72
|
+
'reverse',
|
|
73
|
+
'shift',
|
|
74
|
+
'slice',
|
|
75
|
+
'some',
|
|
76
|
+
'sort',
|
|
77
|
+
'splice',
|
|
78
|
+
'toReversed',
|
|
79
|
+
'toSorted',
|
|
80
|
+
'toSpliced',
|
|
81
|
+
'values',
|
|
82
|
+
'with'
|
|
83
|
+
]);
|
|
84
|
+
const RECEIVER_RETURNING_METHODS = new Set([
|
|
85
|
+
'copyWithin',
|
|
86
|
+
'fill',
|
|
87
|
+
'reverse',
|
|
88
|
+
'sort',
|
|
89
|
+
'valueOf'
|
|
90
|
+
]);
|
|
91
|
+
const isModuleExports = (node)=>__rspack_external__babel_types_6e8337dd.isMemberExpression(node) && __rspack_external__babel_types_6e8337dd.isIdentifier(node.object, {
|
|
92
|
+
name: 'module'
|
|
93
|
+
}) && 'exports' === staticKey(node);
|
|
94
|
+
const readsModuleExports = (node)=>{
|
|
95
|
+
let current = unwrapExpression(node, true);
|
|
96
|
+
for(let hop = 0; hop < MAX_DEPTH; hop += 1){
|
|
97
|
+
if (isModuleExports(current)) return true;
|
|
98
|
+
if (!__rspack_external__babel_types_6e8337dd.isAssignmentExpression(current, {
|
|
99
|
+
operator: '='
|
|
100
|
+
})) break;
|
|
101
|
+
if (isModuleExports(current.left)) return true;
|
|
102
|
+
current = unwrapExpression(current.right, true);
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
};
|
|
106
|
+
const READ_ONLY_GLOBAL_CALLS = new Set([
|
|
107
|
+
'Object.assign',
|
|
108
|
+
'Object.defineProperties',
|
|
109
|
+
'Object.defineProperty',
|
|
110
|
+
'Object.setPrototypeOf',
|
|
111
|
+
'Reflect.defineProperty',
|
|
112
|
+
'Reflect.deleteProperty',
|
|
113
|
+
'Reflect.set',
|
|
114
|
+
'Reflect.setPrototypeOf',
|
|
115
|
+
'Array.isArray',
|
|
116
|
+
'Boolean',
|
|
117
|
+
'JSON.stringify',
|
|
118
|
+
'Number',
|
|
119
|
+
'Object.is',
|
|
120
|
+
'Object.isExtensible',
|
|
121
|
+
'Object.isFrozen',
|
|
122
|
+
'Object.isSealed',
|
|
123
|
+
'Object.keys',
|
|
124
|
+
'String'
|
|
125
|
+
]);
|
|
126
|
+
const STORING_GLOBAL_CALLS = new Map([
|
|
127
|
+
[
|
|
128
|
+
'Object.assign',
|
|
129
|
+
(depth)=>Math.max(depth, 1)
|
|
130
|
+
],
|
|
131
|
+
[
|
|
132
|
+
'Object.setPrototypeOf',
|
|
133
|
+
(depth)=>Math.max(depth, 1)
|
|
134
|
+
],
|
|
135
|
+
[
|
|
136
|
+
'Reflect.setPrototypeOf',
|
|
137
|
+
(depth)=>Math.max(depth, 1)
|
|
138
|
+
],
|
|
139
|
+
[
|
|
140
|
+
'Object.defineProperty',
|
|
141
|
+
(depth)=>Math.max(depth, 1)
|
|
142
|
+
],
|
|
143
|
+
[
|
|
144
|
+
'Reflect.defineProperty',
|
|
145
|
+
(depth)=>Math.max(depth, 1)
|
|
146
|
+
],
|
|
147
|
+
[
|
|
148
|
+
'Object.defineProperties',
|
|
149
|
+
()=>1
|
|
150
|
+
],
|
|
151
|
+
[
|
|
152
|
+
'Reflect.set',
|
|
153
|
+
(depth)=>depth + 1
|
|
154
|
+
]
|
|
155
|
+
]);
|
|
156
|
+
const DYNAMIC_SETTER = Symbol('dynamic setter');
|
|
157
|
+
const setterCache = new WeakMap();
|
|
158
|
+
const setterNames = (program)=>{
|
|
159
|
+
const cached = setterCache.get(program.node);
|
|
160
|
+
if (cached) return cached;
|
|
161
|
+
const names = new Set();
|
|
162
|
+
__rspack_external__babel_types_6e8337dd.traverseFast(program.node, (node)=>{
|
|
163
|
+
if ((__rspack_external__babel_types_6e8337dd.isObjectMethod(node) || __rspack_external__babel_types_6e8337dd.isClassMethod(node)) && 'set' === node.kind) names.add(staticKey(node) ?? DYNAMIC_SETTER);
|
|
164
|
+
});
|
|
165
|
+
setterCache.set(program.node, names);
|
|
166
|
+
return names;
|
|
167
|
+
};
|
|
168
|
+
const patternMembers = (pattern, from = [])=>__rspack_external__babel_types_6e8337dd.isMemberExpression(pattern) || __rspack_external__babel_types_6e8337dd.isOptionalMemberExpression(pattern) ? [
|
|
169
|
+
{
|
|
170
|
+
target: pattern,
|
|
171
|
+
from
|
|
172
|
+
}
|
|
173
|
+
] : __rspack_external__babel_types_6e8337dd.isObjectPattern(pattern) ? pattern.properties.flatMap((property)=>{
|
|
174
|
+
if (__rspack_external__babel_types_6e8337dd.isRestElement(property)) return patternMembers(property.argument, void 0);
|
|
175
|
+
const key = staticKey(property);
|
|
176
|
+
return patternMembers(property.value, from && void 0 !== key ? [
|
|
177
|
+
...from,
|
|
178
|
+
key
|
|
179
|
+
] : void 0);
|
|
180
|
+
}) : __rspack_external__babel_types_6e8337dd.isArrayPattern(pattern) ? pattern.elements.flatMap((element, index)=>element ? patternMembers(element, from && !__rspack_external__babel_types_6e8337dd.isRestElement(element) ? [
|
|
181
|
+
...from,
|
|
182
|
+
String(index)
|
|
183
|
+
] : void 0) : []) : __rspack_external__babel_types_6e8337dd.isRestElement(pattern) ? patternMembers(pattern.argument, void 0) : __rspack_external__babel_types_6e8337dd.isAssignmentPattern(pattern) ? patternMembers(pattern.left, void 0) : [];
|
|
184
|
+
function parseModule(filePath, workspace) {
|
|
185
|
+
if (node_fs.statSync(filePath).size > 1000000) throw new Error(`${filePath}: consumer source exceeds 1 MB analysis budget`);
|
|
186
|
+
const file = parseSource(node_fs.readFileSync(filePath, 'utf8'), filePath);
|
|
187
|
+
let scope;
|
|
188
|
+
const references = new Map();
|
|
189
|
+
const declarations = new Map();
|
|
190
|
+
const returns = new Map();
|
|
191
|
+
const bareReturns = new Set();
|
|
192
|
+
const functionScopes = new Map();
|
|
193
|
+
const writes = new Map();
|
|
194
|
+
const merged = new Set();
|
|
195
|
+
const mutations = [];
|
|
196
|
+
const commonJs = [];
|
|
197
|
+
let exportsDetachedAt;
|
|
198
|
+
const assertAssignable = (binding, at)=>{
|
|
199
|
+
if (binding?.kind === 'const' || binding?.kind === 'module') throw new SourceSyntaxError(`${'module' === binding.kind ? 'imports' : 'const bindings'} must not be reassigned at ${at.start}`);
|
|
200
|
+
};
|
|
201
|
+
const recordWrite = (scopeOf, target, node, value, from)=>{
|
|
202
|
+
const member = writeTarget(target);
|
|
203
|
+
if (!member) {
|
|
204
|
+
if (opaqueReceiver(target, scopeOf)) writes.set(OPAQUE_RECEIVER, [
|
|
205
|
+
...writes.get(OPAQUE_RECEIVER) ?? [],
|
|
206
|
+
{
|
|
207
|
+
path: [],
|
|
208
|
+
dynamic: true,
|
|
209
|
+
depth: 0,
|
|
210
|
+
value,
|
|
211
|
+
from,
|
|
212
|
+
node
|
|
213
|
+
}
|
|
214
|
+
]);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
let root = member;
|
|
218
|
+
let through = [];
|
|
219
|
+
for(let hop = 0; hop < MAX_DEPTH; hop += 1){
|
|
220
|
+
const alias = scopeOf.getBinding(root.root.name);
|
|
221
|
+
const init = alias?.kind === 'const' && __rspack_external__babel_types_6e8337dd.isVariableDeclarator(alias.path.node) ? alias.path.node.init : void 0;
|
|
222
|
+
const next = init ? writeTarget(init) : void 0;
|
|
223
|
+
if (!next || next.dynamic) break;
|
|
224
|
+
through = [
|
|
225
|
+
...root.path,
|
|
226
|
+
...through
|
|
227
|
+
];
|
|
228
|
+
root = next;
|
|
229
|
+
}
|
|
230
|
+
const exported = 'module' === root.root.name && 'exports' === root.path[0] ? [
|
|
231
|
+
...root.path.slice(1),
|
|
232
|
+
...through
|
|
233
|
+
] : 'exports' === root.root.name ? [
|
|
234
|
+
...root.path,
|
|
235
|
+
...through
|
|
236
|
+
] : void 0;
|
|
237
|
+
const detached = 'exports' === root.root.name && (root.path.length + through.length === 0 || void 0 !== exportsDetachedAt && (node.start ?? 0) >= exportsDetachedAt);
|
|
238
|
+
if (exported && !detached && !scopeOf.getBinding(root.root.name)) commonJs.push({
|
|
239
|
+
path: exported,
|
|
240
|
+
dynamic: member.dynamic,
|
|
241
|
+
depth: member.depth,
|
|
242
|
+
value,
|
|
243
|
+
from,
|
|
244
|
+
node
|
|
245
|
+
});
|
|
246
|
+
const binding = member.dynamic || member.path.length > 0 ? scopeOf.getBinding(member.root.name) : void 0;
|
|
247
|
+
if (!binding) return;
|
|
248
|
+
writes.set(binding, [
|
|
249
|
+
...writes.get(binding) ?? [],
|
|
250
|
+
{
|
|
251
|
+
path: member.path,
|
|
252
|
+
dynamic: member.dynamic,
|
|
253
|
+
depth: member.depth,
|
|
254
|
+
value,
|
|
255
|
+
from,
|
|
256
|
+
node
|
|
257
|
+
}
|
|
258
|
+
]);
|
|
259
|
+
};
|
|
260
|
+
const indexBuiltInMutation = (p)=>{
|
|
261
|
+
const callee = unwrapExpression(p.node.callee, true);
|
|
262
|
+
const memberCallee = __rspack_external__babel_types_6e8337dd.isMemberExpression(callee) || __rspack_external__babel_types_6e8337dd.isOptionalMemberExpression(callee) ? callee : void 0;
|
|
263
|
+
const owner = memberCallee && __rspack_external__babel_types_6e8337dd.isIdentifier(memberCallee.object) ? memberCallee.object.name : void 0;
|
|
264
|
+
const method = memberCallee ? staticKey(memberCallee) : void 0;
|
|
265
|
+
const [target, ...rest] = p.node.arguments;
|
|
266
|
+
if (!owner || !method || !target || !__rspack_external__babel_types_6e8337dd.isExpression(target) || p.scope.getBinding(owner) || !('Object' === owner && [
|
|
267
|
+
'assign',
|
|
268
|
+
'defineProperty',
|
|
269
|
+
'defineProperties',
|
|
270
|
+
'setPrototypeOf'
|
|
271
|
+
].includes(method) || 'Reflect' === owner && [
|
|
272
|
+
'set',
|
|
273
|
+
'defineProperty',
|
|
274
|
+
'deleteProperty',
|
|
275
|
+
'setPrototypeOf'
|
|
276
|
+
].includes(method))) return;
|
|
277
|
+
mutations.push(p.node);
|
|
278
|
+
const anyMember = __rspack_external__babel_types_6e8337dd.memberExpression(target, __rspack_external__babel_types_6e8337dd.identifier('key'), true);
|
|
279
|
+
const sources = 'assign' === method ? rest : [
|
|
280
|
+
void 0
|
|
281
|
+
];
|
|
282
|
+
for (const source of sources){
|
|
283
|
+
if (!__rspack_external__babel_types_6e8337dd.isObjectExpression(source)) {
|
|
284
|
+
recordWrite(p.scope, anyMember, p.node);
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
for (const property of source.properties){
|
|
288
|
+
const key = __rspack_external__babel_types_6e8337dd.isObjectProperty(property) ? staticKey(property) : void 0;
|
|
289
|
+
void 0 !== key && __rspack_external__babel_types_6e8337dd.isObjectProperty(property) ? recordWrite(p.scope, __rspack_external__babel_types_6e8337dd.memberExpression(target, __rspack_external__babel_types_6e8337dd.stringLiteral(key), true), p.node, property.value) : recordWrite(p.scope, anyMember, p.node);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
traverseSource(file, {
|
|
294
|
+
Program (p) {
|
|
295
|
+
scope = p.scope;
|
|
296
|
+
},
|
|
297
|
+
ReferencedIdentifier (p) {
|
|
298
|
+
references.set(p.node, p.scope.getBinding(p.node.name));
|
|
299
|
+
},
|
|
300
|
+
BindingIdentifier (p) {
|
|
301
|
+
if (!__rspack_external__babel_types_6e8337dd.isIdentifier(p.node)) return;
|
|
302
|
+
const binding = p.scope.getBinding(p.node.name);
|
|
303
|
+
if (binding?.identifier === p.node) declarations.set(p.node, binding);
|
|
304
|
+
},
|
|
305
|
+
Function (p) {
|
|
306
|
+
functionScopes.set(p.node, p.scope);
|
|
307
|
+
},
|
|
308
|
+
ReturnStatement (p) {
|
|
309
|
+
const owner = p.getFunctionParent();
|
|
310
|
+
if (!owner) return;
|
|
311
|
+
if (p.node.argument) returns.set(owner.node, [
|
|
312
|
+
...returns.get(owner.node) ?? [],
|
|
313
|
+
p.node.argument
|
|
314
|
+
]);
|
|
315
|
+
else bareReturns.add(owner.node);
|
|
316
|
+
},
|
|
317
|
+
AssignmentExpression (p) {
|
|
318
|
+
mutations.push(p.node);
|
|
319
|
+
const stored = [
|
|
320
|
+
'=',
|
|
321
|
+
'&&=',
|
|
322
|
+
'||=',
|
|
323
|
+
'??='
|
|
324
|
+
].includes(p.node.operator) ? p.node.right : void 0;
|
|
325
|
+
for (const name of Object.keys(__rspack_external__babel_types_6e8337dd.getBindingIdentifiers(p.node.left)))assertAssignable(p.scope.getBinding(name), p.node);
|
|
326
|
+
if (__rspack_external__babel_types_6e8337dd.isPattern(p.node.left)) for (const { target, from } of patternMembers(p.node.left))recordWrite(p.scope, target, p.node, from && '=' === p.node.operator ? p.node.right : void 0, from);
|
|
327
|
+
else recordWrite(p.scope, p.node.left, p.node, stored);
|
|
328
|
+
if ('=' === p.node.operator && __rspack_external__babel_types_6e8337dd.isIdentifier(p.node.left, {
|
|
329
|
+
name: 'exports'
|
|
330
|
+
}) && !p.scope.getBinding('exports') && p.parentPath.isExpressionStatement() && p.parentPath.parentPath?.isProgram()) exportsDetachedAt = readsModuleExports(p.node.right) ? void 0 : exportsDetachedAt ?? p.node.end ?? void 0;
|
|
331
|
+
else if (void 0 === exportsDetachedAt && '=' === p.node.operator && __rspack_external__babel_types_6e8337dd.isMemberExpression(p.node.left) && __rspack_external__babel_types_6e8337dd.isIdentifier(p.node.left.object, {
|
|
332
|
+
name: 'module'
|
|
333
|
+
}) && 'exports' === staticKey(p.node.left) && !p.scope.getBinding('module') && !(__rspack_external__babel_types_6e8337dd.isAssignmentExpression(p.node.right) && __rspack_external__babel_types_6e8337dd.isIdentifier(p.node.right.left, {
|
|
334
|
+
name: 'exports'
|
|
335
|
+
})) && p.parentPath.isExpressionStatement() && p.parentPath.parentPath?.isProgram()) exportsDetachedAt = p.node.end ?? void 0;
|
|
336
|
+
},
|
|
337
|
+
ForXStatement (p) {
|
|
338
|
+
const left = p.node.left;
|
|
339
|
+
if (__rspack_external__babel_types_6e8337dd.isVariableDeclaration(left)) return;
|
|
340
|
+
mutations.push(p.node);
|
|
341
|
+
for (const { target } of patternMembers(left))recordWrite(p.scope, target, p.node);
|
|
342
|
+
},
|
|
343
|
+
CallExpression (p) {
|
|
344
|
+
indexBuiltInMutation(p);
|
|
345
|
+
},
|
|
346
|
+
OptionalCallExpression (p) {
|
|
347
|
+
indexBuiltInMutation(p);
|
|
348
|
+
},
|
|
349
|
+
UnaryExpression (p) {
|
|
350
|
+
if ('delete' !== p.node.operator) return;
|
|
351
|
+
mutations.push(p.node);
|
|
352
|
+
recordWrite(p.scope, p.node.argument, p.node);
|
|
353
|
+
},
|
|
354
|
+
UpdateExpression (p) {
|
|
355
|
+
mutations.push(p.node);
|
|
356
|
+
if (__rspack_external__babel_types_6e8337dd.isIdentifier(p.node.argument)) assertAssignable(p.scope.getBinding(p.node.argument.name), p.node);
|
|
357
|
+
recordWrite(p.scope, p.node.argument, p.node);
|
|
358
|
+
},
|
|
359
|
+
TSModuleDeclaration (p) {
|
|
360
|
+
if (!__rspack_external__babel_types_6e8337dd.isIdentifier(p.node.id)) return;
|
|
361
|
+
merged.add(p.node.id.name);
|
|
362
|
+
mutations.push(p.node);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
if (!scope) throw new Error(`${filePath}: program scope missing`);
|
|
366
|
+
const facts = {
|
|
367
|
+
scope,
|
|
368
|
+
workspace,
|
|
369
|
+
references,
|
|
370
|
+
declarations,
|
|
371
|
+
returns,
|
|
372
|
+
bareReturns,
|
|
373
|
+
functionScopes,
|
|
374
|
+
writes,
|
|
375
|
+
merged,
|
|
376
|
+
commonJs
|
|
377
|
+
};
|
|
378
|
+
return {
|
|
379
|
+
file,
|
|
380
|
+
facts,
|
|
381
|
+
mutations
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
const propertyName = (node)=>{
|
|
385
|
+
if (void 0 !== node && (__rspack_external__babel_types_6e8337dd.isIdentifier(node) || __rspack_external__babel_types_6e8337dd.isStringLiteral(node) || __rspack_external__babel_types_6e8337dd.isNumericLiteral(node))) return __rspack_external__babel_types_6e8337dd.isIdentifier(node) ? node.name : String(node.value);
|
|
386
|
+
};
|
|
387
|
+
const localConst = (sourceFile, name)=>{
|
|
388
|
+
for (const item of sourceFile.program.body){
|
|
389
|
+
const statement = __rspack_external__babel_types_6e8337dd.isExportNamedDeclaration(item) ? item.declaration : item;
|
|
390
|
+
if (!__rspack_external__babel_types_6e8337dd.isVariableDeclaration(statement) || 'const' !== statement.kind) continue;
|
|
391
|
+
const matches = statement.declarations.filter((declaration)=>__rspack_external__babel_types_6e8337dd.isIdentifier(declaration.id, {
|
|
392
|
+
name
|
|
393
|
+
}));
|
|
394
|
+
if (1 === matches.length) return matches[0];
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
const exportedConst = (sourceFile, name)=>{
|
|
398
|
+
for (const statement of sourceFile.program.body)if (__rspack_external__babel_types_6e8337dd.isExportNamedDeclaration(statement) && 'type' !== statement.exportKind) {
|
|
399
|
+
if (__rspack_external__babel_types_6e8337dd.isVariableDeclaration(statement.declaration) && 'const' === statement.declaration.kind) {
|
|
400
|
+
const declaration = statement.declaration.declarations.find((value)=>__rspack_external__babel_types_6e8337dd.isIdentifier(value.id, {
|
|
401
|
+
name
|
|
402
|
+
}));
|
|
403
|
+
if (declaration) return declaration;
|
|
404
|
+
}
|
|
405
|
+
if (!statement.source && statement.specifiers.some((value)=>__rspack_external__babel_types_6e8337dd.isExportSpecifier(value) && 'type' !== value.exportKind && __rspack_external__babel_types_6e8337dd.isIdentifier(value.local, {
|
|
406
|
+
name
|
|
407
|
+
}) && __rspack_external__babel_types_6e8337dd.isIdentifier(value.exported, {
|
|
408
|
+
name
|
|
409
|
+
}))) return localConst(sourceFile, name);
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
const inside = (file, boundary)=>file === boundary || file.startsWith(`${boundary}${node_path.sep}`);
|
|
413
|
+
const containingWorkspace = (file)=>{
|
|
414
|
+
for(let directory = node_path.dirname(file);; directory = node_path.dirname(directory)){
|
|
415
|
+
if (node_fs.existsSync(node_path.join(directory, 'pnpm-workspace.yaml'))) return node_fs.realpathSync(directory);
|
|
416
|
+
if (directory === node_path.dirname(directory)) return;
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
const sourceBoundary = (file, workspace)=>{
|
|
420
|
+
for(let directory = node_path.dirname(file);; directory = node_path.dirname(directory)){
|
|
421
|
+
if (node_fs.existsSync(node_path.join(directory, 'package.json')) && directory !== workspace) return node_fs.realpathSync(directory);
|
|
422
|
+
if (directory === workspace || directory === node_path.dirname(directory)) return node_fs.realpathSync(node_path.dirname(file));
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
const sourceFileAt = (target, boundary)=>{
|
|
426
|
+
const stem = target.replace(/\.(?:[cm]?[jt]sx?)$/u, '');
|
|
427
|
+
for (const candidate of [
|
|
428
|
+
`${stem}.ts`,
|
|
429
|
+
`${stem}.tsx`,
|
|
430
|
+
`${stem}.mts`,
|
|
431
|
+
`${stem}.cts`,
|
|
432
|
+
target,
|
|
433
|
+
`${stem}.js`,
|
|
434
|
+
`${stem}.jsx`,
|
|
435
|
+
`${stem}.mjs`,
|
|
436
|
+
`${stem}.cjs`,
|
|
437
|
+
node_path.join(target, 'index.ts'),
|
|
438
|
+
node_path.join(target, 'index.tsx'),
|
|
439
|
+
node_path.join(target, 'index.mts'),
|
|
440
|
+
node_path.join(target, 'index.cts'),
|
|
441
|
+
node_path.join(target, 'index.js'),
|
|
442
|
+
node_path.join(target, 'index.jsx'),
|
|
443
|
+
node_path.join(target, 'index.mjs'),
|
|
444
|
+
node_path.join(target, 'index.cjs')
|
|
445
|
+
])try {
|
|
446
|
+
const real = node_fs.realpathSync(candidate);
|
|
447
|
+
if (inside(real, boundary) && node_fs.statSync(real).isFile()) return real;
|
|
448
|
+
} catch {}
|
|
449
|
+
};
|
|
450
|
+
const packageEntry = (specifier)=>{
|
|
451
|
+
if (specifier.startsWith('.') || specifier.startsWith('/') || specifier.startsWith('#')) return;
|
|
452
|
+
const parts = specifier.split('/');
|
|
453
|
+
const count = specifier.startsWith('@') ? 2 : 1;
|
|
454
|
+
if (parts.length < count || parts.slice(0, count).some((part)=>!part)) return;
|
|
455
|
+
return {
|
|
456
|
+
name: parts.slice(0, count).join('/'),
|
|
457
|
+
exportKey: parts.length === count ? '.' : `./${parts.slice(count).join('/')}`
|
|
458
|
+
};
|
|
459
|
+
};
|
|
460
|
+
const resolveModulePath = (module, specifier, workspace)=>{
|
|
461
|
+
if (/^\.\.?\//u.test(specifier)) {
|
|
462
|
+
const file = sourceFileAt(node_path.resolve(node_path.dirname(module.path), specifier), module.boundary);
|
|
463
|
+
return void 0 === file ? void 0 : {
|
|
464
|
+
kind: 'module',
|
|
465
|
+
path: file,
|
|
466
|
+
boundary: module.boundary
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
const entry = packageEntry(specifier);
|
|
470
|
+
if (!entry) return;
|
|
471
|
+
if (!workspace) return {
|
|
472
|
+
kind: 'external'
|
|
473
|
+
};
|
|
474
|
+
const paths = createRequire(module.path).resolve.paths(entry.name) ?? [];
|
|
475
|
+
for (const lookup of paths){
|
|
476
|
+
const directory = node_path.join(lookup, entry.name);
|
|
477
|
+
const manifest = node_path.join(directory, 'package.json');
|
|
478
|
+
if (!node_fs.existsSync(manifest)) continue;
|
|
479
|
+
const boundary = node_fs.realpathSync(directory);
|
|
480
|
+
if (!inside(boundary, workspace) || boundary.split(node_path.sep).includes('node_modules')) break;
|
|
481
|
+
const pkg = JSON.parse(node_fs.readFileSync(manifest, 'utf8'));
|
|
482
|
+
if (pkg.name !== entry.name || void 0 === pkg.exports) return;
|
|
483
|
+
let target;
|
|
484
|
+
try {
|
|
485
|
+
const targets = external_resolve_exports_exports({
|
|
486
|
+
...pkg,
|
|
487
|
+
exports: selectExportPattern(pkg.exports, entry.exportKey)
|
|
488
|
+
}, entry.exportKey, {
|
|
489
|
+
conditions: [
|
|
490
|
+
'modern:source'
|
|
491
|
+
]
|
|
492
|
+
});
|
|
493
|
+
target = Array.isArray(targets) ? targets[0] : void 0;
|
|
494
|
+
} catch {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
if (!target || !target.startsWith('./')) return;
|
|
498
|
+
const file = sourceFileAt(node_path.resolve(boundary, target), boundary);
|
|
499
|
+
return void 0 === file ? void 0 : {
|
|
500
|
+
kind: 'module',
|
|
501
|
+
path: file,
|
|
502
|
+
boundary
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
return {
|
|
506
|
+
kind: 'external'
|
|
507
|
+
};
|
|
508
|
+
};
|
|
509
|
+
const patternKeyCompare = (a, b)=>{
|
|
510
|
+
const aBase = a.indexOf('*') + 1;
|
|
511
|
+
const bBase = b.indexOf('*') + 1;
|
|
512
|
+
if (aBase !== bBase) return bBase - aBase;
|
|
513
|
+
return b.length - a.length;
|
|
514
|
+
};
|
|
515
|
+
const selectExportPattern = (exports, key)=>{
|
|
516
|
+
if ('object' != typeof exports || null === exports || Array.isArray(exports)) return exports;
|
|
517
|
+
const subpaths = exports;
|
|
518
|
+
const keys = Object.keys(subpaths);
|
|
519
|
+
if (!keys.every((candidate)=>candidate.startsWith('.')) || key in subpaths) return exports;
|
|
520
|
+
let best;
|
|
521
|
+
for (const candidate of keys){
|
|
522
|
+
const star = candidate.indexOf('*');
|
|
523
|
+
if (-1 === star || -1 !== candidate.indexOf('*', star + 1)) continue;
|
|
524
|
+
const prefix = candidate.slice(0, star);
|
|
525
|
+
const suffix = candidate.slice(star + 1);
|
|
526
|
+
if (key.startsWith(prefix) && key !== prefix && key.endsWith(suffix) && key.length >= candidate.length && (void 0 === best || patternKeyCompare(candidate, best) < 0)) best = candidate;
|
|
527
|
+
}
|
|
528
|
+
return void 0 === best ? exports : {
|
|
529
|
+
[best]: subpaths[best]
|
|
530
|
+
};
|
|
531
|
+
};
|
|
532
|
+
const exportHop = (file, name)=>{
|
|
533
|
+
for (const statement of file.program.body){
|
|
534
|
+
if (__rspack_external__babel_types_6e8337dd.isExportDefaultDeclaration(statement)) {
|
|
535
|
+
if ('default' !== name) continue;
|
|
536
|
+
const declaration = statement.declaration;
|
|
537
|
+
if (__rspack_external__babel_types_6e8337dd.isIdentifier(declaration)) return {
|
|
538
|
+
kind: 'local',
|
|
539
|
+
name: declaration.name
|
|
540
|
+
};
|
|
541
|
+
if ((__rspack_external__babel_types_6e8337dd.isFunctionDeclaration(declaration) || __rspack_external__babel_types_6e8337dd.isClassDeclaration(declaration)) && declaration.id) return {
|
|
542
|
+
kind: 'local',
|
|
543
|
+
name: declaration.id.name
|
|
544
|
+
};
|
|
545
|
+
return {
|
|
546
|
+
kind: 'node',
|
|
547
|
+
node: declaration
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
if (!__rspack_external__babel_types_6e8337dd.isExportNamedDeclaration(statement) || 'type' === statement.exportKind) continue;
|
|
551
|
+
const declaration = statement.declaration;
|
|
552
|
+
if ((__rspack_external__babel_types_6e8337dd.isVariableDeclaration(declaration) || __rspack_external__babel_types_6e8337dd.isFunctionDeclaration(declaration) || __rspack_external__babel_types_6e8337dd.isClassDeclaration(declaration)) && !declaration.declare && name in __rspack_external__babel_types_6e8337dd.getBindingIdentifiers(declaration)) return {
|
|
553
|
+
kind: 'local',
|
|
554
|
+
name
|
|
555
|
+
};
|
|
556
|
+
for (const specifier of statement.specifiers){
|
|
557
|
+
if (propertyName(specifier.exported) !== name) continue;
|
|
558
|
+
if (__rspack_external__babel_types_6e8337dd.isExportNamespaceSpecifier(specifier) && statement.source) return {
|
|
559
|
+
kind: 'namespace',
|
|
560
|
+
specifier: statement.source.value
|
|
561
|
+
};
|
|
562
|
+
if (!__rspack_external__babel_types_6e8337dd.isExportSpecifier(specifier) || 'type' === specifier.exportKind) continue;
|
|
563
|
+
const local = propertyName(specifier.local) ?? name;
|
|
564
|
+
return statement.source ? {
|
|
565
|
+
kind: 'reexport',
|
|
566
|
+
specifier: statement.source.value,
|
|
567
|
+
name: local
|
|
568
|
+
} : {
|
|
569
|
+
kind: 'local',
|
|
570
|
+
name: local
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
const exportNames = (file)=>file.program.body.flatMap((statement)=>{
|
|
576
|
+
if (__rspack_external__babel_types_6e8337dd.isExportDefaultDeclaration(statement)) return [
|
|
577
|
+
'default'
|
|
578
|
+
];
|
|
579
|
+
if (!__rspack_external__babel_types_6e8337dd.isExportNamedDeclaration(statement) || 'type' === statement.exportKind) return [];
|
|
580
|
+
const declared = !statement.declaration || __rspack_external__babel_types_6e8337dd.isTSTypeAliasDeclaration(statement.declaration) || __rspack_external__babel_types_6e8337dd.isTSInterfaceDeclaration(statement.declaration) ? [] : Object.keys(__rspack_external__babel_types_6e8337dd.getBindingIdentifiers(statement.declaration));
|
|
581
|
+
return [
|
|
582
|
+
...declared,
|
|
583
|
+
...statement.specifiers.flatMap((specifier)=>__rspack_external__babel_types_6e8337dd.isExportSpecifier(specifier) && 'type' === specifier.exportKind ? [] : [
|
|
584
|
+
propertyName(specifier.exported) ?? ''
|
|
585
|
+
])
|
|
586
|
+
].filter(Boolean);
|
|
587
|
+
});
|
|
588
|
+
const starSources = (file, name)=>'default' === name ? [] : file.program.body.flatMap((statement)=>__rspack_external__babel_types_6e8337dd.isExportAllDeclaration(statement) && 'type' !== statement.exportKind ? [
|
|
589
|
+
statement.source.value
|
|
590
|
+
] : []);
|
|
591
|
+
const importOf = (binding)=>{
|
|
592
|
+
const specifier = binding.path.node;
|
|
593
|
+
const declaration = binding.path.parent;
|
|
594
|
+
if (!__rspack_external__babel_types_6e8337dd.isImportDeclaration(declaration) || 'type' === declaration.importKind || 'typeof' === declaration.importKind || __rspack_external__babel_types_6e8337dd.isImportSpecifier(specifier) && 'type' === specifier.importKind) return;
|
|
595
|
+
const name = __rspack_external__babel_types_6e8337dd.isImportSpecifier(specifier) ? propertyName(specifier.imported) : __rspack_external__babel_types_6e8337dd.isImportDefaultSpecifier(specifier) ? 'default' : __rspack_external__babel_types_6e8337dd.isImportNamespaceSpecifier(specifier) ? '*' : void 0;
|
|
596
|
+
return void 0 === name ? void 0 : {
|
|
597
|
+
specifier: declaration.source.value,
|
|
598
|
+
name
|
|
599
|
+
};
|
|
600
|
+
};
|
|
601
|
+
const patternPath = (pattern, target)=>{
|
|
602
|
+
if (pattern === target) return {
|
|
603
|
+
members: [],
|
|
604
|
+
defaults: []
|
|
605
|
+
};
|
|
606
|
+
if (__rspack_external__babel_types_6e8337dd.isAssignmentPattern(pattern)) {
|
|
607
|
+
const inner = patternPath(pattern.left, target);
|
|
608
|
+
return void 0 === inner || 'dynamic' === inner ? inner : {
|
|
609
|
+
members: inner.members,
|
|
610
|
+
defaults: [
|
|
611
|
+
{
|
|
612
|
+
members: [],
|
|
613
|
+
value: pattern.right
|
|
614
|
+
},
|
|
615
|
+
...inner.defaults
|
|
616
|
+
]
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
if (__rspack_external__babel_types_6e8337dd.isObjectPattern(pattern)) for (const property of pattern.properties){
|
|
620
|
+
const inner = patternPath(__rspack_external__babel_types_6e8337dd.isRestElement(property) ? property.argument : property.value, target);
|
|
621
|
+
if (void 0 === inner) continue;
|
|
622
|
+
const key = __rspack_external__babel_types_6e8337dd.isObjectProperty(property) ? staticKey(property) : void 0;
|
|
623
|
+
if ('dynamic' === inner || void 0 === key) return 'dynamic';
|
|
624
|
+
return {
|
|
625
|
+
members: [
|
|
626
|
+
key,
|
|
627
|
+
...inner.members
|
|
628
|
+
],
|
|
629
|
+
defaults: inner.defaults.map((entry)=>({
|
|
630
|
+
members: [
|
|
631
|
+
key,
|
|
632
|
+
...entry.members
|
|
633
|
+
],
|
|
634
|
+
value: entry.value
|
|
635
|
+
}))
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
if (__rspack_external__babel_types_6e8337dd.isArrayPattern(pattern)) for (const [index, element] of pattern.elements.entries()){
|
|
639
|
+
const inner = element ? patternPath(element, target) : void 0;
|
|
640
|
+
if (void 0 !== inner) {
|
|
641
|
+
if ('dynamic' === inner || __rspack_external__babel_types_6e8337dd.isRestElement(element)) return 'dynamic';
|
|
642
|
+
return {
|
|
643
|
+
members: [
|
|
644
|
+
String(index),
|
|
645
|
+
...inner.members
|
|
646
|
+
],
|
|
647
|
+
defaults: inner.defaults.map((entry)=>({
|
|
648
|
+
members: [
|
|
649
|
+
String(index),
|
|
650
|
+
...entry.members
|
|
651
|
+
],
|
|
652
|
+
value: entry.value
|
|
653
|
+
}))
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
if (__rspack_external__babel_types_6e8337dd.isRestElement(pattern)) return Object.values(__rspack_external__babel_types_6e8337dd.getBindingIdentifiers(pattern)).includes(target) ? 'dynamic' : void 0;
|
|
658
|
+
};
|
|
659
|
+
const objectRestPath = (pattern, target)=>{
|
|
660
|
+
if (!__rspack_external__babel_types_6e8337dd.isObjectPattern(pattern)) return;
|
|
661
|
+
const excluded = new Set();
|
|
662
|
+
for (const property of pattern.properties){
|
|
663
|
+
if (__rspack_external__babel_types_6e8337dd.isRestElement(property)) {
|
|
664
|
+
if (property.argument === target) return {
|
|
665
|
+
members: [],
|
|
666
|
+
excluded
|
|
667
|
+
};
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
670
|
+
const key = staticKey(property);
|
|
671
|
+
if (void 0 === key) break;
|
|
672
|
+
excluded.add(key);
|
|
673
|
+
const inner = objectRestPath(__rspack_external__babel_types_6e8337dd.isAssignmentPattern(property.value) ? property.value.left : property.value, target);
|
|
674
|
+
if (inner) return {
|
|
675
|
+
members: [
|
|
676
|
+
key,
|
|
677
|
+
...inner.members
|
|
678
|
+
],
|
|
679
|
+
excluded: inner.excluded
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
const callSitesOf = (fn)=>{
|
|
684
|
+
const outer = fn.parentPath;
|
|
685
|
+
if (__rspack_external__babel_types_6e8337dd.isCallExpression(outer?.node) && outer.node.callee === fn.node) return {
|
|
686
|
+
calls: [
|
|
687
|
+
outer
|
|
688
|
+
],
|
|
689
|
+
escaped: false
|
|
690
|
+
};
|
|
691
|
+
const member = __rspack_external__babel_types_6e8337dd.isObjectMethod(fn.node) ? fn : __rspack_external__babel_types_6e8337dd.isObjectProperty(outer?.node) && outer.node.value === fn.node ? outer : void 0;
|
|
692
|
+
const key = member && __rspack_external__babel_types_6e8337dd.isObjectMember(member.node) ? staticKey(member.node) : void 0;
|
|
693
|
+
const getter = __rspack_external__babel_types_6e8337dd.isObjectMethod(fn.node) && 'get' === fn.node.kind;
|
|
694
|
+
const object = void 0 === key ? void 0 : member.parentPath;
|
|
695
|
+
const runAt = (callee)=>{
|
|
696
|
+
if (getter) return callee;
|
|
697
|
+
let invoked = callee;
|
|
698
|
+
const via = invoked.parentPath;
|
|
699
|
+
if (via && __rspack_external__babel_types_6e8337dd.isMemberExpression(via.node) && via.node.object === invoked.node && [
|
|
700
|
+
'call',
|
|
701
|
+
'apply'
|
|
702
|
+
].includes(staticKey(via.node) ?? '')) invoked = via;
|
|
703
|
+
const call = invoked.parentPath;
|
|
704
|
+
return call && __rspack_external__babel_types_6e8337dd.isCallExpression(call.node) && call.node.callee === invoked.node ? call : void 0;
|
|
705
|
+
};
|
|
706
|
+
const calls = [];
|
|
707
|
+
let escaped = false;
|
|
708
|
+
const inline = object?.parentPath;
|
|
709
|
+
if (object && (__rspack_external__babel_types_6e8337dd.isMemberExpression(inline?.node) || __rspack_external__babel_types_6e8337dd.isOptionalMemberExpression(inline?.node)) && inline.node.object === object.node) {
|
|
710
|
+
const run = staticKey(inline.node) === key ? runAt(inline) : void 0;
|
|
711
|
+
return run ? {
|
|
712
|
+
calls: [
|
|
713
|
+
run
|
|
714
|
+
],
|
|
715
|
+
escaped: false
|
|
716
|
+
} : {
|
|
717
|
+
calls,
|
|
718
|
+
escaped: true
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
const owner = object?.parentPath;
|
|
722
|
+
const name = __rspack_external__babel_types_6e8337dd.isFunctionDeclaration(fn.node) ? fn.node.id?.name : __rspack_external__babel_types_6e8337dd.isVariableDeclarator(outer?.node) && __rspack_external__babel_types_6e8337dd.isIdentifier(outer.node.id) ? outer.node.id.name : __rspack_external__babel_types_6e8337dd.isVariableDeclarator(owner?.node) && __rspack_external__babel_types_6e8337dd.isIdentifier(owner.node.id) ? owner.node.id.name : void 0;
|
|
723
|
+
const first = name ? (void 0 === key ? fn.scope.parent : owner.scope)?.getBinding(name) : void 0;
|
|
724
|
+
if (!first) return {
|
|
725
|
+
calls,
|
|
726
|
+
escaped: true
|
|
727
|
+
};
|
|
728
|
+
const bindings = [
|
|
729
|
+
first
|
|
730
|
+
];
|
|
731
|
+
for(let index = 0; index < bindings.length && index < MAX_ALIASES; index += 1)for (let reference of bindings[index].referencePaths){
|
|
732
|
+
while(reference.parentPath && unwrapExpression(reference.parent, true) !== reference.parent)reference = reference.parentPath;
|
|
733
|
+
const parent = reference.parent;
|
|
734
|
+
if (__rspack_external__babel_types_6e8337dd.isVariableDeclarator(parent) && parent.init === reference.node && __rspack_external__babel_types_6e8337dd.isIdentifier(parent.id)) {
|
|
735
|
+
const alias = reference.scope.getBinding(parent.id.name);
|
|
736
|
+
if (alias && !bindings.includes(alias)) bindings.push(alias);
|
|
737
|
+
continue;
|
|
738
|
+
}
|
|
739
|
+
const callee = void 0 === key ? reference : (__rspack_external__babel_types_6e8337dd.isMemberExpression(parent) || __rspack_external__babel_types_6e8337dd.isOptionalMemberExpression(parent)) && parent.object === reference.node && staticKey(parent) === key ? reference.parentPath : void 0;
|
|
740
|
+
const run = callee ? runAt(callee) : void 0;
|
|
741
|
+
if (run) calls.push(run);
|
|
742
|
+
else if (callee && (void 0 !== key || !isReadOnlyUse(reference))) escaped = true;
|
|
743
|
+
else if (!callee && !isReadOnlyUse(reference)) escaped = true;
|
|
744
|
+
}
|
|
745
|
+
return {
|
|
746
|
+
calls,
|
|
747
|
+
escaped
|
|
748
|
+
};
|
|
749
|
+
};
|
|
750
|
+
const methodOf = (literal, key, depth = 0)=>{
|
|
751
|
+
for (const entry of literal.get('properties').toReversed()){
|
|
752
|
+
if (entry.isObjectMethod() || entry.isObjectProperty()) {
|
|
753
|
+
let name = staticKey(entry.node);
|
|
754
|
+
if (void 0 === name) {
|
|
755
|
+
const folded = entry.get('key').evaluate();
|
|
756
|
+
if (!folded.confident || 'string' != typeof folded.value) return 'unknown';
|
|
757
|
+
name = folded.value;
|
|
758
|
+
}
|
|
759
|
+
if (name === key) return entry;
|
|
760
|
+
}
|
|
761
|
+
if (!entry.isSpreadElement()) continue;
|
|
762
|
+
const argument = unwrapExpression(entry.node.argument, true);
|
|
763
|
+
const binding = __rspack_external__babel_types_6e8337dd.isIdentifier(argument) ? entry.scope.getBinding(argument.name) : void 0;
|
|
764
|
+
const init = binding?.kind === 'const' && binding.path.isVariableDeclarator() ? binding.path.get('init') : void 0;
|
|
765
|
+
if (!init?.isObjectExpression() || depth >= MAX_DEPTH) return 'unknown';
|
|
766
|
+
const found = methodOf(init, key, depth + 1);
|
|
767
|
+
if (void 0 !== found) return found;
|
|
768
|
+
}
|
|
769
|
+
};
|
|
770
|
+
const functionOf = (binding)=>{
|
|
771
|
+
for(let hop = 0; binding && hop < MAX_DEPTH; hop += 1){
|
|
772
|
+
const declared = binding.path;
|
|
773
|
+
if (declared.isFunctionDeclaration()) return declared;
|
|
774
|
+
if (!declared.isVariableDeclarator() || 'const' !== binding.kind) break;
|
|
775
|
+
const init = declared.get('init');
|
|
776
|
+
let value = init;
|
|
777
|
+
while(unwrapExpression(value.node, true) !== value.node)value = value.get('expression');
|
|
778
|
+
if (value.isFunction()) return value;
|
|
779
|
+
if (!value.isIdentifier()) break;
|
|
780
|
+
binding = value.scope.getBinding(value.node.name);
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
const isReadOnlyUse = (reference)=>{
|
|
784
|
+
const parent = reference.parent;
|
|
785
|
+
const node = reference.node;
|
|
786
|
+
return !__rspack_external__babel_types_6e8337dd.isExpression(node) || __rspack_external__babel_types_6e8337dd.isExportSpecifier(parent) || __rspack_external__babel_types_6e8337dd.isExportDefaultDeclaration(parent) || __rspack_external__babel_types_6e8337dd.isCallExpression(parent) && parent.callee === node || (__rspack_external__babel_types_6e8337dd.isMemberExpression(parent) || __rspack_external__babel_types_6e8337dd.isOptionalMemberExpression(parent)) && parent.object === node || __rspack_external__babel_types_6e8337dd.isExpressionStatement(parent) || __rspack_external__babel_types_6e8337dd.isUnaryExpression(parent) || __rspack_external__babel_types_6e8337dd.isBinaryExpression(parent) || __rspack_external__babel_types_6e8337dd.isTemplateLiteral(parent) || __rspack_external__babel_types_6e8337dd.isAssignmentExpression(parent) && parent.left === node || __rspack_external__babel_types_6e8337dd.isUpdateExpression(parent) && parent.argument === node || (__rspack_external__babel_types_6e8337dd.isIfStatement(parent) || __rspack_external__babel_types_6e8337dd.isConditionalExpression(parent) || __rspack_external__babel_types_6e8337dd.isWhileStatement(parent) || __rspack_external__babel_types_6e8337dd.isDoWhileStatement(parent) || __rspack_external__babel_types_6e8337dd.isForStatement(parent)) && 'test' in parent && parent.test === node || __rspack_external__babel_types_6e8337dd.isSwitchStatement(parent) && parent.discriminant === node;
|
|
787
|
+
};
|
|
788
|
+
const aliasCache = new WeakMap();
|
|
789
|
+
const aliasesOf = (binding, writes)=>{
|
|
790
|
+
if (0 === writes.size) return [
|
|
791
|
+
{
|
|
792
|
+
binding,
|
|
793
|
+
prefix: []
|
|
794
|
+
}
|
|
795
|
+
];
|
|
796
|
+
if (writes.has(OPAQUE_RECEIVER)) return;
|
|
797
|
+
if (aliasCache.has(binding)) return aliasCache.get(binding);
|
|
798
|
+
const result = collectAliases(binding, writes);
|
|
799
|
+
aliasCache.set(binding, result);
|
|
800
|
+
return result;
|
|
801
|
+
};
|
|
802
|
+
const collectAliases = (binding, writes)=>{
|
|
803
|
+
const found = [
|
|
804
|
+
{
|
|
805
|
+
binding,
|
|
806
|
+
prefix: [],
|
|
807
|
+
dynamic: false,
|
|
808
|
+
depth: 0
|
|
809
|
+
}
|
|
810
|
+
];
|
|
811
|
+
let escaped = false;
|
|
812
|
+
const add = (entry)=>{
|
|
813
|
+
if (!found.some((known)=>known.binding === entry.binding && known.dynamic === entry.dynamic && known.depth === entry.depth && JSON.stringify(known.prefix) === JSON.stringify(entry.prefix))) found.push(entry);
|
|
814
|
+
};
|
|
815
|
+
for(let index = 0; index < found.length && index < MAX_ALIASES; index += 1)for (const start of found[index].binding.referencePaths){
|
|
816
|
+
const origin = found[index];
|
|
817
|
+
const pending = [
|
|
818
|
+
{
|
|
819
|
+
reference: start,
|
|
820
|
+
path: [
|
|
821
|
+
...origin.prefix
|
|
822
|
+
],
|
|
823
|
+
dynamic: origin.dynamic,
|
|
824
|
+
depth: origin.depth
|
|
825
|
+
}
|
|
826
|
+
];
|
|
827
|
+
const returnedFrom = new Set();
|
|
828
|
+
for(let flow = pending.pop(); flow; flow = pending.pop()){
|
|
829
|
+
let { reference, dynamic, depth } = flow;
|
|
830
|
+
const { path } = flow;
|
|
831
|
+
const holds = (holder, deeper)=>{
|
|
832
|
+
if (holder) add({
|
|
833
|
+
binding: holder,
|
|
834
|
+
prefix: path,
|
|
835
|
+
dynamic,
|
|
836
|
+
depth: depth + deeper
|
|
837
|
+
});
|
|
838
|
+
};
|
|
839
|
+
const into = (pattern, lookup)=>{
|
|
840
|
+
for (const identifier of Object.values(__rspack_external__babel_types_6e8337dd.getBindingIdentifiers(pattern))){
|
|
841
|
+
const route = patternPath(pattern, identifier);
|
|
842
|
+
const alias = lookup(identifier.name);
|
|
843
|
+
if (void 0 === route || !alias) continue;
|
|
844
|
+
if ('dynamic' === route) {
|
|
845
|
+
add({
|
|
846
|
+
binding: alias,
|
|
847
|
+
prefix: path,
|
|
848
|
+
dynamic: true,
|
|
849
|
+
depth
|
|
850
|
+
});
|
|
851
|
+
continue;
|
|
852
|
+
}
|
|
853
|
+
const consumed = Math.min(depth, route.members.length);
|
|
854
|
+
add({
|
|
855
|
+
binding: alias,
|
|
856
|
+
prefix: [
|
|
857
|
+
...path,
|
|
858
|
+
...route.members.slice(consumed)
|
|
859
|
+
],
|
|
860
|
+
dynamic,
|
|
861
|
+
depth: depth - consumed
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
};
|
|
865
|
+
for(;;){
|
|
866
|
+
const parent = reference.parent;
|
|
867
|
+
const up = reference.parentPath;
|
|
868
|
+
if (!up) break;
|
|
869
|
+
if (unwrapExpression(parent, true) !== parent || __rspack_external__babel_types_6e8337dd.isConditionalExpression(parent) && parent.test !== reference.node || __rspack_external__babel_types_6e8337dd.isLogicalExpression(parent) || __rspack_external__babel_types_6e8337dd.isAwaitExpression(parent) || __rspack_external__babel_types_6e8337dd.isSequenceExpression(parent) && parent.expressions.at(-1) === reference.node) {
|
|
870
|
+
reference = up;
|
|
871
|
+
continue;
|
|
872
|
+
}
|
|
873
|
+
if ((__rspack_external__babel_types_6e8337dd.isMemberExpression(parent) || __rspack_external__babel_types_6e8337dd.isOptionalMemberExpression(parent)) && parent.object === reference.node) {
|
|
874
|
+
if (depth > 0 && (__rspack_external__babel_types_6e8337dd.isCallExpression(up.parent) || __rspack_external__babel_types_6e8337dd.isOptionalCallExpression(up.parent)) && up.parent.callee === parent && CONTAINER_EXTRACTORS.has(staticKey(parent) ?? '')) {
|
|
875
|
+
escaped = true;
|
|
876
|
+
break;
|
|
877
|
+
}
|
|
878
|
+
if (0 === depth && (__rspack_external__babel_types_6e8337dd.isCallExpression(up.parent) || __rspack_external__babel_types_6e8337dd.isOptionalCallExpression(up.parent)) && up.parent.callee === parent && RECEIVER_RETURNING_METHODS.has(staticKey(parent) ?? '')) {
|
|
879
|
+
reference = up.parentPath;
|
|
880
|
+
continue;
|
|
881
|
+
}
|
|
882
|
+
if (depth > 0) depth -= 1;
|
|
883
|
+
else {
|
|
884
|
+
const name = staticKey(parent);
|
|
885
|
+
if (void 0 === name) dynamic = true;
|
|
886
|
+
else path.push(name);
|
|
887
|
+
}
|
|
888
|
+
reference = up;
|
|
889
|
+
continue;
|
|
890
|
+
}
|
|
891
|
+
if (__rspack_external__babel_types_6e8337dd.isReturnStatement(parent) && parent.argument === reference.node || __rspack_external__babel_types_6e8337dd.isArrowFunctionExpression(parent) && parent.body === reference.node) {
|
|
892
|
+
const fn = reference.getFunctionParent();
|
|
893
|
+
if (fn && !returnedFrom.has(fn.node)) {
|
|
894
|
+
returnedFrom.add(fn.node);
|
|
895
|
+
const sites = callSitesOf(fn);
|
|
896
|
+
escaped ||= sites.escaped;
|
|
897
|
+
for (const call of sites.calls)pending.push({
|
|
898
|
+
reference: call,
|
|
899
|
+
path: [
|
|
900
|
+
...path
|
|
901
|
+
],
|
|
902
|
+
dynamic,
|
|
903
|
+
depth
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
break;
|
|
907
|
+
}
|
|
908
|
+
if (__rspack_external__babel_types_6e8337dd.isForOfStatement(parent) && parent.right === reference.node || __rspack_external__babel_types_6e8337dd.isTemplateLiteral(parent) && __rspack_external__babel_types_6e8337dd.isTaggedTemplateExpression(up.parent) || __rspack_external__babel_types_6e8337dd.isJSXExpressionContainer(parent) || __rspack_external__babel_types_6e8337dd.isJSXSpreadAttribute(parent) || __rspack_external__babel_types_6e8337dd.isJSXSpreadChild(parent) || __rspack_external__babel_types_6e8337dd.isYieldExpression(parent)) {
|
|
909
|
+
escaped = true;
|
|
910
|
+
break;
|
|
911
|
+
}
|
|
912
|
+
if (__rspack_external__babel_types_6e8337dd.isObjectProperty(parent) && parent.value === reference.node && __rspack_external__babel_types_6e8337dd.isObjectExpression(up.parent) || __rspack_external__babel_types_6e8337dd.isSpreadElement(parent) && __rspack_external__babel_types_6e8337dd.isObjectExpression(up.parent)) {
|
|
913
|
+
reference = up.parentPath;
|
|
914
|
+
if (!__rspack_external__babel_types_6e8337dd.isSpreadElement(parent) || 0 === depth) depth += 1;
|
|
915
|
+
continue;
|
|
916
|
+
}
|
|
917
|
+
if (__rspack_external__babel_types_6e8337dd.isArrayExpression(parent) || __rspack_external__babel_types_6e8337dd.isSpreadElement(parent) && __rspack_external__babel_types_6e8337dd.isArrayExpression(up.parent)) {
|
|
918
|
+
reference = __rspack_external__babel_types_6e8337dd.isSpreadElement(parent) ? up.parentPath : up;
|
|
919
|
+
if (!__rspack_external__babel_types_6e8337dd.isSpreadElement(parent) || 0 === depth) depth += 1;
|
|
920
|
+
continue;
|
|
921
|
+
}
|
|
922
|
+
if (__rspack_external__babel_types_6e8337dd.isSpreadElement(parent)) {
|
|
923
|
+
escaped = true;
|
|
924
|
+
break;
|
|
925
|
+
}
|
|
926
|
+
if ((__rspack_external__babel_types_6e8337dd.isCallExpression(parent) || __rspack_external__babel_types_6e8337dd.isOptionalCallExpression(parent) || __rspack_external__babel_types_6e8337dd.isNewExpression(parent)) && parent.callee !== reference.node) {
|
|
927
|
+
let calleePath = up.get('callee');
|
|
928
|
+
while(unwrapExpression(calleePath.node, true) !== calleePath.node)calleePath = calleePath.get('expression');
|
|
929
|
+
const callee = calleePath.node;
|
|
930
|
+
const member = __rspack_external__babel_types_6e8337dd.isMemberExpression(callee) || __rspack_external__babel_types_6e8337dd.isOptionalMemberExpression(callee);
|
|
931
|
+
const receiver = member ? writeTarget(callee)?.root : void 0;
|
|
932
|
+
if (receiver) holds(reference.scope.getBinding(receiver.name), 1);
|
|
933
|
+
const receiverObject = member ? unwrapExpression(callee.object, true) : void 0;
|
|
934
|
+
const method = member && (__rspack_external__babel_types_6e8337dd.isIdentifier(receiverObject) || __rspack_external__babel_types_6e8337dd.isObjectExpression(receiverObject)) ? staticKey(callee) : void 0;
|
|
935
|
+
let fn = __rspack_external__babel_types_6e8337dd.isIdentifier(callee) ? reference.scope.getBinding(callee.name) : __rspack_external__babel_types_6e8337dd.isIdentifier(receiverObject) ? reference.scope.getBinding(receiverObject.name) : void 0;
|
|
936
|
+
for(let hop = 0; fn && hop < MAX_DEPTH; hop += 1){
|
|
937
|
+
const aliased = fn.path.isVariableDeclarator() ? unwrapExpression(fn.path.node.init ?? fn.path.node.id, true) : void 0;
|
|
938
|
+
if ('const' !== fn.kind || !__rspack_external__babel_types_6e8337dd.isIdentifier(aliased)) break;
|
|
939
|
+
const next = fn.path.scope.getBinding(aliased.name);
|
|
940
|
+
if (!next || next === fn) break;
|
|
941
|
+
fn = next;
|
|
942
|
+
}
|
|
943
|
+
const declared = fn?.path;
|
|
944
|
+
const init = declared?.isVariableDeclarator() ? declared.get('init') : void 0;
|
|
945
|
+
let literal = init;
|
|
946
|
+
if (__rspack_external__babel_types_6e8337dd.isObjectExpression(receiverObject)) {
|
|
947
|
+
literal = calleePath.get('object');
|
|
948
|
+
while(unwrapExpression(literal.node, true) !== literal.node)literal = literal.get('expression');
|
|
949
|
+
}
|
|
950
|
+
const lookup = void 0 !== method && literal?.isObjectExpression() ? methodOf(literal, method) : void 0;
|
|
951
|
+
if ('unknown' === lookup) escaped = true;
|
|
952
|
+
const property = 'unknown' === lookup ? void 0 : lookup;
|
|
953
|
+
const held = property?.isObjectProperty() ? property.get('value') : property;
|
|
954
|
+
const heldName = held?.isIdentifier() ? held.node.name : void 0;
|
|
955
|
+
const heldFunction = heldName ? functionOf(held.scope.getBinding(heldName)) : void 0;
|
|
956
|
+
const target = calleePath.isFunction() ? calleePath : void 0 !== method ? heldName ? heldFunction : held : declared?.isFunctionDeclaration() ? declared : init;
|
|
957
|
+
if (heldName && !heldFunction?.isFunction()) {
|
|
958
|
+
const binding = held.scope.getBinding(heldName);
|
|
959
|
+
if (binding && 'module' !== binding.kind) escaped = true;
|
|
960
|
+
}
|
|
961
|
+
const initValue = init?.node ? unwrapExpression(init.node, true) : void 0;
|
|
962
|
+
const unseen = !target?.isFunction() && ([
|
|
963
|
+
'param',
|
|
964
|
+
'let',
|
|
965
|
+
'var'
|
|
966
|
+
].includes(fn?.kind ?? '') || !__rspack_external__babel_types_6e8337dd.isIdentifier(callee) && !member || member && !__rspack_external__babel_types_6e8337dd.isIdentifier(receiverObject) && !__rspack_external__babel_types_6e8337dd.isObjectExpression(receiverObject) && (void 0 === receiver || reference.scope.getBinding(receiver.name)?.kind !== 'module') || void 0 !== method && fn?.kind === 'const' && !property && (__rspack_external__babel_types_6e8337dd.isNewExpression(initValue) || __rspack_external__babel_types_6e8337dd.isCallExpression(initValue)) && (()=>{
|
|
967
|
+
const root = writeTarget(unwrapExpression(initValue.callee, true))?.root;
|
|
968
|
+
const owner = root ? fn.path.scope.getBinding(root.name) : void 0;
|
|
969
|
+
return !root || void 0 !== owner && 'module' !== owner.kind;
|
|
970
|
+
})() || fn?.kind === 'const' && void 0 === method && void 0 !== initValue && !__rspack_external__babel_types_6e8337dd.isMemberExpression(initValue) && !__rspack_external__babel_types_6e8337dd.isIdentifier(initValue));
|
|
971
|
+
const globalName = __rspack_external__babel_types_6e8337dd.isIdentifier(callee) ? callee.name : member && __rspack_external__babel_types_6e8337dd.isIdentifier(receiverObject) ? receiverObject.name : void 0;
|
|
972
|
+
const unboundGlobal = void 0 !== globalName && !reference.scope.getBinding(globalName) && !READ_ONLY_GLOBAL_CALLS.has(__rspack_external__babel_types_6e8337dd.isIdentifier(callee) ? globalName : `${globalName}.${staticKey(callee) ?? ''}`) && 'console' !== globalName;
|
|
973
|
+
if (unseen || unboundGlobal) escaped = true;
|
|
974
|
+
const index = parent.arguments.indexOf(reference.node);
|
|
975
|
+
const storing = member && void 0 !== globalName && !reference.scope.getBinding(globalName) ? STORING_GLOBAL_CALLS.get(`${globalName}.${staticKey(callee) ?? ''}`) : void 0;
|
|
976
|
+
if (storing && index >= 1) {
|
|
977
|
+
const stored = parent.arguments[0] ? writeTarget(parent.arguments[0]) : void 0;
|
|
978
|
+
const holder = stored ? reference.scope.getBinding(stored.root.name) : void 0;
|
|
979
|
+
if (holder) holds(holder, stored.depth + storing(depth) - depth);
|
|
980
|
+
else escaped = true;
|
|
981
|
+
}
|
|
982
|
+
if (('call' === method || 'apply' === method || 'bind' === method) && __rspack_external__babel_types_6e8337dd.isIdentifier(receiverObject)) {
|
|
983
|
+
const receiverBinding = reference.scope.getBinding(receiverObject.name);
|
|
984
|
+
const invoked = functionOf(receiverBinding);
|
|
985
|
+
const param = invoked?.isFunction() ? invoked.node.params[index - 1] : void 0;
|
|
986
|
+
if ('call' === method && index >= 1 && param && !__rspack_external__babel_types_6e8337dd.isRestElement(param) && invoked?.isFunction()) into(param, (name)=>invoked.scope.getBinding(name));
|
|
987
|
+
else if (receiverBinding && 'module' !== receiverBinding.kind) escaped = true;
|
|
988
|
+
}
|
|
989
|
+
if (target?.isFunction()) {
|
|
990
|
+
const param = target.node.params[index];
|
|
991
|
+
if (param && !__rspack_external__babel_types_6e8337dd.isRestElement(param)) into(param, (name)=>target.scope.getBinding(name));
|
|
992
|
+
else escaped = true;
|
|
993
|
+
}
|
|
994
|
+
reference = up;
|
|
995
|
+
dynamic = true;
|
|
996
|
+
continue;
|
|
997
|
+
}
|
|
998
|
+
if ((__rspack_external__babel_types_6e8337dd.isClassProperty(parent) || __rspack_external__babel_types_6e8337dd.isClassPrivateProperty(parent) || __rspack_external__babel_types_6e8337dd.isClassAccessorProperty(parent)) && parent.value === reference.node) {
|
|
999
|
+
const owner = up.parentPath?.parentPath;
|
|
1000
|
+
if (!parent.static || __rspack_external__babel_types_6e8337dd.isPrivateName(parent.key) || !owner) {
|
|
1001
|
+
escaped = true;
|
|
1002
|
+
break;
|
|
1003
|
+
}
|
|
1004
|
+
if (owner.isClassDeclaration()) {
|
|
1005
|
+
const id = owner.node.id;
|
|
1006
|
+
const binding = id ? owner.parentPath.scope.getBinding(id.name) : void 0;
|
|
1007
|
+
if (binding) holds(binding, 1);
|
|
1008
|
+
else escaped = true;
|
|
1009
|
+
break;
|
|
1010
|
+
}
|
|
1011
|
+
reference = owner;
|
|
1012
|
+
depth += 1;
|
|
1013
|
+
continue;
|
|
1014
|
+
}
|
|
1015
|
+
if (__rspack_external__babel_types_6e8337dd.isAssignmentExpression(parent) && parent.right === reference.node && !__rspack_external__babel_types_6e8337dd.isIdentifier(parent.left) && !__rspack_external__babel_types_6e8337dd.isPattern(parent.left)) {
|
|
1016
|
+
const stored = writeTarget(parent.left);
|
|
1017
|
+
const setters = setterNames(reference.scope.getProgramParent().path);
|
|
1018
|
+
const key = __rspack_external__babel_types_6e8337dd.isMemberExpression(parent.left) || __rspack_external__babel_types_6e8337dd.isOptionalMemberExpression(parent.left) ? staticKey(parent.left) : void 0;
|
|
1019
|
+
if (setters.has(DYNAMIC_SETTER) || setters.size > 0 && (void 0 === key || setters.has(key))) {
|
|
1020
|
+
escaped = true;
|
|
1021
|
+
break;
|
|
1022
|
+
}
|
|
1023
|
+
if (stored) holds(reference.scope.getBinding(stored.root.name), stored.depth);
|
|
1024
|
+
reference = up;
|
|
1025
|
+
continue;
|
|
1026
|
+
}
|
|
1027
|
+
break;
|
|
1028
|
+
}
|
|
1029
|
+
const parent = reference.parent;
|
|
1030
|
+
const target = __rspack_external__babel_types_6e8337dd.isVariableDeclarator(parent) && parent.init === reference.node ? parent.id : __rspack_external__babel_types_6e8337dd.isAssignmentExpression(parent) && [
|
|
1031
|
+
'=',
|
|
1032
|
+
'&&=',
|
|
1033
|
+
'||=',
|
|
1034
|
+
'??='
|
|
1035
|
+
].includes(parent.operator) || __rspack_external__babel_types_6e8337dd.isAssignmentPattern(parent) ? parent.right === reference.node ? parent.left : void 0 : void 0;
|
|
1036
|
+
if (__rspack_external__babel_types_6e8337dd.isLVal(target)) {
|
|
1037
|
+
into(target, (name)=>reference.scope.getBinding(name));
|
|
1038
|
+
if (__rspack_external__babel_types_6e8337dd.isAssignmentExpression(parent) && reference.parentPath) pending.push({
|
|
1039
|
+
reference: reference.parentPath,
|
|
1040
|
+
path: [
|
|
1041
|
+
...path
|
|
1042
|
+
],
|
|
1043
|
+
dynamic,
|
|
1044
|
+
depth
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
const reaches = (entry)=>(writes.get(entry.binding) ?? []).some((write)=>0 === entry.depth ? entry.dynamic : write.depth > entry.depth);
|
|
1050
|
+
const tracked = new Set(found.map((entry)=>entry.binding));
|
|
1051
|
+
if (found.length > MAX_ALIASES || found.some(reaches) || escaped && [
|
|
1052
|
+
...writes.keys()
|
|
1053
|
+
].some((owner)=>!tracked.has(owner))) return;
|
|
1054
|
+
return found.filter((entry)=>!entry.dynamic && 0 === entry.depth);
|
|
1055
|
+
};
|
|
1056
|
+
function createModuleGraph() {
|
|
1057
|
+
const modules = new Map();
|
|
1058
|
+
const facts = new WeakMap();
|
|
1059
|
+
const workspaces = new Map();
|
|
1060
|
+
const load = (filePath, boundary)=>{
|
|
1061
|
+
const real = node_fs.realpathSync(filePath);
|
|
1062
|
+
let entry = modules.get(real);
|
|
1063
|
+
if (void 0 === entry) {
|
|
1064
|
+
const directory = node_path.dirname(real);
|
|
1065
|
+
if (!workspaces.has(directory)) workspaces.set(directory, containingWorkspace(real));
|
|
1066
|
+
const workspace = workspaces.get(directory);
|
|
1067
|
+
try {
|
|
1068
|
+
const parsed = parseModule(real, workspace);
|
|
1069
|
+
const module = {
|
|
1070
|
+
file: parsed.file,
|
|
1071
|
+
path: real,
|
|
1072
|
+
boundary: boundary ?? sourceBoundary(real, workspace),
|
|
1073
|
+
mutations: parsed.mutations
|
|
1074
|
+
};
|
|
1075
|
+
facts.set(module, parsed.facts);
|
|
1076
|
+
entry = {
|
|
1077
|
+
module,
|
|
1078
|
+
facts: parsed.facts
|
|
1079
|
+
};
|
|
1080
|
+
} catch (error) {
|
|
1081
|
+
if (!(error instanceof SourceSyntaxError)) throw error;
|
|
1082
|
+
entry = error;
|
|
1083
|
+
}
|
|
1084
|
+
modules.set(real, entry);
|
|
1085
|
+
}
|
|
1086
|
+
if (entry instanceof SourceSyntaxError) throw entry;
|
|
1087
|
+
return entry.module;
|
|
1088
|
+
};
|
|
1089
|
+
const factsOf = (module)=>{
|
|
1090
|
+
const known = facts.get(module);
|
|
1091
|
+
if (known) return known;
|
|
1092
|
+
throw new Error(`${module.path}: module does not belong to this graph`);
|
|
1093
|
+
};
|
|
1094
|
+
const follow = (module, specifier)=>{
|
|
1095
|
+
const target = resolveModulePath(module, specifier, factsOf(module).workspace);
|
|
1096
|
+
if (target?.kind === 'external') return 'external';
|
|
1097
|
+
if (void 0 === target) return;
|
|
1098
|
+
try {
|
|
1099
|
+
return load(target.path, target.boundary);
|
|
1100
|
+
} catch (error) {
|
|
1101
|
+
if (error instanceof SourceSyntaxError) return;
|
|
1102
|
+
throw error;
|
|
1103
|
+
}
|
|
1104
|
+
};
|
|
1105
|
+
const mutated = (module, binding)=>binding.constantViolations.length > 0 || factsOf(module).merged.has(binding.identifier.name) || (aliasesOf(binding, factsOf(module).writes)?.some((alias)=>factsOf(module).writes.has(alias.binding)) ?? true);
|
|
1106
|
+
const resolveBinding = (module, name, scope, chain, seen, lexical)=>{
|
|
1107
|
+
const key = `${scope}:${module.path}#${name}`;
|
|
1108
|
+
if (seen.has(key) || seen.size >= MAX_LOOKUPS) return;
|
|
1109
|
+
seen.add(key);
|
|
1110
|
+
const last = chain.at(-1);
|
|
1111
|
+
const hops = last?.path === module.path && last.name === name ? chain : [
|
|
1112
|
+
...chain,
|
|
1113
|
+
{
|
|
1114
|
+
path: module.path,
|
|
1115
|
+
name
|
|
1116
|
+
}
|
|
1117
|
+
];
|
|
1118
|
+
const throughModule = (specifier, imported, allowExternal)=>{
|
|
1119
|
+
const next = follow(module, specifier);
|
|
1120
|
+
if ('external' === next) return allowExternal ? {
|
|
1121
|
+
kind: 'external',
|
|
1122
|
+
specifier,
|
|
1123
|
+
name: imported,
|
|
1124
|
+
chain: hops
|
|
1125
|
+
} : void 0;
|
|
1126
|
+
return void 0 === next ? void 0 : resolveBinding(next, imported, 'export', hops, seen);
|
|
1127
|
+
};
|
|
1128
|
+
if ('local' === scope) {
|
|
1129
|
+
const binding = lexical ?? factsOf(module).scope.getBinding(name);
|
|
1130
|
+
if (!binding || mutated(module, binding)) return;
|
|
1131
|
+
if ('module' === binding.kind) {
|
|
1132
|
+
const imported = importOf(binding);
|
|
1133
|
+
return void 0 === imported || '*' === imported.name ? void 0 : throughModule(imported.specifier, imported.name, true);
|
|
1134
|
+
}
|
|
1135
|
+
const declarator = binding.path.node;
|
|
1136
|
+
return 'const' === binding.kind && __rspack_external__babel_types_6e8337dd.isVariableDeclarator(declarator) && __rspack_external__babel_types_6e8337dd.isIdentifier(declarator.id) && declarator.init ? {
|
|
1137
|
+
kind: 'declaration',
|
|
1138
|
+
expression: declarator.init,
|
|
1139
|
+
module,
|
|
1140
|
+
chain: hops
|
|
1141
|
+
} : void 0;
|
|
1142
|
+
}
|
|
1143
|
+
const hop = exportHop(module.file, name);
|
|
1144
|
+
if (hop?.kind === 'local') return resolveBinding(module, hop.name, 'local', hops, seen);
|
|
1145
|
+
if (hop?.kind === 'reexport') return throughModule(hop.specifier, hop.name, true);
|
|
1146
|
+
if (hop?.kind === 'node') return __rspack_external__babel_types_6e8337dd.isExpression(hop.node) ? {
|
|
1147
|
+
kind: 'declaration',
|
|
1148
|
+
expression: hop.node,
|
|
1149
|
+
module,
|
|
1150
|
+
chain: hops
|
|
1151
|
+
} : void 0;
|
|
1152
|
+
if (void 0 !== hop) return;
|
|
1153
|
+
for (const specifier of starSources(module.file, name)){
|
|
1154
|
+
const resolved = throughModule(specifier, name, false);
|
|
1155
|
+
if (void 0 !== resolved) return resolved;
|
|
1156
|
+
}
|
|
1157
|
+
};
|
|
1158
|
+
const resolveReference = (module, reference)=>{
|
|
1159
|
+
const node = unwrapExpression(reference, true);
|
|
1160
|
+
const moduleFacts = factsOf(module);
|
|
1161
|
+
const bindingAt = (identifier)=>moduleFacts.references.get(identifier) ?? moduleFacts.declarations.get(identifier);
|
|
1162
|
+
if (__rspack_external__babel_types_6e8337dd.isIdentifier(node)) {
|
|
1163
|
+
const binding = bindingAt(node);
|
|
1164
|
+
return binding ? resolveBinding(module, node.name, 'local', [], new Set(), binding) : void 0;
|
|
1165
|
+
}
|
|
1166
|
+
if (!__rspack_external__babel_types_6e8337dd.isMemberExpression(node) || node.computed || !__rspack_external__babel_types_6e8337dd.isIdentifier(node.object) || !__rspack_external__babel_types_6e8337dd.isIdentifier(node.property)) return;
|
|
1167
|
+
const binding = bindingAt(node.object);
|
|
1168
|
+
if (!binding || 'module' !== binding.kind || mutated(module, binding)) return;
|
|
1169
|
+
const imported = importOf(binding);
|
|
1170
|
+
if (imported?.name !== '*') return;
|
|
1171
|
+
const target = follow(module, imported.specifier);
|
|
1172
|
+
const chain = [
|
|
1173
|
+
{
|
|
1174
|
+
path: module.path,
|
|
1175
|
+
name: node.object.name
|
|
1176
|
+
}
|
|
1177
|
+
];
|
|
1178
|
+
if ('external' === target) return {
|
|
1179
|
+
kind: 'external',
|
|
1180
|
+
specifier: imported.specifier,
|
|
1181
|
+
name: node.property.name,
|
|
1182
|
+
chain
|
|
1183
|
+
};
|
|
1184
|
+
return void 0 === target ? void 0 : resolveBinding(target, node.property.name, 'export', chain, new Set());
|
|
1185
|
+
};
|
|
1186
|
+
const isUnboundReference = (module, reference)=>{
|
|
1187
|
+
const node = unwrapExpression(reference, true);
|
|
1188
|
+
const { references } = factsOf(module);
|
|
1189
|
+
return __rspack_external__babel_types_6e8337dd.isIdentifier(node) && references.has(node) && void 0 === references.get(node);
|
|
1190
|
+
};
|
|
1191
|
+
const evaluation = (walking)=>{
|
|
1192
|
+
const active = new Set();
|
|
1193
|
+
let frames = 0;
|
|
1194
|
+
let frame = {
|
|
1195
|
+
id: 0,
|
|
1196
|
+
parameters: new Map()
|
|
1197
|
+
};
|
|
1198
|
+
let steps = 0;
|
|
1199
|
+
const boundArguments = new WeakMap();
|
|
1200
|
+
const closureFrames = new WeakMap();
|
|
1201
|
+
const unresolved = (module, node)=>[
|
|
1202
|
+
{
|
|
1203
|
+
kind: 'unresolved',
|
|
1204
|
+
node,
|
|
1205
|
+
module
|
|
1206
|
+
}
|
|
1207
|
+
];
|
|
1208
|
+
const namespaceValues = (module, specifier, members, at)=>{
|
|
1209
|
+
const next = follow(module, specifier);
|
|
1210
|
+
if ('external' === next) return [
|
|
1211
|
+
0 === members.length ? {
|
|
1212
|
+
kind: 'external',
|
|
1213
|
+
specifier,
|
|
1214
|
+
name: '*',
|
|
1215
|
+
members: []
|
|
1216
|
+
} : {
|
|
1217
|
+
kind: 'external',
|
|
1218
|
+
specifier,
|
|
1219
|
+
name: members[0],
|
|
1220
|
+
members: members.slice(1)
|
|
1221
|
+
}
|
|
1222
|
+
];
|
|
1223
|
+
if (void 0 === next) return unresolved(module, at);
|
|
1224
|
+
if (0 === members.length) {
|
|
1225
|
+
const written = (write)=>write.value ? values(next, write.value, [
|
|
1226
|
+
...write.from ?? []
|
|
1227
|
+
]) : unresolved(next, write.node);
|
|
1228
|
+
const whole = factsOf(next).commonJs.filter((write)=>0 === write.path.length && !write.dynamic);
|
|
1229
|
+
const found = whole.flatMap(written);
|
|
1230
|
+
if (walking) {
|
|
1231
|
+
for (const write of factsOf(next).commonJs)if (write.path.length > 0 || write.dynamic) found.push(...written(write));
|
|
1232
|
+
const key = `namespace:${next.path}`;
|
|
1233
|
+
if (!active.has(key)) {
|
|
1234
|
+
active.add(key);
|
|
1235
|
+
try {
|
|
1236
|
+
for (const name of exportNames(next.file))found.push(...exportValues(next, name, []) ?? []);
|
|
1237
|
+
for (const specifier of starSources(next.file, ''))found.push(...namespaceValues(next, specifier, [], at));
|
|
1238
|
+
} finally{
|
|
1239
|
+
active.delete(key);
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
return whole.length > 0 ? found : [
|
|
1244
|
+
...unresolved(module, at),
|
|
1245
|
+
...found
|
|
1246
|
+
];
|
|
1247
|
+
}
|
|
1248
|
+
return exportValues(next, members[0], members.slice(1)) ?? unresolved(module, at);
|
|
1249
|
+
};
|
|
1250
|
+
const importValues = (module, specifier, name, members, at)=>{
|
|
1251
|
+
if ('*' === name) return namespaceValues(module, specifier, members, at);
|
|
1252
|
+
const next = follow(module, specifier);
|
|
1253
|
+
if ('external' === next) return [
|
|
1254
|
+
{
|
|
1255
|
+
kind: 'external',
|
|
1256
|
+
specifier,
|
|
1257
|
+
name,
|
|
1258
|
+
members
|
|
1259
|
+
}
|
|
1260
|
+
];
|
|
1261
|
+
return (next && exportValues(next, name, members)) ?? unresolved(module, at);
|
|
1262
|
+
};
|
|
1263
|
+
const exportValues = (module, name, members)=>{
|
|
1264
|
+
const key = `export:${module.path}#${name}:${members.join('.')}`;
|
|
1265
|
+
if (active.has(key)) return;
|
|
1266
|
+
if (++steps > MAX_LOOKUPS || active.size >= MAX_DEPTH) return unresolved(module, module.file);
|
|
1267
|
+
active.add(key);
|
|
1268
|
+
try {
|
|
1269
|
+
return exportedValues(module, name, members);
|
|
1270
|
+
} finally{
|
|
1271
|
+
active.delete(key);
|
|
1272
|
+
}
|
|
1273
|
+
};
|
|
1274
|
+
const exportedValues = (module, name, members)=>{
|
|
1275
|
+
const hop = exportHop(module.file, name);
|
|
1276
|
+
if (hop?.kind === 'local') {
|
|
1277
|
+
const binding = factsOf(module).scope.getBinding(hop.name);
|
|
1278
|
+
return binding ? bindingValues(module, binding, members, binding.identifier) : unresolved(module, module.file);
|
|
1279
|
+
}
|
|
1280
|
+
if (hop?.kind === 'reexport') return importValues(module, hop.specifier, hop.name, members, module.file);
|
|
1281
|
+
if (hop?.kind === 'namespace') return namespaceValues(module, hop.specifier, members, module.file);
|
|
1282
|
+
if (hop?.kind === 'node') return values(module, hop.node, members);
|
|
1283
|
+
for (const specifier of starSources(module.file, name)){
|
|
1284
|
+
const next = follow(module, specifier);
|
|
1285
|
+
const found = void 0 === next || 'external' === next ? void 0 : exportValues(next, name, members);
|
|
1286
|
+
if (void 0 !== found) return found;
|
|
1287
|
+
}
|
|
1288
|
+
return commonJsExport(module, name, members);
|
|
1289
|
+
};
|
|
1290
|
+
const commonJsExport = (module, name, members)=>{
|
|
1291
|
+
const found = [];
|
|
1292
|
+
for (const [requested, explicit] of 'default' === name ? [
|
|
1293
|
+
[
|
|
1294
|
+
[
|
|
1295
|
+
...members
|
|
1296
|
+
],
|
|
1297
|
+
false
|
|
1298
|
+
],
|
|
1299
|
+
[
|
|
1300
|
+
[
|
|
1301
|
+
'default',
|
|
1302
|
+
...members
|
|
1303
|
+
],
|
|
1304
|
+
true
|
|
1305
|
+
]
|
|
1306
|
+
] : [
|
|
1307
|
+
[
|
|
1308
|
+
[
|
|
1309
|
+
name,
|
|
1310
|
+
...members
|
|
1311
|
+
],
|
|
1312
|
+
false
|
|
1313
|
+
]
|
|
1314
|
+
])for (const write of factsOf(module).commonJs){
|
|
1315
|
+
if (explicit && 0 === write.path.length) continue;
|
|
1316
|
+
const reads = write.path.length <= requested.length;
|
|
1317
|
+
const [shorter, longer] = reads ? [
|
|
1318
|
+
write.path,
|
|
1319
|
+
requested
|
|
1320
|
+
] : [
|
|
1321
|
+
requested,
|
|
1322
|
+
write.path
|
|
1323
|
+
];
|
|
1324
|
+
if (!(!reads && !walking || shorter.some((key, index)=>longer[index] !== key))) found.push(...write.dynamic || !write.value ? unresolved(module, write.node) : values(module, write.value, [
|
|
1325
|
+
...write.from ?? [],
|
|
1326
|
+
...reads ? requested.slice(write.path.length) : []
|
|
1327
|
+
]));
|
|
1328
|
+
}
|
|
1329
|
+
return found.length > 0 ? found : void 0;
|
|
1330
|
+
};
|
|
1331
|
+
const bindingValues = (module, binding, members, at)=>{
|
|
1332
|
+
const moduleFacts = factsOf(module);
|
|
1333
|
+
if (binding.scope === moduleFacts.scope && moduleFacts.merged.has(binding.identifier.name)) return unresolved(module, at);
|
|
1334
|
+
const found = [];
|
|
1335
|
+
const node = binding.path.node;
|
|
1336
|
+
if ('module' === binding.kind) {
|
|
1337
|
+
const imported = importOf(binding);
|
|
1338
|
+
found.push(...void 0 === imported ? unresolved(module, at) : importValues(module, imported.specifier, imported.name, members, binding.path.parent));
|
|
1339
|
+
} else if (__rspack_external__babel_types_6e8337dd.isVariableDeclarator(node)) {
|
|
1340
|
+
const route = patternPath(node.id, binding.identifier);
|
|
1341
|
+
const rest = 'dynamic' === route && node.init && members.length > 0 ? objectRestPath(node.id, binding.identifier) : void 0;
|
|
1342
|
+
if (rest && !rest.excluded.has(members[0])) found.push(...values(module, node.init, [
|
|
1343
|
+
...rest.members,
|
|
1344
|
+
...members
|
|
1345
|
+
]));
|
|
1346
|
+
else if (void 0 === route || 'dynamic' === route) found.push(...unresolved(module, at));
|
|
1347
|
+
else {
|
|
1348
|
+
if (node.init) found.push(...values(module, node.init, [
|
|
1349
|
+
...route.members,
|
|
1350
|
+
...members
|
|
1351
|
+
]));
|
|
1352
|
+
else if (0 === binding.constantViolations.length || __rspack_external__babel_types_6e8337dd.isForXStatement(binding.path.parentPath?.parent)) found.push(...unresolved(module, at));
|
|
1353
|
+
for (const fallback of route.defaults)found.push(...values(module, fallback.value, [
|
|
1354
|
+
...route.members.slice(fallback.members.length),
|
|
1355
|
+
...members
|
|
1356
|
+
]));
|
|
1357
|
+
}
|
|
1358
|
+
} else if (__rspack_external__babel_types_6e8337dd.isClassDeclaration(node) && members.length > 0) found.push(...staticMemberValues(module, node, members));
|
|
1359
|
+
else if (__rspack_external__babel_types_6e8337dd.isFunctionDeclaration(node) || __rspack_external__babel_types_6e8337dd.isClassDeclaration(node)) found.push(...0 === members.length ? [
|
|
1360
|
+
{
|
|
1361
|
+
kind: 'node',
|
|
1362
|
+
node,
|
|
1363
|
+
module
|
|
1364
|
+
}
|
|
1365
|
+
] : unresolved(module, at));
|
|
1366
|
+
else {
|
|
1367
|
+
const parameter = 'param' === binding.kind ? frame.parameters.get(binding) : void 0;
|
|
1368
|
+
const route = parameter ? patternPath(parameter.pattern, binding.identifier) : void 0;
|
|
1369
|
+
if (parameter && route && 'dynamic' !== route) {
|
|
1370
|
+
const { argument } = parameter;
|
|
1371
|
+
if (argument) {
|
|
1372
|
+
const current = frame;
|
|
1373
|
+
frame = parameter.context;
|
|
1374
|
+
try {
|
|
1375
|
+
found.push(...values(argument.module, argument.node, [
|
|
1376
|
+
...route.members,
|
|
1377
|
+
...members
|
|
1378
|
+
]));
|
|
1379
|
+
} finally{
|
|
1380
|
+
frame = current;
|
|
1381
|
+
}
|
|
1382
|
+
} else if (0 === route.defaults.length) found.push(...unresolved(module, at));
|
|
1383
|
+
for (const fallback of route.defaults)found.push(...values(module, fallback.value, [
|
|
1384
|
+
...route.members.slice(fallback.members.length),
|
|
1385
|
+
...members
|
|
1386
|
+
]));
|
|
1387
|
+
} else found.push(...unresolved(module, at));
|
|
1388
|
+
}
|
|
1389
|
+
for (const violation of binding.constantViolations){
|
|
1390
|
+
const write = violation.node;
|
|
1391
|
+
const target = __rspack_external__babel_types_6e8337dd.isAssignmentExpression(write) && [
|
|
1392
|
+
'=',
|
|
1393
|
+
'&&=',
|
|
1394
|
+
'||=',
|
|
1395
|
+
'??='
|
|
1396
|
+
].includes(write.operator) ? __rspack_external__babel_types_6e8337dd.getBindingIdentifiers(write.left)[binding.identifier.name] : void 0;
|
|
1397
|
+
const route = target && __rspack_external__babel_types_6e8337dd.isAssignmentExpression(write) ? patternPath(write.left, target) : void 0;
|
|
1398
|
+
if (!route || 'dynamic' === route || !__rspack_external__babel_types_6e8337dd.isAssignmentExpression(write)) {
|
|
1399
|
+
found.push(...unresolved(module, write));
|
|
1400
|
+
continue;
|
|
1401
|
+
}
|
|
1402
|
+
found.push(...values(module, write.right, [
|
|
1403
|
+
...route.members,
|
|
1404
|
+
...members
|
|
1405
|
+
]));
|
|
1406
|
+
for (const fallback of route.defaults)found.push(...values(module, fallback.value, [
|
|
1407
|
+
...route.members.slice(fallback.members.length),
|
|
1408
|
+
...members
|
|
1409
|
+
]));
|
|
1410
|
+
}
|
|
1411
|
+
const aliases = aliasesOf(binding, moduleFacts.writes);
|
|
1412
|
+
if (!aliases) found.push(...unresolved(module, at));
|
|
1413
|
+
for (const write of (aliases ?? []).flatMap((alias)=>(moduleFacts.writes.get(alias.binding) ?? []).map((entry)=>({
|
|
1414
|
+
...entry,
|
|
1415
|
+
path: [
|
|
1416
|
+
...alias.prefix,
|
|
1417
|
+
...entry.path
|
|
1418
|
+
]
|
|
1419
|
+
})))){
|
|
1420
|
+
const reads = write.dynamic ? write.path.length < members.length : write.path.length <= members.length;
|
|
1421
|
+
const [shorter, longer] = reads ? [
|
|
1422
|
+
write.path,
|
|
1423
|
+
members
|
|
1424
|
+
] : [
|
|
1425
|
+
members,
|
|
1426
|
+
write.path
|
|
1427
|
+
];
|
|
1428
|
+
if (!(!reads && !walking || shorter.some((name, index)=>longer[index] !== name))) {
|
|
1429
|
+
if (write.dynamic && reads) found.push(...unresolved(module, write.node));
|
|
1430
|
+
found.push(...void 0 === write.value ? unresolved(module, write.node) : values(module, write.value, [
|
|
1431
|
+
...write.from ?? [],
|
|
1432
|
+
...reads ? members.slice(write.path.length + (write.dynamic ? 1 : 0)) : []
|
|
1433
|
+
]));
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
return found;
|
|
1437
|
+
};
|
|
1438
|
+
const propertyValues = (module, object, members)=>{
|
|
1439
|
+
const [name, ...rest] = members;
|
|
1440
|
+
const found = [];
|
|
1441
|
+
for (const property of object.properties.toReversed()){
|
|
1442
|
+
if (__rspack_external__babel_types_6e8337dd.isSpreadElement(property)) {
|
|
1443
|
+
found.push(values(module, property.argument, members));
|
|
1444
|
+
const spread = values(module, property.argument, []);
|
|
1445
|
+
if (void 0 !== name && spread.length > 0 && spread.every((value)=>'node' === value.kind && __rspack_external__babel_types_6e8337dd.isObjectExpression(value.node) && value.node.properties.some((entry)=>!__rspack_external__babel_types_6e8337dd.isSpreadElement(entry) && (staticKey(entry) ?? (entry.computed ? constantString(value.module, entry.key) : void 0)) === name && !(__rspack_external__babel_types_6e8337dd.isObjectMethod(entry) && 'set' === entry.kind)))) break;
|
|
1446
|
+
continue;
|
|
1447
|
+
}
|
|
1448
|
+
const key = staticKey(property) ?? (property.computed ? constantString(module, property.key) : void 0);
|
|
1449
|
+
if (void 0 === key) {
|
|
1450
|
+
found.push(unresolved(module, property));
|
|
1451
|
+
continue;
|
|
1452
|
+
}
|
|
1453
|
+
if (key === name) {
|
|
1454
|
+
found.push(__rspack_external__babel_types_6e8337dd.isObjectMethod(property) ? 'get' === property.kind ? returnValues(module, property, rest) : 0 === rest.length ? [
|
|
1455
|
+
{
|
|
1456
|
+
kind: 'node',
|
|
1457
|
+
node: property,
|
|
1458
|
+
module
|
|
1459
|
+
}
|
|
1460
|
+
] : unresolved(module, property) : values(module, property.value, rest));
|
|
1461
|
+
if (!__rspack_external__babel_types_6e8337dd.isObjectMethod(property) || 'set' !== property.kind) break;
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
const ordered = found.toReversed().flat();
|
|
1465
|
+
return ordered.length > 0 ? ordered : unresolved(module, object);
|
|
1466
|
+
};
|
|
1467
|
+
const staticMemberValues = (module, declaration, members)=>{
|
|
1468
|
+
const [name, ...rest] = members;
|
|
1469
|
+
const found = [];
|
|
1470
|
+
let definite = false;
|
|
1471
|
+
for (const member of declaration.body.body.toReversed()){
|
|
1472
|
+
if (definite) break;
|
|
1473
|
+
if (__rspack_external__babel_types_6e8337dd.isStaticBlock(member)) {
|
|
1474
|
+
found.push(...unresolved(module, member));
|
|
1475
|
+
continue;
|
|
1476
|
+
}
|
|
1477
|
+
if (!(__rspack_external__babel_types_6e8337dd.isClassProperty(member) || __rspack_external__babel_types_6e8337dd.isClassAccessorProperty(member) || __rspack_external__babel_types_6e8337dd.isClassMethod(member)) || !member.static) continue;
|
|
1478
|
+
const key = staticKey(member) ?? (member.computed ? constantString(module, member.key) : void 0);
|
|
1479
|
+
if (void 0 === key) {
|
|
1480
|
+
found.push(...unresolved(module, member));
|
|
1481
|
+
continue;
|
|
1482
|
+
}
|
|
1483
|
+
if (key === name) {
|
|
1484
|
+
if (__rspack_external__babel_types_6e8337dd.isClassProperty(member) || __rspack_external__babel_types_6e8337dd.isClassAccessorProperty(member)) {
|
|
1485
|
+
definite = true;
|
|
1486
|
+
found.push(...member.value ? values(module, member.value, rest) : unresolved(module, member));
|
|
1487
|
+
} else if ('get' === member.kind) {
|
|
1488
|
+
definite = true;
|
|
1489
|
+
found.push(...returnValues(module, member, rest));
|
|
1490
|
+
} else if ('method' === member.kind) {
|
|
1491
|
+
definite = true;
|
|
1492
|
+
found.push(...0 === rest.length ? [
|
|
1493
|
+
{
|
|
1494
|
+
kind: 'node',
|
|
1495
|
+
node: member,
|
|
1496
|
+
module
|
|
1497
|
+
}
|
|
1498
|
+
] : unresolved(module, member));
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
if (!definite || declaration.superClass) found.push(...unresolved(module, declaration));
|
|
1503
|
+
return found;
|
|
1504
|
+
};
|
|
1505
|
+
const returnValues = (module, fn, members)=>{
|
|
1506
|
+
const body = fn.body;
|
|
1507
|
+
if (__rspack_external__babel_types_6e8337dd.isExpression(body)) return values(module, body, members);
|
|
1508
|
+
const moduleFacts = factsOf(module);
|
|
1509
|
+
const found = moduleFacts.bareReturns.has(fn) || !(__rspack_external__babel_types_6e8337dd.isReturnStatement(body.body.at(-1)) || __rspack_external__babel_types_6e8337dd.isThrowStatement(body.body.at(-1))) ? unresolved(module, fn) : [];
|
|
1510
|
+
for (const expression of moduleFacts.returns.get(fn) ?? [])found.push(...values(module, expression, members));
|
|
1511
|
+
return found;
|
|
1512
|
+
};
|
|
1513
|
+
const callable = (value)=>'external' === value.kind || 'node' === value.kind && __rspack_external__babel_types_6e8337dd.isFunction(value.node);
|
|
1514
|
+
const callValues = (module, call, members)=>{
|
|
1515
|
+
const found = [];
|
|
1516
|
+
let terminal = false;
|
|
1517
|
+
const argumentsOf = (args)=>args.map((node)=>({
|
|
1518
|
+
module,
|
|
1519
|
+
node,
|
|
1520
|
+
context: frame
|
|
1521
|
+
}));
|
|
1522
|
+
const run = (callee, callArgs)=>{
|
|
1523
|
+
const args = [
|
|
1524
|
+
...boundArguments.get(callee) ?? [],
|
|
1525
|
+
...callArgs
|
|
1526
|
+
];
|
|
1527
|
+
if ('unresolved' === callee.kind) return void found.push(...unresolved(module, call));
|
|
1528
|
+
if ('node' !== callee.kind || !__rspack_external__babel_types_6e8337dd.isFunction(callee.node)) {
|
|
1529
|
+
terminal = true;
|
|
1530
|
+
return;
|
|
1531
|
+
}
|
|
1532
|
+
const outer = frame;
|
|
1533
|
+
const parameters = new Map([
|
|
1534
|
+
...outer.parameters,
|
|
1535
|
+
...closureFrames.get(callee)?.parameters ?? []
|
|
1536
|
+
]);
|
|
1537
|
+
const fnScope = factsOf(callee.module).functionScopes.get(callee.node);
|
|
1538
|
+
const spread = args.findIndex(({ node })=>__rspack_external__babel_types_6e8337dd.isSpreadElement(node) || __rspack_external__babel_types_6e8337dd.isArgumentPlaceholder(node));
|
|
1539
|
+
callee.node.params.forEach((param, index)=>{
|
|
1540
|
+
if (-1 !== spread && index >= spread) return;
|
|
1541
|
+
const remaining = args.slice(index);
|
|
1542
|
+
const restArray = __rspack_external__babel_types_6e8337dd.isRestElement(param) && __rspack_external__babel_types_6e8337dd.isIdentifier(param.argument) && remaining.every(({ module: from, context })=>from === remaining[0]?.module && context === remaining[0]?.context) ? {
|
|
1543
|
+
...__rspack_external__babel_types_6e8337dd.arrayExpression(remaining.map(({ node })=>node)),
|
|
1544
|
+
start: param.start,
|
|
1545
|
+
end: param.end
|
|
1546
|
+
} : void 0;
|
|
1547
|
+
if (restArray && __rspack_external__babel_types_6e8337dd.isRestElement(param)) {
|
|
1548
|
+
const binding = fnScope?.getOwnBinding(param.argument.name);
|
|
1549
|
+
if (binding) parameters.set(binding, {
|
|
1550
|
+
pattern: param.argument,
|
|
1551
|
+
argument: {
|
|
1552
|
+
module: remaining[0]?.module ?? module,
|
|
1553
|
+
node: restArray
|
|
1554
|
+
},
|
|
1555
|
+
context: remaining[0]?.context ?? outer
|
|
1556
|
+
});
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1559
|
+
const argument = args[index];
|
|
1560
|
+
for (const name of Object.keys(__rspack_external__babel_types_6e8337dd.getBindingIdentifiers(param))){
|
|
1561
|
+
const binding = fnScope?.getOwnBinding(name);
|
|
1562
|
+
if (binding) parameters.set(binding, {
|
|
1563
|
+
pattern: param,
|
|
1564
|
+
argument: argument ? {
|
|
1565
|
+
module: argument.module,
|
|
1566
|
+
node: argument.node
|
|
1567
|
+
} : void 0,
|
|
1568
|
+
context: argument?.context ?? outer
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
});
|
|
1572
|
+
const inner = {
|
|
1573
|
+
id: frames += 1,
|
|
1574
|
+
parameters
|
|
1575
|
+
};
|
|
1576
|
+
frame = inner;
|
|
1577
|
+
try {
|
|
1578
|
+
for (const value of returnValues(callee.module, callee.node, members))if ('node' === value.kind && __rspack_external__babel_types_6e8337dd.isFunction(value.node)) {
|
|
1579
|
+
const closure = {
|
|
1580
|
+
...value
|
|
1581
|
+
};
|
|
1582
|
+
closureFrames.set(closure, inner);
|
|
1583
|
+
const bound = boundArguments.get(value);
|
|
1584
|
+
if (bound) boundArguments.set(closure, bound);
|
|
1585
|
+
found.push(closure);
|
|
1586
|
+
} else found.push(value);
|
|
1587
|
+
} finally{
|
|
1588
|
+
frame = outer;
|
|
1589
|
+
}
|
|
1590
|
+
};
|
|
1591
|
+
const via = unwrapExpression(call.callee, true);
|
|
1592
|
+
const invocation = (__rspack_external__babel_types_6e8337dd.isMemberExpression(via) || __rspack_external__babel_types_6e8337dd.isOptionalMemberExpression(via)) && [
|
|
1593
|
+
'call',
|
|
1594
|
+
'apply',
|
|
1595
|
+
'bind'
|
|
1596
|
+
].includes(staticKey(via) ?? '') ? {
|
|
1597
|
+
name: staticKey(via),
|
|
1598
|
+
object: via.object
|
|
1599
|
+
} : void 0;
|
|
1600
|
+
const reflected = (__rspack_external__babel_types_6e8337dd.isMemberExpression(via) || __rspack_external__babel_types_6e8337dd.isOptionalMemberExpression(via)) && __rspack_external__babel_types_6e8337dd.isIdentifier(via.object, {
|
|
1601
|
+
name: 'Reflect'
|
|
1602
|
+
}) && 'apply' === staticKey(via) && !(factsOf(module).references.get(via.object) ?? factsOf(module).scope.getBinding('Reflect')) && void 0 !== call.arguments[0];
|
|
1603
|
+
if (reflected) {
|
|
1604
|
+
const listed = call.arguments[2];
|
|
1605
|
+
const list = __rspack_external__babel_types_6e8337dd.isArrayExpression(listed) && listed.elements.every((element)=>null !== element && !__rspack_external__babel_types_6e8337dd.isSpreadElement(element)) ? listed.elements : void 0;
|
|
1606
|
+
for (const callee of values(module, call.arguments[0], []))if (list) run(callee, argumentsOf(list));
|
|
1607
|
+
else found.push(...unresolved(module, call));
|
|
1608
|
+
} else if (invocation) {
|
|
1609
|
+
const receivers = values(module, invocation.object, []);
|
|
1610
|
+
if (!receivers.every(callable)) for (const callee of values(module, invocation.object, [
|
|
1611
|
+
invocation.name
|
|
1612
|
+
]))run(callee, argumentsOf(call.arguments));
|
|
1613
|
+
for (const receiver of receivers.filter(callable)){
|
|
1614
|
+
if ('bind' === invocation.name) {
|
|
1615
|
+
if (members.length > 0) {
|
|
1616
|
+
found.push(...unresolved(module, call));
|
|
1617
|
+
continue;
|
|
1618
|
+
}
|
|
1619
|
+
const bound = argumentsOf(call.arguments.slice(1));
|
|
1620
|
+
if (0 === bound.length) {
|
|
1621
|
+
found.push(receiver);
|
|
1622
|
+
continue;
|
|
1623
|
+
}
|
|
1624
|
+
const boundReceiver = {
|
|
1625
|
+
...receiver
|
|
1626
|
+
};
|
|
1627
|
+
const closure = closureFrames.get(receiver);
|
|
1628
|
+
if (closure) closureFrames.set(boundReceiver, closure);
|
|
1629
|
+
boundArguments.set(boundReceiver, [
|
|
1630
|
+
...boundArguments.get(receiver) ?? [],
|
|
1631
|
+
...bound
|
|
1632
|
+
]);
|
|
1633
|
+
found.push(boundReceiver);
|
|
1634
|
+
continue;
|
|
1635
|
+
}
|
|
1636
|
+
const listed = call.arguments[1];
|
|
1637
|
+
run(receiver, argumentsOf('call' === invocation.name ? call.arguments.slice(1) : __rspack_external__babel_types_6e8337dd.isArrayExpression(listed) && listed.elements.every((element)=>null !== element && !__rspack_external__babel_types_6e8337dd.isSpreadElement(element)) ? listed.elements : []));
|
|
1638
|
+
}
|
|
1639
|
+
} else for (const callee of values(module, call.callee, []))run(callee, argumentsOf(call.arguments));
|
|
1640
|
+
if (terminal) found.push(...0 === members.length ? [
|
|
1641
|
+
{
|
|
1642
|
+
kind: 'node',
|
|
1643
|
+
node: call,
|
|
1644
|
+
module
|
|
1645
|
+
}
|
|
1646
|
+
] : unresolved(module, call));
|
|
1647
|
+
return found;
|
|
1648
|
+
};
|
|
1649
|
+
const constantString = (module, expression, depth = 0)=>{
|
|
1650
|
+
const node = unwrapExpression(expression, true);
|
|
1651
|
+
if (depth > MAX_DEPTH) return;
|
|
1652
|
+
if (__rspack_external__babel_types_6e8337dd.isStringLiteral(node)) return node.value;
|
|
1653
|
+
if (__rspack_external__babel_types_6e8337dd.isNumericLiteral(node)) return String(node.value);
|
|
1654
|
+
if (__rspack_external__babel_types_6e8337dd.isTemplateLiteral(node) && 0 === node.expressions.length) return node.quasis[0]?.value.cooked ?? void 0;
|
|
1655
|
+
if (__rspack_external__babel_types_6e8337dd.isBinaryExpression(node, {
|
|
1656
|
+
operator: '+'
|
|
1657
|
+
})) {
|
|
1658
|
+
const left = constantString(module, node.left, depth + 1);
|
|
1659
|
+
const right = constantString(module, node.right, depth + 1);
|
|
1660
|
+
return void 0 === left || void 0 === right ? void 0 : left + right;
|
|
1661
|
+
}
|
|
1662
|
+
if (!__rspack_external__babel_types_6e8337dd.isIdentifier(node)) return;
|
|
1663
|
+
const binding = factsOf(module).references.get(node) ?? factsOf(module).scope.getBinding(node.name);
|
|
1664
|
+
const declarator = binding?.path.node;
|
|
1665
|
+
return binding?.kind === 'const' && __rspack_external__babel_types_6e8337dd.isVariableDeclarator(declarator) && declarator.id === binding.identifier && declarator.init ? constantString(module, declarator.init, depth + 1) : void 0;
|
|
1666
|
+
};
|
|
1667
|
+
const values = (module, expression, members)=>{
|
|
1668
|
+
const node = unwrapExpression(expression, true);
|
|
1669
|
+
const key = `${frame.id}:${module.path}:${node.start}:${node.end}:${node.type}:${members.join('.')}`;
|
|
1670
|
+
if (active.has(key)) return unresolved(module, node);
|
|
1671
|
+
if (++steps > MAX_LOOKUPS || active.size >= MAX_DEPTH) return unresolved(module, node);
|
|
1672
|
+
active.add(key);
|
|
1673
|
+
try {
|
|
1674
|
+
if (__rspack_external__babel_types_6e8337dd.isIdentifier(node) || __rspack_external__babel_types_6e8337dd.isJSXIdentifier(node)) {
|
|
1675
|
+
const binding = factsOf(module).references.get(node) ?? factsOf(module).scope.getBinding(node.name);
|
|
1676
|
+
return binding ? bindingValues(module, binding, members, node) : unresolved(module, node);
|
|
1677
|
+
}
|
|
1678
|
+
if (__rspack_external__babel_types_6e8337dd.isJSXMemberExpression(node)) return values(module, node.object, [
|
|
1679
|
+
node.property.name,
|
|
1680
|
+
...members
|
|
1681
|
+
]);
|
|
1682
|
+
if (__rspack_external__babel_types_6e8337dd.isMemberExpression(node) || __rspack_external__babel_types_6e8337dd.isOptionalMemberExpression(node)) {
|
|
1683
|
+
const name = staticKey(node) ?? (node.computed ? constantString(module, node.property) : void 0);
|
|
1684
|
+
if (void 0 === name) return unresolved(module, node);
|
|
1685
|
+
if (0 === members.length && [
|
|
1686
|
+
'call',
|
|
1687
|
+
'apply',
|
|
1688
|
+
'bind'
|
|
1689
|
+
].includes(name)) {
|
|
1690
|
+
const receivers = values(module, node.object, []);
|
|
1691
|
+
const functions = receivers.filter(callable);
|
|
1692
|
+
return functions.length === receivers.length ? functions : [
|
|
1693
|
+
...functions,
|
|
1694
|
+
...values(module, node.object, [
|
|
1695
|
+
name
|
|
1696
|
+
])
|
|
1697
|
+
];
|
|
1698
|
+
}
|
|
1699
|
+
return values(module, node.object, [
|
|
1700
|
+
name,
|
|
1701
|
+
...members
|
|
1702
|
+
]);
|
|
1703
|
+
}
|
|
1704
|
+
if (__rspack_external__babel_types_6e8337dd.isImportExpression(node) && __rspack_external__babel_types_6e8337dd.isStringLiteral(node.source)) return namespaceValues(module, node.source.value, members, node);
|
|
1705
|
+
if (__rspack_external__babel_types_6e8337dd.isCallExpression(node) && __rspack_external__babel_types_6e8337dd.isIdentifier(node.callee, {
|
|
1706
|
+
name: 'require'
|
|
1707
|
+
}) && !(factsOf(module).references.has(node.callee) ? factsOf(module).references.get(node.callee) : factsOf(module).scope.getBinding('require')) && 1 === node.arguments.length && __rspack_external__babel_types_6e8337dd.isStringLiteral(node.arguments[0])) return namespaceValues(module, node.arguments[0].value, members, node);
|
|
1708
|
+
if (__rspack_external__babel_types_6e8337dd.isCallExpression(node) || __rspack_external__babel_types_6e8337dd.isOptionalCallExpression(node)) return callValues(module, node, members);
|
|
1709
|
+
if (__rspack_external__babel_types_6e8337dd.isConditionalExpression(node)) return [
|
|
1710
|
+
...values(module, node.consequent, members),
|
|
1711
|
+
...values(module, node.alternate, members)
|
|
1712
|
+
];
|
|
1713
|
+
if (__rspack_external__babel_types_6e8337dd.isLogicalExpression(node)) return [
|
|
1714
|
+
...values(module, node.left, members),
|
|
1715
|
+
...values(module, node.right, members)
|
|
1716
|
+
];
|
|
1717
|
+
if (__rspack_external__babel_types_6e8337dd.isAwaitExpression(node)) return values(module, node.argument, members);
|
|
1718
|
+
if (__rspack_external__babel_types_6e8337dd.isAssignmentExpression(node)) return '=' === node.operator ? values(module, node.right, members) : [
|
|
1719
|
+
'&&=',
|
|
1720
|
+
'||=',
|
|
1721
|
+
'??='
|
|
1722
|
+
].includes(node.operator) ? [
|
|
1723
|
+
...values(module, node.left, members),
|
|
1724
|
+
...values(module, node.right, members)
|
|
1725
|
+
] : unresolved(module, node);
|
|
1726
|
+
if (__rspack_external__babel_types_6e8337dd.isSequenceExpression(node)) return values(module, node.expressions.at(-1), members);
|
|
1727
|
+
if (0 === members.length) return [
|
|
1728
|
+
{
|
|
1729
|
+
kind: 'node',
|
|
1730
|
+
node,
|
|
1731
|
+
module
|
|
1732
|
+
}
|
|
1733
|
+
];
|
|
1734
|
+
if (__rspack_external__babel_types_6e8337dd.isObjectExpression(node)) return propertyValues(module, node, members);
|
|
1735
|
+
if (__rspack_external__babel_types_6e8337dd.isClassExpression(node) || __rspack_external__babel_types_6e8337dd.isClassDeclaration(node)) return staticMemberValues(module, node, members);
|
|
1736
|
+
const [index, ...rest] = members;
|
|
1737
|
+
const element = __rspack_external__babel_types_6e8337dd.isArrayExpression(node) && void 0 !== index && /^\d+$/u.test(index) ? node.elements.slice(0, Number(index) + 1) : void 0;
|
|
1738
|
+
return element && element.length === Number(index) + 1 && !element.some((item)=>__rspack_external__babel_types_6e8337dd.isSpreadElement(item)) && element.at(-1) ? values(module, element.at(-1), rest) : unresolved(module, node);
|
|
1739
|
+
} finally{
|
|
1740
|
+
active.delete(key);
|
|
1741
|
+
}
|
|
1742
|
+
};
|
|
1743
|
+
const reachable = (module, expression)=>{
|
|
1744
|
+
const found = [];
|
|
1745
|
+
const walked = new Set();
|
|
1746
|
+
const pending = [
|
|
1747
|
+
[
|
|
1748
|
+
module,
|
|
1749
|
+
expression
|
|
1750
|
+
]
|
|
1751
|
+
];
|
|
1752
|
+
const walk = (owner, node)=>pending.push([
|
|
1753
|
+
owner,
|
|
1754
|
+
node
|
|
1755
|
+
]);
|
|
1756
|
+
for(let next = pending.pop(); next; next = pending.pop()){
|
|
1757
|
+
const [owner, node] = next;
|
|
1758
|
+
const key = `${owner.path}:${node.start}:${node.end}:${node.type}`;
|
|
1759
|
+
if (walked.has(key)) continue;
|
|
1760
|
+
walked.add(key);
|
|
1761
|
+
if (walked.size > MAX_LOOKUPS) {
|
|
1762
|
+
found.push(...unresolved(owner, node));
|
|
1763
|
+
continue;
|
|
1764
|
+
}
|
|
1765
|
+
const reference = (__rspack_external__babel_types_6e8337dd.isIdentifier(node) || __rspack_external__babel_types_6e8337dd.isJSXIdentifier(node)) && factsOf(owner).references.has(node) || __rspack_external__babel_types_6e8337dd.isJSXMemberExpression(node) || __rspack_external__babel_types_6e8337dd.isMemberExpression(node) || __rspack_external__babel_types_6e8337dd.isOptionalMemberExpression(node);
|
|
1766
|
+
const call = __rspack_external__babel_types_6e8337dd.isCallExpression(node) || __rspack_external__babel_types_6e8337dd.isOptionalCallExpression(node);
|
|
1767
|
+
if (reference || call) {
|
|
1768
|
+
steps = 0;
|
|
1769
|
+
const evaluated = values(owner, node, []);
|
|
1770
|
+
for (const value of evaluated)if ('node' !== value.kind) found.push(value);
|
|
1771
|
+
else if (value.node !== node) walk(value.module, value.node);
|
|
1772
|
+
if (reference) {
|
|
1773
|
+
if ((__rspack_external__babel_types_6e8337dd.isMemberExpression(node) || __rspack_external__babel_types_6e8337dd.isOptionalMemberExpression(node) || __rspack_external__babel_types_6e8337dd.isJSXMemberExpression(node)) && evaluated.some((value)=>'unresolved' === value.kind)) {
|
|
1774
|
+
walk(owner, node.object);
|
|
1775
|
+
if (!__rspack_external__babel_types_6e8337dd.isJSXMemberExpression(node) && node.computed) walk(owner, node.property);
|
|
1776
|
+
}
|
|
1777
|
+
continue;
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
if (!(__rspack_external__babel_types_6e8337dd.isIdentifier(node) || node.type.startsWith('TS') && !__rspack_external__babel_types_6e8337dd.isExpression(node))) for (const field of __rspack_external__babel_types_6e8337dd.VISITOR_KEYS[node.type] ?? []){
|
|
1781
|
+
if (/^(?:typeAnnotation|returnType|typeParameters|typeArguments|superTypeParameters)$/u.test(field)) continue;
|
|
1782
|
+
const child = node[field];
|
|
1783
|
+
for (const item of Array.isArray(child) ? child : [
|
|
1784
|
+
child
|
|
1785
|
+
])if (__rspack_external__babel_types_6e8337dd.isNode(item)) walk(owner, item);
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
return found;
|
|
1789
|
+
};
|
|
1790
|
+
return {
|
|
1791
|
+
values,
|
|
1792
|
+
reachable
|
|
1793
|
+
};
|
|
1794
|
+
};
|
|
1795
|
+
return {
|
|
1796
|
+
module: (filePath)=>load(filePath),
|
|
1797
|
+
resolve: (module, name, scope)=>resolveBinding(module, name, scope, [], new Set()),
|
|
1798
|
+
resolveReference,
|
|
1799
|
+
isUnboundReference,
|
|
1800
|
+
evaluate: (module, expression)=>evaluation(false).values(module, expression, []),
|
|
1801
|
+
reachable: (module, expression)=>evaluation(true).reachable(module, expression)
|
|
1802
|
+
};
|
|
1803
|
+
}
|
|
1804
|
+
export { createModuleGraph, exportedConst, localConst, propertyName };
|