@rollup/wasm-node 4.33.0-0 → 4.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v4.33.0-0
4
- Tue, 28 Jan 2025 08:29:38 GMT - commit f854e1988542d09f9691923eddd80888e92240d3
3
+ Rollup.js v4.33.0
4
+ Sat, 01 Feb 2025 07:11:29 GMT - commit 494483e8df7b5d04796b30e37f54d7e96fa91a97
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -17,7 +17,7 @@ const native_js = require('../native.js');
17
17
  const node_perf_hooks = require('node:perf_hooks');
18
18
  const promises = require('node:fs/promises');
19
19
 
20
- var version = "4.33.0-0";
20
+ var version = "4.33.0";
21
21
 
22
22
  function ensureArray$1(items) {
23
23
  if (Array.isArray(items)) {
@@ -3491,6 +3491,71 @@ function renderSystemExportSequenceBeforeExpression(exportedVariable, expression
3491
3491
  }
3492
3492
  }
3493
3493
 
3494
+ /** @import { Node } from 'estree' */
3495
+
3496
+ /**
3497
+ * @param {Node} node
3498
+ * @param {Node} parent
3499
+ * @returns {boolean}
3500
+ */
3501
+ function is_reference(node, parent) {
3502
+ if (node.type === 'MemberExpression') {
3503
+ return !node.computed && is_reference(node.object, node);
3504
+ }
3505
+
3506
+ if (node.type !== 'Identifier') return false;
3507
+
3508
+ switch (parent?.type) {
3509
+ // disregard `bar` in `foo.bar`
3510
+ case 'MemberExpression':
3511
+ return parent.computed || node === parent.object;
3512
+
3513
+ // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
3514
+ case 'MethodDefinition':
3515
+ return parent.computed;
3516
+
3517
+ // disregard the `meta` in `import.meta`
3518
+ case 'MetaProperty':
3519
+ return parent.meta === node;
3520
+
3521
+ // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
3522
+ case 'PropertyDefinition':
3523
+ return parent.computed || node === parent.value;
3524
+
3525
+ // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
3526
+ case 'Property':
3527
+ return parent.computed || node === parent.value;
3528
+
3529
+ // disregard the `bar` in `export { foo as bar }` or
3530
+ // the foo in `import { foo as bar }`
3531
+ case 'ExportSpecifier':
3532
+ case 'ImportSpecifier':
3533
+ return node === parent.local;
3534
+
3535
+ // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
3536
+ case 'LabeledStatement':
3537
+ case 'BreakStatement':
3538
+ case 'ContinueStatement':
3539
+ return false;
3540
+
3541
+ default:
3542
+ return true;
3543
+ }
3544
+ }
3545
+
3546
+ const PureFunctionKey = Symbol('PureFunction');
3547
+ const getPureFunctions = ({ treeshake }) => {
3548
+ const pureFunctions = Object.create(null);
3549
+ for (const functionName of treeshake ? treeshake.manualPureFunctions : []) {
3550
+ let currentFunctions = pureFunctions;
3551
+ for (const pathSegment of functionName.split('.')) {
3552
+ currentFunctions = currentFunctions[pathSegment] ||= Object.create(null);
3553
+ }
3554
+ currentFunctions[PureFunctionKey] = true;
3555
+ }
3556
+ return pureFunctions;
3557
+ };
3558
+
3494
3559
  const UnknownKey = Symbol('Unknown Key');
3495
3560
  const UnknownNonAccessorKey = Symbol('Unknown Non-Accessor Key');
3496
3561
  const UnknownInteger = Symbol('Unknown Integer');
@@ -3505,7 +3570,7 @@ const UNKNOWN_PATH = [UnknownKey];
3505
3570
  const UNKNOWN_NON_ACCESSOR_PATH = [UnknownNonAccessorKey];
3506
3571
  const UNKNOWN_INTEGER_PATH = [UnknownInteger];
3507
3572
  const EntitiesKey = Symbol('Entities');
3508
- class EntityPathTracker {
3573
+ class PathTracker {
3509
3574
  constructor() {
3510
3575
  this.entityPaths = Object.create(null, {
3511
3576
  [EntitiesKey]: { value: new Set() }
@@ -3530,14 +3595,14 @@ class EntityPathTracker {
3530
3595
  getEntities(path) {
3531
3596
  let currentPaths = this.entityPaths;
3532
3597
  for (const pathSegment of path) {
3533
- currentPaths = currentPaths[pathSegment] ||= Object.create(null, {
3534
- [EntitiesKey]: { value: new Set() }
3535
- });
3598
+ currentPaths = currentPaths[pathSegment] =
3599
+ currentPaths[pathSegment] ||
3600
+ Object.create(null, { [EntitiesKey]: { value: new Set() } });
3536
3601
  }
3537
3602
  return currentPaths[EntitiesKey];
3538
3603
  }
3539
3604
  }
3540
- const SHARED_RECURSION_TRACKER = new EntityPathTracker();
3605
+ const SHARED_RECURSION_TRACKER = new PathTracker();
3541
3606
  class DiscriminatedPathTracker {
3542
3607
  constructor() {
3543
3608
  this.entityPaths = Object.create(null, {
@@ -3547,9 +3612,9 @@ class DiscriminatedPathTracker {
3547
3612
  trackEntityAtPathAndGetIfTracked(path, discriminator, entity) {
3548
3613
  let currentPaths = this.entityPaths;
3549
3614
  for (const pathSegment of path) {
3550
- currentPaths = currentPaths[pathSegment] ||= Object.create(null, {
3551
- [EntitiesKey]: { value: new Map() }
3552
- });
3615
+ currentPaths = currentPaths[pathSegment] =
3616
+ currentPaths[pathSegment] ||
3617
+ Object.create(null, { [EntitiesKey]: { value: new Map() } });
3553
3618
  }
3554
3619
  const trackedEntities = getOrCreate(currentPaths[EntitiesKey], discriminator, (getNewSet));
3555
3620
  if (trackedEntities.has(entity))
@@ -3558,174 +3623,6 @@ class DiscriminatedPathTracker {
3558
3623
  return false;
3559
3624
  }
3560
3625
  }
3561
- const UNKNOWN_INCLUDED_PATH = Object.freeze({ [UnknownKey]: parseAst_js.EMPTY_OBJECT });
3562
- class IncludedFullPathTracker {
3563
- constructor() {
3564
- this.includedPaths = null;
3565
- }
3566
- includePathAndGetIfIncluded(path) {
3567
- let included = true;
3568
- let parent = this;
3569
- let parentSegment = 'includedPaths';
3570
- let currentPaths = (this.includedPaths ||=
3571
- ((included = false), Object.create(null)));
3572
- for (const pathSegment of path) {
3573
- // This means from here, all paths are included
3574
- if (currentPaths[UnknownKey]) {
3575
- return true;
3576
- }
3577
- // Including UnknownKey automatically includes all nested paths.
3578
- // From above, we know that UnknownKey is not included yet.
3579
- if (typeof pathSegment === 'symbol') {
3580
- // Hopefully, this saves some memory over just setting
3581
- // currentPaths[UnknownKey] = EMPTY_OBJECT
3582
- parent[parentSegment] = UNKNOWN_INCLUDED_PATH;
3583
- return false;
3584
- }
3585
- parent = currentPaths;
3586
- parentSegment = pathSegment;
3587
- currentPaths = currentPaths[pathSegment] ||= ((included = false), Object.create(null));
3588
- }
3589
- return included;
3590
- }
3591
- }
3592
- const UNKNOWN_INCLUDED_TOP_LEVEL_PATH = Object.freeze({
3593
- [UnknownKey]: true
3594
- });
3595
- class IncludedTopLevelPathTracker {
3596
- constructor() {
3597
- this.includedPaths = null;
3598
- }
3599
- includePathAndGetIfIncluded(path) {
3600
- let included = true;
3601
- const includedPaths = (this.includedPaths ||=
3602
- ((included = false), Object.create(null)));
3603
- if (includedPaths[UnknownKey]) {
3604
- return true;
3605
- }
3606
- const [firstPathSegment, secondPathSegment] = path;
3607
- if (!firstPathSegment) {
3608
- return included;
3609
- }
3610
- if (typeof firstPathSegment === 'symbol') {
3611
- this.includedPaths = UNKNOWN_INCLUDED_TOP_LEVEL_PATH;
3612
- return false;
3613
- }
3614
- if (secondPathSegment) {
3615
- if (includedPaths[firstPathSegment] === UnknownKey) {
3616
- return true;
3617
- }
3618
- includedPaths[firstPathSegment] = UnknownKey;
3619
- return false;
3620
- }
3621
- if (includedPaths[firstPathSegment]) {
3622
- return true;
3623
- }
3624
- includedPaths[firstPathSegment] = true;
3625
- return false;
3626
- }
3627
- includeAllPaths(entity, context, basePath) {
3628
- const { includedPaths } = this;
3629
- if (includedPaths) {
3630
- if (includedPaths[UnknownKey]) {
3631
- entity.includePath([...basePath, UnknownKey], context);
3632
- }
3633
- else {
3634
- const inclusionEntries = Object.entries(includedPaths);
3635
- if (inclusionEntries.length === 0) {
3636
- entity.includePath(basePath, context);
3637
- }
3638
- else {
3639
- for (const [key, value] of inclusionEntries) {
3640
- entity.includePath(value === UnknownKey ? [...basePath, key, UnknownKey] : [...basePath, key], context);
3641
- }
3642
- }
3643
- }
3644
- }
3645
- }
3646
- }
3647
-
3648
- /** @import { Node } from 'estree' */
3649
-
3650
- /**
3651
- * @param {Node} node
3652
- * @param {Node} parent
3653
- * @returns {boolean}
3654
- */
3655
- function is_reference(node, parent) {
3656
- if (node.type === 'MemberExpression') {
3657
- return !node.computed && is_reference(node.object, node);
3658
- }
3659
-
3660
- if (node.type !== 'Identifier') return false;
3661
-
3662
- switch (parent?.type) {
3663
- // disregard `bar` in `foo.bar`
3664
- case 'MemberExpression':
3665
- return parent.computed || node === parent.object;
3666
-
3667
- // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
3668
- case 'MethodDefinition':
3669
- return parent.computed;
3670
-
3671
- // disregard the `meta` in `import.meta`
3672
- case 'MetaProperty':
3673
- return parent.meta === node;
3674
-
3675
- // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
3676
- case 'PropertyDefinition':
3677
- return parent.computed || node === parent.value;
3678
-
3679
- // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
3680
- case 'Property':
3681
- return parent.computed || node === parent.value;
3682
-
3683
- // disregard the `bar` in `export { foo as bar }` or
3684
- // the foo in `import { foo as bar }`
3685
- case 'ExportSpecifier':
3686
- case 'ImportSpecifier':
3687
- return node === parent.local;
3688
-
3689
- // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
3690
- case 'LabeledStatement':
3691
- case 'BreakStatement':
3692
- case 'ContinueStatement':
3693
- return false;
3694
-
3695
- default:
3696
- return true;
3697
- }
3698
- }
3699
-
3700
- function createInclusionContext() {
3701
- return {
3702
- brokenFlow: false,
3703
- hasBreak: false,
3704
- hasContinue: false,
3705
- includedCallArguments: new Set(),
3706
- includedLabels: new Set()
3707
- };
3708
- }
3709
- function createHasEffectsContext() {
3710
- return {
3711
- accessed: new EntityPathTracker(),
3712
- assigned: new EntityPathTracker(),
3713
- brokenFlow: false,
3714
- called: new DiscriminatedPathTracker(),
3715
- hasBreak: false,
3716
- hasContinue: false,
3717
- ignore: {
3718
- breaks: false,
3719
- continues: false,
3720
- labels: new Set(),
3721
- returnYield: false,
3722
- this: false
3723
- },
3724
- includedLabels: new Set(),
3725
- instantiated: new DiscriminatedPathTracker(),
3726
- replacedVariableInits: new Map()
3727
- };
3728
- }
3729
3626
 
3730
3627
  function isFlagSet(flags, flag) {
3731
3628
  return (flags & flag) !== 0;
@@ -3765,25 +3662,12 @@ class ExpressionEntity {
3765
3662
  hasEffectsOnInteractionAtPath(_path, _interaction, _context) {
3766
3663
  return true;
3767
3664
  }
3768
- include(context, _includeChildrenRecursively, _options) {
3769
- if (!this.included)
3770
- this.includeNode(context);
3771
- }
3772
- includeNode(_context) {
3665
+ include(_context, _includeChildrenRecursively, _options) {
3773
3666
  this.included = true;
3774
3667
  }
3775
- includePath(_path, context) {
3776
- if (!this.included)
3777
- this.includeNode(context);
3778
- }
3779
- /* We are both including and including an unknown path here as the former
3780
- * ensures that nested nodes are included while the latter ensures that all
3781
- * paths of the expression are included.
3782
- * */
3783
- includeCallArguments(context, interaction) {
3784
- for (const argument of interaction.args) {
3785
- argument?.includePath(UNKNOWN_PATH, context);
3786
- argument?.include(context, false);
3668
+ includeCallArguments(context, parameters) {
3669
+ for (const argument of parameters) {
3670
+ argument.include(context, false);
3787
3671
  }
3788
3672
  }
3789
3673
  shouldBeIncluded(_context) {
@@ -3822,19 +3706,6 @@ const NODE_INTERACTION_UNKNOWN_CALL = {
3822
3706
  withNew: false
3823
3707
  };
3824
3708
 
3825
- const PureFunctionKey = Symbol('PureFunction');
3826
- const getPureFunctions = ({ treeshake }) => {
3827
- const pureFunctions = Object.create(null);
3828
- for (const functionName of treeshake ? treeshake.manualPureFunctions : []) {
3829
- let currentFunctions = pureFunctions;
3830
- for (const pathSegment of functionName.split('.')) {
3831
- currentFunctions = currentFunctions[pathSegment] ||= Object.create(null);
3832
- }
3833
- currentFunctions[PureFunctionKey] = true;
3834
- }
3835
- return pureFunctions;
3836
- };
3837
-
3838
3709
  class Variable extends ExpressionEntity {
3839
3710
  markReassigned() {
3840
3711
  this.isReassigned = true;
@@ -3911,9 +3782,9 @@ class Variable extends ExpressionEntity {
3911
3782
  * has not been included previously. Once a variable is included, it should
3912
3783
  * take care all its declarations are included.
3913
3784
  */
3914
- includePath(path, context) {
3785
+ include() {
3915
3786
  this.included = true;
3916
- this.renderedLikeHoisted?.includePath(path, context);
3787
+ this.renderedLikeHoisted?.include();
3917
3788
  }
3918
3789
  /**
3919
3790
  * Links the rendered name of this variable to another variable and includes
@@ -3945,8 +3816,8 @@ class ExternalVariable extends Variable {
3945
3816
  hasEffectsOnInteractionAtPath(path, { type }) {
3946
3817
  return type !== INTERACTION_ACCESSED || path.length > (this.isNamespace ? 1 : 0);
3947
3818
  }
3948
- includePath(path, context) {
3949
- super.includePath(path, context);
3819
+ include() {
3820
+ super.include();
3950
3821
  this.module.used = true;
3951
3822
  }
3952
3823
  }
@@ -4245,6 +4116,36 @@ const childNodeKeys = {
4245
4116
  YieldExpression: ['argument']
4246
4117
  };
4247
4118
 
4119
+ function createInclusionContext() {
4120
+ return {
4121
+ brokenFlow: false,
4122
+ hasBreak: false,
4123
+ hasContinue: false,
4124
+ includedCallArguments: new Set(),
4125
+ includedLabels: new Set()
4126
+ };
4127
+ }
4128
+ function createHasEffectsContext() {
4129
+ return {
4130
+ accessed: new PathTracker(),
4131
+ assigned: new PathTracker(),
4132
+ brokenFlow: false,
4133
+ called: new DiscriminatedPathTracker(),
4134
+ hasBreak: false,
4135
+ hasContinue: false,
4136
+ ignore: {
4137
+ breaks: false,
4138
+ continues: false,
4139
+ labels: new Set(),
4140
+ returnYield: false,
4141
+ this: false
4142
+ },
4143
+ includedLabels: new Set(),
4144
+ instantiated: new DiscriminatedPathTracker(),
4145
+ replacedVariableInits: new Map()
4146
+ };
4147
+ }
4148
+
4248
4149
  const INCLUDE_PARAMETERS = 'variables';
4249
4150
  const IS_SKIPPED_CHAIN = Symbol('IS_SKIPPED_CHAIN');
4250
4151
  class NodeBase extends ExpressionEntity {
@@ -4314,37 +4215,20 @@ class NodeBase extends ExpressionEntity {
4314
4215
  this.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.assignmentInteraction, context));
4315
4216
  }
4316
4217
  include(context, includeChildrenRecursively, _options) {
4317
- if (!this.included)
4318
- this.includeNode(context);
4319
- for (const key of childNodeKeys[this.type]) {
4320
- const value = this[key];
4321
- if (value === null)
4322
- continue;
4323
- if (Array.isArray(value)) {
4324
- for (const child of value) {
4325
- child?.include(context, includeChildrenRecursively);
4326
- }
4327
- }
4328
- else {
4329
- value.include(context, includeChildrenRecursively);
4330
- }
4331
- }
4332
- }
4333
- includeNode(context) {
4334
- this.included = true;
4335
4218
  if (!this.deoptimized)
4336
4219
  this.applyDeoptimizations();
4220
+ this.included = true;
4337
4221
  for (const key of childNodeKeys[this.type]) {
4338
4222
  const value = this[key];
4339
4223
  if (value === null)
4340
4224
  continue;
4341
4225
  if (Array.isArray(value)) {
4342
4226
  for (const child of value) {
4343
- child?.includePath(UNKNOWN_PATH, context);
4227
+ child?.include(context, includeChildrenRecursively);
4344
4228
  }
4345
4229
  }
4346
4230
  else {
4347
- value.includePath(UNKNOWN_PATH, context);
4231
+ value.include(context, includeChildrenRecursively);
4348
4232
  }
4349
4233
  }
4350
4234
  }
@@ -4451,17 +4335,6 @@ class NodeBase extends ExpressionEntity {
4451
4335
  function createChildNodeKeysForNode(esTreeNode) {
4452
4336
  return Object.keys(esTreeNode).filter(key => typeof esTreeNode[key] === 'object' && key.charCodeAt(0) !== 95 /* _ */);
4453
4337
  }
4454
- function onlyIncludeSelf() {
4455
- this.included = true;
4456
- if (!this.deoptimized)
4457
- this.applyDeoptimizations();
4458
- }
4459
- function onlyIncludeSelfNoDeoptimize() {
4460
- this.included = true;
4461
- }
4462
- function doNotDeoptimize() {
4463
- this.deoptimized = true;
4464
- }
4465
4338
 
4466
4339
  function isObjectExpressionNode(node) {
4467
4340
  return node instanceof NodeBase && node.type === parseAst_js.ObjectExpression;
@@ -4474,8 +4347,8 @@ function assembleMemberDescriptions(memberDescriptions, inheritedDescriptions =
4474
4347
  return Object.create(inheritedDescriptions, memberDescriptions);
4475
4348
  }
4476
4349
  const UNDEFINED_EXPRESSION = new (class UndefinedExpression extends ExpressionEntity {
4477
- getLiteralValueAtPath(path) {
4478
- return path.length > 0 ? UnknownValue : undefined;
4350
+ getLiteralValueAtPath() {
4351
+ return undefined;
4479
4352
  }
4480
4353
  })();
4481
4354
  const returnsUnknown = {
@@ -4672,6 +4545,31 @@ function getMemberReturnExpressionWhenCalled(members, memberName) {
4672
4545
  return [members[memberName].returns, false];
4673
4546
  }
4674
4547
 
4548
+ class SpreadElement extends NodeBase {
4549
+ deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
4550
+ if (path.length > 0) {
4551
+ this.argument.deoptimizeArgumentsOnInteractionAtPath(interaction, UNKNOWN_PATH, recursionTracker);
4552
+ }
4553
+ }
4554
+ hasEffects(context) {
4555
+ if (!this.deoptimized)
4556
+ this.applyDeoptimizations();
4557
+ const { propertyReadSideEffects } = this.scope.context.options
4558
+ .treeshake;
4559
+ return (this.argument.hasEffects(context) ||
4560
+ (propertyReadSideEffects &&
4561
+ (propertyReadSideEffects === 'always' ||
4562
+ this.argument.hasEffectsOnInteractionAtPath(UNKNOWN_PATH, NODE_INTERACTION_UNKNOWN_ACCESS, context))));
4563
+ }
4564
+ applyDeoptimizations() {
4565
+ this.deoptimized = true;
4566
+ // Only properties of properties of the argument could become subject to reassignment
4567
+ // This will also reassign the return values of iterators
4568
+ this.argument.deoptimizePath([UnknownKey, UnknownKey]);
4569
+ this.scope.context.requestTreeshakingPass();
4570
+ }
4571
+ }
4572
+
4675
4573
  class Method extends ExpressionEntity {
4676
4574
  constructor(description) {
4677
4575
  super();
@@ -4797,7 +4695,6 @@ class ObjectEntity extends ExpressionEntity {
4797
4695
  this.unknownIntegerProps = [];
4798
4696
  this.unmatchableGetters = [];
4799
4697
  this.unmatchablePropertiesAndGetters = [];
4800
- this.unmatchablePropertiesAndSetters = [];
4801
4698
  this.unmatchableSetters = [];
4802
4699
  if (Array.isArray(properties)) {
4803
4700
  this.buildPropertyMaps(properties);
@@ -4954,12 +4851,7 @@ class ObjectEntity extends ExpressionEntity {
4954
4851
  }
4955
4852
  getLiteralValueAtPath(path, recursionTracker, origin) {
4956
4853
  if (path.length === 0) {
4957
- // This should actually be "UnknownTruthyValue". However, this currently
4958
- // causes an issue with TypeScript enums in files with moduleSideEffects:
4959
- // false because we cannot properly track whether a "var" has been
4960
- // initialized. This should be reverted once we can properly track this.
4961
- // return UnknownTruthyValue;
4962
- return UnknownValue;
4854
+ return UnknownTruthyValue;
4963
4855
  }
4964
4856
  const key = path[0];
4965
4857
  const expressionAtPath = this.getMemberExpressionAndTrackDeopt(key, origin);
@@ -5037,36 +4929,9 @@ class ObjectEntity extends ExpressionEntity {
5037
4929
  }
5038
4930
  return false;
5039
4931
  }
5040
- include(context, includeChildrenRecursively) {
5041
- this.included = true;
5042
- for (const property of this.allProperties) {
5043
- if (includeChildrenRecursively || property.shouldBeIncluded(context)) {
5044
- property.include(context, includeChildrenRecursively);
5045
- }
5046
- }
5047
- this.prototypeExpression?.include(context, includeChildrenRecursively);
5048
- }
5049
- includePath(path, context) {
5050
- this.included = true;
5051
- if (path.length === 0)
5052
- return;
5053
- const [key, ...subPath] = path;
5054
- const [includedMembers, includedPath] = typeof key === 'string'
5055
- ? [
5056
- new Set([
5057
- ...(this.propertiesAndGettersByKey[key] || this.unmatchablePropertiesAndGetters),
5058
- ...(this.propertiesAndSettersByKey[key] || this.unmatchablePropertiesAndSetters)
5059
- ]),
5060
- subPath
5061
- ]
5062
- : [this.allProperties, UNKNOWN_PATH];
5063
- for (const property of includedMembers) {
5064
- property.includePath(includedPath, context);
5065
- }
5066
- this.prototypeExpression?.includePath(path, context);
5067
- }
5068
4932
  buildPropertyMaps(properties) {
5069
- const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchablePropertiesAndSetters, unmatchableGetters, unmatchableSetters } = this;
4933
+ const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchableGetters, unmatchableSetters } = this;
4934
+ const unmatchablePropertiesAndSetters = [];
5070
4935
  for (let index = properties.length - 1; index >= 0; index--) {
5071
4936
  const { key, kind, property } = properties[index];
5072
4937
  allProperties.push(property);
@@ -5336,37 +5201,6 @@ const ARRAY_PROTOTYPE = new ObjectEntity({
5336
5201
  values: METHOD_DEOPTS_SELF_RETURNS_UNKNOWN
5337
5202
  }, OBJECT_PROTOTYPE, true);
5338
5203
 
5339
- class SpreadElement extends NodeBase {
5340
- deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
5341
- if (path.length > 0) {
5342
- this.argument.deoptimizeArgumentsOnInteractionAtPath(interaction, UNKNOWN_PATH, recursionTracker);
5343
- }
5344
- }
5345
- hasEffects(context) {
5346
- if (!this.deoptimized)
5347
- this.applyDeoptimizations();
5348
- const { propertyReadSideEffects } = this.scope.context.options
5349
- .treeshake;
5350
- return (this.argument.hasEffects(context) ||
5351
- (propertyReadSideEffects &&
5352
- (propertyReadSideEffects === 'always' ||
5353
- this.argument.hasEffectsOnInteractionAtPath(UNKNOWN_PATH, NODE_INTERACTION_UNKNOWN_ACCESS, context))));
5354
- }
5355
- includeNode(context) {
5356
- this.included = true;
5357
- if (!this.deoptimized)
5358
- this.applyDeoptimizations();
5359
- this.argument.includePath(UNKNOWN_PATH, context);
5360
- }
5361
- applyDeoptimizations() {
5362
- this.deoptimized = true;
5363
- // Only properties of properties of the argument could become subject to reassignment
5364
- // This will also reassign the return values of iterators
5365
- this.argument.deoptimizePath([UnknownKey, UnknownKey]);
5366
- this.scope.context.requestTreeshakingPass();
5367
- }
5368
- }
5369
-
5370
5204
  class ArrayExpression extends NodeBase {
5371
5205
  constructor() {
5372
5206
  super(...arguments);
@@ -5387,16 +5221,6 @@ class ArrayExpression extends NodeBase {
5387
5221
  hasEffectsOnInteractionAtPath(path, interaction, context) {
5388
5222
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
5389
5223
  }
5390
- includeNode(context) {
5391
- this.included = true;
5392
- if (!this.deoptimized)
5393
- this.applyDeoptimizations();
5394
- for (const element of this.elements) {
5395
- if (element) {
5396
- element?.includePath(UNKNOWN_PATH, context);
5397
- }
5398
- }
5399
- }
5400
5224
  applyDeoptimizations() {
5401
5225
  this.deoptimized = true;
5402
5226
  let hasSpread = false;
@@ -6464,37 +6288,17 @@ class GlobalVariable extends Variable {
6464
6288
  }
6465
6289
  }
6466
6290
 
6467
- // To avoid infinite recursions
6468
- const MAX_PATH_DEPTH = 6;
6469
- // If a path is longer than MAX_PATH_DEPTH, it is truncated so that it is at
6470
- // most MAX_PATH_DEPTH long. The last element is always UnknownKey
6471
- const limitConcatenatedPathDepth = (path1, path2) => {
6472
- const { length: length1 } = path1;
6473
- const { length: length2 } = path2;
6474
- return length1 === 0
6475
- ? path2
6476
- : length2 === 0
6477
- ? path1
6478
- : length1 + length2 > MAX_PATH_DEPTH
6479
- ? [...path1, ...path2.slice(0, MAX_PATH_DEPTH - 1 - path1.length), 'UnknownKey']
6480
- : [...path1, ...path2];
6481
- };
6482
-
6483
6291
  class LocalVariable extends Variable {
6484
- constructor(name, declarator, init,
6485
- /** if this is non-empty, the actual init is this path of this.init */
6486
- initPath, context, kind) {
6292
+ constructor(name, declarator, init, context, kind) {
6487
6293
  super(name);
6488
6294
  this.init = init;
6489
- this.initPath = initPath;
6490
- this.kind = kind;
6491
6295
  this.calledFromTryStatement = false;
6492
6296
  this.additionalInitializers = null;
6493
- this.includedPathTracker = new IncludedFullPathTracker();
6494
6297
  this.expressionsToBeDeoptimized = [];
6495
6298
  this.declarations = declarator ? [declarator] : [];
6496
6299
  this.deoptimizationTracker = context.deoptimizationTracker;
6497
6300
  this.module = context.module;
6301
+ this.kind = kind;
6498
6302
  }
6499
6303
  addDeclaration(identifier, init) {
6500
6304
  this.declarations.push(identifier);
@@ -6505,16 +6309,15 @@ class LocalVariable extends Variable {
6505
6309
  for (const initializer of this.additionalInitializers) {
6506
6310
  initializer.deoptimizePath(UNKNOWN_PATH);
6507
6311
  }
6312
+ this.additionalInitializers = null;
6508
6313
  }
6509
6314
  }
6510
6315
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6511
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
6316
+ if (this.isReassigned) {
6512
6317
  deoptimizeInteraction(interaction);
6513
6318
  return;
6514
6319
  }
6515
- recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6516
- this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], recursionTracker);
6517
- }, undefined);
6320
+ recursionTracker.withTrackedEntityAtPath(path, this.init, () => this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker), undefined);
6518
6321
  }
6519
6322
  deoptimizePath(path) {
6520
6323
  if (this.isReassigned ||
@@ -6528,40 +6331,37 @@ class LocalVariable extends Variable {
6528
6331
  for (const expression of expressionsToBeDeoptimized) {
6529
6332
  expression.deoptimizeCache();
6530
6333
  }
6531
- this.init.deoptimizePath([...this.initPath, UnknownKey]);
6334
+ this.init.deoptimizePath(UNKNOWN_PATH);
6532
6335
  }
6533
6336
  else {
6534
- this.init.deoptimizePath(limitConcatenatedPathDepth(this.initPath, path));
6337
+ this.init.deoptimizePath(path);
6535
6338
  }
6536
6339
  }
6537
6340
  getLiteralValueAtPath(path, recursionTracker, origin) {
6538
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
6341
+ if (this.isReassigned) {
6539
6342
  return UnknownValue;
6540
6343
  }
6541
6344
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6542
6345
  this.expressionsToBeDeoptimized.push(origin);
6543
- return this.init.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin);
6346
+ return this.init.getLiteralValueAtPath(path, recursionTracker, origin);
6544
6347
  }, UnknownValue);
6545
6348
  }
6546
6349
  getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
6547
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
6350
+ if (this.isReassigned) {
6548
6351
  return UNKNOWN_RETURN_EXPRESSION;
6549
6352
  }
6550
6353
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6551
6354
  this.expressionsToBeDeoptimized.push(origin);
6552
- return this.init.getReturnExpressionWhenCalledAtPath([...this.initPath, ...path], interaction, recursionTracker, origin);
6355
+ return this.init.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
6553
6356
  }, UNKNOWN_RETURN_EXPRESSION);
6554
6357
  }
6555
6358
  hasEffectsOnInteractionAtPath(path, interaction, context) {
6556
- if (path.length + this.initPath.length > MAX_PATH_DEPTH) {
6557
- return true;
6558
- }
6559
6359
  switch (interaction.type) {
6560
6360
  case INTERACTION_ACCESSED: {
6561
6361
  if (this.isReassigned)
6562
6362
  return true;
6563
6363
  return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
6564
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6364
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6565
6365
  }
6566
6366
  case INTERACTION_ASSIGNED: {
6567
6367
  if (this.included)
@@ -6571,63 +6371,44 @@ class LocalVariable extends Variable {
6571
6371
  if (this.isReassigned)
6572
6372
  return true;
6573
6373
  return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
6574
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6374
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6575
6375
  }
6576
6376
  case INTERACTION_CALLED: {
6577
6377
  if (this.isReassigned)
6578
6378
  return true;
6579
6379
  return (!(interaction.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this) &&
6580
- this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
6380
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6581
6381
  }
6582
6382
  }
6583
6383
  }
6584
- includePath(path, context) {
6585
- if (!this.includedPathTracker.includePathAndGetIfIncluded(path)) {
6586
- this.module.scope.context.requestTreeshakingPass();
6587
- if (!this.included) {
6588
- // This will reduce the number of tree-shaking passes by eagerly
6589
- // including inits. By pushing this here instead of directly including
6590
- // we avoid deep call stacks.
6591
- this.module.scope.context.newlyIncludedVariableInits.add(this.init);
6592
- }
6593
- super.includePath(path, context);
6384
+ include() {
6385
+ if (!this.included) {
6386
+ super.include();
6594
6387
  for (const declaration of this.declarations) {
6595
6388
  // If node is a default export, it can save a tree-shaking run to include the full declaration now
6596
6389
  if (!declaration.included)
6597
- declaration.include(context, false);
6390
+ declaration.include(createInclusionContext(), false);
6598
6391
  let node = declaration.parent;
6599
6392
  while (!node.included) {
6600
6393
  // We do not want to properly include parents in case they are part of a dead branch
6601
6394
  // in which case .include() might pull in more dead code
6602
- node.includeNode(context);
6395
+ node.included = true;
6603
6396
  if (node.type === parseAst_js.Program)
6604
6397
  break;
6605
6398
  node = node.parent;
6606
6399
  }
6607
6400
  }
6608
- // We need to make sure we include the correct path of the init
6609
- if (path.length > 0) {
6610
- this.init.includePath(limitConcatenatedPathDepth(this.initPath, path), context);
6611
- this.additionalInitializers?.forEach(initializer => initializer.includePath(UNKNOWN_PATH, context));
6612
- }
6613
6401
  }
6614
6402
  }
6615
- includeCallArguments(context, interaction) {
6616
- if (this.isReassigned ||
6617
- context.includedCallArguments.has(this.init) ||
6618
- // This can be removed again once we can include arguments when called at
6619
- // a specific path
6620
- this.initPath.length > 0) {
6621
- for (const argument of interaction.args) {
6622
- if (argument) {
6623
- argument.includePath(UNKNOWN_PATH, context);
6624
- argument.include(context, false);
6625
- }
6403
+ includeCallArguments(context, parameters) {
6404
+ if (this.isReassigned || context.includedCallArguments.has(this.init)) {
6405
+ for (const argument of parameters) {
6406
+ argument.include(context, false);
6626
6407
  }
6627
6408
  }
6628
6409
  else {
6629
6410
  context.includedCallArguments.add(this.init);
6630
- this.init.includeCallArguments(context, interaction);
6411
+ this.init.includeCallArguments(context, parameters);
6631
6412
  context.includedCallArguments.delete(this.init);
6632
6413
  }
6633
6414
  }
@@ -6707,31 +6488,18 @@ class IdentifierBase extends NodeBase {
6707
6488
  }
6708
6489
  }
6709
6490
  }
6710
- include(context) {
6711
- if (!this.included)
6712
- this.includeNode(context);
6713
- }
6714
- includeNode(context) {
6715
- this.included = true;
6491
+ include() {
6716
6492
  if (!this.deoptimized)
6717
6493
  this.applyDeoptimizations();
6718
- if (this.variable !== null) {
6719
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
6720
- }
6721
- }
6722
- includePath(path, context) {
6723
6494
  if (!this.included) {
6724
6495
  this.included = true;
6725
6496
  if (this.variable !== null) {
6726
- this.scope.context.includeVariableInModule(this.variable, path, context);
6497
+ this.scope.context.includeVariableInModule(this.variable);
6727
6498
  }
6728
6499
  }
6729
- else if (path.length > 0) {
6730
- this.variable?.includePath(path, context);
6731
- }
6732
6500
  }
6733
- includeCallArguments(context, interaction) {
6734
- this.variable.includeCallArguments(context, interaction);
6501
+ includeCallArguments(context, parameters) {
6502
+ this.variable.includeCallArguments(context, parameters);
6735
6503
  }
6736
6504
  isPossibleTDZ() {
6737
6505
  // return cached value to avoid issues with the next tree-shaking pass
@@ -6814,40 +6582,11 @@ function closestParentFunctionOrProgram(node) {
6814
6582
  return node;
6815
6583
  }
6816
6584
 
6817
- class ObjectMember extends ExpressionEntity {
6818
- constructor(object, path) {
6819
- super();
6820
- this.object = object;
6821
- this.path = path;
6822
- }
6823
- deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6824
- this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.path, ...path], recursionTracker);
6825
- }
6826
- deoptimizePath(path) {
6827
- this.object.deoptimizePath([...this.path, ...path]);
6828
- }
6829
- getLiteralValueAtPath(path, recursionTracker, origin) {
6830
- return this.object.getLiteralValueAtPath([...this.path, ...path], recursionTracker, origin);
6831
- }
6832
- getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
6833
- return this.object.getReturnExpressionWhenCalledAtPath([...this.path, ...path], interaction, recursionTracker, origin);
6834
- }
6835
- hasEffectsOnInteractionAtPath(path, interaction, context) {
6836
- return this.object.hasEffectsOnInteractionAtPath([...this.path, ...path], interaction, context);
6837
- }
6838
- }
6839
-
6840
6585
  class Identifier extends IdentifierBase {
6841
6586
  constructor() {
6842
6587
  super(...arguments);
6843
6588
  this.variable = null;
6844
6589
  }
6845
- get isDestructuringDeoptimized() {
6846
- return isFlagSet(this.flags, 16777216 /* Flag.destructuringDeoptimized */);
6847
- }
6848
- set isDestructuringDeoptimized(value) {
6849
- this.flags = setFlag(this.flags, 16777216 /* Flag.destructuringDeoptimized */, value);
6850
- }
6851
6590
  addExportedVariables(variables, exportNamesByVariable) {
6852
6591
  if (exportNamesByVariable.has(this.variable)) {
6853
6592
  variables.push(this.variable);
@@ -6860,52 +6599,42 @@ class Identifier extends IdentifierBase {
6860
6599
  this.isVariableReference = true;
6861
6600
  }
6862
6601
  }
6863
- declare(kind, destructuredInitPath, init) {
6602
+ declare(kind, init) {
6864
6603
  let variable;
6865
6604
  const { treeshake } = this.scope.context.options;
6866
- if (kind === 'parameter') {
6867
- variable = this.scope.addParameterDeclaration(this, destructuredInitPath);
6868
- }
6869
- else {
6870
- variable = this.scope.addDeclaration(this, this.scope.context, init, destructuredInitPath, kind);
6871
- if (kind === 'var' && treeshake && treeshake.correctVarValueBeforeDeclaration) {
6872
- // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
6873
- variable.markInitializersForDeoptimization();
6605
+ switch (kind) {
6606
+ case 'var': {
6607
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
6608
+ if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
6609
+ // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
6610
+ variable.markInitializersForDeoptimization();
6611
+ }
6612
+ break;
6874
6613
  }
6875
- }
6876
- return [(this.variable = variable)];
6877
- }
6878
- deoptimizeAssignment(destructuredInitPath, init) {
6879
- this.deoptimizePath(EMPTY_PATH);
6880
- init.deoptimizePath([...destructuredInitPath, UnknownKey]);
6881
- }
6882
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
6883
- return (destructuredInitPath.length > 0 &&
6884
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, context));
6885
- }
6886
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
6887
- if (destructuredInitPath.length > 0 && !this.isDestructuringDeoptimized) {
6888
- this.isDestructuringDeoptimized = true;
6889
- init.deoptimizeArgumentsOnInteractionAtPath({
6890
- args: [new ObjectMember(init, destructuredInitPath.slice(0, -1))],
6891
- type: INTERACTION_ACCESSED
6892
- }, destructuredInitPath, SHARED_RECURSION_TRACKER);
6893
- }
6894
- const { propertyReadSideEffects } = this.scope.context.options
6895
- .treeshake;
6896
- if ((this.included ||=
6897
- destructuredInitPath.length > 0 &&
6898
- !context.brokenFlow &&
6899
- propertyReadSideEffects &&
6900
- (propertyReadSideEffects === 'always' ||
6901
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, createHasEffectsContext())))) {
6902
- if (this.variable && !this.variable.included) {
6903
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
6614
+ case 'function': {
6615
+ // in strict mode, functions are only hoisted within a scope but not across block scopes
6616
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
6617
+ break;
6618
+ }
6619
+ case 'let':
6620
+ case 'const':
6621
+ case 'using':
6622
+ case 'await using':
6623
+ case 'class': {
6624
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
6625
+ break;
6626
+ }
6627
+ case 'parameter': {
6628
+ variable = this.scope.addParameterDeclaration(this);
6629
+ break;
6630
+ }
6631
+ /* istanbul ignore next */
6632
+ default: {
6633
+ /* istanbul ignore next */
6634
+ throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
6904
6635
  }
6905
- init.includePath(destructuredInitPath, context);
6906
- return true;
6907
6636
  }
6908
- return false;
6637
+ return [(this.variable = variable)];
6909
6638
  }
6910
6639
  markDeclarationReached() {
6911
6640
  this.variable.initReached = true;
@@ -6959,17 +6688,18 @@ class Scope {
6959
6688
  - then the variable is still declared in the hoisted outer scope, but the initializer is assigned to the parameter
6960
6689
  - const, let, class, and function except in the cases above cannot redeclare anything
6961
6690
  */
6962
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
6691
+ addDeclaration(identifier, context, init, kind) {
6963
6692
  const name = identifier.name;
6964
6693
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
6965
6694
  if (existingVariable) {
6966
- if (kind === 'var' && existingVariable.kind === 'var') {
6695
+ const existingKind = existingVariable.kind;
6696
+ if (kind === 'var' && existingKind === 'var') {
6967
6697
  existingVariable.addDeclaration(identifier, init);
6968
6698
  return existingVariable;
6969
6699
  }
6970
6700
  context.error(parseAst_js.logRedeclarationError(name), identifier.start);
6971
6701
  }
6972
- const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
6702
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
6973
6703
  this.variables.set(name, newVariable);
6974
6704
  return newVariable;
6975
6705
  }
@@ -7145,6 +6875,7 @@ class MethodBase extends NodeBase {
7145
6875
  }
7146
6876
  return this.getAccessedValue()[0].hasEffectsOnInteractionAtPath(path, interaction, context);
7147
6877
  }
6878
+ applyDeoptimizations() { }
7148
6879
  getAccessedValue() {
7149
6880
  if (this.accessedValue === null) {
7150
6881
  if (this.kind === 'get') {
@@ -7158,20 +6889,19 @@ class MethodBase extends NodeBase {
7158
6889
  return this.accessedValue;
7159
6890
  }
7160
6891
  }
7161
- MethodBase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
7162
- MethodBase.prototype.applyDeoptimizations = doNotDeoptimize;
7163
6892
 
7164
6893
  class MethodDefinition extends MethodBase {
7165
6894
  hasEffects(context) {
7166
6895
  return super.hasEffects(context) || checkEffectForNodes(this.decorators, context);
7167
6896
  }
6897
+ applyDeoptimizations() { }
7168
6898
  }
7169
6899
 
7170
6900
  class BlockScope extends ChildScope {
7171
6901
  constructor(parent) {
7172
6902
  super(parent, parent.context);
7173
6903
  }
7174
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
6904
+ addDeclaration(identifier, context, init, kind) {
7175
6905
  if (kind === 'var') {
7176
6906
  const name = identifier.name;
7177
6907
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -7183,7 +6913,7 @@ class BlockScope extends ChildScope {
7183
6913
  }
7184
6914
  return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7185
6915
  }
7186
- const declaredVariable = this.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
6916
+ const declaredVariable = this.parent.addDeclaration(identifier, context, init, kind);
7187
6917
  // Necessary to make sure the init is deoptimized for conditional declarations.
7188
6918
  // We cannot call deoptimizePath here.
7189
6919
  declaredVariable.markInitializersForDeoptimization();
@@ -7191,7 +6921,7 @@ class BlockScope extends ChildScope {
7191
6921
  this.addHoistedVariable(name, declaredVariable);
7192
6922
  return declaredVariable;
7193
6923
  }
7194
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
6924
+ return super.addDeclaration(identifier, context, init, kind);
7195
6925
  }
7196
6926
  }
7197
6927
 
@@ -7223,12 +6953,33 @@ class StaticBlock extends NodeBase {
7223
6953
  }
7224
6954
  }
7225
6955
  }
7226
- StaticBlock.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
7227
- StaticBlock.prototype.applyDeoptimizations = doNotDeoptimize;
7228
6956
  function isStaticBlock(statement) {
7229
6957
  return statement.type === parseAst_js.StaticBlock;
7230
6958
  }
7231
6959
 
6960
+ class ObjectMember extends ExpressionEntity {
6961
+ constructor(object, key) {
6962
+ super();
6963
+ this.object = object;
6964
+ this.key = key;
6965
+ }
6966
+ deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
6967
+ this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [this.key, ...path], recursionTracker);
6968
+ }
6969
+ deoptimizePath(path) {
6970
+ this.object.deoptimizePath([this.key, ...path]);
6971
+ }
6972
+ getLiteralValueAtPath(path, recursionTracker, origin) {
6973
+ return this.object.getLiteralValueAtPath([this.key, ...path], recursionTracker, origin);
6974
+ }
6975
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
6976
+ return this.object.getReturnExpressionWhenCalledAtPath([this.key, ...path], interaction, recursionTracker, origin);
6977
+ }
6978
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
6979
+ return this.object.hasEffectsOnInteractionAtPath([this.key, ...path], interaction, context);
6980
+ }
6981
+ }
6982
+
7232
6983
  class ClassNode extends NodeBase {
7233
6984
  constructor() {
7234
6985
  super(...arguments);
@@ -7269,20 +7020,21 @@ class ClassNode extends NodeBase {
7269
7020
  : this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
7270
7021
  }
7271
7022
  include(context, includeChildrenRecursively) {
7272
- if (!this.included)
7273
- this.includeNode(context);
7023
+ if (!this.deoptimized)
7024
+ this.applyDeoptimizations();
7025
+ this.included = true;
7274
7026
  this.superClass?.include(context, includeChildrenRecursively);
7275
7027
  this.body.include(context, includeChildrenRecursively);
7276
7028
  for (const decorator of this.decorators)
7277
7029
  decorator.include(context, includeChildrenRecursively);
7278
7030
  if (this.id) {
7279
7031
  this.id.markDeclarationReached();
7280
- this.id.include(context);
7032
+ this.id.include();
7281
7033
  }
7282
7034
  }
7283
7035
  initialise() {
7284
7036
  super.initialise();
7285
- this.id?.declare('class', EMPTY_PATH, this);
7037
+ this.id?.declare('class', this);
7286
7038
  for (const method of this.body.body) {
7287
7039
  if (method instanceof MethodDefinition && method.kind === 'constructor') {
7288
7040
  this.classConstructor = method;
@@ -7340,12 +7092,11 @@ class ClassNode extends NodeBase {
7340
7092
  staticProperties.unshift({
7341
7093
  key: 'prototype',
7342
7094
  kind: 'init',
7343
- property: new ObjectEntity(dynamicMethods, this.superClass ? new ObjectMember(this.superClass, ['prototype']) : OBJECT_PROTOTYPE)
7095
+ property: new ObjectEntity(dynamicMethods, this.superClass ? new ObjectMember(this.superClass, 'prototype') : OBJECT_PROTOTYPE)
7344
7096
  });
7345
7097
  return (this.objectEntity = new ObjectEntity(staticProperties, this.superClass || OBJECT_PROTOTYPE));
7346
7098
  }
7347
7099
  }
7348
- ClassNode.prototype.includeNode = onlyIncludeSelf;
7349
7100
 
7350
7101
  class ClassDeclaration extends ClassNode {
7351
7102
  initialise() {
@@ -7398,60 +7149,53 @@ class ClassDeclaration extends ClassNode {
7398
7149
 
7399
7150
  class ArgumentsVariable extends LocalVariable {
7400
7151
  constructor(context) {
7401
- super('arguments', null, UNKNOWN_EXPRESSION, EMPTY_PATH, context, 'other');
7402
- }
7403
- addArgumentToBeDeoptimized(_argument) { }
7404
- // Only If there is at least one reference, then we need to track all
7405
- // arguments in order to be able to deoptimize them.
7406
- addReference() {
7152
+ super('arguments', null, UNKNOWN_EXPRESSION, context, 'other');
7407
7153
  this.deoptimizedArguments = [];
7408
- this.addArgumentToBeDeoptimized = addArgumentToBeDeoptimized;
7154
+ }
7155
+ addArgumentToBeDeoptimized(argument) {
7156
+ if (this.included) {
7157
+ argument.deoptimizePath(UNKNOWN_PATH);
7158
+ }
7159
+ else {
7160
+ this.deoptimizedArguments.push(argument);
7161
+ }
7409
7162
  }
7410
7163
  hasEffectsOnInteractionAtPath(path, { type }) {
7411
7164
  return type !== INTERACTION_ACCESSED || path.length > 1;
7412
7165
  }
7413
- includePath(path, context) {
7414
- super.includePath(path, context);
7166
+ include() {
7167
+ super.include();
7415
7168
  for (const argument of this.deoptimizedArguments) {
7416
7169
  argument.deoptimizePath(UNKNOWN_PATH);
7417
7170
  }
7418
7171
  this.deoptimizedArguments.length = 0;
7419
7172
  }
7420
7173
  }
7421
- function addArgumentToBeDeoptimized(argument) {
7422
- if (this.included) {
7423
- argument.deoptimizePath(UNKNOWN_PATH);
7424
- }
7425
- else {
7426
- this.deoptimizedArguments?.push(argument);
7427
- }
7428
- }
7429
7174
 
7430
7175
  const MAX_TRACKED_INTERACTIONS = 20;
7431
7176
  const NO_INTERACTIONS = parseAst_js.EMPTY_ARRAY;
7432
7177
  const UNKNOWN_DEOPTIMIZED_FIELD = new Set([UnknownKey]);
7433
- const EMPTY_PATH_TRACKER = new EntityPathTracker();
7178
+ const EMPTY_PATH_TRACKER = new PathTracker();
7434
7179
  const UNKNOWN_DEOPTIMIZED_ENTITY = new Set([UNKNOWN_EXPRESSION]);
7435
7180
  class ParameterVariable extends LocalVariable {
7436
- constructor(name, declarator, argumentPath, context) {
7437
- super(name, declarator, UNKNOWN_EXPRESSION, argumentPath, context, 'parameter');
7438
- this.includedPathTracker = new IncludedTopLevelPathTracker();
7439
- this.argumentsToBeDeoptimized = new Set();
7181
+ constructor(name, declarator, context) {
7182
+ super(name, declarator, UNKNOWN_EXPRESSION, context, 'parameter');
7440
7183
  this.deoptimizationInteractions = [];
7441
- this.deoptimizations = new EntityPathTracker();
7184
+ this.deoptimizations = new PathTracker();
7442
7185
  this.deoptimizedFields = new Set();
7443
- this.expressionsDependingOnKnownValue = [];
7186
+ this.entitiesToBeDeoptimized = new Set();
7187
+ this.expressionsUseTheKnownValue = [];
7444
7188
  this.knownValue = null;
7445
7189
  this.knownValueLiteral = UnknownValue;
7190
+ this.frozenValue = null;
7446
7191
  }
7447
- addArgumentValue(entity) {
7448
- this.updateKnownValue(entity);
7192
+ addEntityToBeDeoptimized(entity) {
7449
7193
  if (entity === UNKNOWN_EXPRESSION) {
7450
7194
  // As unknown expressions fully deoptimize all interactions, we can clear
7451
7195
  // the interaction cache at this point provided we keep this optimization
7452
7196
  // in mind when adding new interactions
7453
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7454
- this.argumentsToBeDeoptimized.add(UNKNOWN_EXPRESSION);
7197
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7198
+ this.entitiesToBeDeoptimized.add(UNKNOWN_EXPRESSION);
7455
7199
  for (const { interaction } of this.deoptimizationInteractions) {
7456
7200
  deoptimizeInteraction(interaction);
7457
7201
  }
@@ -7461,30 +7205,27 @@ class ParameterVariable extends LocalVariable {
7461
7205
  else if (this.deoptimizedFields.has(UnknownKey)) {
7462
7206
  // This means that we already deoptimized all interactions and no longer
7463
7207
  // track them
7464
- entity.deoptimizePath([...this.initPath, UnknownKey]);
7208
+ entity.deoptimizePath(UNKNOWN_PATH);
7465
7209
  }
7466
- else if (!this.argumentsToBeDeoptimized.has(entity)) {
7467
- this.argumentsToBeDeoptimized.add(entity);
7210
+ else if (!this.entitiesToBeDeoptimized.has(entity)) {
7211
+ this.entitiesToBeDeoptimized.add(entity);
7468
7212
  for (const field of this.deoptimizedFields) {
7469
- entity.deoptimizePath([...this.initPath, field]);
7213
+ entity.deoptimizePath([field]);
7470
7214
  }
7471
7215
  for (const { interaction, path } of this.deoptimizationInteractions) {
7472
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
7216
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
7473
7217
  }
7474
7218
  }
7475
7219
  }
7476
- /** This says we should not make assumptions about the value of the parameter.
7477
- * This is different from deoptimization that will also cause argument values
7478
- * to be deoptimized. */
7479
7220
  markReassigned() {
7480
7221
  if (this.isReassigned) {
7481
7222
  return;
7482
7223
  }
7483
7224
  super.markReassigned();
7484
- for (const expression of this.expressionsDependingOnKnownValue) {
7225
+ for (const expression of this.expressionsUseTheKnownValue) {
7485
7226
  expression.deoptimizeCache();
7486
7227
  }
7487
- this.expressionsDependingOnKnownValue = parseAst_js.EMPTY_ARRAY;
7228
+ this.expressionsUseTheKnownValue = parseAst_js.EMPTY_ARRAY;
7488
7229
  }
7489
7230
  deoptimizeCache() {
7490
7231
  this.markReassigned();
@@ -7501,7 +7242,7 @@ class ParameterVariable extends LocalVariable {
7501
7242
  }
7502
7243
  if (this.knownValue === null) {
7503
7244
  this.knownValue = argument;
7504
- this.knownValueLiteral = argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this);
7245
+ this.knownValueLiteral = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
7505
7246
  return;
7506
7247
  }
7507
7248
  // the same literal or identifier, do nothing
@@ -7511,10 +7252,14 @@ class ParameterVariable extends LocalVariable {
7511
7252
  this.knownValue.variable === argument.variable)) {
7512
7253
  return;
7513
7254
  }
7514
- const { knownValueLiteral } = this;
7515
- if (typeof knownValueLiteral === 'symbol' ||
7516
- argument.getLiteralValueAtPath(this.initPath, SHARED_RECURSION_TRACKER, this) !==
7517
- knownValueLiteral) {
7255
+ const oldValue = this.knownValueLiteral;
7256
+ if (typeof oldValue === 'symbol') {
7257
+ this.markReassigned();
7258
+ return;
7259
+ }
7260
+ // add tracking for the new argument
7261
+ const newValue = argument.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
7262
+ if (newValue !== oldValue) {
7518
7263
  this.markReassigned();
7519
7264
  }
7520
7265
  }
@@ -7525,47 +7270,42 @@ class ParameterVariable extends LocalVariable {
7525
7270
  * @returns the frozen value
7526
7271
  */
7527
7272
  getKnownValue() {
7528
- return this.knownValue || UNKNOWN_EXPRESSION;
7273
+ if (this.frozenValue === null) {
7274
+ this.frozenValue = this.knownValue || UNKNOWN_EXPRESSION;
7275
+ }
7276
+ return this.frozenValue;
7529
7277
  }
7530
7278
  getLiteralValueAtPath(path, recursionTracker, origin) {
7531
- if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
7279
+ if (this.isReassigned) {
7532
7280
  return UnknownValue;
7533
7281
  }
7534
7282
  const knownValue = this.getKnownValue();
7535
- this.expressionsDependingOnKnownValue.push(origin);
7536
- return recursionTracker.withTrackedEntityAtPath(path, knownValue, () => knownValue.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin), UnknownValue);
7283
+ this.expressionsUseTheKnownValue.push(origin);
7284
+ return recursionTracker.withTrackedEntityAtPath(path, knownValue, () => knownValue.getLiteralValueAtPath(path, recursionTracker, origin), UnknownValue);
7537
7285
  }
7538
7286
  hasEffectsOnInteractionAtPath(path, interaction, context) {
7539
- const { type } = interaction;
7540
- if (this.isReassigned ||
7541
- type === INTERACTION_ASSIGNED ||
7542
- path.length + this.initPath.length > MAX_PATH_DEPTH) {
7287
+ if (this.isReassigned || interaction.type === INTERACTION_ASSIGNED) {
7543
7288
  return super.hasEffectsOnInteractionAtPath(path, interaction, context);
7544
7289
  }
7545
- return (!(type === INTERACTION_CALLED
7546
- ? (interaction.withNew
7547
- ? context.instantiated
7548
- : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this)
7549
- : context.accessed.trackEntityAtPathAndGetIfTracked(path, this)) &&
7550
- this.getKnownValue().hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
7290
+ const knownValue = this.getKnownValue();
7291
+ return knownValue.hasEffectsOnInteractionAtPath(path, interaction, context);
7551
7292
  }
7552
7293
  deoptimizeArgumentsOnInteractionAtPath(interaction, path) {
7553
7294
  // For performance reasons, we fully deoptimize all deeper interactions
7554
7295
  if (path.length >= 2 ||
7555
- this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
7296
+ this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION) ||
7556
7297
  this.deoptimizationInteractions.length >= MAX_TRACKED_INTERACTIONS ||
7557
7298
  (path.length === 1 &&
7558
7299
  (this.deoptimizedFields.has(UnknownKey) ||
7559
- (interaction.type === INTERACTION_CALLED && this.deoptimizedFields.has(path[0])))) ||
7560
- this.initPath.length + path.length > MAX_PATH_DEPTH) {
7300
+ (interaction.type === INTERACTION_CALLED && this.deoptimizedFields.has(path[0]))))) {
7561
7301
  deoptimizeInteraction(interaction);
7562
7302
  return;
7563
7303
  }
7564
7304
  if (!this.deoptimizations.trackEntityAtPathAndGetIfTracked(path, interaction.args)) {
7565
- for (const entity of this.argumentsToBeDeoptimized) {
7566
- entity.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], SHARED_RECURSION_TRACKER);
7305
+ for (const entity of this.entitiesToBeDeoptimized) {
7306
+ entity.deoptimizeArgumentsOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
7567
7307
  }
7568
- if (!this.argumentsToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7308
+ if (!this.entitiesToBeDeoptimized.has(UNKNOWN_EXPRESSION)) {
7569
7309
  this.deoptimizationInteractions.push({
7570
7310
  interaction,
7571
7311
  path
@@ -7586,17 +7326,17 @@ class ParameterVariable extends LocalVariable {
7586
7326
  return;
7587
7327
  }
7588
7328
  this.deoptimizedFields.add(key);
7589
- for (const entity of this.argumentsToBeDeoptimized) {
7329
+ for (const entity of this.entitiesToBeDeoptimized) {
7590
7330
  // We do not need a recursion tracker here as we already track whether
7591
7331
  // this field is deoptimized
7592
- entity.deoptimizePath([...this.initPath, key]);
7332
+ entity.deoptimizePath([key]);
7593
7333
  }
7594
7334
  if (key === UnknownKey) {
7595
7335
  // save some memory
7596
7336
  this.deoptimizationInteractions = NO_INTERACTIONS;
7597
7337
  this.deoptimizations = EMPTY_PATH_TRACKER;
7598
7338
  this.deoptimizedFields = UNKNOWN_DEOPTIMIZED_FIELD;
7599
- this.argumentsToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
7339
+ this.entitiesToBeDeoptimized = UNKNOWN_DEOPTIMIZED_ENTITY;
7600
7340
  }
7601
7341
  }
7602
7342
  getReturnExpressionWhenCalledAtPath(path) {
@@ -7611,14 +7351,11 @@ class ParameterVariable extends LocalVariable {
7611
7351
  }
7612
7352
  return UNKNOWN_RETURN_EXPRESSION;
7613
7353
  }
7614
- includeArgumentPaths(entity, context) {
7615
- this.includedPathTracker.includeAllPaths(entity, context, this.initPath);
7616
- }
7617
7354
  }
7618
7355
 
7619
7356
  class ThisVariable extends ParameterVariable {
7620
7357
  constructor(context) {
7621
- super('this', null, EMPTY_PATH, context);
7358
+ super('this', null, context);
7622
7359
  }
7623
7360
  hasEffectsOnInteractionAtPath(path, interaction, context) {
7624
7361
  return (context.replacedVariableInits.get(this) || UNKNOWN_EXPRESSION).hasEffectsOnInteractionAtPath(path, interaction, context);
@@ -7630,7 +7367,7 @@ class CatchBodyScope extends ChildScope {
7630
7367
  super(parent, parent.context);
7631
7368
  this.parent = parent;
7632
7369
  }
7633
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
7370
+ addDeclaration(identifier, context, init, kind) {
7634
7371
  if (kind === 'var') {
7635
7372
  const name = identifier.name;
7636
7373
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
@@ -7643,7 +7380,7 @@ class CatchBodyScope extends ChildScope {
7643
7380
  // the assignment actually goes to the parameter and the var is
7644
7381
  // hoisted without assignment. Locally, it is shadowed by the
7645
7382
  // parameter
7646
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, destructuredInitPath, kind);
7383
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, kind);
7647
7384
  // To avoid the need to rewrite the declaration, we link the variable
7648
7385
  // names. If we ever implement a logic that splits initialization and
7649
7386
  // assignment for hoisted vars, the "renderLikeHoisted" logic can be
@@ -7662,7 +7399,7 @@ class CatchBodyScope extends ChildScope {
7662
7399
  return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7663
7400
  }
7664
7401
  // We only add parameters to parameter scopes
7665
- const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
7402
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, kind);
7666
7403
  // Necessary to make sure the init is deoptimized for conditional declarations.
7667
7404
  // We cannot call deoptimizePath here.
7668
7405
  declaredVariable.markInitializersForDeoptimization();
@@ -7670,7 +7407,7 @@ class CatchBodyScope extends ChildScope {
7670
7407
  this.addHoistedVariable(name, declaredVariable);
7671
7408
  return declaredVariable;
7672
7409
  }
7673
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
7410
+ return super.addDeclaration(identifier, context, init, kind);
7674
7411
  }
7675
7412
  }
7676
7413
 
@@ -7680,7 +7417,7 @@ class FunctionBodyScope extends ChildScope {
7680
7417
  }
7681
7418
  // There is stuff that is only allowed in function scopes, i.e. functions can
7682
7419
  // be redeclared, functions and var can redeclare each other
7683
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
7420
+ addDeclaration(identifier, context, init, kind) {
7684
7421
  const name = identifier.name;
7685
7422
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
7686
7423
  if (existingVariable) {
@@ -7692,7 +7429,7 @@ class FunctionBodyScope extends ChildScope {
7692
7429
  }
7693
7430
  context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7694
7431
  }
7695
- const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
7432
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
7696
7433
  this.variables.set(name, newVariable);
7697
7434
  return newVariable;
7698
7435
  }
@@ -7701,21 +7438,21 @@ class FunctionBodyScope extends ChildScope {
7701
7438
  class ParameterScope extends ChildScope {
7702
7439
  constructor(parent, isCatchScope) {
7703
7440
  super(parent, parent.context);
7704
- this.hasRest = false;
7705
7441
  this.parameters = [];
7442
+ this.hasRest = false;
7706
7443
  this.bodyScope = isCatchScope ? new CatchBodyScope(this) : new FunctionBodyScope(this);
7707
7444
  }
7708
7445
  /**
7709
7446
  * Adds a parameter to this scope. Parameters must be added in the correct
7710
7447
  * order, i.e. from left to right.
7711
7448
  */
7712
- addParameterDeclaration(identifier, argumentPath) {
7449
+ addParameterDeclaration(identifier) {
7713
7450
  const { name, start } = identifier;
7714
7451
  const existingParameter = this.variables.get(name);
7715
7452
  if (existingParameter) {
7716
7453
  return this.context.error(parseAst_js.logDuplicateArgumentNameError(name), start);
7717
7454
  }
7718
- const variable = new ParameterVariable(name, identifier, argumentPath, this.context);
7455
+ const variable = new ParameterVariable(name, identifier, this.context);
7719
7456
  this.variables.set(name, variable);
7720
7457
  // We also add it to the body scope to detect name conflicts with local
7721
7458
  // variables. We still need the intermediate scope, though, as parameter
@@ -7733,56 +7470,42 @@ class ParameterScope extends ChildScope {
7733
7470
  }
7734
7471
  this.hasRest = hasRest;
7735
7472
  }
7736
- includeCallArguments(context, interaction) {
7473
+ includeCallArguments(context, parameters) {
7737
7474
  let calledFromTryStatement = false;
7738
7475
  let argumentIncluded = false;
7739
7476
  const restParameter = this.hasRest && this.parameters[this.parameters.length - 1];
7740
- const { args } = interaction;
7741
- let lastExplicitlyIncludedIndex = args.length - 1;
7742
- // If there is a SpreadElement, we need to include all arguments after it
7743
- // because we no longer know which argument corresponds to which parameter.
7744
- for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
7745
- const argument = args[argumentIndex];
7746
- if (argument instanceof SpreadElement && !argumentIncluded) {
7747
- argumentIncluded = true;
7748
- lastExplicitlyIncludedIndex = argumentIndex - 1;
7749
- }
7750
- if (argumentIncluded) {
7751
- argument.includePath(UNKNOWN_PATH, context);
7752
- argument.include(context, false);
7477
+ for (const checkedArgument of parameters) {
7478
+ if (checkedArgument instanceof SpreadElement) {
7479
+ for (const argument of parameters) {
7480
+ argument.include(context, false);
7481
+ }
7482
+ break;
7753
7483
  }
7754
7484
  }
7755
- // Now we go backwards either starting from the last argument or before the
7756
- // first SpreadElement to ensure all arguments before are included as needed
7757
- for (let index = lastExplicitlyIncludedIndex; index >= 1; index--) {
7758
- const parameterVariables = this.parameters[index - 1] || restParameter;
7759
- const argument = args[index];
7485
+ for (let index = parameters.length - 1; index >= 0; index--) {
7486
+ const parameterVariables = this.parameters[index] || restParameter;
7487
+ const argument = parameters[index];
7760
7488
  if (parameterVariables) {
7761
7489
  calledFromTryStatement = false;
7762
7490
  if (parameterVariables.length === 0) {
7763
- // handle empty destructuring to avoid destructuring undefined
7491
+ // handle empty destructuring
7764
7492
  argumentIncluded = true;
7765
7493
  }
7766
7494
  else {
7767
- for (const parameterVariable of parameterVariables) {
7768
- if (parameterVariable.calledFromTryStatement) {
7769
- calledFromTryStatement = true;
7770
- }
7771
- if (parameterVariable.included) {
7495
+ for (const variable of parameterVariables) {
7496
+ if (variable.included) {
7772
7497
  argumentIncluded = true;
7773
- if (calledFromTryStatement) {
7774
- argument.include(context, true);
7775
- }
7776
- else {
7777
- parameterVariable.includeArgumentPaths(argument, context);
7778
- argument.include(context, false);
7779
- }
7498
+ }
7499
+ if (variable.calledFromTryStatement) {
7500
+ calledFromTryStatement = true;
7780
7501
  }
7781
7502
  }
7782
7503
  }
7783
7504
  }
7784
- if (!argument.included && (argumentIncluded || argument.shouldBeIncluded(context))) {
7505
+ if (!argumentIncluded && argument.shouldBeIncluded(context)) {
7785
7506
  argumentIncluded = true;
7507
+ }
7508
+ if (argumentIncluded) {
7786
7509
  argument.include(context, calledFromTryStatement);
7787
7510
  }
7788
7511
  }
@@ -7798,62 +7521,11 @@ class ReturnValueScope extends ParameterScope {
7798
7521
  addReturnExpression(expression) {
7799
7522
  this.returnExpressions.push(expression);
7800
7523
  }
7801
- deoptimizeArgumentsOnCall(interaction) {
7802
- const { parameters } = this;
7803
- const { args } = interaction;
7804
- let position = 0;
7805
- for (; position < args.length - 1; position++) {
7806
- // Only the "this" argument arg[0] can be null
7807
- const argument = args[position + 1];
7808
- if (argument instanceof SpreadElement) {
7809
- // This deoptimizes the current and remaining parameters and arguments
7810
- for (; position < parameters.length; position++) {
7811
- args[position + 1]?.deoptimizePath(UNKNOWN_PATH);
7812
- parameters[position].forEach(variable => variable.markReassigned());
7813
- }
7814
- break;
7815
- }
7816
- if (this.hasRest && position >= parameters.length - 1) {
7817
- argument.deoptimizePath(UNKNOWN_PATH);
7818
- }
7819
- else {
7820
- const variables = parameters[position];
7821
- if (variables) {
7822
- for (const variable of variables) {
7823
- variable.addArgumentValue(argument);
7824
- }
7825
- }
7826
- this.addArgumentToBeDeoptimized(argument);
7827
- }
7828
- }
7829
- const nonRestParameterLength = this.hasRest ? parameters.length - 1 : parameters.length;
7830
- for (; position < nonRestParameterLength; position++) {
7831
- for (const variable of parameters[position]) {
7832
- variable.addArgumentValue(UNDEFINED_EXPRESSION);
7833
- }
7834
- }
7835
- }
7836
7524
  getReturnExpression() {
7837
7525
  if (this.returnExpression === null)
7838
7526
  this.updateReturnExpression();
7839
7527
  return this.returnExpression;
7840
7528
  }
7841
- deoptimizeAllParameters() {
7842
- for (const parameter of this.parameters) {
7843
- for (const variable of parameter) {
7844
- variable.deoptimizePath(UNKNOWN_PATH);
7845
- variable.markReassigned();
7846
- }
7847
- }
7848
- }
7849
- reassignAllParameters() {
7850
- for (const parameter of this.parameters) {
7851
- for (const variable of parameter) {
7852
- variable.markReassigned();
7853
- }
7854
- }
7855
- }
7856
- addArgumentToBeDeoptimized(_argument) { }
7857
7529
  updateReturnExpression() {
7858
7530
  if (this.returnExpressions.length === 1) {
7859
7531
  this.returnExpression = this.returnExpressions[0];
@@ -7869,30 +7541,24 @@ class ReturnValueScope extends ParameterScope {
7869
7541
 
7870
7542
  class FunctionScope extends ReturnValueScope {
7871
7543
  constructor(parent) {
7872
- super(parent, false);
7873
7544
  const { context } = parent;
7545
+ super(parent, false);
7874
7546
  this.variables.set('arguments', (this.argumentsVariable = new ArgumentsVariable(context)));
7875
7547
  this.variables.set('this', (this.thisVariable = new ThisVariable(context)));
7876
7548
  }
7877
7549
  findLexicalBoundary() {
7878
7550
  return this;
7879
7551
  }
7880
- includeCallArguments(context, interaction) {
7881
- super.includeCallArguments(context, interaction);
7552
+ includeCallArguments(context, parameters) {
7553
+ super.includeCallArguments(context, parameters);
7882
7554
  if (this.argumentsVariable.included) {
7883
- const { args } = interaction;
7884
- for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
7885
- const argument = args[argumentIndex];
7886
- if (argument) {
7887
- argument.includePath(UNKNOWN_PATH, context);
7555
+ for (const argument of parameters) {
7556
+ if (!argument.included) {
7888
7557
  argument.include(context, false);
7889
7558
  }
7890
7559
  }
7891
7560
  }
7892
7561
  }
7893
- addArgumentToBeDeoptimized(argument) {
7894
- this.argumentsVariable.addArgumentToBeDeoptimized(argument);
7895
- }
7896
7562
  }
7897
7563
 
7898
7564
  class ExpressionStatement extends NodeBase {
@@ -7920,9 +7586,8 @@ class ExpressionStatement extends NodeBase {
7920
7586
  return this.parent.type !== parseAst_js.Program;
7921
7587
  return super.shouldBeIncluded(context);
7922
7588
  }
7589
+ applyDeoptimizations() { }
7923
7590
  }
7924
- ExpressionStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
7925
- ExpressionStatement.prototype.applyDeoptimizations = doNotDeoptimize;
7926
7591
 
7927
7592
  class BlockStatement extends NodeBase {
7928
7593
  get deoptimizeBody() {
@@ -7987,8 +7652,6 @@ class BlockStatement extends NodeBase {
7987
7652
  }
7988
7653
  }
7989
7654
  }
7990
- BlockStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
7991
- BlockStatement.prototype.applyDeoptimizations = doNotDeoptimize;
7992
7655
 
7993
7656
  class RestElement extends NodeBase {
7994
7657
  constructor() {
@@ -7998,12 +7661,9 @@ class RestElement extends NodeBase {
7998
7661
  addExportedVariables(variables, exportNamesByVariable) {
7999
7662
  this.argument.addExportedVariables(variables, exportNamesByVariable);
8000
7663
  }
8001
- declare(kind, destructuredInitPath, init) {
7664
+ declare(kind, init) {
8002
7665
  this.declarationInit = init;
8003
- return this.argument.declare(kind, getIncludedPatternPath$1(destructuredInitPath), init);
8004
- }
8005
- deoptimizeAssignment(destructuredInitPath, init) {
8006
- this.argument.deoptimizeAssignment(getIncludedPatternPath$1(destructuredInitPath), init);
7666
+ return this.argument.declare(kind, UNKNOWN_EXPRESSION);
8007
7667
  }
8008
7668
  deoptimizePath(path) {
8009
7669
  if (path.length === 0) {
@@ -8014,20 +7674,6 @@ class RestElement extends NodeBase {
8014
7674
  return (path.length > 0 ||
8015
7675
  this.argument.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
8016
7676
  }
8017
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
8018
- return this.argument.hasEffectsWhenDestructuring(context, getIncludedPatternPath$1(destructuredInitPath), init);
8019
- }
8020
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
8021
- return (this.included =
8022
- this.argument.includeDestructuredIfNecessary(context, getIncludedPatternPath$1(destructuredInitPath), init) || this.included);
8023
- }
8024
- include(context, includeChildrenRecursively) {
8025
- if (!this.included)
8026
- this.includeNode(context);
8027
- // This should just include the identifier, its properties should be
8028
- // included where the variable is used.
8029
- this.argument.include(context, includeChildrenRecursively);
8030
- }
8031
7677
  markDeclarationReached() {
8032
7678
  this.argument.markDeclarationReached();
8033
7679
  }
@@ -8039,16 +7685,12 @@ class RestElement extends NodeBase {
8039
7685
  }
8040
7686
  }
8041
7687
  }
8042
- RestElement.prototype.includeNode = onlyIncludeSelf;
8043
- const getIncludedPatternPath$1 = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
8044
- ? destructuredInitPath
8045
- : [...destructuredInitPath, UnknownKey];
8046
7688
 
8047
7689
  class FunctionBase extends NodeBase {
8048
7690
  constructor() {
8049
7691
  super(...arguments);
7692
+ this.objectEntity = null;
8050
7693
  this.parameterVariableValuesDeoptimized = false;
8051
- this.includeCallArguments = this.scope.includeCallArguments.bind(this.scope);
8052
7694
  }
8053
7695
  get async() {
8054
7696
  return isFlagSet(this.flags, 256 /* Flag.async */);
@@ -8068,15 +7710,53 @@ class FunctionBase extends NodeBase {
8068
7710
  set generator(value) {
8069
7711
  this.flags = setFlag(this.flags, 4194304 /* Flag.generator */, value);
8070
7712
  }
8071
- get hasCachedEffects() {
8072
- return isFlagSet(this.flags, 67108864 /* Flag.hasEffects */);
7713
+ updateParameterVariableValues(_arguments) {
7714
+ for (let position = 0; position < this.params.length; position++) {
7715
+ const parameter = this.params[position];
7716
+ if (!(parameter instanceof Identifier)) {
7717
+ continue;
7718
+ }
7719
+ const parameterVariable = parameter.variable;
7720
+ const argument = _arguments[position + 1] ?? UNDEFINED_EXPRESSION;
7721
+ parameterVariable.updateKnownValue(argument);
7722
+ }
8073
7723
  }
8074
- set hasCachedEffects(value) {
8075
- this.flags = setFlag(this.flags, 67108864 /* Flag.hasEffects */, value);
7724
+ deoptimizeParameterVariableValues() {
7725
+ for (const parameter of this.params) {
7726
+ if (parameter instanceof Identifier) {
7727
+ const parameterVariable = parameter.variable;
7728
+ parameterVariable.markReassigned();
7729
+ }
7730
+ }
8076
7731
  }
8077
7732
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
8078
- if (interaction.type === INTERACTION_CALLED && path.length === 0) {
8079
- this.scope.deoptimizeArgumentsOnCall(interaction);
7733
+ if (interaction.type === INTERACTION_CALLED) {
7734
+ const { parameters } = this.scope;
7735
+ const { args } = interaction;
7736
+ let hasRest = false;
7737
+ for (let position = 0; position < args.length - 1; position++) {
7738
+ const parameter = this.params[position];
7739
+ // Only the "this" argument arg[0] can be null
7740
+ const argument = args[position + 1];
7741
+ if (argument instanceof SpreadElement) {
7742
+ this.deoptimizeParameterVariableValues();
7743
+ }
7744
+ if (hasRest || parameter instanceof RestElement) {
7745
+ hasRest = true;
7746
+ argument.deoptimizePath(UNKNOWN_PATH);
7747
+ }
7748
+ else if (parameter instanceof Identifier) {
7749
+ parameters[position][0].addEntityToBeDeoptimized(argument);
7750
+ this.addArgumentToBeDeoptimized(argument);
7751
+ }
7752
+ else if (parameter) {
7753
+ argument.deoptimizePath(UNKNOWN_PATH);
7754
+ }
7755
+ else {
7756
+ this.addArgumentToBeDeoptimized(argument);
7757
+ }
7758
+ }
7759
+ this.updateParameterVariableValues(args);
8080
7760
  }
8081
7761
  else {
8082
7762
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -8088,7 +7768,12 @@ class FunctionBase extends NodeBase {
8088
7768
  // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
8089
7769
  // which means the return expression and parameters need to be reassigned
8090
7770
  this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
8091
- this.scope.deoptimizeAllParameters();
7771
+ for (const parameterList of this.scope.parameters) {
7772
+ for (const parameter of parameterList) {
7773
+ parameter.deoptimizePath(UNKNOWN_PATH);
7774
+ parameter.markReassigned();
7775
+ }
7776
+ }
8092
7777
  }
8093
7778
  }
8094
7779
  getLiteralValueAtPath(path, recursionTracker, origin) {
@@ -8112,8 +7797,8 @@ class FunctionBase extends NodeBase {
8112
7797
  if (path.length > 0 || interaction.type !== INTERACTION_CALLED) {
8113
7798
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
8114
7799
  }
8115
- if (this.hasCachedEffects) {
8116
- return true;
7800
+ if (this.annotationNoSideEffects) {
7801
+ return false;
8117
7802
  }
8118
7803
  if (this.async) {
8119
7804
  const { propertyReadSideEffects } = this.scope.context.options
@@ -8123,20 +7808,12 @@ class FunctionBase extends NodeBase {
8123
7808
  (propertyReadSideEffects &&
8124
7809
  (propertyReadSideEffects === 'always' ||
8125
7810
  returnExpression.hasEffectsOnInteractionAtPath(['then'], NODE_INTERACTION_UNKNOWN_ACCESS, context)))) {
8126
- this.hasCachedEffects = true;
8127
7811
  return true;
8128
7812
  }
8129
7813
  }
8130
- const { propertyReadSideEffects } = this.scope.context.options
8131
- .treeshake;
8132
- for (let index = 0; index < this.params.length; index++) {
8133
- const parameter = this.params[index];
8134
- if (parameter.hasEffects(context) ||
8135
- (propertyReadSideEffects &&
8136
- parameter.hasEffectsWhenDestructuring(context, EMPTY_PATH, interaction.args[index + 1] || UNDEFINED_EXPRESSION))) {
8137
- this.hasCachedEffects = true;
7814
+ for (const parameter of this.params) {
7815
+ if (parameter.hasEffects(context))
8138
7816
  return true;
8139
- }
8140
7817
  }
8141
7818
  return false;
8142
7819
  }
@@ -8154,17 +7831,21 @@ class FunctionBase extends NodeBase {
8154
7831
  return variable?.getOnlyFunctionCallUsed() ?? false;
8155
7832
  }
8156
7833
  include(context, includeChildrenRecursively) {
8157
- if (!this.included)
8158
- this.includeNode(context);
8159
- if (!(this.parameterVariableValuesDeoptimized || this.onlyFunctionCallUsed())) {
7834
+ if (!this.parameterVariableValuesDeoptimized && !this.onlyFunctionCallUsed()) {
8160
7835
  this.parameterVariableValuesDeoptimized = true;
8161
- this.scope.reassignAllParameters();
7836
+ this.deoptimizeParameterVariableValues();
8162
7837
  }
7838
+ if (!this.deoptimized)
7839
+ this.applyDeoptimizations();
7840
+ this.included = true;
8163
7841
  const { brokenFlow } = context;
8164
7842
  context.brokenFlow = false;
8165
7843
  this.body.include(context, includeChildrenRecursively);
8166
7844
  context.brokenFlow = brokenFlow;
8167
7845
  }
7846
+ includeCallArguments(context, parameters) {
7847
+ this.scope.includeCallArguments(context, parameters);
7848
+ }
8168
7849
  initialise() {
8169
7850
  super.initialise();
8170
7851
  if (this.body instanceof BlockStatement) {
@@ -8186,14 +7867,14 @@ class FunctionBase extends NodeBase {
8186
7867
  // so that the scope already knows all parameters and can detect conflicts
8187
7868
  // when parsing the body.
8188
7869
  const parameters = (this.params = params.map((parameter) => new (context.getNodeConstructor(parameter.type))(this, scope).parseNode(parameter)));
8189
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
7870
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
8190
7871
  this.body = new (context.getNodeConstructor(body.type))(this, bodyScope).parseNode(body);
8191
7872
  return super.parseNode(esTreeNode);
8192
7873
  }
7874
+ addArgumentToBeDeoptimized(_argument) { }
7875
+ applyDeoptimizations() { }
8193
7876
  }
8194
7877
  FunctionBase.prototype.preventChildBlockScope = true;
8195
- FunctionBase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
8196
- FunctionBase.prototype.applyDeoptimizations = doNotDeoptimize;
8197
7878
 
8198
7879
  class FunctionNode extends FunctionBase {
8199
7880
  constructor() {
@@ -8205,31 +7886,30 @@ class FunctionNode extends FunctionBase {
8205
7886
  this.constructedEntity = new ObjectEntity(Object.create(null), OBJECT_PROTOTYPE);
8206
7887
  // This makes sure that all deoptimizations of "this" are applied to the
8207
7888
  // constructed entity.
8208
- this.scope.thisVariable.addArgumentValue(this.constructedEntity);
7889
+ this.scope.thisVariable.addEntityToBeDeoptimized(this.constructedEntity);
8209
7890
  }
8210
7891
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
8211
7892
  super.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
8212
7893
  if (interaction.type === INTERACTION_CALLED && path.length === 0 && interaction.args[0]) {
8213
7894
  // args[0] is the "this" argument
8214
- this.scope.thisVariable.addArgumentValue(interaction.args[0]);
7895
+ this.scope.thisVariable.addEntityToBeDeoptimized(interaction.args[0]);
8215
7896
  }
8216
7897
  }
8217
7898
  hasEffects(context) {
7899
+ if (!this.deoptimized)
7900
+ this.applyDeoptimizations();
8218
7901
  if (this.annotationNoSideEffects) {
8219
7902
  return false;
8220
7903
  }
8221
7904
  return !!this.id?.hasEffects(context);
8222
7905
  }
8223
7906
  hasEffectsOnInteractionAtPath(path, interaction, context) {
8224
- if (this.annotationNoSideEffects &&
8225
- path.length === 0 &&
8226
- interaction.type === INTERACTION_CALLED) {
8227
- return false;
8228
- }
8229
- if (super.hasEffectsOnInteractionAtPath(path, interaction, context)) {
7907
+ if (super.hasEffectsOnInteractionAtPath(path, interaction, context))
8230
7908
  return true;
7909
+ if (this.annotationNoSideEffects) {
7910
+ return false;
8231
7911
  }
8232
- if (path.length === 0 && interaction.type === INTERACTION_CALLED) {
7912
+ if (interaction.type === INTERACTION_CALLED) {
8233
7913
  const thisInit = context.replacedVariableInits.get(this.scope.thisVariable);
8234
7914
  context.replacedVariableInits.set(this.scope.thisVariable, interaction.withNew ? this.constructedEntity : UNKNOWN_EXPRESSION);
8235
7915
  const { brokenFlow, ignore, replacedVariableInits } = context;
@@ -8240,10 +7920,8 @@ class FunctionNode extends FunctionBase {
8240
7920
  returnYield: true,
8241
7921
  this: interaction.withNew
8242
7922
  };
8243
- if (this.body.hasEffects(context)) {
8244
- this.hasCachedEffects = true;
7923
+ if (this.body.hasEffects(context))
8245
7924
  return true;
8246
- }
8247
7925
  context.brokenFlow = brokenFlow;
8248
7926
  if (thisInit) {
8249
7927
  replacedVariableInits.set(this.scope.thisVariable, thisInit);
@@ -8257,7 +7935,7 @@ class FunctionNode extends FunctionBase {
8257
7935
  }
8258
7936
  include(context, includeChildrenRecursively) {
8259
7937
  super.include(context, includeChildrenRecursively);
8260
- this.id?.include(context);
7938
+ this.id?.include();
8261
7939
  const hasArguments = this.scope.argumentsVariable.included;
8262
7940
  for (const parameter of this.params) {
8263
7941
  if (!(parameter instanceof Identifier) || hasArguments) {
@@ -8265,18 +7943,12 @@ class FunctionNode extends FunctionBase {
8265
7943
  }
8266
7944
  }
8267
7945
  }
8268
- includeNode(context) {
8269
- this.included = true;
8270
- const hasArguments = this.scope.argumentsVariable.included;
8271
- for (const parameter of this.params) {
8272
- if (!(parameter instanceof Identifier) || hasArguments) {
8273
- parameter.includePath(UNKNOWN_PATH, context);
8274
- }
8275
- }
8276
- }
8277
7946
  initialise() {
8278
7947
  super.initialise();
8279
- this.id?.declare('function', EMPTY_PATH, this);
7948
+ this.id?.declare('function', this);
7949
+ }
7950
+ addArgumentToBeDeoptimized(argument) {
7951
+ this.scope.argumentsVariable.addArgumentToBeDeoptimized(argument);
8280
7952
  }
8281
7953
  getObjectEntity() {
8282
7954
  if (this.objectEntity !== null) {
@@ -8326,16 +7998,11 @@ function getFunctionIdInsertPosition(code, start) {
8326
7998
  }
8327
7999
  class ExportDefaultDeclaration extends NodeBase {
8328
8000
  include(context, includeChildrenRecursively) {
8329
- this.included = true;
8330
- this.declaration.include(context, includeChildrenRecursively);
8001
+ super.include(context, includeChildrenRecursively);
8331
8002
  if (includeChildrenRecursively) {
8332
- this.scope.context.includeVariableInModule(this.variable, UNKNOWN_PATH, context);
8003
+ this.scope.context.includeVariableInModule(this.variable);
8333
8004
  }
8334
8005
  }
8335
- includePath(path, context) {
8336
- this.included = true;
8337
- this.declaration.includePath(path, context);
8338
- }
8339
8006
  initialise() {
8340
8007
  super.initialise();
8341
8008
  const declaration = this.declaration;
@@ -8380,6 +8047,7 @@ class ExportDefaultDeclaration extends NodeBase {
8380
8047
  }
8381
8048
  this.declaration.render(code, options);
8382
8049
  }
8050
+ applyDeoptimizations() { }
8383
8051
  renderNamedDeclaration(code, declarationStart, idInsertPosition, options) {
8384
8052
  const { exportNamesByVariable, format, snippets: { getPropertyAccess } } = options;
8385
8053
  const name = this.variable.getName(getPropertyAccess);
@@ -8410,8 +8078,6 @@ class ExportDefaultDeclaration extends NodeBase {
8410
8078
  }
8411
8079
  }
8412
8080
  ExportDefaultDeclaration.prototype.needsBoundaries = true;
8413
- ExportDefaultDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
8414
- ExportDefaultDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
8415
8081
 
8416
8082
  const needsEscapeRegEx = /[\n\r'\\\u2028\u2029]/;
8417
8083
  const quoteNewlineRegEx = /([\n\r'\u2028\u2029])/g;
@@ -8681,7 +8347,6 @@ class Literal extends NodeBase {
8681
8347
  }
8682
8348
  }
8683
8349
  }
8684
- Literal.prototype.includeNode = onlyIncludeSelf;
8685
8350
 
8686
8351
  function getChainElementLiteralValueAtPath(element, object, path, recursionTracker, origin) {
8687
8352
  if ('getLiteralValueAtPathAsChainElement' in object) {
@@ -8697,6 +8362,8 @@ function getChainElementLiteralValueAtPath(element, object, path, recursionTrack
8697
8362
  return element.getLiteralValueAtPath(path, recursionTracker, origin);
8698
8363
  }
8699
8364
 
8365
+ // To avoid infinite recursions
8366
+ const MAX_PATH_DEPTH = 7;
8700
8367
  function getResolvablePropertyKey(memberExpression) {
8701
8368
  return memberExpression.computed
8702
8369
  ? getResolvableComputedPropertyKey(memberExpression.property)
@@ -8795,27 +8462,18 @@ class MemberExpression extends NodeBase {
8795
8462
  }
8796
8463
  else if (!this.isUndefined) {
8797
8464
  if (path.length < MAX_PATH_DEPTH) {
8798
- this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, this.propertyKey === UnknownKey ? UNKNOWN_PATH : [this.propertyKey, ...path], recursionTracker);
8465
+ this.object.deoptimizeArgumentsOnInteractionAtPath(interaction, [this.getPropertyKey(), ...path], recursionTracker);
8799
8466
  }
8800
8467
  else {
8801
8468
  deoptimizeInteraction(interaction);
8802
8469
  }
8803
8470
  }
8804
8471
  }
8805
- deoptimizeAssignment(destructuredInitPath, init) {
8806
- this.deoptimizePath(EMPTY_PATH);
8807
- init.deoptimizePath([...destructuredInitPath, UnknownKey]);
8808
- }
8809
8472
  deoptimizeCache() {
8810
- if (this.propertyKey === this.dynamicPropertyKey)
8811
- return;
8812
8473
  const { expressionsToBeDeoptimized, object } = this;
8813
8474
  this.expressionsToBeDeoptimized = parseAst_js.EMPTY_ARRAY;
8814
- this.dynamicPropertyKey = this.propertyKey;
8475
+ this.propertyKey = UnknownKey;
8815
8476
  object.deoptimizePath(UNKNOWN_PATH);
8816
- if (this.included) {
8817
- object.includePath(UNKNOWN_PATH, createInclusionContext());
8818
- }
8819
8477
  for (const expression of expressionsToBeDeoptimized) {
8820
8478
  expression.deoptimizeCache();
8821
8479
  }
@@ -8826,13 +8484,11 @@ class MemberExpression extends NodeBase {
8826
8484
  if (this.variable) {
8827
8485
  this.variable.deoptimizePath(path);
8828
8486
  }
8829
- else if (!this.isUndefined) {
8830
- const { propertyKey } = this;
8487
+ else if (!this.isUndefined && path.length < MAX_PATH_DEPTH) {
8488
+ const propertyKey = this.getPropertyKey();
8831
8489
  this.object.deoptimizePath([
8832
8490
  propertyKey === UnknownKey ? UnknownNonAccessorKey : propertyKey,
8833
- ...(path.length < MAX_PATH_DEPTH
8834
- ? path
8835
- : [...path.slice(0, MAX_PATH_DEPTH), UnknownKey])
8491
+ ...path
8836
8492
  ]);
8837
8493
  }
8838
8494
  }
@@ -8843,11 +8499,9 @@ class MemberExpression extends NodeBase {
8843
8499
  if (this.isUndefined) {
8844
8500
  return undefined;
8845
8501
  }
8846
- const propertyKey = this.getDynamicPropertyKey();
8847
- if (propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
8848
- if (propertyKey !== this.propertyKey)
8849
- this.expressionsToBeDeoptimized.push(origin);
8850
- return this.object.getLiteralValueAtPath([propertyKey, ...path], recursionTracker, origin);
8502
+ if (this.propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
8503
+ this.expressionsToBeDeoptimized.push(origin);
8504
+ return this.object.getLiteralValueAtPath([this.getPropertyKey(), ...path], recursionTracker, origin);
8851
8505
  }
8852
8506
  return UnknownValue;
8853
8507
  }
@@ -8867,11 +8521,9 @@ class MemberExpression extends NodeBase {
8867
8521
  if (this.isUndefined) {
8868
8522
  return [UNDEFINED_EXPRESSION, false];
8869
8523
  }
8870
- const propertyKey = this.getDynamicPropertyKey();
8871
- if (propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
8872
- if (propertyKey !== this.propertyKey)
8873
- this.expressionsToBeDeoptimized.push(origin);
8874
- return this.object.getReturnExpressionWhenCalledAtPath([propertyKey, ...path], interaction, recursionTracker, origin);
8524
+ if (this.propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
8525
+ this.expressionsToBeDeoptimized.push(origin);
8526
+ return this.object.getReturnExpressionWhenCalledAtPath([this.getPropertyKey(), ...path], interaction, recursionTracker, origin);
8875
8527
  }
8876
8528
  return UNKNOWN_RETURN_EXPRESSION;
8877
8529
  }
@@ -8917,45 +8569,14 @@ class MemberExpression extends NodeBase {
8917
8569
  return true;
8918
8570
  }
8919
8571
  if (path.length < MAX_PATH_DEPTH) {
8920
- return this.object.hasEffectsOnInteractionAtPath([this.getDynamicPropertyKey(), ...path], interaction, context);
8572
+ return this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey(), ...path], interaction, context);
8921
8573
  }
8922
8574
  return true;
8923
8575
  }
8924
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
8925
- return (destructuredInitPath.length > 0 &&
8926
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, context));
8927
- }
8928
8576
  include(context, includeChildrenRecursively) {
8929
- if (!this.included)
8930
- this.includeNode(context);
8931
- this.object.include(context, includeChildrenRecursively);
8932
- this.property.include(context, includeChildrenRecursively);
8933
- }
8934
- includeNode(context) {
8935
- this.included = true;
8936
8577
  if (!this.deoptimized)
8937
8578
  this.applyDeoptimizations();
8938
- if (this.variable) {
8939
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
8940
- }
8941
- else if (!this.isUndefined) {
8942
- this.object.includePath([this.propertyKey], context);
8943
- }
8944
- }
8945
- includePath(path, context) {
8946
- if (!this.included)
8947
- this.includeNode(context);
8948
- if (this.variable) {
8949
- this.variable?.includePath(path, context);
8950
- }
8951
- else if (!this.isUndefined) {
8952
- this.object.includePath([
8953
- this.propertyKey,
8954
- ...(path.length < MAX_PATH_DEPTH
8955
- ? path
8956
- : [...path.slice(0, MAX_PATH_DEPTH), UnknownKey])
8957
- ], context);
8958
- }
8579
+ this.includeProperties(context, includeChildrenRecursively);
8959
8580
  }
8960
8581
  includeAsAssignmentTarget(context, includeChildrenRecursively, deoptimizeAccess) {
8961
8582
  if (!this.assignmentDeoptimized)
@@ -8964,34 +8585,20 @@ class MemberExpression extends NodeBase {
8964
8585
  this.include(context, includeChildrenRecursively);
8965
8586
  }
8966
8587
  else {
8967
- if (!this.included)
8968
- this.includeNode(context);
8969
- this.object.include(context, includeChildrenRecursively);
8970
- this.property.include(context, includeChildrenRecursively);
8588
+ this.includeProperties(context, includeChildrenRecursively);
8971
8589
  }
8972
8590
  }
8973
- includeCallArguments(context, interaction) {
8591
+ includeCallArguments(context, parameters) {
8974
8592
  if (this.variable) {
8975
- this.variable.includeCallArguments(context, interaction);
8593
+ this.variable.includeCallArguments(context, parameters);
8976
8594
  }
8977
8595
  else {
8978
- super.includeCallArguments(context, interaction);
8979
- }
8980
- }
8981
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
8982
- if ((this.included ||=
8983
- destructuredInitPath.length > 0 &&
8984
- !context.brokenFlow &&
8985
- init.hasEffectsOnInteractionAtPath(destructuredInitPath, NODE_INTERACTION_UNKNOWN_ACCESS, createHasEffectsContext()))) {
8986
- init.include(context, false);
8987
- return true;
8596
+ super.includeCallArguments(context, parameters);
8988
8597
  }
8989
- return false;
8990
8598
  }
8991
8599
  initialise() {
8992
8600
  super.initialise();
8993
- this.dynamicPropertyKey = getResolvablePropertyKey(this);
8994
- this.propertyKey = this.dynamicPropertyKey === null ? UnknownKey : this.dynamicPropertyKey;
8601
+ this.propertyKey = getResolvablePropertyKey(this);
8995
8602
  this.accessInteraction = { args: [this.object], type: INTERACTION_ACCESSED };
8996
8603
  }
8997
8604
  render(code, options, { renderedParentType, isCalleeOfRenderedParent, renderedSurroundingElement } = parseAst_js.BLANK) {
@@ -9028,7 +8635,8 @@ class MemberExpression extends NodeBase {
9028
8635
  this.bound &&
9029
8636
  propertyReadSideEffects &&
9030
8637
  !(this.variable || this.isUndefined)) {
9031
- this.object.deoptimizeArgumentsOnInteractionAtPath(this.accessInteraction, [this.propertyKey], SHARED_RECURSION_TRACKER);
8638
+ const propertyKey = this.getPropertyKey();
8639
+ this.object.deoptimizeArgumentsOnInteractionAtPath(this.accessInteraction, [propertyKey], SHARED_RECURSION_TRACKER);
9032
8640
  this.scope.context.requestTreeshakingPass();
9033
8641
  }
9034
8642
  if (this.variable) {
@@ -9045,7 +8653,7 @@ class MemberExpression extends NodeBase {
9045
8653
  this.bound &&
9046
8654
  propertyReadSideEffects &&
9047
8655
  !(this.variable || this.isUndefined)) {
9048
- this.object.deoptimizeArgumentsOnInteractionAtPath(this.assignmentInteraction, [this.propertyKey], SHARED_RECURSION_TRACKER);
8656
+ this.object.deoptimizeArgumentsOnInteractionAtPath(this.assignmentInteraction, [this.getPropertyKey()], SHARED_RECURSION_TRACKER);
9049
8657
  this.scope.context.requestTreeshakingPass();
9050
8658
  }
9051
8659
  }
@@ -9054,24 +8662,24 @@ class MemberExpression extends NodeBase {
9054
8662
  const variable = this.scope.findVariable(this.object.name);
9055
8663
  if (variable.isNamespace) {
9056
8664
  if (this.variable) {
9057
- this.scope.context.includeVariableInModule(this.variable, UNKNOWN_PATH, createInclusionContext());
8665
+ this.scope.context.includeVariableInModule(this.variable);
9058
8666
  }
9059
8667
  this.scope.context.log(parseAst_js.LOGLEVEL_WARN, parseAst_js.logIllegalImportReassignment(this.object.name, this.scope.context.module.id), this.start);
9060
8668
  }
9061
8669
  }
9062
8670
  }
9063
- getDynamicPropertyKey() {
9064
- if (this.dynamicPropertyKey === null) {
9065
- this.dynamicPropertyKey = this.propertyKey;
8671
+ getPropertyKey() {
8672
+ if (this.propertyKey === null) {
8673
+ this.propertyKey = UnknownKey;
9066
8674
  const value = this.property.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
9067
- return (this.dynamicPropertyKey =
8675
+ return (this.propertyKey =
9068
8676
  value === SymbolToStringTag
9069
8677
  ? value
9070
8678
  : typeof value === 'symbol'
9071
8679
  ? UnknownKey
9072
8680
  : String(value));
9073
8681
  }
9074
- return this.dynamicPropertyKey;
8682
+ return this.propertyKey;
9075
8683
  }
9076
8684
  hasAccessEffect(context) {
9077
8685
  const { propertyReadSideEffects } = this.scope.context.options
@@ -9079,7 +8687,17 @@ class MemberExpression extends NodeBase {
9079
8687
  return (!(this.variable || this.isUndefined) &&
9080
8688
  propertyReadSideEffects &&
9081
8689
  (propertyReadSideEffects === 'always' ||
9082
- this.object.hasEffectsOnInteractionAtPath([this.getDynamicPropertyKey()], this.accessInteraction, context)));
8690
+ this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey()], this.accessInteraction, context)));
8691
+ }
8692
+ includeProperties(context, includeChildrenRecursively) {
8693
+ if (!this.included) {
8694
+ this.included = true;
8695
+ if (this.variable) {
8696
+ this.scope.context.includeVariableInModule(this.variable);
8697
+ }
8698
+ }
8699
+ this.object.include(context, includeChildrenRecursively);
8700
+ this.property.include(context, includeChildrenRecursively);
9083
8701
  }
9084
8702
  }
9085
8703
  function resolveNamespaceVariables(baseVariable, path, astContext) {
@@ -9123,20 +8741,18 @@ class MetaProperty extends NodeBase {
9123
8741
  return path.length > 1 || type !== INTERACTION_ACCESSED;
9124
8742
  }
9125
8743
  include() {
9126
- if (!this.included)
9127
- this.includeNode();
9128
- }
9129
- includeNode() {
9130
- this.included = true;
9131
- if (this.meta.name === IMPORT) {
9132
- this.scope.context.addImportMeta(this);
9133
- const parent = this.parent;
9134
- const metaProperty = (this.metaProperty =
9135
- parent instanceof MemberExpression && typeof parent.propertyKey === 'string'
9136
- ? parent.propertyKey
9137
- : null);
9138
- if (metaProperty?.startsWith(FILE_PREFIX)) {
9139
- this.referenceId = metaProperty.slice(FILE_PREFIX.length);
8744
+ if (!this.included) {
8745
+ this.included = true;
8746
+ if (this.meta.name === IMPORT) {
8747
+ this.scope.context.addImportMeta(this);
8748
+ const parent = this.parent;
8749
+ const metaProperty = (this.metaProperty =
8750
+ parent instanceof MemberExpression && typeof parent.propertyKey === 'string'
8751
+ ? parent.propertyKey
8752
+ : null);
8753
+ if (metaProperty?.startsWith(FILE_PREFIX)) {
8754
+ this.referenceId = metaProperty.slice(FILE_PREFIX.length);
8755
+ }
9140
8756
  }
9141
8757
  }
9142
8758
  }
@@ -9243,7 +8859,7 @@ class UndefinedVariable extends Variable {
9243
8859
 
9244
8860
  class ExportDefaultVariable extends LocalVariable {
9245
8861
  constructor(name, exportDefaultDeclaration, context) {
9246
- super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, EMPTY_PATH, context, 'other');
8862
+ super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context, 'other');
9247
8863
  this.hasId = false;
9248
8864
  this.originalId = null;
9249
8865
  this.originalVariable = null;
@@ -9392,8 +9008,8 @@ class NamespaceVariable extends Variable {
9392
9008
  return (!memberVariable ||
9393
9009
  memberVariable.hasEffectsOnInteractionAtPath(path.slice(1), interaction, context));
9394
9010
  }
9395
- includePath(path, context) {
9396
- super.includePath(path, context);
9011
+ include() {
9012
+ super.include();
9397
9013
  this.context.includeAllExports();
9398
9014
  }
9399
9015
  prepare(accessedGlobalsByScope) {
@@ -9486,9 +9102,9 @@ class SyntheticNamedExportVariable extends Variable {
9486
9102
  getName(getPropertyAccess) {
9487
9103
  return `${this.syntheticNamespace.getName(getPropertyAccess)}${getPropertyAccess(this.name)}`;
9488
9104
  }
9489
- includePath(path, context) {
9490
- super.includePath(path, context);
9491
- this.context.includeVariableInModule(this.syntheticNamespace, path, context);
9105
+ include() {
9106
+ super.include();
9107
+ this.context.includeVariableInModule(this.syntheticNamespace);
9492
9108
  }
9493
9109
  setRenderNames(baseName, name) {
9494
9110
  super.setRenderNames(baseName, name);
@@ -12664,37 +12280,21 @@ class ArrayPattern extends NodeBase {
12664
12280
  element?.addExportedVariables(variables, exportNamesByVariable);
12665
12281
  }
12666
12282
  }
12667
- declare(kind, destructuredInitPath, init) {
12283
+ declare(kind) {
12668
12284
  const variables = [];
12669
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12670
12285
  for (const element of this.elements) {
12671
12286
  if (element !== null) {
12672
- variables.push(...element.declare(kind, includedPatternPath, init));
12287
+ variables.push(...element.declare(kind, UNKNOWN_EXPRESSION));
12673
12288
  }
12674
12289
  }
12675
12290
  return variables;
12676
12291
  }
12677
- deoptimizeAssignment(destructuredInitPath, init) {
12678
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12679
- for (const element of this.elements) {
12680
- element?.deoptimizeAssignment(includedPatternPath, init);
12681
- }
12682
- }
12683
12292
  // Patterns can only be deoptimized at the empty path at the moment
12684
12293
  deoptimizePath() {
12685
12294
  for (const element of this.elements) {
12686
12295
  element?.deoptimizePath(EMPTY_PATH);
12687
12296
  }
12688
12297
  }
12689
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
12690
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12691
- for (const element of this.elements) {
12692
- if (element?.hasEffectsWhenDestructuring(context, includedPatternPath, init)) {
12693
- return true;
12694
- }
12695
- }
12696
- return false;
12697
- }
12698
12298
  // Patterns are only checked at the empty path at the moment
12699
12299
  hasEffectsOnInteractionAtPath(_path, interaction, context) {
12700
12300
  for (const element of this.elements) {
@@ -12703,38 +12303,12 @@ class ArrayPattern extends NodeBase {
12703
12303
  }
12704
12304
  return false;
12705
12305
  }
12706
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
12707
- let included = false;
12708
- const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
12709
- for (const element of this.elements) {
12710
- if (element) {
12711
- element.included ||= included;
12712
- included =
12713
- element.includeDestructuredIfNecessary(context, includedPatternPath, init) || included;
12714
- }
12715
- }
12716
- if (included) {
12717
- // This is necessary so that if any pattern element is included, all are
12718
- // included for proper deconflicting
12719
- for (const element of this.elements) {
12720
- if (element && !element.included) {
12721
- element.included = true;
12722
- element.includeDestructuredIfNecessary(context, includedPatternPath, init);
12723
- }
12724
- }
12725
- }
12726
- return (this.included ||= included);
12727
- }
12728
12306
  markDeclarationReached() {
12729
12307
  for (const element of this.elements) {
12730
12308
  element?.markDeclarationReached();
12731
12309
  }
12732
12310
  }
12733
12311
  }
12734
- ArrayPattern.prototype.includeNode = onlyIncludeSelf;
12735
- const getIncludedPatternPath = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
12736
- ? destructuredInitPath
12737
- : [...destructuredInitPath, UnknownInteger];
12738
12312
 
12739
12313
  class ArrowFunctionExpression extends FunctionBase {
12740
12314
  constructor() {
@@ -12751,17 +12325,17 @@ class ArrowFunctionExpression extends FunctionBase {
12751
12325
  this.scope = new ReturnValueScope(parentScope, false);
12752
12326
  }
12753
12327
  hasEffects() {
12328
+ if (!this.deoptimized)
12329
+ this.applyDeoptimizations();
12754
12330
  return false;
12755
12331
  }
12756
12332
  hasEffectsOnInteractionAtPath(path, interaction, context) {
12757
- if (this.annotationNoSideEffects &&
12758
- path.length === 0 &&
12759
- interaction.type === INTERACTION_CALLED) {
12760
- return false;
12761
- }
12762
12333
  if (super.hasEffectsOnInteractionAtPath(path, interaction, context)) {
12763
12334
  return true;
12764
12335
  }
12336
+ if (this.annotationNoSideEffects) {
12337
+ return false;
12338
+ }
12765
12339
  if (interaction.type === INTERACTION_CALLED) {
12766
12340
  const { ignore, brokenFlow } = context;
12767
12341
  context.ignore = {
@@ -12791,15 +12365,6 @@ class ArrowFunctionExpression extends FunctionBase {
12791
12365
  }
12792
12366
  }
12793
12367
  }
12794
- includeNode(context) {
12795
- this.included = true;
12796
- this.body.includePath(UNKNOWN_PATH, context);
12797
- for (const parameter of this.params) {
12798
- if (!(parameter instanceof Identifier)) {
12799
- parameter.includePath(UNKNOWN_PATH, context);
12800
- }
12801
- }
12802
- }
12803
12368
  getObjectEntity() {
12804
12369
  if (this.objectEntity !== null) {
12805
12370
  return this.objectEntity;
@@ -12819,18 +12384,13 @@ class ObjectPattern extends NodeBase {
12819
12384
  }
12820
12385
  }
12821
12386
  }
12822
- declare(kind, destructuredInitPath, init) {
12387
+ declare(kind, init) {
12823
12388
  const variables = [];
12824
12389
  for (const property of this.properties) {
12825
- variables.push(...property.declare(kind, destructuredInitPath, init));
12390
+ variables.push(...property.declare(kind, init));
12826
12391
  }
12827
12392
  return variables;
12828
12393
  }
12829
- deoptimizeAssignment(destructuredInitPath, init) {
12830
- for (const property of this.properties) {
12831
- property.deoptimizeAssignment(destructuredInitPath, init);
12832
- }
12833
- }
12834
12394
  deoptimizePath(path) {
12835
12395
  if (path.length === 0) {
12836
12396
  for (const property of this.properties) {
@@ -12848,46 +12408,12 @@ class ObjectPattern extends NodeBase {
12848
12408
  }
12849
12409
  return false;
12850
12410
  }
12851
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
12852
- for (const property of this.properties) {
12853
- if (property.hasEffectsWhenDestructuring(context, destructuredInitPath, init))
12854
- return true;
12855
- }
12856
- return false;
12857
- }
12858
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
12859
- let included = false;
12860
- for (const property of this.properties) {
12861
- included =
12862
- property.includeDestructuredIfNecessary(context, destructuredInitPath, init) || included;
12863
- }
12864
- return (this.included ||= included);
12865
- }
12866
12411
  markDeclarationReached() {
12867
12412
  for (const property of this.properties) {
12868
12413
  property.markDeclarationReached();
12869
12414
  }
12870
12415
  }
12871
- render(code, options) {
12872
- if (this.properties.length > 0) {
12873
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
12874
- let lastSeparatorPos = null;
12875
- for (const { node, separator, start, end } of separatedNodes) {
12876
- if (!node.included) {
12877
- treeshakeNode(node, code, start, end);
12878
- continue;
12879
- }
12880
- lastSeparatorPos = separator;
12881
- node.render(code, options);
12882
- }
12883
- if (lastSeparatorPos) {
12884
- code.remove(lastSeparatorPos, this.end - 1);
12885
- }
12886
- }
12887
- }
12888
12416
  }
12889
- ObjectPattern.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
12890
- ObjectPattern.prototype.applyDeoptimizations = doNotDeoptimize;
12891
12417
 
12892
12418
  class AssignmentExpression extends NodeBase {
12893
12419
  hasEffects(context) {
@@ -12896,9 +12422,7 @@ class AssignmentExpression extends NodeBase {
12896
12422
  this.applyDeoptimizations();
12897
12423
  // MemberExpressions do not access the property before assignments if the
12898
12424
  // operator is '='.
12899
- return (right.hasEffects(context) ||
12900
- left.hasEffectsAsAssignmentTarget(context, operator !== '=') ||
12901
- this.left.hasEffectsWhenDestructuring?.(context, EMPTY_PATH, right));
12425
+ return (right.hasEffects(context) || left.hasEffectsAsAssignmentTarget(context, operator !== '='));
12902
12426
  }
12903
12427
  hasEffectsOnInteractionAtPath(path, interaction, context) {
12904
12428
  return this.right.hasEffectsOnInteractionAtPath(path, interaction, context);
@@ -12907,24 +12431,15 @@ class AssignmentExpression extends NodeBase {
12907
12431
  const { deoptimized, left, right, operator } = this;
12908
12432
  if (!deoptimized)
12909
12433
  this.applyDeoptimizations();
12910
- if (!this.included)
12911
- this.includeNode(context);
12912
- const hasEffectsContext = createHasEffectsContext();
12434
+ this.included = true;
12913
12435
  if (includeChildrenRecursively ||
12914
12436
  operator !== '=' ||
12915
12437
  left.included ||
12916
- left.hasEffectsAsAssignmentTarget(hasEffectsContext, false) ||
12917
- left.hasEffectsWhenDestructuring?.(hasEffectsContext, EMPTY_PATH, right)) {
12438
+ left.hasEffectsAsAssignmentTarget(createHasEffectsContext(), false)) {
12918
12439
  left.includeAsAssignmentTarget(context, includeChildrenRecursively, operator !== '=');
12919
12440
  }
12920
12441
  right.include(context, includeChildrenRecursively);
12921
12442
  }
12922
- includeNode(context) {
12923
- this.included = true;
12924
- if (!this.deoptimized)
12925
- this.applyDeoptimizations();
12926
- this.right.includePath(UNKNOWN_PATH, context);
12927
- }
12928
12443
  initialise() {
12929
12444
  super.initialise();
12930
12445
  if (this.left instanceof Identifier) {
@@ -12985,7 +12500,8 @@ class AssignmentExpression extends NodeBase {
12985
12500
  }
12986
12501
  applyDeoptimizations() {
12987
12502
  this.deoptimized = true;
12988
- this.left.deoptimizeAssignment(EMPTY_PATH, this.right);
12503
+ this.left.deoptimizePath(EMPTY_PATH);
12504
+ this.right.deoptimizePath(UNKNOWN_PATH);
12989
12505
  this.scope.context.requestTreeshakingPass();
12990
12506
  }
12991
12507
  }
@@ -12994,42 +12510,16 @@ class AssignmentPattern extends NodeBase {
12994
12510
  addExportedVariables(variables, exportNamesByVariable) {
12995
12511
  this.left.addExportedVariables(variables, exportNamesByVariable);
12996
12512
  }
12997
- declare(kind, destructuredInitPath, init) {
12998
- return this.left.declare(kind, destructuredInitPath, init);
12999
- }
13000
- deoptimizeAssignment(destructuredInitPath, init) {
13001
- this.left.deoptimizeAssignment(destructuredInitPath, init);
12513
+ declare(kind, init) {
12514
+ return this.left.declare(kind, init);
13002
12515
  }
13003
12516
  deoptimizePath(path) {
13004
12517
  if (path.length === 0) {
13005
12518
  this.left.deoptimizePath(path);
13006
- }
13007
- }
13008
- hasEffectsOnInteractionAtPath(path, interaction, context) {
13009
- return (path.length > 0 || this.left.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
13010
- }
13011
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
13012
- return this.left.hasEffectsWhenDestructuring(context, destructuredInitPath, init);
13013
- }
13014
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
13015
- let included = this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init) ||
13016
- this.included;
13017
- if ((included ||= this.right.shouldBeIncluded(context))) {
13018
- this.right.include(context, false);
13019
- if (!this.left.included) {
13020
- this.left.included = true;
13021
- // Unfortunately, we need to include the left side again now, so that
13022
- // any declared variables are properly included.
13023
- this.left.includeDestructuredIfNecessary(context, destructuredInitPath, init);
13024
- }
13025
- }
13026
- return (this.included = included);
13027
- }
13028
- includeNode(context) {
13029
- this.included = true;
13030
- if (!this.deoptimized)
13031
- this.applyDeoptimizations();
13032
- this.right.includePath(UNKNOWN_PATH, context);
12519
+ }
12520
+ }
12521
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
12522
+ return (path.length > 0 || this.left.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
13033
12523
  }
13034
12524
  markDeclarationReached() {
13035
12525
  this.left.markDeclarationReached();
@@ -13053,34 +12543,22 @@ class AwaitExpression extends NodeBase {
13053
12543
  return true;
13054
12544
  }
13055
12545
  include(context, includeChildrenRecursively) {
13056
- if (!this.included)
13057
- this.includeNode(context);
13058
- this.argument.include(context, includeChildrenRecursively);
13059
- }
13060
- includeNode(context) {
13061
- this.included = true;
13062
12546
  if (!this.deoptimized)
13063
12547
  this.applyDeoptimizations();
13064
- checkTopLevelAwait: if (!this.scope.context.usesTopLevelAwait) {
13065
- let parent = this.parent;
13066
- do {
13067
- if (parent instanceof FunctionNode || parent instanceof ArrowFunctionExpression)
13068
- break checkTopLevelAwait;
13069
- } while ((parent = parent.parent));
13070
- this.scope.context.usesTopLevelAwait = true;
12548
+ if (!this.included) {
12549
+ this.included = true;
12550
+ checkTopLevelAwait: if (!this.scope.context.usesTopLevelAwait) {
12551
+ let parent = this.parent;
12552
+ do {
12553
+ if (parent instanceof FunctionNode || parent instanceof ArrowFunctionExpression)
12554
+ break checkTopLevelAwait;
12555
+ } while ((parent = parent.parent));
12556
+ this.scope.context.usesTopLevelAwait = true;
12557
+ }
13071
12558
  }
13072
- // Thenables need to be included
13073
- this.argument.includePath(THEN_PATH, context);
13074
- }
13075
- includePath(path, context) {
13076
- if (!this.deoptimized)
13077
- this.applyDeoptimizations();
13078
- if (!this.included)
13079
- this.includeNode(context);
13080
- this.argument.includePath(path, context);
12559
+ this.argument.include(context, includeChildrenRecursively);
13081
12560
  }
13082
12561
  }
13083
- const THEN_PATH = ['then'];
13084
12562
 
13085
12563
  const binaryOperators = {
13086
12564
  '!=': (left, right) => left != right,
@@ -13136,12 +12614,6 @@ class BinaryExpression extends NodeBase {
13136
12614
  hasEffectsOnInteractionAtPath(path, { type }) {
13137
12615
  return type !== INTERACTION_ACCESSED || path.length > 1;
13138
12616
  }
13139
- includeNode(context) {
13140
- this.included = true;
13141
- if (this.operator === 'in') {
13142
- this.right.includePath(UNKNOWN_PATH, context);
13143
- }
13144
- }
13145
12617
  removeAnnotations(code) {
13146
12618
  this.left.removeAnnotations(code);
13147
12619
  }
@@ -13150,7 +12622,6 @@ class BinaryExpression extends NodeBase {
13150
12622
  this.right.render(code, options);
13151
12623
  }
13152
12624
  }
13153
- BinaryExpression.prototype.applyDeoptimizations = doNotDeoptimize;
13154
12625
 
13155
12626
  class BreakStatement extends NodeBase {
13156
12627
  hasEffects(context) {
@@ -13170,7 +12641,7 @@ class BreakStatement extends NodeBase {
13170
12641
  include(context) {
13171
12642
  this.included = true;
13172
12643
  if (this.label) {
13173
- this.label.include(context);
12644
+ this.label.include();
13174
12645
  context.includedLabels.add(this.label.name);
13175
12646
  }
13176
12647
  else {
@@ -13179,8 +12650,6 @@ class BreakStatement extends NodeBase {
13179
12650
  context.brokenFlow = true;
13180
12651
  }
13181
12652
  }
13182
- BreakStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13183
- BreakStatement.prototype.applyDeoptimizations = doNotDeoptimize;
13184
12653
 
13185
12654
  function renderCallArguments(code, options, node) {
13186
12655
  if (node.arguments.length > 0) {
@@ -13367,14 +12836,10 @@ class CallExpression extends CallExpressionBase {
13367
12836
  this.callee.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context)));
13368
12837
  }
13369
12838
  include(context, includeChildrenRecursively) {
13370
- if (!this.included)
13371
- this.includeNode(context);
12839
+ if (!this.deoptimized)
12840
+ this.applyDeoptimizations();
13372
12841
  if (includeChildrenRecursively) {
13373
- this.callee.include(context, true);
13374
- for (const argument of this.arguments) {
13375
- argument.includePath(UNKNOWN_PATH, context);
13376
- argument.include(context, true);
13377
- }
12842
+ super.include(context, includeChildrenRecursively);
13378
12843
  if (includeChildrenRecursively === INCLUDE_PARAMETERS &&
13379
12844
  this.callee instanceof Identifier &&
13380
12845
  this.callee.variable) {
@@ -13382,24 +12847,10 @@ class CallExpression extends CallExpressionBase {
13382
12847
  }
13383
12848
  }
13384
12849
  else {
13385
- // If the callee is a member expression and does not have a variable, its
13386
- // object will already be included via the first argument of the
13387
- // interaction in includeCallArguments. Including it again can lead to
13388
- // severe performance problems.
13389
- if (this.callee instanceof MemberExpression && !this.callee.variable) {
13390
- this.callee.property.include(context, false);
13391
- }
13392
- else {
13393
- this.callee.include(context, false);
13394
- }
13395
- this.callee.includeCallArguments(context, this.interaction);
12850
+ this.included = true;
12851
+ this.callee.include(context, false);
13396
12852
  }
13397
- }
13398
- includeNode(context) {
13399
- this.included = true;
13400
- if (!this.deoptimized)
13401
- this.applyDeoptimizations();
13402
- this.callee.includePath(UNKNOWN_PATH, context);
12853
+ this.callee.includeCallArguments(context, this.arguments);
13403
12854
  }
13404
12855
  initialise() {
13405
12856
  super.initialise();
@@ -13438,14 +12889,13 @@ class CatchClause extends NodeBase {
13438
12889
  this.type = type;
13439
12890
  if (param) {
13440
12891
  this.param = new (this.scope.context.getNodeConstructor(param.type))(this, this.scope).parseNode(param);
13441
- this.param.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
12892
+ this.param.declare('parameter', UNKNOWN_EXPRESSION);
13442
12893
  }
13443
12894
  this.body = new BlockStatement(this, this.scope.bodyScope).parseNode(body);
13444
12895
  return super.parseNode(esTreeNode);
13445
12896
  }
13446
12897
  }
13447
12898
  CatchClause.prototype.preventChildBlockScope = true;
13448
- CatchClause.prototype.includeNode = onlyIncludeSelf;
13449
12899
 
13450
12900
  class ChainExpression extends NodeBase {
13451
12901
  // deoptimizations are not relevant as we are not caching values
@@ -13457,22 +12907,17 @@ class ChainExpression extends NodeBase {
13457
12907
  hasEffects(context) {
13458
12908
  return this.expression.hasEffectsAsChainElement(context) === true;
13459
12909
  }
13460
- includePath(path, context) {
13461
- this.included = true;
13462
- this.expression.includePath(path, context);
13463
- }
13464
12910
  removeAnnotations(code) {
13465
12911
  this.expression.removeAnnotations(code);
13466
12912
  }
12913
+ applyDeoptimizations() { }
13467
12914
  }
13468
- ChainExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13469
- ChainExpression.prototype.applyDeoptimizations = doNotDeoptimize;
13470
12915
 
13471
12916
  class ClassBodyScope extends ChildScope {
13472
12917
  constructor(parent, classNode) {
13473
12918
  const { context } = parent;
13474
12919
  super(parent, context);
13475
- this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, EMPTY_PATH, context, 'other')));
12920
+ this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, context, 'other')));
13476
12921
  this.instanceScope = new ChildScope(this, context);
13477
12922
  this.instanceScope.variables.set('this', new ThisVariable(context));
13478
12923
  }
@@ -13487,7 +12932,7 @@ class ClassBody extends NodeBase {
13487
12932
  }
13488
12933
  include(context, includeChildrenRecursively) {
13489
12934
  this.included = true;
13490
- this.scope.context.includeVariableInModule(this.scope.thisVariable, UNKNOWN_PATH, context);
12935
+ this.scope.context.includeVariableInModule(this.scope.thisVariable);
13491
12936
  for (const definition of this.body) {
13492
12937
  definition.include(context, includeChildrenRecursively);
13493
12938
  }
@@ -13500,9 +12945,8 @@ class ClassBody extends NodeBase {
13500
12945
  }
13501
12946
  return super.parseNode(esTreeNode);
13502
12947
  }
12948
+ applyDeoptimizations() { }
13503
12949
  }
13504
- ClassBody.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13505
- ClassBody.prototype.applyDeoptimizations = doNotDeoptimize;
13506
12950
 
13507
12951
  class ClassExpression extends ClassNode {
13508
12952
  render(code, options, { renderedSurroundingElement } = parseAst_js.BLANK) {
@@ -13573,9 +13017,6 @@ class ConditionalExpression extends NodeBase {
13573
13017
  const unusedBranch = this.usedBranch === this.consequent ? this.alternate : this.consequent;
13574
13018
  this.usedBranch = null;
13575
13019
  unusedBranch.deoptimizePath(UNKNOWN_PATH);
13576
- if (this.included) {
13577
- unusedBranch.includePath(UNKNOWN_PATH, createInclusionContext());
13578
- }
13579
13020
  const { expressionsToBeDeoptimized } = this;
13580
13021
  this.expressionsToBeDeoptimized = parseAst_js.EMPTY_ARRAY;
13581
13022
  for (const expression of expressionsToBeDeoptimized) {
@@ -13633,7 +13074,7 @@ class ConditionalExpression extends NodeBase {
13633
13074
  include(context, includeChildrenRecursively) {
13634
13075
  this.included = true;
13635
13076
  const usedBranch = this.getUsedBranch();
13636
- if (usedBranch === null || includeChildrenRecursively || this.test.shouldBeIncluded(context)) {
13077
+ if (includeChildrenRecursively || this.test.shouldBeIncluded(context) || usedBranch === null) {
13637
13078
  this.test.include(context, includeChildrenRecursively);
13638
13079
  this.consequent.include(context, includeChildrenRecursively);
13639
13080
  this.alternate.include(context, includeChildrenRecursively);
@@ -13642,38 +13083,27 @@ class ConditionalExpression extends NodeBase {
13642
13083
  usedBranch.include(context, includeChildrenRecursively);
13643
13084
  }
13644
13085
  }
13645
- includePath(path, context) {
13646
- this.included = true;
13647
- const usedBranch = this.getUsedBranch();
13648
- if (usedBranch === null || this.test.shouldBeIncluded(context)) {
13649
- this.consequent.includePath(path, context);
13650
- this.alternate.includePath(path, context);
13651
- }
13652
- else {
13653
- usedBranch.includePath(path, context);
13654
- }
13655
- }
13656
- includeCallArguments(context, interaction) {
13086
+ includeCallArguments(context, parameters) {
13657
13087
  const usedBranch = this.getUsedBranch();
13658
13088
  if (usedBranch) {
13659
- usedBranch.includeCallArguments(context, interaction);
13089
+ usedBranch.includeCallArguments(context, parameters);
13660
13090
  }
13661
13091
  else {
13662
- this.consequent.includeCallArguments(context, interaction);
13663
- this.alternate.includeCallArguments(context, interaction);
13092
+ this.consequent.includeCallArguments(context, parameters);
13093
+ this.alternate.includeCallArguments(context, parameters);
13664
13094
  }
13665
13095
  }
13666
13096
  removeAnnotations(code) {
13667
13097
  this.test.removeAnnotations(code);
13668
13098
  }
13669
13099
  render(code, options, { isCalleeOfRenderedParent, preventASI, renderedParentType, renderedSurroundingElement } = parseAst_js.BLANK) {
13100
+ const usedBranch = this.getUsedBranch();
13670
13101
  if (this.test.included) {
13671
13102
  this.test.render(code, options, { renderedSurroundingElement });
13672
13103
  this.consequent.render(code, options);
13673
13104
  this.alternate.render(code, options);
13674
13105
  }
13675
13106
  else {
13676
- const usedBranch = this.getUsedBranch();
13677
13107
  const colonPos = findFirstOccurrenceOutsideComment(code.original, ':', this.consequent.end);
13678
13108
  const inclusionStart = findNonWhiteSpace(code.original, (this.consequent.included
13679
13109
  ? findFirstOccurrenceOutsideComment(code.original, '?', this.test.end)
@@ -13705,8 +13135,6 @@ class ConditionalExpression extends NodeBase {
13705
13135
  : (this.usedBranch = testValue ? this.consequent : this.alternate);
13706
13136
  }
13707
13137
  }
13708
- ConditionalExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13709
- ConditionalExpression.prototype.applyDeoptimizations = doNotDeoptimize;
13710
13138
 
13711
13139
  class ContinueStatement extends NodeBase {
13712
13140
  hasEffects(context) {
@@ -13726,7 +13154,7 @@ class ContinueStatement extends NodeBase {
13726
13154
  include(context) {
13727
13155
  this.included = true;
13728
13156
  if (this.label) {
13729
- this.label.include(context);
13157
+ this.label.include();
13730
13158
  context.includedLabels.add(this.label.name);
13731
13159
  }
13732
13160
  else {
@@ -13735,15 +13163,12 @@ class ContinueStatement extends NodeBase {
13735
13163
  context.brokenFlow = true;
13736
13164
  }
13737
13165
  }
13738
- ContinueStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13739
- ContinueStatement.prototype.applyDeoptimizations = doNotDeoptimize;
13740
13166
 
13741
13167
  class DebuggerStatement extends NodeBase {
13742
13168
  hasEffects() {
13743
13169
  return true;
13744
13170
  }
13745
13171
  }
13746
- DebuggerStatement.prototype.includeNode = onlyIncludeSelf;
13747
13172
 
13748
13173
  class Decorator extends NodeBase {
13749
13174
  hasEffects(context) {
@@ -13751,7 +13176,6 @@ class Decorator extends NodeBase {
13751
13176
  this.expression.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_CALL, context));
13752
13177
  }
13753
13178
  }
13754
- Decorator.prototype.includeNode = onlyIncludeSelf;
13755
13179
 
13756
13180
  function hasLoopBodyEffects(context, body) {
13757
13181
  const { brokenFlow, hasBreak, hasContinue, ignore } = context;
@@ -13791,15 +13215,12 @@ class DoWhileStatement extends NodeBase {
13791
13215
  includeLoopBody(context, this.body, includeChildrenRecursively);
13792
13216
  }
13793
13217
  }
13794
- DoWhileStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13795
- DoWhileStatement.prototype.applyDeoptimizations = doNotDeoptimize;
13796
13218
 
13797
13219
  class EmptyStatement extends NodeBase {
13798
13220
  hasEffects() {
13799
13221
  return false;
13800
13222
  }
13801
13223
  }
13802
- EmptyStatement.prototype.includeNode = onlyIncludeSelf;
13803
13224
 
13804
13225
  class ExportAllDeclaration extends NodeBase {
13805
13226
  hasEffects() {
@@ -13812,10 +13233,9 @@ class ExportAllDeclaration extends NodeBase {
13812
13233
  render(code, _options, nodeRenderOptions) {
13813
13234
  code.remove(nodeRenderOptions.start, nodeRenderOptions.end);
13814
13235
  }
13236
+ applyDeoptimizations() { }
13815
13237
  }
13816
13238
  ExportAllDeclaration.prototype.needsBoundaries = true;
13817
- ExportAllDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13818
- ExportAllDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
13819
13239
 
13820
13240
  class ExportNamedDeclaration extends NodeBase {
13821
13241
  bind() {
@@ -13842,15 +13262,13 @@ class ExportNamedDeclaration extends NodeBase {
13842
13262
  this.declaration.render(code, options, { end, start });
13843
13263
  }
13844
13264
  }
13265
+ applyDeoptimizations() { }
13845
13266
  }
13846
13267
  ExportNamedDeclaration.prototype.needsBoundaries = true;
13847
- ExportNamedDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13848
- ExportNamedDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
13849
13268
 
13850
13269
  class ExportSpecifier extends NodeBase {
13270
+ applyDeoptimizations() { }
13851
13271
  }
13852
- ExportSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13853
- ExportSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
13854
13272
 
13855
13273
  class ForInStatement extends NodeBase {
13856
13274
  createScope(parentScope) {
@@ -13868,18 +13286,11 @@ class ForInStatement extends NodeBase {
13868
13286
  const { body, deoptimized, left, right } = this;
13869
13287
  if (!deoptimized)
13870
13288
  this.applyDeoptimizations();
13871
- if (!this.included)
13872
- this.includeNode(context);
13289
+ this.included = true;
13873
13290
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
13874
13291
  right.include(context, includeChildrenRecursively);
13875
13292
  includeLoopBody(context, body, includeChildrenRecursively);
13876
13293
  }
13877
- includeNode(context) {
13878
- this.included = true;
13879
- if (!this.deoptimized)
13880
- this.applyDeoptimizations();
13881
- this.right.includePath(UNKNOWN_PATH, context);
13882
- }
13883
13294
  initialise() {
13884
13295
  super.initialise();
13885
13296
  this.left.setAssignedValue(UNKNOWN_EXPRESSION);
@@ -13920,18 +13331,11 @@ class ForOfStatement extends NodeBase {
13920
13331
  const { body, deoptimized, left, right } = this;
13921
13332
  if (!deoptimized)
13922
13333
  this.applyDeoptimizations();
13923
- if (!this.included)
13924
- this.includeNode(context);
13334
+ this.included = true;
13925
13335
  left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
13926
13336
  right.include(context, includeChildrenRecursively);
13927
13337
  includeLoopBody(context, body, includeChildrenRecursively);
13928
13338
  }
13929
- includeNode(context) {
13930
- this.included = true;
13931
- if (!this.deoptimized)
13932
- this.applyDeoptimizations();
13933
- this.right.includePath(UNKNOWN_PATH, context);
13934
- }
13935
13339
  initialise() {
13936
13340
  super.initialise();
13937
13341
  this.left.setAssignedValue(UNKNOWN_EXPRESSION);
@@ -13967,9 +13371,7 @@ class ForStatement extends NodeBase {
13967
13371
  }
13968
13372
  include(context, includeChildrenRecursively) {
13969
13373
  this.included = true;
13970
- this.init?.include(context, includeChildrenRecursively, {
13971
- asSingleStatement: true
13972
- });
13374
+ this.init?.include(context, includeChildrenRecursively, { asSingleStatement: true });
13973
13375
  this.test?.include(context, includeChildrenRecursively);
13974
13376
  this.update?.include(context, includeChildrenRecursively);
13975
13377
  includeLoopBody(context, this.body, includeChildrenRecursively);
@@ -13981,8 +13383,6 @@ class ForStatement extends NodeBase {
13981
13383
  this.body.render(code, options);
13982
13384
  }
13983
13385
  }
13984
- ForStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13985
- ForStatement.prototype.applyDeoptimizations = doNotDeoptimize;
13986
13386
 
13987
13387
  class FunctionExpression extends FunctionNode {
13988
13388
  createScope(parentScope) {
@@ -14014,9 +13414,9 @@ class TrackingScope extends BlockScope {
14014
13414
  super(...arguments);
14015
13415
  this.hoistedDeclarations = [];
14016
13416
  }
14017
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
13417
+ addDeclaration(identifier, context, init, kind) {
14018
13418
  this.hoistedDeclarations.push(identifier);
14019
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
13419
+ return super.addDeclaration(identifier, context, init, kind);
14020
13420
  }
14021
13421
  }
14022
13422
 
@@ -14115,6 +13515,7 @@ class IfStatement extends NodeBase {
14115
13515
  }
14116
13516
  this.renderHoistedDeclarations(hoistedDeclarations, code, getPropertyAccess);
14117
13517
  }
13518
+ applyDeoptimizations() { }
14118
13519
  getTestValue() {
14119
13520
  if (this.testValue === unset) {
14120
13521
  return (this.testValue = tryCastLiteralValueToBoolean(this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this)));
@@ -14183,8 +13584,6 @@ class IfStatement extends NodeBase {
14183
13584
  return false;
14184
13585
  }
14185
13586
  }
14186
- IfStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14187
- IfStatement.prototype.applyDeoptimizations = doNotDeoptimize;
14188
13587
 
14189
13588
  class ImportAttribute extends NodeBase {
14190
13589
  }
@@ -14202,15 +13601,13 @@ class ImportDeclaration extends NodeBase {
14202
13601
  render(code, _options, nodeRenderOptions) {
14203
13602
  code.remove(nodeRenderOptions.start, nodeRenderOptions.end);
14204
13603
  }
13604
+ applyDeoptimizations() { }
14205
13605
  }
14206
13606
  ImportDeclaration.prototype.needsBoundaries = true;
14207
- ImportDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14208
- ImportDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
14209
13607
 
14210
13608
  class ImportDefaultSpecifier extends NodeBase {
13609
+ applyDeoptimizations() { }
14211
13610
  }
14212
- ImportDefaultSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14213
- ImportDefaultSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
14214
13611
 
14215
13612
  function isReassignedExportsMember(variable, exportNamesByVariable) {
14216
13613
  return (variable.renderBaseName !== null && exportNamesByVariable.has(variable) && variable.isReassigned);
@@ -14219,33 +13616,28 @@ function isReassignedExportsMember(variable, exportNamesByVariable) {
14219
13616
  class VariableDeclarator extends NodeBase {
14220
13617
  declareDeclarator(kind, isUsingDeclaration) {
14221
13618
  this.isUsingDeclaration = isUsingDeclaration;
14222
- this.id.declare(kind, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION);
13619
+ this.id.declare(kind, this.init || UNDEFINED_EXPRESSION);
14223
13620
  }
14224
13621
  deoptimizePath(path) {
14225
13622
  this.id.deoptimizePath(path);
14226
13623
  }
14227
13624
  hasEffects(context) {
13625
+ if (!this.deoptimized)
13626
+ this.applyDeoptimizations();
14228
13627
  const initEffect = this.init?.hasEffects(context);
14229
13628
  this.id.markDeclarationReached();
14230
- return (initEffect ||
14231
- this.isUsingDeclaration ||
14232
- this.id.hasEffects(context) ||
14233
- (this.scope.context.options.treeshake
14234
- .propertyReadSideEffects &&
14235
- this.id.hasEffectsWhenDestructuring(context, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION)));
13629
+ return initEffect || this.id.hasEffects(context) || this.isUsingDeclaration;
14236
13630
  }
14237
13631
  include(context, includeChildrenRecursively) {
14238
- const { id, init } = this;
14239
- if (!this.included)
14240
- this.includeNode();
13632
+ const { deoptimized, id, init } = this;
13633
+ if (!deoptimized)
13634
+ this.applyDeoptimizations();
13635
+ this.included = true;
14241
13636
  init?.include(context, includeChildrenRecursively);
14242
13637
  id.markDeclarationReached();
14243
- if (includeChildrenRecursively) {
13638
+ if (includeChildrenRecursively || id.shouldBeIncluded(context)) {
14244
13639
  id.include(context, includeChildrenRecursively);
14245
13640
  }
14246
- else {
14247
- id.includeDestructuredIfNecessary(context, EMPTY_PATH, init || UNDEFINED_EXPRESSION);
14248
- }
14249
13641
  }
14250
13642
  removeAnnotations(code) {
14251
13643
  this.init?.removeAnnotations(code);
@@ -14275,8 +13667,8 @@ class VariableDeclarator extends NodeBase {
14275
13667
  code.appendLeft(end, `${_}=${_}void 0`);
14276
13668
  }
14277
13669
  }
14278
- includeNode() {
14279
- this.included = true;
13670
+ applyDeoptimizations() {
13671
+ this.deoptimized = true;
14280
13672
  const { id, init } = this;
14281
13673
  if (init && id instanceof Identifier && init instanceof ClassExpression && !init.id) {
14282
13674
  const { name, variable } = id;
@@ -14288,14 +13680,11 @@ class VariableDeclarator extends NodeBase {
14288
13680
  }
14289
13681
  }
14290
13682
  }
14291
- VariableDeclarator.prototype.applyDeoptimizations = doNotDeoptimize;
14292
13683
 
14293
13684
  class ImportExpression extends NodeBase {
14294
13685
  constructor() {
14295
13686
  super(...arguments);
14296
13687
  this.inlineNamespace = null;
14297
- this.hasUnknownAccessedKey = false;
14298
- this.accessedPropKey = new Set();
14299
13688
  this.attributes = null;
14300
13689
  this.mechanism = null;
14301
13690
  this.namespaceExportName = undefined;
@@ -14328,15 +13717,12 @@ class ImportExpression extends NodeBase {
14328
13717
  if (parent2 instanceof ExpressionStatement) {
14329
13718
  return parseAst_js.EMPTY_ARRAY;
14330
13719
  }
14331
- // Case 1: const { foo } / module = await import('bar')
13720
+ // Case 1: const { foo } = await import('bar')
14332
13721
  if (parent2 instanceof VariableDeclarator) {
14333
13722
  const declaration = parent2.id;
14334
- if (declaration instanceof Identifier) {
14335
- return this.hasUnknownAccessedKey ? undefined : [...this.accessedPropKey];
14336
- }
14337
- if (declaration instanceof ObjectPattern) {
14338
- return getDeterministicObjectDestructure(declaration);
14339
- }
13723
+ return declaration instanceof ObjectPattern
13724
+ ? getDeterministicObjectDestructure(declaration)
13725
+ : undefined;
14340
13726
  }
14341
13727
  // Case 2: (await import('bar')).foo
14342
13728
  if (parent2 instanceof MemberExpression) {
@@ -14386,29 +13772,12 @@ class ImportExpression extends NodeBase {
14386
13772
  return true;
14387
13773
  }
14388
13774
  include(context, includeChildrenRecursively) {
14389
- if (!this.included)
14390
- this.includeNode();
14391
- this.source.include(context, includeChildrenRecursively);
14392
- }
14393
- includeNode() {
14394
- this.included = true;
14395
- this.scope.context.includeDynamicImport(this);
14396
- this.scope.addAccessedDynamicImport(this);
14397
- }
14398
- includePath(path) {
14399
- if (!this.included)
14400
- this.includeNode();
14401
- // Technically, this is not correct as dynamic imports return a Promise.
14402
- if (this.hasUnknownAccessedKey)
14403
- return;
14404
- if (path[0] === UnknownKey) {
14405
- this.hasUnknownAccessedKey = true;
14406
- }
14407
- else if (typeof path[0] === 'string') {
14408
- this.accessedPropKey.add(path[0]);
13775
+ if (!this.included) {
13776
+ this.included = true;
13777
+ this.scope.context.includeDynamicImport(this);
13778
+ this.scope.addAccessedDynamicImport(this);
14409
13779
  }
14410
- // Update included paths
14411
- this.scope.context.includeDynamicImport(this);
13780
+ this.source.include(context, includeChildrenRecursively);
14412
13781
  }
14413
13782
  initialise() {
14414
13783
  super.initialise();
@@ -14419,7 +13788,7 @@ class ImportExpression extends NodeBase {
14419
13788
  return super.parseNode(esTreeNode);
14420
13789
  }
14421
13790
  render(code, options) {
14422
- const { snippets: { _, getDirectReturnFunction, getObject, getPropertyAccess } } = options;
13791
+ const { snippets: { _, getDirectReturnFunction, getObject, getPropertyAccess }, importAttributesKey } = options;
14423
13792
  if (this.inlineNamespace) {
14424
13793
  const [left, right] = getDirectReturnFunction([], {
14425
13794
  functionReturn: true,
@@ -14452,7 +13821,7 @@ class ImportExpression extends NodeBase {
14452
13821
  code.overwrite(this.source.end, this.end - 1, '', { contentOnly: true });
14453
13822
  }
14454
13823
  if (this.attributes) {
14455
- code.appendLeft(this.end - 1, `,${_}${getObject([['assert', this.attributes]], {
13824
+ code.appendLeft(this.end - 1, `,${_}${getObject([[importAttributesKey, this.attributes]], {
14456
13825
  lineBreakIndent: null
14457
13826
  })}`);
14458
13827
  }
@@ -14478,6 +13847,7 @@ class ImportExpression extends NodeBase {
14478
13847
  setInternalResolution(inlineNamespace) {
14479
13848
  this.inlineNamespace = inlineNamespace;
14480
13849
  }
13850
+ applyDeoptimizations() { }
14481
13851
  getDynamicImportMechanismAndHelper(resolution, exportMode, { compact, dynamicImportInCjs, format, generatedCode: { arrowFunctions }, interop }, { _, getDirectReturnFunction, getDirectReturnIifeLeft }, pluginDriver) {
14482
13852
  const mechanism = pluginDriver.hookFirstSync('renderDynamicImport', [
14483
13853
  {
@@ -14567,7 +13937,6 @@ class ImportExpression extends NodeBase {
14567
13937
  return { helper: null, mechanism: null };
14568
13938
  }
14569
13939
  }
14570
- ImportExpression.prototype.applyDeoptimizations = doNotDeoptimize;
14571
13940
  function getInteropHelper(resolution, exportMode, interop) {
14572
13941
  return exportMode === 'external'
14573
13942
  ? namespaceInteropHelpersByInteropType[interop(resolution instanceof ExternalModule ? resolution.id : null)]
@@ -14591,14 +13960,12 @@ function getDeterministicObjectDestructure(objectPattern) {
14591
13960
  }
14592
13961
 
14593
13962
  class ImportNamespaceSpecifier extends NodeBase {
13963
+ applyDeoptimizations() { }
14594
13964
  }
14595
- ImportNamespaceSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14596
- ImportNamespaceSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
14597
13965
 
14598
13966
  class ImportSpecifier extends NodeBase {
13967
+ applyDeoptimizations() { }
14599
13968
  }
14600
- ImportSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14601
- ImportSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
14602
13969
 
14603
13970
  class JSXIdentifier extends IdentifierBase {
14604
13971
  constructor() {
@@ -14615,29 +13982,6 @@ class JSXIdentifier extends IdentifierBase {
14615
13982
  this.isNativeElement = true;
14616
13983
  }
14617
13984
  }
14618
- include(context) {
14619
- if (!this.included)
14620
- this.includeNode(context);
14621
- }
14622
- includeNode(context) {
14623
- this.included = true;
14624
- if (!this.deoptimized)
14625
- this.applyDeoptimizations();
14626
- if (this.variable !== null) {
14627
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
14628
- }
14629
- }
14630
- includePath(path, context) {
14631
- if (!this.included) {
14632
- this.included = true;
14633
- if (this.variable !== null) {
14634
- this.scope.context.includeVariableInModule(this.variable, path, context);
14635
- }
14636
- }
14637
- else if (path.length > 0) {
14638
- this.variable?.includePath(path, context);
14639
- }
14640
- }
14641
13985
  render(code, { snippets: { getPropertyAccess }, useOriginalName }) {
14642
13986
  if (this.variable) {
14643
13987
  const name = this.variable.getName(getPropertyAccess, useOriginalName);
@@ -14699,7 +14043,6 @@ class JSXAttribute extends NodeBase {
14699
14043
  }
14700
14044
  }
14701
14045
  }
14702
- JSXAttribute.prototype.includeNode = onlyIncludeSelf;
14703
14046
 
14704
14047
  class JSXClosingBase extends NodeBase {
14705
14048
  render(code, options) {
@@ -14712,7 +14055,6 @@ class JSXClosingBase extends NodeBase {
14712
14055
  }
14713
14056
  }
14714
14057
  }
14715
- JSXClosingBase.prototype.includeNode = onlyIncludeSelf;
14716
14058
 
14717
14059
  class JSXClosingElement extends JSXClosingBase {
14718
14060
  }
@@ -14733,15 +14075,8 @@ class JSXSpreadAttribute extends NodeBase {
14733
14075
 
14734
14076
  class JSXEmptyExpression extends NodeBase {
14735
14077
  }
14736
- JSXEmptyExpression.prototype.includeNode = onlyIncludeSelf;
14737
14078
 
14738
14079
  class JSXExpressionContainer extends NodeBase {
14739
- includeNode(context) {
14740
- this.included = true;
14741
- if (!this.deoptimized)
14742
- this.applyDeoptimizations();
14743
- this.expression.includePath(UNKNOWN_PATH, context);
14744
- }
14745
14080
  render(code, options) {
14746
14081
  const { mode } = this.scope.context.options.jsx;
14747
14082
  if (mode !== 'preserve') {
@@ -14762,7 +14097,7 @@ function getRenderedJsxChildren(children) {
14762
14097
  return renderedChildren;
14763
14098
  }
14764
14099
 
14765
- function getAndIncludeFactoryVariable(factory, preserve, importSource, node, context) {
14100
+ function getAndIncludeFactoryVariable(factory, preserve, importSource, node) {
14766
14101
  const [baseName, nestedName] = factory.split('.');
14767
14102
  let factoryVariable;
14768
14103
  if (importSource) {
@@ -14770,7 +14105,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node, con
14770
14105
  if (preserve) {
14771
14106
  // This pretends we are accessing an included global variable of the same name
14772
14107
  const globalVariable = node.scope.findGlobal(baseName);
14773
- globalVariable.includePath(UNKNOWN_PATH, context);
14108
+ globalVariable.include();
14774
14109
  // This excludes this variable from renaming
14775
14110
  factoryVariable.globalName = baseName;
14776
14111
  }
@@ -14778,7 +14113,7 @@ function getAndIncludeFactoryVariable(factory, preserve, importSource, node, con
14778
14113
  else {
14779
14114
  factoryVariable = node.scope.findGlobal(baseName);
14780
14115
  }
14781
- node.scope.context.includeVariableInModule(factoryVariable, UNKNOWN_PATH, context);
14116
+ node.scope.context.includeVariableInModule(factoryVariable);
14782
14117
  if (factoryVariable instanceof LocalVariable) {
14783
14118
  factoryVariable.consolidateInitializers();
14784
14119
  factoryVariable.addUsedPlace(node);
@@ -14801,20 +14136,16 @@ class JSXElementBase extends NodeBase {
14801
14136
  }
14802
14137
  }
14803
14138
  include(context, includeChildrenRecursively) {
14804
- if (!this.included)
14805
- this.includeNode(context);
14806
- for (const child of this.children) {
14807
- child.include(context, includeChildrenRecursively);
14808
- }
14809
- }
14810
- includeNode(context) {
14811
- this.included = true;
14812
- const { factory, importSource, mode } = this.jsxMode;
14813
- if (factory) {
14814
- this.factory = factory;
14815
- this.factoryVariable = getAndIncludeFactoryVariable(factory, mode === 'preserve', importSource, this, context);
14139
+ if (!this.included) {
14140
+ const { factory, importSource, mode } = this.jsxMode;
14141
+ if (factory) {
14142
+ this.factory = factory;
14143
+ this.factoryVariable = getAndIncludeFactoryVariable(factory, mode === 'preserve', importSource, this);
14144
+ }
14816
14145
  }
14146
+ super.include(context, includeChildrenRecursively);
14817
14147
  }
14148
+ applyDeoptimizations() { }
14818
14149
  getRenderingMode() {
14819
14150
  const jsx = this.scope.context.options.jsx;
14820
14151
  const { mode, factory, importSource } = jsx;
@@ -14852,14 +14183,8 @@ class JSXElementBase extends NodeBase {
14852
14183
  return { childrenEnd, firstChild, hasMultipleChildren };
14853
14184
  }
14854
14185
  }
14855
- JSXElementBase.prototype.applyDeoptimizations = doNotDeoptimize;
14856
14186
 
14857
14187
  class JSXElement extends JSXElementBase {
14858
- include(context, includeChildrenRecursively) {
14859
- super.include(context, includeChildrenRecursively);
14860
- this.openingElement.include(context, includeChildrenRecursively);
14861
- this.closingElement?.include(context, includeChildrenRecursively);
14862
- }
14863
14188
  render(code, options) {
14864
14189
  switch (this.jsxMode.mode) {
14865
14190
  case 'classic': {
@@ -15011,11 +14336,6 @@ class JSXElement extends JSXElementBase {
15011
14336
  }
15012
14337
 
15013
14338
  class JSXFragment extends JSXElementBase {
15014
- include(context, includeChildrenRecursively) {
15015
- super.include(context, includeChildrenRecursively);
15016
- this.openingFragment.include(context, includeChildrenRecursively);
15017
- this.closingFragment.include(context, includeChildrenRecursively);
15018
- }
15019
14339
  render(code, options) {
15020
14340
  switch (this.jsxMode.mode) {
15021
14341
  case 'classic': {
@@ -15065,22 +14385,10 @@ class JSXFragment extends JSXElementBase {
15065
14385
  }
15066
14386
 
15067
14387
  class JSXMemberExpression extends NodeBase {
15068
- includeNode(context) {
15069
- this.included = true;
15070
- if (!this.deoptimized)
15071
- this.applyDeoptimizations();
15072
- this.object.includePath([this.property.name], context);
15073
- }
15074
- includePath(path, context) {
15075
- if (!this.included)
15076
- this.includeNode(context);
15077
- this.object.includePath([this.property.name, ...path], context);
15078
- }
15079
14388
  }
15080
14389
 
15081
14390
  class JSXNamespacedName extends NodeBase {
15082
14391
  }
15083
- JSXNamespacedName.prototype.includeNode = onlyIncludeSelf;
15084
14392
 
15085
14393
  class JSXOpeningElement extends NodeBase {
15086
14394
  render(code, options, { jsxMode = this.scope.context.options.jsx.mode } = {}) {
@@ -15090,7 +14398,6 @@ class JSXOpeningElement extends NodeBase {
15090
14398
  }
15091
14399
  }
15092
14400
  }
15093
- JSXOpeningElement.prototype.includeNode = onlyIncludeSelf;
15094
14401
 
15095
14402
  class JSXOpeningFragment extends NodeBase {
15096
14403
  constructor() {
@@ -15098,22 +14405,22 @@ class JSXOpeningFragment extends NodeBase {
15098
14405
  this.fragment = null;
15099
14406
  this.fragmentVariable = null;
15100
14407
  }
15101
- includeNode(context) {
15102
- this.included = true;
15103
- if (!this.deoptimized)
15104
- this.applyDeoptimizations();
15105
- const jsx = this.scope.context.options.jsx;
15106
- if (jsx.mode === 'automatic') {
15107
- this.fragment = 'Fragment';
15108
- this.fragmentVariable = getAndIncludeFactoryVariable('Fragment', false, jsx.jsxImportSource, this, context);
15109
- }
15110
- else {
15111
- const { fragment, importSource, mode } = jsx;
15112
- if (fragment != null) {
15113
- this.fragment = fragment;
15114
- this.fragmentVariable = getAndIncludeFactoryVariable(fragment, mode === 'preserve', importSource, this, context);
14408
+ include(context, includeChildrenRecursively) {
14409
+ if (!this.included) {
14410
+ const jsx = this.scope.context.options.jsx;
14411
+ if (jsx.mode === 'automatic') {
14412
+ this.fragment = 'Fragment';
14413
+ this.fragmentVariable = getAndIncludeFactoryVariable('Fragment', false, jsx.jsxImportSource, this);
14414
+ }
14415
+ else {
14416
+ const { fragment, importSource, mode } = jsx;
14417
+ if (fragment != null) {
14418
+ this.fragment = fragment;
14419
+ this.fragmentVariable = getAndIncludeFactoryVariable(fragment, mode === 'preserve', importSource, this);
14420
+ }
15115
14421
  }
15116
14422
  }
14423
+ super.include(context, includeChildrenRecursively);
15117
14424
  }
15118
14425
  render(code, options) {
15119
14426
  const { mode } = this.scope.context.options.jsx;
@@ -15150,7 +14457,6 @@ class JSXText extends NodeBase {
15150
14457
  }
15151
14458
  }
15152
14459
  }
15153
- JSXText.prototype.includeNode = onlyIncludeSelf;
15154
14460
 
15155
14461
  class LabeledStatement extends NodeBase {
15156
14462
  hasEffects(context) {
@@ -15172,22 +14478,17 @@ class LabeledStatement extends NodeBase {
15172
14478
  return bodyHasEffects;
15173
14479
  }
15174
14480
  include(context, includeChildrenRecursively) {
15175
- if (!this.included)
15176
- this.includeNode(context);
14481
+ this.included = true;
15177
14482
  const { brokenFlow, includedLabels } = context;
15178
14483
  context.includedLabels = new Set();
15179
14484
  this.body.include(context, includeChildrenRecursively);
15180
14485
  if (includeChildrenRecursively || context.includedLabels.has(this.label.name)) {
15181
- this.label.include(context);
14486
+ this.label.include();
15182
14487
  context.includedLabels.delete(this.label.name);
15183
14488
  context.brokenFlow = brokenFlow;
15184
14489
  }
15185
14490
  context.includedLabels = new Set([...includedLabels, ...context.includedLabels]);
15186
14491
  }
15187
- includeNode(context) {
15188
- this.included = true;
15189
- this.body.includePath(UNKNOWN_PATH, context);
15190
- }
15191
14492
  render(code, options) {
15192
14493
  if (this.label.included) {
15193
14494
  this.label.render(code, options);
@@ -15198,7 +14499,6 @@ class LabeledStatement extends NodeBase {
15198
14499
  this.body.render(code, options);
15199
14500
  }
15200
14501
  }
15201
- LabeledStatement.prototype.applyDeoptimizations = doNotDeoptimize;
15202
14502
 
15203
14503
  class LogicalExpression extends NodeBase {
15204
14504
  constructor() {
@@ -15215,10 +14515,10 @@ class LogicalExpression extends NodeBase {
15215
14515
  this.flags = setFlag(this.flags, 65536 /* Flag.isBranchResolutionAnalysed */, value);
15216
14516
  }
15217
14517
  get hasDeoptimizedCache() {
15218
- return isFlagSet(this.flags, 33554432 /* Flag.hasDeoptimizedCache */);
14518
+ return isFlagSet(this.flags, 16777216 /* Flag.hasDeoptimizedCache */);
15219
14519
  }
15220
14520
  set hasDeoptimizedCache(value) {
15221
- this.flags = setFlag(this.flags, 33554432 /* Flag.hasDeoptimizedCache */, value);
14521
+ this.flags = setFlag(this.flags, 16777216 /* Flag.hasDeoptimizedCache */, value);
15222
14522
  }
15223
14523
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
15224
14524
  this.left.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -15232,10 +14532,6 @@ class LogicalExpression extends NodeBase {
15232
14532
  const unusedBranch = this.usedBranch === this.left ? this.right : this.left;
15233
14533
  this.usedBranch = null;
15234
14534
  unusedBranch.deoptimizePath(UNKNOWN_PATH);
15235
- if (this.included) {
15236
- // As we are not tracking inclusions, we just include everything
15237
- unusedBranch.includePath(UNKNOWN_PATH, createInclusionContext());
15238
- }
15239
14535
  }
15240
14536
  const { scope: { context }, expressionsToBeDeoptimized } = this;
15241
14537
  this.expressionsToBeDeoptimized = parseAst_js.EMPTY_ARRAY;
@@ -15257,6 +14553,8 @@ class LogicalExpression extends NodeBase {
15257
14553
  }
15258
14554
  }
15259
14555
  getLiteralValueAtPath(path, recursionTracker, origin) {
14556
+ if (origin === this)
14557
+ return UnknownValue;
15260
14558
  const usedBranch = this.getUsedBranch();
15261
14559
  if (usedBranch) {
15262
14560
  this.expressionsToBeDeoptimized.push(origin);
@@ -15280,17 +14578,16 @@ class LogicalExpression extends NodeBase {
15280
14578
  }
15281
14579
  getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
15282
14580
  const usedBranch = this.getUsedBranch();
15283
- if (usedBranch) {
15284
- this.expressionsToBeDeoptimized.push(origin);
15285
- return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
15286
- }
15287
- return [
15288
- new MultiExpression([
15289
- this.left.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0],
15290
- this.right.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0]
15291
- ]),
15292
- false
15293
- ];
14581
+ if (!usedBranch)
14582
+ return [
14583
+ new MultiExpression([
14584
+ this.left.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0],
14585
+ this.right.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0]
14586
+ ]),
14587
+ false
14588
+ ];
14589
+ this.expressionsToBeDeoptimized.push(origin);
14590
+ return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
15294
14591
  }
15295
14592
  hasEffects(context) {
15296
14593
  if (this.left.hasEffects(context)) {
@@ -15303,18 +14600,18 @@ class LogicalExpression extends NodeBase {
15303
14600
  }
15304
14601
  hasEffectsOnInteractionAtPath(path, interaction, context) {
15305
14602
  const usedBranch = this.getUsedBranch();
15306
- if (usedBranch) {
15307
- return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
14603
+ if (!usedBranch) {
14604
+ return (this.left.hasEffectsOnInteractionAtPath(path, interaction, context) ||
14605
+ this.right.hasEffectsOnInteractionAtPath(path, interaction, context));
15308
14606
  }
15309
- return (this.left.hasEffectsOnInteractionAtPath(path, interaction, context) ||
15310
- this.right.hasEffectsOnInteractionAtPath(path, interaction, context));
14607
+ return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
15311
14608
  }
15312
14609
  include(context, includeChildrenRecursively) {
15313
14610
  this.included = true;
15314
14611
  const usedBranch = this.getUsedBranch();
15315
14612
  if (includeChildrenRecursively ||
15316
- !usedBranch ||
15317
- (usedBranch === this.right && this.left.shouldBeIncluded(context))) {
14613
+ (usedBranch === this.right && this.left.shouldBeIncluded(context)) ||
14614
+ !usedBranch) {
15318
14615
  this.left.include(context, includeChildrenRecursively);
15319
14616
  this.right.include(context, includeChildrenRecursively);
15320
14617
  }
@@ -15322,17 +14619,6 @@ class LogicalExpression extends NodeBase {
15322
14619
  usedBranch.include(context, includeChildrenRecursively);
15323
14620
  }
15324
14621
  }
15325
- includePath(path, context) {
15326
- this.included = true;
15327
- const usedBranch = this.getUsedBranch();
15328
- if (!usedBranch || (usedBranch === this.right && this.left.shouldBeIncluded(context))) {
15329
- this.left.includePath(path, context);
15330
- this.right.includePath(path, context);
15331
- }
15332
- else {
15333
- usedBranch.includePath(path, context);
15334
- }
15335
- }
15336
14622
  removeAnnotations(code) {
15337
14623
  this.left.removeAnnotations(code);
15338
14624
  }
@@ -15385,8 +14671,6 @@ class LogicalExpression extends NodeBase {
15385
14671
  return this.usedBranch;
15386
14672
  }
15387
14673
  }
15388
- LogicalExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15389
- LogicalExpression.prototype.applyDeoptimizations = doNotDeoptimize;
15390
14674
 
15391
14675
  class NewExpression extends NodeBase {
15392
14676
  hasEffects(context) {
@@ -15406,21 +14690,16 @@ class NewExpression extends NodeBase {
15406
14690
  return path.length > 0 || type !== INTERACTION_ACCESSED;
15407
14691
  }
15408
14692
  include(context, includeChildrenRecursively) {
14693
+ if (!this.deoptimized)
14694
+ this.applyDeoptimizations();
15409
14695
  if (includeChildrenRecursively) {
15410
14696
  super.include(context, includeChildrenRecursively);
15411
14697
  }
15412
14698
  else {
15413
- if (!this.included)
15414
- this.includeNode(context);
14699
+ this.included = true;
15415
14700
  this.callee.include(context, false);
15416
14701
  }
15417
- this.callee.includeCallArguments(context, this.interaction);
15418
- }
15419
- includeNode(context) {
15420
- this.included = true;
15421
- if (!this.deoptimized)
15422
- this.applyDeoptimizations();
15423
- this.callee.includePath(UNKNOWN_PATH, context);
14702
+ this.callee.includeCallArguments(context, this.arguments);
15424
14703
  }
15425
14704
  initialise() {
15426
14705
  super.initialise();
@@ -15449,7 +14728,6 @@ class ObjectExpression extends NodeBase {
15449
14728
  constructor() {
15450
14729
  super(...arguments);
15451
14730
  this.objectEntity = null;
15452
- this.protoProp = null;
15453
14731
  }
15454
14732
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
15455
14733
  this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
@@ -15469,43 +14747,15 @@ class ObjectExpression extends NodeBase {
15469
14747
  hasEffectsOnInteractionAtPath(path, interaction, context) {
15470
14748
  return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
15471
14749
  }
15472
- include(context, includeChildrenRecursively) {
15473
- if (!this.included)
15474
- this.includeNode(context);
15475
- this.getObjectEntity().include(context, includeChildrenRecursively);
15476
- this.protoProp?.include(context, includeChildrenRecursively);
15477
- }
15478
- includeNode(context) {
15479
- this.included = true;
15480
- this.protoProp?.includePath(UNKNOWN_PATH, context);
15481
- }
15482
- includePath(path, context) {
15483
- if (!this.included)
15484
- this.includeNode(context);
15485
- this.getObjectEntity().includePath(path, context);
15486
- }
15487
14750
  render(code, options, { renderedSurroundingElement } = parseAst_js.BLANK) {
14751
+ super.render(code, options);
15488
14752
  if (renderedSurroundingElement === parseAst_js.ExpressionStatement ||
15489
14753
  renderedSurroundingElement === parseAst_js.ArrowFunctionExpression) {
15490
14754
  code.appendRight(this.start, '(');
15491
14755
  code.prependLeft(this.end, ')');
15492
14756
  }
15493
- if (this.properties.length > 0) {
15494
- const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.properties, code, this.start + 1, this.end - 1);
15495
- let lastSeparatorPos = null;
15496
- for (const { node, separator, start, end } of separatedNodes) {
15497
- if (!node.included) {
15498
- treeshakeNode(node, code, start, end);
15499
- continue;
15500
- }
15501
- lastSeparatorPos = separator;
15502
- node.render(code, options);
15503
- }
15504
- if (lastSeparatorPos) {
15505
- code.remove(lastSeparatorPos, this.end - 1);
15506
- }
15507
- }
15508
14757
  }
14758
+ applyDeoptimizations() { }
15509
14759
  getObjectEntity() {
15510
14760
  if (this.objectEntity !== null) {
15511
14761
  return this.objectEntity;
@@ -15534,7 +14784,6 @@ class ObjectExpression extends NodeBase {
15534
14784
  ? property.key.name
15535
14785
  : String(property.key.value);
15536
14786
  if (key === '__proto__' && property.kind === 'init') {
15537
- this.protoProp = property;
15538
14787
  prototype =
15539
14788
  property.value instanceof Literal && property.value.value === null
15540
14789
  ? null
@@ -15547,7 +14796,6 @@ class ObjectExpression extends NodeBase {
15547
14796
  return (this.objectEntity = new ObjectEntity(properties, prototype));
15548
14797
  }
15549
14798
  }
15550
- ObjectExpression.prototype.applyDeoptimizations = doNotDeoptimize;
15551
14799
 
15552
14800
  class PanicError extends NodeBase {
15553
14801
  initialise() {
@@ -15574,7 +14822,6 @@ class ParseError extends NodeBase {
15574
14822
 
15575
14823
  class PrivateIdentifier extends NodeBase {
15576
14824
  }
15577
- PrivateIdentifier.prototype.includeNode = onlyIncludeSelf;
15578
14825
 
15579
14826
  class Program extends NodeBase {
15580
14827
  constructor() {
@@ -15642,11 +14889,14 @@ class Program extends NodeBase {
15642
14889
  super.render(code, options);
15643
14890
  }
15644
14891
  }
14892
+ applyDeoptimizations() { }
15645
14893
  }
15646
- Program.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15647
- Program.prototype.applyDeoptimizations = doNotDeoptimize;
15648
14894
 
15649
14895
  class Property extends MethodBase {
14896
+ constructor() {
14897
+ super(...arguments);
14898
+ this.declarationInit = null;
14899
+ }
15650
14900
  //declare method: boolean;
15651
14901
  get method() {
15652
14902
  return isFlagSet(this.flags, 262144 /* Flag.method */);
@@ -15661,41 +14911,17 @@ class Property extends MethodBase {
15661
14911
  set shorthand(value) {
15662
14912
  this.flags = setFlag(this.flags, 524288 /* Flag.shorthand */, value);
15663
14913
  }
15664
- declare(kind, destructuredInitPath, init) {
15665
- return this.value.declare(kind, this.getPathInProperty(destructuredInitPath), init);
15666
- }
15667
- deoptimizeAssignment(destructuredInitPath, init) {
15668
- this.value.deoptimizeAssignment?.(this.getPathInProperty(destructuredInitPath), init);
14914
+ declare(kind, init) {
14915
+ this.declarationInit = init;
14916
+ return this.value.declare(kind, UNKNOWN_EXPRESSION);
15669
14917
  }
15670
14918
  hasEffects(context) {
15671
- return this.key.hasEffects(context) || this.value.hasEffects(context);
15672
- }
15673
- hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
15674
- return this.value.hasEffectsWhenDestructuring?.(context, this.getPathInProperty(destructuredInitPath), init);
15675
- }
15676
- includeDestructuredIfNecessary(context, destructuredInitPath, init) {
15677
- const path = this.getPathInProperty(destructuredInitPath);
15678
- let included = this.value.includeDestructuredIfNecessary(context, path, init) ||
15679
- this.included;
15680
- if ((included ||= this.key.hasEffects(createHasEffectsContext()))) {
15681
- this.key.include(context, false);
15682
- if (!this.value.included) {
15683
- this.value.included = true;
15684
- // Unfortunately, we need to include the value again now, so that any
15685
- // declared variables are properly included.
15686
- this.value.includeDestructuredIfNecessary(context, path, init);
15687
- }
15688
- }
15689
- return (this.included = included);
15690
- }
15691
- include(context, includeChildrenRecursively) {
15692
- this.included = true;
15693
- this.key.include(context, includeChildrenRecursively);
15694
- this.value.include(context, includeChildrenRecursively);
15695
- }
15696
- includePath(path, context) {
15697
- this.included = true;
15698
- this.value.includePath(path, context);
14919
+ if (!this.deoptimized)
14920
+ this.applyDeoptimizations();
14921
+ const propertyReadSideEffects = this.scope.context.options.treeshake.propertyReadSideEffects;
14922
+ return ((this.parent.type === 'ObjectPattern' && propertyReadSideEffects === 'always') ||
14923
+ this.key.hasEffects(context) ||
14924
+ this.value.hasEffects(context));
15699
14925
  }
15700
14926
  markDeclarationReached() {
15701
14927
  this.value.markDeclarationReached();
@@ -15706,20 +14932,14 @@ class Property extends MethodBase {
15706
14932
  }
15707
14933
  this.value.render(code, options, { isShorthandProperty: this.shorthand });
15708
14934
  }
15709
- getPathInProperty(destructuredInitPath) {
15710
- return destructuredInitPath.at(-1) === UnknownKey
15711
- ? destructuredInitPath
15712
- : // For now, we only consider static paths as we do not know how to
15713
- // deoptimize the path in the dynamic case.
15714
- this.computed
15715
- ? [...destructuredInitPath, UnknownKey]
15716
- : this.key instanceof Identifier
15717
- ? [...destructuredInitPath, this.key.name]
15718
- : [...destructuredInitPath, String(this.key.value)];
14935
+ applyDeoptimizations() {
14936
+ this.deoptimized = true;
14937
+ if (this.declarationInit !== null) {
14938
+ this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
14939
+ this.scope.context.requestTreeshakingPass();
14940
+ }
15719
14941
  }
15720
14942
  }
15721
- Property.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15722
- Property.prototype.applyDeoptimizations = doNotDeoptimize;
15723
14943
 
15724
14944
  class PropertyDefinition extends NodeBase {
15725
14945
  get computed() {
@@ -15752,15 +14972,8 @@ class PropertyDefinition extends NodeBase {
15752
14972
  hasEffectsOnInteractionAtPath(path, interaction, context) {
15753
14973
  return !this.value || this.value.hasEffectsOnInteractionAtPath(path, interaction, context);
15754
14974
  }
15755
- includeNode(context) {
15756
- this.included = true;
15757
- this.value?.includePath(UNKNOWN_PATH, context);
15758
- for (const decorator of this.decorators) {
15759
- decorator.includePath(UNKNOWN_PATH, context);
15760
- }
15761
- }
14975
+ applyDeoptimizations() { }
15762
14976
  }
15763
- PropertyDefinition.prototype.applyDeoptimizations = doNotDeoptimize;
15764
14977
 
15765
14978
  class ReturnStatement extends NodeBase {
15766
14979
  hasEffects(context) {
@@ -15770,15 +14983,10 @@ class ReturnStatement extends NodeBase {
15770
14983
  return false;
15771
14984
  }
15772
14985
  include(context, includeChildrenRecursively) {
15773
- if (!this.included)
15774
- this.includeNode(context);
14986
+ this.included = true;
15775
14987
  this.argument?.include(context, includeChildrenRecursively);
15776
14988
  context.brokenFlow = true;
15777
14989
  }
15778
- includeNode(context) {
15779
- this.included = true;
15780
- this.argument?.includePath(UNKNOWN_PATH, context);
15781
- }
15782
14990
  initialise() {
15783
14991
  super.initialise();
15784
14992
  this.scope.addReturnExpression(this.argument || UNKNOWN_EXPRESSION);
@@ -15792,7 +15000,6 @@ class ReturnStatement extends NodeBase {
15792
15000
  }
15793
15001
  }
15794
15002
  }
15795
- ReturnStatement.prototype.applyDeoptimizations = doNotDeoptimize;
15796
15003
 
15797
15004
  class SequenceExpression extends NodeBase {
15798
15005
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
@@ -15820,15 +15027,10 @@ class SequenceExpression extends NodeBase {
15820
15027
  for (const expression of this.expressions) {
15821
15028
  if (includeChildrenRecursively ||
15822
15029
  (expression === lastExpression && !(this.parent instanceof ExpressionStatement)) ||
15823
- expression.shouldBeIncluded(context)) {
15030
+ expression.shouldBeIncluded(context))
15824
15031
  expression.include(context, includeChildrenRecursively);
15825
- }
15826
15032
  }
15827
15033
  }
15828
- includePath(path, context) {
15829
- this.included = true;
15830
- this.expressions[this.expressions.length - 1].includePath(path, context);
15831
- }
15832
15034
  removeAnnotations(code) {
15833
15035
  this.expressions[0].removeAnnotations(code);
15834
15036
  }
@@ -15863,8 +15065,6 @@ class SequenceExpression extends NodeBase {
15863
15065
  }
15864
15066
  }
15865
15067
  }
15866
- SequenceExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15867
- SequenceExpression.prototype.applyDeoptimizations = doNotDeoptimize;
15868
15068
 
15869
15069
  class Super extends NodeBase {
15870
15070
  bind() {
@@ -15876,15 +15076,11 @@ class Super extends NodeBase {
15876
15076
  deoptimizePath(path) {
15877
15077
  this.variable.deoptimizePath(path);
15878
15078
  }
15879
- include(context) {
15880
- if (!this.included)
15881
- this.includeNode(context);
15882
- }
15883
- includeNode(context) {
15884
- this.included = true;
15885
- if (!this.deoptimized)
15886
- this.applyDeoptimizations();
15887
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
15079
+ include() {
15080
+ if (!this.included) {
15081
+ this.included = true;
15082
+ this.scope.context.includeVariableInModule(this.variable);
15083
+ }
15888
15084
  }
15889
15085
  }
15890
15086
 
@@ -15925,8 +15121,6 @@ class SwitchCase extends NodeBase {
15925
15121
  }
15926
15122
  }
15927
15123
  SwitchCase.prototype.needsBoundaries = true;
15928
- SwitchCase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15929
- SwitchCase.prototype.applyDeoptimizations = doNotDeoptimize;
15930
15124
 
15931
15125
  class SwitchStatement extends NodeBase {
15932
15126
  createScope(parentScope) {
@@ -16009,8 +15203,6 @@ class SwitchStatement extends NodeBase {
16009
15203
  }
16010
15204
  }
16011
15205
  }
16012
- SwitchStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
16013
- SwitchStatement.prototype.applyDeoptimizations = doNotDeoptimize;
16014
15206
 
16015
15207
  class TaggedTemplateExpression extends CallExpressionBase {
16016
15208
  bind() {
@@ -16034,8 +15226,8 @@ class TaggedTemplateExpression extends CallExpressionBase {
16034
15226
  this.tag.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context));
16035
15227
  }
16036
15228
  include(context, includeChildrenRecursively) {
16037
- if (!this.included)
16038
- this.includeNode(context);
15229
+ if (!this.deoptimized)
15230
+ this.applyDeoptimizations();
16039
15231
  if (includeChildrenRecursively) {
16040
15232
  super.include(context, includeChildrenRecursively);
16041
15233
  }
@@ -16044,7 +15236,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
16044
15236
  this.tag.include(context, includeChildrenRecursively);
16045
15237
  this.quasi.include(context, includeChildrenRecursively);
16046
15238
  }
16047
- this.tag.includeCallArguments(context, this.interaction);
15239
+ this.tag.includeCallArguments(context, this.args);
16048
15240
  const [returnExpression] = this.getReturnExpression();
16049
15241
  if (!returnExpression.included) {
16050
15242
  returnExpression.include(context, false);
@@ -16079,7 +15271,6 @@ class TaggedTemplateExpression extends CallExpressionBase {
16079
15271
  return this.returnExpression;
16080
15272
  }
16081
15273
  }
16082
- TaggedTemplateExpression.prototype.includeNode = onlyIncludeSelf;
16083
15274
 
16084
15275
  class TemplateElement extends NodeBase {
16085
15276
  get tail() {
@@ -16093,13 +15284,15 @@ class TemplateElement extends NodeBase {
16093
15284
  hasEffects() {
16094
15285
  return false;
16095
15286
  }
15287
+ include() {
15288
+ this.included = true;
15289
+ }
16096
15290
  parseNode(esTreeNode) {
16097
15291
  this.value = esTreeNode.value;
16098
15292
  return super.parseNode(esTreeNode);
16099
15293
  }
16100
15294
  render() { }
16101
15295
  }
16102
- TemplateElement.prototype.includeNode = onlyIncludeSelf;
16103
15296
 
16104
15297
  class TemplateLiteral extends NodeBase {
16105
15298
  deoptimizeArgumentsOnInteractionAtPath() { }
@@ -16124,14 +15317,6 @@ class TemplateLiteral extends NodeBase {
16124
15317
  }
16125
15318
  return true;
16126
15319
  }
16127
- includeNode(context) {
16128
- this.included = true;
16129
- if (!this.deoptimized)
16130
- this.applyDeoptimizations();
16131
- for (const node of this.expressions) {
16132
- node.includePath(UNKNOWN_PATH, context);
16133
- }
16134
- }
16135
15320
  render(code, options) {
16136
15321
  code.indentExclusionRanges.push([this.start, this.end]);
16137
15322
  super.render(code, options);
@@ -16141,13 +15326,13 @@ class TemplateLiteral extends NodeBase {
16141
15326
  class ModuleScope extends ChildScope {
16142
15327
  constructor(parent, context) {
16143
15328
  super(parent, context);
16144
- this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, EMPTY_PATH, context, 'other'));
15329
+ this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, context, 'other'));
16145
15330
  }
16146
- addDeclaration(identifier, context, init, destructuredInitPath, kind) {
15331
+ addDeclaration(identifier, context, init, kind) {
16147
15332
  if (this.context.module.importDescriptions.has(identifier.name)) {
16148
15333
  context.error(parseAst_js.logRedeclarationError(identifier.name), identifier.start);
16149
15334
  }
16150
- return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
15335
+ return super.addDeclaration(identifier, context, init, kind);
16151
15336
  }
16152
15337
  addExportDefaultDeclaration(name, exportDefaultDeclaration, context) {
16153
15338
  const variable = new ExportDefaultVariable(name, exportDefaultDeclaration, context);
@@ -16192,23 +15377,10 @@ class ThisExpression extends NodeBase {
16192
15377
  }
16193
15378
  return this.variable.hasEffectsOnInteractionAtPath(path, interaction, context);
16194
15379
  }
16195
- include(context) {
16196
- if (!this.included)
16197
- this.includeNode(context);
16198
- }
16199
- includeNode(context) {
16200
- this.included = true;
16201
- if (!this.deoptimized)
16202
- this.applyDeoptimizations();
16203
- this.scope.context.includeVariableInModule(this.variable, EMPTY_PATH, context);
16204
- }
16205
- includePath(path, context) {
15380
+ include() {
16206
15381
  if (!this.included) {
16207
15382
  this.included = true;
16208
- this.scope.context.includeVariableInModule(this.variable, path, context);
16209
- }
16210
- else if (path.length > 0) {
16211
- this.variable.includePath(path, context);
15383
+ this.scope.context.includeVariableInModule(this.variable);
16212
15384
  }
16213
15385
  }
16214
15386
  initialise() {
@@ -16236,8 +15408,7 @@ class ThrowStatement extends NodeBase {
16236
15408
  return true;
16237
15409
  }
16238
15410
  include(context, includeChildrenRecursively) {
16239
- if (!this.included)
16240
- this.includeNode(context);
15411
+ this.included = true;
16241
15412
  this.argument.include(context, includeChildrenRecursively);
16242
15413
  context.brokenFlow = true;
16243
15414
  }
@@ -16248,7 +15419,6 @@ class ThrowStatement extends NodeBase {
16248
15419
  }
16249
15420
  }
16250
15421
  }
16251
- ThrowStatement.prototype.includeNode = onlyIncludeSelf;
16252
15422
 
16253
15423
  class TryStatement extends NodeBase {
16254
15424
  constructor() {
@@ -16285,8 +15455,6 @@ class TryStatement extends NodeBase {
16285
15455
  this.finalizer?.include(context, includeChildrenRecursively);
16286
15456
  }
16287
15457
  }
16288
- TryStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
16289
- TryStatement.prototype.applyDeoptimizations = doNotDeoptimize;
16290
15458
 
16291
15459
  const unaryOperators = {
16292
15460
  '!': value => !value,
@@ -16316,8 +15484,17 @@ class UnaryExpression extends NodeBase {
16316
15484
  if (path.length > 0)
16317
15485
  return UnknownValue;
16318
15486
  const argumentValue = this.argument.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
16319
- if (typeof argumentValue === 'symbol')
15487
+ if (typeof argumentValue === 'symbol') {
15488
+ if (this.operator === 'void')
15489
+ return undefined;
15490
+ if (this.operator === '!') {
15491
+ if (argumentValue === UnknownFalsyValue)
15492
+ return true;
15493
+ if (argumentValue === UnknownTruthyValue)
15494
+ return false;
15495
+ }
16320
15496
  return UnknownValue;
15497
+ }
16321
15498
  return unaryOperators[this.operator](argumentValue);
16322
15499
  }
16323
15500
  hasEffects(context) {
@@ -16393,7 +15570,6 @@ function getSimplifiedNumber(value) {
16393
15570
  const stringifiedValue = String(value).replace('+', '');
16394
15571
  return finalizedExp.length < stringifiedValue.length ? finalizedExp : stringifiedValue;
16395
15572
  }
16396
- UnaryExpression.prototype.includeNode = onlyIncludeSelf;
16397
15573
 
16398
15574
  class UpdateExpression extends NodeBase {
16399
15575
  hasEffects(context) {
@@ -16405,8 +15581,9 @@ class UpdateExpression extends NodeBase {
16405
15581
  return path.length > 1 || type !== INTERACTION_ACCESSED;
16406
15582
  }
16407
15583
  include(context, includeChildrenRecursively) {
16408
- if (!this.included)
16409
- this.includeNode(context);
15584
+ if (!this.deoptimized)
15585
+ this.applyDeoptimizations();
15586
+ this.included = true;
16410
15587
  this.argument.includeAsAssignmentTarget(context, includeChildrenRecursively, true);
16411
15588
  }
16412
15589
  initialise() {
@@ -16445,7 +15622,6 @@ class UpdateExpression extends NodeBase {
16445
15622
  this.scope.context.requestTreeshakingPass();
16446
15623
  }
16447
15624
  }
16448
- UpdateExpression.prototype.includeNode = onlyIncludeSelf;
16449
15625
 
16450
15626
  function areAllDeclarationsIncludedAndNotExported(declarations, exportNamesByVariable) {
16451
15627
  for (const declarator of declarations) {
@@ -16476,9 +15652,8 @@ class VariableDeclaration extends NodeBase {
16476
15652
  include(context, includeChildrenRecursively, { asSingleStatement } = parseAst_js.BLANK) {
16477
15653
  this.included = true;
16478
15654
  for (const declarator of this.declarations) {
16479
- if (includeChildrenRecursively || declarator.shouldBeIncluded(context)) {
15655
+ if (includeChildrenRecursively || declarator.shouldBeIncluded(context))
16480
15656
  declarator.include(context, includeChildrenRecursively);
16481
- }
16482
15657
  const { id, init } = declarator;
16483
15658
  if (asSingleStatement) {
16484
15659
  id.include(context, includeChildrenRecursively);
@@ -16516,6 +15691,7 @@ class VariableDeclaration extends NodeBase {
16516
15691
  this.renderReplacedDeclarations(code, options);
16517
15692
  }
16518
15693
  }
15694
+ applyDeoptimizations() { }
16519
15695
  renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, systemPatternExports, options) {
16520
15696
  if (code.original.charCodeAt(this.end - 1) === 59 /*";"*/) {
16521
15697
  code.remove(this.end - 1, this.end);
@@ -16558,7 +15734,8 @@ class VariableDeclaration extends NodeBase {
16558
15734
  const singleSystemExport = gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregatedSystemExports);
16559
15735
  for (const { node, start, separator, contentEnd, end } of separatedNodes) {
16560
15736
  if (!node.included) {
16561
- treeshakeNode(node, code, start, end);
15737
+ code.remove(start, end);
15738
+ node.removeAnnotations(code);
16562
15739
  continue;
16563
15740
  }
16564
15741
  node.render(code, options);
@@ -16628,8 +15805,6 @@ function gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregat
16628
15805
  }
16629
15806
  return singleSystemExport;
16630
15807
  }
16631
- VariableDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
16632
- VariableDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
16633
15808
 
16634
15809
  class WhileStatement extends NodeBase {
16635
15810
  hasEffects(context) {
@@ -16643,25 +15818,13 @@ class WhileStatement extends NodeBase {
16643
15818
  includeLoopBody(context, this.body, includeChildrenRecursively);
16644
15819
  }
16645
15820
  }
16646
- WhileStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
16647
- WhileStatement.prototype.applyDeoptimizations = doNotDeoptimize;
16648
15821
 
16649
15822
  class YieldExpression extends NodeBase {
16650
- applyDeoptimizations() {
16651
- this.deoptimized = true;
16652
- this.argument?.deoptimizePath(UNKNOWN_PATH);
16653
- }
16654
15823
  hasEffects(context) {
16655
15824
  if (!this.deoptimized)
16656
15825
  this.applyDeoptimizations();
16657
15826
  return !(context.ignore.returnYield && !this.argument?.hasEffects(context));
16658
15827
  }
16659
- includeNode(context) {
16660
- this.included = true;
16661
- if (!this.deoptimized)
16662
- this.applyDeoptimizations();
16663
- this.argument?.includePath(UNKNOWN_PATH, context);
16664
- }
16665
15828
  render(code, options) {
16666
15829
  if (this.argument) {
16667
15830
  this.argument.render(code, options, { preventASI: true });
@@ -16895,7 +16058,7 @@ const bufferParsers = [
16895
16058
  const annotations = (node.annotations = parseAst_js.convertAnnotations(buffer[position + 1], buffer));
16896
16059
  node.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
16897
16060
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 2], buffer));
16898
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16061
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16899
16062
  node.body = convertNode(node, scope.bodyScope, buffer[position + 3], buffer);
16900
16063
  },
16901
16064
  function assignmentExpression(node, position, buffer) {
@@ -16941,7 +16104,7 @@ const bufferParsers = [
16941
16104
  const parameterPosition = buffer[position];
16942
16105
  const parameter = (node.param =
16943
16106
  parameterPosition === 0 ? null : convertNode(node, scope, parameterPosition, buffer));
16944
- parameter?.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
16107
+ parameter?.declare('parameter', UNKNOWN_EXPRESSION);
16945
16108
  node.body = convertNode(node, scope.bodyScope, buffer[position + 1], buffer);
16946
16109
  },
16947
16110
  function chainExpression(node, position, buffer) {
@@ -17079,7 +16242,7 @@ const bufferParsers = [
17079
16242
  node.id =
17080
16243
  idPosition === 0 ? null : convertNode(node, scope.parent, idPosition, buffer);
17081
16244
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
17082
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16245
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
17083
16246
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
17084
16247
  },
17085
16248
  function functionExpression(node, position, buffer) {
@@ -17092,7 +16255,7 @@ const bufferParsers = [
17092
16255
  const idPosition = buffer[position + 2];
17093
16256
  node.id = idPosition === 0 ? null : convertNode(node, node.idScope, idPosition, buffer);
17094
16257
  const parameters = (node.params = convertNodeList(node, scope, buffer[position + 3], buffer));
17095
- scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
16258
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
17096
16259
  node.body = convertNode(node, scope.bodyScope, buffer[position + 4], buffer);
17097
16260
  },
17098
16261
  function identifier(node, position, buffer) {
@@ -17556,8 +16719,8 @@ class ExportShimVariable extends Variable {
17556
16719
  super(MISSING_EXPORT_SHIM_VARIABLE);
17557
16720
  this.module = module;
17558
16721
  }
17559
- includePath(path, context) {
17560
- super.includePath(path, context);
16722
+ include() {
16723
+ super.include();
17561
16724
  this.module.needsExportShim = true;
17562
16725
  }
17563
16726
  }
@@ -18248,15 +17411,16 @@ class Module {
18248
17411
  markModuleAndImpureDependenciesAsExecuted(this);
18249
17412
  this.graph.needsTreeshakingPass = true;
18250
17413
  }
18251
- const inclusionContext = createInclusionContext();
18252
17414
  for (const exportName of this.exports.keys()) {
18253
17415
  if (includeNamespaceMembers || exportName !== this.info.syntheticNamedExports) {
18254
17416
  const variable = this.getVariableForExportName(exportName)[0];
18255
17417
  if (!variable) {
18256
17418
  return parseAst_js.error(parseAst_js.logMissingEntryExport(exportName, this.id));
18257
17419
  }
18258
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
18259
17420
  variable.deoptimizePath(UNKNOWN_PATH);
17421
+ if (!variable.included) {
17422
+ this.includeVariable(variable);
17423
+ }
18260
17424
  }
18261
17425
  }
18262
17426
  for (const name of this.getReexports()) {
@@ -18264,7 +17428,7 @@ class Module {
18264
17428
  if (variable) {
18265
17429
  variable.deoptimizePath(UNKNOWN_PATH);
18266
17430
  if (!variable.included) {
18267
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
17431
+ this.includeVariable(variable);
18268
17432
  }
18269
17433
  if (variable instanceof ExternalVariable) {
18270
17434
  variable.module.reexported = true;
@@ -18285,12 +17449,13 @@ class Module {
18285
17449
  this.graph.needsTreeshakingPass = true;
18286
17450
  }
18287
17451
  let includeNamespaceMembers = false;
18288
- const inclusionContext = createInclusionContext();
18289
17452
  for (const name of names) {
18290
17453
  const variable = this.getVariableForExportName(name)[0];
18291
17454
  if (variable) {
18292
17455
  variable.deoptimizePath(UNKNOWN_PATH);
18293
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
17456
+ if (!variable.included) {
17457
+ this.includeVariable(variable);
17458
+ }
18294
17459
  }
18295
17460
  if (!this.exports.has(name) && !this.reexportDescriptions.has(name)) {
18296
17461
  includeNamespaceMembers = true;
@@ -18391,7 +17556,6 @@ class Module {
18391
17556
  manualPureFunctions: this.graph.pureFunctions,
18392
17557
  module: this,
18393
17558
  moduleContext: this.context,
18394
- newlyIncludedVariableInits: this.graph.newlyIncludedVariableInits,
18395
17559
  options: this.options,
18396
17560
  requestTreeshakingPass: () => (this.graph.needsTreeshakingPass = true),
18397
17561
  traceExport: (name) => this.getVariableForExportName(name)[0],
@@ -18732,13 +17896,13 @@ class Module {
18732
17896
  for (const module of [this, ...this.exportAllModules]) {
18733
17897
  if (module instanceof ExternalModule) {
18734
17898
  const [externalVariable] = module.getVariableForExportName('*');
18735
- externalVariable.includePath(UNKNOWN_PATH, createInclusionContext());
17899
+ externalVariable.include();
18736
17900
  this.includedImports.add(externalVariable);
18737
17901
  externalNamespaces.add(externalVariable);
18738
17902
  }
18739
17903
  else if (module.info.syntheticNamedExports) {
18740
17904
  const syntheticNamespace = module.getSyntheticNamespace();
18741
- syntheticNamespace.includePath(UNKNOWN_PATH, createInclusionContext());
17905
+ syntheticNamespace.include();
18742
17906
  this.includedImports.add(syntheticNamespace);
18743
17907
  syntheticNamespaces.add(syntheticNamespace);
18744
17908
  }
@@ -18748,9 +17912,7 @@ class Module {
18748
17912
  includeDynamicImport(node) {
18749
17913
  const resolution = this.dynamicImports.find(dynamicImport => dynamicImport.node === node).resolution;
18750
17914
  if (resolution instanceof Module) {
18751
- if (!resolution.includedDynamicImporters.includes(this)) {
18752
- resolution.includedDynamicImporters.push(this);
18753
- }
17915
+ resolution.includedDynamicImporters.push(this);
18754
17916
  const importedNames = this.options.treeshake
18755
17917
  ? node.getDeterministicImportedNames()
18756
17918
  : undefined;
@@ -18762,15 +17924,15 @@ class Module {
18762
17924
  }
18763
17925
  }
18764
17926
  }
18765
- includeVariable(variable, path, context) {
18766
- const { included, module: variableModule } = variable;
18767
- variable.includePath(path, context);
18768
- if (included) {
17927
+ includeVariable(variable) {
17928
+ const variableModule = variable.module;
17929
+ if (variable.included) {
18769
17930
  if (variableModule instanceof Module && variableModule !== this) {
18770
17931
  getAndExtendSideEffectModules(variable, this);
18771
17932
  }
18772
17933
  }
18773
17934
  else {
17935
+ variable.include();
18774
17936
  this.graph.needsTreeshakingPass = true;
18775
17937
  if (variableModule instanceof Module) {
18776
17938
  if (!variableModule.isExecuted) {
@@ -18787,8 +17949,8 @@ class Module {
18787
17949
  }
18788
17950
  }
18789
17951
  }
18790
- includeVariableInModule(variable, path, context) {
18791
- this.includeVariable(variable, path, context);
17952
+ includeVariableInModule(variable) {
17953
+ this.includeVariable(variable);
18792
17954
  const variableModule = variable.module;
18793
17955
  if (variableModule && variableModule !== this) {
18794
17956
  this.includedImports.add(variable);
@@ -19718,17 +18880,21 @@ class Chunk {
19718
18880
  .filter((resolution) => resolution !== this &&
19719
18881
  (resolution instanceof Chunk || resolution instanceof ExternalChunk));
19720
18882
  }
19721
- getDynamicImportStringAndAttributes(resolution, fileName) {
18883
+ getDynamicImportStringAndAttributes(resolution, fileName, node) {
19722
18884
  if (resolution instanceof ExternalModule) {
19723
18885
  const chunk = this.externalChunkByModule.get(resolution);
19724
18886
  return [`'${chunk.getImportPath(fileName)}'`, chunk.getImportAttributes(this.snippets)];
19725
18887
  }
19726
- return [
19727
- resolution || '',
19728
- (['es', 'cjs'].includes(this.outputOptions.format) &&
19729
- this.outputOptions.externalImportAttributes) ||
19730
- null
19731
- ];
18888
+ let attributes = null;
18889
+ if (['es', 'cjs'].includes(this.outputOptions.format) &&
18890
+ this.outputOptions.externalImportAttributes) {
18891
+ const attributesFromImportAttributes = getAttributesFromImportExpression(node);
18892
+ attributes =
18893
+ attributesFromImportAttributes === parseAst_js.EMPTY_OBJECT
18894
+ ? true
18895
+ : formatAttributes(attributesFromImportAttributes, this.snippets);
18896
+ }
18897
+ return [resolution || '', attributes];
19732
18898
  }
19733
18899
  getFallbackChunkName() {
19734
18900
  if (this.manualChunkAlias) {
@@ -19944,7 +19110,7 @@ class Chunk {
19944
19110
  // This method changes properties on the AST before rendering and must not be async
19945
19111
  renderModules(fileName) {
19946
19112
  const { accessedGlobalsByScope, dependencies, exportNamesByVariable, includedNamespaces, inputOptions: { onLog }, isEmpty, orderedModules, outputOptions, pluginDriver, renderedModules, snippets } = this;
19947
- const { compact, format, freeze, generatedCode: { symbols } } = outputOptions;
19113
+ const { compact, format, freeze, generatedCode: { symbols }, importAttributesKey } = outputOptions;
19948
19114
  const { _, cnst, n } = snippets;
19949
19115
  this.setDynamicImportResolutions(fileName);
19950
19116
  this.setImportMetaResolutions(fileName);
@@ -19960,6 +19126,7 @@ class Chunk {
19960
19126
  exportNamesByVariable,
19961
19127
  format,
19962
19128
  freeze,
19129
+ importAttributesKey,
19963
19130
  indent,
19964
19131
  pluginDriver,
19965
19132
  snippets,
@@ -20038,7 +19205,7 @@ class Chunk {
20038
19205
  }
20039
19206
  else {
20040
19207
  const { node, resolution } = resolvedDynamicImport;
20041
- const [resolutionString, attributes] = this.getDynamicImportStringAndAttributes(resolution, fileName);
19208
+ const [resolutionString, attributes] = this.getDynamicImportStringAndAttributes(resolution, fileName, node);
20042
19209
  node.setExternalResolution('external', resolution, outputOptions, snippets, pluginDriver, accessedGlobalsByScope, resolutionString, false, attributes);
20043
19210
  }
20044
19211
  }
@@ -22297,11 +21464,10 @@ class Graph {
22297
21464
  this.options = options;
22298
21465
  this.astLru = flru(5);
22299
21466
  this.cachedModules = new Map();
22300
- this.deoptimizationTracker = new EntityPathTracker();
21467
+ this.deoptimizationTracker = new PathTracker();
22301
21468
  this.entryModules = [];
22302
21469
  this.modulesById = new Map();
22303
21470
  this.needsTreeshakingPass = false;
22304
- this.newlyIncludedVariableInits = new Set();
22305
21471
  this.phase = BuildPhase.LOAD_AND_PARSE;
22306
21472
  this.scope = new GlobalScope();
22307
21473
  this.watchFiles = Object.create(null);
@@ -22395,7 +21561,6 @@ class Graph {
22395
21561
  }
22396
21562
  if (this.options.treeshake) {
22397
21563
  let treeshakingPass = 1;
22398
- this.newlyIncludedVariableInits.clear();
22399
21564
  do {
22400
21565
  timeStart(`treeshaking pass ${treeshakingPass}`, 3);
22401
21566
  this.needsTreeshakingPass = false;
@@ -22408,10 +21573,6 @@ class Graph {
22408
21573
  else {
22409
21574
  module.include();
22410
21575
  }
22411
- for (const entity of this.newlyIncludedVariableInits) {
22412
- this.newlyIncludedVariableInits.delete(entity);
22413
- entity.include(createInclusionContext(), false);
22414
- }
22415
21576
  }
22416
21577
  }
22417
21578
  if (treeshakingPass === 1) {