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