@rollup/wasm-node 4.27.1 → 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.1
4
- Fri, 15 Nov 2024 16:07:10 GMT - commit aaf38b725dd142b1da4190a91de8b04c006fead5
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.1";
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,48 +8599,29 @@ 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);
8622
+ super.includeCallArguments(context, parameters);
8775
8623
  }
8776
8624
  }
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;
8784
- }
8785
- return false;
8786
- }
8787
8625
  initialise() {
8788
8626
  super.initialise();
8789
8627
  this.propertyKey = getResolvablePropertyKey(this);
@@ -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,24 +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
- included =
12541
- element?.includeDestructuredIfNecessary(context, includedPatternPath, init) || included;
12542
- }
12543
- return (this.included ||= included);
12544
- }
12545
12355
  markDeclarationReached() {
12546
12356
  for (const element of this.elements) {
12547
12357
  element?.markDeclarationReached();
12548
12358
  }
12549
12359
  }
12550
12360
  }
12551
- const getIncludedPatternPath = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
12552
- ? destructuredInitPath
12553
- : [...destructuredInitPath, UnknownInteger];
12554
12361
 
12555
12362
  class ArrowFunctionExpression extends FunctionBase {
12556
12363
  constructor() {
@@ -12599,11 +12406,11 @@ class ArrowFunctionExpression extends FunctionBase {
12599
12406
  this.parent.callee === this;
12600
12407
  return isIIFE || super.onlyFunctionCallUsed();
12601
12408
  }
12602
- includePath(_path, context, includeChildrenRecursively) {
12603
- super.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12409
+ include(context, includeChildrenRecursively) {
12410
+ super.include(context, includeChildrenRecursively);
12604
12411
  for (const parameter of this.params) {
12605
12412
  if (!(parameter instanceof Identifier)) {
12606
- parameter.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12413
+ parameter.include(context, includeChildrenRecursively);
12607
12414
  }
12608
12415
  }
12609
12416
  }
@@ -12626,18 +12433,13 @@ class ObjectPattern extends NodeBase {
12626
12433
  }
12627
12434
  }
12628
12435
  }
12629
- declare(kind, destructuredInitPath, init) {
12436
+ declare(kind, init) {
12630
12437
  const variables = [];
12631
12438
  for (const property of this.properties) {
12632
- variables.push(...property.declare(kind, destructuredInitPath, init));
12439
+ variables.push(...property.declare(kind, init));
12633
12440
  }
12634
12441
  return variables;
12635
12442
  }
12636
- deoptimizeAssignment(destructuredInitPath, init) {
12637
- for (const property of this.properties) {
12638
- property.deoptimizeAssignment(destructuredInitPath, init);
12639
- }
12640
- }
12641
12443
  deoptimizePath(path) {
12642
12444
  if (path.length === 0) {
12643
12445
  for (const property of this.properties) {
@@ -12655,44 +12457,11 @@ class ObjectPattern extends NodeBase {
12655
12457
  }
12656
12458
  return false;
12657
12459
  }
12658
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
12659
- for (const property of this.properties) {
12660
- if (property.hasEffectsWhenDestructuring(context, destructuredInitPath, init))
12661
- return true;
12662
- }
12663
- return false;
12664
- }
12665
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
12666
- let included = false;
12667
- for (const property of this.properties) {
12668
- included =
12669
- property.includeDestructuredIfNecessary(context, destructuredInitPath, init) || included;
12670
- }
12671
- return (this.included ||= included);
12672
- }
12673
12460
  markDeclarationReached() {
12674
12461
  for (const property of this.properties) {
12675
12462
  property.markDeclarationReached();
12676
12463
  }
12677
12464
  }
12678
- render(code, options) {
12679
- if (this.properties.length > 0) {
12680
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
12681
- let lastSeparatorPos = null;
12682
- for (const { node, separator, start, end } of separatedNodes) {
12683
- if (!node.included) {
12684
- treeshakeNode(node, code, start, end);
12685
- continue;
12686
- }
12687
- lastSeparatorPos = separator;
12688
- node.render(code, options);
12689
- }
12690
- if (lastSeparatorPos) {
12691
- code.remove(lastSeparatorPos, this.end - 1);
12692
- }
12693
- }
12694
- }
12695
- applyDeoptimizations() { }
12696
12465
  }
12697
12466
 
12698
12467
  class AssignmentExpression extends NodeBase {
@@ -12702,27 +12471,23 @@ class AssignmentExpression extends NodeBase {
12702
12471
  this.applyDeoptimizations();
12703
12472
  // MemberExpressions do not access the property before assignments if the
12704
12473
  // operator is '='.
12705
- return (right.hasEffects(context) ||
12706
- left.hasEffectsAsAssignmentTarget(context, operator !== '=') ||
12707
- this.left.hasEffectsWhenDestructuring?.(context, EMPTY_PATH, right));
12474
+ return (right.hasEffects(context) || left.hasEffectsAsAssignmentTarget(context, operator !== '='));
12708
12475
  }
12709
12476
  hasEffectsOnInteractionAtPath(path, interaction, context) {
12710
12477
  return this.right.hasEffectsOnInteractionAtPath(path, interaction, context);
12711
12478
  }
12712
- includePath(_path, context, includeChildrenRecursively) {
12479
+ include(context, includeChildrenRecursively) {
12713
12480
  const { deoptimized, left, right, operator } = this;
12714
12481
  if (!deoptimized)
12715
12482
  this.applyDeoptimizations();
12716
12483
  this.included = true;
12717
- const hasEffectsContext = createHasEffectsContext();
12718
12484
  if (includeChildrenRecursively ||
12719
12485
  operator !== '=' ||
12720
12486
  left.included ||
12721
- left.hasEffectsAsAssignmentTarget(hasEffectsContext, false) ||
12722
- left.hasEffectsWhenDestructuring?.(hasEffectsContext, EMPTY_PATH, right)) {
12487
+ left.hasEffectsAsAssignmentTarget(createHasEffectsContext(), false)) {
12723
12488
  left.includeAsAssignmentTarget(context, includeChildrenRecursively, operator !== '=');
12724
12489
  }
12725
- right.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12490
+ right.include(context, includeChildrenRecursively);
12726
12491
  }
12727
12492
  initialise() {
12728
12493
  super.initialise();
@@ -12784,7 +12549,8 @@ class AssignmentExpression extends NodeBase {
12784
12549
  }
12785
12550
  applyDeoptimizations() {
12786
12551
  this.deoptimized = true;
12787
- this.left.deoptimizeAssignment(EMPTY_PATH, this.right);
12552
+ this.left.deoptimizePath(EMPTY_PATH);
12553
+ this.right.deoptimizePath(UNKNOWN_PATH);
12788
12554
  this.scope.context.requestTreeshakingPass();
12789
12555
  }
12790
12556
  }
@@ -12793,11 +12559,8 @@ class AssignmentPattern extends NodeBase {
12793
12559
  addExportedVariables(variables, exportNamesByVariable) {
12794
12560
  this.left.addExportedVariables(variables, exportNamesByVariable);
12795
12561
  }
12796
- declare(kind, destructuredInitPath, init) {
12797
- return this.left.declare(kind, destructuredInitPath, init);
12798
- }
12799
- deoptimizeAssignment(destructuredInitPath, init) {
12800
- this.left.deoptimizeAssignment(destructuredInitPath, init);
12562
+ declare(kind, init) {
12563
+ return this.left.declare(kind, init);
12801
12564
  }
12802
12565
  deoptimizePath(path) {
12803
12566
  if (path.length === 0) {
@@ -12807,17 +12570,6 @@ class AssignmentPattern extends NodeBase {
12807
12570
  hasEffectsOnInteractionAtPath(path, interaction, context) {
12808
12571
  return (path.length > 0 || this.left.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
12809
12572
  }
12810
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
12811
- return this.left.hasEffectsWhenDestructuring(context, destructuredInitPath, init);
12812
- }
12813
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
12814
- let included = this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init) ||
12815
- this.included;
12816
- if ((included ||= this.right.shouldBeIncluded(context))) {
12817
- this.right.includePath(UNKNOWN_PATH, context, false);
12818
- }
12819
- return (this.included = included);
12820
- }
12821
12573
  markDeclarationReached() {
12822
12574
  this.left.markDeclarationReached();
12823
12575
  }
@@ -12839,7 +12591,7 @@ class AwaitExpression extends NodeBase {
12839
12591
  this.applyDeoptimizations();
12840
12592
  return true;
12841
12593
  }
12842
- includePath(path, context, includeChildrenRecursively) {
12594
+ include(context, includeChildrenRecursively) {
12843
12595
  if (!this.deoptimized)
12844
12596
  this.applyDeoptimizations();
12845
12597
  if (!this.included) {
@@ -12853,7 +12605,7 @@ class AwaitExpression extends NodeBase {
12853
12605
  this.scope.context.usesTopLevelAwait = true;
12854
12606
  }
12855
12607
  }
12856
- this.argument.includePath(path, context, includeChildrenRecursively);
12608
+ this.argument.include(context, includeChildrenRecursively);
12857
12609
  }
12858
12610
  }
12859
12611
 
@@ -12935,10 +12687,10 @@ class BreakStatement extends NodeBase {
12935
12687
  context.brokenFlow = true;
12936
12688
  return false;
12937
12689
  }
12938
- includePath(_, context) {
12690
+ include(context) {
12939
12691
  this.included = true;
12940
12692
  if (this.label) {
12941
- this.label.includePath(UNKNOWN_PATH, createInclusionContext());
12693
+ this.label.include();
12942
12694
  context.includedLabels.add(this.label.name);
12943
12695
  }
12944
12696
  else {
@@ -13132,11 +12884,11 @@ class CallExpression extends CallExpressionBase {
13132
12884
  (calleeHasEffects ||
13133
12885
  this.callee.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context)));
13134
12886
  }
13135
- includePath(path, context, includeChildrenRecursively) {
12887
+ include(context, includeChildrenRecursively) {
13136
12888
  if (!this.deoptimized)
13137
12889
  this.applyDeoptimizations();
13138
12890
  if (includeChildrenRecursively) {
13139
- super.includePath(path, context, includeChildrenRecursively);
12891
+ super.include(context, includeChildrenRecursively);
13140
12892
  if (includeChildrenRecursively === INCLUDE_PARAMETERS &&
13141
12893
  this.callee instanceof Identifier &&
13142
12894
  this.callee.variable) {
@@ -13145,18 +12897,9 @@ class CallExpression extends CallExpressionBase {
13145
12897
  }
13146
12898
  else {
13147
12899
  this.included = true;
13148
- // If the callee is a member expression and does not have a variable, its
13149
- // object will already be included via the first argument of the
13150
- // interaction in includeCallArguments. Including it again can lead to
13151
- // severe performance problems.
13152
- if (this.callee instanceof MemberExpression && !this.callee.variable) {
13153
- this.callee.property.includePath(UNKNOWN_PATH, context, false);
13154
- }
13155
- else {
13156
- this.callee.includePath(UNKNOWN_PATH, context, false);
13157
- }
13158
- this.callee.includeCallArguments(context, this.interaction);
12900
+ this.callee.include(context, false);
13159
12901
  }
12902
+ this.callee.includeCallArguments(context, this.arguments);
13160
12903
  }
13161
12904
  initialise() {
13162
12905
  super.initialise();
@@ -13195,7 +12938,7 @@ class CatchClause extends NodeBase {
13195
12938
  this.type = type;
13196
12939
  if (param) {
13197
12940
  this.param = new (this.scope.context.getNodeConstructor(param.type))(this, this.scope).parseNode(param);
13198
- this.param.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
12941
+ this.param.declare('parameter', UNKNOWN_EXPRESSION);
13199
12942
  }
13200
12943
  this.body = new BlockStatement(this, this.scope.bodyScope).parseNode(body);
13201
12944
  return super.parseNode(esTreeNode);
@@ -13223,7 +12966,7 @@ class ClassBodyScope extends ChildScope {
13223
12966
  constructor(parent, classNode) {
13224
12967
  const { context } = parent;
13225
12968
  super(parent, context);
13226
- 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')));
13227
12970
  this.instanceScope = new ChildScope(this, context);
13228
12971
  this.instanceScope.variables.set('this', new ThisVariable(context));
13229
12972
  }
@@ -13236,11 +12979,11 @@ class ClassBody extends NodeBase {
13236
12979
  createScope(parentScope) {
13237
12980
  this.scope = new ClassBodyScope(parentScope, this.parent);
13238
12981
  }
13239
- includePath(_path, context, includeChildrenRecursively) {
12982
+ include(context, includeChildrenRecursively) {
13240
12983
  this.included = true;
13241
- this.scope.context.includeVariableInModule(this.scope.thisVariable, UNKNOWN_PATH);
12984
+ this.scope.context.includeVariableInModule(this.scope.thisVariable);
13242
12985
  for (const definition of this.body) {
13243
- definition.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12986
+ definition.include(context, includeChildrenRecursively);
13244
12987
  }
13245
12988
  }
13246
12989
  parseNode(esTreeNode) {
@@ -13364,26 +13107,26 @@ class ConditionalExpression extends NodeBase {
13364
13107
  }
13365
13108
  return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
13366
13109
  }
13367
- includePath(path, context, includeChildrenRecursively) {
13110
+ include(context, includeChildrenRecursively) {
13368
13111
  this.included = true;
13369
13112
  const usedBranch = this.getUsedBranch();
13370
13113
  if (includeChildrenRecursively || this.test.shouldBeIncluded(context) || usedBranch === null) {
13371
- this.test.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13372
- this.consequent.includePath(path, context, includeChildrenRecursively);
13373
- this.alternate.includePath(path, context, includeChildrenRecursively);
13114
+ this.test.include(context, includeChildrenRecursively);
13115
+ this.consequent.include(context, includeChildrenRecursively);
13116
+ this.alternate.include(context, includeChildrenRecursively);
13374
13117
  }
13375
13118
  else {
13376
- usedBranch.includePath(path, context, includeChildrenRecursively);
13119
+ usedBranch.include(context, includeChildrenRecursively);
13377
13120
  }
13378
13121
  }
13379
- includeCallArguments(context, interaction) {
13122
+ includeCallArguments(context, parameters) {
13380
13123
  const usedBranch = this.getUsedBranch();
13381
13124
  if (usedBranch) {
13382
- usedBranch.includeCallArguments(context, interaction);
13125
+ usedBranch.includeCallArguments(context, parameters);
13383
13126
  }
13384
13127
  else {
13385
- this.consequent.includeCallArguments(context, interaction);
13386
- this.alternate.includeCallArguments(context, interaction);
13128
+ this.consequent.includeCallArguments(context, parameters);
13129
+ this.alternate.includeCallArguments(context, parameters);
13387
13130
  }
13388
13131
  }
13389
13132
  removeAnnotations(code) {
@@ -13444,10 +13187,10 @@ class ContinueStatement extends NodeBase {
13444
13187
  context.brokenFlow = true;
13445
13188
  return false;
13446
13189
  }
13447
- includePath(_, context) {
13190
+ include(context) {
13448
13191
  this.included = true;
13449
13192
  if (this.label) {
13450
- this.label.includePath(UNKNOWN_PATH, createInclusionContext());
13193
+ this.label.include();
13451
13194
  context.includedLabels.add(this.label.name);
13452
13195
  }
13453
13196
  else {
@@ -13490,7 +13233,7 @@ function includeLoopBody(context, body, includeChildrenRecursively) {
13490
13233
  const { brokenFlow, hasBreak, hasContinue } = context;
13491
13234
  context.hasBreak = false;
13492
13235
  context.hasContinue = false;
13493
- body.includePath(UNKNOWN_PATH, context, includeChildrenRecursively, { asSingleStatement: true });
13236
+ body.include(context, includeChildrenRecursively, { asSingleStatement: true });
13494
13237
  context.hasBreak = hasBreak;
13495
13238
  context.hasContinue = hasContinue;
13496
13239
  context.brokenFlow = brokenFlow;
@@ -13502,9 +13245,9 @@ class DoWhileStatement extends NodeBase {
13502
13245
  return true;
13503
13246
  return hasLoopBodyEffects(context, this.body);
13504
13247
  }
13505
- includePath(_path, context, includeChildrenRecursively) {
13248
+ include(context, includeChildrenRecursively) {
13506
13249
  this.included = true;
13507
- this.test.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13250
+ this.test.include(context, includeChildrenRecursively);
13508
13251
  includeLoopBody(context, this.body, includeChildrenRecursively);
13509
13252
  }
13510
13253
  }
@@ -13575,13 +13318,13 @@ class ForInStatement extends NodeBase {
13575
13318
  return true;
13576
13319
  return hasLoopBodyEffects(context, body);
13577
13320
  }
13578
- includePath(_path, context, includeChildrenRecursively) {
13321
+ include(context, includeChildrenRecursively) {
13579
13322
  const { body, deoptimized, left, right } = this;
13580
13323
  if (!deoptimized)
13581
13324
  this.applyDeoptimizations();
13582
13325
  this.included = true;
13583
13326
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
13584
- right.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13327
+ right.include(context, includeChildrenRecursively);
13585
13328
  includeLoopBody(context, body, includeChildrenRecursively);
13586
13329
  }
13587
13330
  initialise() {
@@ -13620,13 +13363,13 @@ class ForOfStatement extends NodeBase {
13620
13363
  // Placeholder until proper Symbol.Iterator support
13621
13364
  return true;
13622
13365
  }
13623
- includePath(_path, context, includeChildrenRecursively) {
13366
+ include(context, includeChildrenRecursively) {
13624
13367
  const { body, deoptimized, left, right } = this;
13625
13368
  if (!deoptimized)
13626
13369
  this.applyDeoptimizations();
13627
13370
  this.included = true;
13628
13371
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
13629
- right.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13372
+ right.include(context, includeChildrenRecursively);
13630
13373
  includeLoopBody(context, body, includeChildrenRecursively);
13631
13374
  }
13632
13375
  initialise() {
@@ -13662,13 +13405,11 @@ class ForStatement extends NodeBase {
13662
13405
  }
13663
13406
  return hasLoopBodyEffects(context, this.body);
13664
13407
  }
13665
- includePath(_path, context, includeChildrenRecursively) {
13408
+ include(context, includeChildrenRecursively) {
13666
13409
  this.included = true;
13667
- this.init?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively, {
13668
- asSingleStatement: true
13669
- });
13670
- this.test?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13671
- 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);
13672
13413
  includeLoopBody(context, this.body, includeChildrenRecursively);
13673
13414
  }
13674
13415
  render(code, options) {
@@ -13709,9 +13450,9 @@ class TrackingScope extends BlockScope {
13709
13450
  super(...arguments);
13710
13451
  this.hoistedDeclarations = [];
13711
13452
  }
13712
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
13453
+ addDeclaration(identifier, context, init, kind) {
13713
13454
  this.hoistedDeclarations.push(identifier);
13714
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
13455
+ return super.addDeclaration(identifier, context, init, kind);
13715
13456
  }
13716
13457
  }
13717
13458
 
@@ -13744,7 +13485,7 @@ class IfStatement extends NodeBase {
13744
13485
  }
13745
13486
  return testValue ? this.consequent.hasEffects(context) : !!this.alternate?.hasEffects(context);
13746
13487
  }
13747
- includePath(_, context, includeChildrenRecursively) {
13488
+ include(context, includeChildrenRecursively) {
13748
13489
  this.included = true;
13749
13490
  if (includeChildrenRecursively) {
13750
13491
  this.includeRecursively(includeChildrenRecursively, context);
@@ -13819,31 +13560,31 @@ class IfStatement extends NodeBase {
13819
13560
  }
13820
13561
  includeKnownTest(context, testValue) {
13821
13562
  if (this.test.shouldBeIncluded(context)) {
13822
- this.test.includePath(UNKNOWN_PATH, context, false);
13563
+ this.test.include(context, false);
13823
13564
  }
13824
13565
  if (testValue && this.consequent.shouldBeIncluded(context)) {
13825
- this.consequent.includePath(UNKNOWN_PATH, context, false, { asSingleStatement: true });
13566
+ this.consequent.include(context, false, { asSingleStatement: true });
13826
13567
  }
13827
13568
  if (!testValue && this.alternate?.shouldBeIncluded(context)) {
13828
- this.alternate.includePath(UNKNOWN_PATH, context, false, { asSingleStatement: true });
13569
+ this.alternate.include(context, false, { asSingleStatement: true });
13829
13570
  }
13830
13571
  }
13831
13572
  includeRecursively(includeChildrenRecursively, context) {
13832
- this.test.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13833
- this.consequent.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13834
- 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);
13835
13576
  }
13836
13577
  includeUnknownTest(context) {
13837
- this.test.includePath(UNKNOWN_PATH, context, false);
13578
+ this.test.include(context, false);
13838
13579
  const { brokenFlow } = context;
13839
13580
  let consequentBrokenFlow = false;
13840
13581
  if (this.consequent.shouldBeIncluded(context)) {
13841
- this.consequent.includePath(UNKNOWN_PATH, context, false, { asSingleStatement: true });
13582
+ this.consequent.include(context, false, { asSingleStatement: true });
13842
13583
  consequentBrokenFlow = context.brokenFlow;
13843
13584
  context.brokenFlow = brokenFlow;
13844
13585
  }
13845
13586
  if (this.alternate?.shouldBeIncluded(context)) {
13846
- this.alternate.includePath(UNKNOWN_PATH, context, false, { asSingleStatement: true });
13587
+ this.alternate.include(context, false, { asSingleStatement: true });
13847
13588
  context.brokenFlow = context.brokenFlow && consequentBrokenFlow;
13848
13589
  }
13849
13590
  }
@@ -13911,7 +13652,7 @@ function isReassignedExportsMember(variable, exportNamesByVariable) {
13911
13652
  class VariableDeclarator extends NodeBase {
13912
13653
  declareDeclarator(kind, isUsingDeclaration) {
13913
13654
  this.isUsingDeclaration = isUsingDeclaration;
13914
- this.id.declare(kind, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION);
13655
+ this.id.declare(kind, this.init || UNDEFINED_EXPRESSION);
13915
13656
  }
13916
13657
  deoptimizePath(path) {
13917
13658
  this.id.deoptimizePath(path);
@@ -13921,25 +13662,17 @@ class VariableDeclarator extends NodeBase {
13921
13662
  this.applyDeoptimizations();
13922
13663
  const initEffect = this.init?.hasEffects(context);
13923
13664
  this.id.markDeclarationReached();
13924
- return (initEffect ||
13925
- this.isUsingDeclaration ||
13926
- this.id.hasEffects(context) ||
13927
- (this.scope.context.options.treeshake
13928
- .propertyReadSideEffects &&
13929
- this.id.hasEffectsWhenDestructuring(context, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION)));
13930
- }
13931
- includePath(_path, context, includeChildrenRecursively) {
13665
+ return initEffect || this.id.hasEffects(context) || this.isUsingDeclaration;
13666
+ }
13667
+ include(context, includeChildrenRecursively) {
13932
13668
  const { deoptimized, id, init } = this;
13933
13669
  if (!deoptimized)
13934
13670
  this.applyDeoptimizations();
13935
13671
  this.included = true;
13936
- init?.includePath(EMPTY_PATH, context, includeChildrenRecursively);
13672
+ init?.include(context, includeChildrenRecursively);
13937
13673
  id.markDeclarationReached();
13938
- if (includeChildrenRecursively) {
13939
- id.includePath(EMPTY_PATH, context, includeChildrenRecursively);
13940
- }
13941
- else {
13942
- id.includeDestructuredIfNecessary(context, EMPTY_PATH, init || UNDEFINED_EXPRESSION);
13674
+ if (includeChildrenRecursively || id.shouldBeIncluded(context)) {
13675
+ id.include(context, includeChildrenRecursively);
13943
13676
  }
13944
13677
  }
13945
13678
  removeAnnotations(code) {
@@ -13988,8 +13721,6 @@ class ImportExpression extends NodeBase {
13988
13721
  constructor() {
13989
13722
  super(...arguments);
13990
13723
  this.inlineNamespace = null;
13991
- this.hasUnknownAccessedKey = false;
13992
- this.accessedPropKey = new Set();
13993
13724
  this.attributes = null;
13994
13725
  this.mechanism = null;
13995
13726
  this.namespaceExportName = undefined;
@@ -14022,15 +13753,12 @@ class ImportExpression extends NodeBase {
14022
13753
  if (parent2 instanceof ExpressionStatement) {
14023
13754
  return parseAst_js.EMPTY_ARRAY;
14024
13755
  }
14025
- // Case 1: const { foo } / module = await import('bar')
13756
+ // Case 1: const { foo } = await import('bar')
14026
13757
  if (parent2 instanceof VariableDeclarator) {
14027
13758
  const declaration = parent2.id;
14028
- if (declaration instanceof Identifier) {
14029
- return this.hasUnknownAccessedKey ? undefined : [...this.accessedPropKey];
14030
- }
14031
- if (declaration instanceof ObjectPattern) {
14032
- return getDeterministicObjectDestructure(declaration);
14033
- }
13759
+ return declaration instanceof ObjectPattern
13760
+ ? getDeterministicObjectDestructure(declaration)
13761
+ : undefined;
14034
13762
  }
14035
13763
  // Case 2: (await import('bar')).foo
14036
13764
  if (parent2 instanceof MemberExpression) {
@@ -14079,23 +13807,13 @@ class ImportExpression extends NodeBase {
14079
13807
  hasEffects() {
14080
13808
  return true;
14081
13809
  }
14082
- includePath(path, context, includeChildrenRecursively) {
13810
+ include(context, includeChildrenRecursively) {
14083
13811
  if (!this.included) {
14084
13812
  this.included = true;
14085
13813
  this.scope.context.includeDynamicImport(this);
14086
13814
  this.scope.addAccessedDynamicImport(this);
14087
- this.source.includePath(path, context, includeChildrenRecursively);
14088
- }
14089
- if (this.hasUnknownAccessedKey)
14090
- return;
14091
- if (path[0] === UnknownKey) {
14092
- this.hasUnknownAccessedKey = true;
14093
- this.scope.context.includeDynamicImport(this);
14094
- }
14095
- else if (typeof path[0] === 'string') {
14096
- this.accessedPropKey.add(path[0]);
14097
- this.scope.context.includeDynamicImport(this);
14098
13815
  }
13816
+ this.source.include(context, includeChildrenRecursively);
14099
13817
  }
14100
13818
  initialise() {
14101
13819
  super.initialise();
@@ -14423,7 +14141,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node) {
14423
14141
  if (preserve) {
14424
14142
  // This pretends we are accessing an included global variable of the same name
14425
14143
  const globalVariable = node.scope.findGlobal(baseName);
14426
- globalVariable.includePath(UNKNOWN_PATH, createInclusionContext());
14144
+ globalVariable.include();
14427
14145
  // This excludes this variable from renaming
14428
14146
  factoryVariable.globalName = baseName;
14429
14147
  }
@@ -14431,7 +14149,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node) {
14431
14149
  else {
14432
14150
  factoryVariable = node.scope.findGlobal(baseName);
14433
14151
  }
14434
- node.scope.context.includeVariableInModule(factoryVariable, UNKNOWN_PATH);
14152
+ node.scope.context.includeVariableInModule(factoryVariable);
14435
14153
  if (factoryVariable instanceof LocalVariable) {
14436
14154
  factoryVariable.consolidateInitializers();
14437
14155
  factoryVariable.addUsedPlace(node);
@@ -14453,7 +14171,7 @@ class JSXElementBase extends NodeBase {
14453
14171
  this.scope.context.addImportSource(importSource);
14454
14172
  }
14455
14173
  }
14456
- includePath(path, context, includeChildrenRecursively) {
14174
+ include(context, includeChildrenRecursively) {
14457
14175
  if (!this.included) {
14458
14176
  const { factory, importSource, mode } = this.jsxMode;
14459
14177
  if (factory) {
@@ -14461,7 +14179,7 @@ class JSXElementBase extends NodeBase {
14461
14179
  this.factoryVariable = getAndIncludeFactoryVariable(factory, mode === 'preserve', importSource, this);
14462
14180
  }
14463
14181
  }
14464
- super.includePath(path, context, includeChildrenRecursively);
14182
+ super.include(context, includeChildrenRecursively);
14465
14183
  }
14466
14184
  applyDeoptimizations() { }
14467
14185
  getRenderingMode() {
@@ -14723,7 +14441,7 @@ class JSXOpeningFragment extends NodeBase {
14723
14441
  this.fragment = null;
14724
14442
  this.fragmentVariable = null;
14725
14443
  }
14726
- includePath(path, context, includeChildrenRecursively) {
14444
+ include(context, includeChildrenRecursively) {
14727
14445
  if (!this.included) {
14728
14446
  const jsx = this.scope.context.options.jsx;
14729
14447
  if (jsx.mode === 'automatic') {
@@ -14738,7 +14456,7 @@ class JSXOpeningFragment extends NodeBase {
14738
14456
  }
14739
14457
  }
14740
14458
  }
14741
- super.includePath(path, context, includeChildrenRecursively);
14459
+ super.include(context, includeChildrenRecursively);
14742
14460
  }
14743
14461
  render(code, options) {
14744
14462
  const { mode } = this.scope.context.options.jsx;
@@ -14795,13 +14513,13 @@ class LabeledStatement extends NodeBase {
14795
14513
  context.includedLabels = new Set([...includedLabels, ...context.includedLabels]);
14796
14514
  return bodyHasEffects;
14797
14515
  }
14798
- includePath(_path, context, includeChildrenRecursively) {
14516
+ include(context, includeChildrenRecursively) {
14799
14517
  this.included = true;
14800
14518
  const { brokenFlow, includedLabels } = context;
14801
14519
  context.includedLabels = new Set();
14802
- this.body.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
14520
+ this.body.include(context, includeChildrenRecursively);
14803
14521
  if (includeChildrenRecursively || context.includedLabels.has(this.label.name)) {
14804
- this.label.includePath(UNKNOWN_PATH, createInclusionContext());
14522
+ this.label.include();
14805
14523
  context.includedLabels.delete(this.label.name);
14806
14524
  context.brokenFlow = brokenFlow;
14807
14525
  }
@@ -14898,17 +14616,17 @@ class LogicalExpression extends NodeBase {
14898
14616
  }
14899
14617
  return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
14900
14618
  }
14901
- includePath(path, context, includeChildrenRecursively) {
14619
+ include(context, includeChildrenRecursively) {
14902
14620
  this.included = true;
14903
14621
  const usedBranch = this.getUsedBranch();
14904
14622
  if (includeChildrenRecursively ||
14905
14623
  (usedBranch === this.right && this.left.shouldBeIncluded(context)) ||
14906
14624
  !usedBranch) {
14907
- this.left.includePath(path, context, includeChildrenRecursively);
14908
- this.right.includePath(path, context, includeChildrenRecursively);
14625
+ this.left.include(context, includeChildrenRecursively);
14626
+ this.right.include(context, includeChildrenRecursively);
14909
14627
  }
14910
14628
  else {
14911
- usedBranch.includePath(path, context, includeChildrenRecursively);
14629
+ usedBranch.include(context, includeChildrenRecursively);
14912
14630
  }
14913
14631
  }
14914
14632
  removeAnnotations(code) {
@@ -14980,17 +14698,17 @@ class NewExpression extends NodeBase {
14980
14698
  hasEffectsOnInteractionAtPath(path, { type }) {
14981
14699
  return path.length > 0 || type !== INTERACTION_ACCESSED;
14982
14700
  }
14983
- includePath(path, context, includeChildrenRecursively) {
14701
+ include(context, includeChildrenRecursively) {
14984
14702
  if (!this.deoptimized)
14985
14703
  this.applyDeoptimizations();
14986
14704
  if (includeChildrenRecursively) {
14987
- super.includePath(path, context, includeChildrenRecursively);
14705
+ super.include(context, includeChildrenRecursively);
14988
14706
  }
14989
14707
  else {
14990
14708
  this.included = true;
14991
- this.callee.includePath(UNKNOWN_PATH, context, false);
14709
+ this.callee.include(context, false);
14992
14710
  }
14993
- this.callee.includeCallArguments(context, this.interaction);
14711
+ this.callee.includeCallArguments(context, this.arguments);
14994
14712
  }
14995
14713
  initialise() {
14996
14714
  super.initialise();
@@ -15019,7 +14737,6 @@ class ObjectExpression extends NodeBase {
15019
14737
  constructor() {
15020
14738
  super(...arguments);
15021
14739
  this.objectEntity = null;
15022
- this.protoProp = null;
15023
14740
  }
15024
14741
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
15025
14742
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -15039,32 +14756,13 @@ class ObjectExpression extends NodeBase {
15039
14756
  hasEffectsOnInteractionAtPath(path, interaction, context) {
15040
14757
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
15041
14758
  }
15042
- includePath(path, context, includeChildrenRecursively) {
15043
- this.included = true;
15044
- this.getObjectEntity().includePath(path, context, includeChildrenRecursively);
15045
- this.protoProp?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15046
- }
15047
14759
  render(code, options, { renderedSurroundingElement } = parseAst_js.BLANK) {
14760
+ super.render(code, options);
15048
14761
  if (renderedSurroundingElement === parseAst_js.ExpressionStatement ||
15049
14762
  renderedSurroundingElement === parseAst_js.ArrowFunctionExpression) {
15050
14763
  code.appendRight(this.start, '(');
15051
14764
  code.prependLeft(this.end, ')');
15052
14765
  }
15053
- if (this.properties.length > 0) {
15054
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
15055
- let lastSeparatorPos = null;
15056
- for (const { node, separator, start, end } of separatedNodes) {
15057
- if (!node.included) {
15058
- treeshakeNode(node, code, start, end);
15059
- continue;
15060
- }
15061
- lastSeparatorPos = separator;
15062
- node.render(code, options);
15063
- }
15064
- if (lastSeparatorPos) {
15065
- code.remove(lastSeparatorPos, this.end - 1);
15066
- }
15067
- }
15068
14766
  }
15069
14767
  applyDeoptimizations() { }
15070
14768
  getObjectEntity() {
@@ -15095,7 +14793,6 @@ class ObjectExpression extends NodeBase {
15095
14793
  ? property.key.name
15096
14794
  : String(property.key.value);
15097
14795
  if (key === '__proto__' && property.kind === 'init') {
15098
- this.protoProp = property;
15099
14796
  prototype =
15100
14797
  property.value instanceof Literal && property.value.value === null
15101
14798
  ? null
@@ -15162,11 +14859,11 @@ class Program extends NodeBase {
15162
14859
  }
15163
14860
  return false;
15164
14861
  }
15165
- includePath(_path, context, includeChildrenRecursively) {
14862
+ include(context, includeChildrenRecursively) {
15166
14863
  this.included = true;
15167
14864
  for (const node of this.body) {
15168
14865
  if (includeChildrenRecursively || node.shouldBeIncluded(context)) {
15169
- node.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
14866
+ node.include(context, includeChildrenRecursively);
15170
14867
  }
15171
14868
  }
15172
14869
  }
@@ -15205,6 +14902,10 @@ class Program extends NodeBase {
15205
14902
  }
15206
14903
 
15207
14904
  class Property extends MethodBase {
14905
+ constructor() {
14906
+ super(...arguments);
14907
+ this.declarationInit = null;
14908
+ }
15208
14909
  //declare method: boolean;
15209
14910
  get method() {
15210
14911
  return isFlagSet(this.flags, 262144 /* Flag.method */);
@@ -15219,32 +14920,17 @@ class Property extends MethodBase {
15219
14920
  set shorthand(value) {
15220
14921
  this.flags = setFlag(this.flags, 524288 /* Flag.shorthand */, value);
15221
14922
  }
15222
- declare(kind, destructuredInitPath, init) {
15223
- return this.value.declare(kind, this.getPathInProperty(destructuredInitPath), init);
15224
- }
15225
- deoptimizeAssignment(destructuredInitPath, init) {
15226
- this.value.deoptimizeAssignment?.(this.getPathInProperty(destructuredInitPath), init);
14923
+ declare(kind, init) {
14924
+ this.declarationInit = init;
14925
+ return this.value.declare(kind, UNKNOWN_EXPRESSION);
15227
14926
  }
15228
14927
  hasEffects(context) {
15229
14928
  if (!this.deoptimized)
15230
14929
  this.applyDeoptimizations();
15231
- return this.key.hasEffects(context) || this.value.hasEffects(context);
15232
- }
15233
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
15234
- return this.value.hasEffectsWhenDestructuring?.(context, this.getPathInProperty(destructuredInitPath), init);
15235
- }
15236
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
15237
- let included = this.value.includeDestructuredIfNecessary(context, this.getPathInProperty(destructuredInitPath), init) || this.included;
15238
- included ||= this.key.hasEffects(createHasEffectsContext());
15239
- if (included) {
15240
- this.key.includePath(EMPTY_PATH, context, false);
15241
- }
15242
- return (this.included = included);
15243
- }
15244
- includePath(path, context, includeChildrenRecursively) {
15245
- this.included = true;
15246
- this.key.includePath(EMPTY_PATH, context, includeChildrenRecursively);
15247
- 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));
15248
14934
  }
15249
14935
  markDeclarationReached() {
15250
14936
  this.value.markDeclarationReached();
@@ -15255,17 +14941,12 @@ class Property extends MethodBase {
15255
14941
  }
15256
14942
  this.value.render(code, options, { isShorthandProperty: this.shorthand });
15257
14943
  }
15258
- applyDeoptimizations() { }
15259
- getPathInProperty(destructuredInitPath) {
15260
- return destructuredInitPath.at(-1) === UnknownKey
15261
- ? destructuredInitPath
15262
- : // For now, we only consider static paths as we do not know how to
15263
- // deoptimize the path in the dynamic case.
15264
- this.computed
15265
- ? [...destructuredInitPath, UnknownKey]
15266
- : this.key instanceof Identifier
15267
- ? [...destructuredInitPath, this.key.name]
15268
- : [...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
+ }
15269
14950
  }
15270
14951
  }
15271
14952
 
@@ -15310,9 +14991,9 @@ class ReturnStatement extends NodeBase {
15310
14991
  context.brokenFlow = true;
15311
14992
  return false;
15312
14993
  }
15313
- includePath(_path, context, includeChildrenRecursively) {
14994
+ include(context, includeChildrenRecursively) {
15314
14995
  this.included = true;
15315
- this.argument?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
14996
+ this.argument?.include(context, includeChildrenRecursively);
15316
14997
  context.brokenFlow = true;
15317
14998
  }
15318
14999
  initialise() {
@@ -15349,14 +15030,14 @@ class SequenceExpression extends NodeBase {
15349
15030
  hasEffectsOnInteractionAtPath(path, interaction, context) {
15350
15031
  return this.expressions[this.expressions.length - 1].hasEffectsOnInteractionAtPath(path, interaction, context);
15351
15032
  }
15352
- includePath(path, context, includeChildrenRecursively) {
15033
+ include(context, includeChildrenRecursively) {
15353
15034
  this.included = true;
15354
15035
  const lastExpression = this.expressions[this.expressions.length - 1];
15355
15036
  for (const expression of this.expressions) {
15356
15037
  if (includeChildrenRecursively ||
15357
15038
  (expression === lastExpression && !(this.parent instanceof ExpressionStatement)) ||
15358
15039
  expression.shouldBeIncluded(context))
15359
- expression.includePath(path, context, includeChildrenRecursively);
15040
+ expression.include(context, includeChildrenRecursively);
15360
15041
  }
15361
15042
  }
15362
15043
  removeAnnotations(code) {
@@ -15404,13 +15085,10 @@ class Super extends NodeBase {
15404
15085
  deoptimizePath(path) {
15405
15086
  this.variable.deoptimizePath(path);
15406
15087
  }
15407
- includePath(path, context) {
15088
+ include() {
15408
15089
  if (!this.included) {
15409
15090
  this.included = true;
15410
- this.scope.context.includeVariableInModule(this.variable, path);
15411
- }
15412
- else if (path.length > 0) {
15413
- this.variable.includePath(path, context);
15091
+ this.scope.context.includeVariableInModule(this.variable);
15414
15092
  }
15415
15093
  }
15416
15094
  }
@@ -15427,12 +15105,12 @@ class SwitchCase extends NodeBase {
15427
15105
  }
15428
15106
  return false;
15429
15107
  }
15430
- includePath(_path, context, includeChildrenRecursively) {
15108
+ include(context, includeChildrenRecursively) {
15431
15109
  this.included = true;
15432
- this.test?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15110
+ this.test?.include(context, includeChildrenRecursively);
15433
15111
  for (const node of this.consequent) {
15434
15112
  if (includeChildrenRecursively || node.shouldBeIncluded(context))
15435
- node.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15113
+ node.include(context, includeChildrenRecursively);
15436
15114
  }
15437
15115
  }
15438
15116
  render(code, options, nodeRenderOptions) {
@@ -15480,9 +15158,9 @@ class SwitchStatement extends NodeBase {
15480
15158
  context.hasBreak = hasBreak;
15481
15159
  return false;
15482
15160
  }
15483
- includePath(_path, context, includeChildrenRecursively) {
15161
+ include(context, includeChildrenRecursively) {
15484
15162
  this.included = true;
15485
- this.discriminant.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15163
+ this.discriminant.include(context, includeChildrenRecursively);
15486
15164
  const { brokenFlow, hasBreak } = context;
15487
15165
  context.hasBreak = false;
15488
15166
  let onlyHasBrokenFlow = true;
@@ -15499,7 +15177,7 @@ class SwitchStatement extends NodeBase {
15499
15177
  isCaseIncluded = switchCase.hasEffects(hasEffectsContext);
15500
15178
  }
15501
15179
  if (isCaseIncluded) {
15502
- switchCase.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15180
+ switchCase.include(context, includeChildrenRecursively);
15503
15181
  onlyHasBrokenFlow &&= context.brokenFlow && !context.hasBreak;
15504
15182
  context.hasBreak = false;
15505
15183
  context.brokenFlow = brokenFlow;
@@ -15556,21 +15234,21 @@ class TaggedTemplateExpression extends CallExpressionBase {
15556
15234
  return (this.tag.hasEffects(context) ||
15557
15235
  this.tag.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context));
15558
15236
  }
15559
- includePath(path, context, includeChildrenRecursively) {
15237
+ include(context, includeChildrenRecursively) {
15560
15238
  if (!this.deoptimized)
15561
15239
  this.applyDeoptimizations();
15562
15240
  if (includeChildrenRecursively) {
15563
- super.includePath(path, context, includeChildrenRecursively);
15241
+ super.include(context, includeChildrenRecursively);
15564
15242
  }
15565
15243
  else {
15566
15244
  this.included = true;
15567
- this.tag.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15568
- this.quasi.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15245
+ this.tag.include(context, includeChildrenRecursively);
15246
+ this.quasi.include(context, includeChildrenRecursively);
15569
15247
  }
15570
- this.tag.includeCallArguments(context, this.interaction);
15248
+ this.tag.includeCallArguments(context, this.args);
15571
15249
  const [returnExpression] = this.getReturnExpression();
15572
15250
  if (!returnExpression.included) {
15573
- returnExpression.includePath(UNKNOWN_PATH, context, false);
15251
+ returnExpression.include(context, false);
15574
15252
  }
15575
15253
  }
15576
15254
  initialise() {
@@ -15615,7 +15293,7 @@ class TemplateElement extends NodeBase {
15615
15293
  hasEffects() {
15616
15294
  return false;
15617
15295
  }
15618
- includePath() {
15296
+ include() {
15619
15297
  this.included = true;
15620
15298
  }
15621
15299
  parseNode(esTreeNode) {
@@ -15657,13 +15335,13 @@ class TemplateLiteral extends NodeBase {
15657
15335
  class ModuleScope extends ChildScope {
15658
15336
  constructor(parent, context) {
15659
15337
  super(parent, context);
15660
- 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'));
15661
15339
  }
15662
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
15340
+ addDeclaration(identifier, context, init, kind) {
15663
15341
  if (this.context.module.importDescriptions.has(identifier.name)) {
15664
15342
  context.error(parseAst_js.logRedeclarationError(identifier.name), identifier.start);
15665
15343
  }
15666
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
15344
+ return super.addDeclaration(identifier, context, init, kind);
15667
15345
  }
15668
15346
  addExportDefaultDeclaration(name, exportDefaultDeclaration, context) {
15669
15347
  const variable = new ExportDefaultVariable(name, exportDefaultDeclaration, context);
@@ -15708,13 +15386,10 @@ class ThisExpression extends NodeBase {
15708
15386
  }
15709
15387
  return this.variable.hasEffectsOnInteractionAtPath(path, interaction, context);
15710
15388
  }
15711
- includePath(path, context) {
15389
+ include() {
15712
15390
  if (!this.included) {
15713
15391
  this.included = true;
15714
- this.scope.context.includeVariableInModule(this.variable, path);
15715
- }
15716
- else if (path.length > 0) {
15717
- this.variable.includePath(path, context);
15392
+ this.scope.context.includeVariableInModule(this.variable);
15718
15393
  }
15719
15394
  }
15720
15395
  initialise() {
@@ -15741,9 +15416,9 @@ class ThrowStatement extends NodeBase {
15741
15416
  hasEffects() {
15742
15417
  return true;
15743
15418
  }
15744
- includePath(_path, context, includeChildrenRecursively) {
15419
+ include(context, includeChildrenRecursively) {
15745
15420
  this.included = true;
15746
- this.argument.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15421
+ this.argument.include(context, includeChildrenRecursively);
15747
15422
  context.brokenFlow = true;
15748
15423
  }
15749
15424
  render(code, options) {
@@ -15765,13 +15440,13 @@ class TryStatement extends NodeBase {
15765
15440
  ? this.block.body.length > 0
15766
15441
  : this.block.hasEffects(context)) || !!this.finalizer?.hasEffects(context));
15767
15442
  }
15768
- includePath(_path, context, includeChildrenRecursively) {
15443
+ include(context, includeChildrenRecursively) {
15769
15444
  const tryCatchDeoptimization = this.scope.context.options.treeshake?.tryCatchDeoptimization;
15770
15445
  const { brokenFlow, includedLabels } = context;
15771
15446
  if (!this.directlyIncluded || !tryCatchDeoptimization) {
15772
15447
  this.included = true;
15773
15448
  this.directlyIncluded = true;
15774
- this.block.includePath(UNKNOWN_PATH, context, tryCatchDeoptimization ? INCLUDE_PARAMETERS : includeChildrenRecursively);
15449
+ this.block.include(context, tryCatchDeoptimization ? INCLUDE_PARAMETERS : includeChildrenRecursively);
15775
15450
  if (includedLabels.size > 0) {
15776
15451
  this.includedLabelsAfterBlock = [...includedLabels];
15777
15452
  }
@@ -15783,10 +15458,10 @@ class TryStatement extends NodeBase {
15783
15458
  }
15784
15459
  }
15785
15460
  if (this.handler !== null) {
15786
- this.handler.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15461
+ this.handler.include(context, includeChildrenRecursively);
15787
15462
  context.brokenFlow = brokenFlow;
15788
15463
  }
15789
- this.finalizer?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15464
+ this.finalizer?.include(context, includeChildrenRecursively);
15790
15465
  }
15791
15466
  }
15792
15467
 
@@ -15844,7 +15519,7 @@ class UpdateExpression extends NodeBase {
15844
15519
  hasEffectsOnInteractionAtPath(path, { type }) {
15845
15520
  return path.length > 1 || type !== INTERACTION_ACCESSED;
15846
15521
  }
15847
- includePath(_, context, includeChildrenRecursively) {
15522
+ include(context, includeChildrenRecursively) {
15848
15523
  if (!this.deoptimized)
15849
15524
  this.applyDeoptimizations();
15850
15525
  this.included = true;
@@ -15913,20 +15588,20 @@ class VariableDeclaration extends NodeBase {
15913
15588
  hasEffectsOnInteractionAtPath() {
15914
15589
  return false;
15915
15590
  }
15916
- includePath(_path, context, includeChildrenRecursively, { asSingleStatement } = parseAst_js.BLANK) {
15591
+ include(context, includeChildrenRecursively, { asSingleStatement } = parseAst_js.BLANK) {
15917
15592
  this.included = true;
15918
15593
  for (const declarator of this.declarations) {
15919
15594
  if (includeChildrenRecursively || declarator.shouldBeIncluded(context))
15920
- declarator.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15595
+ declarator.include(context, includeChildrenRecursively);
15921
15596
  const { id, init } = declarator;
15922
15597
  if (asSingleStatement) {
15923
- id.includePath(EMPTY_PATH, context, includeChildrenRecursively);
15598
+ id.include(context, includeChildrenRecursively);
15924
15599
  }
15925
15600
  if (init &&
15926
15601
  id.included &&
15927
15602
  !init.included &&
15928
15603
  (id instanceof ObjectPattern || id instanceof ArrayPattern)) {
15929
- init.includePath(EMPTY_PATH, context, includeChildrenRecursively);
15604
+ init.include(context, includeChildrenRecursively);
15930
15605
  }
15931
15606
  }
15932
15607
  }
@@ -15998,7 +15673,8 @@ class VariableDeclaration extends NodeBase {
15998
15673
  const singleSystemExport = gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregatedSystemExports);
15999
15674
  for (const { node, start, separator, contentEnd, end } of separatedNodes) {
16000
15675
  if (!node.included) {
16001
- treeshakeNode(node, code, start, end);
15676
+ code.remove(start, end);
15677
+ node.removeAnnotations(code);
16002
15678
  continue;
16003
15679
  }
16004
15680
  node.render(code, options);
@@ -16075,9 +15751,9 @@ class WhileStatement extends NodeBase {
16075
15751
  return true;
16076
15752
  return hasLoopBodyEffects(context, this.body);
16077
15753
  }
16078
- includePath(_path, context, includeChildrenRecursively) {
15754
+ include(context, includeChildrenRecursively) {
16079
15755
  this.included = true;
16080
- this.test.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15756
+ this.test.include(context, includeChildrenRecursively);
16081
15757
  includeLoopBody(context, this.body, includeChildrenRecursively);
16082
15758
  }
16083
15759
  }
@@ -16321,7 +15997,7 @@ const bufferParsers = [
16321
15997
  const annotations = (node.annotations = parseAst_js.convertAnnotations(buffer[position + 1], buffer));
16322
15998
  node.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
16323
15999
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 2], buffer));
16324
- 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);
16325
16001
  node.body = convertNode(node, scope.bodyScope, buffer[position + 3], buffer);
16326
16002
  },
16327
16003
  function assignmentExpression(node, position, buffer) {
@@ -16367,7 +16043,7 @@ const bufferParsers = [
16367
16043
  const parameterPosition = buffer[position];
16368
16044
  const parameter = (node.param =
16369
16045
  parameterPosition === 0 ? null : convertNode(node, scope, parameterPosition, buffer));
16370
- parameter?.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
16046
+ parameter?.declare('parameter', UNKNOWN_EXPRESSION);
16371
16047
  node.body = convertNode(node, scope.bodyScope, buffer[position + 1], buffer);
16372
16048
  },
16373
16049
  function chainExpression(node, position, buffer) {
@@ -16505,7 +16181,7 @@ const bufferParsers = [
16505
16181
  node.id =
16506
16182
  idPosition === 0 ? null : convertNode(node, scope.parent, idPosition, buffer);
16507
16183
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
16508
- 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);
16509
16185
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
16510
16186
  },
16511
16187
  function functionExpression(node, position, buffer) {
@@ -16518,7 +16194,7 @@ const bufferParsers = [
16518
16194
  const idPosition = buffer[position + 2];
16519
16195
  node.id = idPosition === 0 ? null : convertNode(node, node.idScope, idPosition, buffer);
16520
16196
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
16521
- 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);
16522
16198
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
16523
16199
  },
16524
16200
  function identifier(node, position, buffer) {
@@ -16877,8 +16553,8 @@ class UnknownNode extends NodeBase {
16877
16553
  hasEffects() {
16878
16554
  return true;
16879
16555
  }
16880
- includePath(path, context) {
16881
- super.includePath(path, context, true);
16556
+ include(context) {
16557
+ super.include(context, true);
16882
16558
  }
16883
16559
  }
16884
16560
 
@@ -16982,8 +16658,8 @@ class ExportShimVariable extends Variable {
16982
16658
  super(MISSING_EXPORT_SHIM_VARIABLE);
16983
16659
  this.module = module;
16984
16660
  }
16985
- includePath(path, context) {
16986
- super.includePath(path, context);
16661
+ include() {
16662
+ super.include();
16987
16663
  this.module.needsExportShim = true;
16988
16664
  }
16989
16665
  }
@@ -17667,7 +17343,7 @@ class Module {
17667
17343
  include() {
17668
17344
  const context = createInclusionContext();
17669
17345
  if (this.ast.shouldBeIncluded(context))
17670
- this.ast.includePath(EMPTY_PATH, context, false);
17346
+ this.ast.include(context, false);
17671
17347
  }
17672
17348
  includeAllExports(includeNamespaceMembers) {
17673
17349
  if (!this.isExecuted) {
@@ -17681,7 +17357,9 @@ class Module {
17681
17357
  return parseAst_js.error(parseAst_js.logMissingEntryExport(exportName, this.id));
17682
17358
  }
17683
17359
  variable.deoptimizePath(UNKNOWN_PATH);
17684
- this.includeVariable(variable, UNKNOWN_PATH);
17360
+ if (!variable.included) {
17361
+ this.includeVariable(variable);
17362
+ }
17685
17363
  }
17686
17364
  }
17687
17365
  for (const name of this.getReexports()) {
@@ -17689,7 +17367,7 @@ class Module {
17689
17367
  if (variable) {
17690
17368
  variable.deoptimizePath(UNKNOWN_PATH);
17691
17369
  if (!variable.included) {
17692
- this.includeVariable(variable, UNKNOWN_PATH);
17370
+ this.includeVariable(variable);
17693
17371
  }
17694
17372
  if (variable instanceof ExternalVariable) {
17695
17373
  variable.module.reexported = true;
@@ -17701,7 +17379,7 @@ class Module {
17701
17379
  }
17702
17380
  }
17703
17381
  includeAllInBundle() {
17704
- this.ast.includePath(UNKNOWN_PATH, createInclusionContext(), true);
17382
+ this.ast.include(createInclusionContext(), true);
17705
17383
  this.includeAllExports(false);
17706
17384
  }
17707
17385
  includeExportsByNames(names) {
@@ -17715,7 +17393,7 @@ class Module {
17715
17393
  if (variable) {
17716
17394
  variable.deoptimizePath(UNKNOWN_PATH);
17717
17395
  if (!variable.included) {
17718
- this.includeVariable(variable, UNKNOWN_PATH);
17396
+ this.includeVariable(variable);
17719
17397
  }
17720
17398
  }
17721
17399
  if (!this.exports.has(name) && !this.reexportDescriptions.has(name)) {
@@ -18157,13 +17835,13 @@ class Module {
18157
17835
  for (const module of [this, ...this.exportAllModules]) {
18158
17836
  if (module instanceof ExternalModule) {
18159
17837
  const [externalVariable] = module.getVariableForExportName('*');
18160
- externalVariable.includePath(UNKNOWN_PATH, createInclusionContext());
17838
+ externalVariable.include();
18161
17839
  this.includedImports.add(externalVariable);
18162
17840
  externalNamespaces.add(externalVariable);
18163
17841
  }
18164
17842
  else if (module.info.syntheticNamedExports) {
18165
17843
  const syntheticNamespace = module.getSyntheticNamespace();
18166
- syntheticNamespace.includePath(UNKNOWN_PATH, createInclusionContext());
17844
+ syntheticNamespace.include();
18167
17845
  this.includedImports.add(syntheticNamespace);
18168
17846
  syntheticNamespaces.add(syntheticNamespace);
18169
17847
  }
@@ -18173,9 +17851,7 @@ class Module {
18173
17851
  includeDynamicImport(node) {
18174
17852
  const resolution = this.dynamicImports.find(dynamicImport => dynamicImport.node === node).resolution;
18175
17853
  if (resolution instanceof Module) {
18176
- if (!resolution.includedDynamicImporters.includes(this)) {
18177
- resolution.includedDynamicImporters.push(this);
18178
- }
17854
+ resolution.includedDynamicImporters.push(this);
18179
17855
  const importedNames = this.options.treeshake
18180
17856
  ? node.getDeterministicImportedNames()
18181
17857
  : undefined;
@@ -18187,7 +17863,7 @@ class Module {
18187
17863
  }
18188
17864
  }
18189
17865
  }
18190
- includeVariable(variable, path) {
17866
+ includeVariable(variable) {
18191
17867
  const variableModule = variable.module;
18192
17868
  if (variable.included) {
18193
17869
  if (variableModule instanceof Module && variableModule !== this) {
@@ -18195,6 +17871,7 @@ class Module {
18195
17871
  }
18196
17872
  }
18197
17873
  else {
17874
+ variable.include();
18198
17875
  this.graph.needsTreeshakingPass = true;
18199
17876
  if (variableModule instanceof Module) {
18200
17877
  if (!variableModule.isExecuted) {
@@ -18210,10 +17887,9 @@ class Module {
18210
17887
  }
18211
17888
  }
18212
17889
  }
18213
- variable.includePath(path, createInclusionContext());
18214
17890
  }
18215
- includeVariableInModule(variable, path) {
18216
- this.includeVariable(variable, path);
17891
+ includeVariableInModule(variable) {
17892
+ this.includeVariable(variable);
18217
17893
  const variableModule = variable.module;
18218
17894
  if (variableModule && variableModule !== this) {
18219
17895
  this.includedImports.add(variable);
@@ -21716,7 +21392,7 @@ class Graph {
21716
21392
  this.options = options;
21717
21393
  this.astLru = flru(5);
21718
21394
  this.cachedModules = new Map();
21719
- this.deoptimizationTracker = new EntityPathTracker();
21395
+ this.deoptimizationTracker = new PathTracker();
21720
21396
  this.entryModules = [];
21721
21397
  this.modulesById = new Map();
21722
21398
  this.needsTreeshakingPass = false;