rollup 2.75.2 → 2.75.5
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.
- package/CHANGELOG.md +27 -1
- package/dist/bin/rollup +2 -2
- package/dist/es/rollup.browser.js +3 -3
- package/dist/es/rollup.js +2 -2
- package/dist/es/shared/rollup.js +818 -867
- package/dist/es/shared/watch.js +5 -5
- package/dist/loadConfigFile.js +2 -2
- package/dist/rollup.browser.js +3 -3
- package/dist/rollup.browser.js.map +1 -1
- package/dist/rollup.js +2 -2
- package/dist/shared/index.js +4 -4
- package/dist/shared/loadConfigFile.js +2 -2
- package/dist/shared/mergeOptions.js +2 -2
- package/dist/shared/rollup.js +818 -867
- package/dist/shared/watch-cli.js +2 -2
- package/dist/shared/watch.js +2 -2
- package/package.json +2 -2
package/dist/shared/rollup.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v2.75.
|
|
4
|
-
|
|
3
|
+
Rollup.js v2.75.5
|
|
4
|
+
Wed, 01 Jun 2022 12:43:56 GMT - commit 14dedb52b4d799deebd8b711c1e14759fc0213d9
|
|
5
5
|
|
|
6
6
|
https://github.com/rollup/rollup
|
|
7
7
|
|
|
@@ -27,7 +27,7 @@ function _interopNamespaceDefault(e) {
|
|
|
27
27
|
return n;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
var version$1 = "2.75.
|
|
30
|
+
var version$1 = "2.75.5";
|
|
31
31
|
|
|
32
32
|
function ensureArray$1(items) {
|
|
33
33
|
if (Array.isArray(items)) {
|
|
@@ -5335,6 +5335,11 @@ const INCLUDE_PARAMETERS = 'variables';
|
|
|
5335
5335
|
class NodeBase extends ExpressionEntity {
|
|
5336
5336
|
constructor(esTreeNode, parent, parentScope) {
|
|
5337
5337
|
super();
|
|
5338
|
+
// Nodes can apply custom deoptimizations once they become part of the
|
|
5339
|
+
// executed code. To do this, they must initialize this as false, implement
|
|
5340
|
+
// applyDeoptimizations and call this from include and hasEffects if they
|
|
5341
|
+
// have custom handlers
|
|
5342
|
+
this.deoptimized = false;
|
|
5338
5343
|
this.esTreeNode = esTreeNode;
|
|
5339
5344
|
this.keys = keys[esTreeNode.type] || getAndCreateKeys(esTreeNode);
|
|
5340
5345
|
this.parent = parent;
|
|
@@ -5372,7 +5377,7 @@ class NodeBase extends ExpressionEntity {
|
|
|
5372
5377
|
this.scope = parentScope;
|
|
5373
5378
|
}
|
|
5374
5379
|
hasEffects(context) {
|
|
5375
|
-
if (this.deoptimized
|
|
5380
|
+
if (!this.deoptimized)
|
|
5376
5381
|
this.applyDeoptimizations();
|
|
5377
5382
|
for (const key of this.keys) {
|
|
5378
5383
|
const value = this[key];
|
|
@@ -5390,7 +5395,7 @@ class NodeBase extends ExpressionEntity {
|
|
|
5390
5395
|
return false;
|
|
5391
5396
|
}
|
|
5392
5397
|
include(context, includeChildrenRecursively, _options) {
|
|
5393
|
-
if (this.deoptimized
|
|
5398
|
+
if (!this.deoptimized)
|
|
5394
5399
|
this.applyDeoptimizations();
|
|
5395
5400
|
this.included = true;
|
|
5396
5401
|
for (const key of this.keys) {
|
|
@@ -5489,10 +5494,6 @@ class NodeBase extends ExpressionEntity {
|
|
|
5489
5494
|
}
|
|
5490
5495
|
|
|
5491
5496
|
class SpreadElement extends NodeBase {
|
|
5492
|
-
constructor() {
|
|
5493
|
-
super(...arguments);
|
|
5494
|
-
this.deoptimized = false;
|
|
5495
|
-
}
|
|
5496
5497
|
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
5497
5498
|
if (path.length > 0) {
|
|
5498
5499
|
this.argument.deoptimizeThisOnEventAtPath(event, [UnknownKey, ...path], thisParameter, recursionTracker);
|
|
@@ -6171,7 +6172,6 @@ const ARRAY_PROTOTYPE = new ObjectEntity({
|
|
|
6171
6172
|
class ArrayExpression extends NodeBase {
|
|
6172
6173
|
constructor() {
|
|
6173
6174
|
super(...arguments);
|
|
6174
|
-
this.deoptimized = false;
|
|
6175
6175
|
this.objectEntity = null;
|
|
6176
6176
|
}
|
|
6177
6177
|
deoptimizePath(path) {
|
|
@@ -6200,8 +6200,8 @@ class ArrayExpression extends NodeBase {
|
|
|
6200
6200
|
let hasSpread = false;
|
|
6201
6201
|
for (let index = 0; index < this.elements.length; index++) {
|
|
6202
6202
|
const element = this.elements[index];
|
|
6203
|
-
if (
|
|
6204
|
-
if (element) {
|
|
6203
|
+
if (element) {
|
|
6204
|
+
if (hasSpread || element instanceof SpreadElement) {
|
|
6205
6205
|
hasSpread = true;
|
|
6206
6206
|
element.deoptimizePath(UNKNOWN_PATH);
|
|
6207
6207
|
}
|
|
@@ -6643,629 +6643,87 @@ class ReturnValueScope extends ParameterScope {
|
|
|
6643
6643
|
}
|
|
6644
6644
|
}
|
|
6645
6645
|
|
|
6646
|
-
|
|
6647
|
-
|
|
6648
|
-
|
|
6649
|
-
|
|
6650
|
-
|
|
6651
|
-
|
|
6652
|
-
|
|
6653
|
-
}
|
|
6654
|
-
declare(kind, init) {
|
|
6655
|
-
return this.left.declare(kind, init);
|
|
6656
|
-
}
|
|
6657
|
-
deoptimizePath(path) {
|
|
6658
|
-
path.length === 0 && this.left.deoptimizePath(path);
|
|
6659
|
-
}
|
|
6660
|
-
hasEffectsWhenAssignedAtPath(path, context) {
|
|
6661
|
-
return path.length > 0 || this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
|
|
6662
|
-
}
|
|
6663
|
-
// Note that FunctionBase may directly include .left and .right without
|
|
6664
|
-
// including the pattern itself. This is how default parameter tree-shaking
|
|
6665
|
-
// works at the moment.
|
|
6666
|
-
include(context, includeChildrenRecursively) {
|
|
6667
|
-
this.included = true;
|
|
6668
|
-
this.left.include(context, includeChildrenRecursively);
|
|
6669
|
-
this.right.include(context, includeChildrenRecursively);
|
|
6670
|
-
}
|
|
6671
|
-
markDeclarationReached() {
|
|
6672
|
-
this.left.markDeclarationReached();
|
|
6673
|
-
}
|
|
6674
|
-
render(code, options, { isShorthandProperty } = BLANK) {
|
|
6675
|
-
this.left.render(code, options, { isShorthandProperty });
|
|
6676
|
-
if (this.right.included) {
|
|
6677
|
-
this.right.render(code, options);
|
|
6678
|
-
}
|
|
6679
|
-
else {
|
|
6680
|
-
code.remove(this.left.end, this.end);
|
|
6681
|
-
}
|
|
6682
|
-
}
|
|
6683
|
-
applyDeoptimizations() {
|
|
6684
|
-
this.deoptimized = true;
|
|
6685
|
-
this.left.deoptimizePath(EMPTY_PATH);
|
|
6686
|
-
this.right.deoptimizePath(UNKNOWN_PATH);
|
|
6687
|
-
this.context.requestTreeshakingPass();
|
|
6688
|
-
}
|
|
6689
|
-
}
|
|
6646
|
+
//@ts-check
|
|
6647
|
+
/** @typedef { import('estree').Node} Node */
|
|
6648
|
+
/** @typedef {Node | {
|
|
6649
|
+
* type: 'PropertyDefinition';
|
|
6650
|
+
* computed: boolean;
|
|
6651
|
+
* value: Node
|
|
6652
|
+
* }} NodeWithPropertyDefinition */
|
|
6690
6653
|
|
|
6691
|
-
|
|
6692
|
-
|
|
6693
|
-
|
|
6694
|
-
|
|
6695
|
-
|
|
6696
|
-
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
|
-
}
|
|
6702
|
-
}
|
|
6703
|
-
}
|
|
6704
|
-
function removeAnnotations(node, code) {
|
|
6705
|
-
if (!node.annotations && node.parent.type === ExpressionStatement$1) {
|
|
6706
|
-
node = node.parent;
|
|
6707
|
-
}
|
|
6708
|
-
if (node.annotations) {
|
|
6709
|
-
for (const annotation of node.annotations) {
|
|
6710
|
-
code.remove(annotation.start, annotation.end);
|
|
6711
|
-
}
|
|
6712
|
-
}
|
|
6713
|
-
}
|
|
6654
|
+
/**
|
|
6655
|
+
*
|
|
6656
|
+
* @param {NodeWithPropertyDefinition} node
|
|
6657
|
+
* @param {NodeWithPropertyDefinition} parent
|
|
6658
|
+
* @returns boolean
|
|
6659
|
+
*/
|
|
6660
|
+
function is_reference (node, parent) {
|
|
6661
|
+
if (node.type === 'MemberExpression') {
|
|
6662
|
+
return !node.computed && is_reference(node.object, node);
|
|
6663
|
+
}
|
|
6714
6664
|
|
|
6715
|
-
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
6740
|
-
|
|
6665
|
+
if (node.type === 'Identifier') {
|
|
6666
|
+
if (!parent) return true;
|
|
6667
|
+
|
|
6668
|
+
switch (parent.type) {
|
|
6669
|
+
// disregard `bar` in `foo.bar`
|
|
6670
|
+
case 'MemberExpression': return parent.computed || node === parent.object;
|
|
6671
|
+
|
|
6672
|
+
// disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
|
|
6673
|
+
case 'MethodDefinition': return parent.computed;
|
|
6674
|
+
|
|
6675
|
+
// disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
|
|
6676
|
+
case 'PropertyDefinition': return parent.computed || node === parent.value;
|
|
6677
|
+
|
|
6678
|
+
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
|
|
6679
|
+
case 'Property': return parent.computed || node === parent.value;
|
|
6680
|
+
|
|
6681
|
+
// disregard the `bar` in `export { foo as bar }` or
|
|
6682
|
+
// the foo in `import { foo as bar }`
|
|
6683
|
+
case 'ExportSpecifier':
|
|
6684
|
+
case 'ImportSpecifier': return node === parent.local;
|
|
6685
|
+
|
|
6686
|
+
// disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
|
|
6687
|
+
case 'LabeledStatement':
|
|
6688
|
+
case 'BreakStatement':
|
|
6689
|
+
case 'ContinueStatement': return false;
|
|
6690
|
+
default: return true;
|
|
6691
|
+
}
|
|
6692
|
+
}
|
|
6693
|
+
|
|
6694
|
+
return false;
|
|
6741
6695
|
}
|
|
6742
|
-
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
|
|
6748
|
-
start = code.indexOf('/', start);
|
|
6749
|
-
if (start === -1 || start > lineBreakPos)
|
|
6750
|
-
return [lineBreakPos, lineBreakPos + 1];
|
|
6751
|
-
// With our assumption, '/' always starts a comment. Determine comment type:
|
|
6752
|
-
charCodeAfterSlash = code.charCodeAt(start + 1);
|
|
6753
|
-
if (charCodeAfterSlash === 47 /*"/"*/)
|
|
6754
|
-
return [start, lineBreakPos + 1];
|
|
6755
|
-
start = code.indexOf('*/', start + 3) + 2;
|
|
6756
|
-
if (start > lineBreakPos) {
|
|
6757
|
-
lineBreakPos = code.indexOf('\n', start);
|
|
6758
|
-
}
|
|
6696
|
+
|
|
6697
|
+
/* eslint sort-keys: "off" */
|
|
6698
|
+
const ValueProperties = Symbol('Value Properties');
|
|
6699
|
+
const PURE = {
|
|
6700
|
+
hasEffectsWhenCalled() {
|
|
6701
|
+
return false;
|
|
6759
6702
|
}
|
|
6760
|
-
}
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
|
|
6764
|
-
let nextNodeNeedsBoundaries = !nextNode.included || nextNode.needsBoundaries;
|
|
6765
|
-
if (nextNodeNeedsBoundaries) {
|
|
6766
|
-
nextNodeStart =
|
|
6767
|
-
start + findFirstLineBreakOutsideComment(code.original.slice(start, nextNode.start))[1];
|
|
6703
|
+
};
|
|
6704
|
+
const IMPURE = {
|
|
6705
|
+
hasEffectsWhenCalled() {
|
|
6706
|
+
return true;
|
|
6768
6707
|
}
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
else {
|
|
6789
|
-
treeshakeNode(currentNode, code, currentNodeStart, nextNodeStart);
|
|
6790
|
-
}
|
|
6791
|
-
}
|
|
6792
|
-
else {
|
|
6793
|
-
currentNode.render(code, options);
|
|
6794
|
-
}
|
|
6795
|
-
}
|
|
6796
|
-
}
|
|
6797
|
-
// This assumes that the first character is not part of the first node
|
|
6798
|
-
function getCommaSeparatedNodesWithBoundaries(nodes, code, start, end) {
|
|
6799
|
-
const splitUpNodes = [];
|
|
6800
|
-
let node, nextNode, nextNodeStart, contentEnd, char;
|
|
6801
|
-
let separator = start - 1;
|
|
6802
|
-
for (let nextIndex = 0; nextIndex < nodes.length; nextIndex++) {
|
|
6803
|
-
nextNode = nodes[nextIndex];
|
|
6804
|
-
if (node !== undefined) {
|
|
6805
|
-
separator =
|
|
6806
|
-
node.end +
|
|
6807
|
-
findFirstOccurrenceOutsideComment(code.original.slice(node.end, nextNode.start), ',');
|
|
6808
|
-
}
|
|
6809
|
-
nextNodeStart = contentEnd =
|
|
6810
|
-
separator +
|
|
6811
|
-
1 +
|
|
6812
|
-
findFirstLineBreakOutsideComment(code.original.slice(separator + 1, nextNode.start))[1];
|
|
6813
|
-
while (((char = code.original.charCodeAt(nextNodeStart)),
|
|
6814
|
-
char === 32 /*" "*/ || char === 9 /*"\t"*/ || char === 10 /*"\n"*/ || char === 13) /*"\r"*/)
|
|
6815
|
-
nextNodeStart++;
|
|
6816
|
-
if (node !== undefined) {
|
|
6817
|
-
splitUpNodes.push({
|
|
6818
|
-
contentEnd,
|
|
6819
|
-
end: nextNodeStart,
|
|
6820
|
-
node,
|
|
6821
|
-
separator,
|
|
6822
|
-
start
|
|
6823
|
-
});
|
|
6824
|
-
}
|
|
6825
|
-
node = nextNode;
|
|
6826
|
-
start = nextNodeStart;
|
|
6827
|
-
}
|
|
6828
|
-
splitUpNodes.push({
|
|
6829
|
-
contentEnd: end,
|
|
6830
|
-
end,
|
|
6831
|
-
node: node,
|
|
6832
|
-
separator: null,
|
|
6833
|
-
start
|
|
6834
|
-
});
|
|
6835
|
-
return splitUpNodes;
|
|
6836
|
-
}
|
|
6837
|
-
// This assumes there are only white-space and comments between start and end
|
|
6838
|
-
function removeLineBreaks(code, start, end) {
|
|
6839
|
-
while (true) {
|
|
6840
|
-
const [removeStart, removeEnd] = findFirstLineBreakOutsideComment(code.original.slice(start, end));
|
|
6841
|
-
if (removeStart === -1) {
|
|
6842
|
-
break;
|
|
6843
|
-
}
|
|
6844
|
-
code.remove(start + removeStart, (start += removeEnd));
|
|
6845
|
-
}
|
|
6846
|
-
}
|
|
6847
|
-
|
|
6848
|
-
class BlockScope extends ChildScope {
|
|
6849
|
-
addDeclaration(identifier, context, init, isHoisted) {
|
|
6850
|
-
if (isHoisted) {
|
|
6851
|
-
const variable = this.parent.addDeclaration(identifier, context, init, isHoisted);
|
|
6852
|
-
// Necessary to make sure the init is deoptimized for conditional declarations.
|
|
6853
|
-
// We cannot call deoptimizePath here.
|
|
6854
|
-
variable.markInitializersForDeoptimization();
|
|
6855
|
-
return variable;
|
|
6856
|
-
}
|
|
6857
|
-
else {
|
|
6858
|
-
return super.addDeclaration(identifier, context, init, false);
|
|
6859
|
-
}
|
|
6860
|
-
}
|
|
6861
|
-
}
|
|
6862
|
-
|
|
6863
|
-
class ExpressionStatement extends NodeBase {
|
|
6864
|
-
initialise() {
|
|
6865
|
-
if (this.directive &&
|
|
6866
|
-
this.directive !== 'use strict' &&
|
|
6867
|
-
this.parent.type === Program$1) {
|
|
6868
|
-
this.context.warn(
|
|
6869
|
-
// This is necessary, because either way (deleting or not) can lead to errors.
|
|
6870
|
-
{
|
|
6871
|
-
code: 'MODULE_LEVEL_DIRECTIVE',
|
|
6872
|
-
message: `Module level directives cause errors when bundled, '${this.directive}' was ignored.`
|
|
6873
|
-
}, this.start);
|
|
6874
|
-
}
|
|
6875
|
-
}
|
|
6876
|
-
render(code, options) {
|
|
6877
|
-
super.render(code, options);
|
|
6878
|
-
if (this.included)
|
|
6879
|
-
this.insertSemicolon(code);
|
|
6880
|
-
}
|
|
6881
|
-
shouldBeIncluded(context) {
|
|
6882
|
-
if (this.directive && this.directive !== 'use strict')
|
|
6883
|
-
return this.parent.type !== Program$1;
|
|
6884
|
-
return super.shouldBeIncluded(context);
|
|
6885
|
-
}
|
|
6886
|
-
}
|
|
6887
|
-
|
|
6888
|
-
class BlockStatement extends NodeBase {
|
|
6889
|
-
constructor() {
|
|
6890
|
-
super(...arguments);
|
|
6891
|
-
this.directlyIncluded = false;
|
|
6892
|
-
}
|
|
6893
|
-
addImplicitReturnExpressionToScope() {
|
|
6894
|
-
const lastStatement = this.body[this.body.length - 1];
|
|
6895
|
-
if (!lastStatement || lastStatement.type !== ReturnStatement$1) {
|
|
6896
|
-
this.scope.addReturnExpression(UNKNOWN_EXPRESSION);
|
|
6897
|
-
}
|
|
6898
|
-
}
|
|
6899
|
-
createScope(parentScope) {
|
|
6900
|
-
this.scope = this.parent.preventChildBlockScope
|
|
6901
|
-
? parentScope
|
|
6902
|
-
: new BlockScope(parentScope);
|
|
6903
|
-
}
|
|
6904
|
-
hasEffects(context) {
|
|
6905
|
-
if (this.deoptimizeBody)
|
|
6906
|
-
return true;
|
|
6907
|
-
for (const node of this.body) {
|
|
6908
|
-
if (context.brokenFlow)
|
|
6909
|
-
break;
|
|
6910
|
-
if (node.hasEffects(context))
|
|
6911
|
-
return true;
|
|
6912
|
-
}
|
|
6913
|
-
return false;
|
|
6914
|
-
}
|
|
6915
|
-
include(context, includeChildrenRecursively) {
|
|
6916
|
-
if (!(this.deoptimizeBody && this.directlyIncluded)) {
|
|
6917
|
-
this.included = true;
|
|
6918
|
-
this.directlyIncluded = true;
|
|
6919
|
-
if (this.deoptimizeBody)
|
|
6920
|
-
includeChildrenRecursively = true;
|
|
6921
|
-
for (const node of this.body) {
|
|
6922
|
-
if (includeChildrenRecursively || node.shouldBeIncluded(context))
|
|
6923
|
-
node.include(context, includeChildrenRecursively);
|
|
6924
|
-
}
|
|
6925
|
-
}
|
|
6926
|
-
}
|
|
6927
|
-
initialise() {
|
|
6928
|
-
const firstBodyStatement = this.body[0];
|
|
6929
|
-
this.deoptimizeBody =
|
|
6930
|
-
firstBodyStatement instanceof ExpressionStatement &&
|
|
6931
|
-
firstBodyStatement.directive === 'use asm';
|
|
6932
|
-
}
|
|
6933
|
-
render(code, options) {
|
|
6934
|
-
if (this.body.length) {
|
|
6935
|
-
renderStatementList(this.body, code, this.start + 1, this.end - 1, options);
|
|
6936
|
-
}
|
|
6937
|
-
else {
|
|
6938
|
-
super.render(code, options);
|
|
6939
|
-
}
|
|
6940
|
-
}
|
|
6941
|
-
}
|
|
6942
|
-
|
|
6943
|
-
class RestElement extends NodeBase {
|
|
6944
|
-
constructor() {
|
|
6945
|
-
super(...arguments);
|
|
6946
|
-
this.deoptimized = false;
|
|
6947
|
-
this.declarationInit = null;
|
|
6948
|
-
}
|
|
6949
|
-
addExportedVariables(variables, exportNamesByVariable) {
|
|
6950
|
-
this.argument.addExportedVariables(variables, exportNamesByVariable);
|
|
6951
|
-
}
|
|
6952
|
-
declare(kind, init) {
|
|
6953
|
-
this.declarationInit = init;
|
|
6954
|
-
return this.argument.declare(kind, UNKNOWN_EXPRESSION);
|
|
6955
|
-
}
|
|
6956
|
-
deoptimizePath(path) {
|
|
6957
|
-
path.length === 0 && this.argument.deoptimizePath(EMPTY_PATH);
|
|
6958
|
-
}
|
|
6959
|
-
hasEffectsWhenAssignedAtPath(path, context) {
|
|
6960
|
-
return path.length > 0 || this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
|
|
6961
|
-
}
|
|
6962
|
-
markDeclarationReached() {
|
|
6963
|
-
this.argument.markDeclarationReached();
|
|
6964
|
-
}
|
|
6965
|
-
applyDeoptimizations() {
|
|
6966
|
-
this.deoptimized = true;
|
|
6967
|
-
if (this.declarationInit !== null) {
|
|
6968
|
-
this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
|
|
6969
|
-
this.context.requestTreeshakingPass();
|
|
6970
|
-
}
|
|
6971
|
-
}
|
|
6972
|
-
}
|
|
6973
|
-
|
|
6974
|
-
class FunctionBase extends NodeBase {
|
|
6975
|
-
constructor() {
|
|
6976
|
-
super(...arguments);
|
|
6977
|
-
this.objectEntity = null;
|
|
6978
|
-
this.deoptimizedReturn = false;
|
|
6979
|
-
this.forceIncludeParameters = false;
|
|
6980
|
-
}
|
|
6981
|
-
deoptimizeCache() {
|
|
6982
|
-
this.forceIncludeParameters = true;
|
|
6983
|
-
}
|
|
6984
|
-
deoptimizePath(path) {
|
|
6985
|
-
this.getObjectEntity().deoptimizePath(path);
|
|
6986
|
-
if (path.length === 1 && path[0] === UnknownKey) {
|
|
6987
|
-
// A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
|
|
6988
|
-
// which means the return expression needs to be reassigned
|
|
6989
|
-
this.forceIncludeParameters = true;
|
|
6990
|
-
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
6991
|
-
}
|
|
6992
|
-
}
|
|
6993
|
-
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
6994
|
-
if (path.length > 0) {
|
|
6995
|
-
this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
6996
|
-
}
|
|
6997
|
-
}
|
|
6998
|
-
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
6999
|
-
return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
|
|
7000
|
-
}
|
|
7001
|
-
getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
|
|
7002
|
-
if (path.length > 0) {
|
|
7003
|
-
return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
|
|
7004
|
-
}
|
|
7005
|
-
if (this.async) {
|
|
7006
|
-
if (!this.deoptimizedReturn) {
|
|
7007
|
-
this.deoptimizedReturn = true;
|
|
7008
|
-
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
7009
|
-
this.context.requestTreeshakingPass();
|
|
7010
|
-
}
|
|
7011
|
-
return UNKNOWN_EXPRESSION;
|
|
7012
|
-
}
|
|
7013
|
-
return this.scope.getReturnExpression();
|
|
7014
|
-
}
|
|
7015
|
-
hasEffectsWhenAccessedAtPath(path, context) {
|
|
7016
|
-
return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
|
|
7017
|
-
}
|
|
7018
|
-
hasEffectsWhenAssignedAtPath(path, context) {
|
|
7019
|
-
return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
|
|
7020
|
-
}
|
|
7021
|
-
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
7022
|
-
var _a;
|
|
7023
|
-
if (path.length > 0) {
|
|
7024
|
-
return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
7025
|
-
}
|
|
7026
|
-
if (this.async) {
|
|
7027
|
-
const { propertyReadSideEffects } = this.context.options
|
|
7028
|
-
.treeshake;
|
|
7029
|
-
const returnExpression = this.scope.getReturnExpression();
|
|
7030
|
-
if (returnExpression.hasEffectsWhenCalledAtPath(['then'], { args: NO_ARGS, thisParam: null, withNew: false }, context) ||
|
|
7031
|
-
(propertyReadSideEffects &&
|
|
7032
|
-
(propertyReadSideEffects === 'always' ||
|
|
7033
|
-
returnExpression.hasEffectsWhenAccessedAtPath(['then'], context)))) {
|
|
7034
|
-
return true;
|
|
7035
|
-
}
|
|
7036
|
-
}
|
|
7037
|
-
for (let position = 0; position < this.params.length; position++) {
|
|
7038
|
-
const parameter = this.params[position];
|
|
7039
|
-
if (parameter instanceof AssignmentPattern) {
|
|
7040
|
-
if (parameter.left.hasEffects(context)) {
|
|
7041
|
-
return true;
|
|
7042
|
-
}
|
|
7043
|
-
const argumentValue = (_a = callOptions.args[position]) === null || _a === void 0 ? void 0 : _a.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
|
|
7044
|
-
if ((argumentValue === undefined || argumentValue === UnknownValue) &&
|
|
7045
|
-
parameter.right.hasEffects(context)) {
|
|
7046
|
-
return true;
|
|
7047
|
-
}
|
|
7048
|
-
}
|
|
7049
|
-
else if (parameter.hasEffects(context)) {
|
|
7050
|
-
return true;
|
|
7051
|
-
}
|
|
7052
|
-
}
|
|
7053
|
-
return false;
|
|
7054
|
-
}
|
|
7055
|
-
include(context, includeChildrenRecursively, { includeWithoutParameterDefaults } = BLANK) {
|
|
7056
|
-
this.included = true;
|
|
7057
|
-
const { brokenFlow } = context;
|
|
7058
|
-
context.brokenFlow = BROKEN_FLOW_NONE;
|
|
7059
|
-
this.body.include(context, includeChildrenRecursively);
|
|
7060
|
-
context.brokenFlow = brokenFlow;
|
|
7061
|
-
if (!includeWithoutParameterDefaults ||
|
|
7062
|
-
includeChildrenRecursively ||
|
|
7063
|
-
this.forceIncludeParameters) {
|
|
7064
|
-
for (const param of this.params) {
|
|
7065
|
-
param.include(context, includeChildrenRecursively);
|
|
7066
|
-
}
|
|
7067
|
-
}
|
|
7068
|
-
}
|
|
7069
|
-
includeCallArguments(context, args) {
|
|
7070
|
-
var _a;
|
|
7071
|
-
for (let position = 0; position < this.params.length; position++) {
|
|
7072
|
-
const parameter = this.params[position];
|
|
7073
|
-
if (parameter instanceof AssignmentPattern) {
|
|
7074
|
-
if (parameter.left.shouldBeIncluded(context)) {
|
|
7075
|
-
parameter.left.include(context, false);
|
|
7076
|
-
}
|
|
7077
|
-
const argumentValue = (_a = args[position]) === null || _a === void 0 ? void 0 : _a.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
|
|
7078
|
-
// If argumentValue === UnknownTruthyValue, then we do not need to
|
|
7079
|
-
// include the default
|
|
7080
|
-
if ((argumentValue === undefined || argumentValue === UnknownValue) &&
|
|
7081
|
-
(this.parameterVariables[position].some(variable => variable.included) ||
|
|
7082
|
-
parameter.right.shouldBeIncluded(context))) {
|
|
7083
|
-
parameter.right.include(context, false);
|
|
7084
|
-
}
|
|
7085
|
-
}
|
|
7086
|
-
else if (parameter.shouldBeIncluded(context)) {
|
|
7087
|
-
parameter.include(context, false);
|
|
7088
|
-
}
|
|
7089
|
-
}
|
|
7090
|
-
this.scope.includeCallArguments(context, args);
|
|
7091
|
-
}
|
|
7092
|
-
initialise() {
|
|
7093
|
-
this.parameterVariables = this.params.map(param => param.declare('parameter', UNKNOWN_EXPRESSION));
|
|
7094
|
-
this.scope.addParameterVariables(this.parameterVariables, this.params[this.params.length - 1] instanceof RestElement);
|
|
7095
|
-
if (this.body instanceof BlockStatement) {
|
|
7096
|
-
this.body.addImplicitReturnExpressionToScope();
|
|
7097
|
-
}
|
|
7098
|
-
else {
|
|
7099
|
-
this.scope.addReturnExpression(this.body);
|
|
7100
|
-
}
|
|
7101
|
-
}
|
|
7102
|
-
parseNode(esTreeNode) {
|
|
7103
|
-
if (esTreeNode.body.type === BlockStatement$1) {
|
|
7104
|
-
this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
|
|
7105
|
-
}
|
|
7106
|
-
super.parseNode(esTreeNode);
|
|
7107
|
-
}
|
|
7108
|
-
}
|
|
7109
|
-
FunctionBase.prototype.preventChildBlockScope = true;
|
|
7110
|
-
|
|
7111
|
-
class ArrowFunctionExpression extends FunctionBase {
|
|
7112
|
-
constructor() {
|
|
7113
|
-
super(...arguments);
|
|
7114
|
-
this.objectEntity = null;
|
|
7115
|
-
}
|
|
7116
|
-
createScope(parentScope) {
|
|
7117
|
-
this.scope = new ReturnValueScope(parentScope, this.context);
|
|
7118
|
-
}
|
|
7119
|
-
hasEffects() {
|
|
7120
|
-
return false;
|
|
7121
|
-
}
|
|
7122
|
-
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
7123
|
-
if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
|
|
7124
|
-
return true;
|
|
7125
|
-
const { ignore, brokenFlow } = context;
|
|
7126
|
-
context.ignore = {
|
|
7127
|
-
breaks: false,
|
|
7128
|
-
continues: false,
|
|
7129
|
-
labels: new Set(),
|
|
7130
|
-
returnYield: true
|
|
7131
|
-
};
|
|
7132
|
-
if (this.body.hasEffects(context))
|
|
7133
|
-
return true;
|
|
7134
|
-
context.ignore = ignore;
|
|
7135
|
-
context.brokenFlow = brokenFlow;
|
|
7136
|
-
return false;
|
|
7137
|
-
}
|
|
7138
|
-
getObjectEntity() {
|
|
7139
|
-
if (this.objectEntity !== null) {
|
|
7140
|
-
return this.objectEntity;
|
|
7141
|
-
}
|
|
7142
|
-
return (this.objectEntity = new ObjectEntity([], OBJECT_PROTOTYPE));
|
|
7143
|
-
}
|
|
7144
|
-
}
|
|
7145
|
-
|
|
7146
|
-
function getSystemExportStatement(exportedVariables, { exportNamesByVariable, snippets: { _, getObject, getPropertyAccess } }, modifier = '') {
|
|
7147
|
-
if (exportedVariables.length === 1 &&
|
|
7148
|
-
exportNamesByVariable.get(exportedVariables[0]).length === 1) {
|
|
7149
|
-
const variable = exportedVariables[0];
|
|
7150
|
-
return `exports('${exportNamesByVariable.get(variable)}',${_}${variable.getName(getPropertyAccess)}${modifier})`;
|
|
7151
|
-
}
|
|
7152
|
-
else {
|
|
7153
|
-
const fields = [];
|
|
7154
|
-
for (const variable of exportedVariables) {
|
|
7155
|
-
for (const exportName of exportNamesByVariable.get(variable)) {
|
|
7156
|
-
fields.push([exportName, variable.getName(getPropertyAccess) + modifier]);
|
|
7157
|
-
}
|
|
7158
|
-
}
|
|
7159
|
-
return `exports(${getObject(fields, { lineBreakIndent: null })})`;
|
|
7160
|
-
}
|
|
7161
|
-
}
|
|
7162
|
-
function renderSystemExportExpression(exportedVariable, expressionStart, expressionEnd, code, { exportNamesByVariable, snippets: { _ } }) {
|
|
7163
|
-
code.prependRight(expressionStart, `exports('${exportNamesByVariable.get(exportedVariable)}',${_}`);
|
|
7164
|
-
code.appendLeft(expressionEnd, ')');
|
|
7165
|
-
}
|
|
7166
|
-
function renderSystemExportFunction(exportedVariables, expressionStart, expressionEnd, needsParens, code, options) {
|
|
7167
|
-
const { _, getDirectReturnIifeLeft } = options.snippets;
|
|
7168
|
-
code.prependRight(expressionStart, getDirectReturnIifeLeft(['v'], `${getSystemExportStatement(exportedVariables, options)},${_}v`, { needsArrowReturnParens: true, needsWrappedFunction: needsParens }));
|
|
7169
|
-
code.appendLeft(expressionEnd, ')');
|
|
7170
|
-
}
|
|
7171
|
-
function renderSystemExportSequenceAfterExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options) {
|
|
7172
|
-
const { _, getPropertyAccess } = options.snippets;
|
|
7173
|
-
code.appendLeft(expressionEnd, `,${_}${getSystemExportStatement([exportedVariable], options)},${_}${exportedVariable.getName(getPropertyAccess)}`);
|
|
7174
|
-
if (needsParens) {
|
|
7175
|
-
code.prependRight(expressionStart, '(');
|
|
7176
|
-
code.appendLeft(expressionEnd, ')');
|
|
7177
|
-
}
|
|
7178
|
-
}
|
|
7179
|
-
function renderSystemExportSequenceBeforeExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options, modifier) {
|
|
7180
|
-
const { _ } = options.snippets;
|
|
7181
|
-
code.prependRight(expressionStart, `${getSystemExportStatement([exportedVariable], options, modifier)},${_}`);
|
|
7182
|
-
if (needsParens) {
|
|
7183
|
-
code.prependRight(expressionStart, '(');
|
|
7184
|
-
code.appendLeft(expressionEnd, ')');
|
|
7185
|
-
}
|
|
7186
|
-
}
|
|
7187
|
-
|
|
7188
|
-
//@ts-check
|
|
7189
|
-
/** @typedef { import('estree').Node} Node */
|
|
7190
|
-
/** @typedef {Node | {
|
|
7191
|
-
* type: 'PropertyDefinition';
|
|
7192
|
-
* computed: boolean;
|
|
7193
|
-
* value: Node
|
|
7194
|
-
* }} NodeWithPropertyDefinition */
|
|
7195
|
-
|
|
7196
|
-
/**
|
|
7197
|
-
*
|
|
7198
|
-
* @param {NodeWithPropertyDefinition} node
|
|
7199
|
-
* @param {NodeWithPropertyDefinition} parent
|
|
7200
|
-
* @returns boolean
|
|
7201
|
-
*/
|
|
7202
|
-
function is_reference (node, parent) {
|
|
7203
|
-
if (node.type === 'MemberExpression') {
|
|
7204
|
-
return !node.computed && is_reference(node.object, node);
|
|
7205
|
-
}
|
|
7206
|
-
|
|
7207
|
-
if (node.type === 'Identifier') {
|
|
7208
|
-
if (!parent) return true;
|
|
7209
|
-
|
|
7210
|
-
switch (parent.type) {
|
|
7211
|
-
// disregard `bar` in `foo.bar`
|
|
7212
|
-
case 'MemberExpression': return parent.computed || node === parent.object;
|
|
7213
|
-
|
|
7214
|
-
// disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
|
|
7215
|
-
case 'MethodDefinition': return parent.computed;
|
|
7216
|
-
|
|
7217
|
-
// disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
|
|
7218
|
-
case 'PropertyDefinition': return parent.computed || node === parent.value;
|
|
7219
|
-
|
|
7220
|
-
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
|
|
7221
|
-
case 'Property': return parent.computed || node === parent.value;
|
|
7222
|
-
|
|
7223
|
-
// disregard the `bar` in `export { foo as bar }` or
|
|
7224
|
-
// the foo in `import { foo as bar }`
|
|
7225
|
-
case 'ExportSpecifier':
|
|
7226
|
-
case 'ImportSpecifier': return node === parent.local;
|
|
7227
|
-
|
|
7228
|
-
// disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
|
|
7229
|
-
case 'LabeledStatement':
|
|
7230
|
-
case 'BreakStatement':
|
|
7231
|
-
case 'ContinueStatement': return false;
|
|
7232
|
-
default: return true;
|
|
7233
|
-
}
|
|
7234
|
-
}
|
|
7235
|
-
|
|
7236
|
-
return false;
|
|
7237
|
-
}
|
|
7238
|
-
|
|
7239
|
-
/* eslint sort-keys: "off" */
|
|
7240
|
-
const ValueProperties = Symbol('Value Properties');
|
|
7241
|
-
const PURE = {
|
|
7242
|
-
hasEffectsWhenCalled() {
|
|
7243
|
-
return false;
|
|
7244
|
-
}
|
|
7245
|
-
};
|
|
7246
|
-
const IMPURE = {
|
|
7247
|
-
hasEffectsWhenCalled() {
|
|
7248
|
-
return true;
|
|
7249
|
-
}
|
|
7250
|
-
};
|
|
7251
|
-
// We use shortened variables to reduce file size here
|
|
7252
|
-
/* OBJECT */
|
|
7253
|
-
const O = {
|
|
7254
|
-
__proto__: null,
|
|
7255
|
-
[ValueProperties]: IMPURE
|
|
7256
|
-
};
|
|
7257
|
-
/* PURE FUNCTION */
|
|
7258
|
-
const PF = {
|
|
7259
|
-
__proto__: null,
|
|
7260
|
-
[ValueProperties]: PURE
|
|
7261
|
-
};
|
|
7262
|
-
/* FUNCTION THAT MUTATES FIRST ARG WITHOUT TRIGGERING ACCESSORS */
|
|
7263
|
-
const MUTATES_ARG_WITHOUT_ACCESSOR = {
|
|
7264
|
-
__proto__: null,
|
|
7265
|
-
[ValueProperties]: {
|
|
7266
|
-
hasEffectsWhenCalled(callOptions, context) {
|
|
7267
|
-
return (!callOptions.args.length ||
|
|
7268
|
-
callOptions.args[0].hasEffectsWhenAssignedAtPath(UNKNOWN_NON_ACCESSOR_PATH, context));
|
|
6708
|
+
};
|
|
6709
|
+
// We use shortened variables to reduce file size here
|
|
6710
|
+
/* OBJECT */
|
|
6711
|
+
const O = {
|
|
6712
|
+
__proto__: null,
|
|
6713
|
+
[ValueProperties]: IMPURE
|
|
6714
|
+
};
|
|
6715
|
+
/* PURE FUNCTION */
|
|
6716
|
+
const PF = {
|
|
6717
|
+
__proto__: null,
|
|
6718
|
+
[ValueProperties]: PURE
|
|
6719
|
+
};
|
|
6720
|
+
/* FUNCTION THAT MUTATES FIRST ARG WITHOUT TRIGGERING ACCESSORS */
|
|
6721
|
+
const MUTATES_ARG_WITHOUT_ACCESSOR = {
|
|
6722
|
+
__proto__: null,
|
|
6723
|
+
[ValueProperties]: {
|
|
6724
|
+
hasEffectsWhenCalled(callOptions, context) {
|
|
6725
|
+
return (!callOptions.args.length ||
|
|
6726
|
+
callOptions.args[0].hasEffectsWhenAssignedAtPath(UNKNOWN_NON_ACCESSOR_PATH, context));
|
|
7269
6727
|
}
|
|
7270
6728
|
}
|
|
7271
6729
|
};
|
|
@@ -8082,222 +7540,688 @@ const knownGlobals = {
|
|
|
8082
7540
|
for (const global of ['window', 'global', 'self', 'globalThis']) {
|
|
8083
7541
|
knownGlobals[global] = knownGlobals;
|
|
8084
7542
|
}
|
|
8085
|
-
function getGlobalAtPath(path) {
|
|
8086
|
-
let currentGlobal = knownGlobals;
|
|
8087
|
-
for (const pathSegment of path) {
|
|
8088
|
-
if (typeof pathSegment !== 'string') {
|
|
8089
|
-
return null;
|
|
7543
|
+
function getGlobalAtPath(path) {
|
|
7544
|
+
let currentGlobal = knownGlobals;
|
|
7545
|
+
for (const pathSegment of path) {
|
|
7546
|
+
if (typeof pathSegment !== 'string') {
|
|
7547
|
+
return null;
|
|
7548
|
+
}
|
|
7549
|
+
currentGlobal = currentGlobal[pathSegment];
|
|
7550
|
+
if (!currentGlobal) {
|
|
7551
|
+
return null;
|
|
7552
|
+
}
|
|
7553
|
+
}
|
|
7554
|
+
return currentGlobal[ValueProperties];
|
|
7555
|
+
}
|
|
7556
|
+
|
|
7557
|
+
class GlobalVariable extends Variable {
|
|
7558
|
+
constructor() {
|
|
7559
|
+
super(...arguments);
|
|
7560
|
+
// Ensure we use live-bindings for globals as we do not know if they have
|
|
7561
|
+
// been reassigned
|
|
7562
|
+
this.isReassigned = true;
|
|
7563
|
+
}
|
|
7564
|
+
getLiteralValueAtPath(path, _recursionTracker, _origin) {
|
|
7565
|
+
return getGlobalAtPath([this.name, ...path]) ? UnknownTruthyValue : UnknownValue;
|
|
7566
|
+
}
|
|
7567
|
+
hasEffectsWhenAccessedAtPath(path) {
|
|
7568
|
+
if (path.length === 0) {
|
|
7569
|
+
// Technically, "undefined" is a global variable of sorts
|
|
7570
|
+
return this.name !== 'undefined' && !getGlobalAtPath([this.name]);
|
|
7571
|
+
}
|
|
7572
|
+
return !getGlobalAtPath([this.name, ...path].slice(0, -1));
|
|
7573
|
+
}
|
|
7574
|
+
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
7575
|
+
const globalAtPath = getGlobalAtPath([this.name, ...path]);
|
|
7576
|
+
return !globalAtPath || globalAtPath.hasEffectsWhenCalled(callOptions, context);
|
|
7577
|
+
}
|
|
7578
|
+
}
|
|
7579
|
+
|
|
7580
|
+
const tdzVariableKinds = {
|
|
7581
|
+
__proto__: null,
|
|
7582
|
+
class: true,
|
|
7583
|
+
const: true,
|
|
7584
|
+
let: true,
|
|
7585
|
+
var: true
|
|
7586
|
+
};
|
|
7587
|
+
class Identifier extends NodeBase {
|
|
7588
|
+
constructor() {
|
|
7589
|
+
super(...arguments);
|
|
7590
|
+
this.variable = null;
|
|
7591
|
+
this.isTDZAccess = null;
|
|
7592
|
+
}
|
|
7593
|
+
addExportedVariables(variables, exportNamesByVariable) {
|
|
7594
|
+
if (exportNamesByVariable.has(this.variable)) {
|
|
7595
|
+
variables.push(this.variable);
|
|
7596
|
+
}
|
|
7597
|
+
}
|
|
7598
|
+
bind() {
|
|
7599
|
+
if (!this.variable && is_reference(this, this.parent)) {
|
|
7600
|
+
this.variable = this.scope.findVariable(this.name);
|
|
7601
|
+
this.variable.addReference(this);
|
|
7602
|
+
}
|
|
7603
|
+
}
|
|
7604
|
+
declare(kind, init) {
|
|
7605
|
+
let variable;
|
|
7606
|
+
const { treeshake } = this.context.options;
|
|
7607
|
+
switch (kind) {
|
|
7608
|
+
case 'var':
|
|
7609
|
+
variable = this.scope.addDeclaration(this, this.context, init, true);
|
|
7610
|
+
if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
|
|
7611
|
+
// Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
|
|
7612
|
+
variable.markInitializersForDeoptimization();
|
|
7613
|
+
}
|
|
7614
|
+
break;
|
|
7615
|
+
case 'function':
|
|
7616
|
+
// in strict mode, functions are only hoisted within a scope but not across block scopes
|
|
7617
|
+
variable = this.scope.addDeclaration(this, this.context, init, false);
|
|
7618
|
+
break;
|
|
7619
|
+
case 'let':
|
|
7620
|
+
case 'const':
|
|
7621
|
+
case 'class':
|
|
7622
|
+
variable = this.scope.addDeclaration(this, this.context, init, false);
|
|
7623
|
+
break;
|
|
7624
|
+
case 'parameter':
|
|
7625
|
+
variable = this.scope.addParameterDeclaration(this);
|
|
7626
|
+
break;
|
|
7627
|
+
/* istanbul ignore next */
|
|
7628
|
+
default:
|
|
7629
|
+
/* istanbul ignore next */
|
|
7630
|
+
throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
|
|
7631
|
+
}
|
|
7632
|
+
variable.kind = kind;
|
|
7633
|
+
return [(this.variable = variable)];
|
|
7634
|
+
}
|
|
7635
|
+
deoptimizePath(path) {
|
|
7636
|
+
var _a;
|
|
7637
|
+
if (path.length === 0 && !this.scope.contains(this.name)) {
|
|
7638
|
+
this.disallowImportReassignment();
|
|
7639
|
+
}
|
|
7640
|
+
// We keep conditional chaining because an unknown Node could have an
|
|
7641
|
+
// Identifier as property that might be deoptimized by default
|
|
7642
|
+
(_a = this.variable) === null || _a === void 0 ? void 0 : _a.deoptimizePath(path);
|
|
7643
|
+
}
|
|
7644
|
+
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
7645
|
+
this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
7646
|
+
}
|
|
7647
|
+
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
7648
|
+
return this.getVariableRespectingTDZ().getLiteralValueAtPath(path, recursionTracker, origin);
|
|
7649
|
+
}
|
|
7650
|
+
getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
|
|
7651
|
+
return this.getVariableRespectingTDZ().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
|
|
7652
|
+
}
|
|
7653
|
+
hasEffects() {
|
|
7654
|
+
if (!this.deoptimized)
|
|
7655
|
+
this.applyDeoptimizations();
|
|
7656
|
+
if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
|
|
7657
|
+
return true;
|
|
7658
|
+
}
|
|
7659
|
+
return (this.context.options.treeshake.unknownGlobalSideEffects &&
|
|
7660
|
+
this.variable instanceof GlobalVariable &&
|
|
7661
|
+
this.variable.hasEffectsWhenAccessedAtPath(EMPTY_PATH));
|
|
7662
|
+
}
|
|
7663
|
+
hasEffectsWhenAccessedAtPath(path, context) {
|
|
7664
|
+
return (this.variable !== null &&
|
|
7665
|
+
this.getVariableRespectingTDZ().hasEffectsWhenAccessedAtPath(path, context));
|
|
7666
|
+
}
|
|
7667
|
+
hasEffectsWhenAssignedAtPath(path, context) {
|
|
7668
|
+
return (path.length > 0 ? this.getVariableRespectingTDZ() : this.variable).hasEffectsWhenAssignedAtPath(path, context);
|
|
7669
|
+
}
|
|
7670
|
+
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
7671
|
+
return this.getVariableRespectingTDZ().hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
7672
|
+
}
|
|
7673
|
+
include() {
|
|
7674
|
+
if (!this.deoptimized)
|
|
7675
|
+
this.applyDeoptimizations();
|
|
7676
|
+
if (!this.included) {
|
|
7677
|
+
this.included = true;
|
|
7678
|
+
if (this.variable !== null) {
|
|
7679
|
+
this.context.includeVariableInModule(this.variable);
|
|
7680
|
+
}
|
|
7681
|
+
}
|
|
7682
|
+
}
|
|
7683
|
+
includeCallArguments(context, args) {
|
|
7684
|
+
this.variable.includeCallArguments(context, args);
|
|
7685
|
+
}
|
|
7686
|
+
isPossibleTDZ() {
|
|
7687
|
+
// return cached value to avoid issues with the next tree-shaking pass
|
|
7688
|
+
if (this.isTDZAccess !== null)
|
|
7689
|
+
return this.isTDZAccess;
|
|
7690
|
+
if (!(this.variable instanceof LocalVariable) ||
|
|
7691
|
+
!this.variable.kind ||
|
|
7692
|
+
!(this.variable.kind in tdzVariableKinds)) {
|
|
7693
|
+
return (this.isTDZAccess = false);
|
|
7694
|
+
}
|
|
7695
|
+
let decl_id;
|
|
7696
|
+
if (this.variable.declarations &&
|
|
7697
|
+
this.variable.declarations.length === 1 &&
|
|
7698
|
+
(decl_id = this.variable.declarations[0]) &&
|
|
7699
|
+
this.start < decl_id.start &&
|
|
7700
|
+
closestParentFunctionOrProgram(this) === closestParentFunctionOrProgram(decl_id)) {
|
|
7701
|
+
// a variable accessed before its declaration
|
|
7702
|
+
// in the same function or at top level of module
|
|
7703
|
+
return (this.isTDZAccess = true);
|
|
7704
|
+
}
|
|
7705
|
+
if (!this.variable.initReached) {
|
|
7706
|
+
// Either a const/let TDZ violation or
|
|
7707
|
+
// var use before declaration was encountered.
|
|
7708
|
+
return (this.isTDZAccess = true);
|
|
7709
|
+
}
|
|
7710
|
+
return (this.isTDZAccess = false);
|
|
7711
|
+
}
|
|
7712
|
+
markDeclarationReached() {
|
|
7713
|
+
this.variable.initReached = true;
|
|
7714
|
+
}
|
|
7715
|
+
render(code, { snippets: { getPropertyAccess } }, { renderedParentType, isCalleeOfRenderedParent, isShorthandProperty } = BLANK) {
|
|
7716
|
+
if (this.variable) {
|
|
7717
|
+
const name = this.variable.getName(getPropertyAccess);
|
|
7718
|
+
if (name !== this.name) {
|
|
7719
|
+
code.overwrite(this.start, this.end, name, {
|
|
7720
|
+
contentOnly: true,
|
|
7721
|
+
storeName: true
|
|
7722
|
+
});
|
|
7723
|
+
if (isShorthandProperty) {
|
|
7724
|
+
code.prependRight(this.start, `${this.name}: `);
|
|
7725
|
+
}
|
|
7726
|
+
}
|
|
7727
|
+
// In strict mode, any variable named "eval" must be the actual "eval" function
|
|
7728
|
+
if (name === 'eval' &&
|
|
7729
|
+
renderedParentType === CallExpression$1 &&
|
|
7730
|
+
isCalleeOfRenderedParent) {
|
|
7731
|
+
code.appendRight(this.start, '0, ');
|
|
7732
|
+
}
|
|
7733
|
+
}
|
|
7734
|
+
}
|
|
7735
|
+
applyDeoptimizations() {
|
|
7736
|
+
this.deoptimized = true;
|
|
7737
|
+
if (this.variable instanceof LocalVariable) {
|
|
7738
|
+
this.variable.consolidateInitializers();
|
|
7739
|
+
this.context.requestTreeshakingPass();
|
|
7740
|
+
}
|
|
7741
|
+
}
|
|
7742
|
+
disallowImportReassignment() {
|
|
7743
|
+
return this.context.error({
|
|
7744
|
+
code: 'ILLEGAL_REASSIGNMENT',
|
|
7745
|
+
message: `Illegal reassignment to import '${this.name}'`
|
|
7746
|
+
}, this.start);
|
|
7747
|
+
}
|
|
7748
|
+
getVariableRespectingTDZ() {
|
|
7749
|
+
if (this.isPossibleTDZ()) {
|
|
7750
|
+
return UNKNOWN_EXPRESSION;
|
|
7751
|
+
}
|
|
7752
|
+
return this.variable;
|
|
7753
|
+
}
|
|
7754
|
+
}
|
|
7755
|
+
function closestParentFunctionOrProgram(node) {
|
|
7756
|
+
while (node && !/^Program|Function/.test(node.type)) {
|
|
7757
|
+
node = node.parent;
|
|
7758
|
+
}
|
|
7759
|
+
// one of: ArrowFunctionExpression, FunctionDeclaration, FunctionExpression or Program
|
|
7760
|
+
return node;
|
|
7761
|
+
}
|
|
7762
|
+
|
|
7763
|
+
function treeshakeNode(node, code, start, end) {
|
|
7764
|
+
code.remove(start, end);
|
|
7765
|
+
if (node.annotations) {
|
|
7766
|
+
for (const annotation of node.annotations) {
|
|
7767
|
+
if (annotation.start < start) {
|
|
7768
|
+
code.remove(annotation.start, annotation.end);
|
|
7769
|
+
}
|
|
7770
|
+
else {
|
|
7771
|
+
return;
|
|
7772
|
+
}
|
|
7773
|
+
}
|
|
7774
|
+
}
|
|
7775
|
+
}
|
|
7776
|
+
function removeAnnotations(node, code) {
|
|
7777
|
+
if (!node.annotations && node.parent.type === ExpressionStatement$1) {
|
|
7778
|
+
node = node.parent;
|
|
7779
|
+
}
|
|
7780
|
+
if (node.annotations) {
|
|
7781
|
+
for (const annotation of node.annotations) {
|
|
7782
|
+
code.remove(annotation.start, annotation.end);
|
|
7783
|
+
}
|
|
7784
|
+
}
|
|
7785
|
+
}
|
|
7786
|
+
|
|
7787
|
+
const NO_SEMICOLON = { isNoStatement: true };
|
|
7788
|
+
// This assumes there are only white-space and comments between start and the string we are looking for
|
|
7789
|
+
function findFirstOccurrenceOutsideComment(code, searchString, start = 0) {
|
|
7790
|
+
let searchPos, charCodeAfterSlash;
|
|
7791
|
+
searchPos = code.indexOf(searchString, start);
|
|
7792
|
+
while (true) {
|
|
7793
|
+
start = code.indexOf('/', start);
|
|
7794
|
+
if (start === -1 || start >= searchPos)
|
|
7795
|
+
return searchPos;
|
|
7796
|
+
charCodeAfterSlash = code.charCodeAt(++start);
|
|
7797
|
+
++start;
|
|
7798
|
+
// With our assumption, '/' always starts a comment. Determine comment type:
|
|
7799
|
+
start =
|
|
7800
|
+
charCodeAfterSlash === 47 /*"/"*/
|
|
7801
|
+
? code.indexOf('\n', start) + 1
|
|
7802
|
+
: code.indexOf('*/', start) + 2;
|
|
7803
|
+
if (start > searchPos) {
|
|
7804
|
+
searchPos = code.indexOf(searchString, start);
|
|
7805
|
+
}
|
|
7806
|
+
}
|
|
7807
|
+
}
|
|
7808
|
+
const NON_WHITESPACE = /\S/g;
|
|
7809
|
+
function findNonWhiteSpace(code, index) {
|
|
7810
|
+
NON_WHITESPACE.lastIndex = index;
|
|
7811
|
+
const result = NON_WHITESPACE.exec(code);
|
|
7812
|
+
return result.index;
|
|
7813
|
+
}
|
|
7814
|
+
// This assumes "code" only contains white-space and comments
|
|
7815
|
+
// Returns position of line-comment if applicable
|
|
7816
|
+
function findFirstLineBreakOutsideComment(code) {
|
|
7817
|
+
let lineBreakPos, charCodeAfterSlash, start = 0;
|
|
7818
|
+
lineBreakPos = code.indexOf('\n', start);
|
|
7819
|
+
while (true) {
|
|
7820
|
+
start = code.indexOf('/', start);
|
|
7821
|
+
if (start === -1 || start > lineBreakPos)
|
|
7822
|
+
return [lineBreakPos, lineBreakPos + 1];
|
|
7823
|
+
// With our assumption, '/' always starts a comment. Determine comment type:
|
|
7824
|
+
charCodeAfterSlash = code.charCodeAt(start + 1);
|
|
7825
|
+
if (charCodeAfterSlash === 47 /*"/"*/)
|
|
7826
|
+
return [start, lineBreakPos + 1];
|
|
7827
|
+
start = code.indexOf('*/', start + 3) + 2;
|
|
7828
|
+
if (start > lineBreakPos) {
|
|
7829
|
+
lineBreakPos = code.indexOf('\n', start);
|
|
7830
|
+
}
|
|
7831
|
+
}
|
|
7832
|
+
}
|
|
7833
|
+
function renderStatementList(statements, code, start, end, options) {
|
|
7834
|
+
let currentNode, currentNodeStart, currentNodeNeedsBoundaries, nextNodeStart;
|
|
7835
|
+
let nextNode = statements[0];
|
|
7836
|
+
let nextNodeNeedsBoundaries = !nextNode.included || nextNode.needsBoundaries;
|
|
7837
|
+
if (nextNodeNeedsBoundaries) {
|
|
7838
|
+
nextNodeStart =
|
|
7839
|
+
start + findFirstLineBreakOutsideComment(code.original.slice(start, nextNode.start))[1];
|
|
7840
|
+
}
|
|
7841
|
+
for (let nextIndex = 1; nextIndex <= statements.length; nextIndex++) {
|
|
7842
|
+
currentNode = nextNode;
|
|
7843
|
+
currentNodeStart = nextNodeStart;
|
|
7844
|
+
currentNodeNeedsBoundaries = nextNodeNeedsBoundaries;
|
|
7845
|
+
nextNode = statements[nextIndex];
|
|
7846
|
+
nextNodeNeedsBoundaries =
|
|
7847
|
+
nextNode === undefined ? false : !nextNode.included || nextNode.needsBoundaries;
|
|
7848
|
+
if (currentNodeNeedsBoundaries || nextNodeNeedsBoundaries) {
|
|
7849
|
+
nextNodeStart =
|
|
7850
|
+
currentNode.end +
|
|
7851
|
+
findFirstLineBreakOutsideComment(code.original.slice(currentNode.end, nextNode === undefined ? end : nextNode.start))[1];
|
|
7852
|
+
if (currentNode.included) {
|
|
7853
|
+
currentNodeNeedsBoundaries
|
|
7854
|
+
? currentNode.render(code, options, {
|
|
7855
|
+
end: nextNodeStart,
|
|
7856
|
+
start: currentNodeStart
|
|
7857
|
+
})
|
|
7858
|
+
: currentNode.render(code, options);
|
|
7859
|
+
}
|
|
7860
|
+
else {
|
|
7861
|
+
treeshakeNode(currentNode, code, currentNodeStart, nextNodeStart);
|
|
7862
|
+
}
|
|
7863
|
+
}
|
|
7864
|
+
else {
|
|
7865
|
+
currentNode.render(code, options);
|
|
7866
|
+
}
|
|
7867
|
+
}
|
|
7868
|
+
}
|
|
7869
|
+
// This assumes that the first character is not part of the first node
|
|
7870
|
+
function getCommaSeparatedNodesWithBoundaries(nodes, code, start, end) {
|
|
7871
|
+
const splitUpNodes = [];
|
|
7872
|
+
let node, nextNode, nextNodeStart, contentEnd, char;
|
|
7873
|
+
let separator = start - 1;
|
|
7874
|
+
for (let nextIndex = 0; nextIndex < nodes.length; nextIndex++) {
|
|
7875
|
+
nextNode = nodes[nextIndex];
|
|
7876
|
+
if (node !== undefined) {
|
|
7877
|
+
separator =
|
|
7878
|
+
node.end +
|
|
7879
|
+
findFirstOccurrenceOutsideComment(code.original.slice(node.end, nextNode.start), ',');
|
|
7880
|
+
}
|
|
7881
|
+
nextNodeStart = contentEnd =
|
|
7882
|
+
separator +
|
|
7883
|
+
1 +
|
|
7884
|
+
findFirstLineBreakOutsideComment(code.original.slice(separator + 1, nextNode.start))[1];
|
|
7885
|
+
while (((char = code.original.charCodeAt(nextNodeStart)),
|
|
7886
|
+
char === 32 /*" "*/ || char === 9 /*"\t"*/ || char === 10 /*"\n"*/ || char === 13) /*"\r"*/)
|
|
7887
|
+
nextNodeStart++;
|
|
7888
|
+
if (node !== undefined) {
|
|
7889
|
+
splitUpNodes.push({
|
|
7890
|
+
contentEnd,
|
|
7891
|
+
end: nextNodeStart,
|
|
7892
|
+
node,
|
|
7893
|
+
separator,
|
|
7894
|
+
start
|
|
7895
|
+
});
|
|
7896
|
+
}
|
|
7897
|
+
node = nextNode;
|
|
7898
|
+
start = nextNodeStart;
|
|
7899
|
+
}
|
|
7900
|
+
splitUpNodes.push({
|
|
7901
|
+
contentEnd: end,
|
|
7902
|
+
end,
|
|
7903
|
+
node: node,
|
|
7904
|
+
separator: null,
|
|
7905
|
+
start
|
|
7906
|
+
});
|
|
7907
|
+
return splitUpNodes;
|
|
7908
|
+
}
|
|
7909
|
+
// This assumes there are only white-space and comments between start and end
|
|
7910
|
+
function removeLineBreaks(code, start, end) {
|
|
7911
|
+
while (true) {
|
|
7912
|
+
const [removeStart, removeEnd] = findFirstLineBreakOutsideComment(code.original.slice(start, end));
|
|
7913
|
+
if (removeStart === -1) {
|
|
7914
|
+
break;
|
|
7915
|
+
}
|
|
7916
|
+
code.remove(start + removeStart, (start += removeEnd));
|
|
7917
|
+
}
|
|
7918
|
+
}
|
|
7919
|
+
|
|
7920
|
+
class BlockScope extends ChildScope {
|
|
7921
|
+
addDeclaration(identifier, context, init, isHoisted) {
|
|
7922
|
+
if (isHoisted) {
|
|
7923
|
+
const variable = this.parent.addDeclaration(identifier, context, init, isHoisted);
|
|
7924
|
+
// Necessary to make sure the init is deoptimized for conditional declarations.
|
|
7925
|
+
// We cannot call deoptimizePath here.
|
|
7926
|
+
variable.markInitializersForDeoptimization();
|
|
7927
|
+
return variable;
|
|
8090
7928
|
}
|
|
8091
|
-
|
|
8092
|
-
|
|
8093
|
-
return null;
|
|
7929
|
+
else {
|
|
7930
|
+
return super.addDeclaration(identifier, context, init, false);
|
|
8094
7931
|
}
|
|
8095
7932
|
}
|
|
8096
|
-
return currentGlobal[ValueProperties];
|
|
8097
7933
|
}
|
|
8098
7934
|
|
|
8099
|
-
class
|
|
7935
|
+
class ExpressionStatement extends NodeBase {
|
|
7936
|
+
initialise() {
|
|
7937
|
+
if (this.directive &&
|
|
7938
|
+
this.directive !== 'use strict' &&
|
|
7939
|
+
this.parent.type === Program$1) {
|
|
7940
|
+
this.context.warn(
|
|
7941
|
+
// This is necessary, because either way (deleting or not) can lead to errors.
|
|
7942
|
+
{
|
|
7943
|
+
code: 'MODULE_LEVEL_DIRECTIVE',
|
|
7944
|
+
message: `Module level directives cause errors when bundled, '${this.directive}' was ignored.`
|
|
7945
|
+
}, this.start);
|
|
7946
|
+
}
|
|
7947
|
+
}
|
|
7948
|
+
render(code, options) {
|
|
7949
|
+
super.render(code, options);
|
|
7950
|
+
if (this.included)
|
|
7951
|
+
this.insertSemicolon(code);
|
|
7952
|
+
}
|
|
7953
|
+
shouldBeIncluded(context) {
|
|
7954
|
+
if (this.directive && this.directive !== 'use strict')
|
|
7955
|
+
return this.parent.type !== Program$1;
|
|
7956
|
+
return super.shouldBeIncluded(context);
|
|
7957
|
+
}
|
|
7958
|
+
applyDeoptimizations() { }
|
|
7959
|
+
}
|
|
7960
|
+
|
|
7961
|
+
class BlockStatement extends NodeBase {
|
|
8100
7962
|
constructor() {
|
|
8101
7963
|
super(...arguments);
|
|
8102
|
-
|
|
8103
|
-
// been reassigned
|
|
8104
|
-
this.isReassigned = true;
|
|
7964
|
+
this.directlyIncluded = false;
|
|
8105
7965
|
}
|
|
8106
|
-
|
|
8107
|
-
|
|
7966
|
+
addImplicitReturnExpressionToScope() {
|
|
7967
|
+
const lastStatement = this.body[this.body.length - 1];
|
|
7968
|
+
if (!lastStatement || lastStatement.type !== ReturnStatement$1) {
|
|
7969
|
+
this.scope.addReturnExpression(UNKNOWN_EXPRESSION);
|
|
7970
|
+
}
|
|
8108
7971
|
}
|
|
8109
|
-
|
|
8110
|
-
|
|
8111
|
-
|
|
8112
|
-
|
|
7972
|
+
createScope(parentScope) {
|
|
7973
|
+
this.scope = this.parent.preventChildBlockScope
|
|
7974
|
+
? parentScope
|
|
7975
|
+
: new BlockScope(parentScope);
|
|
7976
|
+
}
|
|
7977
|
+
hasEffects(context) {
|
|
7978
|
+
if (this.deoptimizeBody)
|
|
7979
|
+
return true;
|
|
7980
|
+
for (const node of this.body) {
|
|
7981
|
+
if (context.brokenFlow)
|
|
7982
|
+
break;
|
|
7983
|
+
if (node.hasEffects(context))
|
|
7984
|
+
return true;
|
|
8113
7985
|
}
|
|
8114
|
-
return
|
|
7986
|
+
return false;
|
|
8115
7987
|
}
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
|
|
7988
|
+
include(context, includeChildrenRecursively) {
|
|
7989
|
+
if (!(this.deoptimizeBody && this.directlyIncluded)) {
|
|
7990
|
+
this.included = true;
|
|
7991
|
+
this.directlyIncluded = true;
|
|
7992
|
+
if (this.deoptimizeBody)
|
|
7993
|
+
includeChildrenRecursively = true;
|
|
7994
|
+
for (const node of this.body) {
|
|
7995
|
+
if (includeChildrenRecursively || node.shouldBeIncluded(context))
|
|
7996
|
+
node.include(context, includeChildrenRecursively);
|
|
7997
|
+
}
|
|
7998
|
+
}
|
|
7999
|
+
}
|
|
8000
|
+
initialise() {
|
|
8001
|
+
const firstBodyStatement = this.body[0];
|
|
8002
|
+
this.deoptimizeBody =
|
|
8003
|
+
firstBodyStatement instanceof ExpressionStatement &&
|
|
8004
|
+
firstBodyStatement.directive === 'use asm';
|
|
8005
|
+
}
|
|
8006
|
+
render(code, options) {
|
|
8007
|
+
if (this.body.length) {
|
|
8008
|
+
renderStatementList(this.body, code, this.start + 1, this.end - 1, options);
|
|
8009
|
+
}
|
|
8010
|
+
else {
|
|
8011
|
+
super.render(code, options);
|
|
8012
|
+
}
|
|
8119
8013
|
}
|
|
8120
8014
|
}
|
|
8121
8015
|
|
|
8122
|
-
|
|
8123
|
-
__proto__: null,
|
|
8124
|
-
class: true,
|
|
8125
|
-
const: true,
|
|
8126
|
-
let: true,
|
|
8127
|
-
var: true
|
|
8128
|
-
};
|
|
8129
|
-
class Identifier extends NodeBase {
|
|
8016
|
+
class RestElement extends NodeBase {
|
|
8130
8017
|
constructor() {
|
|
8131
8018
|
super(...arguments);
|
|
8132
|
-
this.
|
|
8133
|
-
this.deoptimized = false;
|
|
8134
|
-
this.isTDZAccess = null;
|
|
8019
|
+
this.declarationInit = null;
|
|
8135
8020
|
}
|
|
8136
8021
|
addExportedVariables(variables, exportNamesByVariable) {
|
|
8137
|
-
|
|
8138
|
-
variables.push(this.variable);
|
|
8139
|
-
}
|
|
8140
|
-
}
|
|
8141
|
-
bind() {
|
|
8142
|
-
if (!this.variable && is_reference(this, this.parent)) {
|
|
8143
|
-
this.variable = this.scope.findVariable(this.name);
|
|
8144
|
-
this.variable.addReference(this);
|
|
8145
|
-
}
|
|
8022
|
+
this.argument.addExportedVariables(variables, exportNamesByVariable);
|
|
8146
8023
|
}
|
|
8147
8024
|
declare(kind, init) {
|
|
8148
|
-
|
|
8149
|
-
|
|
8150
|
-
|
|
8151
|
-
|
|
8152
|
-
|
|
8153
|
-
|
|
8154
|
-
|
|
8155
|
-
|
|
8156
|
-
|
|
8157
|
-
|
|
8158
|
-
|
|
8159
|
-
|
|
8160
|
-
|
|
8161
|
-
|
|
8162
|
-
|
|
8163
|
-
|
|
8164
|
-
|
|
8165
|
-
variable = this.scope.addDeclaration(this, this.context, init, false);
|
|
8166
|
-
break;
|
|
8167
|
-
case 'parameter':
|
|
8168
|
-
variable = this.scope.addParameterDeclaration(this);
|
|
8169
|
-
break;
|
|
8170
|
-
/* istanbul ignore next */
|
|
8171
|
-
default:
|
|
8172
|
-
/* istanbul ignore next */
|
|
8173
|
-
throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
|
|
8025
|
+
this.declarationInit = init;
|
|
8026
|
+
return this.argument.declare(kind, UNKNOWN_EXPRESSION);
|
|
8027
|
+
}
|
|
8028
|
+
deoptimizePath(path) {
|
|
8029
|
+
path.length === 0 && this.argument.deoptimizePath(EMPTY_PATH);
|
|
8030
|
+
}
|
|
8031
|
+
hasEffectsWhenAssignedAtPath(path, context) {
|
|
8032
|
+
return path.length > 0 || this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
|
|
8033
|
+
}
|
|
8034
|
+
markDeclarationReached() {
|
|
8035
|
+
this.argument.markDeclarationReached();
|
|
8036
|
+
}
|
|
8037
|
+
applyDeoptimizations() {
|
|
8038
|
+
this.deoptimized = true;
|
|
8039
|
+
if (this.declarationInit !== null) {
|
|
8040
|
+
this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
|
|
8041
|
+
this.context.requestTreeshakingPass();
|
|
8174
8042
|
}
|
|
8175
|
-
|
|
8176
|
-
|
|
8043
|
+
}
|
|
8044
|
+
}
|
|
8045
|
+
|
|
8046
|
+
class FunctionBase extends NodeBase {
|
|
8047
|
+
constructor() {
|
|
8048
|
+
super(...arguments);
|
|
8049
|
+
this.objectEntity = null;
|
|
8050
|
+
this.deoptimizedReturn = false;
|
|
8177
8051
|
}
|
|
8178
8052
|
deoptimizePath(path) {
|
|
8179
|
-
|
|
8180
|
-
|
|
8053
|
+
this.getObjectEntity().deoptimizePath(path);
|
|
8054
|
+
if (path.length === 1 && path[0] === UnknownKey) {
|
|
8055
|
+
// A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
|
|
8056
|
+
// which means the return expression needs to be reassigned
|
|
8057
|
+
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
8181
8058
|
}
|
|
8182
|
-
this.variable.deoptimizePath(path);
|
|
8183
8059
|
}
|
|
8184
8060
|
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
8185
|
-
|
|
8061
|
+
if (path.length > 0) {
|
|
8062
|
+
this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
8063
|
+
}
|
|
8186
8064
|
}
|
|
8187
8065
|
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
8188
|
-
return this.
|
|
8066
|
+
return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
|
|
8189
8067
|
}
|
|
8190
8068
|
getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
|
|
8191
|
-
|
|
8192
|
-
|
|
8193
|
-
hasEffects() {
|
|
8194
|
-
if (!this.deoptimized)
|
|
8195
|
-
this.applyDeoptimizations();
|
|
8196
|
-
if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
|
|
8197
|
-
return true;
|
|
8069
|
+
if (path.length > 0) {
|
|
8070
|
+
return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
|
|
8198
8071
|
}
|
|
8199
|
-
|
|
8200
|
-
this.
|
|
8201
|
-
|
|
8072
|
+
if (this.async) {
|
|
8073
|
+
if (!this.deoptimizedReturn) {
|
|
8074
|
+
this.deoptimizedReturn = true;
|
|
8075
|
+
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
8076
|
+
this.context.requestTreeshakingPass();
|
|
8077
|
+
}
|
|
8078
|
+
return UNKNOWN_EXPRESSION;
|
|
8079
|
+
}
|
|
8080
|
+
return this.scope.getReturnExpression();
|
|
8202
8081
|
}
|
|
8203
8082
|
hasEffectsWhenAccessedAtPath(path, context) {
|
|
8204
|
-
return
|
|
8205
|
-
this.getVariableRespectingTDZ().hasEffectsWhenAccessedAtPath(path, context));
|
|
8083
|
+
return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
|
|
8206
8084
|
}
|
|
8207
8085
|
hasEffectsWhenAssignedAtPath(path, context) {
|
|
8208
|
-
return
|
|
8086
|
+
return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
|
|
8209
8087
|
}
|
|
8210
8088
|
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
8211
|
-
|
|
8089
|
+
if (path.length > 0) {
|
|
8090
|
+
return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
8091
|
+
}
|
|
8092
|
+
if (this.async) {
|
|
8093
|
+
const { propertyReadSideEffects } = this.context.options
|
|
8094
|
+
.treeshake;
|
|
8095
|
+
const returnExpression = this.scope.getReturnExpression();
|
|
8096
|
+
if (returnExpression.hasEffectsWhenCalledAtPath(['then'], { args: NO_ARGS, thisParam: null, withNew: false }, context) ||
|
|
8097
|
+
(propertyReadSideEffects &&
|
|
8098
|
+
(propertyReadSideEffects === 'always' ||
|
|
8099
|
+
returnExpression.hasEffectsWhenAccessedAtPath(['then'], context)))) {
|
|
8100
|
+
return true;
|
|
8101
|
+
}
|
|
8102
|
+
}
|
|
8103
|
+
for (const param of this.params) {
|
|
8104
|
+
if (param.hasEffects(context))
|
|
8105
|
+
return true;
|
|
8106
|
+
}
|
|
8107
|
+
return false;
|
|
8212
8108
|
}
|
|
8213
|
-
include() {
|
|
8109
|
+
include(context, includeChildrenRecursively) {
|
|
8214
8110
|
if (!this.deoptimized)
|
|
8215
8111
|
this.applyDeoptimizations();
|
|
8216
|
-
|
|
8217
|
-
|
|
8218
|
-
|
|
8219
|
-
|
|
8220
|
-
|
|
8221
|
-
}
|
|
8112
|
+
this.included = true;
|
|
8113
|
+
const { brokenFlow } = context;
|
|
8114
|
+
context.brokenFlow = BROKEN_FLOW_NONE;
|
|
8115
|
+
this.body.include(context, includeChildrenRecursively);
|
|
8116
|
+
context.brokenFlow = brokenFlow;
|
|
8222
8117
|
}
|
|
8223
8118
|
includeCallArguments(context, args) {
|
|
8224
|
-
this.
|
|
8225
|
-
}
|
|
8226
|
-
|
|
8227
|
-
|
|
8228
|
-
if (this.
|
|
8229
|
-
|
|
8230
|
-
if (!(this.variable instanceof LocalVariable) ||
|
|
8231
|
-
!this.variable.kind ||
|
|
8232
|
-
!(this.variable.kind in tdzVariableKinds)) {
|
|
8233
|
-
return (this.isTDZAccess = false);
|
|
8119
|
+
this.scope.includeCallArguments(context, args);
|
|
8120
|
+
}
|
|
8121
|
+
initialise() {
|
|
8122
|
+
this.scope.addParameterVariables(this.params.map(param => param.declare('parameter', UNKNOWN_EXPRESSION)), this.params[this.params.length - 1] instanceof RestElement);
|
|
8123
|
+
if (this.body instanceof BlockStatement) {
|
|
8124
|
+
this.body.addImplicitReturnExpressionToScope();
|
|
8234
8125
|
}
|
|
8235
|
-
|
|
8236
|
-
|
|
8237
|
-
this.variable.declarations.length === 1 &&
|
|
8238
|
-
(decl_id = this.variable.declarations[0]) &&
|
|
8239
|
-
this.start < decl_id.start &&
|
|
8240
|
-
closestParentFunctionOrProgram(this) === closestParentFunctionOrProgram(decl_id)) {
|
|
8241
|
-
// a variable accessed before its declaration
|
|
8242
|
-
// in the same function or at top level of module
|
|
8243
|
-
return (this.isTDZAccess = true);
|
|
8126
|
+
else {
|
|
8127
|
+
this.scope.addReturnExpression(this.body);
|
|
8244
8128
|
}
|
|
8245
|
-
|
|
8246
|
-
|
|
8247
|
-
|
|
8248
|
-
|
|
8129
|
+
}
|
|
8130
|
+
parseNode(esTreeNode) {
|
|
8131
|
+
if (esTreeNode.body.type === BlockStatement$1) {
|
|
8132
|
+
this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
|
|
8249
8133
|
}
|
|
8250
|
-
|
|
8134
|
+
super.parseNode(esTreeNode);
|
|
8251
8135
|
}
|
|
8252
|
-
|
|
8253
|
-
|
|
8136
|
+
applyDeoptimizations() { }
|
|
8137
|
+
}
|
|
8138
|
+
FunctionBase.prototype.preventChildBlockScope = true;
|
|
8139
|
+
|
|
8140
|
+
class ArrowFunctionExpression extends FunctionBase {
|
|
8141
|
+
constructor() {
|
|
8142
|
+
super(...arguments);
|
|
8143
|
+
this.objectEntity = null;
|
|
8254
8144
|
}
|
|
8255
|
-
|
|
8256
|
-
|
|
8257
|
-
|
|
8258
|
-
|
|
8259
|
-
|
|
8260
|
-
|
|
8261
|
-
|
|
8262
|
-
|
|
8263
|
-
|
|
8264
|
-
|
|
8265
|
-
|
|
8266
|
-
|
|
8267
|
-
|
|
8268
|
-
|
|
8269
|
-
|
|
8270
|
-
|
|
8271
|
-
|
|
8145
|
+
createScope(parentScope) {
|
|
8146
|
+
this.scope = new ReturnValueScope(parentScope, this.context);
|
|
8147
|
+
}
|
|
8148
|
+
hasEffects() {
|
|
8149
|
+
if (!this.deoptimized)
|
|
8150
|
+
this.applyDeoptimizations();
|
|
8151
|
+
return false;
|
|
8152
|
+
}
|
|
8153
|
+
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
8154
|
+
if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
|
|
8155
|
+
return true;
|
|
8156
|
+
const { ignore, brokenFlow } = context;
|
|
8157
|
+
context.ignore = {
|
|
8158
|
+
breaks: false,
|
|
8159
|
+
continues: false,
|
|
8160
|
+
labels: new Set(),
|
|
8161
|
+
returnYield: true
|
|
8162
|
+
};
|
|
8163
|
+
if (this.body.hasEffects(context))
|
|
8164
|
+
return true;
|
|
8165
|
+
context.ignore = ignore;
|
|
8166
|
+
context.brokenFlow = brokenFlow;
|
|
8167
|
+
return false;
|
|
8168
|
+
}
|
|
8169
|
+
include(context, includeChildrenRecursively) {
|
|
8170
|
+
super.include(context, includeChildrenRecursively);
|
|
8171
|
+
for (const param of this.params) {
|
|
8172
|
+
if (!(param instanceof Identifier)) {
|
|
8173
|
+
param.include(context, includeChildrenRecursively);
|
|
8272
8174
|
}
|
|
8273
8175
|
}
|
|
8274
8176
|
}
|
|
8275
|
-
|
|
8276
|
-
this.
|
|
8277
|
-
|
|
8278
|
-
this.variable.consolidateInitializers();
|
|
8279
|
-
this.context.requestTreeshakingPass();
|
|
8177
|
+
getObjectEntity() {
|
|
8178
|
+
if (this.objectEntity !== null) {
|
|
8179
|
+
return this.objectEntity;
|
|
8280
8180
|
}
|
|
8181
|
+
return (this.objectEntity = new ObjectEntity([], OBJECT_PROTOTYPE));
|
|
8281
8182
|
}
|
|
8282
|
-
|
|
8283
|
-
|
|
8284
|
-
|
|
8285
|
-
|
|
8286
|
-
|
|
8183
|
+
}
|
|
8184
|
+
|
|
8185
|
+
function getSystemExportStatement(exportedVariables, { exportNamesByVariable, snippets: { _, getObject, getPropertyAccess } }, modifier = '') {
|
|
8186
|
+
if (exportedVariables.length === 1 &&
|
|
8187
|
+
exportNamesByVariable.get(exportedVariables[0]).length === 1) {
|
|
8188
|
+
const variable = exportedVariables[0];
|
|
8189
|
+
return `exports('${exportNamesByVariable.get(variable)}',${_}${variable.getName(getPropertyAccess)}${modifier})`;
|
|
8287
8190
|
}
|
|
8288
|
-
|
|
8289
|
-
|
|
8290
|
-
|
|
8191
|
+
else {
|
|
8192
|
+
const fields = [];
|
|
8193
|
+
for (const variable of exportedVariables) {
|
|
8194
|
+
for (const exportName of exportNamesByVariable.get(variable)) {
|
|
8195
|
+
fields.push([exportName, variable.getName(getPropertyAccess) + modifier]);
|
|
8196
|
+
}
|
|
8291
8197
|
}
|
|
8292
|
-
return
|
|
8198
|
+
return `exports(${getObject(fields, { lineBreakIndent: null })})`;
|
|
8293
8199
|
}
|
|
8294
8200
|
}
|
|
8295
|
-
function
|
|
8296
|
-
|
|
8297
|
-
|
|
8201
|
+
function renderSystemExportExpression(exportedVariable, expressionStart, expressionEnd, code, { exportNamesByVariable, snippets: { _ } }) {
|
|
8202
|
+
code.prependRight(expressionStart, `exports('${exportNamesByVariable.get(exportedVariable)}',${_}`);
|
|
8203
|
+
code.appendLeft(expressionEnd, ')');
|
|
8204
|
+
}
|
|
8205
|
+
function renderSystemExportFunction(exportedVariables, expressionStart, expressionEnd, needsParens, code, options) {
|
|
8206
|
+
const { _, getDirectReturnIifeLeft } = options.snippets;
|
|
8207
|
+
code.prependRight(expressionStart, getDirectReturnIifeLeft(['v'], `${getSystemExportStatement(exportedVariables, options)},${_}v`, { needsArrowReturnParens: true, needsWrappedFunction: needsParens }));
|
|
8208
|
+
code.appendLeft(expressionEnd, ')');
|
|
8209
|
+
}
|
|
8210
|
+
function renderSystemExportSequenceAfterExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options) {
|
|
8211
|
+
const { _, getPropertyAccess } = options.snippets;
|
|
8212
|
+
code.appendLeft(expressionEnd, `,${_}${getSystemExportStatement([exportedVariable], options)},${_}${exportedVariable.getName(getPropertyAccess)}`);
|
|
8213
|
+
if (needsParens) {
|
|
8214
|
+
code.prependRight(expressionStart, '(');
|
|
8215
|
+
code.appendLeft(expressionEnd, ')');
|
|
8216
|
+
}
|
|
8217
|
+
}
|
|
8218
|
+
function renderSystemExportSequenceBeforeExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options, modifier) {
|
|
8219
|
+
const { _ } = options.snippets;
|
|
8220
|
+
code.prependRight(expressionStart, `${getSystemExportStatement([exportedVariable], options, modifier)},${_}`);
|
|
8221
|
+
if (needsParens) {
|
|
8222
|
+
code.prependRight(expressionStart, '(');
|
|
8223
|
+
code.appendLeft(expressionEnd, ')');
|
|
8298
8224
|
}
|
|
8299
|
-
// one of: ArrowFunctionExpression, FunctionDeclaration, FunctionExpression or Program
|
|
8300
|
-
return node;
|
|
8301
8225
|
}
|
|
8302
8226
|
|
|
8303
8227
|
class ObjectPattern extends NodeBase {
|
|
@@ -8342,10 +8266,6 @@ class ObjectPattern extends NodeBase {
|
|
|
8342
8266
|
}
|
|
8343
8267
|
|
|
8344
8268
|
class AssignmentExpression extends NodeBase {
|
|
8345
|
-
constructor() {
|
|
8346
|
-
super(...arguments);
|
|
8347
|
-
this.deoptimized = false;
|
|
8348
|
-
}
|
|
8349
8269
|
hasEffects(context) {
|
|
8350
8270
|
if (!this.deoptimized)
|
|
8351
8271
|
this.applyDeoptimizations();
|
|
@@ -8426,6 +8346,46 @@ class AssignmentExpression extends NodeBase {
|
|
|
8426
8346
|
}
|
|
8427
8347
|
}
|
|
8428
8348
|
|
|
8349
|
+
class AssignmentPattern extends NodeBase {
|
|
8350
|
+
addExportedVariables(variables, exportNamesByVariable) {
|
|
8351
|
+
this.left.addExportedVariables(variables, exportNamesByVariable);
|
|
8352
|
+
}
|
|
8353
|
+
declare(kind, init) {
|
|
8354
|
+
return this.left.declare(kind, init);
|
|
8355
|
+
}
|
|
8356
|
+
deoptimizePath(path) {
|
|
8357
|
+
path.length === 0 && this.left.deoptimizePath(path);
|
|
8358
|
+
}
|
|
8359
|
+
hasEffectsWhenAssignedAtPath(path, context) {
|
|
8360
|
+
return path.length > 0 || this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
|
|
8361
|
+
}
|
|
8362
|
+
include(context, includeChildrenRecursively) {
|
|
8363
|
+
if (!this.deoptimized)
|
|
8364
|
+
this.applyDeoptimizations();
|
|
8365
|
+
this.included = true;
|
|
8366
|
+
this.left.include(context, includeChildrenRecursively);
|
|
8367
|
+
this.right.include(context, includeChildrenRecursively);
|
|
8368
|
+
}
|
|
8369
|
+
markDeclarationReached() {
|
|
8370
|
+
this.left.markDeclarationReached();
|
|
8371
|
+
}
|
|
8372
|
+
render(code, options, { isShorthandProperty } = BLANK) {
|
|
8373
|
+
this.left.render(code, options, { isShorthandProperty });
|
|
8374
|
+
if (this.right.included) {
|
|
8375
|
+
this.right.render(code, options);
|
|
8376
|
+
}
|
|
8377
|
+
else {
|
|
8378
|
+
code.remove(this.left.end, this.end);
|
|
8379
|
+
}
|
|
8380
|
+
}
|
|
8381
|
+
applyDeoptimizations() {
|
|
8382
|
+
this.deoptimized = true;
|
|
8383
|
+
this.left.deoptimizePath(EMPTY_PATH);
|
|
8384
|
+
this.right.deoptimizePath(UNKNOWN_PATH);
|
|
8385
|
+
this.context.requestTreeshakingPass();
|
|
8386
|
+
}
|
|
8387
|
+
}
|
|
8388
|
+
|
|
8429
8389
|
class ArgumentsVariable extends LocalVariable {
|
|
8430
8390
|
constructor(context) {
|
|
8431
8391
|
super('arguments', null, UNKNOWN_EXPRESSION, context);
|
|
@@ -8534,6 +8494,8 @@ class FunctionNode extends FunctionBase {
|
|
|
8534
8494
|
}
|
|
8535
8495
|
hasEffects() {
|
|
8536
8496
|
var _a;
|
|
8497
|
+
if (!this.deoptimized)
|
|
8498
|
+
this.applyDeoptimizations();
|
|
8537
8499
|
return !!((_a = this.id) === null || _a === void 0 ? void 0 : _a.hasEffects());
|
|
8538
8500
|
}
|
|
8539
8501
|
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
@@ -8562,12 +8524,16 @@ class FunctionNode extends FunctionBase {
|
|
|
8562
8524
|
context.ignore = ignore;
|
|
8563
8525
|
return false;
|
|
8564
8526
|
}
|
|
8565
|
-
include(context, includeChildrenRecursively
|
|
8527
|
+
include(context, includeChildrenRecursively) {
|
|
8566
8528
|
var _a;
|
|
8529
|
+
super.include(context, includeChildrenRecursively);
|
|
8567
8530
|
(_a = this.id) === null || _a === void 0 ? void 0 : _a.include();
|
|
8568
|
-
|
|
8569
|
-
|
|
8570
|
-
|
|
8531
|
+
const hasArguments = this.scope.argumentsVariable.included;
|
|
8532
|
+
for (const param of this.params) {
|
|
8533
|
+
if (!(param instanceof Identifier) || hasArguments) {
|
|
8534
|
+
param.include(context, includeChildrenRecursively);
|
|
8535
|
+
}
|
|
8536
|
+
}
|
|
8571
8537
|
}
|
|
8572
8538
|
initialise() {
|
|
8573
8539
|
var _a;
|
|
@@ -8589,10 +8555,6 @@ class FunctionNode extends FunctionBase {
|
|
|
8589
8555
|
}
|
|
8590
8556
|
|
|
8591
8557
|
class AwaitExpression extends NodeBase {
|
|
8592
|
-
constructor() {
|
|
8593
|
-
super(...arguments);
|
|
8594
|
-
this.deoptimized = false;
|
|
8595
|
-
}
|
|
8596
8558
|
hasEffects() {
|
|
8597
8559
|
if (!this.deoptimized)
|
|
8598
8560
|
this.applyDeoptimizations();
|
|
@@ -8700,6 +8662,31 @@ class BreakStatement extends NodeBase {
|
|
|
8700
8662
|
}
|
|
8701
8663
|
}
|
|
8702
8664
|
|
|
8665
|
+
function renderCallArguments(code, options, node) {
|
|
8666
|
+
if (node.arguments.length > 0) {
|
|
8667
|
+
if (node.arguments[node.arguments.length - 1].included) {
|
|
8668
|
+
for (const arg of node.arguments) {
|
|
8669
|
+
arg.render(code, options);
|
|
8670
|
+
}
|
|
8671
|
+
}
|
|
8672
|
+
else {
|
|
8673
|
+
let lastIncludedIndex = node.arguments.length - 2;
|
|
8674
|
+
while (lastIncludedIndex >= 0 && !node.arguments[lastIncludedIndex].included) {
|
|
8675
|
+
lastIncludedIndex--;
|
|
8676
|
+
}
|
|
8677
|
+
if (lastIncludedIndex >= 0) {
|
|
8678
|
+
for (let index = 0; index <= lastIncludedIndex; index++) {
|
|
8679
|
+
node.arguments[index].render(code, options);
|
|
8680
|
+
}
|
|
8681
|
+
code.remove(findFirstOccurrenceOutsideComment(code.original, ',', node.arguments[lastIncludedIndex].end), node.end - 1);
|
|
8682
|
+
}
|
|
8683
|
+
else {
|
|
8684
|
+
code.remove(findFirstOccurrenceOutsideComment(code.original, '(', node.callee.end) + 1, node.end - 1);
|
|
8685
|
+
}
|
|
8686
|
+
}
|
|
8687
|
+
}
|
|
8688
|
+
}
|
|
8689
|
+
|
|
8703
8690
|
class Literal extends NodeBase {
|
|
8704
8691
|
deoptimizeThisOnEventAtPath() { }
|
|
8705
8692
|
getLiteralValueAtPath(path) {
|
|
@@ -8786,7 +8773,6 @@ class MemberExpression extends NodeBase {
|
|
|
8786
8773
|
constructor() {
|
|
8787
8774
|
super(...arguments);
|
|
8788
8775
|
this.variable = null;
|
|
8789
|
-
this.deoptimized = false;
|
|
8790
8776
|
this.bound = false;
|
|
8791
8777
|
this.expressionsToBeDeoptimized = [];
|
|
8792
8778
|
this.replacement = null;
|
|
@@ -9036,7 +9022,6 @@ class MemberExpression extends NodeBase {
|
|
|
9036
9022
|
class CallExpressionBase extends NodeBase {
|
|
9037
9023
|
constructor() {
|
|
9038
9024
|
super(...arguments);
|
|
9039
|
-
this.deoptimized = false;
|
|
9040
9025
|
this.returnExpression = null;
|
|
9041
9026
|
this.deoptimizableDependentExpressions = [];
|
|
9042
9027
|
this.expressionsToBeDeoptimized = new Set();
|
|
@@ -9165,7 +9150,7 @@ class CallExpression extends CallExpressionBase {
|
|
|
9165
9150
|
}
|
|
9166
9151
|
else {
|
|
9167
9152
|
this.included = true;
|
|
9168
|
-
this.callee.include(context, false
|
|
9153
|
+
this.callee.include(context, false);
|
|
9169
9154
|
}
|
|
9170
9155
|
this.callee.includeCallArguments(context, this.arguments);
|
|
9171
9156
|
const returnExpression = this.getReturnExpression();
|
|
@@ -9178,28 +9163,7 @@ class CallExpression extends CallExpressionBase {
|
|
|
9178
9163
|
isCalleeOfRenderedParent: true,
|
|
9179
9164
|
renderedSurroundingElement
|
|
9180
9165
|
});
|
|
9181
|
-
|
|
9182
|
-
if (this.arguments[this.arguments.length - 1].included) {
|
|
9183
|
-
for (const arg of this.arguments) {
|
|
9184
|
-
arg.render(code, options);
|
|
9185
|
-
}
|
|
9186
|
-
}
|
|
9187
|
-
else {
|
|
9188
|
-
let lastIncludedIndex = this.arguments.length - 2;
|
|
9189
|
-
while (lastIncludedIndex >= 0 && !this.arguments[lastIncludedIndex].included) {
|
|
9190
|
-
lastIncludedIndex--;
|
|
9191
|
-
}
|
|
9192
|
-
if (lastIncludedIndex >= 0) {
|
|
9193
|
-
for (let index = 0; index <= lastIncludedIndex; index++) {
|
|
9194
|
-
this.arguments[index].render(code, options);
|
|
9195
|
-
}
|
|
9196
|
-
code.remove(findFirstOccurrenceOutsideComment(code.original, ',', this.arguments[lastIncludedIndex].end), this.end - 1);
|
|
9197
|
-
}
|
|
9198
|
-
else {
|
|
9199
|
-
code.remove(findFirstOccurrenceOutsideComment(code.original, '(', this.callee.end) + 1, this.end - 1);
|
|
9200
|
-
}
|
|
9201
|
-
}
|
|
9202
|
-
}
|
|
9166
|
+
renderCallArguments(code, options, this);
|
|
9203
9167
|
}
|
|
9204
9168
|
applyDeoptimizations() {
|
|
9205
9169
|
this.deoptimized = true;
|
|
@@ -9287,6 +9251,7 @@ class ClassBody extends NodeBase {
|
|
|
9287
9251
|
}
|
|
9288
9252
|
super.parseNode(esTreeNode);
|
|
9289
9253
|
}
|
|
9254
|
+
applyDeoptimizations() { }
|
|
9290
9255
|
}
|
|
9291
9256
|
|
|
9292
9257
|
class MethodBase extends NodeBase {
|
|
@@ -9338,6 +9303,7 @@ class MethodBase extends NodeBase {
|
|
|
9338
9303
|
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
9339
9304
|
return this.getAccessedValue().hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
9340
9305
|
}
|
|
9306
|
+
applyDeoptimizations() { }
|
|
9341
9307
|
getAccessedValue() {
|
|
9342
9308
|
if (this.accessedValue === null) {
|
|
9343
9309
|
if (this.kind === 'get') {
|
|
@@ -9353,6 +9319,7 @@ class MethodBase extends NodeBase {
|
|
|
9353
9319
|
}
|
|
9354
9320
|
|
|
9355
9321
|
class MethodDefinition extends MethodBase {
|
|
9322
|
+
applyDeoptimizations() { }
|
|
9356
9323
|
}
|
|
9357
9324
|
|
|
9358
9325
|
class ObjectMember extends ExpressionEntity {
|
|
@@ -9387,7 +9354,6 @@ class ObjectMember extends ExpressionEntity {
|
|
|
9387
9354
|
class ClassNode extends NodeBase {
|
|
9388
9355
|
constructor() {
|
|
9389
9356
|
super(...arguments);
|
|
9390
|
-
this.deoptimized = false;
|
|
9391
9357
|
this.objectEntity = null;
|
|
9392
9358
|
}
|
|
9393
9359
|
createScope(parentScope) {
|
|
@@ -9397,14 +9363,7 @@ class ClassNode extends NodeBase {
|
|
|
9397
9363
|
this.getObjectEntity().deoptimizeAllProperties();
|
|
9398
9364
|
}
|
|
9399
9365
|
deoptimizePath(path) {
|
|
9400
|
-
var _a, _b;
|
|
9401
9366
|
this.getObjectEntity().deoptimizePath(path);
|
|
9402
|
-
if (path.length === 1 && path[0] === UnknownKey) {
|
|
9403
|
-
// A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
|
|
9404
|
-
// which means the constructor needs to be reassigned
|
|
9405
|
-
(_a = this.classConstructor) === null || _a === void 0 ? void 0 : _a.deoptimizePath(UNKNOWN_PATH);
|
|
9406
|
-
(_b = this.superClass) === null || _b === void 0 ? void 0 : _b.deoptimizePath(UNKNOWN_PATH);
|
|
9407
|
-
}
|
|
9408
9367
|
}
|
|
9409
9368
|
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
9410
9369
|
this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
@@ -9802,13 +9761,11 @@ class ExportAllDeclaration extends NodeBase {
|
|
|
9802
9761
|
render(code, _options, nodeRenderOptions) {
|
|
9803
9762
|
code.remove(nodeRenderOptions.start, nodeRenderOptions.end);
|
|
9804
9763
|
}
|
|
9764
|
+
applyDeoptimizations() { }
|
|
9805
9765
|
}
|
|
9806
9766
|
ExportAllDeclaration.prototype.needsBoundaries = true;
|
|
9807
9767
|
|
|
9808
9768
|
class FunctionDeclaration extends FunctionNode {
|
|
9809
|
-
include(context, includeChildrenRecursively) {
|
|
9810
|
-
super.include(context, includeChildrenRecursively, { includeWithoutParameterDefaults: true });
|
|
9811
|
-
}
|
|
9812
9769
|
initialise() {
|
|
9813
9770
|
super.initialise();
|
|
9814
9771
|
if (this.id !== null) {
|
|
@@ -9879,6 +9836,7 @@ class ExportDefaultDeclaration extends NodeBase {
|
|
|
9879
9836
|
}
|
|
9880
9837
|
this.declaration.render(code, options);
|
|
9881
9838
|
}
|
|
9839
|
+
applyDeoptimizations() { }
|
|
9882
9840
|
renderNamedDeclaration(code, declarationStart, declarationKeyword, endMarker, needsId, options) {
|
|
9883
9841
|
const { exportNamesByVariable, format, snippets: { getPropertyAccess } } = options;
|
|
9884
9842
|
const name = this.variable.getName(getPropertyAccess);
|
|
@@ -9933,17 +9891,15 @@ class ExportNamedDeclaration extends NodeBase {
|
|
|
9933
9891
|
this.declaration.render(code, options, { end, start });
|
|
9934
9892
|
}
|
|
9935
9893
|
}
|
|
9894
|
+
applyDeoptimizations() { }
|
|
9936
9895
|
}
|
|
9937
9896
|
ExportNamedDeclaration.prototype.needsBoundaries = true;
|
|
9938
9897
|
|
|
9939
9898
|
class ExportSpecifier extends NodeBase {
|
|
9899
|
+
applyDeoptimizations() { }
|
|
9940
9900
|
}
|
|
9941
9901
|
|
|
9942
9902
|
class ForInStatement extends NodeBase {
|
|
9943
|
-
constructor() {
|
|
9944
|
-
super(...arguments);
|
|
9945
|
-
this.deoptimized = false;
|
|
9946
|
-
}
|
|
9947
9903
|
createScope(parentScope) {
|
|
9948
9904
|
this.scope = new BlockScope(parentScope);
|
|
9949
9905
|
}
|
|
@@ -9992,10 +9948,6 @@ class ForInStatement extends NodeBase {
|
|
|
9992
9948
|
}
|
|
9993
9949
|
|
|
9994
9950
|
class ForOfStatement extends NodeBase {
|
|
9995
|
-
constructor() {
|
|
9996
|
-
super(...arguments);
|
|
9997
|
-
this.deoptimized = false;
|
|
9998
|
-
}
|
|
9999
9951
|
createScope(parentScope) {
|
|
10000
9952
|
this.scope = new BlockScope(parentScope);
|
|
10001
9953
|
}
|
|
@@ -10190,6 +10142,7 @@ class IfStatement extends NodeBase {
|
|
|
10190
10142
|
}
|
|
10191
10143
|
this.renderHoistedDeclarations(hoistedDeclarations, code, getPropertyAccess);
|
|
10192
10144
|
}
|
|
10145
|
+
applyDeoptimizations() { }
|
|
10193
10146
|
getTestValue() {
|
|
10194
10147
|
if (this.testValue === unset) {
|
|
10195
10148
|
return (this.testValue = this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this));
|
|
@@ -10275,10 +10228,12 @@ class ImportDeclaration extends NodeBase {
|
|
|
10275
10228
|
render(code, _options, nodeRenderOptions) {
|
|
10276
10229
|
code.remove(nodeRenderOptions.start, nodeRenderOptions.end);
|
|
10277
10230
|
}
|
|
10231
|
+
applyDeoptimizations() { }
|
|
10278
10232
|
}
|
|
10279
10233
|
ImportDeclaration.prototype.needsBoundaries = true;
|
|
10280
10234
|
|
|
10281
10235
|
class ImportDefaultSpecifier extends NodeBase {
|
|
10236
|
+
applyDeoptimizations() { }
|
|
10282
10237
|
}
|
|
10283
10238
|
|
|
10284
10239
|
const INTEROP_DEFAULT_VARIABLE = '_interopDefault';
|
|
@@ -10537,6 +10492,7 @@ class ImportExpression extends NodeBase {
|
|
|
10537
10492
|
setInternalResolution(inlineNamespace) {
|
|
10538
10493
|
this.inlineNamespace = inlineNamespace;
|
|
10539
10494
|
}
|
|
10495
|
+
applyDeoptimizations() { }
|
|
10540
10496
|
getDynamicImportMechanismAndHelper(resolution, exportMode, { compact, dynamicImportFunction, format, generatedCode: { arrowFunctions }, interop }, { _, getDirectReturnFunction, getDirectReturnIifeLeft }, pluginDriver) {
|
|
10541
10497
|
const mechanism = pluginDriver.hookFirstSync('renderDynamicImport', [
|
|
10542
10498
|
{
|
|
@@ -10645,9 +10601,11 @@ const accessedImportGlobals = {
|
|
|
10645
10601
|
};
|
|
10646
10602
|
|
|
10647
10603
|
class ImportNamespaceSpecifier extends NodeBase {
|
|
10604
|
+
applyDeoptimizations() { }
|
|
10648
10605
|
}
|
|
10649
10606
|
|
|
10650
10607
|
class ImportSpecifier extends NodeBase {
|
|
10608
|
+
applyDeoptimizations() { }
|
|
10651
10609
|
}
|
|
10652
10610
|
|
|
10653
10611
|
class LabeledStatement extends NodeBase {
|
|
@@ -10693,13 +10651,16 @@ class LogicalExpression extends NodeBase {
|
|
|
10693
10651
|
this.usedBranch = null;
|
|
10694
10652
|
}
|
|
10695
10653
|
deoptimizeCache() {
|
|
10696
|
-
if (this.usedBranch
|
|
10654
|
+
if (this.usedBranch) {
|
|
10697
10655
|
const unusedBranch = this.usedBranch === this.left ? this.right : this.left;
|
|
10698
10656
|
this.usedBranch = null;
|
|
10699
10657
|
unusedBranch.deoptimizePath(UNKNOWN_PATH);
|
|
10700
10658
|
for (const expression of this.expressionsToBeDeoptimized) {
|
|
10701
10659
|
expression.deoptimizeCache();
|
|
10702
10660
|
}
|
|
10661
|
+
// Request another pass because we need to ensure "include" runs again if
|
|
10662
|
+
// it is rendered
|
|
10663
|
+
this.context.requestTreeshakingPass();
|
|
10703
10664
|
}
|
|
10704
10665
|
}
|
|
10705
10666
|
deoptimizePath(path) {
|
|
@@ -10993,10 +10954,6 @@ const importMetaMechanisms = {
|
|
|
10993
10954
|
};
|
|
10994
10955
|
|
|
10995
10956
|
class NewExpression extends NodeBase {
|
|
10996
|
-
constructor() {
|
|
10997
|
-
super(...arguments);
|
|
10998
|
-
this.deoptimized = false;
|
|
10999
|
-
}
|
|
11000
10957
|
hasEffects(context) {
|
|
11001
10958
|
try {
|
|
11002
10959
|
for (const argument of this.arguments) {
|
|
@@ -11036,6 +10993,10 @@ class NewExpression extends NodeBase {
|
|
|
11036
10993
|
withNew: true
|
|
11037
10994
|
};
|
|
11038
10995
|
}
|
|
10996
|
+
render(code, options) {
|
|
10997
|
+
this.callee.render(code, options);
|
|
10998
|
+
renderCallArguments(code, options, this);
|
|
10999
|
+
}
|
|
11039
11000
|
applyDeoptimizations() {
|
|
11040
11001
|
this.deoptimized = true;
|
|
11041
11002
|
for (const argument of this.arguments) {
|
|
@@ -11083,6 +11044,7 @@ class ObjectExpression extends NodeBase {
|
|
|
11083
11044
|
code.prependLeft(this.end, ')');
|
|
11084
11045
|
}
|
|
11085
11046
|
}
|
|
11047
|
+
applyDeoptimizations() { }
|
|
11086
11048
|
getObjectEntity() {
|
|
11087
11049
|
if (this.objectEntity !== null) {
|
|
11088
11050
|
return this.objectEntity;
|
|
@@ -11159,12 +11121,12 @@ class Program extends NodeBase {
|
|
|
11159
11121
|
super.render(code, options);
|
|
11160
11122
|
}
|
|
11161
11123
|
}
|
|
11124
|
+
applyDeoptimizations() { }
|
|
11162
11125
|
}
|
|
11163
11126
|
|
|
11164
11127
|
class Property extends MethodBase {
|
|
11165
11128
|
constructor() {
|
|
11166
11129
|
super(...arguments);
|
|
11167
|
-
this.deoptimized = false;
|
|
11168
11130
|
this.declarationInit = null;
|
|
11169
11131
|
}
|
|
11170
11132
|
declare(kind, init) {
|
|
@@ -11230,6 +11192,7 @@ class PropertyDefinition extends NodeBase {
|
|
|
11230
11192
|
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
11231
11193
|
return !this.value || this.value.hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
11232
11194
|
}
|
|
11195
|
+
applyDeoptimizations() { }
|
|
11233
11196
|
}
|
|
11234
11197
|
|
|
11235
11198
|
class ReturnStatement extends NodeBase {
|
|
@@ -11826,10 +11789,6 @@ const unaryOperators = {
|
|
|
11826
11789
|
'~': value => ~value
|
|
11827
11790
|
};
|
|
11828
11791
|
class UnaryExpression extends NodeBase {
|
|
11829
|
-
constructor() {
|
|
11830
|
-
super(...arguments);
|
|
11831
|
-
this.deoptimized = false;
|
|
11832
|
-
}
|
|
11833
11792
|
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
11834
11793
|
if (path.length > 0)
|
|
11835
11794
|
return UnknownValue;
|
|
@@ -11872,10 +11831,6 @@ class UnknownNode extends NodeBase {
|
|
|
11872
11831
|
}
|
|
11873
11832
|
|
|
11874
11833
|
class UpdateExpression extends NodeBase {
|
|
11875
|
-
constructor() {
|
|
11876
|
-
super(...arguments);
|
|
11877
|
-
this.deoptimized = false;
|
|
11878
|
-
}
|
|
11879
11834
|
hasEffects(context) {
|
|
11880
11835
|
if (!this.deoptimized)
|
|
11881
11836
|
this.applyDeoptimizations();
|
|
@@ -11977,6 +11932,7 @@ class VariableDeclaration extends NodeBase {
|
|
|
11977
11932
|
this.renderReplacedDeclarations(code, options);
|
|
11978
11933
|
}
|
|
11979
11934
|
}
|
|
11935
|
+
applyDeoptimizations() { }
|
|
11980
11936
|
renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, systemPatternExports, options) {
|
|
11981
11937
|
if (code.original.charCodeAt(this.end - 1) === 59 /*";"*/) {
|
|
11982
11938
|
code.remove(this.end - 1, this.end);
|
|
@@ -12107,9 +12063,7 @@ class VariableDeclarator extends NodeBase {
|
|
|
12107
12063
|
include(context, includeChildrenRecursively) {
|
|
12108
12064
|
var _a;
|
|
12109
12065
|
this.included = true;
|
|
12110
|
-
(_a = this.init) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively
|
|
12111
|
-
includeWithoutParameterDefaults: true
|
|
12112
|
-
});
|
|
12066
|
+
(_a = this.init) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
|
|
12113
12067
|
this.id.markDeclarationReached();
|
|
12114
12068
|
if (includeChildrenRecursively || this.id.shouldBeIncluded(context)) {
|
|
12115
12069
|
this.id.include(context, includeChildrenRecursively);
|
|
@@ -12133,6 +12087,7 @@ class VariableDeclarator extends NodeBase {
|
|
|
12133
12087
|
code.appendLeft(this.end, `${_}=${_}void 0`);
|
|
12134
12088
|
}
|
|
12135
12089
|
}
|
|
12090
|
+
applyDeoptimizations() { }
|
|
12136
12091
|
}
|
|
12137
12092
|
|
|
12138
12093
|
class WhileStatement extends NodeBase {
|
|
@@ -12159,15 +12114,11 @@ class WhileStatement extends NodeBase {
|
|
|
12159
12114
|
}
|
|
12160
12115
|
|
|
12161
12116
|
class YieldExpression extends NodeBase {
|
|
12162
|
-
constructor() {
|
|
12163
|
-
super(...arguments);
|
|
12164
|
-
this.deoptimized = false;
|
|
12165
|
-
}
|
|
12166
12117
|
hasEffects(context) {
|
|
12167
12118
|
var _a;
|
|
12168
12119
|
if (!this.deoptimized)
|
|
12169
12120
|
this.applyDeoptimizations();
|
|
12170
|
-
return !context.ignore.returnYield
|
|
12121
|
+
return !(context.ignore.returnYield && !((_a = this.argument) === null || _a === void 0 ? void 0 : _a.hasEffects(context)));
|
|
12171
12122
|
}
|
|
12172
12123
|
render(code, options) {
|
|
12173
12124
|
if (this.argument) {
|