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