rollup 2.75.5 → 2.75.6

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 v2.75.5
4
- Wed, 01 Jun 2022 12:43:56 GMT - commit 14dedb52b4d799deebd8b711c1e14759fc0213d9
3
+ Rollup.js v2.75.6
4
+ Tue, 07 Jun 2022 14:42:22 GMT - commit 0ab16cc04b7d6dfe5bd14340ba7448085a379e25
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -14,7 +14,7 @@ import { createHash as createHash$1 } from 'crypto';
14
14
  import { promises } from 'fs';
15
15
  import { EventEmitter } from 'events';
16
16
 
17
- var version$1 = "2.75.5";
17
+ var version$1 = "2.75.6";
18
18
 
19
19
  var charToInteger = {};
20
20
  var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
@@ -1594,8 +1594,8 @@ class ExpressionEntity {
1594
1594
  this.included = false;
1595
1595
  }
1596
1596
  deoptimizePath(_path) { }
1597
- deoptimizeThisOnEventAtPath(_event, _path, thisParameter, _recursionTracker) {
1598
- thisParameter.deoptimizePath(UNKNOWN_PATH);
1597
+ deoptimizeThisOnInteractionAtPath({ thisArg }, _path, _recursionTracker) {
1598
+ thisArg.deoptimizePath(UNKNOWN_PATH);
1599
1599
  }
1600
1600
  /**
1601
1601
  * If possible it returns a stringifyable literal value for this node that can be used
@@ -1605,16 +1605,10 @@ class ExpressionEntity {
1605
1605
  getLiteralValueAtPath(_path, _recursionTracker, _origin) {
1606
1606
  return UnknownValue;
1607
1607
  }
1608
- getReturnExpressionWhenCalledAtPath(_path, _callOptions, _recursionTracker, _origin) {
1608
+ getReturnExpressionWhenCalledAtPath(_path, _interaction, _recursionTracker, _origin) {
1609
1609
  return UNKNOWN_EXPRESSION;
1610
1610
  }
1611
- hasEffectsWhenAccessedAtPath(_path, _context) {
1612
- return true;
1613
- }
1614
- hasEffectsWhenAssignedAtPath(_path, _context) {
1615
- return true;
1616
- }
1617
- hasEffectsWhenCalledAtPath(_path, _callOptions, _context) {
1611
+ hasEffectsOnInteractionAtPath(_path, _interaction, _context) {
1618
1612
  return true;
1619
1613
  }
1620
1614
  include(_context, _includeChildrenRecursively, _options) {
@@ -1632,6 +1626,30 @@ class ExpressionEntity {
1632
1626
  const UNKNOWN_EXPRESSION = new (class UnknownExpression extends ExpressionEntity {
1633
1627
  })();
1634
1628
 
1629
+ const INTERACTION_ACCESSED = 0;
1630
+ const INTERACTION_ASSIGNED = 1;
1631
+ const INTERACTION_CALLED = 2;
1632
+ const NODE_INTERACTION_UNKNOWN_ACCESS = {
1633
+ thisArg: null,
1634
+ type: INTERACTION_ACCESSED
1635
+ };
1636
+ const UNKNOWN_ARG = [UNKNOWN_EXPRESSION];
1637
+ const NODE_INTERACTION_UNKNOWN_ASSIGNMENT = {
1638
+ args: UNKNOWN_ARG,
1639
+ thisArg: null,
1640
+ type: INTERACTION_ASSIGNED
1641
+ };
1642
+ const NO_ARGS = [];
1643
+ // While this is technically a call without arguments, we can compare against
1644
+ // this reference in places where precise values or thisArg would make a
1645
+ // difference
1646
+ const NODE_INTERACTION_UNKNOWN_CALL = {
1647
+ args: NO_ARGS,
1648
+ thisArg: null,
1649
+ type: INTERACTION_CALLED,
1650
+ withNew: false
1651
+ };
1652
+
1635
1653
  class Variable extends ExpressionEntity {
1636
1654
  constructor(name) {
1637
1655
  super();
@@ -1656,8 +1674,8 @@ class Variable extends ExpressionEntity {
1656
1674
  const name = this.renderName || this.name;
1657
1675
  return this.renderBaseName ? `${this.renderBaseName}${getPropertyAccess(name)}` : name;
1658
1676
  }
1659
- hasEffectsWhenAccessedAtPath(path, _context) {
1660
- return path.length > 0;
1677
+ hasEffectsOnInteractionAtPath(path, { type }, _context) {
1678
+ return type !== INTERACTION_ACCESSED || path.length > 0;
1661
1679
  }
1662
1680
  /**
1663
1681
  * Marks this variable as being part of the bundle, which is usually the case when one of
@@ -1688,8 +1706,8 @@ class ExternalVariable extends Variable {
1688
1706
  this.module.suggestName(identifier.name);
1689
1707
  }
1690
1708
  }
1691
- hasEffectsWhenAccessedAtPath(path) {
1692
- return path.length > (this.isNamespace ? 1 : 0);
1709
+ hasEffectsOnInteractionAtPath(path, { type }) {
1710
+ return type !== INTERACTION_ACCESSED || path.length > (this.isNamespace ? 1 : 0);
1693
1711
  }
1694
1712
  include() {
1695
1713
  if (!this.included) {
@@ -4579,8 +4597,6 @@ function createHasEffectsContext() {
4579
4597
  };
4580
4598
  }
4581
4599
 
4582
- const NO_ARGS = [];
4583
-
4584
4600
  function assembleMemberDescriptions(memberDescriptions, inheritedDescriptions = null) {
4585
4601
  return Object.create(inheritedDescriptions, memberDescriptions);
4586
4602
  }
@@ -4602,12 +4618,12 @@ const UNKNOWN_LITERAL_BOOLEAN = new (class UnknownBoolean extends ExpressionEnti
4602
4618
  }
4603
4619
  return UNKNOWN_EXPRESSION;
4604
4620
  }
4605
- hasEffectsWhenAccessedAtPath(path) {
4606
- return path.length > 1;
4607
- }
4608
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
4609
- if (path.length === 1) {
4610
- return hasMemberEffectWhenCalled(literalBooleanMembers, path[0], callOptions, context);
4621
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
4622
+ if (interaction.type === INTERACTION_ACCESSED) {
4623
+ return path.length > 1;
4624
+ }
4625
+ if (interaction.type === INTERACTION_CALLED && path.length === 1) {
4626
+ return hasMemberEffectWhenCalled(literalBooleanMembers, path[0], interaction, context);
4611
4627
  }
4612
4628
  return true;
4613
4629
  }
@@ -4625,12 +4641,12 @@ const UNKNOWN_LITERAL_NUMBER = new (class UnknownNumber extends ExpressionEntity
4625
4641
  }
4626
4642
  return UNKNOWN_EXPRESSION;
4627
4643
  }
4628
- hasEffectsWhenAccessedAtPath(path) {
4629
- return path.length > 1;
4630
- }
4631
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
4632
- if (path.length === 1) {
4633
- return hasMemberEffectWhenCalled(literalNumberMembers, path[0], callOptions, context);
4644
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
4645
+ if (interaction.type === INTERACTION_ACCESSED) {
4646
+ return path.length > 1;
4647
+ }
4648
+ if (interaction.type === INTERACTION_CALLED && path.length === 1) {
4649
+ return hasMemberEffectWhenCalled(literalNumberMembers, path[0], interaction, context);
4634
4650
  }
4635
4651
  return true;
4636
4652
  }
@@ -4648,12 +4664,12 @@ const UNKNOWN_LITERAL_STRING = new (class UnknownString extends ExpressionEntity
4648
4664
  }
4649
4665
  return UNKNOWN_EXPRESSION;
4650
4666
  }
4651
- hasEffectsWhenAccessedAtPath(path) {
4652
- return path.length > 1;
4653
- }
4654
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
4655
- if (path.length === 1) {
4656
- return hasMemberEffectWhenCalled(literalStringMembers, path[0], callOptions, context);
4667
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
4668
+ if (interaction.type === INTERACTION_ACCESSED) {
4669
+ return path.length > 1;
4670
+ }
4671
+ if (interaction.type === INTERACTION_CALLED && path.length === 1) {
4672
+ return hasMemberEffectWhenCalled(literalStringMembers, path[0], interaction, context);
4657
4673
  }
4658
4674
  return true;
4659
4675
  }
@@ -4666,17 +4682,13 @@ const returnsString = {
4666
4682
  };
4667
4683
  const stringReplace = {
4668
4684
  value: {
4669
- hasEffectsWhenCalled(callOptions, context) {
4670
- const arg1 = callOptions.args[1];
4671
- return (callOptions.args.length < 2 ||
4685
+ hasEffectsWhenCalled({ args }, context) {
4686
+ const arg1 = args[1];
4687
+ return (args.length < 2 ||
4672
4688
  (typeof arg1.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, {
4673
4689
  deoptimizeCache() { }
4674
4690
  }) === 'symbol' &&
4675
- arg1.hasEffectsWhenCalledAtPath(EMPTY_PATH, {
4676
- args: NO_ARGS,
4677
- thisParam: null,
4678
- withNew: false
4679
- }, context)));
4691
+ arg1.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_CALL, context)));
4680
4692
  },
4681
4693
  returns: UNKNOWN_LITERAL_STRING
4682
4694
  }
@@ -4760,12 +4772,12 @@ function getLiteralMembersForValue(value) {
4760
4772
  }
4761
4773
  return Object.create(null);
4762
4774
  }
4763
- function hasMemberEffectWhenCalled(members, memberName, callOptions, context) {
4775
+ function hasMemberEffectWhenCalled(members, memberName, interaction, context) {
4764
4776
  var _a, _b;
4765
4777
  if (typeof memberName !== 'string' || !members[memberName]) {
4766
4778
  return true;
4767
4779
  }
4768
- return ((_b = (_a = members[memberName]).hasEffectsWhenCalled) === null || _b === void 0 ? void 0 : _b.call(_a, callOptions, context)) || false;
4780
+ return ((_b = (_a = members[memberName]).hasEffectsWhenCalled) === null || _b === void 0 ? void 0 : _b.call(_a, interaction, context)) || false;
4769
4781
  }
4770
4782
  function getMemberReturnExpressionWhenCalled(members, memberName) {
4771
4783
  if (typeof memberName !== 'string' || !members[memberName])
@@ -5204,10 +5216,12 @@ const INCLUDE_PARAMETERS = 'variables';
5204
5216
  class NodeBase extends ExpressionEntity {
5205
5217
  constructor(esTreeNode, parent, parentScope) {
5206
5218
  super();
5207
- // Nodes can apply custom deoptimizations once they become part of the
5208
- // executed code. To do this, they must initialize this as false, implement
5209
- // applyDeoptimizations and call this from include and hasEffects if they
5210
- // have custom handlers
5219
+ /**
5220
+ * Nodes can apply custom deoptimizations once they become part of the
5221
+ * executed code. To do this, they must initialize this as false, implement
5222
+ * applyDeoptimizations and call this from include and hasEffects if they have
5223
+ * custom handlers
5224
+ */
5211
5225
  this.deoptimized = false;
5212
5226
  this.esTreeNode = esTreeNode;
5213
5227
  this.keys = keys[esTreeNode.type] || getAndCreateKeys(esTreeNode);
@@ -5263,6 +5277,10 @@ class NodeBase extends ExpressionEntity {
5263
5277
  }
5264
5278
  return false;
5265
5279
  }
5280
+ hasEffectsAsAssignmentTarget(context, _checkAccess) {
5281
+ return (this.hasEffects(context) ||
5282
+ this.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.assignmentInteraction, context));
5283
+ }
5266
5284
  include(context, includeChildrenRecursively, _options) {
5267
5285
  if (!this.deoptimized)
5268
5286
  this.applyDeoptimizations();
@@ -5281,6 +5299,9 @@ class NodeBase extends ExpressionEntity {
5281
5299
  }
5282
5300
  }
5283
5301
  }
5302
+ includeAsAssignmentTarget(context, includeChildrenRecursively, _deoptimizeAccess) {
5303
+ this.include(context, includeChildrenRecursively);
5304
+ }
5284
5305
  /**
5285
5306
  * Override to perform special initialisation steps after the scope is initialised
5286
5307
  */
@@ -5335,6 +5356,9 @@ class NodeBase extends ExpressionEntity {
5335
5356
  }
5336
5357
  }
5337
5358
  }
5359
+ setAssignedValue(value) {
5360
+ this.assignmentInteraction = { args: [value], thisArg: null, type: INTERACTION_ASSIGNED };
5361
+ }
5338
5362
  shouldBeIncluded(context) {
5339
5363
  return this.included || (!context.brokenFlow && this.hasEffects(createHasEffectsContext()));
5340
5364
  }
@@ -5363,9 +5387,9 @@ class NodeBase extends ExpressionEntity {
5363
5387
  }
5364
5388
 
5365
5389
  class SpreadElement extends NodeBase {
5366
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
5390
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
5367
5391
  if (path.length > 0) {
5368
- this.argument.deoptimizeThisOnEventAtPath(event, [UnknownKey, ...path], thisParameter, recursionTracker);
5392
+ this.argument.deoptimizeThisOnInteractionAtPath(interaction, [UnknownKey, ...path], recursionTracker);
5369
5393
  }
5370
5394
  }
5371
5395
  hasEffects(context) {
@@ -5376,7 +5400,7 @@ class SpreadElement extends NodeBase {
5376
5400
  return (this.argument.hasEffects(context) ||
5377
5401
  (propertyReadSideEffects &&
5378
5402
  (propertyReadSideEffects === 'always' ||
5379
- this.argument.hasEffectsWhenAccessedAtPath(UNKNOWN_PATH, context))));
5403
+ this.argument.hasEffectsOnInteractionAtPath(UNKNOWN_PATH, NODE_INTERACTION_UNKNOWN_ACCESS, context))));
5380
5404
  }
5381
5405
  applyDeoptimizations() {
5382
5406
  this.deoptimized = true;
@@ -5387,53 +5411,43 @@ class SpreadElement extends NodeBase {
5387
5411
  }
5388
5412
  }
5389
5413
 
5390
- const EVENT_ACCESSED = 0;
5391
- const EVENT_ASSIGNED = 1;
5392
- const EVENT_CALLED = 2;
5393
-
5394
5414
  class Method extends ExpressionEntity {
5395
5415
  constructor(description) {
5396
5416
  super();
5397
5417
  this.description = description;
5398
5418
  }
5399
- deoptimizeThisOnEventAtPath(event, path, thisParameter) {
5400
- if (event === EVENT_CALLED && path.length === 0 && this.description.mutatesSelfAsArray) {
5401
- thisParameter.deoptimizePath(UNKNOWN_INTEGER_PATH);
5419
+ deoptimizeThisOnInteractionAtPath({ type, thisArg }, path) {
5420
+ if (type === INTERACTION_CALLED && path.length === 0 && this.description.mutatesSelfAsArray) {
5421
+ thisArg.deoptimizePath(UNKNOWN_INTEGER_PATH);
5402
5422
  }
5403
5423
  }
5404
- getReturnExpressionWhenCalledAtPath(path, callOptions) {
5424
+ getReturnExpressionWhenCalledAtPath(path, { thisArg }) {
5405
5425
  if (path.length > 0) {
5406
5426
  return UNKNOWN_EXPRESSION;
5407
5427
  }
5408
5428
  return (this.description.returnsPrimitive ||
5409
5429
  (this.description.returns === 'self'
5410
- ? callOptions.thisParam || UNKNOWN_EXPRESSION
5430
+ ? thisArg || UNKNOWN_EXPRESSION
5411
5431
  : this.description.returns()));
5412
5432
  }
5413
- hasEffectsWhenAccessedAtPath(path) {
5414
- return path.length > 1;
5415
- }
5416
- hasEffectsWhenAssignedAtPath(path) {
5417
- return path.length > 0;
5418
- }
5419
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
5433
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
5420
5434
  var _a, _b;
5421
- if (path.length > 0 ||
5422
- (this.description.mutatesSelfAsArray === true &&
5423
- ((_a = callOptions.thisParam) === null || _a === void 0 ? void 0 : _a.hasEffectsWhenAssignedAtPath(UNKNOWN_INTEGER_PATH, context)))) {
5435
+ const { type } = interaction;
5436
+ if (path.length > (type === INTERACTION_ACCESSED ? 1 : 0)) {
5424
5437
  return true;
5425
5438
  }
5426
- if (!this.description.callsArgs) {
5427
- return false;
5428
- }
5429
- for (const argIndex of this.description.callsArgs) {
5430
- if ((_b = callOptions.args[argIndex]) === null || _b === void 0 ? void 0 : _b.hasEffectsWhenCalledAtPath(EMPTY_PATH, {
5431
- args: NO_ARGS,
5432
- thisParam: null,
5433
- withNew: false
5434
- }, context)) {
5439
+ if (type === INTERACTION_CALLED) {
5440
+ if (this.description.mutatesSelfAsArray === true &&
5441
+ ((_a = interaction.thisArg) === null || _a === void 0 ? void 0 : _a.hasEffectsOnInteractionAtPath(UNKNOWN_INTEGER_PATH, NODE_INTERACTION_UNKNOWN_ASSIGNMENT, context))) {
5435
5442
  return true;
5436
5443
  }
5444
+ if (this.description.callsArgs) {
5445
+ for (const argIndex of this.description.callsArgs) {
5446
+ if ((_b = interaction.args[argIndex]) === null || _b === void 0 ? void 0 : _b.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_CALL, context)) {
5447
+ return true;
5448
+ }
5449
+ }
5450
+ }
5437
5451
  }
5438
5452
  return false;
5439
5453
  }
@@ -5575,24 +5589,24 @@ class ObjectEntity extends ExpressionEntity {
5575
5589
  }
5576
5590
  (_a = this.prototypeExpression) === null || _a === void 0 ? void 0 : _a.deoptimizePath(path.length === 1 ? [...path, UnknownKey] : path);
5577
5591
  }
5578
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
5592
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
5579
5593
  var _a;
5580
5594
  const [key, ...subPath] = path;
5581
5595
  if (this.hasLostTrack ||
5582
5596
  // single paths that are deoptimized will not become getters or setters
5583
- ((event === EVENT_CALLED || path.length > 1) &&
5597
+ ((interaction.type === INTERACTION_CALLED || path.length > 1) &&
5584
5598
  (this.hasUnknownDeoptimizedProperty ||
5585
5599
  (typeof key === 'string' && this.deoptimizedPaths[key])))) {
5586
- thisParameter.deoptimizePath(UNKNOWN_PATH);
5600
+ interaction.thisArg.deoptimizePath(UNKNOWN_PATH);
5587
5601
  return;
5588
5602
  }
5589
- const [propertiesForExactMatchByKey, relevantPropertiesByKey, relevantUnmatchableProperties] = event === EVENT_CALLED || path.length > 1
5603
+ const [propertiesForExactMatchByKey, relevantPropertiesByKey, relevantUnmatchableProperties] = interaction.type === INTERACTION_CALLED || path.length > 1
5590
5604
  ? [
5591
5605
  this.propertiesAndGettersByKey,
5592
5606
  this.propertiesAndGettersByKey,
5593
5607
  this.unmatchablePropertiesAndGetters
5594
5608
  ]
5595
- : event === EVENT_ACCESSED
5609
+ : interaction.type === INTERACTION_ACCESSED
5596
5610
  ? [this.propertiesAndGettersByKey, this.gettersByKey, this.unmatchableGetters]
5597
5611
  : [this.propertiesAndSettersByKey, this.settersByKey, this.unmatchableSetters];
5598
5612
  if (typeof key === 'string') {
@@ -5600,20 +5614,20 @@ class ObjectEntity extends ExpressionEntity {
5600
5614
  const properties = relevantPropertiesByKey[key];
5601
5615
  if (properties) {
5602
5616
  for (const property of properties) {
5603
- property.deoptimizeThisOnEventAtPath(event, subPath, thisParameter, recursionTracker);
5617
+ property.deoptimizeThisOnInteractionAtPath(interaction, subPath, recursionTracker);
5604
5618
  }
5605
5619
  }
5606
5620
  if (!this.immutable) {
5607
- this.thisParametersToBeDeoptimized.add(thisParameter);
5621
+ this.thisParametersToBeDeoptimized.add(interaction.thisArg);
5608
5622
  }
5609
5623
  return;
5610
5624
  }
5611
5625
  for (const property of relevantUnmatchableProperties) {
5612
- property.deoptimizeThisOnEventAtPath(event, subPath, thisParameter, recursionTracker);
5626
+ property.deoptimizeThisOnInteractionAtPath(interaction, subPath, recursionTracker);
5613
5627
  }
5614
5628
  if (INTEGER_REG_EXP.test(key)) {
5615
5629
  for (const property of this.unknownIntegerProps) {
5616
- property.deoptimizeThisOnEventAtPath(event, subPath, thisParameter, recursionTracker);
5630
+ property.deoptimizeThisOnInteractionAtPath(interaction, subPath, recursionTracker);
5617
5631
  }
5618
5632
  }
5619
5633
  }
@@ -5622,17 +5636,17 @@ class ObjectEntity extends ExpressionEntity {
5622
5636
  relevantUnmatchableProperties
5623
5637
  ])) {
5624
5638
  for (const property of properties) {
5625
- property.deoptimizeThisOnEventAtPath(event, subPath, thisParameter, recursionTracker);
5639
+ property.deoptimizeThisOnInteractionAtPath(interaction, subPath, recursionTracker);
5626
5640
  }
5627
5641
  }
5628
5642
  for (const property of this.unknownIntegerProps) {
5629
- property.deoptimizeThisOnEventAtPath(event, subPath, thisParameter, recursionTracker);
5643
+ property.deoptimizeThisOnInteractionAtPath(interaction, subPath, recursionTracker);
5630
5644
  }
5631
5645
  }
5632
5646
  if (!this.immutable) {
5633
- this.thisParametersToBeDeoptimized.add(thisParameter);
5647
+ this.thisParametersToBeDeoptimized.add(interaction.thisArg);
5634
5648
  }
5635
- (_a = this.prototypeExpression) === null || _a === void 0 ? void 0 : _a.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
5649
+ (_a = this.prototypeExpression) === null || _a === void 0 ? void 0 : _a.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
5636
5650
  }
5637
5651
  getLiteralValueAtPath(path, recursionTracker, origin) {
5638
5652
  if (path.length === 0) {
@@ -5651,79 +5665,29 @@ class ObjectEntity extends ExpressionEntity {
5651
5665
  }
5652
5666
  return UnknownValue;
5653
5667
  }
5654
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
5668
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
5655
5669
  if (path.length === 0) {
5656
5670
  return UNKNOWN_EXPRESSION;
5657
5671
  }
5658
- const key = path[0];
5672
+ const [key, ...subPath] = path;
5659
5673
  const expressionAtPath = this.getMemberExpressionAndTrackDeopt(key, origin);
5660
5674
  if (expressionAtPath) {
5661
- return expressionAtPath.getReturnExpressionWhenCalledAtPath(path.slice(1), callOptions, recursionTracker, origin);
5675
+ return expressionAtPath.getReturnExpressionWhenCalledAtPath(subPath, interaction, recursionTracker, origin);
5662
5676
  }
5663
5677
  if (this.prototypeExpression) {
5664
- return this.prototypeExpression.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
5678
+ return this.prototypeExpression.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
5665
5679
  }
5666
5680
  return UNKNOWN_EXPRESSION;
5667
5681
  }
5668
- hasEffectsWhenAccessedAtPath(path, context) {
5669
- const [key, ...subPath] = path;
5670
- if (path.length > 1) {
5671
- if (typeof key !== 'string') {
5672
- return true;
5673
- }
5674
- const expressionAtPath = this.getMemberExpression(key);
5675
- if (expressionAtPath) {
5676
- return expressionAtPath.hasEffectsWhenAccessedAtPath(subPath, context);
5677
- }
5678
- if (this.prototypeExpression) {
5679
- return this.prototypeExpression.hasEffectsWhenAccessedAtPath(path, context);
5680
- }
5681
- return true;
5682
- }
5683
- if (this.hasLostTrack)
5684
- return true;
5685
- if (typeof key === 'string') {
5686
- if (this.propertiesAndGettersByKey[key]) {
5687
- const getters = this.gettersByKey[key];
5688
- if (getters) {
5689
- for (const getter of getters) {
5690
- if (getter.hasEffectsWhenAccessedAtPath(subPath, context))
5691
- return true;
5692
- }
5693
- }
5694
- return false;
5695
- }
5696
- for (const getter of this.unmatchableGetters) {
5697
- if (getter.hasEffectsWhenAccessedAtPath(subPath, context)) {
5698
- return true;
5699
- }
5700
- }
5701
- }
5702
- else {
5703
- for (const getters of Object.values(this.gettersByKey).concat([this.unmatchableGetters])) {
5704
- for (const getter of getters) {
5705
- if (getter.hasEffectsWhenAccessedAtPath(subPath, context))
5706
- return true;
5707
- }
5708
- }
5709
- }
5710
- if (this.prototypeExpression) {
5711
- return this.prototypeExpression.hasEffectsWhenAccessedAtPath(path, context);
5712
- }
5713
- return false;
5714
- }
5715
- hasEffectsWhenAssignedAtPath(path, context) {
5682
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
5716
5683
  const [key, ...subPath] = path;
5717
- if (path.length > 1) {
5718
- if (typeof key !== 'string') {
5719
- return true;
5720
- }
5684
+ if (subPath.length || interaction.type === INTERACTION_CALLED) {
5721
5685
  const expressionAtPath = this.getMemberExpression(key);
5722
5686
  if (expressionAtPath) {
5723
- return expressionAtPath.hasEffectsWhenAssignedAtPath(subPath, context);
5687
+ return expressionAtPath.hasEffectsOnInteractionAtPath(subPath, interaction, context);
5724
5688
  }
5725
5689
  if (this.prototypeExpression) {
5726
- return this.prototypeExpression.hasEffectsWhenAssignedAtPath(path, context);
5690
+ return this.prototypeExpression.hasEffectsOnInteractionAtPath(path, interaction, context);
5727
5691
  }
5728
5692
  return true;
5729
5693
  }
@@ -5731,47 +5695,39 @@ class ObjectEntity extends ExpressionEntity {
5731
5695
  return false;
5732
5696
  if (this.hasLostTrack)
5733
5697
  return true;
5698
+ const [propertiesAndAccessorsByKey, accessorsByKey, unmatchableAccessors] = interaction.type === INTERACTION_ACCESSED
5699
+ ? [this.propertiesAndGettersByKey, this.gettersByKey, this.unmatchableGetters]
5700
+ : [this.propertiesAndSettersByKey, this.settersByKey, this.unmatchableSetters];
5734
5701
  if (typeof key === 'string') {
5735
- if (this.propertiesAndSettersByKey[key]) {
5736
- const setters = this.settersByKey[key];
5737
- if (setters) {
5738
- for (const setter of setters) {
5739
- if (setter.hasEffectsWhenAssignedAtPath(subPath, context))
5702
+ if (propertiesAndAccessorsByKey[key]) {
5703
+ const accessors = accessorsByKey[key];
5704
+ if (accessors) {
5705
+ for (const accessor of accessors) {
5706
+ if (accessor.hasEffectsOnInteractionAtPath(subPath, interaction, context))
5740
5707
  return true;
5741
5708
  }
5742
5709
  }
5743
5710
  return false;
5744
5711
  }
5745
- for (const property of this.unmatchableSetters) {
5746
- if (property.hasEffectsWhenAssignedAtPath(subPath, context)) {
5712
+ for (const accessor of unmatchableAccessors) {
5713
+ if (accessor.hasEffectsOnInteractionAtPath(subPath, interaction, context)) {
5747
5714
  return true;
5748
5715
  }
5749
5716
  }
5750
5717
  }
5751
5718
  else {
5752
- for (const setters of Object.values(this.settersByKey).concat([this.unmatchableSetters])) {
5753
- for (const setter of setters) {
5754
- if (setter.hasEffectsWhenAssignedAtPath(subPath, context))
5719
+ for (const accessors of Object.values(accessorsByKey).concat([unmatchableAccessors])) {
5720
+ for (const accessor of accessors) {
5721
+ if (accessor.hasEffectsOnInteractionAtPath(subPath, interaction, context))
5755
5722
  return true;
5756
5723
  }
5757
5724
  }
5758
5725
  }
5759
5726
  if (this.prototypeExpression) {
5760
- return this.prototypeExpression.hasEffectsWhenAssignedAtPath(path, context);
5727
+ return this.prototypeExpression.hasEffectsOnInteractionAtPath(path, interaction, context);
5761
5728
  }
5762
5729
  return false;
5763
5730
  }
5764
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
5765
- const key = path[0];
5766
- const expressionAtPath = this.getMemberExpression(key);
5767
- if (expressionAtPath) {
5768
- return expressionAtPath.hasEffectsWhenCalledAtPath(path.slice(1), callOptions, context);
5769
- }
5770
- if (this.prototypeExpression) {
5771
- return this.prototypeExpression.hasEffectsWhenCalledAtPath(path, callOptions, context);
5772
- }
5773
- return true;
5774
- }
5775
5731
  buildPropertyMaps(properties) {
5776
5732
  const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchableGetters, unmatchableSetters } = this;
5777
5733
  const unmatchablePropertiesAndSetters = [];
@@ -5877,9 +5833,9 @@ const isInteger = (prop) => typeof prop === 'string' && /^\d+$/.test(prop);
5877
5833
  // properties as we do not expect new builtin properties to be numbers, this
5878
5834
  // will improve tree-shaking for out-of-bounds array properties
5879
5835
  const OBJECT_PROTOTYPE_FALLBACK = new (class ObjectPrototypeFallbackExpression extends ExpressionEntity {
5880
- deoptimizeThisOnEventAtPath(event, path, thisParameter) {
5881
- if (event === EVENT_CALLED && path.length === 1 && !isInteger(path[0])) {
5882
- thisParameter.deoptimizePath(UNKNOWN_PATH);
5836
+ deoptimizeThisOnInteractionAtPath({ type, thisArg }, path) {
5837
+ if (type === INTERACTION_CALLED && path.length === 1 && !isInteger(path[0])) {
5838
+ thisArg.deoptimizePath(UNKNOWN_PATH);
5883
5839
  }
5884
5840
  }
5885
5841
  getLiteralValueAtPath(path) {
@@ -5888,11 +5844,8 @@ const OBJECT_PROTOTYPE_FALLBACK = new (class ObjectPrototypeFallbackExpression e
5888
5844
  // "undefined"
5889
5845
  return path.length === 1 && isInteger(path[0]) ? undefined : UnknownValue;
5890
5846
  }
5891
- hasEffectsWhenAccessedAtPath(path) {
5892
- return path.length > 1;
5893
- }
5894
- hasEffectsWhenAssignedAtPath(path) {
5895
- return path.length > 1;
5847
+ hasEffectsOnInteractionAtPath(path, { type }) {
5848
+ return path.length > 1 || type === INTERACTION_CALLED;
5896
5849
  }
5897
5850
  })();
5898
5851
  const OBJECT_PROTOTYPE = new ObjectEntity({
@@ -6046,23 +5999,17 @@ class ArrayExpression extends NodeBase {
6046
5999
  deoptimizePath(path) {
6047
6000
  this.getObjectEntity().deoptimizePath(path);
6048
6001
  }
6049
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
6050
- this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
6002
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
6003
+ this.getObjectEntity().deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
6051
6004
  }
6052
6005
  getLiteralValueAtPath(path, recursionTracker, origin) {
6053
6006
  return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
6054
6007
  }
6055
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
6056
- return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
6008
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
6009
+ return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
6057
6010
  }
6058
- hasEffectsWhenAccessedAtPath(path, context) {
6059
- return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
6060
- }
6061
- hasEffectsWhenAssignedAtPath(path, context) {
6062
- return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
6063
- }
6064
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
6065
- return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
6011
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
6012
+ return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
6066
6013
  }
6067
6014
  applyDeoptimizations() {
6068
6015
  this.deoptimized = true;
@@ -6127,9 +6074,9 @@ class ArrayPattern extends NodeBase {
6127
6074
  }
6128
6075
  }
6129
6076
  // Patterns are only checked at the emtpy path at the moment
6130
- hasEffectsWhenAssignedAtPath(_path, context) {
6077
+ hasEffectsOnInteractionAtPath(_path, interaction, context) {
6131
6078
  for (const element of this.elements) {
6132
- if (element === null || element === void 0 ? void 0 : element.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context))
6079
+ if (element === null || element === void 0 ? void 0 : element.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context))
6133
6080
  return true;
6134
6081
  }
6135
6082
  return false;
@@ -6188,11 +6135,11 @@ class LocalVariable extends Variable {
6188
6135
  (_b = this.init) === null || _b === void 0 ? void 0 : _b.deoptimizePath(path);
6189
6136
  }
6190
6137
  }
6191
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
6138
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
6192
6139
  if (this.isReassigned || !this.init) {
6193
- return thisParameter.deoptimizePath(UNKNOWN_PATH);
6140
+ return interaction.thisArg.deoptimizePath(UNKNOWN_PATH);
6194
6141
  }
6195
- recursionTracker.withTrackedEntityAtPath(path, this.init, () => this.init.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker), undefined);
6142
+ recursionTracker.withTrackedEntityAtPath(path, this.init, () => this.init.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker), undefined);
6196
6143
  }
6197
6144
  getLiteralValueAtPath(path, recursionTracker, origin) {
6198
6145
  if (this.isReassigned || !this.init) {
@@ -6203,39 +6150,40 @@ class LocalVariable extends Variable {
6203
6150
  return this.init.getLiteralValueAtPath(path, recursionTracker, origin);
6204
6151
  }, UnknownValue);
6205
6152
  }
6206
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
6153
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
6207
6154
  if (this.isReassigned || !this.init) {
6208
6155
  return UNKNOWN_EXPRESSION;
6209
6156
  }
6210
6157
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6211
6158
  this.expressionsToBeDeoptimized.push(origin);
6212
- return this.init.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
6159
+ return this.init.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
6213
6160
  }, UNKNOWN_EXPRESSION);
6214
6161
  }
6215
- hasEffectsWhenAccessedAtPath(path, context) {
6216
- if (this.isReassigned)
6217
- return true;
6218
- return (this.init &&
6219
- !context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
6220
- this.init.hasEffectsWhenAccessedAtPath(path, context));
6221
- }
6222
- hasEffectsWhenAssignedAtPath(path, context) {
6223
- if (this.included)
6224
- return true;
6225
- if (path.length === 0)
6226
- return false;
6227
- if (this.isReassigned)
6228
- return true;
6229
- return (this.init &&
6230
- !context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
6231
- this.init.hasEffectsWhenAssignedAtPath(path, context));
6232
- }
6233
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
6234
- if (this.isReassigned)
6235
- return true;
6236
- return (this.init &&
6237
- !(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
6238
- this.init.hasEffectsWhenCalledAtPath(path, callOptions, context));
6162
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
6163
+ switch (interaction.type) {
6164
+ case INTERACTION_ACCESSED:
6165
+ if (this.isReassigned)
6166
+ return true;
6167
+ return (this.init &&
6168
+ !context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
6169
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6170
+ case INTERACTION_ASSIGNED:
6171
+ if (this.included)
6172
+ return true;
6173
+ if (path.length === 0)
6174
+ return false;
6175
+ if (this.isReassigned)
6176
+ return true;
6177
+ return (this.init &&
6178
+ !context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
6179
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6180
+ case INTERACTION_CALLED:
6181
+ if (this.isReassigned)
6182
+ return true;
6183
+ return (this.init &&
6184
+ !(interaction.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this) &&
6185
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6186
+ }
6239
6187
  }
6240
6188
  include() {
6241
6189
  if (!this.included) {
@@ -6590,9 +6538,9 @@ const PF = {
6590
6538
  const MUTATES_ARG_WITHOUT_ACCESSOR = {
6591
6539
  __proto__: null,
6592
6540
  [ValueProperties]: {
6593
- hasEffectsWhenCalled(callOptions, context) {
6594
- return (!callOptions.args.length ||
6595
- callOptions.args[0].hasEffectsWhenAssignedAtPath(UNKNOWN_NON_ACCESSOR_PATH, context));
6541
+ hasEffectsWhenCalled({ args }, context) {
6542
+ return (!args.length ||
6543
+ args[0].hasEffectsOnInteractionAtPath(UNKNOWN_NON_ACCESSOR_PATH, NODE_INTERACTION_UNKNOWN_ASSIGNMENT, context));
6596
6544
  }
6597
6545
  }
6598
6546
  };
@@ -7433,16 +7381,21 @@ class GlobalVariable extends Variable {
7433
7381
  getLiteralValueAtPath(path, _recursionTracker, _origin) {
7434
7382
  return getGlobalAtPath([this.name, ...path]) ? UnknownTruthyValue : UnknownValue;
7435
7383
  }
7436
- hasEffectsWhenAccessedAtPath(path) {
7437
- if (path.length === 0) {
7438
- // Technically, "undefined" is a global variable of sorts
7439
- return this.name !== 'undefined' && !getGlobalAtPath([this.name]);
7384
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
7385
+ switch (interaction.type) {
7386
+ case INTERACTION_ACCESSED:
7387
+ if (path.length === 0) {
7388
+ // Technically, "undefined" is a global variable of sorts
7389
+ return this.name !== 'undefined' && !getGlobalAtPath([this.name]);
7390
+ }
7391
+ return !getGlobalAtPath([this.name, ...path].slice(0, -1));
7392
+ case INTERACTION_ASSIGNED:
7393
+ return true;
7394
+ case INTERACTION_CALLED: {
7395
+ const globalAtPath = getGlobalAtPath([this.name, ...path]);
7396
+ return !globalAtPath || globalAtPath.hasEffectsWhenCalled(interaction, context);
7397
+ }
7440
7398
  }
7441
- return !getGlobalAtPath([this.name, ...path].slice(0, -1));
7442
- }
7443
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
7444
- const globalAtPath = getGlobalAtPath([this.name, ...path]);
7445
- return !globalAtPath || globalAtPath.hasEffectsWhenCalled(callOptions, context);
7446
7399
  }
7447
7400
  }
7448
7401
 
@@ -7510,16 +7463,16 @@ class Identifier extends NodeBase {
7510
7463
  // Identifier as property that might be deoptimized by default
7511
7464
  (_a = this.variable) === null || _a === void 0 ? void 0 : _a.deoptimizePath(path);
7512
7465
  }
7513
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
7514
- this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
7466
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
7467
+ this.variable.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
7515
7468
  }
7516
7469
  getLiteralValueAtPath(path, recursionTracker, origin) {
7517
7470
  return this.getVariableRespectingTDZ().getLiteralValueAtPath(path, recursionTracker, origin);
7518
7471
  }
7519
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
7520
- return this.getVariableRespectingTDZ().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
7472
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
7473
+ return this.getVariableRespectingTDZ().getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
7521
7474
  }
7522
- hasEffects() {
7475
+ hasEffects(context) {
7523
7476
  if (!this.deoptimized)
7524
7477
  this.applyDeoptimizations();
7525
7478
  if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
@@ -7527,17 +7480,18 @@ class Identifier extends NodeBase {
7527
7480
  }
7528
7481
  return (this.context.options.treeshake.unknownGlobalSideEffects &&
7529
7482
  this.variable instanceof GlobalVariable &&
7530
- this.variable.hasEffectsWhenAccessedAtPath(EMPTY_PATH));
7531
- }
7532
- hasEffectsWhenAccessedAtPath(path, context) {
7533
- return (this.variable !== null &&
7534
- this.getVariableRespectingTDZ().hasEffectsWhenAccessedAtPath(path, context));
7483
+ this.variable.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_ACCESS, context));
7535
7484
  }
7536
- hasEffectsWhenAssignedAtPath(path, context) {
7537
- return (path.length > 0 ? this.getVariableRespectingTDZ() : this.variable).hasEffectsWhenAssignedAtPath(path, context);
7538
- }
7539
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
7540
- return this.getVariableRespectingTDZ().hasEffectsWhenCalledAtPath(path, callOptions, context);
7485
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
7486
+ switch (interaction.type) {
7487
+ case INTERACTION_ACCESSED:
7488
+ return (this.variable !== null &&
7489
+ this.getVariableRespectingTDZ().hasEffectsOnInteractionAtPath(path, interaction, context));
7490
+ case INTERACTION_ASSIGNED:
7491
+ return (path.length > 0 ? this.getVariableRespectingTDZ() : this.variable).hasEffectsOnInteractionAtPath(path, interaction, context);
7492
+ case INTERACTION_CALLED:
7493
+ return this.getVariableRespectingTDZ().hasEffectsOnInteractionAtPath(path, interaction, context);
7494
+ }
7541
7495
  }
7542
7496
  include() {
7543
7497
  if (!this.deoptimized)
@@ -7897,8 +7851,9 @@ class RestElement extends NodeBase {
7897
7851
  deoptimizePath(path) {
7898
7852
  path.length === 0 && this.argument.deoptimizePath(EMPTY_PATH);
7899
7853
  }
7900
- hasEffectsWhenAssignedAtPath(path, context) {
7901
- return path.length > 0 || this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
7854
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
7855
+ return (path.length > 0 ||
7856
+ this.argument.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
7902
7857
  }
7903
7858
  markDeclarationReached() {
7904
7859
  this.argument.markDeclarationReached();
@@ -7926,17 +7881,17 @@ class FunctionBase extends NodeBase {
7926
7881
  this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
7927
7882
  }
7928
7883
  }
7929
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
7884
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
7930
7885
  if (path.length > 0) {
7931
- this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
7886
+ this.getObjectEntity().deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
7932
7887
  }
7933
7888
  }
7934
7889
  getLiteralValueAtPath(path, recursionTracker, origin) {
7935
7890
  return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
7936
7891
  }
7937
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
7892
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
7938
7893
  if (path.length > 0) {
7939
- return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
7894
+ return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
7940
7895
  }
7941
7896
  if (this.async) {
7942
7897
  if (!this.deoptimizedReturn) {
@@ -7948,24 +7903,18 @@ class FunctionBase extends NodeBase {
7948
7903
  }
7949
7904
  return this.scope.getReturnExpression();
7950
7905
  }
7951
- hasEffectsWhenAccessedAtPath(path, context) {
7952
- return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
7953
- }
7954
- hasEffectsWhenAssignedAtPath(path, context) {
7955
- return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
7956
- }
7957
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
7958
- if (path.length > 0) {
7959
- return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
7906
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
7907
+ if (path.length > 0 || interaction.type !== INTERACTION_CALLED) {
7908
+ return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
7960
7909
  }
7961
7910
  if (this.async) {
7962
7911
  const { propertyReadSideEffects } = this.context.options
7963
7912
  .treeshake;
7964
7913
  const returnExpression = this.scope.getReturnExpression();
7965
- if (returnExpression.hasEffectsWhenCalledAtPath(['then'], { args: NO_ARGS, thisParam: null, withNew: false }, context) ||
7914
+ if (returnExpression.hasEffectsOnInteractionAtPath(['then'], NODE_INTERACTION_UNKNOWN_CALL, context) ||
7966
7915
  (propertyReadSideEffects &&
7967
7916
  (propertyReadSideEffects === 'always' ||
7968
- returnExpression.hasEffectsWhenAccessedAtPath(['then'], context)))) {
7917
+ returnExpression.hasEffectsOnInteractionAtPath(['then'], NODE_INTERACTION_UNKNOWN_ACCESS, context)))) {
7969
7918
  return true;
7970
7919
  }
7971
7920
  }
@@ -8019,20 +7968,22 @@ class ArrowFunctionExpression extends FunctionBase {
8019
7968
  this.applyDeoptimizations();
8020
7969
  return false;
8021
7970
  }
8022
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
8023
- if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
7971
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
7972
+ if (super.hasEffectsOnInteractionAtPath(path, interaction, context))
8024
7973
  return true;
8025
- const { ignore, brokenFlow } = context;
8026
- context.ignore = {
8027
- breaks: false,
8028
- continues: false,
8029
- labels: new Set(),
8030
- returnYield: true
8031
- };
8032
- if (this.body.hasEffects(context))
8033
- return true;
8034
- context.ignore = ignore;
8035
- context.brokenFlow = brokenFlow;
7974
+ if (interaction.type === INTERACTION_CALLED) {
7975
+ const { ignore, brokenFlow } = context;
7976
+ context.ignore = {
7977
+ breaks: false,
7978
+ continues: false,
7979
+ labels: new Set(),
7980
+ returnYield: true
7981
+ };
7982
+ if (this.body.hasEffects(context))
7983
+ return true;
7984
+ context.ignore = ignore;
7985
+ context.brokenFlow = brokenFlow;
7986
+ }
8036
7987
  return false;
8037
7988
  }
8038
7989
  include(context, includeChildrenRecursively) {
@@ -8118,11 +8069,12 @@ class ObjectPattern extends NodeBase {
8118
8069
  }
8119
8070
  }
8120
8071
  }
8121
- hasEffectsWhenAssignedAtPath(path, context) {
8122
- if (path.length > 0)
8123
- return true;
8072
+ hasEffectsOnInteractionAtPath(
8073
+ // At the moment, this is only triggered for assignment left-hand sides,
8074
+ // where the path is empty
8075
+ _path, interaction, context) {
8124
8076
  for (const property of this.properties) {
8125
- if (property.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context))
8077
+ if (property.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context))
8126
8078
  return true;
8127
8079
  }
8128
8080
  return false;
@@ -8136,75 +8088,78 @@ class ObjectPattern extends NodeBase {
8136
8088
 
8137
8089
  class AssignmentExpression extends NodeBase {
8138
8090
  hasEffects(context) {
8139
- if (!this.deoptimized)
8091
+ const { deoptimized, left, right } = this;
8092
+ if (!deoptimized)
8140
8093
  this.applyDeoptimizations();
8141
- return (this.right.hasEffects(context) ||
8142
- this.left.hasEffects(context) ||
8143
- this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context));
8094
+ // MemberExpressions do not access the property before assignments if the
8095
+ // operator is '='.
8096
+ return (right.hasEffects(context) || left.hasEffectsAsAssignmentTarget(context, this.operator !== '='));
8144
8097
  }
8145
- hasEffectsWhenAccessedAtPath(path, context) {
8146
- return path.length > 0 && this.right.hasEffectsWhenAccessedAtPath(path, context);
8098
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
8099
+ return this.right.hasEffectsOnInteractionAtPath(path, interaction, context);
8147
8100
  }
8148
8101
  include(context, includeChildrenRecursively) {
8149
- if (!this.deoptimized)
8102
+ const { deoptimized, left, right, operator } = this;
8103
+ if (!deoptimized)
8150
8104
  this.applyDeoptimizations();
8151
8105
  this.included = true;
8152
- let hasEffectsContext;
8153
8106
  if (includeChildrenRecursively ||
8154
- this.operator !== '=' ||
8155
- this.left.included ||
8156
- ((hasEffectsContext = createHasEffectsContext()),
8157
- this.left.hasEffects(hasEffectsContext) ||
8158
- this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, hasEffectsContext))) {
8159
- this.left.include(context, includeChildrenRecursively);
8107
+ operator !== '=' ||
8108
+ left.included ||
8109
+ left.hasEffectsAsAssignmentTarget(createHasEffectsContext(), false)) {
8110
+ left.includeAsAssignmentTarget(context, includeChildrenRecursively, operator !== '=');
8160
8111
  }
8161
- this.right.include(context, includeChildrenRecursively);
8112
+ right.include(context, includeChildrenRecursively);
8113
+ }
8114
+ initialise() {
8115
+ this.left.setAssignedValue(this.right);
8162
8116
  }
8163
8117
  render(code, options, { preventASI, renderedParentType, renderedSurroundingElement } = BLANK) {
8164
- if (this.left.included) {
8165
- this.left.render(code, options);
8166
- this.right.render(code, options);
8118
+ const { left, right, start, end, parent } = this;
8119
+ if (left.included) {
8120
+ left.render(code, options);
8121
+ right.render(code, options);
8167
8122
  }
8168
8123
  else {
8169
- const inclusionStart = findNonWhiteSpace(code.original, findFirstOccurrenceOutsideComment(code.original, '=', this.left.end) + 1);
8170
- code.remove(this.start, inclusionStart);
8124
+ const inclusionStart = findNonWhiteSpace(code.original, findFirstOccurrenceOutsideComment(code.original, '=', left.end) + 1);
8125
+ code.remove(start, inclusionStart);
8171
8126
  if (preventASI) {
8172
- removeLineBreaks(code, inclusionStart, this.right.start);
8127
+ removeLineBreaks(code, inclusionStart, right.start);
8173
8128
  }
8174
- this.right.render(code, options, {
8175
- renderedParentType: renderedParentType || this.parent.type,
8176
- renderedSurroundingElement: renderedSurroundingElement || this.parent.type
8129
+ right.render(code, options, {
8130
+ renderedParentType: renderedParentType || parent.type,
8131
+ renderedSurroundingElement: renderedSurroundingElement || parent.type
8177
8132
  });
8178
8133
  }
8179
8134
  if (options.format === 'system') {
8180
- if (this.left instanceof Identifier) {
8181
- const variable = this.left.variable;
8135
+ if (left instanceof Identifier) {
8136
+ const variable = left.variable;
8182
8137
  const exportNames = options.exportNamesByVariable.get(variable);
8183
8138
  if (exportNames) {
8184
8139
  if (exportNames.length === 1) {
8185
- renderSystemExportExpression(variable, this.start, this.end, code, options);
8140
+ renderSystemExportExpression(variable, start, end, code, options);
8186
8141
  }
8187
8142
  else {
8188
- renderSystemExportSequenceAfterExpression(variable, this.start, this.end, this.parent.type !== ExpressionStatement$1, code, options);
8143
+ renderSystemExportSequenceAfterExpression(variable, start, end, parent.type !== ExpressionStatement$1, code, options);
8189
8144
  }
8190
8145
  return;
8191
8146
  }
8192
8147
  }
8193
8148
  else {
8194
8149
  const systemPatternExports = [];
8195
- this.left.addExportedVariables(systemPatternExports, options.exportNamesByVariable);
8150
+ left.addExportedVariables(systemPatternExports, options.exportNamesByVariable);
8196
8151
  if (systemPatternExports.length > 0) {
8197
- renderSystemExportFunction(systemPatternExports, this.start, this.end, renderedSurroundingElement === ExpressionStatement$1, code, options);
8152
+ renderSystemExportFunction(systemPatternExports, start, end, renderedSurroundingElement === ExpressionStatement$1, code, options);
8198
8153
  return;
8199
8154
  }
8200
8155
  }
8201
8156
  }
8202
- if (this.left.included &&
8203
- this.left instanceof ObjectPattern &&
8157
+ if (left.included &&
8158
+ left instanceof ObjectPattern &&
8204
8159
  (renderedSurroundingElement === ExpressionStatement$1 ||
8205
8160
  renderedSurroundingElement === ArrowFunctionExpression$1)) {
8206
- code.appendRight(this.start, '(');
8207
- code.prependLeft(this.end, ')');
8161
+ code.appendRight(start, '(');
8162
+ code.prependLeft(end, ')');
8208
8163
  }
8209
8164
  }
8210
8165
  applyDeoptimizations() {
@@ -8225,27 +8180,15 @@ class AssignmentPattern extends NodeBase {
8225
8180
  deoptimizePath(path) {
8226
8181
  path.length === 0 && this.left.deoptimizePath(path);
8227
8182
  }
8228
- hasEffectsWhenAssignedAtPath(path, context) {
8229
- return path.length > 0 || this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
8230
- }
8231
- include(context, includeChildrenRecursively) {
8232
- if (!this.deoptimized)
8233
- this.applyDeoptimizations();
8234
- this.included = true;
8235
- this.left.include(context, includeChildrenRecursively);
8236
- this.right.include(context, includeChildrenRecursively);
8183
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
8184
+ return (path.length > 0 || this.left.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
8237
8185
  }
8238
8186
  markDeclarationReached() {
8239
8187
  this.left.markDeclarationReached();
8240
8188
  }
8241
8189
  render(code, options, { isShorthandProperty } = BLANK) {
8242
8190
  this.left.render(code, options, { isShorthandProperty });
8243
- if (this.right.included) {
8244
- this.right.render(code, options);
8245
- }
8246
- else {
8247
- code.remove(this.left.end, this.end);
8248
- }
8191
+ this.right.render(code, options);
8249
8192
  }
8250
8193
  applyDeoptimizations() {
8251
8194
  this.deoptimized = true;
@@ -8259,14 +8202,8 @@ class ArgumentsVariable extends LocalVariable {
8259
8202
  constructor(context) {
8260
8203
  super('arguments', null, UNKNOWN_EXPRESSION, context);
8261
8204
  }
8262
- hasEffectsWhenAccessedAtPath(path) {
8263
- return path.length > 1;
8264
- }
8265
- hasEffectsWhenAssignedAtPath() {
8266
- return true;
8267
- }
8268
- hasEffectsWhenCalledAtPath() {
8269
- return true;
8205
+ hasEffectsOnInteractionAtPath(path, { type }) {
8206
+ return type !== INTERACTION_ACCESSED || path.length > 1;
8270
8207
  }
8271
8208
  }
8272
8209
 
@@ -8282,8 +8219,8 @@ class ThisVariable extends LocalVariable {
8282
8219
  for (const path of this.deoptimizedPaths) {
8283
8220
  entity.deoptimizePath(path);
8284
8221
  }
8285
- for (const thisDeoptimization of this.thisDeoptimizationList) {
8286
- this.applyThisDeoptimizationEvent(entity, thisDeoptimization);
8222
+ for (const { interaction, path } of this.thisDeoptimizationList) {
8223
+ entity.deoptimizeThisOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
8287
8224
  }
8288
8225
  this.entitiesToBeDeoptimized.add(entity);
8289
8226
  }
@@ -8297,29 +8234,21 @@ class ThisVariable extends LocalVariable {
8297
8234
  entity.deoptimizePath(path);
8298
8235
  }
8299
8236
  }
8300
- deoptimizeThisOnEventAtPath(event, path, thisParameter) {
8237
+ deoptimizeThisOnInteractionAtPath(interaction, path) {
8301
8238
  const thisDeoptimization = {
8302
- event,
8303
- path,
8304
- thisParameter
8239
+ interaction,
8240
+ path
8305
8241
  };
8306
- if (!this.thisDeoptimizations.trackEntityAtPathAndGetIfTracked(path, event, thisParameter)) {
8242
+ if (!this.thisDeoptimizations.trackEntityAtPathAndGetIfTracked(path, interaction.type, interaction.thisArg)) {
8307
8243
  for (const entity of this.entitiesToBeDeoptimized) {
8308
- this.applyThisDeoptimizationEvent(entity, thisDeoptimization);
8244
+ entity.deoptimizeThisOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
8309
8245
  }
8310
8246
  this.thisDeoptimizationList.push(thisDeoptimization);
8311
8247
  }
8312
8248
  }
8313
- hasEffectsWhenAccessedAtPath(path, context) {
8314
- return (this.getInit(context).hasEffectsWhenAccessedAtPath(path, context) ||
8315
- super.hasEffectsWhenAccessedAtPath(path, context));
8316
- }
8317
- hasEffectsWhenAssignedAtPath(path, context) {
8318
- return (this.getInit(context).hasEffectsWhenAssignedAtPath(path, context) ||
8319
- super.hasEffectsWhenAssignedAtPath(path, context));
8320
- }
8321
- applyThisDeoptimizationEvent(entity, { event, path, thisParameter }) {
8322
- entity.deoptimizeThisOnEventAtPath(event, path, thisParameter === this ? entity : thisParameter, SHARED_RECURSION_TRACKER);
8249
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
8250
+ return (this.getInit(context).hasEffectsOnInteractionAtPath(path, interaction, context) ||
8251
+ super.hasEffectsOnInteractionAtPath(path, interaction, context));
8323
8252
  }
8324
8253
  getInit(context) {
8325
8254
  return context.replacedVariableInits.get(this) || UNKNOWN_EXPRESSION;
@@ -8355,42 +8284,44 @@ class FunctionNode extends FunctionBase {
8355
8284
  createScope(parentScope) {
8356
8285
  this.scope = new FunctionScope(parentScope, this.context);
8357
8286
  }
8358
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
8359
- super.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
8360
- if (event === EVENT_CALLED && path.length === 0) {
8361
- this.scope.thisVariable.addEntityToBeDeoptimized(thisParameter);
8287
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
8288
+ super.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
8289
+ if (interaction.type === INTERACTION_CALLED && path.length === 0) {
8290
+ this.scope.thisVariable.addEntityToBeDeoptimized(interaction.thisArg);
8362
8291
  }
8363
8292
  }
8364
- hasEffects() {
8293
+ hasEffects(context) {
8365
8294
  var _a;
8366
8295
  if (!this.deoptimized)
8367
8296
  this.applyDeoptimizations();
8368
- return !!((_a = this.id) === null || _a === void 0 ? void 0 : _a.hasEffects());
8297
+ return !!((_a = this.id) === null || _a === void 0 ? void 0 : _a.hasEffects(context));
8369
8298
  }
8370
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
8371
- if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
8299
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
8300
+ if (super.hasEffectsOnInteractionAtPath(path, interaction, context))
8372
8301
  return true;
8373
- const thisInit = context.replacedVariableInits.get(this.scope.thisVariable);
8374
- context.replacedVariableInits.set(this.scope.thisVariable, callOptions.withNew
8375
- ? new ObjectEntity(Object.create(null), OBJECT_PROTOTYPE)
8376
- : UNKNOWN_EXPRESSION);
8377
- const { brokenFlow, ignore } = context;
8378
- context.ignore = {
8379
- breaks: false,
8380
- continues: false,
8381
- labels: new Set(),
8382
- returnYield: true
8383
- };
8384
- if (this.body.hasEffects(context))
8385
- return true;
8386
- context.brokenFlow = brokenFlow;
8387
- if (thisInit) {
8388
- context.replacedVariableInits.set(this.scope.thisVariable, thisInit);
8389
- }
8390
- else {
8391
- context.replacedVariableInits.delete(this.scope.thisVariable);
8302
+ if (interaction.type === INTERACTION_CALLED) {
8303
+ const thisInit = context.replacedVariableInits.get(this.scope.thisVariable);
8304
+ context.replacedVariableInits.set(this.scope.thisVariable, interaction.withNew
8305
+ ? new ObjectEntity(Object.create(null), OBJECT_PROTOTYPE)
8306
+ : UNKNOWN_EXPRESSION);
8307
+ const { brokenFlow, ignore } = context;
8308
+ context.ignore = {
8309
+ breaks: false,
8310
+ continues: false,
8311
+ labels: new Set(),
8312
+ returnYield: true
8313
+ };
8314
+ if (this.body.hasEffects(context))
8315
+ return true;
8316
+ context.brokenFlow = brokenFlow;
8317
+ if (thisInit) {
8318
+ context.replacedVariableInits.set(this.scope.thisVariable, thisInit);
8319
+ }
8320
+ else {
8321
+ context.replacedVariableInits.delete(this.scope.thisVariable);
8322
+ }
8323
+ context.ignore = ignore;
8392
8324
  }
8393
- context.ignore = ignore;
8394
8325
  return false;
8395
8326
  }
8396
8327
  include(context, includeChildrenRecursively) {
@@ -8497,8 +8428,8 @@ class BinaryExpression extends NodeBase {
8497
8428
  return true;
8498
8429
  return super.hasEffects(context);
8499
8430
  }
8500
- hasEffectsWhenAccessedAtPath(path) {
8501
- return path.length > 1;
8431
+ hasEffectsOnInteractionAtPath(path, { type }) {
8432
+ return type !== INTERACTION_ACCESSED || path.length > 1;
8502
8433
  }
8503
8434
  render(code, options, { renderedSurroundingElement } = BLANK) {
8504
8435
  this.left.render(code, options, { renderedSurroundingElement });
@@ -8557,7 +8488,7 @@ function renderCallArguments(code, options, node) {
8557
8488
  }
8558
8489
 
8559
8490
  class Literal extends NodeBase {
8560
- deoptimizeThisOnEventAtPath() { }
8491
+ deoptimizeThisOnInteractionAtPath() { }
8561
8492
  getLiteralValueAtPath(path) {
8562
8493
  if (path.length > 0 ||
8563
8494
  // unknown literals can also be null but do not start with an "n"
@@ -8574,17 +8505,16 @@ class Literal extends NodeBase {
8574
8505
  return UNKNOWN_EXPRESSION;
8575
8506
  return getMemberReturnExpressionWhenCalled(this.members, path[0]);
8576
8507
  }
8577
- hasEffectsWhenAccessedAtPath(path) {
8578
- if (this.value === null) {
8579
- return path.length > 0;
8580
- }
8581
- return path.length > 1;
8582
- }
8583
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
8584
- if (path.length === 1) {
8585
- return hasMemberEffectWhenCalled(this.members, path[0], callOptions, context);
8508
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
8509
+ switch (interaction.type) {
8510
+ case INTERACTION_ACCESSED:
8511
+ return path.length > (this.value === null ? 0 : 1);
8512
+ case INTERACTION_ASSIGNED:
8513
+ return true;
8514
+ case INTERACTION_CALLED:
8515
+ return (path.length !== 1 ||
8516
+ hasMemberEffectWhenCalled(this.members, path[0], interaction, context));
8586
8517
  }
8587
- return true;
8588
8518
  }
8589
8519
  initialise() {
8590
8520
  this.members = getLiteralMembersForValue(this.value);
@@ -8642,6 +8572,7 @@ class MemberExpression extends NodeBase {
8642
8572
  constructor() {
8643
8573
  super(...arguments);
8644
8574
  this.variable = null;
8575
+ this.assignmentDeoptimized = false;
8645
8576
  this.bound = false;
8646
8577
  this.expressionsToBeDeoptimized = [];
8647
8578
  this.replacement = null;
@@ -8651,7 +8582,7 @@ class MemberExpression extends NodeBase {
8651
8582
  const path = getPathIfNotComputed(this);
8652
8583
  const baseVariable = path && this.scope.findVariable(path[0].key);
8653
8584
  if (baseVariable && baseVariable.isNamespace) {
8654
- const resolvedVariable = this.resolveNamespaceVariables(baseVariable, path.slice(1));
8585
+ const resolvedVariable = resolveNamespaceVariables(baseVariable, path.slice(1), this.context);
8655
8586
  if (!resolvedVariable) {
8656
8587
  super.bind();
8657
8588
  }
@@ -8692,21 +8623,21 @@ class MemberExpression extends NodeBase {
8692
8623
  }
8693
8624
  }
8694
8625
  }
8695
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
8626
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
8696
8627
  if (this.variable) {
8697
- this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
8628
+ this.variable.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
8698
8629
  }
8699
8630
  else if (!this.replacement) {
8700
8631
  if (path.length < MAX_PATH_DEPTH) {
8701
- this.object.deoptimizeThisOnEventAtPath(event, [this.getPropertyKey(), ...path], thisParameter, recursionTracker);
8632
+ this.object.deoptimizeThisOnInteractionAtPath(interaction, [this.getPropertyKey(), ...path], recursionTracker);
8702
8633
  }
8703
8634
  else {
8704
- thisParameter.deoptimizePath(UNKNOWN_PATH);
8635
+ interaction.thisArg.deoptimizePath(UNKNOWN_PATH);
8705
8636
  }
8706
8637
  }
8707
8638
  }
8708
8639
  getLiteralValueAtPath(path, recursionTracker, origin) {
8709
- if (this.variable !== null) {
8640
+ if (this.variable) {
8710
8641
  return this.variable.getLiteralValueAtPath(path, recursionTracker, origin);
8711
8642
  }
8712
8643
  if (this.replacement) {
@@ -8718,81 +8649,62 @@ class MemberExpression extends NodeBase {
8718
8649
  }
8719
8650
  return UnknownValue;
8720
8651
  }
8721
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
8722
- if (this.variable !== null) {
8723
- return this.variable.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
8652
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
8653
+ if (this.variable) {
8654
+ return this.variable.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
8724
8655
  }
8725
8656
  if (this.replacement) {
8726
8657
  return UNKNOWN_EXPRESSION;
8727
8658
  }
8728
8659
  this.expressionsToBeDeoptimized.push(origin);
8729
8660
  if (path.length < MAX_PATH_DEPTH) {
8730
- return this.object.getReturnExpressionWhenCalledAtPath([this.getPropertyKey(), ...path], callOptions, recursionTracker, origin);
8661
+ return this.object.getReturnExpressionWhenCalledAtPath([this.getPropertyKey(), ...path], interaction, recursionTracker, origin);
8731
8662
  }
8732
8663
  return UNKNOWN_EXPRESSION;
8733
8664
  }
8734
8665
  hasEffects(context) {
8735
8666
  if (!this.deoptimized)
8736
8667
  this.applyDeoptimizations();
8737
- const { propertyReadSideEffects } = this.context.options
8738
- .treeshake;
8739
8668
  return (this.property.hasEffects(context) ||
8740
8669
  this.object.hasEffects(context) ||
8741
- // Assignments do not access the property before assigning
8742
- (!(this.variable ||
8743
- this.replacement ||
8744
- (this.parent instanceof AssignmentExpression && this.parent.operator === '=')) &&
8745
- propertyReadSideEffects &&
8746
- (propertyReadSideEffects === 'always' ||
8747
- this.object.hasEffectsWhenAccessedAtPath([this.getPropertyKey()], context))));
8670
+ this.hasAccessEffect(context));
8748
8671
  }
8749
- hasEffectsWhenAccessedAtPath(path, context) {
8750
- if (this.variable !== null) {
8751
- return this.variable.hasEffectsWhenAccessedAtPath(path, context);
8752
- }
8753
- if (this.replacement) {
8754
- return true;
8755
- }
8756
- if (path.length < MAX_PATH_DEPTH) {
8757
- return this.object.hasEffectsWhenAccessedAtPath([this.getPropertyKey(), ...path], context);
8758
- }
8759
- return true;
8760
- }
8761
- hasEffectsWhenAssignedAtPath(path, context) {
8762
- if (this.variable !== null) {
8763
- return this.variable.hasEffectsWhenAssignedAtPath(path, context);
8764
- }
8765
- if (this.replacement) {
8766
- return true;
8767
- }
8768
- if (path.length < MAX_PATH_DEPTH) {
8769
- return this.object.hasEffectsWhenAssignedAtPath([this.getPropertyKey(), ...path], context);
8770
- }
8771
- return true;
8672
+ hasEffectsAsAssignmentTarget(context, checkAccess) {
8673
+ if (checkAccess && !this.deoptimized)
8674
+ this.applyDeoptimizations();
8675
+ if (!this.assignmentDeoptimized)
8676
+ this.applyAssignmentDeoptimization();
8677
+ return (this.property.hasEffects(context) ||
8678
+ this.object.hasEffects(context) ||
8679
+ (checkAccess && this.hasAccessEffect(context)) ||
8680
+ this.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.assignmentInteraction, context));
8772
8681
  }
8773
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
8774
- if (this.variable !== null) {
8775
- return this.variable.hasEffectsWhenCalledAtPath(path, callOptions, context);
8682
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
8683
+ if (this.variable) {
8684
+ return this.variable.hasEffectsOnInteractionAtPath(path, interaction, context);
8776
8685
  }
8777
8686
  if (this.replacement) {
8778
8687
  return true;
8779
8688
  }
8780
8689
  if (path.length < MAX_PATH_DEPTH) {
8781
- return this.object.hasEffectsWhenCalledAtPath([this.getPropertyKey(), ...path], callOptions, context);
8690
+ return this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey(), ...path], interaction, context);
8782
8691
  }
8783
8692
  return true;
8784
8693
  }
8785
8694
  include(context, includeChildrenRecursively) {
8786
8695
  if (!this.deoptimized)
8787
8696
  this.applyDeoptimizations();
8788
- if (!this.included) {
8789
- this.included = true;
8790
- if (this.variable !== null) {
8791
- this.context.includeVariableInModule(this.variable);
8792
- }
8697
+ this.includeProperties(context, includeChildrenRecursively);
8698
+ }
8699
+ includeAsAssignmentTarget(context, includeChildrenRecursively, deoptimizeAccess) {
8700
+ if (!this.assignmentDeoptimized)
8701
+ this.applyAssignmentDeoptimization();
8702
+ if (deoptimizeAccess) {
8703
+ this.include(context, includeChildrenRecursively);
8704
+ }
8705
+ else {
8706
+ this.includeProperties(context, includeChildrenRecursively);
8793
8707
  }
8794
- this.object.include(context, includeChildrenRecursively);
8795
- this.property.include(context, includeChildrenRecursively);
8796
8708
  }
8797
8709
  includeCallArguments(context, args) {
8798
8710
  if (this.variable) {
@@ -8804,6 +8716,7 @@ class MemberExpression extends NodeBase {
8804
8716
  }
8805
8717
  initialise() {
8806
8718
  this.propertyKey = getResolvablePropertyKey(this);
8719
+ this.accessInteraction = { thisArg: this.object, type: INTERACTION_ACCESSED };
8807
8720
  }
8808
8721
  render(code, options, { renderedParentType, isCalleeOfRenderedParent, renderedSurroundingElement } = BLANK) {
8809
8722
  if (this.variable || this.replacement) {
@@ -8824,6 +8737,13 @@ class MemberExpression extends NodeBase {
8824
8737
  this.property.render(code, options);
8825
8738
  }
8826
8739
  }
8740
+ setAssignedValue(value) {
8741
+ this.assignmentInteraction = {
8742
+ args: [value],
8743
+ thisArg: this.object,
8744
+ type: INTERACTION_ASSIGNED
8745
+ };
8746
+ }
8827
8747
  applyDeoptimizations() {
8828
8748
  this.deoptimized = true;
8829
8749
  const { propertyReadSideEffects } = this.context.options
@@ -8833,13 +8753,21 @@ class MemberExpression extends NodeBase {
8833
8753
  this.bound &&
8834
8754
  propertyReadSideEffects &&
8835
8755
  !(this.variable || this.replacement)) {
8836
- // Regular Assignments do not access the property before assigning
8837
- if (!(this.parent instanceof AssignmentExpression && this.parent.operator === '=')) {
8838
- this.object.deoptimizeThisOnEventAtPath(EVENT_ACCESSED, [this.propertyKey], this.object, SHARED_RECURSION_TRACKER);
8839
- }
8840
- if (this.parent instanceof AssignmentExpression) {
8841
- this.object.deoptimizeThisOnEventAtPath(EVENT_ASSIGNED, [this.propertyKey], this.object, SHARED_RECURSION_TRACKER);
8842
- }
8756
+ const propertyKey = this.getPropertyKey();
8757
+ this.object.deoptimizeThisOnInteractionAtPath(this.accessInteraction, [propertyKey], SHARED_RECURSION_TRACKER);
8758
+ this.context.requestTreeshakingPass();
8759
+ }
8760
+ }
8761
+ applyAssignmentDeoptimization() {
8762
+ this.assignmentDeoptimized = true;
8763
+ const { propertyReadSideEffects } = this.context.options
8764
+ .treeshake;
8765
+ if (
8766
+ // Namespaces are not bound and should not be deoptimized
8767
+ this.bound &&
8768
+ propertyReadSideEffects &&
8769
+ !(this.variable || this.replacement)) {
8770
+ this.object.deoptimizeThisOnInteractionAtPath(this.assignmentInteraction, [this.getPropertyKey()], SHARED_RECURSION_TRACKER);
8843
8771
  this.context.requestTreeshakingPass();
8844
8772
  }
8845
8773
  }
@@ -8865,28 +8793,46 @@ class MemberExpression extends NodeBase {
8865
8793
  }
8866
8794
  return this.propertyKey;
8867
8795
  }
8868
- resolveNamespaceVariables(baseVariable, path) {
8869
- if (path.length === 0)
8870
- return baseVariable;
8871
- if (!baseVariable.isNamespace || baseVariable instanceof ExternalVariable)
8872
- return null;
8873
- const exportName = path[0].key;
8874
- const variable = baseVariable.context.traceExport(exportName);
8875
- if (!variable) {
8876
- const fileName = baseVariable.context.fileName;
8877
- this.context.warn({
8878
- code: 'MISSING_EXPORT',
8879
- exporter: relativeId(fileName),
8880
- importer: relativeId(this.context.fileName),
8881
- message: `'${exportName}' is not exported by '${relativeId(fileName)}'`,
8882
- missing: exportName,
8883
- url: `https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module`
8884
- }, path[0].pos);
8885
- return 'undefined';
8796
+ hasAccessEffect(context) {
8797
+ const { propertyReadSideEffects } = this.context.options
8798
+ .treeshake;
8799
+ return (!(this.variable || this.replacement) &&
8800
+ propertyReadSideEffects &&
8801
+ (propertyReadSideEffects === 'always' ||
8802
+ this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey()], this.accessInteraction, context)));
8803
+ }
8804
+ includeProperties(context, includeChildrenRecursively) {
8805
+ if (!this.included) {
8806
+ this.included = true;
8807
+ if (this.variable) {
8808
+ this.context.includeVariableInModule(this.variable);
8809
+ }
8886
8810
  }
8887
- return this.resolveNamespaceVariables(variable, path.slice(1));
8811
+ this.object.include(context, includeChildrenRecursively);
8812
+ this.property.include(context, includeChildrenRecursively);
8888
8813
  }
8889
8814
  }
8815
+ function resolveNamespaceVariables(baseVariable, path, astContext) {
8816
+ if (path.length === 0)
8817
+ return baseVariable;
8818
+ if (!baseVariable.isNamespace || baseVariable instanceof ExternalVariable)
8819
+ return null;
8820
+ const exportName = path[0].key;
8821
+ const variable = baseVariable.context.traceExport(exportName);
8822
+ if (!variable) {
8823
+ const fileName = baseVariable.context.fileName;
8824
+ astContext.warn({
8825
+ code: 'MISSING_EXPORT',
8826
+ exporter: relativeId(fileName),
8827
+ importer: relativeId(astContext.fileName),
8828
+ message: `'${exportName}' is not exported by '${relativeId(fileName)}'`,
8829
+ missing: exportName,
8830
+ url: `https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module`
8831
+ }, path[0].pos);
8832
+ return 'undefined';
8833
+ }
8834
+ return resolveNamespaceVariables(variable, path.slice(1), astContext);
8835
+ }
8890
8836
 
8891
8837
  class CallExpressionBase extends NodeBase {
8892
8838
  constructor() {
@@ -8916,15 +8862,15 @@ class CallExpressionBase extends NodeBase {
8916
8862
  returnExpression.deoptimizePath(path);
8917
8863
  }
8918
8864
  }
8919
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
8865
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
8920
8866
  const returnExpression = this.getReturnExpression(recursionTracker);
8921
8867
  if (returnExpression === UNKNOWN_EXPRESSION) {
8922
- thisParameter.deoptimizePath(UNKNOWN_PATH);
8868
+ interaction.thisArg.deoptimizePath(UNKNOWN_PATH);
8923
8869
  }
8924
8870
  else {
8925
8871
  recursionTracker.withTrackedEntityAtPath(path, returnExpression, () => {
8926
- this.expressionsToBeDeoptimized.add(thisParameter);
8927
- returnExpression.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
8872
+ this.expressionsToBeDeoptimized.add(interaction.thisArg);
8873
+ returnExpression.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
8928
8874
  }, undefined);
8929
8875
  }
8930
8876
  }
@@ -8938,27 +8884,31 @@ class CallExpressionBase extends NodeBase {
8938
8884
  return returnExpression.getLiteralValueAtPath(path, recursionTracker, origin);
8939
8885
  }, UnknownValue);
8940
8886
  }
8941
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
8887
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
8942
8888
  const returnExpression = this.getReturnExpression(recursionTracker);
8943
8889
  if (this.returnExpression === UNKNOWN_EXPRESSION) {
8944
8890
  return UNKNOWN_EXPRESSION;
8945
8891
  }
8946
8892
  return recursionTracker.withTrackedEntityAtPath(path, returnExpression, () => {
8947
8893
  this.deoptimizableDependentExpressions.push(origin);
8948
- return returnExpression.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
8894
+ return returnExpression.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
8949
8895
  }, UNKNOWN_EXPRESSION);
8950
8896
  }
8951
- hasEffectsWhenAccessedAtPath(path, context) {
8952
- return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
8953
- this.getReturnExpression().hasEffectsWhenAccessedAtPath(path, context));
8954
- }
8955
- hasEffectsWhenAssignedAtPath(path, context) {
8956
- return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
8957
- this.getReturnExpression().hasEffectsWhenAssignedAtPath(path, context));
8958
- }
8959
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
8960
- return (!(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
8961
- this.getReturnExpression().hasEffectsWhenCalledAtPath(path, callOptions, context));
8897
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
8898
+ const { type } = interaction;
8899
+ if (type === INTERACTION_CALLED) {
8900
+ if ((interaction.withNew
8901
+ ? context.instantiated
8902
+ : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this)) {
8903
+ return false;
8904
+ }
8905
+ }
8906
+ else if ((type === INTERACTION_ASSIGNED
8907
+ ? context.assigned
8908
+ : context.accessed).trackEntityAtPathAndGetIfTracked(path, this)) {
8909
+ return false;
8910
+ }
8911
+ return this.getReturnExpression().hasEffectsOnInteractionAtPath(path, interaction, context);
8962
8912
  }
8963
8913
  }
8964
8914
 
@@ -8981,11 +8931,12 @@ class CallExpression extends CallExpressionBase {
8981
8931
  }, this.start);
8982
8932
  }
8983
8933
  }
8984
- this.callOptions = {
8934
+ this.interaction = {
8985
8935
  args: this.arguments,
8986
- thisParam: this.callee instanceof MemberExpression && !this.callee.variable
8936
+ thisArg: this.callee instanceof MemberExpression && !this.callee.variable
8987
8937
  ? this.callee.object
8988
8938
  : null,
8939
+ type: INTERACTION_CALLED,
8989
8940
  withNew: false
8990
8941
  };
8991
8942
  }
@@ -8999,7 +8950,7 @@ class CallExpression extends CallExpressionBase {
8999
8950
  this.annotations)
9000
8951
  return false;
9001
8952
  return (this.callee.hasEffects(context) ||
9002
- this.callee.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
8953
+ this.callee.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context));
9003
8954
  }
9004
8955
  finally {
9005
8956
  if (!this.deoptimized)
@@ -9036,9 +8987,8 @@ class CallExpression extends CallExpressionBase {
9036
8987
  }
9037
8988
  applyDeoptimizations() {
9038
8989
  this.deoptimized = true;
9039
- const { thisParam } = this.callOptions;
9040
- if (thisParam) {
9041
- this.callee.deoptimizeThisOnEventAtPath(EVENT_CALLED, EMPTY_PATH, thisParam, SHARED_RECURSION_TRACKER);
8990
+ if (this.interaction.thisArg) {
8991
+ this.callee.deoptimizeThisOnInteractionAtPath(this.interaction, EMPTY_PATH, SHARED_RECURSION_TRACKER);
9042
8992
  }
9043
8993
  for (const argument of this.arguments) {
9044
8994
  // This will make sure all properties of parameters behave as "unknown"
@@ -9049,7 +8999,7 @@ class CallExpression extends CallExpressionBase {
9049
8999
  getReturnExpression(recursionTracker = SHARED_RECURSION_TRACKER) {
9050
9000
  if (this.returnExpression === null) {
9051
9001
  this.returnExpression = UNKNOWN_EXPRESSION;
9052
- return (this.returnExpression = this.callee.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.callOptions, recursionTracker, this));
9002
+ return (this.returnExpression = this.callee.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.interaction, recursionTracker, this));
9053
9003
  }
9054
9004
  return this.returnExpression;
9055
9005
  }
@@ -9127,11 +9077,6 @@ class MethodBase extends NodeBase {
9127
9077
  constructor() {
9128
9078
  super(...arguments);
9129
9079
  this.accessedValue = null;
9130
- this.accessorCallOptions = {
9131
- args: NO_ARGS,
9132
- thisParam: null,
9133
- withNew: false
9134
- };
9135
9080
  }
9136
9081
  // As getter properties directly receive their values from fixed function
9137
9082
  // expressions, there is no known situation where a getter is deoptimized.
@@ -9139,45 +9084,60 @@ class MethodBase extends NodeBase {
9139
9084
  deoptimizePath(path) {
9140
9085
  this.getAccessedValue().deoptimizePath(path);
9141
9086
  }
9142
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
9143
- if (event === EVENT_ACCESSED && this.kind === 'get' && path.length === 0) {
9144
- return this.value.deoptimizeThisOnEventAtPath(EVENT_CALLED, EMPTY_PATH, thisParameter, recursionTracker);
9087
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
9088
+ if (interaction.type === INTERACTION_ACCESSED && this.kind === 'get' && path.length === 0) {
9089
+ return this.value.deoptimizeThisOnInteractionAtPath({
9090
+ args: NO_ARGS,
9091
+ thisArg: interaction.thisArg,
9092
+ type: INTERACTION_CALLED,
9093
+ withNew: false
9094
+ }, EMPTY_PATH, recursionTracker);
9145
9095
  }
9146
- if (event === EVENT_ASSIGNED && this.kind === 'set' && path.length === 0) {
9147
- return this.value.deoptimizeThisOnEventAtPath(EVENT_CALLED, EMPTY_PATH, thisParameter, recursionTracker);
9096
+ if (interaction.type === INTERACTION_ASSIGNED && this.kind === 'set' && path.length === 0) {
9097
+ return this.value.deoptimizeThisOnInteractionAtPath({
9098
+ args: interaction.args,
9099
+ thisArg: interaction.thisArg,
9100
+ type: INTERACTION_CALLED,
9101
+ withNew: false
9102
+ }, EMPTY_PATH, recursionTracker);
9148
9103
  }
9149
- this.getAccessedValue().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
9104
+ this.getAccessedValue().deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
9150
9105
  }
9151
9106
  getLiteralValueAtPath(path, recursionTracker, origin) {
9152
9107
  return this.getAccessedValue().getLiteralValueAtPath(path, recursionTracker, origin);
9153
9108
  }
9154
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
9155
- return this.getAccessedValue().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
9109
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
9110
+ return this.getAccessedValue().getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
9156
9111
  }
9157
9112
  hasEffects(context) {
9158
9113
  return this.key.hasEffects(context);
9159
9114
  }
9160
- hasEffectsWhenAccessedAtPath(path, context) {
9161
- if (this.kind === 'get' && path.length === 0) {
9162
- return this.value.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.accessorCallOptions, context);
9163
- }
9164
- return this.getAccessedValue().hasEffectsWhenAccessedAtPath(path, context);
9165
- }
9166
- hasEffectsWhenAssignedAtPath(path, context) {
9167
- if (this.kind === 'set') {
9168
- return this.value.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.accessorCallOptions, context);
9115
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
9116
+ if (this.kind === 'get' && interaction.type === INTERACTION_ACCESSED && path.length === 0) {
9117
+ return this.value.hasEffectsOnInteractionAtPath(EMPTY_PATH, {
9118
+ args: NO_ARGS,
9119
+ thisArg: interaction.thisArg,
9120
+ type: INTERACTION_CALLED,
9121
+ withNew: false
9122
+ }, context);
9123
+ }
9124
+ // setters are only called for empty paths
9125
+ if (this.kind === 'set' && interaction.type === INTERACTION_ASSIGNED) {
9126
+ return this.value.hasEffectsOnInteractionAtPath(EMPTY_PATH, {
9127
+ args: interaction.args,
9128
+ thisArg: interaction.thisArg,
9129
+ type: INTERACTION_CALLED,
9130
+ withNew: false
9131
+ }, context);
9169
9132
  }
9170
- return this.getAccessedValue().hasEffectsWhenAssignedAtPath(path, context);
9171
- }
9172
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
9173
- return this.getAccessedValue().hasEffectsWhenCalledAtPath(path, callOptions, context);
9133
+ return this.getAccessedValue().hasEffectsOnInteractionAtPath(path, interaction, context);
9174
9134
  }
9175
9135
  applyDeoptimizations() { }
9176
9136
  getAccessedValue() {
9177
9137
  if (this.accessedValue === null) {
9178
9138
  if (this.kind === 'get') {
9179
9139
  this.accessedValue = UNKNOWN_EXPRESSION;
9180
- return (this.accessedValue = this.value.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.accessorCallOptions, SHARED_RECURSION_TRACKER, this));
9140
+ return (this.accessedValue = this.value.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_CALL, SHARED_RECURSION_TRACKER, this));
9181
9141
  }
9182
9142
  else {
9183
9143
  return (this.accessedValue = this.value);
@@ -9200,23 +9160,17 @@ class ObjectMember extends ExpressionEntity {
9200
9160
  deoptimizePath(path) {
9201
9161
  this.object.deoptimizePath([this.key, ...path]);
9202
9162
  }
9203
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
9204
- this.object.deoptimizeThisOnEventAtPath(event, [this.key, ...path], thisParameter, recursionTracker);
9163
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
9164
+ this.object.deoptimizeThisOnInteractionAtPath(interaction, [this.key, ...path], recursionTracker);
9205
9165
  }
9206
9166
  getLiteralValueAtPath(path, recursionTracker, origin) {
9207
9167
  return this.object.getLiteralValueAtPath([this.key, ...path], recursionTracker, origin);
9208
9168
  }
9209
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
9210
- return this.object.getReturnExpressionWhenCalledAtPath([this.key, ...path], callOptions, recursionTracker, origin);
9211
- }
9212
- hasEffectsWhenAccessedAtPath(path, context) {
9213
- return this.object.hasEffectsWhenAccessedAtPath([this.key, ...path], context);
9214
- }
9215
- hasEffectsWhenAssignedAtPath(path, context) {
9216
- return this.object.hasEffectsWhenAssignedAtPath([this.key, ...path], context);
9169
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
9170
+ return this.object.getReturnExpressionWhenCalledAtPath([this.key, ...path], interaction, recursionTracker, origin);
9217
9171
  }
9218
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
9219
- return this.object.hasEffectsWhenCalledAtPath([this.key, ...path], callOptions, context);
9172
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
9173
+ return this.object.hasEffectsOnInteractionAtPath([this.key, ...path], interaction, context);
9220
9174
  }
9221
9175
  }
9222
9176
 
@@ -9234,14 +9188,14 @@ class ClassNode extends NodeBase {
9234
9188
  deoptimizePath(path) {
9235
9189
  this.getObjectEntity().deoptimizePath(path);
9236
9190
  }
9237
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
9238
- this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
9191
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
9192
+ this.getObjectEntity().deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
9239
9193
  }
9240
9194
  getLiteralValueAtPath(path, recursionTracker, origin) {
9241
9195
  return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
9242
9196
  }
9243
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
9244
- return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
9197
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
9198
+ return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
9245
9199
  }
9246
9200
  hasEffects(context) {
9247
9201
  var _a, _b;
@@ -9251,23 +9205,17 @@ class ClassNode extends NodeBase {
9251
9205
  (_b = this.id) === null || _b === void 0 ? void 0 : _b.markDeclarationReached();
9252
9206
  return initEffect || super.hasEffects(context);
9253
9207
  }
9254
- hasEffectsWhenAccessedAtPath(path, context) {
9255
- return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
9256
- }
9257
- hasEffectsWhenAssignedAtPath(path, context) {
9258
- return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
9259
- }
9260
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
9208
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
9261
9209
  var _a;
9262
- if (path.length === 0) {
9263
- return (!callOptions.withNew ||
9210
+ if (interaction.type === INTERACTION_CALLED && path.length === 0) {
9211
+ return (!interaction.withNew ||
9264
9212
  (this.classConstructor !== null
9265
- ? this.classConstructor.hasEffectsWhenCalledAtPath(EMPTY_PATH, callOptions, context)
9266
- : (_a = this.superClass) === null || _a === void 0 ? void 0 : _a.hasEffectsWhenCalledAtPath(path, callOptions, context)) ||
9213
+ ? this.classConstructor.hasEffectsOnInteractionAtPath(path, interaction, context)
9214
+ : (_a = this.superClass) === null || _a === void 0 ? void 0 : _a.hasEffectsOnInteractionAtPath(path, interaction, context)) ||
9267
9215
  false);
9268
9216
  }
9269
9217
  else {
9270
- return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
9218
+ return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
9271
9219
  }
9272
9220
  }
9273
9221
  include(context, includeChildrenRecursively) {
@@ -9388,26 +9336,12 @@ class MultiExpression extends ExpressionEntity {
9388
9336
  expression.deoptimizePath(path);
9389
9337
  }
9390
9338
  }
9391
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
9392
- return new MultiExpression(this.expressions.map(expression => expression.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin)));
9393
- }
9394
- hasEffectsWhenAccessedAtPath(path, context) {
9395
- for (const expression of this.expressions) {
9396
- if (expression.hasEffectsWhenAccessedAtPath(path, context))
9397
- return true;
9398
- }
9399
- return false;
9400
- }
9401
- hasEffectsWhenAssignedAtPath(path, context) {
9402
- for (const expression of this.expressions) {
9403
- if (expression.hasEffectsWhenAssignedAtPath(path, context))
9404
- return true;
9405
- }
9406
- return false;
9339
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
9340
+ return new MultiExpression(this.expressions.map(expression => expression.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)));
9407
9341
  }
9408
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
9342
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
9409
9343
  for (const expression of this.expressions) {
9410
- if (expression.hasEffectsWhenCalledAtPath(path, callOptions, context))
9344
+ if (expression.hasEffectsOnInteractionAtPath(path, interaction, context))
9411
9345
  return true;
9412
9346
  }
9413
9347
  return false;
@@ -9450,9 +9384,9 @@ class ConditionalExpression extends NodeBase {
9450
9384
  usedBranch.deoptimizePath(path);
9451
9385
  }
9452
9386
  }
9453
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
9454
- this.consequent.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
9455
- this.alternate.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
9387
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
9388
+ this.consequent.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
9389
+ this.alternate.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
9456
9390
  }
9457
9391
  getLiteralValueAtPath(path, recursionTracker, origin) {
9458
9392
  const usedBranch = this.getUsedBranch();
@@ -9461,15 +9395,15 @@ class ConditionalExpression extends NodeBase {
9461
9395
  this.expressionsToBeDeoptimized.push(origin);
9462
9396
  return usedBranch.getLiteralValueAtPath(path, recursionTracker, origin);
9463
9397
  }
9464
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
9398
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
9465
9399
  const usedBranch = this.getUsedBranch();
9466
9400
  if (!usedBranch)
9467
9401
  return new MultiExpression([
9468
- this.consequent.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin),
9469
- this.alternate.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin)
9402
+ this.consequent.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin),
9403
+ this.alternate.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)
9470
9404
  ]);
9471
9405
  this.expressionsToBeDeoptimized.push(origin);
9472
- return usedBranch.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
9406
+ return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
9473
9407
  }
9474
9408
  hasEffects(context) {
9475
9409
  if (this.test.hasEffects(context))
@@ -9480,29 +9414,13 @@ class ConditionalExpression extends NodeBase {
9480
9414
  }
9481
9415
  return usedBranch.hasEffects(context);
9482
9416
  }
9483
- hasEffectsWhenAccessedAtPath(path, context) {
9484
- const usedBranch = this.getUsedBranch();
9485
- if (!usedBranch) {
9486
- return (this.consequent.hasEffectsWhenAccessedAtPath(path, context) ||
9487
- this.alternate.hasEffectsWhenAccessedAtPath(path, context));
9488
- }
9489
- return usedBranch.hasEffectsWhenAccessedAtPath(path, context);
9490
- }
9491
- hasEffectsWhenAssignedAtPath(path, context) {
9417
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
9492
9418
  const usedBranch = this.getUsedBranch();
9493
9419
  if (!usedBranch) {
9494
- return (this.consequent.hasEffectsWhenAssignedAtPath(path, context) ||
9495
- this.alternate.hasEffectsWhenAssignedAtPath(path, context));
9420
+ return (this.consequent.hasEffectsOnInteractionAtPath(path, interaction, context) ||
9421
+ this.alternate.hasEffectsOnInteractionAtPath(path, interaction, context));
9496
9422
  }
9497
- return usedBranch.hasEffectsWhenAssignedAtPath(path, context);
9498
- }
9499
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
9500
- const usedBranch = this.getUsedBranch();
9501
- if (!usedBranch) {
9502
- return (this.consequent.hasEffectsWhenCalledAtPath(path, callOptions, context) ||
9503
- this.alternate.hasEffectsWhenCalledAtPath(path, callOptions, context));
9504
- }
9505
- return usedBranch.hasEffectsWhenCalledAtPath(path, callOptions, context);
9423
+ return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
9506
9424
  }
9507
9425
  include(context, includeChildrenRecursively) {
9508
9426
  this.included = true;
@@ -9773,12 +9691,10 @@ class ForInStatement extends NodeBase {
9773
9691
  this.scope = new BlockScope(parentScope);
9774
9692
  }
9775
9693
  hasEffects(context) {
9776
- if (!this.deoptimized)
9694
+ const { deoptimized, left, right } = this;
9695
+ if (!deoptimized)
9777
9696
  this.applyDeoptimizations();
9778
- if ((this.left &&
9779
- (this.left.hasEffects(context) ||
9780
- this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context))) ||
9781
- (this.right && this.right.hasEffects(context)))
9697
+ if (left.hasEffectsAsAssignmentTarget(context, false) || right.hasEffects(context))
9782
9698
  return true;
9783
9699
  const { brokenFlow, ignore: { breaks, continues } } = context;
9784
9700
  context.ignore.breaks = true;
@@ -9791,15 +9707,19 @@ class ForInStatement extends NodeBase {
9791
9707
  return false;
9792
9708
  }
9793
9709
  include(context, includeChildrenRecursively) {
9794
- if (!this.deoptimized)
9710
+ const { body, deoptimized, left, right } = this;
9711
+ if (!deoptimized)
9795
9712
  this.applyDeoptimizations();
9796
9713
  this.included = true;
9797
- this.left.include(context, includeChildrenRecursively || true);
9798
- this.right.include(context, includeChildrenRecursively);
9714
+ left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
9715
+ right.include(context, includeChildrenRecursively);
9799
9716
  const { brokenFlow } = context;
9800
- this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9717
+ body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9801
9718
  context.brokenFlow = brokenFlow;
9802
9719
  }
9720
+ initialise() {
9721
+ this.left.setAssignedValue(UNKNOWN_EXPRESSION);
9722
+ }
9803
9723
  render(code, options) {
9804
9724
  this.left.render(code, options, NO_SEMICOLON);
9805
9725
  this.right.render(code, options, NO_SEMICOLON);
@@ -9827,15 +9747,19 @@ class ForOfStatement extends NodeBase {
9827
9747
  return true;
9828
9748
  }
9829
9749
  include(context, includeChildrenRecursively) {
9830
- if (!this.deoptimized)
9750
+ const { body, deoptimized, left, right } = this;
9751
+ if (!deoptimized)
9831
9752
  this.applyDeoptimizations();
9832
9753
  this.included = true;
9833
- this.left.include(context, includeChildrenRecursively || true);
9834
- this.right.include(context, includeChildrenRecursively);
9754
+ left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
9755
+ right.include(context, includeChildrenRecursively);
9835
9756
  const { brokenFlow } = context;
9836
- this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9757
+ body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9837
9758
  context.brokenFlow = brokenFlow;
9838
9759
  }
9760
+ initialise() {
9761
+ this.left.setAssignedValue(UNKNOWN_EXPRESSION);
9762
+ }
9839
9763
  render(code, options) {
9840
9764
  this.left.render(code, options, NO_SEMICOLON);
9841
9765
  this.right.render(code, options, NO_SEMICOLON);
@@ -10542,9 +10466,9 @@ class LogicalExpression extends NodeBase {
10542
10466
  usedBranch.deoptimizePath(path);
10543
10467
  }
10544
10468
  }
10545
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
10546
- this.left.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
10547
- this.right.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
10469
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
10470
+ this.left.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
10471
+ this.right.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
10548
10472
  }
10549
10473
  getLiteralValueAtPath(path, recursionTracker, origin) {
10550
10474
  const usedBranch = this.getUsedBranch();
@@ -10553,15 +10477,15 @@ class LogicalExpression extends NodeBase {
10553
10477
  this.expressionsToBeDeoptimized.push(origin);
10554
10478
  return usedBranch.getLiteralValueAtPath(path, recursionTracker, origin);
10555
10479
  }
10556
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
10480
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
10557
10481
  const usedBranch = this.getUsedBranch();
10558
10482
  if (!usedBranch)
10559
10483
  return new MultiExpression([
10560
- this.left.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin),
10561
- this.right.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin)
10484
+ this.left.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin),
10485
+ this.right.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)
10562
10486
  ]);
10563
10487
  this.expressionsToBeDeoptimized.push(origin);
10564
- return usedBranch.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
10488
+ return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
10565
10489
  }
10566
10490
  hasEffects(context) {
10567
10491
  if (this.left.hasEffects(context)) {
@@ -10572,29 +10496,13 @@ class LogicalExpression extends NodeBase {
10572
10496
  }
10573
10497
  return false;
10574
10498
  }
10575
- hasEffectsWhenAccessedAtPath(path, context) {
10499
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
10576
10500
  const usedBranch = this.getUsedBranch();
10577
10501
  if (!usedBranch) {
10578
- return (this.left.hasEffectsWhenAccessedAtPath(path, context) ||
10579
- this.right.hasEffectsWhenAccessedAtPath(path, context));
10502
+ return (this.left.hasEffectsOnInteractionAtPath(path, interaction, context) ||
10503
+ this.right.hasEffectsOnInteractionAtPath(path, interaction, context));
10580
10504
  }
10581
- return usedBranch.hasEffectsWhenAccessedAtPath(path, context);
10582
- }
10583
- hasEffectsWhenAssignedAtPath(path, context) {
10584
- const usedBranch = this.getUsedBranch();
10585
- if (!usedBranch) {
10586
- return (this.left.hasEffectsWhenAssignedAtPath(path, context) ||
10587
- this.right.hasEffectsWhenAssignedAtPath(path, context));
10588
- }
10589
- return usedBranch.hasEffectsWhenAssignedAtPath(path, context);
10590
- }
10591
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
10592
- const usedBranch = this.getUsedBranch();
10593
- if (!usedBranch) {
10594
- return (this.left.hasEffectsWhenCalledAtPath(path, callOptions, context) ||
10595
- this.right.hasEffectsWhenCalledAtPath(path, callOptions, context));
10596
- }
10597
- return usedBranch.hasEffectsWhenCalledAtPath(path, callOptions, context);
10505
+ return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
10598
10506
  }
10599
10507
  include(context, includeChildrenRecursively) {
10600
10508
  this.included = true;
@@ -10684,8 +10592,8 @@ class MetaProperty extends NodeBase {
10684
10592
  hasEffects() {
10685
10593
  return false;
10686
10594
  }
10687
- hasEffectsWhenAccessedAtPath(path) {
10688
- return path.length > 1;
10595
+ hasEffectsOnInteractionAtPath(path, { type }) {
10596
+ return path.length > 1 || type !== INTERACTION_ACCESSED;
10689
10597
  }
10690
10598
  include() {
10691
10599
  if (!this.included) {
@@ -10833,15 +10741,15 @@ class NewExpression extends NodeBase {
10833
10741
  this.annotations)
10834
10742
  return false;
10835
10743
  return (this.callee.hasEffects(context) ||
10836
- this.callee.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
10744
+ this.callee.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context));
10837
10745
  }
10838
10746
  finally {
10839
10747
  if (!this.deoptimized)
10840
10748
  this.applyDeoptimizations();
10841
10749
  }
10842
10750
  }
10843
- hasEffectsWhenAccessedAtPath(path) {
10844
- return path.length > 0;
10751
+ hasEffectsOnInteractionAtPath(path, { type }) {
10752
+ return path.length > 0 || type !== INTERACTION_ACCESSED;
10845
10753
  }
10846
10754
  include(context, includeChildrenRecursively) {
10847
10755
  if (!this.deoptimized)
@@ -10856,9 +10764,10 @@ class NewExpression extends NodeBase {
10856
10764
  this.callee.includeCallArguments(context, this.arguments);
10857
10765
  }
10858
10766
  initialise() {
10859
- this.callOptions = {
10767
+ this.interaction = {
10860
10768
  args: this.arguments,
10861
- thisParam: null,
10769
+ thisArg: null,
10770
+ type: INTERACTION_CALLED,
10862
10771
  withNew: true
10863
10772
  };
10864
10773
  }
@@ -10887,23 +10796,17 @@ class ObjectExpression extends NodeBase {
10887
10796
  deoptimizePath(path) {
10888
10797
  this.getObjectEntity().deoptimizePath(path);
10889
10798
  }
10890
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
10891
- this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
10799
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
10800
+ this.getObjectEntity().deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
10892
10801
  }
10893
10802
  getLiteralValueAtPath(path, recursionTracker, origin) {
10894
10803
  return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
10895
10804
  }
10896
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
10897
- return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
10898
- }
10899
- hasEffectsWhenAccessedAtPath(path, context) {
10900
- return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
10901
- }
10902
- hasEffectsWhenAssignedAtPath(path, context) {
10903
- return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
10805
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
10806
+ return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
10904
10807
  }
10905
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
10906
- return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
10808
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
10809
+ return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
10907
10810
  }
10908
10811
  render(code, options, { renderedSurroundingElement } = BLANK) {
10909
10812
  super.render(code, options);
@@ -11034,32 +10937,26 @@ class PropertyDefinition extends NodeBase {
11034
10937
  var _a;
11035
10938
  (_a = this.value) === null || _a === void 0 ? void 0 : _a.deoptimizePath(path);
11036
10939
  }
11037
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
10940
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
11038
10941
  var _a;
11039
- (_a = this.value) === null || _a === void 0 ? void 0 : _a.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
10942
+ (_a = this.value) === null || _a === void 0 ? void 0 : _a.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
11040
10943
  }
11041
10944
  getLiteralValueAtPath(path, recursionTracker, origin) {
11042
10945
  return this.value
11043
10946
  ? this.value.getLiteralValueAtPath(path, recursionTracker, origin)
11044
10947
  : UnknownValue;
11045
10948
  }
11046
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
10949
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
11047
10950
  return this.value
11048
- ? this.value.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin)
10951
+ ? this.value.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)
11049
10952
  : UNKNOWN_EXPRESSION;
11050
10953
  }
11051
10954
  hasEffects(context) {
11052
10955
  var _a;
11053
10956
  return this.key.hasEffects(context) || (this.static && !!((_a = this.value) === null || _a === void 0 ? void 0 : _a.hasEffects(context)));
11054
10957
  }
11055
- hasEffectsWhenAccessedAtPath(path, context) {
11056
- return !this.value || this.value.hasEffectsWhenAccessedAtPath(path, context);
11057
- }
11058
- hasEffectsWhenAssignedAtPath(path, context) {
11059
- return !this.value || this.value.hasEffectsWhenAssignedAtPath(path, context);
11060
- }
11061
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
11062
- return !this.value || this.value.hasEffectsWhenCalledAtPath(path, callOptions, context);
10958
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
10959
+ return !this.value || this.value.hasEffectsOnInteractionAtPath(path, interaction, context);
11063
10960
  }
11064
10961
  applyDeoptimizations() { }
11065
10962
  }
@@ -11095,8 +10992,8 @@ class SequenceExpression extends NodeBase {
11095
10992
  deoptimizePath(path) {
11096
10993
  this.expressions[this.expressions.length - 1].deoptimizePath(path);
11097
10994
  }
11098
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
11099
- this.expressions[this.expressions.length - 1].deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
10995
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
10996
+ this.expressions[this.expressions.length - 1].deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
11100
10997
  }
11101
10998
  getLiteralValueAtPath(path, recursionTracker, origin) {
11102
10999
  return this.expressions[this.expressions.length - 1].getLiteralValueAtPath(path, recursionTracker, origin);
@@ -11108,15 +11005,8 @@ class SequenceExpression extends NodeBase {
11108
11005
  }
11109
11006
  return false;
11110
11007
  }
11111
- hasEffectsWhenAccessedAtPath(path, context) {
11112
- return (path.length > 0 &&
11113
- this.expressions[this.expressions.length - 1].hasEffectsWhenAccessedAtPath(path, context));
11114
- }
11115
- hasEffectsWhenAssignedAtPath(path, context) {
11116
- return this.expressions[this.expressions.length - 1].hasEffectsWhenAssignedAtPath(path, context);
11117
- }
11118
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
11119
- return this.expressions[this.expressions.length - 1].hasEffectsWhenCalledAtPath(path, callOptions, context);
11008
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
11009
+ return this.expressions[this.expressions.length - 1].hasEffectsOnInteractionAtPath(path, interaction, context);
11120
11010
  }
11121
11011
  include(context, includeChildrenRecursively) {
11122
11012
  this.included = true;
@@ -11195,8 +11085,8 @@ class Super extends NodeBase {
11195
11085
  deoptimizePath(path) {
11196
11086
  this.variable.deoptimizePath(path);
11197
11087
  }
11198
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
11199
- this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
11088
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
11089
+ this.variable.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
11200
11090
  }
11201
11091
  include() {
11202
11092
  if (!this.included) {
@@ -11336,7 +11226,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
11336
11226
  return true;
11337
11227
  }
11338
11228
  return (this.tag.hasEffects(context) ||
11339
- this.tag.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
11229
+ this.tag.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context));
11340
11230
  }
11341
11231
  finally {
11342
11232
  if (!this.deoptimized)
@@ -11354,16 +11244,17 @@ class TaggedTemplateExpression extends CallExpressionBase {
11354
11244
  this.tag.include(context, includeChildrenRecursively);
11355
11245
  this.quasi.include(context, includeChildrenRecursively);
11356
11246
  }
11357
- this.tag.includeCallArguments(context, this.callOptions.args);
11247
+ this.tag.includeCallArguments(context, this.interaction.args);
11358
11248
  const returnExpression = this.getReturnExpression();
11359
11249
  if (!returnExpression.included) {
11360
11250
  returnExpression.include(context, false);
11361
11251
  }
11362
11252
  }
11363
11253
  initialise() {
11364
- this.callOptions = {
11254
+ this.interaction = {
11365
11255
  args: [UNKNOWN_EXPRESSION, ...this.quasi.expressions],
11366
- thisParam: this.tag instanceof MemberExpression && !this.tag.variable ? this.tag.object : null,
11256
+ thisArg: this.tag instanceof MemberExpression && !this.tag.variable ? this.tag.object : null,
11257
+ type: INTERACTION_CALLED,
11367
11258
  withNew: false
11368
11259
  };
11369
11260
  }
@@ -11373,9 +11264,8 @@ class TaggedTemplateExpression extends CallExpressionBase {
11373
11264
  }
11374
11265
  applyDeoptimizations() {
11375
11266
  this.deoptimized = true;
11376
- const { thisParam } = this.callOptions;
11377
- if (thisParam) {
11378
- this.tag.deoptimizeThisOnEventAtPath(EVENT_CALLED, EMPTY_PATH, thisParam, SHARED_RECURSION_TRACKER);
11267
+ if (this.interaction.thisArg) {
11268
+ this.tag.deoptimizeThisOnInteractionAtPath(this.interaction, EMPTY_PATH, SHARED_RECURSION_TRACKER);
11379
11269
  }
11380
11270
  for (const argument of this.quasi.expressions) {
11381
11271
  // This will make sure all properties of parameters behave as "unknown"
@@ -11386,7 +11276,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
11386
11276
  getReturnExpression(recursionTracker = SHARED_RECURSION_TRACKER) {
11387
11277
  if (this.returnExpression === null) {
11388
11278
  this.returnExpression = UNKNOWN_EXPRESSION;
11389
- return (this.returnExpression = this.tag.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.callOptions, recursionTracker, this));
11279
+ return (this.returnExpression = this.tag.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.interaction, recursionTracker, this));
11390
11280
  }
11391
11281
  return this.returnExpression;
11392
11282
  }
@@ -11409,7 +11299,7 @@ class TemplateElement extends NodeBase {
11409
11299
  }
11410
11300
 
11411
11301
  class TemplateLiteral extends NodeBase {
11412
- deoptimizeThisOnEventAtPath() { }
11302
+ deoptimizeThisOnInteractionAtPath() { }
11413
11303
  getLiteralValueAtPath(path) {
11414
11304
  if (path.length > 0 || this.quasis.length !== 1) {
11415
11305
  return UnknownValue;
@@ -11422,12 +11312,12 @@ class TemplateLiteral extends NodeBase {
11422
11312
  }
11423
11313
  return getMemberReturnExpressionWhenCalled(literalStringMembers, path[0]);
11424
11314
  }
11425
- hasEffectsWhenAccessedAtPath(path) {
11426
- return path.length > 1;
11427
- }
11428
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
11429
- if (path.length === 1) {
11430
- return hasMemberEffectWhenCalled(literalStringMembers, path[0], callOptions, context);
11315
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
11316
+ if (interaction.type === INTERACTION_ACCESSED) {
11317
+ return path.length > 1;
11318
+ }
11319
+ if (interaction.type === INTERACTION_CALLED && path.length === 1) {
11320
+ return hasMemberEffectWhenCalled(literalStringMembers, path[0], interaction, context);
11431
11321
  }
11432
11322
  return true;
11433
11323
  }
@@ -11555,16 +11445,15 @@ class ThisExpression extends NodeBase {
11555
11445
  deoptimizePath(path) {
11556
11446
  this.variable.deoptimizePath(path);
11557
11447
  }
11558
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
11559
- this.variable.deoptimizeThisOnEventAtPath(event, path,
11448
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
11560
11449
  // We rewrite the parameter so that a ThisVariable can detect self-mutations
11561
- thisParameter === this ? this.variable : thisParameter, recursionTracker);
11562
- }
11563
- hasEffectsWhenAccessedAtPath(path, context) {
11564
- return path.length > 0 && this.variable.hasEffectsWhenAccessedAtPath(path, context);
11450
+ this.variable.deoptimizeThisOnInteractionAtPath(interaction.thisArg === this ? { ...interaction, thisArg: this.variable } : interaction, path, recursionTracker);
11565
11451
  }
11566
- hasEffectsWhenAssignedAtPath(path, context) {
11567
- return this.variable.hasEffectsWhenAssignedAtPath(path, context);
11452
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
11453
+ if (path.length === 0) {
11454
+ return interaction.type !== INTERACTION_ACCESSED;
11455
+ }
11456
+ return this.variable.hasEffectsOnInteractionAtPath(path, interaction, context);
11568
11457
  }
11569
11458
  include() {
11570
11459
  if (!this.included) {
@@ -11673,13 +11562,10 @@ class UnaryExpression extends NodeBase {
11673
11562
  return false;
11674
11563
  return (this.argument.hasEffects(context) ||
11675
11564
  (this.operator === 'delete' &&
11676
- this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context)));
11565
+ this.argument.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_ASSIGNMENT, context)));
11677
11566
  }
11678
- hasEffectsWhenAccessedAtPath(path) {
11679
- if (this.operator === 'void') {
11680
- return path.length > 0;
11681
- }
11682
- return path.length > 1;
11567
+ hasEffectsOnInteractionAtPath(path, { type }) {
11568
+ return type !== INTERACTION_ACCESSED || path.length > (this.operator === 'void' ? 0 : 1);
11683
11569
  }
11684
11570
  applyDeoptimizations() {
11685
11571
  this.deoptimized = true;
@@ -11703,11 +11589,19 @@ class UpdateExpression extends NodeBase {
11703
11589
  hasEffects(context) {
11704
11590
  if (!this.deoptimized)
11705
11591
  this.applyDeoptimizations();
11706
- return (this.argument.hasEffects(context) ||
11707
- this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context));
11592
+ return this.argument.hasEffectsAsAssignmentTarget(context, true);
11593
+ }
11594
+ hasEffectsOnInteractionAtPath(path, { type }) {
11595
+ return path.length > 1 || type !== INTERACTION_ACCESSED;
11708
11596
  }
11709
- hasEffectsWhenAccessedAtPath(path) {
11710
- return path.length > 1;
11597
+ include(context, includeChildrenRecursively) {
11598
+ if (!this.deoptimized)
11599
+ this.applyDeoptimizations();
11600
+ this.included = true;
11601
+ this.argument.includeAsAssignmentTarget(context, includeChildrenRecursively, true);
11602
+ }
11603
+ initialise() {
11604
+ this.argument.setAssignedValue(UNKNOWN_EXPRESSION);
11711
11605
  }
11712
11606
  render(code, options) {
11713
11607
  const { exportNamesByVariable, format, snippets: { _ } } = options;
@@ -11769,7 +11663,7 @@ class VariableDeclaration extends NodeBase {
11769
11663
  declarator.deoptimizePath(EMPTY_PATH);
11770
11664
  }
11771
11665
  }
11772
- hasEffectsWhenAssignedAtPath() {
11666
+ hasEffectsOnInteractionAtPath() {
11773
11667
  return false;
11774
11668
  }
11775
11669
  include(context, includeChildrenRecursively, { asSingleStatement } = BLANK) {