rollup 2.72.0 → 2.74.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.72.0
4
- Thu, 05 May 2022 04:32:50 GMT - commit 19aef1315cf45b04c74c37a290cbef8072ddfa6b
3
+ Rollup.js v2.74.0
4
+ Thu, 19 May 2022 05:01:43 GMT - commit fc99e96e09d26798f1c0aabdd7429307cc908c8e
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.72.0";
30
+ var version$1 = "2.74.0";
31
31
 
32
32
  function ensureArray$1(items) {
33
33
  if (Array.isArray(items)) {
@@ -1865,7 +1865,7 @@ class MagicString {
1865
1865
  const hasOwnProp = Object.prototype.hasOwnProperty;
1866
1866
 
1867
1867
  class Bundle$1 {
1868
- constructor(options = {}) {
1868
+ constructor(options) {
1869
1869
  this.intro = options.intro || '';
1870
1870
  this.separator = options.separator !== undefined ? options.separator : '\n';
1871
1871
  this.sources = [];
@@ -2155,9 +2155,16 @@ function getOrCreate(map, key, init) {
2155
2155
  }
2156
2156
 
2157
2157
  const UnknownKey = Symbol('Unknown Key');
2158
+ const UnknownNonAccessorKey = Symbol('Unknown Non-Accessor Key');
2158
2159
  const UnknownInteger = Symbol('Unknown Integer');
2159
2160
  const EMPTY_PATH = [];
2160
2161
  const UNKNOWN_PATH = [UnknownKey];
2162
+ // For deoptimizations, this means we are modifying an unknown property but did
2163
+ // not lose track of the object or are creating a setter/getter;
2164
+ // For assignment effects it means we do not check for setter/getter effects
2165
+ // but only if something is mutated that is included, which is relevant for
2166
+ // Object.defineProperty
2167
+ const UNKNOWN_NON_ACCESSOR_PATH = [UnknownNonAccessorKey];
2161
2168
  const UNKNOWN_INTEGER_PATH = [UnknownInteger];
2162
2169
  const EntitiesKey = Symbol('Entities');
2163
2170
  class PathTracker {
@@ -2215,6 +2222,7 @@ class DiscriminatedPathTracker {
2215
2222
  }
2216
2223
 
2217
2224
  const UnknownValue = Symbol('Unknown Value');
2225
+ const UnknownTruthyValue = Symbol('Unknown Truthy Value');
2218
2226
  class ExpressionEntity {
2219
2227
  constructor() {
2220
2228
  this.included = false;
@@ -2243,14 +2251,17 @@ class ExpressionEntity {
2243
2251
  hasEffectsWhenCalledAtPath(_path, _callOptions, _context) {
2244
2252
  return true;
2245
2253
  }
2246
- include(_context, _includeChildrenRecursively) {
2254
+ include(_context, _includeChildrenRecursively, _options) {
2247
2255
  this.included = true;
2248
2256
  }
2249
- includeCallArguments(context, args) {
2257
+ includeArgumentsWhenCalledAtPath(_path, context, args) {
2250
2258
  for (const arg of args) {
2251
2259
  arg.include(context, false);
2252
2260
  }
2253
2261
  }
2262
+ shouldBeIncluded(_context) {
2263
+ return true;
2264
+ }
2254
2265
  }
2255
2266
  const UNKNOWN_EXPRESSION = new (class UnknownExpression extends ExpressionEntity {
2256
2267
  })();
@@ -4711,7 +4722,7 @@ const UNDEFINED_EXPRESSION = new (class UndefinedExpression extends ExpressionEn
4711
4722
  })();
4712
4723
  const returnsUnknown = {
4713
4724
  value: {
4714
- callsArgs: null,
4725
+ hasEffectsWhenCalled: null,
4715
4726
  returns: UNKNOWN_EXPRESSION
4716
4727
  }
4717
4728
  };
@@ -4734,7 +4745,7 @@ const UNKNOWN_LITERAL_BOOLEAN = new (class UnknownBoolean extends ExpressionEnti
4734
4745
  })();
4735
4746
  const returnsBoolean = {
4736
4747
  value: {
4737
- callsArgs: null,
4748
+ hasEffectsWhenCalled: null,
4738
4749
  returns: UNKNOWN_LITERAL_BOOLEAN
4739
4750
  }
4740
4751
  };
@@ -4757,7 +4768,7 @@ const UNKNOWN_LITERAL_NUMBER = new (class UnknownNumber extends ExpressionEntity
4757
4768
  })();
4758
4769
  const returnsNumber = {
4759
4770
  value: {
4760
- callsArgs: null,
4771
+ hasEffectsWhenCalled: null,
4761
4772
  returns: UNKNOWN_LITERAL_NUMBER
4762
4773
  }
4763
4774
  };
@@ -4780,7 +4791,24 @@ const UNKNOWN_LITERAL_STRING = new (class UnknownString extends ExpressionEntity
4780
4791
  })();
4781
4792
  const returnsString = {
4782
4793
  value: {
4783
- callsArgs: null,
4794
+ hasEffectsWhenCalled: null,
4795
+ returns: UNKNOWN_LITERAL_STRING
4796
+ }
4797
+ };
4798
+ const stringReplace = {
4799
+ value: {
4800
+ hasEffectsWhenCalled(callOptions, context) {
4801
+ const arg1 = callOptions.args[1];
4802
+ return (callOptions.args.length < 2 ||
4803
+ (typeof arg1.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, {
4804
+ deoptimizeCache() { }
4805
+ }) === 'symbol' &&
4806
+ arg1.hasEffectsWhenCalledAtPath(EMPTY_PATH, {
4807
+ args: NO_ARGS,
4808
+ thisParam: null,
4809
+ withNew: false
4810
+ }, context)));
4811
+ },
4784
4812
  returns: UNKNOWN_LITERAL_STRING
4785
4813
  }
4786
4814
  };
@@ -4828,18 +4856,8 @@ const literalStringMembers = assembleMemberDescriptions({
4828
4856
  padEnd: returnsString,
4829
4857
  padStart: returnsString,
4830
4858
  repeat: returnsString,
4831
- replace: {
4832
- value: {
4833
- callsArgs: [1],
4834
- returns: UNKNOWN_LITERAL_STRING
4835
- }
4836
- },
4837
- replaceAll: {
4838
- value: {
4839
- callsArgs: [1],
4840
- returns: UNKNOWN_LITERAL_STRING
4841
- }
4842
- },
4859
+ replace: stringReplace,
4860
+ replaceAll: stringReplace,
4843
4861
  search: returnsNumber,
4844
4862
  slice: returnsString,
4845
4863
  small: returnsString,
@@ -4874,21 +4892,11 @@ function getLiteralMembersForValue(value) {
4874
4892
  return Object.create(null);
4875
4893
  }
4876
4894
  function hasMemberEffectWhenCalled(members, memberName, callOptions, context) {
4895
+ var _a, _b;
4877
4896
  if (typeof memberName !== 'string' || !members[memberName]) {
4878
4897
  return true;
4879
4898
  }
4880
- if (!members[memberName].callsArgs)
4881
- return false;
4882
- for (const argIndex of members[memberName].callsArgs) {
4883
- if (callOptions.args[argIndex] &&
4884
- callOptions.args[argIndex].hasEffectsWhenCalledAtPath(EMPTY_PATH, {
4885
- args: NO_ARGS,
4886
- thisParam: null,
4887
- withNew: false
4888
- }, context))
4889
- return true;
4890
- }
4891
- return false;
4899
+ return ((_b = (_a = members[memberName]).hasEffectsWhenCalled) === null || _b === void 0 ? void 0 : _b.call(_a, callOptions, context)) || false;
4892
4900
  }
4893
4901
  function getMemberReturnExpressionWhenCalled(members, memberName) {
4894
4902
  if (typeof memberName !== 'string' || !members[memberName])
@@ -5349,8 +5357,7 @@ class NodeBase extends ExpressionEntity {
5349
5357
  continue;
5350
5358
  if (Array.isArray(value)) {
5351
5359
  for (const child of value) {
5352
- if (child !== null)
5353
- child.bind();
5360
+ child === null || child === void 0 ? void 0 : child.bind();
5354
5361
  }
5355
5362
  }
5356
5363
  else {
@@ -5373,7 +5380,7 @@ class NodeBase extends ExpressionEntity {
5373
5380
  continue;
5374
5381
  if (Array.isArray(value)) {
5375
5382
  for (const child of value) {
5376
- if (child !== null && child.hasEffects(context))
5383
+ if (child === null || child === void 0 ? void 0 : child.hasEffects(context))
5377
5384
  return true;
5378
5385
  }
5379
5386
  }
@@ -5382,7 +5389,7 @@ class NodeBase extends ExpressionEntity {
5382
5389
  }
5383
5390
  return false;
5384
5391
  }
5385
- include(context, includeChildrenRecursively) {
5392
+ include(context, includeChildrenRecursively, _options) {
5386
5393
  if (this.deoptimized === false)
5387
5394
  this.applyDeoptimizations();
5388
5395
  this.included = true;
@@ -5392,8 +5399,7 @@ class NodeBase extends ExpressionEntity {
5392
5399
  continue;
5393
5400
  if (Array.isArray(value)) {
5394
5401
  for (const child of value) {
5395
- if (child !== null)
5396
- child.include(context, includeChildrenRecursively);
5402
+ child === null || child === void 0 ? void 0 : child.include(context, includeChildrenRecursively);
5397
5403
  }
5398
5404
  }
5399
5405
  else {
@@ -5401,9 +5407,6 @@ class NodeBase extends ExpressionEntity {
5401
5407
  }
5402
5408
  }
5403
5409
  }
5404
- includeAsSingleStatement(context, includeChildrenRecursively) {
5405
- this.include(context, includeChildrenRecursively);
5406
- }
5407
5410
  /**
5408
5411
  * Override to perform special initialisation steps after the scope is initialised
5409
5412
  */
@@ -5450,8 +5453,7 @@ class NodeBase extends ExpressionEntity {
5450
5453
  continue;
5451
5454
  if (Array.isArray(value)) {
5452
5455
  for (const child of value) {
5453
- if (child !== null)
5454
- child.render(code, options);
5456
+ child === null || child === void 0 ? void 0 : child.render(code, options);
5455
5457
  }
5456
5458
  }
5457
5459
  else {
@@ -5462,7 +5464,28 @@ class NodeBase extends ExpressionEntity {
5462
5464
  shouldBeIncluded(context) {
5463
5465
  return this.included || (!context.brokenFlow && this.hasEffects(createHasEffectsContext()));
5464
5466
  }
5465
- applyDeoptimizations() { }
5467
+ /**
5468
+ * Just deoptimize everything by default so that when e.g. we do not track
5469
+ * something properly, it is deoptimized.
5470
+ * @protected
5471
+ */
5472
+ applyDeoptimizations() {
5473
+ this.deoptimized = true;
5474
+ for (const key of this.keys) {
5475
+ const value = this[key];
5476
+ if (value === null)
5477
+ continue;
5478
+ if (Array.isArray(value)) {
5479
+ for (const child of value) {
5480
+ child === null || child === void 0 ? void 0 : child.deoptimizePath(UNKNOWN_PATH);
5481
+ }
5482
+ }
5483
+ else {
5484
+ value.deoptimizePath(UNKNOWN_PATH);
5485
+ }
5486
+ }
5487
+ this.context.requestTreeshakingPass();
5488
+ }
5466
5489
  }
5467
5490
 
5468
5491
  class SpreadElement extends NodeBase {
@@ -5544,7 +5567,7 @@ class Method extends ExpressionEntity {
5544
5567
  }
5545
5568
  return false;
5546
5569
  }
5547
- includeCallArguments(context, args) {
5570
+ includeArgumentsWhenCalledAtPath(_path, context, args) {
5548
5571
  for (const arg of args) {
5549
5572
  arg.include(context, false);
5550
5573
  }
@@ -5595,6 +5618,7 @@ class ObjectEntity extends ExpressionEntity {
5595
5618
  this.deoptimizedPaths = Object.create(null);
5596
5619
  this.expressionsToBeDeoptimizedByKey = Object.create(null);
5597
5620
  this.gettersByKey = Object.create(null);
5621
+ this.hasLostTrack = false;
5598
5622
  this.hasUnknownDeoptimizedInteger = false;
5599
5623
  this.hasUnknownDeoptimizedProperty = false;
5600
5624
  this.propertiesAndGettersByKey = Object.create(null);
@@ -5615,12 +5639,18 @@ class ObjectEntity extends ExpressionEntity {
5615
5639
  }
5616
5640
  }
5617
5641
  }
5618
- deoptimizeAllProperties() {
5642
+ deoptimizeAllProperties(noAccessors) {
5619
5643
  var _a;
5620
- if (this.hasUnknownDeoptimizedProperty) {
5644
+ const isDeoptimized = this.hasLostTrack || this.hasUnknownDeoptimizedProperty;
5645
+ if (noAccessors) {
5646
+ this.hasUnknownDeoptimizedProperty = true;
5647
+ }
5648
+ else {
5649
+ this.hasLostTrack = true;
5650
+ }
5651
+ if (isDeoptimized) {
5621
5652
  return;
5622
5653
  }
5623
- this.hasUnknownDeoptimizedProperty = true;
5624
5654
  for (const properties of Object.values(this.propertiesAndGettersByKey).concat(Object.values(this.settersByKey))) {
5625
5655
  for (const property of properties) {
5626
5656
  property.deoptimizePath(UNKNOWN_PATH);
@@ -5631,7 +5661,9 @@ class ObjectEntity extends ExpressionEntity {
5631
5661
  this.deoptimizeCachedEntities();
5632
5662
  }
5633
5663
  deoptimizeIntegerProperties() {
5634
- if (this.hasUnknownDeoptimizedProperty || this.hasUnknownDeoptimizedInteger) {
5664
+ if (this.hasLostTrack ||
5665
+ this.hasUnknownDeoptimizedProperty ||
5666
+ this.hasUnknownDeoptimizedInteger) {
5635
5667
  return;
5636
5668
  }
5637
5669
  this.hasUnknownDeoptimizedInteger = true;
@@ -5644,17 +5676,19 @@ class ObjectEntity extends ExpressionEntity {
5644
5676
  }
5645
5677
  this.deoptimizeCachedIntegerEntities();
5646
5678
  }
5679
+ // Assumption: If only a specific path is deoptimized, no accessors are created
5647
5680
  deoptimizePath(path) {
5648
5681
  var _a;
5649
- if (this.hasUnknownDeoptimizedProperty || this.immutable)
5682
+ if (this.hasLostTrack || this.immutable) {
5650
5683
  return;
5684
+ }
5651
5685
  const key = path[0];
5652
5686
  if (path.length === 1) {
5653
5687
  if (typeof key !== 'string') {
5654
5688
  if (key === UnknownInteger) {
5655
5689
  return this.deoptimizeIntegerProperties();
5656
5690
  }
5657
- return this.deoptimizeAllProperties();
5691
+ return this.deoptimizeAllProperties(key === UnknownNonAccessorKey);
5658
5692
  }
5659
5693
  if (!this.deoptimizedPaths[key]) {
5660
5694
  this.deoptimizedPaths[key] = true;
@@ -5674,16 +5708,16 @@ class ObjectEntity extends ExpressionEntity {
5674
5708
  : this.allProperties) {
5675
5709
  property.deoptimizePath(subPath);
5676
5710
  }
5677
- (_a = this.prototypeExpression) === null || _a === void 0 ? void 0 : _a.deoptimizePath(path.length === 1 ? [UnknownKey, UnknownKey] : path);
5711
+ (_a = this.prototypeExpression) === null || _a === void 0 ? void 0 : _a.deoptimizePath(path.length === 1 ? [...path, UnknownKey] : path);
5678
5712
  }
5679
5713
  deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
5680
5714
  var _a;
5681
5715
  const [key, ...subPath] = path;
5682
- if (this.hasUnknownDeoptimizedProperty ||
5716
+ if (this.hasLostTrack ||
5683
5717
  // single paths that are deoptimized will not become getters or setters
5684
5718
  ((event === EVENT_CALLED || path.length > 1) &&
5685
- typeof key === 'string' &&
5686
- this.deoptimizedPaths[key])) {
5719
+ (this.hasUnknownDeoptimizedProperty ||
5720
+ (typeof key === 'string' && this.deoptimizedPaths[key])))) {
5687
5721
  thisParameter.deoptimizePath(UNKNOWN_PATH);
5688
5722
  return;
5689
5723
  }
@@ -5737,7 +5771,7 @@ class ObjectEntity extends ExpressionEntity {
5737
5771
  }
5738
5772
  getLiteralValueAtPath(path, recursionTracker, origin) {
5739
5773
  if (path.length === 0) {
5740
- return UnknownValue;
5774
+ return UnknownTruthyValue;
5741
5775
  }
5742
5776
  const key = path[0];
5743
5777
  const expressionAtPath = this.getMemberExpressionAndTrackDeopt(key, origin);
@@ -5781,7 +5815,7 @@ class ObjectEntity extends ExpressionEntity {
5781
5815
  }
5782
5816
  return true;
5783
5817
  }
5784
- if (this.hasUnknownDeoptimizedProperty)
5818
+ if (this.hasLostTrack)
5785
5819
  return true;
5786
5820
  if (typeof key === 'string') {
5787
5821
  if (this.propertiesAndGettersByKey[key]) {
@@ -5828,9 +5862,10 @@ class ObjectEntity extends ExpressionEntity {
5828
5862
  }
5829
5863
  return true;
5830
5864
  }
5831
- if (this.hasUnknownDeoptimizedProperty)
5865
+ if (key === UnknownNonAccessorKey)
5866
+ return false;
5867
+ if (this.hasLostTrack)
5832
5868
  return true;
5833
- // We do not need to test for unknown properties as in that case, hasUnknownDeoptimizedProperty is true
5834
5869
  if (typeof key === 'string') {
5835
5870
  if (this.propertiesAndSettersByKey[key]) {
5836
5871
  const setters = this.settersByKey[key];
@@ -5848,6 +5883,14 @@ class ObjectEntity extends ExpressionEntity {
5848
5883
  }
5849
5884
  }
5850
5885
  }
5886
+ else {
5887
+ for (const setters of Object.values(this.settersByKey).concat([this.unmatchableSetters])) {
5888
+ for (const setter of setters) {
5889
+ if (setter.hasEffectsWhenAssignedAtPath(subPath, context))
5890
+ return true;
5891
+ }
5892
+ }
5893
+ }
5851
5894
  if (this.prototypeExpression) {
5852
5895
  return this.prototypeExpression.hasEffectsWhenAssignedAtPath(path, context);
5853
5896
  }
@@ -5864,6 +5907,16 @@ class ObjectEntity extends ExpressionEntity {
5864
5907
  }
5865
5908
  return true;
5866
5909
  }
5910
+ includeArgumentsWhenCalledAtPath(path, context, args) {
5911
+ const key = path[0];
5912
+ const expressionAtPath = this.getMemberExpression(key);
5913
+ if (expressionAtPath) {
5914
+ return expressionAtPath.includeArgumentsWhenCalledAtPath(path.slice(1), context, args);
5915
+ }
5916
+ if (this.prototypeExpression) {
5917
+ return this.prototypeExpression.includeArgumentsWhenCalledAtPath(path, context, args);
5918
+ }
5919
+ }
5867
5920
  buildPropertyMaps(properties) {
5868
5921
  const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchableGetters, unmatchableSetters } = this;
5869
5922
  const unmatchablePropertiesAndSetters = [];
@@ -5931,7 +5984,8 @@ class ObjectEntity extends ExpressionEntity {
5931
5984
  }
5932
5985
  }
5933
5986
  getMemberExpression(key) {
5934
- if (this.hasUnknownDeoptimizedProperty ||
5987
+ if (this.hasLostTrack ||
5988
+ this.hasUnknownDeoptimizedProperty ||
5935
5989
  typeof key !== 'string' ||
5936
5990
  (this.hasUnknownDeoptimizedInteger && INTEGER_REG_EXP.test(key)) ||
5937
5991
  this.deoptimizedPaths[key]) {
@@ -6132,6 +6186,7 @@ const ARRAY_PROTOTYPE = new ObjectEntity({
6132
6186
  class ArrayExpression extends NodeBase {
6133
6187
  constructor() {
6134
6188
  super(...arguments);
6189
+ this.deoptimized = false;
6135
6190
  this.objectEntity = null;
6136
6191
  }
6137
6192
  deoptimizePath(path) {
@@ -6155,6 +6210,23 @@ class ArrayExpression extends NodeBase {
6155
6210
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
6156
6211
  return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
6157
6212
  }
6213
+ includeArgumentsWhenCalledAtPath(path, context, args) {
6214
+ this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
6215
+ }
6216
+ applyDeoptimizations() {
6217
+ this.deoptimized = true;
6218
+ let hasSpread = false;
6219
+ for (let index = 0; index < this.elements.length; index++) {
6220
+ const element = this.elements[index];
6221
+ if (hasSpread || element instanceof SpreadElement) {
6222
+ if (element) {
6223
+ hasSpread = true;
6224
+ element.deoptimizePath(UNKNOWN_PATH);
6225
+ }
6226
+ }
6227
+ }
6228
+ this.context.requestTreeshakingPass();
6229
+ }
6158
6230
  getObjectEntity() {
6159
6231
  if (this.objectEntity !== null) {
6160
6232
  return this.objectEntity;
@@ -6165,7 +6237,7 @@ class ArrayExpression extends NodeBase {
6165
6237
  let hasSpread = false;
6166
6238
  for (let index = 0; index < this.elements.length; index++) {
6167
6239
  const element = this.elements[index];
6168
- if (element instanceof SpreadElement || hasSpread) {
6240
+ if (hasSpread || element instanceof SpreadElement) {
6169
6241
  if (element) {
6170
6242
  hasSpread = true;
6171
6243
  properties.unshift({ key: UnknownInteger, kind: 'init', property: element });
@@ -6185,9 +6257,7 @@ class ArrayExpression extends NodeBase {
6185
6257
  class ArrayPattern extends NodeBase {
6186
6258
  addExportedVariables(variables, exportNamesByVariable) {
6187
6259
  for (const element of this.elements) {
6188
- if (element !== null) {
6189
- element.addExportedVariables(variables, exportNamesByVariable);
6190
- }
6260
+ element === null || element === void 0 ? void 0 : element.addExportedVariables(variables, exportNamesByVariable);
6191
6261
  }
6192
6262
  }
6193
6263
  declare(kind) {
@@ -6199,29 +6269,23 @@ class ArrayPattern extends NodeBase {
6199
6269
  }
6200
6270
  return variables;
6201
6271
  }
6202
- deoptimizePath(path) {
6203
- if (path.length === 0) {
6204
- for (const element of this.elements) {
6205
- if (element !== null) {
6206
- element.deoptimizePath(path);
6207
- }
6208
- }
6272
+ // Patterns can only be deoptimized at the empty path at the moment
6273
+ deoptimizePath() {
6274
+ for (const element of this.elements) {
6275
+ element === null || element === void 0 ? void 0 : element.deoptimizePath(EMPTY_PATH);
6209
6276
  }
6210
6277
  }
6211
- hasEffectsWhenAssignedAtPath(path, context) {
6212
- if (path.length > 0)
6213
- return true;
6278
+ // Patterns are only checked at the emtpy path at the moment
6279
+ hasEffectsWhenAssignedAtPath(_path, context) {
6214
6280
  for (const element of this.elements) {
6215
- if (element !== null && element.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context))
6281
+ if (element === null || element === void 0 ? void 0 : element.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context))
6216
6282
  return true;
6217
6283
  }
6218
6284
  return false;
6219
6285
  }
6220
6286
  markDeclarationReached() {
6221
6287
  for (const element of this.elements) {
6222
- if (element !== null) {
6223
- element.markDeclarationReached();
6224
- }
6288
+ element === null || element === void 0 ? void 0 : element.markDeclarationReached();
6225
6289
  }
6226
6290
  }
6227
6291
  }
@@ -6341,7 +6405,7 @@ class LocalVariable extends Variable {
6341
6405
  }
6342
6406
  }
6343
6407
  }
6344
- includeCallArguments(context, args) {
6408
+ includeArgumentsWhenCalledAtPath(path, context, args) {
6345
6409
  if (this.isReassigned || (this.init && context.includedCallArguments.has(this.init))) {
6346
6410
  for (const arg of args) {
6347
6411
  arg.include(context, false);
@@ -6349,7 +6413,7 @@ class LocalVariable extends Variable {
6349
6413
  }
6350
6414
  else if (this.init) {
6351
6415
  context.includedCallArguments.add(this.init);
6352
- this.init.includeCallArguments(context, args);
6416
+ this.init.includeArgumentsWhenCalledAtPath(path, context, args);
6353
6417
  context.includedCallArguments.delete(this.init);
6354
6418
  }
6355
6419
  }
@@ -6597,6 +6661,48 @@ class ReturnValueScope extends ParameterScope {
6597
6661
  }
6598
6662
  }
6599
6663
 
6664
+ class AssignmentPattern extends NodeBase {
6665
+ constructor() {
6666
+ super(...arguments);
6667
+ this.deoptimized = false;
6668
+ }
6669
+ addExportedVariables(variables, exportNamesByVariable) {
6670
+ this.left.addExportedVariables(variables, exportNamesByVariable);
6671
+ }
6672
+ declare(kind, init) {
6673
+ return this.left.declare(kind, init);
6674
+ }
6675
+ deoptimizePath(path) {
6676
+ path.length === 0 && this.left.deoptimizePath(path);
6677
+ }
6678
+ hasEffectsWhenAssignedAtPath(path, context) {
6679
+ return path.length > 0 || this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
6680
+ }
6681
+ include(context, includeChildrenRecursively) {
6682
+ this.included = true;
6683
+ this.left.include(context, includeChildrenRecursively);
6684
+ this.right.include(context, includeChildrenRecursively);
6685
+ }
6686
+ markDeclarationReached() {
6687
+ this.left.markDeclarationReached();
6688
+ }
6689
+ render(code, options, { isShorthandProperty } = BLANK) {
6690
+ this.left.render(code, options, { isShorthandProperty });
6691
+ if (this.right.included) {
6692
+ this.right.render(code, options);
6693
+ }
6694
+ else {
6695
+ code.remove(this.left.end, this.end);
6696
+ }
6697
+ }
6698
+ applyDeoptimizations() {
6699
+ this.deoptimized = true;
6700
+ this.left.deoptimizePath(EMPTY_PATH);
6701
+ this.right.deoptimizePath(UNKNOWN_PATH);
6702
+ this.context.requestTreeshakingPass();
6703
+ }
6704
+ }
6705
+
6600
6706
  function treeshakeNode(node, code, start, end) {
6601
6707
  code.remove(start, end);
6602
6708
  if (node.annotations) {
@@ -6849,109 +6955,363 @@ class BlockStatement extends NodeBase {
6849
6955
  }
6850
6956
  }
6851
6957
 
6852
- //@ts-check
6853
- /** @typedef { import('estree').Node} Node */
6854
- /** @typedef {Node | {
6855
- * type: 'PropertyDefinition';
6856
- * computed: boolean;
6857
- * value: Node
6858
- * }} NodeWithPropertyDefinition */
6859
-
6860
- /**
6861
- *
6862
- * @param {NodeWithPropertyDefinition} node
6863
- * @param {NodeWithPropertyDefinition} parent
6864
- * @returns boolean
6865
- */
6866
- function is_reference (node, parent) {
6867
- if (node.type === 'MemberExpression') {
6868
- return !node.computed && is_reference(node.object, node);
6869
- }
6870
-
6871
- if (node.type === 'Identifier') {
6872
- if (!parent) return true;
6873
-
6874
- switch (parent.type) {
6875
- // disregard `bar` in `foo.bar`
6876
- case 'MemberExpression': return parent.computed || node === parent.object;
6877
-
6878
- // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
6879
- case 'MethodDefinition': return parent.computed;
6880
-
6881
- // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
6882
- case 'PropertyDefinition': return parent.computed || node === parent.value;
6883
-
6884
- // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
6885
- case 'Property': return parent.computed || node === parent.value;
6886
-
6887
- // disregard the `bar` in `export { foo as bar }` or
6888
- // the foo in `import { foo as bar }`
6889
- case 'ExportSpecifier':
6890
- case 'ImportSpecifier': return node === parent.local;
6891
-
6892
- // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
6893
- case 'LabeledStatement':
6894
- case 'BreakStatement':
6895
- case 'ContinueStatement': return false;
6896
- default: return true;
6897
- }
6898
- }
6899
-
6900
- return false;
6958
+ class RestElement extends NodeBase {
6959
+ constructor() {
6960
+ super(...arguments);
6961
+ this.deoptimized = false;
6962
+ this.declarationInit = null;
6963
+ }
6964
+ addExportedVariables(variables, exportNamesByVariable) {
6965
+ this.argument.addExportedVariables(variables, exportNamesByVariable);
6966
+ }
6967
+ declare(kind, init) {
6968
+ this.declarationInit = init;
6969
+ return this.argument.declare(kind, UNKNOWN_EXPRESSION);
6970
+ }
6971
+ deoptimizePath(path) {
6972
+ path.length === 0 && this.argument.deoptimizePath(EMPTY_PATH);
6973
+ }
6974
+ hasEffectsWhenAssignedAtPath(path, context) {
6975
+ return path.length > 0 || this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
6976
+ }
6977
+ markDeclarationReached() {
6978
+ this.argument.markDeclarationReached();
6979
+ }
6980
+ applyDeoptimizations() {
6981
+ this.deoptimized = true;
6982
+ if (this.declarationInit !== null) {
6983
+ this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
6984
+ this.context.requestTreeshakingPass();
6985
+ }
6986
+ }
6901
6987
  }
6902
6988
 
6903
- /* eslint sort-keys: "off" */
6904
- const ValueProperties = Symbol('Value Properties');
6905
- const PURE = { pure: true };
6906
- const IMPURE = { pure: false };
6907
- // We use shortened variables to reduce file size here
6908
- /* OBJECT */
6909
- const O = {
6910
- __proto__: null,
6911
- [ValueProperties]: IMPURE
6912
- };
6913
- /* PURE FUNCTION */
6914
- const PF = {
6915
- __proto__: null,
6916
- [ValueProperties]: PURE
6917
- };
6918
- /* CONSTRUCTOR */
6919
- const C = {
6920
- __proto__: null,
6921
- [ValueProperties]: IMPURE,
6922
- prototype: O
6923
- };
6924
- /* PURE CONSTRUCTOR */
6925
- const PC = {
6926
- __proto__: null,
6927
- [ValueProperties]: PURE,
6928
- prototype: O
6929
- };
6930
- const ARRAY_TYPE = {
6931
- __proto__: null,
6932
- [ValueProperties]: PURE,
6933
- from: PF,
6934
- of: PF,
6935
- prototype: O
6936
- };
6937
- const INTL_MEMBER = {
6938
- __proto__: null,
6939
- [ValueProperties]: PURE,
6940
- supportedLocalesOf: PC
6941
- };
6942
- const knownGlobals = {
6943
- // Placeholders for global objects to avoid shape mutations
6944
- global: O,
6945
- globalThis: O,
6946
- self: O,
6947
- window: O,
6948
- // Common globals
6949
- __proto__: null,
6950
- [ValueProperties]: IMPURE,
6951
- Array: {
6952
- __proto__: null,
6953
- [ValueProperties]: IMPURE,
6954
- from: O,
6989
+ class FunctionBase extends NodeBase {
6990
+ constructor() {
6991
+ super(...arguments);
6992
+ // By default, parameters are included via includeArgumentsWhenCalledAtPath
6993
+ this.alwaysIncludeParameters = false;
6994
+ this.objectEntity = null;
6995
+ this.deoptimizedReturn = false;
6996
+ }
6997
+ deoptimizeCache() {
6998
+ this.alwaysIncludeParameters = true;
6999
+ }
7000
+ deoptimizePath(path) {
7001
+ this.getObjectEntity().deoptimizePath(path);
7002
+ if (path.length === 1 && path[0] === UnknownKey) {
7003
+ // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
7004
+ // which means the return expression needs to be reassigned
7005
+ this.alwaysIncludeParameters = true;
7006
+ this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
7007
+ }
7008
+ }
7009
+ deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
7010
+ if (path.length > 0) {
7011
+ this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
7012
+ }
7013
+ }
7014
+ getLiteralValueAtPath(path, recursionTracker, origin) {
7015
+ return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
7016
+ }
7017
+ getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
7018
+ if (path.length > 0) {
7019
+ return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
7020
+ }
7021
+ if (this.async) {
7022
+ if (!this.deoptimizedReturn) {
7023
+ this.deoptimizedReturn = true;
7024
+ this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
7025
+ this.context.requestTreeshakingPass();
7026
+ }
7027
+ return UNKNOWN_EXPRESSION;
7028
+ }
7029
+ return this.scope.getReturnExpression();
7030
+ }
7031
+ hasEffectsWhenAccessedAtPath(path, context) {
7032
+ return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
7033
+ }
7034
+ hasEffectsWhenAssignedAtPath(path, context) {
7035
+ return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
7036
+ }
7037
+ hasEffectsWhenCalledAtPath(path, callOptions, context) {
7038
+ if (path.length > 0) {
7039
+ return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
7040
+ }
7041
+ if (this.async) {
7042
+ const { propertyReadSideEffects } = this.context.options
7043
+ .treeshake;
7044
+ const returnExpression = this.scope.getReturnExpression();
7045
+ if (returnExpression.hasEffectsWhenCalledAtPath(['then'], { args: NO_ARGS, thisParam: null, withNew: false }, context) ||
7046
+ (propertyReadSideEffects &&
7047
+ (propertyReadSideEffects === 'always' ||
7048
+ returnExpression.hasEffectsWhenAccessedAtPath(['then'], context)))) {
7049
+ return true;
7050
+ }
7051
+ }
7052
+ for (const param of this.params) {
7053
+ if (param.hasEffects(context))
7054
+ return true;
7055
+ }
7056
+ return false;
7057
+ }
7058
+ include(context, includeChildrenRecursively) {
7059
+ this.included = true;
7060
+ const { brokenFlow } = context;
7061
+ context.brokenFlow = BROKEN_FLOW_NONE;
7062
+ this.body.include(context, includeChildrenRecursively);
7063
+ context.brokenFlow = brokenFlow;
7064
+ if (includeChildrenRecursively || this.alwaysIncludeParameters) {
7065
+ for (const param of this.params) {
7066
+ param.include(context, includeChildrenRecursively);
7067
+ }
7068
+ }
7069
+ }
7070
+ includeArgumentsWhenCalledAtPath(path, context, args) {
7071
+ var _a;
7072
+ if (path.length === 0) {
7073
+ for (let position = 0; position < this.params.length; position++) {
7074
+ const parameter = this.params[position];
7075
+ if (parameter instanceof AssignmentPattern) {
7076
+ if (parameter.left.shouldBeIncluded(context)) {
7077
+ parameter.left.include(context, false);
7078
+ }
7079
+ const argumentValue = (_a = args[position]) === null || _a === void 0 ? void 0 : _a.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
7080
+ // If argumentValue === UnknownTruthyValue, then we do not need to
7081
+ // include the default
7082
+ if ((argumentValue === undefined || argumentValue === UnknownValue) &&
7083
+ (this.parameterVariables[position].some(variable => variable.included) ||
7084
+ parameter.right.shouldBeIncluded(context))) {
7085
+ parameter.right.include(context, false);
7086
+ }
7087
+ }
7088
+ else if (parameter.shouldBeIncluded(context)) {
7089
+ parameter.include(context, false);
7090
+ }
7091
+ }
7092
+ this.scope.includeCallArguments(context, args);
7093
+ }
7094
+ else {
7095
+ this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
7096
+ }
7097
+ }
7098
+ initialise() {
7099
+ this.parameterVariables = this.params.map(param => param.declare('parameter', UNKNOWN_EXPRESSION));
7100
+ this.scope.addParameterVariables(this.parameterVariables, this.params[this.params.length - 1] instanceof RestElement);
7101
+ if (this.body instanceof BlockStatement) {
7102
+ this.body.addImplicitReturnExpressionToScope();
7103
+ }
7104
+ else {
7105
+ this.scope.addReturnExpression(this.body);
7106
+ }
7107
+ }
7108
+ parseNode(esTreeNode) {
7109
+ if (esTreeNode.body.type === BlockStatement$1) {
7110
+ this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
7111
+ }
7112
+ super.parseNode(esTreeNode);
7113
+ }
7114
+ }
7115
+ FunctionBase.prototype.preventChildBlockScope = true;
7116
+
7117
+ class ArrowFunctionExpression extends FunctionBase {
7118
+ constructor() {
7119
+ super(...arguments);
7120
+ this.objectEntity = null;
7121
+ }
7122
+ createScope(parentScope) {
7123
+ this.scope = new ReturnValueScope(parentScope, this.context);
7124
+ }
7125
+ hasEffects() {
7126
+ return false;
7127
+ }
7128
+ hasEffectsWhenCalledAtPath(path, callOptions, context) {
7129
+ if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
7130
+ return true;
7131
+ const { ignore, brokenFlow } = context;
7132
+ context.ignore = {
7133
+ breaks: false,
7134
+ continues: false,
7135
+ labels: new Set(),
7136
+ returnYield: true
7137
+ };
7138
+ if (this.body.hasEffects(context))
7139
+ return true;
7140
+ context.ignore = ignore;
7141
+ context.brokenFlow = brokenFlow;
7142
+ return false;
7143
+ }
7144
+ getObjectEntity() {
7145
+ if (this.objectEntity !== null) {
7146
+ return this.objectEntity;
7147
+ }
7148
+ return (this.objectEntity = new ObjectEntity([], OBJECT_PROTOTYPE));
7149
+ }
7150
+ }
7151
+
7152
+ function getSystemExportStatement(exportedVariables, { exportNamesByVariable, snippets: { _, getObject, getPropertyAccess } }, modifier = '') {
7153
+ if (exportedVariables.length === 1 &&
7154
+ exportNamesByVariable.get(exportedVariables[0]).length === 1) {
7155
+ const variable = exportedVariables[0];
7156
+ return `exports('${exportNamesByVariable.get(variable)}',${_}${variable.getName(getPropertyAccess)}${modifier})`;
7157
+ }
7158
+ else {
7159
+ const fields = [];
7160
+ for (const variable of exportedVariables) {
7161
+ for (const exportName of exportNamesByVariable.get(variable)) {
7162
+ fields.push([exportName, variable.getName(getPropertyAccess) + modifier]);
7163
+ }
7164
+ }
7165
+ return `exports(${getObject(fields, { lineBreakIndent: null })})`;
7166
+ }
7167
+ }
7168
+ function renderSystemExportExpression(exportedVariable, expressionStart, expressionEnd, code, { exportNamesByVariable, snippets: { _ } }) {
7169
+ code.prependRight(expressionStart, `exports('${exportNamesByVariable.get(exportedVariable)}',${_}`);
7170
+ code.appendLeft(expressionEnd, ')');
7171
+ }
7172
+ function renderSystemExportFunction(exportedVariables, expressionStart, expressionEnd, needsParens, code, options) {
7173
+ const { _, getDirectReturnIifeLeft } = options.snippets;
7174
+ code.prependRight(expressionStart, getDirectReturnIifeLeft(['v'], `${getSystemExportStatement(exportedVariables, options)},${_}v`, { needsArrowReturnParens: true, needsWrappedFunction: needsParens }));
7175
+ code.appendLeft(expressionEnd, ')');
7176
+ }
7177
+ function renderSystemExportSequenceAfterExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options) {
7178
+ const { _, getPropertyAccess } = options.snippets;
7179
+ code.appendLeft(expressionEnd, `,${_}${getSystemExportStatement([exportedVariable], options)},${_}${exportedVariable.getName(getPropertyAccess)}`);
7180
+ if (needsParens) {
7181
+ code.prependRight(expressionStart, '(');
7182
+ code.appendLeft(expressionEnd, ')');
7183
+ }
7184
+ }
7185
+ function renderSystemExportSequenceBeforeExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options, modifier) {
7186
+ const { _ } = options.snippets;
7187
+ code.prependRight(expressionStart, `${getSystemExportStatement([exportedVariable], options, modifier)},${_}`);
7188
+ if (needsParens) {
7189
+ code.prependRight(expressionStart, '(');
7190
+ code.appendLeft(expressionEnd, ')');
7191
+ }
7192
+ }
7193
+
7194
+ //@ts-check
7195
+ /** @typedef { import('estree').Node} Node */
7196
+ /** @typedef {Node | {
7197
+ * type: 'PropertyDefinition';
7198
+ * computed: boolean;
7199
+ * value: Node
7200
+ * }} NodeWithPropertyDefinition */
7201
+
7202
+ /**
7203
+ *
7204
+ * @param {NodeWithPropertyDefinition} node
7205
+ * @param {NodeWithPropertyDefinition} parent
7206
+ * @returns boolean
7207
+ */
7208
+ function is_reference (node, parent) {
7209
+ if (node.type === 'MemberExpression') {
7210
+ return !node.computed && is_reference(node.object, node);
7211
+ }
7212
+
7213
+ if (node.type === 'Identifier') {
7214
+ if (!parent) return true;
7215
+
7216
+ switch (parent.type) {
7217
+ // disregard `bar` in `foo.bar`
7218
+ case 'MemberExpression': return parent.computed || node === parent.object;
7219
+
7220
+ // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
7221
+ case 'MethodDefinition': return parent.computed;
7222
+
7223
+ // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
7224
+ case 'PropertyDefinition': return parent.computed || node === parent.value;
7225
+
7226
+ // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
7227
+ case 'Property': return parent.computed || node === parent.value;
7228
+
7229
+ // disregard the `bar` in `export { foo as bar }` or
7230
+ // the foo in `import { foo as bar }`
7231
+ case 'ExportSpecifier':
7232
+ case 'ImportSpecifier': return node === parent.local;
7233
+
7234
+ // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
7235
+ case 'LabeledStatement':
7236
+ case 'BreakStatement':
7237
+ case 'ContinueStatement': return false;
7238
+ default: return true;
7239
+ }
7240
+ }
7241
+
7242
+ return false;
7243
+ }
7244
+
7245
+ /* eslint sort-keys: "off" */
7246
+ const ValueProperties = Symbol('Value Properties');
7247
+ const PURE = {
7248
+ hasEffectsWhenCalled() {
7249
+ return false;
7250
+ }
7251
+ };
7252
+ const IMPURE = {
7253
+ hasEffectsWhenCalled() {
7254
+ return true;
7255
+ }
7256
+ };
7257
+ // We use shortened variables to reduce file size here
7258
+ /* OBJECT */
7259
+ const O = {
7260
+ __proto__: null,
7261
+ [ValueProperties]: IMPURE
7262
+ };
7263
+ /* PURE FUNCTION */
7264
+ const PF = {
7265
+ __proto__: null,
7266
+ [ValueProperties]: PURE
7267
+ };
7268
+ /* FUNCTION THAT MUTATES FIRST ARG WITHOUT TRIGGERING ACCESSORS */
7269
+ const MUTATES_ARG_WITHOUT_ACCESSOR = {
7270
+ __proto__: null,
7271
+ [ValueProperties]: {
7272
+ hasEffectsWhenCalled(callOptions, context) {
7273
+ return (!callOptions.args.length ||
7274
+ callOptions.args[0].hasEffectsWhenAssignedAtPath(UNKNOWN_NON_ACCESSOR_PATH, context));
7275
+ }
7276
+ }
7277
+ };
7278
+ /* CONSTRUCTOR */
7279
+ const C = {
7280
+ __proto__: null,
7281
+ [ValueProperties]: IMPURE,
7282
+ prototype: O
7283
+ };
7284
+ /* PURE CONSTRUCTOR */
7285
+ const PC = {
7286
+ __proto__: null,
7287
+ [ValueProperties]: PURE,
7288
+ prototype: O
7289
+ };
7290
+ const ARRAY_TYPE = {
7291
+ __proto__: null,
7292
+ [ValueProperties]: PURE,
7293
+ from: PF,
7294
+ of: PF,
7295
+ prototype: O
7296
+ };
7297
+ const INTL_MEMBER = {
7298
+ __proto__: null,
7299
+ [ValueProperties]: PURE,
7300
+ supportedLocalesOf: PC
7301
+ };
7302
+ const knownGlobals = {
7303
+ // Placeholders for global objects to avoid shape mutations
7304
+ global: O,
7305
+ globalThis: O,
7306
+ self: O,
7307
+ window: O,
7308
+ // Common globals
7309
+ __proto__: null,
7310
+ [ValueProperties]: IMPURE,
7311
+ Array: {
7312
+ __proto__: null,
7313
+ [ValueProperties]: IMPURE,
7314
+ from: O,
6955
7315
  isArray: PF,
6956
7316
  of: PF,
6957
7317
  prototype: O
@@ -7053,6 +7413,11 @@ const knownGlobals = {
7053
7413
  __proto__: null,
7054
7414
  [ValueProperties]: PURE,
7055
7415
  create: PF,
7416
+ // Technically those can throw in certain situations, but we ignore this as
7417
+ // code that relies on this will hopefully wrap this in a try-catch, which
7418
+ // deoptimizes everything anyway
7419
+ defineProperty: MUTATES_ARG_WITHOUT_ACCESSOR,
7420
+ defineProperties: MUTATES_ARG_WITHOUT_ACCESSOR,
7056
7421
  getOwnPropertyDescriptor: PF,
7057
7422
  getOwnPropertyNames: PF,
7058
7423
  getOwnPropertySymbols: PF,
@@ -7736,27 +8101,27 @@ function getGlobalAtPath(path) {
7736
8101
  }
7737
8102
  return currentGlobal[ValueProperties];
7738
8103
  }
7739
- function isPureGlobal(path) {
7740
- const globalAtPath = getGlobalAtPath(path);
7741
- return globalAtPath !== null && globalAtPath.pure;
7742
- }
7743
- function isGlobalMember(path) {
7744
- if (path.length === 1) {
7745
- return path[0] === 'undefined' || getGlobalAtPath(path) !== null;
7746
- }
7747
- return getGlobalAtPath(path.slice(0, -1)) !== null;
7748
- }
7749
8104
 
7750
8105
  class GlobalVariable extends Variable {
7751
8106
  constructor() {
7752
8107
  super(...arguments);
8108
+ // Ensure we use live-bindings for globals as we do not know if they have
8109
+ // been reassigned
7753
8110
  this.isReassigned = true;
7754
8111
  }
8112
+ getLiteralValueAtPath(path, _recursionTracker, _origin) {
8113
+ return getGlobalAtPath([this.name, ...path]) ? UnknownTruthyValue : UnknownValue;
8114
+ }
7755
8115
  hasEffectsWhenAccessedAtPath(path) {
7756
- return !isGlobalMember([this.name, ...path]);
8116
+ if (path.length === 0) {
8117
+ // Technically, "undefined" is a global variable of sorts
8118
+ return this.name !== 'undefined' && !getGlobalAtPath([this.name]);
8119
+ }
8120
+ return !getGlobalAtPath([this.name, ...path].slice(0, -1));
7757
8121
  }
7758
- hasEffectsWhenCalledAtPath(path) {
7759
- return !isPureGlobal([this.name, ...path]);
8122
+ hasEffectsWhenCalledAtPath(path, callOptions, context) {
8123
+ const globalAtPath = getGlobalAtPath([this.name, ...path]);
8124
+ return !globalAtPath || globalAtPath.hasEffectsWhenCalled(callOptions, context);
7760
8125
  }
7761
8126
  }
7762
8127
 
@@ -7775,12 +8140,12 @@ class Identifier extends NodeBase {
7775
8140
  this.isTDZAccess = null;
7776
8141
  }
7777
8142
  addExportedVariables(variables, exportNamesByVariable) {
7778
- if (this.variable !== null && exportNamesByVariable.has(this.variable)) {
8143
+ if (exportNamesByVariable.has(this.variable)) {
7779
8144
  variables.push(this.variable);
7780
8145
  }
7781
8146
  }
7782
8147
  bind() {
7783
- if (this.variable === null && is_reference(this, this.parent)) {
8148
+ if (!this.variable && is_reference(this, this.parent)) {
7784
8149
  this.variable = this.scope.findVariable(this.name);
7785
8150
  this.variable.addReference(this);
7786
8151
  }
@@ -7842,18 +8207,14 @@ class Identifier extends NodeBase {
7842
8207
  this.variable.hasEffectsWhenAccessedAtPath(EMPTY_PATH));
7843
8208
  }
7844
8209
  hasEffectsWhenAccessedAtPath(path, context) {
7845
- return (this.variable !== null &&
7846
- this.getVariableRespectingTDZ().hasEffectsWhenAccessedAtPath(path, context));
8210
+ var _a;
8211
+ return (_a = this.getVariableRespectingTDZ()) === null || _a === void 0 ? void 0 : _a.hasEffectsWhenAccessedAtPath(path, context);
7847
8212
  }
7848
8213
  hasEffectsWhenAssignedAtPath(path, context) {
7849
- return (!this.variable ||
7850
- (path.length > 0
7851
- ? this.getVariableRespectingTDZ()
7852
- : this.variable).hasEffectsWhenAssignedAtPath(path, context));
8214
+ return (path.length > 0 ? this.getVariableRespectingTDZ() : this.variable).hasEffectsWhenAssignedAtPath(path, context);
7853
8215
  }
7854
8216
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
7855
- return (!this.variable ||
7856
- this.getVariableRespectingTDZ().hasEffectsWhenCalledAtPath(path, callOptions, context));
8217
+ return this.getVariableRespectingTDZ().hasEffectsWhenCalledAtPath(path, callOptions, context);
7857
8218
  }
7858
8219
  include() {
7859
8220
  if (!this.deoptimized)
@@ -7865,8 +8226,8 @@ class Identifier extends NodeBase {
7865
8226
  }
7866
8227
  }
7867
8228
  }
7868
- includeCallArguments(context, args) {
7869
- this.getVariableRespectingTDZ().includeCallArguments(context, args);
8229
+ includeArgumentsWhenCalledAtPath(path, context, args) {
8230
+ this.variable.includeArgumentsWhenCalledAtPath(path, context, args);
7870
8231
  }
7871
8232
  isPossibleTDZ() {
7872
8233
  // return cached value to avoid issues with the next tree-shaking pass
@@ -7919,7 +8280,7 @@ class Identifier extends NodeBase {
7919
8280
  }
7920
8281
  applyDeoptimizations() {
7921
8282
  this.deoptimized = true;
7922
- if (this.variable !== null && this.variable instanceof LocalVariable) {
8283
+ if (this.variable instanceof LocalVariable) {
7923
8284
  this.variable.consolidateInitializers();
7924
8285
  this.context.requestTreeshakingPass();
7925
8286
  }
@@ -7945,183 +8306,6 @@ function closestParentFunctionOrProgram(node) {
7945
8306
  return node;
7946
8307
  }
7947
8308
 
7948
- class RestElement extends NodeBase {
7949
- constructor() {
7950
- super(...arguments);
7951
- this.deoptimized = false;
7952
- this.declarationInit = null;
7953
- }
7954
- addExportedVariables(variables, exportNamesByVariable) {
7955
- this.argument.addExportedVariables(variables, exportNamesByVariable);
7956
- }
7957
- declare(kind, init) {
7958
- this.declarationInit = init;
7959
- return this.argument.declare(kind, UNKNOWN_EXPRESSION);
7960
- }
7961
- deoptimizePath(path) {
7962
- path.length === 0 && this.argument.deoptimizePath(EMPTY_PATH);
7963
- }
7964
- hasEffectsWhenAssignedAtPath(path, context) {
7965
- return path.length > 0 || this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
7966
- }
7967
- markDeclarationReached() {
7968
- this.argument.markDeclarationReached();
7969
- }
7970
- applyDeoptimizations() {
7971
- this.deoptimized = true;
7972
- if (this.declarationInit !== null) {
7973
- this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
7974
- this.context.requestTreeshakingPass();
7975
- }
7976
- }
7977
- }
7978
-
7979
- class ArrowFunctionExpression extends NodeBase {
7980
- constructor() {
7981
- super(...arguments);
7982
- this.deoptimizedReturn = false;
7983
- }
7984
- createScope(parentScope) {
7985
- this.scope = new ReturnValueScope(parentScope, this.context);
7986
- }
7987
- deoptimizePath(path) {
7988
- // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
7989
- // which means the return expression needs to be reassigned
7990
- if (path.length === 1 && path[0] === UnknownKey) {
7991
- this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
7992
- }
7993
- }
7994
- // Arrow functions do not mutate their context
7995
- deoptimizeThisOnEventAtPath() { }
7996
- getReturnExpressionWhenCalledAtPath(path) {
7997
- if (path.length !== 0) {
7998
- return UNKNOWN_EXPRESSION;
7999
- }
8000
- if (this.async) {
8001
- if (!this.deoptimizedReturn) {
8002
- this.deoptimizedReturn = true;
8003
- this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
8004
- this.context.requestTreeshakingPass();
8005
- }
8006
- return UNKNOWN_EXPRESSION;
8007
- }
8008
- return this.scope.getReturnExpression();
8009
- }
8010
- hasEffects() {
8011
- return false;
8012
- }
8013
- hasEffectsWhenAccessedAtPath(path) {
8014
- return path.length > 1;
8015
- }
8016
- hasEffectsWhenAssignedAtPath(path) {
8017
- return path.length > 1;
8018
- }
8019
- hasEffectsWhenCalledAtPath(path, _callOptions, context) {
8020
- if (path.length > 0)
8021
- return true;
8022
- if (this.async) {
8023
- const { propertyReadSideEffects } = this.context.options
8024
- .treeshake;
8025
- const returnExpression = this.scope.getReturnExpression();
8026
- if (returnExpression.hasEffectsWhenCalledAtPath(['then'], { args: NO_ARGS, thisParam: null, withNew: false }, context) ||
8027
- (propertyReadSideEffects &&
8028
- (propertyReadSideEffects === 'always' ||
8029
- returnExpression.hasEffectsWhenAccessedAtPath(['then'], context)))) {
8030
- return true;
8031
- }
8032
- }
8033
- for (const param of this.params) {
8034
- if (param.hasEffects(context))
8035
- return true;
8036
- }
8037
- const { ignore, brokenFlow } = context;
8038
- context.ignore = {
8039
- breaks: false,
8040
- continues: false,
8041
- labels: new Set(),
8042
- returnYield: true
8043
- };
8044
- if (this.body.hasEffects(context))
8045
- return true;
8046
- context.ignore = ignore;
8047
- context.brokenFlow = brokenFlow;
8048
- return false;
8049
- }
8050
- include(context, includeChildrenRecursively) {
8051
- this.included = true;
8052
- for (const param of this.params) {
8053
- if (!(param instanceof Identifier)) {
8054
- param.include(context, includeChildrenRecursively);
8055
- }
8056
- }
8057
- const { brokenFlow } = context;
8058
- context.brokenFlow = BROKEN_FLOW_NONE;
8059
- this.body.include(context, includeChildrenRecursively);
8060
- context.brokenFlow = brokenFlow;
8061
- }
8062
- includeCallArguments(context, args) {
8063
- this.scope.includeCallArguments(context, args);
8064
- }
8065
- initialise() {
8066
- this.scope.addParameterVariables(this.params.map(param => param.declare('parameter', UNKNOWN_EXPRESSION)), this.params[this.params.length - 1] instanceof RestElement);
8067
- if (this.body instanceof BlockStatement) {
8068
- this.body.addImplicitReturnExpressionToScope();
8069
- }
8070
- else {
8071
- this.scope.addReturnExpression(this.body);
8072
- }
8073
- }
8074
- parseNode(esTreeNode) {
8075
- if (esTreeNode.body.type === BlockStatement$1) {
8076
- this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
8077
- }
8078
- super.parseNode(esTreeNode);
8079
- }
8080
- }
8081
- ArrowFunctionExpression.prototype.preventChildBlockScope = true;
8082
-
8083
- function getSystemExportStatement(exportedVariables, { exportNamesByVariable, snippets: { _, getObject, getPropertyAccess } }, modifier = '') {
8084
- if (exportedVariables.length === 1 &&
8085
- exportNamesByVariable.get(exportedVariables[0]).length === 1) {
8086
- const variable = exportedVariables[0];
8087
- return `exports('${exportNamesByVariable.get(variable)}',${_}${variable.getName(getPropertyAccess)}${modifier})`;
8088
- }
8089
- else {
8090
- const fields = [];
8091
- for (const variable of exportedVariables) {
8092
- for (const exportName of exportNamesByVariable.get(variable)) {
8093
- fields.push([exportName, variable.getName(getPropertyAccess) + modifier]);
8094
- }
8095
- }
8096
- return `exports(${getObject(fields, { lineBreakIndent: null })})`;
8097
- }
8098
- }
8099
- function renderSystemExportExpression(exportedVariable, expressionStart, expressionEnd, code, { exportNamesByVariable, snippets: { _ } }) {
8100
- code.prependRight(expressionStart, `exports('${exportNamesByVariable.get(exportedVariable)}',${_}`);
8101
- code.appendLeft(expressionEnd, ')');
8102
- }
8103
- function renderSystemExportFunction(exportedVariables, expressionStart, expressionEnd, needsParens, code, options) {
8104
- const { _, getDirectReturnIifeLeft } = options.snippets;
8105
- code.prependRight(expressionStart, getDirectReturnIifeLeft(['v'], `${getSystemExportStatement(exportedVariables, options)},${_}v`, { needsArrowReturnParens: true, needsWrappedFunction: needsParens }));
8106
- code.appendLeft(expressionEnd, ')');
8107
- }
8108
- function renderSystemExportSequenceAfterExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options) {
8109
- const { _, getPropertyAccess } = options.snippets;
8110
- code.appendLeft(expressionEnd, `,${_}${getSystemExportStatement([exportedVariable], options)},${_}${exportedVariable.getName(getPropertyAccess)}`);
8111
- if (needsParens) {
8112
- code.prependRight(expressionStart, '(');
8113
- code.appendLeft(expressionEnd, ')');
8114
- }
8115
- }
8116
- function renderSystemExportSequenceBeforeExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options, modifier) {
8117
- const { _ } = options.snippets;
8118
- code.prependRight(expressionStart, `${getSystemExportStatement([exportedVariable], options, modifier)},${_}`);
8119
- if (needsParens) {
8120
- code.prependRight(expressionStart, '(');
8121
- code.appendLeft(expressionEnd, ')');
8122
- }
8123
- }
8124
-
8125
8309
  class ObjectPattern extends NodeBase {
8126
8310
  addExportedVariables(variables, exportNamesByVariable) {
8127
8311
  for (const property of this.properties) {
@@ -8248,38 +8432,6 @@ class AssignmentExpression extends NodeBase {
8248
8432
  }
8249
8433
  }
8250
8434
 
8251
- class AssignmentPattern extends NodeBase {
8252
- constructor() {
8253
- super(...arguments);
8254
- this.deoptimized = false;
8255
- }
8256
- addExportedVariables(variables, exportNamesByVariable) {
8257
- this.left.addExportedVariables(variables, exportNamesByVariable);
8258
- }
8259
- declare(kind, init) {
8260
- return this.left.declare(kind, init);
8261
- }
8262
- deoptimizePath(path) {
8263
- path.length === 0 && this.left.deoptimizePath(path);
8264
- }
8265
- hasEffectsWhenAssignedAtPath(path, context) {
8266
- return path.length > 0 || this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
8267
- }
8268
- markDeclarationReached() {
8269
- this.left.markDeclarationReached();
8270
- }
8271
- render(code, options, { isShorthandProperty } = BLANK) {
8272
- this.left.render(code, options, { isShorthandProperty });
8273
- this.right.render(code, options);
8274
- }
8275
- applyDeoptimizations() {
8276
- this.deoptimized = true;
8277
- this.left.deoptimizePath(EMPTY_PATH);
8278
- this.right.deoptimizePath(UNKNOWN_PATH);
8279
- this.context.requestTreeshakingPass();
8280
- }
8281
- }
8282
-
8283
8435
  class ArgumentsVariable extends LocalVariable {
8284
8436
  constructor(context) {
8285
8437
  super('arguments', null, UNKNOWN_EXPRESSION, context);
@@ -8372,85 +8524,27 @@ class FunctionScope extends ReturnValueScope {
8372
8524
  }
8373
8525
  }
8374
8526
 
8375
- class FunctionNode extends NodeBase {
8527
+ class FunctionNode extends FunctionBase {
8376
8528
  constructor() {
8377
8529
  super(...arguments);
8378
- this.deoptimizedReturn = false;
8379
- this.isPrototypeDeoptimized = false;
8530
+ this.objectEntity = null;
8380
8531
  }
8381
8532
  createScope(parentScope) {
8382
8533
  this.scope = new FunctionScope(parentScope, this.context);
8383
8534
  }
8384
- deoptimizePath(path) {
8385
- if (path.length === 1) {
8386
- if (path[0] === 'prototype') {
8387
- this.isPrototypeDeoptimized = true;
8388
- }
8389
- else if (path[0] === UnknownKey) {
8390
- this.isPrototypeDeoptimized = true;
8391
- // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
8392
- // which means the return expression needs to be reassigned as well
8393
- this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
8394
- }
8395
- }
8396
- }
8397
- // TODO for completeness, we should also track other events here
8398
- deoptimizeThisOnEventAtPath(event, path, thisParameter) {
8399
- if (event === EVENT_CALLED) {
8400
- if (path.length > 0) {
8401
- thisParameter.deoptimizePath(UNKNOWN_PATH);
8402
- }
8403
- else {
8404
- this.scope.thisVariable.addEntityToBeDeoptimized(thisParameter);
8405
- }
8406
- }
8407
- }
8408
- getReturnExpressionWhenCalledAtPath(path) {
8409
- if (path.length !== 0) {
8410
- return UNKNOWN_EXPRESSION;
8411
- }
8412
- if (this.async) {
8413
- if (!this.deoptimizedReturn) {
8414
- this.deoptimizedReturn = true;
8415
- this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
8416
- this.context.requestTreeshakingPass();
8417
- }
8418
- return UNKNOWN_EXPRESSION;
8535
+ deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
8536
+ super.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
8537
+ if (event === EVENT_CALLED && path.length === 0) {
8538
+ this.scope.thisVariable.addEntityToBeDeoptimized(thisParameter);
8419
8539
  }
8420
- return this.scope.getReturnExpression();
8421
8540
  }
8422
8541
  hasEffects() {
8423
- return this.id !== null && this.id.hasEffects();
8424
- }
8425
- hasEffectsWhenAccessedAtPath(path) {
8426
- if (path.length <= 1)
8427
- return false;
8428
- return path.length > 2 || path[0] !== 'prototype' || this.isPrototypeDeoptimized;
8429
- }
8430
- hasEffectsWhenAssignedAtPath(path) {
8431
- if (path.length <= 1) {
8432
- return false;
8433
- }
8434
- return path.length > 2 || path[0] !== 'prototype' || this.isPrototypeDeoptimized;
8542
+ var _a;
8543
+ return (_a = this.id) === null || _a === void 0 ? void 0 : _a.hasEffects();
8435
8544
  }
8436
8545
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
8437
- if (path.length > 0)
8438
- return true;
8439
- if (this.async) {
8440
- const { propertyReadSideEffects } = this.context.options
8441
- .treeshake;
8442
- const returnExpression = this.scope.getReturnExpression();
8443
- if (returnExpression.hasEffectsWhenCalledAtPath(['then'], { args: NO_ARGS, thisParam: null, withNew: false }, context) ||
8444
- (propertyReadSideEffects &&
8445
- (propertyReadSideEffects === 'always' ||
8446
- returnExpression.hasEffectsWhenAccessedAtPath(['then'], context)))) {
8447
- return true;
8448
- }
8449
- }
8450
- for (const param of this.params) {
8451
- if (param.hasEffects(context))
8452
- return true;
8453
- }
8546
+ if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
8547
+ return true;
8454
8548
  const thisInit = context.replacedVariableInits.get(this.scope.thisVariable);
8455
8549
  context.replacedVariableInits.set(this.scope.thisVariable, callOptions.withNew
8456
8550
  ? new ObjectEntity(Object.create(null), OBJECT_PROTOTYPE)
@@ -8475,36 +8569,32 @@ class FunctionNode extends NodeBase {
8475
8569
  return false;
8476
8570
  }
8477
8571
  include(context, includeChildrenRecursively) {
8478
- this.included = true;
8479
- if (this.id)
8480
- this.id.include();
8481
- const hasArguments = this.scope.argumentsVariable.included;
8482
- for (const param of this.params) {
8483
- if (!(param instanceof Identifier) || hasArguments) {
8484
- param.include(context, includeChildrenRecursively);
8485
- }
8572
+ var _a;
8573
+ // This ensures that super.include will also include all parameters
8574
+ if (this.scope.argumentsVariable.included) {
8575
+ this.alwaysIncludeParameters = true;
8486
8576
  }
8487
- const { brokenFlow } = context;
8488
- context.brokenFlow = BROKEN_FLOW_NONE;
8489
- this.body.include(context, includeChildrenRecursively);
8490
- context.brokenFlow = brokenFlow;
8491
- }
8492
- includeCallArguments(context, args) {
8493
- this.scope.includeCallArguments(context, args);
8577
+ (_a = this.id) === null || _a === void 0 ? void 0 : _a.include();
8578
+ super.include(context, includeChildrenRecursively);
8494
8579
  }
8495
8580
  initialise() {
8496
- if (this.id !== null) {
8497
- this.id.declare('function', this);
8498
- }
8499
- this.scope.addParameterVariables(this.params.map(param => param.declare('parameter', UNKNOWN_EXPRESSION)), this.params[this.params.length - 1] instanceof RestElement);
8500
- this.body.addImplicitReturnExpressionToScope();
8581
+ var _a;
8582
+ super.initialise();
8583
+ (_a = this.id) === null || _a === void 0 ? void 0 : _a.declare('function', this);
8501
8584
  }
8502
- parseNode(esTreeNode) {
8503
- this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
8504
- super.parseNode(esTreeNode);
8585
+ getObjectEntity() {
8586
+ if (this.objectEntity !== null) {
8587
+ return this.objectEntity;
8588
+ }
8589
+ return (this.objectEntity = new ObjectEntity([
8590
+ {
8591
+ key: 'prototype',
8592
+ kind: 'init',
8593
+ property: new ObjectEntity([], OBJECT_PROTOTYPE)
8594
+ }
8595
+ ], OBJECT_PROTOTYPE));
8505
8596
  }
8506
8597
  }
8507
- FunctionNode.prototype.preventChildBlockScope = true;
8508
8598
 
8509
8599
  class AwaitExpression extends NodeBase {
8510
8600
  constructor() {
@@ -8532,11 +8622,6 @@ class AwaitExpression extends NodeBase {
8532
8622
  }
8533
8623
  this.argument.include(context, includeChildrenRecursively);
8534
8624
  }
8535
- applyDeoptimizations() {
8536
- this.deoptimized = true;
8537
- this.argument.deoptimizePath(UNKNOWN_PATH);
8538
- this.context.requestTreeshakingPass();
8539
- }
8540
8625
  }
8541
8626
 
8542
8627
  const binaryOperators = {
@@ -8570,10 +8655,10 @@ class BinaryExpression extends NodeBase {
8570
8655
  if (path.length > 0)
8571
8656
  return UnknownValue;
8572
8657
  const leftValue = this.left.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
8573
- if (leftValue === UnknownValue)
8658
+ if (typeof leftValue === 'symbol')
8574
8659
  return UnknownValue;
8575
8660
  const rightValue = this.right.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
8576
- if (rightValue === UnknownValue)
8661
+ if (typeof rightValue === 'symbol')
8577
8662
  return UnknownValue;
8578
8663
  const operatorFn = binaryOperators[this.operator];
8579
8664
  if (!operatorFn)
@@ -8754,7 +8839,11 @@ class MemberExpression extends NodeBase {
8754
8839
  }
8755
8840
  else if (!this.replacement) {
8756
8841
  if (path.length < MAX_PATH_DEPTH) {
8757
- this.object.deoptimizePath([this.getPropertyKey(), ...path]);
8842
+ const propertyKey = this.getPropertyKey();
8843
+ this.object.deoptimizePath([
8844
+ propertyKey === UnknownKey ? UnknownNonAccessorKey : propertyKey,
8845
+ ...path
8846
+ ]);
8758
8847
  }
8759
8848
  }
8760
8849
  }
@@ -8860,12 +8949,15 @@ class MemberExpression extends NodeBase {
8860
8949
  this.object.include(context, includeChildrenRecursively);
8861
8950
  this.property.include(context, includeChildrenRecursively);
8862
8951
  }
8863
- includeCallArguments(context, args) {
8952
+ includeArgumentsWhenCalledAtPath(path, context, args) {
8864
8953
  if (this.variable) {
8865
- this.variable.includeCallArguments(context, args);
8954
+ this.variable.includeArgumentsWhenCalledAtPath(path, context, args);
8866
8955
  }
8867
- else {
8868
- super.includeCallArguments(context, args);
8956
+ else if (this.replacement) {
8957
+ super.includeArgumentsWhenCalledAtPath(path, context, args);
8958
+ }
8959
+ else if (path.length < MAX_PATH_DEPTH) {
8960
+ this.object.includeArgumentsWhenCalledAtPath([this.getPropertyKey(), ...path], context, args);
8869
8961
  }
8870
8962
  }
8871
8963
  initialise() {
@@ -8927,7 +9019,7 @@ class MemberExpression extends NodeBase {
8927
9019
  if (this.propertyKey === null) {
8928
9020
  this.propertyKey = UnknownKey;
8929
9021
  const value = this.property.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
8930
- return (this.propertyKey = value === UnknownValue ? UnknownKey : String(value));
9022
+ return (this.propertyKey = typeof value === 'symbol' ? UnknownKey : String(value));
8931
9023
  }
8932
9024
  return this.propertyKey;
8933
9025
  }
@@ -8954,39 +9046,13 @@ class MemberExpression extends NodeBase {
8954
9046
  }
8955
9047
  }
8956
9048
 
8957
- class CallExpression extends NodeBase {
9049
+ class CallExpressionBase extends NodeBase {
8958
9050
  constructor() {
8959
9051
  super(...arguments);
8960
9052
  this.deoptimized = false;
9053
+ this.returnExpression = null;
8961
9054
  this.deoptimizableDependentExpressions = [];
8962
9055
  this.expressionsToBeDeoptimized = new Set();
8963
- this.returnExpression = null;
8964
- }
8965
- bind() {
8966
- super.bind();
8967
- if (this.callee instanceof Identifier) {
8968
- const variable = this.scope.findVariable(this.callee.name);
8969
- if (variable.isNamespace) {
8970
- this.context.warn({
8971
- code: 'CANNOT_CALL_NAMESPACE',
8972
- message: `Cannot call a namespace ('${this.callee.name}')`
8973
- }, this.start);
8974
- }
8975
- if (this.callee.name === 'eval') {
8976
- this.context.warn({
8977
- code: 'EVAL',
8978
- message: `Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification`,
8979
- url: 'https://rollupjs.org/guide/en/#avoiding-eval'
8980
- }, this.start);
8981
- }
8982
- }
8983
- this.callOptions = {
8984
- args: this.arguments,
8985
- thisParam: this.callee instanceof MemberExpression && !this.callee.variable
8986
- ? this.callee.object
8987
- : null,
8988
- withNew: false
8989
- };
8990
9056
  }
8991
9057
  deoptimizeCache() {
8992
9058
  if (this.returnExpression !== UNKNOWN_EXPRESSION) {
@@ -9041,6 +9107,47 @@ class CallExpression extends NodeBase {
9041
9107
  return returnExpression.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
9042
9108
  }, UNKNOWN_EXPRESSION);
9043
9109
  }
9110
+ hasEffectsWhenAccessedAtPath(path, context) {
9111
+ return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
9112
+ this.getReturnExpression().hasEffectsWhenAccessedAtPath(path, context));
9113
+ }
9114
+ hasEffectsWhenAssignedAtPath(path, context) {
9115
+ return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
9116
+ this.getReturnExpression().hasEffectsWhenAssignedAtPath(path, context));
9117
+ }
9118
+ hasEffectsWhenCalledAtPath(path, callOptions, context) {
9119
+ return (!(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
9120
+ this.getReturnExpression().hasEffectsWhenCalledAtPath(path, callOptions, context));
9121
+ }
9122
+ }
9123
+
9124
+ class CallExpression extends CallExpressionBase {
9125
+ bind() {
9126
+ super.bind();
9127
+ if (this.callee instanceof Identifier) {
9128
+ const variable = this.scope.findVariable(this.callee.name);
9129
+ if (variable.isNamespace) {
9130
+ this.context.warn({
9131
+ code: 'CANNOT_CALL_NAMESPACE',
9132
+ message: `Cannot call a namespace ('${this.callee.name}')`
9133
+ }, this.start);
9134
+ }
9135
+ if (this.callee.name === 'eval') {
9136
+ this.context.warn({
9137
+ code: 'EVAL',
9138
+ message: `Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification`,
9139
+ url: 'https://rollupjs.org/guide/en/#avoiding-eval'
9140
+ }, this.start);
9141
+ }
9142
+ }
9143
+ this.callOptions = {
9144
+ args: this.arguments,
9145
+ thisParam: this.callee instanceof MemberExpression && !this.callee.variable
9146
+ ? this.callee.object
9147
+ : null,
9148
+ withNew: false
9149
+ };
9150
+ }
9044
9151
  hasEffects(context) {
9045
9152
  try {
9046
9153
  for (const argument of this.arguments) {
@@ -9058,18 +9165,6 @@ class CallExpression extends NodeBase {
9058
9165
  this.applyDeoptimizations();
9059
9166
  }
9060
9167
  }
9061
- hasEffectsWhenAccessedAtPath(path, context) {
9062
- return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
9063
- this.getReturnExpression().hasEffectsWhenAccessedAtPath(path, context));
9064
- }
9065
- hasEffectsWhenAssignedAtPath(path, context) {
9066
- return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
9067
- this.getReturnExpression().hasEffectsWhenAssignedAtPath(path, context));
9068
- }
9069
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
9070
- return (!(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
9071
- this.getReturnExpression().hasEffectsWhenCalledAtPath(path, callOptions, context));
9072
- }
9073
9168
  include(context, includeChildrenRecursively) {
9074
9169
  if (!this.deoptimized)
9075
9170
  this.applyDeoptimizations();
@@ -9085,7 +9180,7 @@ class CallExpression extends NodeBase {
9085
9180
  this.included = true;
9086
9181
  this.callee.include(context, false);
9087
9182
  }
9088
- this.callee.includeCallArguments(context, this.arguments);
9183
+ this.callee.includeArgumentsWhenCalledAtPath(EMPTY_PATH, context, this.arguments);
9089
9184
  const returnExpression = this.getReturnExpression();
9090
9185
  if (!returnExpression.included) {
9091
9186
  returnExpression.include(context, false);
@@ -9256,6 +9351,9 @@ class MethodBase extends NodeBase {
9256
9351
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
9257
9352
  return this.getAccessedValue().hasEffectsWhenCalledAtPath(path, callOptions, context);
9258
9353
  }
9354
+ includeArgumentsWhenCalledAtPath(path, context, args) {
9355
+ this.getAccessedValue().includeArgumentsWhenCalledAtPath(path, context, args);
9356
+ }
9259
9357
  getAccessedValue() {
9260
9358
  if (this.accessedValue === null) {
9261
9359
  if (this.kind === 'get') {
@@ -9292,8 +9390,6 @@ class ObjectMember extends ExpressionEntity {
9292
9390
  return this.object.getReturnExpressionWhenCalledAtPath([this.key, ...path], callOptions, recursionTracker, origin);
9293
9391
  }
9294
9392
  hasEffectsWhenAccessedAtPath(path, context) {
9295
- if (path.length === 0)
9296
- return false;
9297
9393
  return this.object.hasEffectsWhenAccessedAtPath([this.key, ...path], context);
9298
9394
  }
9299
9395
  hasEffectsWhenAssignedAtPath(path, context) {
@@ -9307,6 +9403,7 @@ class ObjectMember extends ExpressionEntity {
9307
9403
  class ClassNode extends NodeBase {
9308
9404
  constructor() {
9309
9405
  super(...arguments);
9406
+ this.deoptimized = false;
9310
9407
  this.objectEntity = null;
9311
9408
  }
9312
9409
  createScope(parentScope) {
@@ -9316,7 +9413,14 @@ class ClassNode extends NodeBase {
9316
9413
  this.getObjectEntity().deoptimizeAllProperties();
9317
9414
  }
9318
9415
  deoptimizePath(path) {
9416
+ var _a, _b;
9319
9417
  this.getObjectEntity().deoptimizePath(path);
9418
+ if (path.length === 1 && path[0] === UnknownKey) {
9419
+ // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
9420
+ // which means the constructor needs to be reassigned
9421
+ (_a = this.classConstructor) === null || _a === void 0 ? void 0 : _a.deoptimizePath(UNKNOWN_PATH);
9422
+ (_b = this.superClass) === null || _b === void 0 ? void 0 : _b.deoptimizePath(UNKNOWN_PATH);
9423
+ }
9320
9424
  }
9321
9425
  deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
9322
9426
  this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
@@ -9329,6 +9433,8 @@ class ClassNode extends NodeBase {
9329
9433
  }
9330
9434
  hasEffects(context) {
9331
9435
  var _a, _b;
9436
+ if (!this.deoptimized)
9437
+ this.applyDeoptimizations();
9332
9438
  const initEffect = ((_a = this.superClass) === null || _a === void 0 ? void 0 : _a.hasEffects(context)) || this.body.hasEffects(context);
9333
9439
  (_b = this.id) === null || _b === void 0 ? void 0 : _b.markDeclarationReached();
9334
9440
  return initEffect || super.hasEffects(context);
@@ -9340,12 +9446,13 @@ class ClassNode extends NodeBase {
9340
9446
  return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
9341
9447
  }
9342
9448
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
9449
+ var _a;
9343
9450
  if (path.length === 0) {
9344
9451
  return (!callOptions.withNew ||
9345
9452
  (this.classConstructor !== null
9346
9453
  ? this.classConstructor.hasEffectsWhenCalledAtPath(EMPTY_PATH, callOptions, context)
9347
- : this.superClass !== null &&
9348
- this.superClass.hasEffectsWhenCalledAtPath(path, callOptions, context)));
9454
+ : (_a = this.superClass) === null || _a === void 0 ? void 0 : _a.hasEffectsWhenCalledAtPath(path, callOptions, context)) ||
9455
+ false);
9349
9456
  }
9350
9457
  else {
9351
9458
  return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
@@ -9353,6 +9460,8 @@ class ClassNode extends NodeBase {
9353
9460
  }
9354
9461
  include(context, includeChildrenRecursively) {
9355
9462
  var _a;
9463
+ if (!this.deoptimized)
9464
+ this.applyDeoptimizations();
9356
9465
  this.included = true;
9357
9466
  (_a = this.superClass) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
9358
9467
  this.body.include(context, includeChildrenRecursively);
@@ -9361,6 +9470,20 @@ class ClassNode extends NodeBase {
9361
9470
  this.id.include();
9362
9471
  }
9363
9472
  }
9473
+ includeArgumentsWhenCalledAtPath(path, context, args) {
9474
+ var _a;
9475
+ if (path.length === 0) {
9476
+ if (this.classConstructor) {
9477
+ this.classConstructor.includeArgumentsWhenCalledAtPath(path, context, args);
9478
+ }
9479
+ else {
9480
+ (_a = this.superClass) === null || _a === void 0 ? void 0 : _a.includeArgumentsWhenCalledAtPath(path, context, args);
9481
+ }
9482
+ }
9483
+ else {
9484
+ this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
9485
+ }
9486
+ }
9364
9487
  initialise() {
9365
9488
  var _a;
9366
9489
  (_a = this.id) === null || _a === void 0 ? void 0 : _a.declare('class', this);
@@ -9372,6 +9495,18 @@ class ClassNode extends NodeBase {
9372
9495
  }
9373
9496
  this.classConstructor = null;
9374
9497
  }
9498
+ applyDeoptimizations() {
9499
+ this.deoptimized = true;
9500
+ for (const definition of this.body.body) {
9501
+ if (!(definition.static ||
9502
+ (definition instanceof MethodDefinition && definition.kind === 'constructor'))) {
9503
+ // Calls to methods are not tracked, ensure that parameter defaults are
9504
+ // included and the return value is deoptimized
9505
+ definition.deoptimizePath(UNKNOWN_PATH);
9506
+ }
9507
+ }
9508
+ this.context.requestTreeshakingPass();
9509
+ }
9375
9510
  getObjectEntity() {
9376
9511
  if (this.objectEntity !== null) {
9377
9512
  return this.objectEntity;
@@ -9388,7 +9523,7 @@ class ClassNode extends NodeBase {
9388
9523
  let key;
9389
9524
  if (definition.computed) {
9390
9525
  const keyValue = definition.key.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
9391
- if (keyValue === UnknownValue) {
9526
+ if (typeof keyValue === 'symbol') {
9392
9527
  properties.push({ key: UnknownKey, kind, property: definition });
9393
9528
  continue;
9394
9529
  }
@@ -9584,14 +9719,14 @@ class ConditionalExpression extends NodeBase {
9584
9719
  usedBranch.include(context, includeChildrenRecursively);
9585
9720
  }
9586
9721
  }
9587
- includeCallArguments(context, args) {
9722
+ includeArgumentsWhenCalledAtPath(path, context, args) {
9588
9723
  const usedBranch = this.getUsedBranch();
9589
9724
  if (usedBranch === null) {
9590
- this.consequent.includeCallArguments(context, args);
9591
- this.alternate.includeCallArguments(context, args);
9725
+ this.consequent.includeArgumentsWhenCalledAtPath(path, context, args);
9726
+ this.alternate.includeArgumentsWhenCalledAtPath(path, context, args);
9592
9727
  }
9593
9728
  else {
9594
- usedBranch.includeCallArguments(context, args);
9729
+ usedBranch.includeArgumentsWhenCalledAtPath(path, context, args);
9595
9730
  }
9596
9731
  }
9597
9732
  render(code, options, { isCalleeOfRenderedParent, preventASI, renderedParentType, renderedSurroundingElement } = BLANK) {
@@ -9628,7 +9763,7 @@ class ConditionalExpression extends NodeBase {
9628
9763
  }
9629
9764
  this.isBranchResolutionAnalysed = true;
9630
9765
  const testValue = this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
9631
- return testValue === UnknownValue
9766
+ return typeof testValue === 'symbol'
9632
9767
  ? null
9633
9768
  : (this.usedBranch = testValue ? this.consequent : this.alternate);
9634
9769
  }
@@ -9677,7 +9812,7 @@ class DoWhileStatement extends NodeBase {
9677
9812
  this.included = true;
9678
9813
  this.test.include(context, includeChildrenRecursively);
9679
9814
  const { brokenFlow } = context;
9680
- this.body.includeAsSingleStatement(context, includeChildrenRecursively);
9815
+ this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9681
9816
  context.brokenFlow = brokenFlow;
9682
9817
  }
9683
9818
  }
@@ -9805,12 +9940,13 @@ ExportDefaultDeclaration.prototype.needsBoundaries = true;
9805
9940
 
9806
9941
  class ExportNamedDeclaration extends NodeBase {
9807
9942
  bind() {
9943
+ var _a;
9808
9944
  // Do not bind specifiers
9809
- if (this.declaration !== null)
9810
- this.declaration.bind();
9945
+ (_a = this.declaration) === null || _a === void 0 ? void 0 : _a.bind();
9811
9946
  }
9812
9947
  hasEffects(context) {
9813
- return this.declaration !== null && this.declaration.hasEffects(context);
9948
+ var _a;
9949
+ return (_a = this.declaration) === null || _a === void 0 ? void 0 : _a.hasEffects(context);
9814
9950
  }
9815
9951
  initialise() {
9816
9952
  this.context.addExport(this);
@@ -9864,7 +10000,7 @@ class ForInStatement extends NodeBase {
9864
10000
  this.left.include(context, includeChildrenRecursively || true);
9865
10001
  this.right.include(context, includeChildrenRecursively);
9866
10002
  const { brokenFlow } = context;
9867
- this.body.includeAsSingleStatement(context, includeChildrenRecursively);
10003
+ this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9868
10004
  context.brokenFlow = brokenFlow;
9869
10005
  }
9870
10006
  render(code, options) {
@@ -9904,7 +10040,7 @@ class ForOfStatement extends NodeBase {
9904
10040
  this.left.include(context, includeChildrenRecursively || true);
9905
10041
  this.right.include(context, includeChildrenRecursively);
9906
10042
  const { brokenFlow } = context;
9907
- this.body.includeAsSingleStatement(context, includeChildrenRecursively);
10043
+ this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9908
10044
  context.brokenFlow = brokenFlow;
9909
10045
  }
9910
10046
  render(code, options) {
@@ -9928,9 +10064,10 @@ class ForStatement extends NodeBase {
9928
10064
  this.scope = new BlockScope(parentScope);
9929
10065
  }
9930
10066
  hasEffects(context) {
9931
- if ((this.init && this.init.hasEffects(context)) ||
9932
- (this.test && this.test.hasEffects(context)) ||
9933
- (this.update && this.update.hasEffects(context)))
10067
+ var _a, _b, _c;
10068
+ if (((_a = this.init) === null || _a === void 0 ? void 0 : _a.hasEffects(context)) ||
10069
+ ((_b = this.test) === null || _b === void 0 ? void 0 : _b.hasEffects(context)) ||
10070
+ ((_c = this.update) === null || _c === void 0 ? void 0 : _c.hasEffects(context)))
9934
10071
  return true;
9935
10072
  const { brokenFlow, ignore: { breaks, continues } } = context;
9936
10073
  context.ignore.breaks = true;
@@ -9943,24 +10080,20 @@ class ForStatement extends NodeBase {
9943
10080
  return false;
9944
10081
  }
9945
10082
  include(context, includeChildrenRecursively) {
10083
+ var _a, _b, _c;
9946
10084
  this.included = true;
9947
- if (this.init)
9948
- this.init.includeAsSingleStatement(context, includeChildrenRecursively);
9949
- if (this.test)
9950
- this.test.include(context, includeChildrenRecursively);
10085
+ (_a = this.init) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively, { asSingleStatement: true });
10086
+ (_b = this.test) === null || _b === void 0 ? void 0 : _b.include(context, includeChildrenRecursively);
9951
10087
  const { brokenFlow } = context;
9952
- if (this.update)
9953
- this.update.include(context, includeChildrenRecursively);
9954
- this.body.includeAsSingleStatement(context, includeChildrenRecursively);
10088
+ (_c = this.update) === null || _c === void 0 ? void 0 : _c.include(context, includeChildrenRecursively);
10089
+ this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9955
10090
  context.brokenFlow = brokenFlow;
9956
10091
  }
9957
10092
  render(code, options) {
9958
- if (this.init)
9959
- this.init.render(code, options, NO_SEMICOLON);
9960
- if (this.test)
9961
- this.test.render(code, options, NO_SEMICOLON);
9962
- if (this.update)
9963
- this.update.render(code, options, NO_SEMICOLON);
10093
+ var _a, _b, _c;
10094
+ (_a = this.init) === null || _a === void 0 ? void 0 : _a.render(code, options, NO_SEMICOLON);
10095
+ (_b = this.test) === null || _b === void 0 ? void 0 : _b.render(code, options, NO_SEMICOLON);
10096
+ (_c = this.update) === null || _c === void 0 ? void 0 : _c.render(code, options, NO_SEMICOLON);
9964
10097
  this.body.render(code, options);
9965
10098
  }
9966
10099
  }
@@ -9996,11 +10129,12 @@ class IfStatement extends NodeBase {
9996
10129
  this.testValue = UnknownValue;
9997
10130
  }
9998
10131
  hasEffects(context) {
10132
+ var _a;
9999
10133
  if (this.test.hasEffects(context)) {
10000
10134
  return true;
10001
10135
  }
10002
10136
  const testValue = this.getTestValue();
10003
- if (testValue === UnknownValue) {
10137
+ if (typeof testValue === 'symbol') {
10004
10138
  const { brokenFlow } = context;
10005
10139
  if (this.consequent.hasEffects(context))
10006
10140
  return true;
@@ -10014,9 +10148,7 @@ class IfStatement extends NodeBase {
10014
10148
  context.brokenFlow < consequentBrokenFlow ? context.brokenFlow : consequentBrokenFlow;
10015
10149
  return false;
10016
10150
  }
10017
- return testValue
10018
- ? this.consequent.hasEffects(context)
10019
- : this.alternate !== null && this.alternate.hasEffects(context);
10151
+ return testValue ? this.consequent.hasEffects(context) : (_a = this.alternate) === null || _a === void 0 ? void 0 : _a.hasEffects(context);
10020
10152
  }
10021
10153
  include(context, includeChildrenRecursively) {
10022
10154
  this.included = true;
@@ -10025,7 +10157,7 @@ class IfStatement extends NodeBase {
10025
10157
  }
10026
10158
  else {
10027
10159
  const testValue = this.getTestValue();
10028
- if (testValue === UnknownValue) {
10160
+ if (typeof testValue === 'symbol') {
10029
10161
  this.includeUnknownTest(context);
10030
10162
  }
10031
10163
  else {
@@ -10055,7 +10187,7 @@ class IfStatement extends NodeBase {
10055
10187
  else {
10056
10188
  code.remove(this.start, this.consequent.start);
10057
10189
  }
10058
- if (this.consequent.included && (noTreeshake || testValue === UnknownValue || testValue)) {
10190
+ if (this.consequent.included && (noTreeshake || typeof testValue === 'symbol' || testValue)) {
10059
10191
  this.consequent.render(code, options);
10060
10192
  }
10061
10193
  else {
@@ -10063,7 +10195,7 @@ class IfStatement extends NodeBase {
10063
10195
  hoistedDeclarations.push(...this.consequentScope.hoistedDeclarations);
10064
10196
  }
10065
10197
  if (this.alternate) {
10066
- if (this.alternate.included && (noTreeshake || testValue === UnknownValue || !testValue)) {
10198
+ if (this.alternate.included && (noTreeshake || typeof testValue === 'symbol' || !testValue)) {
10067
10199
  if (includesIfElse) {
10068
10200
  if (code.original.charCodeAt(this.alternate.start - 1) === 101) {
10069
10201
  code.prependLeft(this.alternate.start, ' ');
@@ -10093,34 +10225,35 @@ class IfStatement extends NodeBase {
10093
10225
  return this.testValue;
10094
10226
  }
10095
10227
  includeKnownTest(context, testValue) {
10228
+ var _a;
10096
10229
  if (this.test.shouldBeIncluded(context)) {
10097
10230
  this.test.include(context, false);
10098
10231
  }
10099
10232
  if (testValue && this.consequent.shouldBeIncluded(context)) {
10100
- this.consequent.includeAsSingleStatement(context, false);
10233
+ this.consequent.include(context, false, { asSingleStatement: true });
10101
10234
  }
10102
- if (this.alternate !== null && !testValue && this.alternate.shouldBeIncluded(context)) {
10103
- this.alternate.includeAsSingleStatement(context, false);
10235
+ if (!testValue && ((_a = this.alternate) === null || _a === void 0 ? void 0 : _a.shouldBeIncluded(context))) {
10236
+ this.alternate.include(context, false, { asSingleStatement: true });
10104
10237
  }
10105
10238
  }
10106
10239
  includeRecursively(includeChildrenRecursively, context) {
10240
+ var _a;
10107
10241
  this.test.include(context, includeChildrenRecursively);
10108
10242
  this.consequent.include(context, includeChildrenRecursively);
10109
- if (this.alternate !== null) {
10110
- this.alternate.include(context, includeChildrenRecursively);
10111
- }
10243
+ (_a = this.alternate) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
10112
10244
  }
10113
10245
  includeUnknownTest(context) {
10246
+ var _a;
10114
10247
  this.test.include(context, false);
10115
10248
  const { brokenFlow } = context;
10116
10249
  let consequentBrokenFlow = BROKEN_FLOW_NONE;
10117
10250
  if (this.consequent.shouldBeIncluded(context)) {
10118
- this.consequent.includeAsSingleStatement(context, false);
10251
+ this.consequent.include(context, false, { asSingleStatement: true });
10119
10252
  consequentBrokenFlow = context.brokenFlow;
10120
10253
  context.brokenFlow = brokenFlow;
10121
10254
  }
10122
- if (this.alternate !== null && this.alternate.shouldBeIncluded(context)) {
10123
- this.alternate.includeAsSingleStatement(context, false);
10255
+ if ((_a = this.alternate) === null || _a === void 0 ? void 0 : _a.shouldBeIncluded(context)) {
10256
+ this.alternate.include(context, false, { asSingleStatement: true });
10124
10257
  context.brokenFlow =
10125
10258
  context.brokenFlow < consequentBrokenFlow ? context.brokenFlow : consequentBrokenFlow;
10126
10259
  }
@@ -10707,7 +10840,7 @@ class LogicalExpression extends NodeBase {
10707
10840
  if (!this.isBranchResolutionAnalysed) {
10708
10841
  this.isBranchResolutionAnalysed = true;
10709
10842
  const leftValue = this.left.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
10710
- if (leftValue === UnknownValue) {
10843
+ if (typeof leftValue === 'symbol') {
10711
10844
  return null;
10712
10845
  }
10713
10846
  else {
@@ -10893,21 +11026,32 @@ class NewExpression extends NodeBase {
10893
11026
  this.deoptimized = false;
10894
11027
  }
10895
11028
  hasEffects(context) {
10896
- if (!this.deoptimized)
10897
- this.applyDeoptimizations();
10898
- for (const argument of this.arguments) {
10899
- if (argument.hasEffects(context))
10900
- return true;
11029
+ try {
11030
+ for (const argument of this.arguments) {
11031
+ if (argument.hasEffects(context))
11032
+ return true;
11033
+ }
11034
+ if (this.context.options.treeshake.annotations &&
11035
+ this.annotations)
11036
+ return false;
11037
+ return (this.callee.hasEffects(context) ||
11038
+ this.callee.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
11039
+ }
11040
+ finally {
11041
+ if (!this.deoptimized)
11042
+ this.applyDeoptimizations();
10901
11043
  }
10902
- if (this.context.options.treeshake.annotations &&
10903
- this.annotations)
10904
- return false;
10905
- return (this.callee.hasEffects(context) ||
10906
- this.callee.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
10907
11044
  }
10908
11045
  hasEffectsWhenAccessedAtPath(path) {
10909
11046
  return path.length > 0;
10910
11047
  }
11048
+ include(context, includeChildrenRecursively) {
11049
+ if (!this.deoptimized)
11050
+ this.applyDeoptimizations();
11051
+ this.included = true;
11052
+ this.callee.include(context, includeChildrenRecursively);
11053
+ this.callee.includeArgumentsWhenCalledAtPath(EMPTY_PATH, context, this.arguments);
11054
+ }
10911
11055
  initialise() {
10912
11056
  this.callOptions = {
10913
11057
  args: this.arguments,
@@ -10954,6 +11098,9 @@ class ObjectExpression extends NodeBase {
10954
11098
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
10955
11099
  return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
10956
11100
  }
11101
+ includeArgumentsWhenCalledAtPath(path, context, args) {
11102
+ this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
11103
+ }
10957
11104
  render(code, options, { renderedSurroundingElement } = BLANK) {
10958
11105
  super.render(code, options);
10959
11106
  if (renderedSurroundingElement === ExpressionStatement$1 ||
@@ -10976,7 +11123,7 @@ class ObjectExpression extends NodeBase {
10976
11123
  let key;
10977
11124
  if (property.computed) {
10978
11125
  const keyValue = property.key.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
10979
- if (keyValue === UnknownValue) {
11126
+ if (typeof keyValue === 'symbol') {
10980
11127
  properties.push({ key: UnknownKey, kind: property.kind, property });
10981
11128
  continue;
10982
11129
  }
@@ -11097,8 +11244,8 @@ class PropertyDefinition extends NodeBase {
11097
11244
  : UNKNOWN_EXPRESSION;
11098
11245
  }
11099
11246
  hasEffects(context) {
11100
- return (this.key.hasEffects(context) ||
11101
- (this.static && this.value !== null && this.value.hasEffects(context)));
11247
+ var _a;
11248
+ return this.key.hasEffects(context) || (this.static && ((_a = this.value) === null || _a === void 0 ? void 0 : _a.hasEffects(context)));
11102
11249
  }
11103
11250
  hasEffectsWhenAccessedAtPath(path, context) {
11104
11251
  return !this.value || this.value.hasEffectsWhenAccessedAtPath(path, context);
@@ -11109,21 +11256,24 @@ class PropertyDefinition extends NodeBase {
11109
11256
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
11110
11257
  return !this.value || this.value.hasEffectsWhenCalledAtPath(path, callOptions, context);
11111
11258
  }
11259
+ includeArgumentsWhenCalledAtPath(path, context, args) {
11260
+ var _a;
11261
+ (_a = this.value) === null || _a === void 0 ? void 0 : _a.includeArgumentsWhenCalledAtPath(path, context, args);
11262
+ }
11112
11263
  }
11113
11264
 
11114
11265
  class ReturnStatement extends NodeBase {
11115
11266
  hasEffects(context) {
11116
- if (!context.ignore.returnYield ||
11117
- (this.argument !== null && this.argument.hasEffects(context)))
11267
+ var _a;
11268
+ if (!context.ignore.returnYield || ((_a = this.argument) === null || _a === void 0 ? void 0 : _a.hasEffects(context)))
11118
11269
  return true;
11119
11270
  context.brokenFlow = BROKEN_FLOW_ERROR_RETURN_LABEL;
11120
11271
  return false;
11121
11272
  }
11122
11273
  include(context, includeChildrenRecursively) {
11274
+ var _a;
11123
11275
  this.included = true;
11124
- if (this.argument) {
11125
- this.argument.include(context, includeChildrenRecursively);
11126
- }
11276
+ (_a = this.argument) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
11127
11277
  context.brokenFlow = BROKEN_FLOW_ERROR_RETURN_LABEL;
11128
11278
  }
11129
11279
  initialise() {
@@ -11243,6 +11393,9 @@ class Super extends NodeBase {
11243
11393
  deoptimizePath(path) {
11244
11394
  this.variable.deoptimizePath(path);
11245
11395
  }
11396
+ deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
11397
+ this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
11398
+ }
11246
11399
  include() {
11247
11400
  if (!this.included) {
11248
11401
  this.included = true;
@@ -11253,7 +11406,8 @@ class Super extends NodeBase {
11253
11406
 
11254
11407
  class SwitchCase extends NodeBase {
11255
11408
  hasEffects(context) {
11256
- if (this.test && this.test.hasEffects(context))
11409
+ var _a;
11410
+ if ((_a = this.test) === null || _a === void 0 ? void 0 : _a.hasEffects(context))
11257
11411
  return true;
11258
11412
  for (const node of this.consequent) {
11259
11413
  if (context.brokenFlow)
@@ -11264,9 +11418,9 @@ class SwitchCase extends NodeBase {
11264
11418
  return false;
11265
11419
  }
11266
11420
  include(context, includeChildrenRecursively) {
11421
+ var _a;
11267
11422
  this.included = true;
11268
- if (this.test)
11269
- this.test.include(context, includeChildrenRecursively);
11423
+ (_a = this.test) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
11270
11424
  for (const node of this.consequent) {
11271
11425
  if (includeChildrenRecursively || node.shouldBeIncluded(context))
11272
11426
  node.include(context, includeChildrenRecursively);
@@ -11359,7 +11513,7 @@ class SwitchStatement extends NodeBase {
11359
11513
  }
11360
11514
  }
11361
11515
 
11362
- class TaggedTemplateExpression extends NodeBase {
11516
+ class TaggedTemplateExpression extends CallExpressionBase {
11363
11517
  bind() {
11364
11518
  super.bind();
11365
11519
  if (this.tag.type === Identifier$1) {
@@ -11374,13 +11528,35 @@ class TaggedTemplateExpression extends NodeBase {
11374
11528
  }
11375
11529
  }
11376
11530
  hasEffects(context) {
11377
- return (super.hasEffects(context) ||
11378
- this.tag.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
11531
+ try {
11532
+ for (const argument of this.quasi.expressions) {
11533
+ if (argument.hasEffects(context))
11534
+ return true;
11535
+ }
11536
+ return (this.tag.hasEffects(context) ||
11537
+ this.tag.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
11538
+ }
11539
+ finally {
11540
+ if (!this.deoptimized)
11541
+ this.applyDeoptimizations();
11542
+ }
11543
+ }
11544
+ include(context, includeChildrenRecursively) {
11545
+ if (!this.deoptimized)
11546
+ this.applyDeoptimizations();
11547
+ this.included = true;
11548
+ this.tag.include(context, includeChildrenRecursively);
11549
+ this.quasi.include(context, includeChildrenRecursively);
11550
+ this.tag.includeArgumentsWhenCalledAtPath(EMPTY_PATH, context, this.callOptions.args);
11551
+ const returnExpression = this.getReturnExpression();
11552
+ if (!returnExpression.included) {
11553
+ returnExpression.include(context, false);
11554
+ }
11379
11555
  }
11380
11556
  initialise() {
11381
11557
  this.callOptions = {
11382
- args: NO_ARGS,
11383
- thisParam: null,
11558
+ args: [UNKNOWN_EXPRESSION, ...this.quasi.expressions],
11559
+ thisParam: this.tag instanceof MemberExpression && !this.tag.variable ? this.tag.object : null,
11384
11560
  withNew: false
11385
11561
  };
11386
11562
  }
@@ -11388,6 +11564,25 @@ class TaggedTemplateExpression extends NodeBase {
11388
11564
  this.tag.render(code, options, { isCalleeOfRenderedParent: true });
11389
11565
  this.quasi.render(code, options);
11390
11566
  }
11567
+ applyDeoptimizations() {
11568
+ this.deoptimized = true;
11569
+ const { thisParam } = this.callOptions;
11570
+ if (thisParam) {
11571
+ this.tag.deoptimizeThisOnEventAtPath(EVENT_CALLED, EMPTY_PATH, thisParam, SHARED_RECURSION_TRACKER);
11572
+ }
11573
+ for (const argument of this.quasi.expressions) {
11574
+ // This will make sure all properties of parameters behave as "unknown"
11575
+ argument.deoptimizePath(UNKNOWN_PATH);
11576
+ }
11577
+ this.context.requestTreeshakingPass();
11578
+ }
11579
+ getReturnExpression(recursionTracker = SHARED_RECURSION_TRACKER) {
11580
+ if (this.returnExpression === null) {
11581
+ this.returnExpression = UNKNOWN_EXPRESSION;
11582
+ return (this.returnExpression = this.tag.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.callOptions, recursionTracker, this));
11583
+ }
11584
+ return this.returnExpression;
11585
+ }
11391
11586
  }
11392
11587
 
11393
11588
  class TemplateElement extends NodeBase {
@@ -11599,13 +11794,15 @@ class TryStatement extends NodeBase {
11599
11794
  this.includedLabelsAfterBlock = null;
11600
11795
  }
11601
11796
  hasEffects(context) {
11797
+ var _a;
11602
11798
  return ((this.context.options.treeshake.tryCatchDeoptimization
11603
11799
  ? this.block.body.length > 0
11604
11800
  : this.block.hasEffects(context)) ||
11605
- (this.finalizer !== null && this.finalizer.hasEffects(context)));
11801
+ ((_a = this.finalizer) === null || _a === void 0 ? void 0 : _a.hasEffects(context)) ||
11802
+ false);
11606
11803
  }
11607
11804
  include(context, includeChildrenRecursively) {
11608
- var _a;
11805
+ var _a, _b;
11609
11806
  const tryCatchDeoptimization = (_a = this.context.options.treeshake) === null || _a === void 0 ? void 0 : _a.tryCatchDeoptimization;
11610
11807
  const { brokenFlow } = context;
11611
11808
  if (!this.directlyIncluded || !tryCatchDeoptimization) {
@@ -11626,9 +11823,7 @@ class TryStatement extends NodeBase {
11626
11823
  this.handler.include(context, includeChildrenRecursively);
11627
11824
  context.brokenFlow = brokenFlow;
11628
11825
  }
11629
- if (this.finalizer !== null) {
11630
- this.finalizer.include(context, includeChildrenRecursively);
11631
- }
11826
+ (_b = this.finalizer) === null || _b === void 0 ? void 0 : _b.include(context, includeChildrenRecursively);
11632
11827
  }
11633
11828
  }
11634
11829
 
@@ -11650,7 +11845,7 @@ class UnaryExpression extends NodeBase {
11650
11845
  if (path.length > 0)
11651
11846
  return UnknownValue;
11652
11847
  const argumentValue = this.argument.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
11653
- if (argumentValue === UnknownValue)
11848
+ if (typeof argumentValue === 'symbol')
11654
11849
  return UnknownValue;
11655
11850
  return unaryOperators[this.operator](argumentValue);
11656
11851
  }
@@ -11764,18 +11959,12 @@ class VariableDeclaration extends NodeBase {
11764
11959
  hasEffectsWhenAssignedAtPath() {
11765
11960
  return false;
11766
11961
  }
11767
- include(context, includeChildrenRecursively) {
11962
+ include(context, includeChildrenRecursively, { asSingleStatement } = BLANK) {
11768
11963
  this.included = true;
11769
11964
  for (const declarator of this.declarations) {
11770
11965
  if (includeChildrenRecursively || declarator.shouldBeIncluded(context))
11771
11966
  declarator.include(context, includeChildrenRecursively);
11772
- }
11773
- }
11774
- includeAsSingleStatement(context, includeChildrenRecursively) {
11775
- this.included = true;
11776
- for (const declarator of this.declarations) {
11777
- if (includeChildrenRecursively || declarator.shouldBeIncluded(context)) {
11778
- declarator.include(context, includeChildrenRecursively);
11967
+ if (asSingleStatement) {
11779
11968
  declarator.id.include(context, includeChildrenRecursively);
11780
11969
  }
11781
11970
  }
@@ -11923,15 +12112,15 @@ class VariableDeclarator extends NodeBase {
11923
12112
  this.id.deoptimizePath(path);
11924
12113
  }
11925
12114
  hasEffects(context) {
11926
- const initEffect = this.init !== null && this.init.hasEffects(context);
12115
+ var _a;
12116
+ const initEffect = (_a = this.init) === null || _a === void 0 ? void 0 : _a.hasEffects(context);
11927
12117
  this.id.markDeclarationReached();
11928
12118
  return initEffect || this.id.hasEffects(context);
11929
12119
  }
11930
12120
  include(context, includeChildrenRecursively) {
12121
+ var _a;
11931
12122
  this.included = true;
11932
- if (this.init) {
11933
- this.init.include(context, includeChildrenRecursively);
11934
- }
12123
+ (_a = this.init) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
11935
12124
  this.id.markDeclarationReached();
11936
12125
  if (includeChildrenRecursively || this.id.shouldBeIncluded(context)) {
11937
12126
  this.id.include(context, includeChildrenRecursively);
@@ -11975,7 +12164,7 @@ class WhileStatement extends NodeBase {
11975
12164
  this.included = true;
11976
12165
  this.test.include(context, includeChildrenRecursively);
11977
12166
  const { brokenFlow } = context;
11978
- this.body.includeAsSingleStatement(context, includeChildrenRecursively);
12167
+ this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
11979
12168
  context.brokenFlow = brokenFlow;
11980
12169
  }
11981
12170
  }
@@ -11986,9 +12175,10 @@ class YieldExpression extends NodeBase {
11986
12175
  this.deoptimized = false;
11987
12176
  }
11988
12177
  hasEffects(context) {
12178
+ var _a;
11989
12179
  if (!this.deoptimized)
11990
12180
  this.applyDeoptimizations();
11991
- return (!context.ignore.returnYield || (this.argument !== null && this.argument.hasEffects(context)));
12181
+ return !context.ignore.returnYield || ((_a = this.argument) === null || _a === void 0 ? void 0 : _a.hasEffects(context));
11992
12182
  }
11993
12183
  render(code, options) {
11994
12184
  if (this.argument) {
@@ -11998,14 +12188,6 @@ class YieldExpression extends NodeBase {
11998
12188
  }
11999
12189
  }
12000
12190
  }
12001
- applyDeoptimizations() {
12002
- this.deoptimized = true;
12003
- const { argument } = this;
12004
- if (argument) {
12005
- argument.deoptimizePath(UNKNOWN_PATH);
12006
- this.context.requestTreeshakingPass();
12007
- }
12008
- }
12009
12191
  }
12010
12192
 
12011
12193
  const nodeConstructors = {
@@ -12434,8 +12616,8 @@ class Module {
12434
12616
  this.importMetas = [];
12435
12617
  this.importedFromNotTreeshaken = false;
12436
12618
  this.importers = [];
12437
- this.imports = new Set();
12438
12619
  this.includedDynamicImporters = [];
12620
+ this.includedImports = new Set();
12439
12621
  this.isExecuted = false;
12440
12622
  this.isUserDefinedEntryPoint = false;
12441
12623
  this.needsExportShim = false;
@@ -12564,7 +12746,7 @@ class Module {
12564
12746
  this.relevantDependencies = new Set();
12565
12747
  const necessaryDependencies = new Set();
12566
12748
  const alwaysCheckedDependencies = new Set();
12567
- const dependencyVariables = new Set(this.imports);
12749
+ const dependencyVariables = new Set(this.includedImports);
12568
12750
  if (this.info.isEntry ||
12569
12751
  this.includedDynamicImporters.length > 0 ||
12570
12752
  this.namespace.included ||
@@ -13142,13 +13324,13 @@ class Module {
13142
13324
  if (module instanceof ExternalModule) {
13143
13325
  const [externalVariable] = module.getVariableForExportName('*');
13144
13326
  externalVariable.include();
13145
- this.imports.add(externalVariable);
13327
+ this.includedImports.add(externalVariable);
13146
13328
  externalNamespaces.add(externalVariable);
13147
13329
  }
13148
13330
  else if (module.info.syntheticNamedExports) {
13149
13331
  const syntheticNamespace = module.getSyntheticNamespace();
13150
13332
  syntheticNamespace.include();
13151
- this.imports.add(syntheticNamespace);
13333
+ this.includedImports.add(syntheticNamespace);
13152
13334
  syntheticNamespaces.add(syntheticNamespace);
13153
13335
  }
13154
13336
  }
@@ -13185,7 +13367,7 @@ class Module {
13185
13367
  this.includeVariable(variable);
13186
13368
  const variableModule = variable.module;
13187
13369
  if (variableModule && variableModule !== this) {
13188
- this.imports.add(variable);
13370
+ this.includedImports.add(variable);
13189
13371
  }
13190
13372
  }
13191
13373
  shimMissingExport(name) {
@@ -14517,6 +14699,7 @@ class Chunk {
14517
14699
  this.implicitEntryModules = [];
14518
14700
  this.implicitlyLoadedBefore = new Set();
14519
14701
  this.imports = new Set();
14702
+ this.includedReexportsByModule = new Map();
14520
14703
  this.indentString = undefined;
14521
14704
  // This may only be updated in the constructor
14522
14705
  this.isEmpty = true;
@@ -14688,6 +14871,9 @@ class Chunk {
14688
14871
  this.exports.add(module.namespace);
14689
14872
  }
14690
14873
  }
14874
+ if (!this.outputOptions.preserveModules) {
14875
+ this.addNecessaryImportsForFacades();
14876
+ }
14691
14877
  return facades;
14692
14878
  }
14693
14879
  generateId(addons, options, existingNames, includeHash) {
@@ -15030,6 +15216,15 @@ class Chunk {
15030
15216
  }
15031
15217
  }
15032
15218
  }
15219
+ addNecessaryImportsForFacades() {
15220
+ for (const [module, variables] of this.includedReexportsByModule) {
15221
+ if (this.includedNamespaces.has(module)) {
15222
+ for (const variable of variables) {
15223
+ this.imports.add(variable);
15224
+ }
15225
+ }
15226
+ }
15227
+ }
15033
15228
  assignFacadeName({ fileName, name }, facadedModule) {
15034
15229
  if (fileName) {
15035
15230
  this.fileName = fileName;
@@ -15077,6 +15272,7 @@ class Chunk {
15077
15272
  return hash.digest('hex').substr(0, 8);
15078
15273
  }
15079
15274
  ensureReexportsAreAvailableForModule(module) {
15275
+ const includedReexports = [];
15080
15276
  const map = module.getExportNamesByVariable();
15081
15277
  for (const exportedVariable of map.keys()) {
15082
15278
  const isSynthetic = exportedVariable instanceof SyntheticNamedExportVariable;
@@ -15090,6 +15286,7 @@ class Chunk {
15090
15286
  const chunk = this.chunkByModule.get(exportingModule);
15091
15287
  if (chunk && chunk !== this) {
15092
15288
  chunk.exports.add(importedVariable);
15289
+ includedReexports.push(importedVariable);
15093
15290
  if (isSynthetic) {
15094
15291
  this.imports.add(importedVariable);
15095
15292
  }
@@ -15097,6 +15294,9 @@ class Chunk {
15097
15294
  }
15098
15295
  }
15099
15296
  }
15297
+ if (includedReexports.length) {
15298
+ this.includedReexportsByModule.set(module, includedReexports);
15299
+ }
15100
15300
  }
15101
15301
  finaliseDynamicImports(options, snippets) {
15102
15302
  const stripKnownJsExtensions = options.format === 'amd';
@@ -15452,7 +15652,7 @@ class Chunk {
15452
15652
  deconflictChunk(this.orderedModules, this.getDependenciesToBeDeconflicted(format !== 'es' && format !== 'system', format === 'amd' || format === 'umd' || format === 'iife', interop), this.imports, usedNames, format, interop, this.outputOptions.preserveModules, this.outputOptions.externalLiveBindings, this.chunkByModule, syntheticExports, this.exportNamesByVariable, this.accessedGlobalsByScope, this.includedNamespaces);
15453
15653
  }
15454
15654
  setUpChunkImportsAndExportsForModule(module) {
15455
- const moduleImports = new Set(module.imports);
15655
+ const moduleImports = new Set(module.includedImports);
15456
15656
  // when we are not preserving modules, we need to make all namespace variables available for
15457
15657
  // rendering the namespace object
15458
15658
  if (!this.outputOptions.preserveModules) {
@@ -23119,6 +23319,12 @@ function formatAction([pluginName, hookName, args]) {
23119
23319
  }
23120
23320
  return action;
23121
23321
  }
23322
+ // We do not directly listen on process to avoid max listeners warnings for
23323
+ // complicated build processes
23324
+ const beforeExitEvent = 'beforeExit';
23325
+ const beforeExitEmitter = new require$$0$2.EventEmitter();
23326
+ beforeExitEmitter.setMaxListeners(0);
23327
+ process$1.on(beforeExitEvent, () => beforeExitEmitter.emit(beforeExitEvent));
23122
23328
  async function catchUnfinishedHookActions(pluginDriver, callback) {
23123
23329
  let handleEmptyEventLoop;
23124
23330
  const emptyEventLoopPromise = new Promise((_, reject) => {
@@ -23127,10 +23333,10 @@ async function catchUnfinishedHookActions(pluginDriver, callback) {
23127
23333
  reject(new Error(`Unexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit:\n` +
23128
23334
  [...unfulfilledActions].map(formatAction).join('\n')));
23129
23335
  };
23130
- process$1.once('beforeExit', handleEmptyEventLoop);
23336
+ beforeExitEmitter.once(beforeExitEvent, handleEmptyEventLoop);
23131
23337
  });
23132
23338
  const result = await Promise.race([callback(), emptyEventLoopPromise]);
23133
- process$1.off('beforeExit', handleEmptyEventLoop);
23339
+ beforeExitEmitter.off(beforeExitEvent, handleEmptyEventLoop);
23134
23340
  return result;
23135
23341
  }
23136
23342