@bleedingdev/modern-js-code-tools 3.9.0-ultramodern.9 → 3.9.3-ultramodern.10

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