rollup 2.74.0 → 2.74.1

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.0
4
- Thu, 19 May 2022 05:01:43 GMT - commit fc99e96e09d26798f1c0aabdd7429307cc908c8e
3
+ Rollup.js v2.74.1
4
+ Thu, 19 May 2022 17:50:11 GMT - commit e823eded9920d6082cc8c1afcf591b716ab6b160
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -14,7 +14,7 @@ import { createHash as createHash$1 } from 'crypto';
14
14
  import { promises } from 'fs';
15
15
  import { EventEmitter } from 'events';
16
16
 
17
- var version$1 = "2.74.0";
17
+ var version$1 = "2.74.1";
18
18
 
19
19
  var charToInteger = {};
20
20
  var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
@@ -1209,7 +1209,7 @@ class MagicString {
1209
1209
  const hasOwnProp = Object.prototype.hasOwnProperty;
1210
1210
 
1211
1211
  class Bundle$1 {
1212
- constructor(options) {
1212
+ constructor(options = {}) {
1213
1213
  this.intro = options.intro || '';
1214
1214
  this.separator = options.separator !== undefined ? options.separator : '\n';
1215
1215
  this.sources = [];
@@ -1588,7 +1588,6 @@ class DiscriminatedPathTracker {
1588
1588
  }
1589
1589
 
1590
1590
  const UnknownValue = Symbol('Unknown Value');
1591
- const UnknownTruthyValue = Symbol('Unknown Truthy Value');
1592
1591
  class ExpressionEntity {
1593
1592
  constructor() {
1594
1593
  this.included = false;
@@ -1617,17 +1616,14 @@ class ExpressionEntity {
1617
1616
  hasEffectsWhenCalledAtPath(_path, _callOptions, _context) {
1618
1617
  return true;
1619
1618
  }
1620
- include(_context, _includeChildrenRecursively, _options) {
1619
+ include(_context, _includeChildrenRecursively) {
1621
1620
  this.included = true;
1622
1621
  }
1623
- includeArgumentsWhenCalledAtPath(_path, context, args) {
1622
+ includeCallArguments(context, args) {
1624
1623
  for (const arg of args) {
1625
1624
  arg.include(context, false);
1626
1625
  }
1627
1626
  }
1628
- shouldBeIncluded(_context) {
1629
- return true;
1630
- }
1631
1627
  }
1632
1628
  const UNKNOWN_EXPRESSION = new (class UnknownExpression extends ExpressionEntity {
1633
1629
  })();
@@ -4669,9 +4665,9 @@ const stringReplace = {
4669
4665
  hasEffectsWhenCalled(callOptions, context) {
4670
4666
  const arg1 = callOptions.args[1];
4671
4667
  return (callOptions.args.length < 2 ||
4672
- (typeof arg1.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, {
4668
+ (arg1.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, {
4673
4669
  deoptimizeCache() { }
4674
- }) === 'symbol' &&
4670
+ }) === UnknownValue &&
4675
4671
  arg1.hasEffectsWhenCalledAtPath(EMPTY_PATH, {
4676
4672
  args: NO_ARGS,
4677
4673
  thisParam: null,
@@ -5226,7 +5222,8 @@ class NodeBase extends ExpressionEntity {
5226
5222
  continue;
5227
5223
  if (Array.isArray(value)) {
5228
5224
  for (const child of value) {
5229
- child === null || child === void 0 ? void 0 : child.bind();
5225
+ if (child !== null)
5226
+ child.bind();
5230
5227
  }
5231
5228
  }
5232
5229
  else {
@@ -5249,7 +5246,7 @@ class NodeBase extends ExpressionEntity {
5249
5246
  continue;
5250
5247
  if (Array.isArray(value)) {
5251
5248
  for (const child of value) {
5252
- if (child === null || child === void 0 ? void 0 : child.hasEffects(context))
5249
+ if (child !== null && child.hasEffects(context))
5253
5250
  return true;
5254
5251
  }
5255
5252
  }
@@ -5258,7 +5255,7 @@ class NodeBase extends ExpressionEntity {
5258
5255
  }
5259
5256
  return false;
5260
5257
  }
5261
- include(context, includeChildrenRecursively, _options) {
5258
+ include(context, includeChildrenRecursively) {
5262
5259
  if (this.deoptimized === false)
5263
5260
  this.applyDeoptimizations();
5264
5261
  this.included = true;
@@ -5268,7 +5265,8 @@ class NodeBase extends ExpressionEntity {
5268
5265
  continue;
5269
5266
  if (Array.isArray(value)) {
5270
5267
  for (const child of value) {
5271
- child === null || child === void 0 ? void 0 : child.include(context, includeChildrenRecursively);
5268
+ if (child !== null)
5269
+ child.include(context, includeChildrenRecursively);
5272
5270
  }
5273
5271
  }
5274
5272
  else {
@@ -5276,6 +5274,9 @@ class NodeBase extends ExpressionEntity {
5276
5274
  }
5277
5275
  }
5278
5276
  }
5277
+ includeAsSingleStatement(context, includeChildrenRecursively) {
5278
+ this.include(context, includeChildrenRecursively);
5279
+ }
5279
5280
  /**
5280
5281
  * Override to perform special initialisation steps after the scope is initialised
5281
5282
  */
@@ -5322,7 +5323,8 @@ class NodeBase extends ExpressionEntity {
5322
5323
  continue;
5323
5324
  if (Array.isArray(value)) {
5324
5325
  for (const child of value) {
5325
- child === null || child === void 0 ? void 0 : child.render(code, options);
5326
+ if (child !== null)
5327
+ child.render(code, options);
5326
5328
  }
5327
5329
  }
5328
5330
  else {
@@ -5333,28 +5335,7 @@ class NodeBase extends ExpressionEntity {
5333
5335
  shouldBeIncluded(context) {
5334
5336
  return this.included || (!context.brokenFlow && this.hasEffects(createHasEffectsContext()));
5335
5337
  }
5336
- /**
5337
- * Just deoptimize everything by default so that when e.g. we do not track
5338
- * something properly, it is deoptimized.
5339
- * @protected
5340
- */
5341
- applyDeoptimizations() {
5342
- this.deoptimized = true;
5343
- for (const key of this.keys) {
5344
- const value = this[key];
5345
- if (value === null)
5346
- continue;
5347
- if (Array.isArray(value)) {
5348
- for (const child of value) {
5349
- child === null || child === void 0 ? void 0 : child.deoptimizePath(UNKNOWN_PATH);
5350
- }
5351
- }
5352
- else {
5353
- value.deoptimizePath(UNKNOWN_PATH);
5354
- }
5355
- }
5356
- this.context.requestTreeshakingPass();
5357
- }
5338
+ applyDeoptimizations() { }
5358
5339
  }
5359
5340
 
5360
5341
  class SpreadElement extends NodeBase {
@@ -5436,7 +5417,7 @@ class Method extends ExpressionEntity {
5436
5417
  }
5437
5418
  return false;
5438
5419
  }
5439
- includeArgumentsWhenCalledAtPath(_path, context, args) {
5420
+ includeCallArguments(context, args) {
5440
5421
  for (const arg of args) {
5441
5422
  arg.include(context, false);
5442
5423
  }
@@ -5640,7 +5621,7 @@ class ObjectEntity extends ExpressionEntity {
5640
5621
  }
5641
5622
  getLiteralValueAtPath(path, recursionTracker, origin) {
5642
5623
  if (path.length === 0) {
5643
- return UnknownTruthyValue;
5624
+ return UnknownValue;
5644
5625
  }
5645
5626
  const key = path[0];
5646
5627
  const expressionAtPath = this.getMemberExpressionAndTrackDeopt(key, origin);
@@ -5776,16 +5757,6 @@ class ObjectEntity extends ExpressionEntity {
5776
5757
  }
5777
5758
  return true;
5778
5759
  }
5779
- includeArgumentsWhenCalledAtPath(path, context, args) {
5780
- const key = path[0];
5781
- const expressionAtPath = this.getMemberExpression(key);
5782
- if (expressionAtPath) {
5783
- return expressionAtPath.includeArgumentsWhenCalledAtPath(path.slice(1), context, args);
5784
- }
5785
- if (this.prototypeExpression) {
5786
- return this.prototypeExpression.includeArgumentsWhenCalledAtPath(path, context, args);
5787
- }
5788
- }
5789
5760
  buildPropertyMaps(properties) {
5790
5761
  const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchableGetters, unmatchableSetters } = this;
5791
5762
  const unmatchablePropertiesAndSetters = [];
@@ -6055,7 +6026,6 @@ const ARRAY_PROTOTYPE = new ObjectEntity({
6055
6026
  class ArrayExpression extends NodeBase {
6056
6027
  constructor() {
6057
6028
  super(...arguments);
6058
- this.deoptimized = false;
6059
6029
  this.objectEntity = null;
6060
6030
  }
6061
6031
  deoptimizePath(path) {
@@ -6079,23 +6049,6 @@ class ArrayExpression extends NodeBase {
6079
6049
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
6080
6050
  return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
6081
6051
  }
6082
- includeArgumentsWhenCalledAtPath(path, context, args) {
6083
- this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
6084
- }
6085
- applyDeoptimizations() {
6086
- this.deoptimized = true;
6087
- let hasSpread = false;
6088
- for (let index = 0; index < this.elements.length; index++) {
6089
- const element = this.elements[index];
6090
- if (hasSpread || element instanceof SpreadElement) {
6091
- if (element) {
6092
- hasSpread = true;
6093
- element.deoptimizePath(UNKNOWN_PATH);
6094
- }
6095
- }
6096
- }
6097
- this.context.requestTreeshakingPass();
6098
- }
6099
6052
  getObjectEntity() {
6100
6053
  if (this.objectEntity !== null) {
6101
6054
  return this.objectEntity;
@@ -6106,7 +6059,7 @@ class ArrayExpression extends NodeBase {
6106
6059
  let hasSpread = false;
6107
6060
  for (let index = 0; index < this.elements.length; index++) {
6108
6061
  const element = this.elements[index];
6109
- if (hasSpread || element instanceof SpreadElement) {
6062
+ if (element instanceof SpreadElement || hasSpread) {
6110
6063
  if (element) {
6111
6064
  hasSpread = true;
6112
6065
  properties.unshift({ key: UnknownInteger, kind: 'init', property: element });
@@ -6126,7 +6079,9 @@ class ArrayExpression extends NodeBase {
6126
6079
  class ArrayPattern extends NodeBase {
6127
6080
  addExportedVariables(variables, exportNamesByVariable) {
6128
6081
  for (const element of this.elements) {
6129
- element === null || element === void 0 ? void 0 : element.addExportedVariables(variables, exportNamesByVariable);
6082
+ if (element !== null) {
6083
+ element.addExportedVariables(variables, exportNamesByVariable);
6084
+ }
6130
6085
  }
6131
6086
  }
6132
6087
  declare(kind) {
@@ -6138,23 +6093,29 @@ class ArrayPattern extends NodeBase {
6138
6093
  }
6139
6094
  return variables;
6140
6095
  }
6141
- // Patterns can only be deoptimized at the empty path at the moment
6142
- deoptimizePath() {
6143
- for (const element of this.elements) {
6144
- element === null || element === void 0 ? void 0 : element.deoptimizePath(EMPTY_PATH);
6096
+ deoptimizePath(path) {
6097
+ if (path.length === 0) {
6098
+ for (const element of this.elements) {
6099
+ if (element !== null) {
6100
+ element.deoptimizePath(path);
6101
+ }
6102
+ }
6145
6103
  }
6146
6104
  }
6147
- // Patterns are only checked at the emtpy path at the moment
6148
- hasEffectsWhenAssignedAtPath(_path, context) {
6105
+ hasEffectsWhenAssignedAtPath(path, context) {
6106
+ if (path.length > 0)
6107
+ return true;
6149
6108
  for (const element of this.elements) {
6150
- if (element === null || element === void 0 ? void 0 : element.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context))
6109
+ if (element !== null && element.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context))
6151
6110
  return true;
6152
6111
  }
6153
6112
  return false;
6154
6113
  }
6155
6114
  markDeclarationReached() {
6156
6115
  for (const element of this.elements) {
6157
- element === null || element === void 0 ? void 0 : element.markDeclarationReached();
6116
+ if (element !== null) {
6117
+ element.markDeclarationReached();
6118
+ }
6158
6119
  }
6159
6120
  }
6160
6121
  }
@@ -6274,7 +6235,7 @@ class LocalVariable extends Variable {
6274
6235
  }
6275
6236
  }
6276
6237
  }
6277
- includeArgumentsWhenCalledAtPath(path, context, args) {
6238
+ includeCallArguments(context, args) {
6278
6239
  if (this.isReassigned || (this.init && context.includedCallArguments.has(this.init))) {
6279
6240
  for (const arg of args) {
6280
6241
  arg.include(context, false);
@@ -6282,7 +6243,7 @@ class LocalVariable extends Variable {
6282
6243
  }
6283
6244
  else if (this.init) {
6284
6245
  context.includedCallArguments.add(this.init);
6285
- this.init.includeArgumentsWhenCalledAtPath(path, context, args);
6246
+ this.init.includeCallArguments(context, args);
6286
6247
  context.includedCallArguments.delete(this.init);
6287
6248
  }
6288
6249
  }
@@ -6530,618 +6491,88 @@ class ReturnValueScope extends ParameterScope {
6530
6491
  }
6531
6492
  }
6532
6493
 
6533
- class AssignmentPattern extends NodeBase {
6534
- constructor() {
6535
- super(...arguments);
6536
- this.deoptimized = false;
6537
- }
6538
- addExportedVariables(variables, exportNamesByVariable) {
6539
- this.left.addExportedVariables(variables, exportNamesByVariable);
6540
- }
6541
- declare(kind, init) {
6542
- return this.left.declare(kind, init);
6543
- }
6544
- deoptimizePath(path) {
6545
- path.length === 0 && this.left.deoptimizePath(path);
6546
- }
6547
- hasEffectsWhenAssignedAtPath(path, context) {
6548
- return path.length > 0 || this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
6549
- }
6550
- include(context, includeChildrenRecursively) {
6551
- this.included = true;
6552
- this.left.include(context, includeChildrenRecursively);
6553
- this.right.include(context, includeChildrenRecursively);
6554
- }
6555
- markDeclarationReached() {
6556
- this.left.markDeclarationReached();
6557
- }
6558
- render(code, options, { isShorthandProperty } = BLANK) {
6559
- this.left.render(code, options, { isShorthandProperty });
6560
- if (this.right.included) {
6561
- this.right.render(code, options);
6562
- }
6563
- else {
6564
- code.remove(this.left.end, this.end);
6565
- }
6566
- }
6567
- applyDeoptimizations() {
6568
- this.deoptimized = true;
6569
- this.left.deoptimizePath(EMPTY_PATH);
6570
- this.right.deoptimizePath(UNKNOWN_PATH);
6571
- this.context.requestTreeshakingPass();
6572
- }
6573
- }
6494
+ //@ts-check
6495
+ /** @typedef { import('estree').Node} Node */
6496
+ /** @typedef {Node | {
6497
+ * type: 'PropertyDefinition';
6498
+ * computed: boolean;
6499
+ * value: Node
6500
+ * }} NodeWithPropertyDefinition */
6574
6501
 
6575
- function treeshakeNode(node, code, start, end) {
6576
- code.remove(start, end);
6577
- if (node.annotations) {
6578
- for (const annotation of node.annotations) {
6579
- if (annotation.start < start) {
6580
- code.remove(annotation.start, annotation.end);
6581
- }
6582
- else {
6583
- return;
6584
- }
6585
- }
6586
- }
6587
- }
6588
- function removeAnnotations(node, code) {
6589
- if (!node.annotations && node.parent.type === ExpressionStatement$1) {
6590
- node = node.parent;
6591
- }
6592
- if (node.annotations) {
6593
- for (const annotation of node.annotations) {
6594
- code.remove(annotation.start, annotation.end);
6595
- }
6596
- }
6502
+ /**
6503
+ *
6504
+ * @param {NodeWithPropertyDefinition} node
6505
+ * @param {NodeWithPropertyDefinition} parent
6506
+ * @returns boolean
6507
+ */
6508
+ function is_reference (node, parent) {
6509
+ if (node.type === 'MemberExpression') {
6510
+ return !node.computed && is_reference(node.object, node);
6511
+ }
6512
+
6513
+ if (node.type === 'Identifier') {
6514
+ if (!parent) return true;
6515
+
6516
+ switch (parent.type) {
6517
+ // disregard `bar` in `foo.bar`
6518
+ case 'MemberExpression': return parent.computed || node === parent.object;
6519
+
6520
+ // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
6521
+ case 'MethodDefinition': return parent.computed;
6522
+
6523
+ // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
6524
+ case 'PropertyDefinition': return parent.computed || node === parent.value;
6525
+
6526
+ // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
6527
+ case 'Property': return parent.computed || node === parent.value;
6528
+
6529
+ // disregard the `bar` in `export { foo as bar }` or
6530
+ // the foo in `import { foo as bar }`
6531
+ case 'ExportSpecifier':
6532
+ case 'ImportSpecifier': return node === parent.local;
6533
+
6534
+ // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
6535
+ case 'LabeledStatement':
6536
+ case 'BreakStatement':
6537
+ case 'ContinueStatement': return false;
6538
+ default: return true;
6539
+ }
6540
+ }
6541
+
6542
+ return false;
6597
6543
  }
6598
6544
 
6599
- const NO_SEMICOLON = { isNoStatement: true };
6600
- // This assumes there are only white-space and comments between start and the string we are looking for
6601
- function findFirstOccurrenceOutsideComment(code, searchString, start = 0) {
6602
- let searchPos, charCodeAfterSlash;
6603
- searchPos = code.indexOf(searchString, start);
6604
- while (true) {
6605
- start = code.indexOf('/', start);
6606
- if (start === -1 || start >= searchPos)
6607
- return searchPos;
6608
- charCodeAfterSlash = code.charCodeAt(++start);
6609
- ++start;
6610
- // With our assumption, '/' always starts a comment. Determine comment type:
6611
- start =
6612
- charCodeAfterSlash === 47 /*"/"*/
6613
- ? code.indexOf('\n', start) + 1
6614
- : code.indexOf('*/', start) + 2;
6615
- if (start > searchPos) {
6616
- searchPos = code.indexOf(searchString, start);
6617
- }
6545
+ /* eslint sort-keys: "off" */
6546
+ const ValueProperties = Symbol('Value Properties');
6547
+ const PURE = {
6548
+ hasEffectsWhenCalled() {
6549
+ return false;
6618
6550
  }
6619
- }
6620
- const NON_WHITESPACE = /\S/g;
6621
- function findNonWhiteSpace(code, index) {
6622
- NON_WHITESPACE.lastIndex = index;
6623
- const result = NON_WHITESPACE.exec(code);
6624
- return result.index;
6625
- }
6626
- // This assumes "code" only contains white-space and comments
6627
- // Returns position of line-comment if applicable
6628
- function findFirstLineBreakOutsideComment(code) {
6629
- let lineBreakPos, charCodeAfterSlash, start = 0;
6630
- lineBreakPos = code.indexOf('\n', start);
6631
- while (true) {
6632
- start = code.indexOf('/', start);
6633
- if (start === -1 || start > lineBreakPos)
6634
- return [lineBreakPos, lineBreakPos + 1];
6635
- // With our assumption, '/' always starts a comment. Determine comment type:
6636
- charCodeAfterSlash = code.charCodeAt(start + 1);
6637
- if (charCodeAfterSlash === 47 /*"/"*/)
6638
- return [start, lineBreakPos + 1];
6639
- start = code.indexOf('*/', start + 3) + 2;
6640
- if (start > lineBreakPos) {
6641
- lineBreakPos = code.indexOf('\n', start);
6642
- }
6551
+ };
6552
+ const IMPURE = {
6553
+ hasEffectsWhenCalled() {
6554
+ return true;
6643
6555
  }
6644
- }
6645
- function renderStatementList(statements, code, start, end, options) {
6646
- let currentNode, currentNodeStart, currentNodeNeedsBoundaries, nextNodeStart;
6647
- let nextNode = statements[0];
6648
- let nextNodeNeedsBoundaries = !nextNode.included || nextNode.needsBoundaries;
6649
- if (nextNodeNeedsBoundaries) {
6650
- nextNodeStart =
6651
- start + findFirstLineBreakOutsideComment(code.original.slice(start, nextNode.start))[1];
6652
- }
6653
- for (let nextIndex = 1; nextIndex <= statements.length; nextIndex++) {
6654
- currentNode = nextNode;
6655
- currentNodeStart = nextNodeStart;
6656
- currentNodeNeedsBoundaries = nextNodeNeedsBoundaries;
6657
- nextNode = statements[nextIndex];
6658
- nextNodeNeedsBoundaries =
6659
- nextNode === undefined ? false : !nextNode.included || nextNode.needsBoundaries;
6660
- if (currentNodeNeedsBoundaries || nextNodeNeedsBoundaries) {
6661
- nextNodeStart =
6662
- currentNode.end +
6663
- findFirstLineBreakOutsideComment(code.original.slice(currentNode.end, nextNode === undefined ? end : nextNode.start))[1];
6664
- if (currentNode.included) {
6665
- currentNodeNeedsBoundaries
6666
- ? currentNode.render(code, options, {
6667
- end: nextNodeStart,
6668
- start: currentNodeStart
6669
- })
6670
- : currentNode.render(code, options);
6671
- }
6672
- else {
6673
- treeshakeNode(currentNode, code, currentNodeStart, nextNodeStart);
6674
- }
6675
- }
6676
- else {
6677
- currentNode.render(code, options);
6678
- }
6679
- }
6680
- }
6681
- // This assumes that the first character is not part of the first node
6682
- function getCommaSeparatedNodesWithBoundaries(nodes, code, start, end) {
6683
- const splitUpNodes = [];
6684
- let node, nextNode, nextNodeStart, contentEnd, char;
6685
- let separator = start - 1;
6686
- for (let nextIndex = 0; nextIndex < nodes.length; nextIndex++) {
6687
- nextNode = nodes[nextIndex];
6688
- if (node !== undefined) {
6689
- separator =
6690
- node.end +
6691
- findFirstOccurrenceOutsideComment(code.original.slice(node.end, nextNode.start), ',');
6692
- }
6693
- nextNodeStart = contentEnd =
6694
- separator +
6695
- 1 +
6696
- findFirstLineBreakOutsideComment(code.original.slice(separator + 1, nextNode.start))[1];
6697
- while (((char = code.original.charCodeAt(nextNodeStart)),
6698
- char === 32 /*" "*/ || char === 9 /*"\t"*/ || char === 10 /*"\n"*/ || char === 13) /*"\r"*/)
6699
- nextNodeStart++;
6700
- if (node !== undefined) {
6701
- splitUpNodes.push({
6702
- contentEnd,
6703
- end: nextNodeStart,
6704
- node,
6705
- separator,
6706
- start
6707
- });
6708
- }
6709
- node = nextNode;
6710
- start = nextNodeStart;
6711
- }
6712
- splitUpNodes.push({
6713
- contentEnd: end,
6714
- end,
6715
- node: node,
6716
- separator: null,
6717
- start
6718
- });
6719
- return splitUpNodes;
6720
- }
6721
- // This assumes there are only white-space and comments between start and end
6722
- function removeLineBreaks(code, start, end) {
6723
- while (true) {
6724
- const [removeStart, removeEnd] = findFirstLineBreakOutsideComment(code.original.slice(start, end));
6725
- if (removeStart === -1) {
6726
- break;
6727
- }
6728
- code.remove(start + removeStart, (start += removeEnd));
6729
- }
6730
- }
6731
-
6732
- class BlockScope extends ChildScope {
6733
- addDeclaration(identifier, context, init, isHoisted) {
6734
- if (isHoisted) {
6735
- const variable = this.parent.addDeclaration(identifier, context, init, isHoisted);
6736
- // Necessary to make sure the init is deoptimized for conditional declarations.
6737
- // We cannot call deoptimizePath here.
6738
- variable.markInitializersForDeoptimization();
6739
- return variable;
6740
- }
6741
- else {
6742
- return super.addDeclaration(identifier, context, init, false);
6743
- }
6744
- }
6745
- }
6746
-
6747
- class ExpressionStatement extends NodeBase {
6748
- initialise() {
6749
- if (this.directive &&
6750
- this.directive !== 'use strict' &&
6751
- this.parent.type === Program$1) {
6752
- this.context.warn(
6753
- // This is necessary, because either way (deleting or not) can lead to errors.
6754
- {
6755
- code: 'MODULE_LEVEL_DIRECTIVE',
6756
- message: `Module level directives cause errors when bundled, '${this.directive}' was ignored.`
6757
- }, this.start);
6758
- }
6759
- }
6760
- render(code, options) {
6761
- super.render(code, options);
6762
- if (this.included)
6763
- this.insertSemicolon(code);
6764
- }
6765
- shouldBeIncluded(context) {
6766
- if (this.directive && this.directive !== 'use strict')
6767
- return this.parent.type !== Program$1;
6768
- return super.shouldBeIncluded(context);
6769
- }
6770
- }
6771
-
6772
- class BlockStatement extends NodeBase {
6773
- constructor() {
6774
- super(...arguments);
6775
- this.directlyIncluded = false;
6776
- }
6777
- addImplicitReturnExpressionToScope() {
6778
- const lastStatement = this.body[this.body.length - 1];
6779
- if (!lastStatement || lastStatement.type !== ReturnStatement$1) {
6780
- this.scope.addReturnExpression(UNKNOWN_EXPRESSION);
6781
- }
6782
- }
6783
- createScope(parentScope) {
6784
- this.scope = this.parent.preventChildBlockScope
6785
- ? parentScope
6786
- : new BlockScope(parentScope);
6787
- }
6788
- hasEffects(context) {
6789
- if (this.deoptimizeBody)
6790
- return true;
6791
- for (const node of this.body) {
6792
- if (context.brokenFlow)
6793
- break;
6794
- if (node.hasEffects(context))
6795
- return true;
6796
- }
6797
- return false;
6798
- }
6799
- include(context, includeChildrenRecursively) {
6800
- if (!(this.deoptimizeBody && this.directlyIncluded)) {
6801
- this.included = true;
6802
- this.directlyIncluded = true;
6803
- if (this.deoptimizeBody)
6804
- includeChildrenRecursively = true;
6805
- for (const node of this.body) {
6806
- if (includeChildrenRecursively || node.shouldBeIncluded(context))
6807
- node.include(context, includeChildrenRecursively);
6808
- }
6809
- }
6810
- }
6811
- initialise() {
6812
- const firstBodyStatement = this.body[0];
6813
- this.deoptimizeBody =
6814
- firstBodyStatement instanceof ExpressionStatement &&
6815
- firstBodyStatement.directive === 'use asm';
6816
- }
6817
- render(code, options) {
6818
- if (this.body.length) {
6819
- renderStatementList(this.body, code, this.start + 1, this.end - 1, options);
6820
- }
6821
- else {
6822
- super.render(code, options);
6823
- }
6824
- }
6825
- }
6826
-
6827
- class RestElement extends NodeBase {
6828
- constructor() {
6829
- super(...arguments);
6830
- this.deoptimized = false;
6831
- this.declarationInit = null;
6832
- }
6833
- addExportedVariables(variables, exportNamesByVariable) {
6834
- this.argument.addExportedVariables(variables, exportNamesByVariable);
6835
- }
6836
- declare(kind, init) {
6837
- this.declarationInit = init;
6838
- return this.argument.declare(kind, UNKNOWN_EXPRESSION);
6839
- }
6840
- deoptimizePath(path) {
6841
- path.length === 0 && this.argument.deoptimizePath(EMPTY_PATH);
6842
- }
6843
- hasEffectsWhenAssignedAtPath(path, context) {
6844
- return path.length > 0 || this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
6845
- }
6846
- markDeclarationReached() {
6847
- this.argument.markDeclarationReached();
6848
- }
6849
- applyDeoptimizations() {
6850
- this.deoptimized = true;
6851
- if (this.declarationInit !== null) {
6852
- this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
6853
- this.context.requestTreeshakingPass();
6854
- }
6855
- }
6856
- }
6857
-
6858
- class FunctionBase extends NodeBase {
6859
- constructor() {
6860
- super(...arguments);
6861
- // By default, parameters are included via includeArgumentsWhenCalledAtPath
6862
- this.alwaysIncludeParameters = false;
6863
- this.objectEntity = null;
6864
- this.deoptimizedReturn = false;
6865
- }
6866
- deoptimizeCache() {
6867
- this.alwaysIncludeParameters = true;
6868
- }
6869
- deoptimizePath(path) {
6870
- this.getObjectEntity().deoptimizePath(path);
6871
- if (path.length === 1 && path[0] === UnknownKey) {
6872
- // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
6873
- // which means the return expression needs to be reassigned
6874
- this.alwaysIncludeParameters = true;
6875
- this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
6876
- }
6877
- }
6878
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
6879
- if (path.length > 0) {
6880
- this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
6881
- }
6882
- }
6883
- getLiteralValueAtPath(path, recursionTracker, origin) {
6884
- return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
6885
- }
6886
- getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
6887
- if (path.length > 0) {
6888
- return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
6889
- }
6890
- if (this.async) {
6891
- if (!this.deoptimizedReturn) {
6892
- this.deoptimizedReturn = true;
6893
- this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
6894
- this.context.requestTreeshakingPass();
6895
- }
6896
- return UNKNOWN_EXPRESSION;
6897
- }
6898
- return this.scope.getReturnExpression();
6899
- }
6900
- hasEffectsWhenAccessedAtPath(path, context) {
6901
- return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
6902
- }
6903
- hasEffectsWhenAssignedAtPath(path, context) {
6904
- return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
6905
- }
6906
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
6907
- if (path.length > 0) {
6908
- return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
6909
- }
6910
- if (this.async) {
6911
- const { propertyReadSideEffects } = this.context.options
6912
- .treeshake;
6913
- const returnExpression = this.scope.getReturnExpression();
6914
- if (returnExpression.hasEffectsWhenCalledAtPath(['then'], { args: NO_ARGS, thisParam: null, withNew: false }, context) ||
6915
- (propertyReadSideEffects &&
6916
- (propertyReadSideEffects === 'always' ||
6917
- returnExpression.hasEffectsWhenAccessedAtPath(['then'], context)))) {
6918
- return true;
6919
- }
6920
- }
6921
- for (const param of this.params) {
6922
- if (param.hasEffects(context))
6923
- return true;
6924
- }
6925
- return false;
6926
- }
6927
- include(context, includeChildrenRecursively) {
6928
- this.included = true;
6929
- const { brokenFlow } = context;
6930
- context.brokenFlow = BROKEN_FLOW_NONE;
6931
- this.body.include(context, includeChildrenRecursively);
6932
- context.brokenFlow = brokenFlow;
6933
- if (includeChildrenRecursively || this.alwaysIncludeParameters) {
6934
- for (const param of this.params) {
6935
- param.include(context, includeChildrenRecursively);
6936
- }
6937
- }
6938
- }
6939
- includeArgumentsWhenCalledAtPath(path, context, args) {
6940
- var _a;
6941
- if (path.length === 0) {
6942
- for (let position = 0; position < this.params.length; position++) {
6943
- const parameter = this.params[position];
6944
- if (parameter instanceof AssignmentPattern) {
6945
- if (parameter.left.shouldBeIncluded(context)) {
6946
- parameter.left.include(context, false);
6947
- }
6948
- const argumentValue = (_a = args[position]) === null || _a === void 0 ? void 0 : _a.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
6949
- // If argumentValue === UnknownTruthyValue, then we do not need to
6950
- // include the default
6951
- if ((argumentValue === undefined || argumentValue === UnknownValue) &&
6952
- (this.parameterVariables[position].some(variable => variable.included) ||
6953
- parameter.right.shouldBeIncluded(context))) {
6954
- parameter.right.include(context, false);
6955
- }
6956
- }
6957
- else if (parameter.shouldBeIncluded(context)) {
6958
- parameter.include(context, false);
6959
- }
6960
- }
6961
- this.scope.includeCallArguments(context, args);
6962
- }
6963
- else {
6964
- this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
6965
- }
6966
- }
6967
- initialise() {
6968
- this.parameterVariables = this.params.map(param => param.declare('parameter', UNKNOWN_EXPRESSION));
6969
- this.scope.addParameterVariables(this.parameterVariables, this.params[this.params.length - 1] instanceof RestElement);
6970
- if (this.body instanceof BlockStatement) {
6971
- this.body.addImplicitReturnExpressionToScope();
6972
- }
6973
- else {
6974
- this.scope.addReturnExpression(this.body);
6975
- }
6976
- }
6977
- parseNode(esTreeNode) {
6978
- if (esTreeNode.body.type === BlockStatement$1) {
6979
- this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
6980
- }
6981
- super.parseNode(esTreeNode);
6982
- }
6983
- }
6984
- FunctionBase.prototype.preventChildBlockScope = true;
6985
-
6986
- class ArrowFunctionExpression extends FunctionBase {
6987
- constructor() {
6988
- super(...arguments);
6989
- this.objectEntity = null;
6990
- }
6991
- createScope(parentScope) {
6992
- this.scope = new ReturnValueScope(parentScope, this.context);
6993
- }
6994
- hasEffects() {
6995
- return false;
6996
- }
6997
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
6998
- if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
6999
- return true;
7000
- const { ignore, brokenFlow } = context;
7001
- context.ignore = {
7002
- breaks: false,
7003
- continues: false,
7004
- labels: new Set(),
7005
- returnYield: true
7006
- };
7007
- if (this.body.hasEffects(context))
7008
- return true;
7009
- context.ignore = ignore;
7010
- context.brokenFlow = brokenFlow;
7011
- return false;
7012
- }
7013
- getObjectEntity() {
7014
- if (this.objectEntity !== null) {
7015
- return this.objectEntity;
7016
- }
7017
- return (this.objectEntity = new ObjectEntity([], OBJECT_PROTOTYPE));
7018
- }
7019
- }
7020
-
7021
- function getSystemExportStatement(exportedVariables, { exportNamesByVariable, snippets: { _, getObject, getPropertyAccess } }, modifier = '') {
7022
- if (exportedVariables.length === 1 &&
7023
- exportNamesByVariable.get(exportedVariables[0]).length === 1) {
7024
- const variable = exportedVariables[0];
7025
- return `exports('${exportNamesByVariable.get(variable)}',${_}${variable.getName(getPropertyAccess)}${modifier})`;
7026
- }
7027
- else {
7028
- const fields = [];
7029
- for (const variable of exportedVariables) {
7030
- for (const exportName of exportNamesByVariable.get(variable)) {
7031
- fields.push([exportName, variable.getName(getPropertyAccess) + modifier]);
7032
- }
7033
- }
7034
- return `exports(${getObject(fields, { lineBreakIndent: null })})`;
7035
- }
7036
- }
7037
- function renderSystemExportExpression(exportedVariable, expressionStart, expressionEnd, code, { exportNamesByVariable, snippets: { _ } }) {
7038
- code.prependRight(expressionStart, `exports('${exportNamesByVariable.get(exportedVariable)}',${_}`);
7039
- code.appendLeft(expressionEnd, ')');
7040
- }
7041
- function renderSystemExportFunction(exportedVariables, expressionStart, expressionEnd, needsParens, code, options) {
7042
- const { _, getDirectReturnIifeLeft } = options.snippets;
7043
- code.prependRight(expressionStart, getDirectReturnIifeLeft(['v'], `${getSystemExportStatement(exportedVariables, options)},${_}v`, { needsArrowReturnParens: true, needsWrappedFunction: needsParens }));
7044
- code.appendLeft(expressionEnd, ')');
7045
- }
7046
- function renderSystemExportSequenceAfterExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options) {
7047
- const { _, getPropertyAccess } = options.snippets;
7048
- code.appendLeft(expressionEnd, `,${_}${getSystemExportStatement([exportedVariable], options)},${_}${exportedVariable.getName(getPropertyAccess)}`);
7049
- if (needsParens) {
7050
- code.prependRight(expressionStart, '(');
7051
- code.appendLeft(expressionEnd, ')');
7052
- }
7053
- }
7054
- function renderSystemExportSequenceBeforeExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options, modifier) {
7055
- const { _ } = options.snippets;
7056
- code.prependRight(expressionStart, `${getSystemExportStatement([exportedVariable], options, modifier)},${_}`);
7057
- if (needsParens) {
7058
- code.prependRight(expressionStart, '(');
7059
- code.appendLeft(expressionEnd, ')');
7060
- }
7061
- }
7062
-
7063
- //@ts-check
7064
- /** @typedef { import('estree').Node} Node */
7065
- /** @typedef {Node | {
7066
- * type: 'PropertyDefinition';
7067
- * computed: boolean;
7068
- * value: Node
7069
- * }} NodeWithPropertyDefinition */
7070
-
7071
- /**
7072
- *
7073
- * @param {NodeWithPropertyDefinition} node
7074
- * @param {NodeWithPropertyDefinition} parent
7075
- * @returns boolean
7076
- */
7077
- function is_reference (node, parent) {
7078
- if (node.type === 'MemberExpression') {
7079
- return !node.computed && is_reference(node.object, node);
7080
- }
7081
-
7082
- if (node.type === 'Identifier') {
7083
- if (!parent) return true;
7084
-
7085
- switch (parent.type) {
7086
- // disregard `bar` in `foo.bar`
7087
- case 'MemberExpression': return parent.computed || node === parent.object;
7088
-
7089
- // disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
7090
- case 'MethodDefinition': return parent.computed;
7091
-
7092
- // disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
7093
- case 'PropertyDefinition': return parent.computed || node === parent.value;
7094
-
7095
- // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
7096
- case 'Property': return parent.computed || node === parent.value;
7097
-
7098
- // disregard the `bar` in `export { foo as bar }` or
7099
- // the foo in `import { foo as bar }`
7100
- case 'ExportSpecifier':
7101
- case 'ImportSpecifier': return node === parent.local;
7102
-
7103
- // disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
7104
- case 'LabeledStatement':
7105
- case 'BreakStatement':
7106
- case 'ContinueStatement': return false;
7107
- default: return true;
7108
- }
7109
- }
7110
-
7111
- return false;
7112
- }
7113
-
7114
- /* eslint sort-keys: "off" */
7115
- const ValueProperties = Symbol('Value Properties');
7116
- const PURE = {
7117
- hasEffectsWhenCalled() {
7118
- return false;
7119
- }
7120
- };
7121
- const IMPURE = {
7122
- hasEffectsWhenCalled() {
7123
- return true;
7124
- }
7125
- };
7126
- // We use shortened variables to reduce file size here
7127
- /* OBJECT */
7128
- const O = {
7129
- __proto__: null,
7130
- [ValueProperties]: IMPURE
7131
- };
7132
- /* PURE FUNCTION */
7133
- const PF = {
7134
- __proto__: null,
7135
- [ValueProperties]: PURE
7136
- };
7137
- /* FUNCTION THAT MUTATES FIRST ARG WITHOUT TRIGGERING ACCESSORS */
7138
- const MUTATES_ARG_WITHOUT_ACCESSOR = {
7139
- __proto__: null,
7140
- [ValueProperties]: {
7141
- hasEffectsWhenCalled(callOptions, context) {
7142
- return (!callOptions.args.length ||
7143
- callOptions.args[0].hasEffectsWhenAssignedAtPath(UNKNOWN_NON_ACCESSOR_PATH, context));
7144
- }
6556
+ };
6557
+ // We use shortened variables to reduce file size here
6558
+ /* OBJECT */
6559
+ const O = {
6560
+ __proto__: null,
6561
+ [ValueProperties]: IMPURE
6562
+ };
6563
+ /* PURE FUNCTION */
6564
+ const PF = {
6565
+ __proto__: null,
6566
+ [ValueProperties]: PURE
6567
+ };
6568
+ /* FUNCTION THAT MUTATES FIRST ARG WITHOUT TRIGGERING ACCESSORS */
6569
+ const MUTATES_ARG_WITHOUT_ACCESSOR = {
6570
+ __proto__: null,
6571
+ [ValueProperties]: {
6572
+ hasEffectsWhenCalled(callOptions, context) {
6573
+ return (!callOptions.args.length ||
6574
+ callOptions.args[0].hasEffectsWhenAssignedAtPath(UNKNOWN_NON_ACCESSOR_PATH, context));
6575
+ }
7145
6576
  }
7146
6577
  };
7147
6578
  /* CONSTRUCTOR */
@@ -7957,222 +7388,682 @@ const knownGlobals = {
7957
7388
  for (const global of ['window', 'global', 'self', 'globalThis']) {
7958
7389
  knownGlobals[global] = knownGlobals;
7959
7390
  }
7960
- function getGlobalAtPath(path) {
7961
- let currentGlobal = knownGlobals;
7962
- for (const pathSegment of path) {
7963
- if (typeof pathSegment !== 'string') {
7964
- return null;
7391
+ function getGlobalAtPath(path) {
7392
+ let currentGlobal = knownGlobals;
7393
+ for (const pathSegment of path) {
7394
+ if (typeof pathSegment !== 'string') {
7395
+ return null;
7396
+ }
7397
+ currentGlobal = currentGlobal[pathSegment];
7398
+ if (!currentGlobal) {
7399
+ return null;
7400
+ }
7401
+ }
7402
+ return currentGlobal[ValueProperties];
7403
+ }
7404
+
7405
+ class GlobalVariable extends Variable {
7406
+ constructor() {
7407
+ super(...arguments);
7408
+ // Ensure we use live-bindings for globals as we do not know if they have
7409
+ // been reassigned
7410
+ this.isReassigned = true;
7411
+ }
7412
+ hasEffectsWhenAccessedAtPath(path) {
7413
+ if (path.length === 0) {
7414
+ // Technically, "undefined" is a global variable of sorts
7415
+ return this.name !== 'undefined' && getGlobalAtPath([this.name]) === null;
7416
+ }
7417
+ return getGlobalAtPath([this.name, ...path].slice(0, -1)) === null;
7418
+ }
7419
+ hasEffectsWhenCalledAtPath(path, callOptions, context) {
7420
+ const globalAtPath = getGlobalAtPath([this.name, ...path]);
7421
+ return globalAtPath === null || globalAtPath.hasEffectsWhenCalled(callOptions, context);
7422
+ }
7423
+ }
7424
+
7425
+ const tdzVariableKinds = {
7426
+ __proto__: null,
7427
+ class: true,
7428
+ const: true,
7429
+ let: true,
7430
+ var: true
7431
+ };
7432
+ class Identifier extends NodeBase {
7433
+ constructor() {
7434
+ super(...arguments);
7435
+ this.variable = null;
7436
+ this.deoptimized = false;
7437
+ this.isTDZAccess = null;
7438
+ }
7439
+ addExportedVariables(variables, exportNamesByVariable) {
7440
+ if (this.variable !== null && exportNamesByVariable.has(this.variable)) {
7441
+ variables.push(this.variable);
7442
+ }
7443
+ }
7444
+ bind() {
7445
+ if (this.variable === null && is_reference(this, this.parent)) {
7446
+ this.variable = this.scope.findVariable(this.name);
7447
+ this.variable.addReference(this);
7448
+ }
7449
+ }
7450
+ declare(kind, init) {
7451
+ let variable;
7452
+ const { treeshake } = this.context.options;
7453
+ switch (kind) {
7454
+ case 'var':
7455
+ variable = this.scope.addDeclaration(this, this.context, init, true);
7456
+ if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
7457
+ // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
7458
+ variable.markInitializersForDeoptimization();
7459
+ }
7460
+ break;
7461
+ case 'function':
7462
+ // in strict mode, functions are only hoisted within a scope but not across block scopes
7463
+ variable = this.scope.addDeclaration(this, this.context, init, false);
7464
+ break;
7465
+ case 'let':
7466
+ case 'const':
7467
+ case 'class':
7468
+ variable = this.scope.addDeclaration(this, this.context, init, false);
7469
+ break;
7470
+ case 'parameter':
7471
+ variable = this.scope.addParameterDeclaration(this);
7472
+ break;
7473
+ /* istanbul ignore next */
7474
+ default:
7475
+ /* istanbul ignore next */
7476
+ throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
7477
+ }
7478
+ variable.kind = kind;
7479
+ return [(this.variable = variable)];
7480
+ }
7481
+ deoptimizePath(path) {
7482
+ if (path.length === 0 && !this.scope.contains(this.name)) {
7483
+ this.disallowImportReassignment();
7484
+ }
7485
+ this.variable.deoptimizePath(path);
7486
+ }
7487
+ deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
7488
+ this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
7489
+ }
7490
+ getLiteralValueAtPath(path, recursionTracker, origin) {
7491
+ return this.getVariableRespectingTDZ().getLiteralValueAtPath(path, recursionTracker, origin);
7492
+ }
7493
+ getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
7494
+ return this.getVariableRespectingTDZ().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
7495
+ }
7496
+ hasEffects() {
7497
+ if (!this.deoptimized)
7498
+ this.applyDeoptimizations();
7499
+ if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
7500
+ return true;
7501
+ }
7502
+ return (this.context.options.treeshake.unknownGlobalSideEffects &&
7503
+ this.variable instanceof GlobalVariable &&
7504
+ this.variable.hasEffectsWhenAccessedAtPath(EMPTY_PATH));
7505
+ }
7506
+ hasEffectsWhenAccessedAtPath(path, context) {
7507
+ return (this.variable !== null &&
7508
+ this.getVariableRespectingTDZ().hasEffectsWhenAccessedAtPath(path, context));
7509
+ }
7510
+ hasEffectsWhenAssignedAtPath(path, context) {
7511
+ return (!this.variable ||
7512
+ (path.length > 0
7513
+ ? this.getVariableRespectingTDZ()
7514
+ : this.variable).hasEffectsWhenAssignedAtPath(path, context));
7515
+ }
7516
+ hasEffectsWhenCalledAtPath(path, callOptions, context) {
7517
+ return (!this.variable ||
7518
+ this.getVariableRespectingTDZ().hasEffectsWhenCalledAtPath(path, callOptions, context));
7519
+ }
7520
+ include() {
7521
+ if (!this.deoptimized)
7522
+ this.applyDeoptimizations();
7523
+ if (!this.included) {
7524
+ this.included = true;
7525
+ if (this.variable !== null) {
7526
+ this.context.includeVariableInModule(this.variable);
7527
+ }
7528
+ }
7529
+ }
7530
+ includeCallArguments(context, args) {
7531
+ this.getVariableRespectingTDZ().includeCallArguments(context, args);
7532
+ }
7533
+ isPossibleTDZ() {
7534
+ // return cached value to avoid issues with the next tree-shaking pass
7535
+ if (this.isTDZAccess !== null)
7536
+ return this.isTDZAccess;
7537
+ if (!(this.variable instanceof LocalVariable) ||
7538
+ !this.variable.kind ||
7539
+ !(this.variable.kind in tdzVariableKinds)) {
7540
+ return (this.isTDZAccess = false);
7541
+ }
7542
+ let decl_id;
7543
+ if (this.variable.declarations &&
7544
+ this.variable.declarations.length === 1 &&
7545
+ (decl_id = this.variable.declarations[0]) &&
7546
+ this.start < decl_id.start &&
7547
+ closestParentFunctionOrProgram(this) === closestParentFunctionOrProgram(decl_id)) {
7548
+ // a variable accessed before its declaration
7549
+ // in the same function or at top level of module
7550
+ return (this.isTDZAccess = true);
7551
+ }
7552
+ if (!this.variable.initReached) {
7553
+ // Either a const/let TDZ violation or
7554
+ // var use before declaration was encountered.
7555
+ return (this.isTDZAccess = true);
7556
+ }
7557
+ return (this.isTDZAccess = false);
7558
+ }
7559
+ markDeclarationReached() {
7560
+ this.variable.initReached = true;
7561
+ }
7562
+ render(code, { snippets: { getPropertyAccess } }, { renderedParentType, isCalleeOfRenderedParent, isShorthandProperty } = BLANK) {
7563
+ if (this.variable) {
7564
+ const name = this.variable.getName(getPropertyAccess);
7565
+ if (name !== this.name) {
7566
+ code.overwrite(this.start, this.end, name, {
7567
+ contentOnly: true,
7568
+ storeName: true
7569
+ });
7570
+ if (isShorthandProperty) {
7571
+ code.prependRight(this.start, `${this.name}: `);
7572
+ }
7573
+ }
7574
+ // In strict mode, any variable named "eval" must be the actual "eval" function
7575
+ if (name === 'eval' &&
7576
+ renderedParentType === CallExpression$1 &&
7577
+ isCalleeOfRenderedParent) {
7578
+ code.appendRight(this.start, '0, ');
7579
+ }
7580
+ }
7581
+ }
7582
+ applyDeoptimizations() {
7583
+ this.deoptimized = true;
7584
+ if (this.variable !== null && this.variable instanceof LocalVariable) {
7585
+ this.variable.consolidateInitializers();
7586
+ this.context.requestTreeshakingPass();
7587
+ }
7588
+ }
7589
+ disallowImportReassignment() {
7590
+ return this.context.error({
7591
+ code: 'ILLEGAL_REASSIGNMENT',
7592
+ message: `Illegal reassignment to import '${this.name}'`
7593
+ }, this.start);
7594
+ }
7595
+ getVariableRespectingTDZ() {
7596
+ if (this.isPossibleTDZ()) {
7597
+ return UNKNOWN_EXPRESSION;
7598
+ }
7599
+ return this.variable;
7600
+ }
7601
+ }
7602
+ function closestParentFunctionOrProgram(node) {
7603
+ while (node && !/^Program|Function/.test(node.type)) {
7604
+ node = node.parent;
7605
+ }
7606
+ // one of: ArrowFunctionExpression, FunctionDeclaration, FunctionExpression or Program
7607
+ return node;
7608
+ }
7609
+
7610
+ function treeshakeNode(node, code, start, end) {
7611
+ code.remove(start, end);
7612
+ if (node.annotations) {
7613
+ for (const annotation of node.annotations) {
7614
+ if (annotation.start < start) {
7615
+ code.remove(annotation.start, annotation.end);
7616
+ }
7617
+ else {
7618
+ return;
7619
+ }
7620
+ }
7621
+ }
7622
+ }
7623
+ function removeAnnotations(node, code) {
7624
+ if (!node.annotations && node.parent.type === ExpressionStatement$1) {
7625
+ node = node.parent;
7626
+ }
7627
+ if (node.annotations) {
7628
+ for (const annotation of node.annotations) {
7629
+ code.remove(annotation.start, annotation.end);
7630
+ }
7631
+ }
7632
+ }
7633
+
7634
+ const NO_SEMICOLON = { isNoStatement: true };
7635
+ // This assumes there are only white-space and comments between start and the string we are looking for
7636
+ function findFirstOccurrenceOutsideComment(code, searchString, start = 0) {
7637
+ let searchPos, charCodeAfterSlash;
7638
+ searchPos = code.indexOf(searchString, start);
7639
+ while (true) {
7640
+ start = code.indexOf('/', start);
7641
+ if (start === -1 || start >= searchPos)
7642
+ return searchPos;
7643
+ charCodeAfterSlash = code.charCodeAt(++start);
7644
+ ++start;
7645
+ // With our assumption, '/' always starts a comment. Determine comment type:
7646
+ start =
7647
+ charCodeAfterSlash === 47 /*"/"*/
7648
+ ? code.indexOf('\n', start) + 1
7649
+ : code.indexOf('*/', start) + 2;
7650
+ if (start > searchPos) {
7651
+ searchPos = code.indexOf(searchString, start);
7652
+ }
7653
+ }
7654
+ }
7655
+ const NON_WHITESPACE = /\S/g;
7656
+ function findNonWhiteSpace(code, index) {
7657
+ NON_WHITESPACE.lastIndex = index;
7658
+ const result = NON_WHITESPACE.exec(code);
7659
+ return result.index;
7660
+ }
7661
+ // This assumes "code" only contains white-space and comments
7662
+ // Returns position of line-comment if applicable
7663
+ function findFirstLineBreakOutsideComment(code) {
7664
+ let lineBreakPos, charCodeAfterSlash, start = 0;
7665
+ lineBreakPos = code.indexOf('\n', start);
7666
+ while (true) {
7667
+ start = code.indexOf('/', start);
7668
+ if (start === -1 || start > lineBreakPos)
7669
+ return [lineBreakPos, lineBreakPos + 1];
7670
+ // With our assumption, '/' always starts a comment. Determine comment type:
7671
+ charCodeAfterSlash = code.charCodeAt(start + 1);
7672
+ if (charCodeAfterSlash === 47 /*"/"*/)
7673
+ return [start, lineBreakPos + 1];
7674
+ start = code.indexOf('*/', start + 3) + 2;
7675
+ if (start > lineBreakPos) {
7676
+ lineBreakPos = code.indexOf('\n', start);
7965
7677
  }
7966
- currentGlobal = currentGlobal[pathSegment];
7967
- if (!currentGlobal) {
7968
- return null;
7678
+ }
7679
+ }
7680
+ function renderStatementList(statements, code, start, end, options) {
7681
+ let currentNode, currentNodeStart, currentNodeNeedsBoundaries, nextNodeStart;
7682
+ let nextNode = statements[0];
7683
+ let nextNodeNeedsBoundaries = !nextNode.included || nextNode.needsBoundaries;
7684
+ if (nextNodeNeedsBoundaries) {
7685
+ nextNodeStart =
7686
+ start + findFirstLineBreakOutsideComment(code.original.slice(start, nextNode.start))[1];
7687
+ }
7688
+ for (let nextIndex = 1; nextIndex <= statements.length; nextIndex++) {
7689
+ currentNode = nextNode;
7690
+ currentNodeStart = nextNodeStart;
7691
+ currentNodeNeedsBoundaries = nextNodeNeedsBoundaries;
7692
+ nextNode = statements[nextIndex];
7693
+ nextNodeNeedsBoundaries =
7694
+ nextNode === undefined ? false : !nextNode.included || nextNode.needsBoundaries;
7695
+ if (currentNodeNeedsBoundaries || nextNodeNeedsBoundaries) {
7696
+ nextNodeStart =
7697
+ currentNode.end +
7698
+ findFirstLineBreakOutsideComment(code.original.slice(currentNode.end, nextNode === undefined ? end : nextNode.start))[1];
7699
+ if (currentNode.included) {
7700
+ currentNodeNeedsBoundaries
7701
+ ? currentNode.render(code, options, {
7702
+ end: nextNodeStart,
7703
+ start: currentNodeStart
7704
+ })
7705
+ : currentNode.render(code, options);
7706
+ }
7707
+ else {
7708
+ treeshakeNode(currentNode, code, currentNodeStart, nextNodeStart);
7709
+ }
7710
+ }
7711
+ else {
7712
+ currentNode.render(code, options);
7969
7713
  }
7970
7714
  }
7971
- return currentGlobal[ValueProperties];
7715
+ }
7716
+ // This assumes that the first character is not part of the first node
7717
+ function getCommaSeparatedNodesWithBoundaries(nodes, code, start, end) {
7718
+ const splitUpNodes = [];
7719
+ let node, nextNode, nextNodeStart, contentEnd, char;
7720
+ let separator = start - 1;
7721
+ for (let nextIndex = 0; nextIndex < nodes.length; nextIndex++) {
7722
+ nextNode = nodes[nextIndex];
7723
+ if (node !== undefined) {
7724
+ separator =
7725
+ node.end +
7726
+ findFirstOccurrenceOutsideComment(code.original.slice(node.end, nextNode.start), ',');
7727
+ }
7728
+ nextNodeStart = contentEnd =
7729
+ separator +
7730
+ 1 +
7731
+ findFirstLineBreakOutsideComment(code.original.slice(separator + 1, nextNode.start))[1];
7732
+ while (((char = code.original.charCodeAt(nextNodeStart)),
7733
+ char === 32 /*" "*/ || char === 9 /*"\t"*/ || char === 10 /*"\n"*/ || char === 13) /*"\r"*/)
7734
+ nextNodeStart++;
7735
+ if (node !== undefined) {
7736
+ splitUpNodes.push({
7737
+ contentEnd,
7738
+ end: nextNodeStart,
7739
+ node,
7740
+ separator,
7741
+ start
7742
+ });
7743
+ }
7744
+ node = nextNode;
7745
+ start = nextNodeStart;
7746
+ }
7747
+ splitUpNodes.push({
7748
+ contentEnd: end,
7749
+ end,
7750
+ node: node,
7751
+ separator: null,
7752
+ start
7753
+ });
7754
+ return splitUpNodes;
7755
+ }
7756
+ // This assumes there are only white-space and comments between start and end
7757
+ function removeLineBreaks(code, start, end) {
7758
+ while (true) {
7759
+ const [removeStart, removeEnd] = findFirstLineBreakOutsideComment(code.original.slice(start, end));
7760
+ if (removeStart === -1) {
7761
+ break;
7762
+ }
7763
+ code.remove(start + removeStart, (start += removeEnd));
7764
+ }
7972
7765
  }
7973
7766
 
7974
- class GlobalVariable extends Variable {
7767
+ class BlockScope extends ChildScope {
7768
+ addDeclaration(identifier, context, init, isHoisted) {
7769
+ if (isHoisted) {
7770
+ const variable = this.parent.addDeclaration(identifier, context, init, isHoisted);
7771
+ // Necessary to make sure the init is deoptimized for conditional declarations.
7772
+ // We cannot call deoptimizePath here.
7773
+ variable.markInitializersForDeoptimization();
7774
+ return variable;
7775
+ }
7776
+ else {
7777
+ return super.addDeclaration(identifier, context, init, false);
7778
+ }
7779
+ }
7780
+ }
7781
+
7782
+ class ExpressionStatement extends NodeBase {
7783
+ initialise() {
7784
+ if (this.directive &&
7785
+ this.directive !== 'use strict' &&
7786
+ this.parent.type === Program$1) {
7787
+ this.context.warn(
7788
+ // This is necessary, because either way (deleting or not) can lead to errors.
7789
+ {
7790
+ code: 'MODULE_LEVEL_DIRECTIVE',
7791
+ message: `Module level directives cause errors when bundled, '${this.directive}' was ignored.`
7792
+ }, this.start);
7793
+ }
7794
+ }
7795
+ render(code, options) {
7796
+ super.render(code, options);
7797
+ if (this.included)
7798
+ this.insertSemicolon(code);
7799
+ }
7800
+ shouldBeIncluded(context) {
7801
+ if (this.directive && this.directive !== 'use strict')
7802
+ return this.parent.type !== Program$1;
7803
+ return super.shouldBeIncluded(context);
7804
+ }
7805
+ }
7806
+
7807
+ class BlockStatement extends NodeBase {
7975
7808
  constructor() {
7976
7809
  super(...arguments);
7977
- // Ensure we use live-bindings for globals as we do not know if they have
7978
- // been reassigned
7979
- this.isReassigned = true;
7810
+ this.directlyIncluded = false;
7811
+ }
7812
+ addImplicitReturnExpressionToScope() {
7813
+ const lastStatement = this.body[this.body.length - 1];
7814
+ if (!lastStatement || lastStatement.type !== ReturnStatement$1) {
7815
+ this.scope.addReturnExpression(UNKNOWN_EXPRESSION);
7816
+ }
7980
7817
  }
7981
- getLiteralValueAtPath(path, _recursionTracker, _origin) {
7982
- return getGlobalAtPath([this.name, ...path]) ? UnknownTruthyValue : UnknownValue;
7818
+ createScope(parentScope) {
7819
+ this.scope = this.parent.preventChildBlockScope
7820
+ ? parentScope
7821
+ : new BlockScope(parentScope);
7983
7822
  }
7984
- hasEffectsWhenAccessedAtPath(path) {
7985
- if (path.length === 0) {
7986
- // Technically, "undefined" is a global variable of sorts
7987
- return this.name !== 'undefined' && !getGlobalAtPath([this.name]);
7823
+ hasEffects(context) {
7824
+ if (this.deoptimizeBody)
7825
+ return true;
7826
+ for (const node of this.body) {
7827
+ if (context.brokenFlow)
7828
+ break;
7829
+ if (node.hasEffects(context))
7830
+ return true;
7988
7831
  }
7989
- return !getGlobalAtPath([this.name, ...path].slice(0, -1));
7832
+ return false;
7990
7833
  }
7991
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
7992
- const globalAtPath = getGlobalAtPath([this.name, ...path]);
7993
- return !globalAtPath || globalAtPath.hasEffectsWhenCalled(callOptions, context);
7834
+ include(context, includeChildrenRecursively) {
7835
+ if (!(this.deoptimizeBody && this.directlyIncluded)) {
7836
+ this.included = true;
7837
+ this.directlyIncluded = true;
7838
+ if (this.deoptimizeBody)
7839
+ includeChildrenRecursively = true;
7840
+ for (const node of this.body) {
7841
+ if (includeChildrenRecursively || node.shouldBeIncluded(context))
7842
+ node.include(context, includeChildrenRecursively);
7843
+ }
7844
+ }
7845
+ }
7846
+ initialise() {
7847
+ const firstBodyStatement = this.body[0];
7848
+ this.deoptimizeBody =
7849
+ firstBodyStatement instanceof ExpressionStatement &&
7850
+ firstBodyStatement.directive === 'use asm';
7851
+ }
7852
+ render(code, options) {
7853
+ if (this.body.length) {
7854
+ renderStatementList(this.body, code, this.start + 1, this.end - 1, options);
7855
+ }
7856
+ else {
7857
+ super.render(code, options);
7858
+ }
7994
7859
  }
7995
7860
  }
7996
7861
 
7997
- const tdzVariableKinds = {
7998
- __proto__: null,
7999
- class: true,
8000
- const: true,
8001
- let: true,
8002
- var: true
8003
- };
8004
- class Identifier extends NodeBase {
7862
+ class RestElement extends NodeBase {
8005
7863
  constructor() {
8006
7864
  super(...arguments);
8007
- this.variable = null;
8008
7865
  this.deoptimized = false;
8009
- this.isTDZAccess = null;
7866
+ this.declarationInit = null;
8010
7867
  }
8011
7868
  addExportedVariables(variables, exportNamesByVariable) {
8012
- if (exportNamesByVariable.has(this.variable)) {
8013
- variables.push(this.variable);
8014
- }
7869
+ this.argument.addExportedVariables(variables, exportNamesByVariable);
8015
7870
  }
8016
- bind() {
8017
- if (!this.variable && is_reference(this, this.parent)) {
8018
- this.variable = this.scope.findVariable(this.name);
8019
- this.variable.addReference(this);
7871
+ declare(kind, init) {
7872
+ this.declarationInit = init;
7873
+ return this.argument.declare(kind, UNKNOWN_EXPRESSION);
7874
+ }
7875
+ deoptimizePath(path) {
7876
+ path.length === 0 && this.argument.deoptimizePath(EMPTY_PATH);
7877
+ }
7878
+ hasEffectsWhenAssignedAtPath(path, context) {
7879
+ return path.length > 0 || this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
7880
+ }
7881
+ markDeclarationReached() {
7882
+ this.argument.markDeclarationReached();
7883
+ }
7884
+ applyDeoptimizations() {
7885
+ this.deoptimized = true;
7886
+ if (this.declarationInit !== null) {
7887
+ this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
7888
+ this.context.requestTreeshakingPass();
8020
7889
  }
8021
7890
  }
8022
- declare(kind, init) {
8023
- let variable;
8024
- const { treeshake } = this.context.options;
8025
- switch (kind) {
8026
- case 'var':
8027
- variable = this.scope.addDeclaration(this, this.context, init, true);
8028
- if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
8029
- // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
8030
- variable.markInitializersForDeoptimization();
8031
- }
8032
- break;
8033
- case 'function':
8034
- // in strict mode, functions are only hoisted within a scope but not across block scopes
8035
- variable = this.scope.addDeclaration(this, this.context, init, false);
8036
- break;
8037
- case 'let':
8038
- case 'const':
8039
- case 'class':
8040
- variable = this.scope.addDeclaration(this, this.context, init, false);
8041
- break;
8042
- case 'parameter':
8043
- variable = this.scope.addParameterDeclaration(this);
8044
- break;
8045
- /* istanbul ignore next */
8046
- default:
8047
- /* istanbul ignore next */
8048
- throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
8049
- }
8050
- variable.kind = kind;
8051
- return [(this.variable = variable)];
7891
+ }
7892
+
7893
+ class FunctionBase extends NodeBase {
7894
+ constructor() {
7895
+ super(...arguments);
7896
+ this.objectEntity = null;
7897
+ this.deoptimizedReturn = false;
8052
7898
  }
8053
7899
  deoptimizePath(path) {
8054
- if (path.length === 0 && !this.scope.contains(this.name)) {
8055
- this.disallowImportReassignment();
7900
+ this.getObjectEntity().deoptimizePath(path);
7901
+ if (path.length === 1 && path[0] === UnknownKey) {
7902
+ // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
7903
+ // which means the return expression needs to be reassigned
7904
+ this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
8056
7905
  }
8057
- this.variable.deoptimizePath(path);
8058
7906
  }
8059
7907
  deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
8060
- this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
7908
+ if (path.length > 0) {
7909
+ this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
7910
+ }
8061
7911
  }
8062
7912
  getLiteralValueAtPath(path, recursionTracker, origin) {
8063
- return this.getVariableRespectingTDZ().getLiteralValueAtPath(path, recursionTracker, origin);
7913
+ return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
8064
7914
  }
8065
7915
  getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
8066
- return this.getVariableRespectingTDZ().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
8067
- }
8068
- hasEffects() {
8069
- if (!this.deoptimized)
8070
- this.applyDeoptimizations();
8071
- if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
8072
- return true;
7916
+ if (path.length > 0) {
7917
+ return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
8073
7918
  }
8074
- return (this.context.options.treeshake.unknownGlobalSideEffects &&
8075
- this.variable instanceof GlobalVariable &&
8076
- this.variable.hasEffectsWhenAccessedAtPath(EMPTY_PATH));
7919
+ if (this.async) {
7920
+ if (!this.deoptimizedReturn) {
7921
+ this.deoptimizedReturn = true;
7922
+ this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
7923
+ this.context.requestTreeshakingPass();
7924
+ }
7925
+ return UNKNOWN_EXPRESSION;
7926
+ }
7927
+ return this.scope.getReturnExpression();
8077
7928
  }
8078
7929
  hasEffectsWhenAccessedAtPath(path, context) {
8079
- var _a;
8080
- return (_a = this.getVariableRespectingTDZ()) === null || _a === void 0 ? void 0 : _a.hasEffectsWhenAccessedAtPath(path, context);
7930
+ return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
8081
7931
  }
8082
7932
  hasEffectsWhenAssignedAtPath(path, context) {
8083
- return (path.length > 0 ? this.getVariableRespectingTDZ() : this.variable).hasEffectsWhenAssignedAtPath(path, context);
7933
+ return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
8084
7934
  }
8085
7935
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
8086
- return this.getVariableRespectingTDZ().hasEffectsWhenCalledAtPath(path, callOptions, context);
8087
- }
8088
- include() {
8089
- if (!this.deoptimized)
8090
- this.applyDeoptimizations();
8091
- if (!this.included) {
8092
- this.included = true;
8093
- if (this.variable !== null) {
8094
- this.context.includeVariableInModule(this.variable);
7936
+ if (path.length > 0) {
7937
+ return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
7938
+ }
7939
+ if (this.async) {
7940
+ const { propertyReadSideEffects } = this.context.options
7941
+ .treeshake;
7942
+ const returnExpression = this.scope.getReturnExpression();
7943
+ if (returnExpression.hasEffectsWhenCalledAtPath(['then'], { args: NO_ARGS, thisParam: null, withNew: false }, context) ||
7944
+ (propertyReadSideEffects &&
7945
+ (propertyReadSideEffects === 'always' ||
7946
+ returnExpression.hasEffectsWhenAccessedAtPath(['then'], context)))) {
7947
+ return true;
8095
7948
  }
8096
7949
  }
7950
+ for (const param of this.params) {
7951
+ if (param.hasEffects(context))
7952
+ return true;
7953
+ }
7954
+ return false;
8097
7955
  }
8098
- includeArgumentsWhenCalledAtPath(path, context, args) {
8099
- this.variable.includeArgumentsWhenCalledAtPath(path, context, args);
7956
+ include(context, includeChildrenRecursively) {
7957
+ this.included = true;
7958
+ const { brokenFlow } = context;
7959
+ context.brokenFlow = BROKEN_FLOW_NONE;
7960
+ this.body.include(context, includeChildrenRecursively);
7961
+ context.brokenFlow = brokenFlow;
8100
7962
  }
8101
- isPossibleTDZ() {
8102
- // return cached value to avoid issues with the next tree-shaking pass
8103
- if (this.isTDZAccess !== null)
8104
- return this.isTDZAccess;
8105
- if (!(this.variable instanceof LocalVariable) ||
8106
- !this.variable.kind ||
8107
- !(this.variable.kind in tdzVariableKinds)) {
8108
- return (this.isTDZAccess = false);
7963
+ includeCallArguments(context, args) {
7964
+ this.scope.includeCallArguments(context, args);
7965
+ }
7966
+ initialise() {
7967
+ this.scope.addParameterVariables(this.params.map(param => param.declare('parameter', UNKNOWN_EXPRESSION)), this.params[this.params.length - 1] instanceof RestElement);
7968
+ if (this.body instanceof BlockStatement) {
7969
+ this.body.addImplicitReturnExpressionToScope();
8109
7970
  }
8110
- let decl_id;
8111
- if (this.variable.declarations &&
8112
- this.variable.declarations.length === 1 &&
8113
- (decl_id = this.variable.declarations[0]) &&
8114
- this.start < decl_id.start &&
8115
- closestParentFunctionOrProgram(this) === closestParentFunctionOrProgram(decl_id)) {
8116
- // a variable accessed before its declaration
8117
- // in the same function or at top level of module
8118
- return (this.isTDZAccess = true);
7971
+ else {
7972
+ this.scope.addReturnExpression(this.body);
8119
7973
  }
8120
- if (!this.variable.initReached) {
8121
- // Either a const/let TDZ violation or
8122
- // var use before declaration was encountered.
8123
- return (this.isTDZAccess = true);
7974
+ }
7975
+ parseNode(esTreeNode) {
7976
+ if (esTreeNode.body.type === BlockStatement$1) {
7977
+ this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
8124
7978
  }
8125
- return (this.isTDZAccess = false);
7979
+ super.parseNode(esTreeNode);
8126
7980
  }
8127
- markDeclarationReached() {
8128
- this.variable.initReached = true;
7981
+ }
7982
+ FunctionBase.prototype.preventChildBlockScope = true;
7983
+
7984
+ class ArrowFunctionExpression extends FunctionBase {
7985
+ constructor() {
7986
+ super(...arguments);
7987
+ this.objectEntity = null;
8129
7988
  }
8130
- render(code, { snippets: { getPropertyAccess } }, { renderedParentType, isCalleeOfRenderedParent, isShorthandProperty } = BLANK) {
8131
- if (this.variable) {
8132
- const name = this.variable.getName(getPropertyAccess);
8133
- if (name !== this.name) {
8134
- code.overwrite(this.start, this.end, name, {
8135
- contentOnly: true,
8136
- storeName: true
8137
- });
8138
- if (isShorthandProperty) {
8139
- code.prependRight(this.start, `${this.name}: `);
8140
- }
8141
- }
8142
- // In strict mode, any variable named "eval" must be the actual "eval" function
8143
- if (name === 'eval' &&
8144
- renderedParentType === CallExpression$1 &&
8145
- isCalleeOfRenderedParent) {
8146
- code.appendRight(this.start, '0, ');
7989
+ createScope(parentScope) {
7990
+ this.scope = new ReturnValueScope(parentScope, this.context);
7991
+ }
7992
+ hasEffects() {
7993
+ return false;
7994
+ }
7995
+ hasEffectsWhenCalledAtPath(path, callOptions, context) {
7996
+ if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
7997
+ return true;
7998
+ const { ignore, brokenFlow } = context;
7999
+ context.ignore = {
8000
+ breaks: false,
8001
+ continues: false,
8002
+ labels: new Set(),
8003
+ returnYield: true
8004
+ };
8005
+ if (this.body.hasEffects(context))
8006
+ return true;
8007
+ context.ignore = ignore;
8008
+ context.brokenFlow = brokenFlow;
8009
+ return false;
8010
+ }
8011
+ include(context, includeChildrenRecursively) {
8012
+ super.include(context, includeChildrenRecursively);
8013
+ for (const param of this.params) {
8014
+ if (!(param instanceof Identifier)) {
8015
+ param.include(context, includeChildrenRecursively);
8147
8016
  }
8148
8017
  }
8149
8018
  }
8150
- applyDeoptimizations() {
8151
- this.deoptimized = true;
8152
- if (this.variable instanceof LocalVariable) {
8153
- this.variable.consolidateInitializers();
8154
- this.context.requestTreeshakingPass();
8019
+ getObjectEntity() {
8020
+ if (this.objectEntity !== null) {
8021
+ return this.objectEntity;
8155
8022
  }
8023
+ return (this.objectEntity = new ObjectEntity([], OBJECT_PROTOTYPE));
8156
8024
  }
8157
- disallowImportReassignment() {
8158
- return this.context.error({
8159
- code: 'ILLEGAL_REASSIGNMENT',
8160
- message: `Illegal reassignment to import '${this.name}'`
8161
- }, this.start);
8025
+ }
8026
+
8027
+ function getSystemExportStatement(exportedVariables, { exportNamesByVariable, snippets: { _, getObject, getPropertyAccess } }, modifier = '') {
8028
+ if (exportedVariables.length === 1 &&
8029
+ exportNamesByVariable.get(exportedVariables[0]).length === 1) {
8030
+ const variable = exportedVariables[0];
8031
+ return `exports('${exportNamesByVariable.get(variable)}',${_}${variable.getName(getPropertyAccess)}${modifier})`;
8162
8032
  }
8163
- getVariableRespectingTDZ() {
8164
- if (this.isPossibleTDZ()) {
8165
- return UNKNOWN_EXPRESSION;
8033
+ else {
8034
+ const fields = [];
8035
+ for (const variable of exportedVariables) {
8036
+ for (const exportName of exportNamesByVariable.get(variable)) {
8037
+ fields.push([exportName, variable.getName(getPropertyAccess) + modifier]);
8038
+ }
8166
8039
  }
8167
- return this.variable;
8040
+ return `exports(${getObject(fields, { lineBreakIndent: null })})`;
8168
8041
  }
8169
8042
  }
8170
- function closestParentFunctionOrProgram(node) {
8171
- while (node && !/^Program|Function/.test(node.type)) {
8172
- node = node.parent;
8043
+ function renderSystemExportExpression(exportedVariable, expressionStart, expressionEnd, code, { exportNamesByVariable, snippets: { _ } }) {
8044
+ code.prependRight(expressionStart, `exports('${exportNamesByVariable.get(exportedVariable)}',${_}`);
8045
+ code.appendLeft(expressionEnd, ')');
8046
+ }
8047
+ function renderSystemExportFunction(exportedVariables, expressionStart, expressionEnd, needsParens, code, options) {
8048
+ const { _, getDirectReturnIifeLeft } = options.snippets;
8049
+ code.prependRight(expressionStart, getDirectReturnIifeLeft(['v'], `${getSystemExportStatement(exportedVariables, options)},${_}v`, { needsArrowReturnParens: true, needsWrappedFunction: needsParens }));
8050
+ code.appendLeft(expressionEnd, ')');
8051
+ }
8052
+ function renderSystemExportSequenceAfterExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options) {
8053
+ const { _, getPropertyAccess } = options.snippets;
8054
+ code.appendLeft(expressionEnd, `,${_}${getSystemExportStatement([exportedVariable], options)},${_}${exportedVariable.getName(getPropertyAccess)}`);
8055
+ if (needsParens) {
8056
+ code.prependRight(expressionStart, '(');
8057
+ code.appendLeft(expressionEnd, ')');
8058
+ }
8059
+ }
8060
+ function renderSystemExportSequenceBeforeExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options, modifier) {
8061
+ const { _ } = options.snippets;
8062
+ code.prependRight(expressionStart, `${getSystemExportStatement([exportedVariable], options, modifier)},${_}`);
8063
+ if (needsParens) {
8064
+ code.prependRight(expressionStart, '(');
8065
+ code.appendLeft(expressionEnd, ')');
8173
8066
  }
8174
- // one of: ArrowFunctionExpression, FunctionDeclaration, FunctionExpression or Program
8175
- return node;
8176
8067
  }
8177
8068
 
8178
8069
  class ObjectPattern extends NodeBase {
@@ -8301,6 +8192,38 @@ class AssignmentExpression extends NodeBase {
8301
8192
  }
8302
8193
  }
8303
8194
 
8195
+ class AssignmentPattern extends NodeBase {
8196
+ constructor() {
8197
+ super(...arguments);
8198
+ this.deoptimized = false;
8199
+ }
8200
+ addExportedVariables(variables, exportNamesByVariable) {
8201
+ this.left.addExportedVariables(variables, exportNamesByVariable);
8202
+ }
8203
+ declare(kind, init) {
8204
+ return this.left.declare(kind, init);
8205
+ }
8206
+ deoptimizePath(path) {
8207
+ path.length === 0 && this.left.deoptimizePath(path);
8208
+ }
8209
+ hasEffectsWhenAssignedAtPath(path, context) {
8210
+ return path.length > 0 || this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
8211
+ }
8212
+ markDeclarationReached() {
8213
+ this.left.markDeclarationReached();
8214
+ }
8215
+ render(code, options, { isShorthandProperty } = BLANK) {
8216
+ this.left.render(code, options, { isShorthandProperty });
8217
+ this.right.render(code, options);
8218
+ }
8219
+ applyDeoptimizations() {
8220
+ this.deoptimized = true;
8221
+ this.left.deoptimizePath(EMPTY_PATH);
8222
+ this.right.deoptimizePath(UNKNOWN_PATH);
8223
+ this.context.requestTreeshakingPass();
8224
+ }
8225
+ }
8226
+
8304
8227
  class ArgumentsVariable extends LocalVariable {
8305
8228
  constructor(context) {
8306
8229
  super('arguments', null, UNKNOWN_EXPRESSION, context);
@@ -8408,8 +8331,7 @@ class FunctionNode extends FunctionBase {
8408
8331
  }
8409
8332
  }
8410
8333
  hasEffects() {
8411
- var _a;
8412
- return (_a = this.id) === null || _a === void 0 ? void 0 : _a.hasEffects();
8334
+ return this.id !== null && this.id.hasEffects();
8413
8335
  }
8414
8336
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
8415
8337
  if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
@@ -8438,13 +8360,15 @@ class FunctionNode extends FunctionBase {
8438
8360
  return false;
8439
8361
  }
8440
8362
  include(context, includeChildrenRecursively) {
8441
- var _a;
8442
- // This ensures that super.include will also include all parameters
8443
- if (this.scope.argumentsVariable.included) {
8444
- this.alwaysIncludeParameters = true;
8445
- }
8446
- (_a = this.id) === null || _a === void 0 ? void 0 : _a.include();
8447
8363
  super.include(context, includeChildrenRecursively);
8364
+ if (this.id)
8365
+ this.id.include();
8366
+ const hasArguments = this.scope.argumentsVariable.included;
8367
+ for (const param of this.params) {
8368
+ if (!(param instanceof Identifier) || hasArguments) {
8369
+ param.include(context, includeChildrenRecursively);
8370
+ }
8371
+ }
8448
8372
  }
8449
8373
  initialise() {
8450
8374
  var _a;
@@ -8491,6 +8415,11 @@ class AwaitExpression extends NodeBase {
8491
8415
  }
8492
8416
  this.argument.include(context, includeChildrenRecursively);
8493
8417
  }
8418
+ applyDeoptimizations() {
8419
+ this.deoptimized = true;
8420
+ this.argument.deoptimizePath(UNKNOWN_PATH);
8421
+ this.context.requestTreeshakingPass();
8422
+ }
8494
8423
  }
8495
8424
 
8496
8425
  const binaryOperators = {
@@ -8524,10 +8453,10 @@ class BinaryExpression extends NodeBase {
8524
8453
  if (path.length > 0)
8525
8454
  return UnknownValue;
8526
8455
  const leftValue = this.left.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
8527
- if (typeof leftValue === 'symbol')
8456
+ if (leftValue === UnknownValue)
8528
8457
  return UnknownValue;
8529
8458
  const rightValue = this.right.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
8530
- if (typeof rightValue === 'symbol')
8459
+ if (rightValue === UnknownValue)
8531
8460
  return UnknownValue;
8532
8461
  const operatorFn = binaryOperators[this.operator];
8533
8462
  if (!operatorFn)
@@ -8818,15 +8747,12 @@ class MemberExpression extends NodeBase {
8818
8747
  this.object.include(context, includeChildrenRecursively);
8819
8748
  this.property.include(context, includeChildrenRecursively);
8820
8749
  }
8821
- includeArgumentsWhenCalledAtPath(path, context, args) {
8750
+ includeCallArguments(context, args) {
8822
8751
  if (this.variable) {
8823
- this.variable.includeArgumentsWhenCalledAtPath(path, context, args);
8752
+ this.variable.includeCallArguments(context, args);
8824
8753
  }
8825
- else if (this.replacement) {
8826
- super.includeArgumentsWhenCalledAtPath(path, context, args);
8827
- }
8828
- else if (path.length < MAX_PATH_DEPTH) {
8829
- this.object.includeArgumentsWhenCalledAtPath([this.getPropertyKey(), ...path], context, args);
8754
+ else {
8755
+ super.includeCallArguments(context, args);
8830
8756
  }
8831
8757
  }
8832
8758
  initialise() {
@@ -8888,7 +8814,7 @@ class MemberExpression extends NodeBase {
8888
8814
  if (this.propertyKey === null) {
8889
8815
  this.propertyKey = UnknownKey;
8890
8816
  const value = this.property.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
8891
- return (this.propertyKey = typeof value === 'symbol' ? UnknownKey : String(value));
8817
+ return (this.propertyKey = value === UnknownValue ? UnknownKey : String(value));
8892
8818
  }
8893
8819
  return this.propertyKey;
8894
8820
  }
@@ -8915,13 +8841,39 @@ class MemberExpression extends NodeBase {
8915
8841
  }
8916
8842
  }
8917
8843
 
8918
- class CallExpressionBase extends NodeBase {
8844
+ class CallExpression extends NodeBase {
8919
8845
  constructor() {
8920
8846
  super(...arguments);
8921
8847
  this.deoptimized = false;
8922
- this.returnExpression = null;
8923
8848
  this.deoptimizableDependentExpressions = [];
8924
8849
  this.expressionsToBeDeoptimized = new Set();
8850
+ this.returnExpression = null;
8851
+ }
8852
+ bind() {
8853
+ super.bind();
8854
+ if (this.callee instanceof Identifier) {
8855
+ const variable = this.scope.findVariable(this.callee.name);
8856
+ if (variable.isNamespace) {
8857
+ this.context.warn({
8858
+ code: 'CANNOT_CALL_NAMESPACE',
8859
+ message: `Cannot call a namespace ('${this.callee.name}')`
8860
+ }, this.start);
8861
+ }
8862
+ if (this.callee.name === 'eval') {
8863
+ this.context.warn({
8864
+ code: 'EVAL',
8865
+ message: `Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification`,
8866
+ url: 'https://rollupjs.org/guide/en/#avoiding-eval'
8867
+ }, this.start);
8868
+ }
8869
+ }
8870
+ this.callOptions = {
8871
+ args: this.arguments,
8872
+ thisParam: this.callee instanceof MemberExpression && !this.callee.variable
8873
+ ? this.callee.object
8874
+ : null,
8875
+ withNew: false
8876
+ };
8925
8877
  }
8926
8878
  deoptimizeCache() {
8927
8879
  if (this.returnExpression !== UNKNOWN_EXPRESSION) {
@@ -8976,47 +8928,6 @@ class CallExpressionBase extends NodeBase {
8976
8928
  return returnExpression.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
8977
8929
  }, UNKNOWN_EXPRESSION);
8978
8930
  }
8979
- hasEffectsWhenAccessedAtPath(path, context) {
8980
- return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
8981
- this.getReturnExpression().hasEffectsWhenAccessedAtPath(path, context));
8982
- }
8983
- hasEffectsWhenAssignedAtPath(path, context) {
8984
- return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
8985
- this.getReturnExpression().hasEffectsWhenAssignedAtPath(path, context));
8986
- }
8987
- hasEffectsWhenCalledAtPath(path, callOptions, context) {
8988
- return (!(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
8989
- this.getReturnExpression().hasEffectsWhenCalledAtPath(path, callOptions, context));
8990
- }
8991
- }
8992
-
8993
- class CallExpression extends CallExpressionBase {
8994
- bind() {
8995
- super.bind();
8996
- if (this.callee instanceof Identifier) {
8997
- const variable = this.scope.findVariable(this.callee.name);
8998
- if (variable.isNamespace) {
8999
- this.context.warn({
9000
- code: 'CANNOT_CALL_NAMESPACE',
9001
- message: `Cannot call a namespace ('${this.callee.name}')`
9002
- }, this.start);
9003
- }
9004
- if (this.callee.name === 'eval') {
9005
- this.context.warn({
9006
- code: 'EVAL',
9007
- message: `Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification`,
9008
- url: 'https://rollupjs.org/guide/en/#avoiding-eval'
9009
- }, this.start);
9010
- }
9011
- }
9012
- this.callOptions = {
9013
- args: this.arguments,
9014
- thisParam: this.callee instanceof MemberExpression && !this.callee.variable
9015
- ? this.callee.object
9016
- : null,
9017
- withNew: false
9018
- };
9019
- }
9020
8931
  hasEffects(context) {
9021
8932
  try {
9022
8933
  for (const argument of this.arguments) {
@@ -9034,6 +8945,18 @@ class CallExpression extends CallExpressionBase {
9034
8945
  this.applyDeoptimizations();
9035
8946
  }
9036
8947
  }
8948
+ hasEffectsWhenAccessedAtPath(path, context) {
8949
+ return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
8950
+ this.getReturnExpression().hasEffectsWhenAccessedAtPath(path, context));
8951
+ }
8952
+ hasEffectsWhenAssignedAtPath(path, context) {
8953
+ return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
8954
+ this.getReturnExpression().hasEffectsWhenAssignedAtPath(path, context));
8955
+ }
8956
+ hasEffectsWhenCalledAtPath(path, callOptions, context) {
8957
+ return (!(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
8958
+ this.getReturnExpression().hasEffectsWhenCalledAtPath(path, callOptions, context));
8959
+ }
9037
8960
  include(context, includeChildrenRecursively) {
9038
8961
  if (!this.deoptimized)
9039
8962
  this.applyDeoptimizations();
@@ -9049,7 +8972,7 @@ class CallExpression extends CallExpressionBase {
9049
8972
  this.included = true;
9050
8973
  this.callee.include(context, false);
9051
8974
  }
9052
- this.callee.includeArgumentsWhenCalledAtPath(EMPTY_PATH, context, this.arguments);
8975
+ this.callee.includeCallArguments(context, this.arguments);
9053
8976
  const returnExpression = this.getReturnExpression();
9054
8977
  if (!returnExpression.included) {
9055
8978
  returnExpression.include(context, false);
@@ -9220,9 +9143,6 @@ class MethodBase extends NodeBase {
9220
9143
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
9221
9144
  return this.getAccessedValue().hasEffectsWhenCalledAtPath(path, callOptions, context);
9222
9145
  }
9223
- includeArgumentsWhenCalledAtPath(path, context, args) {
9224
- this.getAccessedValue().includeArgumentsWhenCalledAtPath(path, context, args);
9225
- }
9226
9146
  getAccessedValue() {
9227
9147
  if (this.accessedValue === null) {
9228
9148
  if (this.kind === 'get') {
@@ -9259,6 +9179,8 @@ class ObjectMember extends ExpressionEntity {
9259
9179
  return this.object.getReturnExpressionWhenCalledAtPath([this.key, ...path], callOptions, recursionTracker, origin);
9260
9180
  }
9261
9181
  hasEffectsWhenAccessedAtPath(path, context) {
9182
+ if (path.length === 0)
9183
+ return false;
9262
9184
  return this.object.hasEffectsWhenAccessedAtPath([this.key, ...path], context);
9263
9185
  }
9264
9186
  hasEffectsWhenAssignedAtPath(path, context) {
@@ -9272,7 +9194,6 @@ class ObjectMember extends ExpressionEntity {
9272
9194
  class ClassNode extends NodeBase {
9273
9195
  constructor() {
9274
9196
  super(...arguments);
9275
- this.deoptimized = false;
9276
9197
  this.objectEntity = null;
9277
9198
  }
9278
9199
  createScope(parentScope) {
@@ -9282,14 +9203,7 @@ class ClassNode extends NodeBase {
9282
9203
  this.getObjectEntity().deoptimizeAllProperties();
9283
9204
  }
9284
9205
  deoptimizePath(path) {
9285
- var _a, _b;
9286
9206
  this.getObjectEntity().deoptimizePath(path);
9287
- if (path.length === 1 && path[0] === UnknownKey) {
9288
- // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
9289
- // which means the constructor needs to be reassigned
9290
- (_a = this.classConstructor) === null || _a === void 0 ? void 0 : _a.deoptimizePath(UNKNOWN_PATH);
9291
- (_b = this.superClass) === null || _b === void 0 ? void 0 : _b.deoptimizePath(UNKNOWN_PATH);
9292
- }
9293
9207
  }
9294
9208
  deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
9295
9209
  this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
@@ -9302,8 +9216,6 @@ class ClassNode extends NodeBase {
9302
9216
  }
9303
9217
  hasEffects(context) {
9304
9218
  var _a, _b;
9305
- if (!this.deoptimized)
9306
- this.applyDeoptimizations();
9307
9219
  const initEffect = ((_a = this.superClass) === null || _a === void 0 ? void 0 : _a.hasEffects(context)) || this.body.hasEffects(context);
9308
9220
  (_b = this.id) === null || _b === void 0 ? void 0 : _b.markDeclarationReached();
9309
9221
  return initEffect || super.hasEffects(context);
@@ -9315,13 +9227,12 @@ class ClassNode extends NodeBase {
9315
9227
  return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
9316
9228
  }
9317
9229
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
9318
- var _a;
9319
9230
  if (path.length === 0) {
9320
9231
  return (!callOptions.withNew ||
9321
9232
  (this.classConstructor !== null
9322
9233
  ? this.classConstructor.hasEffectsWhenCalledAtPath(EMPTY_PATH, callOptions, context)
9323
- : (_a = this.superClass) === null || _a === void 0 ? void 0 : _a.hasEffectsWhenCalledAtPath(path, callOptions, context)) ||
9324
- false);
9234
+ : this.superClass !== null &&
9235
+ this.superClass.hasEffectsWhenCalledAtPath(path, callOptions, context)));
9325
9236
  }
9326
9237
  else {
9327
9238
  return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
@@ -9329,8 +9240,6 @@ class ClassNode extends NodeBase {
9329
9240
  }
9330
9241
  include(context, includeChildrenRecursively) {
9331
9242
  var _a;
9332
- if (!this.deoptimized)
9333
- this.applyDeoptimizations();
9334
9243
  this.included = true;
9335
9244
  (_a = this.superClass) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
9336
9245
  this.body.include(context, includeChildrenRecursively);
@@ -9339,20 +9248,6 @@ class ClassNode extends NodeBase {
9339
9248
  this.id.include();
9340
9249
  }
9341
9250
  }
9342
- includeArgumentsWhenCalledAtPath(path, context, args) {
9343
- var _a;
9344
- if (path.length === 0) {
9345
- if (this.classConstructor) {
9346
- this.classConstructor.includeArgumentsWhenCalledAtPath(path, context, args);
9347
- }
9348
- else {
9349
- (_a = this.superClass) === null || _a === void 0 ? void 0 : _a.includeArgumentsWhenCalledAtPath(path, context, args);
9350
- }
9351
- }
9352
- else {
9353
- this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
9354
- }
9355
- }
9356
9251
  initialise() {
9357
9252
  var _a;
9358
9253
  (_a = this.id) === null || _a === void 0 ? void 0 : _a.declare('class', this);
@@ -9364,18 +9259,6 @@ class ClassNode extends NodeBase {
9364
9259
  }
9365
9260
  this.classConstructor = null;
9366
9261
  }
9367
- applyDeoptimizations() {
9368
- this.deoptimized = true;
9369
- for (const definition of this.body.body) {
9370
- if (!(definition.static ||
9371
- (definition instanceof MethodDefinition && definition.kind === 'constructor'))) {
9372
- // Calls to methods are not tracked, ensure that parameter defaults are
9373
- // included and the return value is deoptimized
9374
- definition.deoptimizePath(UNKNOWN_PATH);
9375
- }
9376
- }
9377
- this.context.requestTreeshakingPass();
9378
- }
9379
9262
  getObjectEntity() {
9380
9263
  if (this.objectEntity !== null) {
9381
9264
  return this.objectEntity;
@@ -9392,7 +9275,7 @@ class ClassNode extends NodeBase {
9392
9275
  let key;
9393
9276
  if (definition.computed) {
9394
9277
  const keyValue = definition.key.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
9395
- if (typeof keyValue === 'symbol') {
9278
+ if (keyValue === UnknownValue) {
9396
9279
  properties.push({ key: UnknownKey, kind, property: definition });
9397
9280
  continue;
9398
9281
  }
@@ -9588,14 +9471,14 @@ class ConditionalExpression extends NodeBase {
9588
9471
  usedBranch.include(context, includeChildrenRecursively);
9589
9472
  }
9590
9473
  }
9591
- includeArgumentsWhenCalledAtPath(path, context, args) {
9474
+ includeCallArguments(context, args) {
9592
9475
  const usedBranch = this.getUsedBranch();
9593
9476
  if (usedBranch === null) {
9594
- this.consequent.includeArgumentsWhenCalledAtPath(path, context, args);
9595
- this.alternate.includeArgumentsWhenCalledAtPath(path, context, args);
9477
+ this.consequent.includeCallArguments(context, args);
9478
+ this.alternate.includeCallArguments(context, args);
9596
9479
  }
9597
9480
  else {
9598
- usedBranch.includeArgumentsWhenCalledAtPath(path, context, args);
9481
+ usedBranch.includeCallArguments(context, args);
9599
9482
  }
9600
9483
  }
9601
9484
  render(code, options, { isCalleeOfRenderedParent, preventASI, renderedParentType, renderedSurroundingElement } = BLANK) {
@@ -9632,7 +9515,7 @@ class ConditionalExpression extends NodeBase {
9632
9515
  }
9633
9516
  this.isBranchResolutionAnalysed = true;
9634
9517
  const testValue = this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
9635
- return typeof testValue === 'symbol'
9518
+ return testValue === UnknownValue
9636
9519
  ? null
9637
9520
  : (this.usedBranch = testValue ? this.consequent : this.alternate);
9638
9521
  }
@@ -9681,7 +9564,7 @@ class DoWhileStatement extends NodeBase {
9681
9564
  this.included = true;
9682
9565
  this.test.include(context, includeChildrenRecursively);
9683
9566
  const { brokenFlow } = context;
9684
- this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9567
+ this.body.includeAsSingleStatement(context, includeChildrenRecursively);
9685
9568
  context.brokenFlow = brokenFlow;
9686
9569
  }
9687
9570
  }
@@ -9809,13 +9692,12 @@ ExportDefaultDeclaration.prototype.needsBoundaries = true;
9809
9692
 
9810
9693
  class ExportNamedDeclaration extends NodeBase {
9811
9694
  bind() {
9812
- var _a;
9813
9695
  // Do not bind specifiers
9814
- (_a = this.declaration) === null || _a === void 0 ? void 0 : _a.bind();
9696
+ if (this.declaration !== null)
9697
+ this.declaration.bind();
9815
9698
  }
9816
9699
  hasEffects(context) {
9817
- var _a;
9818
- return (_a = this.declaration) === null || _a === void 0 ? void 0 : _a.hasEffects(context);
9700
+ return this.declaration !== null && this.declaration.hasEffects(context);
9819
9701
  }
9820
9702
  initialise() {
9821
9703
  this.context.addExport(this);
@@ -9869,7 +9751,7 @@ class ForInStatement extends NodeBase {
9869
9751
  this.left.include(context, includeChildrenRecursively || true);
9870
9752
  this.right.include(context, includeChildrenRecursively);
9871
9753
  const { brokenFlow } = context;
9872
- this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9754
+ this.body.includeAsSingleStatement(context, includeChildrenRecursively);
9873
9755
  context.brokenFlow = brokenFlow;
9874
9756
  }
9875
9757
  render(code, options) {
@@ -9909,7 +9791,7 @@ class ForOfStatement extends NodeBase {
9909
9791
  this.left.include(context, includeChildrenRecursively || true);
9910
9792
  this.right.include(context, includeChildrenRecursively);
9911
9793
  const { brokenFlow } = context;
9912
- this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9794
+ this.body.includeAsSingleStatement(context, includeChildrenRecursively);
9913
9795
  context.brokenFlow = brokenFlow;
9914
9796
  }
9915
9797
  render(code, options) {
@@ -9933,10 +9815,9 @@ class ForStatement extends NodeBase {
9933
9815
  this.scope = new BlockScope(parentScope);
9934
9816
  }
9935
9817
  hasEffects(context) {
9936
- var _a, _b, _c;
9937
- if (((_a = this.init) === null || _a === void 0 ? void 0 : _a.hasEffects(context)) ||
9938
- ((_b = this.test) === null || _b === void 0 ? void 0 : _b.hasEffects(context)) ||
9939
- ((_c = this.update) === null || _c === void 0 ? void 0 : _c.hasEffects(context)))
9818
+ if ((this.init && this.init.hasEffects(context)) ||
9819
+ (this.test && this.test.hasEffects(context)) ||
9820
+ (this.update && this.update.hasEffects(context)))
9940
9821
  return true;
9941
9822
  const { brokenFlow, ignore: { breaks, continues } } = context;
9942
9823
  context.ignore.breaks = true;
@@ -9949,20 +9830,24 @@ class ForStatement extends NodeBase {
9949
9830
  return false;
9950
9831
  }
9951
9832
  include(context, includeChildrenRecursively) {
9952
- var _a, _b, _c;
9953
9833
  this.included = true;
9954
- (_a = this.init) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively, { asSingleStatement: true });
9955
- (_b = this.test) === null || _b === void 0 ? void 0 : _b.include(context, includeChildrenRecursively);
9834
+ if (this.init)
9835
+ this.init.includeAsSingleStatement(context, includeChildrenRecursively);
9836
+ if (this.test)
9837
+ this.test.include(context, includeChildrenRecursively);
9956
9838
  const { brokenFlow } = context;
9957
- (_c = this.update) === null || _c === void 0 ? void 0 : _c.include(context, includeChildrenRecursively);
9958
- this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
9839
+ if (this.update)
9840
+ this.update.include(context, includeChildrenRecursively);
9841
+ this.body.includeAsSingleStatement(context, includeChildrenRecursively);
9959
9842
  context.brokenFlow = brokenFlow;
9960
9843
  }
9961
9844
  render(code, options) {
9962
- var _a, _b, _c;
9963
- (_a = this.init) === null || _a === void 0 ? void 0 : _a.render(code, options, NO_SEMICOLON);
9964
- (_b = this.test) === null || _b === void 0 ? void 0 : _b.render(code, options, NO_SEMICOLON);
9965
- (_c = this.update) === null || _c === void 0 ? void 0 : _c.render(code, options, NO_SEMICOLON);
9845
+ if (this.init)
9846
+ this.init.render(code, options, NO_SEMICOLON);
9847
+ if (this.test)
9848
+ this.test.render(code, options, NO_SEMICOLON);
9849
+ if (this.update)
9850
+ this.update.render(code, options, NO_SEMICOLON);
9966
9851
  this.body.render(code, options);
9967
9852
  }
9968
9853
  }
@@ -9998,12 +9883,11 @@ class IfStatement extends NodeBase {
9998
9883
  this.testValue = UnknownValue;
9999
9884
  }
10000
9885
  hasEffects(context) {
10001
- var _a;
10002
9886
  if (this.test.hasEffects(context)) {
10003
9887
  return true;
10004
9888
  }
10005
9889
  const testValue = this.getTestValue();
10006
- if (typeof testValue === 'symbol') {
9890
+ if (testValue === UnknownValue) {
10007
9891
  const { brokenFlow } = context;
10008
9892
  if (this.consequent.hasEffects(context))
10009
9893
  return true;
@@ -10017,7 +9901,9 @@ class IfStatement extends NodeBase {
10017
9901
  context.brokenFlow < consequentBrokenFlow ? context.brokenFlow : consequentBrokenFlow;
10018
9902
  return false;
10019
9903
  }
10020
- return testValue ? this.consequent.hasEffects(context) : (_a = this.alternate) === null || _a === void 0 ? void 0 : _a.hasEffects(context);
9904
+ return testValue
9905
+ ? this.consequent.hasEffects(context)
9906
+ : this.alternate !== null && this.alternate.hasEffects(context);
10021
9907
  }
10022
9908
  include(context, includeChildrenRecursively) {
10023
9909
  this.included = true;
@@ -10026,7 +9912,7 @@ class IfStatement extends NodeBase {
10026
9912
  }
10027
9913
  else {
10028
9914
  const testValue = this.getTestValue();
10029
- if (typeof testValue === 'symbol') {
9915
+ if (testValue === UnknownValue) {
10030
9916
  this.includeUnknownTest(context);
10031
9917
  }
10032
9918
  else {
@@ -10056,7 +9942,7 @@ class IfStatement extends NodeBase {
10056
9942
  else {
10057
9943
  code.remove(this.start, this.consequent.start);
10058
9944
  }
10059
- if (this.consequent.included && (noTreeshake || typeof testValue === 'symbol' || testValue)) {
9945
+ if (this.consequent.included && (noTreeshake || testValue === UnknownValue || testValue)) {
10060
9946
  this.consequent.render(code, options);
10061
9947
  }
10062
9948
  else {
@@ -10064,7 +9950,7 @@ class IfStatement extends NodeBase {
10064
9950
  hoistedDeclarations.push(...this.consequentScope.hoistedDeclarations);
10065
9951
  }
10066
9952
  if (this.alternate) {
10067
- if (this.alternate.included && (noTreeshake || typeof testValue === 'symbol' || !testValue)) {
9953
+ if (this.alternate.included && (noTreeshake || testValue === UnknownValue || !testValue)) {
10068
9954
  if (includesIfElse) {
10069
9955
  if (code.original.charCodeAt(this.alternate.start - 1) === 101) {
10070
9956
  code.prependLeft(this.alternate.start, ' ');
@@ -10094,35 +9980,34 @@ class IfStatement extends NodeBase {
10094
9980
  return this.testValue;
10095
9981
  }
10096
9982
  includeKnownTest(context, testValue) {
10097
- var _a;
10098
9983
  if (this.test.shouldBeIncluded(context)) {
10099
9984
  this.test.include(context, false);
10100
9985
  }
10101
9986
  if (testValue && this.consequent.shouldBeIncluded(context)) {
10102
- this.consequent.include(context, false, { asSingleStatement: true });
9987
+ this.consequent.includeAsSingleStatement(context, false);
10103
9988
  }
10104
- if (!testValue && ((_a = this.alternate) === null || _a === void 0 ? void 0 : _a.shouldBeIncluded(context))) {
10105
- this.alternate.include(context, false, { asSingleStatement: true });
9989
+ if (this.alternate !== null && !testValue && this.alternate.shouldBeIncluded(context)) {
9990
+ this.alternate.includeAsSingleStatement(context, false);
10106
9991
  }
10107
9992
  }
10108
9993
  includeRecursively(includeChildrenRecursively, context) {
10109
- var _a;
10110
9994
  this.test.include(context, includeChildrenRecursively);
10111
9995
  this.consequent.include(context, includeChildrenRecursively);
10112
- (_a = this.alternate) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
9996
+ if (this.alternate !== null) {
9997
+ this.alternate.include(context, includeChildrenRecursively);
9998
+ }
10113
9999
  }
10114
10000
  includeUnknownTest(context) {
10115
- var _a;
10116
10001
  this.test.include(context, false);
10117
10002
  const { brokenFlow } = context;
10118
10003
  let consequentBrokenFlow = BROKEN_FLOW_NONE;
10119
10004
  if (this.consequent.shouldBeIncluded(context)) {
10120
- this.consequent.include(context, false, { asSingleStatement: true });
10005
+ this.consequent.includeAsSingleStatement(context, false);
10121
10006
  consequentBrokenFlow = context.brokenFlow;
10122
10007
  context.brokenFlow = brokenFlow;
10123
10008
  }
10124
- if ((_a = this.alternate) === null || _a === void 0 ? void 0 : _a.shouldBeIncluded(context)) {
10125
- this.alternate.include(context, false, { asSingleStatement: true });
10009
+ if (this.alternate !== null && this.alternate.shouldBeIncluded(context)) {
10010
+ this.alternate.includeAsSingleStatement(context, false);
10126
10011
  context.brokenFlow =
10127
10012
  context.brokenFlow < consequentBrokenFlow ? context.brokenFlow : consequentBrokenFlow;
10128
10013
  }
@@ -10709,7 +10594,7 @@ class LogicalExpression extends NodeBase {
10709
10594
  if (!this.isBranchResolutionAnalysed) {
10710
10595
  this.isBranchResolutionAnalysed = true;
10711
10596
  const leftValue = this.left.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
10712
- if (typeof leftValue === 'symbol') {
10597
+ if (leftValue === UnknownValue) {
10713
10598
  return null;
10714
10599
  }
10715
10600
  else {
@@ -10895,32 +10780,21 @@ class NewExpression extends NodeBase {
10895
10780
  this.deoptimized = false;
10896
10781
  }
10897
10782
  hasEffects(context) {
10898
- try {
10899
- for (const argument of this.arguments) {
10900
- if (argument.hasEffects(context))
10901
- return true;
10902
- }
10903
- if (this.context.options.treeshake.annotations &&
10904
- this.annotations)
10905
- return false;
10906
- return (this.callee.hasEffects(context) ||
10907
- this.callee.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
10908
- }
10909
- finally {
10910
- if (!this.deoptimized)
10911
- this.applyDeoptimizations();
10783
+ if (!this.deoptimized)
10784
+ this.applyDeoptimizations();
10785
+ for (const argument of this.arguments) {
10786
+ if (argument.hasEffects(context))
10787
+ return true;
10912
10788
  }
10789
+ if (this.context.options.treeshake.annotations &&
10790
+ this.annotations)
10791
+ return false;
10792
+ return (this.callee.hasEffects(context) ||
10793
+ this.callee.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
10913
10794
  }
10914
10795
  hasEffectsWhenAccessedAtPath(path) {
10915
10796
  return path.length > 0;
10916
10797
  }
10917
- include(context, includeChildrenRecursively) {
10918
- if (!this.deoptimized)
10919
- this.applyDeoptimizations();
10920
- this.included = true;
10921
- this.callee.include(context, includeChildrenRecursively);
10922
- this.callee.includeArgumentsWhenCalledAtPath(EMPTY_PATH, context, this.arguments);
10923
- }
10924
10798
  initialise() {
10925
10799
  this.callOptions = {
10926
10800
  args: this.arguments,
@@ -10967,9 +10841,6 @@ class ObjectExpression extends NodeBase {
10967
10841
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
10968
10842
  return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
10969
10843
  }
10970
- includeArgumentsWhenCalledAtPath(path, context, args) {
10971
- this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
10972
- }
10973
10844
  render(code, options, { renderedSurroundingElement } = BLANK) {
10974
10845
  super.render(code, options);
10975
10846
  if (renderedSurroundingElement === ExpressionStatement$1 ||
@@ -10992,7 +10863,7 @@ class ObjectExpression extends NodeBase {
10992
10863
  let key;
10993
10864
  if (property.computed) {
10994
10865
  const keyValue = property.key.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
10995
- if (typeof keyValue === 'symbol') {
10866
+ if (keyValue === UnknownValue) {
10996
10867
  properties.push({ key: UnknownKey, kind: property.kind, property });
10997
10868
  continue;
10998
10869
  }
@@ -11113,8 +10984,8 @@ class PropertyDefinition extends NodeBase {
11113
10984
  : UNKNOWN_EXPRESSION;
11114
10985
  }
11115
10986
  hasEffects(context) {
11116
- var _a;
11117
- return this.key.hasEffects(context) || (this.static && ((_a = this.value) === null || _a === void 0 ? void 0 : _a.hasEffects(context)));
10987
+ return (this.key.hasEffects(context) ||
10988
+ (this.static && this.value !== null && this.value.hasEffects(context)));
11118
10989
  }
11119
10990
  hasEffectsWhenAccessedAtPath(path, context) {
11120
10991
  return !this.value || this.value.hasEffectsWhenAccessedAtPath(path, context);
@@ -11125,24 +10996,21 @@ class PropertyDefinition extends NodeBase {
11125
10996
  hasEffectsWhenCalledAtPath(path, callOptions, context) {
11126
10997
  return !this.value || this.value.hasEffectsWhenCalledAtPath(path, callOptions, context);
11127
10998
  }
11128
- includeArgumentsWhenCalledAtPath(path, context, args) {
11129
- var _a;
11130
- (_a = this.value) === null || _a === void 0 ? void 0 : _a.includeArgumentsWhenCalledAtPath(path, context, args);
11131
- }
11132
10999
  }
11133
11000
 
11134
11001
  class ReturnStatement extends NodeBase {
11135
11002
  hasEffects(context) {
11136
- var _a;
11137
- if (!context.ignore.returnYield || ((_a = this.argument) === null || _a === void 0 ? void 0 : _a.hasEffects(context)))
11003
+ if (!context.ignore.returnYield ||
11004
+ (this.argument !== null && this.argument.hasEffects(context)))
11138
11005
  return true;
11139
11006
  context.brokenFlow = BROKEN_FLOW_ERROR_RETURN_LABEL;
11140
11007
  return false;
11141
11008
  }
11142
11009
  include(context, includeChildrenRecursively) {
11143
- var _a;
11144
11010
  this.included = true;
11145
- (_a = this.argument) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
11011
+ if (this.argument) {
11012
+ this.argument.include(context, includeChildrenRecursively);
11013
+ }
11146
11014
  context.brokenFlow = BROKEN_FLOW_ERROR_RETURN_LABEL;
11147
11015
  }
11148
11016
  initialise() {
@@ -11262,9 +11130,6 @@ class Super extends NodeBase {
11262
11130
  deoptimizePath(path) {
11263
11131
  this.variable.deoptimizePath(path);
11264
11132
  }
11265
- deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
11266
- this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
11267
- }
11268
11133
  include() {
11269
11134
  if (!this.included) {
11270
11135
  this.included = true;
@@ -11275,8 +11140,7 @@ class Super extends NodeBase {
11275
11140
 
11276
11141
  class SwitchCase extends NodeBase {
11277
11142
  hasEffects(context) {
11278
- var _a;
11279
- if ((_a = this.test) === null || _a === void 0 ? void 0 : _a.hasEffects(context))
11143
+ if (this.test && this.test.hasEffects(context))
11280
11144
  return true;
11281
11145
  for (const node of this.consequent) {
11282
11146
  if (context.brokenFlow)
@@ -11287,9 +11151,9 @@ class SwitchCase extends NodeBase {
11287
11151
  return false;
11288
11152
  }
11289
11153
  include(context, includeChildrenRecursively) {
11290
- var _a;
11291
11154
  this.included = true;
11292
- (_a = this.test) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
11155
+ if (this.test)
11156
+ this.test.include(context, includeChildrenRecursively);
11293
11157
  for (const node of this.consequent) {
11294
11158
  if (includeChildrenRecursively || node.shouldBeIncluded(context))
11295
11159
  node.include(context, includeChildrenRecursively);
@@ -11382,7 +11246,7 @@ class SwitchStatement extends NodeBase {
11382
11246
  }
11383
11247
  }
11384
11248
 
11385
- class TaggedTemplateExpression extends CallExpressionBase {
11249
+ class TaggedTemplateExpression extends NodeBase {
11386
11250
  bind() {
11387
11251
  super.bind();
11388
11252
  if (this.tag.type === Identifier$1) {
@@ -11397,35 +11261,13 @@ class TaggedTemplateExpression extends CallExpressionBase {
11397
11261
  }
11398
11262
  }
11399
11263
  hasEffects(context) {
11400
- try {
11401
- for (const argument of this.quasi.expressions) {
11402
- if (argument.hasEffects(context))
11403
- return true;
11404
- }
11405
- return (this.tag.hasEffects(context) ||
11406
- this.tag.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
11407
- }
11408
- finally {
11409
- if (!this.deoptimized)
11410
- this.applyDeoptimizations();
11411
- }
11412
- }
11413
- include(context, includeChildrenRecursively) {
11414
- if (!this.deoptimized)
11415
- this.applyDeoptimizations();
11416
- this.included = true;
11417
- this.tag.include(context, includeChildrenRecursively);
11418
- this.quasi.include(context, includeChildrenRecursively);
11419
- this.tag.includeArgumentsWhenCalledAtPath(EMPTY_PATH, context, this.callOptions.args);
11420
- const returnExpression = this.getReturnExpression();
11421
- if (!returnExpression.included) {
11422
- returnExpression.include(context, false);
11423
- }
11264
+ return (super.hasEffects(context) ||
11265
+ this.tag.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
11424
11266
  }
11425
11267
  initialise() {
11426
11268
  this.callOptions = {
11427
- args: [UNKNOWN_EXPRESSION, ...this.quasi.expressions],
11428
- thisParam: this.tag instanceof MemberExpression && !this.tag.variable ? this.tag.object : null,
11269
+ args: NO_ARGS,
11270
+ thisParam: null,
11429
11271
  withNew: false
11430
11272
  };
11431
11273
  }
@@ -11433,25 +11275,6 @@ class TaggedTemplateExpression extends CallExpressionBase {
11433
11275
  this.tag.render(code, options, { isCalleeOfRenderedParent: true });
11434
11276
  this.quasi.render(code, options);
11435
11277
  }
11436
- applyDeoptimizations() {
11437
- this.deoptimized = true;
11438
- const { thisParam } = this.callOptions;
11439
- if (thisParam) {
11440
- this.tag.deoptimizeThisOnEventAtPath(EVENT_CALLED, EMPTY_PATH, thisParam, SHARED_RECURSION_TRACKER);
11441
- }
11442
- for (const argument of this.quasi.expressions) {
11443
- // This will make sure all properties of parameters behave as "unknown"
11444
- argument.deoptimizePath(UNKNOWN_PATH);
11445
- }
11446
- this.context.requestTreeshakingPass();
11447
- }
11448
- getReturnExpression(recursionTracker = SHARED_RECURSION_TRACKER) {
11449
- if (this.returnExpression === null) {
11450
- this.returnExpression = UNKNOWN_EXPRESSION;
11451
- return (this.returnExpression = this.tag.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.callOptions, recursionTracker, this));
11452
- }
11453
- return this.returnExpression;
11454
- }
11455
11278
  }
11456
11279
 
11457
11280
  class TemplateElement extends NodeBase {
@@ -11663,15 +11486,13 @@ class TryStatement extends NodeBase {
11663
11486
  this.includedLabelsAfterBlock = null;
11664
11487
  }
11665
11488
  hasEffects(context) {
11666
- var _a;
11667
11489
  return ((this.context.options.treeshake.tryCatchDeoptimization
11668
11490
  ? this.block.body.length > 0
11669
11491
  : this.block.hasEffects(context)) ||
11670
- ((_a = this.finalizer) === null || _a === void 0 ? void 0 : _a.hasEffects(context)) ||
11671
- false);
11492
+ (this.finalizer !== null && this.finalizer.hasEffects(context)));
11672
11493
  }
11673
11494
  include(context, includeChildrenRecursively) {
11674
- var _a, _b;
11495
+ var _a;
11675
11496
  const tryCatchDeoptimization = (_a = this.context.options.treeshake) === null || _a === void 0 ? void 0 : _a.tryCatchDeoptimization;
11676
11497
  const { brokenFlow } = context;
11677
11498
  if (!this.directlyIncluded || !tryCatchDeoptimization) {
@@ -11692,7 +11513,9 @@ class TryStatement extends NodeBase {
11692
11513
  this.handler.include(context, includeChildrenRecursively);
11693
11514
  context.brokenFlow = brokenFlow;
11694
11515
  }
11695
- (_b = this.finalizer) === null || _b === void 0 ? void 0 : _b.include(context, includeChildrenRecursively);
11516
+ if (this.finalizer !== null) {
11517
+ this.finalizer.include(context, includeChildrenRecursively);
11518
+ }
11696
11519
  }
11697
11520
  }
11698
11521
 
@@ -11714,7 +11537,7 @@ class UnaryExpression extends NodeBase {
11714
11537
  if (path.length > 0)
11715
11538
  return UnknownValue;
11716
11539
  const argumentValue = this.argument.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
11717
- if (typeof argumentValue === 'symbol')
11540
+ if (argumentValue === UnknownValue)
11718
11541
  return UnknownValue;
11719
11542
  return unaryOperators[this.operator](argumentValue);
11720
11543
  }
@@ -11828,12 +11651,18 @@ class VariableDeclaration extends NodeBase {
11828
11651
  hasEffectsWhenAssignedAtPath() {
11829
11652
  return false;
11830
11653
  }
11831
- include(context, includeChildrenRecursively, { asSingleStatement } = BLANK) {
11654
+ include(context, includeChildrenRecursively) {
11832
11655
  this.included = true;
11833
11656
  for (const declarator of this.declarations) {
11834
11657
  if (includeChildrenRecursively || declarator.shouldBeIncluded(context))
11835
11658
  declarator.include(context, includeChildrenRecursively);
11836
- if (asSingleStatement) {
11659
+ }
11660
+ }
11661
+ includeAsSingleStatement(context, includeChildrenRecursively) {
11662
+ this.included = true;
11663
+ for (const declarator of this.declarations) {
11664
+ if (includeChildrenRecursively || declarator.shouldBeIncluded(context)) {
11665
+ declarator.include(context, includeChildrenRecursively);
11837
11666
  declarator.id.include(context, includeChildrenRecursively);
11838
11667
  }
11839
11668
  }
@@ -11981,15 +11810,15 @@ class VariableDeclarator extends NodeBase {
11981
11810
  this.id.deoptimizePath(path);
11982
11811
  }
11983
11812
  hasEffects(context) {
11984
- var _a;
11985
- const initEffect = (_a = this.init) === null || _a === void 0 ? void 0 : _a.hasEffects(context);
11813
+ const initEffect = this.init !== null && this.init.hasEffects(context);
11986
11814
  this.id.markDeclarationReached();
11987
11815
  return initEffect || this.id.hasEffects(context);
11988
11816
  }
11989
11817
  include(context, includeChildrenRecursively) {
11990
- var _a;
11991
11818
  this.included = true;
11992
- (_a = this.init) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
11819
+ if (this.init) {
11820
+ this.init.include(context, includeChildrenRecursively);
11821
+ }
11993
11822
  this.id.markDeclarationReached();
11994
11823
  if (includeChildrenRecursively || this.id.shouldBeIncluded(context)) {
11995
11824
  this.id.include(context, includeChildrenRecursively);
@@ -12033,7 +11862,7 @@ class WhileStatement extends NodeBase {
12033
11862
  this.included = true;
12034
11863
  this.test.include(context, includeChildrenRecursively);
12035
11864
  const { brokenFlow } = context;
12036
- this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
11865
+ this.body.includeAsSingleStatement(context, includeChildrenRecursively);
12037
11866
  context.brokenFlow = brokenFlow;
12038
11867
  }
12039
11868
  }
@@ -12044,10 +11873,9 @@ class YieldExpression extends NodeBase {
12044
11873
  this.deoptimized = false;
12045
11874
  }
12046
11875
  hasEffects(context) {
12047
- var _a;
12048
11876
  if (!this.deoptimized)
12049
11877
  this.applyDeoptimizations();
12050
- return !context.ignore.returnYield || ((_a = this.argument) === null || _a === void 0 ? void 0 : _a.hasEffects(context));
11878
+ return (!context.ignore.returnYield || (this.argument !== null && this.argument.hasEffects(context)));
12051
11879
  }
12052
11880
  render(code, options) {
12053
11881
  if (this.argument) {
@@ -12057,6 +11885,14 @@ class YieldExpression extends NodeBase {
12057
11885
  }
12058
11886
  }
12059
11887
  }
11888
+ applyDeoptimizations() {
11889
+ this.deoptimized = true;
11890
+ const { argument } = this;
11891
+ if (argument) {
11892
+ argument.deoptimizePath(UNKNOWN_PATH);
11893
+ this.context.requestTreeshakingPass();
11894
+ }
11895
+ }
12060
11896
  }
12061
11897
 
12062
11898
  const nodeConstructors = {