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