rollup 2.74.1 → 2.75.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.74.1
4
- Thu, 19 May 2022 17:50:11 GMT - commit e823eded9920d6082cc8c1afcf591b716ab6b160
3
+ Rollup.js v2.75.0
4
+ Fri, 27 May 2022 08:24:10 GMT - commit c1d62262beb6e743a1b507aecad99cb03f446741
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -27,7 +27,7 @@ function _interopNamespaceDefault(e) {
27
27
  return n;
28
28
  }
29
29
 
30
- var version$1 = "2.74.1";
30
+ var version$1 = "2.75.0";
31
31
 
32
32
  function ensureArray$1(items) {
33
33
  if (Array.isArray(items)) {
@@ -2222,6 +2222,7 @@ class DiscriminatedPathTracker {
2222
2222
  }
2223
2223
 
2224
2224
  const UnknownValue = Symbol('Unknown Value');
2225
+ const UnknownTruthyValue = Symbol('Unknown Truthy Value');
2225
2226
  class ExpressionEntity {
2226
2227
  constructor() {
2227
2228
  this.included = false;
@@ -2250,7 +2251,7 @@ class ExpressionEntity {
2250
2251
  hasEffectsWhenCalledAtPath(_path, _callOptions, _context) {
2251
2252
  return true;
2252
2253
  }
2253
- include(_context, _includeChildrenRecursively) {
2254
+ include(_context, _includeChildrenRecursively, _options) {
2254
2255
  this.included = true;
2255
2256
  }
2256
2257
  includeCallArguments(context, args) {
@@ -2258,6 +2259,9 @@ class ExpressionEntity {
2258
2259
  arg.include(context, false);
2259
2260
  }
2260
2261
  }
2262
+ shouldBeIncluded(_context) {
2263
+ return true;
2264
+ }
2261
2265
  }
2262
2266
  const UNKNOWN_EXPRESSION = new (class UnknownExpression extends ExpressionEntity {
2263
2267
  })();
@@ -4796,9 +4800,9 @@ const stringReplace = {
4796
4800
  hasEffectsWhenCalled(callOptions, context) {
4797
4801
  const arg1 = callOptions.args[1];
4798
4802
  return (callOptions.args.length < 2 ||
4799
- (arg1.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, {
4803
+ (typeof arg1.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, {
4800
4804
  deoptimizeCache() { }
4801
- }) === UnknownValue &&
4805
+ }) === 'symbol' &&
4802
4806
  arg1.hasEffectsWhenCalledAtPath(EMPTY_PATH, {
4803
4807
  args: NO_ARGS,
4804
4808
  thisParam: null,
@@ -5353,8 +5357,7 @@ class NodeBase extends ExpressionEntity {
5353
5357
  continue;
5354
5358
  if (Array.isArray(value)) {
5355
5359
  for (const child of value) {
5356
- if (child !== null)
5357
- child.bind();
5360
+ child === null || child === void 0 ? void 0 : child.bind();
5358
5361
  }
5359
5362
  }
5360
5363
  else {
@@ -5377,7 +5380,7 @@ class NodeBase extends ExpressionEntity {
5377
5380
  continue;
5378
5381
  if (Array.isArray(value)) {
5379
5382
  for (const child of value) {
5380
- if (child !== null && child.hasEffects(context))
5383
+ if (child === null || child === void 0 ? void 0 : child.hasEffects(context))
5381
5384
  return true;
5382
5385
  }
5383
5386
  }
@@ -5386,7 +5389,7 @@ class NodeBase extends ExpressionEntity {
5386
5389
  }
5387
5390
  return false;
5388
5391
  }
5389
- include(context, includeChildrenRecursively) {
5392
+ include(context, includeChildrenRecursively, _options) {
5390
5393
  if (this.deoptimized === false)
5391
5394
  this.applyDeoptimizations();
5392
5395
  this.included = true;
@@ -5396,8 +5399,7 @@ class NodeBase extends ExpressionEntity {
5396
5399
  continue;
5397
5400
  if (Array.isArray(value)) {
5398
5401
  for (const child of value) {
5399
- if (child !== null)
5400
- child.include(context, includeChildrenRecursively);
5402
+ child === null || child === void 0 ? void 0 : child.include(context, includeChildrenRecursively);
5401
5403
  }
5402
5404
  }
5403
5405
  else {
@@ -5405,9 +5407,6 @@ class NodeBase extends ExpressionEntity {
5405
5407
  }
5406
5408
  }
5407
5409
  }
5408
- includeAsSingleStatement(context, includeChildrenRecursively) {
5409
- this.include(context, includeChildrenRecursively);
5410
- }
5411
5410
  /**
5412
5411
  * Override to perform special initialisation steps after the scope is initialised
5413
5412
  */
@@ -5454,8 +5453,7 @@ class NodeBase extends ExpressionEntity {
5454
5453
  continue;
5455
5454
  if (Array.isArray(value)) {
5456
5455
  for (const child of value) {
5457
- if (child !== null)
5458
- child.render(code, options);
5456
+ child === null || child === void 0 ? void 0 : child.render(code, options);
5459
5457
  }
5460
5458
  }
5461
5459
  else {
@@ -5466,7 +5464,28 @@ class NodeBase extends ExpressionEntity {
5466
5464
  shouldBeIncluded(context) {
5467
5465
  return this.included || (!context.brokenFlow && this.hasEffects(createHasEffectsContext()));
5468
5466
  }
5469
- applyDeoptimizations() { }
5467
+ /**
5468
+ * Just deoptimize everything by default so that when e.g. we do not track
5469
+ * something properly, it is deoptimized.
5470
+ * @protected
5471
+ */
5472
+ applyDeoptimizations() {
5473
+ this.deoptimized = true;
5474
+ for (const key of this.keys) {
5475
+ const value = this[key];
5476
+ if (value === null)
5477
+ continue;
5478
+ if (Array.isArray(value)) {
5479
+ for (const child of value) {
5480
+ child === null || child === void 0 ? void 0 : child.deoptimizePath(UNKNOWN_PATH);
5481
+ }
5482
+ }
5483
+ else {
5484
+ value.deoptimizePath(UNKNOWN_PATH);
5485
+ }
5486
+ }
5487
+ this.context.requestTreeshakingPass();
5488
+ }
5470
5489
  }
5471
5490
 
5472
5491
  class SpreadElement extends NodeBase {
@@ -5548,11 +5567,6 @@ class Method extends ExpressionEntity {
5548
5567
  }
5549
5568
  return false;
5550
5569
  }
5551
- includeCallArguments(context, args) {
5552
- for (const arg of args) {
5553
- arg.include(context, false);
5554
- }
5555
- }
5556
5570
  }
5557
5571
  const METHOD_RETURNS_BOOLEAN = [
5558
5572
  new Method({
@@ -5752,7 +5766,7 @@ class ObjectEntity extends ExpressionEntity {
5752
5766
  }
5753
5767
  getLiteralValueAtPath(path, recursionTracker, origin) {
5754
5768
  if (path.length === 0) {
5755
- return UnknownValue;
5769
+ return UnknownTruthyValue;
5756
5770
  }
5757
5771
  const key = path[0];
5758
5772
  const expressionAtPath = this.getMemberExpressionAndTrackDeopt(key, origin);
@@ -6157,6 +6171,7 @@ const ARRAY_PROTOTYPE = new ObjectEntity({
6157
6171
  class ArrayExpression extends NodeBase {
6158
6172
  constructor() {
6159
6173
  super(...arguments);
6174
+ this.deoptimized = false;
6160
6175
  this.objectEntity = null;
6161
6176
  }
6162
6177
  deoptimizePath(path) {
@@ -6180,6 +6195,20 @@ class ArrayExpression extends NodeBase {
6180
6195
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
6181
6196
  return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
6182
6197
  }
6198
+ applyDeoptimizations() {
6199
+ this.deoptimized = true;
6200
+ let hasSpread = false;
6201
+ for (let index = 0; index < this.elements.length; index++) {
6202
+ const element = this.elements[index];
6203
+ if (hasSpread || element instanceof SpreadElement) {
6204
+ if (element) {
6205
+ hasSpread = true;
6206
+ element.deoptimizePath(UNKNOWN_PATH);
6207
+ }
6208
+ }
6209
+ }
6210
+ this.context.requestTreeshakingPass();
6211
+ }
6183
6212
  getObjectEntity() {
6184
6213
  if (this.objectEntity !== null) {
6185
6214
  return this.objectEntity;
@@ -6190,7 +6219,7 @@ class ArrayExpression extends NodeBase {
6190
6219
  let hasSpread = false;
6191
6220
  for (let index = 0; index < this.elements.length; index++) {
6192
6221
  const element = this.elements[index];
6193
- if (element instanceof SpreadElement || hasSpread) {
6222
+ if (hasSpread || element instanceof SpreadElement) {
6194
6223
  if (element) {
6195
6224
  hasSpread = true;
6196
6225
  properties.unshift({ key: UnknownInteger, kind: 'init', property: element });
@@ -6210,9 +6239,7 @@ class ArrayExpression extends NodeBase {
6210
6239
  class ArrayPattern extends NodeBase {
6211
6240
  addExportedVariables(variables, exportNamesByVariable) {
6212
6241
  for (const element of this.elements) {
6213
- if (element !== null) {
6214
- element.addExportedVariables(variables, exportNamesByVariable);
6215
- }
6242
+ element === null || element === void 0 ? void 0 : element.addExportedVariables(variables, exportNamesByVariable);
6216
6243
  }
6217
6244
  }
6218
6245
  declare(kind) {
@@ -6224,29 +6251,23 @@ class ArrayPattern extends NodeBase {
6224
6251
  }
6225
6252
  return variables;
6226
6253
  }
6227
- deoptimizePath(path) {
6228
- if (path.length === 0) {
6229
- for (const element of this.elements) {
6230
- if (element !== null) {
6231
- element.deoptimizePath(path);
6232
- }
6233
- }
6254
+ // Patterns can only be deoptimized at the empty path at the moment
6255
+ deoptimizePath() {
6256
+ for (const element of this.elements) {
6257
+ element === null || element === void 0 ? void 0 : element.deoptimizePath(EMPTY_PATH);
6234
6258
  }
6235
6259
  }
6236
- hasEffectsWhenAssignedAtPath(path, context) {
6237
- if (path.length > 0)
6238
- return true;
6260
+ // Patterns are only checked at the emtpy path at the moment
6261
+ hasEffectsWhenAssignedAtPath(_path, context) {
6239
6262
  for (const element of this.elements) {
6240
- if (element !== null && element.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context))
6263
+ if (element === null || element === void 0 ? void 0 : element.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context))
6241
6264
  return true;
6242
6265
  }
6243
6266
  return false;
6244
6267
  }
6245
6268
  markDeclarationReached() {
6246
6269
  for (const element of this.elements) {
6247
- if (element !== null) {
6248
- element.markDeclarationReached();
6249
- }
6270
+ element === null || element === void 0 ? void 0 : element.markDeclarationReached();
6250
6271
  }
6251
6272
  }
6252
6273
  }
@@ -6622,1579 +6643,1661 @@ class ReturnValueScope extends ParameterScope {
6622
6643
  }
6623
6644
  }
6624
6645
 
6625
- //@ts-check
6626
- /** @typedef { import('estree').Node} Node */
6627
- /** @typedef {Node | {
6628
- * type: 'PropertyDefinition';
6629
- * computed: boolean;
6630
- * value: Node
6631
- * }} NodeWithPropertyDefinition */
6632
-
6633
- /**
6634
- *
6635
- * @param {NodeWithPropertyDefinition} node
6636
- * @param {NodeWithPropertyDefinition} parent
6637
- * @returns boolean
6638
- */
6639
- function is_reference (node, parent) {
6640
- if (node.type === 'MemberExpression') {
6641
- return !node.computed && is_reference(node.object, node);
6642
- }
6643
-
6644
- if (node.type === 'Identifier') {
6645
- if (!parent) return true;
6646
-
6647
- switch (parent.type) {
6648
- // disregard `bar` in `foo.bar`
6649
- case 'MemberExpression': return parent.computed || node === parent.object;
6650
-
6651
- // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
6652
- case 'MethodDefinition': return parent.computed;
6653
-
6654
- // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
6655
- case 'PropertyDefinition': return parent.computed || node === parent.value;
6656
-
6657
- // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
6658
- case 'Property': return parent.computed || node === parent.value;
6659
-
6660
- // disregard the `bar` in `export { foo as bar }` or
6661
- // the foo in `import { foo as bar }`
6662
- case 'ExportSpecifier':
6663
- case 'ImportSpecifier': return node === parent.local;
6664
-
6665
- // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
6666
- case 'LabeledStatement':
6667
- case 'BreakStatement':
6668
- case 'ContinueStatement': return false;
6669
- default: return true;
6670
- }
6671
- }
6672
-
6673
- return false;
6646
+ class AssignmentPattern extends NodeBase {
6647
+ constructor() {
6648
+ super(...arguments);
6649
+ this.deoptimized = false;
6650
+ }
6651
+ addExportedVariables(variables, exportNamesByVariable) {
6652
+ this.left.addExportedVariables(variables, exportNamesByVariable);
6653
+ }
6654
+ declare(kind, init) {
6655
+ return this.left.declare(kind, init);
6656
+ }
6657
+ deoptimizePath(path) {
6658
+ path.length === 0 && this.left.deoptimizePath(path);
6659
+ }
6660
+ hasEffectsWhenAssignedAtPath(path, context) {
6661
+ return path.length > 0 || this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
6662
+ }
6663
+ // Note that FunctionBase may directly include .left and .right without
6664
+ // including the pattern itself. This is how default parameter tree-shaking
6665
+ // works at the moment.
6666
+ include(context, includeChildrenRecursively) {
6667
+ this.included = true;
6668
+ this.left.include(context, includeChildrenRecursively);
6669
+ this.right.include(context, includeChildrenRecursively);
6670
+ }
6671
+ markDeclarationReached() {
6672
+ this.left.markDeclarationReached();
6673
+ }
6674
+ render(code, options, { isShorthandProperty } = BLANK) {
6675
+ this.left.render(code, options, { isShorthandProperty });
6676
+ if (this.right.included) {
6677
+ this.right.render(code, options);
6678
+ }
6679
+ else {
6680
+ code.remove(this.left.end, this.end);
6681
+ }
6682
+ }
6683
+ applyDeoptimizations() {
6684
+ this.deoptimized = true;
6685
+ this.left.deoptimizePath(EMPTY_PATH);
6686
+ this.right.deoptimizePath(UNKNOWN_PATH);
6687
+ this.context.requestTreeshakingPass();
6688
+ }
6674
6689
  }
6675
6690
 
6676
- /* eslint sort-keys: "off" */
6677
- const ValueProperties = Symbol('Value Properties');
6678
- const PURE = {
6679
- hasEffectsWhenCalled() {
6680
- return false;
6691
+ function treeshakeNode(node, code, start, end) {
6692
+ code.remove(start, end);
6693
+ if (node.annotations) {
6694
+ for (const annotation of node.annotations) {
6695
+ if (annotation.start < start) {
6696
+ code.remove(annotation.start, annotation.end);
6697
+ }
6698
+ else {
6699
+ return;
6700
+ }
6701
+ }
6681
6702
  }
6682
- };
6683
- const IMPURE = {
6684
- hasEffectsWhenCalled() {
6685
- return true;
6703
+ }
6704
+ function removeAnnotations(node, code) {
6705
+ if (!node.annotations && node.parent.type === ExpressionStatement$1) {
6706
+ node = node.parent;
6686
6707
  }
6687
- };
6688
- // We use shortened variables to reduce file size here
6689
- /* OBJECT */
6690
- const O = {
6691
- __proto__: null,
6692
- [ValueProperties]: IMPURE
6693
- };
6694
- /* PURE FUNCTION */
6695
- const PF = {
6696
- __proto__: null,
6697
- [ValueProperties]: PURE
6698
- };
6699
- /* FUNCTION THAT MUTATES FIRST ARG WITHOUT TRIGGERING ACCESSORS */
6700
- const MUTATES_ARG_WITHOUT_ACCESSOR = {
6701
- __proto__: null,
6702
- [ValueProperties]: {
6703
- hasEffectsWhenCalled(callOptions, context) {
6704
- return (!callOptions.args.length ||
6705
- callOptions.args[0].hasEffectsWhenAssignedAtPath(UNKNOWN_NON_ACCESSOR_PATH, context));
6708
+ if (node.annotations) {
6709
+ for (const annotation of node.annotations) {
6710
+ code.remove(annotation.start, annotation.end);
6706
6711
  }
6707
6712
  }
6708
- };
6709
- /* CONSTRUCTOR */
6710
- const C = {
6711
- __proto__: null,
6712
- [ValueProperties]: IMPURE,
6713
- prototype: O
6714
- };
6715
- /* PURE CONSTRUCTOR */
6716
- const PC = {
6717
- __proto__: null,
6718
- [ValueProperties]: PURE,
6719
- prototype: O
6720
- };
6721
- const ARRAY_TYPE = {
6722
- __proto__: null,
6723
- [ValueProperties]: PURE,
6724
- from: PF,
6725
- of: PF,
6726
- prototype: O
6727
- };
6728
- const INTL_MEMBER = {
6729
- __proto__: null,
6730
- [ValueProperties]: PURE,
6731
- supportedLocalesOf: PC
6732
- };
6733
- const knownGlobals = {
6734
- // Placeholders for global objects to avoid shape mutations
6735
- global: O,
6736
- globalThis: O,
6737
- self: O,
6738
- window: O,
6739
- // Common globals
6740
- __proto__: null,
6741
- [ValueProperties]: IMPURE,
6742
- Array: {
6743
- __proto__: null,
6744
- [ValueProperties]: IMPURE,
6745
- from: O,
6746
- isArray: PF,
6747
- of: PF,
6748
- prototype: O
6749
- },
6750
- ArrayBuffer: {
6751
- __proto__: null,
6752
- [ValueProperties]: PURE,
6753
- isView: PF,
6754
- prototype: O
6755
- },
6756
- Atomics: O,
6757
- BigInt: C,
6758
- BigInt64Array: C,
6759
- BigUint64Array: C,
6760
- Boolean: PC,
6761
- constructor: C,
6762
- DataView: PC,
6763
- Date: {
6764
- __proto__: null,
6765
- [ValueProperties]: PURE,
6766
- now: PF,
6767
- parse: PF,
6768
- prototype: O,
6769
- UTC: PF
6770
- },
6771
- decodeURI: PF,
6772
- decodeURIComponent: PF,
6773
- encodeURI: PF,
6774
- encodeURIComponent: PF,
6775
- Error: PC,
6776
- escape: PF,
6777
- eval: O,
6778
- EvalError: PC,
6779
- Float32Array: ARRAY_TYPE,
6780
- Float64Array: ARRAY_TYPE,
6781
- Function: C,
6782
- hasOwnProperty: O,
6783
- Infinity: O,
6784
- Int16Array: ARRAY_TYPE,
6785
- Int32Array: ARRAY_TYPE,
6786
- Int8Array: ARRAY_TYPE,
6787
- isFinite: PF,
6788
- isNaN: PF,
6789
- isPrototypeOf: O,
6790
- JSON: O,
6791
- Map: PC,
6792
- Math: {
6793
- __proto__: null,
6794
- [ValueProperties]: IMPURE,
6795
- abs: PF,
6796
- acos: PF,
6797
- acosh: PF,
6798
- asin: PF,
6799
- asinh: PF,
6800
- atan: PF,
6801
- atan2: PF,
6802
- atanh: PF,
6803
- cbrt: PF,
6804
- ceil: PF,
6805
- clz32: PF,
6806
- cos: PF,
6807
- cosh: PF,
6808
- exp: PF,
6809
- expm1: PF,
6810
- floor: PF,
6811
- fround: PF,
6812
- hypot: PF,
6813
- imul: PF,
6814
- log: PF,
6815
- log10: PF,
6816
- log1p: PF,
6817
- log2: PF,
6818
- max: PF,
6819
- min: PF,
6820
- pow: PF,
6821
- random: PF,
6822
- round: PF,
6823
- sign: PF,
6824
- sin: PF,
6825
- sinh: PF,
6826
- sqrt: PF,
6827
- tan: PF,
6828
- tanh: PF,
6829
- trunc: PF
6830
- },
6831
- NaN: O,
6832
- Number: {
6833
- __proto__: null,
6834
- [ValueProperties]: PURE,
6835
- isFinite: PF,
6836
- isInteger: PF,
6837
- isNaN: PF,
6838
- isSafeInteger: PF,
6839
- parseFloat: PF,
6840
- parseInt: PF,
6841
- prototype: O
6842
- },
6843
- Object: {
6844
- __proto__: null,
6845
- [ValueProperties]: PURE,
6846
- create: PF,
6847
- // Technically those can throw in certain situations, but we ignore this as
6848
- // code that relies on this will hopefully wrap this in a try-catch, which
6849
- // deoptimizes everything anyway
6850
- defineProperty: MUTATES_ARG_WITHOUT_ACCESSOR,
6851
- defineProperties: MUTATES_ARG_WITHOUT_ACCESSOR,
6852
- getOwnPropertyDescriptor: PF,
6853
- getOwnPropertyNames: PF,
6854
- getOwnPropertySymbols: PF,
6855
- getPrototypeOf: PF,
6856
- hasOwn: PF,
6857
- is: PF,
6858
- isExtensible: PF,
6859
- isFrozen: PF,
6860
- isSealed: PF,
6861
- keys: PF,
6862
- fromEntries: PF,
6863
- entries: PF,
6864
- prototype: O
6865
- },
6866
- parseFloat: PF,
6867
- parseInt: PF,
6868
- Promise: {
6869
- __proto__: null,
6870
- [ValueProperties]: IMPURE,
6871
- all: O,
6872
- prototype: O,
6873
- race: O,
6874
- reject: O,
6875
- resolve: O
6876
- },
6877
- propertyIsEnumerable: O,
6878
- Proxy: O,
6879
- RangeError: PC,
6880
- ReferenceError: PC,
6881
- Reflect: O,
6882
- RegExp: PC,
6883
- Set: PC,
6884
- SharedArrayBuffer: C,
6885
- String: {
6886
- __proto__: null,
6887
- [ValueProperties]: PURE,
6888
- fromCharCode: PF,
6889
- fromCodePoint: PF,
6890
- prototype: O,
6891
- raw: PF
6892
- },
6893
- Symbol: {
6894
- __proto__: null,
6895
- [ValueProperties]: PURE,
6896
- for: PF,
6897
- keyFor: PF,
6898
- prototype: O
6899
- },
6900
- SyntaxError: PC,
6901
- toLocaleString: O,
6902
- toString: O,
6903
- TypeError: PC,
6904
- Uint16Array: ARRAY_TYPE,
6905
- Uint32Array: ARRAY_TYPE,
6906
- Uint8Array: ARRAY_TYPE,
6907
- Uint8ClampedArray: ARRAY_TYPE,
6908
- // Technically, this is a global, but it needs special handling
6909
- // undefined: ?,
6910
- unescape: PF,
6911
- URIError: PC,
6912
- valueOf: O,
6913
- WeakMap: PC,
6914
- WeakSet: PC,
6915
- // Additional globals shared by Node and Browser that are not strictly part of the language
6916
- clearInterval: C,
6917
- clearTimeout: C,
6918
- console: O,
6919
- Intl: {
6920
- __proto__: null,
6921
- [ValueProperties]: IMPURE,
6922
- Collator: INTL_MEMBER,
6923
- DateTimeFormat: INTL_MEMBER,
6924
- ListFormat: INTL_MEMBER,
6925
- NumberFormat: INTL_MEMBER,
6926
- PluralRules: INTL_MEMBER,
6927
- RelativeTimeFormat: INTL_MEMBER
6928
- },
6929
- setInterval: C,
6930
- setTimeout: C,
6931
- TextDecoder: C,
6932
- TextEncoder: C,
6933
- URL: C,
6934
- URLSearchParams: C,
6935
- // Browser specific globals
6936
- AbortController: C,
6937
- AbortSignal: C,
6938
- addEventListener: O,
6939
- alert: O,
6940
- AnalyserNode: C,
6941
- Animation: C,
6942
- AnimationEvent: C,
6943
- applicationCache: O,
6944
- ApplicationCache: C,
6945
- ApplicationCacheErrorEvent: C,
6946
- atob: O,
6947
- Attr: C,
6948
- Audio: C,
6949
- AudioBuffer: C,
6950
- AudioBufferSourceNode: C,
6951
- AudioContext: C,
6952
- AudioDestinationNode: C,
6953
- AudioListener: C,
6954
- AudioNode: C,
6955
- AudioParam: C,
6956
- AudioProcessingEvent: C,
6957
- AudioScheduledSourceNode: C,
6958
- AudioWorkletNode: C,
6959
- BarProp: C,
6960
- BaseAudioContext: C,
6961
- BatteryManager: C,
6962
- BeforeUnloadEvent: C,
6963
- BiquadFilterNode: C,
6964
- Blob: C,
6965
- BlobEvent: C,
6966
- blur: O,
6967
- BroadcastChannel: C,
6968
- btoa: O,
6969
- ByteLengthQueuingStrategy: C,
6970
- Cache: C,
6971
- caches: O,
6972
- CacheStorage: C,
6973
- cancelAnimationFrame: O,
6974
- cancelIdleCallback: O,
6975
- CanvasCaptureMediaStreamTrack: C,
6976
- CanvasGradient: C,
6977
- CanvasPattern: C,
6978
- CanvasRenderingContext2D: C,
6979
- ChannelMergerNode: C,
6980
- ChannelSplitterNode: C,
6981
- CharacterData: C,
6982
- clientInformation: O,
6983
- ClipboardEvent: C,
6984
- close: O,
6985
- closed: O,
6986
- CloseEvent: C,
6987
- Comment: C,
6988
- CompositionEvent: C,
6989
- confirm: O,
6990
- ConstantSourceNode: C,
6991
- ConvolverNode: C,
6992
- CountQueuingStrategy: C,
6993
- createImageBitmap: O,
6994
- Credential: C,
6995
- CredentialsContainer: C,
6996
- crypto: O,
6997
- Crypto: C,
6998
- CryptoKey: C,
6999
- CSS: C,
7000
- CSSConditionRule: C,
7001
- CSSFontFaceRule: C,
7002
- CSSGroupingRule: C,
7003
- CSSImportRule: C,
7004
- CSSKeyframeRule: C,
7005
- CSSKeyframesRule: C,
7006
- CSSMediaRule: C,
7007
- CSSNamespaceRule: C,
7008
- CSSPageRule: C,
7009
- CSSRule: C,
7010
- CSSRuleList: C,
7011
- CSSStyleDeclaration: C,
7012
- CSSStyleRule: C,
7013
- CSSStyleSheet: C,
7014
- CSSSupportsRule: C,
7015
- CustomElementRegistry: C,
7016
- customElements: O,
7017
- CustomEvent: C,
7018
- DataTransfer: C,
7019
- DataTransferItem: C,
7020
- DataTransferItemList: C,
7021
- defaultstatus: O,
7022
- defaultStatus: O,
7023
- DelayNode: C,
7024
- DeviceMotionEvent: C,
7025
- DeviceOrientationEvent: C,
7026
- devicePixelRatio: O,
7027
- dispatchEvent: O,
7028
- document: O,
7029
- Document: C,
7030
- DocumentFragment: C,
7031
- DocumentType: C,
7032
- DOMError: C,
7033
- DOMException: C,
7034
- DOMImplementation: C,
7035
- DOMMatrix: C,
7036
- DOMMatrixReadOnly: C,
7037
- DOMParser: C,
7038
- DOMPoint: C,
7039
- DOMPointReadOnly: C,
7040
- DOMQuad: C,
7041
- DOMRect: C,
7042
- DOMRectReadOnly: C,
7043
- DOMStringList: C,
7044
- DOMStringMap: C,
7045
- DOMTokenList: C,
7046
- DragEvent: C,
7047
- DynamicsCompressorNode: C,
7048
- Element: C,
7049
- ErrorEvent: C,
7050
- Event: C,
7051
- EventSource: C,
7052
- EventTarget: C,
7053
- external: O,
7054
- fetch: O,
7055
- File: C,
7056
- FileList: C,
7057
- FileReader: C,
7058
- find: O,
7059
- focus: O,
7060
- FocusEvent: C,
7061
- FontFace: C,
7062
- FontFaceSetLoadEvent: C,
7063
- FormData: C,
7064
- frames: O,
7065
- GainNode: C,
7066
- Gamepad: C,
7067
- GamepadButton: C,
7068
- GamepadEvent: C,
7069
- getComputedStyle: O,
7070
- getSelection: O,
7071
- HashChangeEvent: C,
7072
- Headers: C,
7073
- history: O,
7074
- History: C,
7075
- HTMLAllCollection: C,
7076
- HTMLAnchorElement: C,
7077
- HTMLAreaElement: C,
7078
- HTMLAudioElement: C,
7079
- HTMLBaseElement: C,
7080
- HTMLBodyElement: C,
7081
- HTMLBRElement: C,
7082
- HTMLButtonElement: C,
7083
- HTMLCanvasElement: C,
7084
- HTMLCollection: C,
7085
- HTMLContentElement: C,
7086
- HTMLDataElement: C,
7087
- HTMLDataListElement: C,
7088
- HTMLDetailsElement: C,
7089
- HTMLDialogElement: C,
7090
- HTMLDirectoryElement: C,
7091
- HTMLDivElement: C,
7092
- HTMLDListElement: C,
7093
- HTMLDocument: C,
7094
- HTMLElement: C,
7095
- HTMLEmbedElement: C,
7096
- HTMLFieldSetElement: C,
7097
- HTMLFontElement: C,
7098
- HTMLFormControlsCollection: C,
7099
- HTMLFormElement: C,
7100
- HTMLFrameElement: C,
7101
- HTMLFrameSetElement: C,
7102
- HTMLHeadElement: C,
7103
- HTMLHeadingElement: C,
7104
- HTMLHRElement: C,
7105
- HTMLHtmlElement: C,
7106
- HTMLIFrameElement: C,
7107
- HTMLImageElement: C,
7108
- HTMLInputElement: C,
7109
- HTMLLabelElement: C,
7110
- HTMLLegendElement: C,
7111
- HTMLLIElement: C,
7112
- HTMLLinkElement: C,
7113
- HTMLMapElement: C,
7114
- HTMLMarqueeElement: C,
7115
- HTMLMediaElement: C,
7116
- HTMLMenuElement: C,
7117
- HTMLMetaElement: C,
7118
- HTMLMeterElement: C,
7119
- HTMLModElement: C,
7120
- HTMLObjectElement: C,
7121
- HTMLOListElement: C,
7122
- HTMLOptGroupElement: C,
7123
- HTMLOptionElement: C,
7124
- HTMLOptionsCollection: C,
7125
- HTMLOutputElement: C,
7126
- HTMLParagraphElement: C,
7127
- HTMLParamElement: C,
7128
- HTMLPictureElement: C,
7129
- HTMLPreElement: C,
7130
- HTMLProgressElement: C,
7131
- HTMLQuoteElement: C,
7132
- HTMLScriptElement: C,
7133
- HTMLSelectElement: C,
7134
- HTMLShadowElement: C,
7135
- HTMLSlotElement: C,
7136
- HTMLSourceElement: C,
7137
- HTMLSpanElement: C,
7138
- HTMLStyleElement: C,
7139
- HTMLTableCaptionElement: C,
7140
- HTMLTableCellElement: C,
7141
- HTMLTableColElement: C,
7142
- HTMLTableElement: C,
7143
- HTMLTableRowElement: C,
7144
- HTMLTableSectionElement: C,
7145
- HTMLTemplateElement: C,
7146
- HTMLTextAreaElement: C,
7147
- HTMLTimeElement: C,
7148
- HTMLTitleElement: C,
7149
- HTMLTrackElement: C,
7150
- HTMLUListElement: C,
7151
- HTMLUnknownElement: C,
7152
- HTMLVideoElement: C,
7153
- IDBCursor: C,
7154
- IDBCursorWithValue: C,
7155
- IDBDatabase: C,
7156
- IDBFactory: C,
7157
- IDBIndex: C,
7158
- IDBKeyRange: C,
7159
- IDBObjectStore: C,
7160
- IDBOpenDBRequest: C,
7161
- IDBRequest: C,
7162
- IDBTransaction: C,
7163
- IDBVersionChangeEvent: C,
7164
- IdleDeadline: C,
7165
- IIRFilterNode: C,
7166
- Image: C,
7167
- ImageBitmap: C,
7168
- ImageBitmapRenderingContext: C,
7169
- ImageCapture: C,
7170
- ImageData: C,
7171
- indexedDB: O,
7172
- innerHeight: O,
7173
- innerWidth: O,
7174
- InputEvent: C,
7175
- IntersectionObserver: C,
7176
- IntersectionObserverEntry: C,
7177
- isSecureContext: O,
7178
- KeyboardEvent: C,
7179
- KeyframeEffect: C,
7180
- length: O,
7181
- localStorage: O,
7182
- location: O,
7183
- Location: C,
7184
- locationbar: O,
7185
- matchMedia: O,
7186
- MediaDeviceInfo: C,
7187
- MediaDevices: C,
7188
- MediaElementAudioSourceNode: C,
7189
- MediaEncryptedEvent: C,
7190
- MediaError: C,
7191
- MediaKeyMessageEvent: C,
7192
- MediaKeySession: C,
7193
- MediaKeyStatusMap: C,
7194
- MediaKeySystemAccess: C,
7195
- MediaList: C,
7196
- MediaQueryList: C,
7197
- MediaQueryListEvent: C,
7198
- MediaRecorder: C,
7199
- MediaSettingsRange: C,
7200
- MediaSource: C,
7201
- MediaStream: C,
7202
- MediaStreamAudioDestinationNode: C,
7203
- MediaStreamAudioSourceNode: C,
7204
- MediaStreamEvent: C,
7205
- MediaStreamTrack: C,
7206
- MediaStreamTrackEvent: C,
7207
- menubar: O,
7208
- MessageChannel: C,
7209
- MessageEvent: C,
7210
- MessagePort: C,
7211
- MIDIAccess: C,
7212
- MIDIConnectionEvent: C,
7213
- MIDIInput: C,
7214
- MIDIInputMap: C,
7215
- MIDIMessageEvent: C,
7216
- MIDIOutput: C,
7217
- MIDIOutputMap: C,
7218
- MIDIPort: C,
7219
- MimeType: C,
7220
- MimeTypeArray: C,
7221
- MouseEvent: C,
7222
- moveBy: O,
7223
- moveTo: O,
7224
- MutationEvent: C,
7225
- MutationObserver: C,
7226
- MutationRecord: C,
7227
- name: O,
7228
- NamedNodeMap: C,
7229
- NavigationPreloadManager: C,
7230
- navigator: O,
7231
- Navigator: C,
7232
- NetworkInformation: C,
7233
- Node: C,
7234
- NodeFilter: O,
7235
- NodeIterator: C,
7236
- NodeList: C,
7237
- Notification: C,
7238
- OfflineAudioCompletionEvent: C,
7239
- OfflineAudioContext: C,
7240
- offscreenBuffering: O,
7241
- OffscreenCanvas: C,
7242
- open: O,
7243
- openDatabase: O,
7244
- Option: C,
7245
- origin: O,
7246
- OscillatorNode: C,
7247
- outerHeight: O,
7248
- outerWidth: O,
7249
- PageTransitionEvent: C,
7250
- pageXOffset: O,
7251
- pageYOffset: O,
7252
- PannerNode: C,
7253
- parent: O,
7254
- Path2D: C,
7255
- PaymentAddress: C,
7256
- PaymentRequest: C,
7257
- PaymentRequestUpdateEvent: C,
7258
- PaymentResponse: C,
7259
- performance: O,
7260
- Performance: C,
7261
- PerformanceEntry: C,
7262
- PerformanceLongTaskTiming: C,
7263
- PerformanceMark: C,
7264
- PerformanceMeasure: C,
7265
- PerformanceNavigation: C,
7266
- PerformanceNavigationTiming: C,
7267
- PerformanceObserver: C,
7268
- PerformanceObserverEntryList: C,
7269
- PerformancePaintTiming: C,
7270
- PerformanceResourceTiming: C,
7271
- PerformanceTiming: C,
7272
- PeriodicWave: C,
7273
- Permissions: C,
7274
- PermissionStatus: C,
7275
- personalbar: O,
7276
- PhotoCapabilities: C,
7277
- Plugin: C,
7278
- PluginArray: C,
7279
- PointerEvent: C,
7280
- PopStateEvent: C,
7281
- postMessage: O,
7282
- Presentation: C,
7283
- PresentationAvailability: C,
7284
- PresentationConnection: C,
7285
- PresentationConnectionAvailableEvent: C,
7286
- PresentationConnectionCloseEvent: C,
7287
- PresentationConnectionList: C,
7288
- PresentationReceiver: C,
7289
- PresentationRequest: C,
7290
- print: O,
7291
- ProcessingInstruction: C,
7292
- ProgressEvent: C,
7293
- PromiseRejectionEvent: C,
7294
- prompt: O,
7295
- PushManager: C,
7296
- PushSubscription: C,
7297
- PushSubscriptionOptions: C,
7298
- queueMicrotask: O,
7299
- RadioNodeList: C,
7300
- Range: C,
7301
- ReadableStream: C,
7302
- RemotePlayback: C,
7303
- removeEventListener: O,
7304
- Request: C,
7305
- requestAnimationFrame: O,
7306
- requestIdleCallback: O,
7307
- resizeBy: O,
7308
- ResizeObserver: C,
7309
- ResizeObserverEntry: C,
7310
- resizeTo: O,
7311
- Response: C,
7312
- RTCCertificate: C,
7313
- RTCDataChannel: C,
7314
- RTCDataChannelEvent: C,
7315
- RTCDtlsTransport: C,
7316
- RTCIceCandidate: C,
7317
- RTCIceTransport: C,
7318
- RTCPeerConnection: C,
7319
- RTCPeerConnectionIceEvent: C,
7320
- RTCRtpReceiver: C,
7321
- RTCRtpSender: C,
7322
- RTCSctpTransport: C,
7323
- RTCSessionDescription: C,
7324
- RTCStatsReport: C,
7325
- RTCTrackEvent: C,
7326
- screen: O,
7327
- Screen: C,
7328
- screenLeft: O,
7329
- ScreenOrientation: C,
7330
- screenTop: O,
7331
- screenX: O,
7332
- screenY: O,
7333
- ScriptProcessorNode: C,
7334
- scroll: O,
7335
- scrollbars: O,
7336
- scrollBy: O,
7337
- scrollTo: O,
7338
- scrollX: O,
7339
- scrollY: O,
7340
- SecurityPolicyViolationEvent: C,
7341
- Selection: C,
7342
- ServiceWorker: C,
7343
- ServiceWorkerContainer: C,
7344
- ServiceWorkerRegistration: C,
7345
- sessionStorage: O,
7346
- ShadowRoot: C,
7347
- SharedWorker: C,
7348
- SourceBuffer: C,
7349
- SourceBufferList: C,
7350
- speechSynthesis: O,
7351
- SpeechSynthesisEvent: C,
7352
- SpeechSynthesisUtterance: C,
7353
- StaticRange: C,
7354
- status: O,
7355
- statusbar: O,
7356
- StereoPannerNode: C,
7357
- stop: O,
7358
- Storage: C,
7359
- StorageEvent: C,
7360
- StorageManager: C,
7361
- styleMedia: O,
7362
- StyleSheet: C,
7363
- StyleSheetList: C,
7364
- SubtleCrypto: C,
7365
- SVGAElement: C,
7366
- SVGAngle: C,
7367
- SVGAnimatedAngle: C,
7368
- SVGAnimatedBoolean: C,
7369
- SVGAnimatedEnumeration: C,
7370
- SVGAnimatedInteger: C,
7371
- SVGAnimatedLength: C,
7372
- SVGAnimatedLengthList: C,
7373
- SVGAnimatedNumber: C,
7374
- SVGAnimatedNumberList: C,
7375
- SVGAnimatedPreserveAspectRatio: C,
7376
- SVGAnimatedRect: C,
7377
- SVGAnimatedString: C,
7378
- SVGAnimatedTransformList: C,
7379
- SVGAnimateElement: C,
7380
- SVGAnimateMotionElement: C,
7381
- SVGAnimateTransformElement: C,
7382
- SVGAnimationElement: C,
7383
- SVGCircleElement: C,
7384
- SVGClipPathElement: C,
7385
- SVGComponentTransferFunctionElement: C,
7386
- SVGDefsElement: C,
7387
- SVGDescElement: C,
7388
- SVGDiscardElement: C,
7389
- SVGElement: C,
7390
- SVGEllipseElement: C,
7391
- SVGFEBlendElement: C,
7392
- SVGFEColorMatrixElement: C,
7393
- SVGFEComponentTransferElement: C,
7394
- SVGFECompositeElement: C,
7395
- SVGFEConvolveMatrixElement: C,
7396
- SVGFEDiffuseLightingElement: C,
7397
- SVGFEDisplacementMapElement: C,
7398
- SVGFEDistantLightElement: C,
7399
- SVGFEDropShadowElement: C,
7400
- SVGFEFloodElement: C,
7401
- SVGFEFuncAElement: C,
7402
- SVGFEFuncBElement: C,
7403
- SVGFEFuncGElement: C,
7404
- SVGFEFuncRElement: C,
7405
- SVGFEGaussianBlurElement: C,
7406
- SVGFEImageElement: C,
7407
- SVGFEMergeElement: C,
7408
- SVGFEMergeNodeElement: C,
7409
- SVGFEMorphologyElement: C,
7410
- SVGFEOffsetElement: C,
7411
- SVGFEPointLightElement: C,
7412
- SVGFESpecularLightingElement: C,
7413
- SVGFESpotLightElement: C,
7414
- SVGFETileElement: C,
7415
- SVGFETurbulenceElement: C,
7416
- SVGFilterElement: C,
7417
- SVGForeignObjectElement: C,
7418
- SVGGElement: C,
7419
- SVGGeometryElement: C,
7420
- SVGGradientElement: C,
7421
- SVGGraphicsElement: C,
7422
- SVGImageElement: C,
7423
- SVGLength: C,
7424
- SVGLengthList: C,
7425
- SVGLinearGradientElement: C,
7426
- SVGLineElement: C,
7427
- SVGMarkerElement: C,
7428
- SVGMaskElement: C,
7429
- SVGMatrix: C,
7430
- SVGMetadataElement: C,
7431
- SVGMPathElement: C,
7432
- SVGNumber: C,
7433
- SVGNumberList: C,
7434
- SVGPathElement: C,
7435
- SVGPatternElement: C,
7436
- SVGPoint: C,
7437
- SVGPointList: C,
7438
- SVGPolygonElement: C,
7439
- SVGPolylineElement: C,
7440
- SVGPreserveAspectRatio: C,
7441
- SVGRadialGradientElement: C,
7442
- SVGRect: C,
7443
- SVGRectElement: C,
7444
- SVGScriptElement: C,
7445
- SVGSetElement: C,
7446
- SVGStopElement: C,
7447
- SVGStringList: C,
7448
- SVGStyleElement: C,
7449
- SVGSVGElement: C,
7450
- SVGSwitchElement: C,
7451
- SVGSymbolElement: C,
7452
- SVGTextContentElement: C,
7453
- SVGTextElement: C,
7454
- SVGTextPathElement: C,
7455
- SVGTextPositioningElement: C,
7456
- SVGTitleElement: C,
7457
- SVGTransform: C,
7458
- SVGTransformList: C,
7459
- SVGTSpanElement: C,
7460
- SVGUnitTypes: C,
7461
- SVGUseElement: C,
7462
- SVGViewElement: C,
7463
- TaskAttributionTiming: C,
7464
- Text: C,
7465
- TextEvent: C,
7466
- TextMetrics: C,
7467
- TextTrack: C,
7468
- TextTrackCue: C,
7469
- TextTrackCueList: C,
7470
- TextTrackList: C,
7471
- TimeRanges: C,
7472
- toolbar: O,
7473
- top: O,
7474
- Touch: C,
7475
- TouchEvent: C,
7476
- TouchList: C,
7477
- TrackEvent: C,
7478
- TransitionEvent: C,
7479
- TreeWalker: C,
7480
- UIEvent: C,
7481
- ValidityState: C,
7482
- visualViewport: O,
7483
- VisualViewport: C,
7484
- VTTCue: C,
7485
- WaveShaperNode: C,
7486
- WebAssembly: O,
7487
- WebGL2RenderingContext: C,
7488
- WebGLActiveInfo: C,
7489
- WebGLBuffer: C,
7490
- WebGLContextEvent: C,
7491
- WebGLFramebuffer: C,
7492
- WebGLProgram: C,
7493
- WebGLQuery: C,
7494
- WebGLRenderbuffer: C,
7495
- WebGLRenderingContext: C,
7496
- WebGLSampler: C,
7497
- WebGLShader: C,
7498
- WebGLShaderPrecisionFormat: C,
7499
- WebGLSync: C,
7500
- WebGLTexture: C,
7501
- WebGLTransformFeedback: C,
7502
- WebGLUniformLocation: C,
7503
- WebGLVertexArrayObject: C,
7504
- WebSocket: C,
7505
- WheelEvent: C,
7506
- Window: C,
7507
- Worker: C,
7508
- WritableStream: C,
7509
- XMLDocument: C,
7510
- XMLHttpRequest: C,
7511
- XMLHttpRequestEventTarget: C,
7512
- XMLHttpRequestUpload: C,
7513
- XMLSerializer: C,
7514
- XPathEvaluator: C,
7515
- XPathExpression: C,
7516
- XPathResult: C,
7517
- XSLTProcessor: C
7518
- };
7519
- for (const global of ['window', 'global', 'self', 'globalThis']) {
7520
- knownGlobals[global] = knownGlobals;
7521
6713
  }
7522
- function getGlobalAtPath(path) {
7523
- let currentGlobal = knownGlobals;
7524
- for (const pathSegment of path) {
7525
- if (typeof pathSegment !== 'string') {
7526
- return null;
6714
+
6715
+ const NO_SEMICOLON = { isNoStatement: true };
6716
+ // This assumes there are only white-space and comments between start and the string we are looking for
6717
+ function findFirstOccurrenceOutsideComment(code, searchString, start = 0) {
6718
+ let searchPos, charCodeAfterSlash;
6719
+ searchPos = code.indexOf(searchString, start);
6720
+ while (true) {
6721
+ start = code.indexOf('/', start);
6722
+ if (start === -1 || start >= searchPos)
6723
+ return searchPos;
6724
+ charCodeAfterSlash = code.charCodeAt(++start);
6725
+ ++start;
6726
+ // With our assumption, '/' always starts a comment. Determine comment type:
6727
+ start =
6728
+ charCodeAfterSlash === 47 /*"/"*/
6729
+ ? code.indexOf('\n', start) + 1
6730
+ : code.indexOf('*/', start) + 2;
6731
+ if (start > searchPos) {
6732
+ searchPos = code.indexOf(searchString, start);
7527
6733
  }
7528
- currentGlobal = currentGlobal[pathSegment];
7529
- if (!currentGlobal) {
7530
- return null;
6734
+ }
6735
+ }
6736
+ const NON_WHITESPACE = /\S/g;
6737
+ function findNonWhiteSpace(code, index) {
6738
+ NON_WHITESPACE.lastIndex = index;
6739
+ const result = NON_WHITESPACE.exec(code);
6740
+ return result.index;
6741
+ }
6742
+ // This assumes "code" only contains white-space and comments
6743
+ // Returns position of line-comment if applicable
6744
+ function findFirstLineBreakOutsideComment(code) {
6745
+ let lineBreakPos, charCodeAfterSlash, start = 0;
6746
+ lineBreakPos = code.indexOf('\n', start);
6747
+ while (true) {
6748
+ start = code.indexOf('/', start);
6749
+ if (start === -1 || start > lineBreakPos)
6750
+ return [lineBreakPos, lineBreakPos + 1];
6751
+ // With our assumption, '/' always starts a comment. Determine comment type:
6752
+ charCodeAfterSlash = code.charCodeAt(start + 1);
6753
+ if (charCodeAfterSlash === 47 /*"/"*/)
6754
+ return [start, lineBreakPos + 1];
6755
+ start = code.indexOf('*/', start + 3) + 2;
6756
+ if (start > lineBreakPos) {
6757
+ lineBreakPos = code.indexOf('\n', start);
6758
+ }
6759
+ }
6760
+ }
6761
+ function renderStatementList(statements, code, start, end, options) {
6762
+ let currentNode, currentNodeStart, currentNodeNeedsBoundaries, nextNodeStart;
6763
+ let nextNode = statements[0];
6764
+ let nextNodeNeedsBoundaries = !nextNode.included || nextNode.needsBoundaries;
6765
+ if (nextNodeNeedsBoundaries) {
6766
+ nextNodeStart =
6767
+ start + findFirstLineBreakOutsideComment(code.original.slice(start, nextNode.start))[1];
6768
+ }
6769
+ for (let nextIndex = 1; nextIndex <= statements.length; nextIndex++) {
6770
+ currentNode = nextNode;
6771
+ currentNodeStart = nextNodeStart;
6772
+ currentNodeNeedsBoundaries = nextNodeNeedsBoundaries;
6773
+ nextNode = statements[nextIndex];
6774
+ nextNodeNeedsBoundaries =
6775
+ nextNode === undefined ? false : !nextNode.included || nextNode.needsBoundaries;
6776
+ if (currentNodeNeedsBoundaries || nextNodeNeedsBoundaries) {
6777
+ nextNodeStart =
6778
+ currentNode.end +
6779
+ findFirstLineBreakOutsideComment(code.original.slice(currentNode.end, nextNode === undefined ? end : nextNode.start))[1];
6780
+ if (currentNode.included) {
6781
+ currentNodeNeedsBoundaries
6782
+ ? currentNode.render(code, options, {
6783
+ end: nextNodeStart,
6784
+ start: currentNodeStart
6785
+ })
6786
+ : currentNode.render(code, options);
6787
+ }
6788
+ else {
6789
+ treeshakeNode(currentNode, code, currentNodeStart, nextNodeStart);
6790
+ }
6791
+ }
6792
+ else {
6793
+ currentNode.render(code, options);
6794
+ }
6795
+ }
6796
+ }
6797
+ // This assumes that the first character is not part of the first node
6798
+ function getCommaSeparatedNodesWithBoundaries(nodes, code, start, end) {
6799
+ const splitUpNodes = [];
6800
+ let node, nextNode, nextNodeStart, contentEnd, char;
6801
+ let separator = start - 1;
6802
+ for (let nextIndex = 0; nextIndex < nodes.length; nextIndex++) {
6803
+ nextNode = nodes[nextIndex];
6804
+ if (node !== undefined) {
6805
+ separator =
6806
+ node.end +
6807
+ findFirstOccurrenceOutsideComment(code.original.slice(node.end, nextNode.start), ',');
6808
+ }
6809
+ nextNodeStart = contentEnd =
6810
+ separator +
6811
+ 1 +
6812
+ findFirstLineBreakOutsideComment(code.original.slice(separator + 1, nextNode.start))[1];
6813
+ while (((char = code.original.charCodeAt(nextNodeStart)),
6814
+ char === 32 /*" "*/ || char === 9 /*"\t"*/ || char === 10 /*"\n"*/ || char === 13) /*"\r"*/)
6815
+ nextNodeStart++;
6816
+ if (node !== undefined) {
6817
+ splitUpNodes.push({
6818
+ contentEnd,
6819
+ end: nextNodeStart,
6820
+ node,
6821
+ separator,
6822
+ start
6823
+ });
6824
+ }
6825
+ node = nextNode;
6826
+ start = nextNodeStart;
6827
+ }
6828
+ splitUpNodes.push({
6829
+ contentEnd: end,
6830
+ end,
6831
+ node: node,
6832
+ separator: null,
6833
+ start
6834
+ });
6835
+ return splitUpNodes;
6836
+ }
6837
+ // This assumes there are only white-space and comments between start and end
6838
+ function removeLineBreaks(code, start, end) {
6839
+ while (true) {
6840
+ const [removeStart, removeEnd] = findFirstLineBreakOutsideComment(code.original.slice(start, end));
6841
+ if (removeStart === -1) {
6842
+ break;
6843
+ }
6844
+ code.remove(start + removeStart, (start += removeEnd));
6845
+ }
6846
+ }
6847
+
6848
+ class BlockScope extends ChildScope {
6849
+ addDeclaration(identifier, context, init, isHoisted) {
6850
+ if (isHoisted) {
6851
+ const variable = this.parent.addDeclaration(identifier, context, init, isHoisted);
6852
+ // Necessary to make sure the init is deoptimized for conditional declarations.
6853
+ // We cannot call deoptimizePath here.
6854
+ variable.markInitializersForDeoptimization();
6855
+ return variable;
6856
+ }
6857
+ else {
6858
+ return super.addDeclaration(identifier, context, init, false);
6859
+ }
6860
+ }
6861
+ }
6862
+
6863
+ class ExpressionStatement extends NodeBase {
6864
+ initialise() {
6865
+ if (this.directive &&
6866
+ this.directive !== 'use strict' &&
6867
+ this.parent.type === Program$1) {
6868
+ this.context.warn(
6869
+ // This is necessary, because either way (deleting or not) can lead to errors.
6870
+ {
6871
+ code: 'MODULE_LEVEL_DIRECTIVE',
6872
+ message: `Module level directives cause errors when bundled, '${this.directive}' was ignored.`
6873
+ }, this.start);
6874
+ }
6875
+ }
6876
+ render(code, options) {
6877
+ super.render(code, options);
6878
+ if (this.included)
6879
+ this.insertSemicolon(code);
6880
+ }
6881
+ shouldBeIncluded(context) {
6882
+ if (this.directive && this.directive !== 'use strict')
6883
+ return this.parent.type !== Program$1;
6884
+ return super.shouldBeIncluded(context);
6885
+ }
6886
+ }
6887
+
6888
+ class BlockStatement extends NodeBase {
6889
+ constructor() {
6890
+ super(...arguments);
6891
+ this.directlyIncluded = false;
6892
+ }
6893
+ addImplicitReturnExpressionToScope() {
6894
+ const lastStatement = this.body[this.body.length - 1];
6895
+ if (!lastStatement || lastStatement.type !== ReturnStatement$1) {
6896
+ this.scope.addReturnExpression(UNKNOWN_EXPRESSION);
6897
+ }
6898
+ }
6899
+ createScope(parentScope) {
6900
+ this.scope = this.parent.preventChildBlockScope
6901
+ ? parentScope
6902
+ : new BlockScope(parentScope);
6903
+ }
6904
+ hasEffects(context) {
6905
+ if (this.deoptimizeBody)
6906
+ return true;
6907
+ for (const node of this.body) {
6908
+ if (context.brokenFlow)
6909
+ break;
6910
+ if (node.hasEffects(context))
6911
+ return true;
6912
+ }
6913
+ return false;
6914
+ }
6915
+ include(context, includeChildrenRecursively) {
6916
+ if (!(this.deoptimizeBody && this.directlyIncluded)) {
6917
+ this.included = true;
6918
+ this.directlyIncluded = true;
6919
+ if (this.deoptimizeBody)
6920
+ includeChildrenRecursively = true;
6921
+ for (const node of this.body) {
6922
+ if (includeChildrenRecursively || node.shouldBeIncluded(context))
6923
+ node.include(context, includeChildrenRecursively);
6924
+ }
7531
6925
  }
7532
6926
  }
7533
- return currentGlobal[ValueProperties];
7534
- }
7535
-
7536
- class GlobalVariable extends Variable {
7537
- constructor() {
7538
- super(...arguments);
7539
- // Ensure we use live-bindings for globals as we do not know if they have
7540
- // been reassigned
7541
- this.isReassigned = true;
6927
+ initialise() {
6928
+ const firstBodyStatement = this.body[0];
6929
+ this.deoptimizeBody =
6930
+ firstBodyStatement instanceof ExpressionStatement &&
6931
+ firstBodyStatement.directive === 'use asm';
7542
6932
  }
7543
- hasEffectsWhenAccessedAtPath(path) {
7544
- if (path.length === 0) {
7545
- // Technically, "undefined" is a global variable of sorts
7546
- return this.name !== 'undefined' && getGlobalAtPath([this.name]) === null;
6933
+ render(code, options) {
6934
+ if (this.body.length) {
6935
+ renderStatementList(this.body, code, this.start + 1, this.end - 1, options);
6936
+ }
6937
+ else {
6938
+ super.render(code, options);
7547
6939
  }
7548
- return getGlobalAtPath([this.name, ...path].slice(0, -1)) === null;
7549
- }
7550
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
7551
- const globalAtPath = getGlobalAtPath([this.name, ...path]);
7552
- return globalAtPath === null || globalAtPath.hasEffectsWhenCalled(callOptions, context);
7553
6940
  }
7554
6941
  }
7555
6942
 
7556
- const tdzVariableKinds = {
7557
- __proto__: null,
7558
- class: true,
7559
- const: true,
7560
- let: true,
7561
- var: true
7562
- };
7563
- class Identifier extends NodeBase {
6943
+ class RestElement extends NodeBase {
7564
6944
  constructor() {
7565
6945
  super(...arguments);
7566
- this.variable = null;
7567
6946
  this.deoptimized = false;
7568
- this.isTDZAccess = null;
6947
+ this.declarationInit = null;
7569
6948
  }
7570
6949
  addExportedVariables(variables, exportNamesByVariable) {
7571
- if (this.variable !== null && exportNamesByVariable.has(this.variable)) {
7572
- variables.push(this.variable);
7573
- }
7574
- }
7575
- bind() {
7576
- if (this.variable === null && is_reference(this, this.parent)) {
7577
- this.variable = this.scope.findVariable(this.name);
7578
- this.variable.addReference(this);
7579
- }
6950
+ this.argument.addExportedVariables(variables, exportNamesByVariable);
7580
6951
  }
7581
6952
  declare(kind, init) {
7582
- let variable;
7583
- const { treeshake } = this.context.options;
7584
- switch (kind) {
7585
- case 'var':
7586
- variable = this.scope.addDeclaration(this, this.context, init, true);
7587
- if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
7588
- // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
7589
- variable.markInitializersForDeoptimization();
7590
- }
7591
- break;
7592
- case 'function':
7593
- // in strict mode, functions are only hoisted within a scope but not across block scopes
7594
- variable = this.scope.addDeclaration(this, this.context, init, false);
7595
- break;
7596
- case 'let':
7597
- case 'const':
7598
- case 'class':
7599
- variable = this.scope.addDeclaration(this, this.context, init, false);
7600
- break;
7601
- case 'parameter':
7602
- variable = this.scope.addParameterDeclaration(this);
7603
- break;
7604
- /* istanbul ignore next */
7605
- default:
7606
- /* istanbul ignore next */
7607
- throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
6953
+ this.declarationInit = init;
6954
+ return this.argument.declare(kind, UNKNOWN_EXPRESSION);
6955
+ }
6956
+ deoptimizePath(path) {
6957
+ path.length === 0 && this.argument.deoptimizePath(EMPTY_PATH);
6958
+ }
6959
+ hasEffectsWhenAssignedAtPath(path, context) {
6960
+ return path.length > 0 || this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
6961
+ }
6962
+ markDeclarationReached() {
6963
+ this.argument.markDeclarationReached();
6964
+ }
6965
+ applyDeoptimizations() {
6966
+ this.deoptimized = true;
6967
+ if (this.declarationInit !== null) {
6968
+ this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
6969
+ this.context.requestTreeshakingPass();
7608
6970
  }
7609
- variable.kind = kind;
7610
- return [(this.variable = variable)];
6971
+ }
6972
+ }
6973
+
6974
+ class FunctionBase extends NodeBase {
6975
+ constructor() {
6976
+ super(...arguments);
6977
+ this.objectEntity = null;
6978
+ this.deoptimizedReturn = false;
6979
+ this.forceIncludeParameters = false;
6980
+ }
6981
+ deoptimizeCache() {
6982
+ this.forceIncludeParameters = true;
7611
6983
  }
7612
6984
  deoptimizePath(path) {
7613
- if (path.length === 0 && !this.scope.contains(this.name)) {
7614
- this.disallowImportReassignment();
6985
+ this.getObjectEntity().deoptimizePath(path);
6986
+ if (path.length === 1 && path[0] === UnknownKey) {
6987
+ // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
6988
+ // which means the return expression needs to be reassigned
6989
+ this.forceIncludeParameters = true;
6990
+ this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
7615
6991
  }
7616
- this.variable.deoptimizePath(path);
7617
6992
  }
7618
6993
  deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
7619
- this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
6994
+ if (path.length > 0) {
6995
+ this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
6996
+ }
7620
6997
  }
7621
6998
  getLiteralValueAtPath(path, recursionTracker, origin) {
7622
- return this.getVariableRespectingTDZ().getLiteralValueAtPath(path, recursionTracker, origin);
6999
+ return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
7623
7000
  }
7624
7001
  getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
7625
- return this.getVariableRespectingTDZ().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
7626
- }
7627
- hasEffects() {
7628
- if (!this.deoptimized)
7629
- this.applyDeoptimizations();
7630
- if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
7631
- return true;
7002
+ if (path.length > 0) {
7003
+ return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
7632
7004
  }
7633
- return (this.context.options.treeshake.unknownGlobalSideEffects &&
7634
- this.variable instanceof GlobalVariable &&
7635
- this.variable.hasEffectsWhenAccessedAtPath(EMPTY_PATH));
7005
+ if (this.async) {
7006
+ if (!this.deoptimizedReturn) {
7007
+ this.deoptimizedReturn = true;
7008
+ this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
7009
+ this.context.requestTreeshakingPass();
7010
+ }
7011
+ return UNKNOWN_EXPRESSION;
7012
+ }
7013
+ return this.scope.getReturnExpression();
7636
7014
  }
7637
7015
  hasEffectsWhenAccessedAtPath(path, context) {
7638
- return (this.variable !== null &&
7639
- this.getVariableRespectingTDZ().hasEffectsWhenAccessedAtPath(path, context));
7016
+ return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
7640
7017
  }
7641
7018
  hasEffectsWhenAssignedAtPath(path, context) {
7642
- return (!this.variable ||
7643
- (path.length > 0
7644
- ? this.getVariableRespectingTDZ()
7645
- : this.variable).hasEffectsWhenAssignedAtPath(path, context));
7019
+ return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
7646
7020
  }
7647
7021
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
7648
- return (!this.variable ||
7649
- this.getVariableRespectingTDZ().hasEffectsWhenCalledAtPath(path, callOptions, context));
7650
- }
7651
- include() {
7652
- if (!this.deoptimized)
7653
- this.applyDeoptimizations();
7654
- if (!this.included) {
7655
- this.included = true;
7656
- if (this.variable !== null) {
7657
- this.context.includeVariableInModule(this.variable);
7658
- }
7659
- }
7660
- }
7661
- includeCallArguments(context, args) {
7662
- this.getVariableRespectingTDZ().includeCallArguments(context, args);
7663
- }
7664
- isPossibleTDZ() {
7665
- // return cached value to avoid issues with the next tree-shaking pass
7666
- if (this.isTDZAccess !== null)
7667
- return this.isTDZAccess;
7668
- if (!(this.variable instanceof LocalVariable) ||
7669
- !this.variable.kind ||
7670
- !(this.variable.kind in tdzVariableKinds)) {
7671
- return (this.isTDZAccess = false);
7672
- }
7673
- let decl_id;
7674
- if (this.variable.declarations &&
7675
- this.variable.declarations.length === 1 &&
7676
- (decl_id = this.variable.declarations[0]) &&
7677
- this.start < decl_id.start &&
7678
- closestParentFunctionOrProgram(this) === closestParentFunctionOrProgram(decl_id)) {
7679
- // a variable accessed before its declaration
7680
- // in the same function or at top level of module
7681
- return (this.isTDZAccess = true);
7022
+ var _a;
7023
+ if (path.length > 0) {
7024
+ return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
7682
7025
  }
7683
- if (!this.variable.initReached) {
7684
- // Either a const/let TDZ violation or
7685
- // var use before declaration was encountered.
7686
- return (this.isTDZAccess = true);
7026
+ if (this.async) {
7027
+ const { propertyReadSideEffects } = this.context.options
7028
+ .treeshake;
7029
+ const returnExpression = this.scope.getReturnExpression();
7030
+ if (returnExpression.hasEffectsWhenCalledAtPath(['then'], { args: NO_ARGS, thisParam: null, withNew: false }, context) ||
7031
+ (propertyReadSideEffects &&
7032
+ (propertyReadSideEffects === 'always' ||
7033
+ returnExpression.hasEffectsWhenAccessedAtPath(['then'], context)))) {
7034
+ return true;
7035
+ }
7687
7036
  }
7688
- return (this.isTDZAccess = false);
7689
- }
7690
- markDeclarationReached() {
7691
- this.variable.initReached = true;
7692
- }
7693
- render(code, { snippets: { getPropertyAccess } }, { renderedParentType, isCalleeOfRenderedParent, isShorthandProperty } = BLANK) {
7694
- if (this.variable) {
7695
- const name = this.variable.getName(getPropertyAccess);
7696
- if (name !== this.name) {
7697
- code.overwrite(this.start, this.end, name, {
7698
- contentOnly: true,
7699
- storeName: true
7700
- });
7701
- if (isShorthandProperty) {
7702
- code.prependRight(this.start, `${this.name}: `);
7037
+ for (let position = 0; position < this.params.length; position++) {
7038
+ const parameter = this.params[position];
7039
+ if (parameter instanceof AssignmentPattern) {
7040
+ if (parameter.left.hasEffects(context)) {
7041
+ return true;
7042
+ }
7043
+ const argumentValue = (_a = callOptions.args[position]) === null || _a === void 0 ? void 0 : _a.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
7044
+ if ((argumentValue === undefined || argumentValue === UnknownValue) &&
7045
+ parameter.right.hasEffects(context)) {
7046
+ return true;
7703
7047
  }
7704
7048
  }
7705
- // In strict mode, any variable named "eval" must be the actual "eval" function
7706
- if (name === 'eval' &&
7707
- renderedParentType === CallExpression$1 &&
7708
- isCalleeOfRenderedParent) {
7709
- code.appendRight(this.start, '0, ');
7049
+ else if (parameter.hasEffects(context)) {
7050
+ return true;
7710
7051
  }
7711
7052
  }
7053
+ return false;
7712
7054
  }
7713
- applyDeoptimizations() {
7714
- this.deoptimized = true;
7715
- if (this.variable !== null && this.variable instanceof LocalVariable) {
7716
- this.variable.consolidateInitializers();
7717
- this.context.requestTreeshakingPass();
7718
- }
7719
- }
7720
- disallowImportReassignment() {
7721
- return this.context.error({
7722
- code: 'ILLEGAL_REASSIGNMENT',
7723
- message: `Illegal reassignment to import '${this.name}'`
7724
- }, this.start);
7725
- }
7726
- getVariableRespectingTDZ() {
7727
- if (this.isPossibleTDZ()) {
7728
- return UNKNOWN_EXPRESSION;
7729
- }
7730
- return this.variable;
7731
- }
7732
- }
7733
- function closestParentFunctionOrProgram(node) {
7734
- while (node && !/^Program|Function/.test(node.type)) {
7735
- node = node.parent;
7736
- }
7737
- // one of: ArrowFunctionExpression, FunctionDeclaration, FunctionExpression or Program
7738
- return node;
7739
- }
7740
-
7741
- function treeshakeNode(node, code, start, end) {
7742
- code.remove(start, end);
7743
- if (node.annotations) {
7744
- for (const annotation of node.annotations) {
7745
- if (annotation.start < start) {
7746
- code.remove(annotation.start, annotation.end);
7055
+ include(context, includeChildrenRecursively, { includeWithoutParameterDefaults } = BLANK) {
7056
+ this.included = true;
7057
+ const { brokenFlow } = context;
7058
+ context.brokenFlow = BROKEN_FLOW_NONE;
7059
+ this.body.include(context, includeChildrenRecursively);
7060
+ context.brokenFlow = brokenFlow;
7061
+ if (!includeWithoutParameterDefaults ||
7062
+ includeChildrenRecursively ||
7063
+ this.forceIncludeParameters) {
7064
+ for (const param of this.params) {
7065
+ param.include(context, includeChildrenRecursively);
7747
7066
  }
7748
- else {
7749
- return;
7067
+ }
7068
+ }
7069
+ includeCallArguments(context, args) {
7070
+ var _a;
7071
+ for (let position = 0; position < this.params.length; position++) {
7072
+ const parameter = this.params[position];
7073
+ if (parameter instanceof AssignmentPattern) {
7074
+ if (parameter.left.shouldBeIncluded(context)) {
7075
+ parameter.left.include(context, false);
7076
+ }
7077
+ const argumentValue = (_a = args[position]) === null || _a === void 0 ? void 0 : _a.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
7078
+ // If argumentValue === UnknownTruthyValue, then we do not need to
7079
+ // include the default
7080
+ if ((argumentValue === undefined || argumentValue === UnknownValue) &&
7081
+ (this.parameterVariables[position].some(variable => variable.included) ||
7082
+ parameter.right.shouldBeIncluded(context))) {
7083
+ parameter.right.include(context, false);
7084
+ }
7085
+ }
7086
+ else if (parameter.shouldBeIncluded(context)) {
7087
+ parameter.include(context, false);
7750
7088
  }
7751
7089
  }
7090
+ this.scope.includeCallArguments(context, args);
7752
7091
  }
7753
- }
7754
- function removeAnnotations(node, code) {
7755
- if (!node.annotations && node.parent.type === ExpressionStatement$1) {
7756
- node = node.parent;
7092
+ initialise() {
7093
+ this.parameterVariables = this.params.map(param => param.declare('parameter', UNKNOWN_EXPRESSION));
7094
+ this.scope.addParameterVariables(this.parameterVariables, this.params[this.params.length - 1] instanceof RestElement);
7095
+ if (this.body instanceof BlockStatement) {
7096
+ this.body.addImplicitReturnExpressionToScope();
7097
+ }
7098
+ else {
7099
+ this.scope.addReturnExpression(this.body);
7100
+ }
7757
7101
  }
7758
- if (node.annotations) {
7759
- for (const annotation of node.annotations) {
7760
- code.remove(annotation.start, annotation.end);
7102
+ parseNode(esTreeNode) {
7103
+ if (esTreeNode.body.type === BlockStatement$1) {
7104
+ this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
7761
7105
  }
7106
+ super.parseNode(esTreeNode);
7762
7107
  }
7763
7108
  }
7109
+ FunctionBase.prototype.preventChildBlockScope = true;
7764
7110
 
7765
- const NO_SEMICOLON = { isNoStatement: true };
7766
- // This assumes there are only white-space and comments between start and the string we are looking for
7767
- function findFirstOccurrenceOutsideComment(code, searchString, start = 0) {
7768
- let searchPos, charCodeAfterSlash;
7769
- searchPos = code.indexOf(searchString, start);
7770
- while (true) {
7771
- start = code.indexOf('/', start);
7772
- if (start === -1 || start >= searchPos)
7773
- return searchPos;
7774
- charCodeAfterSlash = code.charCodeAt(++start);
7775
- ++start;
7776
- // With our assumption, '/' always starts a comment. Determine comment type:
7777
- start =
7778
- charCodeAfterSlash === 47 /*"/"*/
7779
- ? code.indexOf('\n', start) + 1
7780
- : code.indexOf('*/', start) + 2;
7781
- if (start > searchPos) {
7782
- searchPos = code.indexOf(searchString, start);
7783
- }
7111
+ class ArrowFunctionExpression extends FunctionBase {
7112
+ constructor() {
7113
+ super(...arguments);
7114
+ this.objectEntity = null;
7784
7115
  }
7785
- }
7786
- const NON_WHITESPACE = /\S/g;
7787
- function findNonWhiteSpace(code, index) {
7788
- NON_WHITESPACE.lastIndex = index;
7789
- const result = NON_WHITESPACE.exec(code);
7790
- return result.index;
7791
- }
7792
- // This assumes "code" only contains white-space and comments
7793
- // Returns position of line-comment if applicable
7794
- function findFirstLineBreakOutsideComment(code) {
7795
- let lineBreakPos, charCodeAfterSlash, start = 0;
7796
- lineBreakPos = code.indexOf('\n', start);
7797
- while (true) {
7798
- start = code.indexOf('/', start);
7799
- if (start === -1 || start > lineBreakPos)
7800
- return [lineBreakPos, lineBreakPos + 1];
7801
- // With our assumption, '/' always starts a comment. Determine comment type:
7802
- charCodeAfterSlash = code.charCodeAt(start + 1);
7803
- if (charCodeAfterSlash === 47 /*"/"*/)
7804
- return [start, lineBreakPos + 1];
7805
- start = code.indexOf('*/', start + 3) + 2;
7806
- if (start > lineBreakPos) {
7807
- lineBreakPos = code.indexOf('\n', start);
7116
+ createScope(parentScope) {
7117
+ this.scope = new ReturnValueScope(parentScope, this.context);
7118
+ }
7119
+ hasEffects() {
7120
+ return false;
7121
+ }
7122
+ hasEffectsWhenCalledAtPath(path, callOptions, context) {
7123
+ if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
7124
+ return true;
7125
+ const { ignore, brokenFlow } = context;
7126
+ context.ignore = {
7127
+ breaks: false,
7128
+ continues: false,
7129
+ labels: new Set(),
7130
+ returnYield: true
7131
+ };
7132
+ if (this.body.hasEffects(context))
7133
+ return true;
7134
+ context.ignore = ignore;
7135
+ context.brokenFlow = brokenFlow;
7136
+ return false;
7137
+ }
7138
+ getObjectEntity() {
7139
+ if (this.objectEntity !== null) {
7140
+ return this.objectEntity;
7808
7141
  }
7142
+ return (this.objectEntity = new ObjectEntity([], OBJECT_PROTOTYPE));
7809
7143
  }
7810
7144
  }
7811
- function renderStatementList(statements, code, start, end, options) {
7812
- let currentNode, currentNodeStart, currentNodeNeedsBoundaries, nextNodeStart;
7813
- let nextNode = statements[0];
7814
- let nextNodeNeedsBoundaries = !nextNode.included || nextNode.needsBoundaries;
7815
- if (nextNodeNeedsBoundaries) {
7816
- nextNodeStart =
7817
- start + findFirstLineBreakOutsideComment(code.original.slice(start, nextNode.start))[1];
7145
+
7146
+ function getSystemExportStatement(exportedVariables, { exportNamesByVariable, snippets: { _, getObject, getPropertyAccess } }, modifier = '') {
7147
+ if (exportedVariables.length === 1 &&
7148
+ exportNamesByVariable.get(exportedVariables[0]).length === 1) {
7149
+ const variable = exportedVariables[0];
7150
+ return `exports('${exportNamesByVariable.get(variable)}',${_}${variable.getName(getPropertyAccess)}${modifier})`;
7818
7151
  }
7819
- for (let nextIndex = 1; nextIndex <= statements.length; nextIndex++) {
7820
- currentNode = nextNode;
7821
- currentNodeStart = nextNodeStart;
7822
- currentNodeNeedsBoundaries = nextNodeNeedsBoundaries;
7823
- nextNode = statements[nextIndex];
7824
- nextNodeNeedsBoundaries =
7825
- nextNode === undefined ? false : !nextNode.included || nextNode.needsBoundaries;
7826
- if (currentNodeNeedsBoundaries || nextNodeNeedsBoundaries) {
7827
- nextNodeStart =
7828
- currentNode.end +
7829
- findFirstLineBreakOutsideComment(code.original.slice(currentNode.end, nextNode === undefined ? end : nextNode.start))[1];
7830
- if (currentNode.included) {
7831
- currentNodeNeedsBoundaries
7832
- ? currentNode.render(code, options, {
7833
- end: nextNodeStart,
7834
- start: currentNodeStart
7835
- })
7836
- : currentNode.render(code, options);
7837
- }
7838
- else {
7839
- treeshakeNode(currentNode, code, currentNodeStart, nextNodeStart);
7152
+ else {
7153
+ const fields = [];
7154
+ for (const variable of exportedVariables) {
7155
+ for (const exportName of exportNamesByVariable.get(variable)) {
7156
+ fields.push([exportName, variable.getName(getPropertyAccess) + modifier]);
7840
7157
  }
7841
7158
  }
7842
- else {
7843
- currentNode.render(code, options);
7844
- }
7159
+ return `exports(${getObject(fields, { lineBreakIndent: null })})`;
7845
7160
  }
7846
7161
  }
7847
- // This assumes that the first character is not part of the first node
7848
- function getCommaSeparatedNodesWithBoundaries(nodes, code, start, end) {
7849
- const splitUpNodes = [];
7850
- let node, nextNode, nextNodeStart, contentEnd, char;
7851
- let separator = start - 1;
7852
- for (let nextIndex = 0; nextIndex < nodes.length; nextIndex++) {
7853
- nextNode = nodes[nextIndex];
7854
- if (node !== undefined) {
7855
- separator =
7856
- node.end +
7857
- findFirstOccurrenceOutsideComment(code.original.slice(node.end, nextNode.start), ',');
7858
- }
7859
- nextNodeStart = contentEnd =
7860
- separator +
7861
- 1 +
7862
- findFirstLineBreakOutsideComment(code.original.slice(separator + 1, nextNode.start))[1];
7863
- while (((char = code.original.charCodeAt(nextNodeStart)),
7864
- char === 32 /*" "*/ || char === 9 /*"\t"*/ || char === 10 /*"\n"*/ || char === 13) /*"\r"*/)
7865
- nextNodeStart++;
7866
- if (node !== undefined) {
7867
- splitUpNodes.push({
7868
- contentEnd,
7869
- end: nextNodeStart,
7870
- node,
7871
- separator,
7872
- start
7873
- });
7874
- }
7875
- node = nextNode;
7876
- start = nextNodeStart;
7162
+ function renderSystemExportExpression(exportedVariable, expressionStart, expressionEnd, code, { exportNamesByVariable, snippets: { _ } }) {
7163
+ code.prependRight(expressionStart, `exports('${exportNamesByVariable.get(exportedVariable)}',${_}`);
7164
+ code.appendLeft(expressionEnd, ')');
7165
+ }
7166
+ function renderSystemExportFunction(exportedVariables, expressionStart, expressionEnd, needsParens, code, options) {
7167
+ const { _, getDirectReturnIifeLeft } = options.snippets;
7168
+ code.prependRight(expressionStart, getDirectReturnIifeLeft(['v'], `${getSystemExportStatement(exportedVariables, options)},${_}v`, { needsArrowReturnParens: true, needsWrappedFunction: needsParens }));
7169
+ code.appendLeft(expressionEnd, ')');
7170
+ }
7171
+ function renderSystemExportSequenceAfterExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options) {
7172
+ const { _, getPropertyAccess } = options.snippets;
7173
+ code.appendLeft(expressionEnd, `,${_}${getSystemExportStatement([exportedVariable], options)},${_}${exportedVariable.getName(getPropertyAccess)}`);
7174
+ if (needsParens) {
7175
+ code.prependRight(expressionStart, '(');
7176
+ code.appendLeft(expressionEnd, ')');
7877
7177
  }
7878
- splitUpNodes.push({
7879
- contentEnd: end,
7880
- end,
7881
- node: node,
7882
- separator: null,
7883
- start
7884
- });
7885
- return splitUpNodes;
7886
7178
  }
7887
- // This assumes there are only white-space and comments between start and end
7888
- function removeLineBreaks(code, start, end) {
7889
- while (true) {
7890
- const [removeStart, removeEnd] = findFirstLineBreakOutsideComment(code.original.slice(start, end));
7891
- if (removeStart === -1) {
7892
- break;
7179
+ function renderSystemExportSequenceBeforeExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options, modifier) {
7180
+ const { _ } = options.snippets;
7181
+ code.prependRight(expressionStart, `${getSystemExportStatement([exportedVariable], options, modifier)},${_}`);
7182
+ if (needsParens) {
7183
+ code.prependRight(expressionStart, '(');
7184
+ code.appendLeft(expressionEnd, ')');
7185
+ }
7186
+ }
7187
+
7188
+ //@ts-check
7189
+ /** @typedef { import('estree').Node} Node */
7190
+ /** @typedef {Node | {
7191
+ * type: 'PropertyDefinition';
7192
+ * computed: boolean;
7193
+ * value: Node
7194
+ * }} NodeWithPropertyDefinition */
7195
+
7196
+ /**
7197
+ *
7198
+ * @param {NodeWithPropertyDefinition} node
7199
+ * @param {NodeWithPropertyDefinition} parent
7200
+ * @returns boolean
7201
+ */
7202
+ function is_reference (node, parent) {
7203
+ if (node.type === 'MemberExpression') {
7204
+ return !node.computed && is_reference(node.object, node);
7205
+ }
7206
+
7207
+ if (node.type === 'Identifier') {
7208
+ if (!parent) return true;
7209
+
7210
+ switch (parent.type) {
7211
+ // disregard `bar` in `foo.bar`
7212
+ case 'MemberExpression': return parent.computed || node === parent.object;
7213
+
7214
+ // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
7215
+ case 'MethodDefinition': return parent.computed;
7216
+
7217
+ // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
7218
+ case 'PropertyDefinition': return parent.computed || node === parent.value;
7219
+
7220
+ // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
7221
+ case 'Property': return parent.computed || node === parent.value;
7222
+
7223
+ // disregard the `bar` in `export { foo as bar }` or
7224
+ // the foo in `import { foo as bar }`
7225
+ case 'ExportSpecifier':
7226
+ case 'ImportSpecifier': return node === parent.local;
7227
+
7228
+ // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
7229
+ case 'LabeledStatement':
7230
+ case 'BreakStatement':
7231
+ case 'ContinueStatement': return false;
7232
+ default: return true;
7233
+ }
7234
+ }
7235
+
7236
+ return false;
7237
+ }
7238
+
7239
+ /* eslint sort-keys: "off" */
7240
+ const ValueProperties = Symbol('Value Properties');
7241
+ const PURE = {
7242
+ hasEffectsWhenCalled() {
7243
+ return false;
7244
+ }
7245
+ };
7246
+ const IMPURE = {
7247
+ hasEffectsWhenCalled() {
7248
+ return true;
7249
+ }
7250
+ };
7251
+ // We use shortened variables to reduce file size here
7252
+ /* OBJECT */
7253
+ const O = {
7254
+ __proto__: null,
7255
+ [ValueProperties]: IMPURE
7256
+ };
7257
+ /* PURE FUNCTION */
7258
+ const PF = {
7259
+ __proto__: null,
7260
+ [ValueProperties]: PURE
7261
+ };
7262
+ /* FUNCTION THAT MUTATES FIRST ARG WITHOUT TRIGGERING ACCESSORS */
7263
+ const MUTATES_ARG_WITHOUT_ACCESSOR = {
7264
+ __proto__: null,
7265
+ [ValueProperties]: {
7266
+ hasEffectsWhenCalled(callOptions, context) {
7267
+ return (!callOptions.args.length ||
7268
+ callOptions.args[0].hasEffectsWhenAssignedAtPath(UNKNOWN_NON_ACCESSOR_PATH, context));
7893
7269
  }
7894
- code.remove(start + removeStart, (start += removeEnd));
7895
7270
  }
7271
+ };
7272
+ /* CONSTRUCTOR */
7273
+ const C = {
7274
+ __proto__: null,
7275
+ [ValueProperties]: IMPURE,
7276
+ prototype: O
7277
+ };
7278
+ /* PURE CONSTRUCTOR */
7279
+ const PC = {
7280
+ __proto__: null,
7281
+ [ValueProperties]: PURE,
7282
+ prototype: O
7283
+ };
7284
+ const ARRAY_TYPE = {
7285
+ __proto__: null,
7286
+ [ValueProperties]: PURE,
7287
+ from: PF,
7288
+ of: PF,
7289
+ prototype: O
7290
+ };
7291
+ const INTL_MEMBER = {
7292
+ __proto__: null,
7293
+ [ValueProperties]: PURE,
7294
+ supportedLocalesOf: PC
7295
+ };
7296
+ const knownGlobals = {
7297
+ // Placeholders for global objects to avoid shape mutations
7298
+ global: O,
7299
+ globalThis: O,
7300
+ self: O,
7301
+ window: O,
7302
+ // Common globals
7303
+ __proto__: null,
7304
+ [ValueProperties]: IMPURE,
7305
+ Array: {
7306
+ __proto__: null,
7307
+ [ValueProperties]: IMPURE,
7308
+ from: O,
7309
+ isArray: PF,
7310
+ of: PF,
7311
+ prototype: O
7312
+ },
7313
+ ArrayBuffer: {
7314
+ __proto__: null,
7315
+ [ValueProperties]: PURE,
7316
+ isView: PF,
7317
+ prototype: O
7318
+ },
7319
+ Atomics: O,
7320
+ BigInt: C,
7321
+ BigInt64Array: C,
7322
+ BigUint64Array: C,
7323
+ Boolean: PC,
7324
+ constructor: C,
7325
+ DataView: PC,
7326
+ Date: {
7327
+ __proto__: null,
7328
+ [ValueProperties]: PURE,
7329
+ now: PF,
7330
+ parse: PF,
7331
+ prototype: O,
7332
+ UTC: PF
7333
+ },
7334
+ decodeURI: PF,
7335
+ decodeURIComponent: PF,
7336
+ encodeURI: PF,
7337
+ encodeURIComponent: PF,
7338
+ Error: PC,
7339
+ escape: PF,
7340
+ eval: O,
7341
+ EvalError: PC,
7342
+ Float32Array: ARRAY_TYPE,
7343
+ Float64Array: ARRAY_TYPE,
7344
+ Function: C,
7345
+ hasOwnProperty: O,
7346
+ Infinity: O,
7347
+ Int16Array: ARRAY_TYPE,
7348
+ Int32Array: ARRAY_TYPE,
7349
+ Int8Array: ARRAY_TYPE,
7350
+ isFinite: PF,
7351
+ isNaN: PF,
7352
+ isPrototypeOf: O,
7353
+ JSON: O,
7354
+ Map: PC,
7355
+ Math: {
7356
+ __proto__: null,
7357
+ [ValueProperties]: IMPURE,
7358
+ abs: PF,
7359
+ acos: PF,
7360
+ acosh: PF,
7361
+ asin: PF,
7362
+ asinh: PF,
7363
+ atan: PF,
7364
+ atan2: PF,
7365
+ atanh: PF,
7366
+ cbrt: PF,
7367
+ ceil: PF,
7368
+ clz32: PF,
7369
+ cos: PF,
7370
+ cosh: PF,
7371
+ exp: PF,
7372
+ expm1: PF,
7373
+ floor: PF,
7374
+ fround: PF,
7375
+ hypot: PF,
7376
+ imul: PF,
7377
+ log: PF,
7378
+ log10: PF,
7379
+ log1p: PF,
7380
+ log2: PF,
7381
+ max: PF,
7382
+ min: PF,
7383
+ pow: PF,
7384
+ random: PF,
7385
+ round: PF,
7386
+ sign: PF,
7387
+ sin: PF,
7388
+ sinh: PF,
7389
+ sqrt: PF,
7390
+ tan: PF,
7391
+ tanh: PF,
7392
+ trunc: PF
7393
+ },
7394
+ NaN: O,
7395
+ Number: {
7396
+ __proto__: null,
7397
+ [ValueProperties]: PURE,
7398
+ isFinite: PF,
7399
+ isInteger: PF,
7400
+ isNaN: PF,
7401
+ isSafeInteger: PF,
7402
+ parseFloat: PF,
7403
+ parseInt: PF,
7404
+ prototype: O
7405
+ },
7406
+ Object: {
7407
+ __proto__: null,
7408
+ [ValueProperties]: PURE,
7409
+ create: PF,
7410
+ // Technically those can throw in certain situations, but we ignore this as
7411
+ // code that relies on this will hopefully wrap this in a try-catch, which
7412
+ // deoptimizes everything anyway
7413
+ defineProperty: MUTATES_ARG_WITHOUT_ACCESSOR,
7414
+ defineProperties: MUTATES_ARG_WITHOUT_ACCESSOR,
7415
+ getOwnPropertyDescriptor: PF,
7416
+ getOwnPropertyNames: PF,
7417
+ getOwnPropertySymbols: PF,
7418
+ getPrototypeOf: PF,
7419
+ hasOwn: PF,
7420
+ is: PF,
7421
+ isExtensible: PF,
7422
+ isFrozen: PF,
7423
+ isSealed: PF,
7424
+ keys: PF,
7425
+ fromEntries: PF,
7426
+ entries: PF,
7427
+ prototype: O
7428
+ },
7429
+ parseFloat: PF,
7430
+ parseInt: PF,
7431
+ Promise: {
7432
+ __proto__: null,
7433
+ [ValueProperties]: IMPURE,
7434
+ all: O,
7435
+ prototype: O,
7436
+ race: O,
7437
+ reject: O,
7438
+ resolve: O
7439
+ },
7440
+ propertyIsEnumerable: O,
7441
+ Proxy: O,
7442
+ RangeError: PC,
7443
+ ReferenceError: PC,
7444
+ Reflect: O,
7445
+ RegExp: PC,
7446
+ Set: PC,
7447
+ SharedArrayBuffer: C,
7448
+ String: {
7449
+ __proto__: null,
7450
+ [ValueProperties]: PURE,
7451
+ fromCharCode: PF,
7452
+ fromCodePoint: PF,
7453
+ prototype: O,
7454
+ raw: PF
7455
+ },
7456
+ Symbol: {
7457
+ __proto__: null,
7458
+ [ValueProperties]: PURE,
7459
+ for: PF,
7460
+ keyFor: PF,
7461
+ prototype: O
7462
+ },
7463
+ SyntaxError: PC,
7464
+ toLocaleString: O,
7465
+ toString: O,
7466
+ TypeError: PC,
7467
+ Uint16Array: ARRAY_TYPE,
7468
+ Uint32Array: ARRAY_TYPE,
7469
+ Uint8Array: ARRAY_TYPE,
7470
+ Uint8ClampedArray: ARRAY_TYPE,
7471
+ // Technically, this is a global, but it needs special handling
7472
+ // undefined: ?,
7473
+ unescape: PF,
7474
+ URIError: PC,
7475
+ valueOf: O,
7476
+ WeakMap: PC,
7477
+ WeakSet: PC,
7478
+ // Additional globals shared by Node and Browser that are not strictly part of the language
7479
+ clearInterval: C,
7480
+ clearTimeout: C,
7481
+ console: O,
7482
+ Intl: {
7483
+ __proto__: null,
7484
+ [ValueProperties]: IMPURE,
7485
+ Collator: INTL_MEMBER,
7486
+ DateTimeFormat: INTL_MEMBER,
7487
+ ListFormat: INTL_MEMBER,
7488
+ NumberFormat: INTL_MEMBER,
7489
+ PluralRules: INTL_MEMBER,
7490
+ RelativeTimeFormat: INTL_MEMBER
7491
+ },
7492
+ setInterval: C,
7493
+ setTimeout: C,
7494
+ TextDecoder: C,
7495
+ TextEncoder: C,
7496
+ URL: C,
7497
+ URLSearchParams: C,
7498
+ // Browser specific globals
7499
+ AbortController: C,
7500
+ AbortSignal: C,
7501
+ addEventListener: O,
7502
+ alert: O,
7503
+ AnalyserNode: C,
7504
+ Animation: C,
7505
+ AnimationEvent: C,
7506
+ applicationCache: O,
7507
+ ApplicationCache: C,
7508
+ ApplicationCacheErrorEvent: C,
7509
+ atob: O,
7510
+ Attr: C,
7511
+ Audio: C,
7512
+ AudioBuffer: C,
7513
+ AudioBufferSourceNode: C,
7514
+ AudioContext: C,
7515
+ AudioDestinationNode: C,
7516
+ AudioListener: C,
7517
+ AudioNode: C,
7518
+ AudioParam: C,
7519
+ AudioProcessingEvent: C,
7520
+ AudioScheduledSourceNode: C,
7521
+ AudioWorkletNode: C,
7522
+ BarProp: C,
7523
+ BaseAudioContext: C,
7524
+ BatteryManager: C,
7525
+ BeforeUnloadEvent: C,
7526
+ BiquadFilterNode: C,
7527
+ Blob: C,
7528
+ BlobEvent: C,
7529
+ blur: O,
7530
+ BroadcastChannel: C,
7531
+ btoa: O,
7532
+ ByteLengthQueuingStrategy: C,
7533
+ Cache: C,
7534
+ caches: O,
7535
+ CacheStorage: C,
7536
+ cancelAnimationFrame: O,
7537
+ cancelIdleCallback: O,
7538
+ CanvasCaptureMediaStreamTrack: C,
7539
+ CanvasGradient: C,
7540
+ CanvasPattern: C,
7541
+ CanvasRenderingContext2D: C,
7542
+ ChannelMergerNode: C,
7543
+ ChannelSplitterNode: C,
7544
+ CharacterData: C,
7545
+ clientInformation: O,
7546
+ ClipboardEvent: C,
7547
+ close: O,
7548
+ closed: O,
7549
+ CloseEvent: C,
7550
+ Comment: C,
7551
+ CompositionEvent: C,
7552
+ confirm: O,
7553
+ ConstantSourceNode: C,
7554
+ ConvolverNode: C,
7555
+ CountQueuingStrategy: C,
7556
+ createImageBitmap: O,
7557
+ Credential: C,
7558
+ CredentialsContainer: C,
7559
+ crypto: O,
7560
+ Crypto: C,
7561
+ CryptoKey: C,
7562
+ CSS: C,
7563
+ CSSConditionRule: C,
7564
+ CSSFontFaceRule: C,
7565
+ CSSGroupingRule: C,
7566
+ CSSImportRule: C,
7567
+ CSSKeyframeRule: C,
7568
+ CSSKeyframesRule: C,
7569
+ CSSMediaRule: C,
7570
+ CSSNamespaceRule: C,
7571
+ CSSPageRule: C,
7572
+ CSSRule: C,
7573
+ CSSRuleList: C,
7574
+ CSSStyleDeclaration: C,
7575
+ CSSStyleRule: C,
7576
+ CSSStyleSheet: C,
7577
+ CSSSupportsRule: C,
7578
+ CustomElementRegistry: C,
7579
+ customElements: O,
7580
+ CustomEvent: C,
7581
+ DataTransfer: C,
7582
+ DataTransferItem: C,
7583
+ DataTransferItemList: C,
7584
+ defaultstatus: O,
7585
+ defaultStatus: O,
7586
+ DelayNode: C,
7587
+ DeviceMotionEvent: C,
7588
+ DeviceOrientationEvent: C,
7589
+ devicePixelRatio: O,
7590
+ dispatchEvent: O,
7591
+ document: O,
7592
+ Document: C,
7593
+ DocumentFragment: C,
7594
+ DocumentType: C,
7595
+ DOMError: C,
7596
+ DOMException: C,
7597
+ DOMImplementation: C,
7598
+ DOMMatrix: C,
7599
+ DOMMatrixReadOnly: C,
7600
+ DOMParser: C,
7601
+ DOMPoint: C,
7602
+ DOMPointReadOnly: C,
7603
+ DOMQuad: C,
7604
+ DOMRect: C,
7605
+ DOMRectReadOnly: C,
7606
+ DOMStringList: C,
7607
+ DOMStringMap: C,
7608
+ DOMTokenList: C,
7609
+ DragEvent: C,
7610
+ DynamicsCompressorNode: C,
7611
+ Element: C,
7612
+ ErrorEvent: C,
7613
+ Event: C,
7614
+ EventSource: C,
7615
+ EventTarget: C,
7616
+ external: O,
7617
+ fetch: O,
7618
+ File: C,
7619
+ FileList: C,
7620
+ FileReader: C,
7621
+ find: O,
7622
+ focus: O,
7623
+ FocusEvent: C,
7624
+ FontFace: C,
7625
+ FontFaceSetLoadEvent: C,
7626
+ FormData: C,
7627
+ frames: O,
7628
+ GainNode: C,
7629
+ Gamepad: C,
7630
+ GamepadButton: C,
7631
+ GamepadEvent: C,
7632
+ getComputedStyle: O,
7633
+ getSelection: O,
7634
+ HashChangeEvent: C,
7635
+ Headers: C,
7636
+ history: O,
7637
+ History: C,
7638
+ HTMLAllCollection: C,
7639
+ HTMLAnchorElement: C,
7640
+ HTMLAreaElement: C,
7641
+ HTMLAudioElement: C,
7642
+ HTMLBaseElement: C,
7643
+ HTMLBodyElement: C,
7644
+ HTMLBRElement: C,
7645
+ HTMLButtonElement: C,
7646
+ HTMLCanvasElement: C,
7647
+ HTMLCollection: C,
7648
+ HTMLContentElement: C,
7649
+ HTMLDataElement: C,
7650
+ HTMLDataListElement: C,
7651
+ HTMLDetailsElement: C,
7652
+ HTMLDialogElement: C,
7653
+ HTMLDirectoryElement: C,
7654
+ HTMLDivElement: C,
7655
+ HTMLDListElement: C,
7656
+ HTMLDocument: C,
7657
+ HTMLElement: C,
7658
+ HTMLEmbedElement: C,
7659
+ HTMLFieldSetElement: C,
7660
+ HTMLFontElement: C,
7661
+ HTMLFormControlsCollection: C,
7662
+ HTMLFormElement: C,
7663
+ HTMLFrameElement: C,
7664
+ HTMLFrameSetElement: C,
7665
+ HTMLHeadElement: C,
7666
+ HTMLHeadingElement: C,
7667
+ HTMLHRElement: C,
7668
+ HTMLHtmlElement: C,
7669
+ HTMLIFrameElement: C,
7670
+ HTMLImageElement: C,
7671
+ HTMLInputElement: C,
7672
+ HTMLLabelElement: C,
7673
+ HTMLLegendElement: C,
7674
+ HTMLLIElement: C,
7675
+ HTMLLinkElement: C,
7676
+ HTMLMapElement: C,
7677
+ HTMLMarqueeElement: C,
7678
+ HTMLMediaElement: C,
7679
+ HTMLMenuElement: C,
7680
+ HTMLMetaElement: C,
7681
+ HTMLMeterElement: C,
7682
+ HTMLModElement: C,
7683
+ HTMLObjectElement: C,
7684
+ HTMLOListElement: C,
7685
+ HTMLOptGroupElement: C,
7686
+ HTMLOptionElement: C,
7687
+ HTMLOptionsCollection: C,
7688
+ HTMLOutputElement: C,
7689
+ HTMLParagraphElement: C,
7690
+ HTMLParamElement: C,
7691
+ HTMLPictureElement: C,
7692
+ HTMLPreElement: C,
7693
+ HTMLProgressElement: C,
7694
+ HTMLQuoteElement: C,
7695
+ HTMLScriptElement: C,
7696
+ HTMLSelectElement: C,
7697
+ HTMLShadowElement: C,
7698
+ HTMLSlotElement: C,
7699
+ HTMLSourceElement: C,
7700
+ HTMLSpanElement: C,
7701
+ HTMLStyleElement: C,
7702
+ HTMLTableCaptionElement: C,
7703
+ HTMLTableCellElement: C,
7704
+ HTMLTableColElement: C,
7705
+ HTMLTableElement: C,
7706
+ HTMLTableRowElement: C,
7707
+ HTMLTableSectionElement: C,
7708
+ HTMLTemplateElement: C,
7709
+ HTMLTextAreaElement: C,
7710
+ HTMLTimeElement: C,
7711
+ HTMLTitleElement: C,
7712
+ HTMLTrackElement: C,
7713
+ HTMLUListElement: C,
7714
+ HTMLUnknownElement: C,
7715
+ HTMLVideoElement: C,
7716
+ IDBCursor: C,
7717
+ IDBCursorWithValue: C,
7718
+ IDBDatabase: C,
7719
+ IDBFactory: C,
7720
+ IDBIndex: C,
7721
+ IDBKeyRange: C,
7722
+ IDBObjectStore: C,
7723
+ IDBOpenDBRequest: C,
7724
+ IDBRequest: C,
7725
+ IDBTransaction: C,
7726
+ IDBVersionChangeEvent: C,
7727
+ IdleDeadline: C,
7728
+ IIRFilterNode: C,
7729
+ Image: C,
7730
+ ImageBitmap: C,
7731
+ ImageBitmapRenderingContext: C,
7732
+ ImageCapture: C,
7733
+ ImageData: C,
7734
+ indexedDB: O,
7735
+ innerHeight: O,
7736
+ innerWidth: O,
7737
+ InputEvent: C,
7738
+ IntersectionObserver: C,
7739
+ IntersectionObserverEntry: C,
7740
+ isSecureContext: O,
7741
+ KeyboardEvent: C,
7742
+ KeyframeEffect: C,
7743
+ length: O,
7744
+ localStorage: O,
7745
+ location: O,
7746
+ Location: C,
7747
+ locationbar: O,
7748
+ matchMedia: O,
7749
+ MediaDeviceInfo: C,
7750
+ MediaDevices: C,
7751
+ MediaElementAudioSourceNode: C,
7752
+ MediaEncryptedEvent: C,
7753
+ MediaError: C,
7754
+ MediaKeyMessageEvent: C,
7755
+ MediaKeySession: C,
7756
+ MediaKeyStatusMap: C,
7757
+ MediaKeySystemAccess: C,
7758
+ MediaList: C,
7759
+ MediaQueryList: C,
7760
+ MediaQueryListEvent: C,
7761
+ MediaRecorder: C,
7762
+ MediaSettingsRange: C,
7763
+ MediaSource: C,
7764
+ MediaStream: C,
7765
+ MediaStreamAudioDestinationNode: C,
7766
+ MediaStreamAudioSourceNode: C,
7767
+ MediaStreamEvent: C,
7768
+ MediaStreamTrack: C,
7769
+ MediaStreamTrackEvent: C,
7770
+ menubar: O,
7771
+ MessageChannel: C,
7772
+ MessageEvent: C,
7773
+ MessagePort: C,
7774
+ MIDIAccess: C,
7775
+ MIDIConnectionEvent: C,
7776
+ MIDIInput: C,
7777
+ MIDIInputMap: C,
7778
+ MIDIMessageEvent: C,
7779
+ MIDIOutput: C,
7780
+ MIDIOutputMap: C,
7781
+ MIDIPort: C,
7782
+ MimeType: C,
7783
+ MimeTypeArray: C,
7784
+ MouseEvent: C,
7785
+ moveBy: O,
7786
+ moveTo: O,
7787
+ MutationEvent: C,
7788
+ MutationObserver: C,
7789
+ MutationRecord: C,
7790
+ name: O,
7791
+ NamedNodeMap: C,
7792
+ NavigationPreloadManager: C,
7793
+ navigator: O,
7794
+ Navigator: C,
7795
+ NetworkInformation: C,
7796
+ Node: C,
7797
+ NodeFilter: O,
7798
+ NodeIterator: C,
7799
+ NodeList: C,
7800
+ Notification: C,
7801
+ OfflineAudioCompletionEvent: C,
7802
+ OfflineAudioContext: C,
7803
+ offscreenBuffering: O,
7804
+ OffscreenCanvas: C,
7805
+ open: O,
7806
+ openDatabase: O,
7807
+ Option: C,
7808
+ origin: O,
7809
+ OscillatorNode: C,
7810
+ outerHeight: O,
7811
+ outerWidth: O,
7812
+ PageTransitionEvent: C,
7813
+ pageXOffset: O,
7814
+ pageYOffset: O,
7815
+ PannerNode: C,
7816
+ parent: O,
7817
+ Path2D: C,
7818
+ PaymentAddress: C,
7819
+ PaymentRequest: C,
7820
+ PaymentRequestUpdateEvent: C,
7821
+ PaymentResponse: C,
7822
+ performance: O,
7823
+ Performance: C,
7824
+ PerformanceEntry: C,
7825
+ PerformanceLongTaskTiming: C,
7826
+ PerformanceMark: C,
7827
+ PerformanceMeasure: C,
7828
+ PerformanceNavigation: C,
7829
+ PerformanceNavigationTiming: C,
7830
+ PerformanceObserver: C,
7831
+ PerformanceObserverEntryList: C,
7832
+ PerformancePaintTiming: C,
7833
+ PerformanceResourceTiming: C,
7834
+ PerformanceTiming: C,
7835
+ PeriodicWave: C,
7836
+ Permissions: C,
7837
+ PermissionStatus: C,
7838
+ personalbar: O,
7839
+ PhotoCapabilities: C,
7840
+ Plugin: C,
7841
+ PluginArray: C,
7842
+ PointerEvent: C,
7843
+ PopStateEvent: C,
7844
+ postMessage: O,
7845
+ Presentation: C,
7846
+ PresentationAvailability: C,
7847
+ PresentationConnection: C,
7848
+ PresentationConnectionAvailableEvent: C,
7849
+ PresentationConnectionCloseEvent: C,
7850
+ PresentationConnectionList: C,
7851
+ PresentationReceiver: C,
7852
+ PresentationRequest: C,
7853
+ print: O,
7854
+ ProcessingInstruction: C,
7855
+ ProgressEvent: C,
7856
+ PromiseRejectionEvent: C,
7857
+ prompt: O,
7858
+ PushManager: C,
7859
+ PushSubscription: C,
7860
+ PushSubscriptionOptions: C,
7861
+ queueMicrotask: O,
7862
+ RadioNodeList: C,
7863
+ Range: C,
7864
+ ReadableStream: C,
7865
+ RemotePlayback: C,
7866
+ removeEventListener: O,
7867
+ Request: C,
7868
+ requestAnimationFrame: O,
7869
+ requestIdleCallback: O,
7870
+ resizeBy: O,
7871
+ ResizeObserver: C,
7872
+ ResizeObserverEntry: C,
7873
+ resizeTo: O,
7874
+ Response: C,
7875
+ RTCCertificate: C,
7876
+ RTCDataChannel: C,
7877
+ RTCDataChannelEvent: C,
7878
+ RTCDtlsTransport: C,
7879
+ RTCIceCandidate: C,
7880
+ RTCIceTransport: C,
7881
+ RTCPeerConnection: C,
7882
+ RTCPeerConnectionIceEvent: C,
7883
+ RTCRtpReceiver: C,
7884
+ RTCRtpSender: C,
7885
+ RTCSctpTransport: C,
7886
+ RTCSessionDescription: C,
7887
+ RTCStatsReport: C,
7888
+ RTCTrackEvent: C,
7889
+ screen: O,
7890
+ Screen: C,
7891
+ screenLeft: O,
7892
+ ScreenOrientation: C,
7893
+ screenTop: O,
7894
+ screenX: O,
7895
+ screenY: O,
7896
+ ScriptProcessorNode: C,
7897
+ scroll: O,
7898
+ scrollbars: O,
7899
+ scrollBy: O,
7900
+ scrollTo: O,
7901
+ scrollX: O,
7902
+ scrollY: O,
7903
+ SecurityPolicyViolationEvent: C,
7904
+ Selection: C,
7905
+ ServiceWorker: C,
7906
+ ServiceWorkerContainer: C,
7907
+ ServiceWorkerRegistration: C,
7908
+ sessionStorage: O,
7909
+ ShadowRoot: C,
7910
+ SharedWorker: C,
7911
+ SourceBuffer: C,
7912
+ SourceBufferList: C,
7913
+ speechSynthesis: O,
7914
+ SpeechSynthesisEvent: C,
7915
+ SpeechSynthesisUtterance: C,
7916
+ StaticRange: C,
7917
+ status: O,
7918
+ statusbar: O,
7919
+ StereoPannerNode: C,
7920
+ stop: O,
7921
+ Storage: C,
7922
+ StorageEvent: C,
7923
+ StorageManager: C,
7924
+ styleMedia: O,
7925
+ StyleSheet: C,
7926
+ StyleSheetList: C,
7927
+ SubtleCrypto: C,
7928
+ SVGAElement: C,
7929
+ SVGAngle: C,
7930
+ SVGAnimatedAngle: C,
7931
+ SVGAnimatedBoolean: C,
7932
+ SVGAnimatedEnumeration: C,
7933
+ SVGAnimatedInteger: C,
7934
+ SVGAnimatedLength: C,
7935
+ SVGAnimatedLengthList: C,
7936
+ SVGAnimatedNumber: C,
7937
+ SVGAnimatedNumberList: C,
7938
+ SVGAnimatedPreserveAspectRatio: C,
7939
+ SVGAnimatedRect: C,
7940
+ SVGAnimatedString: C,
7941
+ SVGAnimatedTransformList: C,
7942
+ SVGAnimateElement: C,
7943
+ SVGAnimateMotionElement: C,
7944
+ SVGAnimateTransformElement: C,
7945
+ SVGAnimationElement: C,
7946
+ SVGCircleElement: C,
7947
+ SVGClipPathElement: C,
7948
+ SVGComponentTransferFunctionElement: C,
7949
+ SVGDefsElement: C,
7950
+ SVGDescElement: C,
7951
+ SVGDiscardElement: C,
7952
+ SVGElement: C,
7953
+ SVGEllipseElement: C,
7954
+ SVGFEBlendElement: C,
7955
+ SVGFEColorMatrixElement: C,
7956
+ SVGFEComponentTransferElement: C,
7957
+ SVGFECompositeElement: C,
7958
+ SVGFEConvolveMatrixElement: C,
7959
+ SVGFEDiffuseLightingElement: C,
7960
+ SVGFEDisplacementMapElement: C,
7961
+ SVGFEDistantLightElement: C,
7962
+ SVGFEDropShadowElement: C,
7963
+ SVGFEFloodElement: C,
7964
+ SVGFEFuncAElement: C,
7965
+ SVGFEFuncBElement: C,
7966
+ SVGFEFuncGElement: C,
7967
+ SVGFEFuncRElement: C,
7968
+ SVGFEGaussianBlurElement: C,
7969
+ SVGFEImageElement: C,
7970
+ SVGFEMergeElement: C,
7971
+ SVGFEMergeNodeElement: C,
7972
+ SVGFEMorphologyElement: C,
7973
+ SVGFEOffsetElement: C,
7974
+ SVGFEPointLightElement: C,
7975
+ SVGFESpecularLightingElement: C,
7976
+ SVGFESpotLightElement: C,
7977
+ SVGFETileElement: C,
7978
+ SVGFETurbulenceElement: C,
7979
+ SVGFilterElement: C,
7980
+ SVGForeignObjectElement: C,
7981
+ SVGGElement: C,
7982
+ SVGGeometryElement: C,
7983
+ SVGGradientElement: C,
7984
+ SVGGraphicsElement: C,
7985
+ SVGImageElement: C,
7986
+ SVGLength: C,
7987
+ SVGLengthList: C,
7988
+ SVGLinearGradientElement: C,
7989
+ SVGLineElement: C,
7990
+ SVGMarkerElement: C,
7991
+ SVGMaskElement: C,
7992
+ SVGMatrix: C,
7993
+ SVGMetadataElement: C,
7994
+ SVGMPathElement: C,
7995
+ SVGNumber: C,
7996
+ SVGNumberList: C,
7997
+ SVGPathElement: C,
7998
+ SVGPatternElement: C,
7999
+ SVGPoint: C,
8000
+ SVGPointList: C,
8001
+ SVGPolygonElement: C,
8002
+ SVGPolylineElement: C,
8003
+ SVGPreserveAspectRatio: C,
8004
+ SVGRadialGradientElement: C,
8005
+ SVGRect: C,
8006
+ SVGRectElement: C,
8007
+ SVGScriptElement: C,
8008
+ SVGSetElement: C,
8009
+ SVGStopElement: C,
8010
+ SVGStringList: C,
8011
+ SVGStyleElement: C,
8012
+ SVGSVGElement: C,
8013
+ SVGSwitchElement: C,
8014
+ SVGSymbolElement: C,
8015
+ SVGTextContentElement: C,
8016
+ SVGTextElement: C,
8017
+ SVGTextPathElement: C,
8018
+ SVGTextPositioningElement: C,
8019
+ SVGTitleElement: C,
8020
+ SVGTransform: C,
8021
+ SVGTransformList: C,
8022
+ SVGTSpanElement: C,
8023
+ SVGUnitTypes: C,
8024
+ SVGUseElement: C,
8025
+ SVGViewElement: C,
8026
+ TaskAttributionTiming: C,
8027
+ Text: C,
8028
+ TextEvent: C,
8029
+ TextMetrics: C,
8030
+ TextTrack: C,
8031
+ TextTrackCue: C,
8032
+ TextTrackCueList: C,
8033
+ TextTrackList: C,
8034
+ TimeRanges: C,
8035
+ toolbar: O,
8036
+ top: O,
8037
+ Touch: C,
8038
+ TouchEvent: C,
8039
+ TouchList: C,
8040
+ TrackEvent: C,
8041
+ TransitionEvent: C,
8042
+ TreeWalker: C,
8043
+ UIEvent: C,
8044
+ ValidityState: C,
8045
+ visualViewport: O,
8046
+ VisualViewport: C,
8047
+ VTTCue: C,
8048
+ WaveShaperNode: C,
8049
+ WebAssembly: O,
8050
+ WebGL2RenderingContext: C,
8051
+ WebGLActiveInfo: C,
8052
+ WebGLBuffer: C,
8053
+ WebGLContextEvent: C,
8054
+ WebGLFramebuffer: C,
8055
+ WebGLProgram: C,
8056
+ WebGLQuery: C,
8057
+ WebGLRenderbuffer: C,
8058
+ WebGLRenderingContext: C,
8059
+ WebGLSampler: C,
8060
+ WebGLShader: C,
8061
+ WebGLShaderPrecisionFormat: C,
8062
+ WebGLSync: C,
8063
+ WebGLTexture: C,
8064
+ WebGLTransformFeedback: C,
8065
+ WebGLUniformLocation: C,
8066
+ WebGLVertexArrayObject: C,
8067
+ WebSocket: C,
8068
+ WheelEvent: C,
8069
+ Window: C,
8070
+ Worker: C,
8071
+ WritableStream: C,
8072
+ XMLDocument: C,
8073
+ XMLHttpRequest: C,
8074
+ XMLHttpRequestEventTarget: C,
8075
+ XMLHttpRequestUpload: C,
8076
+ XMLSerializer: C,
8077
+ XPathEvaluator: C,
8078
+ XPathExpression: C,
8079
+ XPathResult: C,
8080
+ XSLTProcessor: C
8081
+ };
8082
+ for (const global of ['window', 'global', 'self', 'globalThis']) {
8083
+ knownGlobals[global] = knownGlobals;
7896
8084
  }
7897
-
7898
- class BlockScope extends ChildScope {
7899
- addDeclaration(identifier, context, init, isHoisted) {
7900
- if (isHoisted) {
7901
- const variable = this.parent.addDeclaration(identifier, context, init, isHoisted);
7902
- // Necessary to make sure the init is deoptimized for conditional declarations.
7903
- // We cannot call deoptimizePath here.
7904
- variable.markInitializersForDeoptimization();
7905
- return variable;
7906
- }
7907
- else {
7908
- return super.addDeclaration(identifier, context, init, false);
8085
+ function getGlobalAtPath(path) {
8086
+ let currentGlobal = knownGlobals;
8087
+ for (const pathSegment of path) {
8088
+ if (typeof pathSegment !== 'string') {
8089
+ return null;
7909
8090
  }
7910
- }
7911
- }
7912
-
7913
- class ExpressionStatement extends NodeBase {
7914
- initialise() {
7915
- if (this.directive &&
7916
- this.directive !== 'use strict' &&
7917
- this.parent.type === Program$1) {
7918
- this.context.warn(
7919
- // This is necessary, because either way (deleting or not) can lead to errors.
7920
- {
7921
- code: 'MODULE_LEVEL_DIRECTIVE',
7922
- message: `Module level directives cause errors when bundled, '${this.directive}' was ignored.`
7923
- }, this.start);
8091
+ currentGlobal = currentGlobal[pathSegment];
8092
+ if (!currentGlobal) {
8093
+ return null;
7924
8094
  }
7925
8095
  }
7926
- render(code, options) {
7927
- super.render(code, options);
7928
- if (this.included)
7929
- this.insertSemicolon(code);
7930
- }
7931
- shouldBeIncluded(context) {
7932
- if (this.directive && this.directive !== 'use strict')
7933
- return this.parent.type !== Program$1;
7934
- return super.shouldBeIncluded(context);
7935
- }
8096
+ return currentGlobal[ValueProperties];
7936
8097
  }
7937
8098
 
7938
- class BlockStatement extends NodeBase {
8099
+ class GlobalVariable extends Variable {
7939
8100
  constructor() {
7940
8101
  super(...arguments);
7941
- this.directlyIncluded = false;
7942
- }
7943
- addImplicitReturnExpressionToScope() {
7944
- const lastStatement = this.body[this.body.length - 1];
7945
- if (!lastStatement || lastStatement.type !== ReturnStatement$1) {
7946
- this.scope.addReturnExpression(UNKNOWN_EXPRESSION);
7947
- }
7948
- }
7949
- createScope(parentScope) {
7950
- this.scope = this.parent.preventChildBlockScope
7951
- ? parentScope
7952
- : new BlockScope(parentScope);
8102
+ // Ensure we use live-bindings for globals as we do not know if they have
8103
+ // been reassigned
8104
+ this.isReassigned = true;
7953
8105
  }
7954
- hasEffects(context) {
7955
- if (this.deoptimizeBody)
7956
- return true;
7957
- for (const node of this.body) {
7958
- if (context.brokenFlow)
7959
- break;
7960
- if (node.hasEffects(context))
7961
- return true;
7962
- }
7963
- return false;
8106
+ getLiteralValueAtPath(path, _recursionTracker, _origin) {
8107
+ return getGlobalAtPath([this.name, ...path]) ? UnknownTruthyValue : UnknownValue;
7964
8108
  }
7965
- include(context, includeChildrenRecursively) {
7966
- if (!(this.deoptimizeBody && this.directlyIncluded)) {
7967
- this.included = true;
7968
- this.directlyIncluded = true;
7969
- if (this.deoptimizeBody)
7970
- includeChildrenRecursively = true;
7971
- for (const node of this.body) {
7972
- if (includeChildrenRecursively || node.shouldBeIncluded(context))
7973
- node.include(context, includeChildrenRecursively);
7974
- }
8109
+ hasEffectsWhenAccessedAtPath(path) {
8110
+ if (path.length === 0) {
8111
+ // Technically, "undefined" is a global variable of sorts
8112
+ return this.name !== 'undefined' && !getGlobalAtPath([this.name]);
7975
8113
  }
8114
+ return !getGlobalAtPath([this.name, ...path].slice(0, -1));
7976
8115
  }
7977
- initialise() {
7978
- const firstBodyStatement = this.body[0];
7979
- this.deoptimizeBody =
7980
- firstBodyStatement instanceof ExpressionStatement &&
7981
- firstBodyStatement.directive === 'use asm';
7982
- }
7983
- render(code, options) {
7984
- if (this.body.length) {
7985
- renderStatementList(this.body, code, this.start + 1, this.end - 1, options);
7986
- }
7987
- else {
7988
- super.render(code, options);
7989
- }
8116
+ hasEffectsWhenCalledAtPath(path, callOptions, context) {
8117
+ const globalAtPath = getGlobalAtPath([this.name, ...path]);
8118
+ return !globalAtPath || globalAtPath.hasEffectsWhenCalled(callOptions, context);
7990
8119
  }
7991
8120
  }
7992
8121
 
7993
- class RestElement extends NodeBase {
8122
+ const tdzVariableKinds = {
8123
+ __proto__: null,
8124
+ class: true,
8125
+ const: true,
8126
+ let: true,
8127
+ var: true
8128
+ };
8129
+ class Identifier extends NodeBase {
7994
8130
  constructor() {
7995
8131
  super(...arguments);
8132
+ this.variable = null;
7996
8133
  this.deoptimized = false;
7997
- this.declarationInit = null;
8134
+ this.isTDZAccess = null;
7998
8135
  }
7999
8136
  addExportedVariables(variables, exportNamesByVariable) {
8000
- this.argument.addExportedVariables(variables, exportNamesByVariable);
8001
- }
8002
- declare(kind, init) {
8003
- this.declarationInit = init;
8004
- return this.argument.declare(kind, UNKNOWN_EXPRESSION);
8005
- }
8006
- deoptimizePath(path) {
8007
- path.length === 0 && this.argument.deoptimizePath(EMPTY_PATH);
8008
- }
8009
- hasEffectsWhenAssignedAtPath(path, context) {
8010
- return path.length > 0 || this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
8011
- }
8012
- markDeclarationReached() {
8013
- this.argument.markDeclarationReached();
8137
+ if (exportNamesByVariable.has(this.variable)) {
8138
+ variables.push(this.variable);
8139
+ }
8014
8140
  }
8015
- applyDeoptimizations() {
8016
- this.deoptimized = true;
8017
- if (this.declarationInit !== null) {
8018
- this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
8019
- this.context.requestTreeshakingPass();
8141
+ bind() {
8142
+ if (!this.variable && is_reference(this, this.parent)) {
8143
+ this.variable = this.scope.findVariable(this.name);
8144
+ this.variable.addReference(this);
8020
8145
  }
8021
8146
  }
8022
- }
8023
-
8024
- class FunctionBase extends NodeBase {
8025
- constructor() {
8026
- super(...arguments);
8027
- this.objectEntity = null;
8028
- this.deoptimizedReturn = false;
8147
+ declare(kind, init) {
8148
+ let variable;
8149
+ const { treeshake } = this.context.options;
8150
+ switch (kind) {
8151
+ case 'var':
8152
+ variable = this.scope.addDeclaration(this, this.context, init, true);
8153
+ if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
8154
+ // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
8155
+ variable.markInitializersForDeoptimization();
8156
+ }
8157
+ break;
8158
+ case 'function':
8159
+ // in strict mode, functions are only hoisted within a scope but not across block scopes
8160
+ variable = this.scope.addDeclaration(this, this.context, init, false);
8161
+ break;
8162
+ case 'let':
8163
+ case 'const':
8164
+ case 'class':
8165
+ variable = this.scope.addDeclaration(this, this.context, init, false);
8166
+ break;
8167
+ case 'parameter':
8168
+ variable = this.scope.addParameterDeclaration(this);
8169
+ break;
8170
+ /* istanbul ignore next */
8171
+ default:
8172
+ /* istanbul ignore next */
8173
+ throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
8174
+ }
8175
+ variable.kind = kind;
8176
+ return [(this.variable = variable)];
8029
8177
  }
8030
8178
  deoptimizePath(path) {
8031
- this.getObjectEntity().deoptimizePath(path);
8032
- if (path.length === 1 && path[0] === UnknownKey) {
8033
- // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
8034
- // which means the return expression needs to be reassigned
8035
- this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
8179
+ if (path.length === 0 && !this.scope.contains(this.name)) {
8180
+ this.disallowImportReassignment();
8036
8181
  }
8182
+ this.variable.deoptimizePath(path);
8037
8183
  }
8038
8184
  deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
8039
- if (path.length > 0) {
8040
- this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
8041
- }
8185
+ this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
8042
8186
  }
8043
8187
  getLiteralValueAtPath(path, recursionTracker, origin) {
8044
- return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
8188
+ return this.getVariableRespectingTDZ().getLiteralValueAtPath(path, recursionTracker, origin);
8045
8189
  }
8046
8190
  getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
8047
- if (path.length > 0) {
8048
- return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
8049
- }
8050
- if (this.async) {
8051
- if (!this.deoptimizedReturn) {
8052
- this.deoptimizedReturn = true;
8053
- this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
8054
- this.context.requestTreeshakingPass();
8055
- }
8056
- return UNKNOWN_EXPRESSION;
8191
+ return this.getVariableRespectingTDZ().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
8192
+ }
8193
+ hasEffects() {
8194
+ if (!this.deoptimized)
8195
+ this.applyDeoptimizations();
8196
+ if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
8197
+ return true;
8057
8198
  }
8058
- return this.scope.getReturnExpression();
8199
+ return (this.context.options.treeshake.unknownGlobalSideEffects &&
8200
+ this.variable instanceof GlobalVariable &&
8201
+ this.variable.hasEffectsWhenAccessedAtPath(EMPTY_PATH));
8059
8202
  }
8060
8203
  hasEffectsWhenAccessedAtPath(path, context) {
8061
- return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
8204
+ return (this.variable !== null &&
8205
+ this.getVariableRespectingTDZ().hasEffectsWhenAccessedAtPath(path, context));
8062
8206
  }
8063
8207
  hasEffectsWhenAssignedAtPath(path, context) {
8064
- return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
8208
+ return (path.length > 0 ? this.getVariableRespectingTDZ() : this.variable).hasEffectsWhenAssignedAtPath(path, context);
8065
8209
  }
8066
8210
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
8067
- if (path.length > 0) {
8068
- return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
8069
- }
8070
- if (this.async) {
8071
- const { propertyReadSideEffects } = this.context.options
8072
- .treeshake;
8073
- const returnExpression = this.scope.getReturnExpression();
8074
- if (returnExpression.hasEffectsWhenCalledAtPath(['then'], { args: NO_ARGS, thisParam: null, withNew: false }, context) ||
8075
- (propertyReadSideEffects &&
8076
- (propertyReadSideEffects === 'always' ||
8077
- returnExpression.hasEffectsWhenAccessedAtPath(['then'], context)))) {
8078
- return true;
8211
+ return this.getVariableRespectingTDZ().hasEffectsWhenCalledAtPath(path, callOptions, context);
8212
+ }
8213
+ include() {
8214
+ if (!this.deoptimized)
8215
+ this.applyDeoptimizations();
8216
+ if (!this.included) {
8217
+ this.included = true;
8218
+ if (this.variable !== null) {
8219
+ this.context.includeVariableInModule(this.variable);
8079
8220
  }
8080
8221
  }
8081
- for (const param of this.params) {
8082
- if (param.hasEffects(context))
8083
- return true;
8084
- }
8085
- return false;
8086
- }
8087
- include(context, includeChildrenRecursively) {
8088
- this.included = true;
8089
- const { brokenFlow } = context;
8090
- context.brokenFlow = BROKEN_FLOW_NONE;
8091
- this.body.include(context, includeChildrenRecursively);
8092
- context.brokenFlow = brokenFlow;
8093
8222
  }
8094
8223
  includeCallArguments(context, args) {
8095
- this.scope.includeCallArguments(context, args);
8224
+ this.variable.includeCallArguments(context, args);
8096
8225
  }
8097
- initialise() {
8098
- this.scope.addParameterVariables(this.params.map(param => param.declare('parameter', UNKNOWN_EXPRESSION)), this.params[this.params.length - 1] instanceof RestElement);
8099
- if (this.body instanceof BlockStatement) {
8100
- this.body.addImplicitReturnExpressionToScope();
8226
+ isPossibleTDZ() {
8227
+ // return cached value to avoid issues with the next tree-shaking pass
8228
+ if (this.isTDZAccess !== null)
8229
+ return this.isTDZAccess;
8230
+ if (!(this.variable instanceof LocalVariable) ||
8231
+ !this.variable.kind ||
8232
+ !(this.variable.kind in tdzVariableKinds)) {
8233
+ return (this.isTDZAccess = false);
8101
8234
  }
8102
- else {
8103
- this.scope.addReturnExpression(this.body);
8235
+ let decl_id;
8236
+ if (this.variable.declarations &&
8237
+ this.variable.declarations.length === 1 &&
8238
+ (decl_id = this.variable.declarations[0]) &&
8239
+ this.start < decl_id.start &&
8240
+ closestParentFunctionOrProgram(this) === closestParentFunctionOrProgram(decl_id)) {
8241
+ // a variable accessed before its declaration
8242
+ // in the same function or at top level of module
8243
+ return (this.isTDZAccess = true);
8104
8244
  }
8105
- }
8106
- parseNode(esTreeNode) {
8107
- if (esTreeNode.body.type === BlockStatement$1) {
8108
- this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
8245
+ if (!this.variable.initReached) {
8246
+ // Either a const/let TDZ violation or
8247
+ // var use before declaration was encountered.
8248
+ return (this.isTDZAccess = true);
8109
8249
  }
8110
- super.parseNode(esTreeNode);
8111
- }
8112
- }
8113
- FunctionBase.prototype.preventChildBlockScope = true;
8114
-
8115
- class ArrowFunctionExpression extends FunctionBase {
8116
- constructor() {
8117
- super(...arguments);
8118
- this.objectEntity = null;
8119
- }
8120
- createScope(parentScope) {
8121
- this.scope = new ReturnValueScope(parentScope, this.context);
8122
- }
8123
- hasEffects() {
8124
- return false;
8250
+ return (this.isTDZAccess = false);
8125
8251
  }
8126
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
8127
- if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
8128
- return true;
8129
- const { ignore, brokenFlow } = context;
8130
- context.ignore = {
8131
- breaks: false,
8132
- continues: false,
8133
- labels: new Set(),
8134
- returnYield: true
8135
- };
8136
- if (this.body.hasEffects(context))
8137
- return true;
8138
- context.ignore = ignore;
8139
- context.brokenFlow = brokenFlow;
8140
- return false;
8252
+ markDeclarationReached() {
8253
+ this.variable.initReached = true;
8141
8254
  }
8142
- include(context, includeChildrenRecursively) {
8143
- super.include(context, includeChildrenRecursively);
8144
- for (const param of this.params) {
8145
- if (!(param instanceof Identifier)) {
8146
- param.include(context, includeChildrenRecursively);
8255
+ render(code, { snippets: { getPropertyAccess } }, { renderedParentType, isCalleeOfRenderedParent, isShorthandProperty } = BLANK) {
8256
+ if (this.variable) {
8257
+ const name = this.variable.getName(getPropertyAccess);
8258
+ if (name !== this.name) {
8259
+ code.overwrite(this.start, this.end, name, {
8260
+ contentOnly: true,
8261
+ storeName: true
8262
+ });
8263
+ if (isShorthandProperty) {
8264
+ code.prependRight(this.start, `${this.name}: `);
8265
+ }
8266
+ }
8267
+ // In strict mode, any variable named "eval" must be the actual "eval" function
8268
+ if (name === 'eval' &&
8269
+ renderedParentType === CallExpression$1 &&
8270
+ isCalleeOfRenderedParent) {
8271
+ code.appendRight(this.start, '0, ');
8147
8272
  }
8148
8273
  }
8149
8274
  }
8150
- getObjectEntity() {
8151
- if (this.objectEntity !== null) {
8152
- return this.objectEntity;
8275
+ applyDeoptimizations() {
8276
+ this.deoptimized = true;
8277
+ if (this.variable instanceof LocalVariable) {
8278
+ this.variable.consolidateInitializers();
8279
+ this.context.requestTreeshakingPass();
8153
8280
  }
8154
- return (this.objectEntity = new ObjectEntity([], OBJECT_PROTOTYPE));
8155
8281
  }
8156
- }
8157
-
8158
- function getSystemExportStatement(exportedVariables, { exportNamesByVariable, snippets: { _, getObject, getPropertyAccess } }, modifier = '') {
8159
- if (exportedVariables.length === 1 &&
8160
- exportNamesByVariable.get(exportedVariables[0]).length === 1) {
8161
- const variable = exportedVariables[0];
8162
- return `exports('${exportNamesByVariable.get(variable)}',${_}${variable.getName(getPropertyAccess)}${modifier})`;
8282
+ disallowImportReassignment() {
8283
+ return this.context.error({
8284
+ code: 'ILLEGAL_REASSIGNMENT',
8285
+ message: `Illegal reassignment to import '${this.name}'`
8286
+ }, this.start);
8163
8287
  }
8164
- else {
8165
- const fields = [];
8166
- for (const variable of exportedVariables) {
8167
- for (const exportName of exportNamesByVariable.get(variable)) {
8168
- fields.push([exportName, variable.getName(getPropertyAccess) + modifier]);
8169
- }
8288
+ getVariableRespectingTDZ() {
8289
+ if (this.isPossibleTDZ()) {
8290
+ return UNKNOWN_EXPRESSION;
8170
8291
  }
8171
- return `exports(${getObject(fields, { lineBreakIndent: null })})`;
8172
- }
8173
- }
8174
- function renderSystemExportExpression(exportedVariable, expressionStart, expressionEnd, code, { exportNamesByVariable, snippets: { _ } }) {
8175
- code.prependRight(expressionStart, `exports('${exportNamesByVariable.get(exportedVariable)}',${_}`);
8176
- code.appendLeft(expressionEnd, ')');
8177
- }
8178
- function renderSystemExportFunction(exportedVariables, expressionStart, expressionEnd, needsParens, code, options) {
8179
- const { _, getDirectReturnIifeLeft } = options.snippets;
8180
- code.prependRight(expressionStart, getDirectReturnIifeLeft(['v'], `${getSystemExportStatement(exportedVariables, options)},${_}v`, { needsArrowReturnParens: true, needsWrappedFunction: needsParens }));
8181
- code.appendLeft(expressionEnd, ')');
8182
- }
8183
- function renderSystemExportSequenceAfterExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options) {
8184
- const { _, getPropertyAccess } = options.snippets;
8185
- code.appendLeft(expressionEnd, `,${_}${getSystemExportStatement([exportedVariable], options)},${_}${exportedVariable.getName(getPropertyAccess)}`);
8186
- if (needsParens) {
8187
- code.prependRight(expressionStart, '(');
8188
- code.appendLeft(expressionEnd, ')');
8292
+ return this.variable;
8189
8293
  }
8190
8294
  }
8191
- function renderSystemExportSequenceBeforeExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options, modifier) {
8192
- const { _ } = options.snippets;
8193
- code.prependRight(expressionStart, `${getSystemExportStatement([exportedVariable], options, modifier)},${_}`);
8194
- if (needsParens) {
8195
- code.prependRight(expressionStart, '(');
8196
- code.appendLeft(expressionEnd, ')');
8295
+ function closestParentFunctionOrProgram(node) {
8296
+ while (node && !/^Program|Function/.test(node.type)) {
8297
+ node = node.parent;
8197
8298
  }
8299
+ // one of: ArrowFunctionExpression, FunctionDeclaration, FunctionExpression or Program
8300
+ return node;
8198
8301
  }
8199
8302
 
8200
8303
  class ObjectPattern extends NodeBase {
@@ -8305,47 +8408,15 @@ class AssignmentExpression extends NodeBase {
8305
8408
  renderSystemExportFunction(systemPatternExports, this.start, this.end, renderedSurroundingElement === ExpressionStatement$1, code, options);
8306
8409
  return;
8307
8410
  }
8308
- }
8309
- }
8310
- if (this.left.included &&
8311
- this.left instanceof ObjectPattern &&
8312
- (renderedSurroundingElement === ExpressionStatement$1 ||
8313
- renderedSurroundingElement === ArrowFunctionExpression$1)) {
8314
- code.appendRight(this.start, '(');
8315
- code.prependLeft(this.end, ')');
8316
- }
8317
- }
8318
- applyDeoptimizations() {
8319
- this.deoptimized = true;
8320
- this.left.deoptimizePath(EMPTY_PATH);
8321
- this.right.deoptimizePath(UNKNOWN_PATH);
8322
- this.context.requestTreeshakingPass();
8323
- }
8324
- }
8325
-
8326
- class AssignmentPattern extends NodeBase {
8327
- constructor() {
8328
- super(...arguments);
8329
- this.deoptimized = false;
8330
- }
8331
- addExportedVariables(variables, exportNamesByVariable) {
8332
- this.left.addExportedVariables(variables, exportNamesByVariable);
8333
- }
8334
- declare(kind, init) {
8335
- return this.left.declare(kind, init);
8336
- }
8337
- deoptimizePath(path) {
8338
- path.length === 0 && this.left.deoptimizePath(path);
8339
- }
8340
- hasEffectsWhenAssignedAtPath(path, context) {
8341
- return path.length > 0 || this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
8342
- }
8343
- markDeclarationReached() {
8344
- this.left.markDeclarationReached();
8345
- }
8346
- render(code, options, { isShorthandProperty } = BLANK) {
8347
- this.left.render(code, options, { isShorthandProperty });
8348
- this.right.render(code, options);
8411
+ }
8412
+ }
8413
+ if (this.left.included &&
8414
+ this.left instanceof ObjectPattern &&
8415
+ (renderedSurroundingElement === ExpressionStatement$1 ||
8416
+ renderedSurroundingElement === ArrowFunctionExpression$1)) {
8417
+ code.appendRight(this.start, '(');
8418
+ code.prependLeft(this.end, ')');
8419
+ }
8349
8420
  }
8350
8421
  applyDeoptimizations() {
8351
8422
  this.deoptimized = true;
@@ -8462,7 +8533,8 @@ class FunctionNode extends FunctionBase {
8462
8533
  }
8463
8534
  }
8464
8535
  hasEffects() {
8465
- return this.id !== null && this.id.hasEffects();
8536
+ var _a;
8537
+ return !!((_a = this.id) === null || _a === void 0 ? void 0 : _a.hasEffects());
8466
8538
  }
8467
8539
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
8468
8540
  if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
@@ -8490,16 +8562,12 @@ class FunctionNode extends FunctionBase {
8490
8562
  context.ignore = ignore;
8491
8563
  return false;
8492
8564
  }
8493
- include(context, includeChildrenRecursively) {
8494
- super.include(context, includeChildrenRecursively);
8495
- if (this.id)
8496
- this.id.include();
8497
- const hasArguments = this.scope.argumentsVariable.included;
8498
- for (const param of this.params) {
8499
- if (!(param instanceof Identifier) || hasArguments) {
8500
- param.include(context, includeChildrenRecursively);
8501
- }
8502
- }
8565
+ include(context, includeChildrenRecursively, { includeWithoutParameterDefaults } = BLANK) {
8566
+ var _a;
8567
+ (_a = this.id) === null || _a === void 0 ? void 0 : _a.include();
8568
+ super.include(context, includeChildrenRecursively, {
8569
+ includeWithoutParameterDefaults: includeWithoutParameterDefaults && !this.scope.argumentsVariable.included
8570
+ });
8503
8571
  }
8504
8572
  initialise() {
8505
8573
  var _a;
@@ -8546,11 +8614,6 @@ class AwaitExpression extends NodeBase {
8546
8614
  }
8547
8615
  this.argument.include(context, includeChildrenRecursively);
8548
8616
  }
8549
- applyDeoptimizations() {
8550
- this.deoptimized = true;
8551
- this.argument.deoptimizePath(UNKNOWN_PATH);
8552
- this.context.requestTreeshakingPass();
8553
- }
8554
8617
  }
8555
8618
 
8556
8619
  const binaryOperators = {
@@ -8574,9 +8637,10 @@ const binaryOperators = {
8574
8637
  '>>': (left, right) => left >> right,
8575
8638
  '>>>': (left, right) => left >>> right,
8576
8639
  '^': (left, right) => left ^ right,
8577
- in: () => UnknownValue,
8578
- instanceof: () => UnknownValue,
8579
8640
  '|': (left, right) => left | right
8641
+ // We use the fallback for cases where we return something unknown
8642
+ // in: () => UnknownValue,
8643
+ // instanceof: () => UnknownValue,
8580
8644
  };
8581
8645
  class BinaryExpression extends NodeBase {
8582
8646
  deoptimizeCache() { }
@@ -8584,10 +8648,10 @@ class BinaryExpression extends NodeBase {
8584
8648
  if (path.length > 0)
8585
8649
  return UnknownValue;
8586
8650
  const leftValue = this.left.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
8587
- if (leftValue === UnknownValue)
8651
+ if (typeof leftValue === 'symbol')
8588
8652
  return UnknownValue;
8589
8653
  const rightValue = this.right.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
8590
- if (rightValue === UnknownValue)
8654
+ if (typeof rightValue === 'symbol')
8591
8655
  return UnknownValue;
8592
8656
  const operatorFn = binaryOperators[this.operator];
8593
8657
  if (!operatorFn)
@@ -8660,9 +8724,6 @@ class Literal extends NodeBase {
8660
8724
  }
8661
8725
  return path.length > 1;
8662
8726
  }
8663
- hasEffectsWhenAssignedAtPath(path) {
8664
- return path.length > 0;
8665
- }
8666
8727
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
8667
8728
  if (path.length === 1) {
8668
8729
  return hasMemberEffectWhenCalled(this.members, path[0], callOptions, context);
@@ -8945,7 +9006,7 @@ class MemberExpression extends NodeBase {
8945
9006
  if (this.propertyKey === null) {
8946
9007
  this.propertyKey = UnknownKey;
8947
9008
  const value = this.property.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
8948
- return (this.propertyKey = value === UnknownValue ? UnknownKey : String(value));
9009
+ return (this.propertyKey = typeof value === 'symbol' ? UnknownKey : String(value));
8949
9010
  }
8950
9011
  return this.propertyKey;
8951
9012
  }
@@ -8972,39 +9033,13 @@ class MemberExpression extends NodeBase {
8972
9033
  }
8973
9034
  }
8974
9035
 
8975
- class CallExpression extends NodeBase {
9036
+ class CallExpressionBase extends NodeBase {
8976
9037
  constructor() {
8977
9038
  super(...arguments);
8978
9039
  this.deoptimized = false;
9040
+ this.returnExpression = null;
8979
9041
  this.deoptimizableDependentExpressions = [];
8980
9042
  this.expressionsToBeDeoptimized = new Set();
8981
- this.returnExpression = null;
8982
- }
8983
- bind() {
8984
- super.bind();
8985
- if (this.callee instanceof Identifier) {
8986
- const variable = this.scope.findVariable(this.callee.name);
8987
- if (variable.isNamespace) {
8988
- this.context.warn({
8989
- code: 'CANNOT_CALL_NAMESPACE',
8990
- message: `Cannot call a namespace ('${this.callee.name}')`
8991
- }, this.start);
8992
- }
8993
- if (this.callee.name === 'eval') {
8994
- this.context.warn({
8995
- code: 'EVAL',
8996
- message: `Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification`,
8997
- url: 'https://rollupjs.org/guide/en/#avoiding-eval'
8998
- }, this.start);
8999
- }
9000
- }
9001
- this.callOptions = {
9002
- args: this.arguments,
9003
- thisParam: this.callee instanceof MemberExpression && !this.callee.variable
9004
- ? this.callee.object
9005
- : null,
9006
- withNew: false
9007
- };
9008
9043
  }
9009
9044
  deoptimizeCache() {
9010
9045
  if (this.returnExpression !== UNKNOWN_EXPRESSION) {
@@ -9059,6 +9094,47 @@ class CallExpression extends NodeBase {
9059
9094
  return returnExpression.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
9060
9095
  }, UNKNOWN_EXPRESSION);
9061
9096
  }
9097
+ hasEffectsWhenAccessedAtPath(path, context) {
9098
+ return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
9099
+ this.getReturnExpression().hasEffectsWhenAccessedAtPath(path, context));
9100
+ }
9101
+ hasEffectsWhenAssignedAtPath(path, context) {
9102
+ return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
9103
+ this.getReturnExpression().hasEffectsWhenAssignedAtPath(path, context));
9104
+ }
9105
+ hasEffectsWhenCalledAtPath(path, callOptions, context) {
9106
+ return (!(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
9107
+ this.getReturnExpression().hasEffectsWhenCalledAtPath(path, callOptions, context));
9108
+ }
9109
+ }
9110
+
9111
+ class CallExpression extends CallExpressionBase {
9112
+ bind() {
9113
+ super.bind();
9114
+ if (this.callee instanceof Identifier) {
9115
+ const variable = this.scope.findVariable(this.callee.name);
9116
+ if (variable.isNamespace) {
9117
+ this.context.warn({
9118
+ code: 'CANNOT_CALL_NAMESPACE',
9119
+ message: `Cannot call a namespace ('${this.callee.name}')`
9120
+ }, this.start);
9121
+ }
9122
+ if (this.callee.name === 'eval') {
9123
+ this.context.warn({
9124
+ code: 'EVAL',
9125
+ message: `Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification`,
9126
+ url: 'https://rollupjs.org/guide/en/#avoiding-eval'
9127
+ }, this.start);
9128
+ }
9129
+ }
9130
+ this.callOptions = {
9131
+ args: this.arguments,
9132
+ thisParam: this.callee instanceof MemberExpression && !this.callee.variable
9133
+ ? this.callee.object
9134
+ : null,
9135
+ withNew: false
9136
+ };
9137
+ }
9062
9138
  hasEffects(context) {
9063
9139
  try {
9064
9140
  for (const argument of this.arguments) {
@@ -9076,18 +9152,6 @@ class CallExpression extends NodeBase {
9076
9152
  this.applyDeoptimizations();
9077
9153
  }
9078
9154
  }
9079
- hasEffectsWhenAccessedAtPath(path, context) {
9080
- return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
9081
- this.getReturnExpression().hasEffectsWhenAccessedAtPath(path, context));
9082
- }
9083
- hasEffectsWhenAssignedAtPath(path, context) {
9084
- return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
9085
- this.getReturnExpression().hasEffectsWhenAssignedAtPath(path, context));
9086
- }
9087
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
9088
- return (!(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
9089
- this.getReturnExpression().hasEffectsWhenCalledAtPath(path, callOptions, context));
9090
- }
9091
9155
  include(context, includeChildrenRecursively) {
9092
9156
  if (!this.deoptimized)
9093
9157
  this.applyDeoptimizations();
@@ -9101,7 +9165,7 @@ class CallExpression extends NodeBase {
9101
9165
  }
9102
9166
  else {
9103
9167
  this.included = true;
9104
- this.callee.include(context, false);
9168
+ this.callee.include(context, false, { includeWithoutParameterDefaults: true });
9105
9169
  }
9106
9170
  this.callee.includeCallArguments(context, this.arguments);
9107
9171
  const returnExpression = this.getReturnExpression();
@@ -9310,8 +9374,6 @@ class ObjectMember extends ExpressionEntity {
9310
9374
  return this.object.getReturnExpressionWhenCalledAtPath([this.key, ...path], callOptions, recursionTracker, origin);
9311
9375
  }
9312
9376
  hasEffectsWhenAccessedAtPath(path, context) {
9313
- if (path.length === 0)
9314
- return false;
9315
9377
  return this.object.hasEffectsWhenAccessedAtPath([this.key, ...path], context);
9316
9378
  }
9317
9379
  hasEffectsWhenAssignedAtPath(path, context) {
@@ -9325,6 +9387,7 @@ class ObjectMember extends ExpressionEntity {
9325
9387
  class ClassNode extends NodeBase {
9326
9388
  constructor() {
9327
9389
  super(...arguments);
9390
+ this.deoptimized = false;
9328
9391
  this.objectEntity = null;
9329
9392
  }
9330
9393
  createScope(parentScope) {
@@ -9334,7 +9397,14 @@ class ClassNode extends NodeBase {
9334
9397
  this.getObjectEntity().deoptimizeAllProperties();
9335
9398
  }
9336
9399
  deoptimizePath(path) {
9400
+ var _a, _b;
9337
9401
  this.getObjectEntity().deoptimizePath(path);
9402
+ if (path.length === 1 && path[0] === UnknownKey) {
9403
+ // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
9404
+ // which means the constructor needs to be reassigned
9405
+ (_a = this.classConstructor) === null || _a === void 0 ? void 0 : _a.deoptimizePath(UNKNOWN_PATH);
9406
+ (_b = this.superClass) === null || _b === void 0 ? void 0 : _b.deoptimizePath(UNKNOWN_PATH);
9407
+ }
9338
9408
  }
9339
9409
  deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
9340
9410
  this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
@@ -9347,6 +9417,8 @@ class ClassNode extends NodeBase {
9347
9417
  }
9348
9418
  hasEffects(context) {
9349
9419
  var _a, _b;
9420
+ if (!this.deoptimized)
9421
+ this.applyDeoptimizations();
9350
9422
  const initEffect = ((_a = this.superClass) === null || _a === void 0 ? void 0 : _a.hasEffects(context)) || this.body.hasEffects(context);
9351
9423
  (_b = this.id) === null || _b === void 0 ? void 0 : _b.markDeclarationReached();
9352
9424
  return initEffect || super.hasEffects(context);
@@ -9358,12 +9430,13 @@ class ClassNode extends NodeBase {
9358
9430
  return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
9359
9431
  }
9360
9432
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
9433
+ var _a;
9361
9434
  if (path.length === 0) {
9362
9435
  return (!callOptions.withNew ||
9363
9436
  (this.classConstructor !== null
9364
9437
  ? this.classConstructor.hasEffectsWhenCalledAtPath(EMPTY_PATH, callOptions, context)
9365
- : this.superClass !== null &&
9366
- this.superClass.hasEffectsWhenCalledAtPath(path, callOptions, context)));
9438
+ : (_a = this.superClass) === null || _a === void 0 ? void 0 : _a.hasEffectsWhenCalledAtPath(path, callOptions, context)) ||
9439
+ false);
9367
9440
  }
9368
9441
  else {
9369
9442
  return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
@@ -9371,6 +9444,8 @@ class ClassNode extends NodeBase {
9371
9444
  }
9372
9445
  include(context, includeChildrenRecursively) {
9373
9446
  var _a;
9447
+ if (!this.deoptimized)
9448
+ this.applyDeoptimizations();
9374
9449
  this.included = true;
9375
9450
  (_a = this.superClass) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
9376
9451
  this.body.include(context, includeChildrenRecursively);
@@ -9390,6 +9465,17 @@ class ClassNode extends NodeBase {
9390
9465
  }
9391
9466
  this.classConstructor = null;
9392
9467
  }
9468
+ applyDeoptimizations() {
9469
+ this.deoptimized = true;
9470
+ for (const definition of this.body.body) {
9471
+ if (!(definition.static ||
9472
+ (definition instanceof MethodDefinition && definition.kind === 'constructor'))) {
9473
+ // Calls to methods are not tracked, ensure that the return value is deoptimized
9474
+ definition.deoptimizePath(UNKNOWN_PATH);
9475
+ }
9476
+ }
9477
+ this.context.requestTreeshakingPass();
9478
+ }
9393
9479
  getObjectEntity() {
9394
9480
  if (this.objectEntity !== null) {
9395
9481
  return this.objectEntity;
@@ -9406,7 +9492,7 @@ class ClassNode extends NodeBase {
9406
9492
  let key;
9407
9493
  if (definition.computed) {
9408
9494
  const keyValue = definition.key.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
9409
- if (keyValue === UnknownValue) {
9495
+ if (typeof keyValue === 'symbol') {
9410
9496
  properties.push({ key: UnknownKey, kind, property: definition });
9411
9497
  continue;
9412
9498
  }
@@ -9528,7 +9614,7 @@ class ConditionalExpression extends NodeBase {
9528
9614
  }
9529
9615
  deoptimizePath(path) {
9530
9616
  const usedBranch = this.getUsedBranch();
9531
- if (usedBranch === null) {
9617
+ if (!usedBranch) {
9532
9618
  this.consequent.deoptimizePath(path);
9533
9619
  this.alternate.deoptimizePath(path);
9534
9620
  }
@@ -9542,14 +9628,14 @@ class ConditionalExpression extends NodeBase {
9542
9628
  }
9543
9629
  getLiteralValueAtPath(path, recursionTracker, origin) {
9544
9630
  const usedBranch = this.getUsedBranch();
9545
- if (usedBranch === null)
9631
+ if (!usedBranch)
9546
9632
  return UnknownValue;
9547
9633
  this.expressionsToBeDeoptimized.push(origin);
9548
9634
  return usedBranch.getLiteralValueAtPath(path, recursionTracker, origin);
9549
9635
  }
9550
9636
  getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
9551
9637
  const usedBranch = this.getUsedBranch();
9552
- if (usedBranch === null)
9638
+ if (!usedBranch)
9553
9639
  return new MultiExpression([
9554
9640
  this.consequent.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin),
9555
9641
  this.alternate.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin)
@@ -9561,14 +9647,14 @@ class ConditionalExpression extends NodeBase {
9561
9647
  if (this.test.hasEffects(context))
9562
9648
  return true;
9563
9649
  const usedBranch = this.getUsedBranch();
9564
- if (usedBranch === null) {
9650
+ if (!usedBranch) {
9565
9651
  return this.consequent.hasEffects(context) || this.alternate.hasEffects(context);
9566
9652
  }
9567
9653
  return usedBranch.hasEffects(context);
9568
9654
  }
9569
9655
  hasEffectsWhenAccessedAtPath(path, context) {
9570
9656
  const usedBranch = this.getUsedBranch();
9571
- if (usedBranch === null) {
9657
+ if (!usedBranch) {
9572
9658
  return (this.consequent.hasEffectsWhenAccessedAtPath(path, context) ||
9573
9659
  this.alternate.hasEffectsWhenAccessedAtPath(path, context));
9574
9660
  }
@@ -9576,7 +9662,7 @@ class ConditionalExpression extends NodeBase {
9576
9662
  }
9577
9663
  hasEffectsWhenAssignedAtPath(path, context) {
9578
9664
  const usedBranch = this.getUsedBranch();
9579
- if (usedBranch === null) {
9665
+ if (!usedBranch) {
9580
9666
  return (this.consequent.hasEffectsWhenAssignedAtPath(path, context) ||
9581
9667
  this.alternate.hasEffectsWhenAssignedAtPath(path, context));
9582
9668
  }
@@ -9584,7 +9670,7 @@ class ConditionalExpression extends NodeBase {
9584
9670
  }
9585
9671
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
9586
9672
  const usedBranch = this.getUsedBranch();
9587
- if (usedBranch === null) {
9673
+ if (!usedBranch) {
9588
9674
  return (this.consequent.hasEffectsWhenCalledAtPath(path, callOptions, context) ||
9589
9675
  this.alternate.hasEffectsWhenCalledAtPath(path, callOptions, context));
9590
9676
  }
@@ -9604,7 +9690,7 @@ class ConditionalExpression extends NodeBase {
9604
9690
  }
9605
9691
  includeCallArguments(context, args) {
9606
9692
  const usedBranch = this.getUsedBranch();
9607
- if (usedBranch === null) {
9693
+ if (!usedBranch) {
9608
9694
  this.consequent.includeCallArguments(context, args);
9609
9695
  this.alternate.includeCallArguments(context, args);
9610
9696
  }
@@ -9646,7 +9732,7 @@ class ConditionalExpression extends NodeBase {
9646
9732
  }
9647
9733
  this.isBranchResolutionAnalysed = true;
9648
9734
  const testValue = this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
9649
- return testValue === UnknownValue
9735
+ return typeof testValue === 'symbol'
9650
9736
  ? null
9651
9737
  : (this.usedBranch = testValue ? this.consequent : this.alternate);
9652
9738
  }
@@ -9695,7 +9781,7 @@ class DoWhileStatement extends NodeBase {
9695
9781
  this.included = true;
9696
9782
  this.test.include(context, includeChildrenRecursively);
9697
9783
  const { brokenFlow } = context;
9698
- this.body.includeAsSingleStatement(context, includeChildrenRecursively);
9784
+ this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9699
9785
  context.brokenFlow = brokenFlow;
9700
9786
  }
9701
9787
  }
@@ -9720,6 +9806,9 @@ class ExportAllDeclaration extends NodeBase {
9720
9806
  ExportAllDeclaration.prototype.needsBoundaries = true;
9721
9807
 
9722
9808
  class FunctionDeclaration extends FunctionNode {
9809
+ include(context, includeChildrenRecursively) {
9810
+ super.include(context, includeChildrenRecursively, { includeWithoutParameterDefaults: true });
9811
+ }
9723
9812
  initialise() {
9724
9813
  super.initialise();
9725
9814
  if (this.id !== null) {
@@ -9823,12 +9912,13 @@ ExportDefaultDeclaration.prototype.needsBoundaries = true;
9823
9912
 
9824
9913
  class ExportNamedDeclaration extends NodeBase {
9825
9914
  bind() {
9915
+ var _a;
9826
9916
  // Do not bind specifiers
9827
- if (this.declaration !== null)
9828
- this.declaration.bind();
9917
+ (_a = this.declaration) === null || _a === void 0 ? void 0 : _a.bind();
9829
9918
  }
9830
9919
  hasEffects(context) {
9831
- return this.declaration !== null && this.declaration.hasEffects(context);
9920
+ var _a;
9921
+ return !!((_a = this.declaration) === null || _a === void 0 ? void 0 : _a.hasEffects(context));
9832
9922
  }
9833
9923
  initialise() {
9834
9924
  this.context.addExport(this);
@@ -9882,7 +9972,7 @@ class ForInStatement extends NodeBase {
9882
9972
  this.left.include(context, includeChildrenRecursively || true);
9883
9973
  this.right.include(context, includeChildrenRecursively);
9884
9974
  const { brokenFlow } = context;
9885
- this.body.includeAsSingleStatement(context, includeChildrenRecursively);
9975
+ this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9886
9976
  context.brokenFlow = brokenFlow;
9887
9977
  }
9888
9978
  render(code, options) {
@@ -9922,7 +10012,7 @@ class ForOfStatement extends NodeBase {
9922
10012
  this.left.include(context, includeChildrenRecursively || true);
9923
10013
  this.right.include(context, includeChildrenRecursively);
9924
10014
  const { brokenFlow } = context;
9925
- this.body.includeAsSingleStatement(context, includeChildrenRecursively);
10015
+ this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9926
10016
  context.brokenFlow = brokenFlow;
9927
10017
  }
9928
10018
  render(code, options) {
@@ -9946,9 +10036,10 @@ class ForStatement extends NodeBase {
9946
10036
  this.scope = new BlockScope(parentScope);
9947
10037
  }
9948
10038
  hasEffects(context) {
9949
- if ((this.init && this.init.hasEffects(context)) ||
9950
- (this.test && this.test.hasEffects(context)) ||
9951
- (this.update && this.update.hasEffects(context)))
10039
+ var _a, _b, _c;
10040
+ if (((_a = this.init) === null || _a === void 0 ? void 0 : _a.hasEffects(context)) ||
10041
+ ((_b = this.test) === null || _b === void 0 ? void 0 : _b.hasEffects(context)) ||
10042
+ ((_c = this.update) === null || _c === void 0 ? void 0 : _c.hasEffects(context)))
9952
10043
  return true;
9953
10044
  const { brokenFlow, ignore: { breaks, continues } } = context;
9954
10045
  context.ignore.breaks = true;
@@ -9961,24 +10052,20 @@ class ForStatement extends NodeBase {
9961
10052
  return false;
9962
10053
  }
9963
10054
  include(context, includeChildrenRecursively) {
10055
+ var _a, _b, _c;
9964
10056
  this.included = true;
9965
- if (this.init)
9966
- this.init.includeAsSingleStatement(context, includeChildrenRecursively);
9967
- if (this.test)
9968
- this.test.include(context, includeChildrenRecursively);
10057
+ (_a = this.init) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively, { asSingleStatement: true });
10058
+ (_b = this.test) === null || _b === void 0 ? void 0 : _b.include(context, includeChildrenRecursively);
9969
10059
  const { brokenFlow } = context;
9970
- if (this.update)
9971
- this.update.include(context, includeChildrenRecursively);
9972
- this.body.includeAsSingleStatement(context, includeChildrenRecursively);
10060
+ (_c = this.update) === null || _c === void 0 ? void 0 : _c.include(context, includeChildrenRecursively);
10061
+ this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9973
10062
  context.brokenFlow = brokenFlow;
9974
10063
  }
9975
10064
  render(code, options) {
9976
- if (this.init)
9977
- this.init.render(code, options, NO_SEMICOLON);
9978
- if (this.test)
9979
- this.test.render(code, options, NO_SEMICOLON);
9980
- if (this.update)
9981
- this.update.render(code, options, NO_SEMICOLON);
10065
+ var _a, _b, _c;
10066
+ (_a = this.init) === null || _a === void 0 ? void 0 : _a.render(code, options, NO_SEMICOLON);
10067
+ (_b = this.test) === null || _b === void 0 ? void 0 : _b.render(code, options, NO_SEMICOLON);
10068
+ (_c = this.update) === null || _c === void 0 ? void 0 : _c.render(code, options, NO_SEMICOLON);
9982
10069
  this.body.render(code, options);
9983
10070
  }
9984
10071
  }
@@ -10014,11 +10101,12 @@ class IfStatement extends NodeBase {
10014
10101
  this.testValue = UnknownValue;
10015
10102
  }
10016
10103
  hasEffects(context) {
10104
+ var _a;
10017
10105
  if (this.test.hasEffects(context)) {
10018
10106
  return true;
10019
10107
  }
10020
10108
  const testValue = this.getTestValue();
10021
- if (testValue === UnknownValue) {
10109
+ if (typeof testValue === 'symbol') {
10022
10110
  const { brokenFlow } = context;
10023
10111
  if (this.consequent.hasEffects(context))
10024
10112
  return true;
@@ -10032,9 +10120,7 @@ class IfStatement extends NodeBase {
10032
10120
  context.brokenFlow < consequentBrokenFlow ? context.brokenFlow : consequentBrokenFlow;
10033
10121
  return false;
10034
10122
  }
10035
- return testValue
10036
- ? this.consequent.hasEffects(context)
10037
- : this.alternate !== null && this.alternate.hasEffects(context);
10123
+ return testValue ? this.consequent.hasEffects(context) : !!((_a = this.alternate) === null || _a === void 0 ? void 0 : _a.hasEffects(context));
10038
10124
  }
10039
10125
  include(context, includeChildrenRecursively) {
10040
10126
  this.included = true;
@@ -10043,7 +10129,7 @@ class IfStatement extends NodeBase {
10043
10129
  }
10044
10130
  else {
10045
10131
  const testValue = this.getTestValue();
10046
- if (testValue === UnknownValue) {
10132
+ if (typeof testValue === 'symbol') {
10047
10133
  this.includeUnknownTest(context);
10048
10134
  }
10049
10135
  else {
@@ -10073,7 +10159,7 @@ class IfStatement extends NodeBase {
10073
10159
  else {
10074
10160
  code.remove(this.start, this.consequent.start);
10075
10161
  }
10076
- if (this.consequent.included && (noTreeshake || testValue === UnknownValue || testValue)) {
10162
+ if (this.consequent.included && (noTreeshake || typeof testValue === 'symbol' || testValue)) {
10077
10163
  this.consequent.render(code, options);
10078
10164
  }
10079
10165
  else {
@@ -10081,7 +10167,7 @@ class IfStatement extends NodeBase {
10081
10167
  hoistedDeclarations.push(...this.consequentScope.hoistedDeclarations);
10082
10168
  }
10083
10169
  if (this.alternate) {
10084
- if (this.alternate.included && (noTreeshake || testValue === UnknownValue || !testValue)) {
10170
+ if (this.alternate.included && (noTreeshake || typeof testValue === 'symbol' || !testValue)) {
10085
10171
  if (includesIfElse) {
10086
10172
  if (code.original.charCodeAt(this.alternate.start - 1) === 101) {
10087
10173
  code.prependLeft(this.alternate.start, ' ');
@@ -10111,34 +10197,35 @@ class IfStatement extends NodeBase {
10111
10197
  return this.testValue;
10112
10198
  }
10113
10199
  includeKnownTest(context, testValue) {
10200
+ var _a;
10114
10201
  if (this.test.shouldBeIncluded(context)) {
10115
10202
  this.test.include(context, false);
10116
10203
  }
10117
10204
  if (testValue && this.consequent.shouldBeIncluded(context)) {
10118
- this.consequent.includeAsSingleStatement(context, false);
10205
+ this.consequent.include(context, false, { asSingleStatement: true });
10119
10206
  }
10120
- if (this.alternate !== null && !testValue && this.alternate.shouldBeIncluded(context)) {
10121
- this.alternate.includeAsSingleStatement(context, false);
10207
+ if (!testValue && ((_a = this.alternate) === null || _a === void 0 ? void 0 : _a.shouldBeIncluded(context))) {
10208
+ this.alternate.include(context, false, { asSingleStatement: true });
10122
10209
  }
10123
10210
  }
10124
10211
  includeRecursively(includeChildrenRecursively, context) {
10212
+ var _a;
10125
10213
  this.test.include(context, includeChildrenRecursively);
10126
10214
  this.consequent.include(context, includeChildrenRecursively);
10127
- if (this.alternate !== null) {
10128
- this.alternate.include(context, includeChildrenRecursively);
10129
- }
10215
+ (_a = this.alternate) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
10130
10216
  }
10131
10217
  includeUnknownTest(context) {
10218
+ var _a;
10132
10219
  this.test.include(context, false);
10133
10220
  const { brokenFlow } = context;
10134
10221
  let consequentBrokenFlow = BROKEN_FLOW_NONE;
10135
10222
  if (this.consequent.shouldBeIncluded(context)) {
10136
- this.consequent.includeAsSingleStatement(context, false);
10223
+ this.consequent.include(context, false, { asSingleStatement: true });
10137
10224
  consequentBrokenFlow = context.brokenFlow;
10138
10225
  context.brokenFlow = brokenFlow;
10139
10226
  }
10140
- if (this.alternate !== null && this.alternate.shouldBeIncluded(context)) {
10141
- this.alternate.includeAsSingleStatement(context, false);
10227
+ if ((_a = this.alternate) === null || _a === void 0 ? void 0 : _a.shouldBeIncluded(context)) {
10228
+ this.alternate.include(context, false, { asSingleStatement: true });
10142
10229
  context.brokenFlow =
10143
10230
  context.brokenFlow < consequentBrokenFlow ? context.brokenFlow : consequentBrokenFlow;
10144
10231
  }
@@ -10617,7 +10704,7 @@ class LogicalExpression extends NodeBase {
10617
10704
  }
10618
10705
  deoptimizePath(path) {
10619
10706
  const usedBranch = this.getUsedBranch();
10620
- if (usedBranch === null) {
10707
+ if (!usedBranch) {
10621
10708
  this.left.deoptimizePath(path);
10622
10709
  this.right.deoptimizePath(path);
10623
10710
  }
@@ -10631,14 +10718,14 @@ class LogicalExpression extends NodeBase {
10631
10718
  }
10632
10719
  getLiteralValueAtPath(path, recursionTracker, origin) {
10633
10720
  const usedBranch = this.getUsedBranch();
10634
- if (usedBranch === null)
10721
+ if (!usedBranch)
10635
10722
  return UnknownValue;
10636
10723
  this.expressionsToBeDeoptimized.push(origin);
10637
10724
  return usedBranch.getLiteralValueAtPath(path, recursionTracker, origin);
10638
10725
  }
10639
10726
  getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
10640
10727
  const usedBranch = this.getUsedBranch();
10641
- if (usedBranch === null)
10728
+ if (!usedBranch)
10642
10729
  return new MultiExpression([
10643
10730
  this.left.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin),
10644
10731
  this.right.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin)
@@ -10657,7 +10744,7 @@ class LogicalExpression extends NodeBase {
10657
10744
  }
10658
10745
  hasEffectsWhenAccessedAtPath(path, context) {
10659
10746
  const usedBranch = this.getUsedBranch();
10660
- if (usedBranch === null) {
10747
+ if (!usedBranch) {
10661
10748
  return (this.left.hasEffectsWhenAccessedAtPath(path, context) ||
10662
10749
  this.right.hasEffectsWhenAccessedAtPath(path, context));
10663
10750
  }
@@ -10665,7 +10752,7 @@ class LogicalExpression extends NodeBase {
10665
10752
  }
10666
10753
  hasEffectsWhenAssignedAtPath(path, context) {
10667
10754
  const usedBranch = this.getUsedBranch();
10668
- if (usedBranch === null) {
10755
+ if (!usedBranch) {
10669
10756
  return (this.left.hasEffectsWhenAssignedAtPath(path, context) ||
10670
10757
  this.right.hasEffectsWhenAssignedAtPath(path, context));
10671
10758
  }
@@ -10673,7 +10760,7 @@ class LogicalExpression extends NodeBase {
10673
10760
  }
10674
10761
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
10675
10762
  const usedBranch = this.getUsedBranch();
10676
- if (usedBranch === null) {
10763
+ if (!usedBranch) {
10677
10764
  return (this.left.hasEffectsWhenCalledAtPath(path, callOptions, context) ||
10678
10765
  this.right.hasEffectsWhenCalledAtPath(path, callOptions, context));
10679
10766
  }
@@ -10684,7 +10771,7 @@ class LogicalExpression extends NodeBase {
10684
10771
  const usedBranch = this.getUsedBranch();
10685
10772
  if (includeChildrenRecursively ||
10686
10773
  (usedBranch === this.right && this.left.shouldBeIncluded(context)) ||
10687
- usedBranch === null) {
10774
+ !usedBranch) {
10688
10775
  this.left.include(context, includeChildrenRecursively);
10689
10776
  this.right.include(context, includeChildrenRecursively);
10690
10777
  }
@@ -10725,7 +10812,7 @@ class LogicalExpression extends NodeBase {
10725
10812
  if (!this.isBranchResolutionAnalysed) {
10726
10813
  this.isBranchResolutionAnalysed = true;
10727
10814
  const leftValue = this.left.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
10728
- if (leftValue === UnknownValue) {
10815
+ if (typeof leftValue === 'symbol') {
10729
10816
  return null;
10730
10817
  }
10731
10818
  else {
@@ -10911,21 +10998,37 @@ class NewExpression extends NodeBase {
10911
10998
  this.deoptimized = false;
10912
10999
  }
10913
11000
  hasEffects(context) {
10914
- if (!this.deoptimized)
10915
- this.applyDeoptimizations();
10916
- for (const argument of this.arguments) {
10917
- if (argument.hasEffects(context))
10918
- return true;
11001
+ try {
11002
+ for (const argument of this.arguments) {
11003
+ if (argument.hasEffects(context))
11004
+ return true;
11005
+ }
11006
+ if (this.context.options.treeshake.annotations &&
11007
+ this.annotations)
11008
+ return false;
11009
+ return (this.callee.hasEffects(context) ||
11010
+ this.callee.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
11011
+ }
11012
+ finally {
11013
+ if (!this.deoptimized)
11014
+ this.applyDeoptimizations();
10919
11015
  }
10920
- if (this.context.options.treeshake.annotations &&
10921
- this.annotations)
10922
- return false;
10923
- return (this.callee.hasEffects(context) ||
10924
- this.callee.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
10925
11016
  }
10926
11017
  hasEffectsWhenAccessedAtPath(path) {
10927
11018
  return path.length > 0;
10928
11019
  }
11020
+ include(context, includeChildrenRecursively) {
11021
+ if (!this.deoptimized)
11022
+ this.applyDeoptimizations();
11023
+ if (includeChildrenRecursively) {
11024
+ super.include(context, includeChildrenRecursively);
11025
+ }
11026
+ else {
11027
+ this.included = true;
11028
+ this.callee.include(context, false);
11029
+ }
11030
+ this.callee.includeCallArguments(context, this.arguments);
11031
+ }
10929
11032
  initialise() {
10930
11033
  this.callOptions = {
10931
11034
  args: this.arguments,
@@ -10994,7 +11097,7 @@ class ObjectExpression extends NodeBase {
10994
11097
  let key;
10995
11098
  if (property.computed) {
10996
11099
  const keyValue = property.key.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
10997
- if (keyValue === UnknownValue) {
11100
+ if (typeof keyValue === 'symbol') {
10998
11101
  properties.push({ key: UnknownKey, kind: property.kind, property });
10999
11102
  continue;
11000
11103
  }
@@ -11115,8 +11218,8 @@ class PropertyDefinition extends NodeBase {
11115
11218
  : UNKNOWN_EXPRESSION;
11116
11219
  }
11117
11220
  hasEffects(context) {
11118
- return (this.key.hasEffects(context) ||
11119
- (this.static && this.value !== null && this.value.hasEffects(context)));
11221
+ var _a;
11222
+ return this.key.hasEffects(context) || (this.static && !!((_a = this.value) === null || _a === void 0 ? void 0 : _a.hasEffects(context)));
11120
11223
  }
11121
11224
  hasEffectsWhenAccessedAtPath(path, context) {
11122
11225
  return !this.value || this.value.hasEffectsWhenAccessedAtPath(path, context);
@@ -11131,17 +11234,16 @@ class PropertyDefinition extends NodeBase {
11131
11234
 
11132
11235
  class ReturnStatement extends NodeBase {
11133
11236
  hasEffects(context) {
11134
- if (!context.ignore.returnYield ||
11135
- (this.argument !== null && this.argument.hasEffects(context)))
11237
+ var _a;
11238
+ if (!context.ignore.returnYield || ((_a = this.argument) === null || _a === void 0 ? void 0 : _a.hasEffects(context)))
11136
11239
  return true;
11137
11240
  context.brokenFlow = BROKEN_FLOW_ERROR_RETURN_LABEL;
11138
11241
  return false;
11139
11242
  }
11140
11243
  include(context, includeChildrenRecursively) {
11244
+ var _a;
11141
11245
  this.included = true;
11142
- if (this.argument) {
11143
- this.argument.include(context, includeChildrenRecursively);
11144
- }
11246
+ (_a = this.argument) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
11145
11247
  context.brokenFlow = BROKEN_FLOW_ERROR_RETURN_LABEL;
11146
11248
  }
11147
11249
  initialise() {
@@ -11261,6 +11363,9 @@ class Super extends NodeBase {
11261
11363
  deoptimizePath(path) {
11262
11364
  this.variable.deoptimizePath(path);
11263
11365
  }
11366
+ deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
11367
+ this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
11368
+ }
11264
11369
  include() {
11265
11370
  if (!this.included) {
11266
11371
  this.included = true;
@@ -11271,7 +11376,8 @@ class Super extends NodeBase {
11271
11376
 
11272
11377
  class SwitchCase extends NodeBase {
11273
11378
  hasEffects(context) {
11274
- if (this.test && this.test.hasEffects(context))
11379
+ var _a;
11380
+ if ((_a = this.test) === null || _a === void 0 ? void 0 : _a.hasEffects(context))
11275
11381
  return true;
11276
11382
  for (const node of this.consequent) {
11277
11383
  if (context.brokenFlow)
@@ -11282,9 +11388,9 @@ class SwitchCase extends NodeBase {
11282
11388
  return false;
11283
11389
  }
11284
11390
  include(context, includeChildrenRecursively) {
11391
+ var _a;
11285
11392
  this.included = true;
11286
- if (this.test)
11287
- this.test.include(context, includeChildrenRecursively);
11393
+ (_a = this.test) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
11288
11394
  for (const node of this.consequent) {
11289
11395
  if (includeChildrenRecursively || node.shouldBeIncluded(context))
11290
11396
  node.include(context, includeChildrenRecursively);
@@ -11377,7 +11483,7 @@ class SwitchStatement extends NodeBase {
11377
11483
  }
11378
11484
  }
11379
11485
 
11380
- class TaggedTemplateExpression extends NodeBase {
11486
+ class TaggedTemplateExpression extends CallExpressionBase {
11381
11487
  bind() {
11382
11488
  super.bind();
11383
11489
  if (this.tag.type === Identifier$1) {
@@ -11392,13 +11498,40 @@ class TaggedTemplateExpression extends NodeBase {
11392
11498
  }
11393
11499
  }
11394
11500
  hasEffects(context) {
11395
- return (super.hasEffects(context) ||
11396
- this.tag.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
11501
+ try {
11502
+ for (const argument of this.quasi.expressions) {
11503
+ if (argument.hasEffects(context))
11504
+ return true;
11505
+ }
11506
+ return (this.tag.hasEffects(context) ||
11507
+ this.tag.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
11508
+ }
11509
+ finally {
11510
+ if (!this.deoptimized)
11511
+ this.applyDeoptimizations();
11512
+ }
11513
+ }
11514
+ include(context, includeChildrenRecursively) {
11515
+ if (!this.deoptimized)
11516
+ this.applyDeoptimizations();
11517
+ if (includeChildrenRecursively) {
11518
+ super.include(context, includeChildrenRecursively);
11519
+ }
11520
+ else {
11521
+ this.included = true;
11522
+ this.tag.include(context, includeChildrenRecursively);
11523
+ this.quasi.include(context, includeChildrenRecursively);
11524
+ }
11525
+ this.tag.includeCallArguments(context, this.callOptions.args);
11526
+ const returnExpression = this.getReturnExpression();
11527
+ if (!returnExpression.included) {
11528
+ returnExpression.include(context, false);
11529
+ }
11397
11530
  }
11398
11531
  initialise() {
11399
11532
  this.callOptions = {
11400
- args: NO_ARGS,
11401
- thisParam: null,
11533
+ args: [UNKNOWN_EXPRESSION, ...this.quasi.expressions],
11534
+ thisParam: this.tag instanceof MemberExpression && !this.tag.variable ? this.tag.object : null,
11402
11535
  withNew: false
11403
11536
  };
11404
11537
  }
@@ -11406,6 +11539,25 @@ class TaggedTemplateExpression extends NodeBase {
11406
11539
  this.tag.render(code, options, { isCalleeOfRenderedParent: true });
11407
11540
  this.quasi.render(code, options);
11408
11541
  }
11542
+ applyDeoptimizations() {
11543
+ this.deoptimized = true;
11544
+ const { thisParam } = this.callOptions;
11545
+ if (thisParam) {
11546
+ this.tag.deoptimizeThisOnEventAtPath(EVENT_CALLED, EMPTY_PATH, thisParam, SHARED_RECURSION_TRACKER);
11547
+ }
11548
+ for (const argument of this.quasi.expressions) {
11549
+ // This will make sure all properties of parameters behave as "unknown"
11550
+ argument.deoptimizePath(UNKNOWN_PATH);
11551
+ }
11552
+ this.context.requestTreeshakingPass();
11553
+ }
11554
+ getReturnExpression(recursionTracker = SHARED_RECURSION_TRACKER) {
11555
+ if (this.returnExpression === null) {
11556
+ this.returnExpression = UNKNOWN_EXPRESSION;
11557
+ return (this.returnExpression = this.tag.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.callOptions, recursionTracker, this));
11558
+ }
11559
+ return this.returnExpression;
11560
+ }
11409
11561
  }
11410
11562
 
11411
11563
  class TemplateElement extends NodeBase {
@@ -11425,12 +11577,28 @@ class TemplateElement extends NodeBase {
11425
11577
  }
11426
11578
 
11427
11579
  class TemplateLiteral extends NodeBase {
11580
+ deoptimizeThisOnEventAtPath() { }
11428
11581
  getLiteralValueAtPath(path) {
11429
11582
  if (path.length > 0 || this.quasis.length !== 1) {
11430
11583
  return UnknownValue;
11431
11584
  }
11432
11585
  return this.quasis[0].value.cooked;
11433
11586
  }
11587
+ getReturnExpressionWhenCalledAtPath(path) {
11588
+ if (path.length !== 1) {
11589
+ return UNKNOWN_EXPRESSION;
11590
+ }
11591
+ return getMemberReturnExpressionWhenCalled(literalStringMembers, path[0]);
11592
+ }
11593
+ hasEffectsWhenAccessedAtPath(path) {
11594
+ return path.length > 1;
11595
+ }
11596
+ hasEffectsWhenCalledAtPath(path, callOptions, context) {
11597
+ if (path.length === 1) {
11598
+ return hasMemberEffectWhenCalled(literalStringMembers, path[0], callOptions, context);
11599
+ }
11600
+ return true;
11601
+ }
11434
11602
  render(code, options) {
11435
11603
  code.indentExclusionRanges.push([this.start, this.end]);
11436
11604
  super.render(code, options);
@@ -11617,13 +11785,13 @@ class TryStatement extends NodeBase {
11617
11785
  this.includedLabelsAfterBlock = null;
11618
11786
  }
11619
11787
  hasEffects(context) {
11788
+ var _a;
11620
11789
  return ((this.context.options.treeshake.tryCatchDeoptimization
11621
11790
  ? this.block.body.length > 0
11622
- : this.block.hasEffects(context)) ||
11623
- (this.finalizer !== null && this.finalizer.hasEffects(context)));
11791
+ : this.block.hasEffects(context)) || !!((_a = this.finalizer) === null || _a === void 0 ? void 0 : _a.hasEffects(context)));
11624
11792
  }
11625
11793
  include(context, includeChildrenRecursively) {
11626
- var _a;
11794
+ var _a, _b;
11627
11795
  const tryCatchDeoptimization = (_a = this.context.options.treeshake) === null || _a === void 0 ? void 0 : _a.tryCatchDeoptimization;
11628
11796
  const { brokenFlow } = context;
11629
11797
  if (!this.directlyIncluded || !tryCatchDeoptimization) {
@@ -11644,9 +11812,7 @@ class TryStatement extends NodeBase {
11644
11812
  this.handler.include(context, includeChildrenRecursively);
11645
11813
  context.brokenFlow = brokenFlow;
11646
11814
  }
11647
- if (this.finalizer !== null) {
11648
- this.finalizer.include(context, includeChildrenRecursively);
11649
- }
11815
+ (_b = this.finalizer) === null || _b === void 0 ? void 0 : _b.include(context, includeChildrenRecursively);
11650
11816
  }
11651
11817
  }
11652
11818
 
@@ -11668,7 +11834,7 @@ class UnaryExpression extends NodeBase {
11668
11834
  if (path.length > 0)
11669
11835
  return UnknownValue;
11670
11836
  const argumentValue = this.argument.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
11671
- if (argumentValue === UnknownValue)
11837
+ if (typeof argumentValue === 'symbol')
11672
11838
  return UnknownValue;
11673
11839
  return unaryOperators[this.operator](argumentValue);
11674
11840
  }
@@ -11782,18 +11948,12 @@ class VariableDeclaration extends NodeBase {
11782
11948
  hasEffectsWhenAssignedAtPath() {
11783
11949
  return false;
11784
11950
  }
11785
- include(context, includeChildrenRecursively) {
11951
+ include(context, includeChildrenRecursively, { asSingleStatement } = BLANK) {
11786
11952
  this.included = true;
11787
11953
  for (const declarator of this.declarations) {
11788
11954
  if (includeChildrenRecursively || declarator.shouldBeIncluded(context))
11789
11955
  declarator.include(context, includeChildrenRecursively);
11790
- }
11791
- }
11792
- includeAsSingleStatement(context, includeChildrenRecursively) {
11793
- this.included = true;
11794
- for (const declarator of this.declarations) {
11795
- if (includeChildrenRecursively || declarator.shouldBeIncluded(context)) {
11796
- declarator.include(context, includeChildrenRecursively);
11956
+ if (asSingleStatement) {
11797
11957
  declarator.id.include(context, includeChildrenRecursively);
11798
11958
  }
11799
11959
  }
@@ -11814,16 +11974,14 @@ class VariableDeclaration extends NodeBase {
11814
11974
  }
11815
11975
  }
11816
11976
  else {
11817
- this.renderReplacedDeclarations(code, options, nodeRenderOptions);
11977
+ this.renderReplacedDeclarations(code, options);
11818
11978
  }
11819
11979
  }
11820
- renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, systemPatternExports, options, isNoStatement) {
11980
+ renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, systemPatternExports, options) {
11821
11981
  if (code.original.charCodeAt(this.end - 1) === 59 /*";"*/) {
11822
11982
  code.remove(this.end - 1, this.end);
11823
11983
  }
11824
- if (!isNoStatement) {
11825
- separatorString += ';';
11826
- }
11984
+ separatorString += ';';
11827
11985
  if (lastSeparatorPos !== null) {
11828
11986
  if (code.original.charCodeAt(actualContentEnd - 1) === 10 /*"\n"*/ &&
11829
11987
  (code.original.charCodeAt(this.end) === 10 /*"\n"*/ ||
@@ -11848,7 +12006,7 @@ class VariableDeclaration extends NodeBase {
11848
12006
  code.appendLeft(renderedContentEnd, ` ${getSystemExportStatement(systemPatternExports, options)};`);
11849
12007
  }
11850
12008
  }
11851
- renderReplacedDeclarations(code, options, { isNoStatement }) {
12009
+ renderReplacedDeclarations(code, options) {
11852
12010
  const separatedNodes = getCommaSeparatedNodesWithBoundaries(this.declarations, code, this.start + this.kind.length, this.end - (code.original.charCodeAt(this.end - 1) === 59 /*";"*/ ? 1 : 0));
11853
12011
  let actualContentEnd, renderedContentEnd;
11854
12012
  renderedContentEnd = findNonWhiteSpace(code.original, this.start + this.kind.length);
@@ -11904,7 +12062,7 @@ class VariableDeclaration extends NodeBase {
11904
12062
  lastSeparatorPos = separator;
11905
12063
  separatorString = nextSeparatorString;
11906
12064
  }
11907
- this.renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, aggregatedSystemExports, options, isNoStatement);
12065
+ this.renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, aggregatedSystemExports, options);
11908
12066
  }
11909
12067
  }
11910
12068
  function gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregatedSystemExports) {
@@ -11941,15 +12099,17 @@ class VariableDeclarator extends NodeBase {
11941
12099
  this.id.deoptimizePath(path);
11942
12100
  }
11943
12101
  hasEffects(context) {
11944
- const initEffect = this.init !== null && this.init.hasEffects(context);
12102
+ var _a;
12103
+ const initEffect = (_a = this.init) === null || _a === void 0 ? void 0 : _a.hasEffects(context);
11945
12104
  this.id.markDeclarationReached();
11946
12105
  return initEffect || this.id.hasEffects(context);
11947
12106
  }
11948
12107
  include(context, includeChildrenRecursively) {
12108
+ var _a;
11949
12109
  this.included = true;
11950
- if (this.init) {
11951
- this.init.include(context, includeChildrenRecursively);
11952
- }
12110
+ (_a = this.init) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively, {
12111
+ includeWithoutParameterDefaults: true
12112
+ });
11953
12113
  this.id.markDeclarationReached();
11954
12114
  if (includeChildrenRecursively || this.id.shouldBeIncluded(context)) {
11955
12115
  this.id.include(context, includeChildrenRecursively);
@@ -11993,7 +12153,7 @@ class WhileStatement extends NodeBase {
11993
12153
  this.included = true;
11994
12154
  this.test.include(context, includeChildrenRecursively);
11995
12155
  const { brokenFlow } = context;
11996
- this.body.includeAsSingleStatement(context, includeChildrenRecursively);
12156
+ this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
11997
12157
  context.brokenFlow = brokenFlow;
11998
12158
  }
11999
12159
  }
@@ -12004,9 +12164,10 @@ class YieldExpression extends NodeBase {
12004
12164
  this.deoptimized = false;
12005
12165
  }
12006
12166
  hasEffects(context) {
12167
+ var _a;
12007
12168
  if (!this.deoptimized)
12008
12169
  this.applyDeoptimizations();
12009
- return (!context.ignore.returnYield || (this.argument !== null && this.argument.hasEffects(context)));
12170
+ return !context.ignore.returnYield || !!((_a = this.argument) === null || _a === void 0 ? void 0 : _a.hasEffects(context));
12010
12171
  }
12011
12172
  render(code, options) {
12012
12173
  if (this.argument) {
@@ -12016,14 +12177,6 @@ class YieldExpression extends NodeBase {
12016
12177
  }
12017
12178
  }
12018
12179
  }
12019
- applyDeoptimizations() {
12020
- this.deoptimized = true;
12021
- const { argument } = this;
12022
- if (argument) {
12023
- argument.deoptimizePath(UNKNOWN_PATH);
12024
- this.context.requestTreeshakingPass();
12025
- }
12026
- }
12027
12180
  }
12028
12181
 
12029
12182
  const nodeConstructors = {