@rollup/wasm-node 4.25.0-0 → 4.25.0

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.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v4.25.0-0
4
- Tue, 29 Oct 2024 06:14:37 GMT - commit b7fcaba12e863db516f39de74c1eacfe5329a5c3
3
+ Rollup.js v4.25.0
4
+ Sat, 09 Nov 2024 08:36:52 GMT - commit 42e587e0e37bc0661aa39fe7ad6f1d7fd33f825c
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -31,7 +31,7 @@ function _interopNamespaceDefault(e) {
31
31
 
32
32
  const tty__namespace = /*#__PURE__*/_interopNamespaceDefault(tty);
33
33
 
34
- var version = "4.25.0-0";
34
+ var version = "4.25.0";
35
35
 
36
36
  function ensureArray$1(items) {
37
37
  if (Array.isArray(items)) {
@@ -1379,6 +1379,7 @@ async function mergeOutputOptions(config, overrides, log) {
1379
1379
  sanitizeFileName: getOption('sanitizeFileName'),
1380
1380
  sourcemap: getOption('sourcemap'),
1381
1381
  sourcemapBaseUrl: getOption('sourcemapBaseUrl'),
1382
+ sourcemapDebugIds: getOption('sourcemapDebugIds'),
1382
1383
  sourcemapExcludeSources: getOption('sourcemapExcludeSources'),
1383
1384
  sourcemapFile: getOption('sourcemapFile'),
1384
1385
  sourcemapFileNames: getOption('sourcemapFileNames'),
@@ -3594,7 +3595,7 @@ const UNKNOWN_PATH = [UnknownKey];
3594
3595
  const UNKNOWN_NON_ACCESSOR_PATH = [UnknownNonAccessorKey];
3595
3596
  const UNKNOWN_INTEGER_PATH = [UnknownInteger];
3596
3597
  const EntitiesKey = Symbol('Entities');
3597
- class EntityPathTracker {
3598
+ class PathTracker {
3598
3599
  constructor() {
3599
3600
  this.entityPaths = Object.create(null, {
3600
3601
  [EntitiesKey]: { value: new Set() }
@@ -3619,14 +3620,14 @@ class EntityPathTracker {
3619
3620
  getEntities(path) {
3620
3621
  let currentPaths = this.entityPaths;
3621
3622
  for (const pathSegment of path) {
3622
- currentPaths = currentPaths[pathSegment] ||= Object.create(null, {
3623
- [EntitiesKey]: { value: new Set() }
3624
- });
3623
+ currentPaths = currentPaths[pathSegment] =
3624
+ currentPaths[pathSegment] ||
3625
+ Object.create(null, { [EntitiesKey]: { value: new Set() } });
3625
3626
  }
3626
3627
  return currentPaths[EntitiesKey];
3627
3628
  }
3628
3629
  }
3629
- const SHARED_RECURSION_TRACKER = new EntityPathTracker();
3630
+ const SHARED_RECURSION_TRACKER = new PathTracker();
3630
3631
  class DiscriminatedPathTracker {
3631
3632
  constructor() {
3632
3633
  this.entityPaths = Object.create(null, {
@@ -3636,9 +3637,9 @@ class DiscriminatedPathTracker {
3636
3637
  trackEntityAtPathAndGetIfTracked(path, discriminator, entity) {
3637
3638
  let currentPaths = this.entityPaths;
3638
3639
  for (const pathSegment of path) {
3639
- currentPaths = currentPaths[pathSegment] ||= Object.create(null, {
3640
- [EntitiesKey]: { value: new Map() }
3641
- });
3640
+ currentPaths = currentPaths[pathSegment] =
3641
+ currentPaths[pathSegment] ||
3642
+ Object.create(null, { [EntitiesKey]: { value: new Map() } });
3642
3643
  }
3643
3644
  const trackedEntities = getOrCreate(currentPaths[EntitiesKey], discriminator, (getNewSet));
3644
3645
  if (trackedEntities.has(entity))
@@ -3647,55 +3648,6 @@ class DiscriminatedPathTracker {
3647
3648
  return false;
3648
3649
  }
3649
3650
  }
3650
- const UNKNOWN_INCLUDED_PATH = Object.freeze({ [UnknownKey]: parseAst_js.EMPTY_OBJECT });
3651
- class IncludedPathTracker {
3652
- constructor() {
3653
- this.includedPaths = null;
3654
- }
3655
- includePathAndGetIfIncluded(path) {
3656
- let included = true;
3657
- let parent = this;
3658
- let parentSegment = 'includedPaths';
3659
- let currentPaths = (this.includedPaths ||=
3660
- ((included = false), Object.create(null)));
3661
- for (const pathSegment of path) {
3662
- // This means from here, all paths are included
3663
- if (currentPaths[UnknownKey]) {
3664
- return true;
3665
- }
3666
- // Including UnknownKey automatically includes all nested paths.
3667
- // From above, we know that UnknownKey is not included yet.
3668
- if (typeof pathSegment === 'symbol') {
3669
- // Hopefully, this saves some memory over just setting
3670
- // currentPaths[UnknownKey] = EMPTY_OBJECT
3671
- parent[parentSegment] = UNKNOWN_INCLUDED_PATH;
3672
- return false;
3673
- }
3674
- parent = currentPaths;
3675
- parentSegment = pathSegment;
3676
- currentPaths = currentPaths[pathSegment] ||= ((included = false), Object.create(null));
3677
- }
3678
- return included;
3679
- }
3680
- includeAllPaths(entity, context, basePath) {
3681
- const { includedPaths } = this;
3682
- if (includedPaths) {
3683
- includeAllPaths(entity, context, basePath, includedPaths);
3684
- }
3685
- }
3686
- }
3687
- function includeAllPaths(entity, context, basePath, currentPaths) {
3688
- if (currentPaths[UnknownKey]) {
3689
- return entity.includePath([...basePath, UnknownKey], context, false);
3690
- }
3691
- const keys = Object.keys(currentPaths);
3692
- if (keys.length === 0) {
3693
- return entity.includePath(basePath, context, false);
3694
- }
3695
- for (const key of keys) {
3696
- includeAllPaths(entity, context, [...basePath, key], currentPaths[key]);
3697
- }
3698
- }
3699
3651
 
3700
3652
  function isFlagSet(flags, flag) {
3701
3653
  return (flags & flag) !== 0;
@@ -3734,12 +3686,12 @@ class ExpressionEntity {
3734
3686
  hasEffectsOnInteractionAtPath(_path, _interaction, _context) {
3735
3687
  return true;
3736
3688
  }
3737
- includePath(_path, _context, _includeChildrenRecursively, _options) {
3689
+ include(_context, _includeChildrenRecursively, _options) {
3738
3690
  this.included = true;
3739
3691
  }
3740
- includeCallArguments(context, interaction) {
3741
- for (const argument of interaction.args) {
3742
- argument?.includePath(UNKNOWN_PATH, context, false);
3692
+ includeCallArguments(context, parameters) {
3693
+ for (const argument of parameters) {
3694
+ argument.include(context, false);
3743
3695
  }
3744
3696
  }
3745
3697
  shouldBeIncluded(_context) {
@@ -3854,9 +3806,9 @@ class Variable extends ExpressionEntity {
3854
3806
  * has not been included previously. Once a variable is included, it should
3855
3807
  * take care all its declarations are included.
3856
3808
  */
3857
- includePath(path, context) {
3809
+ include() {
3858
3810
  this.included = true;
3859
- this.renderedLikeHoisted?.includePath(path, context);
3811
+ this.renderedLikeHoisted?.include();
3860
3812
  }
3861
3813
  /**
3862
3814
  * Links the rendered name of this variable to another variable and includes
@@ -3888,8 +3840,8 @@ class ExternalVariable extends Variable {
3888
3840
  hasEffectsOnInteractionAtPath(path, { type }) {
3889
3841
  return type !== INTERACTION_ACCESSED || path.length > (this.isNamespace ? 1 : 0);
3890
3842
  }
3891
- includePath(path, context) {
3892
- super.includePath(path, context);
3843
+ include() {
3844
+ super.include();
3893
3845
  this.module.used = true;
3894
3846
  }
3895
3847
  }
@@ -4094,208 +4046,6 @@ function markModuleAndImpureDependenciesAsExecuted(baseModule) {
4094
4046
  }
4095
4047
  }
4096
4048
 
4097
- function assembleMemberDescriptions(memberDescriptions, inheritedDescriptions = null) {
4098
- return Object.create(inheritedDescriptions, memberDescriptions);
4099
- }
4100
- const UNDEFINED_EXPRESSION = new (class UndefinedExpression extends ExpressionEntity {
4101
- getLiteralValueAtPath() {
4102
- return undefined;
4103
- }
4104
- })();
4105
- const returnsUnknown = {
4106
- value: {
4107
- hasEffectsWhenCalled: null,
4108
- returns: UNKNOWN_EXPRESSION
4109
- }
4110
- };
4111
- const UNKNOWN_LITERAL_BOOLEAN = new (class UnknownBoolean extends ExpressionEntity {
4112
- getReturnExpressionWhenCalledAtPath(path) {
4113
- if (path.length === 1) {
4114
- return getMemberReturnExpressionWhenCalled(literalBooleanMembers, path[0]);
4115
- }
4116
- return UNKNOWN_RETURN_EXPRESSION;
4117
- }
4118
- hasEffectsOnInteractionAtPath(path, interaction, context) {
4119
- if (interaction.type === INTERACTION_ACCESSED) {
4120
- return path.length > 1;
4121
- }
4122
- if (interaction.type === INTERACTION_CALLED && path.length === 1) {
4123
- return hasMemberEffectWhenCalled(literalBooleanMembers, path[0], interaction, context);
4124
- }
4125
- return true;
4126
- }
4127
- })();
4128
- const returnsBoolean = {
4129
- value: {
4130
- hasEffectsWhenCalled: null,
4131
- returns: UNKNOWN_LITERAL_BOOLEAN
4132
- }
4133
- };
4134
- const UNKNOWN_LITERAL_NUMBER = new (class UnknownNumber extends ExpressionEntity {
4135
- getReturnExpressionWhenCalledAtPath(path) {
4136
- if (path.length === 1) {
4137
- return getMemberReturnExpressionWhenCalled(literalNumberMembers, path[0]);
4138
- }
4139
- return UNKNOWN_RETURN_EXPRESSION;
4140
- }
4141
- hasEffectsOnInteractionAtPath(path, interaction, context) {
4142
- if (interaction.type === INTERACTION_ACCESSED) {
4143
- return path.length > 1;
4144
- }
4145
- if (interaction.type === INTERACTION_CALLED && path.length === 1) {
4146
- return hasMemberEffectWhenCalled(literalNumberMembers, path[0], interaction, context);
4147
- }
4148
- return true;
4149
- }
4150
- })();
4151
- const returnsNumber = {
4152
- value: {
4153
- hasEffectsWhenCalled: null,
4154
- returns: UNKNOWN_LITERAL_NUMBER
4155
- }
4156
- };
4157
- const UNKNOWN_LITERAL_STRING = new (class UnknownString extends ExpressionEntity {
4158
- getReturnExpressionWhenCalledAtPath(path) {
4159
- if (path.length === 1) {
4160
- return getMemberReturnExpressionWhenCalled(literalStringMembers, path[0]);
4161
- }
4162
- return UNKNOWN_RETURN_EXPRESSION;
4163
- }
4164
- hasEffectsOnInteractionAtPath(path, interaction, context) {
4165
- if (interaction.type === INTERACTION_ACCESSED) {
4166
- return path.length > 1;
4167
- }
4168
- if (interaction.type === INTERACTION_CALLED && path.length === 1) {
4169
- return hasMemberEffectWhenCalled(literalStringMembers, path[0], interaction, context);
4170
- }
4171
- return true;
4172
- }
4173
- })();
4174
- const returnsString = {
4175
- value: {
4176
- hasEffectsWhenCalled: null,
4177
- returns: UNKNOWN_LITERAL_STRING
4178
- }
4179
- };
4180
- const stringReplace = {
4181
- value: {
4182
- hasEffectsWhenCalled({ args }, context) {
4183
- const argument1 = args[2];
4184
- return (args.length < 3 ||
4185
- (typeof argument1.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, {
4186
- deoptimizeCache() { }
4187
- }) === 'symbol' &&
4188
- argument1.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_CALL, context)));
4189
- },
4190
- returns: UNKNOWN_LITERAL_STRING
4191
- }
4192
- };
4193
- const objectMembers = assembleMemberDescriptions({
4194
- hasOwnProperty: returnsBoolean,
4195
- isPrototypeOf: returnsBoolean,
4196
- propertyIsEnumerable: returnsBoolean,
4197
- toLocaleString: returnsString,
4198
- toString: returnsString,
4199
- valueOf: returnsUnknown
4200
- });
4201
- const literalBooleanMembers = assembleMemberDescriptions({
4202
- valueOf: returnsBoolean
4203
- }, objectMembers);
4204
- const literalNumberMembers = assembleMemberDescriptions({
4205
- toExponential: returnsString,
4206
- toFixed: returnsString,
4207
- toLocaleString: returnsString,
4208
- toPrecision: returnsString,
4209
- valueOf: returnsNumber
4210
- }, objectMembers);
4211
- /**
4212
- * RegExp are stateful when they have the global or sticky flags set.
4213
- * But if we actually don't use them, the side effect does not matter.
4214
- * the check logic in `hasEffectsOnInteractionAtPath`.
4215
- */
4216
- const literalRegExpMembers = assembleMemberDescriptions({
4217
- exec: returnsUnknown,
4218
- test: returnsBoolean
4219
- }, objectMembers);
4220
- const literalStringMembers = assembleMemberDescriptions({
4221
- anchor: returnsString,
4222
- at: returnsUnknown,
4223
- big: returnsString,
4224
- blink: returnsString,
4225
- bold: returnsString,
4226
- charAt: returnsString,
4227
- charCodeAt: returnsNumber,
4228
- codePointAt: returnsUnknown,
4229
- concat: returnsString,
4230
- endsWith: returnsBoolean,
4231
- fixed: returnsString,
4232
- fontcolor: returnsString,
4233
- fontsize: returnsString,
4234
- includes: returnsBoolean,
4235
- indexOf: returnsNumber,
4236
- italics: returnsString,
4237
- lastIndexOf: returnsNumber,
4238
- link: returnsString,
4239
- localeCompare: returnsNumber,
4240
- match: returnsUnknown,
4241
- matchAll: returnsUnknown,
4242
- normalize: returnsString,
4243
- padEnd: returnsString,
4244
- padStart: returnsString,
4245
- repeat: returnsString,
4246
- replace: stringReplace,
4247
- replaceAll: stringReplace,
4248
- search: returnsNumber,
4249
- slice: returnsString,
4250
- small: returnsString,
4251
- split: returnsUnknown,
4252
- startsWith: returnsBoolean,
4253
- strike: returnsString,
4254
- sub: returnsString,
4255
- substr: returnsString,
4256
- substring: returnsString,
4257
- sup: returnsString,
4258
- toLocaleLowerCase: returnsString,
4259
- toLocaleUpperCase: returnsString,
4260
- toLowerCase: returnsString,
4261
- toString: returnsString, // overrides the toString() method of the Object object; it does not inherit Object.prototype.toString()
4262
- toUpperCase: returnsString,
4263
- trim: returnsString,
4264
- trimEnd: returnsString,
4265
- trimLeft: returnsString,
4266
- trimRight: returnsString,
4267
- trimStart: returnsString,
4268
- valueOf: returnsString
4269
- }, objectMembers);
4270
- function getLiteralMembersForValue(value) {
4271
- if (value instanceof RegExp) {
4272
- return literalRegExpMembers;
4273
- }
4274
- switch (typeof value) {
4275
- case 'boolean': {
4276
- return literalBooleanMembers;
4277
- }
4278
- case 'number': {
4279
- return literalNumberMembers;
4280
- }
4281
- case 'string': {
4282
- return literalStringMembers;
4283
- }
4284
- }
4285
- return Object.create(null);
4286
- }
4287
- function hasMemberEffectWhenCalled(members, memberName, interaction, context) {
4288
- if (typeof memberName !== 'string' || !members[memberName]) {
4289
- return true;
4290
- }
4291
- return members[memberName].hasEffectsWhenCalled?.(interaction, context) || false;
4292
- }
4293
- function getMemberReturnExpressionWhenCalled(members, memberName) {
4294
- if (typeof memberName !== 'string' || !members[memberName])
4295
- return UNKNOWN_RETURN_EXPRESSION;
4296
- return [members[memberName].returns, false];
4297
- }
4298
-
4299
4049
  // This file is generated by scripts/generate-child-node-keys.js.
4300
4050
  // Do not edit this file directly.
4301
4051
  const childNodeKeys = {
@@ -4401,8 +4151,8 @@ function createInclusionContext() {
4401
4151
  }
4402
4152
  function createHasEffectsContext() {
4403
4153
  return {
4404
- accessed: new EntityPathTracker(),
4405
- assigned: new EntityPathTracker(),
4154
+ accessed: new PathTracker(),
4155
+ assigned: new PathTracker(),
4406
4156
  brokenFlow: false,
4407
4157
  called: new DiscriminatedPathTracker(),
4408
4158
  hasBreak: false,
@@ -4488,7 +4238,7 @@ class NodeBase extends ExpressionEntity {
4488
4238
  return (this.hasEffects(context) ||
4489
4239
  this.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.assignmentInteraction, context));
4490
4240
  }
4491
- includePath(_path, context, includeChildrenRecursively, _options) {
4241
+ include(context, includeChildrenRecursively, _options) {
4492
4242
  if (!this.deoptimized)
4493
4243
  this.applyDeoptimizations();
4494
4244
  this.included = true;
@@ -4498,16 +4248,16 @@ class NodeBase extends ExpressionEntity {
4498
4248
  continue;
4499
4249
  if (Array.isArray(value)) {
4500
4250
  for (const child of value) {
4501
- child?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
4251
+ child?.include(context, includeChildrenRecursively);
4502
4252
  }
4503
4253
  }
4504
4254
  else {
4505
- value.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
4255
+ value.include(context, includeChildrenRecursively);
4506
4256
  }
4507
4257
  }
4508
4258
  }
4509
4259
  includeAsAssignmentTarget(context, includeChildrenRecursively, _deoptimizeAccess) {
4510
- this.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
4260
+ this.include(context, includeChildrenRecursively);
4511
4261
  }
4512
4262
  /**
4513
4263
  * Override to perform special initialisation steps after the scope is
@@ -4537,11 +4287,13 @@ class NodeBase extends ExpressionEntity {
4537
4287
  this[key] = value;
4538
4288
  }
4539
4289
  else if (Array.isArray(value)) {
4540
- this[key] = [];
4290
+ this[key] = new Array(value.length);
4291
+ let index = 0;
4541
4292
  for (const child of value) {
4542
- this[key].push(child === null
4543
- ? null
4544
- : new (this.scope.context.getNodeConstructor(child.type))(this, this.scope).parseNode(child));
4293
+ this[key][index++] =
4294
+ child === null
4295
+ ? null
4296
+ : new (this.scope.context.getNodeConstructor(child.type))(this, this.scope).parseNode(child);
4545
4297
  }
4546
4298
  }
4547
4299
  else {
@@ -4553,59 +4305,268 @@ class NodeBase extends ExpressionEntity {
4553
4305
  this.initialise();
4554
4306
  return this;
4555
4307
  }
4556
- removeAnnotations(code) {
4557
- if (this.annotations) {
4558
- for (const annotation of this.annotations) {
4559
- code.remove(annotation.start, annotation.end);
4560
- }
4308
+ removeAnnotations(code) {
4309
+ if (this.annotations) {
4310
+ for (const annotation of this.annotations) {
4311
+ code.remove(annotation.start, annotation.end);
4312
+ }
4313
+ }
4314
+ }
4315
+ render(code, options) {
4316
+ for (const key of childNodeKeys[this.type]) {
4317
+ const value = this[key];
4318
+ if (value === null)
4319
+ continue;
4320
+ if (Array.isArray(value)) {
4321
+ for (const child of value) {
4322
+ child?.render(code, options);
4323
+ }
4324
+ }
4325
+ else {
4326
+ value.render(code, options);
4327
+ }
4328
+ }
4329
+ }
4330
+ setAssignedValue(value) {
4331
+ this.assignmentInteraction = { args: [null, value], type: INTERACTION_ASSIGNED };
4332
+ }
4333
+ shouldBeIncluded(context) {
4334
+ return this.included || (!context.brokenFlow && this.hasEffects(createHasEffectsContext()));
4335
+ }
4336
+ /**
4337
+ * Just deoptimize everything by default so that when e.g. we do not track
4338
+ * something properly, it is deoptimized.
4339
+ * @protected
4340
+ */
4341
+ applyDeoptimizations() {
4342
+ this.deoptimized = true;
4343
+ for (const key of childNodeKeys[this.type]) {
4344
+ const value = this[key];
4345
+ if (value === null)
4346
+ continue;
4347
+ if (Array.isArray(value)) {
4348
+ for (const child of value) {
4349
+ child?.deoptimizePath(UNKNOWN_PATH);
4350
+ }
4351
+ }
4352
+ else {
4353
+ value.deoptimizePath(UNKNOWN_PATH);
4354
+ }
4355
+ }
4356
+ this.scope.context.requestTreeshakingPass();
4357
+ }
4358
+ }
4359
+ function createChildNodeKeysForNode(esTreeNode) {
4360
+ return Object.keys(esTreeNode).filter(key => typeof esTreeNode[key] === 'object' && key.charCodeAt(0) !== 95 /* _ */);
4361
+ }
4362
+
4363
+ function isObjectExpressionNode(node) {
4364
+ return node instanceof NodeBase && node.type === parseAst_js.ObjectExpression;
4365
+ }
4366
+ function isPropertyNode(node) {
4367
+ return node.type === parseAst_js.Property;
4368
+ }
4369
+
4370
+ function assembleMemberDescriptions(memberDescriptions, inheritedDescriptions = null) {
4371
+ return Object.create(inheritedDescriptions, memberDescriptions);
4372
+ }
4373
+ const UNDEFINED_EXPRESSION = new (class UndefinedExpression extends ExpressionEntity {
4374
+ getLiteralValueAtPath() {
4375
+ return undefined;
4376
+ }
4377
+ })();
4378
+ const returnsUnknown = {
4379
+ value: {
4380
+ hasEffectsWhenCalled: null,
4381
+ returns: UNKNOWN_EXPRESSION
4382
+ }
4383
+ };
4384
+ const UNKNOWN_LITERAL_BOOLEAN = new (class UnknownBoolean extends ExpressionEntity {
4385
+ getReturnExpressionWhenCalledAtPath(path) {
4386
+ if (path.length === 1) {
4387
+ return getMemberReturnExpressionWhenCalled(literalBooleanMembers, path[0]);
4388
+ }
4389
+ return UNKNOWN_RETURN_EXPRESSION;
4390
+ }
4391
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
4392
+ if (interaction.type === INTERACTION_ACCESSED) {
4393
+ return path.length > 1;
4394
+ }
4395
+ if (interaction.type === INTERACTION_CALLED && path.length === 1) {
4396
+ return hasMemberEffectWhenCalled(literalBooleanMembers, path[0], interaction, context);
4397
+ }
4398
+ return true;
4399
+ }
4400
+ })();
4401
+ const returnsBoolean = {
4402
+ value: {
4403
+ hasEffectsWhenCalled: null,
4404
+ returns: UNKNOWN_LITERAL_BOOLEAN
4405
+ }
4406
+ };
4407
+ const UNKNOWN_LITERAL_NUMBER = new (class UnknownNumber extends ExpressionEntity {
4408
+ getReturnExpressionWhenCalledAtPath(path) {
4409
+ if (path.length === 1) {
4410
+ return getMemberReturnExpressionWhenCalled(literalNumberMembers, path[0]);
4411
+ }
4412
+ return UNKNOWN_RETURN_EXPRESSION;
4413
+ }
4414
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
4415
+ if (interaction.type === INTERACTION_ACCESSED) {
4416
+ return path.length > 1;
4417
+ }
4418
+ if (interaction.type === INTERACTION_CALLED && path.length === 1) {
4419
+ return hasMemberEffectWhenCalled(literalNumberMembers, path[0], interaction, context);
4420
+ }
4421
+ return true;
4422
+ }
4423
+ })();
4424
+ const returnsNumber = {
4425
+ value: {
4426
+ hasEffectsWhenCalled: null,
4427
+ returns: UNKNOWN_LITERAL_NUMBER
4428
+ }
4429
+ };
4430
+ const UNKNOWN_LITERAL_STRING = new (class UnknownString extends ExpressionEntity {
4431
+ getReturnExpressionWhenCalledAtPath(path) {
4432
+ if (path.length === 1) {
4433
+ return getMemberReturnExpressionWhenCalled(literalStringMembers, path[0]);
4434
+ }
4435
+ return UNKNOWN_RETURN_EXPRESSION;
4436
+ }
4437
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
4438
+ if (interaction.type === INTERACTION_ACCESSED) {
4439
+ return path.length > 1;
4440
+ }
4441
+ if (interaction.type === INTERACTION_CALLED && path.length === 1) {
4442
+ return hasMemberEffectWhenCalled(literalStringMembers, path[0], interaction, context);
4443
+ }
4444
+ return true;
4445
+ }
4446
+ })();
4447
+ const returnsString = {
4448
+ value: {
4449
+ hasEffectsWhenCalled: null,
4450
+ returns: UNKNOWN_LITERAL_STRING
4451
+ }
4452
+ };
4453
+ const stringReplace = {
4454
+ value: {
4455
+ hasEffectsWhenCalled({ args }, context) {
4456
+ const argument1 = args[2];
4457
+ return (args.length < 3 ||
4458
+ (typeof argument1.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, {
4459
+ deoptimizeCache() { }
4460
+ }) === 'symbol' &&
4461
+ argument1.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_CALL, context)));
4462
+ },
4463
+ returns: UNKNOWN_LITERAL_STRING
4464
+ }
4465
+ };
4466
+ const objectMembers = assembleMemberDescriptions({
4467
+ hasOwnProperty: returnsBoolean,
4468
+ isPrototypeOf: returnsBoolean,
4469
+ propertyIsEnumerable: returnsBoolean,
4470
+ toLocaleString: returnsString,
4471
+ toString: returnsString,
4472
+ valueOf: returnsUnknown
4473
+ });
4474
+ const literalBooleanMembers = assembleMemberDescriptions({
4475
+ valueOf: returnsBoolean
4476
+ }, objectMembers);
4477
+ const literalNumberMembers = assembleMemberDescriptions({
4478
+ toExponential: returnsString,
4479
+ toFixed: returnsString,
4480
+ toLocaleString: returnsString,
4481
+ toPrecision: returnsString,
4482
+ valueOf: returnsNumber
4483
+ }, objectMembers);
4484
+ /**
4485
+ * RegExp are stateful when they have the global or sticky flags set.
4486
+ * But if we actually don't use them, the side effect does not matter.
4487
+ * the check logic in `hasEffectsOnInteractionAtPath`.
4488
+ */
4489
+ const literalRegExpMembers = assembleMemberDescriptions({
4490
+ exec: returnsUnknown,
4491
+ test: returnsBoolean
4492
+ }, objectMembers);
4493
+ const literalStringMembers = assembleMemberDescriptions({
4494
+ anchor: returnsString,
4495
+ at: returnsUnknown,
4496
+ big: returnsString,
4497
+ blink: returnsString,
4498
+ bold: returnsString,
4499
+ charAt: returnsString,
4500
+ charCodeAt: returnsNumber,
4501
+ codePointAt: returnsUnknown,
4502
+ concat: returnsString,
4503
+ endsWith: returnsBoolean,
4504
+ fixed: returnsString,
4505
+ fontcolor: returnsString,
4506
+ fontsize: returnsString,
4507
+ includes: returnsBoolean,
4508
+ indexOf: returnsNumber,
4509
+ italics: returnsString,
4510
+ lastIndexOf: returnsNumber,
4511
+ link: returnsString,
4512
+ localeCompare: returnsNumber,
4513
+ match: returnsUnknown,
4514
+ matchAll: returnsUnknown,
4515
+ normalize: returnsString,
4516
+ padEnd: returnsString,
4517
+ padStart: returnsString,
4518
+ repeat: returnsString,
4519
+ replace: stringReplace,
4520
+ replaceAll: stringReplace,
4521
+ search: returnsNumber,
4522
+ slice: returnsString,
4523
+ small: returnsString,
4524
+ split: returnsUnknown,
4525
+ startsWith: returnsBoolean,
4526
+ strike: returnsString,
4527
+ sub: returnsString,
4528
+ substr: returnsString,
4529
+ substring: returnsString,
4530
+ sup: returnsString,
4531
+ toLocaleLowerCase: returnsString,
4532
+ toLocaleUpperCase: returnsString,
4533
+ toLowerCase: returnsString,
4534
+ toString: returnsString, // overrides the toString() method of the Object object; it does not inherit Object.prototype.toString()
4535
+ toUpperCase: returnsString,
4536
+ trim: returnsString,
4537
+ trimEnd: returnsString,
4538
+ trimLeft: returnsString,
4539
+ trimRight: returnsString,
4540
+ trimStart: returnsString,
4541
+ valueOf: returnsString
4542
+ }, objectMembers);
4543
+ function getLiteralMembersForValue(value) {
4544
+ if (value instanceof RegExp) {
4545
+ return literalRegExpMembers;
4546
+ }
4547
+ switch (typeof value) {
4548
+ case 'boolean': {
4549
+ return literalBooleanMembers;
4561
4550
  }
4562
- }
4563
- render(code, options) {
4564
- for (const key of childNodeKeys[this.type]) {
4565
- const value = this[key];
4566
- if (value === null)
4567
- continue;
4568
- if (Array.isArray(value)) {
4569
- for (const child of value) {
4570
- child?.render(code, options);
4571
- }
4572
- }
4573
- else {
4574
- value.render(code, options);
4575
- }
4551
+ case 'number': {
4552
+ return literalNumberMembers;
4576
4553
  }
4577
- }
4578
- setAssignedValue(value) {
4579
- this.assignmentInteraction = { args: [null, value], type: INTERACTION_ASSIGNED };
4580
- }
4581
- shouldBeIncluded(context) {
4582
- return this.included || (!context.brokenFlow && this.hasEffects(createHasEffectsContext()));
4583
- }
4584
- /**
4585
- * Just deoptimize everything by default so that when e.g. we do not track
4586
- * something properly, it is deoptimized.
4587
- * @protected
4588
- */
4589
- applyDeoptimizations() {
4590
- this.deoptimized = true;
4591
- for (const key of childNodeKeys[this.type]) {
4592
- const value = this[key];
4593
- if (value === null)
4594
- continue;
4595
- if (Array.isArray(value)) {
4596
- for (const child of value) {
4597
- child?.deoptimizePath(UNKNOWN_PATH);
4598
- }
4599
- }
4600
- else {
4601
- value.deoptimizePath(UNKNOWN_PATH);
4602
- }
4554
+ case 'string': {
4555
+ return literalStringMembers;
4603
4556
  }
4604
- this.scope.context.requestTreeshakingPass();
4605
4557
  }
4558
+ return Object.create(null);
4606
4559
  }
4607
- function createChildNodeKeysForNode(esTreeNode) {
4608
- return Object.keys(esTreeNode).filter(key => typeof esTreeNode[key] === 'object' && key.charCodeAt(0) !== 95 /* _ */);
4560
+ function hasMemberEffectWhenCalled(members, memberName, interaction, context) {
4561
+ if (typeof memberName !== 'string' || !members[memberName]) {
4562
+ return true;
4563
+ }
4564
+ return members[memberName].hasEffectsWhenCalled?.(interaction, context) || false;
4565
+ }
4566
+ function getMemberReturnExpressionWhenCalled(members, memberName) {
4567
+ if (typeof memberName !== 'string' || !members[memberName])
4568
+ return UNKNOWN_RETURN_EXPRESSION;
4569
+ return [members[memberName].returns, false];
4609
4570
  }
4610
4571
 
4611
4572
  class SpreadElement extends NodeBase {
@@ -4758,7 +4719,6 @@ class ObjectEntity extends ExpressionEntity {
4758
4719
  this.unknownIntegerProps = [];
4759
4720
  this.unmatchableGetters = [];
4760
4721
  this.unmatchablePropertiesAndGetters = [];
4761
- this.unmatchablePropertiesAndSetters = [];
4762
4722
  this.unmatchableSetters = [];
4763
4723
  if (Array.isArray(properties)) {
4764
4724
  this.buildPropertyMaps(properties);
@@ -4993,37 +4953,9 @@ class ObjectEntity extends ExpressionEntity {
4993
4953
  }
4994
4954
  return false;
4995
4955
  }
4996
- includePath(path, context, includeChildrenRecursively) {
4997
- this.included = true;
4998
- const [key, ...subPath] = path;
4999
- if (key == null || includeChildrenRecursively) {
5000
- for (const property of this.allProperties) {
5001
- if (includeChildrenRecursively || property.shouldBeIncluded(context)) {
5002
- property.includePath(EMPTY_PATH, context, includeChildrenRecursively);
5003
- }
5004
- }
5005
- this.prototypeExpression?.includePath(EMPTY_PATH, context, includeChildrenRecursively);
5006
- }
5007
- else {
5008
- const [includedMembers, includedPath] = typeof key === 'string'
5009
- ? [
5010
- [
5011
- ...new Set([
5012
- ...(this.propertiesAndGettersByKey[key] || this.unmatchablePropertiesAndGetters),
5013
- ...(this.propertiesAndSettersByKey[key] || this.unmatchablePropertiesAndSetters)
5014
- ])
5015
- ],
5016
- subPath
5017
- ]
5018
- : [this.allProperties, UNKNOWN_PATH];
5019
- for (const property of includedMembers) {
5020
- property.includePath(includedPath, context, includeChildrenRecursively);
5021
- }
5022
- this.prototypeExpression?.includePath(path, context, includeChildrenRecursively);
5023
- }
5024
- }
5025
4956
  buildPropertyMaps(properties) {
5026
- const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchablePropertiesAndSetters, unmatchableGetters, unmatchableSetters } = this;
4957
+ const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchableGetters, unmatchableSetters } = this;
4958
+ const unmatchablePropertiesAndSetters = [];
5027
4959
  for (let index = properties.length - 1; index >= 0; index--) {
5028
4960
  const { key, kind, property } = properties[index];
5029
4961
  allProperties.push(property);
@@ -5594,7 +5526,29 @@ const knownGlobals = {
5594
5526
  resolve: O
5595
5527
  },
5596
5528
  propertyIsEnumerable: O,
5597
- Proxy: O,
5529
+ Proxy: {
5530
+ __proto__: null,
5531
+ [ValueProperties]: {
5532
+ deoptimizeArgumentsOnCall: ({ args: [, target, parameter] }) => {
5533
+ if (isObjectExpressionNode(parameter)) {
5534
+ const hasSpreadElement = parameter.properties.some(property => !isPropertyNode(property));
5535
+ if (!hasSpreadElement) {
5536
+ for (const property of parameter.properties) {
5537
+ property.deoptimizeArgumentsOnInteractionAtPath({
5538
+ args: [null, target],
5539
+ type: INTERACTION_CALLED,
5540
+ withNew: false
5541
+ }, EMPTY_PATH, SHARED_RECURSION_TRACKER);
5542
+ }
5543
+ return;
5544
+ }
5545
+ }
5546
+ target.deoptimizePath(UNKNOWN_PATH);
5547
+ },
5548
+ getLiteralValue: getTruthyLiteralValue,
5549
+ hasEffectsWhenCalled: returnTrue
5550
+ }
5551
+ },
5598
5552
  RangeError: PC,
5599
5553
  ReferenceError: PC,
5600
5554
  Reflect: O,
@@ -6359,20 +6313,16 @@ class GlobalVariable extends Variable {
6359
6313
  }
6360
6314
 
6361
6315
  class LocalVariable extends Variable {
6362
- constructor(name, declarator, init,
6363
- /** if this is non-empty, the actual init is this path of this.init */
6364
- initPath, context, kind) {
6316
+ constructor(name, declarator, init, context, kind) {
6365
6317
  super(name);
6366
6318
  this.init = init;
6367
- this.initPath = initPath;
6368
- this.kind = kind;
6369
6319
  this.calledFromTryStatement = false;
6370
6320
  this.additionalInitializers = null;
6371
- this.includedPathTracker = new IncludedPathTracker();
6372
6321
  this.expressionsToBeDeoptimized = [];
6373
6322
  this.declarations = declarator ? [declarator] : [];
6374
6323
  this.deoptimizationTracker = context.deoptimizationTracker;
6375
6324
  this.module = context.module;
6325
+ this.kind = kind;
6376
6326
  }
6377
6327
  addDeclaration(identifier, init) {
6378
6328
  this.declarations.push(identifier);
@@ -6383,6 +6333,7 @@ class LocalVariable extends Variable {
6383
6333
  for (const initializer of this.additionalInitializers) {
6384
6334
  initializer.deoptimizePath(UNKNOWN_PATH);
6385
6335
  }
6336
+ this.additionalInitializers = null;
6386
6337
  }
6387
6338
  }
6388
6339
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
@@ -6390,7 +6341,7 @@ class LocalVariable extends Variable {
6390
6341
  deoptimizeInteraction(interaction);
6391
6342
  return;
6392
6343
  }
6393
- recursionTracker.withTrackedEntityAtPath(path, this.init, () => this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], recursionTracker), undefined);
6344
+ recursionTracker.withTrackedEntityAtPath(path, this.init, () => this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker), undefined);
6394
6345
  }
6395
6346
  deoptimizePath(path) {
6396
6347
  if (this.isReassigned ||
@@ -6404,10 +6355,10 @@ class LocalVariable extends Variable {
6404
6355
  for (const expression of expressionsToBeDeoptimized) {
6405
6356
  expression.deoptimizeCache();
6406
6357
  }
6407
- this.init.deoptimizePath([...this.initPath, UnknownKey]);
6358
+ this.init.deoptimizePath(UNKNOWN_PATH);
6408
6359
  }
6409
6360
  else {
6410
- this.init.deoptimizePath([...this.initPath, ...path]);
6361
+ this.init.deoptimizePath(path);
6411
6362
  }
6412
6363
  }
6413
6364
  getLiteralValueAtPath(path, recursionTracker, origin) {
@@ -6416,7 +6367,7 @@ class LocalVariable extends Variable {
6416
6367
  }
6417
6368
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6418
6369
  this.expressionsToBeDeoptimized.push(origin);
6419
- return this.init.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin);
6370
+ return this.init.getLiteralValueAtPath(path, recursionTracker, origin);
6420
6371
  }, UnknownValue);
6421
6372
  }
6422
6373
  getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
@@ -6425,7 +6376,7 @@ class LocalVariable extends Variable {
6425
6376
  }
6426
6377
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6427
6378
  this.expressionsToBeDeoptimized.push(origin);
6428
- return this.init.getReturnExpressionWhenCalledAtPath([...this.initPath, ...path], interaction, recursionTracker, origin);
6379
+ return this.init.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
6429
6380
  }, UNKNOWN_RETURN_EXPRESSION);
6430
6381
  }
6431
6382
  hasEffectsOnInteractionAtPath(path, interaction, context) {
@@ -6434,7 +6385,7 @@ class LocalVariable extends Variable {
6434
6385
  if (this.isReassigned)
6435
6386
  return true;
6436
6387
  return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
6437
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6388
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6438
6389
  }
6439
6390
  case INTERACTION_ASSIGNED: {
6440
6391
  if (this.included)
@@ -6444,23 +6395,23 @@ class LocalVariable extends Variable {
6444
6395
  if (this.isReassigned)
6445
6396
  return true;
6446
6397
  return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
6447
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6398
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6448
6399
  }
6449
6400
  case INTERACTION_CALLED: {
6450
6401
  if (this.isReassigned)
6451
6402
  return true;
6452
6403
  return (!(interaction.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this) &&
6453
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6404
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6454
6405
  }
6455
6406
  }
6456
6407
  }
6457
- includePath(path, context) {
6458
- if (!this.includedPathTracker.includePathAndGetIfIncluded(path)) {
6459
- super.includePath(path, context);
6408
+ include() {
6409
+ if (!this.included) {
6410
+ super.include();
6460
6411
  for (const declaration of this.declarations) {
6461
6412
  // If node is a default export, it can save a tree-shaking run to include the full declaration now
6462
6413
  if (!declaration.included)
6463
- declaration.includePath(EMPTY_PATH, context, false);
6414
+ declaration.include(createInclusionContext(), false);
6464
6415
  let node = declaration.parent;
6465
6416
  while (!node.included) {
6466
6417
  // We do not want to properly include parents in case they are part of a dead branch
@@ -6471,26 +6422,17 @@ class LocalVariable extends Variable {
6471
6422
  node = node.parent;
6472
6423
  }
6473
6424
  }
6474
- // We need to make sure we include the correct path of the init
6475
- if (path.length > 0) {
6476
- this.init.includePath([...this.initPath, ...path], context, false);
6477
- this.additionalInitializers?.forEach(initializer => initializer.includePath(UNKNOWN_PATH, context, false));
6478
- }
6479
6425
  }
6480
6426
  }
6481
- includeCallArguments(context, interaction) {
6482
- if (this.isReassigned ||
6483
- context.includedCallArguments.has(this.init) ||
6484
- // This can be removed again once we can include arguments when called at
6485
- // a specific path
6486
- this.initPath.length > 0) {
6487
- for (const argument of interaction.args) {
6488
- argument?.includePath(UNKNOWN_PATH, context, false);
6427
+ includeCallArguments(context, parameters) {
6428
+ if (this.isReassigned || context.includedCallArguments.has(this.init)) {
6429
+ for (const argument of parameters) {
6430
+ argument.include(context, false);
6489
6431
  }
6490
6432
  }
6491
6433
  else {
6492
6434
  context.includedCallArguments.add(this.init);
6493
- this.init.includeCallArguments(context, interaction);
6435
+ this.init.includeCallArguments(context, parameters);
6494
6436
  context.includedCallArguments.delete(this.init);
6495
6437
  }
6496
6438
  }
@@ -6570,21 +6512,18 @@ class IdentifierBase extends NodeBase {
6570
6512
  }
6571
6513
  }
6572
6514
  }
6573
- includePath(path, context) {
6515
+ include() {
6574
6516
  if (!this.deoptimized)
6575
6517
  this.applyDeoptimizations();
6576
6518
  if (!this.included) {
6577
6519
  this.included = true;
6578
6520
  if (this.variable !== null) {
6579
- this.scope.context.includeVariableInModule(this.variable, path);
6521
+ this.scope.context.includeVariableInModule(this.variable);
6580
6522
  }
6581
6523
  }
6582
- else if (path.length > 0) {
6583
- this.variable?.includePath(path, context);
6584
- }
6585
6524
  }
6586
- includeCallArguments(context, interaction) {
6587
- this.variable.includeCallArguments(context, interaction);
6525
+ includeCallArguments(context, parameters) {
6526
+ this.variable.includeCallArguments(context, parameters);
6588
6527
  }
6589
6528
  isPossibleTDZ() {
6590
6529
  // return cached value to avoid issues with the next tree-shaking pass
@@ -6684,17 +6623,39 @@ class Identifier extends IdentifierBase {
6684
6623
  this.isVariableReference = true;
6685
6624
  }
6686
6625
  }
6687
- declare(kind, includedInitPath, init) {
6626
+ declare(kind, init) {
6688
6627
  let variable;
6689
6628
  const { treeshake } = this.scope.context.options;
6690
- if (kind === 'parameter') {
6691
- variable = this.scope.addParameterDeclaration(this, includedInitPath);
6692
- }
6693
- else {
6694
- variable = this.scope.addDeclaration(this, this.scope.context, init, includedInitPath, kind);
6695
- if (kind === 'var' && treeshake && treeshake.correctVarValueBeforeDeclaration) {
6696
- // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
6697
- variable.markInitializersForDeoptimization();
6629
+ switch (kind) {
6630
+ case 'var': {
6631
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
6632
+ if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
6633
+ // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
6634
+ variable.markInitializersForDeoptimization();
6635
+ }
6636
+ break;
6637
+ }
6638
+ case 'function': {
6639
+ // in strict mode, functions are only hoisted within a scope but not across block scopes
6640
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
6641
+ break;
6642
+ }
6643
+ case 'let':
6644
+ case 'const':
6645
+ case 'using':
6646
+ case 'await using':
6647
+ case 'class': {
6648
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
6649
+ break;
6650
+ }
6651
+ case 'parameter': {
6652
+ variable = this.scope.addParameterDeclaration(this);
6653
+ break;
6654
+ }
6655
+ /* istanbul ignore next */
6656
+ default: {
6657
+ /* istanbul ignore next */
6658
+ throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
6698
6659
  }
6699
6660
  }
6700
6661
  return [(this.variable = variable)];
@@ -6751,17 +6712,18 @@ class Scope {
6751
6712
  - then the variable is still declared in the hoisted outer scope, but the initializer is assigned to the parameter
6752
6713
  - const, let, class, and function except in the cases above cannot redeclare anything
6753
6714
  */
6754
- addDeclaration(identifier, context, init, includedInitPath, kind) {
6715
+ addDeclaration(identifier, context, init, kind) {
6755
6716
  const name = identifier.name;
6756
6717
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
6757
6718
  if (existingVariable) {
6758
- if (kind === 'var' && existingVariable.kind === 'var') {
6719
+ const existingKind = existingVariable.kind;
6720
+ if (kind === 'var' && existingKind === 'var') {
6759
6721
  existingVariable.addDeclaration(identifier, init);
6760
6722
  return existingVariable;
6761
6723
  }
6762
6724
  context.error(parseAst_js.logRedeclarationError(name), identifier.start);
6763
6725
  }
6764
- const newVariable = new LocalVariable(identifier.name, identifier, init, includedInitPath, context, kind);
6726
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
6765
6727
  this.variables.set(name, newVariable);
6766
6728
  return newVariable;
6767
6729
  }
@@ -6963,7 +6925,7 @@ class BlockScope extends ChildScope {
6963
6925
  constructor(parent) {
6964
6926
  super(parent, parent.context);
6965
6927
  }
6966
- addDeclaration(identifier, context, init, includedInitPath, kind) {
6928
+ addDeclaration(identifier, context, init, kind) {
6967
6929
  if (kind === 'var') {
6968
6930
  const name = identifier.name;
6969
6931
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -6975,7 +6937,7 @@ class BlockScope extends ChildScope {
6975
6937
  }
6976
6938
  return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
6977
6939
  }
6978
- const declaredVariable = this.parent.addDeclaration(identifier, context, init, includedInitPath, kind);
6940
+ const declaredVariable = this.parent.addDeclaration(identifier, context, init, kind);
6979
6941
  // Necessary to make sure the init is deoptimized for conditional declarations.
6980
6942
  // We cannot call deoptimizePath here.
6981
6943
  declaredVariable.markInitializersForDeoptimization();
@@ -6983,7 +6945,7 @@ class BlockScope extends ChildScope {
6983
6945
  this.addHoistedVariable(name, declaredVariable);
6984
6946
  return declaredVariable;
6985
6947
  }
6986
- return super.addDeclaration(identifier, context, init, includedInitPath, kind);
6948
+ return super.addDeclaration(identifier, context, init, kind);
6987
6949
  }
6988
6950
  }
6989
6951
 
@@ -6998,11 +6960,11 @@ class StaticBlock extends NodeBase {
6998
6960
  }
6999
6961
  return false;
7000
6962
  }
7001
- includePath(_path, context, includeChildrenRecursively) {
6963
+ include(context, includeChildrenRecursively) {
7002
6964
  this.included = true;
7003
6965
  for (const node of this.body) {
7004
6966
  if (includeChildrenRecursively || node.shouldBeIncluded(context))
7005
- node.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
6967
+ node.include(context, includeChildrenRecursively);
7006
6968
  }
7007
6969
  }
7008
6970
  render(code, options) {
@@ -7081,22 +7043,22 @@ class ClassNode extends NodeBase {
7081
7043
  false
7082
7044
  : this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
7083
7045
  }
7084
- includePath(_path, context, includeChildrenRecursively) {
7046
+ include(context, includeChildrenRecursively) {
7085
7047
  if (!this.deoptimized)
7086
7048
  this.applyDeoptimizations();
7087
7049
  this.included = true;
7088
- this.superClass?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
7089
- this.body.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
7050
+ this.superClass?.include(context, includeChildrenRecursively);
7051
+ this.body.include(context, includeChildrenRecursively);
7090
7052
  for (const decorator of this.decorators)
7091
- decorator.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
7053
+ decorator.include(context, includeChildrenRecursively);
7092
7054
  if (this.id) {
7093
7055
  this.id.markDeclarationReached();
7094
- this.id.includePath(UNKNOWN_PATH, createInclusionContext());
7056
+ this.id.include();
7095
7057
  }
7096
7058
  }
7097
7059
  initialise() {
7098
7060
  super.initialise();
7099
- this.id?.declare('class', EMPTY_PATH, this);
7061
+ this.id?.declare('class', this);
7100
7062
  for (const method of this.body.body) {
7101
7063
  if (method instanceof MethodDefinition && method.kind === 'constructor') {
7102
7064
  this.classConstructor = method;
@@ -7211,7 +7173,7 @@ class ClassDeclaration extends ClassNode {
7211
7173
 
7212
7174
  class ArgumentsVariable extends LocalVariable {
7213
7175
  constructor(context) {
7214
- super('arguments', null, UNKNOWN_EXPRESSION, EMPTY_PATH, context, 'other');
7176
+ super('arguments', null, UNKNOWN_EXPRESSION, context, 'other');
7215
7177
  this.deoptimizedArguments = [];
7216
7178
  }
7217
7179
  addArgumentToBeDeoptimized(argument) {
@@ -7225,8 +7187,8 @@ class ArgumentsVariable extends LocalVariable {
7225
7187
  hasEffectsOnInteractionAtPath(path, { type }) {
7226
7188
  return type !== INTERACTION_ACCESSED || path.length > 1;
7227
7189
  }
7228
- includePath(path, context) {
7229
- super.includePath(path, context);
7190
+ include() {
7191
+ super.include();
7230
7192
  for (const argument of this.deoptimizedArguments) {
7231
7193
  argument.deoptimizePath(UNKNOWN_PATH);
7232
7194
  }
@@ -7237,28 +7199,27 @@ class ArgumentsVariable extends LocalVariable {
7237
7199
  const MAX_TRACKED_INTERACTIONS = 20;
7238
7200
  const NO_INTERACTIONS = parseAst_js.EMPTY_ARRAY;
7239
7201
  const UNKNOWN_DEOPTIMIZED_FIELD = new Set([UnknownKey]);
7240
- const EMPTY_PATH_TRACKER = new EntityPathTracker();
7202
+ const EMPTY_PATH_TRACKER = new PathTracker();
7241
7203
  const UNKNOWN_DEOPTIMIZED_ENTITY = new Set([UNKNOWN_EXPRESSION]);
7242
7204
  class ParameterVariable extends LocalVariable {
7243
- constructor(name, declarator, argumentPath, context) {
7244
- super(name, declarator, UNKNOWN_EXPRESSION, argumentPath, context, 'parameter');
7205
+ constructor(name, declarator, context) {
7206
+ super(name, declarator, UNKNOWN_EXPRESSION, context, 'parameter');
7245
7207
  this.deoptimizationInteractions = [];
7246
- this.deoptimizations = new EntityPathTracker();
7208
+ this.deoptimizations = new PathTracker();
7247
7209
  this.deoptimizedFields = new Set();
7248
- this.argumentsToBeDeoptimized = new Set();
7249
- this.expressionsDependingOnKnownValue = [];
7210
+ this.entitiesToBeDeoptimized = new Set();
7211
+ this.expressionsUseTheKnownValue = [];
7250
7212
  this.knownValue = null;
7251
7213
  this.knownValueLiteral = UnknownValue;
7252
7214
  this.frozenValue = null;
7253
7215
  }
7254
- addArgumentValue(entity) {
7255
- this.updateKnownValue(entity);
7216
+ addEntityToBeDeoptimized(entity) {
7256
7217
  if (entity === UNKNOWN_EXPRESSION) {
7257
7218
  // As unknown expressions fully deoptimize all interactions, we can clear
7258
7219
  // the interaction cache at this point provided we keep this optimization
7259
7220
  // in mind when adding new interactions
7260
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7261
- this.argumentsToBeDeoptimized.add(UNKNOWN_EXPRESSION);
7221
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7222
+ this.entitiesToBeDeoptimized.add(UNKNOWN_EXPRESSION);
7262
7223
  for (const { interaction } of this.deoptimizationInteractions) {
7263
7224
  deoptimizeInteraction(interaction);
7264
7225
  }
@@ -7268,30 +7229,27 @@ class ParameterVariable extends LocalVariable {
7268
7229
  else if (this.deoptimizedFields.has(UnknownKey)) {
7269
7230
  // This means that we already deoptimized all interactions and no longer
7270
7231
  // track them
7271
- entity.deoptimizePath([...this.initPath, UnknownKey]);
7232
+ entity.deoptimizePath(UNKNOWN_PATH);
7272
7233
  }
7273
- else if (!this.argumentsToBeDeoptimized.has(entity)) {
7274
- this.argumentsToBeDeoptimized.add(entity);
7234
+ else if (!this.entitiesToBeDeoptimized.has(entity)) {
7235
+ this.entitiesToBeDeoptimized.add(entity);
7275
7236
  for (const field of this.deoptimizedFields) {
7276
- entity.deoptimizePath([...this.initPath, field]);
7237
+ entity.deoptimizePath([field]);
7277
7238
  }
7278
7239
  for (const { interaction, path } of this.deoptimizationInteractions) {
7279
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
7240
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
7280
7241
  }
7281
7242
  }
7282
7243
  }
7283
- /** This says we should not make assumptions about the value of the parameter.
7284
- * This is different from deoptimization that will also cause argument values
7285
- * to be deoptimized. */
7286
7244
  markReassigned() {
7287
7245
  if (this.isReassigned) {
7288
7246
  return;
7289
7247
  }
7290
7248
  super.markReassigned();
7291
- for (const expression of this.expressionsDependingOnKnownValue) {
7249
+ for (const expression of this.expressionsUseTheKnownValue) {
7292
7250
  expression.deoptimizeCache();
7293
7251
  }
7294
- this.expressionsDependingOnKnownValue = parseAst_js.EMPTY_ARRAY;
7252
+ this.expressionsUseTheKnownValue = parseAst_js.EMPTY_ARRAY;
7295
7253
  }
7296
7254
  deoptimizeCache() {
7297
7255
  this.markReassigned();
@@ -7308,7 +7266,7 @@ class ParameterVariable extends LocalVariable {
7308
7266
  }
7309
7267
  if (this.knownValue === null) {
7310
7268
  this.knownValue = argument;
7311
- this.knownValueLiteral = argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this);
7269
+ this.knownValueLiteral = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
7312
7270
  return;
7313
7271
  }
7314
7272
  // the same literal or identifier, do nothing
@@ -7324,7 +7282,7 @@ class ParameterVariable extends LocalVariable {
7324
7282
  return;
7325
7283
  }
7326
7284
  // add tracking for the new argument
7327
- const newValue = argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this);
7285
+ const newValue = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
7328
7286
  if (newValue !== oldValue) {
7329
7287
  this.markReassigned();
7330
7288
  }
@@ -7346,25 +7304,20 @@ class ParameterVariable extends LocalVariable {
7346
7304
  return UnknownValue;
7347
7305
  }
7348
7306
  const knownValue = this.getKnownValue();
7349
- this.expressionsDependingOnKnownValue.push(origin);
7350
- return recursionTracker.withTrackedEntityAtPath(path, knownValue, () => knownValue.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin), UnknownValue);
7307
+ this.expressionsUseTheKnownValue.push(origin);
7308
+ return recursionTracker.withTrackedEntityAtPath(path, knownValue, () => knownValue.getLiteralValueAtPath(path, recursionTracker, origin), UnknownValue);
7351
7309
  }
7352
7310
  hasEffectsOnInteractionAtPath(path, interaction, context) {
7353
- const { type } = interaction;
7354
- if (this.isReassigned || type === INTERACTION_ASSIGNED) {
7311
+ if (this.isReassigned || interaction.type === INTERACTION_ASSIGNED) {
7355
7312
  return super.hasEffectsOnInteractionAtPath(path, interaction, context);
7356
7313
  }
7357
- return (!(type === INTERACTION_CALLED
7358
- ? (interaction.withNew
7359
- ? context.instantiated
7360
- : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this)
7361
- : context.accessed.trackEntityAtPathAndGetIfTracked(path, this)) &&
7362
- this.getKnownValue().hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
7314
+ const knownValue = this.getKnownValue();
7315
+ return knownValue.hasEffectsOnInteractionAtPath(path, interaction, context);
7363
7316
  }
7364
7317
  deoptimizeArgumentsOnInteractionAtPath(interaction, path) {
7365
7318
  // For performance reasons, we fully deoptimize all deeper interactions
7366
7319
  if (path.length >= 2 ||
7367
- this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
7320
+ this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
7368
7321
  this.deoptimizationInteractions.length >= MAX_TRACKED_INTERACTIONS ||
7369
7322
  (path.length === 1 &&
7370
7323
  (this.deoptimizedFields.has(UnknownKey) ||
@@ -7373,10 +7326,10 @@ class ParameterVariable extends LocalVariable {
7373
7326
  return;
7374
7327
  }
7375
7328
  if (!this.deoptimizations.trackEntityAtPathAndGetIfTracked(path, interaction.args)) {
7376
- for (const entity of this.argumentsToBeDeoptimized) {
7377
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
7329
+ for (const entity of this.entitiesToBeDeoptimized) {
7330
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
7378
7331
  }
7379
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7332
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7380
7333
  this.deoptimizationInteractions.push({
7381
7334
  interaction,
7382
7335
  path
@@ -7397,17 +7350,17 @@ class ParameterVariable extends LocalVariable {
7397
7350
  return;
7398
7351
  }
7399
7352
  this.deoptimizedFields.add(key);
7400
- for (const entity of this.argumentsToBeDeoptimized) {
7353
+ for (const entity of this.entitiesToBeDeoptimized) {
7401
7354
  // We do not need a recursion tracker here as we already track whether
7402
7355
  // this field is deoptimized
7403
- entity.deoptimizePath([...this.initPath, key]);
7356
+ entity.deoptimizePath([key]);
7404
7357
  }
7405
7358
  if (key === UnknownKey) {
7406
7359
  // save some memory
7407
7360
  this.deoptimizationInteractions = NO_INTERACTIONS;
7408
7361
  this.deoptimizations = EMPTY_PATH_TRACKER;
7409
7362
  this.deoptimizedFields = UNKNOWN_DEOPTIMIZED_FIELD;
7410
- this.argumentsToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
7363
+ this.entitiesToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
7411
7364
  }
7412
7365
  }
7413
7366
  getReturnExpressionWhenCalledAtPath(path) {
@@ -7422,14 +7375,11 @@ class ParameterVariable extends LocalVariable {
7422
7375
  }
7423
7376
  return UNKNOWN_RETURN_EXPRESSION;
7424
7377
  }
7425
- includeArgumentPaths(entity, context) {
7426
- this.includedPathTracker.includeAllPaths(entity, context, this.initPath);
7427
- }
7428
7378
  }
7429
7379
 
7430
7380
  class ThisVariable extends ParameterVariable {
7431
7381
  constructor(context) {
7432
- super('this', null, EMPTY_PATH, context);
7382
+ super('this', null, context);
7433
7383
  }
7434
7384
  hasEffectsOnInteractionAtPath(path, interaction, context) {
7435
7385
  return (context.replacedVariableInits.get(this) || UNKNOWN_EXPRESSION).hasEffectsOnInteractionAtPath(path, interaction, context);
@@ -7441,7 +7391,7 @@ class CatchBodyScope extends ChildScope {
7441
7391
  super(parent, parent.context);
7442
7392
  this.parent = parent;
7443
7393
  }
7444
- addDeclaration(identifier, context, init, includedInitPath, kind) {
7394
+ addDeclaration(identifier, context, init, kind) {
7445
7395
  if (kind === 'var') {
7446
7396
  const name = identifier.name;
7447
7397
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -7454,7 +7404,7 @@ class CatchBodyScope extends ChildScope {
7454
7404
  // the assignment actually goes to the parameter and the var is
7455
7405
  // hoisted without assignment. Locally, it is shadowed by the
7456
7406
  // parameter
7457
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, includedInitPath, kind);
7407
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, kind);
7458
7408
  // To avoid the need to rewrite the declaration, we link the variable
7459
7409
  // names. If we ever implement a logic that splits initialization and
7460
7410
  // assignment for hoisted vars, the "renderLikeHoisted" logic can be
@@ -7473,7 +7423,7 @@ class CatchBodyScope extends ChildScope {
7473
7423
  return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7474
7424
  }
7475
7425
  // We only add parameters to parameter scopes
7476
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, includedInitPath, kind);
7426
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, kind);
7477
7427
  // Necessary to make sure the init is deoptimized for conditional declarations.
7478
7428
  // We cannot call deoptimizePath here.
7479
7429
  declaredVariable.markInitializersForDeoptimization();
@@ -7481,7 +7431,7 @@ class CatchBodyScope extends ChildScope {
7481
7431
  this.addHoistedVariable(name, declaredVariable);
7482
7432
  return declaredVariable;
7483
7433
  }
7484
- return super.addDeclaration(identifier, context, init, includedInitPath, kind);
7434
+ return super.addDeclaration(identifier, context, init, kind);
7485
7435
  }
7486
7436
  }
7487
7437
 
@@ -7491,7 +7441,7 @@ class FunctionBodyScope extends ChildScope {
7491
7441
  }
7492
7442
  // There is stuff that is only allowed in function scopes, i.e. functions can
7493
7443
  // be redeclared, functions and var can redeclare each other
7494
- addDeclaration(identifier, context, init, includedInitPath, kind) {
7444
+ addDeclaration(identifier, context, init, kind) {
7495
7445
  const name = identifier.name;
7496
7446
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
7497
7447
  if (existingVariable) {
@@ -7503,7 +7453,7 @@ class FunctionBodyScope extends ChildScope {
7503
7453
  }
7504
7454
  context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7505
7455
  }
7506
- const newVariable = new LocalVariable(identifier.name, identifier, init, includedInitPath, context, kind);
7456
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
7507
7457
  this.variables.set(name, newVariable);
7508
7458
  return newVariable;
7509
7459
  }
@@ -7512,21 +7462,21 @@ class FunctionBodyScope extends ChildScope {
7512
7462
  class ParameterScope extends ChildScope {
7513
7463
  constructor(parent, isCatchScope) {
7514
7464
  super(parent, parent.context);
7515
- this.hasRest = false;
7516
7465
  this.parameters = [];
7466
+ this.hasRest = false;
7517
7467
  this.bodyScope = isCatchScope ? new CatchBodyScope(this) : new FunctionBodyScope(this);
7518
7468
  }
7519
7469
  /**
7520
7470
  * Adds a parameter to this scope. Parameters must be added in the correct
7521
7471
  * order, i.e. from left to right.
7522
7472
  */
7523
- addParameterDeclaration(identifier, argumentPath) {
7473
+ addParameterDeclaration(identifier) {
7524
7474
  const { name, start } = identifier;
7525
7475
  const existingParameter = this.variables.get(name);
7526
7476
  if (existingParameter) {
7527
7477
  return this.context.error(parseAst_js.logDuplicateArgumentNameError(name), start);
7528
7478
  }
7529
- const variable = new ParameterVariable(name, identifier, argumentPath, this.context);
7479
+ const variable = new ParameterVariable(name, identifier, this.context);
7530
7480
  this.variables.set(name, variable);
7531
7481
  // We also add it to the body scope to detect name conflicts with local
7532
7482
  // variables. We still need the intermediate scope, though, as parameter
@@ -7544,54 +7494,43 @@ class ParameterScope extends ChildScope {
7544
7494
  }
7545
7495
  this.hasRest = hasRest;
7546
7496
  }
7547
- includeCallArguments(context, interaction) {
7497
+ includeCallArguments(context, parameters) {
7548
7498
  let calledFromTryStatement = false;
7549
7499
  let argumentIncluded = false;
7550
7500
  const restParameter = this.hasRest && this.parameters[this.parameters.length - 1];
7551
- const { args } = interaction;
7552
- let lastExplicitlyIncludedIndex = args.length - 1;
7553
- // If there is a SpreadElement, we need to include all arguments after it
7554
- // because we no longer know which argument corresponds to which parameter.
7555
- for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
7556
- if (args[argumentIndex] instanceof SpreadElement && !argumentIncluded) {
7557
- argumentIncluded = true;
7558
- lastExplicitlyIncludedIndex = argumentIndex - 1;
7559
- }
7560
- if (argumentIncluded) {
7561
- args[argumentIndex].includePath(UNKNOWN_PATH, context, false);
7501
+ for (const checkedArgument of parameters) {
7502
+ if (checkedArgument instanceof SpreadElement) {
7503
+ for (const argument of parameters) {
7504
+ argument.include(context, false);
7505
+ }
7506
+ break;
7562
7507
  }
7563
7508
  }
7564
- // Now we go backwards either starting from the last argument or before the
7565
- // first SpreadElement to ensure all arguments before are included as needed
7566
- for (let index = lastExplicitlyIncludedIndex; index >= 1; index--) {
7567
- const parameterVariables = this.parameters[index - 1] || restParameter;
7568
- const argument = args[index];
7509
+ for (let index = parameters.length - 1; index >= 0; index--) {
7510
+ const parameterVariables = this.parameters[index] || restParameter;
7511
+ const argument = parameters[index];
7569
7512
  if (parameterVariables) {
7570
7513
  calledFromTryStatement = false;
7571
7514
  if (parameterVariables.length === 0) {
7572
- // handle empty destructuring to avoid destructuring undefined
7515
+ // handle empty destructuring
7573
7516
  argumentIncluded = true;
7574
7517
  }
7575
7518
  else {
7576
7519
  for (const variable of parameterVariables) {
7577
- if (variable.calledFromTryStatement) {
7578
- calledFromTryStatement = true;
7579
- }
7580
7520
  if (variable.included) {
7581
7521
  argumentIncluded = true;
7582
- if (calledFromTryStatement) {
7583
- argument.includePath(UNKNOWN_PATH, context, true);
7584
- }
7585
- else {
7586
- variable.includeArgumentPaths(argument, context);
7587
- }
7522
+ }
7523
+ if (variable.calledFromTryStatement) {
7524
+ calledFromTryStatement = true;
7588
7525
  }
7589
7526
  }
7590
7527
  }
7591
7528
  }
7592
- if (!argument.included && (argumentIncluded || argument.shouldBeIncluded(context))) {
7529
+ if (!argumentIncluded && argument.shouldBeIncluded(context)) {
7593
7530
  argumentIncluded = true;
7594
- argument.includePath(EMPTY_PATH, context, calledFromTryStatement);
7531
+ }
7532
+ if (argumentIncluded) {
7533
+ argument.include(context, calledFromTryStatement);
7595
7534
  }
7596
7535
  }
7597
7536
  }
@@ -7606,61 +7545,11 @@ class ReturnValueScope extends ParameterScope {
7606
7545
  addReturnExpression(expression) {
7607
7546
  this.returnExpressions.push(expression);
7608
7547
  }
7609
- deoptimizeArgumentsOnCall(interaction) {
7610
- const { parameters } = this;
7611
- const { args } = interaction;
7612
- let position = 0;
7613
- for (; position < args.length - 1; position++) {
7614
- // Only the "this" argument arg[0] can be null
7615
- const argument = args[position + 1];
7616
- if (argument instanceof SpreadElement) {
7617
- // This deoptimizes the current and remaining parameters and arguments
7618
- for (; position < parameters.length; position++) {
7619
- args[position + 1]?.deoptimizePath(UNKNOWN_PATH);
7620
- parameters[position].forEach(variable => variable.markReassigned());
7621
- }
7622
- break;
7623
- }
7624
- if (this.hasRest && position >= parameters.length - 1) {
7625
- argument.deoptimizePath(UNKNOWN_PATH);
7626
- }
7627
- else {
7628
- const variables = parameters[position];
7629
- if (variables) {
7630
- for (const variable of variables) {
7631
- variable.addArgumentValue(argument);
7632
- }
7633
- }
7634
- this.addArgumentToBeDeoptimized(argument);
7635
- }
7636
- }
7637
- for (; position < parameters.length; position++) {
7638
- for (const variable of parameters[position]) {
7639
- variable.addArgumentValue(UNDEFINED_EXPRESSION);
7640
- }
7641
- }
7642
- }
7643
7548
  getReturnExpression() {
7644
7549
  if (this.returnExpression === null)
7645
7550
  this.updateReturnExpression();
7646
7551
  return this.returnExpression;
7647
7552
  }
7648
- deoptimizeAllParameters() {
7649
- for (const parameter of this.parameters) {
7650
- for (const variable of parameter) {
7651
- variable.deoptimizePath(UNKNOWN_PATH);
7652
- variable.markReassigned();
7653
- }
7654
- }
7655
- }
7656
- reassignAllParameters() {
7657
- for (const parameter of this.parameters) {
7658
- for (const variable of parameter) {
7659
- variable.markReassigned();
7660
- }
7661
- }
7662
- }
7663
- addArgumentToBeDeoptimized(_argument) { }
7664
7553
  updateReturnExpression() {
7665
7554
  if (this.returnExpressions.length === 1) {
7666
7555
  this.returnExpression = this.returnExpressions[0];
@@ -7676,26 +7565,24 @@ class ReturnValueScope extends ParameterScope {
7676
7565
 
7677
7566
  class FunctionScope extends ReturnValueScope {
7678
7567
  constructor(parent) {
7679
- super(parent, false);
7680
7568
  const { context } = parent;
7569
+ super(parent, false);
7681
7570
  this.variables.set('arguments', (this.argumentsVariable = new ArgumentsVariable(context)));
7682
7571
  this.variables.set('this', (this.thisVariable = new ThisVariable(context)));
7683
7572
  }
7684
7573
  findLexicalBoundary() {
7685
7574
  return this;
7686
7575
  }
7687
- includeCallArguments(context, interaction) {
7688
- super.includeCallArguments(context, interaction);
7576
+ includeCallArguments(context, parameters) {
7577
+ super.includeCallArguments(context, parameters);
7689
7578
  if (this.argumentsVariable.included) {
7690
- const { args } = interaction;
7691
- for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
7692
- args[argumentIndex]?.includePath(UNKNOWN_PATH, context, false);
7579
+ for (const argument of parameters) {
7580
+ if (!argument.included) {
7581
+ argument.include(context, false);
7582
+ }
7693
7583
  }
7694
7584
  }
7695
7585
  }
7696
- addArgumentToBeDeoptimized(argument) {
7697
- this.argumentsVariable.addArgumentToBeDeoptimized(argument);
7698
- }
7699
7586
  }
7700
7587
 
7701
7588
  class ExpressionStatement extends NodeBase {
@@ -7761,7 +7648,7 @@ class BlockStatement extends NodeBase {
7761
7648
  }
7762
7649
  return false;
7763
7650
  }
7764
- includePath(_path, context, includeChildrenRecursively) {
7651
+ include(context, includeChildrenRecursively) {
7765
7652
  if (!(this.deoptimizeBody && this.directlyIncluded)) {
7766
7653
  this.included = true;
7767
7654
  this.directlyIncluded = true;
@@ -7769,7 +7656,7 @@ class BlockStatement extends NodeBase {
7769
7656
  includeChildrenRecursively = true;
7770
7657
  for (const node of this.body) {
7771
7658
  if (includeChildrenRecursively || node.shouldBeIncluded(context))
7772
- node.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
7659
+ node.include(context, includeChildrenRecursively);
7773
7660
  }
7774
7661
  }
7775
7662
  }
@@ -7798,9 +7685,9 @@ class RestElement extends NodeBase {
7798
7685
  addExportedVariables(variables, exportNamesByVariable) {
7799
7686
  this.argument.addExportedVariables(variables, exportNamesByVariable);
7800
7687
  }
7801
- declare(kind, includedInitPath, init) {
7688
+ declare(kind, init) {
7802
7689
  this.declarationInit = init;
7803
- return this.argument.declare(kind, includedInitPath.at(-1) === UnknownKey ? includedInitPath : [...includedInitPath, UnknownKey], init);
7690
+ return this.argument.declare(kind, UNKNOWN_EXPRESSION);
7804
7691
  }
7805
7692
  deoptimizePath(path) {
7806
7693
  if (path.length === 0) {
@@ -7811,12 +7698,6 @@ class RestElement extends NodeBase {
7811
7698
  return (path.length > 0 ||
7812
7699
  this.argument.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
7813
7700
  }
7814
- includePath(_path, context, includeChildrenRecursively) {
7815
- this.included = true;
7816
- // This should just include the identifier, its properties should be
7817
- // included where the variable is used.
7818
- this.argument.includePath(EMPTY_PATH, context, includeChildrenRecursively);
7819
- }
7820
7701
  markDeclarationReached() {
7821
7702
  this.argument.markDeclarationReached();
7822
7703
  }
@@ -7832,8 +7713,8 @@ class RestElement extends NodeBase {
7832
7713
  class FunctionBase extends NodeBase {
7833
7714
  constructor() {
7834
7715
  super(...arguments);
7716
+ this.objectEntity = null;
7835
7717
  this.parameterVariableValuesDeoptimized = false;
7836
- this.includeCallArguments = this.scope.includeCallArguments.bind(this.scope);
7837
7718
  }
7838
7719
  get async() {
7839
7720
  return isFlagSet(this.flags, 256 /* Flag.async */);
@@ -7853,9 +7734,53 @@ class FunctionBase extends NodeBase {
7853
7734
  set generator(value) {
7854
7735
  this.flags = setFlag(this.flags, 4194304 /* Flag.generator */, value);
7855
7736
  }
7737
+ updateParameterVariableValues(_arguments) {
7738
+ for (let position = 0; position < this.params.length; position++) {
7739
+ const parameter = this.params[position];
7740
+ if (!(parameter instanceof Identifier)) {
7741
+ continue;
7742
+ }
7743
+ const parameterVariable = parameter.variable;
7744
+ const argument = _arguments[position + 1] ?? UNDEFINED_EXPRESSION;
7745
+ parameterVariable.updateKnownValue(argument);
7746
+ }
7747
+ }
7748
+ deoptimizeParameterVariableValues() {
7749
+ for (const parameter of this.params) {
7750
+ if (parameter instanceof Identifier) {
7751
+ const parameterVariable = parameter.variable;
7752
+ parameterVariable.markReassigned();
7753
+ }
7754
+ }
7755
+ }
7856
7756
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
7857
- if (interaction.type === INTERACTION_CALLED && path.length === 0) {
7858
- this.scope.deoptimizeArgumentsOnCall(interaction);
7757
+ if (interaction.type === INTERACTION_CALLED) {
7758
+ const { parameters } = this.scope;
7759
+ const { args } = interaction;
7760
+ let hasRest = false;
7761
+ for (let position = 0; position < args.length - 1; position++) {
7762
+ const parameter = this.params[position];
7763
+ // Only the "this" argument arg[0] can be null
7764
+ const argument = args[position + 1];
7765
+ if (argument instanceof SpreadElement) {
7766
+ this.deoptimizeParameterVariableValues();
7767
+ }
7768
+ if (hasRest || parameter instanceof RestElement) {
7769
+ hasRest = true;
7770
+ argument.deoptimizePath(UNKNOWN_PATH);
7771
+ }
7772
+ else if (parameter instanceof Identifier) {
7773
+ parameters[position][0].addEntityToBeDeoptimized(argument);
7774
+ this.addArgumentToBeDeoptimized(argument);
7775
+ }
7776
+ else if (parameter) {
7777
+ argument.deoptimizePath(UNKNOWN_PATH);
7778
+ }
7779
+ else {
7780
+ this.addArgumentToBeDeoptimized(argument);
7781
+ }
7782
+ }
7783
+ this.updateParameterVariableValues(args);
7859
7784
  }
7860
7785
  else {
7861
7786
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -7867,7 +7792,12 @@ class FunctionBase extends NodeBase {
7867
7792
  // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
7868
7793
  // which means the return expression and parameters need to be reassigned
7869
7794
  this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
7870
- this.scope.deoptimizeAllParameters();
7795
+ for (const parameterList of this.scope.parameters) {
7796
+ for (const parameter of parameterList) {
7797
+ parameter.deoptimizePath(UNKNOWN_PATH);
7798
+ parameter.markReassigned();
7799
+ }
7800
+ }
7871
7801
  }
7872
7802
  }
7873
7803
  getLiteralValueAtPath(path, recursionTracker, origin) {
@@ -7924,19 +7854,22 @@ class FunctionBase extends NodeBase {
7924
7854
  }
7925
7855
  return variable?.getOnlyFunctionCallUsed() ?? false;
7926
7856
  }
7927
- includePath(_path, context, includeChildrenRecursively) {
7928
- if (!(this.parameterVariableValuesDeoptimized || this.onlyFunctionCallUsed())) {
7857
+ include(context, includeChildrenRecursively) {
7858
+ if (!this.parameterVariableValuesDeoptimized && !this.onlyFunctionCallUsed()) {
7929
7859
  this.parameterVariableValuesDeoptimized = true;
7930
- this.scope.reassignAllParameters();
7860
+ this.deoptimizeParameterVariableValues();
7931
7861
  }
7932
7862
  if (!this.deoptimized)
7933
7863
  this.applyDeoptimizations();
7934
7864
  this.included = true;
7935
7865
  const { brokenFlow } = context;
7936
7866
  context.brokenFlow = false;
7937
- this.body.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
7867
+ this.body.include(context, includeChildrenRecursively);
7938
7868
  context.brokenFlow = brokenFlow;
7939
7869
  }
7870
+ includeCallArguments(context, parameters) {
7871
+ this.scope.includeCallArguments(context, parameters);
7872
+ }
7940
7873
  initialise() {
7941
7874
  super.initialise();
7942
7875
  if (this.body instanceof BlockStatement) {
@@ -7958,10 +7891,11 @@ class FunctionBase extends NodeBase {
7958
7891
  // so that the scope already knows all parameters and can detect conflicts
7959
7892
  // when parsing the body.
7960
7893
  const parameters = (this.params = params.map((parameter) => new (context.getNodeConstructor(parameter.type))(this, scope).parseNode(parameter)));
7961
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
7894
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
7962
7895
  this.body = new (context.getNodeConstructor(body.type))(this, bodyScope).parseNode(body);
7963
7896
  return super.parseNode(esTreeNode);
7964
7897
  }
7898
+ addArgumentToBeDeoptimized(_argument) { }
7965
7899
  applyDeoptimizations() { }
7966
7900
  }
7967
7901
  FunctionBase.prototype.preventChildBlockScope = true;
@@ -7976,13 +7910,13 @@ class FunctionNode extends FunctionBase {
7976
7910
  this.constructedEntity = new ObjectEntity(Object.create(null), OBJECT_PROTOTYPE);
7977
7911
  // This makes sure that all deoptimizations of "this" are applied to the
7978
7912
  // constructed entity.
7979
- this.scope.thisVariable.addArgumentValue(this.constructedEntity);
7913
+ this.scope.thisVariable.addEntityToBeDeoptimized(this.constructedEntity);
7980
7914
  }
7981
7915
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
7982
7916
  super.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
7983
7917
  if (interaction.type === INTERACTION_CALLED && path.length === 0 && interaction.args[0]) {
7984
7918
  // args[0] is the "this" argument
7985
- this.scope.thisVariable.addArgumentValue(interaction.args[0]);
7919
+ this.scope.thisVariable.addEntityToBeDeoptimized(interaction.args[0]);
7986
7920
  }
7987
7921
  }
7988
7922
  hasEffects(context) {
@@ -8023,19 +7957,22 @@ class FunctionNode extends FunctionBase {
8023
7957
  }
8024
7958
  return false;
8025
7959
  }
8026
- includePath(path, context, includeChildrenRecursively) {
8027
- super.includePath(path, context, includeChildrenRecursively);
8028
- this.id?.includePath(UNKNOWN_PATH, createInclusionContext());
7960
+ include(context, includeChildrenRecursively) {
7961
+ super.include(context, includeChildrenRecursively);
7962
+ this.id?.include();
8029
7963
  const hasArguments = this.scope.argumentsVariable.included;
8030
7964
  for (const parameter of this.params) {
8031
7965
  if (!(parameter instanceof Identifier) || hasArguments) {
8032
- parameter.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
7966
+ parameter.include(context, includeChildrenRecursively);
8033
7967
  }
8034
7968
  }
8035
7969
  }
8036
7970
  initialise() {
8037
7971
  super.initialise();
8038
- this.id?.declare('function', EMPTY_PATH, this);
7972
+ this.id?.declare('function', this);
7973
+ }
7974
+ addArgumentToBeDeoptimized(argument) {
7975
+ this.scope.argumentsVariable.addArgumentToBeDeoptimized(argument);
8039
7976
  }
8040
7977
  getObjectEntity() {
8041
7978
  if (this.objectEntity !== null) {
@@ -8084,11 +8021,10 @@ function getFunctionIdInsertPosition(code, start) {
8084
8021
  return declarationEnd + generatorStarPos + 1;
8085
8022
  }
8086
8023
  class ExportDefaultDeclaration extends NodeBase {
8087
- includePath(path, context, includeChildrenRecursively) {
8088
- this.included = true;
8089
- this.declaration.includePath(path, context, includeChildrenRecursively);
8024
+ include(context, includeChildrenRecursively) {
8025
+ super.include(context, includeChildrenRecursively);
8090
8026
  if (includeChildrenRecursively) {
8091
- this.scope.context.includeVariableInModule(this.variable, path);
8027
+ this.scope.context.includeVariableInModule(this.variable);
8092
8028
  }
8093
8029
  }
8094
8030
  initialise() {
@@ -8661,27 +8597,27 @@ class MemberExpression extends NodeBase {
8661
8597
  }
8662
8598
  return true;
8663
8599
  }
8664
- includePath(path, context, includeChildrenRecursively) {
8600
+ include(context, includeChildrenRecursively) {
8665
8601
  if (!this.deoptimized)
8666
8602
  this.applyDeoptimizations();
8667
- this.includeProperties(path, [this.getPropertyKey(), ...path], context, includeChildrenRecursively);
8603
+ this.includeProperties(context, includeChildrenRecursively);
8668
8604
  }
8669
8605
  includeAsAssignmentTarget(context, includeChildrenRecursively, deoptimizeAccess) {
8670
8606
  if (!this.assignmentDeoptimized)
8671
8607
  this.applyAssignmentDeoptimization();
8672
8608
  if (deoptimizeAccess) {
8673
- this.includePath([this.getPropertyKey()], context, includeChildrenRecursively);
8609
+ this.include(context, includeChildrenRecursively);
8674
8610
  }
8675
8611
  else {
8676
- this.includeProperties(EMPTY_PATH, [this.getPropertyKey()], context, includeChildrenRecursively);
8612
+ this.includeProperties(context, includeChildrenRecursively);
8677
8613
  }
8678
8614
  }
8679
- includeCallArguments(context, interaction) {
8615
+ includeCallArguments(context, parameters) {
8680
8616
  if (this.variable) {
8681
- this.variable.includeCallArguments(context, interaction);
8617
+ this.variable.includeCallArguments(context, parameters);
8682
8618
  }
8683
8619
  else {
8684
- super.includeCallArguments(context, interaction);
8620
+ super.includeCallArguments(context, parameters);
8685
8621
  }
8686
8622
  }
8687
8623
  initialise() {
@@ -8750,7 +8686,7 @@ class MemberExpression extends NodeBase {
8750
8686
  const variable = this.scope.findVariable(this.object.name);
8751
8687
  if (variable.isNamespace) {
8752
8688
  if (this.variable) {
8753
- this.scope.context.includeVariableInModule(this.variable, UNKNOWN_PATH);
8689
+ this.scope.context.includeVariableInModule(this.variable);
8754
8690
  }
8755
8691
  this.scope.context.log(parseAst_js.LOGLEVEL_WARN, parseAst_js.logIllegalImportReassignment(this.object.name, this.scope.context.module.id), this.start);
8756
8692
  }
@@ -8777,18 +8713,15 @@ class MemberExpression extends NodeBase {
8777
8713
  (propertyReadSideEffects === 'always' ||
8778
8714
  this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey()], this.accessInteraction, context)));
8779
8715
  }
8780
- includeProperties(includedPath, objectPath, context, includeChildrenRecursively) {
8716
+ includeProperties(context, includeChildrenRecursively) {
8781
8717
  if (!this.included) {
8782
8718
  this.included = true;
8783
8719
  if (this.variable) {
8784
- this.scope.context.includeVariableInModule(this.variable, includedPath);
8720
+ this.scope.context.includeVariableInModule(this.variable);
8785
8721
  }
8786
8722
  }
8787
- else if (includedPath.length > 0) {
8788
- this.variable?.includePath(includedPath, context);
8789
- }
8790
- this.object.includePath(objectPath, context, includeChildrenRecursively);
8791
- this.property.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
8723
+ this.object.include(context, includeChildrenRecursively);
8724
+ this.property.include(context, includeChildrenRecursively);
8792
8725
  }
8793
8726
  }
8794
8727
  function resolveNamespaceVariables(baseVariable, path, astContext) {
@@ -8831,7 +8764,7 @@ class MetaProperty extends NodeBase {
8831
8764
  hasEffectsOnInteractionAtPath(path, { type }) {
8832
8765
  return path.length > 1 || type !== INTERACTION_ACCESSED;
8833
8766
  }
8834
- includePath() {
8767
+ include() {
8835
8768
  if (!this.included) {
8836
8769
  this.included = true;
8837
8770
  if (this.meta.name === IMPORT) {
@@ -8950,7 +8883,7 @@ class UndefinedVariable extends Variable {
8950
8883
 
8951
8884
  class ExportDefaultVariable extends LocalVariable {
8952
8885
  constructor(name, exportDefaultDeclaration, context) {
8953
- super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, EMPTY_PATH, context, 'other');
8886
+ super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context, 'other');
8954
8887
  this.hasId = false;
8955
8888
  this.originalId = null;
8956
8889
  this.originalVariable = null;
@@ -9099,8 +9032,8 @@ class NamespaceVariable extends Variable {
9099
9032
  return (!memberVariable ||
9100
9033
  memberVariable.hasEffectsOnInteractionAtPath(path.slice(1), interaction, context));
9101
9034
  }
9102
- includePath(path, context) {
9103
- super.includePath(path, context);
9035
+ include() {
9036
+ super.include();
9104
9037
  this.context.includeAllExports();
9105
9038
  }
9106
9039
  prepare(accessedGlobalsByScope) {
@@ -9193,9 +9126,9 @@ class SyntheticNamedExportVariable extends Variable {
9193
9126
  getName(getPropertyAccess) {
9194
9127
  return `${this.syntheticNamespace.getName(getPropertyAccess)}${getPropertyAccess(this.name)}`;
9195
9128
  }
9196
- includePath(path, context) {
9197
- super.includePath(path, context);
9198
- this.context.includeVariableInModule(this.syntheticNamespace, path);
9129
+ include() {
9130
+ super.include();
9131
+ this.context.includeVariableInModule(this.syntheticNamespace);
9199
9132
  }
9200
9133
  setRenderNames(baseName, name) {
9201
9134
  super.setRenderNames(baseName, name);
@@ -9722,14 +9655,16 @@ function getImportBlock(dependencies, importAttributesKey, { _ }) {
9722
9655
  }
9723
9656
  function getExportBlock(exports, { _, cnst }) {
9724
9657
  const exportBlock = [];
9725
- const exportDeclaration = [];
9658
+ const exportDeclaration = new Array(exports.length);
9659
+ let index = 0;
9726
9660
  for (const specifier of exports) {
9727
9661
  if (specifier.expression) {
9728
9662
  exportBlock.push(`${cnst} ${specifier.local}${_}=${_}${specifier.expression};`);
9729
9663
  }
9730
- exportDeclaration.push(specifier.exported === specifier.local
9731
- ? specifier.local
9732
- : `${specifier.local} as ${stringifyIdentifierIfNeeded(specifier.exported)}`);
9664
+ exportDeclaration[index++] =
9665
+ specifier.exported === specifier.local
9666
+ ? specifier.local
9667
+ : `${specifier.local} as ${stringifyIdentifierIfNeeded(specifier.exported)}`;
9733
9668
  }
9734
9669
  if (exportDeclaration.length > 0) {
9735
9670
  exportBlock.push(`export${_}{${_}${exportDeclaration.join(`,${_}`)}${_}};`);
@@ -12392,14 +12327,11 @@ class ArrayPattern extends NodeBase {
12392
12327
  element?.addExportedVariables(variables, exportNamesByVariable);
12393
12328
  }
12394
12329
  }
12395
- declare(kind, includedInitPath, init) {
12330
+ declare(kind) {
12396
12331
  const variables = [];
12397
- const includedPatternPath = includedInitPath.at(-1) === UnknownKey
12398
- ? includedInitPath
12399
- : [...includedInitPath, UnknownInteger];
12400
12332
  for (const element of this.elements) {
12401
12333
  if (element !== null) {
12402
- variables.push(...element.declare(kind, includedPatternPath, init));
12334
+ variables.push(...element.declare(kind, UNKNOWN_EXPRESSION));
12403
12335
  }
12404
12336
  }
12405
12337
  return variables;
@@ -12472,11 +12404,11 @@ class ArrowFunctionExpression extends FunctionBase {
12472
12404
  this.parent.callee === this;
12473
12405
  return isIIFE || super.onlyFunctionCallUsed();
12474
12406
  }
12475
- includePath(_path, context, includeChildrenRecursively) {
12476
- super.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12407
+ include(context, includeChildrenRecursively) {
12408
+ super.include(context, includeChildrenRecursively);
12477
12409
  for (const parameter of this.params) {
12478
12410
  if (!(parameter instanceof Identifier)) {
12479
- parameter.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12411
+ parameter.include(context, includeChildrenRecursively);
12480
12412
  }
12481
12413
  }
12482
12414
  }
@@ -12499,10 +12431,10 @@ class ObjectPattern extends NodeBase {
12499
12431
  }
12500
12432
  }
12501
12433
  }
12502
- declare(kind, includedInitPath, init) {
12434
+ declare(kind, init) {
12503
12435
  const variables = [];
12504
12436
  for (const property of this.properties) {
12505
- variables.push(...property.declare(kind, includedInitPath, init));
12437
+ variables.push(...property.declare(kind, init));
12506
12438
  }
12507
12439
  return variables;
12508
12440
  }
@@ -12523,22 +12455,11 @@ class ObjectPattern extends NodeBase {
12523
12455
  }
12524
12456
  return false;
12525
12457
  }
12526
- includePath(_path, context, includeChildrenRecursively) {
12527
- this.included = true;
12528
- for (const property of this.properties) {
12529
- // Including a pattern should not deeply include its children as that
12530
- // would include all children of nested variable references. Their paths
12531
- // will be included via their usages instead, and we store the path in
12532
- // the pattern when declaring the variables.
12533
- property.includePath(EMPTY_PATH, context, includeChildrenRecursively);
12534
- }
12535
- }
12536
12458
  markDeclarationReached() {
12537
12459
  for (const property of this.properties) {
12538
12460
  property.markDeclarationReached();
12539
12461
  }
12540
12462
  }
12541
- applyDeoptimizations() { }
12542
12463
  }
12543
12464
 
12544
12465
  class AssignmentExpression extends NodeBase {
@@ -12553,7 +12474,7 @@ class AssignmentExpression extends NodeBase {
12553
12474
  hasEffectsOnInteractionAtPath(path, interaction, context) {
12554
12475
  return this.right.hasEffectsOnInteractionAtPath(path, interaction, context);
12555
12476
  }
12556
- includePath(_path, context, includeChildrenRecursively) {
12477
+ include(context, includeChildrenRecursively) {
12557
12478
  const { deoptimized, left, right, operator } = this;
12558
12479
  if (!deoptimized)
12559
12480
  this.applyDeoptimizations();
@@ -12564,7 +12485,7 @@ class AssignmentExpression extends NodeBase {
12564
12485
  left.hasEffectsAsAssignmentTarget(createHasEffectsContext(), false)) {
12565
12486
  left.includeAsAssignmentTarget(context, includeChildrenRecursively, operator !== '=');
12566
12487
  }
12567
- right.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12488
+ right.include(context, includeChildrenRecursively);
12568
12489
  }
12569
12490
  initialise() {
12570
12491
  super.initialise();
@@ -12636,8 +12557,8 @@ class AssignmentPattern extends NodeBase {
12636
12557
  addExportedVariables(variables, exportNamesByVariable) {
12637
12558
  this.left.addExportedVariables(variables, exportNamesByVariable);
12638
12559
  }
12639
- declare(kind, includedInitPath, init) {
12640
- return this.left.declare(kind, includedInitPath, init);
12560
+ declare(kind, init) {
12561
+ return this.left.declare(kind, init);
12641
12562
  }
12642
12563
  deoptimizePath(path) {
12643
12564
  if (path.length === 0) {
@@ -12668,7 +12589,7 @@ class AwaitExpression extends NodeBase {
12668
12589
  this.applyDeoptimizations();
12669
12590
  return true;
12670
12591
  }
12671
- includePath(path, context, includeChildrenRecursively) {
12592
+ include(context, includeChildrenRecursively) {
12672
12593
  if (!this.deoptimized)
12673
12594
  this.applyDeoptimizations();
12674
12595
  if (!this.included) {
@@ -12682,7 +12603,7 @@ class AwaitExpression extends NodeBase {
12682
12603
  this.scope.context.usesTopLevelAwait = true;
12683
12604
  }
12684
12605
  }
12685
- this.argument.includePath(path, context, includeChildrenRecursively);
12606
+ this.argument.include(context, includeChildrenRecursively);
12686
12607
  }
12687
12608
  }
12688
12609
 
@@ -12764,10 +12685,10 @@ class BreakStatement extends NodeBase {
12764
12685
  context.brokenFlow = true;
12765
12686
  return false;
12766
12687
  }
12767
- includePath(_, context) {
12688
+ include(context) {
12768
12689
  this.included = true;
12769
12690
  if (this.label) {
12770
- this.label.includePath(UNKNOWN_PATH, createInclusionContext());
12691
+ this.label.include();
12771
12692
  context.includedLabels.add(this.label.name);
12772
12693
  }
12773
12694
  else {
@@ -12961,11 +12882,11 @@ class CallExpression extends CallExpressionBase {
12961
12882
  (calleeHasEffects ||
12962
12883
  this.callee.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context)));
12963
12884
  }
12964
- includePath(path, context, includeChildrenRecursively) {
12885
+ include(context, includeChildrenRecursively) {
12965
12886
  if (!this.deoptimized)
12966
12887
  this.applyDeoptimizations();
12967
12888
  if (includeChildrenRecursively) {
12968
- super.includePath(path, context, includeChildrenRecursively);
12889
+ super.include(context, includeChildrenRecursively);
12969
12890
  if (includeChildrenRecursively === INCLUDE_PARAMETERS &&
12970
12891
  this.callee instanceof Identifier &&
12971
12892
  this.callee.variable) {
@@ -12974,18 +12895,9 @@ class CallExpression extends CallExpressionBase {
12974
12895
  }
12975
12896
  else {
12976
12897
  this.included = true;
12977
- // If the callee is a member expression and does not have a variable, its
12978
- // object will already be included via the first argument of the
12979
- // interaction in includeCallArguments. Including it again can lead to
12980
- // severe performance problems.
12981
- if (this.callee instanceof MemberExpression && !this.callee.variable) {
12982
- this.callee.property.includePath(UNKNOWN_PATH, context, false);
12983
- }
12984
- else {
12985
- this.callee.includePath(UNKNOWN_PATH, context, false);
12986
- }
12987
- this.callee.includeCallArguments(context, this.interaction);
12898
+ this.callee.include(context, false);
12988
12899
  }
12900
+ this.callee.includeCallArguments(context, this.arguments);
12989
12901
  }
12990
12902
  initialise() {
12991
12903
  super.initialise();
@@ -13024,7 +12936,7 @@ class CatchClause extends NodeBase {
13024
12936
  this.type = type;
13025
12937
  if (param) {
13026
12938
  this.param = new (this.scope.context.getNodeConstructor(param.type))(this, this.scope).parseNode(param);
13027
- this.param.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
12939
+ this.param.declare('parameter', UNKNOWN_EXPRESSION);
13028
12940
  }
13029
12941
  this.body = new BlockStatement(this, this.scope.bodyScope).parseNode(body);
13030
12942
  return super.parseNode(esTreeNode);
@@ -13052,7 +12964,7 @@ class ClassBodyScope extends ChildScope {
13052
12964
  constructor(parent, classNode) {
13053
12965
  const { context } = parent;
13054
12966
  super(parent, context);
13055
- this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, EMPTY_PATH, context, 'other')));
12967
+ this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, context, 'other')));
13056
12968
  this.instanceScope = new ChildScope(this, context);
13057
12969
  this.instanceScope.variables.set('this', new ThisVariable(context));
13058
12970
  }
@@ -13065,17 +12977,18 @@ class ClassBody extends NodeBase {
13065
12977
  createScope(parentScope) {
13066
12978
  this.scope = new ClassBodyScope(parentScope, this.parent);
13067
12979
  }
13068
- includePath(_path, context, includeChildrenRecursively) {
12980
+ include(context, includeChildrenRecursively) {
13069
12981
  this.included = true;
13070
- this.scope.context.includeVariableInModule(this.scope.thisVariable, UNKNOWN_PATH);
12982
+ this.scope.context.includeVariableInModule(this.scope.thisVariable);
13071
12983
  for (const definition of this.body) {
13072
- definition.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12984
+ definition.include(context, includeChildrenRecursively);
13073
12985
  }
13074
12986
  }
13075
12987
  parseNode(esTreeNode) {
13076
- const body = (this.body = []);
12988
+ const body = (this.body = new Array(esTreeNode.body.length));
12989
+ let index = 0;
13077
12990
  for (const definition of esTreeNode.body) {
13078
- body.push(new (this.scope.context.getNodeConstructor(definition.type))(this, definition.static ? this.scope : this.scope.instanceScope).parseNode(definition));
12991
+ body[index++] = new (this.scope.context.getNodeConstructor(definition.type))(this, definition.static ? this.scope : this.scope.instanceScope).parseNode(definition);
13079
12992
  }
13080
12993
  return super.parseNode(esTreeNode);
13081
12994
  }
@@ -13192,26 +13105,26 @@ class ConditionalExpression extends NodeBase {
13192
13105
  }
13193
13106
  return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
13194
13107
  }
13195
- includePath(path, context, includeChildrenRecursively) {
13108
+ include(context, includeChildrenRecursively) {
13196
13109
  this.included = true;
13197
13110
  const usedBranch = this.getUsedBranch();
13198
13111
  if (includeChildrenRecursively || this.test.shouldBeIncluded(context) || usedBranch === null) {
13199
- this.test.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13200
- this.consequent.includePath(path, context, includeChildrenRecursively);
13201
- this.alternate.includePath(path, context, includeChildrenRecursively);
13112
+ this.test.include(context, includeChildrenRecursively);
13113
+ this.consequent.include(context, includeChildrenRecursively);
13114
+ this.alternate.include(context, includeChildrenRecursively);
13202
13115
  }
13203
13116
  else {
13204
- usedBranch.includePath(path, context, includeChildrenRecursively);
13117
+ usedBranch.include(context, includeChildrenRecursively);
13205
13118
  }
13206
13119
  }
13207
- includeCallArguments(context, interaction) {
13120
+ includeCallArguments(context, parameters) {
13208
13121
  const usedBranch = this.getUsedBranch();
13209
13122
  if (usedBranch) {
13210
- usedBranch.includeCallArguments(context, interaction);
13123
+ usedBranch.includeCallArguments(context, parameters);
13211
13124
  }
13212
13125
  else {
13213
- this.consequent.includeCallArguments(context, interaction);
13214
- this.alternate.includeCallArguments(context, interaction);
13126
+ this.consequent.includeCallArguments(context, parameters);
13127
+ this.alternate.includeCallArguments(context, parameters);
13215
13128
  }
13216
13129
  }
13217
13130
  removeAnnotations(code) {
@@ -13272,10 +13185,10 @@ class ContinueStatement extends NodeBase {
13272
13185
  context.brokenFlow = true;
13273
13186
  return false;
13274
13187
  }
13275
- includePath(_, context) {
13188
+ include(context) {
13276
13189
  this.included = true;
13277
13190
  if (this.label) {
13278
- this.label.includePath(UNKNOWN_PATH, createInclusionContext());
13191
+ this.label.include();
13279
13192
  context.includedLabels.add(this.label.name);
13280
13193
  }
13281
13194
  else {
@@ -13318,7 +13231,7 @@ function includeLoopBody(context, body, includeChildrenRecursively) {
13318
13231
  const { brokenFlow, hasBreak, hasContinue } = context;
13319
13232
  context.hasBreak = false;
13320
13233
  context.hasContinue = false;
13321
- body.includePath(UNKNOWN_PATH, context, includeChildrenRecursively, { asSingleStatement: true });
13234
+ body.include(context, includeChildrenRecursively, { asSingleStatement: true });
13322
13235
  context.hasBreak = hasBreak;
13323
13236
  context.hasContinue = hasContinue;
13324
13237
  context.brokenFlow = brokenFlow;
@@ -13330,9 +13243,9 @@ class DoWhileStatement extends NodeBase {
13330
13243
  return true;
13331
13244
  return hasLoopBodyEffects(context, this.body);
13332
13245
  }
13333
- includePath(_path, context, includeChildrenRecursively) {
13246
+ include(context, includeChildrenRecursively) {
13334
13247
  this.included = true;
13335
- this.test.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13248
+ this.test.include(context, includeChildrenRecursively);
13336
13249
  includeLoopBody(context, this.body, includeChildrenRecursively);
13337
13250
  }
13338
13251
  }
@@ -13403,13 +13316,13 @@ class ForInStatement extends NodeBase {
13403
13316
  return true;
13404
13317
  return hasLoopBodyEffects(context, body);
13405
13318
  }
13406
- includePath(_path, context, includeChildrenRecursively) {
13319
+ include(context, includeChildrenRecursively) {
13407
13320
  const { body, deoptimized, left, right } = this;
13408
13321
  if (!deoptimized)
13409
13322
  this.applyDeoptimizations();
13410
13323
  this.included = true;
13411
13324
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
13412
- right.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13325
+ right.include(context, includeChildrenRecursively);
13413
13326
  includeLoopBody(context, body, includeChildrenRecursively);
13414
13327
  }
13415
13328
  initialise() {
@@ -13448,13 +13361,13 @@ class ForOfStatement extends NodeBase {
13448
13361
  // Placeholder until proper Symbol.Iterator support
13449
13362
  return true;
13450
13363
  }
13451
- includePath(_path, context, includeChildrenRecursively) {
13364
+ include(context, includeChildrenRecursively) {
13452
13365
  const { body, deoptimized, left, right } = this;
13453
13366
  if (!deoptimized)
13454
13367
  this.applyDeoptimizations();
13455
13368
  this.included = true;
13456
13369
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
13457
- right.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13370
+ right.include(context, includeChildrenRecursively);
13458
13371
  includeLoopBody(context, body, includeChildrenRecursively);
13459
13372
  }
13460
13373
  initialise() {
@@ -13490,13 +13403,11 @@ class ForStatement extends NodeBase {
13490
13403
  }
13491
13404
  return hasLoopBodyEffects(context, this.body);
13492
13405
  }
13493
- includePath(_path, context, includeChildrenRecursively) {
13406
+ include(context, includeChildrenRecursively) {
13494
13407
  this.included = true;
13495
- this.init?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively, {
13496
- asSingleStatement: true
13497
- });
13498
- this.test?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13499
- this.update?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13408
+ this.init?.include(context, includeChildrenRecursively, { asSingleStatement: true });
13409
+ this.test?.include(context, includeChildrenRecursively);
13410
+ this.update?.include(context, includeChildrenRecursively);
13500
13411
  includeLoopBody(context, this.body, includeChildrenRecursively);
13501
13412
  }
13502
13413
  render(code, options) {
@@ -13537,9 +13448,9 @@ class TrackingScope extends BlockScope {
13537
13448
  super(...arguments);
13538
13449
  this.hoistedDeclarations = [];
13539
13450
  }
13540
- addDeclaration(identifier, context, init, includedInitPath, kind) {
13451
+ addDeclaration(identifier, context, init, kind) {
13541
13452
  this.hoistedDeclarations.push(identifier);
13542
- return super.addDeclaration(identifier, context, init, includedInitPath, kind);
13453
+ return super.addDeclaration(identifier, context, init, kind);
13543
13454
  }
13544
13455
  }
13545
13456
 
@@ -13572,7 +13483,7 @@ class IfStatement extends NodeBase {
13572
13483
  }
13573
13484
  return testValue ? this.consequent.hasEffects(context) : !!this.alternate?.hasEffects(context);
13574
13485
  }
13575
- includePath(_, context, includeChildrenRecursively) {
13486
+ include(context, includeChildrenRecursively) {
13576
13487
  this.included = true;
13577
13488
  if (includeChildrenRecursively) {
13578
13489
  this.includeRecursively(includeChildrenRecursively, context);
@@ -13647,31 +13558,31 @@ class IfStatement extends NodeBase {
13647
13558
  }
13648
13559
  includeKnownTest(context, testValue) {
13649
13560
  if (this.test.shouldBeIncluded(context)) {
13650
- this.test.includePath(UNKNOWN_PATH, context, false);
13561
+ this.test.include(context, false);
13651
13562
  }
13652
13563
  if (testValue && this.consequent.shouldBeIncluded(context)) {
13653
- this.consequent.includePath(UNKNOWN_PATH, context, false, { asSingleStatement: true });
13564
+ this.consequent.include(context, false, { asSingleStatement: true });
13654
13565
  }
13655
13566
  if (!testValue && this.alternate?.shouldBeIncluded(context)) {
13656
- this.alternate.includePath(UNKNOWN_PATH, context, false, { asSingleStatement: true });
13567
+ this.alternate.include(context, false, { asSingleStatement: true });
13657
13568
  }
13658
13569
  }
13659
13570
  includeRecursively(includeChildrenRecursively, context) {
13660
- this.test.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13661
- this.consequent.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13662
- this.alternate?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13571
+ this.test.include(context, includeChildrenRecursively);
13572
+ this.consequent.include(context, includeChildrenRecursively);
13573
+ this.alternate?.include(context, includeChildrenRecursively);
13663
13574
  }
13664
13575
  includeUnknownTest(context) {
13665
- this.test.includePath(UNKNOWN_PATH, context, false);
13576
+ this.test.include(context, false);
13666
13577
  const { brokenFlow } = context;
13667
13578
  let consequentBrokenFlow = false;
13668
13579
  if (this.consequent.shouldBeIncluded(context)) {
13669
- this.consequent.includePath(UNKNOWN_PATH, context, false, { asSingleStatement: true });
13580
+ this.consequent.include(context, false, { asSingleStatement: true });
13670
13581
  consequentBrokenFlow = context.brokenFlow;
13671
13582
  context.brokenFlow = brokenFlow;
13672
13583
  }
13673
13584
  if (this.alternate?.shouldBeIncluded(context)) {
13674
- this.alternate.includePath(UNKNOWN_PATH, context, false, { asSingleStatement: true });
13585
+ this.alternate.include(context, false, { asSingleStatement: true });
13675
13586
  context.brokenFlow = context.brokenFlow && consequentBrokenFlow;
13676
13587
  }
13677
13588
  }
@@ -13739,7 +13650,7 @@ function isReassignedExportsMember(variable, exportNamesByVariable) {
13739
13650
  class VariableDeclarator extends NodeBase {
13740
13651
  declareDeclarator(kind, isUsingDeclaration) {
13741
13652
  this.isUsingDeclaration = isUsingDeclaration;
13742
- this.id.declare(kind, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION);
13653
+ this.id.declare(kind, this.init || UNDEFINED_EXPRESSION);
13743
13654
  }
13744
13655
  deoptimizePath(path) {
13745
13656
  this.id.deoptimizePath(path);
@@ -13751,15 +13662,15 @@ class VariableDeclarator extends NodeBase {
13751
13662
  this.id.markDeclarationReached();
13752
13663
  return initEffect || this.id.hasEffects(context) || this.isUsingDeclaration;
13753
13664
  }
13754
- includePath(_path, context, includeChildrenRecursively) {
13665
+ include(context, includeChildrenRecursively) {
13755
13666
  const { deoptimized, id, init } = this;
13756
13667
  if (!deoptimized)
13757
13668
  this.applyDeoptimizations();
13758
13669
  this.included = true;
13759
- init?.includePath(EMPTY_PATH, context, includeChildrenRecursively);
13670
+ init?.include(context, includeChildrenRecursively);
13760
13671
  id.markDeclarationReached();
13761
13672
  if (includeChildrenRecursively || id.shouldBeIncluded(context)) {
13762
- id.includePath(EMPTY_PATH, context, includeChildrenRecursively);
13673
+ id.include(context, includeChildrenRecursively);
13763
13674
  }
13764
13675
  }
13765
13676
  removeAnnotations(code) {
@@ -13808,8 +13719,6 @@ class ImportExpression extends NodeBase {
13808
13719
  constructor() {
13809
13720
  super(...arguments);
13810
13721
  this.inlineNamespace = null;
13811
- this.hasUnknownAccessedKey = false;
13812
- this.accessedPropKey = new Set();
13813
13722
  this.attributes = null;
13814
13723
  this.mechanism = null;
13815
13724
  this.namespaceExportName = undefined;
@@ -13842,15 +13751,12 @@ class ImportExpression extends NodeBase {
13842
13751
  if (parent2 instanceof ExpressionStatement) {
13843
13752
  return parseAst_js.EMPTY_ARRAY;
13844
13753
  }
13845
- // Case 1: const { foo } / module = await import('bar')
13754
+ // Case 1: const { foo } = await import('bar')
13846
13755
  if (parent2 instanceof VariableDeclarator) {
13847
13756
  const declaration = parent2.id;
13848
- if (declaration instanceof Identifier) {
13849
- return this.hasUnknownAccessedKey ? undefined : [...this.accessedPropKey];
13850
- }
13851
- if (declaration instanceof ObjectPattern) {
13852
- return getDeterministicObjectDestructure(declaration);
13853
- }
13757
+ return declaration instanceof ObjectPattern
13758
+ ? getDeterministicObjectDestructure(declaration)
13759
+ : undefined;
13854
13760
  }
13855
13761
  // Case 2: (await import('bar')).foo
13856
13762
  if (parent2 instanceof MemberExpression) {
@@ -13899,23 +13805,13 @@ class ImportExpression extends NodeBase {
13899
13805
  hasEffects() {
13900
13806
  return true;
13901
13807
  }
13902
- includePath(path, context, includeChildrenRecursively) {
13808
+ include(context, includeChildrenRecursively) {
13903
13809
  if (!this.included) {
13904
13810
  this.included = true;
13905
13811
  this.scope.context.includeDynamicImport(this);
13906
13812
  this.scope.addAccessedDynamicImport(this);
13907
- this.source.includePath(path, context, includeChildrenRecursively);
13908
- }
13909
- if (this.hasUnknownAccessedKey)
13910
- return;
13911
- if (path[0] === UnknownKey) {
13912
- this.hasUnknownAccessedKey = true;
13913
- this.scope.context.includeDynamicImport(this);
13914
- }
13915
- else if (typeof path[0] === 'string') {
13916
- this.accessedPropKey.add(path[0]);
13917
- this.scope.context.includeDynamicImport(this);
13918
13813
  }
13814
+ this.source.include(context, includeChildrenRecursively);
13919
13815
  }
13920
13816
  initialise() {
13921
13817
  super.initialise();
@@ -14243,7 +14139,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node) {
14243
14139
  if (preserve) {
14244
14140
  // This pretends we are accessing an included global variable of the same name
14245
14141
  const globalVariable = node.scope.findGlobal(baseName);
14246
- globalVariable.includePath(UNKNOWN_PATH, createInclusionContext());
14142
+ globalVariable.include();
14247
14143
  // This excludes this variable from renaming
14248
14144
  factoryVariable.globalName = baseName;
14249
14145
  }
@@ -14251,7 +14147,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node) {
14251
14147
  else {
14252
14148
  factoryVariable = node.scope.findGlobal(baseName);
14253
14149
  }
14254
- node.scope.context.includeVariableInModule(factoryVariable, UNKNOWN_PATH);
14150
+ node.scope.context.includeVariableInModule(factoryVariable);
14255
14151
  if (factoryVariable instanceof LocalVariable) {
14256
14152
  factoryVariable.consolidateInitializers();
14257
14153
  factoryVariable.addUsedPlace(node);
@@ -14273,7 +14169,7 @@ class JSXElementBase extends NodeBase {
14273
14169
  this.scope.context.addImportSource(importSource);
14274
14170
  }
14275
14171
  }
14276
- includePath(path, context, includeChildrenRecursively) {
14172
+ include(context, includeChildrenRecursively) {
14277
14173
  if (!this.included) {
14278
14174
  const { factory, importSource, mode } = this.jsxMode;
14279
14175
  if (factory) {
@@ -14281,7 +14177,7 @@ class JSXElementBase extends NodeBase {
14281
14177
  this.factoryVariable = getAndIncludeFactoryVariable(factory, mode === 'preserve', importSource, this);
14282
14178
  }
14283
14179
  }
14284
- super.includePath(path, context, includeChildrenRecursively);
14180
+ super.include(context, includeChildrenRecursively);
14285
14181
  }
14286
14182
  applyDeoptimizations() { }
14287
14183
  getRenderingMode() {
@@ -14543,7 +14439,7 @@ class JSXOpeningFragment extends NodeBase {
14543
14439
  this.fragment = null;
14544
14440
  this.fragmentVariable = null;
14545
14441
  }
14546
- includePath(path, context, includeChildrenRecursively) {
14442
+ include(context, includeChildrenRecursively) {
14547
14443
  if (!this.included) {
14548
14444
  const jsx = this.scope.context.options.jsx;
14549
14445
  if (jsx.mode === 'automatic') {
@@ -14558,7 +14454,7 @@ class JSXOpeningFragment extends NodeBase {
14558
14454
  }
14559
14455
  }
14560
14456
  }
14561
- super.includePath(path, context, includeChildrenRecursively);
14457
+ super.include(context, includeChildrenRecursively);
14562
14458
  }
14563
14459
  render(code, options) {
14564
14460
  const { mode } = this.scope.context.options.jsx;
@@ -14615,13 +14511,13 @@ class LabeledStatement extends NodeBase {
14615
14511
  context.includedLabels = new Set([...includedLabels, ...context.includedLabels]);
14616
14512
  return bodyHasEffects;
14617
14513
  }
14618
- includePath(_path, context, includeChildrenRecursively) {
14514
+ include(context, includeChildrenRecursively) {
14619
14515
  this.included = true;
14620
14516
  const { brokenFlow, includedLabels } = context;
14621
14517
  context.includedLabels = new Set();
14622
- this.body.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
14518
+ this.body.include(context, includeChildrenRecursively);
14623
14519
  if (includeChildrenRecursively || context.includedLabels.has(this.label.name)) {
14624
- this.label.includePath(UNKNOWN_PATH, createInclusionContext());
14520
+ this.label.include();
14625
14521
  context.includedLabels.delete(this.label.name);
14626
14522
  context.brokenFlow = brokenFlow;
14627
14523
  }
@@ -14718,17 +14614,17 @@ class LogicalExpression extends NodeBase {
14718
14614
  }
14719
14615
  return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
14720
14616
  }
14721
- includePath(path, context, includeChildrenRecursively) {
14617
+ include(context, includeChildrenRecursively) {
14722
14618
  this.included = true;
14723
14619
  const usedBranch = this.getUsedBranch();
14724
14620
  if (includeChildrenRecursively ||
14725
14621
  (usedBranch === this.right && this.left.shouldBeIncluded(context)) ||
14726
14622
  !usedBranch) {
14727
- this.left.includePath(path, context, includeChildrenRecursively);
14728
- this.right.includePath(path, context, includeChildrenRecursively);
14623
+ this.left.include(context, includeChildrenRecursively);
14624
+ this.right.include(context, includeChildrenRecursively);
14729
14625
  }
14730
14626
  else {
14731
- usedBranch.includePath(path, context, includeChildrenRecursively);
14627
+ usedBranch.include(context, includeChildrenRecursively);
14732
14628
  }
14733
14629
  }
14734
14630
  removeAnnotations(code) {
@@ -14800,17 +14696,17 @@ class NewExpression extends NodeBase {
14800
14696
  hasEffectsOnInteractionAtPath(path, { type }) {
14801
14697
  return path.length > 0 || type !== INTERACTION_ACCESSED;
14802
14698
  }
14803
- includePath(path, context, includeChildrenRecursively) {
14699
+ include(context, includeChildrenRecursively) {
14804
14700
  if (!this.deoptimized)
14805
14701
  this.applyDeoptimizations();
14806
14702
  if (includeChildrenRecursively) {
14807
- super.includePath(path, context, includeChildrenRecursively);
14703
+ super.include(context, includeChildrenRecursively);
14808
14704
  }
14809
14705
  else {
14810
14706
  this.included = true;
14811
- this.callee.includePath(UNKNOWN_PATH, context, false);
14707
+ this.callee.include(context, false);
14812
14708
  }
14813
- this.callee.includeCallArguments(context, this.interaction);
14709
+ this.callee.includeCallArguments(context, this.arguments);
14814
14710
  }
14815
14711
  initialise() {
14816
14712
  super.initialise();
@@ -14839,7 +14735,6 @@ class ObjectExpression extends NodeBase {
14839
14735
  constructor() {
14840
14736
  super(...arguments);
14841
14737
  this.objectEntity = null;
14842
- this.protoProp = null;
14843
14738
  }
14844
14739
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
14845
14740
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -14859,32 +14754,13 @@ class ObjectExpression extends NodeBase {
14859
14754
  hasEffectsOnInteractionAtPath(path, interaction, context) {
14860
14755
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
14861
14756
  }
14862
- includePath(path, context, includeChildrenRecursively) {
14863
- this.included = true;
14864
- this.getObjectEntity().includePath(path, context, includeChildrenRecursively);
14865
- this.protoProp?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
14866
- }
14867
14757
  render(code, options, { renderedSurroundingElement } = parseAst_js.BLANK) {
14758
+ super.render(code, options);
14868
14759
  if (renderedSurroundingElement === parseAst_js.ExpressionStatement ||
14869
14760
  renderedSurroundingElement === parseAst_js.ArrowFunctionExpression) {
14870
14761
  code.appendRight(this.start, '(');
14871
14762
  code.prependLeft(this.end, ')');
14872
14763
  }
14873
- if (this.properties.length > 0) {
14874
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
14875
- let lastSeparatorPos = null;
14876
- for (const { node, separator, start, end } of separatedNodes) {
14877
- if (!node.included) {
14878
- treeshakeNode(node, code, start, end);
14879
- continue;
14880
- }
14881
- lastSeparatorPos = separator;
14882
- node.render(code, options);
14883
- }
14884
- if (lastSeparatorPos) {
14885
- code.remove(lastSeparatorPos, this.end - 1);
14886
- }
14887
- }
14888
14764
  }
14889
14765
  applyDeoptimizations() { }
14890
14766
  getObjectEntity() {
@@ -14915,7 +14791,6 @@ class ObjectExpression extends NodeBase {
14915
14791
  ? property.key.name
14916
14792
  : String(property.key.value);
14917
14793
  if (key === '__proto__' && property.kind === 'init') {
14918
- this.protoProp = property;
14919
14794
  prototype =
14920
14795
  property.value instanceof Literal && property.value.value === null
14921
14796
  ? null
@@ -14982,11 +14857,11 @@ class Program extends NodeBase {
14982
14857
  }
14983
14858
  return false;
14984
14859
  }
14985
- includePath(_path, context, includeChildrenRecursively) {
14860
+ include(context, includeChildrenRecursively) {
14986
14861
  this.included = true;
14987
14862
  for (const node of this.body) {
14988
14863
  if (includeChildrenRecursively || node.shouldBeIncluded(context)) {
14989
- node.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
14864
+ node.include(context, includeChildrenRecursively);
14990
14865
  }
14991
14866
  }
14992
14867
  }
@@ -15025,6 +14900,10 @@ class Program extends NodeBase {
15025
14900
  }
15026
14901
 
15027
14902
  class Property extends MethodBase {
14903
+ constructor() {
14904
+ super(...arguments);
14905
+ this.declarationInit = null;
14906
+ }
15028
14907
  //declare method: boolean;
15029
14908
  get method() {
15030
14909
  return isFlagSet(this.flags, 262144 /* Flag.method */);
@@ -15039,17 +14918,9 @@ class Property extends MethodBase {
15039
14918
  set shorthand(value) {
15040
14919
  this.flags = setFlag(this.flags, 524288 /* Flag.shorthand */, value);
15041
14920
  }
15042
- declare(kind, includedInitPath, init) {
15043
- const pathInProperty = includedInitPath.at(-1) === UnknownKey
15044
- ? includedInitPath
15045
- : // For now, we only consider static path as we do not know how to
15046
- // deoptimize the path in the dynamic case.
15047
- this.computed
15048
- ? [...includedInitPath, UnknownKey]
15049
- : this.key instanceof Identifier
15050
- ? [...includedInitPath, this.key.name]
15051
- : [...includedInitPath, String(this.key.value)];
15052
- return this.value.declare(kind, pathInProperty, init);
14921
+ declare(kind, init) {
14922
+ this.declarationInit = init;
14923
+ return this.value.declare(kind, UNKNOWN_EXPRESSION);
15053
14924
  }
15054
14925
  hasEffects(context) {
15055
14926
  if (!this.deoptimized)
@@ -15059,11 +14930,6 @@ class Property extends MethodBase {
15059
14930
  this.key.hasEffects(context) ||
15060
14931
  this.value.hasEffects(context));
15061
14932
  }
15062
- includePath(path, context, includeChildrenRecursively) {
15063
- this.included = true;
15064
- this.key.includePath(EMPTY_PATH, context, includeChildrenRecursively);
15065
- this.value.includePath(path, context, includeChildrenRecursively);
15066
- }
15067
14933
  markDeclarationReached() {
15068
14934
  this.value.markDeclarationReached();
15069
14935
  }
@@ -15073,7 +14939,13 @@ class Property extends MethodBase {
15073
14939
  }
15074
14940
  this.value.render(code, options, { isShorthandProperty: this.shorthand });
15075
14941
  }
15076
- applyDeoptimizations() { }
14942
+ applyDeoptimizations() {
14943
+ this.deoptimized = true;
14944
+ if (this.declarationInit !== null) {
14945
+ this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
14946
+ this.scope.context.requestTreeshakingPass();
14947
+ }
14948
+ }
15077
14949
  }
15078
14950
 
15079
14951
  class PropertyDefinition extends NodeBase {
@@ -15117,9 +14989,9 @@ class ReturnStatement extends NodeBase {
15117
14989
  context.brokenFlow = true;
15118
14990
  return false;
15119
14991
  }
15120
- includePath(_path, context, includeChildrenRecursively) {
14992
+ include(context, includeChildrenRecursively) {
15121
14993
  this.included = true;
15122
- this.argument?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
14994
+ this.argument?.include(context, includeChildrenRecursively);
15123
14995
  context.brokenFlow = true;
15124
14996
  }
15125
14997
  initialise() {
@@ -15156,14 +15028,14 @@ class SequenceExpression extends NodeBase {
15156
15028
  hasEffectsOnInteractionAtPath(path, interaction, context) {
15157
15029
  return this.expressions[this.expressions.length - 1].hasEffectsOnInteractionAtPath(path, interaction, context);
15158
15030
  }
15159
- includePath(path, context, includeChildrenRecursively) {
15031
+ include(context, includeChildrenRecursively) {
15160
15032
  this.included = true;
15161
15033
  const lastExpression = this.expressions[this.expressions.length - 1];
15162
15034
  for (const expression of this.expressions) {
15163
15035
  if (includeChildrenRecursively ||
15164
15036
  (expression === lastExpression && !(this.parent instanceof ExpressionStatement)) ||
15165
15037
  expression.shouldBeIncluded(context))
15166
- expression.includePath(path, context, includeChildrenRecursively);
15038
+ expression.include(context, includeChildrenRecursively);
15167
15039
  }
15168
15040
  }
15169
15041
  removeAnnotations(code) {
@@ -15211,13 +15083,10 @@ class Super extends NodeBase {
15211
15083
  deoptimizePath(path) {
15212
15084
  this.variable.deoptimizePath(path);
15213
15085
  }
15214
- includePath(path, context) {
15086
+ include() {
15215
15087
  if (!this.included) {
15216
15088
  this.included = true;
15217
- this.scope.context.includeVariableInModule(this.variable, path);
15218
- }
15219
- else if (path.length > 0) {
15220
- this.variable.includePath(path, context);
15089
+ this.scope.context.includeVariableInModule(this.variable);
15221
15090
  }
15222
15091
  }
15223
15092
  }
@@ -15234,12 +15103,12 @@ class SwitchCase extends NodeBase {
15234
15103
  }
15235
15104
  return false;
15236
15105
  }
15237
- includePath(_path, context, includeChildrenRecursively) {
15106
+ include(context, includeChildrenRecursively) {
15238
15107
  this.included = true;
15239
- this.test?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15108
+ this.test?.include(context, includeChildrenRecursively);
15240
15109
  for (const node of this.consequent) {
15241
15110
  if (includeChildrenRecursively || node.shouldBeIncluded(context))
15242
- node.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15111
+ node.include(context, includeChildrenRecursively);
15243
15112
  }
15244
15113
  }
15245
15114
  render(code, options, nodeRenderOptions) {
@@ -15287,9 +15156,9 @@ class SwitchStatement extends NodeBase {
15287
15156
  context.hasBreak = hasBreak;
15288
15157
  return false;
15289
15158
  }
15290
- includePath(_path, context, includeChildrenRecursively) {
15159
+ include(context, includeChildrenRecursively) {
15291
15160
  this.included = true;
15292
- this.discriminant.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15161
+ this.discriminant.include(context, includeChildrenRecursively);
15293
15162
  const { brokenFlow, hasBreak } = context;
15294
15163
  context.hasBreak = false;
15295
15164
  let onlyHasBrokenFlow = true;
@@ -15306,7 +15175,7 @@ class SwitchStatement extends NodeBase {
15306
15175
  isCaseIncluded = switchCase.hasEffects(hasEffectsContext);
15307
15176
  }
15308
15177
  if (isCaseIncluded) {
15309
- switchCase.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15178
+ switchCase.include(context, includeChildrenRecursively);
15310
15179
  onlyHasBrokenFlow &&= context.brokenFlow && !context.hasBreak;
15311
15180
  context.hasBreak = false;
15312
15181
  context.brokenFlow = brokenFlow;
@@ -15363,21 +15232,21 @@ class TaggedTemplateExpression extends CallExpressionBase {
15363
15232
  return (this.tag.hasEffects(context) ||
15364
15233
  this.tag.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context));
15365
15234
  }
15366
- includePath(path, context, includeChildrenRecursively) {
15235
+ include(context, includeChildrenRecursively) {
15367
15236
  if (!this.deoptimized)
15368
15237
  this.applyDeoptimizations();
15369
15238
  if (includeChildrenRecursively) {
15370
- super.includePath(path, context, includeChildrenRecursively);
15239
+ super.include(context, includeChildrenRecursively);
15371
15240
  }
15372
15241
  else {
15373
15242
  this.included = true;
15374
- this.tag.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15375
- this.quasi.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15243
+ this.tag.include(context, includeChildrenRecursively);
15244
+ this.quasi.include(context, includeChildrenRecursively);
15376
15245
  }
15377
- this.tag.includeCallArguments(context, this.interaction);
15246
+ this.tag.includeCallArguments(context, this.args);
15378
15247
  const [returnExpression] = this.getReturnExpression();
15379
15248
  if (!returnExpression.included) {
15380
- returnExpression.includePath(UNKNOWN_PATH, context, false);
15249
+ returnExpression.include(context, false);
15381
15250
  }
15382
15251
  }
15383
15252
  initialise() {
@@ -15422,7 +15291,7 @@ class TemplateElement extends NodeBase {
15422
15291
  hasEffects() {
15423
15292
  return false;
15424
15293
  }
15425
- includePath() {
15294
+ include() {
15426
15295
  this.included = true;
15427
15296
  }
15428
15297
  parseNode(esTreeNode) {
@@ -15464,13 +15333,13 @@ class TemplateLiteral extends NodeBase {
15464
15333
  class ModuleScope extends ChildScope {
15465
15334
  constructor(parent, context) {
15466
15335
  super(parent, context);
15467
- this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, EMPTY_PATH, context, 'other'));
15336
+ this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, context, 'other'));
15468
15337
  }
15469
- addDeclaration(identifier, context, init, includedInitPath, kind) {
15338
+ addDeclaration(identifier, context, init, kind) {
15470
15339
  if (this.context.module.importDescriptions.has(identifier.name)) {
15471
15340
  context.error(parseAst_js.logRedeclarationError(identifier.name), identifier.start);
15472
15341
  }
15473
- return super.addDeclaration(identifier, context, init, includedInitPath, kind);
15342
+ return super.addDeclaration(identifier, context, init, kind);
15474
15343
  }
15475
15344
  addExportDefaultDeclaration(name, exportDefaultDeclaration, context) {
15476
15345
  const variable = new ExportDefaultVariable(name, exportDefaultDeclaration, context);
@@ -15515,13 +15384,10 @@ class ThisExpression extends NodeBase {
15515
15384
  }
15516
15385
  return this.variable.hasEffectsOnInteractionAtPath(path, interaction, context);
15517
15386
  }
15518
- includePath(path, context) {
15387
+ include() {
15519
15388
  if (!this.included) {
15520
15389
  this.included = true;
15521
- this.scope.context.includeVariableInModule(this.variable, path);
15522
- }
15523
- else if (path.length > 0) {
15524
- this.variable.includePath(path, context);
15390
+ this.scope.context.includeVariableInModule(this.variable);
15525
15391
  }
15526
15392
  }
15527
15393
  initialise() {
@@ -15548,9 +15414,9 @@ class ThrowStatement extends NodeBase {
15548
15414
  hasEffects() {
15549
15415
  return true;
15550
15416
  }
15551
- includePath(_path, context, includeChildrenRecursively) {
15417
+ include(context, includeChildrenRecursively) {
15552
15418
  this.included = true;
15553
- this.argument.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15419
+ this.argument.include(context, includeChildrenRecursively);
15554
15420
  context.brokenFlow = true;
15555
15421
  }
15556
15422
  render(code, options) {
@@ -15572,13 +15438,13 @@ class TryStatement extends NodeBase {
15572
15438
  ? this.block.body.length > 0
15573
15439
  : this.block.hasEffects(context)) || !!this.finalizer?.hasEffects(context));
15574
15440
  }
15575
- includePath(_path, context, includeChildrenRecursively) {
15441
+ include(context, includeChildrenRecursively) {
15576
15442
  const tryCatchDeoptimization = this.scope.context.options.treeshake?.tryCatchDeoptimization;
15577
15443
  const { brokenFlow, includedLabels } = context;
15578
15444
  if (!this.directlyIncluded || !tryCatchDeoptimization) {
15579
15445
  this.included = true;
15580
15446
  this.directlyIncluded = true;
15581
- this.block.includePath(UNKNOWN_PATH, context, tryCatchDeoptimization ? INCLUDE_PARAMETERS : includeChildrenRecursively);
15447
+ this.block.include(context, tryCatchDeoptimization ? INCLUDE_PARAMETERS : includeChildrenRecursively);
15582
15448
  if (includedLabels.size > 0) {
15583
15449
  this.includedLabelsAfterBlock = [...includedLabels];
15584
15450
  }
@@ -15590,10 +15456,10 @@ class TryStatement extends NodeBase {
15590
15456
  }
15591
15457
  }
15592
15458
  if (this.handler !== null) {
15593
- this.handler.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15459
+ this.handler.include(context, includeChildrenRecursively);
15594
15460
  context.brokenFlow = brokenFlow;
15595
15461
  }
15596
- this.finalizer?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15462
+ this.finalizer?.include(context, includeChildrenRecursively);
15597
15463
  }
15598
15464
  }
15599
15465
 
@@ -15651,7 +15517,7 @@ class UpdateExpression extends NodeBase {
15651
15517
  hasEffectsOnInteractionAtPath(path, { type }) {
15652
15518
  return path.length > 1 || type !== INTERACTION_ACCESSED;
15653
15519
  }
15654
- includePath(_, context, includeChildrenRecursively) {
15520
+ include(context, includeChildrenRecursively) {
15655
15521
  if (!this.deoptimized)
15656
15522
  this.applyDeoptimizations();
15657
15523
  this.included = true;
@@ -15720,20 +15586,20 @@ class VariableDeclaration extends NodeBase {
15720
15586
  hasEffectsOnInteractionAtPath() {
15721
15587
  return false;
15722
15588
  }
15723
- includePath(_path, context, includeChildrenRecursively, { asSingleStatement } = parseAst_js.BLANK) {
15589
+ include(context, includeChildrenRecursively, { asSingleStatement } = parseAst_js.BLANK) {
15724
15590
  this.included = true;
15725
15591
  for (const declarator of this.declarations) {
15726
15592
  if (includeChildrenRecursively || declarator.shouldBeIncluded(context))
15727
- declarator.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15593
+ declarator.include(context, includeChildrenRecursively);
15728
15594
  const { id, init } = declarator;
15729
15595
  if (asSingleStatement) {
15730
- id.includePath(EMPTY_PATH, context, includeChildrenRecursively);
15596
+ id.include(context, includeChildrenRecursively);
15731
15597
  }
15732
15598
  if (init &&
15733
15599
  id.included &&
15734
15600
  !init.included &&
15735
15601
  (id instanceof ObjectPattern || id instanceof ArrayPattern)) {
15736
- init.includePath(EMPTY_PATH, context, includeChildrenRecursively);
15602
+ init.include(context, includeChildrenRecursively);
15737
15603
  }
15738
15604
  }
15739
15605
  }
@@ -15805,7 +15671,8 @@ class VariableDeclaration extends NodeBase {
15805
15671
  const singleSystemExport = gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregatedSystemExports);
15806
15672
  for (const { node, start, separator, contentEnd, end } of separatedNodes) {
15807
15673
  if (!node.included) {
15808
- treeshakeNode(node, code, start, end);
15674
+ code.remove(start, end);
15675
+ node.removeAnnotations(code);
15809
15676
  continue;
15810
15677
  }
15811
15678
  node.render(code, options);
@@ -15882,9 +15749,9 @@ class WhileStatement extends NodeBase {
15882
15749
  return true;
15883
15750
  return hasLoopBodyEffects(context, this.body);
15884
15751
  }
15885
- includePath(_path, context, includeChildrenRecursively) {
15752
+ include(context, includeChildrenRecursively) {
15886
15753
  this.included = true;
15887
- this.test.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15754
+ this.test.include(context, includeChildrenRecursively);
15888
15755
  includeLoopBody(context, this.body, includeChildrenRecursively);
15889
15756
  }
15890
15757
  }
@@ -16128,7 +15995,7 @@ const bufferParsers = [
16128
15995
  const annotations = (node.annotations = parseAst_js.convertAnnotations(buffer[position + 1], buffer));
16129
15996
  node.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
16130
15997
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 2], buffer));
16131
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
15998
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16132
15999
  node.body = convertNode(node, scope.bodyScope, buffer[position + 3], buffer);
16133
16000
  },
16134
16001
  function assignmentExpression(node, position, buffer) {
@@ -16174,7 +16041,7 @@ const bufferParsers = [
16174
16041
  const parameterPosition = buffer[position];
16175
16042
  const parameter = (node.param =
16176
16043
  parameterPosition === 0 ? null : convertNode(node, scope, parameterPosition, buffer));
16177
- parameter?.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
16044
+ parameter?.declare('parameter', UNKNOWN_EXPRESSION);
16178
16045
  node.body = convertNode(node, scope.bodyScope, buffer[position + 1], buffer);
16179
16046
  },
16180
16047
  function chainExpression(node, position, buffer) {
@@ -16184,14 +16051,17 @@ const bufferParsers = [
16184
16051
  function classBody(node, position, buffer) {
16185
16052
  const { scope } = node;
16186
16053
  const bodyPosition = buffer[position];
16187
- const body = (node.body = []);
16188
16054
  if (bodyPosition) {
16189
16055
  const length = buffer[bodyPosition];
16056
+ const body = (node.body = new Array(length));
16190
16057
  for (let index = 0; index < length; index++) {
16191
16058
  const nodePosition = buffer[bodyPosition + 1 + index];
16192
- body.push(convertNode(node, (buffer[nodePosition + 3] & 1) === 0 ? scope.instanceScope : scope, nodePosition, buffer));
16059
+ body[index] = convertNode(node, (buffer[nodePosition + 3] & 1) === 0 ? scope.instanceScope : scope, nodePosition, buffer);
16193
16060
  }
16194
16061
  }
16062
+ else {
16063
+ node.body = [];
16064
+ }
16195
16065
  },
16196
16066
  function classDeclaration(node, position, buffer) {
16197
16067
  const { scope } = node;
@@ -16309,7 +16179,7 @@ const bufferParsers = [
16309
16179
  node.id =
16310
16180
  idPosition === 0 ? null : convertNode(node, scope.parent, idPosition, buffer);
16311
16181
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
16312
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16182
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16313
16183
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
16314
16184
  },
16315
16185
  function functionExpression(node, position, buffer) {
@@ -16322,7 +16192,7 @@ const bufferParsers = [
16322
16192
  const idPosition = buffer[position + 2];
16323
16193
  node.id = idPosition === 0 ? null : convertNode(node, node.idScope, idPosition, buffer);
16324
16194
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
16325
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16195
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16326
16196
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
16327
16197
  },
16328
16198
  function identifier(node, position, buffer) {
@@ -16669,10 +16539,10 @@ function convertNodeList(parent, parentScope, position, buffer) {
16669
16539
  if (position === 0)
16670
16540
  return parseAst_js.EMPTY_ARRAY;
16671
16541
  const length = buffer[position++];
16672
- const list = [];
16542
+ const list = new Array(length);
16673
16543
  for (let index = 0; index < length; index++) {
16674
16544
  const nodePosition = buffer[position++];
16675
- list.push(nodePosition ? convertNode(parent, parentScope, nodePosition, buffer) : null);
16545
+ list[index] = nodePosition ? convertNode(parent, parentScope, nodePosition, buffer) : null;
16676
16546
  }
16677
16547
  return list;
16678
16548
  }
@@ -16681,8 +16551,8 @@ class UnknownNode extends NodeBase {
16681
16551
  hasEffects() {
16682
16552
  return true;
16683
16553
  }
16684
- includePath(path, context) {
16685
- super.includePath(path, context, true);
16554
+ include(context) {
16555
+ super.include(context, true);
16686
16556
  }
16687
16557
  }
16688
16558
 
@@ -16786,8 +16656,8 @@ class ExportShimVariable extends Variable {
16786
16656
  super(MISSING_EXPORT_SHIM_VARIABLE);
16787
16657
  this.module = module;
16788
16658
  }
16789
- includePath(path, context) {
16790
- super.includePath(path, context);
16659
+ include() {
16660
+ super.include();
16791
16661
  this.module.needsExportShim = true;
16792
16662
  }
16793
16663
  }
@@ -17471,7 +17341,7 @@ class Module {
17471
17341
  include() {
17472
17342
  const context = createInclusionContext();
17473
17343
  if (this.ast.shouldBeIncluded(context))
17474
- this.ast.includePath(EMPTY_PATH, context, false);
17344
+ this.ast.include(context, false);
17475
17345
  }
17476
17346
  includeAllExports(includeNamespaceMembers) {
17477
17347
  if (!this.isExecuted) {
@@ -17485,7 +17355,9 @@ class Module {
17485
17355
  return parseAst_js.error(parseAst_js.logMissingEntryExport(exportName, this.id));
17486
17356
  }
17487
17357
  variable.deoptimizePath(UNKNOWN_PATH);
17488
- this.includeVariable(variable, UNKNOWN_PATH);
17358
+ if (!variable.included) {
17359
+ this.includeVariable(variable);
17360
+ }
17489
17361
  }
17490
17362
  }
17491
17363
  for (const name of this.getReexports()) {
@@ -17493,7 +17365,7 @@ class Module {
17493
17365
  if (variable) {
17494
17366
  variable.deoptimizePath(UNKNOWN_PATH);
17495
17367
  if (!variable.included) {
17496
- this.includeVariable(variable, UNKNOWN_PATH);
17368
+ this.includeVariable(variable);
17497
17369
  }
17498
17370
  if (variable instanceof ExternalVariable) {
17499
17371
  variable.module.reexported = true;
@@ -17505,7 +17377,7 @@ class Module {
17505
17377
  }
17506
17378
  }
17507
17379
  includeAllInBundle() {
17508
- this.ast.includePath(UNKNOWN_PATH, createInclusionContext(), true);
17380
+ this.ast.include(createInclusionContext(), true);
17509
17381
  this.includeAllExports(false);
17510
17382
  }
17511
17383
  includeExportsByNames(names) {
@@ -17519,7 +17391,7 @@ class Module {
17519
17391
  if (variable) {
17520
17392
  variable.deoptimizePath(UNKNOWN_PATH);
17521
17393
  if (!variable.included) {
17522
- this.includeVariable(variable, EMPTY_PATH);
17394
+ this.includeVariable(variable);
17523
17395
  }
17524
17396
  }
17525
17397
  if (!this.exports.has(name) && !this.reexportDescriptions.has(name)) {
@@ -17961,13 +17833,13 @@ class Module {
17961
17833
  for (const module of [this, ...this.exportAllModules]) {
17962
17834
  if (module instanceof ExternalModule) {
17963
17835
  const [externalVariable] = module.getVariableForExportName('*');
17964
- externalVariable.includePath(UNKNOWN_PATH, createInclusionContext());
17836
+ externalVariable.include();
17965
17837
  this.includedImports.add(externalVariable);
17966
17838
  externalNamespaces.add(externalVariable);
17967
17839
  }
17968
17840
  else if (module.info.syntheticNamedExports) {
17969
17841
  const syntheticNamespace = module.getSyntheticNamespace();
17970
- syntheticNamespace.includePath(UNKNOWN_PATH, createInclusionContext());
17842
+ syntheticNamespace.include();
17971
17843
  this.includedImports.add(syntheticNamespace);
17972
17844
  syntheticNamespaces.add(syntheticNamespace);
17973
17845
  }
@@ -17977,9 +17849,7 @@ class Module {
17977
17849
  includeDynamicImport(node) {
17978
17850
  const resolution = this.dynamicImports.find(dynamicImport => dynamicImport.node === node).resolution;
17979
17851
  if (resolution instanceof Module) {
17980
- if (!resolution.includedDynamicImporters.includes(this)) {
17981
- resolution.includedDynamicImporters.push(this);
17982
- }
17852
+ resolution.includedDynamicImporters.push(this);
17983
17853
  const importedNames = this.options.treeshake
17984
17854
  ? node.getDeterministicImportedNames()
17985
17855
  : undefined;
@@ -17991,7 +17861,7 @@ class Module {
17991
17861
  }
17992
17862
  }
17993
17863
  }
17994
- includeVariable(variable, path) {
17864
+ includeVariable(variable) {
17995
17865
  const variableModule = variable.module;
17996
17866
  if (variable.included) {
17997
17867
  if (variableModule instanceof Module && variableModule !== this) {
@@ -17999,6 +17869,7 @@ class Module {
17999
17869
  }
18000
17870
  }
18001
17871
  else {
17872
+ variable.include();
18002
17873
  this.graph.needsTreeshakingPass = true;
18003
17874
  if (variableModule instanceof Module) {
18004
17875
  if (!variableModule.isExecuted) {
@@ -18014,10 +17885,9 @@ class Module {
18014
17885
  }
18015
17886
  }
18016
17887
  }
18017
- variable.includePath(path, createInclusionContext());
18018
17888
  }
18019
- includeVariableInModule(variable, path) {
18020
- this.includeVariable(variable, path);
17889
+ includeVariableInModule(variable) {
17890
+ this.includeVariable(variable);
18021
17891
  const variableModule = variable.module;
18022
17892
  if (variableModule && variableModule !== this) {
18023
17893
  this.includedImports.add(variable);
@@ -19549,14 +19419,16 @@ function getChunkAssignments(entries, manualChunkAliasByEntry, minChunkSize, log
19549
19419
  return chunkDefinitions;
19550
19420
  }
19551
19421
  function getChunkDefinitionsFromManualChunks(manualChunkAliasByEntry) {
19552
- const chunkDefinitions = [];
19553
19422
  const modulesInManualChunks = new Set(manualChunkAliasByEntry.keys());
19554
19423
  const manualChunkModulesByAlias = Object.create(null);
19555
19424
  for (const [entry, alias] of manualChunkAliasByEntry) {
19556
19425
  addStaticDependenciesToManualChunk(entry, (manualChunkModulesByAlias[alias] ||= []), modulesInManualChunks);
19557
19426
  }
19558
- for (const [alias, modules] of Object.entries(manualChunkModulesByAlias)) {
19559
- chunkDefinitions.push({ alias, modules });
19427
+ const manualChunks = Object.entries(manualChunkModulesByAlias);
19428
+ const chunkDefinitions = new Array(manualChunks.length);
19429
+ let index = 0;
19430
+ for (const [alias, modules] of manualChunks) {
19431
+ chunkDefinitions[index++] = { alias, modules };
19560
19432
  }
19561
19433
  return { chunkDefinitions, modulesInManualChunks };
19562
19434
  }
@@ -19575,12 +19447,12 @@ function addStaticDependenciesToManualChunk(entry, manualChunkModules, modulesIn
19575
19447
  function analyzeModuleGraph(entries) {
19576
19448
  const dynamicEntryModules = new Set();
19577
19449
  const dependentEntriesByModule = new Map();
19578
- const dynamicImportModulesByEntry = [];
19579
19450
  const allEntriesSet = new Set(entries);
19451
+ const dynamicImportModulesByEntry = new Array(allEntriesSet.size);
19580
19452
  let entryIndex = 0;
19581
19453
  for (const currentEntry of allEntriesSet) {
19582
19454
  const dynamicImportsForCurrentEntry = new Set();
19583
- dynamicImportModulesByEntry.push(dynamicImportsForCurrentEntry);
19455
+ dynamicImportModulesByEntry[entryIndex] = dynamicImportsForCurrentEntry;
19584
19456
  const modulesToHandle = new Set([currentEntry]);
19585
19457
  for (const module of modulesToHandle) {
19586
19458
  getOrCreate(dependentEntriesByModule, module, (getNewSet)).add(entryIndex);
@@ -19625,13 +19497,14 @@ function getDynamicEntries(allEntries, dynamicEntryModules, dynamicImportModules
19625
19497
  dynamicEntries.add(entryIndex);
19626
19498
  }
19627
19499
  }
19628
- const dynamicImportsByEntry = [];
19500
+ const dynamicImportsByEntry = new Array(dynamicImportModulesByEntry.length);
19501
+ let index = 0;
19629
19502
  for (const dynamicImportModules of dynamicImportModulesByEntry) {
19630
19503
  const dynamicImports = new Set();
19631
19504
  for (const dynamicEntry of dynamicImportModules) {
19632
19505
  dynamicImports.add(entryIndexByModule.get(dynamicEntry));
19633
19506
  }
19634
- dynamicImportsByEntry.push(dynamicImports);
19507
+ dynamicImportsByEntry[index++] = dynamicImports;
19635
19508
  }
19636
19509
  return { dynamicEntries, dynamicImportsByEntry };
19637
19510
  }
@@ -19736,9 +19609,10 @@ function removeUnnecessaryDependentEntries(chunkAtoms, alreadyLoadedAtomsByEntry
19736
19609
  function getChunksWithSameDependentEntriesAndCorrelatedAtoms(chunkAtoms, staticDependencyAtomsByEntry, alreadyLoadedAtomsByEntry, minChunkSize) {
19737
19610
  const chunksBySignature = Object.create(null);
19738
19611
  const chunkByModule = new Map();
19739
- const sizeByAtom = [];
19612
+ const sizeByAtom = new Array(chunkAtoms.length);
19740
19613
  let sideEffectAtoms = 0n;
19741
19614
  let atomMask = 1n;
19615
+ let index = 0;
19742
19616
  for (const { dependentEntries, modules } of chunkAtoms) {
19743
19617
  let chunkSignature = 0n;
19744
19618
  let correlatedAtoms = -1n;
@@ -19776,7 +19650,7 @@ function getChunksWithSameDependentEntriesAndCorrelatedAtoms(chunkAtoms, staticD
19776
19650
  if (!pure) {
19777
19651
  sideEffectAtoms |= atomMask;
19778
19652
  }
19779
- sizeByAtom.push(atomSize);
19653
+ sizeByAtom[index++] = atomSize;
19780
19654
  chunk.containedAtoms |= atomMask;
19781
19655
  chunk.modules.push(...modules);
19782
19656
  chunk.pure &&= pure;
@@ -20526,6 +20400,9 @@ function addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, bun
20526
20400
  const finalFileName = replacePlaceholders(fileName, hashesByPlaceholder);
20527
20401
  let finalSourcemapFileName = null;
20528
20402
  if (map) {
20403
+ if (options.sourcemapDebugIds) {
20404
+ updatedCode += calculateDebugIdAndGetComment(updatedCode, map);
20405
+ }
20529
20406
  finalSourcemapFileName = sourcemapFileName
20530
20407
  ? replacePlaceholders(sourcemapFileName, hashesByPlaceholder)
20531
20408
  : `${finalFileName}.map`;
@@ -20538,6 +20415,9 @@ function addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, bun
20538
20415
  let updatedCode = hashesByPlaceholder.size > 0 ? replacePlaceholders(code, hashesByPlaceholder) : code;
20539
20416
  let finalSourcemapFileName = null;
20540
20417
  if (map) {
20418
+ if (options.sourcemapDebugIds) {
20419
+ updatedCode += calculateDebugIdAndGetComment(updatedCode, map);
20420
+ }
20541
20421
  finalSourcemapFileName = sourcemapFileName
20542
20422
  ? replacePlaceholders(sourcemapFileName, hashesByPlaceholder)
20543
20423
  : `${fileName}.map`;
@@ -20565,6 +20445,18 @@ function emitSourceMapAndGetComment(fileName, map, pluginDriver, { sourcemap, so
20565
20445
  }
20566
20446
  return sourcemap === 'hidden' ? '' : `//# ${SOURCEMAPPING_URL}=${url}\n`;
20567
20447
  }
20448
+ function calculateDebugIdAndGetComment(code, map) {
20449
+ const hash = hasherByType.hex(code);
20450
+ const debugId = [
20451
+ hash.slice(0, 8),
20452
+ hash.slice(8, 12),
20453
+ '4' + hash.slice(12, 15),
20454
+ ((parseInt(hash.slice(15, 16), 16) & 3) | 8).toString(16) + hash.slice(17, 20),
20455
+ hash.slice(20, 32)
20456
+ ].join('-');
20457
+ map.debugId = debugId;
20458
+ return '//# debugId=' + debugId + '\n';
20459
+ }
20568
20460
 
20569
20461
  class Bundle {
20570
20462
  constructor(outputOptions, unsetOptions, inputOptions, pluginDriver, graph) {
@@ -20672,16 +20564,18 @@ class Bundle {
20672
20564
  const includedModules = getIncludedModules(this.graph.modulesById);
20673
20565
  const inputBase = commondir(getAbsoluteEntryModulePaths(includedModules, preserveModules));
20674
20566
  const externalChunkByModule = getExternalChunkByModule(this.graph.modulesById, this.outputOptions, inputBase);
20675
- const chunks = [];
20676
- const chunkByModule = new Map();
20677
- for (const { alias, modules } of inlineDynamicImports
20567
+ const executableModule = inlineDynamicImports
20678
20568
  ? [{ alias: null, modules: includedModules }]
20679
20569
  : preserveModules
20680
20570
  ? includedModules.map(module => ({ alias: null, modules: [module] }))
20681
- : getChunkAssignments(this.graph.entryModules, manualChunkAliasByEntry, experimentalMinChunkSize, this.inputOptions.onLog)) {
20571
+ : getChunkAssignments(this.graph.entryModules, manualChunkAliasByEntry, experimentalMinChunkSize, this.inputOptions.onLog);
20572
+ const chunks = new Array(executableModule.length);
20573
+ const chunkByModule = new Map();
20574
+ let index = 0;
20575
+ for (const { alias, modules } of executableModule) {
20682
20576
  sortByExecutionOrder(modules);
20683
20577
  const chunk = new Chunk(modules, this.inputOptions, this.outputOptions, this.unsetOptions, this.pluginDriver, this.graph.modulesById, chunkByModule, externalChunkByModule, this.facadeChunkByModule, this.includedNamespaces, alias, getHashPlaceholder, bundle, inputBase, snippets);
20684
- chunks.push(chunk);
20578
+ chunks[index++] = chunk;
20685
20579
  }
20686
20580
  for (const chunk of chunks) {
20687
20581
  chunk.link();
@@ -21496,7 +21390,7 @@ class Graph {
21496
21390
  this.options = options;
21497
21391
  this.astLru = flru(5);
21498
21392
  this.cachedModules = new Map();
21499
- this.deoptimizationTracker = new EntityPathTracker();
21393
+ this.deoptimizationTracker = new PathTracker();
21500
21394
  this.entryModules = [];
21501
21395
  this.modulesById = new Map();
21502
21396
  this.needsTreeshakingPass = false;
@@ -21944,6 +21838,7 @@ async function normalizeOutputOptions(config, inputOptions, unsetInputOptions) {
21944
21838
  : sanitizeFileName,
21945
21839
  sourcemap: config.sourcemap || false,
21946
21840
  sourcemapBaseUrl: getSourcemapBaseUrl(config),
21841
+ sourcemapDebugIds: config.sourcemapDebugIds || false,
21947
21842
  sourcemapExcludeSources: config.sourcemapExcludeSources || false,
21948
21843
  sourcemapFile: config.sourcemapFile,
21949
21844
  sourcemapFileNames: getSourcemapFileNames(config, unsetOptions),