@rollup/wasm-node 4.27.2 → 4.27.3

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.27.2
4
- Fri, 15 Nov 2024 17:19:22 GMT - commit a503a4dd9982bf20fd38aeb171882a27828906ae
3
+ Rollup.js v4.27.3
4
+ Mon, 18 Nov 2024 16:39:05 GMT - commit 7c0b1f8810013b5a351a976df30a6a5da4fa164b
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.27.2";
34
+ var version = "4.27.3";
35
35
 
36
36
  function ensureArray$1(items) {
37
37
  if (Array.isArray(items)) {
@@ -1500,8 +1500,48 @@ const createColors = ({ useColor = isColorSupported } = {}) =>
1500
1500
  );
1501
1501
 
1502
1502
  const {
1503
+ reset,
1504
+ bold: bold$1,
1505
+ dim: dim$1,
1506
+ italic,
1507
+ underline: underline$1,
1508
+ inverse,
1509
+ hidden,
1510
+ strikethrough,
1511
+ black,
1512
+ red: red$1,
1513
+ green: green$1,
1514
+ yellow: yellow$1,
1503
1515
  blue,
1504
- cyan: cyan$1} = createColors();
1516
+ magenta,
1517
+ cyan: cyan$1,
1518
+ white,
1519
+ gray: gray$1,
1520
+ bgBlack,
1521
+ bgRed,
1522
+ bgGreen,
1523
+ bgYellow,
1524
+ bgBlue,
1525
+ bgMagenta,
1526
+ bgCyan,
1527
+ bgWhite,
1528
+ blackBright,
1529
+ redBright,
1530
+ greenBright,
1531
+ yellowBright,
1532
+ blueBright,
1533
+ magentaBright,
1534
+ cyanBright,
1535
+ whiteBright,
1536
+ bgBlackBright,
1537
+ bgRedBright,
1538
+ bgGreenBright,
1539
+ bgYellowBright,
1540
+ bgBlueBright,
1541
+ bgMagentaBright,
1542
+ bgCyanBright,
1543
+ bgWhiteBright,
1544
+ } = createColors();
1505
1545
 
1506
1546
  // @see https://no-color.org
1507
1547
  // @see https://www.npmjs.com/package/chalk
@@ -3530,6 +3570,19 @@ function is_reference(node, parent) {
3530
3570
  }
3531
3571
  }
3532
3572
 
3573
+ const PureFunctionKey = Symbol('PureFunction');
3574
+ const getPureFunctions = ({ treeshake }) => {
3575
+ const pureFunctions = Object.create(null);
3576
+ for (const functionName of treeshake ? treeshake.manualPureFunctions : []) {
3577
+ let currentFunctions = pureFunctions;
3578
+ for (const pathSegment of functionName.split('.')) {
3579
+ currentFunctions = currentFunctions[pathSegment] ||= Object.create(null);
3580
+ }
3581
+ currentFunctions[PureFunctionKey] = true;
3582
+ }
3583
+ return pureFunctions;
3584
+ };
3585
+
3533
3586
  const UnknownKey = Symbol('Unknown Key');
3534
3587
  const UnknownNonAccessorKey = Symbol('Unknown Non-Accessor Key');
3535
3588
  const UnknownInteger = Symbol('Unknown Integer');
@@ -3544,7 +3597,7 @@ const UNKNOWN_PATH = [UnknownKey];
3544
3597
  const UNKNOWN_NON_ACCESSOR_PATH = [UnknownNonAccessorKey];
3545
3598
  const UNKNOWN_INTEGER_PATH = [UnknownInteger];
3546
3599
  const EntitiesKey = Symbol('Entities');
3547
- class EntityPathTracker {
3600
+ class PathTracker {
3548
3601
  constructor() {
3549
3602
  this.entityPaths = Object.create(null, {
3550
3603
  [EntitiesKey]: { value: new Set() }
@@ -3569,14 +3622,14 @@ class EntityPathTracker {
3569
3622
  getEntities(path) {
3570
3623
  let currentPaths = this.entityPaths;
3571
3624
  for (const pathSegment of path) {
3572
- currentPaths = currentPaths[pathSegment] ||= Object.create(null, {
3573
- [EntitiesKey]: { value: new Set() }
3574
- });
3625
+ currentPaths = currentPaths[pathSegment] =
3626
+ currentPaths[pathSegment] ||
3627
+ Object.create(null, { [EntitiesKey]: { value: new Set() } });
3575
3628
  }
3576
3629
  return currentPaths[EntitiesKey];
3577
3630
  }
3578
3631
  }
3579
- const SHARED_RECURSION_TRACKER = new EntityPathTracker();
3632
+ const SHARED_RECURSION_TRACKER = new PathTracker();
3580
3633
  class DiscriminatedPathTracker {
3581
3634
  constructor() {
3582
3635
  this.entityPaths = Object.create(null, {
@@ -3586,9 +3639,9 @@ class DiscriminatedPathTracker {
3586
3639
  trackEntityAtPathAndGetIfTracked(path, discriminator, entity) {
3587
3640
  let currentPaths = this.entityPaths;
3588
3641
  for (const pathSegment of path) {
3589
- currentPaths = currentPaths[pathSegment] ||= Object.create(null, {
3590
- [EntitiesKey]: { value: new Map() }
3591
- });
3642
+ currentPaths = currentPaths[pathSegment] =
3643
+ currentPaths[pathSegment] ||
3644
+ Object.create(null, { [EntitiesKey]: { value: new Map() } });
3592
3645
  }
3593
3646
  const trackedEntities = getOrCreate(currentPaths[EntitiesKey], discriminator, (getNewSet));
3594
3647
  if (trackedEntities.has(entity))
@@ -3597,85 +3650,6 @@ class DiscriminatedPathTracker {
3597
3650
  return false;
3598
3651
  }
3599
3652
  }
3600
- const UNKNOWN_INCLUDED_PATH = Object.freeze({ [UnknownKey]: parseAst_js.EMPTY_OBJECT });
3601
- class IncludedPathTracker {
3602
- constructor() {
3603
- this.includedPaths = null;
3604
- }
3605
- includePathAndGetIfIncluded(path) {
3606
- let included = true;
3607
- let parent = this;
3608
- let parentSegment = 'includedPaths';
3609
- let currentPaths = (this.includedPaths ||=
3610
- ((included = false), Object.create(null)));
3611
- for (const pathSegment of path) {
3612
- // This means from here, all paths are included
3613
- if (currentPaths[UnknownKey]) {
3614
- return true;
3615
- }
3616
- // Including UnknownKey automatically includes all nested paths.
3617
- // From above, we know that UnknownKey is not included yet.
3618
- if (typeof pathSegment === 'symbol') {
3619
- // Hopefully, this saves some memory over just setting
3620
- // currentPaths[UnknownKey] = EMPTY_OBJECT
3621
- parent[parentSegment] = UNKNOWN_INCLUDED_PATH;
3622
- return false;
3623
- }
3624
- parent = currentPaths;
3625
- parentSegment = pathSegment;
3626
- currentPaths = currentPaths[pathSegment] ||= ((included = false), Object.create(null));
3627
- }
3628
- return included;
3629
- }
3630
- includeAllPaths(entity, context, basePath) {
3631
- const { includedPaths } = this;
3632
- if (includedPaths) {
3633
- includeAllPaths(entity, context, basePath, includedPaths);
3634
- }
3635
- }
3636
- }
3637
- function includeAllPaths(entity, context, basePath, currentPaths) {
3638
- if (currentPaths[UnknownKey]) {
3639
- return entity.includePath([...basePath, UnknownKey], context, false);
3640
- }
3641
- const keys = Object.keys(currentPaths);
3642
- if (keys.length === 0) {
3643
- return entity.includePath(basePath, context, false);
3644
- }
3645
- for (const key of keys) {
3646
- includeAllPaths(entity, context, [...basePath, key], currentPaths[key]);
3647
- }
3648
- }
3649
-
3650
- function createInclusionContext() {
3651
- return {
3652
- brokenFlow: false,
3653
- hasBreak: false,
3654
- hasContinue: false,
3655
- includedCallArguments: new Set(),
3656
- includedLabels: new Set()
3657
- };
3658
- }
3659
- function createHasEffectsContext() {
3660
- return {
3661
- accessed: new EntityPathTracker(),
3662
- assigned: new EntityPathTracker(),
3663
- brokenFlow: false,
3664
- called: new DiscriminatedPathTracker(),
3665
- hasBreak: false,
3666
- hasContinue: false,
3667
- ignore: {
3668
- breaks: false,
3669
- continues: false,
3670
- labels: new Set(),
3671
- returnYield: false,
3672
- this: false
3673
- },
3674
- includedLabels: new Set(),
3675
- instantiated: new DiscriminatedPathTracker(),
3676
- replacedVariableInits: new Map()
3677
- };
3678
- }
3679
3653
 
3680
3654
  function isFlagSet(flags, flag) {
3681
3655
  return (flags & flag) !== 0;
@@ -3714,12 +3688,12 @@ class ExpressionEntity {
3714
3688
  hasEffectsOnInteractionAtPath(_path, _interaction, _context) {
3715
3689
  return true;
3716
3690
  }
3717
- includePath(_path, _context, _includeChildrenRecursively, _options) {
3691
+ include(_context, _includeChildrenRecursively, _options) {
3718
3692
  this.included = true;
3719
3693
  }
3720
- includeCallArguments(context, interaction) {
3721
- for (const argument of interaction.args) {
3722
- argument?.includePath(UNKNOWN_PATH, context, false);
3694
+ includeCallArguments(context, parameters) {
3695
+ for (const argument of parameters) {
3696
+ argument.include(context, false);
3723
3697
  }
3724
3698
  }
3725
3699
  shouldBeIncluded(_context) {
@@ -3758,19 +3732,6 @@ const NODE_INTERACTION_UNKNOWN_CALL = {
3758
3732
  withNew: false
3759
3733
  };
3760
3734
 
3761
- const PureFunctionKey = Symbol('PureFunction');
3762
- const getPureFunctions = ({ treeshake }) => {
3763
- const pureFunctions = Object.create(null);
3764
- for (const functionName of treeshake ? treeshake.manualPureFunctions : []) {
3765
- let currentFunctions = pureFunctions;
3766
- for (const pathSegment of functionName.split('.')) {
3767
- currentFunctions = currentFunctions[pathSegment] ||= Object.create(null);
3768
- }
3769
- currentFunctions[PureFunctionKey] = true;
3770
- }
3771
- return pureFunctions;
3772
- };
3773
-
3774
3735
  class Variable extends ExpressionEntity {
3775
3736
  markReassigned() {
3776
3737
  this.isReassigned = true;
@@ -3847,9 +3808,9 @@ class Variable extends ExpressionEntity {
3847
3808
  * has not been included previously. Once a variable is included, it should
3848
3809
  * take care all its declarations are included.
3849
3810
  */
3850
- includePath(path, context) {
3811
+ include() {
3851
3812
  this.included = true;
3852
- this.renderedLikeHoisted?.includePath(path, context);
3813
+ this.renderedLikeHoisted?.include();
3853
3814
  }
3854
3815
  /**
3855
3816
  * Links the rendered name of this variable to another variable and includes
@@ -3881,8 +3842,8 @@ class ExternalVariable extends Variable {
3881
3842
  hasEffectsOnInteractionAtPath(path, { type }) {
3882
3843
  return type !== INTERACTION_ACCESSED || path.length > (this.isNamespace ? 1 : 0);
3883
3844
  }
3884
- includePath(path, context) {
3885
- super.includePath(path, context);
3845
+ include() {
3846
+ super.include();
3886
3847
  this.module.used = true;
3887
3848
  }
3888
3849
  }
@@ -4181,6 +4142,36 @@ const childNodeKeys = {
4181
4142
  YieldExpression: ['argument']
4182
4143
  };
4183
4144
 
4145
+ function createInclusionContext() {
4146
+ return {
4147
+ brokenFlow: false,
4148
+ hasBreak: false,
4149
+ hasContinue: false,
4150
+ includedCallArguments: new Set(),
4151
+ includedLabels: new Set()
4152
+ };
4153
+ }
4154
+ function createHasEffectsContext() {
4155
+ return {
4156
+ accessed: new PathTracker(),
4157
+ assigned: new PathTracker(),
4158
+ brokenFlow: false,
4159
+ called: new DiscriminatedPathTracker(),
4160
+ hasBreak: false,
4161
+ hasContinue: false,
4162
+ ignore: {
4163
+ breaks: false,
4164
+ continues: false,
4165
+ labels: new Set(),
4166
+ returnYield: false,
4167
+ this: false
4168
+ },
4169
+ includedLabels: new Set(),
4170
+ instantiated: new DiscriminatedPathTracker(),
4171
+ replacedVariableInits: new Map()
4172
+ };
4173
+ }
4174
+
4184
4175
  const INCLUDE_PARAMETERS = 'variables';
4185
4176
  const IS_SKIPPED_CHAIN = Symbol('IS_SKIPPED_CHAIN');
4186
4177
  class NodeBase extends ExpressionEntity {
@@ -4249,7 +4240,7 @@ class NodeBase extends ExpressionEntity {
4249
4240
  return (this.hasEffects(context) ||
4250
4241
  this.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.assignmentInteraction, context));
4251
4242
  }
4252
- includePath(_path, context, includeChildrenRecursively, _options) {
4243
+ include(context, includeChildrenRecursively, _options) {
4253
4244
  if (!this.deoptimized)
4254
4245
  this.applyDeoptimizations();
4255
4246
  this.included = true;
@@ -4259,16 +4250,16 @@ class NodeBase extends ExpressionEntity {
4259
4250
  continue;
4260
4251
  if (Array.isArray(value)) {
4261
4252
  for (const child of value) {
4262
- child?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
4253
+ child?.include(context, includeChildrenRecursively);
4263
4254
  }
4264
4255
  }
4265
4256
  else {
4266
- value.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
4257
+ value.include(context, includeChildrenRecursively);
4267
4258
  }
4268
4259
  }
4269
4260
  }
4270
4261
  includeAsAssignmentTarget(context, includeChildrenRecursively, _deoptimizeAccess) {
4271
- this.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
4262
+ this.include(context, includeChildrenRecursively);
4272
4263
  }
4273
4264
  /**
4274
4265
  * Override to perform special initialisation steps after the scope is
@@ -4730,7 +4721,6 @@ class ObjectEntity extends ExpressionEntity {
4730
4721
  this.unknownIntegerProps = [];
4731
4722
  this.unmatchableGetters = [];
4732
4723
  this.unmatchablePropertiesAndGetters = [];
4733
- this.unmatchablePropertiesAndSetters = [];
4734
4724
  this.unmatchableSetters = [];
4735
4725
  if (Array.isArray(properties)) {
4736
4726
  this.buildPropertyMaps(properties);
@@ -4965,37 +4955,9 @@ class ObjectEntity extends ExpressionEntity {
4965
4955
  }
4966
4956
  return false;
4967
4957
  }
4968
- includePath(path, context, includeChildrenRecursively) {
4969
- this.included = true;
4970
- const [key, ...subPath] = path;
4971
- if (key == null || includeChildrenRecursively) {
4972
- for (const property of this.allProperties) {
4973
- if (includeChildrenRecursively || property.shouldBeIncluded(context)) {
4974
- property.includePath(EMPTY_PATH, context, includeChildrenRecursively);
4975
- }
4976
- }
4977
- this.prototypeExpression?.includePath(EMPTY_PATH, context, includeChildrenRecursively);
4978
- }
4979
- else {
4980
- const [includedMembers, includedPath] = typeof key === 'string'
4981
- ? [
4982
- [
4983
- ...new Set([
4984
- ...(this.propertiesAndGettersByKey[key] || this.unmatchablePropertiesAndGetters),
4985
- ...(this.propertiesAndSettersByKey[key] || this.unmatchablePropertiesAndSetters)
4986
- ])
4987
- ],
4988
- subPath
4989
- ]
4990
- : [this.allProperties, UNKNOWN_PATH];
4991
- for (const property of includedMembers) {
4992
- property.includePath(includedPath, context, includeChildrenRecursively);
4993
- }
4994
- this.prototypeExpression?.includePath(path, context, includeChildrenRecursively);
4995
- }
4996
- }
4997
4958
  buildPropertyMaps(properties) {
4998
- const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchablePropertiesAndSetters, unmatchableGetters, unmatchableSetters } = this;
4959
+ const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchableGetters, unmatchableSetters } = this;
4960
+ const unmatchablePropertiesAndSetters = [];
4999
4961
  for (let index = properties.length - 1; index >= 0; index--) {
5000
4962
  const { key, kind, property } = properties[index];
5001
4963
  allProperties.push(property);
@@ -6352,37 +6314,17 @@ class GlobalVariable extends Variable {
6352
6314
  }
6353
6315
  }
6354
6316
 
6355
- // To avoid infinite recursions
6356
- const MAX_PATH_DEPTH = 6;
6357
- // If a path is longer than MAX_PATH_DEPTH, it is truncated so that it is at
6358
- // most MAX_PATH_DEPTH long. The last element is always UnknownKey
6359
- const limitConcatenatedPathDepth = (path1, path2) => {
6360
- const { length: length1 } = path1;
6361
- const { length: length2 } = path2;
6362
- return length1 === 0
6363
- ? path2
6364
- : length2 === 0
6365
- ? path1
6366
- : length1 + length2 > MAX_PATH_DEPTH
6367
- ? [...path1, ...path2.slice(0, MAX_PATH_DEPTH - 1 - path1.length), 'UnknownKey']
6368
- : [...path1, ...path2];
6369
- };
6370
-
6371
6317
  class LocalVariable extends Variable {
6372
- constructor(name, declarator, init,
6373
- /** if this is non-empty, the actual init is this path of this.init */
6374
- initPath, context, kind) {
6318
+ constructor(name, declarator, init, context, kind) {
6375
6319
  super(name);
6376
6320
  this.init = init;
6377
- this.initPath = initPath;
6378
- this.kind = kind;
6379
6321
  this.calledFromTryStatement = false;
6380
6322
  this.additionalInitializers = null;
6381
- this.includedPathTracker = new IncludedPathTracker();
6382
6323
  this.expressionsToBeDeoptimized = [];
6383
6324
  this.declarations = declarator ? [declarator] : [];
6384
6325
  this.deoptimizationTracker = context.deoptimizationTracker;
6385
6326
  this.module = context.module;
6327
+ this.kind = kind;
6386
6328
  }
6387
6329
  addDeclaration(identifier, init) {
6388
6330
  this.declarations.push(identifier);
@@ -6393,16 +6335,15 @@ class LocalVariable extends Variable {
6393
6335
  for (const initializer of this.additionalInitializers) {
6394
6336
  initializer.deoptimizePath(UNKNOWN_PATH);
6395
6337
  }
6338
+ this.additionalInitializers = null;
6396
6339
  }
6397
6340
  }
6398
6341
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6399
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
6342
+ if (this.isReassigned) {
6400
6343
  deoptimizeInteraction(interaction);
6401
6344
  return;
6402
6345
  }
6403
- recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6404
- this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], recursionTracker);
6405
- }, undefined);
6346
+ recursionTracker.withTrackedEntityAtPath(path, this.init, () => this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker), undefined);
6406
6347
  }
6407
6348
  deoptimizePath(path) {
6408
6349
  if (this.isReassigned ||
@@ -6416,40 +6357,37 @@ class LocalVariable extends Variable {
6416
6357
  for (const expression of expressionsToBeDeoptimized) {
6417
6358
  expression.deoptimizeCache();
6418
6359
  }
6419
- this.init.deoptimizePath([...this.initPath, UnknownKey]);
6360
+ this.init.deoptimizePath(UNKNOWN_PATH);
6420
6361
  }
6421
6362
  else {
6422
- this.init.deoptimizePath(limitConcatenatedPathDepth(this.initPath, path));
6363
+ this.init.deoptimizePath(path);
6423
6364
  }
6424
6365
  }
6425
6366
  getLiteralValueAtPath(path, recursionTracker, origin) {
6426
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
6367
+ if (this.isReassigned) {
6427
6368
  return UnknownValue;
6428
6369
  }
6429
6370
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6430
6371
  this.expressionsToBeDeoptimized.push(origin);
6431
- return this.init.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin);
6372
+ return this.init.getLiteralValueAtPath(path, recursionTracker, origin);
6432
6373
  }, UnknownValue);
6433
6374
  }
6434
6375
  getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
6435
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
6376
+ if (this.isReassigned) {
6436
6377
  return UNKNOWN_RETURN_EXPRESSION;
6437
6378
  }
6438
6379
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6439
6380
  this.expressionsToBeDeoptimized.push(origin);
6440
- return this.init.getReturnExpressionWhenCalledAtPath([...this.initPath, ...path], interaction, recursionTracker, origin);
6381
+ return this.init.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
6441
6382
  }, UNKNOWN_RETURN_EXPRESSION);
6442
6383
  }
6443
6384
  hasEffectsOnInteractionAtPath(path, interaction, context) {
6444
- if (path.length + this.initPath.length > MAX_PATH_DEPTH) {
6445
- return true;
6446
- }
6447
6385
  switch (interaction.type) {
6448
6386
  case INTERACTION_ACCESSED: {
6449
6387
  if (this.isReassigned)
6450
6388
  return true;
6451
6389
  return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
6452
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6390
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6453
6391
  }
6454
6392
  case INTERACTION_ASSIGNED: {
6455
6393
  if (this.included)
@@ -6459,23 +6397,23 @@ class LocalVariable extends Variable {
6459
6397
  if (this.isReassigned)
6460
6398
  return true;
6461
6399
  return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
6462
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6400
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6463
6401
  }
6464
6402
  case INTERACTION_CALLED: {
6465
6403
  if (this.isReassigned)
6466
6404
  return true;
6467
6405
  return (!(interaction.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this) &&
6468
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6406
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6469
6407
  }
6470
6408
  }
6471
6409
  }
6472
- includePath(path, context) {
6473
- if (!this.includedPathTracker.includePathAndGetIfIncluded(path)) {
6474
- super.includePath(path, context);
6410
+ include() {
6411
+ if (!this.included) {
6412
+ super.include();
6475
6413
  for (const declaration of this.declarations) {
6476
6414
  // If node is a default export, it can save a tree-shaking run to include the full declaration now
6477
6415
  if (!declaration.included)
6478
- declaration.includePath(EMPTY_PATH, context, false);
6416
+ declaration.include(createInclusionContext(), false);
6479
6417
  let node = declaration.parent;
6480
6418
  while (!node.included) {
6481
6419
  // We do not want to properly include parents in case they are part of a dead branch
@@ -6486,26 +6424,17 @@ class LocalVariable extends Variable {
6486
6424
  node = node.parent;
6487
6425
  }
6488
6426
  }
6489
- // We need to make sure we include the correct path of the init
6490
- if (path.length > 0) {
6491
- this.init.includePath(limitConcatenatedPathDepth(this.initPath, path), context, false);
6492
- this.additionalInitializers?.forEach(initializer => initializer.includePath(UNKNOWN_PATH, context, false));
6493
- }
6494
6427
  }
6495
6428
  }
6496
- includeCallArguments(context, interaction) {
6497
- if (this.isReassigned ||
6498
- context.includedCallArguments.has(this.init) ||
6499
- // This can be removed again once we can include arguments when called at
6500
- // a specific path
6501
- this.initPath.length > 0) {
6502
- for (const argument of interaction.args) {
6503
- argument?.includePath(UNKNOWN_PATH, context, false);
6429
+ includeCallArguments(context, parameters) {
6430
+ if (this.isReassigned || context.includedCallArguments.has(this.init)) {
6431
+ for (const argument of parameters) {
6432
+ argument.include(context, false);
6504
6433
  }
6505
6434
  }
6506
6435
  else {
6507
6436
  context.includedCallArguments.add(this.init);
6508
- this.init.includeCallArguments(context, interaction);
6437
+ this.init.includeCallArguments(context, parameters);
6509
6438
  context.includedCallArguments.delete(this.init);
6510
6439
  }
6511
6440
  }
@@ -6585,21 +6514,18 @@ class IdentifierBase extends NodeBase {
6585
6514
  }
6586
6515
  }
6587
6516
  }
6588
- includePath(path, context) {
6517
+ include() {
6589
6518
  if (!this.deoptimized)
6590
6519
  this.applyDeoptimizations();
6591
6520
  if (!this.included) {
6592
6521
  this.included = true;
6593
6522
  if (this.variable !== null) {
6594
- this.scope.context.includeVariableInModule(this.variable, path);
6523
+ this.scope.context.includeVariableInModule(this.variable);
6595
6524
  }
6596
6525
  }
6597
- else if (path.length > 0) {
6598
- this.variable?.includePath(path, context);
6599
- }
6600
6526
  }
6601
- includeCallArguments(context, interaction) {
6602
- this.variable.includeCallArguments(context, interaction);
6527
+ includeCallArguments(context, parameters) {
6528
+ this.variable.includeCallArguments(context, parameters);
6603
6529
  }
6604
6530
  isPossibleTDZ() {
6605
6531
  // return cached value to avoid issues with the next tree-shaking pass
@@ -6682,40 +6608,11 @@ function closestParentFunctionOrProgram(node) {
6682
6608
  return node;
6683
6609
  }
6684
6610
 
6685
- class ObjectMember extends ExpressionEntity {
6686
- constructor(object, path) {
6687
- super();
6688
- this.object = object;
6689
- this.path = path;
6690
- }
6691
- deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6692
- this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.path, ...path], recursionTracker);
6693
- }
6694
- deoptimizePath(path) {
6695
- this.object.deoptimizePath([...this.path, ...path]);
6696
- }
6697
- getLiteralValueAtPath(path, recursionTracker, origin) {
6698
- return this.object.getLiteralValueAtPath([...this.path, ...path], recursionTracker, origin);
6699
- }
6700
- getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
6701
- return this.object.getReturnExpressionWhenCalledAtPath([...this.path, ...path], interaction, recursionTracker, origin);
6702
- }
6703
- hasEffectsOnInteractionAtPath(path, interaction, context) {
6704
- return this.object.hasEffectsOnInteractionAtPath([...this.path, ...path], interaction, context);
6705
- }
6706
- }
6707
-
6708
6611
  class Identifier extends IdentifierBase {
6709
6612
  constructor() {
6710
6613
  super(...arguments);
6711
6614
  this.variable = null;
6712
6615
  }
6713
- get isDestructuringDeoptimized() {
6714
- return isFlagSet(this.flags, 8388608 /* Flag.destructuringDeoptimized */);
6715
- }
6716
- set isDestructuringDeoptimized(value) {
6717
- this.flags = setFlag(this.flags, 8388608 /* Flag.destructuringDeoptimized */, value);
6718
- }
6719
6616
  addExportedVariables(variables, exportNamesByVariable) {
6720
6617
  if (exportNamesByVariable.has(this.variable)) {
6721
6618
  variables.push(this.variable);
@@ -6728,52 +6625,42 @@ class Identifier extends IdentifierBase {
6728
6625
  this.isVariableReference = true;
6729
6626
  }
6730
6627
  }
6731
- declare(kind, destructuredInitPath, init) {
6628
+ declare(kind, init) {
6732
6629
  let variable;
6733
6630
  const { treeshake } = this.scope.context.options;
6734
- if (kind === 'parameter') {
6735
- variable = this.scope.addParameterDeclaration(this, destructuredInitPath);
6736
- }
6737
- else {
6738
- variable = this.scope.addDeclaration(this, this.scope.context, init, destructuredInitPath, kind);
6739
- if (kind === 'var' && treeshake && treeshake.correctVarValueBeforeDeclaration) {
6740
- // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
6741
- variable.markInitializersForDeoptimization();
6631
+ switch (kind) {
6632
+ case 'var': {
6633
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
6634
+ if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
6635
+ // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
6636
+ variable.markInitializersForDeoptimization();
6637
+ }
6638
+ break;
6742
6639
  }
6743
- }
6744
- return [(this.variable = variable)];
6745
- }
6746
- deoptimizeAssignment(destructuredInitPath, init) {
6747
- this.deoptimizePath(EMPTY_PATH);
6748
- init.deoptimizePath([...destructuredInitPath, UnknownKey]);
6749
- }
6750
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
6751
- return (destructuredInitPath.length > 0 &&
6752
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, context));
6753
- }
6754
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
6755
- if (destructuredInitPath.length > 0 && !this.isDestructuringDeoptimized) {
6756
- this.isDestructuringDeoptimized = true;
6757
- init.deoptimizeArgumentsOnInteractionAtPath({
6758
- args: [new ObjectMember(init, destructuredInitPath.slice(0, -1))],
6759
- type: INTERACTION_ACCESSED
6760
- }, destructuredInitPath, SHARED_RECURSION_TRACKER);
6761
- }
6762
- const { propertyReadSideEffects } = this.scope.context.options
6763
- .treeshake;
6764
- if ((this.included ||=
6765
- destructuredInitPath.length > 0 &&
6766
- !context.brokenFlow &&
6767
- propertyReadSideEffects &&
6768
- (propertyReadSideEffects === 'always' ||
6769
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, createHasEffectsContext())))) {
6770
- if (this.variable && !this.variable.included) {
6771
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH);
6640
+ case 'function': {
6641
+ // in strict mode, functions are only hoisted within a scope but not across block scopes
6642
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
6643
+ break;
6644
+ }
6645
+ case 'let':
6646
+ case 'const':
6647
+ case 'using':
6648
+ case 'await using':
6649
+ case 'class': {
6650
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
6651
+ break;
6652
+ }
6653
+ case 'parameter': {
6654
+ variable = this.scope.addParameterDeclaration(this);
6655
+ break;
6656
+ }
6657
+ /* istanbul ignore next */
6658
+ default: {
6659
+ /* istanbul ignore next */
6660
+ throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
6772
6661
  }
6773
- init.includePath(destructuredInitPath, context, false);
6774
- return true;
6775
6662
  }
6776
- return false;
6663
+ return [(this.variable = variable)];
6777
6664
  }
6778
6665
  markDeclarationReached() {
6779
6666
  this.variable.initReached = true;
@@ -6827,17 +6714,18 @@ class Scope {
6827
6714
  - then the variable is still declared in the hoisted outer scope, but the initializer is assigned to the parameter
6828
6715
  - const, let, class, and function except in the cases above cannot redeclare anything
6829
6716
  */
6830
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
6717
+ addDeclaration(identifier, context, init, kind) {
6831
6718
  const name = identifier.name;
6832
6719
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
6833
6720
  if (existingVariable) {
6834
- if (kind === 'var' && existingVariable.kind === 'var') {
6721
+ const existingKind = existingVariable.kind;
6722
+ if (kind === 'var' && existingKind === 'var') {
6835
6723
  existingVariable.addDeclaration(identifier, init);
6836
6724
  return existingVariable;
6837
6725
  }
6838
6726
  context.error(parseAst_js.logRedeclarationError(name), identifier.start);
6839
6727
  }
6840
- const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
6728
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
6841
6729
  this.variables.set(name, newVariable);
6842
6730
  return newVariable;
6843
6731
  }
@@ -7039,7 +6927,7 @@ class BlockScope extends ChildScope {
7039
6927
  constructor(parent) {
7040
6928
  super(parent, parent.context);
7041
6929
  }
7042
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
6930
+ addDeclaration(identifier, context, init, kind) {
7043
6931
  if (kind === 'var') {
7044
6932
  const name = identifier.name;
7045
6933
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -7051,7 +6939,7 @@ class BlockScope extends ChildScope {
7051
6939
  }
7052
6940
  return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7053
6941
  }
7054
- const declaredVariable = this.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
6942
+ const declaredVariable = this.parent.addDeclaration(identifier, context, init, kind);
7055
6943
  // Necessary to make sure the init is deoptimized for conditional declarations.
7056
6944
  // We cannot call deoptimizePath here.
7057
6945
  declaredVariable.markInitializersForDeoptimization();
@@ -7059,7 +6947,7 @@ class BlockScope extends ChildScope {
7059
6947
  this.addHoistedVariable(name, declaredVariable);
7060
6948
  return declaredVariable;
7061
6949
  }
7062
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
6950
+ return super.addDeclaration(identifier, context, init, kind);
7063
6951
  }
7064
6952
  }
7065
6953
 
@@ -7074,11 +6962,11 @@ class StaticBlock extends NodeBase {
7074
6962
  }
7075
6963
  return false;
7076
6964
  }
7077
- includePath(_path, context, includeChildrenRecursively) {
6965
+ include(context, includeChildrenRecursively) {
7078
6966
  this.included = true;
7079
6967
  for (const node of this.body) {
7080
6968
  if (includeChildrenRecursively || node.shouldBeIncluded(context))
7081
- node.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
6969
+ node.include(context, includeChildrenRecursively);
7082
6970
  }
7083
6971
  }
7084
6972
  render(code, options) {
@@ -7095,6 +6983,29 @@ function isStaticBlock(statement) {
7095
6983
  return statement.type === parseAst_js.StaticBlock;
7096
6984
  }
7097
6985
 
6986
+ class ObjectMember extends ExpressionEntity {
6987
+ constructor(object, key) {
6988
+ super();
6989
+ this.object = object;
6990
+ this.key = key;
6991
+ }
6992
+ deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6993
+ this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [this.key, ...path], recursionTracker);
6994
+ }
6995
+ deoptimizePath(path) {
6996
+ this.object.deoptimizePath([this.key, ...path]);
6997
+ }
6998
+ getLiteralValueAtPath(path, recursionTracker, origin) {
6999
+ return this.object.getLiteralValueAtPath([this.key, ...path], recursionTracker, origin);
7000
+ }
7001
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
7002
+ return this.object.getReturnExpressionWhenCalledAtPath([this.key, ...path], interaction, recursionTracker, origin);
7003
+ }
7004
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
7005
+ return this.object.hasEffectsOnInteractionAtPath([this.key, ...path], interaction, context);
7006
+ }
7007
+ }
7008
+
7098
7009
  class ClassNode extends NodeBase {
7099
7010
  constructor() {
7100
7011
  super(...arguments);
@@ -7134,22 +7045,22 @@ class ClassNode extends NodeBase {
7134
7045
  false
7135
7046
  : this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
7136
7047
  }
7137
- includePath(_path, context, includeChildrenRecursively) {
7048
+ include(context, includeChildrenRecursively) {
7138
7049
  if (!this.deoptimized)
7139
7050
  this.applyDeoptimizations();
7140
7051
  this.included = true;
7141
- this.superClass?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
7142
- this.body.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
7052
+ this.superClass?.include(context, includeChildrenRecursively);
7053
+ this.body.include(context, includeChildrenRecursively);
7143
7054
  for (const decorator of this.decorators)
7144
- decorator.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
7055
+ decorator.include(context, includeChildrenRecursively);
7145
7056
  if (this.id) {
7146
7057
  this.id.markDeclarationReached();
7147
- this.id.includePath(UNKNOWN_PATH, createInclusionContext());
7058
+ this.id.include();
7148
7059
  }
7149
7060
  }
7150
7061
  initialise() {
7151
7062
  super.initialise();
7152
- this.id?.declare('class', EMPTY_PATH, this);
7063
+ this.id?.declare('class', this);
7153
7064
  for (const method of this.body.body) {
7154
7065
  if (method instanceof MethodDefinition && method.kind === 'constructor') {
7155
7066
  this.classConstructor = method;
@@ -7207,7 +7118,7 @@ class ClassNode extends NodeBase {
7207
7118
  staticProperties.unshift({
7208
7119
  key: 'prototype',
7209
7120
  kind: 'init',
7210
- property: new ObjectEntity(dynamicMethods, this.superClass ? new ObjectMember(this.superClass, ['prototype']) : OBJECT_PROTOTYPE)
7121
+ property: new ObjectEntity(dynamicMethods, this.superClass ? new ObjectMember(this.superClass, 'prototype') : OBJECT_PROTOTYPE)
7211
7122
  });
7212
7123
  return (this.objectEntity = new ObjectEntity(staticProperties, this.superClass || OBJECT_PROTOTYPE));
7213
7124
  }
@@ -7264,7 +7175,7 @@ class ClassDeclaration extends ClassNode {
7264
7175
 
7265
7176
  class ArgumentsVariable extends LocalVariable {
7266
7177
  constructor(context) {
7267
- super('arguments', null, UNKNOWN_EXPRESSION, EMPTY_PATH, context, 'other');
7178
+ super('arguments', null, UNKNOWN_EXPRESSION, context, 'other');
7268
7179
  this.deoptimizedArguments = [];
7269
7180
  }
7270
7181
  addArgumentToBeDeoptimized(argument) {
@@ -7278,8 +7189,8 @@ class ArgumentsVariable extends LocalVariable {
7278
7189
  hasEffectsOnInteractionAtPath(path, { type }) {
7279
7190
  return type !== INTERACTION_ACCESSED || path.length > 1;
7280
7191
  }
7281
- includePath(path, context) {
7282
- super.includePath(path, context);
7192
+ include() {
7193
+ super.include();
7283
7194
  for (const argument of this.deoptimizedArguments) {
7284
7195
  argument.deoptimizePath(UNKNOWN_PATH);
7285
7196
  }
@@ -7290,28 +7201,27 @@ class ArgumentsVariable extends LocalVariable {
7290
7201
  const MAX_TRACKED_INTERACTIONS = 20;
7291
7202
  const NO_INTERACTIONS = parseAst_js.EMPTY_ARRAY;
7292
7203
  const UNKNOWN_DEOPTIMIZED_FIELD = new Set([UnknownKey]);
7293
- const EMPTY_PATH_TRACKER = new EntityPathTracker();
7204
+ const EMPTY_PATH_TRACKER = new PathTracker();
7294
7205
  const UNKNOWN_DEOPTIMIZED_ENTITY = new Set([UNKNOWN_EXPRESSION]);
7295
7206
  class ParameterVariable extends LocalVariable {
7296
- constructor(name, declarator, argumentPath, context) {
7297
- super(name, declarator, UNKNOWN_EXPRESSION, argumentPath, context, 'parameter');
7207
+ constructor(name, declarator, context) {
7208
+ super(name, declarator, UNKNOWN_EXPRESSION, context, 'parameter');
7298
7209
  this.deoptimizationInteractions = [];
7299
- this.deoptimizations = new EntityPathTracker();
7210
+ this.deoptimizations = new PathTracker();
7300
7211
  this.deoptimizedFields = new Set();
7301
- this.argumentsToBeDeoptimized = new Set();
7302
- this.expressionsDependingOnKnownValue = [];
7212
+ this.entitiesToBeDeoptimized = new Set();
7213
+ this.expressionsUseTheKnownValue = [];
7303
7214
  this.knownValue = null;
7304
7215
  this.knownValueLiteral = UnknownValue;
7305
7216
  this.frozenValue = null;
7306
7217
  }
7307
- addArgumentValue(entity) {
7308
- this.updateKnownValue(entity);
7218
+ addEntityToBeDeoptimized(entity) {
7309
7219
  if (entity === UNKNOWN_EXPRESSION) {
7310
7220
  // As unknown expressions fully deoptimize all interactions, we can clear
7311
7221
  // the interaction cache at this point provided we keep this optimization
7312
7222
  // in mind when adding new interactions
7313
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7314
- this.argumentsToBeDeoptimized.add(UNKNOWN_EXPRESSION);
7223
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7224
+ this.entitiesToBeDeoptimized.add(UNKNOWN_EXPRESSION);
7315
7225
  for (const { interaction } of this.deoptimizationInteractions) {
7316
7226
  deoptimizeInteraction(interaction);
7317
7227
  }
@@ -7321,34 +7231,27 @@ class ParameterVariable extends LocalVariable {
7321
7231
  else if (this.deoptimizedFields.has(UnknownKey)) {
7322
7232
  // This means that we already deoptimized all interactions and no longer
7323
7233
  // track them
7324
- entity.deoptimizePath([...this.initPath, UnknownKey]);
7234
+ entity.deoptimizePath(UNKNOWN_PATH);
7325
7235
  }
7326
- else if (!this.argumentsToBeDeoptimized.has(entity)) {
7327
- this.argumentsToBeDeoptimized.add(entity);
7236
+ else if (!this.entitiesToBeDeoptimized.has(entity)) {
7237
+ this.entitiesToBeDeoptimized.add(entity);
7328
7238
  for (const field of this.deoptimizedFields) {
7329
- entity.deoptimizePath([...this.initPath, field]);
7239
+ entity.deoptimizePath([field]);
7330
7240
  }
7331
7241
  for (const { interaction, path } of this.deoptimizationInteractions) {
7332
- if (this.initPath.length + path.length > MAX_PATH_DEPTH) {
7333
- deoptimizeInteraction(interaction);
7334
- continue;
7335
- }
7336
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
7242
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
7337
7243
  }
7338
7244
  }
7339
7245
  }
7340
- /** This says we should not make assumptions about the value of the parameter.
7341
- * This is different from deoptimization that will also cause argument values
7342
- * to be deoptimized. */
7343
7246
  markReassigned() {
7344
7247
  if (this.isReassigned) {
7345
7248
  return;
7346
7249
  }
7347
7250
  super.markReassigned();
7348
- for (const expression of this.expressionsDependingOnKnownValue) {
7251
+ for (const expression of this.expressionsUseTheKnownValue) {
7349
7252
  expression.deoptimizeCache();
7350
7253
  }
7351
- this.expressionsDependingOnKnownValue = parseAst_js.EMPTY_ARRAY;
7254
+ this.expressionsUseTheKnownValue = parseAst_js.EMPTY_ARRAY;
7352
7255
  }
7353
7256
  deoptimizeCache() {
7354
7257
  this.markReassigned();
@@ -7365,7 +7268,7 @@ class ParameterVariable extends LocalVariable {
7365
7268
  }
7366
7269
  if (this.knownValue === null) {
7367
7270
  this.knownValue = argument;
7368
- this.knownValueLiteral = argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this);
7271
+ this.knownValueLiteral = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
7369
7272
  return;
7370
7273
  }
7371
7274
  // the same literal or identifier, do nothing
@@ -7381,7 +7284,7 @@ class ParameterVariable extends LocalVariable {
7381
7284
  return;
7382
7285
  }
7383
7286
  // add tracking for the new argument
7384
- const newValue = argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this);
7287
+ const newValue = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
7385
7288
  if (newValue !== oldValue) {
7386
7289
  this.markReassigned();
7387
7290
  }
@@ -7399,31 +7302,24 @@ class ParameterVariable extends LocalVariable {
7399
7302
  return this.frozenValue;
7400
7303
  }
7401
7304
  getLiteralValueAtPath(path, recursionTracker, origin) {
7402
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
7305
+ if (this.isReassigned) {
7403
7306
  return UnknownValue;
7404
7307
  }
7405
7308
  const knownValue = this.getKnownValue();
7406
- this.expressionsDependingOnKnownValue.push(origin);
7407
- return recursionTracker.withTrackedEntityAtPath(path, knownValue, () => knownValue.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin), UnknownValue);
7309
+ this.expressionsUseTheKnownValue.push(origin);
7310
+ return recursionTracker.withTrackedEntityAtPath(path, knownValue, () => knownValue.getLiteralValueAtPath(path, recursionTracker, origin), UnknownValue);
7408
7311
  }
7409
7312
  hasEffectsOnInteractionAtPath(path, interaction, context) {
7410
- const { type } = interaction;
7411
- if (this.isReassigned ||
7412
- type === INTERACTION_ASSIGNED ||
7413
- path.length + this.initPath.length > MAX_PATH_DEPTH) {
7313
+ if (this.isReassigned || interaction.type === INTERACTION_ASSIGNED) {
7414
7314
  return super.hasEffectsOnInteractionAtPath(path, interaction, context);
7415
7315
  }
7416
- return (!(type === INTERACTION_CALLED
7417
- ? (interaction.withNew
7418
- ? context.instantiated
7419
- : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this)
7420
- : context.accessed.trackEntityAtPathAndGetIfTracked(path, this)) &&
7421
- this.getKnownValue().hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
7316
+ const knownValue = this.getKnownValue();
7317
+ return knownValue.hasEffectsOnInteractionAtPath(path, interaction, context);
7422
7318
  }
7423
7319
  deoptimizeArgumentsOnInteractionAtPath(interaction, path) {
7424
7320
  // For performance reasons, we fully deoptimize all deeper interactions
7425
7321
  if (path.length >= 2 ||
7426
- this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
7322
+ this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
7427
7323
  this.deoptimizationInteractions.length >= MAX_TRACKED_INTERACTIONS ||
7428
7324
  (path.length === 1 &&
7429
7325
  (this.deoptimizedFields.has(UnknownKey) ||
@@ -7432,10 +7328,10 @@ class ParameterVariable extends LocalVariable {
7432
7328
  return;
7433
7329
  }
7434
7330
  if (!this.deoptimizations.trackEntityAtPathAndGetIfTracked(path, interaction.args)) {
7435
- for (const entity of this.argumentsToBeDeoptimized) {
7436
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
7331
+ for (const entity of this.entitiesToBeDeoptimized) {
7332
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
7437
7333
  }
7438
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7334
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7439
7335
  this.deoptimizationInteractions.push({
7440
7336
  interaction,
7441
7337
  path
@@ -7456,17 +7352,17 @@ class ParameterVariable extends LocalVariable {
7456
7352
  return;
7457
7353
  }
7458
7354
  this.deoptimizedFields.add(key);
7459
- for (const entity of this.argumentsToBeDeoptimized) {
7355
+ for (const entity of this.entitiesToBeDeoptimized) {
7460
7356
  // We do not need a recursion tracker here as we already track whether
7461
7357
  // this field is deoptimized
7462
- entity.deoptimizePath([...this.initPath, key]);
7358
+ entity.deoptimizePath([key]);
7463
7359
  }
7464
7360
  if (key === UnknownKey) {
7465
7361
  // save some memory
7466
7362
  this.deoptimizationInteractions = NO_INTERACTIONS;
7467
7363
  this.deoptimizations = EMPTY_PATH_TRACKER;
7468
7364
  this.deoptimizedFields = UNKNOWN_DEOPTIMIZED_FIELD;
7469
- this.argumentsToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
7365
+ this.entitiesToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
7470
7366
  }
7471
7367
  }
7472
7368
  getReturnExpressionWhenCalledAtPath(path) {
@@ -7481,14 +7377,11 @@ class ParameterVariable extends LocalVariable {
7481
7377
  }
7482
7378
  return UNKNOWN_RETURN_EXPRESSION;
7483
7379
  }
7484
- includeArgumentPaths(entity, context) {
7485
- this.includedPathTracker.includeAllPaths(entity, context, this.initPath);
7486
- }
7487
7380
  }
7488
7381
 
7489
7382
  class ThisVariable extends ParameterVariable {
7490
7383
  constructor(context) {
7491
- super('this', null, EMPTY_PATH, context);
7384
+ super('this', null, context);
7492
7385
  }
7493
7386
  hasEffectsOnInteractionAtPath(path, interaction, context) {
7494
7387
  return (context.replacedVariableInits.get(this) || UNKNOWN_EXPRESSION).hasEffectsOnInteractionAtPath(path, interaction, context);
@@ -7500,7 +7393,7 @@ class CatchBodyScope extends ChildScope {
7500
7393
  super(parent, parent.context);
7501
7394
  this.parent = parent;
7502
7395
  }
7503
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
7396
+ addDeclaration(identifier, context, init, kind) {
7504
7397
  if (kind === 'var') {
7505
7398
  const name = identifier.name;
7506
7399
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -7513,7 +7406,7 @@ class CatchBodyScope extends ChildScope {
7513
7406
  // the assignment actually goes to the parameter and the var is
7514
7407
  // hoisted without assignment. Locally, it is shadowed by the
7515
7408
  // parameter
7516
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, destructuredInitPath, kind);
7409
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, kind);
7517
7410
  // To avoid the need to rewrite the declaration, we link the variable
7518
7411
  // names. If we ever implement a logic that splits initialization and
7519
7412
  // assignment for hoisted vars, the "renderLikeHoisted" logic can be
@@ -7532,7 +7425,7 @@ class CatchBodyScope extends ChildScope {
7532
7425
  return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7533
7426
  }
7534
7427
  // We only add parameters to parameter scopes
7535
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
7428
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, kind);
7536
7429
  // Necessary to make sure the init is deoptimized for conditional declarations.
7537
7430
  // We cannot call deoptimizePath here.
7538
7431
  declaredVariable.markInitializersForDeoptimization();
@@ -7540,7 +7433,7 @@ class CatchBodyScope extends ChildScope {
7540
7433
  this.addHoistedVariable(name, declaredVariable);
7541
7434
  return declaredVariable;
7542
7435
  }
7543
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
7436
+ return super.addDeclaration(identifier, context, init, kind);
7544
7437
  }
7545
7438
  }
7546
7439
 
@@ -7550,7 +7443,7 @@ class FunctionBodyScope extends ChildScope {
7550
7443
  }
7551
7444
  // There is stuff that is only allowed in function scopes, i.e. functions can
7552
7445
  // be redeclared, functions and var can redeclare each other
7553
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
7446
+ addDeclaration(identifier, context, init, kind) {
7554
7447
  const name = identifier.name;
7555
7448
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
7556
7449
  if (existingVariable) {
@@ -7562,7 +7455,7 @@ class FunctionBodyScope extends ChildScope {
7562
7455
  }
7563
7456
  context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7564
7457
  }
7565
- const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
7458
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
7566
7459
  this.variables.set(name, newVariable);
7567
7460
  return newVariable;
7568
7461
  }
@@ -7571,21 +7464,21 @@ class FunctionBodyScope extends ChildScope {
7571
7464
  class ParameterScope extends ChildScope {
7572
7465
  constructor(parent, isCatchScope) {
7573
7466
  super(parent, parent.context);
7574
- this.hasRest = false;
7575
7467
  this.parameters = [];
7468
+ this.hasRest = false;
7576
7469
  this.bodyScope = isCatchScope ? new CatchBodyScope(this) : new FunctionBodyScope(this);
7577
7470
  }
7578
7471
  /**
7579
7472
  * Adds a parameter to this scope. Parameters must be added in the correct
7580
7473
  * order, i.e. from left to right.
7581
7474
  */
7582
- addParameterDeclaration(identifier, argumentPath) {
7475
+ addParameterDeclaration(identifier) {
7583
7476
  const { name, start } = identifier;
7584
7477
  const existingParameter = this.variables.get(name);
7585
7478
  if (existingParameter) {
7586
7479
  return this.context.error(parseAst_js.logDuplicateArgumentNameError(name), start);
7587
7480
  }
7588
- const variable = new ParameterVariable(name, identifier, argumentPath, this.context);
7481
+ const variable = new ParameterVariable(name, identifier, this.context);
7589
7482
  this.variables.set(name, variable);
7590
7483
  // We also add it to the body scope to detect name conflicts with local
7591
7484
  // variables. We still need the intermediate scope, though, as parameter
@@ -7603,54 +7496,43 @@ class ParameterScope extends ChildScope {
7603
7496
  }
7604
7497
  this.hasRest = hasRest;
7605
7498
  }
7606
- includeCallArguments(context, interaction) {
7499
+ includeCallArguments(context, parameters) {
7607
7500
  let calledFromTryStatement = false;
7608
7501
  let argumentIncluded = false;
7609
7502
  const restParameter = this.hasRest && this.parameters[this.parameters.length - 1];
7610
- const { args } = interaction;
7611
- let lastExplicitlyIncludedIndex = args.length - 1;
7612
- // If there is a SpreadElement, we need to include all arguments after it
7613
- // because we no longer know which argument corresponds to which parameter.
7614
- for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
7615
- if (args[argumentIndex] instanceof SpreadElement && !argumentIncluded) {
7616
- argumentIncluded = true;
7617
- lastExplicitlyIncludedIndex = argumentIndex - 1;
7618
- }
7619
- if (argumentIncluded) {
7620
- args[argumentIndex].includePath(UNKNOWN_PATH, context, false);
7503
+ for (const checkedArgument of parameters) {
7504
+ if (checkedArgument instanceof SpreadElement) {
7505
+ for (const argument of parameters) {
7506
+ argument.include(context, false);
7507
+ }
7508
+ break;
7621
7509
  }
7622
7510
  }
7623
- // Now we go backwards either starting from the last argument or before the
7624
- // first SpreadElement to ensure all arguments before are included as needed
7625
- for (let index = lastExplicitlyIncludedIndex; index >= 1; index--) {
7626
- const parameterVariables = this.parameters[index - 1] || restParameter;
7627
- const argument = args[index];
7511
+ for (let index = parameters.length - 1; index >= 0; index--) {
7512
+ const parameterVariables = this.parameters[index] || restParameter;
7513
+ const argument = parameters[index];
7628
7514
  if (parameterVariables) {
7629
7515
  calledFromTryStatement = false;
7630
7516
  if (parameterVariables.length === 0) {
7631
- // handle empty destructuring to avoid destructuring undefined
7517
+ // handle empty destructuring
7632
7518
  argumentIncluded = true;
7633
7519
  }
7634
7520
  else {
7635
7521
  for (const variable of parameterVariables) {
7636
- if (variable.calledFromTryStatement) {
7637
- calledFromTryStatement = true;
7638
- }
7639
7522
  if (variable.included) {
7640
7523
  argumentIncluded = true;
7641
- if (calledFromTryStatement) {
7642
- argument.includePath(UNKNOWN_PATH, context, true);
7643
- }
7644
- else {
7645
- variable.includeArgumentPaths(argument, context);
7646
- }
7524
+ }
7525
+ if (variable.calledFromTryStatement) {
7526
+ calledFromTryStatement = true;
7647
7527
  }
7648
7528
  }
7649
7529
  }
7650
7530
  }
7651
- if (!argument.included && (argumentIncluded || argument.shouldBeIncluded(context))) {
7531
+ if (!argumentIncluded && argument.shouldBeIncluded(context)) {
7652
7532
  argumentIncluded = true;
7653
- argument.includePath(EMPTY_PATH, context, calledFromTryStatement);
7533
+ }
7534
+ if (argumentIncluded) {
7535
+ argument.include(context, calledFromTryStatement);
7654
7536
  }
7655
7537
  }
7656
7538
  }
@@ -7665,61 +7547,11 @@ class ReturnValueScope extends ParameterScope {
7665
7547
  addReturnExpression(expression) {
7666
7548
  this.returnExpressions.push(expression);
7667
7549
  }
7668
- deoptimizeArgumentsOnCall(interaction) {
7669
- const { parameters } = this;
7670
- const { args } = interaction;
7671
- let position = 0;
7672
- for (; position < args.length - 1; position++) {
7673
- // Only the "this" argument arg[0] can be null
7674
- const argument = args[position + 1];
7675
- if (argument instanceof SpreadElement) {
7676
- // This deoptimizes the current and remaining parameters and arguments
7677
- for (; position < parameters.length; position++) {
7678
- args[position + 1]?.deoptimizePath(UNKNOWN_PATH);
7679
- parameters[position].forEach(variable => variable.markReassigned());
7680
- }
7681
- break;
7682
- }
7683
- if (this.hasRest && position >= parameters.length - 1) {
7684
- argument.deoptimizePath(UNKNOWN_PATH);
7685
- }
7686
- else {
7687
- const variables = parameters[position];
7688
- if (variables) {
7689
- for (const variable of variables) {
7690
- variable.addArgumentValue(argument);
7691
- }
7692
- }
7693
- this.addArgumentToBeDeoptimized(argument);
7694
- }
7695
- }
7696
- for (; position < parameters.length; position++) {
7697
- for (const variable of parameters[position]) {
7698
- variable.addArgumentValue(UNDEFINED_EXPRESSION);
7699
- }
7700
- }
7701
- }
7702
7550
  getReturnExpression() {
7703
7551
  if (this.returnExpression === null)
7704
7552
  this.updateReturnExpression();
7705
7553
  return this.returnExpression;
7706
7554
  }
7707
- deoptimizeAllParameters() {
7708
- for (const parameter of this.parameters) {
7709
- for (const variable of parameter) {
7710
- variable.deoptimizePath(UNKNOWN_PATH);
7711
- variable.markReassigned();
7712
- }
7713
- }
7714
- }
7715
- reassignAllParameters() {
7716
- for (const parameter of this.parameters) {
7717
- for (const variable of parameter) {
7718
- variable.markReassigned();
7719
- }
7720
- }
7721
- }
7722
- addArgumentToBeDeoptimized(_argument) { }
7723
7555
  updateReturnExpression() {
7724
7556
  if (this.returnExpressions.length === 1) {
7725
7557
  this.returnExpression = this.returnExpressions[0];
@@ -7735,26 +7567,24 @@ class ReturnValueScope extends ParameterScope {
7735
7567
 
7736
7568
  class FunctionScope extends ReturnValueScope {
7737
7569
  constructor(parent) {
7738
- super(parent, false);
7739
7570
  const { context } = parent;
7571
+ super(parent, false);
7740
7572
  this.variables.set('arguments', (this.argumentsVariable = new ArgumentsVariable(context)));
7741
7573
  this.variables.set('this', (this.thisVariable = new ThisVariable(context)));
7742
7574
  }
7743
7575
  findLexicalBoundary() {
7744
7576
  return this;
7745
7577
  }
7746
- includeCallArguments(context, interaction) {
7747
- super.includeCallArguments(context, interaction);
7578
+ includeCallArguments(context, parameters) {
7579
+ super.includeCallArguments(context, parameters);
7748
7580
  if (this.argumentsVariable.included) {
7749
- const { args } = interaction;
7750
- for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
7751
- args[argumentIndex]?.includePath(UNKNOWN_PATH, context, false);
7581
+ for (const argument of parameters) {
7582
+ if (!argument.included) {
7583
+ argument.include(context, false);
7584
+ }
7752
7585
  }
7753
7586
  }
7754
7587
  }
7755
- addArgumentToBeDeoptimized(argument) {
7756
- this.argumentsVariable.addArgumentToBeDeoptimized(argument);
7757
- }
7758
7588
  }
7759
7589
 
7760
7590
  class ExpressionStatement extends NodeBase {
@@ -7820,7 +7650,7 @@ class BlockStatement extends NodeBase {
7820
7650
  }
7821
7651
  return false;
7822
7652
  }
7823
- includePath(_path, context, includeChildrenRecursively) {
7653
+ include(context, includeChildrenRecursively) {
7824
7654
  if (!(this.deoptimizeBody && this.directlyIncluded)) {
7825
7655
  this.included = true;
7826
7656
  this.directlyIncluded = true;
@@ -7828,7 +7658,7 @@ class BlockStatement extends NodeBase {
7828
7658
  includeChildrenRecursively = true;
7829
7659
  for (const node of this.body) {
7830
7660
  if (includeChildrenRecursively || node.shouldBeIncluded(context))
7831
- node.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
7661
+ node.include(context, includeChildrenRecursively);
7832
7662
  }
7833
7663
  }
7834
7664
  }
@@ -7857,12 +7687,9 @@ class RestElement extends NodeBase {
7857
7687
  addExportedVariables(variables, exportNamesByVariable) {
7858
7688
  this.argument.addExportedVariables(variables, exportNamesByVariable);
7859
7689
  }
7860
- declare(kind, destructuredInitPath, init) {
7690
+ declare(kind, init) {
7861
7691
  this.declarationInit = init;
7862
- return this.argument.declare(kind, getIncludedPatternPath$1(destructuredInitPath), init);
7863
- }
7864
- deoptimizeAssignment(destructuredInitPath, init) {
7865
- this.argument.deoptimizeAssignment(getIncludedPatternPath$1(destructuredInitPath), init);
7692
+ return this.argument.declare(kind, UNKNOWN_EXPRESSION);
7866
7693
  }
7867
7694
  deoptimizePath(path) {
7868
7695
  if (path.length === 0) {
@@ -7873,19 +7700,6 @@ class RestElement extends NodeBase {
7873
7700
  return (path.length > 0 ||
7874
7701
  this.argument.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
7875
7702
  }
7876
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
7877
- return this.argument.hasEffectsWhenDestructuring(context, getIncludedPatternPath$1(destructuredInitPath), init);
7878
- }
7879
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
7880
- return (this.included =
7881
- this.argument.includeDestructuredIfNecessary(context, getIncludedPatternPath$1(destructuredInitPath), init) || this.included);
7882
- }
7883
- includePath(_path, context, includeChildrenRecursively) {
7884
- this.included = true;
7885
- // This should just include the identifier, its properties should be
7886
- // included where the variable is used.
7887
- this.argument.includePath(EMPTY_PATH, context, includeChildrenRecursively);
7888
- }
7889
7703
  markDeclarationReached() {
7890
7704
  this.argument.markDeclarationReached();
7891
7705
  }
@@ -7897,15 +7711,12 @@ class RestElement extends NodeBase {
7897
7711
  }
7898
7712
  }
7899
7713
  }
7900
- const getIncludedPatternPath$1 = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
7901
- ? destructuredInitPath
7902
- : [...destructuredInitPath, UnknownKey];
7903
7714
 
7904
7715
  class FunctionBase extends NodeBase {
7905
7716
  constructor() {
7906
7717
  super(...arguments);
7718
+ this.objectEntity = null;
7907
7719
  this.parameterVariableValuesDeoptimized = false;
7908
- this.includeCallArguments = this.scope.includeCallArguments.bind(this.scope);
7909
7720
  }
7910
7721
  get async() {
7911
7722
  return isFlagSet(this.flags, 256 /* Flag.async */);
@@ -7925,9 +7736,53 @@ class FunctionBase extends NodeBase {
7925
7736
  set generator(value) {
7926
7737
  this.flags = setFlag(this.flags, 4194304 /* Flag.generator */, value);
7927
7738
  }
7739
+ updateParameterVariableValues(_arguments) {
7740
+ for (let position = 0; position < this.params.length; position++) {
7741
+ const parameter = this.params[position];
7742
+ if (!(parameter instanceof Identifier)) {
7743
+ continue;
7744
+ }
7745
+ const parameterVariable = parameter.variable;
7746
+ const argument = _arguments[position + 1] ?? UNDEFINED_EXPRESSION;
7747
+ parameterVariable.updateKnownValue(argument);
7748
+ }
7749
+ }
7750
+ deoptimizeParameterVariableValues() {
7751
+ for (const parameter of this.params) {
7752
+ if (parameter instanceof Identifier) {
7753
+ const parameterVariable = parameter.variable;
7754
+ parameterVariable.markReassigned();
7755
+ }
7756
+ }
7757
+ }
7928
7758
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
7929
- if (interaction.type === INTERACTION_CALLED && path.length === 0) {
7930
- this.scope.deoptimizeArgumentsOnCall(interaction);
7759
+ if (interaction.type === INTERACTION_CALLED) {
7760
+ const { parameters } = this.scope;
7761
+ const { args } = interaction;
7762
+ let hasRest = false;
7763
+ for (let position = 0; position < args.length - 1; position++) {
7764
+ const parameter = this.params[position];
7765
+ // Only the "this" argument arg[0] can be null
7766
+ const argument = args[position + 1];
7767
+ if (argument instanceof SpreadElement) {
7768
+ this.deoptimizeParameterVariableValues();
7769
+ }
7770
+ if (hasRest || parameter instanceof RestElement) {
7771
+ hasRest = true;
7772
+ argument.deoptimizePath(UNKNOWN_PATH);
7773
+ }
7774
+ else if (parameter instanceof Identifier) {
7775
+ parameters[position][0].addEntityToBeDeoptimized(argument);
7776
+ this.addArgumentToBeDeoptimized(argument);
7777
+ }
7778
+ else if (parameter) {
7779
+ argument.deoptimizePath(UNKNOWN_PATH);
7780
+ }
7781
+ else {
7782
+ this.addArgumentToBeDeoptimized(argument);
7783
+ }
7784
+ }
7785
+ this.updateParameterVariableValues(args);
7931
7786
  }
7932
7787
  else {
7933
7788
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -7939,7 +7794,12 @@ class FunctionBase extends NodeBase {
7939
7794
  // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
7940
7795
  // which means the return expression and parameters need to be reassigned
7941
7796
  this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
7942
- this.scope.deoptimizeAllParameters();
7797
+ for (const parameterList of this.scope.parameters) {
7798
+ for (const parameter of parameterList) {
7799
+ parameter.deoptimizePath(UNKNOWN_PATH);
7800
+ parameter.markReassigned();
7801
+ }
7802
+ }
7943
7803
  }
7944
7804
  }
7945
7805
  getLiteralValueAtPath(path, recursionTracker, origin) {
@@ -7977,13 +7837,8 @@ class FunctionBase extends NodeBase {
7977
7837
  return true;
7978
7838
  }
7979
7839
  }
7980
- const { propertyReadSideEffects } = this.scope.context.options
7981
- .treeshake;
7982
- for (let index = 0; index < this.params.length; index++) {
7983
- const parameter = this.params[index];
7984
- if (parameter.hasEffects(context) ||
7985
- (propertyReadSideEffects &&
7986
- parameter.hasEffectsWhenDestructuring(context, EMPTY_PATH, interaction.args[index + 1] || UNDEFINED_EXPRESSION)))
7840
+ for (const parameter of this.params) {
7841
+ if (parameter.hasEffects(context))
7987
7842
  return true;
7988
7843
  }
7989
7844
  return false;
@@ -8001,19 +7856,22 @@ class FunctionBase extends NodeBase {
8001
7856
  }
8002
7857
  return variable?.getOnlyFunctionCallUsed() ?? false;
8003
7858
  }
8004
- includePath(_path, context, includeChildrenRecursively) {
8005
- if (!(this.parameterVariableValuesDeoptimized || this.onlyFunctionCallUsed())) {
7859
+ include(context, includeChildrenRecursively) {
7860
+ if (!this.parameterVariableValuesDeoptimized && !this.onlyFunctionCallUsed()) {
8006
7861
  this.parameterVariableValuesDeoptimized = true;
8007
- this.scope.reassignAllParameters();
7862
+ this.deoptimizeParameterVariableValues();
8008
7863
  }
8009
7864
  if (!this.deoptimized)
8010
7865
  this.applyDeoptimizations();
8011
7866
  this.included = true;
8012
7867
  const { brokenFlow } = context;
8013
7868
  context.brokenFlow = false;
8014
- this.body.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
7869
+ this.body.include(context, includeChildrenRecursively);
8015
7870
  context.brokenFlow = brokenFlow;
8016
7871
  }
7872
+ includeCallArguments(context, parameters) {
7873
+ this.scope.includeCallArguments(context, parameters);
7874
+ }
8017
7875
  initialise() {
8018
7876
  super.initialise();
8019
7877
  if (this.body instanceof BlockStatement) {
@@ -8035,10 +7893,11 @@ class FunctionBase extends NodeBase {
8035
7893
  // so that the scope already knows all parameters and can detect conflicts
8036
7894
  // when parsing the body.
8037
7895
  const parameters = (this.params = params.map((parameter) => new (context.getNodeConstructor(parameter.type))(this, scope).parseNode(parameter)));
8038
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
7896
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
8039
7897
  this.body = new (context.getNodeConstructor(body.type))(this, bodyScope).parseNode(body);
8040
7898
  return super.parseNode(esTreeNode);
8041
7899
  }
7900
+ addArgumentToBeDeoptimized(_argument) { }
8042
7901
  applyDeoptimizations() { }
8043
7902
  }
8044
7903
  FunctionBase.prototype.preventChildBlockScope = true;
@@ -8053,13 +7912,13 @@ class FunctionNode extends FunctionBase {
8053
7912
  this.constructedEntity = new ObjectEntity(Object.create(null), OBJECT_PROTOTYPE);
8054
7913
  // This makes sure that all deoptimizations of "this" are applied to the
8055
7914
  // constructed entity.
8056
- this.scope.thisVariable.addArgumentValue(this.constructedEntity);
7915
+ this.scope.thisVariable.addEntityToBeDeoptimized(this.constructedEntity);
8057
7916
  }
8058
7917
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
8059
7918
  super.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
8060
7919
  if (interaction.type === INTERACTION_CALLED && path.length === 0 && interaction.args[0]) {
8061
7920
  // args[0] is the "this" argument
8062
- this.scope.thisVariable.addArgumentValue(interaction.args[0]);
7921
+ this.scope.thisVariable.addEntityToBeDeoptimized(interaction.args[0]);
8063
7922
  }
8064
7923
  }
8065
7924
  hasEffects(context) {
@@ -8100,19 +7959,22 @@ class FunctionNode extends FunctionBase {
8100
7959
  }
8101
7960
  return false;
8102
7961
  }
8103
- includePath(path, context, includeChildrenRecursively) {
8104
- super.includePath(path, context, includeChildrenRecursively);
8105
- this.id?.includePath(UNKNOWN_PATH, createInclusionContext());
7962
+ include(context, includeChildrenRecursively) {
7963
+ super.include(context, includeChildrenRecursively);
7964
+ this.id?.include();
8106
7965
  const hasArguments = this.scope.argumentsVariable.included;
8107
7966
  for (const parameter of this.params) {
8108
7967
  if (!(parameter instanceof Identifier) || hasArguments) {
8109
- parameter.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
7968
+ parameter.include(context, includeChildrenRecursively);
8110
7969
  }
8111
7970
  }
8112
7971
  }
8113
7972
  initialise() {
8114
7973
  super.initialise();
8115
- this.id?.declare('function', EMPTY_PATH, this);
7974
+ this.id?.declare('function', this);
7975
+ }
7976
+ addArgumentToBeDeoptimized(argument) {
7977
+ this.scope.argumentsVariable.addArgumentToBeDeoptimized(argument);
8116
7978
  }
8117
7979
  getObjectEntity() {
8118
7980
  if (this.objectEntity !== null) {
@@ -8161,11 +8023,10 @@ function getFunctionIdInsertPosition(code, start) {
8161
8023
  return declarationEnd + generatorStarPos + 1;
8162
8024
  }
8163
8025
  class ExportDefaultDeclaration extends NodeBase {
8164
- includePath(path, context, includeChildrenRecursively) {
8165
- this.included = true;
8166
- this.declaration.includePath(path, context, includeChildrenRecursively);
8026
+ include(context, includeChildrenRecursively) {
8027
+ super.include(context, includeChildrenRecursively);
8167
8028
  if (includeChildrenRecursively) {
8168
- this.scope.context.includeVariableInModule(this.variable, path);
8029
+ this.scope.context.includeVariableInModule(this.variable);
8169
8030
  }
8170
8031
  }
8171
8032
  initialise() {
@@ -8527,6 +8388,8 @@ function getChainElementLiteralValueAtPath(element, object, path, recursionTrack
8527
8388
  return element.getLiteralValueAtPath(path, recursionTracker, origin);
8528
8389
  }
8529
8390
 
8391
+ // To avoid infinite recursions
8392
+ const MAX_PATH_DEPTH = 7;
8530
8393
  function getResolvablePropertyKey(memberExpression) {
8531
8394
  return memberExpression.computed
8532
8395
  ? getResolvableComputedPropertyKey(memberExpression.property)
@@ -8632,10 +8495,6 @@ class MemberExpression extends NodeBase {
8632
8495
  }
8633
8496
  }
8634
8497
  }
8635
- deoptimizeAssignment(destructuredInitPath, init) {
8636
- this.deoptimizePath(EMPTY_PATH);
8637
- init.deoptimizePath([...destructuredInitPath, UnknownKey]);
8638
- }
8639
8498
  deoptimizeCache() {
8640
8499
  const { expressionsToBeDeoptimized, object } = this;
8641
8500
  this.expressionsToBeDeoptimized = parseAst_js.EMPTY_ARRAY;
@@ -8651,13 +8510,11 @@ class MemberExpression extends NodeBase {
8651
8510
  if (this.variable) {
8652
8511
  this.variable.deoptimizePath(path);
8653
8512
  }
8654
- else if (!this.isUndefined) {
8513
+ else if (!this.isUndefined && path.length < MAX_PATH_DEPTH) {
8655
8514
  const propertyKey = this.getPropertyKey();
8656
8515
  this.object.deoptimizePath([
8657
8516
  propertyKey === UnknownKey ? UnknownNonAccessorKey : propertyKey,
8658
- ...(path.length < MAX_PATH_DEPTH
8659
- ? path
8660
- : [...path.slice(0, MAX_PATH_DEPTH), UnknownKey])
8517
+ ...path
8661
8518
  ]);
8662
8519
  }
8663
8520
  }
@@ -8742,47 +8599,28 @@ class MemberExpression extends NodeBase {
8742
8599
  }
8743
8600
  return true;
8744
8601
  }
8745
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
8746
- return (destructuredInitPath.length > 0 &&
8747
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, context));
8748
- }
8749
- includePath(path, context, includeChildrenRecursively) {
8602
+ include(context, includeChildrenRecursively) {
8750
8603
  if (!this.deoptimized)
8751
8604
  this.applyDeoptimizations();
8752
- this.includeProperties(path, [
8753
- this.getPropertyKey(),
8754
- ...(path.length < MAX_PATH_DEPTH
8755
- ? path
8756
- : [...path.slice(0, MAX_PATH_DEPTH), UnknownKey])
8757
- ], context, includeChildrenRecursively);
8605
+ this.includeProperties(context, includeChildrenRecursively);
8758
8606
  }
8759
8607
  includeAsAssignmentTarget(context, includeChildrenRecursively, deoptimizeAccess) {
8760
8608
  if (!this.assignmentDeoptimized)
8761
8609
  this.applyAssignmentDeoptimization();
8762
8610
  if (deoptimizeAccess) {
8763
- this.includePath([this.getPropertyKey()], context, includeChildrenRecursively);
8611
+ this.include(context, includeChildrenRecursively);
8764
8612
  }
8765
8613
  else {
8766
- this.includeProperties(EMPTY_PATH, [this.getPropertyKey()], context, includeChildrenRecursively);
8614
+ this.includeProperties(context, includeChildrenRecursively);
8767
8615
  }
8768
8616
  }
8769
- includeCallArguments(context, interaction) {
8617
+ includeCallArguments(context, parameters) {
8770
8618
  if (this.variable) {
8771
- this.variable.includeCallArguments(context, interaction);
8619
+ this.variable.includeCallArguments(context, parameters);
8772
8620
  }
8773
8621
  else {
8774
- super.includeCallArguments(context, interaction);
8775
- }
8776
- }
8777
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
8778
- if ((this.included ||=
8779
- destructuredInitPath.length > 0 &&
8780
- !context.brokenFlow &&
8781
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, createHasEffectsContext()))) {
8782
- init.includePath(destructuredInitPath, context, false);
8783
- return true;
8622
+ super.includeCallArguments(context, parameters);
8784
8623
  }
8785
- return false;
8786
8624
  }
8787
8625
  initialise() {
8788
8626
  super.initialise();
@@ -8850,7 +8688,7 @@ class MemberExpression extends NodeBase {
8850
8688
  const variable = this.scope.findVariable(this.object.name);
8851
8689
  if (variable.isNamespace) {
8852
8690
  if (this.variable) {
8853
- this.scope.context.includeVariableInModule(this.variable, UNKNOWN_PATH);
8691
+ this.scope.context.includeVariableInModule(this.variable);
8854
8692
  }
8855
8693
  this.scope.context.log(parseAst_js.LOGLEVEL_WARN, parseAst_js.logIllegalImportReassignment(this.object.name, this.scope.context.module.id), this.start);
8856
8694
  }
@@ -8877,18 +8715,15 @@ class MemberExpression extends NodeBase {
8877
8715
  (propertyReadSideEffects === 'always' ||
8878
8716
  this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey()], this.accessInteraction, context)));
8879
8717
  }
8880
- includeProperties(includedPath, objectPath, context, includeChildrenRecursively) {
8718
+ includeProperties(context, includeChildrenRecursively) {
8881
8719
  if (!this.included) {
8882
8720
  this.included = true;
8883
8721
  if (this.variable) {
8884
- this.scope.context.includeVariableInModule(this.variable, includedPath);
8722
+ this.scope.context.includeVariableInModule(this.variable);
8885
8723
  }
8886
8724
  }
8887
- else if (includedPath.length > 0) {
8888
- this.variable?.includePath(includedPath, context);
8889
- }
8890
- this.object.includePath(objectPath, context, includeChildrenRecursively);
8891
- this.property.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
8725
+ this.object.include(context, includeChildrenRecursively);
8726
+ this.property.include(context, includeChildrenRecursively);
8892
8727
  }
8893
8728
  }
8894
8729
  function resolveNamespaceVariables(baseVariable, path, astContext) {
@@ -8931,7 +8766,7 @@ class MetaProperty extends NodeBase {
8931
8766
  hasEffectsOnInteractionAtPath(path, { type }) {
8932
8767
  return path.length > 1 || type !== INTERACTION_ACCESSED;
8933
8768
  }
8934
- includePath() {
8769
+ include() {
8935
8770
  if (!this.included) {
8936
8771
  this.included = true;
8937
8772
  if (this.meta.name === IMPORT) {
@@ -9050,7 +8885,7 @@ class UndefinedVariable extends Variable {
9050
8885
 
9051
8886
  class ExportDefaultVariable extends LocalVariable {
9052
8887
  constructor(name, exportDefaultDeclaration, context) {
9053
- super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, EMPTY_PATH, context, 'other');
8888
+ super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context, 'other');
9054
8889
  this.hasId = false;
9055
8890
  this.originalId = null;
9056
8891
  this.originalVariable = null;
@@ -9199,8 +9034,8 @@ class NamespaceVariable extends Variable {
9199
9034
  return (!memberVariable ||
9200
9035
  memberVariable.hasEffectsOnInteractionAtPath(path.slice(1), interaction, context));
9201
9036
  }
9202
- includePath(path, context) {
9203
- super.includePath(path, context);
9037
+ include() {
9038
+ super.include();
9204
9039
  this.context.includeAllExports();
9205
9040
  }
9206
9041
  prepare(accessedGlobalsByScope) {
@@ -9293,9 +9128,9 @@ class SyntheticNamedExportVariable extends Variable {
9293
9128
  getName(getPropertyAccess) {
9294
9129
  return `${this.syntheticNamespace.getName(getPropertyAccess)}${getPropertyAccess(this.name)}`;
9295
9130
  }
9296
- includePath(path, context) {
9297
- super.includePath(path, context);
9298
- this.context.includeVariableInModule(this.syntheticNamespace, path);
9131
+ include() {
9132
+ super.include();
9133
+ this.context.includeVariableInModule(this.syntheticNamespace);
9299
9134
  }
9300
9135
  setRenderNames(baseName, name) {
9301
9136
  super.setRenderNames(baseName, name);
@@ -12494,37 +12329,21 @@ class ArrayPattern extends NodeBase {
12494
12329
  element?.addExportedVariables(variables, exportNamesByVariable);
12495
12330
  }
12496
12331
  }
12497
- declare(kind, destructuredInitPath, init) {
12332
+ declare(kind) {
12498
12333
  const variables = [];
12499
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12500
12334
  for (const element of this.elements) {
12501
12335
  if (element !== null) {
12502
- variables.push(...element.declare(kind, includedPatternPath, init));
12336
+ variables.push(...element.declare(kind, UNKNOWN_EXPRESSION));
12503
12337
  }
12504
12338
  }
12505
12339
  return variables;
12506
12340
  }
12507
- deoptimizeAssignment(destructuredInitPath, init) {
12508
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12509
- for (const element of this.elements) {
12510
- element?.deoptimizeAssignment(includedPatternPath, init);
12511
- }
12512
- }
12513
12341
  // Patterns can only be deoptimized at the empty path at the moment
12514
12342
  deoptimizePath() {
12515
12343
  for (const element of this.elements) {
12516
12344
  element?.deoptimizePath(EMPTY_PATH);
12517
12345
  }
12518
12346
  }
12519
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
12520
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12521
- for (const element of this.elements) {
12522
- if (element?.hasEffectsWhenDestructuring(context, includedPatternPath, init)) {
12523
- return true;
12524
- }
12525
- }
12526
- return false;
12527
- }
12528
12347
  // Patterns are only checked at the empty path at the moment
12529
12348
  hasEffectsOnInteractionAtPath(_path, interaction, context) {
12530
12349
  for (const element of this.elements) {
@@ -12533,37 +12352,12 @@ class ArrayPattern extends NodeBase {
12533
12352
  }
12534
12353
  return false;
12535
12354
  }
12536
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
12537
- let included = false;
12538
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12539
- for (const element of this.elements) {
12540
- if (element) {
12541
- element.included ||= included;
12542
- included =
12543
- element.includeDestructuredIfNecessary(context, includedPatternPath, init) || included;
12544
- }
12545
- }
12546
- if (included) {
12547
- // This is necessary so that if any pattern element is included, all are
12548
- // included for proper deconflicting
12549
- for (const element of this.elements) {
12550
- if (element && !element.included) {
12551
- element.included = true;
12552
- element.includeDestructuredIfNecessary(context, includedPatternPath, init);
12553
- }
12554
- }
12555
- }
12556
- return (this.included ||= included);
12557
- }
12558
12355
  markDeclarationReached() {
12559
12356
  for (const element of this.elements) {
12560
12357
  element?.markDeclarationReached();
12561
12358
  }
12562
12359
  }
12563
12360
  }
12564
- const getIncludedPatternPath = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
12565
- ? destructuredInitPath
12566
- : [...destructuredInitPath, UnknownInteger];
12567
12361
 
12568
12362
  class ArrowFunctionExpression extends FunctionBase {
12569
12363
  constructor() {
@@ -12612,11 +12406,11 @@ class ArrowFunctionExpression extends FunctionBase {
12612
12406
  this.parent.callee === this;
12613
12407
  return isIIFE || super.onlyFunctionCallUsed();
12614
12408
  }
12615
- includePath(_path, context, includeChildrenRecursively) {
12616
- super.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12409
+ include(context, includeChildrenRecursively) {
12410
+ super.include(context, includeChildrenRecursively);
12617
12411
  for (const parameter of this.params) {
12618
12412
  if (!(parameter instanceof Identifier)) {
12619
- parameter.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12413
+ parameter.include(context, includeChildrenRecursively);
12620
12414
  }
12621
12415
  }
12622
12416
  }
@@ -12639,18 +12433,13 @@ class ObjectPattern extends NodeBase {
12639
12433
  }
12640
12434
  }
12641
12435
  }
12642
- declare(kind, destructuredInitPath, init) {
12436
+ declare(kind, init) {
12643
12437
  const variables = [];
12644
12438
  for (const property of this.properties) {
12645
- variables.push(...property.declare(kind, destructuredInitPath, init));
12439
+ variables.push(...property.declare(kind, init));
12646
12440
  }
12647
12441
  return variables;
12648
12442
  }
12649
- deoptimizeAssignment(destructuredInitPath, init) {
12650
- for (const property of this.properties) {
12651
- property.deoptimizeAssignment(destructuredInitPath, init);
12652
- }
12653
- }
12654
12443
  deoptimizePath(path) {
12655
12444
  if (path.length === 0) {
12656
12445
  for (const property of this.properties) {
@@ -12668,44 +12457,11 @@ class ObjectPattern extends NodeBase {
12668
12457
  }
12669
12458
  return false;
12670
12459
  }
12671
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
12672
- for (const property of this.properties) {
12673
- if (property.hasEffectsWhenDestructuring(context, destructuredInitPath, init))
12674
- return true;
12675
- }
12676
- return false;
12677
- }
12678
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
12679
- let included = false;
12680
- for (const property of this.properties) {
12681
- included =
12682
- property.includeDestructuredIfNecessary(context, destructuredInitPath, init) || included;
12683
- }
12684
- return (this.included ||= included);
12685
- }
12686
12460
  markDeclarationReached() {
12687
12461
  for (const property of this.properties) {
12688
12462
  property.markDeclarationReached();
12689
12463
  }
12690
12464
  }
12691
- render(code, options) {
12692
- if (this.properties.length > 0) {
12693
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
12694
- let lastSeparatorPos = null;
12695
- for (const { node, separator, start, end } of separatedNodes) {
12696
- if (!node.included) {
12697
- treeshakeNode(node, code, start, end);
12698
- continue;
12699
- }
12700
- lastSeparatorPos = separator;
12701
- node.render(code, options);
12702
- }
12703
- if (lastSeparatorPos) {
12704
- code.remove(lastSeparatorPos, this.end - 1);
12705
- }
12706
- }
12707
- }
12708
- applyDeoptimizations() { }
12709
12465
  }
12710
12466
 
12711
12467
  class AssignmentExpression extends NodeBase {
@@ -12715,27 +12471,23 @@ class AssignmentExpression extends NodeBase {
12715
12471
  this.applyDeoptimizations();
12716
12472
  // MemberExpressions do not access the property before assignments if the
12717
12473
  // operator is '='.
12718
- return (right.hasEffects(context) ||
12719
- left.hasEffectsAsAssignmentTarget(context, operator !== '=') ||
12720
- this.left.hasEffectsWhenDestructuring?.(context, EMPTY_PATH, right));
12474
+ return (right.hasEffects(context) || left.hasEffectsAsAssignmentTarget(context, operator !== '='));
12721
12475
  }
12722
12476
  hasEffectsOnInteractionAtPath(path, interaction, context) {
12723
12477
  return this.right.hasEffectsOnInteractionAtPath(path, interaction, context);
12724
12478
  }
12725
- includePath(_path, context, includeChildrenRecursively) {
12479
+ include(context, includeChildrenRecursively) {
12726
12480
  const { deoptimized, left, right, operator } = this;
12727
12481
  if (!deoptimized)
12728
12482
  this.applyDeoptimizations();
12729
12483
  this.included = true;
12730
- const hasEffectsContext = createHasEffectsContext();
12731
12484
  if (includeChildrenRecursively ||
12732
12485
  operator !== '=' ||
12733
12486
  left.included ||
12734
- left.hasEffectsAsAssignmentTarget(hasEffectsContext, false) ||
12735
- left.hasEffectsWhenDestructuring?.(hasEffectsContext, EMPTY_PATH, right)) {
12487
+ left.hasEffectsAsAssignmentTarget(createHasEffectsContext(), false)) {
12736
12488
  left.includeAsAssignmentTarget(context, includeChildrenRecursively, operator !== '=');
12737
12489
  }
12738
- right.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12490
+ right.include(context, includeChildrenRecursively);
12739
12491
  }
12740
12492
  initialise() {
12741
12493
  super.initialise();
@@ -12797,7 +12549,8 @@ class AssignmentExpression extends NodeBase {
12797
12549
  }
12798
12550
  applyDeoptimizations() {
12799
12551
  this.deoptimized = true;
12800
- this.left.deoptimizeAssignment(EMPTY_PATH, this.right);
12552
+ this.left.deoptimizePath(EMPTY_PATH);
12553
+ this.right.deoptimizePath(UNKNOWN_PATH);
12801
12554
  this.scope.context.requestTreeshakingPass();
12802
12555
  }
12803
12556
  }
@@ -12806,11 +12559,8 @@ class AssignmentPattern extends NodeBase {
12806
12559
  addExportedVariables(variables, exportNamesByVariable) {
12807
12560
  this.left.addExportedVariables(variables, exportNamesByVariable);
12808
12561
  }
12809
- declare(kind, destructuredInitPath, init) {
12810
- return this.left.declare(kind, destructuredInitPath, init);
12811
- }
12812
- deoptimizeAssignment(destructuredInitPath, init) {
12813
- this.left.deoptimizeAssignment(destructuredInitPath, init);
12562
+ declare(kind, init) {
12563
+ return this.left.declare(kind, init);
12814
12564
  }
12815
12565
  deoptimizePath(path) {
12816
12566
  if (path.length === 0) {
@@ -12820,23 +12570,6 @@ class AssignmentPattern extends NodeBase {
12820
12570
  hasEffectsOnInteractionAtPath(path, interaction, context) {
12821
12571
  return (path.length > 0 || this.left.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
12822
12572
  }
12823
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
12824
- return this.left.hasEffectsWhenDestructuring(context, destructuredInitPath, init);
12825
- }
12826
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
12827
- let included = this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init) ||
12828
- this.included;
12829
- if ((included ||= this.right.shouldBeIncluded(context))) {
12830
- this.right.includePath(UNKNOWN_PATH, context, false);
12831
- if (!this.left.included) {
12832
- this.left.included = true;
12833
- // Unfortunately, we need to include the left side again now, so that
12834
- // any declared variables are properly included.
12835
- this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init);
12836
- }
12837
- }
12838
- return (this.included = included);
12839
- }
12840
12573
  markDeclarationReached() {
12841
12574
  this.left.markDeclarationReached();
12842
12575
  }
@@ -12858,7 +12591,7 @@ class AwaitExpression extends NodeBase {
12858
12591
  this.applyDeoptimizations();
12859
12592
  return true;
12860
12593
  }
12861
- includePath(path, context, includeChildrenRecursively) {
12594
+ include(context, includeChildrenRecursively) {
12862
12595
  if (!this.deoptimized)
12863
12596
  this.applyDeoptimizations();
12864
12597
  if (!this.included) {
@@ -12872,7 +12605,7 @@ class AwaitExpression extends NodeBase {
12872
12605
  this.scope.context.usesTopLevelAwait = true;
12873
12606
  }
12874
12607
  }
12875
- this.argument.includePath(path, context, includeChildrenRecursively);
12608
+ this.argument.include(context, includeChildrenRecursively);
12876
12609
  }
12877
12610
  }
12878
12611
 
@@ -12954,10 +12687,10 @@ class BreakStatement extends NodeBase {
12954
12687
  context.brokenFlow = true;
12955
12688
  return false;
12956
12689
  }
12957
- includePath(_, context) {
12690
+ include(context) {
12958
12691
  this.included = true;
12959
12692
  if (this.label) {
12960
- this.label.includePath(UNKNOWN_PATH, createInclusionContext());
12693
+ this.label.include();
12961
12694
  context.includedLabels.add(this.label.name);
12962
12695
  }
12963
12696
  else {
@@ -13151,11 +12884,11 @@ class CallExpression extends CallExpressionBase {
13151
12884
  (calleeHasEffects ||
13152
12885
  this.callee.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context)));
13153
12886
  }
13154
- includePath(path, context, includeChildrenRecursively) {
12887
+ include(context, includeChildrenRecursively) {
13155
12888
  if (!this.deoptimized)
13156
12889
  this.applyDeoptimizations();
13157
12890
  if (includeChildrenRecursively) {
13158
- super.includePath(path, context, includeChildrenRecursively);
12891
+ super.include(context, includeChildrenRecursively);
13159
12892
  if (includeChildrenRecursively === INCLUDE_PARAMETERS &&
13160
12893
  this.callee instanceof Identifier &&
13161
12894
  this.callee.variable) {
@@ -13164,18 +12897,9 @@ class CallExpression extends CallExpressionBase {
13164
12897
  }
13165
12898
  else {
13166
12899
  this.included = true;
13167
- // If the callee is a member expression and does not have a variable, its
13168
- // object will already be included via the first argument of the
13169
- // interaction in includeCallArguments. Including it again can lead to
13170
- // severe performance problems.
13171
- if (this.callee instanceof MemberExpression && !this.callee.variable) {
13172
- this.callee.property.includePath(UNKNOWN_PATH, context, false);
13173
- }
13174
- else {
13175
- this.callee.includePath(UNKNOWN_PATH, context, false);
13176
- }
13177
- this.callee.includeCallArguments(context, this.interaction);
12900
+ this.callee.include(context, false);
13178
12901
  }
12902
+ this.callee.includeCallArguments(context, this.arguments);
13179
12903
  }
13180
12904
  initialise() {
13181
12905
  super.initialise();
@@ -13214,7 +12938,7 @@ class CatchClause extends NodeBase {
13214
12938
  this.type = type;
13215
12939
  if (param) {
13216
12940
  this.param = new (this.scope.context.getNodeConstructor(param.type))(this, this.scope).parseNode(param);
13217
- this.param.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
12941
+ this.param.declare('parameter', UNKNOWN_EXPRESSION);
13218
12942
  }
13219
12943
  this.body = new BlockStatement(this, this.scope.bodyScope).parseNode(body);
13220
12944
  return super.parseNode(esTreeNode);
@@ -13242,7 +12966,7 @@ class ClassBodyScope extends ChildScope {
13242
12966
  constructor(parent, classNode) {
13243
12967
  const { context } = parent;
13244
12968
  super(parent, context);
13245
- this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, EMPTY_PATH, context, 'other')));
12969
+ this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, context, 'other')));
13246
12970
  this.instanceScope = new ChildScope(this, context);
13247
12971
  this.instanceScope.variables.set('this', new ThisVariable(context));
13248
12972
  }
@@ -13255,11 +12979,11 @@ class ClassBody extends NodeBase {
13255
12979
  createScope(parentScope) {
13256
12980
  this.scope = new ClassBodyScope(parentScope, this.parent);
13257
12981
  }
13258
- includePath(_path, context, includeChildrenRecursively) {
12982
+ include(context, includeChildrenRecursively) {
13259
12983
  this.included = true;
13260
- this.scope.context.includeVariableInModule(this.scope.thisVariable, UNKNOWN_PATH);
12984
+ this.scope.context.includeVariableInModule(this.scope.thisVariable);
13261
12985
  for (const definition of this.body) {
13262
- definition.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12986
+ definition.include(context, includeChildrenRecursively);
13263
12987
  }
13264
12988
  }
13265
12989
  parseNode(esTreeNode) {
@@ -13383,26 +13107,26 @@ class ConditionalExpression extends NodeBase {
13383
13107
  }
13384
13108
  return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
13385
13109
  }
13386
- includePath(path, context, includeChildrenRecursively) {
13110
+ include(context, includeChildrenRecursively) {
13387
13111
  this.included = true;
13388
13112
  const usedBranch = this.getUsedBranch();
13389
13113
  if (includeChildrenRecursively || this.test.shouldBeIncluded(context) || usedBranch === null) {
13390
- this.test.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13391
- this.consequent.includePath(path, context, includeChildrenRecursively);
13392
- this.alternate.includePath(path, context, includeChildrenRecursively);
13114
+ this.test.include(context, includeChildrenRecursively);
13115
+ this.consequent.include(context, includeChildrenRecursively);
13116
+ this.alternate.include(context, includeChildrenRecursively);
13393
13117
  }
13394
13118
  else {
13395
- usedBranch.includePath(path, context, includeChildrenRecursively);
13119
+ usedBranch.include(context, includeChildrenRecursively);
13396
13120
  }
13397
13121
  }
13398
- includeCallArguments(context, interaction) {
13122
+ includeCallArguments(context, parameters) {
13399
13123
  const usedBranch = this.getUsedBranch();
13400
13124
  if (usedBranch) {
13401
- usedBranch.includeCallArguments(context, interaction);
13125
+ usedBranch.includeCallArguments(context, parameters);
13402
13126
  }
13403
13127
  else {
13404
- this.consequent.includeCallArguments(context, interaction);
13405
- this.alternate.includeCallArguments(context, interaction);
13128
+ this.consequent.includeCallArguments(context, parameters);
13129
+ this.alternate.includeCallArguments(context, parameters);
13406
13130
  }
13407
13131
  }
13408
13132
  removeAnnotations(code) {
@@ -13463,10 +13187,10 @@ class ContinueStatement extends NodeBase {
13463
13187
  context.brokenFlow = true;
13464
13188
  return false;
13465
13189
  }
13466
- includePath(_, context) {
13190
+ include(context) {
13467
13191
  this.included = true;
13468
13192
  if (this.label) {
13469
- this.label.includePath(UNKNOWN_PATH, createInclusionContext());
13193
+ this.label.include();
13470
13194
  context.includedLabels.add(this.label.name);
13471
13195
  }
13472
13196
  else {
@@ -13509,7 +13233,7 @@ function includeLoopBody(context, body, includeChildrenRecursively) {
13509
13233
  const { brokenFlow, hasBreak, hasContinue } = context;
13510
13234
  context.hasBreak = false;
13511
13235
  context.hasContinue = false;
13512
- body.includePath(UNKNOWN_PATH, context, includeChildrenRecursively, { asSingleStatement: true });
13236
+ body.include(context, includeChildrenRecursively, { asSingleStatement: true });
13513
13237
  context.hasBreak = hasBreak;
13514
13238
  context.hasContinue = hasContinue;
13515
13239
  context.brokenFlow = brokenFlow;
@@ -13521,9 +13245,9 @@ class DoWhileStatement extends NodeBase {
13521
13245
  return true;
13522
13246
  return hasLoopBodyEffects(context, this.body);
13523
13247
  }
13524
- includePath(_path, context, includeChildrenRecursively) {
13248
+ include(context, includeChildrenRecursively) {
13525
13249
  this.included = true;
13526
- this.test.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13250
+ this.test.include(context, includeChildrenRecursively);
13527
13251
  includeLoopBody(context, this.body, includeChildrenRecursively);
13528
13252
  }
13529
13253
  }
@@ -13594,13 +13318,13 @@ class ForInStatement extends NodeBase {
13594
13318
  return true;
13595
13319
  return hasLoopBodyEffects(context, body);
13596
13320
  }
13597
- includePath(_path, context, includeChildrenRecursively) {
13321
+ include(context, includeChildrenRecursively) {
13598
13322
  const { body, deoptimized, left, right } = this;
13599
13323
  if (!deoptimized)
13600
13324
  this.applyDeoptimizations();
13601
13325
  this.included = true;
13602
13326
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
13603
- right.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13327
+ right.include(context, includeChildrenRecursively);
13604
13328
  includeLoopBody(context, body, includeChildrenRecursively);
13605
13329
  }
13606
13330
  initialise() {
@@ -13639,13 +13363,13 @@ class ForOfStatement extends NodeBase {
13639
13363
  // Placeholder until proper Symbol.Iterator support
13640
13364
  return true;
13641
13365
  }
13642
- includePath(_path, context, includeChildrenRecursively) {
13366
+ include(context, includeChildrenRecursively) {
13643
13367
  const { body, deoptimized, left, right } = this;
13644
13368
  if (!deoptimized)
13645
13369
  this.applyDeoptimizations();
13646
13370
  this.included = true;
13647
13371
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
13648
- right.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13372
+ right.include(context, includeChildrenRecursively);
13649
13373
  includeLoopBody(context, body, includeChildrenRecursively);
13650
13374
  }
13651
13375
  initialise() {
@@ -13681,13 +13405,11 @@ class ForStatement extends NodeBase {
13681
13405
  }
13682
13406
  return hasLoopBodyEffects(context, this.body);
13683
13407
  }
13684
- includePath(_path, context, includeChildrenRecursively) {
13408
+ include(context, includeChildrenRecursively) {
13685
13409
  this.included = true;
13686
- this.init?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively, {
13687
- asSingleStatement: true
13688
- });
13689
- this.test?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13690
- this.update?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13410
+ this.init?.include(context, includeChildrenRecursively, { asSingleStatement: true });
13411
+ this.test?.include(context, includeChildrenRecursively);
13412
+ this.update?.include(context, includeChildrenRecursively);
13691
13413
  includeLoopBody(context, this.body, includeChildrenRecursively);
13692
13414
  }
13693
13415
  render(code, options) {
@@ -13728,9 +13450,9 @@ class TrackingScope extends BlockScope {
13728
13450
  super(...arguments);
13729
13451
  this.hoistedDeclarations = [];
13730
13452
  }
13731
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
13453
+ addDeclaration(identifier, context, init, kind) {
13732
13454
  this.hoistedDeclarations.push(identifier);
13733
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
13455
+ return super.addDeclaration(identifier, context, init, kind);
13734
13456
  }
13735
13457
  }
13736
13458
 
@@ -13763,7 +13485,7 @@ class IfStatement extends NodeBase {
13763
13485
  }
13764
13486
  return testValue ? this.consequent.hasEffects(context) : !!this.alternate?.hasEffects(context);
13765
13487
  }
13766
- includePath(_, context, includeChildrenRecursively) {
13488
+ include(context, includeChildrenRecursively) {
13767
13489
  this.included = true;
13768
13490
  if (includeChildrenRecursively) {
13769
13491
  this.includeRecursively(includeChildrenRecursively, context);
@@ -13838,31 +13560,31 @@ class IfStatement extends NodeBase {
13838
13560
  }
13839
13561
  includeKnownTest(context, testValue) {
13840
13562
  if (this.test.shouldBeIncluded(context)) {
13841
- this.test.includePath(UNKNOWN_PATH, context, false);
13563
+ this.test.include(context, false);
13842
13564
  }
13843
13565
  if (testValue && this.consequent.shouldBeIncluded(context)) {
13844
- this.consequent.includePath(UNKNOWN_PATH, context, false, { asSingleStatement: true });
13566
+ this.consequent.include(context, false, { asSingleStatement: true });
13845
13567
  }
13846
13568
  if (!testValue && this.alternate?.shouldBeIncluded(context)) {
13847
- this.alternate.includePath(UNKNOWN_PATH, context, false, { asSingleStatement: true });
13569
+ this.alternate.include(context, false, { asSingleStatement: true });
13848
13570
  }
13849
13571
  }
13850
13572
  includeRecursively(includeChildrenRecursively, context) {
13851
- this.test.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13852
- this.consequent.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13853
- this.alternate?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13573
+ this.test.include(context, includeChildrenRecursively);
13574
+ this.consequent.include(context, includeChildrenRecursively);
13575
+ this.alternate?.include(context, includeChildrenRecursively);
13854
13576
  }
13855
13577
  includeUnknownTest(context) {
13856
- this.test.includePath(UNKNOWN_PATH, context, false);
13578
+ this.test.include(context, false);
13857
13579
  const { brokenFlow } = context;
13858
13580
  let consequentBrokenFlow = false;
13859
13581
  if (this.consequent.shouldBeIncluded(context)) {
13860
- this.consequent.includePath(UNKNOWN_PATH, context, false, { asSingleStatement: true });
13582
+ this.consequent.include(context, false, { asSingleStatement: true });
13861
13583
  consequentBrokenFlow = context.brokenFlow;
13862
13584
  context.brokenFlow = brokenFlow;
13863
13585
  }
13864
13586
  if (this.alternate?.shouldBeIncluded(context)) {
13865
- this.alternate.includePath(UNKNOWN_PATH, context, false, { asSingleStatement: true });
13587
+ this.alternate.include(context, false, { asSingleStatement: true });
13866
13588
  context.brokenFlow = context.brokenFlow && consequentBrokenFlow;
13867
13589
  }
13868
13590
  }
@@ -13930,7 +13652,7 @@ function isReassignedExportsMember(variable, exportNamesByVariable) {
13930
13652
  class VariableDeclarator extends NodeBase {
13931
13653
  declareDeclarator(kind, isUsingDeclaration) {
13932
13654
  this.isUsingDeclaration = isUsingDeclaration;
13933
- this.id.declare(kind, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION);
13655
+ this.id.declare(kind, this.init || UNDEFINED_EXPRESSION);
13934
13656
  }
13935
13657
  deoptimizePath(path) {
13936
13658
  this.id.deoptimizePath(path);
@@ -13940,25 +13662,17 @@ class VariableDeclarator extends NodeBase {
13940
13662
  this.applyDeoptimizations();
13941
13663
  const initEffect = this.init?.hasEffects(context);
13942
13664
  this.id.markDeclarationReached();
13943
- return (initEffect ||
13944
- this.isUsingDeclaration ||
13945
- this.id.hasEffects(context) ||
13946
- (this.scope.context.options.treeshake
13947
- .propertyReadSideEffects &&
13948
- this.id.hasEffectsWhenDestructuring(context, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION)));
13949
- }
13950
- includePath(_path, context, includeChildrenRecursively) {
13665
+ return initEffect || this.id.hasEffects(context) || this.isUsingDeclaration;
13666
+ }
13667
+ include(context, includeChildrenRecursively) {
13951
13668
  const { deoptimized, id, init } = this;
13952
13669
  if (!deoptimized)
13953
13670
  this.applyDeoptimizations();
13954
13671
  this.included = true;
13955
- init?.includePath(EMPTY_PATH, context, includeChildrenRecursively);
13672
+ init?.include(context, includeChildrenRecursively);
13956
13673
  id.markDeclarationReached();
13957
- if (includeChildrenRecursively) {
13958
- id.includePath(EMPTY_PATH, context, includeChildrenRecursively);
13959
- }
13960
- else {
13961
- id.includeDestructuredIfNecessary(context, EMPTY_PATH, init || UNDEFINED_EXPRESSION);
13674
+ if (includeChildrenRecursively || id.shouldBeIncluded(context)) {
13675
+ id.include(context, includeChildrenRecursively);
13962
13676
  }
13963
13677
  }
13964
13678
  removeAnnotations(code) {
@@ -14007,8 +13721,6 @@ class ImportExpression extends NodeBase {
14007
13721
  constructor() {
14008
13722
  super(...arguments);
14009
13723
  this.inlineNamespace = null;
14010
- this.hasUnknownAccessedKey = false;
14011
- this.accessedPropKey = new Set();
14012
13724
  this.attributes = null;
14013
13725
  this.mechanism = null;
14014
13726
  this.namespaceExportName = undefined;
@@ -14041,15 +13753,12 @@ class ImportExpression extends NodeBase {
14041
13753
  if (parent2 instanceof ExpressionStatement) {
14042
13754
  return parseAst_js.EMPTY_ARRAY;
14043
13755
  }
14044
- // Case 1: const { foo } / module = await import('bar')
13756
+ // Case 1: const { foo } = await import('bar')
14045
13757
  if (parent2 instanceof VariableDeclarator) {
14046
13758
  const declaration = parent2.id;
14047
- if (declaration instanceof Identifier) {
14048
- return this.hasUnknownAccessedKey ? undefined : [...this.accessedPropKey];
14049
- }
14050
- if (declaration instanceof ObjectPattern) {
14051
- return getDeterministicObjectDestructure(declaration);
14052
- }
13759
+ return declaration instanceof ObjectPattern
13760
+ ? getDeterministicObjectDestructure(declaration)
13761
+ : undefined;
14053
13762
  }
14054
13763
  // Case 2: (await import('bar')).foo
14055
13764
  if (parent2 instanceof MemberExpression) {
@@ -14098,23 +13807,13 @@ class ImportExpression extends NodeBase {
14098
13807
  hasEffects() {
14099
13808
  return true;
14100
13809
  }
14101
- includePath(path, context, includeChildrenRecursively) {
13810
+ include(context, includeChildrenRecursively) {
14102
13811
  if (!this.included) {
14103
13812
  this.included = true;
14104
13813
  this.scope.context.includeDynamicImport(this);
14105
13814
  this.scope.addAccessedDynamicImport(this);
14106
- this.source.includePath(path, context, includeChildrenRecursively);
14107
- }
14108
- if (this.hasUnknownAccessedKey)
14109
- return;
14110
- if (path[0] === UnknownKey) {
14111
- this.hasUnknownAccessedKey = true;
14112
- this.scope.context.includeDynamicImport(this);
14113
- }
14114
- else if (typeof path[0] === 'string') {
14115
- this.accessedPropKey.add(path[0]);
14116
- this.scope.context.includeDynamicImport(this);
14117
13815
  }
13816
+ this.source.include(context, includeChildrenRecursively);
14118
13817
  }
14119
13818
  initialise() {
14120
13819
  super.initialise();
@@ -14442,7 +14141,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node) {
14442
14141
  if (preserve) {
14443
14142
  // This pretends we are accessing an included global variable of the same name
14444
14143
  const globalVariable = node.scope.findGlobal(baseName);
14445
- globalVariable.includePath(UNKNOWN_PATH, createInclusionContext());
14144
+ globalVariable.include();
14446
14145
  // This excludes this variable from renaming
14447
14146
  factoryVariable.globalName = baseName;
14448
14147
  }
@@ -14450,7 +14149,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node) {
14450
14149
  else {
14451
14150
  factoryVariable = node.scope.findGlobal(baseName);
14452
14151
  }
14453
- node.scope.context.includeVariableInModule(factoryVariable, UNKNOWN_PATH);
14152
+ node.scope.context.includeVariableInModule(factoryVariable);
14454
14153
  if (factoryVariable instanceof LocalVariable) {
14455
14154
  factoryVariable.consolidateInitializers();
14456
14155
  factoryVariable.addUsedPlace(node);
@@ -14472,7 +14171,7 @@ class JSXElementBase extends NodeBase {
14472
14171
  this.scope.context.addImportSource(importSource);
14473
14172
  }
14474
14173
  }
14475
- includePath(path, context, includeChildrenRecursively) {
14174
+ include(context, includeChildrenRecursively) {
14476
14175
  if (!this.included) {
14477
14176
  const { factory, importSource, mode } = this.jsxMode;
14478
14177
  if (factory) {
@@ -14480,7 +14179,7 @@ class JSXElementBase extends NodeBase {
14480
14179
  this.factoryVariable = getAndIncludeFactoryVariable(factory, mode === 'preserve', importSource, this);
14481
14180
  }
14482
14181
  }
14483
- super.includePath(path, context, includeChildrenRecursively);
14182
+ super.include(context, includeChildrenRecursively);
14484
14183
  }
14485
14184
  applyDeoptimizations() { }
14486
14185
  getRenderingMode() {
@@ -14742,7 +14441,7 @@ class JSXOpeningFragment extends NodeBase {
14742
14441
  this.fragment = null;
14743
14442
  this.fragmentVariable = null;
14744
14443
  }
14745
- includePath(path, context, includeChildrenRecursively) {
14444
+ include(context, includeChildrenRecursively) {
14746
14445
  if (!this.included) {
14747
14446
  const jsx = this.scope.context.options.jsx;
14748
14447
  if (jsx.mode === 'automatic') {
@@ -14757,7 +14456,7 @@ class JSXOpeningFragment extends NodeBase {
14757
14456
  }
14758
14457
  }
14759
14458
  }
14760
- super.includePath(path, context, includeChildrenRecursively);
14459
+ super.include(context, includeChildrenRecursively);
14761
14460
  }
14762
14461
  render(code, options) {
14763
14462
  const { mode } = this.scope.context.options.jsx;
@@ -14814,13 +14513,13 @@ class LabeledStatement extends NodeBase {
14814
14513
  context.includedLabels = new Set([...includedLabels, ...context.includedLabels]);
14815
14514
  return bodyHasEffects;
14816
14515
  }
14817
- includePath(_path, context, includeChildrenRecursively) {
14516
+ include(context, includeChildrenRecursively) {
14818
14517
  this.included = true;
14819
14518
  const { brokenFlow, includedLabels } = context;
14820
14519
  context.includedLabels = new Set();
14821
- this.body.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
14520
+ this.body.include(context, includeChildrenRecursively);
14822
14521
  if (includeChildrenRecursively || context.includedLabels.has(this.label.name)) {
14823
- this.label.includePath(UNKNOWN_PATH, createInclusionContext());
14522
+ this.label.include();
14824
14523
  context.includedLabels.delete(this.label.name);
14825
14524
  context.brokenFlow = brokenFlow;
14826
14525
  }
@@ -14917,17 +14616,17 @@ class LogicalExpression extends NodeBase {
14917
14616
  }
14918
14617
  return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
14919
14618
  }
14920
- includePath(path, context, includeChildrenRecursively) {
14619
+ include(context, includeChildrenRecursively) {
14921
14620
  this.included = true;
14922
14621
  const usedBranch = this.getUsedBranch();
14923
14622
  if (includeChildrenRecursively ||
14924
14623
  (usedBranch === this.right && this.left.shouldBeIncluded(context)) ||
14925
14624
  !usedBranch) {
14926
- this.left.includePath(path, context, includeChildrenRecursively);
14927
- this.right.includePath(path, context, includeChildrenRecursively);
14625
+ this.left.include(context, includeChildrenRecursively);
14626
+ this.right.include(context, includeChildrenRecursively);
14928
14627
  }
14929
14628
  else {
14930
- usedBranch.includePath(path, context, includeChildrenRecursively);
14629
+ usedBranch.include(context, includeChildrenRecursively);
14931
14630
  }
14932
14631
  }
14933
14632
  removeAnnotations(code) {
@@ -14999,17 +14698,17 @@ class NewExpression extends NodeBase {
14999
14698
  hasEffectsOnInteractionAtPath(path, { type }) {
15000
14699
  return path.length > 0 || type !== INTERACTION_ACCESSED;
15001
14700
  }
15002
- includePath(path, context, includeChildrenRecursively) {
14701
+ include(context, includeChildrenRecursively) {
15003
14702
  if (!this.deoptimized)
15004
14703
  this.applyDeoptimizations();
15005
14704
  if (includeChildrenRecursively) {
15006
- super.includePath(path, context, includeChildrenRecursively);
14705
+ super.include(context, includeChildrenRecursively);
15007
14706
  }
15008
14707
  else {
15009
14708
  this.included = true;
15010
- this.callee.includePath(UNKNOWN_PATH, context, false);
14709
+ this.callee.include(context, false);
15011
14710
  }
15012
- this.callee.includeCallArguments(context, this.interaction);
14711
+ this.callee.includeCallArguments(context, this.arguments);
15013
14712
  }
15014
14713
  initialise() {
15015
14714
  super.initialise();
@@ -15038,7 +14737,6 @@ class ObjectExpression extends NodeBase {
15038
14737
  constructor() {
15039
14738
  super(...arguments);
15040
14739
  this.objectEntity = null;
15041
- this.protoProp = null;
15042
14740
  }
15043
14741
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
15044
14742
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -15058,32 +14756,13 @@ class ObjectExpression extends NodeBase {
15058
14756
  hasEffectsOnInteractionAtPath(path, interaction, context) {
15059
14757
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
15060
14758
  }
15061
- includePath(path, context, includeChildrenRecursively) {
15062
- this.included = true;
15063
- this.getObjectEntity().includePath(path, context, includeChildrenRecursively);
15064
- this.protoProp?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15065
- }
15066
14759
  render(code, options, { renderedSurroundingElement } = parseAst_js.BLANK) {
14760
+ super.render(code, options);
15067
14761
  if (renderedSurroundingElement === parseAst_js.ExpressionStatement ||
15068
14762
  renderedSurroundingElement === parseAst_js.ArrowFunctionExpression) {
15069
14763
  code.appendRight(this.start, '(');
15070
14764
  code.prependLeft(this.end, ')');
15071
14765
  }
15072
- if (this.properties.length > 0) {
15073
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
15074
- let lastSeparatorPos = null;
15075
- for (const { node, separator, start, end } of separatedNodes) {
15076
- if (!node.included) {
15077
- treeshakeNode(node, code, start, end);
15078
- continue;
15079
- }
15080
- lastSeparatorPos = separator;
15081
- node.render(code, options);
15082
- }
15083
- if (lastSeparatorPos) {
15084
- code.remove(lastSeparatorPos, this.end - 1);
15085
- }
15086
- }
15087
14766
  }
15088
14767
  applyDeoptimizations() { }
15089
14768
  getObjectEntity() {
@@ -15114,7 +14793,6 @@ class ObjectExpression extends NodeBase {
15114
14793
  ? property.key.name
15115
14794
  : String(property.key.value);
15116
14795
  if (key === '__proto__' && property.kind === 'init') {
15117
- this.protoProp = property;
15118
14796
  prototype =
15119
14797
  property.value instanceof Literal && property.value.value === null
15120
14798
  ? null
@@ -15181,11 +14859,11 @@ class Program extends NodeBase {
15181
14859
  }
15182
14860
  return false;
15183
14861
  }
15184
- includePath(_path, context, includeChildrenRecursively) {
14862
+ include(context, includeChildrenRecursively) {
15185
14863
  this.included = true;
15186
14864
  for (const node of this.body) {
15187
14865
  if (includeChildrenRecursively || node.shouldBeIncluded(context)) {
15188
- node.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
14866
+ node.include(context, includeChildrenRecursively);
15189
14867
  }
15190
14868
  }
15191
14869
  }
@@ -15224,6 +14902,10 @@ class Program extends NodeBase {
15224
14902
  }
15225
14903
 
15226
14904
  class Property extends MethodBase {
14905
+ constructor() {
14906
+ super(...arguments);
14907
+ this.declarationInit = null;
14908
+ }
15227
14909
  //declare method: boolean;
15228
14910
  get method() {
15229
14911
  return isFlagSet(this.flags, 262144 /* Flag.method */);
@@ -15238,39 +14920,17 @@ class Property extends MethodBase {
15238
14920
  set shorthand(value) {
15239
14921
  this.flags = setFlag(this.flags, 524288 /* Flag.shorthand */, value);
15240
14922
  }
15241
- declare(kind, destructuredInitPath, init) {
15242
- return this.value.declare(kind, this.getPathInProperty(destructuredInitPath), init);
15243
- }
15244
- deoptimizeAssignment(destructuredInitPath, init) {
15245
- this.value.deoptimizeAssignment?.(this.getPathInProperty(destructuredInitPath), init);
14923
+ declare(kind, init) {
14924
+ this.declarationInit = init;
14925
+ return this.value.declare(kind, UNKNOWN_EXPRESSION);
15246
14926
  }
15247
14927
  hasEffects(context) {
15248
14928
  if (!this.deoptimized)
15249
14929
  this.applyDeoptimizations();
15250
- return this.key.hasEffects(context) || this.value.hasEffects(context);
15251
- }
15252
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
15253
- return this.value.hasEffectsWhenDestructuring?.(context, this.getPathInProperty(destructuredInitPath), init);
15254
- }
15255
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
15256
- const path = this.getPathInProperty(destructuredInitPath);
15257
- let included = this.value.includeDestructuredIfNecessary(context, path, init) ||
15258
- this.included;
15259
- if ((included ||= this.key.hasEffects(createHasEffectsContext()))) {
15260
- this.key.includePath(EMPTY_PATH, context, false);
15261
- if (!this.value.included) {
15262
- this.value.included = true;
15263
- // Unfortunately, we need to include the value again now, so that any
15264
- // declared variables are properly included.
15265
- this.value.includeDestructuredIfNecessary(context, path, init);
15266
- }
15267
- }
15268
- return (this.included = included);
15269
- }
15270
- includePath(path, context, includeChildrenRecursively) {
15271
- this.included = true;
15272
- this.key.includePath(EMPTY_PATH, context, includeChildrenRecursively);
15273
- this.value.includePath(path, context, includeChildrenRecursively);
14930
+ const propertyReadSideEffects = this.scope.context.options.treeshake.propertyReadSideEffects;
14931
+ return ((this.parent.type === 'ObjectPattern' && propertyReadSideEffects === 'always') ||
14932
+ this.key.hasEffects(context) ||
14933
+ this.value.hasEffects(context));
15274
14934
  }
15275
14935
  markDeclarationReached() {
15276
14936
  this.value.markDeclarationReached();
@@ -15281,17 +14941,12 @@ class Property extends MethodBase {
15281
14941
  }
15282
14942
  this.value.render(code, options, { isShorthandProperty: this.shorthand });
15283
14943
  }
15284
- applyDeoptimizations() { }
15285
- getPathInProperty(destructuredInitPath) {
15286
- return destructuredInitPath.at(-1) === UnknownKey
15287
- ? destructuredInitPath
15288
- : // For now, we only consider static paths as we do not know how to
15289
- // deoptimize the path in the dynamic case.
15290
- this.computed
15291
- ? [...destructuredInitPath, UnknownKey]
15292
- : this.key instanceof Identifier
15293
- ? [...destructuredInitPath, this.key.name]
15294
- : [...destructuredInitPath, String(this.key.value)];
14944
+ applyDeoptimizations() {
14945
+ this.deoptimized = true;
14946
+ if (this.declarationInit !== null) {
14947
+ this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
14948
+ this.scope.context.requestTreeshakingPass();
14949
+ }
15295
14950
  }
15296
14951
  }
15297
14952
 
@@ -15336,9 +14991,9 @@ class ReturnStatement extends NodeBase {
15336
14991
  context.brokenFlow = true;
15337
14992
  return false;
15338
14993
  }
15339
- includePath(_path, context, includeChildrenRecursively) {
14994
+ include(context, includeChildrenRecursively) {
15340
14995
  this.included = true;
15341
- this.argument?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
14996
+ this.argument?.include(context, includeChildrenRecursively);
15342
14997
  context.brokenFlow = true;
15343
14998
  }
15344
14999
  initialise() {
@@ -15375,14 +15030,14 @@ class SequenceExpression extends NodeBase {
15375
15030
  hasEffectsOnInteractionAtPath(path, interaction, context) {
15376
15031
  return this.expressions[this.expressions.length - 1].hasEffectsOnInteractionAtPath(path, interaction, context);
15377
15032
  }
15378
- includePath(path, context, includeChildrenRecursively) {
15033
+ include(context, includeChildrenRecursively) {
15379
15034
  this.included = true;
15380
15035
  const lastExpression = this.expressions[this.expressions.length - 1];
15381
15036
  for (const expression of this.expressions) {
15382
15037
  if (includeChildrenRecursively ||
15383
15038
  (expression === lastExpression && !(this.parent instanceof ExpressionStatement)) ||
15384
15039
  expression.shouldBeIncluded(context))
15385
- expression.includePath(path, context, includeChildrenRecursively);
15040
+ expression.include(context, includeChildrenRecursively);
15386
15041
  }
15387
15042
  }
15388
15043
  removeAnnotations(code) {
@@ -15430,13 +15085,10 @@ class Super extends NodeBase {
15430
15085
  deoptimizePath(path) {
15431
15086
  this.variable.deoptimizePath(path);
15432
15087
  }
15433
- includePath(path, context) {
15088
+ include() {
15434
15089
  if (!this.included) {
15435
15090
  this.included = true;
15436
- this.scope.context.includeVariableInModule(this.variable, path);
15437
- }
15438
- else if (path.length > 0) {
15439
- this.variable.includePath(path, context);
15091
+ this.scope.context.includeVariableInModule(this.variable);
15440
15092
  }
15441
15093
  }
15442
15094
  }
@@ -15453,12 +15105,12 @@ class SwitchCase extends NodeBase {
15453
15105
  }
15454
15106
  return false;
15455
15107
  }
15456
- includePath(_path, context, includeChildrenRecursively) {
15108
+ include(context, includeChildrenRecursively) {
15457
15109
  this.included = true;
15458
- this.test?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15110
+ this.test?.include(context, includeChildrenRecursively);
15459
15111
  for (const node of this.consequent) {
15460
15112
  if (includeChildrenRecursively || node.shouldBeIncluded(context))
15461
- node.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15113
+ node.include(context, includeChildrenRecursively);
15462
15114
  }
15463
15115
  }
15464
15116
  render(code, options, nodeRenderOptions) {
@@ -15506,9 +15158,9 @@ class SwitchStatement extends NodeBase {
15506
15158
  context.hasBreak = hasBreak;
15507
15159
  return false;
15508
15160
  }
15509
- includePath(_path, context, includeChildrenRecursively) {
15161
+ include(context, includeChildrenRecursively) {
15510
15162
  this.included = true;
15511
- this.discriminant.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15163
+ this.discriminant.include(context, includeChildrenRecursively);
15512
15164
  const { brokenFlow, hasBreak } = context;
15513
15165
  context.hasBreak = false;
15514
15166
  let onlyHasBrokenFlow = true;
@@ -15525,7 +15177,7 @@ class SwitchStatement extends NodeBase {
15525
15177
  isCaseIncluded = switchCase.hasEffects(hasEffectsContext);
15526
15178
  }
15527
15179
  if (isCaseIncluded) {
15528
- switchCase.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15180
+ switchCase.include(context, includeChildrenRecursively);
15529
15181
  onlyHasBrokenFlow &&= context.brokenFlow && !context.hasBreak;
15530
15182
  context.hasBreak = false;
15531
15183
  context.brokenFlow = brokenFlow;
@@ -15582,21 +15234,21 @@ class TaggedTemplateExpression extends CallExpressionBase {
15582
15234
  return (this.tag.hasEffects(context) ||
15583
15235
  this.tag.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context));
15584
15236
  }
15585
- includePath(path, context, includeChildrenRecursively) {
15237
+ include(context, includeChildrenRecursively) {
15586
15238
  if (!this.deoptimized)
15587
15239
  this.applyDeoptimizations();
15588
15240
  if (includeChildrenRecursively) {
15589
- super.includePath(path, context, includeChildrenRecursively);
15241
+ super.include(context, includeChildrenRecursively);
15590
15242
  }
15591
15243
  else {
15592
15244
  this.included = true;
15593
- this.tag.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15594
- this.quasi.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15245
+ this.tag.include(context, includeChildrenRecursively);
15246
+ this.quasi.include(context, includeChildrenRecursively);
15595
15247
  }
15596
- this.tag.includeCallArguments(context, this.interaction);
15248
+ this.tag.includeCallArguments(context, this.args);
15597
15249
  const [returnExpression] = this.getReturnExpression();
15598
15250
  if (!returnExpression.included) {
15599
- returnExpression.includePath(UNKNOWN_PATH, context, false);
15251
+ returnExpression.include(context, false);
15600
15252
  }
15601
15253
  }
15602
15254
  initialise() {
@@ -15641,7 +15293,7 @@ class TemplateElement extends NodeBase {
15641
15293
  hasEffects() {
15642
15294
  return false;
15643
15295
  }
15644
- includePath() {
15296
+ include() {
15645
15297
  this.included = true;
15646
15298
  }
15647
15299
  parseNode(esTreeNode) {
@@ -15683,13 +15335,13 @@ class TemplateLiteral extends NodeBase {
15683
15335
  class ModuleScope extends ChildScope {
15684
15336
  constructor(parent, context) {
15685
15337
  super(parent, context);
15686
- this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, EMPTY_PATH, context, 'other'));
15338
+ this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, context, 'other'));
15687
15339
  }
15688
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
15340
+ addDeclaration(identifier, context, init, kind) {
15689
15341
  if (this.context.module.importDescriptions.has(identifier.name)) {
15690
15342
  context.error(parseAst_js.logRedeclarationError(identifier.name), identifier.start);
15691
15343
  }
15692
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
15344
+ return super.addDeclaration(identifier, context, init, kind);
15693
15345
  }
15694
15346
  addExportDefaultDeclaration(name, exportDefaultDeclaration, context) {
15695
15347
  const variable = new ExportDefaultVariable(name, exportDefaultDeclaration, context);
@@ -15734,13 +15386,10 @@ class ThisExpression extends NodeBase {
15734
15386
  }
15735
15387
  return this.variable.hasEffectsOnInteractionAtPath(path, interaction, context);
15736
15388
  }
15737
- includePath(path, context) {
15389
+ include() {
15738
15390
  if (!this.included) {
15739
15391
  this.included = true;
15740
- this.scope.context.includeVariableInModule(this.variable, path);
15741
- }
15742
- else if (path.length > 0) {
15743
- this.variable.includePath(path, context);
15392
+ this.scope.context.includeVariableInModule(this.variable);
15744
15393
  }
15745
15394
  }
15746
15395
  initialise() {
@@ -15767,9 +15416,9 @@ class ThrowStatement extends NodeBase {
15767
15416
  hasEffects() {
15768
15417
  return true;
15769
15418
  }
15770
- includePath(_path, context, includeChildrenRecursively) {
15419
+ include(context, includeChildrenRecursively) {
15771
15420
  this.included = true;
15772
- this.argument.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15421
+ this.argument.include(context, includeChildrenRecursively);
15773
15422
  context.brokenFlow = true;
15774
15423
  }
15775
15424
  render(code, options) {
@@ -15791,13 +15440,13 @@ class TryStatement extends NodeBase {
15791
15440
  ? this.block.body.length > 0
15792
15441
  : this.block.hasEffects(context)) || !!this.finalizer?.hasEffects(context));
15793
15442
  }
15794
- includePath(_path, context, includeChildrenRecursively) {
15443
+ include(context, includeChildrenRecursively) {
15795
15444
  const tryCatchDeoptimization = this.scope.context.options.treeshake?.tryCatchDeoptimization;
15796
15445
  const { brokenFlow, includedLabels } = context;
15797
15446
  if (!this.directlyIncluded || !tryCatchDeoptimization) {
15798
15447
  this.included = true;
15799
15448
  this.directlyIncluded = true;
15800
- this.block.includePath(UNKNOWN_PATH, context, tryCatchDeoptimization ? INCLUDE_PARAMETERS : includeChildrenRecursively);
15449
+ this.block.include(context, tryCatchDeoptimization ? INCLUDE_PARAMETERS : includeChildrenRecursively);
15801
15450
  if (includedLabels.size > 0) {
15802
15451
  this.includedLabelsAfterBlock = [...includedLabels];
15803
15452
  }
@@ -15809,10 +15458,10 @@ class TryStatement extends NodeBase {
15809
15458
  }
15810
15459
  }
15811
15460
  if (this.handler !== null) {
15812
- this.handler.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15461
+ this.handler.include(context, includeChildrenRecursively);
15813
15462
  context.brokenFlow = brokenFlow;
15814
15463
  }
15815
- this.finalizer?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15464
+ this.finalizer?.include(context, includeChildrenRecursively);
15816
15465
  }
15817
15466
  }
15818
15467
 
@@ -15870,7 +15519,7 @@ class UpdateExpression extends NodeBase {
15870
15519
  hasEffectsOnInteractionAtPath(path, { type }) {
15871
15520
  return path.length > 1 || type !== INTERACTION_ACCESSED;
15872
15521
  }
15873
- includePath(_, context, includeChildrenRecursively) {
15522
+ include(context, includeChildrenRecursively) {
15874
15523
  if (!this.deoptimized)
15875
15524
  this.applyDeoptimizations();
15876
15525
  this.included = true;
@@ -15939,20 +15588,20 @@ class VariableDeclaration extends NodeBase {
15939
15588
  hasEffectsOnInteractionAtPath() {
15940
15589
  return false;
15941
15590
  }
15942
- includePath(_path, context, includeChildrenRecursively, { asSingleStatement } = parseAst_js.BLANK) {
15591
+ include(context, includeChildrenRecursively, { asSingleStatement } = parseAst_js.BLANK) {
15943
15592
  this.included = true;
15944
15593
  for (const declarator of this.declarations) {
15945
15594
  if (includeChildrenRecursively || declarator.shouldBeIncluded(context))
15946
- declarator.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15595
+ declarator.include(context, includeChildrenRecursively);
15947
15596
  const { id, init } = declarator;
15948
15597
  if (asSingleStatement) {
15949
- id.includePath(EMPTY_PATH, context, includeChildrenRecursively);
15598
+ id.include(context, includeChildrenRecursively);
15950
15599
  }
15951
15600
  if (init &&
15952
15601
  id.included &&
15953
15602
  !init.included &&
15954
15603
  (id instanceof ObjectPattern || id instanceof ArrayPattern)) {
15955
- init.includePath(EMPTY_PATH, context, includeChildrenRecursively);
15604
+ init.include(context, includeChildrenRecursively);
15956
15605
  }
15957
15606
  }
15958
15607
  }
@@ -16024,7 +15673,8 @@ class VariableDeclaration extends NodeBase {
16024
15673
  const singleSystemExport = gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregatedSystemExports);
16025
15674
  for (const { node, start, separator, contentEnd, end } of separatedNodes) {
16026
15675
  if (!node.included) {
16027
- treeshakeNode(node, code, start, end);
15676
+ code.remove(start, end);
15677
+ node.removeAnnotations(code);
16028
15678
  continue;
16029
15679
  }
16030
15680
  node.render(code, options);
@@ -16101,9 +15751,9 @@ class WhileStatement extends NodeBase {
16101
15751
  return true;
16102
15752
  return hasLoopBodyEffects(context, this.body);
16103
15753
  }
16104
- includePath(_path, context, includeChildrenRecursively) {
15754
+ include(context, includeChildrenRecursively) {
16105
15755
  this.included = true;
16106
- this.test.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15756
+ this.test.include(context, includeChildrenRecursively);
16107
15757
  includeLoopBody(context, this.body, includeChildrenRecursively);
16108
15758
  }
16109
15759
  }
@@ -16347,7 +15997,7 @@ const bufferParsers = [
16347
15997
  const annotations = (node.annotations = parseAst_js.convertAnnotations(buffer[position + 1], buffer));
16348
15998
  node.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
16349
15999
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 2], buffer));
16350
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16000
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16351
16001
  node.body = convertNode(node, scope.bodyScope, buffer[position + 3], buffer);
16352
16002
  },
16353
16003
  function assignmentExpression(node, position, buffer) {
@@ -16393,7 +16043,7 @@ const bufferParsers = [
16393
16043
  const parameterPosition = buffer[position];
16394
16044
  const parameter = (node.param =
16395
16045
  parameterPosition === 0 ? null : convertNode(node, scope, parameterPosition, buffer));
16396
- parameter?.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
16046
+ parameter?.declare('parameter', UNKNOWN_EXPRESSION);
16397
16047
  node.body = convertNode(node, scope.bodyScope, buffer[position + 1], buffer);
16398
16048
  },
16399
16049
  function chainExpression(node, position, buffer) {
@@ -16531,7 +16181,7 @@ const bufferParsers = [
16531
16181
  node.id =
16532
16182
  idPosition === 0 ? null : convertNode(node, scope.parent, idPosition, buffer);
16533
16183
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
16534
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16184
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16535
16185
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
16536
16186
  },
16537
16187
  function functionExpression(node, position, buffer) {
@@ -16544,7 +16194,7 @@ const bufferParsers = [
16544
16194
  const idPosition = buffer[position + 2];
16545
16195
  node.id = idPosition === 0 ? null : convertNode(node, node.idScope, idPosition, buffer);
16546
16196
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
16547
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16197
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16548
16198
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
16549
16199
  },
16550
16200
  function identifier(node, position, buffer) {
@@ -16903,8 +16553,8 @@ class UnknownNode extends NodeBase {
16903
16553
  hasEffects() {
16904
16554
  return true;
16905
16555
  }
16906
- includePath(path, context) {
16907
- super.includePath(path, context, true);
16556
+ include(context) {
16557
+ super.include(context, true);
16908
16558
  }
16909
16559
  }
16910
16560
 
@@ -17008,8 +16658,8 @@ class ExportShimVariable extends Variable {
17008
16658
  super(MISSING_EXPORT_SHIM_VARIABLE);
17009
16659
  this.module = module;
17010
16660
  }
17011
- includePath(path, context) {
17012
- super.includePath(path, context);
16661
+ include() {
16662
+ super.include();
17013
16663
  this.module.needsExportShim = true;
17014
16664
  }
17015
16665
  }
@@ -17693,7 +17343,7 @@ class Module {
17693
17343
  include() {
17694
17344
  const context = createInclusionContext();
17695
17345
  if (this.ast.shouldBeIncluded(context))
17696
- this.ast.includePath(EMPTY_PATH, context, false);
17346
+ this.ast.include(context, false);
17697
17347
  }
17698
17348
  includeAllExports(includeNamespaceMembers) {
17699
17349
  if (!this.isExecuted) {
@@ -17707,7 +17357,9 @@ class Module {
17707
17357
  return parseAst_js.error(parseAst_js.logMissingEntryExport(exportName, this.id));
17708
17358
  }
17709
17359
  variable.deoptimizePath(UNKNOWN_PATH);
17710
- this.includeVariable(variable, UNKNOWN_PATH);
17360
+ if (!variable.included) {
17361
+ this.includeVariable(variable);
17362
+ }
17711
17363
  }
17712
17364
  }
17713
17365
  for (const name of this.getReexports()) {
@@ -17715,7 +17367,7 @@ class Module {
17715
17367
  if (variable) {
17716
17368
  variable.deoptimizePath(UNKNOWN_PATH);
17717
17369
  if (!variable.included) {
17718
- this.includeVariable(variable, UNKNOWN_PATH);
17370
+ this.includeVariable(variable);
17719
17371
  }
17720
17372
  if (variable instanceof ExternalVariable) {
17721
17373
  variable.module.reexported = true;
@@ -17727,7 +17379,7 @@ class Module {
17727
17379
  }
17728
17380
  }
17729
17381
  includeAllInBundle() {
17730
- this.ast.includePath(UNKNOWN_PATH, createInclusionContext(), true);
17382
+ this.ast.include(createInclusionContext(), true);
17731
17383
  this.includeAllExports(false);
17732
17384
  }
17733
17385
  includeExportsByNames(names) {
@@ -17741,7 +17393,7 @@ class Module {
17741
17393
  if (variable) {
17742
17394
  variable.deoptimizePath(UNKNOWN_PATH);
17743
17395
  if (!variable.included) {
17744
- this.includeVariable(variable, UNKNOWN_PATH);
17396
+ this.includeVariable(variable);
17745
17397
  }
17746
17398
  }
17747
17399
  if (!this.exports.has(name) && !this.reexportDescriptions.has(name)) {
@@ -18183,13 +17835,13 @@ class Module {
18183
17835
  for (const module of [this, ...this.exportAllModules]) {
18184
17836
  if (module instanceof ExternalModule) {
18185
17837
  const [externalVariable] = module.getVariableForExportName('*');
18186
- externalVariable.includePath(UNKNOWN_PATH, createInclusionContext());
17838
+ externalVariable.include();
18187
17839
  this.includedImports.add(externalVariable);
18188
17840
  externalNamespaces.add(externalVariable);
18189
17841
  }
18190
17842
  else if (module.info.syntheticNamedExports) {
18191
17843
  const syntheticNamespace = module.getSyntheticNamespace();
18192
- syntheticNamespace.includePath(UNKNOWN_PATH, createInclusionContext());
17844
+ syntheticNamespace.include();
18193
17845
  this.includedImports.add(syntheticNamespace);
18194
17846
  syntheticNamespaces.add(syntheticNamespace);
18195
17847
  }
@@ -18199,9 +17851,7 @@ class Module {
18199
17851
  includeDynamicImport(node) {
18200
17852
  const resolution = this.dynamicImports.find(dynamicImport => dynamicImport.node === node).resolution;
18201
17853
  if (resolution instanceof Module) {
18202
- if (!resolution.includedDynamicImporters.includes(this)) {
18203
- resolution.includedDynamicImporters.push(this);
18204
- }
17854
+ resolution.includedDynamicImporters.push(this);
18205
17855
  const importedNames = this.options.treeshake
18206
17856
  ? node.getDeterministicImportedNames()
18207
17857
  : undefined;
@@ -18213,7 +17863,7 @@ class Module {
18213
17863
  }
18214
17864
  }
18215
17865
  }
18216
- includeVariable(variable, path) {
17866
+ includeVariable(variable) {
18217
17867
  const variableModule = variable.module;
18218
17868
  if (variable.included) {
18219
17869
  if (variableModule instanceof Module && variableModule !== this) {
@@ -18221,6 +17871,7 @@ class Module {
18221
17871
  }
18222
17872
  }
18223
17873
  else {
17874
+ variable.include();
18224
17875
  this.graph.needsTreeshakingPass = true;
18225
17876
  if (variableModule instanceof Module) {
18226
17877
  if (!variableModule.isExecuted) {
@@ -18236,10 +17887,9 @@ class Module {
18236
17887
  }
18237
17888
  }
18238
17889
  }
18239
- variable.includePath(path, createInclusionContext());
18240
17890
  }
18241
- includeVariableInModule(variable, path) {
18242
- this.includeVariable(variable, path);
17891
+ includeVariableInModule(variable) {
17892
+ this.includeVariable(variable);
18243
17893
  const variableModule = variable.module;
18244
17894
  if (variableModule && variableModule !== this) {
18245
17895
  this.includedImports.add(variable);
@@ -21742,7 +21392,7 @@ class Graph {
21742
21392
  this.options = options;
21743
21393
  this.astLru = flru(5);
21744
21394
  this.cachedModules = new Map();
21745
- this.deoptimizationTracker = new EntityPathTracker();
21395
+ this.deoptimizationTracker = new PathTracker();
21746
21396
  this.entryModules = [];
21747
21397
  this.modulesById = new Map();
21748
21398
  this.needsTreeshakingPass = false;