rollup 2.72.1 → 2.74.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +49 -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 +582 -540
- package/dist/es/shared/watch.js +3 -3
- package/dist/loadConfigFile.js +3 -3
- 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 +2 -2
- package/dist/shared/loadConfigFile.js +4 -5
- package/dist/shared/mergeOptions.js +2 -2
- package/dist/shared/rollup.js +582 -540
- 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.
|
|
4
|
-
|
|
3
|
+
Rollup.js v2.74.1
|
|
4
|
+
Thu, 19 May 2022 17:50:11 GMT - commit e823eded9920d6082cc8c1afcf591b716ab6b160
|
|
5
5
|
|
|
6
6
|
https://github.com/rollup/rollup
|
|
7
7
|
|
|
@@ -27,7 +27,7 @@ function _interopNamespaceDefault(e) {
|
|
|
27
27
|
return n;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
var version$1 = "2.
|
|
30
|
+
var version$1 = "2.74.1";
|
|
31
31
|
|
|
32
32
|
function ensureArray$1(items) {
|
|
33
33
|
if (Array.isArray(items)) {
|
|
@@ -2155,9 +2155,16 @@ function getOrCreate(map, key, init) {
|
|
|
2155
2155
|
}
|
|
2156
2156
|
|
|
2157
2157
|
const UnknownKey = Symbol('Unknown Key');
|
|
2158
|
+
const UnknownNonAccessorKey = Symbol('Unknown Non-Accessor Key');
|
|
2158
2159
|
const UnknownInteger = Symbol('Unknown Integer');
|
|
2159
2160
|
const EMPTY_PATH = [];
|
|
2160
2161
|
const UNKNOWN_PATH = [UnknownKey];
|
|
2162
|
+
// For deoptimizations, this means we are modifying an unknown property but did
|
|
2163
|
+
// not lose track of the object or are creating a setter/getter;
|
|
2164
|
+
// For assignment effects it means we do not check for setter/getter effects
|
|
2165
|
+
// but only if something is mutated that is included, which is relevant for
|
|
2166
|
+
// Object.defineProperty
|
|
2167
|
+
const UNKNOWN_NON_ACCESSOR_PATH = [UnknownNonAccessorKey];
|
|
2161
2168
|
const UNKNOWN_INTEGER_PATH = [UnknownInteger];
|
|
2162
2169
|
const EntitiesKey = Symbol('Entities');
|
|
2163
2170
|
class PathTracker {
|
|
@@ -4711,7 +4718,7 @@ const UNDEFINED_EXPRESSION = new (class UndefinedExpression extends ExpressionEn
|
|
|
4711
4718
|
})();
|
|
4712
4719
|
const returnsUnknown = {
|
|
4713
4720
|
value: {
|
|
4714
|
-
|
|
4721
|
+
hasEffectsWhenCalled: null,
|
|
4715
4722
|
returns: UNKNOWN_EXPRESSION
|
|
4716
4723
|
}
|
|
4717
4724
|
};
|
|
@@ -4734,7 +4741,7 @@ const UNKNOWN_LITERAL_BOOLEAN = new (class UnknownBoolean extends ExpressionEnti
|
|
|
4734
4741
|
})();
|
|
4735
4742
|
const returnsBoolean = {
|
|
4736
4743
|
value: {
|
|
4737
|
-
|
|
4744
|
+
hasEffectsWhenCalled: null,
|
|
4738
4745
|
returns: UNKNOWN_LITERAL_BOOLEAN
|
|
4739
4746
|
}
|
|
4740
4747
|
};
|
|
@@ -4757,7 +4764,7 @@ const UNKNOWN_LITERAL_NUMBER = new (class UnknownNumber extends ExpressionEntity
|
|
|
4757
4764
|
})();
|
|
4758
4765
|
const returnsNumber = {
|
|
4759
4766
|
value: {
|
|
4760
|
-
|
|
4767
|
+
hasEffectsWhenCalled: null,
|
|
4761
4768
|
returns: UNKNOWN_LITERAL_NUMBER
|
|
4762
4769
|
}
|
|
4763
4770
|
};
|
|
@@ -4780,7 +4787,24 @@ const UNKNOWN_LITERAL_STRING = new (class UnknownString extends ExpressionEntity
|
|
|
4780
4787
|
})();
|
|
4781
4788
|
const returnsString = {
|
|
4782
4789
|
value: {
|
|
4783
|
-
|
|
4790
|
+
hasEffectsWhenCalled: null,
|
|
4791
|
+
returns: UNKNOWN_LITERAL_STRING
|
|
4792
|
+
}
|
|
4793
|
+
};
|
|
4794
|
+
const stringReplace = {
|
|
4795
|
+
value: {
|
|
4796
|
+
hasEffectsWhenCalled(callOptions, context) {
|
|
4797
|
+
const arg1 = callOptions.args[1];
|
|
4798
|
+
return (callOptions.args.length < 2 ||
|
|
4799
|
+
(arg1.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, {
|
|
4800
|
+
deoptimizeCache() { }
|
|
4801
|
+
}) === UnknownValue &&
|
|
4802
|
+
arg1.hasEffectsWhenCalledAtPath(EMPTY_PATH, {
|
|
4803
|
+
args: NO_ARGS,
|
|
4804
|
+
thisParam: null,
|
|
4805
|
+
withNew: false
|
|
4806
|
+
}, context)));
|
|
4807
|
+
},
|
|
4784
4808
|
returns: UNKNOWN_LITERAL_STRING
|
|
4785
4809
|
}
|
|
4786
4810
|
};
|
|
@@ -4828,18 +4852,8 @@ const literalStringMembers = assembleMemberDescriptions({
|
|
|
4828
4852
|
padEnd: returnsString,
|
|
4829
4853
|
padStart: returnsString,
|
|
4830
4854
|
repeat: returnsString,
|
|
4831
|
-
replace:
|
|
4832
|
-
|
|
4833
|
-
callsArgs: [1],
|
|
4834
|
-
returns: UNKNOWN_LITERAL_STRING
|
|
4835
|
-
}
|
|
4836
|
-
},
|
|
4837
|
-
replaceAll: {
|
|
4838
|
-
value: {
|
|
4839
|
-
callsArgs: [1],
|
|
4840
|
-
returns: UNKNOWN_LITERAL_STRING
|
|
4841
|
-
}
|
|
4842
|
-
},
|
|
4855
|
+
replace: stringReplace,
|
|
4856
|
+
replaceAll: stringReplace,
|
|
4843
4857
|
search: returnsNumber,
|
|
4844
4858
|
slice: returnsString,
|
|
4845
4859
|
small: returnsString,
|
|
@@ -4874,21 +4888,11 @@ function getLiteralMembersForValue(value) {
|
|
|
4874
4888
|
return Object.create(null);
|
|
4875
4889
|
}
|
|
4876
4890
|
function hasMemberEffectWhenCalled(members, memberName, callOptions, context) {
|
|
4891
|
+
var _a, _b;
|
|
4877
4892
|
if (typeof memberName !== 'string' || !members[memberName]) {
|
|
4878
4893
|
return true;
|
|
4879
4894
|
}
|
|
4880
|
-
|
|
4881
|
-
return false;
|
|
4882
|
-
for (const argIndex of members[memberName].callsArgs) {
|
|
4883
|
-
if (callOptions.args[argIndex] &&
|
|
4884
|
-
callOptions.args[argIndex].hasEffectsWhenCalledAtPath(EMPTY_PATH, {
|
|
4885
|
-
args: NO_ARGS,
|
|
4886
|
-
thisParam: null,
|
|
4887
|
-
withNew: false
|
|
4888
|
-
}, context))
|
|
4889
|
-
return true;
|
|
4890
|
-
}
|
|
4891
|
-
return false;
|
|
4895
|
+
return ((_b = (_a = members[memberName]).hasEffectsWhenCalled) === null || _b === void 0 ? void 0 : _b.call(_a, callOptions, context)) || false;
|
|
4892
4896
|
}
|
|
4893
4897
|
function getMemberReturnExpressionWhenCalled(members, memberName) {
|
|
4894
4898
|
if (typeof memberName !== 'string' || !members[memberName])
|
|
@@ -5595,6 +5599,7 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5595
5599
|
this.deoptimizedPaths = Object.create(null);
|
|
5596
5600
|
this.expressionsToBeDeoptimizedByKey = Object.create(null);
|
|
5597
5601
|
this.gettersByKey = Object.create(null);
|
|
5602
|
+
this.hasLostTrack = false;
|
|
5598
5603
|
this.hasUnknownDeoptimizedInteger = false;
|
|
5599
5604
|
this.hasUnknownDeoptimizedProperty = false;
|
|
5600
5605
|
this.propertiesAndGettersByKey = Object.create(null);
|
|
@@ -5615,12 +5620,18 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5615
5620
|
}
|
|
5616
5621
|
}
|
|
5617
5622
|
}
|
|
5618
|
-
deoptimizeAllProperties() {
|
|
5623
|
+
deoptimizeAllProperties(noAccessors) {
|
|
5619
5624
|
var _a;
|
|
5620
|
-
|
|
5625
|
+
const isDeoptimized = this.hasLostTrack || this.hasUnknownDeoptimizedProperty;
|
|
5626
|
+
if (noAccessors) {
|
|
5627
|
+
this.hasUnknownDeoptimizedProperty = true;
|
|
5628
|
+
}
|
|
5629
|
+
else {
|
|
5630
|
+
this.hasLostTrack = true;
|
|
5631
|
+
}
|
|
5632
|
+
if (isDeoptimized) {
|
|
5621
5633
|
return;
|
|
5622
5634
|
}
|
|
5623
|
-
this.hasUnknownDeoptimizedProperty = true;
|
|
5624
5635
|
for (const properties of Object.values(this.propertiesAndGettersByKey).concat(Object.values(this.settersByKey))) {
|
|
5625
5636
|
for (const property of properties) {
|
|
5626
5637
|
property.deoptimizePath(UNKNOWN_PATH);
|
|
@@ -5631,7 +5642,9 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5631
5642
|
this.deoptimizeCachedEntities();
|
|
5632
5643
|
}
|
|
5633
5644
|
deoptimizeIntegerProperties() {
|
|
5634
|
-
if (this.
|
|
5645
|
+
if (this.hasLostTrack ||
|
|
5646
|
+
this.hasUnknownDeoptimizedProperty ||
|
|
5647
|
+
this.hasUnknownDeoptimizedInteger) {
|
|
5635
5648
|
return;
|
|
5636
5649
|
}
|
|
5637
5650
|
this.hasUnknownDeoptimizedInteger = true;
|
|
@@ -5644,17 +5657,19 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5644
5657
|
}
|
|
5645
5658
|
this.deoptimizeCachedIntegerEntities();
|
|
5646
5659
|
}
|
|
5660
|
+
// Assumption: If only a specific path is deoptimized, no accessors are created
|
|
5647
5661
|
deoptimizePath(path) {
|
|
5648
5662
|
var _a;
|
|
5649
|
-
if (this.
|
|
5663
|
+
if (this.hasLostTrack || this.immutable) {
|
|
5650
5664
|
return;
|
|
5665
|
+
}
|
|
5651
5666
|
const key = path[0];
|
|
5652
5667
|
if (path.length === 1) {
|
|
5653
5668
|
if (typeof key !== 'string') {
|
|
5654
5669
|
if (key === UnknownInteger) {
|
|
5655
5670
|
return this.deoptimizeIntegerProperties();
|
|
5656
5671
|
}
|
|
5657
|
-
return this.deoptimizeAllProperties();
|
|
5672
|
+
return this.deoptimizeAllProperties(key === UnknownNonAccessorKey);
|
|
5658
5673
|
}
|
|
5659
5674
|
if (!this.deoptimizedPaths[key]) {
|
|
5660
5675
|
this.deoptimizedPaths[key] = true;
|
|
@@ -5679,11 +5694,11 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5679
5694
|
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
5680
5695
|
var _a;
|
|
5681
5696
|
const [key, ...subPath] = path;
|
|
5682
|
-
if (this.
|
|
5697
|
+
if (this.hasLostTrack ||
|
|
5683
5698
|
// single paths that are deoptimized will not become getters or setters
|
|
5684
5699
|
((event === EVENT_CALLED || path.length > 1) &&
|
|
5685
|
-
|
|
5686
|
-
|
|
5700
|
+
(this.hasUnknownDeoptimizedProperty ||
|
|
5701
|
+
(typeof key === 'string' && this.deoptimizedPaths[key])))) {
|
|
5687
5702
|
thisParameter.deoptimizePath(UNKNOWN_PATH);
|
|
5688
5703
|
return;
|
|
5689
5704
|
}
|
|
@@ -5781,7 +5796,7 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5781
5796
|
}
|
|
5782
5797
|
return true;
|
|
5783
5798
|
}
|
|
5784
|
-
if (this.
|
|
5799
|
+
if (this.hasLostTrack)
|
|
5785
5800
|
return true;
|
|
5786
5801
|
if (typeof key === 'string') {
|
|
5787
5802
|
if (this.propertiesAndGettersByKey[key]) {
|
|
@@ -5828,9 +5843,10 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5828
5843
|
}
|
|
5829
5844
|
return true;
|
|
5830
5845
|
}
|
|
5831
|
-
if (
|
|
5846
|
+
if (key === UnknownNonAccessorKey)
|
|
5847
|
+
return false;
|
|
5848
|
+
if (this.hasLostTrack)
|
|
5832
5849
|
return true;
|
|
5833
|
-
// We do not need to test for unknown properties as in that case, hasUnknownDeoptimizedProperty is true
|
|
5834
5850
|
if (typeof key === 'string') {
|
|
5835
5851
|
if (this.propertiesAndSettersByKey[key]) {
|
|
5836
5852
|
const setters = this.settersByKey[key];
|
|
@@ -5848,6 +5864,14 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5848
5864
|
}
|
|
5849
5865
|
}
|
|
5850
5866
|
}
|
|
5867
|
+
else {
|
|
5868
|
+
for (const setters of Object.values(this.settersByKey).concat([this.unmatchableSetters])) {
|
|
5869
|
+
for (const setter of setters) {
|
|
5870
|
+
if (setter.hasEffectsWhenAssignedAtPath(subPath, context))
|
|
5871
|
+
return true;
|
|
5872
|
+
}
|
|
5873
|
+
}
|
|
5874
|
+
}
|
|
5851
5875
|
if (this.prototypeExpression) {
|
|
5852
5876
|
return this.prototypeExpression.hasEffectsWhenAssignedAtPath(path, context);
|
|
5853
5877
|
}
|
|
@@ -5931,7 +5955,8 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5931
5955
|
}
|
|
5932
5956
|
}
|
|
5933
5957
|
getMemberExpression(key) {
|
|
5934
|
-
if (this.
|
|
5958
|
+
if (this.hasLostTrack ||
|
|
5959
|
+
this.hasUnknownDeoptimizedProperty ||
|
|
5935
5960
|
typeof key !== 'string' ||
|
|
5936
5961
|
(this.hasUnknownDeoptimizedInteger && INTEGER_REG_EXP.test(key)) ||
|
|
5937
5962
|
this.deoptimizedPaths[key]) {
|
|
@@ -6597,323 +6622,89 @@ class ReturnValueScope extends ParameterScope {
|
|
|
6597
6622
|
}
|
|
6598
6623
|
}
|
|
6599
6624
|
|
|
6600
|
-
|
|
6601
|
-
|
|
6602
|
-
|
|
6603
|
-
|
|
6604
|
-
|
|
6605
|
-
|
|
6606
|
-
|
|
6607
|
-
else {
|
|
6608
|
-
return;
|
|
6609
|
-
}
|
|
6610
|
-
}
|
|
6611
|
-
}
|
|
6612
|
-
}
|
|
6613
|
-
function removeAnnotations(node, code) {
|
|
6614
|
-
if (!node.annotations && node.parent.type === ExpressionStatement$1) {
|
|
6615
|
-
node = node.parent;
|
|
6616
|
-
}
|
|
6617
|
-
if (node.annotations) {
|
|
6618
|
-
for (const annotation of node.annotations) {
|
|
6619
|
-
code.remove(annotation.start, annotation.end);
|
|
6620
|
-
}
|
|
6621
|
-
}
|
|
6622
|
-
}
|
|
6625
|
+
//@ts-check
|
|
6626
|
+
/** @typedef { import('estree').Node} Node */
|
|
6627
|
+
/** @typedef {Node | {
|
|
6628
|
+
* type: 'PropertyDefinition';
|
|
6629
|
+
* computed: boolean;
|
|
6630
|
+
* value: Node
|
|
6631
|
+
* }} NodeWithPropertyDefinition */
|
|
6623
6632
|
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
6632
|
-
|
|
6633
|
-
|
|
6634
|
-
|
|
6635
|
-
|
|
6636
|
-
|
|
6637
|
-
|
|
6638
|
-
|
|
6639
|
-
|
|
6640
|
-
|
|
6641
|
-
|
|
6642
|
-
|
|
6643
|
-
|
|
6644
|
-
|
|
6645
|
-
|
|
6646
|
-
|
|
6647
|
-
|
|
6648
|
-
|
|
6649
|
-
|
|
6650
|
-
|
|
6651
|
-
//
|
|
6652
|
-
//
|
|
6653
|
-
|
|
6654
|
-
|
|
6655
|
-
|
|
6656
|
-
|
|
6657
|
-
|
|
6658
|
-
|
|
6659
|
-
|
|
6660
|
-
|
|
6661
|
-
|
|
6662
|
-
|
|
6663
|
-
|
|
6664
|
-
|
|
6665
|
-
if (start > lineBreakPos) {
|
|
6666
|
-
lineBreakPos = code.indexOf('\n', start);
|
|
6667
|
-
}
|
|
6668
|
-
}
|
|
6633
|
+
/**
|
|
6634
|
+
*
|
|
6635
|
+
* @param {NodeWithPropertyDefinition} node
|
|
6636
|
+
* @param {NodeWithPropertyDefinition} parent
|
|
6637
|
+
* @returns boolean
|
|
6638
|
+
*/
|
|
6639
|
+
function is_reference (node, parent) {
|
|
6640
|
+
if (node.type === 'MemberExpression') {
|
|
6641
|
+
return !node.computed && is_reference(node.object, node);
|
|
6642
|
+
}
|
|
6643
|
+
|
|
6644
|
+
if (node.type === 'Identifier') {
|
|
6645
|
+
if (!parent) return true;
|
|
6646
|
+
|
|
6647
|
+
switch (parent.type) {
|
|
6648
|
+
// disregard `bar` in `foo.bar`
|
|
6649
|
+
case 'MemberExpression': return parent.computed || node === parent.object;
|
|
6650
|
+
|
|
6651
|
+
// disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
|
|
6652
|
+
case 'MethodDefinition': return parent.computed;
|
|
6653
|
+
|
|
6654
|
+
// disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
|
|
6655
|
+
case 'PropertyDefinition': return parent.computed || node === parent.value;
|
|
6656
|
+
|
|
6657
|
+
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
|
|
6658
|
+
case 'Property': return parent.computed || node === parent.value;
|
|
6659
|
+
|
|
6660
|
+
// disregard the `bar` in `export { foo as bar }` or
|
|
6661
|
+
// the foo in `import { foo as bar }`
|
|
6662
|
+
case 'ExportSpecifier':
|
|
6663
|
+
case 'ImportSpecifier': return node === parent.local;
|
|
6664
|
+
|
|
6665
|
+
// disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
|
|
6666
|
+
case 'LabeledStatement':
|
|
6667
|
+
case 'BreakStatement':
|
|
6668
|
+
case 'ContinueStatement': return false;
|
|
6669
|
+
default: return true;
|
|
6670
|
+
}
|
|
6671
|
+
}
|
|
6672
|
+
|
|
6673
|
+
return false;
|
|
6669
6674
|
}
|
|
6670
|
-
|
|
6671
|
-
|
|
6672
|
-
|
|
6673
|
-
|
|
6674
|
-
|
|
6675
|
-
|
|
6676
|
-
start + findFirstLineBreakOutsideComment(code.original.slice(start, nextNode.start))[1];
|
|
6677
|
-
}
|
|
6678
|
-
for (let nextIndex = 1; nextIndex <= statements.length; nextIndex++) {
|
|
6679
|
-
currentNode = nextNode;
|
|
6680
|
-
currentNodeStart = nextNodeStart;
|
|
6681
|
-
currentNodeNeedsBoundaries = nextNodeNeedsBoundaries;
|
|
6682
|
-
nextNode = statements[nextIndex];
|
|
6683
|
-
nextNodeNeedsBoundaries =
|
|
6684
|
-
nextNode === undefined ? false : !nextNode.included || nextNode.needsBoundaries;
|
|
6685
|
-
if (currentNodeNeedsBoundaries || nextNodeNeedsBoundaries) {
|
|
6686
|
-
nextNodeStart =
|
|
6687
|
-
currentNode.end +
|
|
6688
|
-
findFirstLineBreakOutsideComment(code.original.slice(currentNode.end, nextNode === undefined ? end : nextNode.start))[1];
|
|
6689
|
-
if (currentNode.included) {
|
|
6690
|
-
currentNodeNeedsBoundaries
|
|
6691
|
-
? currentNode.render(code, options, {
|
|
6692
|
-
end: nextNodeStart,
|
|
6693
|
-
start: currentNodeStart
|
|
6694
|
-
})
|
|
6695
|
-
: currentNode.render(code, options);
|
|
6696
|
-
}
|
|
6697
|
-
else {
|
|
6698
|
-
treeshakeNode(currentNode, code, currentNodeStart, nextNodeStart);
|
|
6699
|
-
}
|
|
6700
|
-
}
|
|
6701
|
-
else {
|
|
6702
|
-
currentNode.render(code, options);
|
|
6703
|
-
}
|
|
6675
|
+
|
|
6676
|
+
/* eslint sort-keys: "off" */
|
|
6677
|
+
const ValueProperties = Symbol('Value Properties');
|
|
6678
|
+
const PURE = {
|
|
6679
|
+
hasEffectsWhenCalled() {
|
|
6680
|
+
return false;
|
|
6704
6681
|
}
|
|
6705
|
-
}
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
let node, nextNode, nextNodeStart, contentEnd, char;
|
|
6710
|
-
let separator = start - 1;
|
|
6711
|
-
for (let nextIndex = 0; nextIndex < nodes.length; nextIndex++) {
|
|
6712
|
-
nextNode = nodes[nextIndex];
|
|
6713
|
-
if (node !== undefined) {
|
|
6714
|
-
separator =
|
|
6715
|
-
node.end +
|
|
6716
|
-
findFirstOccurrenceOutsideComment(code.original.slice(node.end, nextNode.start), ',');
|
|
6717
|
-
}
|
|
6718
|
-
nextNodeStart = contentEnd =
|
|
6719
|
-
separator +
|
|
6720
|
-
1 +
|
|
6721
|
-
findFirstLineBreakOutsideComment(code.original.slice(separator + 1, nextNode.start))[1];
|
|
6722
|
-
while (((char = code.original.charCodeAt(nextNodeStart)),
|
|
6723
|
-
char === 32 /*" "*/ || char === 9 /*"\t"*/ || char === 10 /*"\n"*/ || char === 13) /*"\r"*/)
|
|
6724
|
-
nextNodeStart++;
|
|
6725
|
-
if (node !== undefined) {
|
|
6726
|
-
splitUpNodes.push({
|
|
6727
|
-
contentEnd,
|
|
6728
|
-
end: nextNodeStart,
|
|
6729
|
-
node,
|
|
6730
|
-
separator,
|
|
6731
|
-
start
|
|
6732
|
-
});
|
|
6733
|
-
}
|
|
6734
|
-
node = nextNode;
|
|
6735
|
-
start = nextNodeStart;
|
|
6682
|
+
};
|
|
6683
|
+
const IMPURE = {
|
|
6684
|
+
hasEffectsWhenCalled() {
|
|
6685
|
+
return true;
|
|
6736
6686
|
}
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
6740
|
-
|
|
6741
|
-
|
|
6742
|
-
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
|
|
6748
|
-
|
|
6749
|
-
|
|
6750
|
-
|
|
6751
|
-
|
|
6687
|
+
};
|
|
6688
|
+
// We use shortened variables to reduce file size here
|
|
6689
|
+
/* OBJECT */
|
|
6690
|
+
const O = {
|
|
6691
|
+
__proto__: null,
|
|
6692
|
+
[ValueProperties]: IMPURE
|
|
6693
|
+
};
|
|
6694
|
+
/* PURE FUNCTION */
|
|
6695
|
+
const PF = {
|
|
6696
|
+
__proto__: null,
|
|
6697
|
+
[ValueProperties]: PURE
|
|
6698
|
+
};
|
|
6699
|
+
/* FUNCTION THAT MUTATES FIRST ARG WITHOUT TRIGGERING ACCESSORS */
|
|
6700
|
+
const MUTATES_ARG_WITHOUT_ACCESSOR = {
|
|
6701
|
+
__proto__: null,
|
|
6702
|
+
[ValueProperties]: {
|
|
6703
|
+
hasEffectsWhenCalled(callOptions, context) {
|
|
6704
|
+
return (!callOptions.args.length ||
|
|
6705
|
+
callOptions.args[0].hasEffectsWhenAssignedAtPath(UNKNOWN_NON_ACCESSOR_PATH, context));
|
|
6752
6706
|
}
|
|
6753
|
-
code.remove(start + removeStart, (start += removeEnd));
|
|
6754
6707
|
}
|
|
6755
|
-
}
|
|
6756
|
-
|
|
6757
|
-
class BlockScope extends ChildScope {
|
|
6758
|
-
addDeclaration(identifier, context, init, isHoisted) {
|
|
6759
|
-
if (isHoisted) {
|
|
6760
|
-
const variable = this.parent.addDeclaration(identifier, context, init, isHoisted);
|
|
6761
|
-
// Necessary to make sure the init is deoptimized for conditional declarations.
|
|
6762
|
-
// We cannot call deoptimizePath here.
|
|
6763
|
-
variable.markInitializersForDeoptimization();
|
|
6764
|
-
return variable;
|
|
6765
|
-
}
|
|
6766
|
-
else {
|
|
6767
|
-
return super.addDeclaration(identifier, context, init, false);
|
|
6768
|
-
}
|
|
6769
|
-
}
|
|
6770
|
-
}
|
|
6771
|
-
|
|
6772
|
-
class ExpressionStatement extends NodeBase {
|
|
6773
|
-
initialise() {
|
|
6774
|
-
if (this.directive &&
|
|
6775
|
-
this.directive !== 'use strict' &&
|
|
6776
|
-
this.parent.type === Program$1) {
|
|
6777
|
-
this.context.warn(
|
|
6778
|
-
// This is necessary, because either way (deleting or not) can lead to errors.
|
|
6779
|
-
{
|
|
6780
|
-
code: 'MODULE_LEVEL_DIRECTIVE',
|
|
6781
|
-
message: `Module level directives cause errors when bundled, '${this.directive}' was ignored.`
|
|
6782
|
-
}, this.start);
|
|
6783
|
-
}
|
|
6784
|
-
}
|
|
6785
|
-
render(code, options) {
|
|
6786
|
-
super.render(code, options);
|
|
6787
|
-
if (this.included)
|
|
6788
|
-
this.insertSemicolon(code);
|
|
6789
|
-
}
|
|
6790
|
-
shouldBeIncluded(context) {
|
|
6791
|
-
if (this.directive && this.directive !== 'use strict')
|
|
6792
|
-
return this.parent.type !== Program$1;
|
|
6793
|
-
return super.shouldBeIncluded(context);
|
|
6794
|
-
}
|
|
6795
|
-
}
|
|
6796
|
-
|
|
6797
|
-
class BlockStatement extends NodeBase {
|
|
6798
|
-
constructor() {
|
|
6799
|
-
super(...arguments);
|
|
6800
|
-
this.directlyIncluded = false;
|
|
6801
|
-
}
|
|
6802
|
-
addImplicitReturnExpressionToScope() {
|
|
6803
|
-
const lastStatement = this.body[this.body.length - 1];
|
|
6804
|
-
if (!lastStatement || lastStatement.type !== ReturnStatement$1) {
|
|
6805
|
-
this.scope.addReturnExpression(UNKNOWN_EXPRESSION);
|
|
6806
|
-
}
|
|
6807
|
-
}
|
|
6808
|
-
createScope(parentScope) {
|
|
6809
|
-
this.scope = this.parent.preventChildBlockScope
|
|
6810
|
-
? parentScope
|
|
6811
|
-
: new BlockScope(parentScope);
|
|
6812
|
-
}
|
|
6813
|
-
hasEffects(context) {
|
|
6814
|
-
if (this.deoptimizeBody)
|
|
6815
|
-
return true;
|
|
6816
|
-
for (const node of this.body) {
|
|
6817
|
-
if (context.brokenFlow)
|
|
6818
|
-
break;
|
|
6819
|
-
if (node.hasEffects(context))
|
|
6820
|
-
return true;
|
|
6821
|
-
}
|
|
6822
|
-
return false;
|
|
6823
|
-
}
|
|
6824
|
-
include(context, includeChildrenRecursively) {
|
|
6825
|
-
if (!(this.deoptimizeBody && this.directlyIncluded)) {
|
|
6826
|
-
this.included = true;
|
|
6827
|
-
this.directlyIncluded = true;
|
|
6828
|
-
if (this.deoptimizeBody)
|
|
6829
|
-
includeChildrenRecursively = true;
|
|
6830
|
-
for (const node of this.body) {
|
|
6831
|
-
if (includeChildrenRecursively || node.shouldBeIncluded(context))
|
|
6832
|
-
node.include(context, includeChildrenRecursively);
|
|
6833
|
-
}
|
|
6834
|
-
}
|
|
6835
|
-
}
|
|
6836
|
-
initialise() {
|
|
6837
|
-
const firstBodyStatement = this.body[0];
|
|
6838
|
-
this.deoptimizeBody =
|
|
6839
|
-
firstBodyStatement instanceof ExpressionStatement &&
|
|
6840
|
-
firstBodyStatement.directive === 'use asm';
|
|
6841
|
-
}
|
|
6842
|
-
render(code, options) {
|
|
6843
|
-
if (this.body.length) {
|
|
6844
|
-
renderStatementList(this.body, code, this.start + 1, this.end - 1, options);
|
|
6845
|
-
}
|
|
6846
|
-
else {
|
|
6847
|
-
super.render(code, options);
|
|
6848
|
-
}
|
|
6849
|
-
}
|
|
6850
|
-
}
|
|
6851
|
-
|
|
6852
|
-
//@ts-check
|
|
6853
|
-
/** @typedef { import('estree').Node} Node */
|
|
6854
|
-
/** @typedef {Node | {
|
|
6855
|
-
* type: 'PropertyDefinition';
|
|
6856
|
-
* computed: boolean;
|
|
6857
|
-
* value: Node
|
|
6858
|
-
* }} NodeWithPropertyDefinition */
|
|
6859
|
-
|
|
6860
|
-
/**
|
|
6861
|
-
*
|
|
6862
|
-
* @param {NodeWithPropertyDefinition} node
|
|
6863
|
-
* @param {NodeWithPropertyDefinition} parent
|
|
6864
|
-
* @returns boolean
|
|
6865
|
-
*/
|
|
6866
|
-
function is_reference (node, parent) {
|
|
6867
|
-
if (node.type === 'MemberExpression') {
|
|
6868
|
-
return !node.computed && is_reference(node.object, node);
|
|
6869
|
-
}
|
|
6870
|
-
|
|
6871
|
-
if (node.type === 'Identifier') {
|
|
6872
|
-
if (!parent) return true;
|
|
6873
|
-
|
|
6874
|
-
switch (parent.type) {
|
|
6875
|
-
// disregard `bar` in `foo.bar`
|
|
6876
|
-
case 'MemberExpression': return parent.computed || node === parent.object;
|
|
6877
|
-
|
|
6878
|
-
// disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
|
|
6879
|
-
case 'MethodDefinition': return parent.computed;
|
|
6880
|
-
|
|
6881
|
-
// disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
|
|
6882
|
-
case 'PropertyDefinition': return parent.computed || node === parent.value;
|
|
6883
|
-
|
|
6884
|
-
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
|
|
6885
|
-
case 'Property': return parent.computed || node === parent.value;
|
|
6886
|
-
|
|
6887
|
-
// disregard the `bar` in `export { foo as bar }` or
|
|
6888
|
-
// the foo in `import { foo as bar }`
|
|
6889
|
-
case 'ExportSpecifier':
|
|
6890
|
-
case 'ImportSpecifier': return node === parent.local;
|
|
6891
|
-
|
|
6892
|
-
// disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
|
|
6893
|
-
case 'LabeledStatement':
|
|
6894
|
-
case 'BreakStatement':
|
|
6895
|
-
case 'ContinueStatement': return false;
|
|
6896
|
-
default: return true;
|
|
6897
|
-
}
|
|
6898
|
-
}
|
|
6899
|
-
|
|
6900
|
-
return false;
|
|
6901
|
-
}
|
|
6902
|
-
|
|
6903
|
-
/* eslint sort-keys: "off" */
|
|
6904
|
-
const ValueProperties = Symbol('Value Properties');
|
|
6905
|
-
const PURE = { pure: true };
|
|
6906
|
-
const IMPURE = { pure: false };
|
|
6907
|
-
// We use shortened variables to reduce file size here
|
|
6908
|
-
/* OBJECT */
|
|
6909
|
-
const O = {
|
|
6910
|
-
__proto__: null,
|
|
6911
|
-
[ValueProperties]: IMPURE
|
|
6912
|
-
};
|
|
6913
|
-
/* PURE FUNCTION */
|
|
6914
|
-
const PF = {
|
|
6915
|
-
__proto__: null,
|
|
6916
|
-
[ValueProperties]: PURE
|
|
6917
6708
|
};
|
|
6918
6709
|
/* CONSTRUCTOR */
|
|
6919
6710
|
const C = {
|
|
@@ -7053,6 +6844,11 @@ const knownGlobals = {
|
|
|
7053
6844
|
__proto__: null,
|
|
7054
6845
|
[ValueProperties]: PURE,
|
|
7055
6846
|
create: PF,
|
|
6847
|
+
// Technically those can throw in certain situations, but we ignore this as
|
|
6848
|
+
// code that relies on this will hopefully wrap this in a try-catch, which
|
|
6849
|
+
// deoptimizes everything anyway
|
|
6850
|
+
defineProperty: MUTATES_ARG_WITHOUT_ACCESSOR,
|
|
6851
|
+
defineProperties: MUTATES_ARG_WITHOUT_ACCESSOR,
|
|
7056
6852
|
getOwnPropertyDescriptor: PF,
|
|
7057
6853
|
getOwnPropertyNames: PF,
|
|
7058
6854
|
getOwnPropertySymbols: PF,
|
|
@@ -7736,27 +7532,24 @@ function getGlobalAtPath(path) {
|
|
|
7736
7532
|
}
|
|
7737
7533
|
return currentGlobal[ValueProperties];
|
|
7738
7534
|
}
|
|
7739
|
-
function isPureGlobal(path) {
|
|
7740
|
-
const globalAtPath = getGlobalAtPath(path);
|
|
7741
|
-
return globalAtPath !== null && globalAtPath.pure;
|
|
7742
|
-
}
|
|
7743
|
-
function isGlobalMember(path) {
|
|
7744
|
-
if (path.length === 1) {
|
|
7745
|
-
return path[0] === 'undefined' || getGlobalAtPath(path) !== null;
|
|
7746
|
-
}
|
|
7747
|
-
return getGlobalAtPath(path.slice(0, -1)) !== null;
|
|
7748
|
-
}
|
|
7749
7535
|
|
|
7750
7536
|
class GlobalVariable extends Variable {
|
|
7751
7537
|
constructor() {
|
|
7752
7538
|
super(...arguments);
|
|
7539
|
+
// Ensure we use live-bindings for globals as we do not know if they have
|
|
7540
|
+
// been reassigned
|
|
7753
7541
|
this.isReassigned = true;
|
|
7754
7542
|
}
|
|
7755
7543
|
hasEffectsWhenAccessedAtPath(path) {
|
|
7756
|
-
|
|
7544
|
+
if (path.length === 0) {
|
|
7545
|
+
// Technically, "undefined" is a global variable of sorts
|
|
7546
|
+
return this.name !== 'undefined' && getGlobalAtPath([this.name]) === null;
|
|
7547
|
+
}
|
|
7548
|
+
return getGlobalAtPath([this.name, ...path].slice(0, -1)) === null;
|
|
7757
7549
|
}
|
|
7758
|
-
hasEffectsWhenCalledAtPath(path) {
|
|
7759
|
-
|
|
7550
|
+
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
7551
|
+
const globalAtPath = getGlobalAtPath([this.name, ...path]);
|
|
7552
|
+
return globalAtPath === null || globalAtPath.hasEffectsWhenCalled(callOptions, context);
|
|
7760
7553
|
}
|
|
7761
7554
|
}
|
|
7762
7555
|
|
|
@@ -7892,57 +7685,309 @@ class Identifier extends NodeBase {
|
|
|
7892
7685
|
// var use before declaration was encountered.
|
|
7893
7686
|
return (this.isTDZAccess = true);
|
|
7894
7687
|
}
|
|
7895
|
-
return (this.isTDZAccess = false);
|
|
7688
|
+
return (this.isTDZAccess = false);
|
|
7689
|
+
}
|
|
7690
|
+
markDeclarationReached() {
|
|
7691
|
+
this.variable.initReached = true;
|
|
7692
|
+
}
|
|
7693
|
+
render(code, { snippets: { getPropertyAccess } }, { renderedParentType, isCalleeOfRenderedParent, isShorthandProperty } = BLANK) {
|
|
7694
|
+
if (this.variable) {
|
|
7695
|
+
const name = this.variable.getName(getPropertyAccess);
|
|
7696
|
+
if (name !== this.name) {
|
|
7697
|
+
code.overwrite(this.start, this.end, name, {
|
|
7698
|
+
contentOnly: true,
|
|
7699
|
+
storeName: true
|
|
7700
|
+
});
|
|
7701
|
+
if (isShorthandProperty) {
|
|
7702
|
+
code.prependRight(this.start, `${this.name}: `);
|
|
7703
|
+
}
|
|
7704
|
+
}
|
|
7705
|
+
// In strict mode, any variable named "eval" must be the actual "eval" function
|
|
7706
|
+
if (name === 'eval' &&
|
|
7707
|
+
renderedParentType === CallExpression$1 &&
|
|
7708
|
+
isCalleeOfRenderedParent) {
|
|
7709
|
+
code.appendRight(this.start, '0, ');
|
|
7710
|
+
}
|
|
7711
|
+
}
|
|
7712
|
+
}
|
|
7713
|
+
applyDeoptimizations() {
|
|
7714
|
+
this.deoptimized = true;
|
|
7715
|
+
if (this.variable !== null && this.variable instanceof LocalVariable) {
|
|
7716
|
+
this.variable.consolidateInitializers();
|
|
7717
|
+
this.context.requestTreeshakingPass();
|
|
7718
|
+
}
|
|
7719
|
+
}
|
|
7720
|
+
disallowImportReassignment() {
|
|
7721
|
+
return this.context.error({
|
|
7722
|
+
code: 'ILLEGAL_REASSIGNMENT',
|
|
7723
|
+
message: `Illegal reassignment to import '${this.name}'`
|
|
7724
|
+
}, this.start);
|
|
7725
|
+
}
|
|
7726
|
+
getVariableRespectingTDZ() {
|
|
7727
|
+
if (this.isPossibleTDZ()) {
|
|
7728
|
+
return UNKNOWN_EXPRESSION;
|
|
7729
|
+
}
|
|
7730
|
+
return this.variable;
|
|
7731
|
+
}
|
|
7732
|
+
}
|
|
7733
|
+
function closestParentFunctionOrProgram(node) {
|
|
7734
|
+
while (node && !/^Program|Function/.test(node.type)) {
|
|
7735
|
+
node = node.parent;
|
|
7736
|
+
}
|
|
7737
|
+
// one of: ArrowFunctionExpression, FunctionDeclaration, FunctionExpression or Program
|
|
7738
|
+
return node;
|
|
7739
|
+
}
|
|
7740
|
+
|
|
7741
|
+
function treeshakeNode(node, code, start, end) {
|
|
7742
|
+
code.remove(start, end);
|
|
7743
|
+
if (node.annotations) {
|
|
7744
|
+
for (const annotation of node.annotations) {
|
|
7745
|
+
if (annotation.start < start) {
|
|
7746
|
+
code.remove(annotation.start, annotation.end);
|
|
7747
|
+
}
|
|
7748
|
+
else {
|
|
7749
|
+
return;
|
|
7750
|
+
}
|
|
7751
|
+
}
|
|
7752
|
+
}
|
|
7753
|
+
}
|
|
7754
|
+
function removeAnnotations(node, code) {
|
|
7755
|
+
if (!node.annotations && node.parent.type === ExpressionStatement$1) {
|
|
7756
|
+
node = node.parent;
|
|
7757
|
+
}
|
|
7758
|
+
if (node.annotations) {
|
|
7759
|
+
for (const annotation of node.annotations) {
|
|
7760
|
+
code.remove(annotation.start, annotation.end);
|
|
7761
|
+
}
|
|
7762
|
+
}
|
|
7763
|
+
}
|
|
7764
|
+
|
|
7765
|
+
const NO_SEMICOLON = { isNoStatement: true };
|
|
7766
|
+
// This assumes there are only white-space and comments between start and the string we are looking for
|
|
7767
|
+
function findFirstOccurrenceOutsideComment(code, searchString, start = 0) {
|
|
7768
|
+
let searchPos, charCodeAfterSlash;
|
|
7769
|
+
searchPos = code.indexOf(searchString, start);
|
|
7770
|
+
while (true) {
|
|
7771
|
+
start = code.indexOf('/', start);
|
|
7772
|
+
if (start === -1 || start >= searchPos)
|
|
7773
|
+
return searchPos;
|
|
7774
|
+
charCodeAfterSlash = code.charCodeAt(++start);
|
|
7775
|
+
++start;
|
|
7776
|
+
// With our assumption, '/' always starts a comment. Determine comment type:
|
|
7777
|
+
start =
|
|
7778
|
+
charCodeAfterSlash === 47 /*"/"*/
|
|
7779
|
+
? code.indexOf('\n', start) + 1
|
|
7780
|
+
: code.indexOf('*/', start) + 2;
|
|
7781
|
+
if (start > searchPos) {
|
|
7782
|
+
searchPos = code.indexOf(searchString, start);
|
|
7783
|
+
}
|
|
7784
|
+
}
|
|
7785
|
+
}
|
|
7786
|
+
const NON_WHITESPACE = /\S/g;
|
|
7787
|
+
function findNonWhiteSpace(code, index) {
|
|
7788
|
+
NON_WHITESPACE.lastIndex = index;
|
|
7789
|
+
const result = NON_WHITESPACE.exec(code);
|
|
7790
|
+
return result.index;
|
|
7791
|
+
}
|
|
7792
|
+
// This assumes "code" only contains white-space and comments
|
|
7793
|
+
// Returns position of line-comment if applicable
|
|
7794
|
+
function findFirstLineBreakOutsideComment(code) {
|
|
7795
|
+
let lineBreakPos, charCodeAfterSlash, start = 0;
|
|
7796
|
+
lineBreakPos = code.indexOf('\n', start);
|
|
7797
|
+
while (true) {
|
|
7798
|
+
start = code.indexOf('/', start);
|
|
7799
|
+
if (start === -1 || start > lineBreakPos)
|
|
7800
|
+
return [lineBreakPos, lineBreakPos + 1];
|
|
7801
|
+
// With our assumption, '/' always starts a comment. Determine comment type:
|
|
7802
|
+
charCodeAfterSlash = code.charCodeAt(start + 1);
|
|
7803
|
+
if (charCodeAfterSlash === 47 /*"/"*/)
|
|
7804
|
+
return [start, lineBreakPos + 1];
|
|
7805
|
+
start = code.indexOf('*/', start + 3) + 2;
|
|
7806
|
+
if (start > lineBreakPos) {
|
|
7807
|
+
lineBreakPos = code.indexOf('\n', start);
|
|
7808
|
+
}
|
|
7809
|
+
}
|
|
7810
|
+
}
|
|
7811
|
+
function renderStatementList(statements, code, start, end, options) {
|
|
7812
|
+
let currentNode, currentNodeStart, currentNodeNeedsBoundaries, nextNodeStart;
|
|
7813
|
+
let nextNode = statements[0];
|
|
7814
|
+
let nextNodeNeedsBoundaries = !nextNode.included || nextNode.needsBoundaries;
|
|
7815
|
+
if (nextNodeNeedsBoundaries) {
|
|
7816
|
+
nextNodeStart =
|
|
7817
|
+
start + findFirstLineBreakOutsideComment(code.original.slice(start, nextNode.start))[1];
|
|
7818
|
+
}
|
|
7819
|
+
for (let nextIndex = 1; nextIndex <= statements.length; nextIndex++) {
|
|
7820
|
+
currentNode = nextNode;
|
|
7821
|
+
currentNodeStart = nextNodeStart;
|
|
7822
|
+
currentNodeNeedsBoundaries = nextNodeNeedsBoundaries;
|
|
7823
|
+
nextNode = statements[nextIndex];
|
|
7824
|
+
nextNodeNeedsBoundaries =
|
|
7825
|
+
nextNode === undefined ? false : !nextNode.included || nextNode.needsBoundaries;
|
|
7826
|
+
if (currentNodeNeedsBoundaries || nextNodeNeedsBoundaries) {
|
|
7827
|
+
nextNodeStart =
|
|
7828
|
+
currentNode.end +
|
|
7829
|
+
findFirstLineBreakOutsideComment(code.original.slice(currentNode.end, nextNode === undefined ? end : nextNode.start))[1];
|
|
7830
|
+
if (currentNode.included) {
|
|
7831
|
+
currentNodeNeedsBoundaries
|
|
7832
|
+
? currentNode.render(code, options, {
|
|
7833
|
+
end: nextNodeStart,
|
|
7834
|
+
start: currentNodeStart
|
|
7835
|
+
})
|
|
7836
|
+
: currentNode.render(code, options);
|
|
7837
|
+
}
|
|
7838
|
+
else {
|
|
7839
|
+
treeshakeNode(currentNode, code, currentNodeStart, nextNodeStart);
|
|
7840
|
+
}
|
|
7841
|
+
}
|
|
7842
|
+
else {
|
|
7843
|
+
currentNode.render(code, options);
|
|
7844
|
+
}
|
|
7845
|
+
}
|
|
7846
|
+
}
|
|
7847
|
+
// This assumes that the first character is not part of the first node
|
|
7848
|
+
function getCommaSeparatedNodesWithBoundaries(nodes, code, start, end) {
|
|
7849
|
+
const splitUpNodes = [];
|
|
7850
|
+
let node, nextNode, nextNodeStart, contentEnd, char;
|
|
7851
|
+
let separator = start - 1;
|
|
7852
|
+
for (let nextIndex = 0; nextIndex < nodes.length; nextIndex++) {
|
|
7853
|
+
nextNode = nodes[nextIndex];
|
|
7854
|
+
if (node !== undefined) {
|
|
7855
|
+
separator =
|
|
7856
|
+
node.end +
|
|
7857
|
+
findFirstOccurrenceOutsideComment(code.original.slice(node.end, nextNode.start), ',');
|
|
7858
|
+
}
|
|
7859
|
+
nextNodeStart = contentEnd =
|
|
7860
|
+
separator +
|
|
7861
|
+
1 +
|
|
7862
|
+
findFirstLineBreakOutsideComment(code.original.slice(separator + 1, nextNode.start))[1];
|
|
7863
|
+
while (((char = code.original.charCodeAt(nextNodeStart)),
|
|
7864
|
+
char === 32 /*" "*/ || char === 9 /*"\t"*/ || char === 10 /*"\n"*/ || char === 13) /*"\r"*/)
|
|
7865
|
+
nextNodeStart++;
|
|
7866
|
+
if (node !== undefined) {
|
|
7867
|
+
splitUpNodes.push({
|
|
7868
|
+
contentEnd,
|
|
7869
|
+
end: nextNodeStart,
|
|
7870
|
+
node,
|
|
7871
|
+
separator,
|
|
7872
|
+
start
|
|
7873
|
+
});
|
|
7874
|
+
}
|
|
7875
|
+
node = nextNode;
|
|
7876
|
+
start = nextNodeStart;
|
|
7877
|
+
}
|
|
7878
|
+
splitUpNodes.push({
|
|
7879
|
+
contentEnd: end,
|
|
7880
|
+
end,
|
|
7881
|
+
node: node,
|
|
7882
|
+
separator: null,
|
|
7883
|
+
start
|
|
7884
|
+
});
|
|
7885
|
+
return splitUpNodes;
|
|
7886
|
+
}
|
|
7887
|
+
// This assumes there are only white-space and comments between start and end
|
|
7888
|
+
function removeLineBreaks(code, start, end) {
|
|
7889
|
+
while (true) {
|
|
7890
|
+
const [removeStart, removeEnd] = findFirstLineBreakOutsideComment(code.original.slice(start, end));
|
|
7891
|
+
if (removeStart === -1) {
|
|
7892
|
+
break;
|
|
7893
|
+
}
|
|
7894
|
+
code.remove(start + removeStart, (start += removeEnd));
|
|
7895
|
+
}
|
|
7896
|
+
}
|
|
7897
|
+
|
|
7898
|
+
class BlockScope extends ChildScope {
|
|
7899
|
+
addDeclaration(identifier, context, init, isHoisted) {
|
|
7900
|
+
if (isHoisted) {
|
|
7901
|
+
const variable = this.parent.addDeclaration(identifier, context, init, isHoisted);
|
|
7902
|
+
// Necessary to make sure the init is deoptimized for conditional declarations.
|
|
7903
|
+
// We cannot call deoptimizePath here.
|
|
7904
|
+
variable.markInitializersForDeoptimization();
|
|
7905
|
+
return variable;
|
|
7906
|
+
}
|
|
7907
|
+
else {
|
|
7908
|
+
return super.addDeclaration(identifier, context, init, false);
|
|
7909
|
+
}
|
|
7910
|
+
}
|
|
7911
|
+
}
|
|
7912
|
+
|
|
7913
|
+
class ExpressionStatement extends NodeBase {
|
|
7914
|
+
initialise() {
|
|
7915
|
+
if (this.directive &&
|
|
7916
|
+
this.directive !== 'use strict' &&
|
|
7917
|
+
this.parent.type === Program$1) {
|
|
7918
|
+
this.context.warn(
|
|
7919
|
+
// This is necessary, because either way (deleting or not) can lead to errors.
|
|
7920
|
+
{
|
|
7921
|
+
code: 'MODULE_LEVEL_DIRECTIVE',
|
|
7922
|
+
message: `Module level directives cause errors when bundled, '${this.directive}' was ignored.`
|
|
7923
|
+
}, this.start);
|
|
7924
|
+
}
|
|
7925
|
+
}
|
|
7926
|
+
render(code, options) {
|
|
7927
|
+
super.render(code, options);
|
|
7928
|
+
if (this.included)
|
|
7929
|
+
this.insertSemicolon(code);
|
|
7930
|
+
}
|
|
7931
|
+
shouldBeIncluded(context) {
|
|
7932
|
+
if (this.directive && this.directive !== 'use strict')
|
|
7933
|
+
return this.parent.type !== Program$1;
|
|
7934
|
+
return super.shouldBeIncluded(context);
|
|
7935
|
+
}
|
|
7936
|
+
}
|
|
7937
|
+
|
|
7938
|
+
class BlockStatement extends NodeBase {
|
|
7939
|
+
constructor() {
|
|
7940
|
+
super(...arguments);
|
|
7941
|
+
this.directlyIncluded = false;
|
|
7942
|
+
}
|
|
7943
|
+
addImplicitReturnExpressionToScope() {
|
|
7944
|
+
const lastStatement = this.body[this.body.length - 1];
|
|
7945
|
+
if (!lastStatement || lastStatement.type !== ReturnStatement$1) {
|
|
7946
|
+
this.scope.addReturnExpression(UNKNOWN_EXPRESSION);
|
|
7947
|
+
}
|
|
7896
7948
|
}
|
|
7897
|
-
|
|
7898
|
-
this.
|
|
7949
|
+
createScope(parentScope) {
|
|
7950
|
+
this.scope = this.parent.preventChildBlockScope
|
|
7951
|
+
? parentScope
|
|
7952
|
+
: new BlockScope(parentScope);
|
|
7899
7953
|
}
|
|
7900
|
-
|
|
7901
|
-
if (this.
|
|
7902
|
-
|
|
7903
|
-
|
|
7904
|
-
|
|
7905
|
-
|
|
7906
|
-
|
|
7907
|
-
|
|
7908
|
-
if (isShorthandProperty) {
|
|
7909
|
-
code.prependRight(this.start, `${this.name}: `);
|
|
7910
|
-
}
|
|
7911
|
-
}
|
|
7912
|
-
// In strict mode, any variable named "eval" must be the actual "eval" function
|
|
7913
|
-
if (name === 'eval' &&
|
|
7914
|
-
renderedParentType === CallExpression$1 &&
|
|
7915
|
-
isCalleeOfRenderedParent) {
|
|
7916
|
-
code.appendRight(this.start, '0, ');
|
|
7917
|
-
}
|
|
7954
|
+
hasEffects(context) {
|
|
7955
|
+
if (this.deoptimizeBody)
|
|
7956
|
+
return true;
|
|
7957
|
+
for (const node of this.body) {
|
|
7958
|
+
if (context.brokenFlow)
|
|
7959
|
+
break;
|
|
7960
|
+
if (node.hasEffects(context))
|
|
7961
|
+
return true;
|
|
7918
7962
|
}
|
|
7963
|
+
return false;
|
|
7919
7964
|
}
|
|
7920
|
-
|
|
7921
|
-
this.
|
|
7922
|
-
|
|
7923
|
-
this.
|
|
7924
|
-
this.
|
|
7965
|
+
include(context, includeChildrenRecursively) {
|
|
7966
|
+
if (!(this.deoptimizeBody && this.directlyIncluded)) {
|
|
7967
|
+
this.included = true;
|
|
7968
|
+
this.directlyIncluded = true;
|
|
7969
|
+
if (this.deoptimizeBody)
|
|
7970
|
+
includeChildrenRecursively = true;
|
|
7971
|
+
for (const node of this.body) {
|
|
7972
|
+
if (includeChildrenRecursively || node.shouldBeIncluded(context))
|
|
7973
|
+
node.include(context, includeChildrenRecursively);
|
|
7974
|
+
}
|
|
7925
7975
|
}
|
|
7926
7976
|
}
|
|
7927
|
-
|
|
7928
|
-
|
|
7929
|
-
|
|
7930
|
-
|
|
7931
|
-
|
|
7977
|
+
initialise() {
|
|
7978
|
+
const firstBodyStatement = this.body[0];
|
|
7979
|
+
this.deoptimizeBody =
|
|
7980
|
+
firstBodyStatement instanceof ExpressionStatement &&
|
|
7981
|
+
firstBodyStatement.directive === 'use asm';
|
|
7932
7982
|
}
|
|
7933
|
-
|
|
7934
|
-
if (this.
|
|
7935
|
-
|
|
7983
|
+
render(code, options) {
|
|
7984
|
+
if (this.body.length) {
|
|
7985
|
+
renderStatementList(this.body, code, this.start + 1, this.end - 1, options);
|
|
7986
|
+
}
|
|
7987
|
+
else {
|
|
7988
|
+
super.render(code, options);
|
|
7936
7989
|
}
|
|
7937
|
-
return this.variable;
|
|
7938
|
-
}
|
|
7939
|
-
}
|
|
7940
|
-
function closestParentFunctionOrProgram(node) {
|
|
7941
|
-
while (node && !/^Program|Function/.test(node.type)) {
|
|
7942
|
-
node = node.parent;
|
|
7943
7990
|
}
|
|
7944
|
-
// one of: ArrowFunctionExpression, FunctionDeclaration, FunctionExpression or Program
|
|
7945
|
-
return node;
|
|
7946
7991
|
}
|
|
7947
7992
|
|
|
7948
7993
|
class RestElement extends NodeBase {
|
|
@@ -7976,26 +8021,31 @@ class RestElement extends NodeBase {
|
|
|
7976
8021
|
}
|
|
7977
8022
|
}
|
|
7978
8023
|
|
|
7979
|
-
class
|
|
8024
|
+
class FunctionBase extends NodeBase {
|
|
7980
8025
|
constructor() {
|
|
7981
8026
|
super(...arguments);
|
|
8027
|
+
this.objectEntity = null;
|
|
7982
8028
|
this.deoptimizedReturn = false;
|
|
7983
8029
|
}
|
|
7984
|
-
createScope(parentScope) {
|
|
7985
|
-
this.scope = new ReturnValueScope(parentScope, this.context);
|
|
7986
|
-
}
|
|
7987
8030
|
deoptimizePath(path) {
|
|
7988
|
-
|
|
7989
|
-
// which means the return expression needs to be reassigned
|
|
8031
|
+
this.getObjectEntity().deoptimizePath(path);
|
|
7990
8032
|
if (path.length === 1 && path[0] === UnknownKey) {
|
|
8033
|
+
// A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
|
|
8034
|
+
// which means the return expression needs to be reassigned
|
|
7991
8035
|
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
7992
8036
|
}
|
|
7993
8037
|
}
|
|
7994
|
-
|
|
7995
|
-
|
|
7996
|
-
|
|
7997
|
-
|
|
7998
|
-
|
|
8038
|
+
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
8039
|
+
if (path.length > 0) {
|
|
8040
|
+
this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
8041
|
+
}
|
|
8042
|
+
}
|
|
8043
|
+
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
8044
|
+
return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
|
|
8045
|
+
}
|
|
8046
|
+
getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
|
|
8047
|
+
if (path.length > 0) {
|
|
8048
|
+
return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
|
|
7999
8049
|
}
|
|
8000
8050
|
if (this.async) {
|
|
8001
8051
|
if (!this.deoptimizedReturn) {
|
|
@@ -8007,18 +8057,16 @@ class ArrowFunctionExpression extends NodeBase {
|
|
|
8007
8057
|
}
|
|
8008
8058
|
return this.scope.getReturnExpression();
|
|
8009
8059
|
}
|
|
8010
|
-
|
|
8011
|
-
return
|
|
8012
|
-
}
|
|
8013
|
-
hasEffectsWhenAccessedAtPath(path) {
|
|
8014
|
-
return path.length > 1;
|
|
8060
|
+
hasEffectsWhenAccessedAtPath(path, context) {
|
|
8061
|
+
return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
|
|
8015
8062
|
}
|
|
8016
|
-
hasEffectsWhenAssignedAtPath(path) {
|
|
8017
|
-
return path
|
|
8063
|
+
hasEffectsWhenAssignedAtPath(path, context) {
|
|
8064
|
+
return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
|
|
8018
8065
|
}
|
|
8019
|
-
hasEffectsWhenCalledAtPath(path,
|
|
8020
|
-
if (path.length > 0)
|
|
8021
|
-
return
|
|
8066
|
+
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
8067
|
+
if (path.length > 0) {
|
|
8068
|
+
return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
8069
|
+
}
|
|
8022
8070
|
if (this.async) {
|
|
8023
8071
|
const { propertyReadSideEffects } = this.context.options
|
|
8024
8072
|
.treeshake;
|
|
@@ -8034,26 +8082,10 @@ class ArrowFunctionExpression extends NodeBase {
|
|
|
8034
8082
|
if (param.hasEffects(context))
|
|
8035
8083
|
return true;
|
|
8036
8084
|
}
|
|
8037
|
-
const { ignore, brokenFlow } = context;
|
|
8038
|
-
context.ignore = {
|
|
8039
|
-
breaks: false,
|
|
8040
|
-
continues: false,
|
|
8041
|
-
labels: new Set(),
|
|
8042
|
-
returnYield: true
|
|
8043
|
-
};
|
|
8044
|
-
if (this.body.hasEffects(context))
|
|
8045
|
-
return true;
|
|
8046
|
-
context.ignore = ignore;
|
|
8047
|
-
context.brokenFlow = brokenFlow;
|
|
8048
8085
|
return false;
|
|
8049
8086
|
}
|
|
8050
8087
|
include(context, includeChildrenRecursively) {
|
|
8051
8088
|
this.included = true;
|
|
8052
|
-
for (const param of this.params) {
|
|
8053
|
-
if (!(param instanceof Identifier)) {
|
|
8054
|
-
param.include(context, includeChildrenRecursively);
|
|
8055
|
-
}
|
|
8056
|
-
}
|
|
8057
8089
|
const { brokenFlow } = context;
|
|
8058
8090
|
context.brokenFlow = BROKEN_FLOW_NONE;
|
|
8059
8091
|
this.body.include(context, includeChildrenRecursively);
|
|
@@ -8078,7 +8110,50 @@ class ArrowFunctionExpression extends NodeBase {
|
|
|
8078
8110
|
super.parseNode(esTreeNode);
|
|
8079
8111
|
}
|
|
8080
8112
|
}
|
|
8081
|
-
|
|
8113
|
+
FunctionBase.prototype.preventChildBlockScope = true;
|
|
8114
|
+
|
|
8115
|
+
class ArrowFunctionExpression extends FunctionBase {
|
|
8116
|
+
constructor() {
|
|
8117
|
+
super(...arguments);
|
|
8118
|
+
this.objectEntity = null;
|
|
8119
|
+
}
|
|
8120
|
+
createScope(parentScope) {
|
|
8121
|
+
this.scope = new ReturnValueScope(parentScope, this.context);
|
|
8122
|
+
}
|
|
8123
|
+
hasEffects() {
|
|
8124
|
+
return false;
|
|
8125
|
+
}
|
|
8126
|
+
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
8127
|
+
if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
|
|
8128
|
+
return true;
|
|
8129
|
+
const { ignore, brokenFlow } = context;
|
|
8130
|
+
context.ignore = {
|
|
8131
|
+
breaks: false,
|
|
8132
|
+
continues: false,
|
|
8133
|
+
labels: new Set(),
|
|
8134
|
+
returnYield: true
|
|
8135
|
+
};
|
|
8136
|
+
if (this.body.hasEffects(context))
|
|
8137
|
+
return true;
|
|
8138
|
+
context.ignore = ignore;
|
|
8139
|
+
context.brokenFlow = brokenFlow;
|
|
8140
|
+
return false;
|
|
8141
|
+
}
|
|
8142
|
+
include(context, includeChildrenRecursively) {
|
|
8143
|
+
super.include(context, includeChildrenRecursively);
|
|
8144
|
+
for (const param of this.params) {
|
|
8145
|
+
if (!(param instanceof Identifier)) {
|
|
8146
|
+
param.include(context, includeChildrenRecursively);
|
|
8147
|
+
}
|
|
8148
|
+
}
|
|
8149
|
+
}
|
|
8150
|
+
getObjectEntity() {
|
|
8151
|
+
if (this.objectEntity !== null) {
|
|
8152
|
+
return this.objectEntity;
|
|
8153
|
+
}
|
|
8154
|
+
return (this.objectEntity = new ObjectEntity([], OBJECT_PROTOTYPE));
|
|
8155
|
+
}
|
|
8156
|
+
}
|
|
8082
8157
|
|
|
8083
8158
|
function getSystemExportStatement(exportedVariables, { exportNamesByVariable, snippets: { _, getObject, getPropertyAccess } }, modifier = '') {
|
|
8084
8159
|
if (exportedVariables.length === 1 &&
|
|
@@ -8372,85 +8447,26 @@ class FunctionScope extends ReturnValueScope {
|
|
|
8372
8447
|
}
|
|
8373
8448
|
}
|
|
8374
8449
|
|
|
8375
|
-
class FunctionNode extends
|
|
8450
|
+
class FunctionNode extends FunctionBase {
|
|
8376
8451
|
constructor() {
|
|
8377
8452
|
super(...arguments);
|
|
8378
|
-
this.
|
|
8379
|
-
this.isPrototypeDeoptimized = false;
|
|
8453
|
+
this.objectEntity = null;
|
|
8380
8454
|
}
|
|
8381
8455
|
createScope(parentScope) {
|
|
8382
8456
|
this.scope = new FunctionScope(parentScope, this.context);
|
|
8383
8457
|
}
|
|
8384
|
-
|
|
8385
|
-
|
|
8386
|
-
|
|
8387
|
-
|
|
8388
|
-
}
|
|
8389
|
-
else if (path[0] === UnknownKey) {
|
|
8390
|
-
this.isPrototypeDeoptimized = true;
|
|
8391
|
-
// A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
|
|
8392
|
-
// which means the return expression needs to be reassigned as well
|
|
8393
|
-
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
8394
|
-
}
|
|
8395
|
-
}
|
|
8396
|
-
}
|
|
8397
|
-
// TODO for completeness, we should also track other events here
|
|
8398
|
-
deoptimizeThisOnEventAtPath(event, path, thisParameter) {
|
|
8399
|
-
if (event === EVENT_CALLED) {
|
|
8400
|
-
if (path.length > 0) {
|
|
8401
|
-
thisParameter.deoptimizePath(UNKNOWN_PATH);
|
|
8402
|
-
}
|
|
8403
|
-
else {
|
|
8404
|
-
this.scope.thisVariable.addEntityToBeDeoptimized(thisParameter);
|
|
8405
|
-
}
|
|
8406
|
-
}
|
|
8407
|
-
}
|
|
8408
|
-
getReturnExpressionWhenCalledAtPath(path) {
|
|
8409
|
-
if (path.length !== 0) {
|
|
8410
|
-
return UNKNOWN_EXPRESSION;
|
|
8411
|
-
}
|
|
8412
|
-
if (this.async) {
|
|
8413
|
-
if (!this.deoptimizedReturn) {
|
|
8414
|
-
this.deoptimizedReturn = true;
|
|
8415
|
-
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
8416
|
-
this.context.requestTreeshakingPass();
|
|
8417
|
-
}
|
|
8418
|
-
return UNKNOWN_EXPRESSION;
|
|
8458
|
+
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
8459
|
+
super.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
8460
|
+
if (event === EVENT_CALLED && path.length === 0) {
|
|
8461
|
+
this.scope.thisVariable.addEntityToBeDeoptimized(thisParameter);
|
|
8419
8462
|
}
|
|
8420
|
-
return this.scope.getReturnExpression();
|
|
8421
8463
|
}
|
|
8422
8464
|
hasEffects() {
|
|
8423
8465
|
return this.id !== null && this.id.hasEffects();
|
|
8424
8466
|
}
|
|
8425
|
-
hasEffectsWhenAccessedAtPath(path) {
|
|
8426
|
-
if (path.length <= 1)
|
|
8427
|
-
return false;
|
|
8428
|
-
return path.length > 2 || path[0] !== 'prototype' || this.isPrototypeDeoptimized;
|
|
8429
|
-
}
|
|
8430
|
-
hasEffectsWhenAssignedAtPath(path) {
|
|
8431
|
-
if (path.length <= 1) {
|
|
8432
|
-
return false;
|
|
8433
|
-
}
|
|
8434
|
-
return path.length > 2 || path[0] !== 'prototype' || this.isPrototypeDeoptimized;
|
|
8435
|
-
}
|
|
8436
8467
|
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
8437
|
-
if (path
|
|
8468
|
+
if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
|
|
8438
8469
|
return true;
|
|
8439
|
-
if (this.async) {
|
|
8440
|
-
const { propertyReadSideEffects } = this.context.options
|
|
8441
|
-
.treeshake;
|
|
8442
|
-
const returnExpression = this.scope.getReturnExpression();
|
|
8443
|
-
if (returnExpression.hasEffectsWhenCalledAtPath(['then'], { args: NO_ARGS, thisParam: null, withNew: false }, context) ||
|
|
8444
|
-
(propertyReadSideEffects &&
|
|
8445
|
-
(propertyReadSideEffects === 'always' ||
|
|
8446
|
-
returnExpression.hasEffectsWhenAccessedAtPath(['then'], context)))) {
|
|
8447
|
-
return true;
|
|
8448
|
-
}
|
|
8449
|
-
}
|
|
8450
|
-
for (const param of this.params) {
|
|
8451
|
-
if (param.hasEffects(context))
|
|
8452
|
-
return true;
|
|
8453
|
-
}
|
|
8454
8470
|
const thisInit = context.replacedVariableInits.get(this.scope.thisVariable);
|
|
8455
8471
|
context.replacedVariableInits.set(this.scope.thisVariable, callOptions.withNew
|
|
8456
8472
|
? new ObjectEntity(Object.create(null), OBJECT_PROTOTYPE)
|
|
@@ -8475,7 +8491,7 @@ class FunctionNode extends NodeBase {
|
|
|
8475
8491
|
return false;
|
|
8476
8492
|
}
|
|
8477
8493
|
include(context, includeChildrenRecursively) {
|
|
8478
|
-
|
|
8494
|
+
super.include(context, includeChildrenRecursively);
|
|
8479
8495
|
if (this.id)
|
|
8480
8496
|
this.id.include();
|
|
8481
8497
|
const hasArguments = this.scope.argumentsVariable.included;
|
|
@@ -8484,27 +8500,25 @@ class FunctionNode extends NodeBase {
|
|
|
8484
8500
|
param.include(context, includeChildrenRecursively);
|
|
8485
8501
|
}
|
|
8486
8502
|
}
|
|
8487
|
-
const { brokenFlow } = context;
|
|
8488
|
-
context.brokenFlow = BROKEN_FLOW_NONE;
|
|
8489
|
-
this.body.include(context, includeChildrenRecursively);
|
|
8490
|
-
context.brokenFlow = brokenFlow;
|
|
8491
|
-
}
|
|
8492
|
-
includeCallArguments(context, args) {
|
|
8493
|
-
this.scope.includeCallArguments(context, args);
|
|
8494
8503
|
}
|
|
8495
8504
|
initialise() {
|
|
8496
|
-
|
|
8497
|
-
|
|
8498
|
-
|
|
8499
|
-
this.scope.addParameterVariables(this.params.map(param => param.declare('parameter', UNKNOWN_EXPRESSION)), this.params[this.params.length - 1] instanceof RestElement);
|
|
8500
|
-
this.body.addImplicitReturnExpressionToScope();
|
|
8505
|
+
var _a;
|
|
8506
|
+
super.initialise();
|
|
8507
|
+
(_a = this.id) === null || _a === void 0 ? void 0 : _a.declare('function', this);
|
|
8501
8508
|
}
|
|
8502
|
-
|
|
8503
|
-
|
|
8504
|
-
|
|
8509
|
+
getObjectEntity() {
|
|
8510
|
+
if (this.objectEntity !== null) {
|
|
8511
|
+
return this.objectEntity;
|
|
8512
|
+
}
|
|
8513
|
+
return (this.objectEntity = new ObjectEntity([
|
|
8514
|
+
{
|
|
8515
|
+
key: 'prototype',
|
|
8516
|
+
kind: 'init',
|
|
8517
|
+
property: new ObjectEntity([], OBJECT_PROTOTYPE)
|
|
8518
|
+
}
|
|
8519
|
+
], OBJECT_PROTOTYPE));
|
|
8505
8520
|
}
|
|
8506
8521
|
}
|
|
8507
|
-
FunctionNode.prototype.preventChildBlockScope = true;
|
|
8508
8522
|
|
|
8509
8523
|
class AwaitExpression extends NodeBase {
|
|
8510
8524
|
constructor() {
|
|
@@ -8754,7 +8768,11 @@ class MemberExpression extends NodeBase {
|
|
|
8754
8768
|
}
|
|
8755
8769
|
else if (!this.replacement) {
|
|
8756
8770
|
if (path.length < MAX_PATH_DEPTH) {
|
|
8757
|
-
this.
|
|
8771
|
+
const propertyKey = this.getPropertyKey();
|
|
8772
|
+
this.object.deoptimizePath([
|
|
8773
|
+
propertyKey === UnknownKey ? UnknownNonAccessorKey : propertyKey,
|
|
8774
|
+
...path
|
|
8775
|
+
]);
|
|
8758
8776
|
}
|
|
8759
8777
|
}
|
|
8760
8778
|
}
|
|
@@ -12434,8 +12452,8 @@ class Module {
|
|
|
12434
12452
|
this.importMetas = [];
|
|
12435
12453
|
this.importedFromNotTreeshaken = false;
|
|
12436
12454
|
this.importers = [];
|
|
12437
|
-
this.imports = new Set();
|
|
12438
12455
|
this.includedDynamicImporters = [];
|
|
12456
|
+
this.includedImports = new Set();
|
|
12439
12457
|
this.isExecuted = false;
|
|
12440
12458
|
this.isUserDefinedEntryPoint = false;
|
|
12441
12459
|
this.needsExportShim = false;
|
|
@@ -12564,7 +12582,7 @@ class Module {
|
|
|
12564
12582
|
this.relevantDependencies = new Set();
|
|
12565
12583
|
const necessaryDependencies = new Set();
|
|
12566
12584
|
const alwaysCheckedDependencies = new Set();
|
|
12567
|
-
const dependencyVariables = new Set(this.
|
|
12585
|
+
const dependencyVariables = new Set(this.includedImports);
|
|
12568
12586
|
if (this.info.isEntry ||
|
|
12569
12587
|
this.includedDynamicImporters.length > 0 ||
|
|
12570
12588
|
this.namespace.included ||
|
|
@@ -13142,13 +13160,13 @@ class Module {
|
|
|
13142
13160
|
if (module instanceof ExternalModule) {
|
|
13143
13161
|
const [externalVariable] = module.getVariableForExportName('*');
|
|
13144
13162
|
externalVariable.include();
|
|
13145
|
-
this.
|
|
13163
|
+
this.includedImports.add(externalVariable);
|
|
13146
13164
|
externalNamespaces.add(externalVariable);
|
|
13147
13165
|
}
|
|
13148
13166
|
else if (module.info.syntheticNamedExports) {
|
|
13149
13167
|
const syntheticNamespace = module.getSyntheticNamespace();
|
|
13150
13168
|
syntheticNamespace.include();
|
|
13151
|
-
this.
|
|
13169
|
+
this.includedImports.add(syntheticNamespace);
|
|
13152
13170
|
syntheticNamespaces.add(syntheticNamespace);
|
|
13153
13171
|
}
|
|
13154
13172
|
}
|
|
@@ -13185,7 +13203,7 @@ class Module {
|
|
|
13185
13203
|
this.includeVariable(variable);
|
|
13186
13204
|
const variableModule = variable.module;
|
|
13187
13205
|
if (variableModule && variableModule !== this) {
|
|
13188
|
-
this.
|
|
13206
|
+
this.includedImports.add(variable);
|
|
13189
13207
|
}
|
|
13190
13208
|
}
|
|
13191
13209
|
shimMissingExport(name) {
|
|
@@ -14517,6 +14535,7 @@ class Chunk {
|
|
|
14517
14535
|
this.implicitEntryModules = [];
|
|
14518
14536
|
this.implicitlyLoadedBefore = new Set();
|
|
14519
14537
|
this.imports = new Set();
|
|
14538
|
+
this.includedReexportsByModule = new Map();
|
|
14520
14539
|
this.indentString = undefined;
|
|
14521
14540
|
// This may only be updated in the constructor
|
|
14522
14541
|
this.isEmpty = true;
|
|
@@ -14688,6 +14707,9 @@ class Chunk {
|
|
|
14688
14707
|
this.exports.add(module.namespace);
|
|
14689
14708
|
}
|
|
14690
14709
|
}
|
|
14710
|
+
if (!this.outputOptions.preserveModules) {
|
|
14711
|
+
this.addNecessaryImportsForFacades();
|
|
14712
|
+
}
|
|
14691
14713
|
return facades;
|
|
14692
14714
|
}
|
|
14693
14715
|
generateId(addons, options, existingNames, includeHash) {
|
|
@@ -15030,6 +15052,15 @@ class Chunk {
|
|
|
15030
15052
|
}
|
|
15031
15053
|
}
|
|
15032
15054
|
}
|
|
15055
|
+
addNecessaryImportsForFacades() {
|
|
15056
|
+
for (const [module, variables] of this.includedReexportsByModule) {
|
|
15057
|
+
if (this.includedNamespaces.has(module)) {
|
|
15058
|
+
for (const variable of variables) {
|
|
15059
|
+
this.imports.add(variable);
|
|
15060
|
+
}
|
|
15061
|
+
}
|
|
15062
|
+
}
|
|
15063
|
+
}
|
|
15033
15064
|
assignFacadeName({ fileName, name }, facadedModule) {
|
|
15034
15065
|
if (fileName) {
|
|
15035
15066
|
this.fileName = fileName;
|
|
@@ -15077,6 +15108,7 @@ class Chunk {
|
|
|
15077
15108
|
return hash.digest('hex').substr(0, 8);
|
|
15078
15109
|
}
|
|
15079
15110
|
ensureReexportsAreAvailableForModule(module) {
|
|
15111
|
+
const includedReexports = [];
|
|
15080
15112
|
const map = module.getExportNamesByVariable();
|
|
15081
15113
|
for (const exportedVariable of map.keys()) {
|
|
15082
15114
|
const isSynthetic = exportedVariable instanceof SyntheticNamedExportVariable;
|
|
@@ -15090,6 +15122,7 @@ class Chunk {
|
|
|
15090
15122
|
const chunk = this.chunkByModule.get(exportingModule);
|
|
15091
15123
|
if (chunk && chunk !== this) {
|
|
15092
15124
|
chunk.exports.add(importedVariable);
|
|
15125
|
+
includedReexports.push(importedVariable);
|
|
15093
15126
|
if (isSynthetic) {
|
|
15094
15127
|
this.imports.add(importedVariable);
|
|
15095
15128
|
}
|
|
@@ -15097,6 +15130,9 @@ class Chunk {
|
|
|
15097
15130
|
}
|
|
15098
15131
|
}
|
|
15099
15132
|
}
|
|
15133
|
+
if (includedReexports.length) {
|
|
15134
|
+
this.includedReexportsByModule.set(module, includedReexports);
|
|
15135
|
+
}
|
|
15100
15136
|
}
|
|
15101
15137
|
finaliseDynamicImports(options, snippets) {
|
|
15102
15138
|
const stripKnownJsExtensions = options.format === 'amd';
|
|
@@ -15452,7 +15488,7 @@ class Chunk {
|
|
|
15452
15488
|
deconflictChunk(this.orderedModules, this.getDependenciesToBeDeconflicted(format !== 'es' && format !== 'system', format === 'amd' || format === 'umd' || format === 'iife', interop), this.imports, usedNames, format, interop, this.outputOptions.preserveModules, this.outputOptions.externalLiveBindings, this.chunkByModule, syntheticExports, this.exportNamesByVariable, this.accessedGlobalsByScope, this.includedNamespaces);
|
|
15453
15489
|
}
|
|
15454
15490
|
setUpChunkImportsAndExportsForModule(module) {
|
|
15455
|
-
const moduleImports = new Set(module.
|
|
15491
|
+
const moduleImports = new Set(module.includedImports);
|
|
15456
15492
|
// when we are not preserving modules, we need to make all namespace variables available for
|
|
15457
15493
|
// rendering the namespace object
|
|
15458
15494
|
if (!this.outputOptions.preserveModules) {
|
|
@@ -23119,6 +23155,12 @@ function formatAction([pluginName, hookName, args]) {
|
|
|
23119
23155
|
}
|
|
23120
23156
|
return action;
|
|
23121
23157
|
}
|
|
23158
|
+
// We do not directly listen on process to avoid max listeners warnings for
|
|
23159
|
+
// complicated build processes
|
|
23160
|
+
const beforeExitEvent = 'beforeExit';
|
|
23161
|
+
const beforeExitEmitter = new require$$0$2.EventEmitter();
|
|
23162
|
+
beforeExitEmitter.setMaxListeners(0);
|
|
23163
|
+
process$1.on(beforeExitEvent, () => beforeExitEmitter.emit(beforeExitEvent));
|
|
23122
23164
|
async function catchUnfinishedHookActions(pluginDriver, callback) {
|
|
23123
23165
|
let handleEmptyEventLoop;
|
|
23124
23166
|
const emptyEventLoopPromise = new Promise((_, reject) => {
|
|
@@ -23127,10 +23169,10 @@ async function catchUnfinishedHookActions(pluginDriver, callback) {
|
|
|
23127
23169
|
reject(new Error(`Unexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit:\n` +
|
|
23128
23170
|
[...unfulfilledActions].map(formatAction).join('\n')));
|
|
23129
23171
|
};
|
|
23130
|
-
|
|
23172
|
+
beforeExitEmitter.once(beforeExitEvent, handleEmptyEventLoop);
|
|
23131
23173
|
});
|
|
23132
23174
|
const result = await Promise.race([callback(), emptyEventLoopPromise]);
|
|
23133
|
-
|
|
23175
|
+
beforeExitEmitter.off(beforeExitEvent, handleEmptyEventLoop);
|
|
23134
23176
|
return result;
|
|
23135
23177
|
}
|
|
23136
23178
|
|