rollup 2.75.5 → 2.76.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.75.5
4
- Wed, 01 Jun 2022 12:43:56 GMT - commit 14dedb52b4d799deebd8b711c1e14759fc0213d9
3
+ Rollup.js v2.76.0
4
+ Fri, 08 Jul 2022 08:35:58 GMT - commit 0eb042740eb41812b9e96e0e7b6ed8aa4cab04a7
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -27,7 +27,7 @@ function _interopNamespaceDefault(e) {
27
27
  return n;
28
28
  }
29
29
 
30
- var version$1 = "2.75.5";
30
+ var version$1 = "2.76.0";
31
31
 
32
32
  function ensureArray$1(items) {
33
33
  if (Array.isArray(items)) {
@@ -2228,8 +2228,8 @@ class ExpressionEntity {
2228
2228
  this.included = false;
2229
2229
  }
2230
2230
  deoptimizePath(_path) { }
2231
- deoptimizeThisOnEventAtPath(_event, _path, thisParameter, _recursionTracker) {
2232
- thisParameter.deoptimizePath(UNKNOWN_PATH);
2231
+ deoptimizeThisOnInteractionAtPath({ thisArg }, _path, _recursionTracker) {
2232
+ thisArg.deoptimizePath(UNKNOWN_PATH);
2233
2233
  }
2234
2234
  /**
2235
2235
  * If possible it returns a stringifyable literal value for this node that can be used
@@ -2239,16 +2239,10 @@ class ExpressionEntity {
2239
2239
  getLiteralValueAtPath(_path, _recursionTracker, _origin) {
2240
2240
  return UnknownValue;
2241
2241
  }
2242
- getReturnExpressionWhenCalledAtPath(_path, _callOptions, _recursionTracker, _origin) {
2242
+ getReturnExpressionWhenCalledAtPath(_path, _interaction, _recursionTracker, _origin) {
2243
2243
  return UNKNOWN_EXPRESSION;
2244
2244
  }
2245
- hasEffectsWhenAccessedAtPath(_path, _context) {
2246
- return true;
2247
- }
2248
- hasEffectsWhenAssignedAtPath(_path, _context) {
2249
- return true;
2250
- }
2251
- hasEffectsWhenCalledAtPath(_path, _callOptions, _context) {
2245
+ hasEffectsOnInteractionAtPath(_path, _interaction, _context) {
2252
2246
  return true;
2253
2247
  }
2254
2248
  include(_context, _includeChildrenRecursively, _options) {
@@ -2266,6 +2260,30 @@ class ExpressionEntity {
2266
2260
  const UNKNOWN_EXPRESSION = new (class UnknownExpression extends ExpressionEntity {
2267
2261
  })();
2268
2262
 
2263
+ const INTERACTION_ACCESSED = 0;
2264
+ const INTERACTION_ASSIGNED = 1;
2265
+ const INTERACTION_CALLED = 2;
2266
+ const NODE_INTERACTION_UNKNOWN_ACCESS = {
2267
+ thisArg: null,
2268
+ type: INTERACTION_ACCESSED
2269
+ };
2270
+ const UNKNOWN_ARG = [UNKNOWN_EXPRESSION];
2271
+ const NODE_INTERACTION_UNKNOWN_ASSIGNMENT = {
2272
+ args: UNKNOWN_ARG,
2273
+ thisArg: null,
2274
+ type: INTERACTION_ASSIGNED
2275
+ };
2276
+ const NO_ARGS = [];
2277
+ // While this is technically a call without arguments, we can compare against
2278
+ // this reference in places where precise values or thisArg would make a
2279
+ // difference
2280
+ const NODE_INTERACTION_UNKNOWN_CALL = {
2281
+ args: NO_ARGS,
2282
+ thisArg: null,
2283
+ type: INTERACTION_CALLED,
2284
+ withNew: false
2285
+ };
2286
+
2269
2287
  class Variable extends ExpressionEntity {
2270
2288
  constructor(name) {
2271
2289
  super();
@@ -2290,8 +2308,8 @@ class Variable extends ExpressionEntity {
2290
2308
  const name = this.renderName || this.name;
2291
2309
  return this.renderBaseName ? `${this.renderBaseName}${getPropertyAccess(name)}` : name;
2292
2310
  }
2293
- hasEffectsWhenAccessedAtPath(path, _context) {
2294
- return path.length > 0;
2311
+ hasEffectsOnInteractionAtPath(path, { type }, _context) {
2312
+ return type !== INTERACTION_ACCESSED || path.length > 0;
2295
2313
  }
2296
2314
  /**
2297
2315
  * Marks this variable as being part of the bundle, which is usually the case when one of
@@ -2322,8 +2340,8 @@ class ExternalVariable extends Variable {
2322
2340
  this.module.suggestName(identifier.name);
2323
2341
  }
2324
2342
  }
2325
- hasEffectsWhenAccessedAtPath(path) {
2326
- return path.length > (this.isNamespace ? 1 : 0);
2343
+ hasEffectsOnInteractionAtPath(path, { type }) {
2344
+ return type !== INTERACTION_ACCESSED || path.length > (this.isNamespace ? 1 : 0);
2327
2345
  }
2328
2346
  include() {
2329
2347
  if (!this.included) {
@@ -4710,8 +4728,6 @@ function createHasEffectsContext() {
4710
4728
  };
4711
4729
  }
4712
4730
 
4713
- const NO_ARGS = [];
4714
-
4715
4731
  function assembleMemberDescriptions(memberDescriptions, inheritedDescriptions = null) {
4716
4732
  return Object.create(inheritedDescriptions, memberDescriptions);
4717
4733
  }
@@ -4733,12 +4749,12 @@ const UNKNOWN_LITERAL_BOOLEAN = new (class UnknownBoolean extends ExpressionEnti
4733
4749
  }
4734
4750
  return UNKNOWN_EXPRESSION;
4735
4751
  }
4736
- hasEffectsWhenAccessedAtPath(path) {
4737
- return path.length > 1;
4738
- }
4739
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
4740
- if (path.length === 1) {
4741
- return hasMemberEffectWhenCalled(literalBooleanMembers, path[0], callOptions, context);
4752
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
4753
+ if (interaction.type === INTERACTION_ACCESSED) {
4754
+ return path.length > 1;
4755
+ }
4756
+ if (interaction.type === INTERACTION_CALLED && path.length === 1) {
4757
+ return hasMemberEffectWhenCalled(literalBooleanMembers, path[0], interaction, context);
4742
4758
  }
4743
4759
  return true;
4744
4760
  }
@@ -4756,12 +4772,12 @@ const UNKNOWN_LITERAL_NUMBER = new (class UnknownNumber extends ExpressionEntity
4756
4772
  }
4757
4773
  return UNKNOWN_EXPRESSION;
4758
4774
  }
4759
- hasEffectsWhenAccessedAtPath(path) {
4760
- return path.length > 1;
4761
- }
4762
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
4763
- if (path.length === 1) {
4764
- return hasMemberEffectWhenCalled(literalNumberMembers, path[0], callOptions, context);
4775
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
4776
+ if (interaction.type === INTERACTION_ACCESSED) {
4777
+ return path.length > 1;
4778
+ }
4779
+ if (interaction.type === INTERACTION_CALLED && path.length === 1) {
4780
+ return hasMemberEffectWhenCalled(literalNumberMembers, path[0], interaction, context);
4765
4781
  }
4766
4782
  return true;
4767
4783
  }
@@ -4779,12 +4795,12 @@ const UNKNOWN_LITERAL_STRING = new (class UnknownString extends ExpressionEntity
4779
4795
  }
4780
4796
  return UNKNOWN_EXPRESSION;
4781
4797
  }
4782
- hasEffectsWhenAccessedAtPath(path) {
4783
- return path.length > 1;
4784
- }
4785
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
4786
- if (path.length === 1) {
4787
- return hasMemberEffectWhenCalled(literalStringMembers, path[0], callOptions, context);
4798
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
4799
+ if (interaction.type === INTERACTION_ACCESSED) {
4800
+ return path.length > 1;
4801
+ }
4802
+ if (interaction.type === INTERACTION_CALLED && path.length === 1) {
4803
+ return hasMemberEffectWhenCalled(literalStringMembers, path[0], interaction, context);
4788
4804
  }
4789
4805
  return true;
4790
4806
  }
@@ -4797,17 +4813,13 @@ const returnsString = {
4797
4813
  };
4798
4814
  const stringReplace = {
4799
4815
  value: {
4800
- hasEffectsWhenCalled(callOptions, context) {
4801
- const arg1 = callOptions.args[1];
4802
- return (callOptions.args.length < 2 ||
4816
+ hasEffectsWhenCalled({ args }, context) {
4817
+ const arg1 = args[1];
4818
+ return (args.length < 2 ||
4803
4819
  (typeof arg1.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, {
4804
4820
  deoptimizeCache() { }
4805
4821
  }) === 'symbol' &&
4806
- arg1.hasEffectsWhenCalledAtPath(EMPTY_PATH, {
4807
- args: NO_ARGS,
4808
- thisParam: null,
4809
- withNew: false
4810
- }, context)));
4822
+ arg1.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_CALL, context)));
4811
4823
  },
4812
4824
  returns: UNKNOWN_LITERAL_STRING
4813
4825
  }
@@ -4891,12 +4903,12 @@ function getLiteralMembersForValue(value) {
4891
4903
  }
4892
4904
  return Object.create(null);
4893
4905
  }
4894
- function hasMemberEffectWhenCalled(members, memberName, callOptions, context) {
4906
+ function hasMemberEffectWhenCalled(members, memberName, interaction, context) {
4895
4907
  var _a, _b;
4896
4908
  if (typeof memberName !== 'string' || !members[memberName]) {
4897
4909
  return true;
4898
4910
  }
4899
- return ((_b = (_a = members[memberName]).hasEffectsWhenCalled) === null || _b === void 0 ? void 0 : _b.call(_a, callOptions, context)) || false;
4911
+ return ((_b = (_a = members[memberName]).hasEffectsWhenCalled) === null || _b === void 0 ? void 0 : _b.call(_a, interaction, context)) || false;
4900
4912
  }
4901
4913
  function getMemberReturnExpressionWhenCalled(members, memberName) {
4902
4914
  if (typeof memberName !== 'string' || !members[memberName])
@@ -5335,10 +5347,12 @@ const INCLUDE_PARAMETERS = 'variables';
5335
5347
  class NodeBase extends ExpressionEntity {
5336
5348
  constructor(esTreeNode, parent, parentScope) {
5337
5349
  super();
5338
- // Nodes can apply custom deoptimizations once they become part of the
5339
- // executed code. To do this, they must initialize this as false, implement
5340
- // applyDeoptimizations and call this from include and hasEffects if they
5341
- // have custom handlers
5350
+ /**
5351
+ * Nodes can apply custom deoptimizations once they become part of the
5352
+ * executed code. To do this, they must initialize this as false, implement
5353
+ * applyDeoptimizations and call this from include and hasEffects if they have
5354
+ * custom handlers
5355
+ */
5342
5356
  this.deoptimized = false;
5343
5357
  this.esTreeNode = esTreeNode;
5344
5358
  this.keys = keys[esTreeNode.type] || getAndCreateKeys(esTreeNode);
@@ -5394,6 +5408,10 @@ class NodeBase extends ExpressionEntity {
5394
5408
  }
5395
5409
  return false;
5396
5410
  }
5411
+ hasEffectsAsAssignmentTarget(context, _checkAccess) {
5412
+ return (this.hasEffects(context) ||
5413
+ this.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.assignmentInteraction, context));
5414
+ }
5397
5415
  include(context, includeChildrenRecursively, _options) {
5398
5416
  if (!this.deoptimized)
5399
5417
  this.applyDeoptimizations();
@@ -5412,6 +5430,9 @@ class NodeBase extends ExpressionEntity {
5412
5430
  }
5413
5431
  }
5414
5432
  }
5433
+ includeAsAssignmentTarget(context, includeChildrenRecursively, _deoptimizeAccess) {
5434
+ this.include(context, includeChildrenRecursively);
5435
+ }
5415
5436
  /**
5416
5437
  * Override to perform special initialisation steps after the scope is initialised
5417
5438
  */
@@ -5466,6 +5487,9 @@ class NodeBase extends ExpressionEntity {
5466
5487
  }
5467
5488
  }
5468
5489
  }
5490
+ setAssignedValue(value) {
5491
+ this.assignmentInteraction = { args: [value], thisArg: null, type: INTERACTION_ASSIGNED };
5492
+ }
5469
5493
  shouldBeIncluded(context) {
5470
5494
  return this.included || (!context.brokenFlow && this.hasEffects(createHasEffectsContext()));
5471
5495
  }
@@ -5494,9 +5518,9 @@ class NodeBase extends ExpressionEntity {
5494
5518
  }
5495
5519
 
5496
5520
  class SpreadElement extends NodeBase {
5497
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
5521
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
5498
5522
  if (path.length > 0) {
5499
- this.argument.deoptimizeThisOnEventAtPath(event, [UnknownKey, ...path], thisParameter, recursionTracker);
5523
+ this.argument.deoptimizeThisOnInteractionAtPath(interaction, [UnknownKey, ...path], recursionTracker);
5500
5524
  }
5501
5525
  }
5502
5526
  hasEffects(context) {
@@ -5507,7 +5531,7 @@ class SpreadElement extends NodeBase {
5507
5531
  return (this.argument.hasEffects(context) ||
5508
5532
  (propertyReadSideEffects &&
5509
5533
  (propertyReadSideEffects === 'always' ||
5510
- this.argument.hasEffectsWhenAccessedAtPath(UNKNOWN_PATH, context))));
5534
+ this.argument.hasEffectsOnInteractionAtPath(UNKNOWN_PATH, NODE_INTERACTION_UNKNOWN_ACCESS, context))));
5511
5535
  }
5512
5536
  applyDeoptimizations() {
5513
5537
  this.deoptimized = true;
@@ -5518,53 +5542,43 @@ class SpreadElement extends NodeBase {
5518
5542
  }
5519
5543
  }
5520
5544
 
5521
- const EVENT_ACCESSED = 0;
5522
- const EVENT_ASSIGNED = 1;
5523
- const EVENT_CALLED = 2;
5524
-
5525
5545
  class Method extends ExpressionEntity {
5526
5546
  constructor(description) {
5527
5547
  super();
5528
5548
  this.description = description;
5529
5549
  }
5530
- deoptimizeThisOnEventAtPath(event, path, thisParameter) {
5531
- if (event === EVENT_CALLED && path.length === 0 && this.description.mutatesSelfAsArray) {
5532
- thisParameter.deoptimizePath(UNKNOWN_INTEGER_PATH);
5550
+ deoptimizeThisOnInteractionAtPath({ type, thisArg }, path) {
5551
+ if (type === INTERACTION_CALLED && path.length === 0 && this.description.mutatesSelfAsArray) {
5552
+ thisArg.deoptimizePath(UNKNOWN_INTEGER_PATH);
5533
5553
  }
5534
5554
  }
5535
- getReturnExpressionWhenCalledAtPath(path, callOptions) {
5555
+ getReturnExpressionWhenCalledAtPath(path, { thisArg }) {
5536
5556
  if (path.length > 0) {
5537
5557
  return UNKNOWN_EXPRESSION;
5538
5558
  }
5539
5559
  return (this.description.returnsPrimitive ||
5540
5560
  (this.description.returns === 'self'
5541
- ? callOptions.thisParam || UNKNOWN_EXPRESSION
5561
+ ? thisArg || UNKNOWN_EXPRESSION
5542
5562
  : this.description.returns()));
5543
5563
  }
5544
- hasEffectsWhenAccessedAtPath(path) {
5545
- return path.length > 1;
5546
- }
5547
- hasEffectsWhenAssignedAtPath(path) {
5548
- return path.length > 0;
5549
- }
5550
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
5564
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
5551
5565
  var _a, _b;
5552
- if (path.length > 0 ||
5553
- (this.description.mutatesSelfAsArray === true &&
5554
- ((_a = callOptions.thisParam) === null || _a === void 0 ? void 0 : _a.hasEffectsWhenAssignedAtPath(UNKNOWN_INTEGER_PATH, context)))) {
5566
+ const { type } = interaction;
5567
+ if (path.length > (type === INTERACTION_ACCESSED ? 1 : 0)) {
5555
5568
  return true;
5556
5569
  }
5557
- if (!this.description.callsArgs) {
5558
- return false;
5559
- }
5560
- for (const argIndex of this.description.callsArgs) {
5561
- if ((_b = callOptions.args[argIndex]) === null || _b === void 0 ? void 0 : _b.hasEffectsWhenCalledAtPath(EMPTY_PATH, {
5562
- args: NO_ARGS,
5563
- thisParam: null,
5564
- withNew: false
5565
- }, context)) {
5570
+ if (type === INTERACTION_CALLED) {
5571
+ if (this.description.mutatesSelfAsArray === true &&
5572
+ ((_a = interaction.thisArg) === null || _a === void 0 ? void 0 : _a.hasEffectsOnInteractionAtPath(UNKNOWN_INTEGER_PATH, NODE_INTERACTION_UNKNOWN_ASSIGNMENT, context))) {
5566
5573
  return true;
5567
5574
  }
5575
+ if (this.description.callsArgs) {
5576
+ for (const argIndex of this.description.callsArgs) {
5577
+ if ((_b = interaction.args[argIndex]) === null || _b === void 0 ? void 0 : _b.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_CALL, context)) {
5578
+ return true;
5579
+ }
5580
+ }
5581
+ }
5568
5582
  }
5569
5583
  return false;
5570
5584
  }
@@ -5706,24 +5720,24 @@ class ObjectEntity extends ExpressionEntity {
5706
5720
  }
5707
5721
  (_a = this.prototypeExpression) === null || _a === void 0 ? void 0 : _a.deoptimizePath(path.length === 1 ? [...path, UnknownKey] : path);
5708
5722
  }
5709
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
5723
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
5710
5724
  var _a;
5711
5725
  const [key, ...subPath] = path;
5712
5726
  if (this.hasLostTrack ||
5713
5727
  // single paths that are deoptimized will not become getters or setters
5714
- ((event === EVENT_CALLED || path.length > 1) &&
5728
+ ((interaction.type === INTERACTION_CALLED || path.length > 1) &&
5715
5729
  (this.hasUnknownDeoptimizedProperty ||
5716
5730
  (typeof key === 'string' && this.deoptimizedPaths[key])))) {
5717
- thisParameter.deoptimizePath(UNKNOWN_PATH);
5731
+ interaction.thisArg.deoptimizePath(UNKNOWN_PATH);
5718
5732
  return;
5719
5733
  }
5720
- const [propertiesForExactMatchByKey, relevantPropertiesByKey, relevantUnmatchableProperties] = event === EVENT_CALLED || path.length > 1
5734
+ const [propertiesForExactMatchByKey, relevantPropertiesByKey, relevantUnmatchableProperties] = interaction.type === INTERACTION_CALLED || path.length > 1
5721
5735
  ? [
5722
5736
  this.propertiesAndGettersByKey,
5723
5737
  this.propertiesAndGettersByKey,
5724
5738
  this.unmatchablePropertiesAndGetters
5725
5739
  ]
5726
- : event === EVENT_ACCESSED
5740
+ : interaction.type === INTERACTION_ACCESSED
5727
5741
  ? [this.propertiesAndGettersByKey, this.gettersByKey, this.unmatchableGetters]
5728
5742
  : [this.propertiesAndSettersByKey, this.settersByKey, this.unmatchableSetters];
5729
5743
  if (typeof key === 'string') {
@@ -5731,20 +5745,20 @@ class ObjectEntity extends ExpressionEntity {
5731
5745
  const properties = relevantPropertiesByKey[key];
5732
5746
  if (properties) {
5733
5747
  for (const property of properties) {
5734
- property.deoptimizeThisOnEventAtPath(event, subPath, thisParameter, recursionTracker);
5748
+ property.deoptimizeThisOnInteractionAtPath(interaction, subPath, recursionTracker);
5735
5749
  }
5736
5750
  }
5737
5751
  if (!this.immutable) {
5738
- this.thisParametersToBeDeoptimized.add(thisParameter);
5752
+ this.thisParametersToBeDeoptimized.add(interaction.thisArg);
5739
5753
  }
5740
5754
  return;
5741
5755
  }
5742
5756
  for (const property of relevantUnmatchableProperties) {
5743
- property.deoptimizeThisOnEventAtPath(event, subPath, thisParameter, recursionTracker);
5757
+ property.deoptimizeThisOnInteractionAtPath(interaction, subPath, recursionTracker);
5744
5758
  }
5745
5759
  if (INTEGER_REG_EXP.test(key)) {
5746
5760
  for (const property of this.unknownIntegerProps) {
5747
- property.deoptimizeThisOnEventAtPath(event, subPath, thisParameter, recursionTracker);
5761
+ property.deoptimizeThisOnInteractionAtPath(interaction, subPath, recursionTracker);
5748
5762
  }
5749
5763
  }
5750
5764
  }
@@ -5753,17 +5767,17 @@ class ObjectEntity extends ExpressionEntity {
5753
5767
  relevantUnmatchableProperties
5754
5768
  ])) {
5755
5769
  for (const property of properties) {
5756
- property.deoptimizeThisOnEventAtPath(event, subPath, thisParameter, recursionTracker);
5770
+ property.deoptimizeThisOnInteractionAtPath(interaction, subPath, recursionTracker);
5757
5771
  }
5758
5772
  }
5759
5773
  for (const property of this.unknownIntegerProps) {
5760
- property.deoptimizeThisOnEventAtPath(event, subPath, thisParameter, recursionTracker);
5774
+ property.deoptimizeThisOnInteractionAtPath(interaction, subPath, recursionTracker);
5761
5775
  }
5762
5776
  }
5763
5777
  if (!this.immutable) {
5764
- this.thisParametersToBeDeoptimized.add(thisParameter);
5778
+ this.thisParametersToBeDeoptimized.add(interaction.thisArg);
5765
5779
  }
5766
- (_a = this.prototypeExpression) === null || _a === void 0 ? void 0 : _a.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
5780
+ (_a = this.prototypeExpression) === null || _a === void 0 ? void 0 : _a.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
5767
5781
  }
5768
5782
  getLiteralValueAtPath(path, recursionTracker, origin) {
5769
5783
  if (path.length === 0) {
@@ -5782,79 +5796,29 @@ class ObjectEntity extends ExpressionEntity {
5782
5796
  }
5783
5797
  return UnknownValue;
5784
5798
  }
5785
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
5799
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
5786
5800
  if (path.length === 0) {
5787
5801
  return UNKNOWN_EXPRESSION;
5788
5802
  }
5789
- const key = path[0];
5803
+ const [key, ...subPath] = path;
5790
5804
  const expressionAtPath = this.getMemberExpressionAndTrackDeopt(key, origin);
5791
5805
  if (expressionAtPath) {
5792
- return expressionAtPath.getReturnExpressionWhenCalledAtPath(path.slice(1), callOptions, recursionTracker, origin);
5806
+ return expressionAtPath.getReturnExpressionWhenCalledAtPath(subPath, interaction, recursionTracker, origin);
5793
5807
  }
5794
5808
  if (this.prototypeExpression) {
5795
- return this.prototypeExpression.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
5809
+ return this.prototypeExpression.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
5796
5810
  }
5797
5811
  return UNKNOWN_EXPRESSION;
5798
5812
  }
5799
- hasEffectsWhenAccessedAtPath(path, context) {
5813
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
5800
5814
  const [key, ...subPath] = path;
5801
- if (path.length > 1) {
5802
- if (typeof key !== 'string') {
5803
- return true;
5804
- }
5815
+ if (subPath.length || interaction.type === INTERACTION_CALLED) {
5805
5816
  const expressionAtPath = this.getMemberExpression(key);
5806
5817
  if (expressionAtPath) {
5807
- return expressionAtPath.hasEffectsWhenAccessedAtPath(subPath, context);
5818
+ return expressionAtPath.hasEffectsOnInteractionAtPath(subPath, interaction, context);
5808
5819
  }
5809
5820
  if (this.prototypeExpression) {
5810
- return this.prototypeExpression.hasEffectsWhenAccessedAtPath(path, context);
5811
- }
5812
- return true;
5813
- }
5814
- if (this.hasLostTrack)
5815
- return true;
5816
- if (typeof key === 'string') {
5817
- if (this.propertiesAndGettersByKey[key]) {
5818
- const getters = this.gettersByKey[key];
5819
- if (getters) {
5820
- for (const getter of getters) {
5821
- if (getter.hasEffectsWhenAccessedAtPath(subPath, context))
5822
- return true;
5823
- }
5824
- }
5825
- return false;
5826
- }
5827
- for (const getter of this.unmatchableGetters) {
5828
- if (getter.hasEffectsWhenAccessedAtPath(subPath, context)) {
5829
- return true;
5830
- }
5831
- }
5832
- }
5833
- else {
5834
- for (const getters of Object.values(this.gettersByKey).concat([this.unmatchableGetters])) {
5835
- for (const getter of getters) {
5836
- if (getter.hasEffectsWhenAccessedAtPath(subPath, context))
5837
- return true;
5838
- }
5839
- }
5840
- }
5841
- if (this.prototypeExpression) {
5842
- return this.prototypeExpression.hasEffectsWhenAccessedAtPath(path, context);
5843
- }
5844
- return false;
5845
- }
5846
- hasEffectsWhenAssignedAtPath(path, context) {
5847
- const [key, ...subPath] = path;
5848
- if (path.length > 1) {
5849
- if (typeof key !== 'string') {
5850
- return true;
5851
- }
5852
- const expressionAtPath = this.getMemberExpression(key);
5853
- if (expressionAtPath) {
5854
- return expressionAtPath.hasEffectsWhenAssignedAtPath(subPath, context);
5855
- }
5856
- if (this.prototypeExpression) {
5857
- return this.prototypeExpression.hasEffectsWhenAssignedAtPath(path, context);
5821
+ return this.prototypeExpression.hasEffectsOnInteractionAtPath(path, interaction, context);
5858
5822
  }
5859
5823
  return true;
5860
5824
  }
@@ -5862,47 +5826,39 @@ class ObjectEntity extends ExpressionEntity {
5862
5826
  return false;
5863
5827
  if (this.hasLostTrack)
5864
5828
  return true;
5829
+ const [propertiesAndAccessorsByKey, accessorsByKey, unmatchableAccessors] = interaction.type === INTERACTION_ACCESSED
5830
+ ? [this.propertiesAndGettersByKey, this.gettersByKey, this.unmatchableGetters]
5831
+ : [this.propertiesAndSettersByKey, this.settersByKey, this.unmatchableSetters];
5865
5832
  if (typeof key === 'string') {
5866
- if (this.propertiesAndSettersByKey[key]) {
5867
- const setters = this.settersByKey[key];
5868
- if (setters) {
5869
- for (const setter of setters) {
5870
- if (setter.hasEffectsWhenAssignedAtPath(subPath, context))
5833
+ if (propertiesAndAccessorsByKey[key]) {
5834
+ const accessors = accessorsByKey[key];
5835
+ if (accessors) {
5836
+ for (const accessor of accessors) {
5837
+ if (accessor.hasEffectsOnInteractionAtPath(subPath, interaction, context))
5871
5838
  return true;
5872
5839
  }
5873
5840
  }
5874
5841
  return false;
5875
5842
  }
5876
- for (const property of this.unmatchableSetters) {
5877
- if (property.hasEffectsWhenAssignedAtPath(subPath, context)) {
5843
+ for (const accessor of unmatchableAccessors) {
5844
+ if (accessor.hasEffectsOnInteractionAtPath(subPath, interaction, context)) {
5878
5845
  return true;
5879
5846
  }
5880
5847
  }
5881
5848
  }
5882
5849
  else {
5883
- for (const setters of Object.values(this.settersByKey).concat([this.unmatchableSetters])) {
5884
- for (const setter of setters) {
5885
- if (setter.hasEffectsWhenAssignedAtPath(subPath, context))
5850
+ for (const accessors of Object.values(accessorsByKey).concat([unmatchableAccessors])) {
5851
+ for (const accessor of accessors) {
5852
+ if (accessor.hasEffectsOnInteractionAtPath(subPath, interaction, context))
5886
5853
  return true;
5887
5854
  }
5888
5855
  }
5889
5856
  }
5890
5857
  if (this.prototypeExpression) {
5891
- return this.prototypeExpression.hasEffectsWhenAssignedAtPath(path, context);
5858
+ return this.prototypeExpression.hasEffectsOnInteractionAtPath(path, interaction, context);
5892
5859
  }
5893
5860
  return false;
5894
5861
  }
5895
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
5896
- const key = path[0];
5897
- const expressionAtPath = this.getMemberExpression(key);
5898
- if (expressionAtPath) {
5899
- return expressionAtPath.hasEffectsWhenCalledAtPath(path.slice(1), callOptions, context);
5900
- }
5901
- if (this.prototypeExpression) {
5902
- return this.prototypeExpression.hasEffectsWhenCalledAtPath(path, callOptions, context);
5903
- }
5904
- return true;
5905
- }
5906
5862
  buildPropertyMaps(properties) {
5907
5863
  const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchableGetters, unmatchableSetters } = this;
5908
5864
  const unmatchablePropertiesAndSetters = [];
@@ -6008,9 +5964,9 @@ const isInteger = (prop) => typeof prop === 'string' && /^\d+$/.test(prop);
6008
5964
  // properties as we do not expect new builtin properties to be numbers, this
6009
5965
  // will improve tree-shaking for out-of-bounds array properties
6010
5966
  const OBJECT_PROTOTYPE_FALLBACK = new (class ObjectPrototypeFallbackExpression extends ExpressionEntity {
6011
- deoptimizeThisOnEventAtPath(event, path, thisParameter) {
6012
- if (event === EVENT_CALLED && path.length === 1 && !isInteger(path[0])) {
6013
- thisParameter.deoptimizePath(UNKNOWN_PATH);
5967
+ deoptimizeThisOnInteractionAtPath({ type, thisArg }, path) {
5968
+ if (type === INTERACTION_CALLED && path.length === 1 && !isInteger(path[0])) {
5969
+ thisArg.deoptimizePath(UNKNOWN_PATH);
6014
5970
  }
6015
5971
  }
6016
5972
  getLiteralValueAtPath(path) {
@@ -6019,11 +5975,8 @@ const OBJECT_PROTOTYPE_FALLBACK = new (class ObjectPrototypeFallbackExpression e
6019
5975
  // "undefined"
6020
5976
  return path.length === 1 && isInteger(path[0]) ? undefined : UnknownValue;
6021
5977
  }
6022
- hasEffectsWhenAccessedAtPath(path) {
6023
- return path.length > 1;
6024
- }
6025
- hasEffectsWhenAssignedAtPath(path) {
6026
- return path.length > 1;
5978
+ hasEffectsOnInteractionAtPath(path, { type }) {
5979
+ return path.length > 1 || type === INTERACTION_CALLED;
6027
5980
  }
6028
5981
  })();
6029
5982
  const OBJECT_PROTOTYPE = new ObjectEntity({
@@ -6145,8 +6098,8 @@ const ARRAY_PROTOTYPE = new ObjectEntity({
6145
6098
  flat: METHOD_DEOPTS_SELF_RETURNS_NEW_ARRAY,
6146
6099
  flatMap: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_NEW_ARRAY,
6147
6100
  forEach: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN,
6148
- groupBy: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN,
6149
- groupByToMap: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN,
6101
+ group: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN,
6102
+ groupToMap: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN,
6150
6103
  includes: METHOD_RETURNS_BOOLEAN,
6151
6104
  indexOf: METHOD_RETURNS_NUMBER,
6152
6105
  join: METHOD_RETURNS_STRING,
@@ -6177,23 +6130,17 @@ class ArrayExpression extends NodeBase {
6177
6130
  deoptimizePath(path) {
6178
6131
  this.getObjectEntity().deoptimizePath(path);
6179
6132
  }
6180
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
6181
- this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
6133
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
6134
+ this.getObjectEntity().deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
6182
6135
  }
6183
6136
  getLiteralValueAtPath(path, recursionTracker, origin) {
6184
6137
  return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
6185
6138
  }
6186
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
6187
- return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
6188
- }
6189
- hasEffectsWhenAccessedAtPath(path, context) {
6190
- return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
6139
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
6140
+ return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
6191
6141
  }
6192
- hasEffectsWhenAssignedAtPath(path, context) {
6193
- return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
6194
- }
6195
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
6196
- return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
6142
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
6143
+ return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
6197
6144
  }
6198
6145
  applyDeoptimizations() {
6199
6146
  this.deoptimized = true;
@@ -6258,9 +6205,9 @@ class ArrayPattern extends NodeBase {
6258
6205
  }
6259
6206
  }
6260
6207
  // Patterns are only checked at the emtpy path at the moment
6261
- hasEffectsWhenAssignedAtPath(_path, context) {
6208
+ hasEffectsOnInteractionAtPath(_path, interaction, context) {
6262
6209
  for (const element of this.elements) {
6263
- if (element === null || element === void 0 ? void 0 : element.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context))
6210
+ if (element === null || element === void 0 ? void 0 : element.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context))
6264
6211
  return true;
6265
6212
  }
6266
6213
  return false;
@@ -6319,11 +6266,11 @@ class LocalVariable extends Variable {
6319
6266
  (_b = this.init) === null || _b === void 0 ? void 0 : _b.deoptimizePath(path);
6320
6267
  }
6321
6268
  }
6322
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
6269
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
6323
6270
  if (this.isReassigned || !this.init) {
6324
- return thisParameter.deoptimizePath(UNKNOWN_PATH);
6271
+ return interaction.thisArg.deoptimizePath(UNKNOWN_PATH);
6325
6272
  }
6326
- recursionTracker.withTrackedEntityAtPath(path, this.init, () => this.init.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker), undefined);
6273
+ recursionTracker.withTrackedEntityAtPath(path, this.init, () => this.init.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker), undefined);
6327
6274
  }
6328
6275
  getLiteralValueAtPath(path, recursionTracker, origin) {
6329
6276
  if (this.isReassigned || !this.init) {
@@ -6334,39 +6281,40 @@ class LocalVariable extends Variable {
6334
6281
  return this.init.getLiteralValueAtPath(path, recursionTracker, origin);
6335
6282
  }, UnknownValue);
6336
6283
  }
6337
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
6284
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
6338
6285
  if (this.isReassigned || !this.init) {
6339
6286
  return UNKNOWN_EXPRESSION;
6340
6287
  }
6341
6288
  return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
6342
6289
  this.expressionsToBeDeoptimized.push(origin);
6343
- return this.init.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
6290
+ return this.init.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
6344
6291
  }, UNKNOWN_EXPRESSION);
6345
6292
  }
6346
- hasEffectsWhenAccessedAtPath(path, context) {
6347
- if (this.isReassigned)
6348
- return true;
6349
- return (this.init &&
6350
- !context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
6351
- this.init.hasEffectsWhenAccessedAtPath(path, context));
6352
- }
6353
- hasEffectsWhenAssignedAtPath(path, context) {
6354
- if (this.included)
6355
- return true;
6356
- if (path.length === 0)
6357
- return false;
6358
- if (this.isReassigned)
6359
- return true;
6360
- return (this.init &&
6361
- !context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
6362
- this.init.hasEffectsWhenAssignedAtPath(path, context));
6363
- }
6364
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
6365
- if (this.isReassigned)
6366
- return true;
6367
- return (this.init &&
6368
- !(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
6369
- this.init.hasEffectsWhenCalledAtPath(path, callOptions, context));
6293
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
6294
+ switch (interaction.type) {
6295
+ case INTERACTION_ACCESSED:
6296
+ if (this.isReassigned)
6297
+ return true;
6298
+ return (this.init &&
6299
+ !context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
6300
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6301
+ case INTERACTION_ASSIGNED:
6302
+ if (this.included)
6303
+ return true;
6304
+ if (path.length === 0)
6305
+ return false;
6306
+ if (this.isReassigned)
6307
+ return true;
6308
+ return (this.init &&
6309
+ !context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
6310
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6311
+ case INTERACTION_CALLED:
6312
+ if (this.isReassigned)
6313
+ return true;
6314
+ return (this.init &&
6315
+ !(interaction.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this) &&
6316
+ this.init.hasEffectsOnInteractionAtPath(path, interaction, context));
6317
+ }
6370
6318
  }
6371
6319
  include() {
6372
6320
  if (!this.included) {
@@ -6721,9 +6669,9 @@ const PF = {
6721
6669
  const MUTATES_ARG_WITHOUT_ACCESSOR = {
6722
6670
  __proto__: null,
6723
6671
  [ValueProperties]: {
6724
- hasEffectsWhenCalled(callOptions, context) {
6725
- return (!callOptions.args.length ||
6726
- callOptions.args[0].hasEffectsWhenAssignedAtPath(UNKNOWN_NON_ACCESSOR_PATH, context));
6672
+ hasEffectsWhenCalled({ args }, context) {
6673
+ return (!args.length ||
6674
+ args[0].hasEffectsOnInteractionAtPath(UNKNOWN_NON_ACCESSOR_PATH, NODE_INTERACTION_UNKNOWN_ASSIGNMENT, context));
6727
6675
  }
6728
6676
  }
6729
6677
  };
@@ -7564,16 +7512,21 @@ class GlobalVariable extends Variable {
7564
7512
  getLiteralValueAtPath(path, _recursionTracker, _origin) {
7565
7513
  return getGlobalAtPath([this.name, ...path]) ? UnknownTruthyValue : UnknownValue;
7566
7514
  }
7567
- hasEffectsWhenAccessedAtPath(path) {
7568
- if (path.length === 0) {
7569
- // Technically, "undefined" is a global variable of sorts
7570
- return this.name !== 'undefined' && !getGlobalAtPath([this.name]);
7515
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
7516
+ switch (interaction.type) {
7517
+ case INTERACTION_ACCESSED:
7518
+ if (path.length === 0) {
7519
+ // Technically, "undefined" is a global variable of sorts
7520
+ return this.name !== 'undefined' && !getGlobalAtPath([this.name]);
7521
+ }
7522
+ return !getGlobalAtPath([this.name, ...path].slice(0, -1));
7523
+ case INTERACTION_ASSIGNED:
7524
+ return true;
7525
+ case INTERACTION_CALLED: {
7526
+ const globalAtPath = getGlobalAtPath([this.name, ...path]);
7527
+ return !globalAtPath || globalAtPath.hasEffectsWhenCalled(interaction, context);
7528
+ }
7571
7529
  }
7572
- return !getGlobalAtPath([this.name, ...path].slice(0, -1));
7573
- }
7574
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
7575
- const globalAtPath = getGlobalAtPath([this.name, ...path]);
7576
- return !globalAtPath || globalAtPath.hasEffectsWhenCalled(callOptions, context);
7577
7530
  }
7578
7531
  }
7579
7532
 
@@ -7641,16 +7594,16 @@ class Identifier extends NodeBase {
7641
7594
  // Identifier as property that might be deoptimized by default
7642
7595
  (_a = this.variable) === null || _a === void 0 ? void 0 : _a.deoptimizePath(path);
7643
7596
  }
7644
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
7645
- this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
7597
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
7598
+ this.variable.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
7646
7599
  }
7647
7600
  getLiteralValueAtPath(path, recursionTracker, origin) {
7648
7601
  return this.getVariableRespectingTDZ().getLiteralValueAtPath(path, recursionTracker, origin);
7649
7602
  }
7650
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
7651
- return this.getVariableRespectingTDZ().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
7603
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
7604
+ return this.getVariableRespectingTDZ().getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
7652
7605
  }
7653
- hasEffects() {
7606
+ hasEffects(context) {
7654
7607
  if (!this.deoptimized)
7655
7608
  this.applyDeoptimizations();
7656
7609
  if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
@@ -7658,17 +7611,18 @@ class Identifier extends NodeBase {
7658
7611
  }
7659
7612
  return (this.context.options.treeshake.unknownGlobalSideEffects &&
7660
7613
  this.variable instanceof GlobalVariable &&
7661
- this.variable.hasEffectsWhenAccessedAtPath(EMPTY_PATH));
7614
+ this.variable.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_ACCESS, context));
7662
7615
  }
7663
- hasEffectsWhenAccessedAtPath(path, context) {
7664
- return (this.variable !== null &&
7665
- this.getVariableRespectingTDZ().hasEffectsWhenAccessedAtPath(path, context));
7666
- }
7667
- hasEffectsWhenAssignedAtPath(path, context) {
7668
- return (path.length > 0 ? this.getVariableRespectingTDZ() : this.variable).hasEffectsWhenAssignedAtPath(path, context);
7669
- }
7670
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
7671
- return this.getVariableRespectingTDZ().hasEffectsWhenCalledAtPath(path, callOptions, context);
7616
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
7617
+ switch (interaction.type) {
7618
+ case INTERACTION_ACCESSED:
7619
+ return (this.variable !== null &&
7620
+ this.getVariableRespectingTDZ().hasEffectsOnInteractionAtPath(path, interaction, context));
7621
+ case INTERACTION_ASSIGNED:
7622
+ return (path.length > 0 ? this.getVariableRespectingTDZ() : this.variable).hasEffectsOnInteractionAtPath(path, interaction, context);
7623
+ case INTERACTION_CALLED:
7624
+ return this.getVariableRespectingTDZ().hasEffectsOnInteractionAtPath(path, interaction, context);
7625
+ }
7672
7626
  }
7673
7627
  include() {
7674
7628
  if (!this.deoptimized)
@@ -8028,8 +7982,9 @@ class RestElement extends NodeBase {
8028
7982
  deoptimizePath(path) {
8029
7983
  path.length === 0 && this.argument.deoptimizePath(EMPTY_PATH);
8030
7984
  }
8031
- hasEffectsWhenAssignedAtPath(path, context) {
8032
- return path.length > 0 || this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
7985
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
7986
+ return (path.length > 0 ||
7987
+ this.argument.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
8033
7988
  }
8034
7989
  markDeclarationReached() {
8035
7990
  this.argument.markDeclarationReached();
@@ -8057,17 +8012,17 @@ class FunctionBase extends NodeBase {
8057
8012
  this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
8058
8013
  }
8059
8014
  }
8060
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
8015
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
8061
8016
  if (path.length > 0) {
8062
- this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
8017
+ this.getObjectEntity().deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
8063
8018
  }
8064
8019
  }
8065
8020
  getLiteralValueAtPath(path, recursionTracker, origin) {
8066
8021
  return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
8067
8022
  }
8068
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
8023
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
8069
8024
  if (path.length > 0) {
8070
- return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
8025
+ return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
8071
8026
  }
8072
8027
  if (this.async) {
8073
8028
  if (!this.deoptimizedReturn) {
@@ -8079,24 +8034,18 @@ class FunctionBase extends NodeBase {
8079
8034
  }
8080
8035
  return this.scope.getReturnExpression();
8081
8036
  }
8082
- hasEffectsWhenAccessedAtPath(path, context) {
8083
- return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
8084
- }
8085
- hasEffectsWhenAssignedAtPath(path, context) {
8086
- return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
8087
- }
8088
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
8089
- if (path.length > 0) {
8090
- return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
8037
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
8038
+ if (path.length > 0 || interaction.type !== INTERACTION_CALLED) {
8039
+ return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
8091
8040
  }
8092
8041
  if (this.async) {
8093
8042
  const { propertyReadSideEffects } = this.context.options
8094
8043
  .treeshake;
8095
8044
  const returnExpression = this.scope.getReturnExpression();
8096
- if (returnExpression.hasEffectsWhenCalledAtPath(['then'], { args: NO_ARGS, thisParam: null, withNew: false }, context) ||
8045
+ if (returnExpression.hasEffectsOnInteractionAtPath(['then'], NODE_INTERACTION_UNKNOWN_CALL, context) ||
8097
8046
  (propertyReadSideEffects &&
8098
8047
  (propertyReadSideEffects === 'always' ||
8099
- returnExpression.hasEffectsWhenAccessedAtPath(['then'], context)))) {
8048
+ returnExpression.hasEffectsOnInteractionAtPath(['then'], NODE_INTERACTION_UNKNOWN_ACCESS, context)))) {
8100
8049
  return true;
8101
8050
  }
8102
8051
  }
@@ -8150,20 +8099,22 @@ class ArrowFunctionExpression extends FunctionBase {
8150
8099
  this.applyDeoptimizations();
8151
8100
  return false;
8152
8101
  }
8153
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
8154
- if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
8155
- return true;
8156
- const { ignore, brokenFlow } = context;
8157
- context.ignore = {
8158
- breaks: false,
8159
- continues: false,
8160
- labels: new Set(),
8161
- returnYield: true
8162
- };
8163
- if (this.body.hasEffects(context))
8102
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
8103
+ if (super.hasEffectsOnInteractionAtPath(path, interaction, context))
8164
8104
  return true;
8165
- context.ignore = ignore;
8166
- context.brokenFlow = brokenFlow;
8105
+ if (interaction.type === INTERACTION_CALLED) {
8106
+ const { ignore, brokenFlow } = context;
8107
+ context.ignore = {
8108
+ breaks: false,
8109
+ continues: false,
8110
+ labels: new Set(),
8111
+ returnYield: true
8112
+ };
8113
+ if (this.body.hasEffects(context))
8114
+ return true;
8115
+ context.ignore = ignore;
8116
+ context.brokenFlow = brokenFlow;
8117
+ }
8167
8118
  return false;
8168
8119
  }
8169
8120
  include(context, includeChildrenRecursively) {
@@ -8249,11 +8200,12 @@ class ObjectPattern extends NodeBase {
8249
8200
  }
8250
8201
  }
8251
8202
  }
8252
- hasEffectsWhenAssignedAtPath(path, context) {
8253
- if (path.length > 0)
8254
- return true;
8203
+ hasEffectsOnInteractionAtPath(
8204
+ // At the moment, this is only triggered for assignment left-hand sides,
8205
+ // where the path is empty
8206
+ _path, interaction, context) {
8255
8207
  for (const property of this.properties) {
8256
- if (property.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context))
8208
+ if (property.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context))
8257
8209
  return true;
8258
8210
  }
8259
8211
  return false;
@@ -8267,75 +8219,78 @@ class ObjectPattern extends NodeBase {
8267
8219
 
8268
8220
  class AssignmentExpression extends NodeBase {
8269
8221
  hasEffects(context) {
8270
- if (!this.deoptimized)
8222
+ const { deoptimized, left, right } = this;
8223
+ if (!deoptimized)
8271
8224
  this.applyDeoptimizations();
8272
- return (this.right.hasEffects(context) ||
8273
- this.left.hasEffects(context) ||
8274
- this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context));
8225
+ // MemberExpressions do not access the property before assignments if the
8226
+ // operator is '='.
8227
+ return (right.hasEffects(context) || left.hasEffectsAsAssignmentTarget(context, this.operator !== '='));
8275
8228
  }
8276
- hasEffectsWhenAccessedAtPath(path, context) {
8277
- return path.length > 0 && this.right.hasEffectsWhenAccessedAtPath(path, context);
8229
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
8230
+ return this.right.hasEffectsOnInteractionAtPath(path, interaction, context);
8278
8231
  }
8279
8232
  include(context, includeChildrenRecursively) {
8280
- if (!this.deoptimized)
8233
+ const { deoptimized, left, right, operator } = this;
8234
+ if (!deoptimized)
8281
8235
  this.applyDeoptimizations();
8282
8236
  this.included = true;
8283
- let hasEffectsContext;
8284
8237
  if (includeChildrenRecursively ||
8285
- this.operator !== '=' ||
8286
- this.left.included ||
8287
- ((hasEffectsContext = createHasEffectsContext()),
8288
- this.left.hasEffects(hasEffectsContext) ||
8289
- this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, hasEffectsContext))) {
8290
- this.left.include(context, includeChildrenRecursively);
8238
+ operator !== '=' ||
8239
+ left.included ||
8240
+ left.hasEffectsAsAssignmentTarget(createHasEffectsContext(), false)) {
8241
+ left.includeAsAssignmentTarget(context, includeChildrenRecursively, operator !== '=');
8291
8242
  }
8292
- this.right.include(context, includeChildrenRecursively);
8243
+ right.include(context, includeChildrenRecursively);
8244
+ }
8245
+ initialise() {
8246
+ this.left.setAssignedValue(this.right);
8293
8247
  }
8294
8248
  render(code, options, { preventASI, renderedParentType, renderedSurroundingElement } = BLANK) {
8295
- if (this.left.included) {
8296
- this.left.render(code, options);
8297
- this.right.render(code, options);
8249
+ const { left, right, start, end, parent } = this;
8250
+ if (left.included) {
8251
+ left.render(code, options);
8252
+ right.render(code, options);
8298
8253
  }
8299
8254
  else {
8300
- const inclusionStart = findNonWhiteSpace(code.original, findFirstOccurrenceOutsideComment(code.original, '=', this.left.end) + 1);
8301
- code.remove(this.start, inclusionStart);
8255
+ const inclusionStart = findNonWhiteSpace(code.original, findFirstOccurrenceOutsideComment(code.original, '=', left.end) + 1);
8256
+ code.remove(start, inclusionStart);
8302
8257
  if (preventASI) {
8303
- removeLineBreaks(code, inclusionStart, this.right.start);
8258
+ removeLineBreaks(code, inclusionStart, right.start);
8304
8259
  }
8305
- this.right.render(code, options, {
8306
- renderedParentType: renderedParentType || this.parent.type,
8307
- renderedSurroundingElement: renderedSurroundingElement || this.parent.type
8260
+ right.render(code, options, {
8261
+ renderedParentType: renderedParentType || parent.type,
8262
+ renderedSurroundingElement: renderedSurroundingElement || parent.type
8308
8263
  });
8309
8264
  }
8310
8265
  if (options.format === 'system') {
8311
- if (this.left instanceof Identifier) {
8312
- const variable = this.left.variable;
8266
+ if (left instanceof Identifier) {
8267
+ const variable = left.variable;
8313
8268
  const exportNames = options.exportNamesByVariable.get(variable);
8314
8269
  if (exportNames) {
8315
8270
  if (exportNames.length === 1) {
8316
- renderSystemExportExpression(variable, this.start, this.end, code, options);
8271
+ renderSystemExportExpression(variable, start, end, code, options);
8317
8272
  }
8318
8273
  else {
8319
- renderSystemExportSequenceAfterExpression(variable, this.start, this.end, this.parent.type !== ExpressionStatement$1, code, options);
8274
+ renderSystemExportSequenceAfterExpression(variable, start, end, parent.type !== ExpressionStatement$1, code, options);
8320
8275
  }
8321
8276
  return;
8322
8277
  }
8323
8278
  }
8324
8279
  else {
8325
8280
  const systemPatternExports = [];
8326
- this.left.addExportedVariables(systemPatternExports, options.exportNamesByVariable);
8281
+ left.addExportedVariables(systemPatternExports, options.exportNamesByVariable);
8327
8282
  if (systemPatternExports.length > 0) {
8328
- renderSystemExportFunction(systemPatternExports, this.start, this.end, renderedSurroundingElement === ExpressionStatement$1, code, options);
8283
+ renderSystemExportFunction(systemPatternExports, start, end, renderedSurroundingElement === ExpressionStatement$1, code, options);
8329
8284
  return;
8330
8285
  }
8331
8286
  }
8332
8287
  }
8333
- if (this.left.included &&
8334
- this.left instanceof ObjectPattern &&
8288
+ if (left.included &&
8289
+ left instanceof ObjectPattern &&
8335
8290
  (renderedSurroundingElement === ExpressionStatement$1 ||
8336
8291
  renderedSurroundingElement === ArrowFunctionExpression$1)) {
8337
- code.appendRight(this.start, '(');
8338
- code.prependLeft(this.end, ')');
8292
+ code.appendRight(start, '(');
8293
+ code.prependLeft(end, ')');
8339
8294
  }
8340
8295
  }
8341
8296
  applyDeoptimizations() {
@@ -8356,27 +8311,15 @@ class AssignmentPattern extends NodeBase {
8356
8311
  deoptimizePath(path) {
8357
8312
  path.length === 0 && this.left.deoptimizePath(path);
8358
8313
  }
8359
- hasEffectsWhenAssignedAtPath(path, context) {
8360
- return path.length > 0 || this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
8361
- }
8362
- include(context, includeChildrenRecursively) {
8363
- if (!this.deoptimized)
8364
- this.applyDeoptimizations();
8365
- this.included = true;
8366
- this.left.include(context, includeChildrenRecursively);
8367
- this.right.include(context, includeChildrenRecursively);
8314
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
8315
+ return (path.length > 0 || this.left.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
8368
8316
  }
8369
8317
  markDeclarationReached() {
8370
8318
  this.left.markDeclarationReached();
8371
8319
  }
8372
8320
  render(code, options, { isShorthandProperty } = BLANK) {
8373
8321
  this.left.render(code, options, { isShorthandProperty });
8374
- if (this.right.included) {
8375
- this.right.render(code, options);
8376
- }
8377
- else {
8378
- code.remove(this.left.end, this.end);
8379
- }
8322
+ this.right.render(code, options);
8380
8323
  }
8381
8324
  applyDeoptimizations() {
8382
8325
  this.deoptimized = true;
@@ -8390,14 +8333,8 @@ class ArgumentsVariable extends LocalVariable {
8390
8333
  constructor(context) {
8391
8334
  super('arguments', null, UNKNOWN_EXPRESSION, context);
8392
8335
  }
8393
- hasEffectsWhenAccessedAtPath(path) {
8394
- return path.length > 1;
8395
- }
8396
- hasEffectsWhenAssignedAtPath() {
8397
- return true;
8398
- }
8399
- hasEffectsWhenCalledAtPath() {
8400
- return true;
8336
+ hasEffectsOnInteractionAtPath(path, { type }) {
8337
+ return type !== INTERACTION_ACCESSED || path.length > 1;
8401
8338
  }
8402
8339
  }
8403
8340
 
@@ -8413,8 +8350,8 @@ class ThisVariable extends LocalVariable {
8413
8350
  for (const path of this.deoptimizedPaths) {
8414
8351
  entity.deoptimizePath(path);
8415
8352
  }
8416
- for (const thisDeoptimization of this.thisDeoptimizationList) {
8417
- this.applyThisDeoptimizationEvent(entity, thisDeoptimization);
8353
+ for (const { interaction, path } of this.thisDeoptimizationList) {
8354
+ entity.deoptimizeThisOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
8418
8355
  }
8419
8356
  this.entitiesToBeDeoptimized.add(entity);
8420
8357
  }
@@ -8428,29 +8365,21 @@ class ThisVariable extends LocalVariable {
8428
8365
  entity.deoptimizePath(path);
8429
8366
  }
8430
8367
  }
8431
- deoptimizeThisOnEventAtPath(event, path, thisParameter) {
8368
+ deoptimizeThisOnInteractionAtPath(interaction, path) {
8432
8369
  const thisDeoptimization = {
8433
- event,
8434
- path,
8435
- thisParameter
8370
+ interaction,
8371
+ path
8436
8372
  };
8437
- if (!this.thisDeoptimizations.trackEntityAtPathAndGetIfTracked(path, event, thisParameter)) {
8373
+ if (!this.thisDeoptimizations.trackEntityAtPathAndGetIfTracked(path, interaction.type, interaction.thisArg)) {
8438
8374
  for (const entity of this.entitiesToBeDeoptimized) {
8439
- this.applyThisDeoptimizationEvent(entity, thisDeoptimization);
8375
+ entity.deoptimizeThisOnInteractionAtPath(interaction, path, SHARED_RECURSION_TRACKER);
8440
8376
  }
8441
8377
  this.thisDeoptimizationList.push(thisDeoptimization);
8442
8378
  }
8443
8379
  }
8444
- hasEffectsWhenAccessedAtPath(path, context) {
8445
- return (this.getInit(context).hasEffectsWhenAccessedAtPath(path, context) ||
8446
- super.hasEffectsWhenAccessedAtPath(path, context));
8447
- }
8448
- hasEffectsWhenAssignedAtPath(path, context) {
8449
- return (this.getInit(context).hasEffectsWhenAssignedAtPath(path, context) ||
8450
- super.hasEffectsWhenAssignedAtPath(path, context));
8451
- }
8452
- applyThisDeoptimizationEvent(entity, { event, path, thisParameter }) {
8453
- entity.deoptimizeThisOnEventAtPath(event, path, thisParameter === this ? entity : thisParameter, SHARED_RECURSION_TRACKER);
8380
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
8381
+ return (this.getInit(context).hasEffectsOnInteractionAtPath(path, interaction, context) ||
8382
+ super.hasEffectsOnInteractionAtPath(path, interaction, context));
8454
8383
  }
8455
8384
  getInit(context) {
8456
8385
  return context.replacedVariableInits.get(this) || UNKNOWN_EXPRESSION;
@@ -8486,42 +8415,44 @@ class FunctionNode extends FunctionBase {
8486
8415
  createScope(parentScope) {
8487
8416
  this.scope = new FunctionScope(parentScope, this.context);
8488
8417
  }
8489
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
8490
- super.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
8491
- if (event === EVENT_CALLED && path.length === 0) {
8492
- this.scope.thisVariable.addEntityToBeDeoptimized(thisParameter);
8418
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
8419
+ super.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
8420
+ if (interaction.type === INTERACTION_CALLED && path.length === 0) {
8421
+ this.scope.thisVariable.addEntityToBeDeoptimized(interaction.thisArg);
8493
8422
  }
8494
8423
  }
8495
- hasEffects() {
8424
+ hasEffects(context) {
8496
8425
  var _a;
8497
8426
  if (!this.deoptimized)
8498
8427
  this.applyDeoptimizations();
8499
- return !!((_a = this.id) === null || _a === void 0 ? void 0 : _a.hasEffects());
8428
+ return !!((_a = this.id) === null || _a === void 0 ? void 0 : _a.hasEffects(context));
8500
8429
  }
8501
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
8502
- if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
8503
- return true;
8504
- const thisInit = context.replacedVariableInits.get(this.scope.thisVariable);
8505
- context.replacedVariableInits.set(this.scope.thisVariable, callOptions.withNew
8506
- ? new ObjectEntity(Object.create(null), OBJECT_PROTOTYPE)
8507
- : UNKNOWN_EXPRESSION);
8508
- const { brokenFlow, ignore } = context;
8509
- context.ignore = {
8510
- breaks: false,
8511
- continues: false,
8512
- labels: new Set(),
8513
- returnYield: true
8514
- };
8515
- if (this.body.hasEffects(context))
8430
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
8431
+ if (super.hasEffectsOnInteractionAtPath(path, interaction, context))
8516
8432
  return true;
8517
- context.brokenFlow = brokenFlow;
8518
- if (thisInit) {
8519
- context.replacedVariableInits.set(this.scope.thisVariable, thisInit);
8520
- }
8521
- else {
8522
- context.replacedVariableInits.delete(this.scope.thisVariable);
8433
+ if (interaction.type === INTERACTION_CALLED) {
8434
+ const thisInit = context.replacedVariableInits.get(this.scope.thisVariable);
8435
+ context.replacedVariableInits.set(this.scope.thisVariable, interaction.withNew
8436
+ ? new ObjectEntity(Object.create(null), OBJECT_PROTOTYPE)
8437
+ : UNKNOWN_EXPRESSION);
8438
+ const { brokenFlow, ignore } = context;
8439
+ context.ignore = {
8440
+ breaks: false,
8441
+ continues: false,
8442
+ labels: new Set(),
8443
+ returnYield: true
8444
+ };
8445
+ if (this.body.hasEffects(context))
8446
+ return true;
8447
+ context.brokenFlow = brokenFlow;
8448
+ if (thisInit) {
8449
+ context.replacedVariableInits.set(this.scope.thisVariable, thisInit);
8450
+ }
8451
+ else {
8452
+ context.replacedVariableInits.delete(this.scope.thisVariable);
8453
+ }
8454
+ context.ignore = ignore;
8523
8455
  }
8524
- context.ignore = ignore;
8525
8456
  return false;
8526
8457
  }
8527
8458
  include(context, includeChildrenRecursively) {
@@ -8624,12 +8555,13 @@ class BinaryExpression extends NodeBase {
8624
8555
  // support some implicit type coercion runtime errors
8625
8556
  if (this.operator === '+' &&
8626
8557
  this.parent instanceof ExpressionStatement &&
8627
- this.left.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this) === '')
8558
+ this.left.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this) === '') {
8628
8559
  return true;
8560
+ }
8629
8561
  return super.hasEffects(context);
8630
8562
  }
8631
- hasEffectsWhenAccessedAtPath(path) {
8632
- return path.length > 1;
8563
+ hasEffectsOnInteractionAtPath(path, { type }) {
8564
+ return type !== INTERACTION_ACCESSED || path.length > 1;
8633
8565
  }
8634
8566
  render(code, options, { renderedSurroundingElement } = BLANK) {
8635
8567
  this.left.render(code, options, { renderedSurroundingElement });
@@ -8688,7 +8620,7 @@ function renderCallArguments(code, options, node) {
8688
8620
  }
8689
8621
 
8690
8622
  class Literal extends NodeBase {
8691
- deoptimizeThisOnEventAtPath() { }
8623
+ deoptimizeThisOnInteractionAtPath() { }
8692
8624
  getLiteralValueAtPath(path) {
8693
8625
  if (path.length > 0 ||
8694
8626
  // unknown literals can also be null but do not start with an "n"
@@ -8705,17 +8637,16 @@ class Literal extends NodeBase {
8705
8637
  return UNKNOWN_EXPRESSION;
8706
8638
  return getMemberReturnExpressionWhenCalled(this.members, path[0]);
8707
8639
  }
8708
- hasEffectsWhenAccessedAtPath(path) {
8709
- if (this.value === null) {
8710
- return path.length > 0;
8711
- }
8712
- return path.length > 1;
8713
- }
8714
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
8715
- if (path.length === 1) {
8716
- return hasMemberEffectWhenCalled(this.members, path[0], callOptions, context);
8640
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
8641
+ switch (interaction.type) {
8642
+ case INTERACTION_ACCESSED:
8643
+ return path.length > (this.value === null ? 0 : 1);
8644
+ case INTERACTION_ASSIGNED:
8645
+ return true;
8646
+ case INTERACTION_CALLED:
8647
+ return (path.length !== 1 ||
8648
+ hasMemberEffectWhenCalled(this.members, path[0], interaction, context));
8717
8649
  }
8718
- return true;
8719
8650
  }
8720
8651
  initialise() {
8721
8652
  this.members = getLiteralMembersForValue(this.value);
@@ -8773,6 +8704,7 @@ class MemberExpression extends NodeBase {
8773
8704
  constructor() {
8774
8705
  super(...arguments);
8775
8706
  this.variable = null;
8707
+ this.assignmentDeoptimized = false;
8776
8708
  this.bound = false;
8777
8709
  this.expressionsToBeDeoptimized = [];
8778
8710
  this.replacement = null;
@@ -8782,7 +8714,7 @@ class MemberExpression extends NodeBase {
8782
8714
  const path = getPathIfNotComputed(this);
8783
8715
  const baseVariable = path && this.scope.findVariable(path[0].key);
8784
8716
  if (baseVariable && baseVariable.isNamespace) {
8785
- const resolvedVariable = this.resolveNamespaceVariables(baseVariable, path.slice(1));
8717
+ const resolvedVariable = resolveNamespaceVariables(baseVariable, path.slice(1), this.context);
8786
8718
  if (!resolvedVariable) {
8787
8719
  super.bind();
8788
8720
  }
@@ -8823,21 +8755,21 @@ class MemberExpression extends NodeBase {
8823
8755
  }
8824
8756
  }
8825
8757
  }
8826
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
8758
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
8827
8759
  if (this.variable) {
8828
- this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
8760
+ this.variable.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
8829
8761
  }
8830
8762
  else if (!this.replacement) {
8831
8763
  if (path.length < MAX_PATH_DEPTH) {
8832
- this.object.deoptimizeThisOnEventAtPath(event, [this.getPropertyKey(), ...path], thisParameter, recursionTracker);
8764
+ this.object.deoptimizeThisOnInteractionAtPath(interaction, [this.getPropertyKey(), ...path], recursionTracker);
8833
8765
  }
8834
8766
  else {
8835
- thisParameter.deoptimizePath(UNKNOWN_PATH);
8767
+ interaction.thisArg.deoptimizePath(UNKNOWN_PATH);
8836
8768
  }
8837
8769
  }
8838
8770
  }
8839
8771
  getLiteralValueAtPath(path, recursionTracker, origin) {
8840
- if (this.variable !== null) {
8772
+ if (this.variable) {
8841
8773
  return this.variable.getLiteralValueAtPath(path, recursionTracker, origin);
8842
8774
  }
8843
8775
  if (this.replacement) {
@@ -8849,81 +8781,62 @@ class MemberExpression extends NodeBase {
8849
8781
  }
8850
8782
  return UnknownValue;
8851
8783
  }
8852
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
8853
- if (this.variable !== null) {
8854
- return this.variable.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
8784
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
8785
+ if (this.variable) {
8786
+ return this.variable.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
8855
8787
  }
8856
8788
  if (this.replacement) {
8857
8789
  return UNKNOWN_EXPRESSION;
8858
8790
  }
8859
8791
  this.expressionsToBeDeoptimized.push(origin);
8860
8792
  if (path.length < MAX_PATH_DEPTH) {
8861
- return this.object.getReturnExpressionWhenCalledAtPath([this.getPropertyKey(), ...path], callOptions, recursionTracker, origin);
8793
+ return this.object.getReturnExpressionWhenCalledAtPath([this.getPropertyKey(), ...path], interaction, recursionTracker, origin);
8862
8794
  }
8863
8795
  return UNKNOWN_EXPRESSION;
8864
8796
  }
8865
8797
  hasEffects(context) {
8866
8798
  if (!this.deoptimized)
8867
8799
  this.applyDeoptimizations();
8868
- const { propertyReadSideEffects } = this.context.options
8869
- .treeshake;
8870
8800
  return (this.property.hasEffects(context) ||
8871
8801
  this.object.hasEffects(context) ||
8872
- // Assignments do not access the property before assigning
8873
- (!(this.variable ||
8874
- this.replacement ||
8875
- (this.parent instanceof AssignmentExpression && this.parent.operator === '=')) &&
8876
- propertyReadSideEffects &&
8877
- (propertyReadSideEffects === 'always' ||
8878
- this.object.hasEffectsWhenAccessedAtPath([this.getPropertyKey()], context))));
8879
- }
8880
- hasEffectsWhenAccessedAtPath(path, context) {
8881
- if (this.variable !== null) {
8882
- return this.variable.hasEffectsWhenAccessedAtPath(path, context);
8883
- }
8884
- if (this.replacement) {
8885
- return true;
8886
- }
8887
- if (path.length < MAX_PATH_DEPTH) {
8888
- return this.object.hasEffectsWhenAccessedAtPath([this.getPropertyKey(), ...path], context);
8889
- }
8890
- return true;
8802
+ this.hasAccessEffect(context));
8891
8803
  }
8892
- hasEffectsWhenAssignedAtPath(path, context) {
8893
- if (this.variable !== null) {
8894
- return this.variable.hasEffectsWhenAssignedAtPath(path, context);
8895
- }
8896
- if (this.replacement) {
8897
- return true;
8898
- }
8899
- if (path.length < MAX_PATH_DEPTH) {
8900
- return this.object.hasEffectsWhenAssignedAtPath([this.getPropertyKey(), ...path], context);
8901
- }
8902
- return true;
8804
+ hasEffectsAsAssignmentTarget(context, checkAccess) {
8805
+ if (checkAccess && !this.deoptimized)
8806
+ this.applyDeoptimizations();
8807
+ if (!this.assignmentDeoptimized)
8808
+ this.applyAssignmentDeoptimization();
8809
+ return (this.property.hasEffects(context) ||
8810
+ this.object.hasEffects(context) ||
8811
+ (checkAccess && this.hasAccessEffect(context)) ||
8812
+ this.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.assignmentInteraction, context));
8903
8813
  }
8904
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
8905
- if (this.variable !== null) {
8906
- return this.variable.hasEffectsWhenCalledAtPath(path, callOptions, context);
8814
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
8815
+ if (this.variable) {
8816
+ return this.variable.hasEffectsOnInteractionAtPath(path, interaction, context);
8907
8817
  }
8908
8818
  if (this.replacement) {
8909
8819
  return true;
8910
8820
  }
8911
8821
  if (path.length < MAX_PATH_DEPTH) {
8912
- return this.object.hasEffectsWhenCalledAtPath([this.getPropertyKey(), ...path], callOptions, context);
8822
+ return this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey(), ...path], interaction, context);
8913
8823
  }
8914
8824
  return true;
8915
8825
  }
8916
8826
  include(context, includeChildrenRecursively) {
8917
8827
  if (!this.deoptimized)
8918
8828
  this.applyDeoptimizations();
8919
- if (!this.included) {
8920
- this.included = true;
8921
- if (this.variable !== null) {
8922
- this.context.includeVariableInModule(this.variable);
8923
- }
8829
+ this.includeProperties(context, includeChildrenRecursively);
8830
+ }
8831
+ includeAsAssignmentTarget(context, includeChildrenRecursively, deoptimizeAccess) {
8832
+ if (!this.assignmentDeoptimized)
8833
+ this.applyAssignmentDeoptimization();
8834
+ if (deoptimizeAccess) {
8835
+ this.include(context, includeChildrenRecursively);
8836
+ }
8837
+ else {
8838
+ this.includeProperties(context, includeChildrenRecursively);
8924
8839
  }
8925
- this.object.include(context, includeChildrenRecursively);
8926
- this.property.include(context, includeChildrenRecursively);
8927
8840
  }
8928
8841
  includeCallArguments(context, args) {
8929
8842
  if (this.variable) {
@@ -8935,6 +8848,7 @@ class MemberExpression extends NodeBase {
8935
8848
  }
8936
8849
  initialise() {
8937
8850
  this.propertyKey = getResolvablePropertyKey(this);
8851
+ this.accessInteraction = { thisArg: this.object, type: INTERACTION_ACCESSED };
8938
8852
  }
8939
8853
  render(code, options, { renderedParentType, isCalleeOfRenderedParent, renderedSurroundingElement } = BLANK) {
8940
8854
  if (this.variable || this.replacement) {
@@ -8955,6 +8869,13 @@ class MemberExpression extends NodeBase {
8955
8869
  this.property.render(code, options);
8956
8870
  }
8957
8871
  }
8872
+ setAssignedValue(value) {
8873
+ this.assignmentInteraction = {
8874
+ args: [value],
8875
+ thisArg: this.object,
8876
+ type: INTERACTION_ASSIGNED
8877
+ };
8878
+ }
8958
8879
  applyDeoptimizations() {
8959
8880
  this.deoptimized = true;
8960
8881
  const { propertyReadSideEffects } = this.context.options
@@ -8964,13 +8885,21 @@ class MemberExpression extends NodeBase {
8964
8885
  this.bound &&
8965
8886
  propertyReadSideEffects &&
8966
8887
  !(this.variable || this.replacement)) {
8967
- // Regular Assignments do not access the property before assigning
8968
- if (!(this.parent instanceof AssignmentExpression && this.parent.operator === '=')) {
8969
- this.object.deoptimizeThisOnEventAtPath(EVENT_ACCESSED, [this.propertyKey], this.object, SHARED_RECURSION_TRACKER);
8970
- }
8971
- if (this.parent instanceof AssignmentExpression) {
8972
- this.object.deoptimizeThisOnEventAtPath(EVENT_ASSIGNED, [this.propertyKey], this.object, SHARED_RECURSION_TRACKER);
8973
- }
8888
+ const propertyKey = this.getPropertyKey();
8889
+ this.object.deoptimizeThisOnInteractionAtPath(this.accessInteraction, [propertyKey], SHARED_RECURSION_TRACKER);
8890
+ this.context.requestTreeshakingPass();
8891
+ }
8892
+ }
8893
+ applyAssignmentDeoptimization() {
8894
+ this.assignmentDeoptimized = true;
8895
+ const { propertyReadSideEffects } = this.context.options
8896
+ .treeshake;
8897
+ if (
8898
+ // Namespaces are not bound and should not be deoptimized
8899
+ this.bound &&
8900
+ propertyReadSideEffects &&
8901
+ !(this.variable || this.replacement)) {
8902
+ this.object.deoptimizeThisOnInteractionAtPath(this.assignmentInteraction, [this.getPropertyKey()], SHARED_RECURSION_TRACKER);
8974
8903
  this.context.requestTreeshakingPass();
8975
8904
  }
8976
8905
  }
@@ -8996,28 +8925,46 @@ class MemberExpression extends NodeBase {
8996
8925
  }
8997
8926
  return this.propertyKey;
8998
8927
  }
8999
- resolveNamespaceVariables(baseVariable, path) {
9000
- if (path.length === 0)
9001
- return baseVariable;
9002
- if (!baseVariable.isNamespace || baseVariable instanceof ExternalVariable)
9003
- return null;
9004
- const exportName = path[0].key;
9005
- const variable = baseVariable.context.traceExport(exportName);
9006
- if (!variable) {
9007
- const fileName = baseVariable.context.fileName;
9008
- this.context.warn({
9009
- code: 'MISSING_EXPORT',
9010
- exporter: relativeId(fileName),
9011
- importer: relativeId(this.context.fileName),
9012
- message: `'${exportName}' is not exported by '${relativeId(fileName)}'`,
9013
- missing: exportName,
9014
- url: `https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module`
9015
- }, path[0].pos);
9016
- return 'undefined';
8928
+ hasAccessEffect(context) {
8929
+ const { propertyReadSideEffects } = this.context.options
8930
+ .treeshake;
8931
+ return (!(this.variable || this.replacement) &&
8932
+ propertyReadSideEffects &&
8933
+ (propertyReadSideEffects === 'always' ||
8934
+ this.object.hasEffectsOnInteractionAtPath([this.getPropertyKey()], this.accessInteraction, context)));
8935
+ }
8936
+ includeProperties(context, includeChildrenRecursively) {
8937
+ if (!this.included) {
8938
+ this.included = true;
8939
+ if (this.variable) {
8940
+ this.context.includeVariableInModule(this.variable);
8941
+ }
9017
8942
  }
9018
- return this.resolveNamespaceVariables(variable, path.slice(1));
8943
+ this.object.include(context, includeChildrenRecursively);
8944
+ this.property.include(context, includeChildrenRecursively);
9019
8945
  }
9020
8946
  }
8947
+ function resolveNamespaceVariables(baseVariable, path, astContext) {
8948
+ if (path.length === 0)
8949
+ return baseVariable;
8950
+ if (!baseVariable.isNamespace || baseVariable instanceof ExternalVariable)
8951
+ return null;
8952
+ const exportName = path[0].key;
8953
+ const variable = baseVariable.context.traceExport(exportName);
8954
+ if (!variable) {
8955
+ const fileName = baseVariable.context.fileName;
8956
+ astContext.warn({
8957
+ code: 'MISSING_EXPORT',
8958
+ exporter: relativeId(fileName),
8959
+ importer: relativeId(astContext.fileName),
8960
+ message: `'${exportName}' is not exported by '${relativeId(fileName)}'`,
8961
+ missing: exportName,
8962
+ url: `https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module`
8963
+ }, path[0].pos);
8964
+ return 'undefined';
8965
+ }
8966
+ return resolveNamespaceVariables(variable, path.slice(1), astContext);
8967
+ }
9021
8968
 
9022
8969
  class CallExpressionBase extends NodeBase {
9023
8970
  constructor() {
@@ -9047,15 +8994,15 @@ class CallExpressionBase extends NodeBase {
9047
8994
  returnExpression.deoptimizePath(path);
9048
8995
  }
9049
8996
  }
9050
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
8997
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
9051
8998
  const returnExpression = this.getReturnExpression(recursionTracker);
9052
8999
  if (returnExpression === UNKNOWN_EXPRESSION) {
9053
- thisParameter.deoptimizePath(UNKNOWN_PATH);
9000
+ interaction.thisArg.deoptimizePath(UNKNOWN_PATH);
9054
9001
  }
9055
9002
  else {
9056
9003
  recursionTracker.withTrackedEntityAtPath(path, returnExpression, () => {
9057
- this.expressionsToBeDeoptimized.add(thisParameter);
9058
- returnExpression.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
9004
+ this.expressionsToBeDeoptimized.add(interaction.thisArg);
9005
+ returnExpression.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
9059
9006
  }, undefined);
9060
9007
  }
9061
9008
  }
@@ -9069,27 +9016,31 @@ class CallExpressionBase extends NodeBase {
9069
9016
  return returnExpression.getLiteralValueAtPath(path, recursionTracker, origin);
9070
9017
  }, UnknownValue);
9071
9018
  }
9072
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
9019
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
9073
9020
  const returnExpression = this.getReturnExpression(recursionTracker);
9074
9021
  if (this.returnExpression === UNKNOWN_EXPRESSION) {
9075
9022
  return UNKNOWN_EXPRESSION;
9076
9023
  }
9077
9024
  return recursionTracker.withTrackedEntityAtPath(path, returnExpression, () => {
9078
9025
  this.deoptimizableDependentExpressions.push(origin);
9079
- return returnExpression.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
9026
+ return returnExpression.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
9080
9027
  }, UNKNOWN_EXPRESSION);
9081
9028
  }
9082
- hasEffectsWhenAccessedAtPath(path, context) {
9083
- return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
9084
- this.getReturnExpression().hasEffectsWhenAccessedAtPath(path, context));
9085
- }
9086
- hasEffectsWhenAssignedAtPath(path, context) {
9087
- return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
9088
- this.getReturnExpression().hasEffectsWhenAssignedAtPath(path, context));
9089
- }
9090
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
9091
- return (!(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
9092
- this.getReturnExpression().hasEffectsWhenCalledAtPath(path, callOptions, context));
9029
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
9030
+ const { type } = interaction;
9031
+ if (type === INTERACTION_CALLED) {
9032
+ if ((interaction.withNew
9033
+ ? context.instantiated
9034
+ : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this)) {
9035
+ return false;
9036
+ }
9037
+ }
9038
+ else if ((type === INTERACTION_ASSIGNED
9039
+ ? context.assigned
9040
+ : context.accessed).trackEntityAtPathAndGetIfTracked(path, this)) {
9041
+ return false;
9042
+ }
9043
+ return this.getReturnExpression().hasEffectsOnInteractionAtPath(path, interaction, context);
9093
9044
  }
9094
9045
  }
9095
9046
 
@@ -9112,11 +9063,12 @@ class CallExpression extends CallExpressionBase {
9112
9063
  }, this.start);
9113
9064
  }
9114
9065
  }
9115
- this.callOptions = {
9066
+ this.interaction = {
9116
9067
  args: this.arguments,
9117
- thisParam: this.callee instanceof MemberExpression && !this.callee.variable
9068
+ thisArg: this.callee instanceof MemberExpression && !this.callee.variable
9118
9069
  ? this.callee.object
9119
9070
  : null,
9071
+ type: INTERACTION_CALLED,
9120
9072
  withNew: false
9121
9073
  };
9122
9074
  }
@@ -9130,7 +9082,7 @@ class CallExpression extends CallExpressionBase {
9130
9082
  this.annotations)
9131
9083
  return false;
9132
9084
  return (this.callee.hasEffects(context) ||
9133
- this.callee.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
9085
+ this.callee.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context));
9134
9086
  }
9135
9087
  finally {
9136
9088
  if (!this.deoptimized)
@@ -9167,9 +9119,8 @@ class CallExpression extends CallExpressionBase {
9167
9119
  }
9168
9120
  applyDeoptimizations() {
9169
9121
  this.deoptimized = true;
9170
- const { thisParam } = this.callOptions;
9171
- if (thisParam) {
9172
- this.callee.deoptimizeThisOnEventAtPath(EVENT_CALLED, EMPTY_PATH, thisParam, SHARED_RECURSION_TRACKER);
9122
+ if (this.interaction.thisArg) {
9123
+ this.callee.deoptimizeThisOnInteractionAtPath(this.interaction, EMPTY_PATH, SHARED_RECURSION_TRACKER);
9173
9124
  }
9174
9125
  for (const argument of this.arguments) {
9175
9126
  // This will make sure all properties of parameters behave as "unknown"
@@ -9180,7 +9131,7 @@ class CallExpression extends CallExpressionBase {
9180
9131
  getReturnExpression(recursionTracker = SHARED_RECURSION_TRACKER) {
9181
9132
  if (this.returnExpression === null) {
9182
9133
  this.returnExpression = UNKNOWN_EXPRESSION;
9183
- return (this.returnExpression = this.callee.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.callOptions, recursionTracker, this));
9134
+ return (this.returnExpression = this.callee.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.interaction, recursionTracker, this));
9184
9135
  }
9185
9136
  return this.returnExpression;
9186
9137
  }
@@ -9258,11 +9209,6 @@ class MethodBase extends NodeBase {
9258
9209
  constructor() {
9259
9210
  super(...arguments);
9260
9211
  this.accessedValue = null;
9261
- this.accessorCallOptions = {
9262
- args: NO_ARGS,
9263
- thisParam: null,
9264
- withNew: false
9265
- };
9266
9212
  }
9267
9213
  // As getter properties directly receive their values from fixed function
9268
9214
  // expressions, there is no known situation where a getter is deoptimized.
@@ -9270,45 +9216,60 @@ class MethodBase extends NodeBase {
9270
9216
  deoptimizePath(path) {
9271
9217
  this.getAccessedValue().deoptimizePath(path);
9272
9218
  }
9273
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
9274
- if (event === EVENT_ACCESSED && this.kind === 'get' && path.length === 0) {
9275
- return this.value.deoptimizeThisOnEventAtPath(EVENT_CALLED, EMPTY_PATH, thisParameter, recursionTracker);
9219
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
9220
+ if (interaction.type === INTERACTION_ACCESSED && this.kind === 'get' && path.length === 0) {
9221
+ return this.value.deoptimizeThisOnInteractionAtPath({
9222
+ args: NO_ARGS,
9223
+ thisArg: interaction.thisArg,
9224
+ type: INTERACTION_CALLED,
9225
+ withNew: false
9226
+ }, EMPTY_PATH, recursionTracker);
9276
9227
  }
9277
- if (event === EVENT_ASSIGNED && this.kind === 'set' && path.length === 0) {
9278
- return this.value.deoptimizeThisOnEventAtPath(EVENT_CALLED, EMPTY_PATH, thisParameter, recursionTracker);
9228
+ if (interaction.type === INTERACTION_ASSIGNED && this.kind === 'set' && path.length === 0) {
9229
+ return this.value.deoptimizeThisOnInteractionAtPath({
9230
+ args: interaction.args,
9231
+ thisArg: interaction.thisArg,
9232
+ type: INTERACTION_CALLED,
9233
+ withNew: false
9234
+ }, EMPTY_PATH, recursionTracker);
9279
9235
  }
9280
- this.getAccessedValue().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
9236
+ this.getAccessedValue().deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
9281
9237
  }
9282
9238
  getLiteralValueAtPath(path, recursionTracker, origin) {
9283
9239
  return this.getAccessedValue().getLiteralValueAtPath(path, recursionTracker, origin);
9284
9240
  }
9285
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
9286
- return this.getAccessedValue().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
9241
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
9242
+ return this.getAccessedValue().getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
9287
9243
  }
9288
9244
  hasEffects(context) {
9289
9245
  return this.key.hasEffects(context);
9290
9246
  }
9291
- hasEffectsWhenAccessedAtPath(path, context) {
9292
- if (this.kind === 'get' && path.length === 0) {
9293
- return this.value.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.accessorCallOptions, context);
9294
- }
9295
- return this.getAccessedValue().hasEffectsWhenAccessedAtPath(path, context);
9296
- }
9297
- hasEffectsWhenAssignedAtPath(path, context) {
9298
- if (this.kind === 'set') {
9299
- return this.value.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.accessorCallOptions, context);
9247
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
9248
+ if (this.kind === 'get' && interaction.type === INTERACTION_ACCESSED && path.length === 0) {
9249
+ return this.value.hasEffectsOnInteractionAtPath(EMPTY_PATH, {
9250
+ args: NO_ARGS,
9251
+ thisArg: interaction.thisArg,
9252
+ type: INTERACTION_CALLED,
9253
+ withNew: false
9254
+ }, context);
9255
+ }
9256
+ // setters are only called for empty paths
9257
+ if (this.kind === 'set' && interaction.type === INTERACTION_ASSIGNED) {
9258
+ return this.value.hasEffectsOnInteractionAtPath(EMPTY_PATH, {
9259
+ args: interaction.args,
9260
+ thisArg: interaction.thisArg,
9261
+ type: INTERACTION_CALLED,
9262
+ withNew: false
9263
+ }, context);
9300
9264
  }
9301
- return this.getAccessedValue().hasEffectsWhenAssignedAtPath(path, context);
9302
- }
9303
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
9304
- return this.getAccessedValue().hasEffectsWhenCalledAtPath(path, callOptions, context);
9265
+ return this.getAccessedValue().hasEffectsOnInteractionAtPath(path, interaction, context);
9305
9266
  }
9306
9267
  applyDeoptimizations() { }
9307
9268
  getAccessedValue() {
9308
9269
  if (this.accessedValue === null) {
9309
9270
  if (this.kind === 'get') {
9310
9271
  this.accessedValue = UNKNOWN_EXPRESSION;
9311
- return (this.accessedValue = this.value.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.accessorCallOptions, SHARED_RECURSION_TRACKER, this));
9272
+ return (this.accessedValue = this.value.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_CALL, SHARED_RECURSION_TRACKER, this));
9312
9273
  }
9313
9274
  else {
9314
9275
  return (this.accessedValue = this.value);
@@ -9331,23 +9292,17 @@ class ObjectMember extends ExpressionEntity {
9331
9292
  deoptimizePath(path) {
9332
9293
  this.object.deoptimizePath([this.key, ...path]);
9333
9294
  }
9334
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
9335
- this.object.deoptimizeThisOnEventAtPath(event, [this.key, ...path], thisParameter, recursionTracker);
9295
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
9296
+ this.object.deoptimizeThisOnInteractionAtPath(interaction, [this.key, ...path], recursionTracker);
9336
9297
  }
9337
9298
  getLiteralValueAtPath(path, recursionTracker, origin) {
9338
9299
  return this.object.getLiteralValueAtPath([this.key, ...path], recursionTracker, origin);
9339
9300
  }
9340
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
9341
- return this.object.getReturnExpressionWhenCalledAtPath([this.key, ...path], callOptions, recursionTracker, origin);
9342
- }
9343
- hasEffectsWhenAccessedAtPath(path, context) {
9344
- return this.object.hasEffectsWhenAccessedAtPath([this.key, ...path], context);
9345
- }
9346
- hasEffectsWhenAssignedAtPath(path, context) {
9347
- return this.object.hasEffectsWhenAssignedAtPath([this.key, ...path], context);
9301
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
9302
+ return this.object.getReturnExpressionWhenCalledAtPath([this.key, ...path], interaction, recursionTracker, origin);
9348
9303
  }
9349
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
9350
- return this.object.hasEffectsWhenCalledAtPath([this.key, ...path], callOptions, context);
9304
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
9305
+ return this.object.hasEffectsOnInteractionAtPath([this.key, ...path], interaction, context);
9351
9306
  }
9352
9307
  }
9353
9308
 
@@ -9365,14 +9320,14 @@ class ClassNode extends NodeBase {
9365
9320
  deoptimizePath(path) {
9366
9321
  this.getObjectEntity().deoptimizePath(path);
9367
9322
  }
9368
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
9369
- this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
9323
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
9324
+ this.getObjectEntity().deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
9370
9325
  }
9371
9326
  getLiteralValueAtPath(path, recursionTracker, origin) {
9372
9327
  return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
9373
9328
  }
9374
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
9375
- return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
9329
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
9330
+ return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
9376
9331
  }
9377
9332
  hasEffects(context) {
9378
9333
  var _a, _b;
@@ -9382,23 +9337,17 @@ class ClassNode extends NodeBase {
9382
9337
  (_b = this.id) === null || _b === void 0 ? void 0 : _b.markDeclarationReached();
9383
9338
  return initEffect || super.hasEffects(context);
9384
9339
  }
9385
- hasEffectsWhenAccessedAtPath(path, context) {
9386
- return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
9387
- }
9388
- hasEffectsWhenAssignedAtPath(path, context) {
9389
- return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
9390
- }
9391
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
9340
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
9392
9341
  var _a;
9393
- if (path.length === 0) {
9394
- return (!callOptions.withNew ||
9342
+ if (interaction.type === INTERACTION_CALLED && path.length === 0) {
9343
+ return (!interaction.withNew ||
9395
9344
  (this.classConstructor !== null
9396
- ? this.classConstructor.hasEffectsWhenCalledAtPath(EMPTY_PATH, callOptions, context)
9397
- : (_a = this.superClass) === null || _a === void 0 ? void 0 : _a.hasEffectsWhenCalledAtPath(path, callOptions, context)) ||
9345
+ ? this.classConstructor.hasEffectsOnInteractionAtPath(path, interaction, context)
9346
+ : (_a = this.superClass) === null || _a === void 0 ? void 0 : _a.hasEffectsOnInteractionAtPath(path, interaction, context)) ||
9398
9347
  false);
9399
9348
  }
9400
9349
  else {
9401
- return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
9350
+ return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
9402
9351
  }
9403
9352
  }
9404
9353
  include(context, includeChildrenRecursively) {
@@ -9519,26 +9468,12 @@ class MultiExpression extends ExpressionEntity {
9519
9468
  expression.deoptimizePath(path);
9520
9469
  }
9521
9470
  }
9522
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
9523
- return new MultiExpression(this.expressions.map(expression => expression.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin)));
9524
- }
9525
- hasEffectsWhenAccessedAtPath(path, context) {
9526
- for (const expression of this.expressions) {
9527
- if (expression.hasEffectsWhenAccessedAtPath(path, context))
9528
- return true;
9529
- }
9530
- return false;
9471
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
9472
+ return new MultiExpression(this.expressions.map(expression => expression.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)));
9531
9473
  }
9532
- hasEffectsWhenAssignedAtPath(path, context) {
9474
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
9533
9475
  for (const expression of this.expressions) {
9534
- if (expression.hasEffectsWhenAssignedAtPath(path, context))
9535
- return true;
9536
- }
9537
- return false;
9538
- }
9539
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
9540
- for (const expression of this.expressions) {
9541
- if (expression.hasEffectsWhenCalledAtPath(path, callOptions, context))
9476
+ if (expression.hasEffectsOnInteractionAtPath(path, interaction, context))
9542
9477
  return true;
9543
9478
  }
9544
9479
  return false;
@@ -9581,9 +9516,9 @@ class ConditionalExpression extends NodeBase {
9581
9516
  usedBranch.deoptimizePath(path);
9582
9517
  }
9583
9518
  }
9584
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
9585
- this.consequent.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
9586
- this.alternate.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
9519
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
9520
+ this.consequent.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
9521
+ this.alternate.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
9587
9522
  }
9588
9523
  getLiteralValueAtPath(path, recursionTracker, origin) {
9589
9524
  const usedBranch = this.getUsedBranch();
@@ -9592,15 +9527,15 @@ class ConditionalExpression extends NodeBase {
9592
9527
  this.expressionsToBeDeoptimized.push(origin);
9593
9528
  return usedBranch.getLiteralValueAtPath(path, recursionTracker, origin);
9594
9529
  }
9595
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
9530
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
9596
9531
  const usedBranch = this.getUsedBranch();
9597
9532
  if (!usedBranch)
9598
9533
  return new MultiExpression([
9599
- this.consequent.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin),
9600
- this.alternate.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin)
9534
+ this.consequent.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin),
9535
+ this.alternate.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)
9601
9536
  ]);
9602
9537
  this.expressionsToBeDeoptimized.push(origin);
9603
- return usedBranch.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
9538
+ return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
9604
9539
  }
9605
9540
  hasEffects(context) {
9606
9541
  if (this.test.hasEffects(context))
@@ -9611,29 +9546,13 @@ class ConditionalExpression extends NodeBase {
9611
9546
  }
9612
9547
  return usedBranch.hasEffects(context);
9613
9548
  }
9614
- hasEffectsWhenAccessedAtPath(path, context) {
9615
- const usedBranch = this.getUsedBranch();
9616
- if (!usedBranch) {
9617
- return (this.consequent.hasEffectsWhenAccessedAtPath(path, context) ||
9618
- this.alternate.hasEffectsWhenAccessedAtPath(path, context));
9619
- }
9620
- return usedBranch.hasEffectsWhenAccessedAtPath(path, context);
9621
- }
9622
- hasEffectsWhenAssignedAtPath(path, context) {
9623
- const usedBranch = this.getUsedBranch();
9624
- if (!usedBranch) {
9625
- return (this.consequent.hasEffectsWhenAssignedAtPath(path, context) ||
9626
- this.alternate.hasEffectsWhenAssignedAtPath(path, context));
9627
- }
9628
- return usedBranch.hasEffectsWhenAssignedAtPath(path, context);
9629
- }
9630
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
9549
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
9631
9550
  const usedBranch = this.getUsedBranch();
9632
9551
  if (!usedBranch) {
9633
- return (this.consequent.hasEffectsWhenCalledAtPath(path, callOptions, context) ||
9634
- this.alternate.hasEffectsWhenCalledAtPath(path, callOptions, context));
9552
+ return (this.consequent.hasEffectsOnInteractionAtPath(path, interaction, context) ||
9553
+ this.alternate.hasEffectsOnInteractionAtPath(path, interaction, context));
9635
9554
  }
9636
- return usedBranch.hasEffectsWhenCalledAtPath(path, callOptions, context);
9555
+ return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
9637
9556
  }
9638
9557
  include(context, includeChildrenRecursively) {
9639
9558
  this.included = true;
@@ -9904,12 +9823,10 @@ class ForInStatement extends NodeBase {
9904
9823
  this.scope = new BlockScope(parentScope);
9905
9824
  }
9906
9825
  hasEffects(context) {
9907
- if (!this.deoptimized)
9826
+ const { deoptimized, left, right } = this;
9827
+ if (!deoptimized)
9908
9828
  this.applyDeoptimizations();
9909
- if ((this.left &&
9910
- (this.left.hasEffects(context) ||
9911
- this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context))) ||
9912
- (this.right && this.right.hasEffects(context)))
9829
+ if (left.hasEffectsAsAssignmentTarget(context, false) || right.hasEffects(context))
9913
9830
  return true;
9914
9831
  const { brokenFlow, ignore: { breaks, continues } } = context;
9915
9832
  context.ignore.breaks = true;
@@ -9922,15 +9839,19 @@ class ForInStatement extends NodeBase {
9922
9839
  return false;
9923
9840
  }
9924
9841
  include(context, includeChildrenRecursively) {
9925
- if (!this.deoptimized)
9842
+ const { body, deoptimized, left, right } = this;
9843
+ if (!deoptimized)
9926
9844
  this.applyDeoptimizations();
9927
9845
  this.included = true;
9928
- this.left.include(context, includeChildrenRecursively || true);
9929
- this.right.include(context, includeChildrenRecursively);
9846
+ left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
9847
+ right.include(context, includeChildrenRecursively);
9930
9848
  const { brokenFlow } = context;
9931
- this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9849
+ body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9932
9850
  context.brokenFlow = brokenFlow;
9933
9851
  }
9852
+ initialise() {
9853
+ this.left.setAssignedValue(UNKNOWN_EXPRESSION);
9854
+ }
9934
9855
  render(code, options) {
9935
9856
  this.left.render(code, options, NO_SEMICOLON);
9936
9857
  this.right.render(code, options, NO_SEMICOLON);
@@ -9958,15 +9879,19 @@ class ForOfStatement extends NodeBase {
9958
9879
  return true;
9959
9880
  }
9960
9881
  include(context, includeChildrenRecursively) {
9961
- if (!this.deoptimized)
9882
+ const { body, deoptimized, left, right } = this;
9883
+ if (!deoptimized)
9962
9884
  this.applyDeoptimizations();
9963
9885
  this.included = true;
9964
- this.left.include(context, includeChildrenRecursively || true);
9965
- this.right.include(context, includeChildrenRecursively);
9886
+ left.includeAsAssignmentTarget(context, includeChildrenRecursively || true, false);
9887
+ right.include(context, includeChildrenRecursively);
9966
9888
  const { brokenFlow } = context;
9967
- this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9889
+ body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9968
9890
  context.brokenFlow = brokenFlow;
9969
9891
  }
9892
+ initialise() {
9893
+ this.left.setAssignedValue(UNKNOWN_EXPRESSION);
9894
+ }
9970
9895
  render(code, options) {
9971
9896
  this.left.render(code, options, NO_SEMICOLON);
9972
9897
  this.right.render(code, options, NO_SEMICOLON);
@@ -10673,9 +10598,9 @@ class LogicalExpression extends NodeBase {
10673
10598
  usedBranch.deoptimizePath(path);
10674
10599
  }
10675
10600
  }
10676
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
10677
- this.left.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
10678
- this.right.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
10601
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
10602
+ this.left.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
10603
+ this.right.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
10679
10604
  }
10680
10605
  getLiteralValueAtPath(path, recursionTracker, origin) {
10681
10606
  const usedBranch = this.getUsedBranch();
@@ -10684,15 +10609,15 @@ class LogicalExpression extends NodeBase {
10684
10609
  this.expressionsToBeDeoptimized.push(origin);
10685
10610
  return usedBranch.getLiteralValueAtPath(path, recursionTracker, origin);
10686
10611
  }
10687
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
10612
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
10688
10613
  const usedBranch = this.getUsedBranch();
10689
10614
  if (!usedBranch)
10690
10615
  return new MultiExpression([
10691
- this.left.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin),
10692
- this.right.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin)
10616
+ this.left.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin),
10617
+ this.right.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)
10693
10618
  ]);
10694
10619
  this.expressionsToBeDeoptimized.push(origin);
10695
- return usedBranch.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
10620
+ return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
10696
10621
  }
10697
10622
  hasEffects(context) {
10698
10623
  if (this.left.hasEffects(context)) {
@@ -10703,29 +10628,13 @@ class LogicalExpression extends NodeBase {
10703
10628
  }
10704
10629
  return false;
10705
10630
  }
10706
- hasEffectsWhenAccessedAtPath(path, context) {
10631
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
10707
10632
  const usedBranch = this.getUsedBranch();
10708
10633
  if (!usedBranch) {
10709
- return (this.left.hasEffectsWhenAccessedAtPath(path, context) ||
10710
- this.right.hasEffectsWhenAccessedAtPath(path, context));
10634
+ return (this.left.hasEffectsOnInteractionAtPath(path, interaction, context) ||
10635
+ this.right.hasEffectsOnInteractionAtPath(path, interaction, context));
10711
10636
  }
10712
- return usedBranch.hasEffectsWhenAccessedAtPath(path, context);
10713
- }
10714
- hasEffectsWhenAssignedAtPath(path, context) {
10715
- const usedBranch = this.getUsedBranch();
10716
- if (!usedBranch) {
10717
- return (this.left.hasEffectsWhenAssignedAtPath(path, context) ||
10718
- this.right.hasEffectsWhenAssignedAtPath(path, context));
10719
- }
10720
- return usedBranch.hasEffectsWhenAssignedAtPath(path, context);
10721
- }
10722
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
10723
- const usedBranch = this.getUsedBranch();
10724
- if (!usedBranch) {
10725
- return (this.left.hasEffectsWhenCalledAtPath(path, callOptions, context) ||
10726
- this.right.hasEffectsWhenCalledAtPath(path, callOptions, context));
10727
- }
10728
- return usedBranch.hasEffectsWhenCalledAtPath(path, callOptions, context);
10637
+ return usedBranch.hasEffectsOnInteractionAtPath(path, interaction, context);
10729
10638
  }
10730
10639
  include(context, includeChildrenRecursively) {
10731
10640
  this.included = true;
@@ -10815,8 +10724,8 @@ class MetaProperty extends NodeBase {
10815
10724
  hasEffects() {
10816
10725
  return false;
10817
10726
  }
10818
- hasEffectsWhenAccessedAtPath(path) {
10819
- return path.length > 1;
10727
+ hasEffectsOnInteractionAtPath(path, { type }) {
10728
+ return path.length > 1 || type !== INTERACTION_ACCESSED;
10820
10729
  }
10821
10730
  include() {
10822
10731
  if (!this.included) {
@@ -10961,18 +10870,19 @@ class NewExpression extends NodeBase {
10961
10870
  return true;
10962
10871
  }
10963
10872
  if (this.context.options.treeshake.annotations &&
10964
- this.annotations)
10873
+ this.annotations) {
10965
10874
  return false;
10875
+ }
10966
10876
  return (this.callee.hasEffects(context) ||
10967
- this.callee.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
10877
+ this.callee.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context));
10968
10878
  }
10969
10879
  finally {
10970
10880
  if (!this.deoptimized)
10971
10881
  this.applyDeoptimizations();
10972
10882
  }
10973
10883
  }
10974
- hasEffectsWhenAccessedAtPath(path) {
10975
- return path.length > 0;
10884
+ hasEffectsOnInteractionAtPath(path, { type }) {
10885
+ return path.length > 0 || type !== INTERACTION_ACCESSED;
10976
10886
  }
10977
10887
  include(context, includeChildrenRecursively) {
10978
10888
  if (!this.deoptimized)
@@ -10987,9 +10897,10 @@ class NewExpression extends NodeBase {
10987
10897
  this.callee.includeCallArguments(context, this.arguments);
10988
10898
  }
10989
10899
  initialise() {
10990
- this.callOptions = {
10900
+ this.interaction = {
10991
10901
  args: this.arguments,
10992
- thisParam: null,
10902
+ thisArg: null,
10903
+ type: INTERACTION_CALLED,
10993
10904
  withNew: true
10994
10905
  };
10995
10906
  }
@@ -11018,23 +10929,17 @@ class ObjectExpression extends NodeBase {
11018
10929
  deoptimizePath(path) {
11019
10930
  this.getObjectEntity().deoptimizePath(path);
11020
10931
  }
11021
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
11022
- this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
10932
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
10933
+ this.getObjectEntity().deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
11023
10934
  }
11024
10935
  getLiteralValueAtPath(path, recursionTracker, origin) {
11025
10936
  return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
11026
10937
  }
11027
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
11028
- return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
11029
- }
11030
- hasEffectsWhenAccessedAtPath(path, context) {
11031
- return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
10938
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
10939
+ return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
11032
10940
  }
11033
- hasEffectsWhenAssignedAtPath(path, context) {
11034
- return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
11035
- }
11036
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
11037
- return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
10941
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
10942
+ return this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
11038
10943
  }
11039
10944
  render(code, options, { renderedSurroundingElement } = BLANK) {
11040
10945
  super.render(code, options);
@@ -11165,32 +11070,26 @@ class PropertyDefinition extends NodeBase {
11165
11070
  var _a;
11166
11071
  (_a = this.value) === null || _a === void 0 ? void 0 : _a.deoptimizePath(path);
11167
11072
  }
11168
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
11073
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
11169
11074
  var _a;
11170
- (_a = this.value) === null || _a === void 0 ? void 0 : _a.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
11075
+ (_a = this.value) === null || _a === void 0 ? void 0 : _a.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
11171
11076
  }
11172
11077
  getLiteralValueAtPath(path, recursionTracker, origin) {
11173
11078
  return this.value
11174
11079
  ? this.value.getLiteralValueAtPath(path, recursionTracker, origin)
11175
11080
  : UnknownValue;
11176
11081
  }
11177
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
11082
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
11178
11083
  return this.value
11179
- ? this.value.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin)
11084
+ ? this.value.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)
11180
11085
  : UNKNOWN_EXPRESSION;
11181
11086
  }
11182
11087
  hasEffects(context) {
11183
11088
  var _a;
11184
11089
  return this.key.hasEffects(context) || (this.static && !!((_a = this.value) === null || _a === void 0 ? void 0 : _a.hasEffects(context)));
11185
11090
  }
11186
- hasEffectsWhenAccessedAtPath(path, context) {
11187
- return !this.value || this.value.hasEffectsWhenAccessedAtPath(path, context);
11188
- }
11189
- hasEffectsWhenAssignedAtPath(path, context) {
11190
- return !this.value || this.value.hasEffectsWhenAssignedAtPath(path, context);
11191
- }
11192
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
11193
- return !this.value || this.value.hasEffectsWhenCalledAtPath(path, callOptions, context);
11091
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
11092
+ return !this.value || this.value.hasEffectsOnInteractionAtPath(path, interaction, context);
11194
11093
  }
11195
11094
  applyDeoptimizations() { }
11196
11095
  }
@@ -11226,8 +11125,8 @@ class SequenceExpression extends NodeBase {
11226
11125
  deoptimizePath(path) {
11227
11126
  this.expressions[this.expressions.length - 1].deoptimizePath(path);
11228
11127
  }
11229
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
11230
- this.expressions[this.expressions.length - 1].deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
11128
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
11129
+ this.expressions[this.expressions.length - 1].deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
11231
11130
  }
11232
11131
  getLiteralValueAtPath(path, recursionTracker, origin) {
11233
11132
  return this.expressions[this.expressions.length - 1].getLiteralValueAtPath(path, recursionTracker, origin);
@@ -11239,15 +11138,8 @@ class SequenceExpression extends NodeBase {
11239
11138
  }
11240
11139
  return false;
11241
11140
  }
11242
- hasEffectsWhenAccessedAtPath(path, context) {
11243
- return (path.length > 0 &&
11244
- this.expressions[this.expressions.length - 1].hasEffectsWhenAccessedAtPath(path, context));
11245
- }
11246
- hasEffectsWhenAssignedAtPath(path, context) {
11247
- return this.expressions[this.expressions.length - 1].hasEffectsWhenAssignedAtPath(path, context);
11248
- }
11249
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
11250
- return this.expressions[this.expressions.length - 1].hasEffectsWhenCalledAtPath(path, callOptions, context);
11141
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
11142
+ return this.expressions[this.expressions.length - 1].hasEffectsOnInteractionAtPath(path, interaction, context);
11251
11143
  }
11252
11144
  include(context, includeChildrenRecursively) {
11253
11145
  this.included = true;
@@ -11326,8 +11218,8 @@ class Super extends NodeBase {
11326
11218
  deoptimizePath(path) {
11327
11219
  this.variable.deoptimizePath(path);
11328
11220
  }
11329
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
11330
- this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
11221
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
11222
+ this.variable.deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
11331
11223
  }
11332
11224
  include() {
11333
11225
  if (!this.included) {
@@ -11467,7 +11359,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
11467
11359
  return true;
11468
11360
  }
11469
11361
  return (this.tag.hasEffects(context) ||
11470
- this.tag.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
11362
+ this.tag.hasEffectsOnInteractionAtPath(EMPTY_PATH, this.interaction, context));
11471
11363
  }
11472
11364
  finally {
11473
11365
  if (!this.deoptimized)
@@ -11485,16 +11377,17 @@ class TaggedTemplateExpression extends CallExpressionBase {
11485
11377
  this.tag.include(context, includeChildrenRecursively);
11486
11378
  this.quasi.include(context, includeChildrenRecursively);
11487
11379
  }
11488
- this.tag.includeCallArguments(context, this.callOptions.args);
11380
+ this.tag.includeCallArguments(context, this.interaction.args);
11489
11381
  const returnExpression = this.getReturnExpression();
11490
11382
  if (!returnExpression.included) {
11491
11383
  returnExpression.include(context, false);
11492
11384
  }
11493
11385
  }
11494
11386
  initialise() {
11495
- this.callOptions = {
11387
+ this.interaction = {
11496
11388
  args: [UNKNOWN_EXPRESSION, ...this.quasi.expressions],
11497
- thisParam: this.tag instanceof MemberExpression && !this.tag.variable ? this.tag.object : null,
11389
+ thisArg: this.tag instanceof MemberExpression && !this.tag.variable ? this.tag.object : null,
11390
+ type: INTERACTION_CALLED,
11498
11391
  withNew: false
11499
11392
  };
11500
11393
  }
@@ -11504,9 +11397,8 @@ class TaggedTemplateExpression extends CallExpressionBase {
11504
11397
  }
11505
11398
  applyDeoptimizations() {
11506
11399
  this.deoptimized = true;
11507
- const { thisParam } = this.callOptions;
11508
- if (thisParam) {
11509
- this.tag.deoptimizeThisOnEventAtPath(EVENT_CALLED, EMPTY_PATH, thisParam, SHARED_RECURSION_TRACKER);
11400
+ if (this.interaction.thisArg) {
11401
+ this.tag.deoptimizeThisOnInteractionAtPath(this.interaction, EMPTY_PATH, SHARED_RECURSION_TRACKER);
11510
11402
  }
11511
11403
  for (const argument of this.quasi.expressions) {
11512
11404
  // This will make sure all properties of parameters behave as "unknown"
@@ -11517,7 +11409,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
11517
11409
  getReturnExpression(recursionTracker = SHARED_RECURSION_TRACKER) {
11518
11410
  if (this.returnExpression === null) {
11519
11411
  this.returnExpression = UNKNOWN_EXPRESSION;
11520
- return (this.returnExpression = this.tag.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.callOptions, recursionTracker, this));
11412
+ return (this.returnExpression = this.tag.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.interaction, recursionTracker, this));
11521
11413
  }
11522
11414
  return this.returnExpression;
11523
11415
  }
@@ -11540,7 +11432,7 @@ class TemplateElement extends NodeBase {
11540
11432
  }
11541
11433
 
11542
11434
  class TemplateLiteral extends NodeBase {
11543
- deoptimizeThisOnEventAtPath() { }
11435
+ deoptimizeThisOnInteractionAtPath() { }
11544
11436
  getLiteralValueAtPath(path) {
11545
11437
  if (path.length > 0 || this.quasis.length !== 1) {
11546
11438
  return UnknownValue;
@@ -11553,12 +11445,12 @@ class TemplateLiteral extends NodeBase {
11553
11445
  }
11554
11446
  return getMemberReturnExpressionWhenCalled(literalStringMembers, path[0]);
11555
11447
  }
11556
- hasEffectsWhenAccessedAtPath(path) {
11557
- return path.length > 1;
11558
- }
11559
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
11560
- if (path.length === 1) {
11561
- return hasMemberEffectWhenCalled(literalStringMembers, path[0], callOptions, context);
11448
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
11449
+ if (interaction.type === INTERACTION_ACCESSED) {
11450
+ return path.length > 1;
11451
+ }
11452
+ if (interaction.type === INTERACTION_CALLED && path.length === 1) {
11453
+ return hasMemberEffectWhenCalled(literalStringMembers, path[0], interaction, context);
11562
11454
  }
11563
11455
  return true;
11564
11456
  }
@@ -11686,16 +11578,15 @@ class ThisExpression extends NodeBase {
11686
11578
  deoptimizePath(path) {
11687
11579
  this.variable.deoptimizePath(path);
11688
11580
  }
11689
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
11690
- this.variable.deoptimizeThisOnEventAtPath(event, path,
11581
+ deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
11691
11582
  // We rewrite the parameter so that a ThisVariable can detect self-mutations
11692
- thisParameter === this ? this.variable : thisParameter, recursionTracker);
11583
+ this.variable.deoptimizeThisOnInteractionAtPath(interaction.thisArg === this ? { ...interaction, thisArg: this.variable } : interaction, path, recursionTracker);
11693
11584
  }
11694
- hasEffectsWhenAccessedAtPath(path, context) {
11695
- return path.length > 0 && this.variable.hasEffectsWhenAccessedAtPath(path, context);
11696
- }
11697
- hasEffectsWhenAssignedAtPath(path, context) {
11698
- return this.variable.hasEffectsWhenAssignedAtPath(path, context);
11585
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
11586
+ if (path.length === 0) {
11587
+ return interaction.type !== INTERACTION_ACCESSED;
11588
+ }
11589
+ return this.variable.hasEffectsOnInteractionAtPath(path, interaction, context);
11699
11590
  }
11700
11591
  include() {
11701
11592
  if (!this.included) {
@@ -11804,13 +11695,10 @@ class UnaryExpression extends NodeBase {
11804
11695
  return false;
11805
11696
  return (this.argument.hasEffects(context) ||
11806
11697
  (this.operator === 'delete' &&
11807
- this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context)));
11698
+ this.argument.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_ASSIGNMENT, context)));
11808
11699
  }
11809
- hasEffectsWhenAccessedAtPath(path) {
11810
- if (this.operator === 'void') {
11811
- return path.length > 0;
11812
- }
11813
- return path.length > 1;
11700
+ hasEffectsOnInteractionAtPath(path, { type }) {
11701
+ return type !== INTERACTION_ACCESSED || path.length > (this.operator === 'void' ? 0 : 1);
11814
11702
  }
11815
11703
  applyDeoptimizations() {
11816
11704
  this.deoptimized = true;
@@ -11834,11 +11722,19 @@ class UpdateExpression extends NodeBase {
11834
11722
  hasEffects(context) {
11835
11723
  if (!this.deoptimized)
11836
11724
  this.applyDeoptimizations();
11837
- return (this.argument.hasEffects(context) ||
11838
- this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context));
11725
+ return this.argument.hasEffectsAsAssignmentTarget(context, true);
11726
+ }
11727
+ hasEffectsOnInteractionAtPath(path, { type }) {
11728
+ return path.length > 1 || type !== INTERACTION_ACCESSED;
11729
+ }
11730
+ include(context, includeChildrenRecursively) {
11731
+ if (!this.deoptimized)
11732
+ this.applyDeoptimizations();
11733
+ this.included = true;
11734
+ this.argument.includeAsAssignmentTarget(context, includeChildrenRecursively, true);
11839
11735
  }
11840
- hasEffectsWhenAccessedAtPath(path) {
11841
- return path.length > 1;
11736
+ initialise() {
11737
+ this.argument.setAssignedValue(UNKNOWN_EXPRESSION);
11842
11738
  }
11843
11739
  render(code, options) {
11844
11740
  const { exportNamesByVariable, format, snippets: { _ } } = options;
@@ -11900,7 +11796,7 @@ class VariableDeclaration extends NodeBase {
11900
11796
  declarator.deoptimizePath(EMPTY_PATH);
11901
11797
  }
11902
11798
  }
11903
- hasEffectsWhenAssignedAtPath() {
11799
+ hasEffectsOnInteractionAtPath() {
11904
11800
  return false;
11905
11801
  }
11906
11802
  include(context, includeChildrenRecursively, { asSingleStatement } = BLANK) {
@@ -14569,7 +14465,7 @@ function renderChunk({ code, options, outputPluginDriver, renderChunk, sourcemap
14569
14465
 
14570
14466
  function renderNamePattern(pattern, patternName, replacements) {
14571
14467
  if (isPathFragment(pattern))
14572
- return error(errFailedValidation(`Invalid pattern "${pattern}" for "${patternName}", patterns can be neither absolute nor relative paths.`));
14468
+ return error(errFailedValidation(`Invalid pattern "${pattern}" for "${patternName}", patterns can be neither absolute nor relative paths. If you want your files to be stored in a subdirectory, write its name without a leading slash like this: subdirectory/pattern.`));
14573
14469
  return pattern.replace(/\[(\w+)\]/g, (_match, type) => {
14574
14470
  if (!replacements.hasOwnProperty(type)) {
14575
14471
  return error(errFailedValidation(`"[${type}]" is not a valid placeholder in "${patternName}" pattern.`));
@@ -23472,6 +23368,16 @@ function sanitizeFileName(name) {
23472
23368
  return driveLetter + name.substr(driveLetter.length).replace(INVALID_CHAR_REGEX, '_');
23473
23369
  }
23474
23370
 
23371
+ function isValidUrl(url) {
23372
+ try {
23373
+ new URL(url);
23374
+ }
23375
+ catch (_) {
23376
+ return false;
23377
+ }
23378
+ return true;
23379
+ }
23380
+
23475
23381
  function normalizeOutputOptions(config, inputOptions, unsetInputOptions) {
23476
23382
  var _a, _b, _c, _d, _e, _f, _g;
23477
23383
  // These are options that may trigger special warnings or behaviour later
@@ -23525,6 +23431,7 @@ function normalizeOutputOptions(config, inputOptions, unsetInputOptions) {
23525
23431
  ? id => id
23526
23432
  : sanitizeFileName,
23527
23433
  sourcemap: config.sourcemap || false,
23434
+ sourcemapBaseUrl: getSourcemapBaseUrl(config),
23528
23435
  sourcemapExcludeSources: config.sourcemapExcludeSources || false,
23529
23436
  sourcemapFile: config.sourcemapFile,
23530
23437
  sourcemapPathTransform: config.sourcemapPathTransform,
@@ -23750,6 +23657,15 @@ const getNamespaceToStringTag = (config, generatedCode, inputOptions) => {
23750
23657
  }
23751
23658
  return generatedCode.symbols || false;
23752
23659
  };
23660
+ const getSourcemapBaseUrl = (config) => {
23661
+ const { sourcemapBaseUrl } = config;
23662
+ if (sourcemapBaseUrl) {
23663
+ if (isValidUrl(sourcemapBaseUrl)) {
23664
+ return sourcemapBaseUrl;
23665
+ }
23666
+ return error(errInvalidOption('output.sourcemapBaseUrl', 'outputsourcemapbaseurl', `must be a valid URL, received ${JSON.stringify(sourcemapBaseUrl)}`));
23667
+ }
23668
+ };
23753
23669
 
23754
23670
  function rollup(rawInputOptions) {
23755
23671
  return rollupInternal(rawInputOptions, null);
@@ -23912,7 +23828,11 @@ async function writeOutputFile(outputFile, outputOptions) {
23912
23828
  url = outputFile.map.toUrl();
23913
23829
  }
23914
23830
  else {
23915
- url = `${require$$0.basename(outputFile.fileName)}.map`;
23831
+ const { sourcemapBaseUrl } = outputOptions;
23832
+ const sourcemapFileName = `${require$$0.basename(outputFile.fileName)}.map`;
23833
+ url = sourcemapBaseUrl
23834
+ ? new URL(sourcemapFileName, sourcemapBaseUrl).toString()
23835
+ : sourcemapFileName;
23916
23836
  writeSourceMapPromise = require$$0$1.promises.writeFile(`${fileName}.map`, outputFile.map.toString());
23917
23837
  }
23918
23838
  if (outputOptions.sourcemap !== 'hidden') {