@rollup/wasm-node 4.27.2 → 4.27.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v4.27.2
4
- Fri, 15 Nov 2024 17:19:22 GMT - commit a503a4dd9982bf20fd38aeb171882a27828906ae
3
+ Rollup.js v4.27.4
4
+ Sat, 23 Nov 2024 06:59:50 GMT - commit e805b546405a4e6cfccd3fe73e9f4df770023824
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -31,7 +31,7 @@ function _interopNamespaceDefault(e) {
31
31
 
32
32
  const tty__namespace = /*#__PURE__*/_interopNamespaceDefault(tty);
33
33
 
34
- var version = "4.27.2";
34
+ var version = "4.27.4";
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
@@ -1954,6 +1994,9 @@ class SourceMap {
1954
1994
  if (typeof properties.x_google_ignoreList !== 'undefined') {
1955
1995
  this.x_google_ignoreList = properties.x_google_ignoreList;
1956
1996
  }
1997
+ if (typeof properties.debugId !== 'undefined') {
1998
+ this.debugId = properties.debugId;
1999
+ }
1957
2000
  }
1958
2001
 
1959
2002
  toString() {
@@ -3530,6 +3573,19 @@ function is_reference(node, parent) {
3530
3573
  }
3531
3574
  }
3532
3575
 
3576
+ const PureFunctionKey = Symbol('PureFunction');
3577
+ const getPureFunctions = ({ treeshake }) => {
3578
+ const pureFunctions = Object.create(null);
3579
+ for (const functionName of treeshake ? treeshake.manualPureFunctions : []) {
3580
+ let currentFunctions = pureFunctions;
3581
+ for (const pathSegment of functionName.split('.')) {
3582
+ currentFunctions = currentFunctions[pathSegment] ||= Object.create(null);
3583
+ }
3584
+ currentFunctions[PureFunctionKey] = true;
3585
+ }
3586
+ return pureFunctions;
3587
+ };
3588
+
3533
3589
  const UnknownKey = Symbol('Unknown Key');
3534
3590
  const UnknownNonAccessorKey = Symbol('Unknown Non-Accessor Key');
3535
3591
  const UnknownInteger = Symbol('Unknown Integer');
@@ -3544,7 +3600,7 @@ const UNKNOWN_PATH = [UnknownKey];
3544
3600
  const UNKNOWN_NON_ACCESSOR_PATH = [UnknownNonAccessorKey];
3545
3601
  const UNKNOWN_INTEGER_PATH = [UnknownInteger];
3546
3602
  const EntitiesKey = Symbol('Entities');
3547
- class EntityPathTracker {
3603
+ class PathTracker {
3548
3604
  constructor() {
3549
3605
  this.entityPaths = Object.create(null, {
3550
3606
  [EntitiesKey]: { value: new Set() }
@@ -3569,14 +3625,14 @@ class EntityPathTracker {
3569
3625
  getEntities(path) {
3570
3626
  let currentPaths = this.entityPaths;
3571
3627
  for (const pathSegment of path) {
3572
- currentPaths = currentPaths[pathSegment] ||= Object.create(null, {
3573
- [EntitiesKey]: { value: new Set() }
3574
- });
3628
+ currentPaths = currentPaths[pathSegment] =
3629
+ currentPaths[pathSegment] ||
3630
+ Object.create(null, { [EntitiesKey]: { value: new Set() } });
3575
3631
  }
3576
3632
  return currentPaths[EntitiesKey];
3577
3633
  }
3578
3634
  }
3579
- const SHARED_RECURSION_TRACKER = new EntityPathTracker();
3635
+ const SHARED_RECURSION_TRACKER = new PathTracker();
3580
3636
  class DiscriminatedPathTracker {
3581
3637
  constructor() {
3582
3638
  this.entityPaths = Object.create(null, {
@@ -3586,9 +3642,9 @@ class DiscriminatedPathTracker {
3586
3642
  trackEntityAtPathAndGetIfTracked(path, discriminator, entity) {
3587
3643
  let currentPaths = this.entityPaths;
3588
3644
  for (const pathSegment of path) {
3589
- currentPaths = currentPaths[pathSegment] ||= Object.create(null, {
3590
- [EntitiesKey]: { value: new Map() }
3591
- });
3645
+ currentPaths = currentPaths[pathSegment] =
3646
+ currentPaths[pathSegment] ||
3647
+ Object.create(null, { [EntitiesKey]: { value: new Map() } });
3592
3648
  }
3593
3649
  const trackedEntities = getOrCreate(currentPaths[EntitiesKey], discriminator, (getNewSet));
3594
3650
  if (trackedEntities.has(entity))
@@ -3597,85 +3653,6 @@ class DiscriminatedPathTracker {
3597
3653
  return false;
3598
3654
  }
3599
3655
  }
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
3656
 
3680
3657
  function isFlagSet(flags, flag) {
3681
3658
  return (flags & flag) !== 0;
@@ -3714,12 +3691,12 @@ class ExpressionEntity {
3714
3691
  hasEffectsOnInteractionAtPath(_path, _interaction, _context) {
3715
3692
  return true;
3716
3693
  }
3717
- includePath(_path, _context, _includeChildrenRecursively, _options) {
3694
+ include(_context, _includeChildrenRecursively, _options) {
3718
3695
  this.included = true;
3719
3696
  }
3720
- includeCallArguments(context, interaction) {
3721
- for (const argument of interaction.args) {
3722
- argument?.includePath(UNKNOWN_PATH, context, false);
3697
+ includeCallArguments(context, parameters) {
3698
+ for (const argument of parameters) {
3699
+ argument.include(context, false);
3723
3700
  }
3724
3701
  }
3725
3702
  shouldBeIncluded(_context) {
@@ -3758,19 +3735,6 @@ const NODE_INTERACTION_UNKNOWN_CALL = {
3758
3735
  withNew: false
3759
3736
  };
3760
3737
 
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
3738
  class Variable extends ExpressionEntity {
3775
3739
  markReassigned() {
3776
3740
  this.isReassigned = true;
@@ -3847,9 +3811,9 @@ class Variable extends ExpressionEntity {
3847
3811
  * has not been included previously. Once a variable is included, it should
3848
3812
  * take care all its declarations are included.
3849
3813
  */
3850
- includePath(path, context) {
3814
+ include() {
3851
3815
  this.included = true;
3852
- this.renderedLikeHoisted?.includePath(path, context);
3816
+ this.renderedLikeHoisted?.include();
3853
3817
  }
3854
3818
  /**
3855
3819
  * Links the rendered name of this variable to another variable and includes
@@ -3881,8 +3845,8 @@ class ExternalVariable extends Variable {
3881
3845
  hasEffectsOnInteractionAtPath(path, { type }) {
3882
3846
  return type !== INTERACTION_ACCESSED || path.length > (this.isNamespace ? 1 : 0);
3883
3847
  }
3884
- includePath(path, context) {
3885
- super.includePath(path, context);
3848
+ include() {
3849
+ super.include();
3886
3850
  this.module.used = true;
3887
3851
  }
3888
3852
  }
@@ -4181,6 +4145,36 @@ const childNodeKeys = {
4181
4145
  YieldExpression: ['argument']
4182
4146
  };
4183
4147
 
4148
+ function createInclusionContext() {
4149
+ return {
4150
+ brokenFlow: false,
4151
+ hasBreak: false,
4152
+ hasContinue: false,
4153
+ includedCallArguments: new Set(),
4154
+ includedLabels: new Set()
4155
+ };
4156
+ }
4157
+ function createHasEffectsContext() {
4158
+ return {
4159
+ accessed: new PathTracker(),
4160
+ assigned: new PathTracker(),
4161
+ brokenFlow: false,
4162
+ called: new DiscriminatedPathTracker(),
4163
+ hasBreak: false,
4164
+ hasContinue: false,
4165
+ ignore: {
4166
+ breaks: false,
4167
+ continues: false,
4168
+ labels: new Set(),
4169
+ returnYield: false,
4170
+ this: false
4171
+ },
4172
+ includedLabels: new Set(),
4173
+ instantiated: new DiscriminatedPathTracker(),
4174
+ replacedVariableInits: new Map()
4175
+ };
4176
+ }
4177
+
4184
4178
  const INCLUDE_PARAMETERS = 'variables';
4185
4179
  const IS_SKIPPED_CHAIN = Symbol('IS_SKIPPED_CHAIN');
4186
4180
  class NodeBase extends ExpressionEntity {
@@ -4249,7 +4243,7 @@ class NodeBase extends ExpressionEntity {
4249
4243
  return (this.hasEffects(context) ||
4250
4244
  this.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.assignmentInteraction, context));
4251
4245
  }
4252
- includePath(_path, context, includeChildrenRecursively, _options) {
4246
+ include(context, includeChildrenRecursively, _options) {
4253
4247
  if (!this.deoptimized)
4254
4248
  this.applyDeoptimizations();
4255
4249
  this.included = true;
@@ -4259,16 +4253,16 @@ class NodeBase extends ExpressionEntity {
4259
4253
  continue;
4260
4254
  if (Array.isArray(value)) {
4261
4255
  for (const child of value) {
4262
- child?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
4256
+ child?.include(context, includeChildrenRecursively);
4263
4257
  }
4264
4258
  }
4265
4259
  else {
4266
- value.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
4260
+ value.include(context, includeChildrenRecursively);
4267
4261
  }
4268
4262
  }
4269
4263
  }
4270
4264
  includeAsAssignmentTarget(context, includeChildrenRecursively, _deoptimizeAccess) {
4271
- this.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
4265
+ this.include(context, includeChildrenRecursively);
4272
4266
  }
4273
4267
  /**
4274
4268
  * Override to perform special initialisation steps after the scope is
@@ -4730,7 +4724,6 @@ class ObjectEntity extends ExpressionEntity {
4730
4724
  this.unknownIntegerProps = [];
4731
4725
  this.unmatchableGetters = [];
4732
4726
  this.unmatchablePropertiesAndGetters = [];
4733
- this.unmatchablePropertiesAndSetters = [];
4734
4727
  this.unmatchableSetters = [];
4735
4728
  if (Array.isArray(properties)) {
4736
4729
  this.buildPropertyMaps(properties);
@@ -4965,37 +4958,9 @@ class ObjectEntity extends ExpressionEntity {
4965
4958
  }
4966
4959
  return false;
4967
4960
  }
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
4961
  buildPropertyMaps(properties) {
4998
- const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchablePropertiesAndSetters, unmatchableGetters, unmatchableSetters } = this;
4962
+ const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchableGetters, unmatchableSetters } = this;
4963
+ const unmatchablePropertiesAndSetters = [];
4999
4964
  for (let index = properties.length - 1; index >= 0; index--) {
5000
4965
  const { key, kind, property } = properties[index];
5001
4966
  allProperties.push(property);
@@ -6352,37 +6317,17 @@ class GlobalVariable extends Variable {
6352
6317
  }
6353
6318
  }
6354
6319
 
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
6320
  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) {
6321
+ constructor(name, declarator, init, context, kind) {
6375
6322
  super(name);
6376
6323
  this.init = init;
6377
- this.initPath = initPath;
6378
- this.kind = kind;
6379
6324
  this.calledFromTryStatement = false;
6380
6325
  this.additionalInitializers = null;
6381
- this.includedPathTracker = new IncludedPathTracker();
6382
6326
  this.expressionsToBeDeoptimized = [];
6383
6327
  this.declarations = declarator ? [declarator] : [];
6384
6328
  this.deoptimizationTracker = context.deoptimizationTracker;
6385
6329
  this.module = context.module;
6330
+ this.kind = kind;
6386
6331
  }
6387
6332
  addDeclaration(identifier, init) {
6388
6333
  this.declarations.push(identifier);
@@ -6393,16 +6338,15 @@ class LocalVariable extends Variable {
6393
6338
  for (const initializer of this.additionalInitializers) {
6394
6339
  initializer.deoptimizePath(UNKNOWN_PATH);
6395
6340
  }
6341
+ this.additionalInitializers = null;
6396
6342
  }
6397
6343
  }
6398
6344
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6399
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
6345
+ if (this.isReassigned) {
6400
6346
  deoptimizeInteraction(interaction);
6401
6347
  return;
6402
6348
  }
6403
- recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6404
- this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], recursionTracker);
6405
- }, undefined);
6349
+ recursionTracker.withTrackedEntityAtPath(path, this.init, () => this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker), undefined);
6406
6350
  }
6407
6351
  deoptimizePath(path) {
6408
6352
  if (this.isReassigned ||
@@ -6416,40 +6360,37 @@ class LocalVariable extends Variable {
6416
6360
  for (const expression of expressionsToBeDeoptimized) {
6417
6361
  expression.deoptimizeCache();
6418
6362
  }
6419
- this.init.deoptimizePath([...this.initPath, UnknownKey]);
6363
+ this.init.deoptimizePath(UNKNOWN_PATH);
6420
6364
  }
6421
6365
  else {
6422
- this.init.deoptimizePath(limitConcatenatedPathDepth(this.initPath, path));
6366
+ this.init.deoptimizePath(path);
6423
6367
  }
6424
6368
  }
6425
6369
  getLiteralValueAtPath(path, recursionTracker, origin) {
6426
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
6370
+ if (this.isReassigned) {
6427
6371
  return UnknownValue;
6428
6372
  }
6429
6373
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6430
6374
  this.expressionsToBeDeoptimized.push(origin);
6431
- return this.init.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin);
6375
+ return this.init.getLiteralValueAtPath(path, recursionTracker, origin);
6432
6376
  }, UnknownValue);
6433
6377
  }
6434
6378
  getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
6435
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
6379
+ if (this.isReassigned) {
6436
6380
  return UNKNOWN_RETURN_EXPRESSION;
6437
6381
  }
6438
6382
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6439
6383
  this.expressionsToBeDeoptimized.push(origin);
6440
- return this.init.getReturnExpressionWhenCalledAtPath([...this.initPath, ...path], interaction, recursionTracker, origin);
6384
+ return this.init.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
6441
6385
  }, UNKNOWN_RETURN_EXPRESSION);
6442
6386
  }
6443
6387
  hasEffectsOnInteractionAtPath(path, interaction, context) {
6444
- if (path.length + this.initPath.length > MAX_PATH_DEPTH) {
6445
- return true;
6446
- }
6447
6388
  switch (interaction.type) {
6448
6389
  case INTERACTION_ACCESSED: {
6449
6390
  if (this.isReassigned)
6450
6391
  return true;
6451
6392
  return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
6452
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6393
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6453
6394
  }
6454
6395
  case INTERACTION_ASSIGNED: {
6455
6396
  if (this.included)
@@ -6459,23 +6400,23 @@ class LocalVariable extends Variable {
6459
6400
  if (this.isReassigned)
6460
6401
  return true;
6461
6402
  return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
6462
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6403
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6463
6404
  }
6464
6405
  case INTERACTION_CALLED: {
6465
6406
  if (this.isReassigned)
6466
6407
  return true;
6467
6408
  return (!(interaction.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this) &&
6468
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6409
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6469
6410
  }
6470
6411
  }
6471
6412
  }
6472
- includePath(path, context) {
6473
- if (!this.includedPathTracker.includePathAndGetIfIncluded(path)) {
6474
- super.includePath(path, context);
6413
+ include() {
6414
+ if (!this.included) {
6415
+ super.include();
6475
6416
  for (const declaration of this.declarations) {
6476
6417
  // If node is a default export, it can save a tree-shaking run to include the full declaration now
6477
6418
  if (!declaration.included)
6478
- declaration.includePath(EMPTY_PATH, context, false);
6419
+ declaration.include(createInclusionContext(), false);
6479
6420
  let node = declaration.parent;
6480
6421
  while (!node.included) {
6481
6422
  // We do not want to properly include parents in case they are part of a dead branch
@@ -6486,26 +6427,17 @@ class LocalVariable extends Variable {
6486
6427
  node = node.parent;
6487
6428
  }
6488
6429
  }
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
6430
  }
6495
6431
  }
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);
6432
+ includeCallArguments(context, parameters) {
6433
+ if (this.isReassigned || context.includedCallArguments.has(this.init)) {
6434
+ for (const argument of parameters) {
6435
+ argument.include(context, false);
6504
6436
  }
6505
6437
  }
6506
6438
  else {
6507
6439
  context.includedCallArguments.add(this.init);
6508
- this.init.includeCallArguments(context, interaction);
6440
+ this.init.includeCallArguments(context, parameters);
6509
6441
  context.includedCallArguments.delete(this.init);
6510
6442
  }
6511
6443
  }
@@ -6585,21 +6517,18 @@ class IdentifierBase extends NodeBase {
6585
6517
  }
6586
6518
  }
6587
6519
  }
6588
- includePath(path, context) {
6520
+ include() {
6589
6521
  if (!this.deoptimized)
6590
6522
  this.applyDeoptimizations();
6591
6523
  if (!this.included) {
6592
6524
  this.included = true;
6593
6525
  if (this.variable !== null) {
6594
- this.scope.context.includeVariableInModule(this.variable, path);
6526
+ this.scope.context.includeVariableInModule(this.variable);
6595
6527
  }
6596
6528
  }
6597
- else if (path.length > 0) {
6598
- this.variable?.includePath(path, context);
6599
- }
6600
6529
  }
6601
- includeCallArguments(context, interaction) {
6602
- this.variable.includeCallArguments(context, interaction);
6530
+ includeCallArguments(context, parameters) {
6531
+ this.variable.includeCallArguments(context, parameters);
6603
6532
  }
6604
6533
  isPossibleTDZ() {
6605
6534
  // return cached value to avoid issues with the next tree-shaking pass
@@ -6682,40 +6611,11 @@ function closestParentFunctionOrProgram(node) {
6682
6611
  return node;
6683
6612
  }
6684
6613
 
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
6614
  class Identifier extends IdentifierBase {
6709
6615
  constructor() {
6710
6616
  super(...arguments);
6711
6617
  this.variable = null;
6712
6618
  }
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
6619
  addExportedVariables(variables, exportNamesByVariable) {
6720
6620
  if (exportNamesByVariable.has(this.variable)) {
6721
6621
  variables.push(this.variable);
@@ -6728,52 +6628,42 @@ class Identifier extends IdentifierBase {
6728
6628
  this.isVariableReference = true;
6729
6629
  }
6730
6630
  }
6731
- declare(kind, destructuredInitPath, init) {
6631
+ declare(kind, init) {
6732
6632
  let variable;
6733
6633
  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();
6634
+ switch (kind) {
6635
+ case 'var': {
6636
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
6637
+ if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
6638
+ // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
6639
+ variable.markInitializersForDeoptimization();
6640
+ }
6641
+ break;
6742
6642
  }
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);
6643
+ case 'function': {
6644
+ // in strict mode, functions are only hoisted within a scope but not across block scopes
6645
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
6646
+ break;
6647
+ }
6648
+ case 'let':
6649
+ case 'const':
6650
+ case 'using':
6651
+ case 'await using':
6652
+ case 'class': {
6653
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
6654
+ break;
6655
+ }
6656
+ case 'parameter': {
6657
+ variable = this.scope.addParameterDeclaration(this);
6658
+ break;
6659
+ }
6660
+ /* istanbul ignore next */
6661
+ default: {
6662
+ /* istanbul ignore next */
6663
+ throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
6772
6664
  }
6773
- init.includePath(destructuredInitPath, context, false);
6774
- return true;
6775
6665
  }
6776
- return false;
6666
+ return [(this.variable = variable)];
6777
6667
  }
6778
6668
  markDeclarationReached() {
6779
6669
  this.variable.initReached = true;
@@ -6827,17 +6717,18 @@ class Scope {
6827
6717
  - then the variable is still declared in the hoisted outer scope, but the initializer is assigned to the parameter
6828
6718
  - const, let, class, and function except in the cases above cannot redeclare anything
6829
6719
  */
6830
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
6720
+ addDeclaration(identifier, context, init, kind) {
6831
6721
  const name = identifier.name;
6832
6722
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
6833
6723
  if (existingVariable) {
6834
- if (kind === 'var' && existingVariable.kind === 'var') {
6724
+ const existingKind = existingVariable.kind;
6725
+ if (kind === 'var' && existingKind === 'var') {
6835
6726
  existingVariable.addDeclaration(identifier, init);
6836
6727
  return existingVariable;
6837
6728
  }
6838
6729
  context.error(parseAst_js.logRedeclarationError(name), identifier.start);
6839
6730
  }
6840
- const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
6731
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
6841
6732
  this.variables.set(name, newVariable);
6842
6733
  return newVariable;
6843
6734
  }
@@ -7039,7 +6930,7 @@ class BlockScope extends ChildScope {
7039
6930
  constructor(parent) {
7040
6931
  super(parent, parent.context);
7041
6932
  }
7042
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
6933
+ addDeclaration(identifier, context, init, kind) {
7043
6934
  if (kind === 'var') {
7044
6935
  const name = identifier.name;
7045
6936
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -7051,7 +6942,7 @@ class BlockScope extends ChildScope {
7051
6942
  }
7052
6943
  return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7053
6944
  }
7054
- const declaredVariable = this.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
6945
+ const declaredVariable = this.parent.addDeclaration(identifier, context, init, kind);
7055
6946
  // Necessary to make sure the init is deoptimized for conditional declarations.
7056
6947
  // We cannot call deoptimizePath here.
7057
6948
  declaredVariable.markInitializersForDeoptimization();
@@ -7059,7 +6950,7 @@ class BlockScope extends ChildScope {
7059
6950
  this.addHoistedVariable(name, declaredVariable);
7060
6951
  return declaredVariable;
7061
6952
  }
7062
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
6953
+ return super.addDeclaration(identifier, context, init, kind);
7063
6954
  }
7064
6955
  }
7065
6956
 
@@ -7074,11 +6965,11 @@ class StaticBlock extends NodeBase {
7074
6965
  }
7075
6966
  return false;
7076
6967
  }
7077
- includePath(_path, context, includeChildrenRecursively) {
6968
+ include(context, includeChildrenRecursively) {
7078
6969
  this.included = true;
7079
6970
  for (const node of this.body) {
7080
6971
  if (includeChildrenRecursively || node.shouldBeIncluded(context))
7081
- node.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
6972
+ node.include(context, includeChildrenRecursively);
7082
6973
  }
7083
6974
  }
7084
6975
  render(code, options) {
@@ -7095,6 +6986,29 @@ function isStaticBlock(statement) {
7095
6986
  return statement.type === parseAst_js.StaticBlock;
7096
6987
  }
7097
6988
 
6989
+ class ObjectMember extends ExpressionEntity {
6990
+ constructor(object, key) {
6991
+ super();
6992
+ this.object = object;
6993
+ this.key = key;
6994
+ }
6995
+ deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6996
+ this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [this.key, ...path], recursionTracker);
6997
+ }
6998
+ deoptimizePath(path) {
6999
+ this.object.deoptimizePath([this.key, ...path]);
7000
+ }
7001
+ getLiteralValueAtPath(path, recursionTracker, origin) {
7002
+ return this.object.getLiteralValueAtPath([this.key, ...path], recursionTracker, origin);
7003
+ }
7004
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
7005
+ return this.object.getReturnExpressionWhenCalledAtPath([this.key, ...path], interaction, recursionTracker, origin);
7006
+ }
7007
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
7008
+ return this.object.hasEffectsOnInteractionAtPath([this.key, ...path], interaction, context);
7009
+ }
7010
+ }
7011
+
7098
7012
  class ClassNode extends NodeBase {
7099
7013
  constructor() {
7100
7014
  super(...arguments);
@@ -7134,22 +7048,22 @@ class ClassNode extends NodeBase {
7134
7048
  false
7135
7049
  : this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
7136
7050
  }
7137
- includePath(_path, context, includeChildrenRecursively) {
7051
+ include(context, includeChildrenRecursively) {
7138
7052
  if (!this.deoptimized)
7139
7053
  this.applyDeoptimizations();
7140
7054
  this.included = true;
7141
- this.superClass?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
7142
- this.body.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
7055
+ this.superClass?.include(context, includeChildrenRecursively);
7056
+ this.body.include(context, includeChildrenRecursively);
7143
7057
  for (const decorator of this.decorators)
7144
- decorator.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
7058
+ decorator.include(context, includeChildrenRecursively);
7145
7059
  if (this.id) {
7146
7060
  this.id.markDeclarationReached();
7147
- this.id.includePath(UNKNOWN_PATH, createInclusionContext());
7061
+ this.id.include();
7148
7062
  }
7149
7063
  }
7150
7064
  initialise() {
7151
7065
  super.initialise();
7152
- this.id?.declare('class', EMPTY_PATH, this);
7066
+ this.id?.declare('class', this);
7153
7067
  for (const method of this.body.body) {
7154
7068
  if (method instanceof MethodDefinition && method.kind === 'constructor') {
7155
7069
  this.classConstructor = method;
@@ -7207,7 +7121,7 @@ class ClassNode extends NodeBase {
7207
7121
  staticProperties.unshift({
7208
7122
  key: 'prototype',
7209
7123
  kind: 'init',
7210
- property: new ObjectEntity(dynamicMethods, this.superClass ? new ObjectMember(this.superClass, ['prototype']) : OBJECT_PROTOTYPE)
7124
+ property: new ObjectEntity(dynamicMethods, this.superClass ? new ObjectMember(this.superClass, 'prototype') : OBJECT_PROTOTYPE)
7211
7125
  });
7212
7126
  return (this.objectEntity = new ObjectEntity(staticProperties, this.superClass || OBJECT_PROTOTYPE));
7213
7127
  }
@@ -7264,7 +7178,7 @@ class ClassDeclaration extends ClassNode {
7264
7178
 
7265
7179
  class ArgumentsVariable extends LocalVariable {
7266
7180
  constructor(context) {
7267
- super('arguments', null, UNKNOWN_EXPRESSION, EMPTY_PATH, context, 'other');
7181
+ super('arguments', null, UNKNOWN_EXPRESSION, context, 'other');
7268
7182
  this.deoptimizedArguments = [];
7269
7183
  }
7270
7184
  addArgumentToBeDeoptimized(argument) {
@@ -7278,8 +7192,8 @@ class ArgumentsVariable extends LocalVariable {
7278
7192
  hasEffectsOnInteractionAtPath(path, { type }) {
7279
7193
  return type !== INTERACTION_ACCESSED || path.length > 1;
7280
7194
  }
7281
- includePath(path, context) {
7282
- super.includePath(path, context);
7195
+ include() {
7196
+ super.include();
7283
7197
  for (const argument of this.deoptimizedArguments) {
7284
7198
  argument.deoptimizePath(UNKNOWN_PATH);
7285
7199
  }
@@ -7290,28 +7204,27 @@ class ArgumentsVariable extends LocalVariable {
7290
7204
  const MAX_TRACKED_INTERACTIONS = 20;
7291
7205
  const NO_INTERACTIONS = parseAst_js.EMPTY_ARRAY;
7292
7206
  const UNKNOWN_DEOPTIMIZED_FIELD = new Set([UnknownKey]);
7293
- const EMPTY_PATH_TRACKER = new EntityPathTracker();
7207
+ const EMPTY_PATH_TRACKER = new PathTracker();
7294
7208
  const UNKNOWN_DEOPTIMIZED_ENTITY = new Set([UNKNOWN_EXPRESSION]);
7295
7209
  class ParameterVariable extends LocalVariable {
7296
- constructor(name, declarator, argumentPath, context) {
7297
- super(name, declarator, UNKNOWN_EXPRESSION, argumentPath, context, 'parameter');
7210
+ constructor(name, declarator, context) {
7211
+ super(name, declarator, UNKNOWN_EXPRESSION, context, 'parameter');
7298
7212
  this.deoptimizationInteractions = [];
7299
- this.deoptimizations = new EntityPathTracker();
7213
+ this.deoptimizations = new PathTracker();
7300
7214
  this.deoptimizedFields = new Set();
7301
- this.argumentsToBeDeoptimized = new Set();
7302
- this.expressionsDependingOnKnownValue = [];
7215
+ this.entitiesToBeDeoptimized = new Set();
7216
+ this.expressionsUseTheKnownValue = [];
7303
7217
  this.knownValue = null;
7304
7218
  this.knownValueLiteral = UnknownValue;
7305
7219
  this.frozenValue = null;
7306
7220
  }
7307
- addArgumentValue(entity) {
7308
- this.updateKnownValue(entity);
7221
+ addEntityToBeDeoptimized(entity) {
7309
7222
  if (entity === UNKNOWN_EXPRESSION) {
7310
7223
  // As unknown expressions fully deoptimize all interactions, we can clear
7311
7224
  // the interaction cache at this point provided we keep this optimization
7312
7225
  // in mind when adding new interactions
7313
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7314
- this.argumentsToBeDeoptimized.add(UNKNOWN_EXPRESSION);
7226
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7227
+ this.entitiesToBeDeoptimized.add(UNKNOWN_EXPRESSION);
7315
7228
  for (const { interaction } of this.deoptimizationInteractions) {
7316
7229
  deoptimizeInteraction(interaction);
7317
7230
  }
@@ -7321,34 +7234,27 @@ class ParameterVariable extends LocalVariable {
7321
7234
  else if (this.deoptimizedFields.has(UnknownKey)) {
7322
7235
  // This means that we already deoptimized all interactions and no longer
7323
7236
  // track them
7324
- entity.deoptimizePath([...this.initPath, UnknownKey]);
7237
+ entity.deoptimizePath(UNKNOWN_PATH);
7325
7238
  }
7326
- else if (!this.argumentsToBeDeoptimized.has(entity)) {
7327
- this.argumentsToBeDeoptimized.add(entity);
7239
+ else if (!this.entitiesToBeDeoptimized.has(entity)) {
7240
+ this.entitiesToBeDeoptimized.add(entity);
7328
7241
  for (const field of this.deoptimizedFields) {
7329
- entity.deoptimizePath([...this.initPath, field]);
7242
+ entity.deoptimizePath([field]);
7330
7243
  }
7331
7244
  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);
7245
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
7337
7246
  }
7338
7247
  }
7339
7248
  }
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
7249
  markReassigned() {
7344
7250
  if (this.isReassigned) {
7345
7251
  return;
7346
7252
  }
7347
7253
  super.markReassigned();
7348
- for (const expression of this.expressionsDependingOnKnownValue) {
7254
+ for (const expression of this.expressionsUseTheKnownValue) {
7349
7255
  expression.deoptimizeCache();
7350
7256
  }
7351
- this.expressionsDependingOnKnownValue = parseAst_js.EMPTY_ARRAY;
7257
+ this.expressionsUseTheKnownValue = parseAst_js.EMPTY_ARRAY;
7352
7258
  }
7353
7259
  deoptimizeCache() {
7354
7260
  this.markReassigned();
@@ -7365,7 +7271,7 @@ class ParameterVariable extends LocalVariable {
7365
7271
  }
7366
7272
  if (this.knownValue === null) {
7367
7273
  this.knownValue = argument;
7368
- this.knownValueLiteral = argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this);
7274
+ this.knownValueLiteral = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
7369
7275
  return;
7370
7276
  }
7371
7277
  // the same literal or identifier, do nothing
@@ -7381,7 +7287,7 @@ class ParameterVariable extends LocalVariable {
7381
7287
  return;
7382
7288
  }
7383
7289
  // add tracking for the new argument
7384
- const newValue = argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this);
7290
+ const newValue = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
7385
7291
  if (newValue !== oldValue) {
7386
7292
  this.markReassigned();
7387
7293
  }
@@ -7399,31 +7305,24 @@ class ParameterVariable extends LocalVariable {
7399
7305
  return this.frozenValue;
7400
7306
  }
7401
7307
  getLiteralValueAtPath(path, recursionTracker, origin) {
7402
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
7308
+ if (this.isReassigned) {
7403
7309
  return UnknownValue;
7404
7310
  }
7405
7311
  const knownValue = this.getKnownValue();
7406
- this.expressionsDependingOnKnownValue.push(origin);
7407
- return recursionTracker.withTrackedEntityAtPath(path, knownValue, () => knownValue.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin), UnknownValue);
7312
+ this.expressionsUseTheKnownValue.push(origin);
7313
+ return recursionTracker.withTrackedEntityAtPath(path, knownValue, () => knownValue.getLiteralValueAtPath(path, recursionTracker, origin), UnknownValue);
7408
7314
  }
7409
7315
  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) {
7316
+ if (this.isReassigned || interaction.type === INTERACTION_ASSIGNED) {
7414
7317
  return super.hasEffectsOnInteractionAtPath(path, interaction, context);
7415
7318
  }
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));
7319
+ const knownValue = this.getKnownValue();
7320
+ return knownValue.hasEffectsOnInteractionAtPath(path, interaction, context);
7422
7321
  }
7423
7322
  deoptimizeArgumentsOnInteractionAtPath(interaction, path) {
7424
7323
  // For performance reasons, we fully deoptimize all deeper interactions
7425
7324
  if (path.length >= 2 ||
7426
- this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
7325
+ this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
7427
7326
  this.deoptimizationInteractions.length >= MAX_TRACKED_INTERACTIONS ||
7428
7327
  (path.length === 1 &&
7429
7328
  (this.deoptimizedFields.has(UnknownKey) ||
@@ -7432,10 +7331,10 @@ class ParameterVariable extends LocalVariable {
7432
7331
  return;
7433
7332
  }
7434
7333
  if (!this.deoptimizations.trackEntityAtPathAndGetIfTracked(path, interaction.args)) {
7435
- for (const entity of this.argumentsToBeDeoptimized) {
7436
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
7334
+ for (const entity of this.entitiesToBeDeoptimized) {
7335
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
7437
7336
  }
7438
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7337
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7439
7338
  this.deoptimizationInteractions.push({
7440
7339
  interaction,
7441
7340
  path
@@ -7456,17 +7355,17 @@ class ParameterVariable extends LocalVariable {
7456
7355
  return;
7457
7356
  }
7458
7357
  this.deoptimizedFields.add(key);
7459
- for (const entity of this.argumentsToBeDeoptimized) {
7358
+ for (const entity of this.entitiesToBeDeoptimized) {
7460
7359
  // We do not need a recursion tracker here as we already track whether
7461
7360
  // this field is deoptimized
7462
- entity.deoptimizePath([...this.initPath, key]);
7361
+ entity.deoptimizePath([key]);
7463
7362
  }
7464
7363
  if (key === UnknownKey) {
7465
7364
  // save some memory
7466
7365
  this.deoptimizationInteractions = NO_INTERACTIONS;
7467
7366
  this.deoptimizations = EMPTY_PATH_TRACKER;
7468
7367
  this.deoptimizedFields = UNKNOWN_DEOPTIMIZED_FIELD;
7469
- this.argumentsToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
7368
+ this.entitiesToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
7470
7369
  }
7471
7370
  }
7472
7371
  getReturnExpressionWhenCalledAtPath(path) {
@@ -7481,14 +7380,11 @@ class ParameterVariable extends LocalVariable {
7481
7380
  }
7482
7381
  return UNKNOWN_RETURN_EXPRESSION;
7483
7382
  }
7484
- includeArgumentPaths(entity, context) {
7485
- this.includedPathTracker.includeAllPaths(entity, context, this.initPath);
7486
- }
7487
7383
  }
7488
7384
 
7489
7385
  class ThisVariable extends ParameterVariable {
7490
7386
  constructor(context) {
7491
- super('this', null, EMPTY_PATH, context);
7387
+ super('this', null, context);
7492
7388
  }
7493
7389
  hasEffectsOnInteractionAtPath(path, interaction, context) {
7494
7390
  return (context.replacedVariableInits.get(this) || UNKNOWN_EXPRESSION).hasEffectsOnInteractionAtPath(path, interaction, context);
@@ -7500,7 +7396,7 @@ class CatchBodyScope extends ChildScope {
7500
7396
  super(parent, parent.context);
7501
7397
  this.parent = parent;
7502
7398
  }
7503
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
7399
+ addDeclaration(identifier, context, init, kind) {
7504
7400
  if (kind === 'var') {
7505
7401
  const name = identifier.name;
7506
7402
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -7513,7 +7409,7 @@ class CatchBodyScope extends ChildScope {
7513
7409
  // the assignment actually goes to the parameter and the var is
7514
7410
  // hoisted without assignment. Locally, it is shadowed by the
7515
7411
  // parameter
7516
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, destructuredInitPath, kind);
7412
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, kind);
7517
7413
  // To avoid the need to rewrite the declaration, we link the variable
7518
7414
  // names. If we ever implement a logic that splits initialization and
7519
7415
  // assignment for hoisted vars, the "renderLikeHoisted" logic can be
@@ -7532,7 +7428,7 @@ class CatchBodyScope extends ChildScope {
7532
7428
  return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7533
7429
  }
7534
7430
  // We only add parameters to parameter scopes
7535
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
7431
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, kind);
7536
7432
  // Necessary to make sure the init is deoptimized for conditional declarations.
7537
7433
  // We cannot call deoptimizePath here.
7538
7434
  declaredVariable.markInitializersForDeoptimization();
@@ -7540,7 +7436,7 @@ class CatchBodyScope extends ChildScope {
7540
7436
  this.addHoistedVariable(name, declaredVariable);
7541
7437
  return declaredVariable;
7542
7438
  }
7543
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
7439
+ return super.addDeclaration(identifier, context, init, kind);
7544
7440
  }
7545
7441
  }
7546
7442
 
@@ -7550,7 +7446,7 @@ class FunctionBodyScope extends ChildScope {
7550
7446
  }
7551
7447
  // There is stuff that is only allowed in function scopes, i.e. functions can
7552
7448
  // be redeclared, functions and var can redeclare each other
7553
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
7449
+ addDeclaration(identifier, context, init, kind) {
7554
7450
  const name = identifier.name;
7555
7451
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
7556
7452
  if (existingVariable) {
@@ -7562,7 +7458,7 @@ class FunctionBodyScope extends ChildScope {
7562
7458
  }
7563
7459
  context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7564
7460
  }
7565
- const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
7461
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
7566
7462
  this.variables.set(name, newVariable);
7567
7463
  return newVariable;
7568
7464
  }
@@ -7571,21 +7467,21 @@ class FunctionBodyScope extends ChildScope {
7571
7467
  class ParameterScope extends ChildScope {
7572
7468
  constructor(parent, isCatchScope) {
7573
7469
  super(parent, parent.context);
7574
- this.hasRest = false;
7575
7470
  this.parameters = [];
7471
+ this.hasRest = false;
7576
7472
  this.bodyScope = isCatchScope ? new CatchBodyScope(this) : new FunctionBodyScope(this);
7577
7473
  }
7578
7474
  /**
7579
7475
  * Adds a parameter to this scope. Parameters must be added in the correct
7580
7476
  * order, i.e. from left to right.
7581
7477
  */
7582
- addParameterDeclaration(identifier, argumentPath) {
7478
+ addParameterDeclaration(identifier) {
7583
7479
  const { name, start } = identifier;
7584
7480
  const existingParameter = this.variables.get(name);
7585
7481
  if (existingParameter) {
7586
7482
  return this.context.error(parseAst_js.logDuplicateArgumentNameError(name), start);
7587
7483
  }
7588
- const variable = new ParameterVariable(name, identifier, argumentPath, this.context);
7484
+ const variable = new ParameterVariable(name, identifier, this.context);
7589
7485
  this.variables.set(name, variable);
7590
7486
  // We also add it to the body scope to detect name conflicts with local
7591
7487
  // variables. We still need the intermediate scope, though, as parameter
@@ -7603,54 +7499,43 @@ class ParameterScope extends ChildScope {
7603
7499
  }
7604
7500
  this.hasRest = hasRest;
7605
7501
  }
7606
- includeCallArguments(context, interaction) {
7502
+ includeCallArguments(context, parameters) {
7607
7503
  let calledFromTryStatement = false;
7608
7504
  let argumentIncluded = false;
7609
7505
  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);
7506
+ for (const checkedArgument of parameters) {
7507
+ if (checkedArgument instanceof SpreadElement) {
7508
+ for (const argument of parameters) {
7509
+ argument.include(context, false);
7510
+ }
7511
+ break;
7621
7512
  }
7622
7513
  }
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];
7514
+ for (let index = parameters.length - 1; index >= 0; index--) {
7515
+ const parameterVariables = this.parameters[index] || restParameter;
7516
+ const argument = parameters[index];
7628
7517
  if (parameterVariables) {
7629
7518
  calledFromTryStatement = false;
7630
7519
  if (parameterVariables.length === 0) {
7631
- // handle empty destructuring to avoid destructuring undefined
7520
+ // handle empty destructuring
7632
7521
  argumentIncluded = true;
7633
7522
  }
7634
7523
  else {
7635
7524
  for (const variable of parameterVariables) {
7636
- if (variable.calledFromTryStatement) {
7637
- calledFromTryStatement = true;
7638
- }
7639
7525
  if (variable.included) {
7640
7526
  argumentIncluded = true;
7641
- if (calledFromTryStatement) {
7642
- argument.includePath(UNKNOWN_PATH, context, true);
7643
- }
7644
- else {
7645
- variable.includeArgumentPaths(argument, context);
7646
- }
7527
+ }
7528
+ if (variable.calledFromTryStatement) {
7529
+ calledFromTryStatement = true;
7647
7530
  }
7648
7531
  }
7649
7532
  }
7650
7533
  }
7651
- if (!argument.included && (argumentIncluded || argument.shouldBeIncluded(context))) {
7534
+ if (!argumentIncluded && argument.shouldBeIncluded(context)) {
7652
7535
  argumentIncluded = true;
7653
- argument.includePath(EMPTY_PATH, context, calledFromTryStatement);
7536
+ }
7537
+ if (argumentIncluded) {
7538
+ argument.include(context, calledFromTryStatement);
7654
7539
  }
7655
7540
  }
7656
7541
  }
@@ -7665,61 +7550,11 @@ class ReturnValueScope extends ParameterScope {
7665
7550
  addReturnExpression(expression) {
7666
7551
  this.returnExpressions.push(expression);
7667
7552
  }
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
7553
  getReturnExpression() {
7703
7554
  if (this.returnExpression === null)
7704
7555
  this.updateReturnExpression();
7705
7556
  return this.returnExpression;
7706
7557
  }
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
7558
  updateReturnExpression() {
7724
7559
  if (this.returnExpressions.length === 1) {
7725
7560
  this.returnExpression = this.returnExpressions[0];
@@ -7735,26 +7570,24 @@ class ReturnValueScope extends ParameterScope {
7735
7570
 
7736
7571
  class FunctionScope extends ReturnValueScope {
7737
7572
  constructor(parent) {
7738
- super(parent, false);
7739
7573
  const { context } = parent;
7574
+ super(parent, false);
7740
7575
  this.variables.set('arguments', (this.argumentsVariable = new ArgumentsVariable(context)));
7741
7576
  this.variables.set('this', (this.thisVariable = new ThisVariable(context)));
7742
7577
  }
7743
7578
  findLexicalBoundary() {
7744
7579
  return this;
7745
7580
  }
7746
- includeCallArguments(context, interaction) {
7747
- super.includeCallArguments(context, interaction);
7581
+ includeCallArguments(context, parameters) {
7582
+ super.includeCallArguments(context, parameters);
7748
7583
  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);
7584
+ for (const argument of parameters) {
7585
+ if (!argument.included) {
7586
+ argument.include(context, false);
7587
+ }
7752
7588
  }
7753
7589
  }
7754
7590
  }
7755
- addArgumentToBeDeoptimized(argument) {
7756
- this.argumentsVariable.addArgumentToBeDeoptimized(argument);
7757
- }
7758
7591
  }
7759
7592
 
7760
7593
  class ExpressionStatement extends NodeBase {
@@ -7820,7 +7653,7 @@ class BlockStatement extends NodeBase {
7820
7653
  }
7821
7654
  return false;
7822
7655
  }
7823
- includePath(_path, context, includeChildrenRecursively) {
7656
+ include(context, includeChildrenRecursively) {
7824
7657
  if (!(this.deoptimizeBody && this.directlyIncluded)) {
7825
7658
  this.included = true;
7826
7659
  this.directlyIncluded = true;
@@ -7828,7 +7661,7 @@ class BlockStatement extends NodeBase {
7828
7661
  includeChildrenRecursively = true;
7829
7662
  for (const node of this.body) {
7830
7663
  if (includeChildrenRecursively || node.shouldBeIncluded(context))
7831
- node.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
7664
+ node.include(context, includeChildrenRecursively);
7832
7665
  }
7833
7666
  }
7834
7667
  }
@@ -7857,12 +7690,9 @@ class RestElement extends NodeBase {
7857
7690
  addExportedVariables(variables, exportNamesByVariable) {
7858
7691
  this.argument.addExportedVariables(variables, exportNamesByVariable);
7859
7692
  }
7860
- declare(kind, destructuredInitPath, init) {
7693
+ declare(kind, init) {
7861
7694
  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);
7695
+ return this.argument.declare(kind, UNKNOWN_EXPRESSION);
7866
7696
  }
7867
7697
  deoptimizePath(path) {
7868
7698
  if (path.length === 0) {
@@ -7873,19 +7703,6 @@ class RestElement extends NodeBase {
7873
7703
  return (path.length > 0 ||
7874
7704
  this.argument.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
7875
7705
  }
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
7706
  markDeclarationReached() {
7890
7707
  this.argument.markDeclarationReached();
7891
7708
  }
@@ -7897,15 +7714,12 @@ class RestElement extends NodeBase {
7897
7714
  }
7898
7715
  }
7899
7716
  }
7900
- const getIncludedPatternPath$1 = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
7901
- ? destructuredInitPath
7902
- : [...destructuredInitPath, UnknownKey];
7903
7717
 
7904
7718
  class FunctionBase extends NodeBase {
7905
7719
  constructor() {
7906
7720
  super(...arguments);
7721
+ this.objectEntity = null;
7907
7722
  this.parameterVariableValuesDeoptimized = false;
7908
- this.includeCallArguments = this.scope.includeCallArguments.bind(this.scope);
7909
7723
  }
7910
7724
  get async() {
7911
7725
  return isFlagSet(this.flags, 256 /* Flag.async */);
@@ -7925,9 +7739,53 @@ class FunctionBase extends NodeBase {
7925
7739
  set generator(value) {
7926
7740
  this.flags = setFlag(this.flags, 4194304 /* Flag.generator */, value);
7927
7741
  }
7742
+ updateParameterVariableValues(_arguments) {
7743
+ for (let position = 0; position < this.params.length; position++) {
7744
+ const parameter = this.params[position];
7745
+ if (!(parameter instanceof Identifier)) {
7746
+ continue;
7747
+ }
7748
+ const parameterVariable = parameter.variable;
7749
+ const argument = _arguments[position + 1] ?? UNDEFINED_EXPRESSION;
7750
+ parameterVariable.updateKnownValue(argument);
7751
+ }
7752
+ }
7753
+ deoptimizeParameterVariableValues() {
7754
+ for (const parameter of this.params) {
7755
+ if (parameter instanceof Identifier) {
7756
+ const parameterVariable = parameter.variable;
7757
+ parameterVariable.markReassigned();
7758
+ }
7759
+ }
7760
+ }
7928
7761
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
7929
- if (interaction.type === INTERACTION_CALLED && path.length === 0) {
7930
- this.scope.deoptimizeArgumentsOnCall(interaction);
7762
+ if (interaction.type === INTERACTION_CALLED) {
7763
+ const { parameters } = this.scope;
7764
+ const { args } = interaction;
7765
+ let hasRest = false;
7766
+ for (let position = 0; position < args.length - 1; position++) {
7767
+ const parameter = this.params[position];
7768
+ // Only the "this" argument arg[0] can be null
7769
+ const argument = args[position + 1];
7770
+ if (argument instanceof SpreadElement) {
7771
+ this.deoptimizeParameterVariableValues();
7772
+ }
7773
+ if (hasRest || parameter instanceof RestElement) {
7774
+ hasRest = true;
7775
+ argument.deoptimizePath(UNKNOWN_PATH);
7776
+ }
7777
+ else if (parameter instanceof Identifier) {
7778
+ parameters[position][0].addEntityToBeDeoptimized(argument);
7779
+ this.addArgumentToBeDeoptimized(argument);
7780
+ }
7781
+ else if (parameter) {
7782
+ argument.deoptimizePath(UNKNOWN_PATH);
7783
+ }
7784
+ else {
7785
+ this.addArgumentToBeDeoptimized(argument);
7786
+ }
7787
+ }
7788
+ this.updateParameterVariableValues(args);
7931
7789
  }
7932
7790
  else {
7933
7791
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -7939,7 +7797,12 @@ class FunctionBase extends NodeBase {
7939
7797
  // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
7940
7798
  // which means the return expression and parameters need to be reassigned
7941
7799
  this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
7942
- this.scope.deoptimizeAllParameters();
7800
+ for (const parameterList of this.scope.parameters) {
7801
+ for (const parameter of parameterList) {
7802
+ parameter.deoptimizePath(UNKNOWN_PATH);
7803
+ parameter.markReassigned();
7804
+ }
7805
+ }
7943
7806
  }
7944
7807
  }
7945
7808
  getLiteralValueAtPath(path, recursionTracker, origin) {
@@ -7977,13 +7840,8 @@ class FunctionBase extends NodeBase {
7977
7840
  return true;
7978
7841
  }
7979
7842
  }
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)))
7843
+ for (const parameter of this.params) {
7844
+ if (parameter.hasEffects(context))
7987
7845
  return true;
7988
7846
  }
7989
7847
  return false;
@@ -8001,19 +7859,22 @@ class FunctionBase extends NodeBase {
8001
7859
  }
8002
7860
  return variable?.getOnlyFunctionCallUsed() ?? false;
8003
7861
  }
8004
- includePath(_path, context, includeChildrenRecursively) {
8005
- if (!(this.parameterVariableValuesDeoptimized || this.onlyFunctionCallUsed())) {
7862
+ include(context, includeChildrenRecursively) {
7863
+ if (!this.parameterVariableValuesDeoptimized && !this.onlyFunctionCallUsed()) {
8006
7864
  this.parameterVariableValuesDeoptimized = true;
8007
- this.scope.reassignAllParameters();
7865
+ this.deoptimizeParameterVariableValues();
8008
7866
  }
8009
7867
  if (!this.deoptimized)
8010
7868
  this.applyDeoptimizations();
8011
7869
  this.included = true;
8012
7870
  const { brokenFlow } = context;
8013
7871
  context.brokenFlow = false;
8014
- this.body.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
7872
+ this.body.include(context, includeChildrenRecursively);
8015
7873
  context.brokenFlow = brokenFlow;
8016
7874
  }
7875
+ includeCallArguments(context, parameters) {
7876
+ this.scope.includeCallArguments(context, parameters);
7877
+ }
8017
7878
  initialise() {
8018
7879
  super.initialise();
8019
7880
  if (this.body instanceof BlockStatement) {
@@ -8035,10 +7896,11 @@ class FunctionBase extends NodeBase {
8035
7896
  // so that the scope already knows all parameters and can detect conflicts
8036
7897
  // when parsing the body.
8037
7898
  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);
7899
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
8039
7900
  this.body = new (context.getNodeConstructor(body.type))(this, bodyScope).parseNode(body);
8040
7901
  return super.parseNode(esTreeNode);
8041
7902
  }
7903
+ addArgumentToBeDeoptimized(_argument) { }
8042
7904
  applyDeoptimizations() { }
8043
7905
  }
8044
7906
  FunctionBase.prototype.preventChildBlockScope = true;
@@ -8053,13 +7915,13 @@ class FunctionNode extends FunctionBase {
8053
7915
  this.constructedEntity = new ObjectEntity(Object.create(null), OBJECT_PROTOTYPE);
8054
7916
  // This makes sure that all deoptimizations of "this" are applied to the
8055
7917
  // constructed entity.
8056
- this.scope.thisVariable.addArgumentValue(this.constructedEntity);
7918
+ this.scope.thisVariable.addEntityToBeDeoptimized(this.constructedEntity);
8057
7919
  }
8058
7920
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
8059
7921
  super.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
8060
7922
  if (interaction.type === INTERACTION_CALLED && path.length === 0 && interaction.args[0]) {
8061
7923
  // args[0] is the "this" argument
8062
- this.scope.thisVariable.addArgumentValue(interaction.args[0]);
7924
+ this.scope.thisVariable.addEntityToBeDeoptimized(interaction.args[0]);
8063
7925
  }
8064
7926
  }
8065
7927
  hasEffects(context) {
@@ -8100,19 +7962,22 @@ class FunctionNode extends FunctionBase {
8100
7962
  }
8101
7963
  return false;
8102
7964
  }
8103
- includePath(path, context, includeChildrenRecursively) {
8104
- super.includePath(path, context, includeChildrenRecursively);
8105
- this.id?.includePath(UNKNOWN_PATH, createInclusionContext());
7965
+ include(context, includeChildrenRecursively) {
7966
+ super.include(context, includeChildrenRecursively);
7967
+ this.id?.include();
8106
7968
  const hasArguments = this.scope.argumentsVariable.included;
8107
7969
  for (const parameter of this.params) {
8108
7970
  if (!(parameter instanceof Identifier) || hasArguments) {
8109
- parameter.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
7971
+ parameter.include(context, includeChildrenRecursively);
8110
7972
  }
8111
7973
  }
8112
7974
  }
8113
7975
  initialise() {
8114
7976
  super.initialise();
8115
- this.id?.declare('function', EMPTY_PATH, this);
7977
+ this.id?.declare('function', this);
7978
+ }
7979
+ addArgumentToBeDeoptimized(argument) {
7980
+ this.scope.argumentsVariable.addArgumentToBeDeoptimized(argument);
8116
7981
  }
8117
7982
  getObjectEntity() {
8118
7983
  if (this.objectEntity !== null) {
@@ -8161,11 +8026,10 @@ function getFunctionIdInsertPosition(code, start) {
8161
8026
  return declarationEnd + generatorStarPos + 1;
8162
8027
  }
8163
8028
  class ExportDefaultDeclaration extends NodeBase {
8164
- includePath(path, context, includeChildrenRecursively) {
8165
- this.included = true;
8166
- this.declaration.includePath(path, context, includeChildrenRecursively);
8029
+ include(context, includeChildrenRecursively) {
8030
+ super.include(context, includeChildrenRecursively);
8167
8031
  if (includeChildrenRecursively) {
8168
- this.scope.context.includeVariableInModule(this.variable, path);
8032
+ this.scope.context.includeVariableInModule(this.variable);
8169
8033
  }
8170
8034
  }
8171
8035
  initialise() {
@@ -8527,6 +8391,8 @@ function getChainElementLiteralValueAtPath(element, object, path, recursionTrack
8527
8391
  return element.getLiteralValueAtPath(path, recursionTracker, origin);
8528
8392
  }
8529
8393
 
8394
+ // To avoid infinite recursions
8395
+ const MAX_PATH_DEPTH = 7;
8530
8396
  function getResolvablePropertyKey(memberExpression) {
8531
8397
  return memberExpression.computed
8532
8398
  ? getResolvableComputedPropertyKey(memberExpression.property)
@@ -8632,10 +8498,6 @@ class MemberExpression extends NodeBase {
8632
8498
  }
8633
8499
  }
8634
8500
  }
8635
- deoptimizeAssignment(destructuredInitPath, init) {
8636
- this.deoptimizePath(EMPTY_PATH);
8637
- init.deoptimizePath([...destructuredInitPath, UnknownKey]);
8638
- }
8639
8501
  deoptimizeCache() {
8640
8502
  const { expressionsToBeDeoptimized, object } = this;
8641
8503
  this.expressionsToBeDeoptimized = parseAst_js.EMPTY_ARRAY;
@@ -8651,13 +8513,11 @@ class MemberExpression extends NodeBase {
8651
8513
  if (this.variable) {
8652
8514
  this.variable.deoptimizePath(path);
8653
8515
  }
8654
- else if (!this.isUndefined) {
8516
+ else if (!this.isUndefined && path.length < MAX_PATH_DEPTH) {
8655
8517
  const propertyKey = this.getPropertyKey();
8656
8518
  this.object.deoptimizePath([
8657
8519
  propertyKey === UnknownKey ? UnknownNonAccessorKey : propertyKey,
8658
- ...(path.length < MAX_PATH_DEPTH
8659
- ? path
8660
- : [...path.slice(0, MAX_PATH_DEPTH), UnknownKey])
8520
+ ...path
8661
8521
  ]);
8662
8522
  }
8663
8523
  }
@@ -8742,47 +8602,28 @@ class MemberExpression extends NodeBase {
8742
8602
  }
8743
8603
  return true;
8744
8604
  }
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) {
8605
+ include(context, includeChildrenRecursively) {
8750
8606
  if (!this.deoptimized)
8751
8607
  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);
8608
+ this.includeProperties(context, includeChildrenRecursively);
8758
8609
  }
8759
8610
  includeAsAssignmentTarget(context, includeChildrenRecursively, deoptimizeAccess) {
8760
8611
  if (!this.assignmentDeoptimized)
8761
8612
  this.applyAssignmentDeoptimization();
8762
8613
  if (deoptimizeAccess) {
8763
- this.includePath([this.getPropertyKey()], context, includeChildrenRecursively);
8614
+ this.include(context, includeChildrenRecursively);
8764
8615
  }
8765
8616
  else {
8766
- this.includeProperties(EMPTY_PATH, [this.getPropertyKey()], context, includeChildrenRecursively);
8617
+ this.includeProperties(context, includeChildrenRecursively);
8767
8618
  }
8768
8619
  }
8769
- includeCallArguments(context, interaction) {
8620
+ includeCallArguments(context, parameters) {
8770
8621
  if (this.variable) {
8771
- this.variable.includeCallArguments(context, interaction);
8622
+ this.variable.includeCallArguments(context, parameters);
8772
8623
  }
8773
8624
  else {
8774
- super.includeCallArguments(context, interaction);
8775
- }
8776
- }
8777
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
8778
- if ((this.included ||=
8779
- destructuredInitPath.length > 0 &&
8780
- !context.brokenFlow &&
8781
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, createHasEffectsContext()))) {
8782
- init.includePath(destructuredInitPath, context, false);
8783
- return true;
8625
+ super.includeCallArguments(context, parameters);
8784
8626
  }
8785
- return false;
8786
8627
  }
8787
8628
  initialise() {
8788
8629
  super.initialise();
@@ -8850,7 +8691,7 @@ class MemberExpression extends NodeBase {
8850
8691
  const variable = this.scope.findVariable(this.object.name);
8851
8692
  if (variable.isNamespace) {
8852
8693
  if (this.variable) {
8853
- this.scope.context.includeVariableInModule(this.variable, UNKNOWN_PATH);
8694
+ this.scope.context.includeVariableInModule(this.variable);
8854
8695
  }
8855
8696
  this.scope.context.log(parseAst_js.LOGLEVEL_WARN, parseAst_js.logIllegalImportReassignment(this.object.name, this.scope.context.module.id), this.start);
8856
8697
  }
@@ -8877,18 +8718,15 @@ class MemberExpression extends NodeBase {
8877
8718
  (propertyReadSideEffects === 'always' ||
8878
8719
  this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey()], this.accessInteraction, context)));
8879
8720
  }
8880
- includeProperties(includedPath, objectPath, context, includeChildrenRecursively) {
8721
+ includeProperties(context, includeChildrenRecursively) {
8881
8722
  if (!this.included) {
8882
8723
  this.included = true;
8883
8724
  if (this.variable) {
8884
- this.scope.context.includeVariableInModule(this.variable, includedPath);
8725
+ this.scope.context.includeVariableInModule(this.variable);
8885
8726
  }
8886
8727
  }
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);
8728
+ this.object.include(context, includeChildrenRecursively);
8729
+ this.property.include(context, includeChildrenRecursively);
8892
8730
  }
8893
8731
  }
8894
8732
  function resolveNamespaceVariables(baseVariable, path, astContext) {
@@ -8931,7 +8769,7 @@ class MetaProperty extends NodeBase {
8931
8769
  hasEffectsOnInteractionAtPath(path, { type }) {
8932
8770
  return path.length > 1 || type !== INTERACTION_ACCESSED;
8933
8771
  }
8934
- includePath() {
8772
+ include() {
8935
8773
  if (!this.included) {
8936
8774
  this.included = true;
8937
8775
  if (this.meta.name === IMPORT) {
@@ -9050,7 +8888,7 @@ class UndefinedVariable extends Variable {
9050
8888
 
9051
8889
  class ExportDefaultVariable extends LocalVariable {
9052
8890
  constructor(name, exportDefaultDeclaration, context) {
9053
- super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, EMPTY_PATH, context, 'other');
8891
+ super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context, 'other');
9054
8892
  this.hasId = false;
9055
8893
  this.originalId = null;
9056
8894
  this.originalVariable = null;
@@ -9199,8 +9037,8 @@ class NamespaceVariable extends Variable {
9199
9037
  return (!memberVariable ||
9200
9038
  memberVariable.hasEffectsOnInteractionAtPath(path.slice(1), interaction, context));
9201
9039
  }
9202
- includePath(path, context) {
9203
- super.includePath(path, context);
9040
+ include() {
9041
+ super.include();
9204
9042
  this.context.includeAllExports();
9205
9043
  }
9206
9044
  prepare(accessedGlobalsByScope) {
@@ -9293,9 +9131,9 @@ class SyntheticNamedExportVariable extends Variable {
9293
9131
  getName(getPropertyAccess) {
9294
9132
  return `${this.syntheticNamespace.getName(getPropertyAccess)}${getPropertyAccess(this.name)}`;
9295
9133
  }
9296
- includePath(path, context) {
9297
- super.includePath(path, context);
9298
- this.context.includeVariableInModule(this.syntheticNamespace, path);
9134
+ include() {
9135
+ super.include();
9136
+ this.context.includeVariableInModule(this.syntheticNamespace);
9299
9137
  }
9300
9138
  setRenderNames(baseName, name) {
9301
9139
  super.setRenderNames(baseName, name);
@@ -12494,37 +12332,21 @@ class ArrayPattern extends NodeBase {
12494
12332
  element?.addExportedVariables(variables, exportNamesByVariable);
12495
12333
  }
12496
12334
  }
12497
- declare(kind, destructuredInitPath, init) {
12335
+ declare(kind) {
12498
12336
  const variables = [];
12499
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12500
12337
  for (const element of this.elements) {
12501
12338
  if (element !== null) {
12502
- variables.push(...element.declare(kind, includedPatternPath, init));
12339
+ variables.push(...element.declare(kind, UNKNOWN_EXPRESSION));
12503
12340
  }
12504
12341
  }
12505
12342
  return variables;
12506
12343
  }
12507
- deoptimizeAssignment(destructuredInitPath, init) {
12508
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12509
- for (const element of this.elements) {
12510
- element?.deoptimizeAssignment(includedPatternPath, init);
12511
- }
12512
- }
12513
12344
  // Patterns can only be deoptimized at the empty path at the moment
12514
12345
  deoptimizePath() {
12515
12346
  for (const element of this.elements) {
12516
12347
  element?.deoptimizePath(EMPTY_PATH);
12517
12348
  }
12518
12349
  }
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
12350
  // Patterns are only checked at the empty path at the moment
12529
12351
  hasEffectsOnInteractionAtPath(_path, interaction, context) {
12530
12352
  for (const element of this.elements) {
@@ -12533,37 +12355,12 @@ class ArrayPattern extends NodeBase {
12533
12355
  }
12534
12356
  return false;
12535
12357
  }
12536
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
12537
- let included = false;
12538
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12539
- for (const element of this.elements) {
12540
- if (element) {
12541
- element.included ||= included;
12542
- included =
12543
- element.includeDestructuredIfNecessary(context, includedPatternPath, init) || included;
12544
- }
12545
- }
12546
- if (included) {
12547
- // This is necessary so that if any pattern element is included, all are
12548
- // included for proper deconflicting
12549
- for (const element of this.elements) {
12550
- if (element && !element.included) {
12551
- element.included = true;
12552
- element.includeDestructuredIfNecessary(context, includedPatternPath, init);
12553
- }
12554
- }
12555
- }
12556
- return (this.included ||= included);
12557
- }
12558
12358
  markDeclarationReached() {
12559
12359
  for (const element of this.elements) {
12560
12360
  element?.markDeclarationReached();
12561
12361
  }
12562
12362
  }
12563
12363
  }
12564
- const getIncludedPatternPath = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
12565
- ? destructuredInitPath
12566
- : [...destructuredInitPath, UnknownInteger];
12567
12364
 
12568
12365
  class ArrowFunctionExpression extends FunctionBase {
12569
12366
  constructor() {
@@ -12612,11 +12409,11 @@ class ArrowFunctionExpression extends FunctionBase {
12612
12409
  this.parent.callee === this;
12613
12410
  return isIIFE || super.onlyFunctionCallUsed();
12614
12411
  }
12615
- includePath(_path, context, includeChildrenRecursively) {
12616
- super.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12412
+ include(context, includeChildrenRecursively) {
12413
+ super.include(context, includeChildrenRecursively);
12617
12414
  for (const parameter of this.params) {
12618
12415
  if (!(parameter instanceof Identifier)) {
12619
- parameter.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12416
+ parameter.include(context, includeChildrenRecursively);
12620
12417
  }
12621
12418
  }
12622
12419
  }
@@ -12639,18 +12436,13 @@ class ObjectPattern extends NodeBase {
12639
12436
  }
12640
12437
  }
12641
12438
  }
12642
- declare(kind, destructuredInitPath, init) {
12439
+ declare(kind, init) {
12643
12440
  const variables = [];
12644
12441
  for (const property of this.properties) {
12645
- variables.push(...property.declare(kind, destructuredInitPath, init));
12442
+ variables.push(...property.declare(kind, init));
12646
12443
  }
12647
12444
  return variables;
12648
12445
  }
12649
- deoptimizeAssignment(destructuredInitPath, init) {
12650
- for (const property of this.properties) {
12651
- property.deoptimizeAssignment(destructuredInitPath, init);
12652
- }
12653
- }
12654
12446
  deoptimizePath(path) {
12655
12447
  if (path.length === 0) {
12656
12448
  for (const property of this.properties) {
@@ -12668,44 +12460,11 @@ class ObjectPattern extends NodeBase {
12668
12460
  }
12669
12461
  return false;
12670
12462
  }
12671
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
12672
- for (const property of this.properties) {
12673
- if (property.hasEffectsWhenDestructuring(context, destructuredInitPath, init))
12674
- return true;
12675
- }
12676
- return false;
12677
- }
12678
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
12679
- let included = false;
12680
- for (const property of this.properties) {
12681
- included =
12682
- property.includeDestructuredIfNecessary(context, destructuredInitPath, init) || included;
12683
- }
12684
- return (this.included ||= included);
12685
- }
12686
12463
  markDeclarationReached() {
12687
12464
  for (const property of this.properties) {
12688
12465
  property.markDeclarationReached();
12689
12466
  }
12690
12467
  }
12691
- render(code, options) {
12692
- if (this.properties.length > 0) {
12693
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
12694
- let lastSeparatorPos = null;
12695
- for (const { node, separator, start, end } of separatedNodes) {
12696
- if (!node.included) {
12697
- treeshakeNode(node, code, start, end);
12698
- continue;
12699
- }
12700
- lastSeparatorPos = separator;
12701
- node.render(code, options);
12702
- }
12703
- if (lastSeparatorPos) {
12704
- code.remove(lastSeparatorPos, this.end - 1);
12705
- }
12706
- }
12707
- }
12708
- applyDeoptimizations() { }
12709
12468
  }
12710
12469
 
12711
12470
  class AssignmentExpression extends NodeBase {
@@ -12715,27 +12474,23 @@ class AssignmentExpression extends NodeBase {
12715
12474
  this.applyDeoptimizations();
12716
12475
  // MemberExpressions do not access the property before assignments if the
12717
12476
  // operator is '='.
12718
- return (right.hasEffects(context) ||
12719
- left.hasEffectsAsAssignmentTarget(context, operator !== '=') ||
12720
- this.left.hasEffectsWhenDestructuring?.(context, EMPTY_PATH, right));
12477
+ return (right.hasEffects(context) || left.hasEffectsAsAssignmentTarget(context, operator !== '='));
12721
12478
  }
12722
12479
  hasEffectsOnInteractionAtPath(path, interaction, context) {
12723
12480
  return this.right.hasEffectsOnInteractionAtPath(path, interaction, context);
12724
12481
  }
12725
- includePath(_path, context, includeChildrenRecursively) {
12482
+ include(context, includeChildrenRecursively) {
12726
12483
  const { deoptimized, left, right, operator } = this;
12727
12484
  if (!deoptimized)
12728
12485
  this.applyDeoptimizations();
12729
12486
  this.included = true;
12730
- const hasEffectsContext = createHasEffectsContext();
12731
12487
  if (includeChildrenRecursively ||
12732
12488
  operator !== '=' ||
12733
12489
  left.included ||
12734
- left.hasEffectsAsAssignmentTarget(hasEffectsContext, false) ||
12735
- left.hasEffectsWhenDestructuring?.(hasEffectsContext, EMPTY_PATH, right)) {
12490
+ left.hasEffectsAsAssignmentTarget(createHasEffectsContext(), false)) {
12736
12491
  left.includeAsAssignmentTarget(context, includeChildrenRecursively, operator !== '=');
12737
12492
  }
12738
- right.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12493
+ right.include(context, includeChildrenRecursively);
12739
12494
  }
12740
12495
  initialise() {
12741
12496
  super.initialise();
@@ -12797,7 +12552,8 @@ class AssignmentExpression extends NodeBase {
12797
12552
  }
12798
12553
  applyDeoptimizations() {
12799
12554
  this.deoptimized = true;
12800
- this.left.deoptimizeAssignment(EMPTY_PATH, this.right);
12555
+ this.left.deoptimizePath(EMPTY_PATH);
12556
+ this.right.deoptimizePath(UNKNOWN_PATH);
12801
12557
  this.scope.context.requestTreeshakingPass();
12802
12558
  }
12803
12559
  }
@@ -12806,11 +12562,8 @@ class AssignmentPattern extends NodeBase {
12806
12562
  addExportedVariables(variables, exportNamesByVariable) {
12807
12563
  this.left.addExportedVariables(variables, exportNamesByVariable);
12808
12564
  }
12809
- declare(kind, destructuredInitPath, init) {
12810
- return this.left.declare(kind, destructuredInitPath, init);
12811
- }
12812
- deoptimizeAssignment(destructuredInitPath, init) {
12813
- this.left.deoptimizeAssignment(destructuredInitPath, init);
12565
+ declare(kind, init) {
12566
+ return this.left.declare(kind, init);
12814
12567
  }
12815
12568
  deoptimizePath(path) {
12816
12569
  if (path.length === 0) {
@@ -12820,23 +12573,6 @@ class AssignmentPattern extends NodeBase {
12820
12573
  hasEffectsOnInteractionAtPath(path, interaction, context) {
12821
12574
  return (path.length > 0 || this.left.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
12822
12575
  }
12823
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
12824
- return this.left.hasEffectsWhenDestructuring(context, destructuredInitPath, init);
12825
- }
12826
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
12827
- let included = this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init) ||
12828
- this.included;
12829
- if ((included ||= this.right.shouldBeIncluded(context))) {
12830
- this.right.includePath(UNKNOWN_PATH, context, false);
12831
- if (!this.left.included) {
12832
- this.left.included = true;
12833
- // Unfortunately, we need to include the left side again now, so that
12834
- // any declared variables are properly included.
12835
- this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init);
12836
- }
12837
- }
12838
- return (this.included = included);
12839
- }
12840
12576
  markDeclarationReached() {
12841
12577
  this.left.markDeclarationReached();
12842
12578
  }
@@ -12858,7 +12594,7 @@ class AwaitExpression extends NodeBase {
12858
12594
  this.applyDeoptimizations();
12859
12595
  return true;
12860
12596
  }
12861
- includePath(path, context, includeChildrenRecursively) {
12597
+ include(context, includeChildrenRecursively) {
12862
12598
  if (!this.deoptimized)
12863
12599
  this.applyDeoptimizations();
12864
12600
  if (!this.included) {
@@ -12872,7 +12608,7 @@ class AwaitExpression extends NodeBase {
12872
12608
  this.scope.context.usesTopLevelAwait = true;
12873
12609
  }
12874
12610
  }
12875
- this.argument.includePath(path, context, includeChildrenRecursively);
12611
+ this.argument.include(context, includeChildrenRecursively);
12876
12612
  }
12877
12613
  }
12878
12614
 
@@ -12954,10 +12690,10 @@ class BreakStatement extends NodeBase {
12954
12690
  context.brokenFlow = true;
12955
12691
  return false;
12956
12692
  }
12957
- includePath(_, context) {
12693
+ include(context) {
12958
12694
  this.included = true;
12959
12695
  if (this.label) {
12960
- this.label.includePath(UNKNOWN_PATH, createInclusionContext());
12696
+ this.label.include();
12961
12697
  context.includedLabels.add(this.label.name);
12962
12698
  }
12963
12699
  else {
@@ -13151,11 +12887,11 @@ class CallExpression extends CallExpressionBase {
13151
12887
  (calleeHasEffects ||
13152
12888
  this.callee.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context)));
13153
12889
  }
13154
- includePath(path, context, includeChildrenRecursively) {
12890
+ include(context, includeChildrenRecursively) {
13155
12891
  if (!this.deoptimized)
13156
12892
  this.applyDeoptimizations();
13157
12893
  if (includeChildrenRecursively) {
13158
- super.includePath(path, context, includeChildrenRecursively);
12894
+ super.include(context, includeChildrenRecursively);
13159
12895
  if (includeChildrenRecursively === INCLUDE_PARAMETERS &&
13160
12896
  this.callee instanceof Identifier &&
13161
12897
  this.callee.variable) {
@@ -13164,18 +12900,9 @@ class CallExpression extends CallExpressionBase {
13164
12900
  }
13165
12901
  else {
13166
12902
  this.included = true;
13167
- // If the callee is a member expression and does not have a variable, its
13168
- // object will already be included via the first argument of the
13169
- // interaction in includeCallArguments. Including it again can lead to
13170
- // severe performance problems.
13171
- if (this.callee instanceof MemberExpression && !this.callee.variable) {
13172
- this.callee.property.includePath(UNKNOWN_PATH, context, false);
13173
- }
13174
- else {
13175
- this.callee.includePath(UNKNOWN_PATH, context, false);
13176
- }
13177
- this.callee.includeCallArguments(context, this.interaction);
12903
+ this.callee.include(context, false);
13178
12904
  }
12905
+ this.callee.includeCallArguments(context, this.arguments);
13179
12906
  }
13180
12907
  initialise() {
13181
12908
  super.initialise();
@@ -13214,7 +12941,7 @@ class CatchClause extends NodeBase {
13214
12941
  this.type = type;
13215
12942
  if (param) {
13216
12943
  this.param = new (this.scope.context.getNodeConstructor(param.type))(this, this.scope).parseNode(param);
13217
- this.param.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
12944
+ this.param.declare('parameter', UNKNOWN_EXPRESSION);
13218
12945
  }
13219
12946
  this.body = new BlockStatement(this, this.scope.bodyScope).parseNode(body);
13220
12947
  return super.parseNode(esTreeNode);
@@ -13242,7 +12969,7 @@ class ClassBodyScope extends ChildScope {
13242
12969
  constructor(parent, classNode) {
13243
12970
  const { context } = parent;
13244
12971
  super(parent, context);
13245
- this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, EMPTY_PATH, context, 'other')));
12972
+ this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, context, 'other')));
13246
12973
  this.instanceScope = new ChildScope(this, context);
13247
12974
  this.instanceScope.variables.set('this', new ThisVariable(context));
13248
12975
  }
@@ -13255,11 +12982,11 @@ class ClassBody extends NodeBase {
13255
12982
  createScope(parentScope) {
13256
12983
  this.scope = new ClassBodyScope(parentScope, this.parent);
13257
12984
  }
13258
- includePath(_path, context, includeChildrenRecursively) {
12985
+ include(context, includeChildrenRecursively) {
13259
12986
  this.included = true;
13260
- this.scope.context.includeVariableInModule(this.scope.thisVariable, UNKNOWN_PATH);
12987
+ this.scope.context.includeVariableInModule(this.scope.thisVariable);
13261
12988
  for (const definition of this.body) {
13262
- definition.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
12989
+ definition.include(context, includeChildrenRecursively);
13263
12990
  }
13264
12991
  }
13265
12992
  parseNode(esTreeNode) {
@@ -13383,26 +13110,26 @@ class ConditionalExpression extends NodeBase {
13383
13110
  }
13384
13111
  return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
13385
13112
  }
13386
- includePath(path, context, includeChildrenRecursively) {
13113
+ include(context, includeChildrenRecursively) {
13387
13114
  this.included = true;
13388
13115
  const usedBranch = this.getUsedBranch();
13389
13116
  if (includeChildrenRecursively || this.test.shouldBeIncluded(context) || usedBranch === null) {
13390
- this.test.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13391
- this.consequent.includePath(path, context, includeChildrenRecursively);
13392
- this.alternate.includePath(path, context, includeChildrenRecursively);
13117
+ this.test.include(context, includeChildrenRecursively);
13118
+ this.consequent.include(context, includeChildrenRecursively);
13119
+ this.alternate.include(context, includeChildrenRecursively);
13393
13120
  }
13394
13121
  else {
13395
- usedBranch.includePath(path, context, includeChildrenRecursively);
13122
+ usedBranch.include(context, includeChildrenRecursively);
13396
13123
  }
13397
13124
  }
13398
- includeCallArguments(context, interaction) {
13125
+ includeCallArguments(context, parameters) {
13399
13126
  const usedBranch = this.getUsedBranch();
13400
13127
  if (usedBranch) {
13401
- usedBranch.includeCallArguments(context, interaction);
13128
+ usedBranch.includeCallArguments(context, parameters);
13402
13129
  }
13403
13130
  else {
13404
- this.consequent.includeCallArguments(context, interaction);
13405
- this.alternate.includeCallArguments(context, interaction);
13131
+ this.consequent.includeCallArguments(context, parameters);
13132
+ this.alternate.includeCallArguments(context, parameters);
13406
13133
  }
13407
13134
  }
13408
13135
  removeAnnotations(code) {
@@ -13463,10 +13190,10 @@ class ContinueStatement extends NodeBase {
13463
13190
  context.brokenFlow = true;
13464
13191
  return false;
13465
13192
  }
13466
- includePath(_, context) {
13193
+ include(context) {
13467
13194
  this.included = true;
13468
13195
  if (this.label) {
13469
- this.label.includePath(UNKNOWN_PATH, createInclusionContext());
13196
+ this.label.include();
13470
13197
  context.includedLabels.add(this.label.name);
13471
13198
  }
13472
13199
  else {
@@ -13509,7 +13236,7 @@ function includeLoopBody(context, body, includeChildrenRecursively) {
13509
13236
  const { brokenFlow, hasBreak, hasContinue } = context;
13510
13237
  context.hasBreak = false;
13511
13238
  context.hasContinue = false;
13512
- body.includePath(UNKNOWN_PATH, context, includeChildrenRecursively, { asSingleStatement: true });
13239
+ body.include(context, includeChildrenRecursively, { asSingleStatement: true });
13513
13240
  context.hasBreak = hasBreak;
13514
13241
  context.hasContinue = hasContinue;
13515
13242
  context.brokenFlow = brokenFlow;
@@ -13521,9 +13248,9 @@ class DoWhileStatement extends NodeBase {
13521
13248
  return true;
13522
13249
  return hasLoopBodyEffects(context, this.body);
13523
13250
  }
13524
- includePath(_path, context, includeChildrenRecursively) {
13251
+ include(context, includeChildrenRecursively) {
13525
13252
  this.included = true;
13526
- this.test.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13253
+ this.test.include(context, includeChildrenRecursively);
13527
13254
  includeLoopBody(context, this.body, includeChildrenRecursively);
13528
13255
  }
13529
13256
  }
@@ -13594,13 +13321,13 @@ class ForInStatement extends NodeBase {
13594
13321
  return true;
13595
13322
  return hasLoopBodyEffects(context, body);
13596
13323
  }
13597
- includePath(_path, context, includeChildrenRecursively) {
13324
+ include(context, includeChildrenRecursively) {
13598
13325
  const { body, deoptimized, left, right } = this;
13599
13326
  if (!deoptimized)
13600
13327
  this.applyDeoptimizations();
13601
13328
  this.included = true;
13602
13329
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
13603
- right.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13330
+ right.include(context, includeChildrenRecursively);
13604
13331
  includeLoopBody(context, body, includeChildrenRecursively);
13605
13332
  }
13606
13333
  initialise() {
@@ -13639,13 +13366,13 @@ class ForOfStatement extends NodeBase {
13639
13366
  // Placeholder until proper Symbol.Iterator support
13640
13367
  return true;
13641
13368
  }
13642
- includePath(_path, context, includeChildrenRecursively) {
13369
+ include(context, includeChildrenRecursively) {
13643
13370
  const { body, deoptimized, left, right } = this;
13644
13371
  if (!deoptimized)
13645
13372
  this.applyDeoptimizations();
13646
13373
  this.included = true;
13647
13374
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
13648
- right.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13375
+ right.include(context, includeChildrenRecursively);
13649
13376
  includeLoopBody(context, body, includeChildrenRecursively);
13650
13377
  }
13651
13378
  initialise() {
@@ -13681,13 +13408,11 @@ class ForStatement extends NodeBase {
13681
13408
  }
13682
13409
  return hasLoopBodyEffects(context, this.body);
13683
13410
  }
13684
- includePath(_path, context, includeChildrenRecursively) {
13411
+ include(context, includeChildrenRecursively) {
13685
13412
  this.included = true;
13686
- this.init?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively, {
13687
- asSingleStatement: true
13688
- });
13689
- this.test?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13690
- this.update?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13413
+ this.init?.include(context, includeChildrenRecursively, { asSingleStatement: true });
13414
+ this.test?.include(context, includeChildrenRecursively);
13415
+ this.update?.include(context, includeChildrenRecursively);
13691
13416
  includeLoopBody(context, this.body, includeChildrenRecursively);
13692
13417
  }
13693
13418
  render(code, options) {
@@ -13728,9 +13453,9 @@ class TrackingScope extends BlockScope {
13728
13453
  super(...arguments);
13729
13454
  this.hoistedDeclarations = [];
13730
13455
  }
13731
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
13456
+ addDeclaration(identifier, context, init, kind) {
13732
13457
  this.hoistedDeclarations.push(identifier);
13733
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
13458
+ return super.addDeclaration(identifier, context, init, kind);
13734
13459
  }
13735
13460
  }
13736
13461
 
@@ -13763,7 +13488,7 @@ class IfStatement extends NodeBase {
13763
13488
  }
13764
13489
  return testValue ? this.consequent.hasEffects(context) : !!this.alternate?.hasEffects(context);
13765
13490
  }
13766
- includePath(_, context, includeChildrenRecursively) {
13491
+ include(context, includeChildrenRecursively) {
13767
13492
  this.included = true;
13768
13493
  if (includeChildrenRecursively) {
13769
13494
  this.includeRecursively(includeChildrenRecursively, context);
@@ -13838,31 +13563,31 @@ class IfStatement extends NodeBase {
13838
13563
  }
13839
13564
  includeKnownTest(context, testValue) {
13840
13565
  if (this.test.shouldBeIncluded(context)) {
13841
- this.test.includePath(UNKNOWN_PATH, context, false);
13566
+ this.test.include(context, false);
13842
13567
  }
13843
13568
  if (testValue && this.consequent.shouldBeIncluded(context)) {
13844
- this.consequent.includePath(UNKNOWN_PATH, context, false, { asSingleStatement: true });
13569
+ this.consequent.include(context, false, { asSingleStatement: true });
13845
13570
  }
13846
13571
  if (!testValue && this.alternate?.shouldBeIncluded(context)) {
13847
- this.alternate.includePath(UNKNOWN_PATH, context, false, { asSingleStatement: true });
13572
+ this.alternate.include(context, false, { asSingleStatement: true });
13848
13573
  }
13849
13574
  }
13850
13575
  includeRecursively(includeChildrenRecursively, context) {
13851
- this.test.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13852
- this.consequent.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13853
- this.alternate?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
13576
+ this.test.include(context, includeChildrenRecursively);
13577
+ this.consequent.include(context, includeChildrenRecursively);
13578
+ this.alternate?.include(context, includeChildrenRecursively);
13854
13579
  }
13855
13580
  includeUnknownTest(context) {
13856
- this.test.includePath(UNKNOWN_PATH, context, false);
13581
+ this.test.include(context, false);
13857
13582
  const { brokenFlow } = context;
13858
13583
  let consequentBrokenFlow = false;
13859
13584
  if (this.consequent.shouldBeIncluded(context)) {
13860
- this.consequent.includePath(UNKNOWN_PATH, context, false, { asSingleStatement: true });
13585
+ this.consequent.include(context, false, { asSingleStatement: true });
13861
13586
  consequentBrokenFlow = context.brokenFlow;
13862
13587
  context.brokenFlow = brokenFlow;
13863
13588
  }
13864
13589
  if (this.alternate?.shouldBeIncluded(context)) {
13865
- this.alternate.includePath(UNKNOWN_PATH, context, false, { asSingleStatement: true });
13590
+ this.alternate.include(context, false, { asSingleStatement: true });
13866
13591
  context.brokenFlow = context.brokenFlow && consequentBrokenFlow;
13867
13592
  }
13868
13593
  }
@@ -13930,7 +13655,7 @@ function isReassignedExportsMember(variable, exportNamesByVariable) {
13930
13655
  class VariableDeclarator extends NodeBase {
13931
13656
  declareDeclarator(kind, isUsingDeclaration) {
13932
13657
  this.isUsingDeclaration = isUsingDeclaration;
13933
- this.id.declare(kind, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION);
13658
+ this.id.declare(kind, this.init || UNDEFINED_EXPRESSION);
13934
13659
  }
13935
13660
  deoptimizePath(path) {
13936
13661
  this.id.deoptimizePath(path);
@@ -13940,25 +13665,17 @@ class VariableDeclarator extends NodeBase {
13940
13665
  this.applyDeoptimizations();
13941
13666
  const initEffect = this.init?.hasEffects(context);
13942
13667
  this.id.markDeclarationReached();
13943
- return (initEffect ||
13944
- this.isUsingDeclaration ||
13945
- this.id.hasEffects(context) ||
13946
- (this.scope.context.options.treeshake
13947
- .propertyReadSideEffects &&
13948
- this.id.hasEffectsWhenDestructuring(context, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION)));
13949
- }
13950
- includePath(_path, context, includeChildrenRecursively) {
13668
+ return initEffect || this.id.hasEffects(context) || this.isUsingDeclaration;
13669
+ }
13670
+ include(context, includeChildrenRecursively) {
13951
13671
  const { deoptimized, id, init } = this;
13952
13672
  if (!deoptimized)
13953
13673
  this.applyDeoptimizations();
13954
13674
  this.included = true;
13955
- init?.includePath(EMPTY_PATH, context, includeChildrenRecursively);
13675
+ init?.include(context, includeChildrenRecursively);
13956
13676
  id.markDeclarationReached();
13957
- if (includeChildrenRecursively) {
13958
- id.includePath(EMPTY_PATH, context, includeChildrenRecursively);
13959
- }
13960
- else {
13961
- id.includeDestructuredIfNecessary(context, EMPTY_PATH, init || UNDEFINED_EXPRESSION);
13677
+ if (includeChildrenRecursively || id.shouldBeIncluded(context)) {
13678
+ id.include(context, includeChildrenRecursively);
13962
13679
  }
13963
13680
  }
13964
13681
  removeAnnotations(code) {
@@ -14007,8 +13724,6 @@ class ImportExpression extends NodeBase {
14007
13724
  constructor() {
14008
13725
  super(...arguments);
14009
13726
  this.inlineNamespace = null;
14010
- this.hasUnknownAccessedKey = false;
14011
- this.accessedPropKey = new Set();
14012
13727
  this.attributes = null;
14013
13728
  this.mechanism = null;
14014
13729
  this.namespaceExportName = undefined;
@@ -14041,15 +13756,12 @@ class ImportExpression extends NodeBase {
14041
13756
  if (parent2 instanceof ExpressionStatement) {
14042
13757
  return parseAst_js.EMPTY_ARRAY;
14043
13758
  }
14044
- // Case 1: const { foo } / module = await import('bar')
13759
+ // Case 1: const { foo } = await import('bar')
14045
13760
  if (parent2 instanceof VariableDeclarator) {
14046
13761
  const declaration = parent2.id;
14047
- if (declaration instanceof Identifier) {
14048
- return this.hasUnknownAccessedKey ? undefined : [...this.accessedPropKey];
14049
- }
14050
- if (declaration instanceof ObjectPattern) {
14051
- return getDeterministicObjectDestructure(declaration);
14052
- }
13762
+ return declaration instanceof ObjectPattern
13763
+ ? getDeterministicObjectDestructure(declaration)
13764
+ : undefined;
14053
13765
  }
14054
13766
  // Case 2: (await import('bar')).foo
14055
13767
  if (parent2 instanceof MemberExpression) {
@@ -14098,23 +13810,13 @@ class ImportExpression extends NodeBase {
14098
13810
  hasEffects() {
14099
13811
  return true;
14100
13812
  }
14101
- includePath(path, context, includeChildrenRecursively) {
13813
+ include(context, includeChildrenRecursively) {
14102
13814
  if (!this.included) {
14103
13815
  this.included = true;
14104
13816
  this.scope.context.includeDynamicImport(this);
14105
13817
  this.scope.addAccessedDynamicImport(this);
14106
- this.source.includePath(path, context, includeChildrenRecursively);
14107
- }
14108
- if (this.hasUnknownAccessedKey)
14109
- return;
14110
- if (path[0] === UnknownKey) {
14111
- this.hasUnknownAccessedKey = true;
14112
- this.scope.context.includeDynamicImport(this);
14113
- }
14114
- else if (typeof path[0] === 'string') {
14115
- this.accessedPropKey.add(path[0]);
14116
- this.scope.context.includeDynamicImport(this);
14117
13818
  }
13819
+ this.source.include(context, includeChildrenRecursively);
14118
13820
  }
14119
13821
  initialise() {
14120
13822
  super.initialise();
@@ -14442,7 +14144,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node) {
14442
14144
  if (preserve) {
14443
14145
  // This pretends we are accessing an included global variable of the same name
14444
14146
  const globalVariable = node.scope.findGlobal(baseName);
14445
- globalVariable.includePath(UNKNOWN_PATH, createInclusionContext());
14147
+ globalVariable.include();
14446
14148
  // This excludes this variable from renaming
14447
14149
  factoryVariable.globalName = baseName;
14448
14150
  }
@@ -14450,7 +14152,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node) {
14450
14152
  else {
14451
14153
  factoryVariable = node.scope.findGlobal(baseName);
14452
14154
  }
14453
- node.scope.context.includeVariableInModule(factoryVariable, UNKNOWN_PATH);
14155
+ node.scope.context.includeVariableInModule(factoryVariable);
14454
14156
  if (factoryVariable instanceof LocalVariable) {
14455
14157
  factoryVariable.consolidateInitializers();
14456
14158
  factoryVariable.addUsedPlace(node);
@@ -14472,7 +14174,7 @@ class JSXElementBase extends NodeBase {
14472
14174
  this.scope.context.addImportSource(importSource);
14473
14175
  }
14474
14176
  }
14475
- includePath(path, context, includeChildrenRecursively) {
14177
+ include(context, includeChildrenRecursively) {
14476
14178
  if (!this.included) {
14477
14179
  const { factory, importSource, mode } = this.jsxMode;
14478
14180
  if (factory) {
@@ -14480,7 +14182,7 @@ class JSXElementBase extends NodeBase {
14480
14182
  this.factoryVariable = getAndIncludeFactoryVariable(factory, mode === 'preserve', importSource, this);
14481
14183
  }
14482
14184
  }
14483
- super.includePath(path, context, includeChildrenRecursively);
14185
+ super.include(context, includeChildrenRecursively);
14484
14186
  }
14485
14187
  applyDeoptimizations() { }
14486
14188
  getRenderingMode() {
@@ -14742,7 +14444,7 @@ class JSXOpeningFragment extends NodeBase {
14742
14444
  this.fragment = null;
14743
14445
  this.fragmentVariable = null;
14744
14446
  }
14745
- includePath(path, context, includeChildrenRecursively) {
14447
+ include(context, includeChildrenRecursively) {
14746
14448
  if (!this.included) {
14747
14449
  const jsx = this.scope.context.options.jsx;
14748
14450
  if (jsx.mode === 'automatic') {
@@ -14757,7 +14459,7 @@ class JSXOpeningFragment extends NodeBase {
14757
14459
  }
14758
14460
  }
14759
14461
  }
14760
- super.includePath(path, context, includeChildrenRecursively);
14462
+ super.include(context, includeChildrenRecursively);
14761
14463
  }
14762
14464
  render(code, options) {
14763
14465
  const { mode } = this.scope.context.options.jsx;
@@ -14814,13 +14516,13 @@ class LabeledStatement extends NodeBase {
14814
14516
  context.includedLabels = new Set([...includedLabels, ...context.includedLabels]);
14815
14517
  return bodyHasEffects;
14816
14518
  }
14817
- includePath(_path, context, includeChildrenRecursively) {
14519
+ include(context, includeChildrenRecursively) {
14818
14520
  this.included = true;
14819
14521
  const { brokenFlow, includedLabels } = context;
14820
14522
  context.includedLabels = new Set();
14821
- this.body.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
14523
+ this.body.include(context, includeChildrenRecursively);
14822
14524
  if (includeChildrenRecursively || context.includedLabels.has(this.label.name)) {
14823
- this.label.includePath(UNKNOWN_PATH, createInclusionContext());
14525
+ this.label.include();
14824
14526
  context.includedLabels.delete(this.label.name);
14825
14527
  context.brokenFlow = brokenFlow;
14826
14528
  }
@@ -14917,17 +14619,17 @@ class LogicalExpression extends NodeBase {
14917
14619
  }
14918
14620
  return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
14919
14621
  }
14920
- includePath(path, context, includeChildrenRecursively) {
14622
+ include(context, includeChildrenRecursively) {
14921
14623
  this.included = true;
14922
14624
  const usedBranch = this.getUsedBranch();
14923
14625
  if (includeChildrenRecursively ||
14924
14626
  (usedBranch === this.right && this.left.shouldBeIncluded(context)) ||
14925
14627
  !usedBranch) {
14926
- this.left.includePath(path, context, includeChildrenRecursively);
14927
- this.right.includePath(path, context, includeChildrenRecursively);
14628
+ this.left.include(context, includeChildrenRecursively);
14629
+ this.right.include(context, includeChildrenRecursively);
14928
14630
  }
14929
14631
  else {
14930
- usedBranch.includePath(path, context, includeChildrenRecursively);
14632
+ usedBranch.include(context, includeChildrenRecursively);
14931
14633
  }
14932
14634
  }
14933
14635
  removeAnnotations(code) {
@@ -14999,17 +14701,17 @@ class NewExpression extends NodeBase {
14999
14701
  hasEffectsOnInteractionAtPath(path, { type }) {
15000
14702
  return path.length > 0 || type !== INTERACTION_ACCESSED;
15001
14703
  }
15002
- includePath(path, context, includeChildrenRecursively) {
14704
+ include(context, includeChildrenRecursively) {
15003
14705
  if (!this.deoptimized)
15004
14706
  this.applyDeoptimizations();
15005
14707
  if (includeChildrenRecursively) {
15006
- super.includePath(path, context, includeChildrenRecursively);
14708
+ super.include(context, includeChildrenRecursively);
15007
14709
  }
15008
14710
  else {
15009
14711
  this.included = true;
15010
- this.callee.includePath(UNKNOWN_PATH, context, false);
14712
+ this.callee.include(context, false);
15011
14713
  }
15012
- this.callee.includeCallArguments(context, this.interaction);
14714
+ this.callee.includeCallArguments(context, this.arguments);
15013
14715
  }
15014
14716
  initialise() {
15015
14717
  super.initialise();
@@ -15038,7 +14740,6 @@ class ObjectExpression extends NodeBase {
15038
14740
  constructor() {
15039
14741
  super(...arguments);
15040
14742
  this.objectEntity = null;
15041
- this.protoProp = null;
15042
14743
  }
15043
14744
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
15044
14745
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -15058,32 +14759,13 @@ class ObjectExpression extends NodeBase {
15058
14759
  hasEffectsOnInteractionAtPath(path, interaction, context) {
15059
14760
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
15060
14761
  }
15061
- includePath(path, context, includeChildrenRecursively) {
15062
- this.included = true;
15063
- this.getObjectEntity().includePath(path, context, includeChildrenRecursively);
15064
- this.protoProp?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15065
- }
15066
14762
  render(code, options, { renderedSurroundingElement } = parseAst_js.BLANK) {
14763
+ super.render(code, options);
15067
14764
  if (renderedSurroundingElement === parseAst_js.ExpressionStatement ||
15068
14765
  renderedSurroundingElement === parseAst_js.ArrowFunctionExpression) {
15069
14766
  code.appendRight(this.start, '(');
15070
14767
  code.prependLeft(this.end, ')');
15071
14768
  }
15072
- if (this.properties.length > 0) {
15073
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
15074
- let lastSeparatorPos = null;
15075
- for (const { node, separator, start, end } of separatedNodes) {
15076
- if (!node.included) {
15077
- treeshakeNode(node, code, start, end);
15078
- continue;
15079
- }
15080
- lastSeparatorPos = separator;
15081
- node.render(code, options);
15082
- }
15083
- if (lastSeparatorPos) {
15084
- code.remove(lastSeparatorPos, this.end - 1);
15085
- }
15086
- }
15087
14769
  }
15088
14770
  applyDeoptimizations() { }
15089
14771
  getObjectEntity() {
@@ -15114,7 +14796,6 @@ class ObjectExpression extends NodeBase {
15114
14796
  ? property.key.name
15115
14797
  : String(property.key.value);
15116
14798
  if (key === '__proto__' && property.kind === 'init') {
15117
- this.protoProp = property;
15118
14799
  prototype =
15119
14800
  property.value instanceof Literal && property.value.value === null
15120
14801
  ? null
@@ -15181,11 +14862,11 @@ class Program extends NodeBase {
15181
14862
  }
15182
14863
  return false;
15183
14864
  }
15184
- includePath(_path, context, includeChildrenRecursively) {
14865
+ include(context, includeChildrenRecursively) {
15185
14866
  this.included = true;
15186
14867
  for (const node of this.body) {
15187
14868
  if (includeChildrenRecursively || node.shouldBeIncluded(context)) {
15188
- node.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
14869
+ node.include(context, includeChildrenRecursively);
15189
14870
  }
15190
14871
  }
15191
14872
  }
@@ -15224,6 +14905,10 @@ class Program extends NodeBase {
15224
14905
  }
15225
14906
 
15226
14907
  class Property extends MethodBase {
14908
+ constructor() {
14909
+ super(...arguments);
14910
+ this.declarationInit = null;
14911
+ }
15227
14912
  //declare method: boolean;
15228
14913
  get method() {
15229
14914
  return isFlagSet(this.flags, 262144 /* Flag.method */);
@@ -15238,39 +14923,17 @@ class Property extends MethodBase {
15238
14923
  set shorthand(value) {
15239
14924
  this.flags = setFlag(this.flags, 524288 /* Flag.shorthand */, value);
15240
14925
  }
15241
- declare(kind, destructuredInitPath, init) {
15242
- return this.value.declare(kind, this.getPathInProperty(destructuredInitPath), init);
15243
- }
15244
- deoptimizeAssignment(destructuredInitPath, init) {
15245
- this.value.deoptimizeAssignment?.(this.getPathInProperty(destructuredInitPath), init);
14926
+ declare(kind, init) {
14927
+ this.declarationInit = init;
14928
+ return this.value.declare(kind, UNKNOWN_EXPRESSION);
15246
14929
  }
15247
14930
  hasEffects(context) {
15248
14931
  if (!this.deoptimized)
15249
14932
  this.applyDeoptimizations();
15250
- return this.key.hasEffects(context) || this.value.hasEffects(context);
15251
- }
15252
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
15253
- return this.value.hasEffectsWhenDestructuring?.(context, this.getPathInProperty(destructuredInitPath), init);
15254
- }
15255
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
15256
- const path = this.getPathInProperty(destructuredInitPath);
15257
- let included = this.value.includeDestructuredIfNecessary(context, path, init) ||
15258
- this.included;
15259
- if ((included ||= this.key.hasEffects(createHasEffectsContext()))) {
15260
- this.key.includePath(EMPTY_PATH, context, false);
15261
- if (!this.value.included) {
15262
- this.value.included = true;
15263
- // Unfortunately, we need to include the value again now, so that any
15264
- // declared variables are properly included.
15265
- this.value.includeDestructuredIfNecessary(context, path, init);
15266
- }
15267
- }
15268
- return (this.included = included);
15269
- }
15270
- includePath(path, context, includeChildrenRecursively) {
15271
- this.included = true;
15272
- this.key.includePath(EMPTY_PATH, context, includeChildrenRecursively);
15273
- this.value.includePath(path, context, includeChildrenRecursively);
14933
+ const propertyReadSideEffects = this.scope.context.options.treeshake.propertyReadSideEffects;
14934
+ return ((this.parent.type === 'ObjectPattern' && propertyReadSideEffects === 'always') ||
14935
+ this.key.hasEffects(context) ||
14936
+ this.value.hasEffects(context));
15274
14937
  }
15275
14938
  markDeclarationReached() {
15276
14939
  this.value.markDeclarationReached();
@@ -15281,17 +14944,12 @@ class Property extends MethodBase {
15281
14944
  }
15282
14945
  this.value.render(code, options, { isShorthandProperty: this.shorthand });
15283
14946
  }
15284
- applyDeoptimizations() { }
15285
- getPathInProperty(destructuredInitPath) {
15286
- return destructuredInitPath.at(-1) === UnknownKey
15287
- ? destructuredInitPath
15288
- : // For now, we only consider static paths as we do not know how to
15289
- // deoptimize the path in the dynamic case.
15290
- this.computed
15291
- ? [...destructuredInitPath, UnknownKey]
15292
- : this.key instanceof Identifier
15293
- ? [...destructuredInitPath, this.key.name]
15294
- : [...destructuredInitPath, String(this.key.value)];
14947
+ applyDeoptimizations() {
14948
+ this.deoptimized = true;
14949
+ if (this.declarationInit !== null) {
14950
+ this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
14951
+ this.scope.context.requestTreeshakingPass();
14952
+ }
15295
14953
  }
15296
14954
  }
15297
14955
 
@@ -15336,9 +14994,9 @@ class ReturnStatement extends NodeBase {
15336
14994
  context.brokenFlow = true;
15337
14995
  return false;
15338
14996
  }
15339
- includePath(_path, context, includeChildrenRecursively) {
14997
+ include(context, includeChildrenRecursively) {
15340
14998
  this.included = true;
15341
- this.argument?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
14999
+ this.argument?.include(context, includeChildrenRecursively);
15342
15000
  context.brokenFlow = true;
15343
15001
  }
15344
15002
  initialise() {
@@ -15375,14 +15033,14 @@ class SequenceExpression extends NodeBase {
15375
15033
  hasEffectsOnInteractionAtPath(path, interaction, context) {
15376
15034
  return this.expressions[this.expressions.length - 1].hasEffectsOnInteractionAtPath(path, interaction, context);
15377
15035
  }
15378
- includePath(path, context, includeChildrenRecursively) {
15036
+ include(context, includeChildrenRecursively) {
15379
15037
  this.included = true;
15380
15038
  const lastExpression = this.expressions[this.expressions.length - 1];
15381
15039
  for (const expression of this.expressions) {
15382
15040
  if (includeChildrenRecursively ||
15383
15041
  (expression === lastExpression && !(this.parent instanceof ExpressionStatement)) ||
15384
15042
  expression.shouldBeIncluded(context))
15385
- expression.includePath(path, context, includeChildrenRecursively);
15043
+ expression.include(context, includeChildrenRecursively);
15386
15044
  }
15387
15045
  }
15388
15046
  removeAnnotations(code) {
@@ -15430,13 +15088,10 @@ class Super extends NodeBase {
15430
15088
  deoptimizePath(path) {
15431
15089
  this.variable.deoptimizePath(path);
15432
15090
  }
15433
- includePath(path, context) {
15091
+ include() {
15434
15092
  if (!this.included) {
15435
15093
  this.included = true;
15436
- this.scope.context.includeVariableInModule(this.variable, path);
15437
- }
15438
- else if (path.length > 0) {
15439
- this.variable.includePath(path, context);
15094
+ this.scope.context.includeVariableInModule(this.variable);
15440
15095
  }
15441
15096
  }
15442
15097
  }
@@ -15453,12 +15108,12 @@ class SwitchCase extends NodeBase {
15453
15108
  }
15454
15109
  return false;
15455
15110
  }
15456
- includePath(_path, context, includeChildrenRecursively) {
15111
+ include(context, includeChildrenRecursively) {
15457
15112
  this.included = true;
15458
- this.test?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15113
+ this.test?.include(context, includeChildrenRecursively);
15459
15114
  for (const node of this.consequent) {
15460
15115
  if (includeChildrenRecursively || node.shouldBeIncluded(context))
15461
- node.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15116
+ node.include(context, includeChildrenRecursively);
15462
15117
  }
15463
15118
  }
15464
15119
  render(code, options, nodeRenderOptions) {
@@ -15506,9 +15161,9 @@ class SwitchStatement extends NodeBase {
15506
15161
  context.hasBreak = hasBreak;
15507
15162
  return false;
15508
15163
  }
15509
- includePath(_path, context, includeChildrenRecursively) {
15164
+ include(context, includeChildrenRecursively) {
15510
15165
  this.included = true;
15511
- this.discriminant.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15166
+ this.discriminant.include(context, includeChildrenRecursively);
15512
15167
  const { brokenFlow, hasBreak } = context;
15513
15168
  context.hasBreak = false;
15514
15169
  let onlyHasBrokenFlow = true;
@@ -15525,7 +15180,7 @@ class SwitchStatement extends NodeBase {
15525
15180
  isCaseIncluded = switchCase.hasEffects(hasEffectsContext);
15526
15181
  }
15527
15182
  if (isCaseIncluded) {
15528
- switchCase.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15183
+ switchCase.include(context, includeChildrenRecursively);
15529
15184
  onlyHasBrokenFlow &&= context.brokenFlow && !context.hasBreak;
15530
15185
  context.hasBreak = false;
15531
15186
  context.brokenFlow = brokenFlow;
@@ -15582,21 +15237,21 @@ class TaggedTemplateExpression extends CallExpressionBase {
15582
15237
  return (this.tag.hasEffects(context) ||
15583
15238
  this.tag.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context));
15584
15239
  }
15585
- includePath(path, context, includeChildrenRecursively) {
15240
+ include(context, includeChildrenRecursively) {
15586
15241
  if (!this.deoptimized)
15587
15242
  this.applyDeoptimizations();
15588
15243
  if (includeChildrenRecursively) {
15589
- super.includePath(path, context, includeChildrenRecursively);
15244
+ super.include(context, includeChildrenRecursively);
15590
15245
  }
15591
15246
  else {
15592
15247
  this.included = true;
15593
- this.tag.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15594
- this.quasi.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15248
+ this.tag.include(context, includeChildrenRecursively);
15249
+ this.quasi.include(context, includeChildrenRecursively);
15595
15250
  }
15596
- this.tag.includeCallArguments(context, this.interaction);
15251
+ this.tag.includeCallArguments(context, this.args);
15597
15252
  const [returnExpression] = this.getReturnExpression();
15598
15253
  if (!returnExpression.included) {
15599
- returnExpression.includePath(UNKNOWN_PATH, context, false);
15254
+ returnExpression.include(context, false);
15600
15255
  }
15601
15256
  }
15602
15257
  initialise() {
@@ -15641,7 +15296,7 @@ class TemplateElement extends NodeBase {
15641
15296
  hasEffects() {
15642
15297
  return false;
15643
15298
  }
15644
- includePath() {
15299
+ include() {
15645
15300
  this.included = true;
15646
15301
  }
15647
15302
  parseNode(esTreeNode) {
@@ -15683,13 +15338,13 @@ class TemplateLiteral extends NodeBase {
15683
15338
  class ModuleScope extends ChildScope {
15684
15339
  constructor(parent, context) {
15685
15340
  super(parent, context);
15686
- this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, EMPTY_PATH, context, 'other'));
15341
+ this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, context, 'other'));
15687
15342
  }
15688
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
15343
+ addDeclaration(identifier, context, init, kind) {
15689
15344
  if (this.context.module.importDescriptions.has(identifier.name)) {
15690
15345
  context.error(parseAst_js.logRedeclarationError(identifier.name), identifier.start);
15691
15346
  }
15692
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
15347
+ return super.addDeclaration(identifier, context, init, kind);
15693
15348
  }
15694
15349
  addExportDefaultDeclaration(name, exportDefaultDeclaration, context) {
15695
15350
  const variable = new ExportDefaultVariable(name, exportDefaultDeclaration, context);
@@ -15734,13 +15389,10 @@ class ThisExpression extends NodeBase {
15734
15389
  }
15735
15390
  return this.variable.hasEffectsOnInteractionAtPath(path, interaction, context);
15736
15391
  }
15737
- includePath(path, context) {
15392
+ include() {
15738
15393
  if (!this.included) {
15739
15394
  this.included = true;
15740
- this.scope.context.includeVariableInModule(this.variable, path);
15741
- }
15742
- else if (path.length > 0) {
15743
- this.variable.includePath(path, context);
15395
+ this.scope.context.includeVariableInModule(this.variable);
15744
15396
  }
15745
15397
  }
15746
15398
  initialise() {
@@ -15767,9 +15419,9 @@ class ThrowStatement extends NodeBase {
15767
15419
  hasEffects() {
15768
15420
  return true;
15769
15421
  }
15770
- includePath(_path, context, includeChildrenRecursively) {
15422
+ include(context, includeChildrenRecursively) {
15771
15423
  this.included = true;
15772
- this.argument.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15424
+ this.argument.include(context, includeChildrenRecursively);
15773
15425
  context.brokenFlow = true;
15774
15426
  }
15775
15427
  render(code, options) {
@@ -15791,13 +15443,13 @@ class TryStatement extends NodeBase {
15791
15443
  ? this.block.body.length > 0
15792
15444
  : this.block.hasEffects(context)) || !!this.finalizer?.hasEffects(context));
15793
15445
  }
15794
- includePath(_path, context, includeChildrenRecursively) {
15446
+ include(context, includeChildrenRecursively) {
15795
15447
  const tryCatchDeoptimization = this.scope.context.options.treeshake?.tryCatchDeoptimization;
15796
15448
  const { brokenFlow, includedLabels } = context;
15797
15449
  if (!this.directlyIncluded || !tryCatchDeoptimization) {
15798
15450
  this.included = true;
15799
15451
  this.directlyIncluded = true;
15800
- this.block.includePath(UNKNOWN_PATH, context, tryCatchDeoptimization ? INCLUDE_PARAMETERS : includeChildrenRecursively);
15452
+ this.block.include(context, tryCatchDeoptimization ? INCLUDE_PARAMETERS : includeChildrenRecursively);
15801
15453
  if (includedLabels.size > 0) {
15802
15454
  this.includedLabelsAfterBlock = [...includedLabels];
15803
15455
  }
@@ -15809,10 +15461,10 @@ class TryStatement extends NodeBase {
15809
15461
  }
15810
15462
  }
15811
15463
  if (this.handler !== null) {
15812
- this.handler.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15464
+ this.handler.include(context, includeChildrenRecursively);
15813
15465
  context.brokenFlow = brokenFlow;
15814
15466
  }
15815
- this.finalizer?.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15467
+ this.finalizer?.include(context, includeChildrenRecursively);
15816
15468
  }
15817
15469
  }
15818
15470
 
@@ -15870,7 +15522,7 @@ class UpdateExpression extends NodeBase {
15870
15522
  hasEffectsOnInteractionAtPath(path, { type }) {
15871
15523
  return path.length > 1 || type !== INTERACTION_ACCESSED;
15872
15524
  }
15873
- includePath(_, context, includeChildrenRecursively) {
15525
+ include(context, includeChildrenRecursively) {
15874
15526
  if (!this.deoptimized)
15875
15527
  this.applyDeoptimizations();
15876
15528
  this.included = true;
@@ -15939,20 +15591,20 @@ class VariableDeclaration extends NodeBase {
15939
15591
  hasEffectsOnInteractionAtPath() {
15940
15592
  return false;
15941
15593
  }
15942
- includePath(_path, context, includeChildrenRecursively, { asSingleStatement } = parseAst_js.BLANK) {
15594
+ include(context, includeChildrenRecursively, { asSingleStatement } = parseAst_js.BLANK) {
15943
15595
  this.included = true;
15944
15596
  for (const declarator of this.declarations) {
15945
15597
  if (includeChildrenRecursively || declarator.shouldBeIncluded(context))
15946
- declarator.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15598
+ declarator.include(context, includeChildrenRecursively);
15947
15599
  const { id, init } = declarator;
15948
15600
  if (asSingleStatement) {
15949
- id.includePath(EMPTY_PATH, context, includeChildrenRecursively);
15601
+ id.include(context, includeChildrenRecursively);
15950
15602
  }
15951
15603
  if (init &&
15952
15604
  id.included &&
15953
15605
  !init.included &&
15954
15606
  (id instanceof ObjectPattern || id instanceof ArrayPattern)) {
15955
- init.includePath(EMPTY_PATH, context, includeChildrenRecursively);
15607
+ init.include(context, includeChildrenRecursively);
15956
15608
  }
15957
15609
  }
15958
15610
  }
@@ -16024,7 +15676,8 @@ class VariableDeclaration extends NodeBase {
16024
15676
  const singleSystemExport = gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregatedSystemExports);
16025
15677
  for (const { node, start, separator, contentEnd, end } of separatedNodes) {
16026
15678
  if (!node.included) {
16027
- treeshakeNode(node, code, start, end);
15679
+ code.remove(start, end);
15680
+ node.removeAnnotations(code);
16028
15681
  continue;
16029
15682
  }
16030
15683
  node.render(code, options);
@@ -16101,9 +15754,9 @@ class WhileStatement extends NodeBase {
16101
15754
  return true;
16102
15755
  return hasLoopBodyEffects(context, this.body);
16103
15756
  }
16104
- includePath(_path, context, includeChildrenRecursively) {
15757
+ include(context, includeChildrenRecursively) {
16105
15758
  this.included = true;
16106
- this.test.includePath(UNKNOWN_PATH, context, includeChildrenRecursively);
15759
+ this.test.include(context, includeChildrenRecursively);
16107
15760
  includeLoopBody(context, this.body, includeChildrenRecursively);
16108
15761
  }
16109
15762
  }
@@ -16347,7 +16000,7 @@ const bufferParsers = [
16347
16000
  const annotations = (node.annotations = parseAst_js.convertAnnotations(buffer[position + 1], buffer));
16348
16001
  node.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
16349
16002
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 2], buffer));
16350
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16003
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16351
16004
  node.body = convertNode(node, scope.bodyScope, buffer[position + 3], buffer);
16352
16005
  },
16353
16006
  function assignmentExpression(node, position, buffer) {
@@ -16393,7 +16046,7 @@ const bufferParsers = [
16393
16046
  const parameterPosition = buffer[position];
16394
16047
  const parameter = (node.param =
16395
16048
  parameterPosition === 0 ? null : convertNode(node, scope, parameterPosition, buffer));
16396
- parameter?.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
16049
+ parameter?.declare('parameter', UNKNOWN_EXPRESSION);
16397
16050
  node.body = convertNode(node, scope.bodyScope, buffer[position + 1], buffer);
16398
16051
  },
16399
16052
  function chainExpression(node, position, buffer) {
@@ -16531,7 +16184,7 @@ const bufferParsers = [
16531
16184
  node.id =
16532
16185
  idPosition === 0 ? null : convertNode(node, scope.parent, idPosition, buffer);
16533
16186
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
16534
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16187
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16535
16188
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
16536
16189
  },
16537
16190
  function functionExpression(node, position, buffer) {
@@ -16544,7 +16197,7 @@ const bufferParsers = [
16544
16197
  const idPosition = buffer[position + 2];
16545
16198
  node.id = idPosition === 0 ? null : convertNode(node, node.idScope, idPosition, buffer);
16546
16199
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
16547
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16200
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16548
16201
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
16549
16202
  },
16550
16203
  function identifier(node, position, buffer) {
@@ -16903,8 +16556,8 @@ class UnknownNode extends NodeBase {
16903
16556
  hasEffects() {
16904
16557
  return true;
16905
16558
  }
16906
- includePath(path, context) {
16907
- super.includePath(path, context, true);
16559
+ include(context) {
16560
+ super.include(context, true);
16908
16561
  }
16909
16562
  }
16910
16563
 
@@ -17008,8 +16661,8 @@ class ExportShimVariable extends Variable {
17008
16661
  super(MISSING_EXPORT_SHIM_VARIABLE);
17009
16662
  this.module = module;
17010
16663
  }
17011
- includePath(path, context) {
17012
- super.includePath(path, context);
16664
+ include() {
16665
+ super.include();
17013
16666
  this.module.needsExportShim = true;
17014
16667
  }
17015
16668
  }
@@ -17693,7 +17346,7 @@ class Module {
17693
17346
  include() {
17694
17347
  const context = createInclusionContext();
17695
17348
  if (this.ast.shouldBeIncluded(context))
17696
- this.ast.includePath(EMPTY_PATH, context, false);
17349
+ this.ast.include(context, false);
17697
17350
  }
17698
17351
  includeAllExports(includeNamespaceMembers) {
17699
17352
  if (!this.isExecuted) {
@@ -17707,7 +17360,9 @@ class Module {
17707
17360
  return parseAst_js.error(parseAst_js.logMissingEntryExport(exportName, this.id));
17708
17361
  }
17709
17362
  variable.deoptimizePath(UNKNOWN_PATH);
17710
- this.includeVariable(variable, UNKNOWN_PATH);
17363
+ if (!variable.included) {
17364
+ this.includeVariable(variable);
17365
+ }
17711
17366
  }
17712
17367
  }
17713
17368
  for (const name of this.getReexports()) {
@@ -17715,7 +17370,7 @@ class Module {
17715
17370
  if (variable) {
17716
17371
  variable.deoptimizePath(UNKNOWN_PATH);
17717
17372
  if (!variable.included) {
17718
- this.includeVariable(variable, UNKNOWN_PATH);
17373
+ this.includeVariable(variable);
17719
17374
  }
17720
17375
  if (variable instanceof ExternalVariable) {
17721
17376
  variable.module.reexported = true;
@@ -17727,7 +17382,7 @@ class Module {
17727
17382
  }
17728
17383
  }
17729
17384
  includeAllInBundle() {
17730
- this.ast.includePath(UNKNOWN_PATH, createInclusionContext(), true);
17385
+ this.ast.include(createInclusionContext(), true);
17731
17386
  this.includeAllExports(false);
17732
17387
  }
17733
17388
  includeExportsByNames(names) {
@@ -17741,7 +17396,7 @@ class Module {
17741
17396
  if (variable) {
17742
17397
  variable.deoptimizePath(UNKNOWN_PATH);
17743
17398
  if (!variable.included) {
17744
- this.includeVariable(variable, UNKNOWN_PATH);
17399
+ this.includeVariable(variable);
17745
17400
  }
17746
17401
  }
17747
17402
  if (!this.exports.has(name) && !this.reexportDescriptions.has(name)) {
@@ -18183,13 +17838,13 @@ class Module {
18183
17838
  for (const module of [this, ...this.exportAllModules]) {
18184
17839
  if (module instanceof ExternalModule) {
18185
17840
  const [externalVariable] = module.getVariableForExportName('*');
18186
- externalVariable.includePath(UNKNOWN_PATH, createInclusionContext());
17841
+ externalVariable.include();
18187
17842
  this.includedImports.add(externalVariable);
18188
17843
  externalNamespaces.add(externalVariable);
18189
17844
  }
18190
17845
  else if (module.info.syntheticNamedExports) {
18191
17846
  const syntheticNamespace = module.getSyntheticNamespace();
18192
- syntheticNamespace.includePath(UNKNOWN_PATH, createInclusionContext());
17847
+ syntheticNamespace.include();
18193
17848
  this.includedImports.add(syntheticNamespace);
18194
17849
  syntheticNamespaces.add(syntheticNamespace);
18195
17850
  }
@@ -18199,9 +17854,7 @@ class Module {
18199
17854
  includeDynamicImport(node) {
18200
17855
  const resolution = this.dynamicImports.find(dynamicImport => dynamicImport.node === node).resolution;
18201
17856
  if (resolution instanceof Module) {
18202
- if (!resolution.includedDynamicImporters.includes(this)) {
18203
- resolution.includedDynamicImporters.push(this);
18204
- }
17857
+ resolution.includedDynamicImporters.push(this);
18205
17858
  const importedNames = this.options.treeshake
18206
17859
  ? node.getDeterministicImportedNames()
18207
17860
  : undefined;
@@ -18213,7 +17866,7 @@ class Module {
18213
17866
  }
18214
17867
  }
18215
17868
  }
18216
- includeVariable(variable, path) {
17869
+ includeVariable(variable) {
18217
17870
  const variableModule = variable.module;
18218
17871
  if (variable.included) {
18219
17872
  if (variableModule instanceof Module && variableModule !== this) {
@@ -18221,6 +17874,7 @@ class Module {
18221
17874
  }
18222
17875
  }
18223
17876
  else {
17877
+ variable.include();
18224
17878
  this.graph.needsTreeshakingPass = true;
18225
17879
  if (variableModule instanceof Module) {
18226
17880
  if (!variableModule.isExecuted) {
@@ -18236,10 +17890,9 @@ class Module {
18236
17890
  }
18237
17891
  }
18238
17892
  }
18239
- variable.includePath(path, createInclusionContext());
18240
17893
  }
18241
- includeVariableInModule(variable, path) {
18242
- this.includeVariable(variable, path);
17894
+ includeVariableInModule(variable) {
17895
+ this.includeVariable(variable);
18243
17896
  const variableModule = variable.module;
18244
17897
  if (variableModule && variableModule !== this) {
18245
17898
  this.includedImports.add(variable);
@@ -21742,7 +21395,7 @@ class Graph {
21742
21395
  this.options = options;
21743
21396
  this.astLru = flru(5);
21744
21397
  this.cachedModules = new Map();
21745
- this.deoptimizationTracker = new EntityPathTracker();
21398
+ this.deoptimizationTracker = new PathTracker();
21746
21399
  this.entryModules = [];
21747
21400
  this.modulesById = new Map();
21748
21401
  this.needsTreeshakingPass = false;