rollup 2.73.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.73.0
4
- Fri, 13 May 2022 15:50:44 GMT - commit 931a19940f58c745e9da9eae5585b551f356b2ed
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
 
@@ -14,7 +14,7 @@ import { createHash as createHash$1 } from 'crypto';
14
14
  import { promises } from 'fs';
15
15
  import { EventEmitter } from 'events';
16
16
 
17
- var version$1 = "2.73.0";
17
+ var version$1 = "2.74.0";
18
18
 
19
19
  var charToInteger = {};
20
20
  var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
@@ -1209,7 +1209,7 @@ class MagicString {
1209
1209
  const hasOwnProp = Object.prototype.hasOwnProperty;
1210
1210
 
1211
1211
  class Bundle$1 {
1212
- constructor(options = {}) {
1212
+ constructor(options) {
1213
1213
  this.intro = options.intro || '';
1214
1214
  this.separator = options.separator !== undefined ? options.separator : '\n';
1215
1215
  this.sources = [];
@@ -1588,6 +1588,7 @@ class DiscriminatedPathTracker {
1588
1588
  }
1589
1589
 
1590
1590
  const UnknownValue = Symbol('Unknown Value');
1591
+ const UnknownTruthyValue = Symbol('Unknown Truthy Value');
1591
1592
  class ExpressionEntity {
1592
1593
  constructor() {
1593
1594
  this.included = false;
@@ -1616,14 +1617,17 @@ class ExpressionEntity {
1616
1617
  hasEffectsWhenCalledAtPath(_path, _callOptions, _context) {
1617
1618
  return true;
1618
1619
  }
1619
- include(_context, _includeChildrenRecursively) {
1620
+ include(_context, _includeChildrenRecursively, _options) {
1620
1621
  this.included = true;
1621
1622
  }
1622
- includeCallArguments(context, args) {
1623
+ includeArgumentsWhenCalledAtPath(_path, context, args) {
1623
1624
  for (const arg of args) {
1624
1625
  arg.include(context, false);
1625
1626
  }
1626
1627
  }
1628
+ shouldBeIncluded(_context) {
1629
+ return true;
1630
+ }
1627
1631
  }
1628
1632
  const UNKNOWN_EXPRESSION = new (class UnknownExpression extends ExpressionEntity {
1629
1633
  })();
@@ -4665,9 +4669,9 @@ const stringReplace = {
4665
4669
  hasEffectsWhenCalled(callOptions, context) {
4666
4670
  const arg1 = callOptions.args[1];
4667
4671
  return (callOptions.args.length < 2 ||
4668
- (arg1.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, {
4672
+ (typeof arg1.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, {
4669
4673
  deoptimizeCache() { }
4670
- }) === UnknownValue &&
4674
+ }) === 'symbol' &&
4671
4675
  arg1.hasEffectsWhenCalledAtPath(EMPTY_PATH, {
4672
4676
  args: NO_ARGS,
4673
4677
  thisParam: null,
@@ -5222,8 +5226,7 @@ class NodeBase extends ExpressionEntity {
5222
5226
  continue;
5223
5227
  if (Array.isArray(value)) {
5224
5228
  for (const child of value) {
5225
- if (child !== null)
5226
- child.bind();
5229
+ child === null || child === void 0 ? void 0 : child.bind();
5227
5230
  }
5228
5231
  }
5229
5232
  else {
@@ -5246,7 +5249,7 @@ class NodeBase extends ExpressionEntity {
5246
5249
  continue;
5247
5250
  if (Array.isArray(value)) {
5248
5251
  for (const child of value) {
5249
- if (child !== null && child.hasEffects(context))
5252
+ if (child === null || child === void 0 ? void 0 : child.hasEffects(context))
5250
5253
  return true;
5251
5254
  }
5252
5255
  }
@@ -5255,7 +5258,7 @@ class NodeBase extends ExpressionEntity {
5255
5258
  }
5256
5259
  return false;
5257
5260
  }
5258
- include(context, includeChildrenRecursively) {
5261
+ include(context, includeChildrenRecursively, _options) {
5259
5262
  if (this.deoptimized === false)
5260
5263
  this.applyDeoptimizations();
5261
5264
  this.included = true;
@@ -5265,8 +5268,7 @@ class NodeBase extends ExpressionEntity {
5265
5268
  continue;
5266
5269
  if (Array.isArray(value)) {
5267
5270
  for (const child of value) {
5268
- if (child !== null)
5269
- child.include(context, includeChildrenRecursively);
5271
+ child === null || child === void 0 ? void 0 : child.include(context, includeChildrenRecursively);
5270
5272
  }
5271
5273
  }
5272
5274
  else {
@@ -5274,9 +5276,6 @@ class NodeBase extends ExpressionEntity {
5274
5276
  }
5275
5277
  }
5276
5278
  }
5277
- includeAsSingleStatement(context, includeChildrenRecursively) {
5278
- this.include(context, includeChildrenRecursively);
5279
- }
5280
5279
  /**
5281
5280
  * Override to perform special initialisation steps after the scope is initialised
5282
5281
  */
@@ -5323,8 +5322,7 @@ class NodeBase extends ExpressionEntity {
5323
5322
  continue;
5324
5323
  if (Array.isArray(value)) {
5325
5324
  for (const child of value) {
5326
- if (child !== null)
5327
- child.render(code, options);
5325
+ child === null || child === void 0 ? void 0 : child.render(code, options);
5328
5326
  }
5329
5327
  }
5330
5328
  else {
@@ -5335,7 +5333,28 @@ class NodeBase extends ExpressionEntity {
5335
5333
  shouldBeIncluded(context) {
5336
5334
  return this.included || (!context.brokenFlow && this.hasEffects(createHasEffectsContext()));
5337
5335
  }
5338
- applyDeoptimizations() { }
5336
+ /**
5337
+ * Just deoptimize everything by default so that when e.g. we do not track
5338
+ * something properly, it is deoptimized.
5339
+ * @protected
5340
+ */
5341
+ applyDeoptimizations() {
5342
+ this.deoptimized = true;
5343
+ for (const key of this.keys) {
5344
+ const value = this[key];
5345
+ if (value === null)
5346
+ continue;
5347
+ if (Array.isArray(value)) {
5348
+ for (const child of value) {
5349
+ child === null || child === void 0 ? void 0 : child.deoptimizePath(UNKNOWN_PATH);
5350
+ }
5351
+ }
5352
+ else {
5353
+ value.deoptimizePath(UNKNOWN_PATH);
5354
+ }
5355
+ }
5356
+ this.context.requestTreeshakingPass();
5357
+ }
5339
5358
  }
5340
5359
 
5341
5360
  class SpreadElement extends NodeBase {
@@ -5417,7 +5436,7 @@ class Method extends ExpressionEntity {
5417
5436
  }
5418
5437
  return false;
5419
5438
  }
5420
- includeCallArguments(context, args) {
5439
+ includeArgumentsWhenCalledAtPath(_path, context, args) {
5421
5440
  for (const arg of args) {
5422
5441
  arg.include(context, false);
5423
5442
  }
@@ -5621,7 +5640,7 @@ class ObjectEntity extends ExpressionEntity {
5621
5640
  }
5622
5641
  getLiteralValueAtPath(path, recursionTracker, origin) {
5623
5642
  if (path.length === 0) {
5624
- return UnknownValue;
5643
+ return UnknownTruthyValue;
5625
5644
  }
5626
5645
  const key = path[0];
5627
5646
  const expressionAtPath = this.getMemberExpressionAndTrackDeopt(key, origin);
@@ -5757,6 +5776,16 @@ class ObjectEntity extends ExpressionEntity {
5757
5776
  }
5758
5777
  return true;
5759
5778
  }
5779
+ includeArgumentsWhenCalledAtPath(path, context, args) {
5780
+ const key = path[0];
5781
+ const expressionAtPath = this.getMemberExpression(key);
5782
+ if (expressionAtPath) {
5783
+ return expressionAtPath.includeArgumentsWhenCalledAtPath(path.slice(1), context, args);
5784
+ }
5785
+ if (this.prototypeExpression) {
5786
+ return this.prototypeExpression.includeArgumentsWhenCalledAtPath(path, context, args);
5787
+ }
5788
+ }
5760
5789
  buildPropertyMaps(properties) {
5761
5790
  const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchableGetters, unmatchableSetters } = this;
5762
5791
  const unmatchablePropertiesAndSetters = [];
@@ -6026,6 +6055,7 @@ const ARRAY_PROTOTYPE = new ObjectEntity({
6026
6055
  class ArrayExpression extends NodeBase {
6027
6056
  constructor() {
6028
6057
  super(...arguments);
6058
+ this.deoptimized = false;
6029
6059
  this.objectEntity = null;
6030
6060
  }
6031
6061
  deoptimizePath(path) {
@@ -6049,6 +6079,23 @@ class ArrayExpression extends NodeBase {
6049
6079
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
6050
6080
  return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
6051
6081
  }
6082
+ includeArgumentsWhenCalledAtPath(path, context, args) {
6083
+ this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
6084
+ }
6085
+ applyDeoptimizations() {
6086
+ this.deoptimized = true;
6087
+ let hasSpread = false;
6088
+ for (let index = 0; index < this.elements.length; index++) {
6089
+ const element = this.elements[index];
6090
+ if (hasSpread || element instanceof SpreadElement) {
6091
+ if (element) {
6092
+ hasSpread = true;
6093
+ element.deoptimizePath(UNKNOWN_PATH);
6094
+ }
6095
+ }
6096
+ }
6097
+ this.context.requestTreeshakingPass();
6098
+ }
6052
6099
  getObjectEntity() {
6053
6100
  if (this.objectEntity !== null) {
6054
6101
  return this.objectEntity;
@@ -6059,7 +6106,7 @@ class ArrayExpression extends NodeBase {
6059
6106
  let hasSpread = false;
6060
6107
  for (let index = 0; index < this.elements.length; index++) {
6061
6108
  const element = this.elements[index];
6062
- if (element instanceof SpreadElement || hasSpread) {
6109
+ if (hasSpread || element instanceof SpreadElement) {
6063
6110
  if (element) {
6064
6111
  hasSpread = true;
6065
6112
  properties.unshift({ key: UnknownInteger, kind: 'init', property: element });
@@ -6079,9 +6126,7 @@ class ArrayExpression extends NodeBase {
6079
6126
  class ArrayPattern extends NodeBase {
6080
6127
  addExportedVariables(variables, exportNamesByVariable) {
6081
6128
  for (const element of this.elements) {
6082
- if (element !== null) {
6083
- element.addExportedVariables(variables, exportNamesByVariable);
6084
- }
6129
+ element === null || element === void 0 ? void 0 : element.addExportedVariables(variables, exportNamesByVariable);
6085
6130
  }
6086
6131
  }
6087
6132
  declare(kind) {
@@ -6093,29 +6138,23 @@ class ArrayPattern extends NodeBase {
6093
6138
  }
6094
6139
  return variables;
6095
6140
  }
6096
- deoptimizePath(path) {
6097
- if (path.length === 0) {
6098
- for (const element of this.elements) {
6099
- if (element !== null) {
6100
- element.deoptimizePath(path);
6101
- }
6102
- }
6141
+ // Patterns can only be deoptimized at the empty path at the moment
6142
+ deoptimizePath() {
6143
+ for (const element of this.elements) {
6144
+ element === null || element === void 0 ? void 0 : element.deoptimizePath(EMPTY_PATH);
6103
6145
  }
6104
6146
  }
6105
- hasEffectsWhenAssignedAtPath(path, context) {
6106
- if (path.length > 0)
6107
- return true;
6147
+ // Patterns are only checked at the emtpy path at the moment
6148
+ hasEffectsWhenAssignedAtPath(_path, context) {
6108
6149
  for (const element of this.elements) {
6109
- if (element !== null && element.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context))
6150
+ if (element === null || element === void 0 ? void 0 : element.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context))
6110
6151
  return true;
6111
6152
  }
6112
6153
  return false;
6113
6154
  }
6114
6155
  markDeclarationReached() {
6115
6156
  for (const element of this.elements) {
6116
- if (element !== null) {
6117
- element.markDeclarationReached();
6118
- }
6157
+ element === null || element === void 0 ? void 0 : element.markDeclarationReached();
6119
6158
  }
6120
6159
  }
6121
6160
  }
@@ -6235,7 +6274,7 @@ class LocalVariable extends Variable {
6235
6274
  }
6236
6275
  }
6237
6276
  }
6238
- includeCallArguments(context, args) {
6277
+ includeArgumentsWhenCalledAtPath(path, context, args) {
6239
6278
  if (this.isReassigned || (this.init && context.includedCallArguments.has(this.init))) {
6240
6279
  for (const arg of args) {
6241
6280
  arg.include(context, false);
@@ -6243,7 +6282,7 @@ class LocalVariable extends Variable {
6243
6282
  }
6244
6283
  else if (this.init) {
6245
6284
  context.includedCallArguments.add(this.init);
6246
- this.init.includeCallArguments(context, args);
6285
+ this.init.includeArgumentsWhenCalledAtPath(path, context, args);
6247
6286
  context.includedCallArguments.delete(this.init);
6248
6287
  }
6249
6288
  }
@@ -6491,1579 +6530,1649 @@ class ReturnValueScope extends ParameterScope {
6491
6530
  }
6492
6531
  }
6493
6532
 
6494
- //@ts-check
6495
- /** @typedef { import('estree').Node} Node */
6496
- /** @typedef {Node | {
6497
- * type: 'PropertyDefinition';
6498
- * computed: boolean;
6499
- * value: Node
6500
- * }} NodeWithPropertyDefinition */
6501
-
6502
- /**
6503
- *
6504
- * @param {NodeWithPropertyDefinition} node
6505
- * @param {NodeWithPropertyDefinition} parent
6506
- * @returns boolean
6507
- */
6508
- function is_reference (node, parent) {
6509
- if (node.type === 'MemberExpression') {
6510
- return !node.computed && is_reference(node.object, node);
6511
- }
6512
-
6513
- if (node.type === 'Identifier') {
6514
- if (!parent) return true;
6515
-
6516
- switch (parent.type) {
6517
- // disregard `bar` in `foo.bar`
6518
- case 'MemberExpression': return parent.computed || node === parent.object;
6519
-
6520
- // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
6521
- case 'MethodDefinition': return parent.computed;
6522
-
6523
- // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
6524
- case 'PropertyDefinition': return parent.computed || node === parent.value;
6525
-
6526
- // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
6527
- case 'Property': return parent.computed || node === parent.value;
6528
-
6529
- // disregard the `bar` in `export { foo as bar }` or
6530
- // the foo in `import { foo as bar }`
6531
- case 'ExportSpecifier':
6532
- case 'ImportSpecifier': return node === parent.local;
6533
-
6534
- // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
6535
- case 'LabeledStatement':
6536
- case 'BreakStatement':
6537
- case 'ContinueStatement': return false;
6538
- default: return true;
6539
- }
6540
- }
6541
-
6542
- return false;
6533
+ class AssignmentPattern extends NodeBase {
6534
+ constructor() {
6535
+ super(...arguments);
6536
+ this.deoptimized = false;
6537
+ }
6538
+ addExportedVariables(variables, exportNamesByVariable) {
6539
+ this.left.addExportedVariables(variables, exportNamesByVariable);
6540
+ }
6541
+ declare(kind, init) {
6542
+ return this.left.declare(kind, init);
6543
+ }
6544
+ deoptimizePath(path) {
6545
+ path.length === 0 && this.left.deoptimizePath(path);
6546
+ }
6547
+ hasEffectsWhenAssignedAtPath(path, context) {
6548
+ return path.length > 0 || this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
6549
+ }
6550
+ include(context, includeChildrenRecursively) {
6551
+ this.included = true;
6552
+ this.left.include(context, includeChildrenRecursively);
6553
+ this.right.include(context, includeChildrenRecursively);
6554
+ }
6555
+ markDeclarationReached() {
6556
+ this.left.markDeclarationReached();
6557
+ }
6558
+ render(code, options, { isShorthandProperty } = BLANK) {
6559
+ this.left.render(code, options, { isShorthandProperty });
6560
+ if (this.right.included) {
6561
+ this.right.render(code, options);
6562
+ }
6563
+ else {
6564
+ code.remove(this.left.end, this.end);
6565
+ }
6566
+ }
6567
+ applyDeoptimizations() {
6568
+ this.deoptimized = true;
6569
+ this.left.deoptimizePath(EMPTY_PATH);
6570
+ this.right.deoptimizePath(UNKNOWN_PATH);
6571
+ this.context.requestTreeshakingPass();
6572
+ }
6543
6573
  }
6544
6574
 
6545
- /* eslint sort-keys: "off" */
6546
- const ValueProperties = Symbol('Value Properties');
6547
- const PURE = {
6548
- hasEffectsWhenCalled() {
6549
- return false;
6575
+ function treeshakeNode(node, code, start, end) {
6576
+ code.remove(start, end);
6577
+ if (node.annotations) {
6578
+ for (const annotation of node.annotations) {
6579
+ if (annotation.start < start) {
6580
+ code.remove(annotation.start, annotation.end);
6581
+ }
6582
+ else {
6583
+ return;
6584
+ }
6585
+ }
6550
6586
  }
6551
- };
6552
- const IMPURE = {
6553
- hasEffectsWhenCalled() {
6554
- return true;
6587
+ }
6588
+ function removeAnnotations(node, code) {
6589
+ if (!node.annotations && node.parent.type === ExpressionStatement$1) {
6590
+ node = node.parent;
6555
6591
  }
6556
- };
6557
- // We use shortened variables to reduce file size here
6558
- /* OBJECT */
6559
- const O = {
6560
- __proto__: null,
6561
- [ValueProperties]: IMPURE
6562
- };
6563
- /* PURE FUNCTION */
6564
- const PF = {
6565
- __proto__: null,
6566
- [ValueProperties]: PURE
6567
- };
6568
- /* FUNCTION THAT MUTATES FIRST ARG WITHOUT TRIGGERING ACCESSORS */
6569
- const MUTATES_ARG_WITHOUT_ACCESSOR = {
6570
- __proto__: null,
6571
- [ValueProperties]: {
6572
- hasEffectsWhenCalled(callOptions, context) {
6573
- return (!callOptions.args.length ||
6574
- callOptions.args[0].hasEffectsWhenAssignedAtPath(UNKNOWN_NON_ACCESSOR_PATH, context));
6592
+ if (node.annotations) {
6593
+ for (const annotation of node.annotations) {
6594
+ code.remove(annotation.start, annotation.end);
6575
6595
  }
6576
6596
  }
6577
- };
6578
- /* CONSTRUCTOR */
6579
- const C = {
6580
- __proto__: null,
6581
- [ValueProperties]: IMPURE,
6582
- prototype: O
6583
- };
6584
- /* PURE CONSTRUCTOR */
6585
- const PC = {
6586
- __proto__: null,
6587
- [ValueProperties]: PURE,
6588
- prototype: O
6589
- };
6590
- const ARRAY_TYPE = {
6591
- __proto__: null,
6592
- [ValueProperties]: PURE,
6593
- from: PF,
6594
- of: PF,
6595
- prototype: O
6596
- };
6597
- const INTL_MEMBER = {
6598
- __proto__: null,
6599
- [ValueProperties]: PURE,
6600
- supportedLocalesOf: PC
6601
- };
6602
- const knownGlobals = {
6603
- // Placeholders for global objects to avoid shape mutations
6604
- global: O,
6605
- globalThis: O,
6606
- self: O,
6607
- window: O,
6608
- // Common globals
6609
- __proto__: null,
6610
- [ValueProperties]: IMPURE,
6611
- Array: {
6612
- __proto__: null,
6613
- [ValueProperties]: IMPURE,
6614
- from: O,
6615
- isArray: PF,
6616
- of: PF,
6617
- prototype: O
6618
- },
6619
- ArrayBuffer: {
6620
- __proto__: null,
6621
- [ValueProperties]: PURE,
6622
- isView: PF,
6623
- prototype: O
6624
- },
6625
- Atomics: O,
6626
- BigInt: C,
6627
- BigInt64Array: C,
6628
- BigUint64Array: C,
6629
- Boolean: PC,
6630
- constructor: C,
6631
- DataView: PC,
6632
- Date: {
6633
- __proto__: null,
6634
- [ValueProperties]: PURE,
6635
- now: PF,
6636
- parse: PF,
6637
- prototype: O,
6638
- UTC: PF
6639
- },
6640
- decodeURI: PF,
6641
- decodeURIComponent: PF,
6642
- encodeURI: PF,
6643
- encodeURIComponent: PF,
6644
- Error: PC,
6645
- escape: PF,
6646
- eval: O,
6647
- EvalError: PC,
6648
- Float32Array: ARRAY_TYPE,
6649
- Float64Array: ARRAY_TYPE,
6650
- Function: C,
6651
- hasOwnProperty: O,
6652
- Infinity: O,
6653
- Int16Array: ARRAY_TYPE,
6654
- Int32Array: ARRAY_TYPE,
6655
- Int8Array: ARRAY_TYPE,
6656
- isFinite: PF,
6657
- isNaN: PF,
6658
- isPrototypeOf: O,
6659
- JSON: O,
6660
- Map: PC,
6661
- Math: {
6662
- __proto__: null,
6663
- [ValueProperties]: IMPURE,
6664
- abs: PF,
6665
- acos: PF,
6666
- acosh: PF,
6667
- asin: PF,
6668
- asinh: PF,
6669
- atan: PF,
6670
- atan2: PF,
6671
- atanh: PF,
6672
- cbrt: PF,
6673
- ceil: PF,
6674
- clz32: PF,
6675
- cos: PF,
6676
- cosh: PF,
6677
- exp: PF,
6678
- expm1: PF,
6679
- floor: PF,
6680
- fround: PF,
6681
- hypot: PF,
6682
- imul: PF,
6683
- log: PF,
6684
- log10: PF,
6685
- log1p: PF,
6686
- log2: PF,
6687
- max: PF,
6688
- min: PF,
6689
- pow: PF,
6690
- random: PF,
6691
- round: PF,
6692
- sign: PF,
6693
- sin: PF,
6694
- sinh: PF,
6695
- sqrt: PF,
6696
- tan: PF,
6697
- tanh: PF,
6698
- trunc: PF
6699
- },
6700
- NaN: O,
6701
- Number: {
6702
- __proto__: null,
6703
- [ValueProperties]: PURE,
6704
- isFinite: PF,
6705
- isInteger: PF,
6706
- isNaN: PF,
6707
- isSafeInteger: PF,
6708
- parseFloat: PF,
6709
- parseInt: PF,
6710
- prototype: O
6711
- },
6712
- Object: {
6713
- __proto__: null,
6714
- [ValueProperties]: PURE,
6715
- create: PF,
6716
- // Technically those can throw in certain situations, but we ignore this as
6717
- // code that relies on this will hopefully wrap this in a try-catch, which
6718
- // deoptimizes everything anyway
6719
- defineProperty: MUTATES_ARG_WITHOUT_ACCESSOR,
6720
- defineProperties: MUTATES_ARG_WITHOUT_ACCESSOR,
6721
- getOwnPropertyDescriptor: PF,
6722
- getOwnPropertyNames: PF,
6723
- getOwnPropertySymbols: PF,
6724
- getPrototypeOf: PF,
6725
- hasOwn: PF,
6726
- is: PF,
6727
- isExtensible: PF,
6728
- isFrozen: PF,
6729
- isSealed: PF,
6730
- keys: PF,
6731
- fromEntries: PF,
6732
- entries: PF,
6733
- prototype: O
6734
- },
6735
- parseFloat: PF,
6736
- parseInt: PF,
6737
- Promise: {
6738
- __proto__: null,
6739
- [ValueProperties]: IMPURE,
6740
- all: O,
6741
- prototype: O,
6742
- race: O,
6743
- reject: O,
6744
- resolve: O
6745
- },
6746
- propertyIsEnumerable: O,
6747
- Proxy: O,
6748
- RangeError: PC,
6749
- ReferenceError: PC,
6750
- Reflect: O,
6751
- RegExp: PC,
6752
- Set: PC,
6753
- SharedArrayBuffer: C,
6754
- String: {
6755
- __proto__: null,
6756
- [ValueProperties]: PURE,
6757
- fromCharCode: PF,
6758
- fromCodePoint: PF,
6759
- prototype: O,
6760
- raw: PF
6761
- },
6762
- Symbol: {
6763
- __proto__: null,
6764
- [ValueProperties]: PURE,
6765
- for: PF,
6766
- keyFor: PF,
6767
- prototype: O
6768
- },
6769
- SyntaxError: PC,
6770
- toLocaleString: O,
6771
- toString: O,
6772
- TypeError: PC,
6773
- Uint16Array: ARRAY_TYPE,
6774
- Uint32Array: ARRAY_TYPE,
6775
- Uint8Array: ARRAY_TYPE,
6776
- Uint8ClampedArray: ARRAY_TYPE,
6777
- // Technically, this is a global, but it needs special handling
6778
- // undefined: ?,
6779
- unescape: PF,
6780
- URIError: PC,
6781
- valueOf: O,
6782
- WeakMap: PC,
6783
- WeakSet: PC,
6784
- // Additional globals shared by Node and Browser that are not strictly part of the language
6785
- clearInterval: C,
6786
- clearTimeout: C,
6787
- console: O,
6788
- Intl: {
6789
- __proto__: null,
6790
- [ValueProperties]: IMPURE,
6791
- Collator: INTL_MEMBER,
6792
- DateTimeFormat: INTL_MEMBER,
6793
- ListFormat: INTL_MEMBER,
6794
- NumberFormat: INTL_MEMBER,
6795
- PluralRules: INTL_MEMBER,
6796
- RelativeTimeFormat: INTL_MEMBER
6797
- },
6798
- setInterval: C,
6799
- setTimeout: C,
6800
- TextDecoder: C,
6801
- TextEncoder: C,
6802
- URL: C,
6803
- URLSearchParams: C,
6804
- // Browser specific globals
6805
- AbortController: C,
6806
- AbortSignal: C,
6807
- addEventListener: O,
6808
- alert: O,
6809
- AnalyserNode: C,
6810
- Animation: C,
6811
- AnimationEvent: C,
6812
- applicationCache: O,
6813
- ApplicationCache: C,
6814
- ApplicationCacheErrorEvent: C,
6815
- atob: O,
6816
- Attr: C,
6817
- Audio: C,
6818
- AudioBuffer: C,
6819
- AudioBufferSourceNode: C,
6820
- AudioContext: C,
6821
- AudioDestinationNode: C,
6822
- AudioListener: C,
6823
- AudioNode: C,
6824
- AudioParam: C,
6825
- AudioProcessingEvent: C,
6826
- AudioScheduledSourceNode: C,
6827
- AudioWorkletNode: C,
6828
- BarProp: C,
6829
- BaseAudioContext: C,
6830
- BatteryManager: C,
6831
- BeforeUnloadEvent: C,
6832
- BiquadFilterNode: C,
6833
- Blob: C,
6834
- BlobEvent: C,
6835
- blur: O,
6836
- BroadcastChannel: C,
6837
- btoa: O,
6838
- ByteLengthQueuingStrategy: C,
6839
- Cache: C,
6840
- caches: O,
6841
- CacheStorage: C,
6842
- cancelAnimationFrame: O,
6843
- cancelIdleCallback: O,
6844
- CanvasCaptureMediaStreamTrack: C,
6845
- CanvasGradient: C,
6846
- CanvasPattern: C,
6847
- CanvasRenderingContext2D: C,
6848
- ChannelMergerNode: C,
6849
- ChannelSplitterNode: C,
6850
- CharacterData: C,
6851
- clientInformation: O,
6852
- ClipboardEvent: C,
6853
- close: O,
6854
- closed: O,
6855
- CloseEvent: C,
6856
- Comment: C,
6857
- CompositionEvent: C,
6858
- confirm: O,
6859
- ConstantSourceNode: C,
6860
- ConvolverNode: C,
6861
- CountQueuingStrategy: C,
6862
- createImageBitmap: O,
6863
- Credential: C,
6864
- CredentialsContainer: C,
6865
- crypto: O,
6866
- Crypto: C,
6867
- CryptoKey: C,
6868
- CSS: C,
6869
- CSSConditionRule: C,
6870
- CSSFontFaceRule: C,
6871
- CSSGroupingRule: C,
6872
- CSSImportRule: C,
6873
- CSSKeyframeRule: C,
6874
- CSSKeyframesRule: C,
6875
- CSSMediaRule: C,
6876
- CSSNamespaceRule: C,
6877
- CSSPageRule: C,
6878
- CSSRule: C,
6879
- CSSRuleList: C,
6880
- CSSStyleDeclaration: C,
6881
- CSSStyleRule: C,
6882
- CSSStyleSheet: C,
6883
- CSSSupportsRule: C,
6884
- CustomElementRegistry: C,
6885
- customElements: O,
6886
- CustomEvent: C,
6887
- DataTransfer: C,
6888
- DataTransferItem: C,
6889
- DataTransferItemList: C,
6890
- defaultstatus: O,
6891
- defaultStatus: O,
6892
- DelayNode: C,
6893
- DeviceMotionEvent: C,
6894
- DeviceOrientationEvent: C,
6895
- devicePixelRatio: O,
6896
- dispatchEvent: O,
6897
- document: O,
6898
- Document: C,
6899
- DocumentFragment: C,
6900
- DocumentType: C,
6901
- DOMError: C,
6902
- DOMException: C,
6903
- DOMImplementation: C,
6904
- DOMMatrix: C,
6905
- DOMMatrixReadOnly: C,
6906
- DOMParser: C,
6907
- DOMPoint: C,
6908
- DOMPointReadOnly: C,
6909
- DOMQuad: C,
6910
- DOMRect: C,
6911
- DOMRectReadOnly: C,
6912
- DOMStringList: C,
6913
- DOMStringMap: C,
6914
- DOMTokenList: C,
6915
- DragEvent: C,
6916
- DynamicsCompressorNode: C,
6917
- Element: C,
6918
- ErrorEvent: C,
6919
- Event: C,
6920
- EventSource: C,
6921
- EventTarget: C,
6922
- external: O,
6923
- fetch: O,
6924
- File: C,
6925
- FileList: C,
6926
- FileReader: C,
6927
- find: O,
6928
- focus: O,
6929
- FocusEvent: C,
6930
- FontFace: C,
6931
- FontFaceSetLoadEvent: C,
6932
- FormData: C,
6933
- frames: O,
6934
- GainNode: C,
6935
- Gamepad: C,
6936
- GamepadButton: C,
6937
- GamepadEvent: C,
6938
- getComputedStyle: O,
6939
- getSelection: O,
6940
- HashChangeEvent: C,
6941
- Headers: C,
6942
- history: O,
6943
- History: C,
6944
- HTMLAllCollection: C,
6945
- HTMLAnchorElement: C,
6946
- HTMLAreaElement: C,
6947
- HTMLAudioElement: C,
6948
- HTMLBaseElement: C,
6949
- HTMLBodyElement: C,
6950
- HTMLBRElement: C,
6951
- HTMLButtonElement: C,
6952
- HTMLCanvasElement: C,
6953
- HTMLCollection: C,
6954
- HTMLContentElement: C,
6955
- HTMLDataElement: C,
6956
- HTMLDataListElement: C,
6957
- HTMLDetailsElement: C,
6958
- HTMLDialogElement: C,
6959
- HTMLDirectoryElement: C,
6960
- HTMLDivElement: C,
6961
- HTMLDListElement: C,
6962
- HTMLDocument: C,
6963
- HTMLElement: C,
6964
- HTMLEmbedElement: C,
6965
- HTMLFieldSetElement: C,
6966
- HTMLFontElement: C,
6967
- HTMLFormControlsCollection: C,
6968
- HTMLFormElement: C,
6969
- HTMLFrameElement: C,
6970
- HTMLFrameSetElement: C,
6971
- HTMLHeadElement: C,
6972
- HTMLHeadingElement: C,
6973
- HTMLHRElement: C,
6974
- HTMLHtmlElement: C,
6975
- HTMLIFrameElement: C,
6976
- HTMLImageElement: C,
6977
- HTMLInputElement: C,
6978
- HTMLLabelElement: C,
6979
- HTMLLegendElement: C,
6980
- HTMLLIElement: C,
6981
- HTMLLinkElement: C,
6982
- HTMLMapElement: C,
6983
- HTMLMarqueeElement: C,
6984
- HTMLMediaElement: C,
6985
- HTMLMenuElement: C,
6986
- HTMLMetaElement: C,
6987
- HTMLMeterElement: C,
6988
- HTMLModElement: C,
6989
- HTMLObjectElement: C,
6990
- HTMLOListElement: C,
6991
- HTMLOptGroupElement: C,
6992
- HTMLOptionElement: C,
6993
- HTMLOptionsCollection: C,
6994
- HTMLOutputElement: C,
6995
- HTMLParagraphElement: C,
6996
- HTMLParamElement: C,
6997
- HTMLPictureElement: C,
6998
- HTMLPreElement: C,
6999
- HTMLProgressElement: C,
7000
- HTMLQuoteElement: C,
7001
- HTMLScriptElement: C,
7002
- HTMLSelectElement: C,
7003
- HTMLShadowElement: C,
7004
- HTMLSlotElement: C,
7005
- HTMLSourceElement: C,
7006
- HTMLSpanElement: C,
7007
- HTMLStyleElement: C,
7008
- HTMLTableCaptionElement: C,
7009
- HTMLTableCellElement: C,
7010
- HTMLTableColElement: C,
7011
- HTMLTableElement: C,
7012
- HTMLTableRowElement: C,
7013
- HTMLTableSectionElement: C,
7014
- HTMLTemplateElement: C,
7015
- HTMLTextAreaElement: C,
7016
- HTMLTimeElement: C,
7017
- HTMLTitleElement: C,
7018
- HTMLTrackElement: C,
7019
- HTMLUListElement: C,
7020
- HTMLUnknownElement: C,
7021
- HTMLVideoElement: C,
7022
- IDBCursor: C,
7023
- IDBCursorWithValue: C,
7024
- IDBDatabase: C,
7025
- IDBFactory: C,
7026
- IDBIndex: C,
7027
- IDBKeyRange: C,
7028
- IDBObjectStore: C,
7029
- IDBOpenDBRequest: C,
7030
- IDBRequest: C,
7031
- IDBTransaction: C,
7032
- IDBVersionChangeEvent: C,
7033
- IdleDeadline: C,
7034
- IIRFilterNode: C,
7035
- Image: C,
7036
- ImageBitmap: C,
7037
- ImageBitmapRenderingContext: C,
7038
- ImageCapture: C,
7039
- ImageData: C,
7040
- indexedDB: O,
7041
- innerHeight: O,
7042
- innerWidth: O,
7043
- InputEvent: C,
7044
- IntersectionObserver: C,
7045
- IntersectionObserverEntry: C,
7046
- isSecureContext: O,
7047
- KeyboardEvent: C,
7048
- KeyframeEffect: C,
7049
- length: O,
7050
- localStorage: O,
7051
- location: O,
7052
- Location: C,
7053
- locationbar: O,
7054
- matchMedia: O,
7055
- MediaDeviceInfo: C,
7056
- MediaDevices: C,
7057
- MediaElementAudioSourceNode: C,
7058
- MediaEncryptedEvent: C,
7059
- MediaError: C,
7060
- MediaKeyMessageEvent: C,
7061
- MediaKeySession: C,
7062
- MediaKeyStatusMap: C,
7063
- MediaKeySystemAccess: C,
7064
- MediaList: C,
7065
- MediaQueryList: C,
7066
- MediaQueryListEvent: C,
7067
- MediaRecorder: C,
7068
- MediaSettingsRange: C,
7069
- MediaSource: C,
7070
- MediaStream: C,
7071
- MediaStreamAudioDestinationNode: C,
7072
- MediaStreamAudioSourceNode: C,
7073
- MediaStreamEvent: C,
7074
- MediaStreamTrack: C,
7075
- MediaStreamTrackEvent: C,
7076
- menubar: O,
7077
- MessageChannel: C,
7078
- MessageEvent: C,
7079
- MessagePort: C,
7080
- MIDIAccess: C,
7081
- MIDIConnectionEvent: C,
7082
- MIDIInput: C,
7083
- MIDIInputMap: C,
7084
- MIDIMessageEvent: C,
7085
- MIDIOutput: C,
7086
- MIDIOutputMap: C,
7087
- MIDIPort: C,
7088
- MimeType: C,
7089
- MimeTypeArray: C,
7090
- MouseEvent: C,
7091
- moveBy: O,
7092
- moveTo: O,
7093
- MutationEvent: C,
7094
- MutationObserver: C,
7095
- MutationRecord: C,
7096
- name: O,
7097
- NamedNodeMap: C,
7098
- NavigationPreloadManager: C,
7099
- navigator: O,
7100
- Navigator: C,
7101
- NetworkInformation: C,
7102
- Node: C,
7103
- NodeFilter: O,
7104
- NodeIterator: C,
7105
- NodeList: C,
7106
- Notification: C,
7107
- OfflineAudioCompletionEvent: C,
7108
- OfflineAudioContext: C,
7109
- offscreenBuffering: O,
7110
- OffscreenCanvas: C,
7111
- open: O,
7112
- openDatabase: O,
7113
- Option: C,
7114
- origin: O,
7115
- OscillatorNode: C,
7116
- outerHeight: O,
7117
- outerWidth: O,
7118
- PageTransitionEvent: C,
7119
- pageXOffset: O,
7120
- pageYOffset: O,
7121
- PannerNode: C,
7122
- parent: O,
7123
- Path2D: C,
7124
- PaymentAddress: C,
7125
- PaymentRequest: C,
7126
- PaymentRequestUpdateEvent: C,
7127
- PaymentResponse: C,
7128
- performance: O,
7129
- Performance: C,
7130
- PerformanceEntry: C,
7131
- PerformanceLongTaskTiming: C,
7132
- PerformanceMark: C,
7133
- PerformanceMeasure: C,
7134
- PerformanceNavigation: C,
7135
- PerformanceNavigationTiming: C,
7136
- PerformanceObserver: C,
7137
- PerformanceObserverEntryList: C,
7138
- PerformancePaintTiming: C,
7139
- PerformanceResourceTiming: C,
7140
- PerformanceTiming: C,
7141
- PeriodicWave: C,
7142
- Permissions: C,
7143
- PermissionStatus: C,
7144
- personalbar: O,
7145
- PhotoCapabilities: C,
7146
- Plugin: C,
7147
- PluginArray: C,
7148
- PointerEvent: C,
7149
- PopStateEvent: C,
7150
- postMessage: O,
7151
- Presentation: C,
7152
- PresentationAvailability: C,
7153
- PresentationConnection: C,
7154
- PresentationConnectionAvailableEvent: C,
7155
- PresentationConnectionCloseEvent: C,
7156
- PresentationConnectionList: C,
7157
- PresentationReceiver: C,
7158
- PresentationRequest: C,
7159
- print: O,
7160
- ProcessingInstruction: C,
7161
- ProgressEvent: C,
7162
- PromiseRejectionEvent: C,
7163
- prompt: O,
7164
- PushManager: C,
7165
- PushSubscription: C,
7166
- PushSubscriptionOptions: C,
7167
- queueMicrotask: O,
7168
- RadioNodeList: C,
7169
- Range: C,
7170
- ReadableStream: C,
7171
- RemotePlayback: C,
7172
- removeEventListener: O,
7173
- Request: C,
7174
- requestAnimationFrame: O,
7175
- requestIdleCallback: O,
7176
- resizeBy: O,
7177
- ResizeObserver: C,
7178
- ResizeObserverEntry: C,
7179
- resizeTo: O,
7180
- Response: C,
7181
- RTCCertificate: C,
7182
- RTCDataChannel: C,
7183
- RTCDataChannelEvent: C,
7184
- RTCDtlsTransport: C,
7185
- RTCIceCandidate: C,
7186
- RTCIceTransport: C,
7187
- RTCPeerConnection: C,
7188
- RTCPeerConnectionIceEvent: C,
7189
- RTCRtpReceiver: C,
7190
- RTCRtpSender: C,
7191
- RTCSctpTransport: C,
7192
- RTCSessionDescription: C,
7193
- RTCStatsReport: C,
7194
- RTCTrackEvent: C,
7195
- screen: O,
7196
- Screen: C,
7197
- screenLeft: O,
7198
- ScreenOrientation: C,
7199
- screenTop: O,
7200
- screenX: O,
7201
- screenY: O,
7202
- ScriptProcessorNode: C,
7203
- scroll: O,
7204
- scrollbars: O,
7205
- scrollBy: O,
7206
- scrollTo: O,
7207
- scrollX: O,
7208
- scrollY: O,
7209
- SecurityPolicyViolationEvent: C,
7210
- Selection: C,
7211
- ServiceWorker: C,
7212
- ServiceWorkerContainer: C,
7213
- ServiceWorkerRegistration: C,
7214
- sessionStorage: O,
7215
- ShadowRoot: C,
7216
- SharedWorker: C,
7217
- SourceBuffer: C,
7218
- SourceBufferList: C,
7219
- speechSynthesis: O,
7220
- SpeechSynthesisEvent: C,
7221
- SpeechSynthesisUtterance: C,
7222
- StaticRange: C,
7223
- status: O,
7224
- statusbar: O,
7225
- StereoPannerNode: C,
7226
- stop: O,
7227
- Storage: C,
7228
- StorageEvent: C,
7229
- StorageManager: C,
7230
- styleMedia: O,
7231
- StyleSheet: C,
7232
- StyleSheetList: C,
7233
- SubtleCrypto: C,
7234
- SVGAElement: C,
7235
- SVGAngle: C,
7236
- SVGAnimatedAngle: C,
7237
- SVGAnimatedBoolean: C,
7238
- SVGAnimatedEnumeration: C,
7239
- SVGAnimatedInteger: C,
7240
- SVGAnimatedLength: C,
7241
- SVGAnimatedLengthList: C,
7242
- SVGAnimatedNumber: C,
7243
- SVGAnimatedNumberList: C,
7244
- SVGAnimatedPreserveAspectRatio: C,
7245
- SVGAnimatedRect: C,
7246
- SVGAnimatedString: C,
7247
- SVGAnimatedTransformList: C,
7248
- SVGAnimateElement: C,
7249
- SVGAnimateMotionElement: C,
7250
- SVGAnimateTransformElement: C,
7251
- SVGAnimationElement: C,
7252
- SVGCircleElement: C,
7253
- SVGClipPathElement: C,
7254
- SVGComponentTransferFunctionElement: C,
7255
- SVGDefsElement: C,
7256
- SVGDescElement: C,
7257
- SVGDiscardElement: C,
7258
- SVGElement: C,
7259
- SVGEllipseElement: C,
7260
- SVGFEBlendElement: C,
7261
- SVGFEColorMatrixElement: C,
7262
- SVGFEComponentTransferElement: C,
7263
- SVGFECompositeElement: C,
7264
- SVGFEConvolveMatrixElement: C,
7265
- SVGFEDiffuseLightingElement: C,
7266
- SVGFEDisplacementMapElement: C,
7267
- SVGFEDistantLightElement: C,
7268
- SVGFEDropShadowElement: C,
7269
- SVGFEFloodElement: C,
7270
- SVGFEFuncAElement: C,
7271
- SVGFEFuncBElement: C,
7272
- SVGFEFuncGElement: C,
7273
- SVGFEFuncRElement: C,
7274
- SVGFEGaussianBlurElement: C,
7275
- SVGFEImageElement: C,
7276
- SVGFEMergeElement: C,
7277
- SVGFEMergeNodeElement: C,
7278
- SVGFEMorphologyElement: C,
7279
- SVGFEOffsetElement: C,
7280
- SVGFEPointLightElement: C,
7281
- SVGFESpecularLightingElement: C,
7282
- SVGFESpotLightElement: C,
7283
- SVGFETileElement: C,
7284
- SVGFETurbulenceElement: C,
7285
- SVGFilterElement: C,
7286
- SVGForeignObjectElement: C,
7287
- SVGGElement: C,
7288
- SVGGeometryElement: C,
7289
- SVGGradientElement: C,
7290
- SVGGraphicsElement: C,
7291
- SVGImageElement: C,
7292
- SVGLength: C,
7293
- SVGLengthList: C,
7294
- SVGLinearGradientElement: C,
7295
- SVGLineElement: C,
7296
- SVGMarkerElement: C,
7297
- SVGMaskElement: C,
7298
- SVGMatrix: C,
7299
- SVGMetadataElement: C,
7300
- SVGMPathElement: C,
7301
- SVGNumber: C,
7302
- SVGNumberList: C,
7303
- SVGPathElement: C,
7304
- SVGPatternElement: C,
7305
- SVGPoint: C,
7306
- SVGPointList: C,
7307
- SVGPolygonElement: C,
7308
- SVGPolylineElement: C,
7309
- SVGPreserveAspectRatio: C,
7310
- SVGRadialGradientElement: C,
7311
- SVGRect: C,
7312
- SVGRectElement: C,
7313
- SVGScriptElement: C,
7314
- SVGSetElement: C,
7315
- SVGStopElement: C,
7316
- SVGStringList: C,
7317
- SVGStyleElement: C,
7318
- SVGSVGElement: C,
7319
- SVGSwitchElement: C,
7320
- SVGSymbolElement: C,
7321
- SVGTextContentElement: C,
7322
- SVGTextElement: C,
7323
- SVGTextPathElement: C,
7324
- SVGTextPositioningElement: C,
7325
- SVGTitleElement: C,
7326
- SVGTransform: C,
7327
- SVGTransformList: C,
7328
- SVGTSpanElement: C,
7329
- SVGUnitTypes: C,
7330
- SVGUseElement: C,
7331
- SVGViewElement: C,
7332
- TaskAttributionTiming: C,
7333
- Text: C,
7334
- TextEvent: C,
7335
- TextMetrics: C,
7336
- TextTrack: C,
7337
- TextTrackCue: C,
7338
- TextTrackCueList: C,
7339
- TextTrackList: C,
7340
- TimeRanges: C,
7341
- toolbar: O,
7342
- top: O,
7343
- Touch: C,
7344
- TouchEvent: C,
7345
- TouchList: C,
7346
- TrackEvent: C,
7347
- TransitionEvent: C,
7348
- TreeWalker: C,
7349
- UIEvent: C,
7350
- ValidityState: C,
7351
- visualViewport: O,
7352
- VisualViewport: C,
7353
- VTTCue: C,
7354
- WaveShaperNode: C,
7355
- WebAssembly: O,
7356
- WebGL2RenderingContext: C,
7357
- WebGLActiveInfo: C,
7358
- WebGLBuffer: C,
7359
- WebGLContextEvent: C,
7360
- WebGLFramebuffer: C,
7361
- WebGLProgram: C,
7362
- WebGLQuery: C,
7363
- WebGLRenderbuffer: C,
7364
- WebGLRenderingContext: C,
7365
- WebGLSampler: C,
7366
- WebGLShader: C,
7367
- WebGLShaderPrecisionFormat: C,
7368
- WebGLSync: C,
7369
- WebGLTexture: C,
7370
- WebGLTransformFeedback: C,
7371
- WebGLUniformLocation: C,
7372
- WebGLVertexArrayObject: C,
7373
- WebSocket: C,
7374
- WheelEvent: C,
7375
- Window: C,
7376
- Worker: C,
7377
- WritableStream: C,
7378
- XMLDocument: C,
7379
- XMLHttpRequest: C,
7380
- XMLHttpRequestEventTarget: C,
7381
- XMLHttpRequestUpload: C,
7382
- XMLSerializer: C,
7383
- XPathEvaluator: C,
7384
- XPathExpression: C,
7385
- XPathResult: C,
7386
- XSLTProcessor: C
7387
- };
7388
- for (const global of ['window', 'global', 'self', 'globalThis']) {
7389
- knownGlobals[global] = knownGlobals;
7390
6597
  }
7391
- function getGlobalAtPath(path) {
7392
- let currentGlobal = knownGlobals;
7393
- for (const pathSegment of path) {
7394
- if (typeof pathSegment !== 'string') {
7395
- return null;
6598
+
6599
+ const NO_SEMICOLON = { isNoStatement: true };
6600
+ // This assumes there are only white-space and comments between start and the string we are looking for
6601
+ function findFirstOccurrenceOutsideComment(code, searchString, start = 0) {
6602
+ let searchPos, charCodeAfterSlash;
6603
+ searchPos = code.indexOf(searchString, start);
6604
+ while (true) {
6605
+ start = code.indexOf('/', start);
6606
+ if (start === -1 || start >= searchPos)
6607
+ return searchPos;
6608
+ charCodeAfterSlash = code.charCodeAt(++start);
6609
+ ++start;
6610
+ // With our assumption, '/' always starts a comment. Determine comment type:
6611
+ start =
6612
+ charCodeAfterSlash === 47 /*"/"*/
6613
+ ? code.indexOf('\n', start) + 1
6614
+ : code.indexOf('*/', start) + 2;
6615
+ if (start > searchPos) {
6616
+ searchPos = code.indexOf(searchString, start);
6617
+ }
6618
+ }
6619
+ }
6620
+ const NON_WHITESPACE = /\S/g;
6621
+ function findNonWhiteSpace(code, index) {
6622
+ NON_WHITESPACE.lastIndex = index;
6623
+ const result = NON_WHITESPACE.exec(code);
6624
+ return result.index;
6625
+ }
6626
+ // This assumes "code" only contains white-space and comments
6627
+ // Returns position of line-comment if applicable
6628
+ function findFirstLineBreakOutsideComment(code) {
6629
+ let lineBreakPos, charCodeAfterSlash, start = 0;
6630
+ lineBreakPos = code.indexOf('\n', start);
6631
+ while (true) {
6632
+ start = code.indexOf('/', start);
6633
+ if (start === -1 || start > lineBreakPos)
6634
+ return [lineBreakPos, lineBreakPos + 1];
6635
+ // With our assumption, '/' always starts a comment. Determine comment type:
6636
+ charCodeAfterSlash = code.charCodeAt(start + 1);
6637
+ if (charCodeAfterSlash === 47 /*"/"*/)
6638
+ return [start, lineBreakPos + 1];
6639
+ start = code.indexOf('*/', start + 3) + 2;
6640
+ if (start > lineBreakPos) {
6641
+ lineBreakPos = code.indexOf('\n', start);
6642
+ }
6643
+ }
6644
+ }
6645
+ function renderStatementList(statements, code, start, end, options) {
6646
+ let currentNode, currentNodeStart, currentNodeNeedsBoundaries, nextNodeStart;
6647
+ let nextNode = statements[0];
6648
+ let nextNodeNeedsBoundaries = !nextNode.included || nextNode.needsBoundaries;
6649
+ if (nextNodeNeedsBoundaries) {
6650
+ nextNodeStart =
6651
+ start + findFirstLineBreakOutsideComment(code.original.slice(start, nextNode.start))[1];
6652
+ }
6653
+ for (let nextIndex = 1; nextIndex <= statements.length; nextIndex++) {
6654
+ currentNode = nextNode;
6655
+ currentNodeStart = nextNodeStart;
6656
+ currentNodeNeedsBoundaries = nextNodeNeedsBoundaries;
6657
+ nextNode = statements[nextIndex];
6658
+ nextNodeNeedsBoundaries =
6659
+ nextNode === undefined ? false : !nextNode.included || nextNode.needsBoundaries;
6660
+ if (currentNodeNeedsBoundaries || nextNodeNeedsBoundaries) {
6661
+ nextNodeStart =
6662
+ currentNode.end +
6663
+ findFirstLineBreakOutsideComment(code.original.slice(currentNode.end, nextNode === undefined ? end : nextNode.start))[1];
6664
+ if (currentNode.included) {
6665
+ currentNodeNeedsBoundaries
6666
+ ? currentNode.render(code, options, {
6667
+ end: nextNodeStart,
6668
+ start: currentNodeStart
6669
+ })
6670
+ : currentNode.render(code, options);
6671
+ }
6672
+ else {
6673
+ treeshakeNode(currentNode, code, currentNodeStart, nextNodeStart);
6674
+ }
6675
+ }
6676
+ else {
6677
+ currentNode.render(code, options);
6678
+ }
6679
+ }
6680
+ }
6681
+ // This assumes that the first character is not part of the first node
6682
+ function getCommaSeparatedNodesWithBoundaries(nodes, code, start, end) {
6683
+ const splitUpNodes = [];
6684
+ let node, nextNode, nextNodeStart, contentEnd, char;
6685
+ let separator = start - 1;
6686
+ for (let nextIndex = 0; nextIndex < nodes.length; nextIndex++) {
6687
+ nextNode = nodes[nextIndex];
6688
+ if (node !== undefined) {
6689
+ separator =
6690
+ node.end +
6691
+ findFirstOccurrenceOutsideComment(code.original.slice(node.end, nextNode.start), ',');
6692
+ }
6693
+ nextNodeStart = contentEnd =
6694
+ separator +
6695
+ 1 +
6696
+ findFirstLineBreakOutsideComment(code.original.slice(separator + 1, nextNode.start))[1];
6697
+ while (((char = code.original.charCodeAt(nextNodeStart)),
6698
+ char === 32 /*" "*/ || char === 9 /*"\t"*/ || char === 10 /*"\n"*/ || char === 13) /*"\r"*/)
6699
+ nextNodeStart++;
6700
+ if (node !== undefined) {
6701
+ splitUpNodes.push({
6702
+ contentEnd,
6703
+ end: nextNodeStart,
6704
+ node,
6705
+ separator,
6706
+ start
6707
+ });
6708
+ }
6709
+ node = nextNode;
6710
+ start = nextNodeStart;
6711
+ }
6712
+ splitUpNodes.push({
6713
+ contentEnd: end,
6714
+ end,
6715
+ node: node,
6716
+ separator: null,
6717
+ start
6718
+ });
6719
+ return splitUpNodes;
6720
+ }
6721
+ // This assumes there are only white-space and comments between start and end
6722
+ function removeLineBreaks(code, start, end) {
6723
+ while (true) {
6724
+ const [removeStart, removeEnd] = findFirstLineBreakOutsideComment(code.original.slice(start, end));
6725
+ if (removeStart === -1) {
6726
+ break;
6727
+ }
6728
+ code.remove(start + removeStart, (start += removeEnd));
6729
+ }
6730
+ }
6731
+
6732
+ class BlockScope extends ChildScope {
6733
+ addDeclaration(identifier, context, init, isHoisted) {
6734
+ if (isHoisted) {
6735
+ const variable = this.parent.addDeclaration(identifier, context, init, isHoisted);
6736
+ // Necessary to make sure the init is deoptimized for conditional declarations.
6737
+ // We cannot call deoptimizePath here.
6738
+ variable.markInitializersForDeoptimization();
6739
+ return variable;
6740
+ }
6741
+ else {
6742
+ return super.addDeclaration(identifier, context, init, false);
6743
+ }
6744
+ }
6745
+ }
6746
+
6747
+ class ExpressionStatement extends NodeBase {
6748
+ initialise() {
6749
+ if (this.directive &&
6750
+ this.directive !== 'use strict' &&
6751
+ this.parent.type === Program$1) {
6752
+ this.context.warn(
6753
+ // This is necessary, because either way (deleting or not) can lead to errors.
6754
+ {
6755
+ code: 'MODULE_LEVEL_DIRECTIVE',
6756
+ message: `Module level directives cause errors when bundled, '${this.directive}' was ignored.`
6757
+ }, this.start);
6758
+ }
6759
+ }
6760
+ render(code, options) {
6761
+ super.render(code, options);
6762
+ if (this.included)
6763
+ this.insertSemicolon(code);
6764
+ }
6765
+ shouldBeIncluded(context) {
6766
+ if (this.directive && this.directive !== 'use strict')
6767
+ return this.parent.type !== Program$1;
6768
+ return super.shouldBeIncluded(context);
6769
+ }
6770
+ }
6771
+
6772
+ class BlockStatement extends NodeBase {
6773
+ constructor() {
6774
+ super(...arguments);
6775
+ this.directlyIncluded = false;
6776
+ }
6777
+ addImplicitReturnExpressionToScope() {
6778
+ const lastStatement = this.body[this.body.length - 1];
6779
+ if (!lastStatement || lastStatement.type !== ReturnStatement$1) {
6780
+ this.scope.addReturnExpression(UNKNOWN_EXPRESSION);
6781
+ }
6782
+ }
6783
+ createScope(parentScope) {
6784
+ this.scope = this.parent.preventChildBlockScope
6785
+ ? parentScope
6786
+ : new BlockScope(parentScope);
6787
+ }
6788
+ hasEffects(context) {
6789
+ if (this.deoptimizeBody)
6790
+ return true;
6791
+ for (const node of this.body) {
6792
+ if (context.brokenFlow)
6793
+ break;
6794
+ if (node.hasEffects(context))
6795
+ return true;
6796
+ }
6797
+ return false;
6798
+ }
6799
+ include(context, includeChildrenRecursively) {
6800
+ if (!(this.deoptimizeBody && this.directlyIncluded)) {
6801
+ this.included = true;
6802
+ this.directlyIncluded = true;
6803
+ if (this.deoptimizeBody)
6804
+ includeChildrenRecursively = true;
6805
+ for (const node of this.body) {
6806
+ if (includeChildrenRecursively || node.shouldBeIncluded(context))
6807
+ node.include(context, includeChildrenRecursively);
6808
+ }
6809
+ }
6810
+ }
6811
+ initialise() {
6812
+ const firstBodyStatement = this.body[0];
6813
+ this.deoptimizeBody =
6814
+ firstBodyStatement instanceof ExpressionStatement &&
6815
+ firstBodyStatement.directive === 'use asm';
6816
+ }
6817
+ render(code, options) {
6818
+ if (this.body.length) {
6819
+ renderStatementList(this.body, code, this.start + 1, this.end - 1, options);
7396
6820
  }
7397
- currentGlobal = currentGlobal[pathSegment];
7398
- if (!currentGlobal) {
7399
- return null;
6821
+ else {
6822
+ super.render(code, options);
7400
6823
  }
7401
6824
  }
7402
- return currentGlobal[ValueProperties];
7403
6825
  }
7404
6826
 
7405
- class GlobalVariable extends Variable {
6827
+ class RestElement extends NodeBase {
7406
6828
  constructor() {
7407
6829
  super(...arguments);
7408
- // Ensure we use live-bindings for globals as we do not know if they have
7409
- // been reassigned
7410
- this.isReassigned = true;
6830
+ this.deoptimized = false;
6831
+ this.declarationInit = null;
7411
6832
  }
7412
- hasEffectsWhenAccessedAtPath(path) {
7413
- if (path.length === 0) {
7414
- // Technically, "undefined" is a global variable of sorts
7415
- return this.name !== 'undefined' && getGlobalAtPath([this.name]) === null;
7416
- }
7417
- return getGlobalAtPath([this.name, ...path].slice(0, -1)) === null;
6833
+ addExportedVariables(variables, exportNamesByVariable) {
6834
+ this.argument.addExportedVariables(variables, exportNamesByVariable);
7418
6835
  }
7419
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
7420
- const globalAtPath = getGlobalAtPath([this.name, ...path]);
7421
- return globalAtPath === null || globalAtPath.hasEffectsWhenCalled(callOptions, context);
6836
+ declare(kind, init) {
6837
+ this.declarationInit = init;
6838
+ return this.argument.declare(kind, UNKNOWN_EXPRESSION);
6839
+ }
6840
+ deoptimizePath(path) {
6841
+ path.length === 0 && this.argument.deoptimizePath(EMPTY_PATH);
6842
+ }
6843
+ hasEffectsWhenAssignedAtPath(path, context) {
6844
+ return path.length > 0 || this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
6845
+ }
6846
+ markDeclarationReached() {
6847
+ this.argument.markDeclarationReached();
6848
+ }
6849
+ applyDeoptimizations() {
6850
+ this.deoptimized = true;
6851
+ if (this.declarationInit !== null) {
6852
+ this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
6853
+ this.context.requestTreeshakingPass();
6854
+ }
7422
6855
  }
7423
6856
  }
7424
6857
 
7425
- const tdzVariableKinds = {
7426
- __proto__: null,
7427
- class: true,
7428
- const: true,
7429
- let: true,
7430
- var: true
7431
- };
7432
- class Identifier extends NodeBase {
6858
+ class FunctionBase extends NodeBase {
7433
6859
  constructor() {
7434
6860
  super(...arguments);
7435
- this.variable = null;
7436
- this.deoptimized = false;
7437
- this.isTDZAccess = null;
7438
- }
7439
- addExportedVariables(variables, exportNamesByVariable) {
7440
- if (this.variable !== null && exportNamesByVariable.has(this.variable)) {
7441
- variables.push(this.variable);
7442
- }
7443
- }
7444
- bind() {
7445
- if (this.variable === null && is_reference(this, this.parent)) {
7446
- this.variable = this.scope.findVariable(this.name);
7447
- this.variable.addReference(this);
7448
- }
6861
+ // By default, parameters are included via includeArgumentsWhenCalledAtPath
6862
+ this.alwaysIncludeParameters = false;
6863
+ this.objectEntity = null;
6864
+ this.deoptimizedReturn = false;
7449
6865
  }
7450
- declare(kind, init) {
7451
- let variable;
7452
- const { treeshake } = this.context.options;
7453
- switch (kind) {
7454
- case 'var':
7455
- variable = this.scope.addDeclaration(this, this.context, init, true);
7456
- if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
7457
- // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
7458
- variable.markInitializersForDeoptimization();
7459
- }
7460
- break;
7461
- case 'function':
7462
- // in strict mode, functions are only hoisted within a scope but not across block scopes
7463
- variable = this.scope.addDeclaration(this, this.context, init, false);
7464
- break;
7465
- case 'let':
7466
- case 'const':
7467
- case 'class':
7468
- variable = this.scope.addDeclaration(this, this.context, init, false);
7469
- break;
7470
- case 'parameter':
7471
- variable = this.scope.addParameterDeclaration(this);
7472
- break;
7473
- /* istanbul ignore next */
7474
- default:
7475
- /* istanbul ignore next */
7476
- throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
7477
- }
7478
- variable.kind = kind;
7479
- return [(this.variable = variable)];
6866
+ deoptimizeCache() {
6867
+ this.alwaysIncludeParameters = true;
7480
6868
  }
7481
6869
  deoptimizePath(path) {
7482
- if (path.length === 0 && !this.scope.contains(this.name)) {
7483
- this.disallowImportReassignment();
6870
+ this.getObjectEntity().deoptimizePath(path);
6871
+ if (path.length === 1 && path[0] === UnknownKey) {
6872
+ // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
6873
+ // which means the return expression needs to be reassigned
6874
+ this.alwaysIncludeParameters = true;
6875
+ this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
7484
6876
  }
7485
- this.variable.deoptimizePath(path);
7486
6877
  }
7487
6878
  deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
7488
- this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
6879
+ if (path.length > 0) {
6880
+ this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
6881
+ }
7489
6882
  }
7490
6883
  getLiteralValueAtPath(path, recursionTracker, origin) {
7491
- return this.getVariableRespectingTDZ().getLiteralValueAtPath(path, recursionTracker, origin);
6884
+ return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
7492
6885
  }
7493
6886
  getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
7494
- return this.getVariableRespectingTDZ().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
7495
- }
7496
- hasEffects() {
7497
- if (!this.deoptimized)
7498
- this.applyDeoptimizations();
7499
- if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
7500
- return true;
6887
+ if (path.length > 0) {
6888
+ return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
7501
6889
  }
7502
- return (this.context.options.treeshake.unknownGlobalSideEffects &&
7503
- this.variable instanceof GlobalVariable &&
7504
- this.variable.hasEffectsWhenAccessedAtPath(EMPTY_PATH));
6890
+ if (this.async) {
6891
+ if (!this.deoptimizedReturn) {
6892
+ this.deoptimizedReturn = true;
6893
+ this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
6894
+ this.context.requestTreeshakingPass();
6895
+ }
6896
+ return UNKNOWN_EXPRESSION;
6897
+ }
6898
+ return this.scope.getReturnExpression();
7505
6899
  }
7506
6900
  hasEffectsWhenAccessedAtPath(path, context) {
7507
- return (this.variable !== null &&
7508
- this.getVariableRespectingTDZ().hasEffectsWhenAccessedAtPath(path, context));
6901
+ return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
7509
6902
  }
7510
6903
  hasEffectsWhenAssignedAtPath(path, context) {
7511
- return (!this.variable ||
7512
- (path.length > 0
7513
- ? this.getVariableRespectingTDZ()
7514
- : this.variable).hasEffectsWhenAssignedAtPath(path, context));
6904
+ return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
7515
6905
  }
7516
6906
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
7517
- return (!this.variable ||
7518
- this.getVariableRespectingTDZ().hasEffectsWhenCalledAtPath(path, callOptions, context));
7519
- }
7520
- include() {
7521
- if (!this.deoptimized)
7522
- this.applyDeoptimizations();
7523
- if (!this.included) {
7524
- this.included = true;
7525
- if (this.variable !== null) {
7526
- this.context.includeVariableInModule(this.variable);
7527
- }
7528
- }
7529
- }
7530
- includeCallArguments(context, args) {
7531
- this.getVariableRespectingTDZ().includeCallArguments(context, args);
7532
- }
7533
- isPossibleTDZ() {
7534
- // return cached value to avoid issues with the next tree-shaking pass
7535
- if (this.isTDZAccess !== null)
7536
- return this.isTDZAccess;
7537
- if (!(this.variable instanceof LocalVariable) ||
7538
- !this.variable.kind ||
7539
- !(this.variable.kind in tdzVariableKinds)) {
7540
- return (this.isTDZAccess = false);
7541
- }
7542
- let decl_id;
7543
- if (this.variable.declarations &&
7544
- this.variable.declarations.length === 1 &&
7545
- (decl_id = this.variable.declarations[0]) &&
7546
- this.start < decl_id.start &&
7547
- closestParentFunctionOrProgram(this) === closestParentFunctionOrProgram(decl_id)) {
7548
- // a variable accessed before its declaration
7549
- // in the same function or at top level of module
7550
- return (this.isTDZAccess = true);
7551
- }
7552
- if (!this.variable.initReached) {
7553
- // Either a const/let TDZ violation or
7554
- // var use before declaration was encountered.
7555
- return (this.isTDZAccess = true);
6907
+ if (path.length > 0) {
6908
+ return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
7556
6909
  }
7557
- return (this.isTDZAccess = false);
7558
- }
7559
- markDeclarationReached() {
7560
- this.variable.initReached = true;
7561
- }
7562
- render(code, { snippets: { getPropertyAccess } }, { renderedParentType, isCalleeOfRenderedParent, isShorthandProperty } = BLANK) {
7563
- if (this.variable) {
7564
- const name = this.variable.getName(getPropertyAccess);
7565
- if (name !== this.name) {
7566
- code.overwrite(this.start, this.end, name, {
7567
- contentOnly: true,
7568
- storeName: true
7569
- });
7570
- if (isShorthandProperty) {
7571
- code.prependRight(this.start, `${this.name}: `);
7572
- }
7573
- }
7574
- // In strict mode, any variable named "eval" must be the actual "eval" function
7575
- if (name === 'eval' &&
7576
- renderedParentType === CallExpression$1 &&
7577
- isCalleeOfRenderedParent) {
7578
- code.appendRight(this.start, '0, ');
6910
+ if (this.async) {
6911
+ const { propertyReadSideEffects } = this.context.options
6912
+ .treeshake;
6913
+ const returnExpression = this.scope.getReturnExpression();
6914
+ if (returnExpression.hasEffectsWhenCalledAtPath(['then'], { args: NO_ARGS, thisParam: null, withNew: false }, context) ||
6915
+ (propertyReadSideEffects &&
6916
+ (propertyReadSideEffects === 'always' ||
6917
+ returnExpression.hasEffectsWhenAccessedAtPath(['then'], context)))) {
6918
+ return true;
7579
6919
  }
7580
6920
  }
7581
- }
7582
- applyDeoptimizations() {
7583
- this.deoptimized = true;
7584
- if (this.variable !== null && this.variable instanceof LocalVariable) {
7585
- this.variable.consolidateInitializers();
7586
- this.context.requestTreeshakingPass();
6921
+ for (const param of this.params) {
6922
+ if (param.hasEffects(context))
6923
+ return true;
7587
6924
  }
6925
+ return false;
7588
6926
  }
7589
- disallowImportReassignment() {
7590
- return this.context.error({
7591
- code: 'ILLEGAL_REASSIGNMENT',
7592
- message: `Illegal reassignment to import '${this.name}'`
7593
- }, this.start);
7594
- }
7595
- getVariableRespectingTDZ() {
7596
- if (this.isPossibleTDZ()) {
7597
- return UNKNOWN_EXPRESSION;
6927
+ include(context, includeChildrenRecursively) {
6928
+ this.included = true;
6929
+ const { brokenFlow } = context;
6930
+ context.brokenFlow = BROKEN_FLOW_NONE;
6931
+ this.body.include(context, includeChildrenRecursively);
6932
+ context.brokenFlow = brokenFlow;
6933
+ if (includeChildrenRecursively || this.alwaysIncludeParameters) {
6934
+ for (const param of this.params) {
6935
+ param.include(context, includeChildrenRecursively);
6936
+ }
7598
6937
  }
7599
- return this.variable;
7600
6938
  }
7601
- }
7602
- function closestParentFunctionOrProgram(node) {
7603
- while (node && !/^Program|Function/.test(node.type)) {
7604
- node = node.parent;
7605
- }
7606
- // one of: ArrowFunctionExpression, FunctionDeclaration, FunctionExpression or Program
7607
- return node;
7608
- }
7609
-
7610
- function treeshakeNode(node, code, start, end) {
7611
- code.remove(start, end);
7612
- if (node.annotations) {
7613
- for (const annotation of node.annotations) {
7614
- if (annotation.start < start) {
7615
- code.remove(annotation.start, annotation.end);
7616
- }
7617
- else {
7618
- return;
6939
+ includeArgumentsWhenCalledAtPath(path, context, args) {
6940
+ var _a;
6941
+ if (path.length === 0) {
6942
+ for (let position = 0; position < this.params.length; position++) {
6943
+ const parameter = this.params[position];
6944
+ if (parameter instanceof AssignmentPattern) {
6945
+ if (parameter.left.shouldBeIncluded(context)) {
6946
+ parameter.left.include(context, false);
6947
+ }
6948
+ const argumentValue = (_a = args[position]) === null || _a === void 0 ? void 0 : _a.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
6949
+ // If argumentValue === UnknownTruthyValue, then we do not need to
6950
+ // include the default
6951
+ if ((argumentValue === undefined || argumentValue === UnknownValue) &&
6952
+ (this.parameterVariables[position].some(variable => variable.included) ||
6953
+ parameter.right.shouldBeIncluded(context))) {
6954
+ parameter.right.include(context, false);
6955
+ }
6956
+ }
6957
+ else if (parameter.shouldBeIncluded(context)) {
6958
+ parameter.include(context, false);
6959
+ }
7619
6960
  }
6961
+ this.scope.includeCallArguments(context, args);
6962
+ }
6963
+ else {
6964
+ this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
7620
6965
  }
7621
6966
  }
7622
- }
7623
- function removeAnnotations(node, code) {
7624
- if (!node.annotations && node.parent.type === ExpressionStatement$1) {
7625
- node = node.parent;
6967
+ initialise() {
6968
+ this.parameterVariables = this.params.map(param => param.declare('parameter', UNKNOWN_EXPRESSION));
6969
+ this.scope.addParameterVariables(this.parameterVariables, this.params[this.params.length - 1] instanceof RestElement);
6970
+ if (this.body instanceof BlockStatement) {
6971
+ this.body.addImplicitReturnExpressionToScope();
6972
+ }
6973
+ else {
6974
+ this.scope.addReturnExpression(this.body);
6975
+ }
7626
6976
  }
7627
- if (node.annotations) {
7628
- for (const annotation of node.annotations) {
7629
- code.remove(annotation.start, annotation.end);
6977
+ parseNode(esTreeNode) {
6978
+ if (esTreeNode.body.type === BlockStatement$1) {
6979
+ this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
7630
6980
  }
6981
+ super.parseNode(esTreeNode);
7631
6982
  }
7632
6983
  }
6984
+ FunctionBase.prototype.preventChildBlockScope = true;
7633
6985
 
7634
- const NO_SEMICOLON = { isNoStatement: true };
7635
- // This assumes there are only white-space and comments between start and the string we are looking for
7636
- function findFirstOccurrenceOutsideComment(code, searchString, start = 0) {
7637
- let searchPos, charCodeAfterSlash;
7638
- searchPos = code.indexOf(searchString, start);
7639
- while (true) {
7640
- start = code.indexOf('/', start);
7641
- if (start === -1 || start >= searchPos)
7642
- return searchPos;
7643
- charCodeAfterSlash = code.charCodeAt(++start);
7644
- ++start;
7645
- // With our assumption, '/' always starts a comment. Determine comment type:
7646
- start =
7647
- charCodeAfterSlash === 47 /*"/"*/
7648
- ? code.indexOf('\n', start) + 1
7649
- : code.indexOf('*/', start) + 2;
7650
- if (start > searchPos) {
7651
- searchPos = code.indexOf(searchString, start);
7652
- }
6986
+ class ArrowFunctionExpression extends FunctionBase {
6987
+ constructor() {
6988
+ super(...arguments);
6989
+ this.objectEntity = null;
7653
6990
  }
7654
- }
7655
- const NON_WHITESPACE = /\S/g;
7656
- function findNonWhiteSpace(code, index) {
7657
- NON_WHITESPACE.lastIndex = index;
7658
- const result = NON_WHITESPACE.exec(code);
7659
- return result.index;
7660
- }
7661
- // This assumes "code" only contains white-space and comments
7662
- // Returns position of line-comment if applicable
7663
- function findFirstLineBreakOutsideComment(code) {
7664
- let lineBreakPos, charCodeAfterSlash, start = 0;
7665
- lineBreakPos = code.indexOf('\n', start);
7666
- while (true) {
7667
- start = code.indexOf('/', start);
7668
- if (start === -1 || start > lineBreakPos)
7669
- return [lineBreakPos, lineBreakPos + 1];
7670
- // With our assumption, '/' always starts a comment. Determine comment type:
7671
- charCodeAfterSlash = code.charCodeAt(start + 1);
7672
- if (charCodeAfterSlash === 47 /*"/"*/)
7673
- return [start, lineBreakPos + 1];
7674
- start = code.indexOf('*/', start + 3) + 2;
7675
- if (start > lineBreakPos) {
7676
- lineBreakPos = code.indexOf('\n', start);
6991
+ createScope(parentScope) {
6992
+ this.scope = new ReturnValueScope(parentScope, this.context);
6993
+ }
6994
+ hasEffects() {
6995
+ return false;
6996
+ }
6997
+ hasEffectsWhenCalledAtPath(path, callOptions, context) {
6998
+ if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
6999
+ return true;
7000
+ const { ignore, brokenFlow } = context;
7001
+ context.ignore = {
7002
+ breaks: false,
7003
+ continues: false,
7004
+ labels: new Set(),
7005
+ returnYield: true
7006
+ };
7007
+ if (this.body.hasEffects(context))
7008
+ return true;
7009
+ context.ignore = ignore;
7010
+ context.brokenFlow = brokenFlow;
7011
+ return false;
7012
+ }
7013
+ getObjectEntity() {
7014
+ if (this.objectEntity !== null) {
7015
+ return this.objectEntity;
7677
7016
  }
7017
+ return (this.objectEntity = new ObjectEntity([], OBJECT_PROTOTYPE));
7678
7018
  }
7679
7019
  }
7680
- function renderStatementList(statements, code, start, end, options) {
7681
- let currentNode, currentNodeStart, currentNodeNeedsBoundaries, nextNodeStart;
7682
- let nextNode = statements[0];
7683
- let nextNodeNeedsBoundaries = !nextNode.included || nextNode.needsBoundaries;
7684
- if (nextNodeNeedsBoundaries) {
7685
- nextNodeStart =
7686
- start + findFirstLineBreakOutsideComment(code.original.slice(start, nextNode.start))[1];
7020
+
7021
+ function getSystemExportStatement(exportedVariables, { exportNamesByVariable, snippets: { _, getObject, getPropertyAccess } }, modifier = '') {
7022
+ if (exportedVariables.length === 1 &&
7023
+ exportNamesByVariable.get(exportedVariables[0]).length === 1) {
7024
+ const variable = exportedVariables[0];
7025
+ return `exports('${exportNamesByVariable.get(variable)}',${_}${variable.getName(getPropertyAccess)}${modifier})`;
7687
7026
  }
7688
- for (let nextIndex = 1; nextIndex <= statements.length; nextIndex++) {
7689
- currentNode = nextNode;
7690
- currentNodeStart = nextNodeStart;
7691
- currentNodeNeedsBoundaries = nextNodeNeedsBoundaries;
7692
- nextNode = statements[nextIndex];
7693
- nextNodeNeedsBoundaries =
7694
- nextNode === undefined ? false : !nextNode.included || nextNode.needsBoundaries;
7695
- if (currentNodeNeedsBoundaries || nextNodeNeedsBoundaries) {
7696
- nextNodeStart =
7697
- currentNode.end +
7698
- findFirstLineBreakOutsideComment(code.original.slice(currentNode.end, nextNode === undefined ? end : nextNode.start))[1];
7699
- if (currentNode.included) {
7700
- currentNodeNeedsBoundaries
7701
- ? currentNode.render(code, options, {
7702
- end: nextNodeStart,
7703
- start: currentNodeStart
7704
- })
7705
- : currentNode.render(code, options);
7706
- }
7707
- else {
7708
- treeshakeNode(currentNode, code, currentNodeStart, nextNodeStart);
7027
+ else {
7028
+ const fields = [];
7029
+ for (const variable of exportedVariables) {
7030
+ for (const exportName of exportNamesByVariable.get(variable)) {
7031
+ fields.push([exportName, variable.getName(getPropertyAccess) + modifier]);
7709
7032
  }
7710
7033
  }
7711
- else {
7712
- currentNode.render(code, options);
7713
- }
7034
+ return `exports(${getObject(fields, { lineBreakIndent: null })})`;
7714
7035
  }
7715
7036
  }
7716
- // This assumes that the first character is not part of the first node
7717
- function getCommaSeparatedNodesWithBoundaries(nodes, code, start, end) {
7718
- const splitUpNodes = [];
7719
- let node, nextNode, nextNodeStart, contentEnd, char;
7720
- let separator = start - 1;
7721
- for (let nextIndex = 0; nextIndex < nodes.length; nextIndex++) {
7722
- nextNode = nodes[nextIndex];
7723
- if (node !== undefined) {
7724
- separator =
7725
- node.end +
7726
- findFirstOccurrenceOutsideComment(code.original.slice(node.end, nextNode.start), ',');
7727
- }
7728
- nextNodeStart = contentEnd =
7729
- separator +
7730
- 1 +
7731
- findFirstLineBreakOutsideComment(code.original.slice(separator + 1, nextNode.start))[1];
7732
- while (((char = code.original.charCodeAt(nextNodeStart)),
7733
- char === 32 /*" "*/ || char === 9 /*"\t"*/ || char === 10 /*"\n"*/ || char === 13) /*"\r"*/)
7734
- nextNodeStart++;
7735
- if (node !== undefined) {
7736
- splitUpNodes.push({
7737
- contentEnd,
7738
- end: nextNodeStart,
7739
- node,
7740
- separator,
7741
- start
7742
- });
7743
- }
7744
- node = nextNode;
7745
- start = nextNodeStart;
7037
+ function renderSystemExportExpression(exportedVariable, expressionStart, expressionEnd, code, { exportNamesByVariable, snippets: { _ } }) {
7038
+ code.prependRight(expressionStart, `exports('${exportNamesByVariable.get(exportedVariable)}',${_}`);
7039
+ code.appendLeft(expressionEnd, ')');
7040
+ }
7041
+ function renderSystemExportFunction(exportedVariables, expressionStart, expressionEnd, needsParens, code, options) {
7042
+ const { _, getDirectReturnIifeLeft } = options.snippets;
7043
+ code.prependRight(expressionStart, getDirectReturnIifeLeft(['v'], `${getSystemExportStatement(exportedVariables, options)},${_}v`, { needsArrowReturnParens: true, needsWrappedFunction: needsParens }));
7044
+ code.appendLeft(expressionEnd, ')');
7045
+ }
7046
+ function renderSystemExportSequenceAfterExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options) {
7047
+ const { _, getPropertyAccess } = options.snippets;
7048
+ code.appendLeft(expressionEnd, `,${_}${getSystemExportStatement([exportedVariable], options)},${_}${exportedVariable.getName(getPropertyAccess)}`);
7049
+ if (needsParens) {
7050
+ code.prependRight(expressionStart, '(');
7051
+ code.appendLeft(expressionEnd, ')');
7746
7052
  }
7747
- splitUpNodes.push({
7748
- contentEnd: end,
7749
- end,
7750
- node: node,
7751
- separator: null,
7752
- start
7753
- });
7754
- return splitUpNodes;
7755
7053
  }
7756
- // This assumes there are only white-space and comments between start and end
7757
- function removeLineBreaks(code, start, end) {
7758
- while (true) {
7759
- const [removeStart, removeEnd] = findFirstLineBreakOutsideComment(code.original.slice(start, end));
7760
- if (removeStart === -1) {
7761
- break;
7054
+ function renderSystemExportSequenceBeforeExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options, modifier) {
7055
+ const { _ } = options.snippets;
7056
+ code.prependRight(expressionStart, `${getSystemExportStatement([exportedVariable], options, modifier)},${_}`);
7057
+ if (needsParens) {
7058
+ code.prependRight(expressionStart, '(');
7059
+ code.appendLeft(expressionEnd, ')');
7060
+ }
7061
+ }
7062
+
7063
+ //@ts-check
7064
+ /** @typedef { import('estree').Node} Node */
7065
+ /** @typedef {Node | {
7066
+ * type: 'PropertyDefinition';
7067
+ * computed: boolean;
7068
+ * value: Node
7069
+ * }} NodeWithPropertyDefinition */
7070
+
7071
+ /**
7072
+ *
7073
+ * @param {NodeWithPropertyDefinition} node
7074
+ * @param {NodeWithPropertyDefinition} parent
7075
+ * @returns boolean
7076
+ */
7077
+ function is_reference (node, parent) {
7078
+ if (node.type === 'MemberExpression') {
7079
+ return !node.computed && is_reference(node.object, node);
7080
+ }
7081
+
7082
+ if (node.type === 'Identifier') {
7083
+ if (!parent) return true;
7084
+
7085
+ switch (parent.type) {
7086
+ // disregard `bar` in `foo.bar`
7087
+ case 'MemberExpression': return parent.computed || node === parent.object;
7088
+
7089
+ // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
7090
+ case 'MethodDefinition': return parent.computed;
7091
+
7092
+ // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
7093
+ case 'PropertyDefinition': return parent.computed || node === parent.value;
7094
+
7095
+ // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
7096
+ case 'Property': return parent.computed || node === parent.value;
7097
+
7098
+ // disregard the `bar` in `export { foo as bar }` or
7099
+ // the foo in `import { foo as bar }`
7100
+ case 'ExportSpecifier':
7101
+ case 'ImportSpecifier': return node === parent.local;
7102
+
7103
+ // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
7104
+ case 'LabeledStatement':
7105
+ case 'BreakStatement':
7106
+ case 'ContinueStatement': return false;
7107
+ default: return true;
7108
+ }
7109
+ }
7110
+
7111
+ return false;
7112
+ }
7113
+
7114
+ /* eslint sort-keys: "off" */
7115
+ const ValueProperties = Symbol('Value Properties');
7116
+ const PURE = {
7117
+ hasEffectsWhenCalled() {
7118
+ return false;
7119
+ }
7120
+ };
7121
+ const IMPURE = {
7122
+ hasEffectsWhenCalled() {
7123
+ return true;
7124
+ }
7125
+ };
7126
+ // We use shortened variables to reduce file size here
7127
+ /* OBJECT */
7128
+ const O = {
7129
+ __proto__: null,
7130
+ [ValueProperties]: IMPURE
7131
+ };
7132
+ /* PURE FUNCTION */
7133
+ const PF = {
7134
+ __proto__: null,
7135
+ [ValueProperties]: PURE
7136
+ };
7137
+ /* FUNCTION THAT MUTATES FIRST ARG WITHOUT TRIGGERING ACCESSORS */
7138
+ const MUTATES_ARG_WITHOUT_ACCESSOR = {
7139
+ __proto__: null,
7140
+ [ValueProperties]: {
7141
+ hasEffectsWhenCalled(callOptions, context) {
7142
+ return (!callOptions.args.length ||
7143
+ callOptions.args[0].hasEffectsWhenAssignedAtPath(UNKNOWN_NON_ACCESSOR_PATH, context));
7762
7144
  }
7763
- code.remove(start + removeStart, (start += removeEnd));
7764
7145
  }
7146
+ };
7147
+ /* CONSTRUCTOR */
7148
+ const C = {
7149
+ __proto__: null,
7150
+ [ValueProperties]: IMPURE,
7151
+ prototype: O
7152
+ };
7153
+ /* PURE CONSTRUCTOR */
7154
+ const PC = {
7155
+ __proto__: null,
7156
+ [ValueProperties]: PURE,
7157
+ prototype: O
7158
+ };
7159
+ const ARRAY_TYPE = {
7160
+ __proto__: null,
7161
+ [ValueProperties]: PURE,
7162
+ from: PF,
7163
+ of: PF,
7164
+ prototype: O
7165
+ };
7166
+ const INTL_MEMBER = {
7167
+ __proto__: null,
7168
+ [ValueProperties]: PURE,
7169
+ supportedLocalesOf: PC
7170
+ };
7171
+ const knownGlobals = {
7172
+ // Placeholders for global objects to avoid shape mutations
7173
+ global: O,
7174
+ globalThis: O,
7175
+ self: O,
7176
+ window: O,
7177
+ // Common globals
7178
+ __proto__: null,
7179
+ [ValueProperties]: IMPURE,
7180
+ Array: {
7181
+ __proto__: null,
7182
+ [ValueProperties]: IMPURE,
7183
+ from: O,
7184
+ isArray: PF,
7185
+ of: PF,
7186
+ prototype: O
7187
+ },
7188
+ ArrayBuffer: {
7189
+ __proto__: null,
7190
+ [ValueProperties]: PURE,
7191
+ isView: PF,
7192
+ prototype: O
7193
+ },
7194
+ Atomics: O,
7195
+ BigInt: C,
7196
+ BigInt64Array: C,
7197
+ BigUint64Array: C,
7198
+ Boolean: PC,
7199
+ constructor: C,
7200
+ DataView: PC,
7201
+ Date: {
7202
+ __proto__: null,
7203
+ [ValueProperties]: PURE,
7204
+ now: PF,
7205
+ parse: PF,
7206
+ prototype: O,
7207
+ UTC: PF
7208
+ },
7209
+ decodeURI: PF,
7210
+ decodeURIComponent: PF,
7211
+ encodeURI: PF,
7212
+ encodeURIComponent: PF,
7213
+ Error: PC,
7214
+ escape: PF,
7215
+ eval: O,
7216
+ EvalError: PC,
7217
+ Float32Array: ARRAY_TYPE,
7218
+ Float64Array: ARRAY_TYPE,
7219
+ Function: C,
7220
+ hasOwnProperty: O,
7221
+ Infinity: O,
7222
+ Int16Array: ARRAY_TYPE,
7223
+ Int32Array: ARRAY_TYPE,
7224
+ Int8Array: ARRAY_TYPE,
7225
+ isFinite: PF,
7226
+ isNaN: PF,
7227
+ isPrototypeOf: O,
7228
+ JSON: O,
7229
+ Map: PC,
7230
+ Math: {
7231
+ __proto__: null,
7232
+ [ValueProperties]: IMPURE,
7233
+ abs: PF,
7234
+ acos: PF,
7235
+ acosh: PF,
7236
+ asin: PF,
7237
+ asinh: PF,
7238
+ atan: PF,
7239
+ atan2: PF,
7240
+ atanh: PF,
7241
+ cbrt: PF,
7242
+ ceil: PF,
7243
+ clz32: PF,
7244
+ cos: PF,
7245
+ cosh: PF,
7246
+ exp: PF,
7247
+ expm1: PF,
7248
+ floor: PF,
7249
+ fround: PF,
7250
+ hypot: PF,
7251
+ imul: PF,
7252
+ log: PF,
7253
+ log10: PF,
7254
+ log1p: PF,
7255
+ log2: PF,
7256
+ max: PF,
7257
+ min: PF,
7258
+ pow: PF,
7259
+ random: PF,
7260
+ round: PF,
7261
+ sign: PF,
7262
+ sin: PF,
7263
+ sinh: PF,
7264
+ sqrt: PF,
7265
+ tan: PF,
7266
+ tanh: PF,
7267
+ trunc: PF
7268
+ },
7269
+ NaN: O,
7270
+ Number: {
7271
+ __proto__: null,
7272
+ [ValueProperties]: PURE,
7273
+ isFinite: PF,
7274
+ isInteger: PF,
7275
+ isNaN: PF,
7276
+ isSafeInteger: PF,
7277
+ parseFloat: PF,
7278
+ parseInt: PF,
7279
+ prototype: O
7280
+ },
7281
+ Object: {
7282
+ __proto__: null,
7283
+ [ValueProperties]: PURE,
7284
+ create: PF,
7285
+ // Technically those can throw in certain situations, but we ignore this as
7286
+ // code that relies on this will hopefully wrap this in a try-catch, which
7287
+ // deoptimizes everything anyway
7288
+ defineProperty: MUTATES_ARG_WITHOUT_ACCESSOR,
7289
+ defineProperties: MUTATES_ARG_WITHOUT_ACCESSOR,
7290
+ getOwnPropertyDescriptor: PF,
7291
+ getOwnPropertyNames: PF,
7292
+ getOwnPropertySymbols: PF,
7293
+ getPrototypeOf: PF,
7294
+ hasOwn: PF,
7295
+ is: PF,
7296
+ isExtensible: PF,
7297
+ isFrozen: PF,
7298
+ isSealed: PF,
7299
+ keys: PF,
7300
+ fromEntries: PF,
7301
+ entries: PF,
7302
+ prototype: O
7303
+ },
7304
+ parseFloat: PF,
7305
+ parseInt: PF,
7306
+ Promise: {
7307
+ __proto__: null,
7308
+ [ValueProperties]: IMPURE,
7309
+ all: O,
7310
+ prototype: O,
7311
+ race: O,
7312
+ reject: O,
7313
+ resolve: O
7314
+ },
7315
+ propertyIsEnumerable: O,
7316
+ Proxy: O,
7317
+ RangeError: PC,
7318
+ ReferenceError: PC,
7319
+ Reflect: O,
7320
+ RegExp: PC,
7321
+ Set: PC,
7322
+ SharedArrayBuffer: C,
7323
+ String: {
7324
+ __proto__: null,
7325
+ [ValueProperties]: PURE,
7326
+ fromCharCode: PF,
7327
+ fromCodePoint: PF,
7328
+ prototype: O,
7329
+ raw: PF
7330
+ },
7331
+ Symbol: {
7332
+ __proto__: null,
7333
+ [ValueProperties]: PURE,
7334
+ for: PF,
7335
+ keyFor: PF,
7336
+ prototype: O
7337
+ },
7338
+ SyntaxError: PC,
7339
+ toLocaleString: O,
7340
+ toString: O,
7341
+ TypeError: PC,
7342
+ Uint16Array: ARRAY_TYPE,
7343
+ Uint32Array: ARRAY_TYPE,
7344
+ Uint8Array: ARRAY_TYPE,
7345
+ Uint8ClampedArray: ARRAY_TYPE,
7346
+ // Technically, this is a global, but it needs special handling
7347
+ // undefined: ?,
7348
+ unescape: PF,
7349
+ URIError: PC,
7350
+ valueOf: O,
7351
+ WeakMap: PC,
7352
+ WeakSet: PC,
7353
+ // Additional globals shared by Node and Browser that are not strictly part of the language
7354
+ clearInterval: C,
7355
+ clearTimeout: C,
7356
+ console: O,
7357
+ Intl: {
7358
+ __proto__: null,
7359
+ [ValueProperties]: IMPURE,
7360
+ Collator: INTL_MEMBER,
7361
+ DateTimeFormat: INTL_MEMBER,
7362
+ ListFormat: INTL_MEMBER,
7363
+ NumberFormat: INTL_MEMBER,
7364
+ PluralRules: INTL_MEMBER,
7365
+ RelativeTimeFormat: INTL_MEMBER
7366
+ },
7367
+ setInterval: C,
7368
+ setTimeout: C,
7369
+ TextDecoder: C,
7370
+ TextEncoder: C,
7371
+ URL: C,
7372
+ URLSearchParams: C,
7373
+ // Browser specific globals
7374
+ AbortController: C,
7375
+ AbortSignal: C,
7376
+ addEventListener: O,
7377
+ alert: O,
7378
+ AnalyserNode: C,
7379
+ Animation: C,
7380
+ AnimationEvent: C,
7381
+ applicationCache: O,
7382
+ ApplicationCache: C,
7383
+ ApplicationCacheErrorEvent: C,
7384
+ atob: O,
7385
+ Attr: C,
7386
+ Audio: C,
7387
+ AudioBuffer: C,
7388
+ AudioBufferSourceNode: C,
7389
+ AudioContext: C,
7390
+ AudioDestinationNode: C,
7391
+ AudioListener: C,
7392
+ AudioNode: C,
7393
+ AudioParam: C,
7394
+ AudioProcessingEvent: C,
7395
+ AudioScheduledSourceNode: C,
7396
+ AudioWorkletNode: C,
7397
+ BarProp: C,
7398
+ BaseAudioContext: C,
7399
+ BatteryManager: C,
7400
+ BeforeUnloadEvent: C,
7401
+ BiquadFilterNode: C,
7402
+ Blob: C,
7403
+ BlobEvent: C,
7404
+ blur: O,
7405
+ BroadcastChannel: C,
7406
+ btoa: O,
7407
+ ByteLengthQueuingStrategy: C,
7408
+ Cache: C,
7409
+ caches: O,
7410
+ CacheStorage: C,
7411
+ cancelAnimationFrame: O,
7412
+ cancelIdleCallback: O,
7413
+ CanvasCaptureMediaStreamTrack: C,
7414
+ CanvasGradient: C,
7415
+ CanvasPattern: C,
7416
+ CanvasRenderingContext2D: C,
7417
+ ChannelMergerNode: C,
7418
+ ChannelSplitterNode: C,
7419
+ CharacterData: C,
7420
+ clientInformation: O,
7421
+ ClipboardEvent: C,
7422
+ close: O,
7423
+ closed: O,
7424
+ CloseEvent: C,
7425
+ Comment: C,
7426
+ CompositionEvent: C,
7427
+ confirm: O,
7428
+ ConstantSourceNode: C,
7429
+ ConvolverNode: C,
7430
+ CountQueuingStrategy: C,
7431
+ createImageBitmap: O,
7432
+ Credential: C,
7433
+ CredentialsContainer: C,
7434
+ crypto: O,
7435
+ Crypto: C,
7436
+ CryptoKey: C,
7437
+ CSS: C,
7438
+ CSSConditionRule: C,
7439
+ CSSFontFaceRule: C,
7440
+ CSSGroupingRule: C,
7441
+ CSSImportRule: C,
7442
+ CSSKeyframeRule: C,
7443
+ CSSKeyframesRule: C,
7444
+ CSSMediaRule: C,
7445
+ CSSNamespaceRule: C,
7446
+ CSSPageRule: C,
7447
+ CSSRule: C,
7448
+ CSSRuleList: C,
7449
+ CSSStyleDeclaration: C,
7450
+ CSSStyleRule: C,
7451
+ CSSStyleSheet: C,
7452
+ CSSSupportsRule: C,
7453
+ CustomElementRegistry: C,
7454
+ customElements: O,
7455
+ CustomEvent: C,
7456
+ DataTransfer: C,
7457
+ DataTransferItem: C,
7458
+ DataTransferItemList: C,
7459
+ defaultstatus: O,
7460
+ defaultStatus: O,
7461
+ DelayNode: C,
7462
+ DeviceMotionEvent: C,
7463
+ DeviceOrientationEvent: C,
7464
+ devicePixelRatio: O,
7465
+ dispatchEvent: O,
7466
+ document: O,
7467
+ Document: C,
7468
+ DocumentFragment: C,
7469
+ DocumentType: C,
7470
+ DOMError: C,
7471
+ DOMException: C,
7472
+ DOMImplementation: C,
7473
+ DOMMatrix: C,
7474
+ DOMMatrixReadOnly: C,
7475
+ DOMParser: C,
7476
+ DOMPoint: C,
7477
+ DOMPointReadOnly: C,
7478
+ DOMQuad: C,
7479
+ DOMRect: C,
7480
+ DOMRectReadOnly: C,
7481
+ DOMStringList: C,
7482
+ DOMStringMap: C,
7483
+ DOMTokenList: C,
7484
+ DragEvent: C,
7485
+ DynamicsCompressorNode: C,
7486
+ Element: C,
7487
+ ErrorEvent: C,
7488
+ Event: C,
7489
+ EventSource: C,
7490
+ EventTarget: C,
7491
+ external: O,
7492
+ fetch: O,
7493
+ File: C,
7494
+ FileList: C,
7495
+ FileReader: C,
7496
+ find: O,
7497
+ focus: O,
7498
+ FocusEvent: C,
7499
+ FontFace: C,
7500
+ FontFaceSetLoadEvent: C,
7501
+ FormData: C,
7502
+ frames: O,
7503
+ GainNode: C,
7504
+ Gamepad: C,
7505
+ GamepadButton: C,
7506
+ GamepadEvent: C,
7507
+ getComputedStyle: O,
7508
+ getSelection: O,
7509
+ HashChangeEvent: C,
7510
+ Headers: C,
7511
+ history: O,
7512
+ History: C,
7513
+ HTMLAllCollection: C,
7514
+ HTMLAnchorElement: C,
7515
+ HTMLAreaElement: C,
7516
+ HTMLAudioElement: C,
7517
+ HTMLBaseElement: C,
7518
+ HTMLBodyElement: C,
7519
+ HTMLBRElement: C,
7520
+ HTMLButtonElement: C,
7521
+ HTMLCanvasElement: C,
7522
+ HTMLCollection: C,
7523
+ HTMLContentElement: C,
7524
+ HTMLDataElement: C,
7525
+ HTMLDataListElement: C,
7526
+ HTMLDetailsElement: C,
7527
+ HTMLDialogElement: C,
7528
+ HTMLDirectoryElement: C,
7529
+ HTMLDivElement: C,
7530
+ HTMLDListElement: C,
7531
+ HTMLDocument: C,
7532
+ HTMLElement: C,
7533
+ HTMLEmbedElement: C,
7534
+ HTMLFieldSetElement: C,
7535
+ HTMLFontElement: C,
7536
+ HTMLFormControlsCollection: C,
7537
+ HTMLFormElement: C,
7538
+ HTMLFrameElement: C,
7539
+ HTMLFrameSetElement: C,
7540
+ HTMLHeadElement: C,
7541
+ HTMLHeadingElement: C,
7542
+ HTMLHRElement: C,
7543
+ HTMLHtmlElement: C,
7544
+ HTMLIFrameElement: C,
7545
+ HTMLImageElement: C,
7546
+ HTMLInputElement: C,
7547
+ HTMLLabelElement: C,
7548
+ HTMLLegendElement: C,
7549
+ HTMLLIElement: C,
7550
+ HTMLLinkElement: C,
7551
+ HTMLMapElement: C,
7552
+ HTMLMarqueeElement: C,
7553
+ HTMLMediaElement: C,
7554
+ HTMLMenuElement: C,
7555
+ HTMLMetaElement: C,
7556
+ HTMLMeterElement: C,
7557
+ HTMLModElement: C,
7558
+ HTMLObjectElement: C,
7559
+ HTMLOListElement: C,
7560
+ HTMLOptGroupElement: C,
7561
+ HTMLOptionElement: C,
7562
+ HTMLOptionsCollection: C,
7563
+ HTMLOutputElement: C,
7564
+ HTMLParagraphElement: C,
7565
+ HTMLParamElement: C,
7566
+ HTMLPictureElement: C,
7567
+ HTMLPreElement: C,
7568
+ HTMLProgressElement: C,
7569
+ HTMLQuoteElement: C,
7570
+ HTMLScriptElement: C,
7571
+ HTMLSelectElement: C,
7572
+ HTMLShadowElement: C,
7573
+ HTMLSlotElement: C,
7574
+ HTMLSourceElement: C,
7575
+ HTMLSpanElement: C,
7576
+ HTMLStyleElement: C,
7577
+ HTMLTableCaptionElement: C,
7578
+ HTMLTableCellElement: C,
7579
+ HTMLTableColElement: C,
7580
+ HTMLTableElement: C,
7581
+ HTMLTableRowElement: C,
7582
+ HTMLTableSectionElement: C,
7583
+ HTMLTemplateElement: C,
7584
+ HTMLTextAreaElement: C,
7585
+ HTMLTimeElement: C,
7586
+ HTMLTitleElement: C,
7587
+ HTMLTrackElement: C,
7588
+ HTMLUListElement: C,
7589
+ HTMLUnknownElement: C,
7590
+ HTMLVideoElement: C,
7591
+ IDBCursor: C,
7592
+ IDBCursorWithValue: C,
7593
+ IDBDatabase: C,
7594
+ IDBFactory: C,
7595
+ IDBIndex: C,
7596
+ IDBKeyRange: C,
7597
+ IDBObjectStore: C,
7598
+ IDBOpenDBRequest: C,
7599
+ IDBRequest: C,
7600
+ IDBTransaction: C,
7601
+ IDBVersionChangeEvent: C,
7602
+ IdleDeadline: C,
7603
+ IIRFilterNode: C,
7604
+ Image: C,
7605
+ ImageBitmap: C,
7606
+ ImageBitmapRenderingContext: C,
7607
+ ImageCapture: C,
7608
+ ImageData: C,
7609
+ indexedDB: O,
7610
+ innerHeight: O,
7611
+ innerWidth: O,
7612
+ InputEvent: C,
7613
+ IntersectionObserver: C,
7614
+ IntersectionObserverEntry: C,
7615
+ isSecureContext: O,
7616
+ KeyboardEvent: C,
7617
+ KeyframeEffect: C,
7618
+ length: O,
7619
+ localStorage: O,
7620
+ location: O,
7621
+ Location: C,
7622
+ locationbar: O,
7623
+ matchMedia: O,
7624
+ MediaDeviceInfo: C,
7625
+ MediaDevices: C,
7626
+ MediaElementAudioSourceNode: C,
7627
+ MediaEncryptedEvent: C,
7628
+ MediaError: C,
7629
+ MediaKeyMessageEvent: C,
7630
+ MediaKeySession: C,
7631
+ MediaKeyStatusMap: C,
7632
+ MediaKeySystemAccess: C,
7633
+ MediaList: C,
7634
+ MediaQueryList: C,
7635
+ MediaQueryListEvent: C,
7636
+ MediaRecorder: C,
7637
+ MediaSettingsRange: C,
7638
+ MediaSource: C,
7639
+ MediaStream: C,
7640
+ MediaStreamAudioDestinationNode: C,
7641
+ MediaStreamAudioSourceNode: C,
7642
+ MediaStreamEvent: C,
7643
+ MediaStreamTrack: C,
7644
+ MediaStreamTrackEvent: C,
7645
+ menubar: O,
7646
+ MessageChannel: C,
7647
+ MessageEvent: C,
7648
+ MessagePort: C,
7649
+ MIDIAccess: C,
7650
+ MIDIConnectionEvent: C,
7651
+ MIDIInput: C,
7652
+ MIDIInputMap: C,
7653
+ MIDIMessageEvent: C,
7654
+ MIDIOutput: C,
7655
+ MIDIOutputMap: C,
7656
+ MIDIPort: C,
7657
+ MimeType: C,
7658
+ MimeTypeArray: C,
7659
+ MouseEvent: C,
7660
+ moveBy: O,
7661
+ moveTo: O,
7662
+ MutationEvent: C,
7663
+ MutationObserver: C,
7664
+ MutationRecord: C,
7665
+ name: O,
7666
+ NamedNodeMap: C,
7667
+ NavigationPreloadManager: C,
7668
+ navigator: O,
7669
+ Navigator: C,
7670
+ NetworkInformation: C,
7671
+ Node: C,
7672
+ NodeFilter: O,
7673
+ NodeIterator: C,
7674
+ NodeList: C,
7675
+ Notification: C,
7676
+ OfflineAudioCompletionEvent: C,
7677
+ OfflineAudioContext: C,
7678
+ offscreenBuffering: O,
7679
+ OffscreenCanvas: C,
7680
+ open: O,
7681
+ openDatabase: O,
7682
+ Option: C,
7683
+ origin: O,
7684
+ OscillatorNode: C,
7685
+ outerHeight: O,
7686
+ outerWidth: O,
7687
+ PageTransitionEvent: C,
7688
+ pageXOffset: O,
7689
+ pageYOffset: O,
7690
+ PannerNode: C,
7691
+ parent: O,
7692
+ Path2D: C,
7693
+ PaymentAddress: C,
7694
+ PaymentRequest: C,
7695
+ PaymentRequestUpdateEvent: C,
7696
+ PaymentResponse: C,
7697
+ performance: O,
7698
+ Performance: C,
7699
+ PerformanceEntry: C,
7700
+ PerformanceLongTaskTiming: C,
7701
+ PerformanceMark: C,
7702
+ PerformanceMeasure: C,
7703
+ PerformanceNavigation: C,
7704
+ PerformanceNavigationTiming: C,
7705
+ PerformanceObserver: C,
7706
+ PerformanceObserverEntryList: C,
7707
+ PerformancePaintTiming: C,
7708
+ PerformanceResourceTiming: C,
7709
+ PerformanceTiming: C,
7710
+ PeriodicWave: C,
7711
+ Permissions: C,
7712
+ PermissionStatus: C,
7713
+ personalbar: O,
7714
+ PhotoCapabilities: C,
7715
+ Plugin: C,
7716
+ PluginArray: C,
7717
+ PointerEvent: C,
7718
+ PopStateEvent: C,
7719
+ postMessage: O,
7720
+ Presentation: C,
7721
+ PresentationAvailability: C,
7722
+ PresentationConnection: C,
7723
+ PresentationConnectionAvailableEvent: C,
7724
+ PresentationConnectionCloseEvent: C,
7725
+ PresentationConnectionList: C,
7726
+ PresentationReceiver: C,
7727
+ PresentationRequest: C,
7728
+ print: O,
7729
+ ProcessingInstruction: C,
7730
+ ProgressEvent: C,
7731
+ PromiseRejectionEvent: C,
7732
+ prompt: O,
7733
+ PushManager: C,
7734
+ PushSubscription: C,
7735
+ PushSubscriptionOptions: C,
7736
+ queueMicrotask: O,
7737
+ RadioNodeList: C,
7738
+ Range: C,
7739
+ ReadableStream: C,
7740
+ RemotePlayback: C,
7741
+ removeEventListener: O,
7742
+ Request: C,
7743
+ requestAnimationFrame: O,
7744
+ requestIdleCallback: O,
7745
+ resizeBy: O,
7746
+ ResizeObserver: C,
7747
+ ResizeObserverEntry: C,
7748
+ resizeTo: O,
7749
+ Response: C,
7750
+ RTCCertificate: C,
7751
+ RTCDataChannel: C,
7752
+ RTCDataChannelEvent: C,
7753
+ RTCDtlsTransport: C,
7754
+ RTCIceCandidate: C,
7755
+ RTCIceTransport: C,
7756
+ RTCPeerConnection: C,
7757
+ RTCPeerConnectionIceEvent: C,
7758
+ RTCRtpReceiver: C,
7759
+ RTCRtpSender: C,
7760
+ RTCSctpTransport: C,
7761
+ RTCSessionDescription: C,
7762
+ RTCStatsReport: C,
7763
+ RTCTrackEvent: C,
7764
+ screen: O,
7765
+ Screen: C,
7766
+ screenLeft: O,
7767
+ ScreenOrientation: C,
7768
+ screenTop: O,
7769
+ screenX: O,
7770
+ screenY: O,
7771
+ ScriptProcessorNode: C,
7772
+ scroll: O,
7773
+ scrollbars: O,
7774
+ scrollBy: O,
7775
+ scrollTo: O,
7776
+ scrollX: O,
7777
+ scrollY: O,
7778
+ SecurityPolicyViolationEvent: C,
7779
+ Selection: C,
7780
+ ServiceWorker: C,
7781
+ ServiceWorkerContainer: C,
7782
+ ServiceWorkerRegistration: C,
7783
+ sessionStorage: O,
7784
+ ShadowRoot: C,
7785
+ SharedWorker: C,
7786
+ SourceBuffer: C,
7787
+ SourceBufferList: C,
7788
+ speechSynthesis: O,
7789
+ SpeechSynthesisEvent: C,
7790
+ SpeechSynthesisUtterance: C,
7791
+ StaticRange: C,
7792
+ status: O,
7793
+ statusbar: O,
7794
+ StereoPannerNode: C,
7795
+ stop: O,
7796
+ Storage: C,
7797
+ StorageEvent: C,
7798
+ StorageManager: C,
7799
+ styleMedia: O,
7800
+ StyleSheet: C,
7801
+ StyleSheetList: C,
7802
+ SubtleCrypto: C,
7803
+ SVGAElement: C,
7804
+ SVGAngle: C,
7805
+ SVGAnimatedAngle: C,
7806
+ SVGAnimatedBoolean: C,
7807
+ SVGAnimatedEnumeration: C,
7808
+ SVGAnimatedInteger: C,
7809
+ SVGAnimatedLength: C,
7810
+ SVGAnimatedLengthList: C,
7811
+ SVGAnimatedNumber: C,
7812
+ SVGAnimatedNumberList: C,
7813
+ SVGAnimatedPreserveAspectRatio: C,
7814
+ SVGAnimatedRect: C,
7815
+ SVGAnimatedString: C,
7816
+ SVGAnimatedTransformList: C,
7817
+ SVGAnimateElement: C,
7818
+ SVGAnimateMotionElement: C,
7819
+ SVGAnimateTransformElement: C,
7820
+ SVGAnimationElement: C,
7821
+ SVGCircleElement: C,
7822
+ SVGClipPathElement: C,
7823
+ SVGComponentTransferFunctionElement: C,
7824
+ SVGDefsElement: C,
7825
+ SVGDescElement: C,
7826
+ SVGDiscardElement: C,
7827
+ SVGElement: C,
7828
+ SVGEllipseElement: C,
7829
+ SVGFEBlendElement: C,
7830
+ SVGFEColorMatrixElement: C,
7831
+ SVGFEComponentTransferElement: C,
7832
+ SVGFECompositeElement: C,
7833
+ SVGFEConvolveMatrixElement: C,
7834
+ SVGFEDiffuseLightingElement: C,
7835
+ SVGFEDisplacementMapElement: C,
7836
+ SVGFEDistantLightElement: C,
7837
+ SVGFEDropShadowElement: C,
7838
+ SVGFEFloodElement: C,
7839
+ SVGFEFuncAElement: C,
7840
+ SVGFEFuncBElement: C,
7841
+ SVGFEFuncGElement: C,
7842
+ SVGFEFuncRElement: C,
7843
+ SVGFEGaussianBlurElement: C,
7844
+ SVGFEImageElement: C,
7845
+ SVGFEMergeElement: C,
7846
+ SVGFEMergeNodeElement: C,
7847
+ SVGFEMorphologyElement: C,
7848
+ SVGFEOffsetElement: C,
7849
+ SVGFEPointLightElement: C,
7850
+ SVGFESpecularLightingElement: C,
7851
+ SVGFESpotLightElement: C,
7852
+ SVGFETileElement: C,
7853
+ SVGFETurbulenceElement: C,
7854
+ SVGFilterElement: C,
7855
+ SVGForeignObjectElement: C,
7856
+ SVGGElement: C,
7857
+ SVGGeometryElement: C,
7858
+ SVGGradientElement: C,
7859
+ SVGGraphicsElement: C,
7860
+ SVGImageElement: C,
7861
+ SVGLength: C,
7862
+ SVGLengthList: C,
7863
+ SVGLinearGradientElement: C,
7864
+ SVGLineElement: C,
7865
+ SVGMarkerElement: C,
7866
+ SVGMaskElement: C,
7867
+ SVGMatrix: C,
7868
+ SVGMetadataElement: C,
7869
+ SVGMPathElement: C,
7870
+ SVGNumber: C,
7871
+ SVGNumberList: C,
7872
+ SVGPathElement: C,
7873
+ SVGPatternElement: C,
7874
+ SVGPoint: C,
7875
+ SVGPointList: C,
7876
+ SVGPolygonElement: C,
7877
+ SVGPolylineElement: C,
7878
+ SVGPreserveAspectRatio: C,
7879
+ SVGRadialGradientElement: C,
7880
+ SVGRect: C,
7881
+ SVGRectElement: C,
7882
+ SVGScriptElement: C,
7883
+ SVGSetElement: C,
7884
+ SVGStopElement: C,
7885
+ SVGStringList: C,
7886
+ SVGStyleElement: C,
7887
+ SVGSVGElement: C,
7888
+ SVGSwitchElement: C,
7889
+ SVGSymbolElement: C,
7890
+ SVGTextContentElement: C,
7891
+ SVGTextElement: C,
7892
+ SVGTextPathElement: C,
7893
+ SVGTextPositioningElement: C,
7894
+ SVGTitleElement: C,
7895
+ SVGTransform: C,
7896
+ SVGTransformList: C,
7897
+ SVGTSpanElement: C,
7898
+ SVGUnitTypes: C,
7899
+ SVGUseElement: C,
7900
+ SVGViewElement: C,
7901
+ TaskAttributionTiming: C,
7902
+ Text: C,
7903
+ TextEvent: C,
7904
+ TextMetrics: C,
7905
+ TextTrack: C,
7906
+ TextTrackCue: C,
7907
+ TextTrackCueList: C,
7908
+ TextTrackList: C,
7909
+ TimeRanges: C,
7910
+ toolbar: O,
7911
+ top: O,
7912
+ Touch: C,
7913
+ TouchEvent: C,
7914
+ TouchList: C,
7915
+ TrackEvent: C,
7916
+ TransitionEvent: C,
7917
+ TreeWalker: C,
7918
+ UIEvent: C,
7919
+ ValidityState: C,
7920
+ visualViewport: O,
7921
+ VisualViewport: C,
7922
+ VTTCue: C,
7923
+ WaveShaperNode: C,
7924
+ WebAssembly: O,
7925
+ WebGL2RenderingContext: C,
7926
+ WebGLActiveInfo: C,
7927
+ WebGLBuffer: C,
7928
+ WebGLContextEvent: C,
7929
+ WebGLFramebuffer: C,
7930
+ WebGLProgram: C,
7931
+ WebGLQuery: C,
7932
+ WebGLRenderbuffer: C,
7933
+ WebGLRenderingContext: C,
7934
+ WebGLSampler: C,
7935
+ WebGLShader: C,
7936
+ WebGLShaderPrecisionFormat: C,
7937
+ WebGLSync: C,
7938
+ WebGLTexture: C,
7939
+ WebGLTransformFeedback: C,
7940
+ WebGLUniformLocation: C,
7941
+ WebGLVertexArrayObject: C,
7942
+ WebSocket: C,
7943
+ WheelEvent: C,
7944
+ Window: C,
7945
+ Worker: C,
7946
+ WritableStream: C,
7947
+ XMLDocument: C,
7948
+ XMLHttpRequest: C,
7949
+ XMLHttpRequestEventTarget: C,
7950
+ XMLHttpRequestUpload: C,
7951
+ XMLSerializer: C,
7952
+ XPathEvaluator: C,
7953
+ XPathExpression: C,
7954
+ XPathResult: C,
7955
+ XSLTProcessor: C
7956
+ };
7957
+ for (const global of ['window', 'global', 'self', 'globalThis']) {
7958
+ knownGlobals[global] = knownGlobals;
7765
7959
  }
7766
-
7767
- class BlockScope extends ChildScope {
7768
- addDeclaration(identifier, context, init, isHoisted) {
7769
- if (isHoisted) {
7770
- const variable = this.parent.addDeclaration(identifier, context, init, isHoisted);
7771
- // Necessary to make sure the init is deoptimized for conditional declarations.
7772
- // We cannot call deoptimizePath here.
7773
- variable.markInitializersForDeoptimization();
7774
- return variable;
7775
- }
7776
- else {
7777
- return super.addDeclaration(identifier, context, init, false);
7960
+ function getGlobalAtPath(path) {
7961
+ let currentGlobal = knownGlobals;
7962
+ for (const pathSegment of path) {
7963
+ if (typeof pathSegment !== 'string') {
7964
+ return null;
7778
7965
  }
7779
- }
7780
- }
7781
-
7782
- class ExpressionStatement extends NodeBase {
7783
- initialise() {
7784
- if (this.directive &&
7785
- this.directive !== 'use strict' &&
7786
- this.parent.type === Program$1) {
7787
- this.context.warn(
7788
- // This is necessary, because either way (deleting or not) can lead to errors.
7789
- {
7790
- code: 'MODULE_LEVEL_DIRECTIVE',
7791
- message: `Module level directives cause errors when bundled, '${this.directive}' was ignored.`
7792
- }, this.start);
7966
+ currentGlobal = currentGlobal[pathSegment];
7967
+ if (!currentGlobal) {
7968
+ return null;
7793
7969
  }
7794
7970
  }
7795
- render(code, options) {
7796
- super.render(code, options);
7797
- if (this.included)
7798
- this.insertSemicolon(code);
7799
- }
7800
- shouldBeIncluded(context) {
7801
- if (this.directive && this.directive !== 'use strict')
7802
- return this.parent.type !== Program$1;
7803
- return super.shouldBeIncluded(context);
7804
- }
7971
+ return currentGlobal[ValueProperties];
7805
7972
  }
7806
7973
 
7807
- class BlockStatement extends NodeBase {
7974
+ class GlobalVariable extends Variable {
7808
7975
  constructor() {
7809
7976
  super(...arguments);
7810
- this.directlyIncluded = false;
7811
- }
7812
- addImplicitReturnExpressionToScope() {
7813
- const lastStatement = this.body[this.body.length - 1];
7814
- if (!lastStatement || lastStatement.type !== ReturnStatement$1) {
7815
- this.scope.addReturnExpression(UNKNOWN_EXPRESSION);
7816
- }
7817
- }
7818
- createScope(parentScope) {
7819
- this.scope = this.parent.preventChildBlockScope
7820
- ? parentScope
7821
- : new BlockScope(parentScope);
7977
+ // Ensure we use live-bindings for globals as we do not know if they have
7978
+ // been reassigned
7979
+ this.isReassigned = true;
7822
7980
  }
7823
- hasEffects(context) {
7824
- if (this.deoptimizeBody)
7825
- return true;
7826
- for (const node of this.body) {
7827
- if (context.brokenFlow)
7828
- break;
7829
- if (node.hasEffects(context))
7830
- return true;
7831
- }
7832
- return false;
7981
+ getLiteralValueAtPath(path, _recursionTracker, _origin) {
7982
+ return getGlobalAtPath([this.name, ...path]) ? UnknownTruthyValue : UnknownValue;
7833
7983
  }
7834
- include(context, includeChildrenRecursively) {
7835
- if (!(this.deoptimizeBody && this.directlyIncluded)) {
7836
- this.included = true;
7837
- this.directlyIncluded = true;
7838
- if (this.deoptimizeBody)
7839
- includeChildrenRecursively = true;
7840
- for (const node of this.body) {
7841
- if (includeChildrenRecursively || node.shouldBeIncluded(context))
7842
- node.include(context, includeChildrenRecursively);
7843
- }
7984
+ hasEffectsWhenAccessedAtPath(path) {
7985
+ if (path.length === 0) {
7986
+ // Technically, "undefined" is a global variable of sorts
7987
+ return this.name !== 'undefined' && !getGlobalAtPath([this.name]);
7844
7988
  }
7989
+ return !getGlobalAtPath([this.name, ...path].slice(0, -1));
7845
7990
  }
7846
- initialise() {
7847
- const firstBodyStatement = this.body[0];
7848
- this.deoptimizeBody =
7849
- firstBodyStatement instanceof ExpressionStatement &&
7850
- firstBodyStatement.directive === 'use asm';
7851
- }
7852
- render(code, options) {
7853
- if (this.body.length) {
7854
- renderStatementList(this.body, code, this.start + 1, this.end - 1, options);
7855
- }
7856
- else {
7857
- super.render(code, options);
7858
- }
7991
+ hasEffectsWhenCalledAtPath(path, callOptions, context) {
7992
+ const globalAtPath = getGlobalAtPath([this.name, ...path]);
7993
+ return !globalAtPath || globalAtPath.hasEffectsWhenCalled(callOptions, context);
7859
7994
  }
7860
7995
  }
7861
7996
 
7862
- class RestElement extends NodeBase {
7997
+ const tdzVariableKinds = {
7998
+ __proto__: null,
7999
+ class: true,
8000
+ const: true,
8001
+ let: true,
8002
+ var: true
8003
+ };
8004
+ class Identifier extends NodeBase {
7863
8005
  constructor() {
7864
8006
  super(...arguments);
8007
+ this.variable = null;
7865
8008
  this.deoptimized = false;
7866
- this.declarationInit = null;
8009
+ this.isTDZAccess = null;
7867
8010
  }
7868
8011
  addExportedVariables(variables, exportNamesByVariable) {
7869
- this.argument.addExportedVariables(variables, exportNamesByVariable);
7870
- }
7871
- declare(kind, init) {
7872
- this.declarationInit = init;
7873
- return this.argument.declare(kind, UNKNOWN_EXPRESSION);
7874
- }
7875
- deoptimizePath(path) {
7876
- path.length === 0 && this.argument.deoptimizePath(EMPTY_PATH);
7877
- }
7878
- hasEffectsWhenAssignedAtPath(path, context) {
7879
- return path.length > 0 || this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
7880
- }
7881
- markDeclarationReached() {
7882
- this.argument.markDeclarationReached();
8012
+ if (exportNamesByVariable.has(this.variable)) {
8013
+ variables.push(this.variable);
8014
+ }
7883
8015
  }
7884
- applyDeoptimizations() {
7885
- this.deoptimized = true;
7886
- if (this.declarationInit !== null) {
7887
- this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
7888
- this.context.requestTreeshakingPass();
8016
+ bind() {
8017
+ if (!this.variable && is_reference(this, this.parent)) {
8018
+ this.variable = this.scope.findVariable(this.name);
8019
+ this.variable.addReference(this);
7889
8020
  }
7890
8021
  }
7891
- }
7892
-
7893
- class FunctionBase extends NodeBase {
7894
- constructor() {
7895
- super(...arguments);
7896
- this.objectEntity = null;
7897
- this.deoptimizedReturn = false;
8022
+ declare(kind, init) {
8023
+ let variable;
8024
+ const { treeshake } = this.context.options;
8025
+ switch (kind) {
8026
+ case 'var':
8027
+ variable = this.scope.addDeclaration(this, this.context, init, true);
8028
+ if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
8029
+ // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
8030
+ variable.markInitializersForDeoptimization();
8031
+ }
8032
+ break;
8033
+ case 'function':
8034
+ // in strict mode, functions are only hoisted within a scope but not across block scopes
8035
+ variable = this.scope.addDeclaration(this, this.context, init, false);
8036
+ break;
8037
+ case 'let':
8038
+ case 'const':
8039
+ case 'class':
8040
+ variable = this.scope.addDeclaration(this, this.context, init, false);
8041
+ break;
8042
+ case 'parameter':
8043
+ variable = this.scope.addParameterDeclaration(this);
8044
+ break;
8045
+ /* istanbul ignore next */
8046
+ default:
8047
+ /* istanbul ignore next */
8048
+ throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
8049
+ }
8050
+ variable.kind = kind;
8051
+ return [(this.variable = variable)];
7898
8052
  }
7899
8053
  deoptimizePath(path) {
7900
- this.getObjectEntity().deoptimizePath(path);
7901
- if (path.length === 1 && path[0] === UnknownKey) {
7902
- // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
7903
- // which means the return expression needs to be reassigned
7904
- this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
8054
+ if (path.length === 0 && !this.scope.contains(this.name)) {
8055
+ this.disallowImportReassignment();
7905
8056
  }
8057
+ this.variable.deoptimizePath(path);
7906
8058
  }
7907
8059
  deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
7908
- if (path.length > 0) {
7909
- this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
7910
- }
8060
+ this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
7911
8061
  }
7912
8062
  getLiteralValueAtPath(path, recursionTracker, origin) {
7913
- return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
8063
+ return this.getVariableRespectingTDZ().getLiteralValueAtPath(path, recursionTracker, origin);
7914
8064
  }
7915
8065
  getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
7916
- if (path.length > 0) {
7917
- return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
7918
- }
7919
- if (this.async) {
7920
- if (!this.deoptimizedReturn) {
7921
- this.deoptimizedReturn = true;
7922
- this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
7923
- this.context.requestTreeshakingPass();
7924
- }
7925
- return UNKNOWN_EXPRESSION;
8066
+ return this.getVariableRespectingTDZ().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
8067
+ }
8068
+ hasEffects() {
8069
+ if (!this.deoptimized)
8070
+ this.applyDeoptimizations();
8071
+ if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
8072
+ return true;
7926
8073
  }
7927
- return this.scope.getReturnExpression();
8074
+ return (this.context.options.treeshake.unknownGlobalSideEffects &&
8075
+ this.variable instanceof GlobalVariable &&
8076
+ this.variable.hasEffectsWhenAccessedAtPath(EMPTY_PATH));
7928
8077
  }
7929
8078
  hasEffectsWhenAccessedAtPath(path, context) {
7930
- return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
8079
+ var _a;
8080
+ return (_a = this.getVariableRespectingTDZ()) === null || _a === void 0 ? void 0 : _a.hasEffectsWhenAccessedAtPath(path, context);
7931
8081
  }
7932
8082
  hasEffectsWhenAssignedAtPath(path, context) {
7933
- return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
8083
+ return (path.length > 0 ? this.getVariableRespectingTDZ() : this.variable).hasEffectsWhenAssignedAtPath(path, context);
7934
8084
  }
7935
8085
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
7936
- if (path.length > 0) {
7937
- return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
7938
- }
7939
- if (this.async) {
7940
- const { propertyReadSideEffects } = this.context.options
7941
- .treeshake;
7942
- const returnExpression = this.scope.getReturnExpression();
7943
- if (returnExpression.hasEffectsWhenCalledAtPath(['then'], { args: NO_ARGS, thisParam: null, withNew: false }, context) ||
7944
- (propertyReadSideEffects &&
7945
- (propertyReadSideEffects === 'always' ||
7946
- returnExpression.hasEffectsWhenAccessedAtPath(['then'], context)))) {
7947
- return true;
8086
+ return this.getVariableRespectingTDZ().hasEffectsWhenCalledAtPath(path, callOptions, context);
8087
+ }
8088
+ include() {
8089
+ if (!this.deoptimized)
8090
+ this.applyDeoptimizations();
8091
+ if (!this.included) {
8092
+ this.included = true;
8093
+ if (this.variable !== null) {
8094
+ this.context.includeVariableInModule(this.variable);
7948
8095
  }
7949
8096
  }
7950
- for (const param of this.params) {
7951
- if (param.hasEffects(context))
7952
- return true;
7953
- }
7954
- return false;
7955
- }
7956
- include(context, includeChildrenRecursively) {
7957
- this.included = true;
7958
- const { brokenFlow } = context;
7959
- context.brokenFlow = BROKEN_FLOW_NONE;
7960
- this.body.include(context, includeChildrenRecursively);
7961
- context.brokenFlow = brokenFlow;
7962
8097
  }
7963
- includeCallArguments(context, args) {
7964
- this.scope.includeCallArguments(context, args);
8098
+ includeArgumentsWhenCalledAtPath(path, context, args) {
8099
+ this.variable.includeArgumentsWhenCalledAtPath(path, context, args);
7965
8100
  }
7966
- initialise() {
7967
- this.scope.addParameterVariables(this.params.map(param => param.declare('parameter', UNKNOWN_EXPRESSION)), this.params[this.params.length - 1] instanceof RestElement);
7968
- if (this.body instanceof BlockStatement) {
7969
- this.body.addImplicitReturnExpressionToScope();
8101
+ isPossibleTDZ() {
8102
+ // return cached value to avoid issues with the next tree-shaking pass
8103
+ if (this.isTDZAccess !== null)
8104
+ return this.isTDZAccess;
8105
+ if (!(this.variable instanceof LocalVariable) ||
8106
+ !this.variable.kind ||
8107
+ !(this.variable.kind in tdzVariableKinds)) {
8108
+ return (this.isTDZAccess = false);
7970
8109
  }
7971
- else {
7972
- this.scope.addReturnExpression(this.body);
8110
+ let decl_id;
8111
+ if (this.variable.declarations &&
8112
+ this.variable.declarations.length === 1 &&
8113
+ (decl_id = this.variable.declarations[0]) &&
8114
+ this.start < decl_id.start &&
8115
+ closestParentFunctionOrProgram(this) === closestParentFunctionOrProgram(decl_id)) {
8116
+ // a variable accessed before its declaration
8117
+ // in the same function or at top level of module
8118
+ return (this.isTDZAccess = true);
7973
8119
  }
7974
- }
7975
- parseNode(esTreeNode) {
7976
- if (esTreeNode.body.type === BlockStatement$1) {
7977
- this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
8120
+ if (!this.variable.initReached) {
8121
+ // Either a const/let TDZ violation or
8122
+ // var use before declaration was encountered.
8123
+ return (this.isTDZAccess = true);
7978
8124
  }
7979
- super.parseNode(esTreeNode);
7980
- }
7981
- }
7982
- FunctionBase.prototype.preventChildBlockScope = true;
7983
-
7984
- class ArrowFunctionExpression extends FunctionBase {
7985
- constructor() {
7986
- super(...arguments);
7987
- this.objectEntity = null;
7988
- }
7989
- createScope(parentScope) {
7990
- this.scope = new ReturnValueScope(parentScope, this.context);
7991
- }
7992
- hasEffects() {
7993
- return false;
8125
+ return (this.isTDZAccess = false);
7994
8126
  }
7995
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
7996
- if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
7997
- return true;
7998
- const { ignore, brokenFlow } = context;
7999
- context.ignore = {
8000
- breaks: false,
8001
- continues: false,
8002
- labels: new Set(),
8003
- returnYield: true
8004
- };
8005
- if (this.body.hasEffects(context))
8006
- return true;
8007
- context.ignore = ignore;
8008
- context.brokenFlow = brokenFlow;
8009
- return false;
8127
+ markDeclarationReached() {
8128
+ this.variable.initReached = true;
8010
8129
  }
8011
- include(context, includeChildrenRecursively) {
8012
- super.include(context, includeChildrenRecursively);
8013
- for (const param of this.params) {
8014
- if (!(param instanceof Identifier)) {
8015
- param.include(context, includeChildrenRecursively);
8130
+ render(code, { snippets: { getPropertyAccess } }, { renderedParentType, isCalleeOfRenderedParent, isShorthandProperty } = BLANK) {
8131
+ if (this.variable) {
8132
+ const name = this.variable.getName(getPropertyAccess);
8133
+ if (name !== this.name) {
8134
+ code.overwrite(this.start, this.end, name, {
8135
+ contentOnly: true,
8136
+ storeName: true
8137
+ });
8138
+ if (isShorthandProperty) {
8139
+ code.prependRight(this.start, `${this.name}: `);
8140
+ }
8141
+ }
8142
+ // In strict mode, any variable named "eval" must be the actual "eval" function
8143
+ if (name === 'eval' &&
8144
+ renderedParentType === CallExpression$1 &&
8145
+ isCalleeOfRenderedParent) {
8146
+ code.appendRight(this.start, '0, ');
8016
8147
  }
8017
8148
  }
8018
8149
  }
8019
- getObjectEntity() {
8020
- if (this.objectEntity !== null) {
8021
- return this.objectEntity;
8150
+ applyDeoptimizations() {
8151
+ this.deoptimized = true;
8152
+ if (this.variable instanceof LocalVariable) {
8153
+ this.variable.consolidateInitializers();
8154
+ this.context.requestTreeshakingPass();
8022
8155
  }
8023
- return (this.objectEntity = new ObjectEntity([], OBJECT_PROTOTYPE));
8024
8156
  }
8025
- }
8026
-
8027
- function getSystemExportStatement(exportedVariables, { exportNamesByVariable, snippets: { _, getObject, getPropertyAccess } }, modifier = '') {
8028
- if (exportedVariables.length === 1 &&
8029
- exportNamesByVariable.get(exportedVariables[0]).length === 1) {
8030
- const variable = exportedVariables[0];
8031
- return `exports('${exportNamesByVariable.get(variable)}',${_}${variable.getName(getPropertyAccess)}${modifier})`;
8157
+ disallowImportReassignment() {
8158
+ return this.context.error({
8159
+ code: 'ILLEGAL_REASSIGNMENT',
8160
+ message: `Illegal reassignment to import '${this.name}'`
8161
+ }, this.start);
8032
8162
  }
8033
- else {
8034
- const fields = [];
8035
- for (const variable of exportedVariables) {
8036
- for (const exportName of exportNamesByVariable.get(variable)) {
8037
- fields.push([exportName, variable.getName(getPropertyAccess) + modifier]);
8038
- }
8163
+ getVariableRespectingTDZ() {
8164
+ if (this.isPossibleTDZ()) {
8165
+ return UNKNOWN_EXPRESSION;
8039
8166
  }
8040
- return `exports(${getObject(fields, { lineBreakIndent: null })})`;
8041
- }
8042
- }
8043
- function renderSystemExportExpression(exportedVariable, expressionStart, expressionEnd, code, { exportNamesByVariable, snippets: { _ } }) {
8044
- code.prependRight(expressionStart, `exports('${exportNamesByVariable.get(exportedVariable)}',${_}`);
8045
- code.appendLeft(expressionEnd, ')');
8046
- }
8047
- function renderSystemExportFunction(exportedVariables, expressionStart, expressionEnd, needsParens, code, options) {
8048
- const { _, getDirectReturnIifeLeft } = options.snippets;
8049
- code.prependRight(expressionStart, getDirectReturnIifeLeft(['v'], `${getSystemExportStatement(exportedVariables, options)},${_}v`, { needsArrowReturnParens: true, needsWrappedFunction: needsParens }));
8050
- code.appendLeft(expressionEnd, ')');
8051
- }
8052
- function renderSystemExportSequenceAfterExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options) {
8053
- const { _, getPropertyAccess } = options.snippets;
8054
- code.appendLeft(expressionEnd, `,${_}${getSystemExportStatement([exportedVariable], options)},${_}${exportedVariable.getName(getPropertyAccess)}`);
8055
- if (needsParens) {
8056
- code.prependRight(expressionStart, '(');
8057
- code.appendLeft(expressionEnd, ')');
8167
+ return this.variable;
8058
8168
  }
8059
8169
  }
8060
- function renderSystemExportSequenceBeforeExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options, modifier) {
8061
- const { _ } = options.snippets;
8062
- code.prependRight(expressionStart, `${getSystemExportStatement([exportedVariable], options, modifier)},${_}`);
8063
- if (needsParens) {
8064
- code.prependRight(expressionStart, '(');
8065
- code.appendLeft(expressionEnd, ')');
8170
+ function closestParentFunctionOrProgram(node) {
8171
+ while (node && !/^Program|Function/.test(node.type)) {
8172
+ node = node.parent;
8066
8173
  }
8174
+ // one of: ArrowFunctionExpression, FunctionDeclaration, FunctionExpression or Program
8175
+ return node;
8067
8176
  }
8068
8177
 
8069
8178
  class ObjectPattern extends NodeBase {
@@ -8165,56 +8274,24 @@ class AssignmentExpression extends NodeBase {
8165
8274
  renderSystemExportSequenceAfterExpression(variable, this.start, this.end, this.parent.type !== ExpressionStatement$1, code, options);
8166
8275
  }
8167
8276
  return;
8168
- }
8169
- }
8170
- else {
8171
- const systemPatternExports = [];
8172
- this.left.addExportedVariables(systemPatternExports, options.exportNamesByVariable);
8173
- if (systemPatternExports.length > 0) {
8174
- renderSystemExportFunction(systemPatternExports, this.start, this.end, renderedSurroundingElement === ExpressionStatement$1, code, options);
8175
- return;
8176
- }
8177
- }
8178
- }
8179
- if (this.left.included &&
8180
- this.left instanceof ObjectPattern &&
8181
- (renderedSurroundingElement === ExpressionStatement$1 ||
8182
- renderedSurroundingElement === ArrowFunctionExpression$1)) {
8183
- code.appendRight(this.start, '(');
8184
- code.prependLeft(this.end, ')');
8185
- }
8186
- }
8187
- applyDeoptimizations() {
8188
- this.deoptimized = true;
8189
- this.left.deoptimizePath(EMPTY_PATH);
8190
- this.right.deoptimizePath(UNKNOWN_PATH);
8191
- this.context.requestTreeshakingPass();
8192
- }
8193
- }
8194
-
8195
- class AssignmentPattern extends NodeBase {
8196
- constructor() {
8197
- super(...arguments);
8198
- this.deoptimized = false;
8199
- }
8200
- addExportedVariables(variables, exportNamesByVariable) {
8201
- this.left.addExportedVariables(variables, exportNamesByVariable);
8202
- }
8203
- declare(kind, init) {
8204
- return this.left.declare(kind, init);
8205
- }
8206
- deoptimizePath(path) {
8207
- path.length === 0 && this.left.deoptimizePath(path);
8208
- }
8209
- hasEffectsWhenAssignedAtPath(path, context) {
8210
- return path.length > 0 || this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
8211
- }
8212
- markDeclarationReached() {
8213
- this.left.markDeclarationReached();
8214
- }
8215
- render(code, options, { isShorthandProperty } = BLANK) {
8216
- this.left.render(code, options, { isShorthandProperty });
8217
- this.right.render(code, options);
8277
+ }
8278
+ }
8279
+ else {
8280
+ const systemPatternExports = [];
8281
+ this.left.addExportedVariables(systemPatternExports, options.exportNamesByVariable);
8282
+ if (systemPatternExports.length > 0) {
8283
+ renderSystemExportFunction(systemPatternExports, this.start, this.end, renderedSurroundingElement === ExpressionStatement$1, code, options);
8284
+ return;
8285
+ }
8286
+ }
8287
+ }
8288
+ if (this.left.included &&
8289
+ this.left instanceof ObjectPattern &&
8290
+ (renderedSurroundingElement === ExpressionStatement$1 ||
8291
+ renderedSurroundingElement === ArrowFunctionExpression$1)) {
8292
+ code.appendRight(this.start, '(');
8293
+ code.prependLeft(this.end, ')');
8294
+ }
8218
8295
  }
8219
8296
  applyDeoptimizations() {
8220
8297
  this.deoptimized = true;
@@ -8331,7 +8408,8 @@ class FunctionNode extends FunctionBase {
8331
8408
  }
8332
8409
  }
8333
8410
  hasEffects() {
8334
- return this.id !== null && this.id.hasEffects();
8411
+ var _a;
8412
+ return (_a = this.id) === null || _a === void 0 ? void 0 : _a.hasEffects();
8335
8413
  }
8336
8414
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
8337
8415
  if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
@@ -8360,15 +8438,13 @@ class FunctionNode extends FunctionBase {
8360
8438
  return false;
8361
8439
  }
8362
8440
  include(context, includeChildrenRecursively) {
8363
- super.include(context, includeChildrenRecursively);
8364
- if (this.id)
8365
- this.id.include();
8366
- const hasArguments = this.scope.argumentsVariable.included;
8367
- for (const param of this.params) {
8368
- if (!(param instanceof Identifier) || hasArguments) {
8369
- param.include(context, includeChildrenRecursively);
8370
- }
8441
+ var _a;
8442
+ // This ensures that super.include will also include all parameters
8443
+ if (this.scope.argumentsVariable.included) {
8444
+ this.alwaysIncludeParameters = true;
8371
8445
  }
8446
+ (_a = this.id) === null || _a === void 0 ? void 0 : _a.include();
8447
+ super.include(context, includeChildrenRecursively);
8372
8448
  }
8373
8449
  initialise() {
8374
8450
  var _a;
@@ -8415,11 +8491,6 @@ class AwaitExpression extends NodeBase {
8415
8491
  }
8416
8492
  this.argument.include(context, includeChildrenRecursively);
8417
8493
  }
8418
- applyDeoptimizations() {
8419
- this.deoptimized = true;
8420
- this.argument.deoptimizePath(UNKNOWN_PATH);
8421
- this.context.requestTreeshakingPass();
8422
- }
8423
8494
  }
8424
8495
 
8425
8496
  const binaryOperators = {
@@ -8453,10 +8524,10 @@ class BinaryExpression extends NodeBase {
8453
8524
  if (path.length > 0)
8454
8525
  return UnknownValue;
8455
8526
  const leftValue = this.left.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
8456
- if (leftValue === UnknownValue)
8527
+ if (typeof leftValue === 'symbol')
8457
8528
  return UnknownValue;
8458
8529
  const rightValue = this.right.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
8459
- if (rightValue === UnknownValue)
8530
+ if (typeof rightValue === 'symbol')
8460
8531
  return UnknownValue;
8461
8532
  const operatorFn = binaryOperators[this.operator];
8462
8533
  if (!operatorFn)
@@ -8747,12 +8818,15 @@ class MemberExpression extends NodeBase {
8747
8818
  this.object.include(context, includeChildrenRecursively);
8748
8819
  this.property.include(context, includeChildrenRecursively);
8749
8820
  }
8750
- includeCallArguments(context, args) {
8821
+ includeArgumentsWhenCalledAtPath(path, context, args) {
8751
8822
  if (this.variable) {
8752
- this.variable.includeCallArguments(context, args);
8823
+ this.variable.includeArgumentsWhenCalledAtPath(path, context, args);
8753
8824
  }
8754
- else {
8755
- super.includeCallArguments(context, args);
8825
+ else if (this.replacement) {
8826
+ super.includeArgumentsWhenCalledAtPath(path, context, args);
8827
+ }
8828
+ else if (path.length < MAX_PATH_DEPTH) {
8829
+ this.object.includeArgumentsWhenCalledAtPath([this.getPropertyKey(), ...path], context, args);
8756
8830
  }
8757
8831
  }
8758
8832
  initialise() {
@@ -8814,7 +8888,7 @@ class MemberExpression extends NodeBase {
8814
8888
  if (this.propertyKey === null) {
8815
8889
  this.propertyKey = UnknownKey;
8816
8890
  const value = this.property.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
8817
- return (this.propertyKey = value === UnknownValue ? UnknownKey : String(value));
8891
+ return (this.propertyKey = typeof value === 'symbol' ? UnknownKey : String(value));
8818
8892
  }
8819
8893
  return this.propertyKey;
8820
8894
  }
@@ -8841,39 +8915,13 @@ class MemberExpression extends NodeBase {
8841
8915
  }
8842
8916
  }
8843
8917
 
8844
- class CallExpression extends NodeBase {
8918
+ class CallExpressionBase extends NodeBase {
8845
8919
  constructor() {
8846
8920
  super(...arguments);
8847
8921
  this.deoptimized = false;
8922
+ this.returnExpression = null;
8848
8923
  this.deoptimizableDependentExpressions = [];
8849
8924
  this.expressionsToBeDeoptimized = new Set();
8850
- this.returnExpression = null;
8851
- }
8852
- bind() {
8853
- super.bind();
8854
- if (this.callee instanceof Identifier) {
8855
- const variable = this.scope.findVariable(this.callee.name);
8856
- if (variable.isNamespace) {
8857
- this.context.warn({
8858
- code: 'CANNOT_CALL_NAMESPACE',
8859
- message: `Cannot call a namespace ('${this.callee.name}')`
8860
- }, this.start);
8861
- }
8862
- if (this.callee.name === 'eval') {
8863
- this.context.warn({
8864
- code: 'EVAL',
8865
- message: `Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification`,
8866
- url: 'https://rollupjs.org/guide/en/#avoiding-eval'
8867
- }, this.start);
8868
- }
8869
- }
8870
- this.callOptions = {
8871
- args: this.arguments,
8872
- thisParam: this.callee instanceof MemberExpression && !this.callee.variable
8873
- ? this.callee.object
8874
- : null,
8875
- withNew: false
8876
- };
8877
8925
  }
8878
8926
  deoptimizeCache() {
8879
8927
  if (this.returnExpression !== UNKNOWN_EXPRESSION) {
@@ -8928,6 +8976,47 @@ class CallExpression extends NodeBase {
8928
8976
  return returnExpression.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
8929
8977
  }, UNKNOWN_EXPRESSION);
8930
8978
  }
8979
+ hasEffectsWhenAccessedAtPath(path, context) {
8980
+ return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
8981
+ this.getReturnExpression().hasEffectsWhenAccessedAtPath(path, context));
8982
+ }
8983
+ hasEffectsWhenAssignedAtPath(path, context) {
8984
+ return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
8985
+ this.getReturnExpression().hasEffectsWhenAssignedAtPath(path, context));
8986
+ }
8987
+ hasEffectsWhenCalledAtPath(path, callOptions, context) {
8988
+ return (!(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
8989
+ this.getReturnExpression().hasEffectsWhenCalledAtPath(path, callOptions, context));
8990
+ }
8991
+ }
8992
+
8993
+ class CallExpression extends CallExpressionBase {
8994
+ bind() {
8995
+ super.bind();
8996
+ if (this.callee instanceof Identifier) {
8997
+ const variable = this.scope.findVariable(this.callee.name);
8998
+ if (variable.isNamespace) {
8999
+ this.context.warn({
9000
+ code: 'CANNOT_CALL_NAMESPACE',
9001
+ message: `Cannot call a namespace ('${this.callee.name}')`
9002
+ }, this.start);
9003
+ }
9004
+ if (this.callee.name === 'eval') {
9005
+ this.context.warn({
9006
+ code: 'EVAL',
9007
+ message: `Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification`,
9008
+ url: 'https://rollupjs.org/guide/en/#avoiding-eval'
9009
+ }, this.start);
9010
+ }
9011
+ }
9012
+ this.callOptions = {
9013
+ args: this.arguments,
9014
+ thisParam: this.callee instanceof MemberExpression && !this.callee.variable
9015
+ ? this.callee.object
9016
+ : null,
9017
+ withNew: false
9018
+ };
9019
+ }
8931
9020
  hasEffects(context) {
8932
9021
  try {
8933
9022
  for (const argument of this.arguments) {
@@ -8945,18 +9034,6 @@ class CallExpression extends NodeBase {
8945
9034
  this.applyDeoptimizations();
8946
9035
  }
8947
9036
  }
8948
- hasEffectsWhenAccessedAtPath(path, context) {
8949
- return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
8950
- this.getReturnExpression().hasEffectsWhenAccessedAtPath(path, context));
8951
- }
8952
- hasEffectsWhenAssignedAtPath(path, context) {
8953
- return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
8954
- this.getReturnExpression().hasEffectsWhenAssignedAtPath(path, context));
8955
- }
8956
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
8957
- return (!(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
8958
- this.getReturnExpression().hasEffectsWhenCalledAtPath(path, callOptions, context));
8959
- }
8960
9037
  include(context, includeChildrenRecursively) {
8961
9038
  if (!this.deoptimized)
8962
9039
  this.applyDeoptimizations();
@@ -8972,7 +9049,7 @@ class CallExpression extends NodeBase {
8972
9049
  this.included = true;
8973
9050
  this.callee.include(context, false);
8974
9051
  }
8975
- this.callee.includeCallArguments(context, this.arguments);
9052
+ this.callee.includeArgumentsWhenCalledAtPath(EMPTY_PATH, context, this.arguments);
8976
9053
  const returnExpression = this.getReturnExpression();
8977
9054
  if (!returnExpression.included) {
8978
9055
  returnExpression.include(context, false);
@@ -9143,6 +9220,9 @@ class MethodBase extends NodeBase {
9143
9220
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
9144
9221
  return this.getAccessedValue().hasEffectsWhenCalledAtPath(path, callOptions, context);
9145
9222
  }
9223
+ includeArgumentsWhenCalledAtPath(path, context, args) {
9224
+ this.getAccessedValue().includeArgumentsWhenCalledAtPath(path, context, args);
9225
+ }
9146
9226
  getAccessedValue() {
9147
9227
  if (this.accessedValue === null) {
9148
9228
  if (this.kind === 'get') {
@@ -9179,8 +9259,6 @@ class ObjectMember extends ExpressionEntity {
9179
9259
  return this.object.getReturnExpressionWhenCalledAtPath([this.key, ...path], callOptions, recursionTracker, origin);
9180
9260
  }
9181
9261
  hasEffectsWhenAccessedAtPath(path, context) {
9182
- if (path.length === 0)
9183
- return false;
9184
9262
  return this.object.hasEffectsWhenAccessedAtPath([this.key, ...path], context);
9185
9263
  }
9186
9264
  hasEffectsWhenAssignedAtPath(path, context) {
@@ -9194,6 +9272,7 @@ class ObjectMember extends ExpressionEntity {
9194
9272
  class ClassNode extends NodeBase {
9195
9273
  constructor() {
9196
9274
  super(...arguments);
9275
+ this.deoptimized = false;
9197
9276
  this.objectEntity = null;
9198
9277
  }
9199
9278
  createScope(parentScope) {
@@ -9203,7 +9282,14 @@ class ClassNode extends NodeBase {
9203
9282
  this.getObjectEntity().deoptimizeAllProperties();
9204
9283
  }
9205
9284
  deoptimizePath(path) {
9285
+ var _a, _b;
9206
9286
  this.getObjectEntity().deoptimizePath(path);
9287
+ if (path.length === 1 && path[0] === UnknownKey) {
9288
+ // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
9289
+ // which means the constructor needs to be reassigned
9290
+ (_a = this.classConstructor) === null || _a === void 0 ? void 0 : _a.deoptimizePath(UNKNOWN_PATH);
9291
+ (_b = this.superClass) === null || _b === void 0 ? void 0 : _b.deoptimizePath(UNKNOWN_PATH);
9292
+ }
9207
9293
  }
9208
9294
  deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
9209
9295
  this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
@@ -9216,6 +9302,8 @@ class ClassNode extends NodeBase {
9216
9302
  }
9217
9303
  hasEffects(context) {
9218
9304
  var _a, _b;
9305
+ if (!this.deoptimized)
9306
+ this.applyDeoptimizations();
9219
9307
  const initEffect = ((_a = this.superClass) === null || _a === void 0 ? void 0 : _a.hasEffects(context)) || this.body.hasEffects(context);
9220
9308
  (_b = this.id) === null || _b === void 0 ? void 0 : _b.markDeclarationReached();
9221
9309
  return initEffect || super.hasEffects(context);
@@ -9227,12 +9315,13 @@ class ClassNode extends NodeBase {
9227
9315
  return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
9228
9316
  }
9229
9317
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
9318
+ var _a;
9230
9319
  if (path.length === 0) {
9231
9320
  return (!callOptions.withNew ||
9232
9321
  (this.classConstructor !== null
9233
9322
  ? this.classConstructor.hasEffectsWhenCalledAtPath(EMPTY_PATH, callOptions, context)
9234
- : this.superClass !== null &&
9235
- this.superClass.hasEffectsWhenCalledAtPath(path, callOptions, context)));
9323
+ : (_a = this.superClass) === null || _a === void 0 ? void 0 : _a.hasEffectsWhenCalledAtPath(path, callOptions, context)) ||
9324
+ false);
9236
9325
  }
9237
9326
  else {
9238
9327
  return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
@@ -9240,6 +9329,8 @@ class ClassNode extends NodeBase {
9240
9329
  }
9241
9330
  include(context, includeChildrenRecursively) {
9242
9331
  var _a;
9332
+ if (!this.deoptimized)
9333
+ this.applyDeoptimizations();
9243
9334
  this.included = true;
9244
9335
  (_a = this.superClass) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
9245
9336
  this.body.include(context, includeChildrenRecursively);
@@ -9248,6 +9339,20 @@ class ClassNode extends NodeBase {
9248
9339
  this.id.include();
9249
9340
  }
9250
9341
  }
9342
+ includeArgumentsWhenCalledAtPath(path, context, args) {
9343
+ var _a;
9344
+ if (path.length === 0) {
9345
+ if (this.classConstructor) {
9346
+ this.classConstructor.includeArgumentsWhenCalledAtPath(path, context, args);
9347
+ }
9348
+ else {
9349
+ (_a = this.superClass) === null || _a === void 0 ? void 0 : _a.includeArgumentsWhenCalledAtPath(path, context, args);
9350
+ }
9351
+ }
9352
+ else {
9353
+ this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
9354
+ }
9355
+ }
9251
9356
  initialise() {
9252
9357
  var _a;
9253
9358
  (_a = this.id) === null || _a === void 0 ? void 0 : _a.declare('class', this);
@@ -9259,6 +9364,18 @@ class ClassNode extends NodeBase {
9259
9364
  }
9260
9365
  this.classConstructor = null;
9261
9366
  }
9367
+ applyDeoptimizations() {
9368
+ this.deoptimized = true;
9369
+ for (const definition of this.body.body) {
9370
+ if (!(definition.static ||
9371
+ (definition instanceof MethodDefinition && definition.kind === 'constructor'))) {
9372
+ // Calls to methods are not tracked, ensure that parameter defaults are
9373
+ // included and the return value is deoptimized
9374
+ definition.deoptimizePath(UNKNOWN_PATH);
9375
+ }
9376
+ }
9377
+ this.context.requestTreeshakingPass();
9378
+ }
9262
9379
  getObjectEntity() {
9263
9380
  if (this.objectEntity !== null) {
9264
9381
  return this.objectEntity;
@@ -9275,7 +9392,7 @@ class ClassNode extends NodeBase {
9275
9392
  let key;
9276
9393
  if (definition.computed) {
9277
9394
  const keyValue = definition.key.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
9278
- if (keyValue === UnknownValue) {
9395
+ if (typeof keyValue === 'symbol') {
9279
9396
  properties.push({ key: UnknownKey, kind, property: definition });
9280
9397
  continue;
9281
9398
  }
@@ -9471,14 +9588,14 @@ class ConditionalExpression extends NodeBase {
9471
9588
  usedBranch.include(context, includeChildrenRecursively);
9472
9589
  }
9473
9590
  }
9474
- includeCallArguments(context, args) {
9591
+ includeArgumentsWhenCalledAtPath(path, context, args) {
9475
9592
  const usedBranch = this.getUsedBranch();
9476
9593
  if (usedBranch === null) {
9477
- this.consequent.includeCallArguments(context, args);
9478
- this.alternate.includeCallArguments(context, args);
9594
+ this.consequent.includeArgumentsWhenCalledAtPath(path, context, args);
9595
+ this.alternate.includeArgumentsWhenCalledAtPath(path, context, args);
9479
9596
  }
9480
9597
  else {
9481
- usedBranch.includeCallArguments(context, args);
9598
+ usedBranch.includeArgumentsWhenCalledAtPath(path, context, args);
9482
9599
  }
9483
9600
  }
9484
9601
  render(code, options, { isCalleeOfRenderedParent, preventASI, renderedParentType, renderedSurroundingElement } = BLANK) {
@@ -9515,7 +9632,7 @@ class ConditionalExpression extends NodeBase {
9515
9632
  }
9516
9633
  this.isBranchResolutionAnalysed = true;
9517
9634
  const testValue = this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
9518
- return testValue === UnknownValue
9635
+ return typeof testValue === 'symbol'
9519
9636
  ? null
9520
9637
  : (this.usedBranch = testValue ? this.consequent : this.alternate);
9521
9638
  }
@@ -9564,7 +9681,7 @@ class DoWhileStatement extends NodeBase {
9564
9681
  this.included = true;
9565
9682
  this.test.include(context, includeChildrenRecursively);
9566
9683
  const { brokenFlow } = context;
9567
- this.body.includeAsSingleStatement(context, includeChildrenRecursively);
9684
+ this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9568
9685
  context.brokenFlow = brokenFlow;
9569
9686
  }
9570
9687
  }
@@ -9692,12 +9809,13 @@ ExportDefaultDeclaration.prototype.needsBoundaries = true;
9692
9809
 
9693
9810
  class ExportNamedDeclaration extends NodeBase {
9694
9811
  bind() {
9812
+ var _a;
9695
9813
  // Do not bind specifiers
9696
- if (this.declaration !== null)
9697
- this.declaration.bind();
9814
+ (_a = this.declaration) === null || _a === void 0 ? void 0 : _a.bind();
9698
9815
  }
9699
9816
  hasEffects(context) {
9700
- return this.declaration !== null && this.declaration.hasEffects(context);
9817
+ var _a;
9818
+ return (_a = this.declaration) === null || _a === void 0 ? void 0 : _a.hasEffects(context);
9701
9819
  }
9702
9820
  initialise() {
9703
9821
  this.context.addExport(this);
@@ -9751,7 +9869,7 @@ class ForInStatement extends NodeBase {
9751
9869
  this.left.include(context, includeChildrenRecursively || true);
9752
9870
  this.right.include(context, includeChildrenRecursively);
9753
9871
  const { brokenFlow } = context;
9754
- this.body.includeAsSingleStatement(context, includeChildrenRecursively);
9872
+ this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9755
9873
  context.brokenFlow = brokenFlow;
9756
9874
  }
9757
9875
  render(code, options) {
@@ -9791,7 +9909,7 @@ class ForOfStatement extends NodeBase {
9791
9909
  this.left.include(context, includeChildrenRecursively || true);
9792
9910
  this.right.include(context, includeChildrenRecursively);
9793
9911
  const { brokenFlow } = context;
9794
- this.body.includeAsSingleStatement(context, includeChildrenRecursively);
9912
+ this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9795
9913
  context.brokenFlow = brokenFlow;
9796
9914
  }
9797
9915
  render(code, options) {
@@ -9815,9 +9933,10 @@ class ForStatement extends NodeBase {
9815
9933
  this.scope = new BlockScope(parentScope);
9816
9934
  }
9817
9935
  hasEffects(context) {
9818
- if ((this.init && this.init.hasEffects(context)) ||
9819
- (this.test && this.test.hasEffects(context)) ||
9820
- (this.update && this.update.hasEffects(context)))
9936
+ var _a, _b, _c;
9937
+ if (((_a = this.init) === null || _a === void 0 ? void 0 : _a.hasEffects(context)) ||
9938
+ ((_b = this.test) === null || _b === void 0 ? void 0 : _b.hasEffects(context)) ||
9939
+ ((_c = this.update) === null || _c === void 0 ? void 0 : _c.hasEffects(context)))
9821
9940
  return true;
9822
9941
  const { brokenFlow, ignore: { breaks, continues } } = context;
9823
9942
  context.ignore.breaks = true;
@@ -9830,24 +9949,20 @@ class ForStatement extends NodeBase {
9830
9949
  return false;
9831
9950
  }
9832
9951
  include(context, includeChildrenRecursively) {
9952
+ var _a, _b, _c;
9833
9953
  this.included = true;
9834
- if (this.init)
9835
- this.init.includeAsSingleStatement(context, includeChildrenRecursively);
9836
- if (this.test)
9837
- this.test.include(context, includeChildrenRecursively);
9954
+ (_a = this.init) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively, { asSingleStatement: true });
9955
+ (_b = this.test) === null || _b === void 0 ? void 0 : _b.include(context, includeChildrenRecursively);
9838
9956
  const { brokenFlow } = context;
9839
- if (this.update)
9840
- this.update.include(context, includeChildrenRecursively);
9841
- this.body.includeAsSingleStatement(context, includeChildrenRecursively);
9957
+ (_c = this.update) === null || _c === void 0 ? void 0 : _c.include(context, includeChildrenRecursively);
9958
+ this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9842
9959
  context.brokenFlow = brokenFlow;
9843
9960
  }
9844
9961
  render(code, options) {
9845
- if (this.init)
9846
- this.init.render(code, options, NO_SEMICOLON);
9847
- if (this.test)
9848
- this.test.render(code, options, NO_SEMICOLON);
9849
- if (this.update)
9850
- this.update.render(code, options, NO_SEMICOLON);
9962
+ var _a, _b, _c;
9963
+ (_a = this.init) === null || _a === void 0 ? void 0 : _a.render(code, options, NO_SEMICOLON);
9964
+ (_b = this.test) === null || _b === void 0 ? void 0 : _b.render(code, options, NO_SEMICOLON);
9965
+ (_c = this.update) === null || _c === void 0 ? void 0 : _c.render(code, options, NO_SEMICOLON);
9851
9966
  this.body.render(code, options);
9852
9967
  }
9853
9968
  }
@@ -9883,11 +9998,12 @@ class IfStatement extends NodeBase {
9883
9998
  this.testValue = UnknownValue;
9884
9999
  }
9885
10000
  hasEffects(context) {
10001
+ var _a;
9886
10002
  if (this.test.hasEffects(context)) {
9887
10003
  return true;
9888
10004
  }
9889
10005
  const testValue = this.getTestValue();
9890
- if (testValue === UnknownValue) {
10006
+ if (typeof testValue === 'symbol') {
9891
10007
  const { brokenFlow } = context;
9892
10008
  if (this.consequent.hasEffects(context))
9893
10009
  return true;
@@ -9901,9 +10017,7 @@ class IfStatement extends NodeBase {
9901
10017
  context.brokenFlow < consequentBrokenFlow ? context.brokenFlow : consequentBrokenFlow;
9902
10018
  return false;
9903
10019
  }
9904
- return testValue
9905
- ? this.consequent.hasEffects(context)
9906
- : this.alternate !== null && this.alternate.hasEffects(context);
10020
+ return testValue ? this.consequent.hasEffects(context) : (_a = this.alternate) === null || _a === void 0 ? void 0 : _a.hasEffects(context);
9907
10021
  }
9908
10022
  include(context, includeChildrenRecursively) {
9909
10023
  this.included = true;
@@ -9912,7 +10026,7 @@ class IfStatement extends NodeBase {
9912
10026
  }
9913
10027
  else {
9914
10028
  const testValue = this.getTestValue();
9915
- if (testValue === UnknownValue) {
10029
+ if (typeof testValue === 'symbol') {
9916
10030
  this.includeUnknownTest(context);
9917
10031
  }
9918
10032
  else {
@@ -9942,7 +10056,7 @@ class IfStatement extends NodeBase {
9942
10056
  else {
9943
10057
  code.remove(this.start, this.consequent.start);
9944
10058
  }
9945
- if (this.consequent.included && (noTreeshake || testValue === UnknownValue || testValue)) {
10059
+ if (this.consequent.included && (noTreeshake || typeof testValue === 'symbol' || testValue)) {
9946
10060
  this.consequent.render(code, options);
9947
10061
  }
9948
10062
  else {
@@ -9950,7 +10064,7 @@ class IfStatement extends NodeBase {
9950
10064
  hoistedDeclarations.push(...this.consequentScope.hoistedDeclarations);
9951
10065
  }
9952
10066
  if (this.alternate) {
9953
- if (this.alternate.included && (noTreeshake || testValue === UnknownValue || !testValue)) {
10067
+ if (this.alternate.included && (noTreeshake || typeof testValue === 'symbol' || !testValue)) {
9954
10068
  if (includesIfElse) {
9955
10069
  if (code.original.charCodeAt(this.alternate.start - 1) === 101) {
9956
10070
  code.prependLeft(this.alternate.start, ' ');
@@ -9980,34 +10094,35 @@ class IfStatement extends NodeBase {
9980
10094
  return this.testValue;
9981
10095
  }
9982
10096
  includeKnownTest(context, testValue) {
10097
+ var _a;
9983
10098
  if (this.test.shouldBeIncluded(context)) {
9984
10099
  this.test.include(context, false);
9985
10100
  }
9986
10101
  if (testValue && this.consequent.shouldBeIncluded(context)) {
9987
- this.consequent.includeAsSingleStatement(context, false);
10102
+ this.consequent.include(context, false, { asSingleStatement: true });
9988
10103
  }
9989
- if (this.alternate !== null && !testValue && this.alternate.shouldBeIncluded(context)) {
9990
- this.alternate.includeAsSingleStatement(context, false);
10104
+ if (!testValue && ((_a = this.alternate) === null || _a === void 0 ? void 0 : _a.shouldBeIncluded(context))) {
10105
+ this.alternate.include(context, false, { asSingleStatement: true });
9991
10106
  }
9992
10107
  }
9993
10108
  includeRecursively(includeChildrenRecursively, context) {
10109
+ var _a;
9994
10110
  this.test.include(context, includeChildrenRecursively);
9995
10111
  this.consequent.include(context, includeChildrenRecursively);
9996
- if (this.alternate !== null) {
9997
- this.alternate.include(context, includeChildrenRecursively);
9998
- }
10112
+ (_a = this.alternate) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
9999
10113
  }
10000
10114
  includeUnknownTest(context) {
10115
+ var _a;
10001
10116
  this.test.include(context, false);
10002
10117
  const { brokenFlow } = context;
10003
10118
  let consequentBrokenFlow = BROKEN_FLOW_NONE;
10004
10119
  if (this.consequent.shouldBeIncluded(context)) {
10005
- this.consequent.includeAsSingleStatement(context, false);
10120
+ this.consequent.include(context, false, { asSingleStatement: true });
10006
10121
  consequentBrokenFlow = context.brokenFlow;
10007
10122
  context.brokenFlow = brokenFlow;
10008
10123
  }
10009
- if (this.alternate !== null && this.alternate.shouldBeIncluded(context)) {
10010
- this.alternate.includeAsSingleStatement(context, false);
10124
+ if ((_a = this.alternate) === null || _a === void 0 ? void 0 : _a.shouldBeIncluded(context)) {
10125
+ this.alternate.include(context, false, { asSingleStatement: true });
10011
10126
  context.brokenFlow =
10012
10127
  context.brokenFlow < consequentBrokenFlow ? context.brokenFlow : consequentBrokenFlow;
10013
10128
  }
@@ -10594,7 +10709,7 @@ class LogicalExpression extends NodeBase {
10594
10709
  if (!this.isBranchResolutionAnalysed) {
10595
10710
  this.isBranchResolutionAnalysed = true;
10596
10711
  const leftValue = this.left.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
10597
- if (leftValue === UnknownValue) {
10712
+ if (typeof leftValue === 'symbol') {
10598
10713
  return null;
10599
10714
  }
10600
10715
  else {
@@ -10780,21 +10895,32 @@ class NewExpression extends NodeBase {
10780
10895
  this.deoptimized = false;
10781
10896
  }
10782
10897
  hasEffects(context) {
10783
- if (!this.deoptimized)
10784
- this.applyDeoptimizations();
10785
- for (const argument of this.arguments) {
10786
- if (argument.hasEffects(context))
10787
- return true;
10898
+ try {
10899
+ for (const argument of this.arguments) {
10900
+ if (argument.hasEffects(context))
10901
+ return true;
10902
+ }
10903
+ if (this.context.options.treeshake.annotations &&
10904
+ this.annotations)
10905
+ return false;
10906
+ return (this.callee.hasEffects(context) ||
10907
+ this.callee.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
10908
+ }
10909
+ finally {
10910
+ if (!this.deoptimized)
10911
+ this.applyDeoptimizations();
10788
10912
  }
10789
- if (this.context.options.treeshake.annotations &&
10790
- this.annotations)
10791
- return false;
10792
- return (this.callee.hasEffects(context) ||
10793
- this.callee.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
10794
10913
  }
10795
10914
  hasEffectsWhenAccessedAtPath(path) {
10796
10915
  return path.length > 0;
10797
10916
  }
10917
+ include(context, includeChildrenRecursively) {
10918
+ if (!this.deoptimized)
10919
+ this.applyDeoptimizations();
10920
+ this.included = true;
10921
+ this.callee.include(context, includeChildrenRecursively);
10922
+ this.callee.includeArgumentsWhenCalledAtPath(EMPTY_PATH, context, this.arguments);
10923
+ }
10798
10924
  initialise() {
10799
10925
  this.callOptions = {
10800
10926
  args: this.arguments,
@@ -10841,6 +10967,9 @@ class ObjectExpression extends NodeBase {
10841
10967
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
10842
10968
  return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
10843
10969
  }
10970
+ includeArgumentsWhenCalledAtPath(path, context, args) {
10971
+ this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
10972
+ }
10844
10973
  render(code, options, { renderedSurroundingElement } = BLANK) {
10845
10974
  super.render(code, options);
10846
10975
  if (renderedSurroundingElement === ExpressionStatement$1 ||
@@ -10863,7 +10992,7 @@ class ObjectExpression extends NodeBase {
10863
10992
  let key;
10864
10993
  if (property.computed) {
10865
10994
  const keyValue = property.key.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
10866
- if (keyValue === UnknownValue) {
10995
+ if (typeof keyValue === 'symbol') {
10867
10996
  properties.push({ key: UnknownKey, kind: property.kind, property });
10868
10997
  continue;
10869
10998
  }
@@ -10984,8 +11113,8 @@ class PropertyDefinition extends NodeBase {
10984
11113
  : UNKNOWN_EXPRESSION;
10985
11114
  }
10986
11115
  hasEffects(context) {
10987
- return (this.key.hasEffects(context) ||
10988
- (this.static && this.value !== null && this.value.hasEffects(context)));
11116
+ var _a;
11117
+ return this.key.hasEffects(context) || (this.static && ((_a = this.value) === null || _a === void 0 ? void 0 : _a.hasEffects(context)));
10989
11118
  }
10990
11119
  hasEffectsWhenAccessedAtPath(path, context) {
10991
11120
  return !this.value || this.value.hasEffectsWhenAccessedAtPath(path, context);
@@ -10996,21 +11125,24 @@ class PropertyDefinition extends NodeBase {
10996
11125
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
10997
11126
  return !this.value || this.value.hasEffectsWhenCalledAtPath(path, callOptions, context);
10998
11127
  }
11128
+ includeArgumentsWhenCalledAtPath(path, context, args) {
11129
+ var _a;
11130
+ (_a = this.value) === null || _a === void 0 ? void 0 : _a.includeArgumentsWhenCalledAtPath(path, context, args);
11131
+ }
10999
11132
  }
11000
11133
 
11001
11134
  class ReturnStatement extends NodeBase {
11002
11135
  hasEffects(context) {
11003
- if (!context.ignore.returnYield ||
11004
- (this.argument !== null && this.argument.hasEffects(context)))
11136
+ var _a;
11137
+ if (!context.ignore.returnYield || ((_a = this.argument) === null || _a === void 0 ? void 0 : _a.hasEffects(context)))
11005
11138
  return true;
11006
11139
  context.brokenFlow = BROKEN_FLOW_ERROR_RETURN_LABEL;
11007
11140
  return false;
11008
11141
  }
11009
11142
  include(context, includeChildrenRecursively) {
11143
+ var _a;
11010
11144
  this.included = true;
11011
- if (this.argument) {
11012
- this.argument.include(context, includeChildrenRecursively);
11013
- }
11145
+ (_a = this.argument) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
11014
11146
  context.brokenFlow = BROKEN_FLOW_ERROR_RETURN_LABEL;
11015
11147
  }
11016
11148
  initialise() {
@@ -11130,6 +11262,9 @@ class Super extends NodeBase {
11130
11262
  deoptimizePath(path) {
11131
11263
  this.variable.deoptimizePath(path);
11132
11264
  }
11265
+ deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
11266
+ this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
11267
+ }
11133
11268
  include() {
11134
11269
  if (!this.included) {
11135
11270
  this.included = true;
@@ -11140,7 +11275,8 @@ class Super extends NodeBase {
11140
11275
 
11141
11276
  class SwitchCase extends NodeBase {
11142
11277
  hasEffects(context) {
11143
- if (this.test && this.test.hasEffects(context))
11278
+ var _a;
11279
+ if ((_a = this.test) === null || _a === void 0 ? void 0 : _a.hasEffects(context))
11144
11280
  return true;
11145
11281
  for (const node of this.consequent) {
11146
11282
  if (context.brokenFlow)
@@ -11151,9 +11287,9 @@ class SwitchCase extends NodeBase {
11151
11287
  return false;
11152
11288
  }
11153
11289
  include(context, includeChildrenRecursively) {
11290
+ var _a;
11154
11291
  this.included = true;
11155
- if (this.test)
11156
- this.test.include(context, includeChildrenRecursively);
11292
+ (_a = this.test) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
11157
11293
  for (const node of this.consequent) {
11158
11294
  if (includeChildrenRecursively || node.shouldBeIncluded(context))
11159
11295
  node.include(context, includeChildrenRecursively);
@@ -11246,7 +11382,7 @@ class SwitchStatement extends NodeBase {
11246
11382
  }
11247
11383
  }
11248
11384
 
11249
- class TaggedTemplateExpression extends NodeBase {
11385
+ class TaggedTemplateExpression extends CallExpressionBase {
11250
11386
  bind() {
11251
11387
  super.bind();
11252
11388
  if (this.tag.type === Identifier$1) {
@@ -11261,13 +11397,35 @@ class TaggedTemplateExpression extends NodeBase {
11261
11397
  }
11262
11398
  }
11263
11399
  hasEffects(context) {
11264
- return (super.hasEffects(context) ||
11265
- this.tag.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
11400
+ try {
11401
+ for (const argument of this.quasi.expressions) {
11402
+ if (argument.hasEffects(context))
11403
+ return true;
11404
+ }
11405
+ return (this.tag.hasEffects(context) ||
11406
+ this.tag.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
11407
+ }
11408
+ finally {
11409
+ if (!this.deoptimized)
11410
+ this.applyDeoptimizations();
11411
+ }
11412
+ }
11413
+ include(context, includeChildrenRecursively) {
11414
+ if (!this.deoptimized)
11415
+ this.applyDeoptimizations();
11416
+ this.included = true;
11417
+ this.tag.include(context, includeChildrenRecursively);
11418
+ this.quasi.include(context, includeChildrenRecursively);
11419
+ this.tag.includeArgumentsWhenCalledAtPath(EMPTY_PATH, context, this.callOptions.args);
11420
+ const returnExpression = this.getReturnExpression();
11421
+ if (!returnExpression.included) {
11422
+ returnExpression.include(context, false);
11423
+ }
11266
11424
  }
11267
11425
  initialise() {
11268
11426
  this.callOptions = {
11269
- args: NO_ARGS,
11270
- thisParam: null,
11427
+ args: [UNKNOWN_EXPRESSION, ...this.quasi.expressions],
11428
+ thisParam: this.tag instanceof MemberExpression && !this.tag.variable ? this.tag.object : null,
11271
11429
  withNew: false
11272
11430
  };
11273
11431
  }
@@ -11275,6 +11433,25 @@ class TaggedTemplateExpression extends NodeBase {
11275
11433
  this.tag.render(code, options, { isCalleeOfRenderedParent: true });
11276
11434
  this.quasi.render(code, options);
11277
11435
  }
11436
+ applyDeoptimizations() {
11437
+ this.deoptimized = true;
11438
+ const { thisParam } = this.callOptions;
11439
+ if (thisParam) {
11440
+ this.tag.deoptimizeThisOnEventAtPath(EVENT_CALLED, EMPTY_PATH, thisParam, SHARED_RECURSION_TRACKER);
11441
+ }
11442
+ for (const argument of this.quasi.expressions) {
11443
+ // This will make sure all properties of parameters behave as "unknown"
11444
+ argument.deoptimizePath(UNKNOWN_PATH);
11445
+ }
11446
+ this.context.requestTreeshakingPass();
11447
+ }
11448
+ getReturnExpression(recursionTracker = SHARED_RECURSION_TRACKER) {
11449
+ if (this.returnExpression === null) {
11450
+ this.returnExpression = UNKNOWN_EXPRESSION;
11451
+ return (this.returnExpression = this.tag.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.callOptions, recursionTracker, this));
11452
+ }
11453
+ return this.returnExpression;
11454
+ }
11278
11455
  }
11279
11456
 
11280
11457
  class TemplateElement extends NodeBase {
@@ -11486,13 +11663,15 @@ class TryStatement extends NodeBase {
11486
11663
  this.includedLabelsAfterBlock = null;
11487
11664
  }
11488
11665
  hasEffects(context) {
11666
+ var _a;
11489
11667
  return ((this.context.options.treeshake.tryCatchDeoptimization
11490
11668
  ? this.block.body.length > 0
11491
11669
  : this.block.hasEffects(context)) ||
11492
- (this.finalizer !== null && this.finalizer.hasEffects(context)));
11670
+ ((_a = this.finalizer) === null || _a === void 0 ? void 0 : _a.hasEffects(context)) ||
11671
+ false);
11493
11672
  }
11494
11673
  include(context, includeChildrenRecursively) {
11495
- var _a;
11674
+ var _a, _b;
11496
11675
  const tryCatchDeoptimization = (_a = this.context.options.treeshake) === null || _a === void 0 ? void 0 : _a.tryCatchDeoptimization;
11497
11676
  const { brokenFlow } = context;
11498
11677
  if (!this.directlyIncluded || !tryCatchDeoptimization) {
@@ -11513,9 +11692,7 @@ class TryStatement extends NodeBase {
11513
11692
  this.handler.include(context, includeChildrenRecursively);
11514
11693
  context.brokenFlow = brokenFlow;
11515
11694
  }
11516
- if (this.finalizer !== null) {
11517
- this.finalizer.include(context, includeChildrenRecursively);
11518
- }
11695
+ (_b = this.finalizer) === null || _b === void 0 ? void 0 : _b.include(context, includeChildrenRecursively);
11519
11696
  }
11520
11697
  }
11521
11698
 
@@ -11537,7 +11714,7 @@ class UnaryExpression extends NodeBase {
11537
11714
  if (path.length > 0)
11538
11715
  return UnknownValue;
11539
11716
  const argumentValue = this.argument.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
11540
- if (argumentValue === UnknownValue)
11717
+ if (typeof argumentValue === 'symbol')
11541
11718
  return UnknownValue;
11542
11719
  return unaryOperators[this.operator](argumentValue);
11543
11720
  }
@@ -11651,18 +11828,12 @@ class VariableDeclaration extends NodeBase {
11651
11828
  hasEffectsWhenAssignedAtPath() {
11652
11829
  return false;
11653
11830
  }
11654
- include(context, includeChildrenRecursively) {
11831
+ include(context, includeChildrenRecursively, { asSingleStatement } = BLANK) {
11655
11832
  this.included = true;
11656
11833
  for (const declarator of this.declarations) {
11657
11834
  if (includeChildrenRecursively || declarator.shouldBeIncluded(context))
11658
11835
  declarator.include(context, includeChildrenRecursively);
11659
- }
11660
- }
11661
- includeAsSingleStatement(context, includeChildrenRecursively) {
11662
- this.included = true;
11663
- for (const declarator of this.declarations) {
11664
- if (includeChildrenRecursively || declarator.shouldBeIncluded(context)) {
11665
- declarator.include(context, includeChildrenRecursively);
11836
+ if (asSingleStatement) {
11666
11837
  declarator.id.include(context, includeChildrenRecursively);
11667
11838
  }
11668
11839
  }
@@ -11810,15 +11981,15 @@ class VariableDeclarator extends NodeBase {
11810
11981
  this.id.deoptimizePath(path);
11811
11982
  }
11812
11983
  hasEffects(context) {
11813
- const initEffect = this.init !== null && this.init.hasEffects(context);
11984
+ var _a;
11985
+ const initEffect = (_a = this.init) === null || _a === void 0 ? void 0 : _a.hasEffects(context);
11814
11986
  this.id.markDeclarationReached();
11815
11987
  return initEffect || this.id.hasEffects(context);
11816
11988
  }
11817
11989
  include(context, includeChildrenRecursively) {
11990
+ var _a;
11818
11991
  this.included = true;
11819
- if (this.init) {
11820
- this.init.include(context, includeChildrenRecursively);
11821
- }
11992
+ (_a = this.init) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
11822
11993
  this.id.markDeclarationReached();
11823
11994
  if (includeChildrenRecursively || this.id.shouldBeIncluded(context)) {
11824
11995
  this.id.include(context, includeChildrenRecursively);
@@ -11862,7 +12033,7 @@ class WhileStatement extends NodeBase {
11862
12033
  this.included = true;
11863
12034
  this.test.include(context, includeChildrenRecursively);
11864
12035
  const { brokenFlow } = context;
11865
- this.body.includeAsSingleStatement(context, includeChildrenRecursively);
12036
+ this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
11866
12037
  context.brokenFlow = brokenFlow;
11867
12038
  }
11868
12039
  }
@@ -11873,9 +12044,10 @@ class YieldExpression extends NodeBase {
11873
12044
  this.deoptimized = false;
11874
12045
  }
11875
12046
  hasEffects(context) {
12047
+ var _a;
11876
12048
  if (!this.deoptimized)
11877
12049
  this.applyDeoptimizations();
11878
- return (!context.ignore.returnYield || (this.argument !== null && this.argument.hasEffects(context)));
12050
+ return !context.ignore.returnYield || ((_a = this.argument) === null || _a === void 0 ? void 0 : _a.hasEffects(context));
11879
12051
  }
11880
12052
  render(code, options) {
11881
12053
  if (this.argument) {
@@ -11885,14 +12057,6 @@ class YieldExpression extends NodeBase {
11885
12057
  }
11886
12058
  }
11887
12059
  }
11888
- applyDeoptimizations() {
11889
- this.deoptimized = true;
11890
- const { argument } = this;
11891
- if (argument) {
11892
- argument.deoptimizePath(UNKNOWN_PATH);
11893
- this.context.requestTreeshakingPass();
11894
- }
11895
- }
11896
12060
  }
11897
12061
 
11898
12062
  const nodeConstructors = {
@@ -12321,8 +12485,8 @@ class Module {
12321
12485
  this.importMetas = [];
12322
12486
  this.importedFromNotTreeshaken = false;
12323
12487
  this.importers = [];
12324
- this.imports = new Set();
12325
12488
  this.includedDynamicImporters = [];
12489
+ this.includedImports = new Set();
12326
12490
  this.isExecuted = false;
12327
12491
  this.isUserDefinedEntryPoint = false;
12328
12492
  this.needsExportShim = false;
@@ -12451,7 +12615,7 @@ class Module {
12451
12615
  this.relevantDependencies = new Set();
12452
12616
  const necessaryDependencies = new Set();
12453
12617
  const alwaysCheckedDependencies = new Set();
12454
- const dependencyVariables = new Set(this.imports);
12618
+ const dependencyVariables = new Set(this.includedImports);
12455
12619
  if (this.info.isEntry ||
12456
12620
  this.includedDynamicImporters.length > 0 ||
12457
12621
  this.namespace.included ||
@@ -13029,13 +13193,13 @@ class Module {
13029
13193
  if (module instanceof ExternalModule) {
13030
13194
  const [externalVariable] = module.getVariableForExportName('*');
13031
13195
  externalVariable.include();
13032
- this.imports.add(externalVariable);
13196
+ this.includedImports.add(externalVariable);
13033
13197
  externalNamespaces.add(externalVariable);
13034
13198
  }
13035
13199
  else if (module.info.syntheticNamedExports) {
13036
13200
  const syntheticNamespace = module.getSyntheticNamespace();
13037
13201
  syntheticNamespace.include();
13038
- this.imports.add(syntheticNamespace);
13202
+ this.includedImports.add(syntheticNamespace);
13039
13203
  syntheticNamespaces.add(syntheticNamespace);
13040
13204
  }
13041
13205
  }
@@ -13072,7 +13236,7 @@ class Module {
13072
13236
  this.includeVariable(variable);
13073
13237
  const variableModule = variable.module;
13074
13238
  if (variableModule && variableModule !== this) {
13075
- this.imports.add(variable);
13239
+ this.includedImports.add(variable);
13076
13240
  }
13077
13241
  }
13078
13242
  shimMissingExport(name) {
@@ -14404,6 +14568,7 @@ class Chunk {
14404
14568
  this.implicitEntryModules = [];
14405
14569
  this.implicitlyLoadedBefore = new Set();
14406
14570
  this.imports = new Set();
14571
+ this.includedReexportsByModule = new Map();
14407
14572
  this.indentString = undefined;
14408
14573
  // This may only be updated in the constructor
14409
14574
  this.isEmpty = true;
@@ -14575,6 +14740,9 @@ class Chunk {
14575
14740
  this.exports.add(module.namespace);
14576
14741
  }
14577
14742
  }
14743
+ if (!this.outputOptions.preserveModules) {
14744
+ this.addNecessaryImportsForFacades();
14745
+ }
14578
14746
  return facades;
14579
14747
  }
14580
14748
  generateId(addons, options, existingNames, includeHash) {
@@ -14917,6 +15085,15 @@ class Chunk {
14917
15085
  }
14918
15086
  }
14919
15087
  }
15088
+ addNecessaryImportsForFacades() {
15089
+ for (const [module, variables] of this.includedReexportsByModule) {
15090
+ if (this.includedNamespaces.has(module)) {
15091
+ for (const variable of variables) {
15092
+ this.imports.add(variable);
15093
+ }
15094
+ }
15095
+ }
15096
+ }
14920
15097
  assignFacadeName({ fileName, name }, facadedModule) {
14921
15098
  if (fileName) {
14922
15099
  this.fileName = fileName;
@@ -14964,6 +15141,7 @@ class Chunk {
14964
15141
  return hash.digest('hex').substr(0, 8);
14965
15142
  }
14966
15143
  ensureReexportsAreAvailableForModule(module) {
15144
+ const includedReexports = [];
14967
15145
  const map = module.getExportNamesByVariable();
14968
15146
  for (const exportedVariable of map.keys()) {
14969
15147
  const isSynthetic = exportedVariable instanceof SyntheticNamedExportVariable;
@@ -14977,6 +15155,7 @@ class Chunk {
14977
15155
  const chunk = this.chunkByModule.get(exportingModule);
14978
15156
  if (chunk && chunk !== this) {
14979
15157
  chunk.exports.add(importedVariable);
15158
+ includedReexports.push(importedVariable);
14980
15159
  if (isSynthetic) {
14981
15160
  this.imports.add(importedVariable);
14982
15161
  }
@@ -14984,6 +15163,9 @@ class Chunk {
14984
15163
  }
14985
15164
  }
14986
15165
  }
15166
+ if (includedReexports.length) {
15167
+ this.includedReexportsByModule.set(module, includedReexports);
15168
+ }
14987
15169
  }
14988
15170
  finaliseDynamicImports(options, snippets) {
14989
15171
  const stripKnownJsExtensions = options.format === 'amd';
@@ -15339,7 +15521,7 @@ class Chunk {
15339
15521
  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);
15340
15522
  }
15341
15523
  setUpChunkImportsAndExportsForModule(module) {
15342
- const moduleImports = new Set(module.imports);
15524
+ const moduleImports = new Set(module.includedImports);
15343
15525
  // when we are not preserving modules, we need to make all namespace variables available for
15344
15526
  // rendering the namespace object
15345
15527
  if (!this.outputOptions.preserveModules) {
@@ -23016,6 +23198,12 @@ function formatAction([pluginName, hookName, args]) {
23016
23198
  }
23017
23199
  return action;
23018
23200
  }
23201
+ // We do not directly listen on process to avoid max listeners warnings for
23202
+ // complicated build processes
23203
+ const beforeExitEvent = 'beforeExit';
23204
+ const beforeExitEmitter = new EventEmitter();
23205
+ beforeExitEmitter.setMaxListeners(0);
23206
+ process$1.on(beforeExitEvent, () => beforeExitEmitter.emit(beforeExitEvent));
23019
23207
  async function catchUnfinishedHookActions(pluginDriver, callback) {
23020
23208
  let handleEmptyEventLoop;
23021
23209
  const emptyEventLoopPromise = new Promise((_, reject) => {
@@ -23024,10 +23212,10 @@ async function catchUnfinishedHookActions(pluginDriver, callback) {
23024
23212
  reject(new Error(`Unexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit:\n` +
23025
23213
  [...unfulfilledActions].map(formatAction).join('\n')));
23026
23214
  };
23027
- process$1.once('beforeExit', handleEmptyEventLoop);
23215
+ beforeExitEmitter.once(beforeExitEvent, handleEmptyEventLoop);
23028
23216
  });
23029
23217
  const result = await Promise.race([callback(), emptyEventLoopPromise]);
23030
- process$1.off('beforeExit', handleEmptyEventLoop);
23218
+ beforeExitEmitter.off(beforeExitEvent, handleEmptyEventLoop);
23031
23219
  return result;
23032
23220
  }
23033
23221