rollup 2.75.4 → 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 +14 -0
- 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 +860 -932
- 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 +860 -932
- package/dist/shared/watch-cli.js +2 -2
- package/dist/shared/watch.js +2 -2
- package/package.json +1 -1
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)) {
|
|
@@ -2227,7 +2227,6 @@ class ExpressionEntity {
|
|
|
2227
2227
|
constructor() {
|
|
2228
2228
|
this.included = false;
|
|
2229
2229
|
}
|
|
2230
|
-
deoptimizeCallParameters() { }
|
|
2231
2230
|
deoptimizePath(_path) { }
|
|
2232
2231
|
deoptimizeThisOnEventAtPath(_event, _path, thisParameter, _recursionTracker) {
|
|
2233
2232
|
thisParameter.deoptimizePath(UNKNOWN_PATH);
|
|
@@ -6204,13 +6203,8 @@ class ArrayExpression extends NodeBase {
|
|
|
6204
6203
|
if (element) {
|
|
6205
6204
|
if (hasSpread || element instanceof SpreadElement) {
|
|
6206
6205
|
hasSpread = true;
|
|
6207
|
-
// This also deoptimizes parameter defaults
|
|
6208
6206
|
element.deoptimizePath(UNKNOWN_PATH);
|
|
6209
6207
|
}
|
|
6210
|
-
else {
|
|
6211
|
-
// We do not track parameter defaults in arrays
|
|
6212
|
-
element.deoptimizeCallParameters();
|
|
6213
|
-
}
|
|
6214
6208
|
}
|
|
6215
6209
|
}
|
|
6216
6210
|
this.context.requestTreeshakingPass();
|
|
@@ -6304,10 +6298,6 @@ class LocalVariable extends Variable {
|
|
|
6304
6298
|
this.additionalInitializers = null;
|
|
6305
6299
|
}
|
|
6306
6300
|
}
|
|
6307
|
-
deoptimizeCallParameters() {
|
|
6308
|
-
var _a;
|
|
6309
|
-
(_a = this.init) === null || _a === void 0 ? void 0 : _a.deoptimizeCallParameters();
|
|
6310
|
-
}
|
|
6311
6301
|
deoptimizePath(path) {
|
|
6312
6302
|
var _a, _b;
|
|
6313
6303
|
if (this.isReassigned ||
|
|
@@ -6653,641 +6643,87 @@ class ReturnValueScope extends ParameterScope {
|
|
|
6653
6643
|
}
|
|
6654
6644
|
}
|
|
6655
6645
|
|
|
6656
|
-
|
|
6657
|
-
|
|
6658
|
-
|
|
6659
|
-
|
|
6660
|
-
|
|
6661
|
-
|
|
6662
|
-
|
|
6663
|
-
deoptimizePath(path) {
|
|
6664
|
-
path.length === 0 && this.left.deoptimizePath(path);
|
|
6665
|
-
}
|
|
6666
|
-
hasEffectsWhenAssignedAtPath(path, context) {
|
|
6667
|
-
return path.length > 0 || this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
|
|
6668
|
-
}
|
|
6669
|
-
// Note that FunctionBase may directly include .left and .right without
|
|
6670
|
-
// including the pattern itself. This is how default parameter tree-shaking
|
|
6671
|
-
// works at the moment.
|
|
6672
|
-
include(context, includeChildrenRecursively) {
|
|
6673
|
-
this.included = true;
|
|
6674
|
-
this.left.include(context, includeChildrenRecursively);
|
|
6675
|
-
this.right.include(context, includeChildrenRecursively);
|
|
6676
|
-
}
|
|
6677
|
-
markDeclarationReached() {
|
|
6678
|
-
this.left.markDeclarationReached();
|
|
6679
|
-
}
|
|
6680
|
-
render(code, options, { isShorthandProperty } = BLANK) {
|
|
6681
|
-
this.left.render(code, options, { isShorthandProperty });
|
|
6682
|
-
if (this.right.included) {
|
|
6683
|
-
this.right.render(code, options);
|
|
6684
|
-
}
|
|
6685
|
-
else {
|
|
6686
|
-
code.remove(this.left.end, this.end);
|
|
6687
|
-
}
|
|
6688
|
-
}
|
|
6689
|
-
applyDeoptimizations() {
|
|
6690
|
-
this.deoptimized = true;
|
|
6691
|
-
this.left.deoptimizePath(EMPTY_PATH);
|
|
6692
|
-
this.right.deoptimizePath(UNKNOWN_PATH);
|
|
6693
|
-
this.context.requestTreeshakingPass();
|
|
6694
|
-
}
|
|
6695
|
-
}
|
|
6646
|
+
//@ts-check
|
|
6647
|
+
/** @typedef { import('estree').Node} Node */
|
|
6648
|
+
/** @typedef {Node | {
|
|
6649
|
+
* type: 'PropertyDefinition';
|
|
6650
|
+
* computed: boolean;
|
|
6651
|
+
* value: Node
|
|
6652
|
+
* }} NodeWithPropertyDefinition */
|
|
6696
6653
|
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
|
-
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
}
|
|
6708
|
-
}
|
|
6709
|
-
}
|
|
6710
|
-
function removeAnnotations(node, code) {
|
|
6711
|
-
if (!node.annotations && node.parent.type === ExpressionStatement$1) {
|
|
6712
|
-
node = node.parent;
|
|
6713
|
-
}
|
|
6714
|
-
if (node.annotations) {
|
|
6715
|
-
for (const annotation of node.annotations) {
|
|
6716
|
-
code.remove(annotation.start, annotation.end);
|
|
6717
|
-
}
|
|
6718
|
-
}
|
|
6719
|
-
}
|
|
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
|
+
}
|
|
6720
6664
|
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
6740
|
-
|
|
6741
|
-
|
|
6742
|
-
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
}
|
|
6748
|
-
|
|
6749
|
-
|
|
6750
|
-
|
|
6751
|
-
let lineBreakPos, charCodeAfterSlash, start = 0;
|
|
6752
|
-
lineBreakPos = code.indexOf('\n', start);
|
|
6753
|
-
while (true) {
|
|
6754
|
-
start = code.indexOf('/', start);
|
|
6755
|
-
if (start === -1 || start > lineBreakPos)
|
|
6756
|
-
return [lineBreakPos, lineBreakPos + 1];
|
|
6757
|
-
// With our assumption, '/' always starts a comment. Determine comment type:
|
|
6758
|
-
charCodeAfterSlash = code.charCodeAt(start + 1);
|
|
6759
|
-
if (charCodeAfterSlash === 47 /*"/"*/)
|
|
6760
|
-
return [start, lineBreakPos + 1];
|
|
6761
|
-
start = code.indexOf('*/', start + 3) + 2;
|
|
6762
|
-
if (start > lineBreakPos) {
|
|
6763
|
-
lineBreakPos = code.indexOf('\n', start);
|
|
6764
|
-
}
|
|
6765
|
-
}
|
|
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;
|
|
6766
6695
|
}
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
start + findFirstLineBreakOutsideComment(code.original.slice(start, nextNode.start))[1];
|
|
6696
|
+
|
|
6697
|
+
/* eslint sort-keys: "off" */
|
|
6698
|
+
const ValueProperties = Symbol('Value Properties');
|
|
6699
|
+
const PURE = {
|
|
6700
|
+
hasEffectsWhenCalled() {
|
|
6701
|
+
return false;
|
|
6774
6702
|
}
|
|
6775
|
-
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
nextNode = statements[nextIndex];
|
|
6780
|
-
nextNodeNeedsBoundaries =
|
|
6781
|
-
nextNode === undefined ? false : !nextNode.included || nextNode.needsBoundaries;
|
|
6782
|
-
if (currentNodeNeedsBoundaries || nextNodeNeedsBoundaries) {
|
|
6783
|
-
nextNodeStart =
|
|
6784
|
-
currentNode.end +
|
|
6785
|
-
findFirstLineBreakOutsideComment(code.original.slice(currentNode.end, nextNode === undefined ? end : nextNode.start))[1];
|
|
6786
|
-
if (currentNode.included) {
|
|
6787
|
-
currentNodeNeedsBoundaries
|
|
6788
|
-
? currentNode.render(code, options, {
|
|
6789
|
-
end: nextNodeStart,
|
|
6790
|
-
start: currentNodeStart
|
|
6791
|
-
})
|
|
6792
|
-
: currentNode.render(code, options);
|
|
6793
|
-
}
|
|
6794
|
-
else {
|
|
6795
|
-
treeshakeNode(currentNode, code, currentNodeStart, nextNodeStart);
|
|
6796
|
-
}
|
|
6797
|
-
}
|
|
6798
|
-
else {
|
|
6799
|
-
currentNode.render(code, options);
|
|
6800
|
-
}
|
|
6703
|
+
};
|
|
6704
|
+
const IMPURE = {
|
|
6705
|
+
hasEffectsWhenCalled() {
|
|
6706
|
+
return true;
|
|
6801
6707
|
}
|
|
6802
|
-
}
|
|
6803
|
-
//
|
|
6804
|
-
|
|
6805
|
-
|
|
6806
|
-
|
|
6807
|
-
|
|
6808
|
-
|
|
6809
|
-
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
|
|
6814
|
-
|
|
6815
|
-
|
|
6816
|
-
|
|
6817
|
-
|
|
6818
|
-
|
|
6819
|
-
|
|
6820
|
-
|
|
6821
|
-
nextNodeStart++;
|
|
6822
|
-
if (node !== undefined) {
|
|
6823
|
-
splitUpNodes.push({
|
|
6824
|
-
contentEnd,
|
|
6825
|
-
end: nextNodeStart,
|
|
6826
|
-
node,
|
|
6827
|
-
separator,
|
|
6828
|
-
start
|
|
6829
|
-
});
|
|
6830
|
-
}
|
|
6831
|
-
node = nextNode;
|
|
6832
|
-
start = nextNodeStart;
|
|
6833
|
-
}
|
|
6834
|
-
splitUpNodes.push({
|
|
6835
|
-
contentEnd: end,
|
|
6836
|
-
end,
|
|
6837
|
-
node: node,
|
|
6838
|
-
separator: null,
|
|
6839
|
-
start
|
|
6840
|
-
});
|
|
6841
|
-
return splitUpNodes;
|
|
6842
|
-
}
|
|
6843
|
-
// This assumes there are only white-space and comments between start and end
|
|
6844
|
-
function removeLineBreaks(code, start, end) {
|
|
6845
|
-
while (true) {
|
|
6846
|
-
const [removeStart, removeEnd] = findFirstLineBreakOutsideComment(code.original.slice(start, end));
|
|
6847
|
-
if (removeStart === -1) {
|
|
6848
|
-
break;
|
|
6849
|
-
}
|
|
6850
|
-
code.remove(start + removeStart, (start += removeEnd));
|
|
6851
|
-
}
|
|
6852
|
-
}
|
|
6853
|
-
|
|
6854
|
-
class BlockScope extends ChildScope {
|
|
6855
|
-
addDeclaration(identifier, context, init, isHoisted) {
|
|
6856
|
-
if (isHoisted) {
|
|
6857
|
-
const variable = this.parent.addDeclaration(identifier, context, init, isHoisted);
|
|
6858
|
-
// Necessary to make sure the init is deoptimized for conditional declarations.
|
|
6859
|
-
// We cannot call deoptimizePath here.
|
|
6860
|
-
variable.markInitializersForDeoptimization();
|
|
6861
|
-
return variable;
|
|
6862
|
-
}
|
|
6863
|
-
else {
|
|
6864
|
-
return super.addDeclaration(identifier, context, init, false);
|
|
6865
|
-
}
|
|
6866
|
-
}
|
|
6867
|
-
}
|
|
6868
|
-
|
|
6869
|
-
class ExpressionStatement extends NodeBase {
|
|
6870
|
-
initialise() {
|
|
6871
|
-
if (this.directive &&
|
|
6872
|
-
this.directive !== 'use strict' &&
|
|
6873
|
-
this.parent.type === Program$1) {
|
|
6874
|
-
this.context.warn(
|
|
6875
|
-
// This is necessary, because either way (deleting or not) can lead to errors.
|
|
6876
|
-
{
|
|
6877
|
-
code: 'MODULE_LEVEL_DIRECTIVE',
|
|
6878
|
-
message: `Module level directives cause errors when bundled, '${this.directive}' was ignored.`
|
|
6879
|
-
}, this.start);
|
|
6880
|
-
}
|
|
6881
|
-
}
|
|
6882
|
-
render(code, options) {
|
|
6883
|
-
super.render(code, options);
|
|
6884
|
-
if (this.included)
|
|
6885
|
-
this.insertSemicolon(code);
|
|
6886
|
-
}
|
|
6887
|
-
shouldBeIncluded(context) {
|
|
6888
|
-
if (this.directive && this.directive !== 'use strict')
|
|
6889
|
-
return this.parent.type !== Program$1;
|
|
6890
|
-
return super.shouldBeIncluded(context);
|
|
6891
|
-
}
|
|
6892
|
-
applyDeoptimizations() { }
|
|
6893
|
-
}
|
|
6894
|
-
|
|
6895
|
-
class BlockStatement extends NodeBase {
|
|
6896
|
-
constructor() {
|
|
6897
|
-
super(...arguments);
|
|
6898
|
-
this.directlyIncluded = false;
|
|
6899
|
-
}
|
|
6900
|
-
addImplicitReturnExpressionToScope() {
|
|
6901
|
-
const lastStatement = this.body[this.body.length - 1];
|
|
6902
|
-
if (!lastStatement || lastStatement.type !== ReturnStatement$1) {
|
|
6903
|
-
this.scope.addReturnExpression(UNKNOWN_EXPRESSION);
|
|
6904
|
-
}
|
|
6905
|
-
}
|
|
6906
|
-
createScope(parentScope) {
|
|
6907
|
-
this.scope = this.parent.preventChildBlockScope
|
|
6908
|
-
? parentScope
|
|
6909
|
-
: new BlockScope(parentScope);
|
|
6910
|
-
}
|
|
6911
|
-
hasEffects(context) {
|
|
6912
|
-
if (this.deoptimizeBody)
|
|
6913
|
-
return true;
|
|
6914
|
-
for (const node of this.body) {
|
|
6915
|
-
if (context.brokenFlow)
|
|
6916
|
-
break;
|
|
6917
|
-
if (node.hasEffects(context))
|
|
6918
|
-
return true;
|
|
6919
|
-
}
|
|
6920
|
-
return false;
|
|
6921
|
-
}
|
|
6922
|
-
include(context, includeChildrenRecursively) {
|
|
6923
|
-
if (!(this.deoptimizeBody && this.directlyIncluded)) {
|
|
6924
|
-
this.included = true;
|
|
6925
|
-
this.directlyIncluded = true;
|
|
6926
|
-
if (this.deoptimizeBody)
|
|
6927
|
-
includeChildrenRecursively = true;
|
|
6928
|
-
for (const node of this.body) {
|
|
6929
|
-
if (includeChildrenRecursively || node.shouldBeIncluded(context))
|
|
6930
|
-
node.include(context, includeChildrenRecursively);
|
|
6931
|
-
}
|
|
6932
|
-
}
|
|
6933
|
-
}
|
|
6934
|
-
initialise() {
|
|
6935
|
-
const firstBodyStatement = this.body[0];
|
|
6936
|
-
this.deoptimizeBody =
|
|
6937
|
-
firstBodyStatement instanceof ExpressionStatement &&
|
|
6938
|
-
firstBodyStatement.directive === 'use asm';
|
|
6939
|
-
}
|
|
6940
|
-
render(code, options) {
|
|
6941
|
-
if (this.body.length) {
|
|
6942
|
-
renderStatementList(this.body, code, this.start + 1, this.end - 1, options);
|
|
6943
|
-
}
|
|
6944
|
-
else {
|
|
6945
|
-
super.render(code, options);
|
|
6946
|
-
}
|
|
6947
|
-
}
|
|
6948
|
-
}
|
|
6949
|
-
|
|
6950
|
-
class RestElement extends NodeBase {
|
|
6951
|
-
constructor() {
|
|
6952
|
-
super(...arguments);
|
|
6953
|
-
this.declarationInit = null;
|
|
6954
|
-
}
|
|
6955
|
-
addExportedVariables(variables, exportNamesByVariable) {
|
|
6956
|
-
this.argument.addExportedVariables(variables, exportNamesByVariable);
|
|
6957
|
-
}
|
|
6958
|
-
declare(kind, init) {
|
|
6959
|
-
this.declarationInit = init;
|
|
6960
|
-
return this.argument.declare(kind, UNKNOWN_EXPRESSION);
|
|
6961
|
-
}
|
|
6962
|
-
deoptimizePath(path) {
|
|
6963
|
-
path.length === 0 && this.argument.deoptimizePath(EMPTY_PATH);
|
|
6964
|
-
}
|
|
6965
|
-
hasEffectsWhenAssignedAtPath(path, context) {
|
|
6966
|
-
return path.length > 0 || this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
|
|
6967
|
-
}
|
|
6968
|
-
markDeclarationReached() {
|
|
6969
|
-
this.argument.markDeclarationReached();
|
|
6970
|
-
}
|
|
6971
|
-
applyDeoptimizations() {
|
|
6972
|
-
this.deoptimized = true;
|
|
6973
|
-
if (this.declarationInit !== null) {
|
|
6974
|
-
this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
|
|
6975
|
-
this.context.requestTreeshakingPass();
|
|
6976
|
-
}
|
|
6977
|
-
}
|
|
6978
|
-
}
|
|
6979
|
-
|
|
6980
|
-
class FunctionBase extends NodeBase {
|
|
6981
|
-
constructor() {
|
|
6982
|
-
super(...arguments);
|
|
6983
|
-
this.objectEntity = null;
|
|
6984
|
-
this.deoptimizedReturn = false;
|
|
6985
|
-
this.forceIncludeParameters = false;
|
|
6986
|
-
}
|
|
6987
|
-
deoptimizeCache() {
|
|
6988
|
-
this.forceIncludeParameters = true;
|
|
6989
|
-
}
|
|
6990
|
-
deoptimizeCallParameters() {
|
|
6991
|
-
this.forceIncludeParameters = true;
|
|
6992
|
-
}
|
|
6993
|
-
deoptimizePath(path) {
|
|
6994
|
-
this.getObjectEntity().deoptimizePath(path);
|
|
6995
|
-
if (path.length === 1 && path[0] === UnknownKey) {
|
|
6996
|
-
// A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
|
|
6997
|
-
// which means the return expression needs to be reassigned
|
|
6998
|
-
this.forceIncludeParameters = true;
|
|
6999
|
-
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
7000
|
-
}
|
|
7001
|
-
}
|
|
7002
|
-
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
7003
|
-
if (path.length > 0) {
|
|
7004
|
-
this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
7005
|
-
}
|
|
7006
|
-
}
|
|
7007
|
-
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
7008
|
-
return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
|
|
7009
|
-
}
|
|
7010
|
-
getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
|
|
7011
|
-
if (path.length > 0) {
|
|
7012
|
-
return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
|
|
7013
|
-
}
|
|
7014
|
-
if (this.async) {
|
|
7015
|
-
if (!this.deoptimizedReturn) {
|
|
7016
|
-
this.deoptimizedReturn = true;
|
|
7017
|
-
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
7018
|
-
this.context.requestTreeshakingPass();
|
|
7019
|
-
}
|
|
7020
|
-
return UNKNOWN_EXPRESSION;
|
|
7021
|
-
}
|
|
7022
|
-
return this.scope.getReturnExpression();
|
|
7023
|
-
}
|
|
7024
|
-
hasEffectsWhenAccessedAtPath(path, context) {
|
|
7025
|
-
return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
|
|
7026
|
-
}
|
|
7027
|
-
hasEffectsWhenAssignedAtPath(path, context) {
|
|
7028
|
-
return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
|
|
7029
|
-
}
|
|
7030
|
-
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
7031
|
-
var _a;
|
|
7032
|
-
if (path.length > 0) {
|
|
7033
|
-
return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
7034
|
-
}
|
|
7035
|
-
if (this.async) {
|
|
7036
|
-
const { propertyReadSideEffects } = this.context.options
|
|
7037
|
-
.treeshake;
|
|
7038
|
-
const returnExpression = this.scope.getReturnExpression();
|
|
7039
|
-
if (returnExpression.hasEffectsWhenCalledAtPath(['then'], { args: NO_ARGS, thisParam: null, withNew: false }, context) ||
|
|
7040
|
-
(propertyReadSideEffects &&
|
|
7041
|
-
(propertyReadSideEffects === 'always' ||
|
|
7042
|
-
returnExpression.hasEffectsWhenAccessedAtPath(['then'], context)))) {
|
|
7043
|
-
return true;
|
|
7044
|
-
}
|
|
7045
|
-
}
|
|
7046
|
-
for (let position = 0; position < this.params.length; position++) {
|
|
7047
|
-
const parameter = this.params[position];
|
|
7048
|
-
if (parameter instanceof AssignmentPattern) {
|
|
7049
|
-
if (parameter.left.hasEffects(context)) {
|
|
7050
|
-
return true;
|
|
7051
|
-
}
|
|
7052
|
-
const argumentValue = (_a = callOptions.args[position]) === null || _a === void 0 ? void 0 : _a.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
|
|
7053
|
-
if ((argumentValue === undefined || argumentValue === UnknownValue) &&
|
|
7054
|
-
parameter.right.hasEffects(context)) {
|
|
7055
|
-
return true;
|
|
7056
|
-
}
|
|
7057
|
-
}
|
|
7058
|
-
else if (parameter.hasEffects(context)) {
|
|
7059
|
-
return true;
|
|
7060
|
-
}
|
|
7061
|
-
}
|
|
7062
|
-
return false;
|
|
7063
|
-
}
|
|
7064
|
-
include(context, includeChildrenRecursively, { includeWithoutParameterDefaults } = BLANK) {
|
|
7065
|
-
if (!this.deoptimized)
|
|
7066
|
-
this.applyDeoptimizations();
|
|
7067
|
-
this.included = true;
|
|
7068
|
-
const { brokenFlow } = context;
|
|
7069
|
-
context.brokenFlow = BROKEN_FLOW_NONE;
|
|
7070
|
-
this.body.include(context, includeChildrenRecursively);
|
|
7071
|
-
context.brokenFlow = brokenFlow;
|
|
7072
|
-
if (!includeWithoutParameterDefaults ||
|
|
7073
|
-
includeChildrenRecursively ||
|
|
7074
|
-
this.forceIncludeParameters) {
|
|
7075
|
-
for (const param of this.params) {
|
|
7076
|
-
param.include(context, includeChildrenRecursively);
|
|
7077
|
-
}
|
|
7078
|
-
}
|
|
7079
|
-
}
|
|
7080
|
-
includeCallArguments(context, args) {
|
|
7081
|
-
var _a;
|
|
7082
|
-
for (let position = 0; position < this.params.length; position++) {
|
|
7083
|
-
const parameter = this.params[position];
|
|
7084
|
-
if (parameter instanceof AssignmentPattern) {
|
|
7085
|
-
if (parameter.left.shouldBeIncluded(context)) {
|
|
7086
|
-
parameter.left.include(context, false);
|
|
7087
|
-
}
|
|
7088
|
-
const argumentValue = (_a = args[position]) === null || _a === void 0 ? void 0 : _a.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
|
|
7089
|
-
// If argumentValue === UnknownTruthyValue, then we do not need to
|
|
7090
|
-
// include the default
|
|
7091
|
-
if ((argumentValue === undefined || argumentValue === UnknownValue) &&
|
|
7092
|
-
(this.parameterVariables[position].some(variable => variable.included) ||
|
|
7093
|
-
parameter.right.shouldBeIncluded(context))) {
|
|
7094
|
-
parameter.right.include(context, false);
|
|
7095
|
-
}
|
|
7096
|
-
}
|
|
7097
|
-
else if (parameter.shouldBeIncluded(context)) {
|
|
7098
|
-
parameter.include(context, false);
|
|
7099
|
-
}
|
|
7100
|
-
}
|
|
7101
|
-
this.scope.includeCallArguments(context, args);
|
|
7102
|
-
}
|
|
7103
|
-
initialise() {
|
|
7104
|
-
this.parameterVariables = this.params.map(param => param.declare('parameter', UNKNOWN_EXPRESSION));
|
|
7105
|
-
this.scope.addParameterVariables(this.parameterVariables, this.params[this.params.length - 1] instanceof RestElement);
|
|
7106
|
-
if (this.body instanceof BlockStatement) {
|
|
7107
|
-
this.body.addImplicitReturnExpressionToScope();
|
|
7108
|
-
}
|
|
7109
|
-
else {
|
|
7110
|
-
this.scope.addReturnExpression(this.body);
|
|
7111
|
-
}
|
|
7112
|
-
}
|
|
7113
|
-
parseNode(esTreeNode) {
|
|
7114
|
-
if (esTreeNode.body.type === BlockStatement$1) {
|
|
7115
|
-
this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
|
|
7116
|
-
}
|
|
7117
|
-
super.parseNode(esTreeNode);
|
|
7118
|
-
}
|
|
7119
|
-
applyDeoptimizations() {
|
|
7120
|
-
// We currently do not track deoptimizations of default values, deoptimize them
|
|
7121
|
-
// just as we deoptimize call arguments
|
|
7122
|
-
for (const param of this.params) {
|
|
7123
|
-
if (param instanceof AssignmentPattern) {
|
|
7124
|
-
param.right.deoptimizePath(UNKNOWN_PATH);
|
|
7125
|
-
}
|
|
7126
|
-
}
|
|
7127
|
-
}
|
|
7128
|
-
}
|
|
7129
|
-
FunctionBase.prototype.preventChildBlockScope = true;
|
|
7130
|
-
|
|
7131
|
-
class ArrowFunctionExpression extends FunctionBase {
|
|
7132
|
-
constructor() {
|
|
7133
|
-
super(...arguments);
|
|
7134
|
-
this.objectEntity = null;
|
|
7135
|
-
}
|
|
7136
|
-
createScope(parentScope) {
|
|
7137
|
-
this.scope = new ReturnValueScope(parentScope, this.context);
|
|
7138
|
-
}
|
|
7139
|
-
hasEffects() {
|
|
7140
|
-
if (!this.deoptimized)
|
|
7141
|
-
this.applyDeoptimizations();
|
|
7142
|
-
return false;
|
|
7143
|
-
}
|
|
7144
|
-
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
7145
|
-
if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
|
|
7146
|
-
return true;
|
|
7147
|
-
const { ignore, brokenFlow } = context;
|
|
7148
|
-
context.ignore = {
|
|
7149
|
-
breaks: false,
|
|
7150
|
-
continues: false,
|
|
7151
|
-
labels: new Set(),
|
|
7152
|
-
returnYield: true
|
|
7153
|
-
};
|
|
7154
|
-
if (this.body.hasEffects(context))
|
|
7155
|
-
return true;
|
|
7156
|
-
context.ignore = ignore;
|
|
7157
|
-
context.brokenFlow = brokenFlow;
|
|
7158
|
-
return false;
|
|
7159
|
-
}
|
|
7160
|
-
getObjectEntity() {
|
|
7161
|
-
if (this.objectEntity !== null) {
|
|
7162
|
-
return this.objectEntity;
|
|
7163
|
-
}
|
|
7164
|
-
return (this.objectEntity = new ObjectEntity([], OBJECT_PROTOTYPE));
|
|
7165
|
-
}
|
|
7166
|
-
}
|
|
7167
|
-
|
|
7168
|
-
function getSystemExportStatement(exportedVariables, { exportNamesByVariable, snippets: { _, getObject, getPropertyAccess } }, modifier = '') {
|
|
7169
|
-
if (exportedVariables.length === 1 &&
|
|
7170
|
-
exportNamesByVariable.get(exportedVariables[0]).length === 1) {
|
|
7171
|
-
const variable = exportedVariables[0];
|
|
7172
|
-
return `exports('${exportNamesByVariable.get(variable)}',${_}${variable.getName(getPropertyAccess)}${modifier})`;
|
|
7173
|
-
}
|
|
7174
|
-
else {
|
|
7175
|
-
const fields = [];
|
|
7176
|
-
for (const variable of exportedVariables) {
|
|
7177
|
-
for (const exportName of exportNamesByVariable.get(variable)) {
|
|
7178
|
-
fields.push([exportName, variable.getName(getPropertyAccess) + modifier]);
|
|
7179
|
-
}
|
|
7180
|
-
}
|
|
7181
|
-
return `exports(${getObject(fields, { lineBreakIndent: null })})`;
|
|
7182
|
-
}
|
|
7183
|
-
}
|
|
7184
|
-
function renderSystemExportExpression(exportedVariable, expressionStart, expressionEnd, code, { exportNamesByVariable, snippets: { _ } }) {
|
|
7185
|
-
code.prependRight(expressionStart, `exports('${exportNamesByVariable.get(exportedVariable)}',${_}`);
|
|
7186
|
-
code.appendLeft(expressionEnd, ')');
|
|
7187
|
-
}
|
|
7188
|
-
function renderSystemExportFunction(exportedVariables, expressionStart, expressionEnd, needsParens, code, options) {
|
|
7189
|
-
const { _, getDirectReturnIifeLeft } = options.snippets;
|
|
7190
|
-
code.prependRight(expressionStart, getDirectReturnIifeLeft(['v'], `${getSystemExportStatement(exportedVariables, options)},${_}v`, { needsArrowReturnParens: true, needsWrappedFunction: needsParens }));
|
|
7191
|
-
code.appendLeft(expressionEnd, ')');
|
|
7192
|
-
}
|
|
7193
|
-
function renderSystemExportSequenceAfterExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options) {
|
|
7194
|
-
const { _, getPropertyAccess } = options.snippets;
|
|
7195
|
-
code.appendLeft(expressionEnd, `,${_}${getSystemExportStatement([exportedVariable], options)},${_}${exportedVariable.getName(getPropertyAccess)}`);
|
|
7196
|
-
if (needsParens) {
|
|
7197
|
-
code.prependRight(expressionStart, '(');
|
|
7198
|
-
code.appendLeft(expressionEnd, ')');
|
|
7199
|
-
}
|
|
7200
|
-
}
|
|
7201
|
-
function renderSystemExportSequenceBeforeExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options, modifier) {
|
|
7202
|
-
const { _ } = options.snippets;
|
|
7203
|
-
code.prependRight(expressionStart, `${getSystemExportStatement([exportedVariable], options, modifier)},${_}`);
|
|
7204
|
-
if (needsParens) {
|
|
7205
|
-
code.prependRight(expressionStart, '(');
|
|
7206
|
-
code.appendLeft(expressionEnd, ')');
|
|
7207
|
-
}
|
|
7208
|
-
}
|
|
7209
|
-
|
|
7210
|
-
//@ts-check
|
|
7211
|
-
/** @typedef { import('estree').Node} Node */
|
|
7212
|
-
/** @typedef {Node | {
|
|
7213
|
-
* type: 'PropertyDefinition';
|
|
7214
|
-
* computed: boolean;
|
|
7215
|
-
* value: Node
|
|
7216
|
-
* }} NodeWithPropertyDefinition */
|
|
7217
|
-
|
|
7218
|
-
/**
|
|
7219
|
-
*
|
|
7220
|
-
* @param {NodeWithPropertyDefinition} node
|
|
7221
|
-
* @param {NodeWithPropertyDefinition} parent
|
|
7222
|
-
* @returns boolean
|
|
7223
|
-
*/
|
|
7224
|
-
function is_reference (node, parent) {
|
|
7225
|
-
if (node.type === 'MemberExpression') {
|
|
7226
|
-
return !node.computed && is_reference(node.object, node);
|
|
7227
|
-
}
|
|
7228
|
-
|
|
7229
|
-
if (node.type === 'Identifier') {
|
|
7230
|
-
if (!parent) return true;
|
|
7231
|
-
|
|
7232
|
-
switch (parent.type) {
|
|
7233
|
-
// disregard `bar` in `foo.bar`
|
|
7234
|
-
case 'MemberExpression': return parent.computed || node === parent.object;
|
|
7235
|
-
|
|
7236
|
-
// disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
|
|
7237
|
-
case 'MethodDefinition': return parent.computed;
|
|
7238
|
-
|
|
7239
|
-
// disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
|
|
7240
|
-
case 'PropertyDefinition': return parent.computed || node === parent.value;
|
|
7241
|
-
|
|
7242
|
-
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
|
|
7243
|
-
case 'Property': return parent.computed || node === parent.value;
|
|
7244
|
-
|
|
7245
|
-
// disregard the `bar` in `export { foo as bar }` or
|
|
7246
|
-
// the foo in `import { foo as bar }`
|
|
7247
|
-
case 'ExportSpecifier':
|
|
7248
|
-
case 'ImportSpecifier': return node === parent.local;
|
|
7249
|
-
|
|
7250
|
-
// disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
|
|
7251
|
-
case 'LabeledStatement':
|
|
7252
|
-
case 'BreakStatement':
|
|
7253
|
-
case 'ContinueStatement': return false;
|
|
7254
|
-
default: return true;
|
|
7255
|
-
}
|
|
7256
|
-
}
|
|
7257
|
-
|
|
7258
|
-
return false;
|
|
7259
|
-
}
|
|
7260
|
-
|
|
7261
|
-
/* eslint sort-keys: "off" */
|
|
7262
|
-
const ValueProperties = Symbol('Value Properties');
|
|
7263
|
-
const PURE = {
|
|
7264
|
-
hasEffectsWhenCalled() {
|
|
7265
|
-
return false;
|
|
7266
|
-
}
|
|
7267
|
-
};
|
|
7268
|
-
const IMPURE = {
|
|
7269
|
-
hasEffectsWhenCalled() {
|
|
7270
|
-
return true;
|
|
7271
|
-
}
|
|
7272
|
-
};
|
|
7273
|
-
// We use shortened variables to reduce file size here
|
|
7274
|
-
/* OBJECT */
|
|
7275
|
-
const O = {
|
|
7276
|
-
__proto__: null,
|
|
7277
|
-
[ValueProperties]: IMPURE
|
|
7278
|
-
};
|
|
7279
|
-
/* PURE FUNCTION */
|
|
7280
|
-
const PF = {
|
|
7281
|
-
__proto__: null,
|
|
7282
|
-
[ValueProperties]: PURE
|
|
7283
|
-
};
|
|
7284
|
-
/* FUNCTION THAT MUTATES FIRST ARG WITHOUT TRIGGERING ACCESSORS */
|
|
7285
|
-
const MUTATES_ARG_WITHOUT_ACCESSOR = {
|
|
7286
|
-
__proto__: null,
|
|
7287
|
-
[ValueProperties]: {
|
|
7288
|
-
hasEffectsWhenCalled(callOptions, context) {
|
|
7289
|
-
return (!callOptions.args.length ||
|
|
7290
|
-
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));
|
|
7291
6727
|
}
|
|
7292
6728
|
}
|
|
7293
6729
|
};
|
|
@@ -8104,227 +7540,688 @@ const knownGlobals = {
|
|
|
8104
7540
|
for (const global of ['window', 'global', 'self', 'globalThis']) {
|
|
8105
7541
|
knownGlobals[global] = knownGlobals;
|
|
8106
7542
|
}
|
|
8107
|
-
function getGlobalAtPath(path) {
|
|
8108
|
-
let currentGlobal = knownGlobals;
|
|
8109
|
-
for (const pathSegment of path) {
|
|
8110
|
-
if (typeof pathSegment !== 'string') {
|
|
8111
|
-
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);
|
|
8112
7830
|
}
|
|
8113
|
-
|
|
8114
|
-
|
|
8115
|
-
|
|
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);
|
|
8116
7866
|
}
|
|
8117
7867
|
}
|
|
8118
|
-
|
|
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
|
+
}
|
|
8119
7918
|
}
|
|
8120
7919
|
|
|
8121
|
-
class
|
|
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;
|
|
7928
|
+
}
|
|
7929
|
+
else {
|
|
7930
|
+
return super.addDeclaration(identifier, context, init, false);
|
|
7931
|
+
}
|
|
7932
|
+
}
|
|
7933
|
+
}
|
|
7934
|
+
|
|
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 {
|
|
8122
7962
|
constructor() {
|
|
8123
7963
|
super(...arguments);
|
|
8124
|
-
|
|
8125
|
-
// been reassigned
|
|
8126
|
-
this.isReassigned = true;
|
|
7964
|
+
this.directlyIncluded = false;
|
|
8127
7965
|
}
|
|
8128
|
-
|
|
8129
|
-
|
|
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
|
+
}
|
|
8130
7971
|
}
|
|
8131
|
-
|
|
8132
|
-
|
|
8133
|
-
|
|
8134
|
-
|
|
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;
|
|
8135
7985
|
}
|
|
8136
|
-
return
|
|
7986
|
+
return false;
|
|
8137
7987
|
}
|
|
8138
|
-
|
|
8139
|
-
|
|
8140
|
-
|
|
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
|
+
}
|
|
8141
8013
|
}
|
|
8142
8014
|
}
|
|
8143
8015
|
|
|
8144
|
-
|
|
8145
|
-
__proto__: null,
|
|
8146
|
-
class: true,
|
|
8147
|
-
const: true,
|
|
8148
|
-
let: true,
|
|
8149
|
-
var: true
|
|
8150
|
-
};
|
|
8151
|
-
class Identifier extends NodeBase {
|
|
8016
|
+
class RestElement extends NodeBase {
|
|
8152
8017
|
constructor() {
|
|
8153
8018
|
super(...arguments);
|
|
8154
|
-
this.
|
|
8155
|
-
|
|
8019
|
+
this.declarationInit = null;
|
|
8020
|
+
}
|
|
8021
|
+
addExportedVariables(variables, exportNamesByVariable) {
|
|
8022
|
+
this.argument.addExportedVariables(variables, exportNamesByVariable);
|
|
8023
|
+
}
|
|
8024
|
+
declare(kind, init) {
|
|
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);
|
|
8156
8030
|
}
|
|
8157
|
-
|
|
8158
|
-
|
|
8159
|
-
variables.push(this.variable);
|
|
8160
|
-
}
|
|
8031
|
+
hasEffectsWhenAssignedAtPath(path, context) {
|
|
8032
|
+
return path.length > 0 || this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
|
|
8161
8033
|
}
|
|
8162
|
-
|
|
8163
|
-
|
|
8164
|
-
this.variable = this.scope.findVariable(this.name);
|
|
8165
|
-
this.variable.addReference(this);
|
|
8166
|
-
}
|
|
8034
|
+
markDeclarationReached() {
|
|
8035
|
+
this.argument.markDeclarationReached();
|
|
8167
8036
|
}
|
|
8168
|
-
|
|
8169
|
-
|
|
8170
|
-
|
|
8171
|
-
|
|
8172
|
-
|
|
8173
|
-
variable = this.scope.addDeclaration(this, this.context, init, true);
|
|
8174
|
-
if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
|
|
8175
|
-
// Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
|
|
8176
|
-
variable.markInitializersForDeoptimization();
|
|
8177
|
-
}
|
|
8178
|
-
break;
|
|
8179
|
-
case 'function':
|
|
8180
|
-
// in strict mode, functions are only hoisted within a scope but not across block scopes
|
|
8181
|
-
variable = this.scope.addDeclaration(this, this.context, init, false);
|
|
8182
|
-
break;
|
|
8183
|
-
case 'let':
|
|
8184
|
-
case 'const':
|
|
8185
|
-
case 'class':
|
|
8186
|
-
variable = this.scope.addDeclaration(this, this.context, init, false);
|
|
8187
|
-
break;
|
|
8188
|
-
case 'parameter':
|
|
8189
|
-
variable = this.scope.addParameterDeclaration(this);
|
|
8190
|
-
break;
|
|
8191
|
-
/* istanbul ignore next */
|
|
8192
|
-
default:
|
|
8193
|
-
/* istanbul ignore next */
|
|
8194
|
-
throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
|
|
8037
|
+
applyDeoptimizations() {
|
|
8038
|
+
this.deoptimized = true;
|
|
8039
|
+
if (this.declarationInit !== null) {
|
|
8040
|
+
this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
|
|
8041
|
+
this.context.requestTreeshakingPass();
|
|
8195
8042
|
}
|
|
8196
|
-
variable.kind = kind;
|
|
8197
|
-
return [(this.variable = variable)];
|
|
8198
8043
|
}
|
|
8199
|
-
|
|
8200
|
-
|
|
8044
|
+
}
|
|
8045
|
+
|
|
8046
|
+
class FunctionBase extends NodeBase {
|
|
8047
|
+
constructor() {
|
|
8048
|
+
super(...arguments);
|
|
8049
|
+
this.objectEntity = null;
|
|
8050
|
+
this.deoptimizedReturn = false;
|
|
8201
8051
|
}
|
|
8202
8052
|
deoptimizePath(path) {
|
|
8203
|
-
|
|
8204
|
-
if (path.length ===
|
|
8205
|
-
|
|
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);
|
|
8206
8058
|
}
|
|
8207
|
-
// We keep conditional chaining because an unknown Node could have an
|
|
8208
|
-
// Identifier as property that might be deoptimized by default
|
|
8209
|
-
(_a = this.variable) === null || _a === void 0 ? void 0 : _a.deoptimizePath(path);
|
|
8210
8059
|
}
|
|
8211
8060
|
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
8212
|
-
|
|
8061
|
+
if (path.length > 0) {
|
|
8062
|
+
this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
8063
|
+
}
|
|
8213
8064
|
}
|
|
8214
8065
|
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
8215
|
-
return this.
|
|
8066
|
+
return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
|
|
8216
8067
|
}
|
|
8217
8068
|
getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
|
|
8218
|
-
|
|
8219
|
-
|
|
8220
|
-
hasEffects() {
|
|
8221
|
-
if (!this.deoptimized)
|
|
8222
|
-
this.applyDeoptimizations();
|
|
8223
|
-
if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
|
|
8224
|
-
return true;
|
|
8069
|
+
if (path.length > 0) {
|
|
8070
|
+
return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
|
|
8225
8071
|
}
|
|
8226
|
-
|
|
8227
|
-
this.
|
|
8228
|
-
|
|
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();
|
|
8229
8081
|
}
|
|
8230
8082
|
hasEffectsWhenAccessedAtPath(path, context) {
|
|
8231
|
-
return
|
|
8232
|
-
this.getVariableRespectingTDZ().hasEffectsWhenAccessedAtPath(path, context));
|
|
8083
|
+
return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
|
|
8233
8084
|
}
|
|
8234
8085
|
hasEffectsWhenAssignedAtPath(path, context) {
|
|
8235
|
-
return
|
|
8086
|
+
return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
|
|
8236
8087
|
}
|
|
8237
8088
|
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
8238
|
-
|
|
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;
|
|
8239
8108
|
}
|
|
8240
|
-
include() {
|
|
8109
|
+
include(context, includeChildrenRecursively) {
|
|
8241
8110
|
if (!this.deoptimized)
|
|
8242
8111
|
this.applyDeoptimizations();
|
|
8243
|
-
|
|
8244
|
-
|
|
8245
|
-
|
|
8246
|
-
|
|
8247
|
-
|
|
8248
|
-
}
|
|
8112
|
+
this.included = true;
|
|
8113
|
+
const { brokenFlow } = context;
|
|
8114
|
+
context.brokenFlow = BROKEN_FLOW_NONE;
|
|
8115
|
+
this.body.include(context, includeChildrenRecursively);
|
|
8116
|
+
context.brokenFlow = brokenFlow;
|
|
8249
8117
|
}
|
|
8250
8118
|
includeCallArguments(context, args) {
|
|
8251
|
-
this.
|
|
8119
|
+
this.scope.includeCallArguments(context, args);
|
|
8252
8120
|
}
|
|
8253
|
-
|
|
8254
|
-
|
|
8255
|
-
if (this.
|
|
8256
|
-
|
|
8257
|
-
if (!(this.variable instanceof LocalVariable) ||
|
|
8258
|
-
!this.variable.kind ||
|
|
8259
|
-
!(this.variable.kind in tdzVariableKinds)) {
|
|
8260
|
-
return (this.isTDZAccess = false);
|
|
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();
|
|
8261
8125
|
}
|
|
8262
|
-
|
|
8263
|
-
|
|
8264
|
-
this.variable.declarations.length === 1 &&
|
|
8265
|
-
(decl_id = this.variable.declarations[0]) &&
|
|
8266
|
-
this.start < decl_id.start &&
|
|
8267
|
-
closestParentFunctionOrProgram(this) === closestParentFunctionOrProgram(decl_id)) {
|
|
8268
|
-
// a variable accessed before its declaration
|
|
8269
|
-
// in the same function or at top level of module
|
|
8270
|
-
return (this.isTDZAccess = true);
|
|
8126
|
+
else {
|
|
8127
|
+
this.scope.addReturnExpression(this.body);
|
|
8271
8128
|
}
|
|
8272
|
-
|
|
8273
|
-
|
|
8274
|
-
|
|
8275
|
-
|
|
8129
|
+
}
|
|
8130
|
+
parseNode(esTreeNode) {
|
|
8131
|
+
if (esTreeNode.body.type === BlockStatement$1) {
|
|
8132
|
+
this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
|
|
8276
8133
|
}
|
|
8277
|
-
|
|
8134
|
+
super.parseNode(esTreeNode);
|
|
8278
8135
|
}
|
|
8279
|
-
|
|
8280
|
-
|
|
8136
|
+
applyDeoptimizations() { }
|
|
8137
|
+
}
|
|
8138
|
+
FunctionBase.prototype.preventChildBlockScope = true;
|
|
8139
|
+
|
|
8140
|
+
class ArrowFunctionExpression extends FunctionBase {
|
|
8141
|
+
constructor() {
|
|
8142
|
+
super(...arguments);
|
|
8143
|
+
this.objectEntity = null;
|
|
8281
8144
|
}
|
|
8282
|
-
|
|
8283
|
-
|
|
8284
|
-
|
|
8285
|
-
|
|
8286
|
-
|
|
8287
|
-
|
|
8288
|
-
|
|
8289
|
-
|
|
8290
|
-
|
|
8291
|
-
|
|
8292
|
-
|
|
8293
|
-
|
|
8294
|
-
|
|
8295
|
-
|
|
8296
|
-
|
|
8297
|
-
|
|
8298
|
-
|
|
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);
|
|
8299
8174
|
}
|
|
8300
8175
|
}
|
|
8301
8176
|
}
|
|
8302
|
-
|
|
8303
|
-
this.
|
|
8304
|
-
|
|
8305
|
-
this.variable.consolidateInitializers();
|
|
8306
|
-
this.context.requestTreeshakingPass();
|
|
8177
|
+
getObjectEntity() {
|
|
8178
|
+
if (this.objectEntity !== null) {
|
|
8179
|
+
return this.objectEntity;
|
|
8307
8180
|
}
|
|
8181
|
+
return (this.objectEntity = new ObjectEntity([], OBJECT_PROTOTYPE));
|
|
8308
8182
|
}
|
|
8309
|
-
|
|
8310
|
-
|
|
8311
|
-
|
|
8312
|
-
|
|
8313
|
-
|
|
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})`;
|
|
8314
8190
|
}
|
|
8315
|
-
|
|
8316
|
-
|
|
8317
|
-
|
|
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
|
+
}
|
|
8318
8197
|
}
|
|
8319
|
-
return
|
|
8198
|
+
return `exports(${getObject(fields, { lineBreakIndent: null })})`;
|
|
8199
|
+
}
|
|
8200
|
+
}
|
|
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, ')');
|
|
8320
8216
|
}
|
|
8321
8217
|
}
|
|
8322
|
-
function
|
|
8323
|
-
|
|
8324
|
-
|
|
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, ')');
|
|
8325
8224
|
}
|
|
8326
|
-
// one of: ArrowFunctionExpression, FunctionDeclaration, FunctionExpression or Program
|
|
8327
|
-
return node;
|
|
8328
8225
|
}
|
|
8329
8226
|
|
|
8330
8227
|
class ObjectPattern extends NodeBase {
|
|
@@ -8449,6 +8346,46 @@ class AssignmentExpression extends NodeBase {
|
|
|
8449
8346
|
}
|
|
8450
8347
|
}
|
|
8451
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
|
+
|
|
8452
8389
|
class ArgumentsVariable extends LocalVariable {
|
|
8453
8390
|
constructor(context) {
|
|
8454
8391
|
super('arguments', null, UNKNOWN_EXPRESSION, context);
|
|
@@ -8587,12 +8524,16 @@ class FunctionNode extends FunctionBase {
|
|
|
8587
8524
|
context.ignore = ignore;
|
|
8588
8525
|
return false;
|
|
8589
8526
|
}
|
|
8590
|
-
include(context, includeChildrenRecursively
|
|
8527
|
+
include(context, includeChildrenRecursively) {
|
|
8591
8528
|
var _a;
|
|
8529
|
+
super.include(context, includeChildrenRecursively);
|
|
8592
8530
|
(_a = this.id) === null || _a === void 0 ? void 0 : _a.include();
|
|
8593
|
-
|
|
8594
|
-
|
|
8595
|
-
|
|
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
|
+
}
|
|
8596
8537
|
}
|
|
8597
8538
|
initialise() {
|
|
8598
8539
|
var _a;
|
|
@@ -8721,6 +8662,31 @@ class BreakStatement extends NodeBase {
|
|
|
8721
8662
|
}
|
|
8722
8663
|
}
|
|
8723
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
|
+
|
|
8724
8690
|
class Literal extends NodeBase {
|
|
8725
8691
|
deoptimizeThisOnEventAtPath() { }
|
|
8726
8692
|
getLiteralValueAtPath(path) {
|
|
@@ -9184,7 +9150,7 @@ class CallExpression extends CallExpressionBase {
|
|
|
9184
9150
|
}
|
|
9185
9151
|
else {
|
|
9186
9152
|
this.included = true;
|
|
9187
|
-
this.callee.include(context, false
|
|
9153
|
+
this.callee.include(context, false);
|
|
9188
9154
|
}
|
|
9189
9155
|
this.callee.includeCallArguments(context, this.arguments);
|
|
9190
9156
|
const returnExpression = this.getReturnExpression();
|
|
@@ -9197,28 +9163,7 @@ class CallExpression extends CallExpressionBase {
|
|
|
9197
9163
|
isCalleeOfRenderedParent: true,
|
|
9198
9164
|
renderedSurroundingElement
|
|
9199
9165
|
});
|
|
9200
|
-
|
|
9201
|
-
if (this.arguments[this.arguments.length - 1].included) {
|
|
9202
|
-
for (const arg of this.arguments) {
|
|
9203
|
-
arg.render(code, options);
|
|
9204
|
-
}
|
|
9205
|
-
}
|
|
9206
|
-
else {
|
|
9207
|
-
let lastIncludedIndex = this.arguments.length - 2;
|
|
9208
|
-
while (lastIncludedIndex >= 0 && !this.arguments[lastIncludedIndex].included) {
|
|
9209
|
-
lastIncludedIndex--;
|
|
9210
|
-
}
|
|
9211
|
-
if (lastIncludedIndex >= 0) {
|
|
9212
|
-
for (let index = 0; index <= lastIncludedIndex; index++) {
|
|
9213
|
-
this.arguments[index].render(code, options);
|
|
9214
|
-
}
|
|
9215
|
-
code.remove(findFirstOccurrenceOutsideComment(code.original, ',', this.arguments[lastIncludedIndex].end), this.end - 1);
|
|
9216
|
-
}
|
|
9217
|
-
else {
|
|
9218
|
-
code.remove(findFirstOccurrenceOutsideComment(code.original, '(', this.callee.end) + 1, this.end - 1);
|
|
9219
|
-
}
|
|
9220
|
-
}
|
|
9221
|
-
}
|
|
9166
|
+
renderCallArguments(code, options, this);
|
|
9222
9167
|
}
|
|
9223
9168
|
applyDeoptimizations() {
|
|
9224
9169
|
this.deoptimized = true;
|
|
@@ -9377,41 +9322,6 @@ class MethodDefinition extends MethodBase {
|
|
|
9377
9322
|
applyDeoptimizations() { }
|
|
9378
9323
|
}
|
|
9379
9324
|
|
|
9380
|
-
class PropertyDefinition extends NodeBase {
|
|
9381
|
-
deoptimizePath(path) {
|
|
9382
|
-
var _a;
|
|
9383
|
-
(_a = this.value) === null || _a === void 0 ? void 0 : _a.deoptimizePath(path);
|
|
9384
|
-
}
|
|
9385
|
-
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
9386
|
-
var _a;
|
|
9387
|
-
(_a = this.value) === null || _a === void 0 ? void 0 : _a.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
9388
|
-
}
|
|
9389
|
-
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
9390
|
-
return this.value
|
|
9391
|
-
? this.value.getLiteralValueAtPath(path, recursionTracker, origin)
|
|
9392
|
-
: UnknownValue;
|
|
9393
|
-
}
|
|
9394
|
-
getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
|
|
9395
|
-
return this.value
|
|
9396
|
-
? this.value.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin)
|
|
9397
|
-
: UNKNOWN_EXPRESSION;
|
|
9398
|
-
}
|
|
9399
|
-
hasEffects(context) {
|
|
9400
|
-
var _a;
|
|
9401
|
-
return this.key.hasEffects(context) || (this.static && !!((_a = this.value) === null || _a === void 0 ? void 0 : _a.hasEffects(context)));
|
|
9402
|
-
}
|
|
9403
|
-
hasEffectsWhenAccessedAtPath(path, context) {
|
|
9404
|
-
return !this.value || this.value.hasEffectsWhenAccessedAtPath(path, context);
|
|
9405
|
-
}
|
|
9406
|
-
hasEffectsWhenAssignedAtPath(path, context) {
|
|
9407
|
-
return !this.value || this.value.hasEffectsWhenAssignedAtPath(path, context);
|
|
9408
|
-
}
|
|
9409
|
-
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
9410
|
-
return !this.value || this.value.hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
9411
|
-
}
|
|
9412
|
-
applyDeoptimizations() { }
|
|
9413
|
-
}
|
|
9414
|
-
|
|
9415
9325
|
class ObjectMember extends ExpressionEntity {
|
|
9416
9326
|
constructor(object, key) {
|
|
9417
9327
|
super();
|
|
@@ -9453,14 +9363,7 @@ class ClassNode extends NodeBase {
|
|
|
9453
9363
|
this.getObjectEntity().deoptimizeAllProperties();
|
|
9454
9364
|
}
|
|
9455
9365
|
deoptimizePath(path) {
|
|
9456
|
-
var _a, _b;
|
|
9457
9366
|
this.getObjectEntity().deoptimizePath(path);
|
|
9458
|
-
if (path.length === 1 && path[0] === UnknownKey) {
|
|
9459
|
-
// A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
|
|
9460
|
-
// which means the constructor needs to be reassigned
|
|
9461
|
-
(_a = this.classConstructor) === null || _a === void 0 ? void 0 : _a.deoptimizePath(UNKNOWN_PATH);
|
|
9462
|
-
(_b = this.superClass) === null || _b === void 0 ? void 0 : _b.deoptimizePath(UNKNOWN_PATH);
|
|
9463
|
-
}
|
|
9464
9367
|
}
|
|
9465
9368
|
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
9466
9369
|
this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
@@ -9522,7 +9425,6 @@ class ClassNode extends NodeBase {
|
|
|
9522
9425
|
this.classConstructor = null;
|
|
9523
9426
|
}
|
|
9524
9427
|
applyDeoptimizations() {
|
|
9525
|
-
var _a, _b;
|
|
9526
9428
|
this.deoptimized = true;
|
|
9527
9429
|
for (const definition of this.body.body) {
|
|
9528
9430
|
if (!(definition.static ||
|
|
@@ -9530,11 +9432,7 @@ class ClassNode extends NodeBase {
|
|
|
9530
9432
|
// Calls to methods are not tracked, ensure that the return value is deoptimized
|
|
9531
9433
|
definition.deoptimizePath(UNKNOWN_PATH);
|
|
9532
9434
|
}
|
|
9533
|
-
else if (definition instanceof PropertyDefinition) {
|
|
9534
|
-
(_a = definition.value) === null || _a === void 0 ? void 0 : _a.deoptimizeCallParameters();
|
|
9535
|
-
}
|
|
9536
9435
|
}
|
|
9537
|
-
(_b = this.superClass) === null || _b === void 0 ? void 0 : _b.deoptimizeCallParameters();
|
|
9538
9436
|
this.context.requestTreeshakingPass();
|
|
9539
9437
|
}
|
|
9540
9438
|
getObjectEntity() {
|
|
@@ -9868,9 +9766,6 @@ class ExportAllDeclaration extends NodeBase {
|
|
|
9868
9766
|
ExportAllDeclaration.prototype.needsBoundaries = true;
|
|
9869
9767
|
|
|
9870
9768
|
class FunctionDeclaration extends FunctionNode {
|
|
9871
|
-
include(context, includeChildrenRecursively) {
|
|
9872
|
-
super.include(context, includeChildrenRecursively, { includeWithoutParameterDefaults: true });
|
|
9873
|
-
}
|
|
9874
9769
|
initialise() {
|
|
9875
9770
|
super.initialise();
|
|
9876
9771
|
if (this.id !== null) {
|
|
@@ -10756,13 +10651,16 @@ class LogicalExpression extends NodeBase {
|
|
|
10756
10651
|
this.usedBranch = null;
|
|
10757
10652
|
}
|
|
10758
10653
|
deoptimizeCache() {
|
|
10759
|
-
if (this.usedBranch
|
|
10654
|
+
if (this.usedBranch) {
|
|
10760
10655
|
const unusedBranch = this.usedBranch === this.left ? this.right : this.left;
|
|
10761
10656
|
this.usedBranch = null;
|
|
10762
10657
|
unusedBranch.deoptimizePath(UNKNOWN_PATH);
|
|
10763
10658
|
for (const expression of this.expressionsToBeDeoptimized) {
|
|
10764
10659
|
expression.deoptimizeCache();
|
|
10765
10660
|
}
|
|
10661
|
+
// Request another pass because we need to ensure "include" runs again if
|
|
10662
|
+
// it is rendered
|
|
10663
|
+
this.context.requestTreeshakingPass();
|
|
10766
10664
|
}
|
|
10767
10665
|
}
|
|
10768
10666
|
deoptimizePath(path) {
|
|
@@ -11095,6 +10993,10 @@ class NewExpression extends NodeBase {
|
|
|
11095
10993
|
withNew: true
|
|
11096
10994
|
};
|
|
11097
10995
|
}
|
|
10996
|
+
render(code, options) {
|
|
10997
|
+
this.callee.render(code, options);
|
|
10998
|
+
renderCallArguments(code, options, this);
|
|
10999
|
+
}
|
|
11098
11000
|
applyDeoptimizations() {
|
|
11099
11001
|
this.deoptimized = true;
|
|
11100
11002
|
for (const argument of this.arguments) {
|
|
@@ -11105,42 +11007,6 @@ class NewExpression extends NodeBase {
|
|
|
11105
11007
|
}
|
|
11106
11008
|
}
|
|
11107
11009
|
|
|
11108
|
-
class Property extends MethodBase {
|
|
11109
|
-
constructor() {
|
|
11110
|
-
super(...arguments);
|
|
11111
|
-
this.declarationInit = null;
|
|
11112
|
-
}
|
|
11113
|
-
declare(kind, init) {
|
|
11114
|
-
this.declarationInit = init;
|
|
11115
|
-
return this.value.declare(kind, UNKNOWN_EXPRESSION);
|
|
11116
|
-
}
|
|
11117
|
-
hasEffects(context) {
|
|
11118
|
-
if (!this.deoptimized)
|
|
11119
|
-
this.applyDeoptimizations();
|
|
11120
|
-
const propertyReadSideEffects = this.context.options.treeshake
|
|
11121
|
-
.propertyReadSideEffects;
|
|
11122
|
-
return ((this.parent.type === 'ObjectPattern' && propertyReadSideEffects === 'always') ||
|
|
11123
|
-
this.key.hasEffects(context) ||
|
|
11124
|
-
this.value.hasEffects(context));
|
|
11125
|
-
}
|
|
11126
|
-
markDeclarationReached() {
|
|
11127
|
-
this.value.markDeclarationReached();
|
|
11128
|
-
}
|
|
11129
|
-
render(code, options) {
|
|
11130
|
-
if (!this.shorthand) {
|
|
11131
|
-
this.key.render(code, options);
|
|
11132
|
-
}
|
|
11133
|
-
this.value.render(code, options, { isShorthandProperty: this.shorthand });
|
|
11134
|
-
}
|
|
11135
|
-
applyDeoptimizations() {
|
|
11136
|
-
this.deoptimized = true;
|
|
11137
|
-
if (this.declarationInit !== null) {
|
|
11138
|
-
this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
|
|
11139
|
-
this.context.requestTreeshakingPass();
|
|
11140
|
-
}
|
|
11141
|
-
}
|
|
11142
|
-
}
|
|
11143
|
-
|
|
11144
11010
|
class ObjectExpression extends NodeBase {
|
|
11145
11011
|
constructor() {
|
|
11146
11012
|
super(...arguments);
|
|
@@ -11178,14 +11044,7 @@ class ObjectExpression extends NodeBase {
|
|
|
11178
11044
|
code.prependLeft(this.end, ')');
|
|
11179
11045
|
}
|
|
11180
11046
|
}
|
|
11181
|
-
applyDeoptimizations() {
|
|
11182
|
-
this.deoptimized = true;
|
|
11183
|
-
for (const property of this.properties) {
|
|
11184
|
-
if (property instanceof Property) {
|
|
11185
|
-
property.value.deoptimizeCallParameters();
|
|
11186
|
-
}
|
|
11187
|
-
}
|
|
11188
|
-
}
|
|
11047
|
+
applyDeoptimizations() { }
|
|
11189
11048
|
getObjectEntity() {
|
|
11190
11049
|
if (this.objectEntity !== null) {
|
|
11191
11050
|
return this.objectEntity;
|
|
@@ -11265,6 +11124,77 @@ class Program extends NodeBase {
|
|
|
11265
11124
|
applyDeoptimizations() { }
|
|
11266
11125
|
}
|
|
11267
11126
|
|
|
11127
|
+
class Property extends MethodBase {
|
|
11128
|
+
constructor() {
|
|
11129
|
+
super(...arguments);
|
|
11130
|
+
this.declarationInit = null;
|
|
11131
|
+
}
|
|
11132
|
+
declare(kind, init) {
|
|
11133
|
+
this.declarationInit = init;
|
|
11134
|
+
return this.value.declare(kind, UNKNOWN_EXPRESSION);
|
|
11135
|
+
}
|
|
11136
|
+
hasEffects(context) {
|
|
11137
|
+
if (!this.deoptimized)
|
|
11138
|
+
this.applyDeoptimizations();
|
|
11139
|
+
const propertyReadSideEffects = this.context.options.treeshake
|
|
11140
|
+
.propertyReadSideEffects;
|
|
11141
|
+
return ((this.parent.type === 'ObjectPattern' && propertyReadSideEffects === 'always') ||
|
|
11142
|
+
this.key.hasEffects(context) ||
|
|
11143
|
+
this.value.hasEffects(context));
|
|
11144
|
+
}
|
|
11145
|
+
markDeclarationReached() {
|
|
11146
|
+
this.value.markDeclarationReached();
|
|
11147
|
+
}
|
|
11148
|
+
render(code, options) {
|
|
11149
|
+
if (!this.shorthand) {
|
|
11150
|
+
this.key.render(code, options);
|
|
11151
|
+
}
|
|
11152
|
+
this.value.render(code, options, { isShorthandProperty: this.shorthand });
|
|
11153
|
+
}
|
|
11154
|
+
applyDeoptimizations() {
|
|
11155
|
+
this.deoptimized = true;
|
|
11156
|
+
if (this.declarationInit !== null) {
|
|
11157
|
+
this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
|
|
11158
|
+
this.context.requestTreeshakingPass();
|
|
11159
|
+
}
|
|
11160
|
+
}
|
|
11161
|
+
}
|
|
11162
|
+
|
|
11163
|
+
class PropertyDefinition extends NodeBase {
|
|
11164
|
+
deoptimizePath(path) {
|
|
11165
|
+
var _a;
|
|
11166
|
+
(_a = this.value) === null || _a === void 0 ? void 0 : _a.deoptimizePath(path);
|
|
11167
|
+
}
|
|
11168
|
+
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
11169
|
+
var _a;
|
|
11170
|
+
(_a = this.value) === null || _a === void 0 ? void 0 : _a.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
11171
|
+
}
|
|
11172
|
+
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
11173
|
+
return this.value
|
|
11174
|
+
? this.value.getLiteralValueAtPath(path, recursionTracker, origin)
|
|
11175
|
+
: UnknownValue;
|
|
11176
|
+
}
|
|
11177
|
+
getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
|
|
11178
|
+
return this.value
|
|
11179
|
+
? this.value.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin)
|
|
11180
|
+
: UNKNOWN_EXPRESSION;
|
|
11181
|
+
}
|
|
11182
|
+
hasEffects(context) {
|
|
11183
|
+
var _a;
|
|
11184
|
+
return this.key.hasEffects(context) || (this.static && !!((_a = this.value) === null || _a === void 0 ? void 0 : _a.hasEffects(context)));
|
|
11185
|
+
}
|
|
11186
|
+
hasEffectsWhenAccessedAtPath(path, context) {
|
|
11187
|
+
return !this.value || this.value.hasEffectsWhenAccessedAtPath(path, context);
|
|
11188
|
+
}
|
|
11189
|
+
hasEffectsWhenAssignedAtPath(path, context) {
|
|
11190
|
+
return !this.value || this.value.hasEffectsWhenAssignedAtPath(path, context);
|
|
11191
|
+
}
|
|
11192
|
+
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
11193
|
+
return !this.value || this.value.hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
11194
|
+
}
|
|
11195
|
+
applyDeoptimizations() { }
|
|
11196
|
+
}
|
|
11197
|
+
|
|
11268
11198
|
class ReturnStatement extends NodeBase {
|
|
11269
11199
|
hasEffects(context) {
|
|
11270
11200
|
var _a;
|
|
@@ -12133,9 +12063,7 @@ class VariableDeclarator extends NodeBase {
|
|
|
12133
12063
|
include(context, includeChildrenRecursively) {
|
|
12134
12064
|
var _a;
|
|
12135
12065
|
this.included = true;
|
|
12136
|
-
(_a = this.init) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively
|
|
12137
|
-
includeWithoutParameterDefaults: true
|
|
12138
|
-
});
|
|
12066
|
+
(_a = this.init) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
|
|
12139
12067
|
this.id.markDeclarationReached();
|
|
12140
12068
|
if (includeChildrenRecursively || this.id.shouldBeIncluded(context)) {
|
|
12141
12069
|
this.id.include(context, includeChildrenRecursively);
|
|
@@ -12190,7 +12118,7 @@ class YieldExpression extends NodeBase {
|
|
|
12190
12118
|
var _a;
|
|
12191
12119
|
if (!this.deoptimized)
|
|
12192
12120
|
this.applyDeoptimizations();
|
|
12193
|
-
return !context.ignore.returnYield
|
|
12121
|
+
return !(context.ignore.returnYield && !((_a = this.argument) === null || _a === void 0 ? void 0 : _a.hasEffects(context)));
|
|
12194
12122
|
}
|
|
12195
12123
|
render(code, options) {
|
|
12196
12124
|
if (this.argument) {
|