rollup 2.74.0 → 2.74.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -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 +935 -1099
- 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 +935 -1099
- 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.74.
|
|
4
|
-
Thu, 19 May 2022
|
|
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.74.
|
|
30
|
+
var version$1 = "2.74.1";
|
|
31
31
|
|
|
32
32
|
function ensureArray$1(items) {
|
|
33
33
|
if (Array.isArray(items)) {
|
|
@@ -1865,7 +1865,7 @@ class MagicString {
|
|
|
1865
1865
|
const hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1866
1866
|
|
|
1867
1867
|
class Bundle$1 {
|
|
1868
|
-
constructor(options) {
|
|
1868
|
+
constructor(options = {}) {
|
|
1869
1869
|
this.intro = options.intro || '';
|
|
1870
1870
|
this.separator = options.separator !== undefined ? options.separator : '\n';
|
|
1871
1871
|
this.sources = [];
|
|
@@ -2222,7 +2222,6 @@ class DiscriminatedPathTracker {
|
|
|
2222
2222
|
}
|
|
2223
2223
|
|
|
2224
2224
|
const UnknownValue = Symbol('Unknown Value');
|
|
2225
|
-
const UnknownTruthyValue = Symbol('Unknown Truthy Value');
|
|
2226
2225
|
class ExpressionEntity {
|
|
2227
2226
|
constructor() {
|
|
2228
2227
|
this.included = false;
|
|
@@ -2251,17 +2250,14 @@ class ExpressionEntity {
|
|
|
2251
2250
|
hasEffectsWhenCalledAtPath(_path, _callOptions, _context) {
|
|
2252
2251
|
return true;
|
|
2253
2252
|
}
|
|
2254
|
-
include(_context, _includeChildrenRecursively
|
|
2253
|
+
include(_context, _includeChildrenRecursively) {
|
|
2255
2254
|
this.included = true;
|
|
2256
2255
|
}
|
|
2257
|
-
|
|
2256
|
+
includeCallArguments(context, args) {
|
|
2258
2257
|
for (const arg of args) {
|
|
2259
2258
|
arg.include(context, false);
|
|
2260
2259
|
}
|
|
2261
2260
|
}
|
|
2262
|
-
shouldBeIncluded(_context) {
|
|
2263
|
-
return true;
|
|
2264
|
-
}
|
|
2265
2261
|
}
|
|
2266
2262
|
const UNKNOWN_EXPRESSION = new (class UnknownExpression extends ExpressionEntity {
|
|
2267
2263
|
})();
|
|
@@ -4800,9 +4796,9 @@ const stringReplace = {
|
|
|
4800
4796
|
hasEffectsWhenCalled(callOptions, context) {
|
|
4801
4797
|
const arg1 = callOptions.args[1];
|
|
4802
4798
|
return (callOptions.args.length < 2 ||
|
|
4803
|
-
(
|
|
4799
|
+
(arg1.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, {
|
|
4804
4800
|
deoptimizeCache() { }
|
|
4805
|
-
}) ===
|
|
4801
|
+
}) === UnknownValue &&
|
|
4806
4802
|
arg1.hasEffectsWhenCalledAtPath(EMPTY_PATH, {
|
|
4807
4803
|
args: NO_ARGS,
|
|
4808
4804
|
thisParam: null,
|
|
@@ -5357,7 +5353,8 @@ class NodeBase extends ExpressionEntity {
|
|
|
5357
5353
|
continue;
|
|
5358
5354
|
if (Array.isArray(value)) {
|
|
5359
5355
|
for (const child of value) {
|
|
5360
|
-
child
|
|
5356
|
+
if (child !== null)
|
|
5357
|
+
child.bind();
|
|
5361
5358
|
}
|
|
5362
5359
|
}
|
|
5363
5360
|
else {
|
|
@@ -5380,7 +5377,7 @@ class NodeBase extends ExpressionEntity {
|
|
|
5380
5377
|
continue;
|
|
5381
5378
|
if (Array.isArray(value)) {
|
|
5382
5379
|
for (const child of value) {
|
|
5383
|
-
if (child
|
|
5380
|
+
if (child !== null && child.hasEffects(context))
|
|
5384
5381
|
return true;
|
|
5385
5382
|
}
|
|
5386
5383
|
}
|
|
@@ -5389,7 +5386,7 @@ class NodeBase extends ExpressionEntity {
|
|
|
5389
5386
|
}
|
|
5390
5387
|
return false;
|
|
5391
5388
|
}
|
|
5392
|
-
include(context, includeChildrenRecursively
|
|
5389
|
+
include(context, includeChildrenRecursively) {
|
|
5393
5390
|
if (this.deoptimized === false)
|
|
5394
5391
|
this.applyDeoptimizations();
|
|
5395
5392
|
this.included = true;
|
|
@@ -5399,7 +5396,8 @@ class NodeBase extends ExpressionEntity {
|
|
|
5399
5396
|
continue;
|
|
5400
5397
|
if (Array.isArray(value)) {
|
|
5401
5398
|
for (const child of value) {
|
|
5402
|
-
child
|
|
5399
|
+
if (child !== null)
|
|
5400
|
+
child.include(context, includeChildrenRecursively);
|
|
5403
5401
|
}
|
|
5404
5402
|
}
|
|
5405
5403
|
else {
|
|
@@ -5407,6 +5405,9 @@ class NodeBase extends ExpressionEntity {
|
|
|
5407
5405
|
}
|
|
5408
5406
|
}
|
|
5409
5407
|
}
|
|
5408
|
+
includeAsSingleStatement(context, includeChildrenRecursively) {
|
|
5409
|
+
this.include(context, includeChildrenRecursively);
|
|
5410
|
+
}
|
|
5410
5411
|
/**
|
|
5411
5412
|
* Override to perform special initialisation steps after the scope is initialised
|
|
5412
5413
|
*/
|
|
@@ -5453,7 +5454,8 @@ class NodeBase extends ExpressionEntity {
|
|
|
5453
5454
|
continue;
|
|
5454
5455
|
if (Array.isArray(value)) {
|
|
5455
5456
|
for (const child of value) {
|
|
5456
|
-
child
|
|
5457
|
+
if (child !== null)
|
|
5458
|
+
child.render(code, options);
|
|
5457
5459
|
}
|
|
5458
5460
|
}
|
|
5459
5461
|
else {
|
|
@@ -5464,28 +5466,7 @@ class NodeBase extends ExpressionEntity {
|
|
|
5464
5466
|
shouldBeIncluded(context) {
|
|
5465
5467
|
return this.included || (!context.brokenFlow && this.hasEffects(createHasEffectsContext()));
|
|
5466
5468
|
}
|
|
5467
|
-
|
|
5468
|
-
* Just deoptimize everything by default so that when e.g. we do not track
|
|
5469
|
-
* something properly, it is deoptimized.
|
|
5470
|
-
* @protected
|
|
5471
|
-
*/
|
|
5472
|
-
applyDeoptimizations() {
|
|
5473
|
-
this.deoptimized = true;
|
|
5474
|
-
for (const key of this.keys) {
|
|
5475
|
-
const value = this[key];
|
|
5476
|
-
if (value === null)
|
|
5477
|
-
continue;
|
|
5478
|
-
if (Array.isArray(value)) {
|
|
5479
|
-
for (const child of value) {
|
|
5480
|
-
child === null || child === void 0 ? void 0 : child.deoptimizePath(UNKNOWN_PATH);
|
|
5481
|
-
}
|
|
5482
|
-
}
|
|
5483
|
-
else {
|
|
5484
|
-
value.deoptimizePath(UNKNOWN_PATH);
|
|
5485
|
-
}
|
|
5486
|
-
}
|
|
5487
|
-
this.context.requestTreeshakingPass();
|
|
5488
|
-
}
|
|
5469
|
+
applyDeoptimizations() { }
|
|
5489
5470
|
}
|
|
5490
5471
|
|
|
5491
5472
|
class SpreadElement extends NodeBase {
|
|
@@ -5567,7 +5548,7 @@ class Method extends ExpressionEntity {
|
|
|
5567
5548
|
}
|
|
5568
5549
|
return false;
|
|
5569
5550
|
}
|
|
5570
|
-
|
|
5551
|
+
includeCallArguments(context, args) {
|
|
5571
5552
|
for (const arg of args) {
|
|
5572
5553
|
arg.include(context, false);
|
|
5573
5554
|
}
|
|
@@ -5771,7 +5752,7 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5771
5752
|
}
|
|
5772
5753
|
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
5773
5754
|
if (path.length === 0) {
|
|
5774
|
-
return
|
|
5755
|
+
return UnknownValue;
|
|
5775
5756
|
}
|
|
5776
5757
|
const key = path[0];
|
|
5777
5758
|
const expressionAtPath = this.getMemberExpressionAndTrackDeopt(key, origin);
|
|
@@ -5907,16 +5888,6 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5907
5888
|
}
|
|
5908
5889
|
return true;
|
|
5909
5890
|
}
|
|
5910
|
-
includeArgumentsWhenCalledAtPath(path, context, args) {
|
|
5911
|
-
const key = path[0];
|
|
5912
|
-
const expressionAtPath = this.getMemberExpression(key);
|
|
5913
|
-
if (expressionAtPath) {
|
|
5914
|
-
return expressionAtPath.includeArgumentsWhenCalledAtPath(path.slice(1), context, args);
|
|
5915
|
-
}
|
|
5916
|
-
if (this.prototypeExpression) {
|
|
5917
|
-
return this.prototypeExpression.includeArgumentsWhenCalledAtPath(path, context, args);
|
|
5918
|
-
}
|
|
5919
|
-
}
|
|
5920
5891
|
buildPropertyMaps(properties) {
|
|
5921
5892
|
const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchableGetters, unmatchableSetters } = this;
|
|
5922
5893
|
const unmatchablePropertiesAndSetters = [];
|
|
@@ -6186,7 +6157,6 @@ const ARRAY_PROTOTYPE = new ObjectEntity({
|
|
|
6186
6157
|
class ArrayExpression extends NodeBase {
|
|
6187
6158
|
constructor() {
|
|
6188
6159
|
super(...arguments);
|
|
6189
|
-
this.deoptimized = false;
|
|
6190
6160
|
this.objectEntity = null;
|
|
6191
6161
|
}
|
|
6192
6162
|
deoptimizePath(path) {
|
|
@@ -6210,23 +6180,6 @@ class ArrayExpression extends NodeBase {
|
|
|
6210
6180
|
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
6211
6181
|
return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
6212
6182
|
}
|
|
6213
|
-
includeArgumentsWhenCalledAtPath(path, context, args) {
|
|
6214
|
-
this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
|
|
6215
|
-
}
|
|
6216
|
-
applyDeoptimizations() {
|
|
6217
|
-
this.deoptimized = true;
|
|
6218
|
-
let hasSpread = false;
|
|
6219
|
-
for (let index = 0; index < this.elements.length; index++) {
|
|
6220
|
-
const element = this.elements[index];
|
|
6221
|
-
if (hasSpread || element instanceof SpreadElement) {
|
|
6222
|
-
if (element) {
|
|
6223
|
-
hasSpread = true;
|
|
6224
|
-
element.deoptimizePath(UNKNOWN_PATH);
|
|
6225
|
-
}
|
|
6226
|
-
}
|
|
6227
|
-
}
|
|
6228
|
-
this.context.requestTreeshakingPass();
|
|
6229
|
-
}
|
|
6230
6183
|
getObjectEntity() {
|
|
6231
6184
|
if (this.objectEntity !== null) {
|
|
6232
6185
|
return this.objectEntity;
|
|
@@ -6237,7 +6190,7 @@ class ArrayExpression extends NodeBase {
|
|
|
6237
6190
|
let hasSpread = false;
|
|
6238
6191
|
for (let index = 0; index < this.elements.length; index++) {
|
|
6239
6192
|
const element = this.elements[index];
|
|
6240
|
-
if (
|
|
6193
|
+
if (element instanceof SpreadElement || hasSpread) {
|
|
6241
6194
|
if (element) {
|
|
6242
6195
|
hasSpread = true;
|
|
6243
6196
|
properties.unshift({ key: UnknownInteger, kind: 'init', property: element });
|
|
@@ -6257,7 +6210,9 @@ class ArrayExpression extends NodeBase {
|
|
|
6257
6210
|
class ArrayPattern extends NodeBase {
|
|
6258
6211
|
addExportedVariables(variables, exportNamesByVariable) {
|
|
6259
6212
|
for (const element of this.elements) {
|
|
6260
|
-
element
|
|
6213
|
+
if (element !== null) {
|
|
6214
|
+
element.addExportedVariables(variables, exportNamesByVariable);
|
|
6215
|
+
}
|
|
6261
6216
|
}
|
|
6262
6217
|
}
|
|
6263
6218
|
declare(kind) {
|
|
@@ -6269,23 +6224,29 @@ class ArrayPattern extends NodeBase {
|
|
|
6269
6224
|
}
|
|
6270
6225
|
return variables;
|
|
6271
6226
|
}
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6227
|
+
deoptimizePath(path) {
|
|
6228
|
+
if (path.length === 0) {
|
|
6229
|
+
for (const element of this.elements) {
|
|
6230
|
+
if (element !== null) {
|
|
6231
|
+
element.deoptimizePath(path);
|
|
6232
|
+
}
|
|
6233
|
+
}
|
|
6276
6234
|
}
|
|
6277
6235
|
}
|
|
6278
|
-
|
|
6279
|
-
|
|
6236
|
+
hasEffectsWhenAssignedAtPath(path, context) {
|
|
6237
|
+
if (path.length > 0)
|
|
6238
|
+
return true;
|
|
6280
6239
|
for (const element of this.elements) {
|
|
6281
|
-
if (element
|
|
6240
|
+
if (element !== null && element.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context))
|
|
6282
6241
|
return true;
|
|
6283
6242
|
}
|
|
6284
6243
|
return false;
|
|
6285
6244
|
}
|
|
6286
6245
|
markDeclarationReached() {
|
|
6287
6246
|
for (const element of this.elements) {
|
|
6288
|
-
element
|
|
6247
|
+
if (element !== null) {
|
|
6248
|
+
element.markDeclarationReached();
|
|
6249
|
+
}
|
|
6289
6250
|
}
|
|
6290
6251
|
}
|
|
6291
6252
|
}
|
|
@@ -6405,7 +6366,7 @@ class LocalVariable extends Variable {
|
|
|
6405
6366
|
}
|
|
6406
6367
|
}
|
|
6407
6368
|
}
|
|
6408
|
-
|
|
6369
|
+
includeCallArguments(context, args) {
|
|
6409
6370
|
if (this.isReassigned || (this.init && context.includedCallArguments.has(this.init))) {
|
|
6410
6371
|
for (const arg of args) {
|
|
6411
6372
|
arg.include(context, false);
|
|
@@ -6413,7 +6374,7 @@ class LocalVariable extends Variable {
|
|
|
6413
6374
|
}
|
|
6414
6375
|
else if (this.init) {
|
|
6415
6376
|
context.includedCallArguments.add(this.init);
|
|
6416
|
-
this.init.
|
|
6377
|
+
this.init.includeCallArguments(context, args);
|
|
6417
6378
|
context.includedCallArguments.delete(this.init);
|
|
6418
6379
|
}
|
|
6419
6380
|
}
|
|
@@ -6661,618 +6622,88 @@ class ReturnValueScope extends ParameterScope {
|
|
|
6661
6622
|
}
|
|
6662
6623
|
}
|
|
6663
6624
|
|
|
6664
|
-
|
|
6665
|
-
|
|
6666
|
-
|
|
6667
|
-
|
|
6668
|
-
|
|
6669
|
-
|
|
6670
|
-
|
|
6671
|
-
}
|
|
6672
|
-
declare(kind, init) {
|
|
6673
|
-
return this.left.declare(kind, init);
|
|
6674
|
-
}
|
|
6675
|
-
deoptimizePath(path) {
|
|
6676
|
-
path.length === 0 && this.left.deoptimizePath(path);
|
|
6677
|
-
}
|
|
6678
|
-
hasEffectsWhenAssignedAtPath(path, context) {
|
|
6679
|
-
return path.length > 0 || this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
|
|
6680
|
-
}
|
|
6681
|
-
include(context, includeChildrenRecursively) {
|
|
6682
|
-
this.included = true;
|
|
6683
|
-
this.left.include(context, includeChildrenRecursively);
|
|
6684
|
-
this.right.include(context, includeChildrenRecursively);
|
|
6685
|
-
}
|
|
6686
|
-
markDeclarationReached() {
|
|
6687
|
-
this.left.markDeclarationReached();
|
|
6688
|
-
}
|
|
6689
|
-
render(code, options, { isShorthandProperty } = BLANK) {
|
|
6690
|
-
this.left.render(code, options, { isShorthandProperty });
|
|
6691
|
-
if (this.right.included) {
|
|
6692
|
-
this.right.render(code, options);
|
|
6693
|
-
}
|
|
6694
|
-
else {
|
|
6695
|
-
code.remove(this.left.end, this.end);
|
|
6696
|
-
}
|
|
6697
|
-
}
|
|
6698
|
-
applyDeoptimizations() {
|
|
6699
|
-
this.deoptimized = true;
|
|
6700
|
-
this.left.deoptimizePath(EMPTY_PATH);
|
|
6701
|
-
this.right.deoptimizePath(UNKNOWN_PATH);
|
|
6702
|
-
this.context.requestTreeshakingPass();
|
|
6703
|
-
}
|
|
6704
|
-
}
|
|
6625
|
+
//@ts-check
|
|
6626
|
+
/** @typedef { import('estree').Node} Node */
|
|
6627
|
+
/** @typedef {Node | {
|
|
6628
|
+
* type: 'PropertyDefinition';
|
|
6629
|
+
* computed: boolean;
|
|
6630
|
+
* value: Node
|
|
6631
|
+
* }} NodeWithPropertyDefinition */
|
|
6705
6632
|
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
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;
|
|
6728
6674
|
}
|
|
6729
6675
|
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
while (true) {
|
|
6736
|
-
start = code.indexOf('/', start);
|
|
6737
|
-
if (start === -1 || start >= searchPos)
|
|
6738
|
-
return searchPos;
|
|
6739
|
-
charCodeAfterSlash = code.charCodeAt(++start);
|
|
6740
|
-
++start;
|
|
6741
|
-
// With our assumption, '/' always starts a comment. Determine comment type:
|
|
6742
|
-
start =
|
|
6743
|
-
charCodeAfterSlash === 47 /*"/"*/
|
|
6744
|
-
? code.indexOf('\n', start) + 1
|
|
6745
|
-
: code.indexOf('*/', start) + 2;
|
|
6746
|
-
if (start > searchPos) {
|
|
6747
|
-
searchPos = code.indexOf(searchString, start);
|
|
6748
|
-
}
|
|
6676
|
+
/* eslint sort-keys: "off" */
|
|
6677
|
+
const ValueProperties = Symbol('Value Properties');
|
|
6678
|
+
const PURE = {
|
|
6679
|
+
hasEffectsWhenCalled() {
|
|
6680
|
+
return false;
|
|
6749
6681
|
}
|
|
6750
|
-
}
|
|
6751
|
-
const
|
|
6752
|
-
|
|
6753
|
-
|
|
6754
|
-
const result = NON_WHITESPACE.exec(code);
|
|
6755
|
-
return result.index;
|
|
6756
|
-
}
|
|
6757
|
-
// This assumes "code" only contains white-space and comments
|
|
6758
|
-
// Returns position of line-comment if applicable
|
|
6759
|
-
function findFirstLineBreakOutsideComment(code) {
|
|
6760
|
-
let lineBreakPos, charCodeAfterSlash, start = 0;
|
|
6761
|
-
lineBreakPos = code.indexOf('\n', start);
|
|
6762
|
-
while (true) {
|
|
6763
|
-
start = code.indexOf('/', start);
|
|
6764
|
-
if (start === -1 || start > lineBreakPos)
|
|
6765
|
-
return [lineBreakPos, lineBreakPos + 1];
|
|
6766
|
-
// With our assumption, '/' always starts a comment. Determine comment type:
|
|
6767
|
-
charCodeAfterSlash = code.charCodeAt(start + 1);
|
|
6768
|
-
if (charCodeAfterSlash === 47 /*"/"*/)
|
|
6769
|
-
return [start, lineBreakPos + 1];
|
|
6770
|
-
start = code.indexOf('*/', start + 3) + 2;
|
|
6771
|
-
if (start > lineBreakPos) {
|
|
6772
|
-
lineBreakPos = code.indexOf('\n', start);
|
|
6773
|
-
}
|
|
6682
|
+
};
|
|
6683
|
+
const IMPURE = {
|
|
6684
|
+
hasEffectsWhenCalled() {
|
|
6685
|
+
return true;
|
|
6774
6686
|
}
|
|
6775
|
-
}
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
|
|
6793
|
-
|
|
6794
|
-
|
|
6795
|
-
if (currentNode.included) {
|
|
6796
|
-
currentNodeNeedsBoundaries
|
|
6797
|
-
? currentNode.render(code, options, {
|
|
6798
|
-
end: nextNodeStart,
|
|
6799
|
-
start: currentNodeStart
|
|
6800
|
-
})
|
|
6801
|
-
: currentNode.render(code, options);
|
|
6802
|
-
}
|
|
6803
|
-
else {
|
|
6804
|
-
treeshakeNode(currentNode, code, currentNodeStart, nextNodeStart);
|
|
6805
|
-
}
|
|
6806
|
-
}
|
|
6807
|
-
else {
|
|
6808
|
-
currentNode.render(code, options);
|
|
6809
|
-
}
|
|
6810
|
-
}
|
|
6811
|
-
}
|
|
6812
|
-
// This assumes that the first character is not part of the first node
|
|
6813
|
-
function getCommaSeparatedNodesWithBoundaries(nodes, code, start, end) {
|
|
6814
|
-
const splitUpNodes = [];
|
|
6815
|
-
let node, nextNode, nextNodeStart, contentEnd, char;
|
|
6816
|
-
let separator = start - 1;
|
|
6817
|
-
for (let nextIndex = 0; nextIndex < nodes.length; nextIndex++) {
|
|
6818
|
-
nextNode = nodes[nextIndex];
|
|
6819
|
-
if (node !== undefined) {
|
|
6820
|
-
separator =
|
|
6821
|
-
node.end +
|
|
6822
|
-
findFirstOccurrenceOutsideComment(code.original.slice(node.end, nextNode.start), ',');
|
|
6823
|
-
}
|
|
6824
|
-
nextNodeStart = contentEnd =
|
|
6825
|
-
separator +
|
|
6826
|
-
1 +
|
|
6827
|
-
findFirstLineBreakOutsideComment(code.original.slice(separator + 1, nextNode.start))[1];
|
|
6828
|
-
while (((char = code.original.charCodeAt(nextNodeStart)),
|
|
6829
|
-
char === 32 /*" "*/ || char === 9 /*"\t"*/ || char === 10 /*"\n"*/ || char === 13) /*"\r"*/)
|
|
6830
|
-
nextNodeStart++;
|
|
6831
|
-
if (node !== undefined) {
|
|
6832
|
-
splitUpNodes.push({
|
|
6833
|
-
contentEnd,
|
|
6834
|
-
end: nextNodeStart,
|
|
6835
|
-
node,
|
|
6836
|
-
separator,
|
|
6837
|
-
start
|
|
6838
|
-
});
|
|
6839
|
-
}
|
|
6840
|
-
node = nextNode;
|
|
6841
|
-
start = nextNodeStart;
|
|
6842
|
-
}
|
|
6843
|
-
splitUpNodes.push({
|
|
6844
|
-
contentEnd: end,
|
|
6845
|
-
end,
|
|
6846
|
-
node: node,
|
|
6847
|
-
separator: null,
|
|
6848
|
-
start
|
|
6849
|
-
});
|
|
6850
|
-
return splitUpNodes;
|
|
6851
|
-
}
|
|
6852
|
-
// This assumes there are only white-space and comments between start and end
|
|
6853
|
-
function removeLineBreaks(code, start, end) {
|
|
6854
|
-
while (true) {
|
|
6855
|
-
const [removeStart, removeEnd] = findFirstLineBreakOutsideComment(code.original.slice(start, end));
|
|
6856
|
-
if (removeStart === -1) {
|
|
6857
|
-
break;
|
|
6858
|
-
}
|
|
6859
|
-
code.remove(start + removeStart, (start += removeEnd));
|
|
6860
|
-
}
|
|
6861
|
-
}
|
|
6862
|
-
|
|
6863
|
-
class BlockScope extends ChildScope {
|
|
6864
|
-
addDeclaration(identifier, context, init, isHoisted) {
|
|
6865
|
-
if (isHoisted) {
|
|
6866
|
-
const variable = this.parent.addDeclaration(identifier, context, init, isHoisted);
|
|
6867
|
-
// Necessary to make sure the init is deoptimized for conditional declarations.
|
|
6868
|
-
// We cannot call deoptimizePath here.
|
|
6869
|
-
variable.markInitializersForDeoptimization();
|
|
6870
|
-
return variable;
|
|
6871
|
-
}
|
|
6872
|
-
else {
|
|
6873
|
-
return super.addDeclaration(identifier, context, init, false);
|
|
6874
|
-
}
|
|
6875
|
-
}
|
|
6876
|
-
}
|
|
6877
|
-
|
|
6878
|
-
class ExpressionStatement extends NodeBase {
|
|
6879
|
-
initialise() {
|
|
6880
|
-
if (this.directive &&
|
|
6881
|
-
this.directive !== 'use strict' &&
|
|
6882
|
-
this.parent.type === Program$1) {
|
|
6883
|
-
this.context.warn(
|
|
6884
|
-
// This is necessary, because either way (deleting or not) can lead to errors.
|
|
6885
|
-
{
|
|
6886
|
-
code: 'MODULE_LEVEL_DIRECTIVE',
|
|
6887
|
-
message: `Module level directives cause errors when bundled, '${this.directive}' was ignored.`
|
|
6888
|
-
}, this.start);
|
|
6889
|
-
}
|
|
6890
|
-
}
|
|
6891
|
-
render(code, options) {
|
|
6892
|
-
super.render(code, options);
|
|
6893
|
-
if (this.included)
|
|
6894
|
-
this.insertSemicolon(code);
|
|
6895
|
-
}
|
|
6896
|
-
shouldBeIncluded(context) {
|
|
6897
|
-
if (this.directive && this.directive !== 'use strict')
|
|
6898
|
-
return this.parent.type !== Program$1;
|
|
6899
|
-
return super.shouldBeIncluded(context);
|
|
6900
|
-
}
|
|
6901
|
-
}
|
|
6902
|
-
|
|
6903
|
-
class BlockStatement extends NodeBase {
|
|
6904
|
-
constructor() {
|
|
6905
|
-
super(...arguments);
|
|
6906
|
-
this.directlyIncluded = false;
|
|
6907
|
-
}
|
|
6908
|
-
addImplicitReturnExpressionToScope() {
|
|
6909
|
-
const lastStatement = this.body[this.body.length - 1];
|
|
6910
|
-
if (!lastStatement || lastStatement.type !== ReturnStatement$1) {
|
|
6911
|
-
this.scope.addReturnExpression(UNKNOWN_EXPRESSION);
|
|
6912
|
-
}
|
|
6913
|
-
}
|
|
6914
|
-
createScope(parentScope) {
|
|
6915
|
-
this.scope = this.parent.preventChildBlockScope
|
|
6916
|
-
? parentScope
|
|
6917
|
-
: new BlockScope(parentScope);
|
|
6918
|
-
}
|
|
6919
|
-
hasEffects(context) {
|
|
6920
|
-
if (this.deoptimizeBody)
|
|
6921
|
-
return true;
|
|
6922
|
-
for (const node of this.body) {
|
|
6923
|
-
if (context.brokenFlow)
|
|
6924
|
-
break;
|
|
6925
|
-
if (node.hasEffects(context))
|
|
6926
|
-
return true;
|
|
6927
|
-
}
|
|
6928
|
-
return false;
|
|
6929
|
-
}
|
|
6930
|
-
include(context, includeChildrenRecursively) {
|
|
6931
|
-
if (!(this.deoptimizeBody && this.directlyIncluded)) {
|
|
6932
|
-
this.included = true;
|
|
6933
|
-
this.directlyIncluded = true;
|
|
6934
|
-
if (this.deoptimizeBody)
|
|
6935
|
-
includeChildrenRecursively = true;
|
|
6936
|
-
for (const node of this.body) {
|
|
6937
|
-
if (includeChildrenRecursively || node.shouldBeIncluded(context))
|
|
6938
|
-
node.include(context, includeChildrenRecursively);
|
|
6939
|
-
}
|
|
6940
|
-
}
|
|
6941
|
-
}
|
|
6942
|
-
initialise() {
|
|
6943
|
-
const firstBodyStatement = this.body[0];
|
|
6944
|
-
this.deoptimizeBody =
|
|
6945
|
-
firstBodyStatement instanceof ExpressionStatement &&
|
|
6946
|
-
firstBodyStatement.directive === 'use asm';
|
|
6947
|
-
}
|
|
6948
|
-
render(code, options) {
|
|
6949
|
-
if (this.body.length) {
|
|
6950
|
-
renderStatementList(this.body, code, this.start + 1, this.end - 1, options);
|
|
6951
|
-
}
|
|
6952
|
-
else {
|
|
6953
|
-
super.render(code, options);
|
|
6954
|
-
}
|
|
6955
|
-
}
|
|
6956
|
-
}
|
|
6957
|
-
|
|
6958
|
-
class RestElement extends NodeBase {
|
|
6959
|
-
constructor() {
|
|
6960
|
-
super(...arguments);
|
|
6961
|
-
this.deoptimized = false;
|
|
6962
|
-
this.declarationInit = null;
|
|
6963
|
-
}
|
|
6964
|
-
addExportedVariables(variables, exportNamesByVariable) {
|
|
6965
|
-
this.argument.addExportedVariables(variables, exportNamesByVariable);
|
|
6966
|
-
}
|
|
6967
|
-
declare(kind, init) {
|
|
6968
|
-
this.declarationInit = init;
|
|
6969
|
-
return this.argument.declare(kind, UNKNOWN_EXPRESSION);
|
|
6970
|
-
}
|
|
6971
|
-
deoptimizePath(path) {
|
|
6972
|
-
path.length === 0 && this.argument.deoptimizePath(EMPTY_PATH);
|
|
6973
|
-
}
|
|
6974
|
-
hasEffectsWhenAssignedAtPath(path, context) {
|
|
6975
|
-
return path.length > 0 || this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
|
|
6976
|
-
}
|
|
6977
|
-
markDeclarationReached() {
|
|
6978
|
-
this.argument.markDeclarationReached();
|
|
6979
|
-
}
|
|
6980
|
-
applyDeoptimizations() {
|
|
6981
|
-
this.deoptimized = true;
|
|
6982
|
-
if (this.declarationInit !== null) {
|
|
6983
|
-
this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
|
|
6984
|
-
this.context.requestTreeshakingPass();
|
|
6985
|
-
}
|
|
6986
|
-
}
|
|
6987
|
-
}
|
|
6988
|
-
|
|
6989
|
-
class FunctionBase extends NodeBase {
|
|
6990
|
-
constructor() {
|
|
6991
|
-
super(...arguments);
|
|
6992
|
-
// By default, parameters are included via includeArgumentsWhenCalledAtPath
|
|
6993
|
-
this.alwaysIncludeParameters = false;
|
|
6994
|
-
this.objectEntity = null;
|
|
6995
|
-
this.deoptimizedReturn = false;
|
|
6996
|
-
}
|
|
6997
|
-
deoptimizeCache() {
|
|
6998
|
-
this.alwaysIncludeParameters = true;
|
|
6999
|
-
}
|
|
7000
|
-
deoptimizePath(path) {
|
|
7001
|
-
this.getObjectEntity().deoptimizePath(path);
|
|
7002
|
-
if (path.length === 1 && path[0] === UnknownKey) {
|
|
7003
|
-
// A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
|
|
7004
|
-
// which means the return expression needs to be reassigned
|
|
7005
|
-
this.alwaysIncludeParameters = true;
|
|
7006
|
-
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
7007
|
-
}
|
|
7008
|
-
}
|
|
7009
|
-
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
7010
|
-
if (path.length > 0) {
|
|
7011
|
-
this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
7012
|
-
}
|
|
7013
|
-
}
|
|
7014
|
-
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
7015
|
-
return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
|
|
7016
|
-
}
|
|
7017
|
-
getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
|
|
7018
|
-
if (path.length > 0) {
|
|
7019
|
-
return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
|
|
7020
|
-
}
|
|
7021
|
-
if (this.async) {
|
|
7022
|
-
if (!this.deoptimizedReturn) {
|
|
7023
|
-
this.deoptimizedReturn = true;
|
|
7024
|
-
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
7025
|
-
this.context.requestTreeshakingPass();
|
|
7026
|
-
}
|
|
7027
|
-
return UNKNOWN_EXPRESSION;
|
|
7028
|
-
}
|
|
7029
|
-
return this.scope.getReturnExpression();
|
|
7030
|
-
}
|
|
7031
|
-
hasEffectsWhenAccessedAtPath(path, context) {
|
|
7032
|
-
return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
|
|
7033
|
-
}
|
|
7034
|
-
hasEffectsWhenAssignedAtPath(path, context) {
|
|
7035
|
-
return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
|
|
7036
|
-
}
|
|
7037
|
-
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
7038
|
-
if (path.length > 0) {
|
|
7039
|
-
return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
7040
|
-
}
|
|
7041
|
-
if (this.async) {
|
|
7042
|
-
const { propertyReadSideEffects } = this.context.options
|
|
7043
|
-
.treeshake;
|
|
7044
|
-
const returnExpression = this.scope.getReturnExpression();
|
|
7045
|
-
if (returnExpression.hasEffectsWhenCalledAtPath(['then'], { args: NO_ARGS, thisParam: null, withNew: false }, context) ||
|
|
7046
|
-
(propertyReadSideEffects &&
|
|
7047
|
-
(propertyReadSideEffects === 'always' ||
|
|
7048
|
-
returnExpression.hasEffectsWhenAccessedAtPath(['then'], context)))) {
|
|
7049
|
-
return true;
|
|
7050
|
-
}
|
|
7051
|
-
}
|
|
7052
|
-
for (const param of this.params) {
|
|
7053
|
-
if (param.hasEffects(context))
|
|
7054
|
-
return true;
|
|
7055
|
-
}
|
|
7056
|
-
return false;
|
|
7057
|
-
}
|
|
7058
|
-
include(context, includeChildrenRecursively) {
|
|
7059
|
-
this.included = true;
|
|
7060
|
-
const { brokenFlow } = context;
|
|
7061
|
-
context.brokenFlow = BROKEN_FLOW_NONE;
|
|
7062
|
-
this.body.include(context, includeChildrenRecursively);
|
|
7063
|
-
context.brokenFlow = brokenFlow;
|
|
7064
|
-
if (includeChildrenRecursively || this.alwaysIncludeParameters) {
|
|
7065
|
-
for (const param of this.params) {
|
|
7066
|
-
param.include(context, includeChildrenRecursively);
|
|
7067
|
-
}
|
|
7068
|
-
}
|
|
7069
|
-
}
|
|
7070
|
-
includeArgumentsWhenCalledAtPath(path, context, args) {
|
|
7071
|
-
var _a;
|
|
7072
|
-
if (path.length === 0) {
|
|
7073
|
-
for (let position = 0; position < this.params.length; position++) {
|
|
7074
|
-
const parameter = this.params[position];
|
|
7075
|
-
if (parameter instanceof AssignmentPattern) {
|
|
7076
|
-
if (parameter.left.shouldBeIncluded(context)) {
|
|
7077
|
-
parameter.left.include(context, false);
|
|
7078
|
-
}
|
|
7079
|
-
const argumentValue = (_a = args[position]) === null || _a === void 0 ? void 0 : _a.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
|
|
7080
|
-
// If argumentValue === UnknownTruthyValue, then we do not need to
|
|
7081
|
-
// include the default
|
|
7082
|
-
if ((argumentValue === undefined || argumentValue === UnknownValue) &&
|
|
7083
|
-
(this.parameterVariables[position].some(variable => variable.included) ||
|
|
7084
|
-
parameter.right.shouldBeIncluded(context))) {
|
|
7085
|
-
parameter.right.include(context, false);
|
|
7086
|
-
}
|
|
7087
|
-
}
|
|
7088
|
-
else if (parameter.shouldBeIncluded(context)) {
|
|
7089
|
-
parameter.include(context, false);
|
|
7090
|
-
}
|
|
7091
|
-
}
|
|
7092
|
-
this.scope.includeCallArguments(context, args);
|
|
7093
|
-
}
|
|
7094
|
-
else {
|
|
7095
|
-
this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
|
|
7096
|
-
}
|
|
7097
|
-
}
|
|
7098
|
-
initialise() {
|
|
7099
|
-
this.parameterVariables = this.params.map(param => param.declare('parameter', UNKNOWN_EXPRESSION));
|
|
7100
|
-
this.scope.addParameterVariables(this.parameterVariables, this.params[this.params.length - 1] instanceof RestElement);
|
|
7101
|
-
if (this.body instanceof BlockStatement) {
|
|
7102
|
-
this.body.addImplicitReturnExpressionToScope();
|
|
7103
|
-
}
|
|
7104
|
-
else {
|
|
7105
|
-
this.scope.addReturnExpression(this.body);
|
|
7106
|
-
}
|
|
7107
|
-
}
|
|
7108
|
-
parseNode(esTreeNode) {
|
|
7109
|
-
if (esTreeNode.body.type === BlockStatement$1) {
|
|
7110
|
-
this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
|
|
7111
|
-
}
|
|
7112
|
-
super.parseNode(esTreeNode);
|
|
7113
|
-
}
|
|
7114
|
-
}
|
|
7115
|
-
FunctionBase.prototype.preventChildBlockScope = true;
|
|
7116
|
-
|
|
7117
|
-
class ArrowFunctionExpression extends FunctionBase {
|
|
7118
|
-
constructor() {
|
|
7119
|
-
super(...arguments);
|
|
7120
|
-
this.objectEntity = null;
|
|
7121
|
-
}
|
|
7122
|
-
createScope(parentScope) {
|
|
7123
|
-
this.scope = new ReturnValueScope(parentScope, this.context);
|
|
7124
|
-
}
|
|
7125
|
-
hasEffects() {
|
|
7126
|
-
return false;
|
|
7127
|
-
}
|
|
7128
|
-
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
7129
|
-
if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
|
|
7130
|
-
return true;
|
|
7131
|
-
const { ignore, brokenFlow } = context;
|
|
7132
|
-
context.ignore = {
|
|
7133
|
-
breaks: false,
|
|
7134
|
-
continues: false,
|
|
7135
|
-
labels: new Set(),
|
|
7136
|
-
returnYield: true
|
|
7137
|
-
};
|
|
7138
|
-
if (this.body.hasEffects(context))
|
|
7139
|
-
return true;
|
|
7140
|
-
context.ignore = ignore;
|
|
7141
|
-
context.brokenFlow = brokenFlow;
|
|
7142
|
-
return false;
|
|
7143
|
-
}
|
|
7144
|
-
getObjectEntity() {
|
|
7145
|
-
if (this.objectEntity !== null) {
|
|
7146
|
-
return this.objectEntity;
|
|
7147
|
-
}
|
|
7148
|
-
return (this.objectEntity = new ObjectEntity([], OBJECT_PROTOTYPE));
|
|
7149
|
-
}
|
|
7150
|
-
}
|
|
7151
|
-
|
|
7152
|
-
function getSystemExportStatement(exportedVariables, { exportNamesByVariable, snippets: { _, getObject, getPropertyAccess } }, modifier = '') {
|
|
7153
|
-
if (exportedVariables.length === 1 &&
|
|
7154
|
-
exportNamesByVariable.get(exportedVariables[0]).length === 1) {
|
|
7155
|
-
const variable = exportedVariables[0];
|
|
7156
|
-
return `exports('${exportNamesByVariable.get(variable)}',${_}${variable.getName(getPropertyAccess)}${modifier})`;
|
|
7157
|
-
}
|
|
7158
|
-
else {
|
|
7159
|
-
const fields = [];
|
|
7160
|
-
for (const variable of exportedVariables) {
|
|
7161
|
-
for (const exportName of exportNamesByVariable.get(variable)) {
|
|
7162
|
-
fields.push([exportName, variable.getName(getPropertyAccess) + modifier]);
|
|
7163
|
-
}
|
|
7164
|
-
}
|
|
7165
|
-
return `exports(${getObject(fields, { lineBreakIndent: null })})`;
|
|
7166
|
-
}
|
|
7167
|
-
}
|
|
7168
|
-
function renderSystemExportExpression(exportedVariable, expressionStart, expressionEnd, code, { exportNamesByVariable, snippets: { _ } }) {
|
|
7169
|
-
code.prependRight(expressionStart, `exports('${exportNamesByVariable.get(exportedVariable)}',${_}`);
|
|
7170
|
-
code.appendLeft(expressionEnd, ')');
|
|
7171
|
-
}
|
|
7172
|
-
function renderSystemExportFunction(exportedVariables, expressionStart, expressionEnd, needsParens, code, options) {
|
|
7173
|
-
const { _, getDirectReturnIifeLeft } = options.snippets;
|
|
7174
|
-
code.prependRight(expressionStart, getDirectReturnIifeLeft(['v'], `${getSystemExportStatement(exportedVariables, options)},${_}v`, { needsArrowReturnParens: true, needsWrappedFunction: needsParens }));
|
|
7175
|
-
code.appendLeft(expressionEnd, ')');
|
|
7176
|
-
}
|
|
7177
|
-
function renderSystemExportSequenceAfterExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options) {
|
|
7178
|
-
const { _, getPropertyAccess } = options.snippets;
|
|
7179
|
-
code.appendLeft(expressionEnd, `,${_}${getSystemExportStatement([exportedVariable], options)},${_}${exportedVariable.getName(getPropertyAccess)}`);
|
|
7180
|
-
if (needsParens) {
|
|
7181
|
-
code.prependRight(expressionStart, '(');
|
|
7182
|
-
code.appendLeft(expressionEnd, ')');
|
|
7183
|
-
}
|
|
7184
|
-
}
|
|
7185
|
-
function renderSystemExportSequenceBeforeExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options, modifier) {
|
|
7186
|
-
const { _ } = options.snippets;
|
|
7187
|
-
code.prependRight(expressionStart, `${getSystemExportStatement([exportedVariable], options, modifier)},${_}`);
|
|
7188
|
-
if (needsParens) {
|
|
7189
|
-
code.prependRight(expressionStart, '(');
|
|
7190
|
-
code.appendLeft(expressionEnd, ')');
|
|
7191
|
-
}
|
|
7192
|
-
}
|
|
7193
|
-
|
|
7194
|
-
//@ts-check
|
|
7195
|
-
/** @typedef { import('estree').Node} Node */
|
|
7196
|
-
/** @typedef {Node | {
|
|
7197
|
-
* type: 'PropertyDefinition';
|
|
7198
|
-
* computed: boolean;
|
|
7199
|
-
* value: Node
|
|
7200
|
-
* }} NodeWithPropertyDefinition */
|
|
7201
|
-
|
|
7202
|
-
/**
|
|
7203
|
-
*
|
|
7204
|
-
* @param {NodeWithPropertyDefinition} node
|
|
7205
|
-
* @param {NodeWithPropertyDefinition} parent
|
|
7206
|
-
* @returns boolean
|
|
7207
|
-
*/
|
|
7208
|
-
function is_reference (node, parent) {
|
|
7209
|
-
if (node.type === 'MemberExpression') {
|
|
7210
|
-
return !node.computed && is_reference(node.object, node);
|
|
7211
|
-
}
|
|
7212
|
-
|
|
7213
|
-
if (node.type === 'Identifier') {
|
|
7214
|
-
if (!parent) return true;
|
|
7215
|
-
|
|
7216
|
-
switch (parent.type) {
|
|
7217
|
-
// disregard `bar` in `foo.bar`
|
|
7218
|
-
case 'MemberExpression': return parent.computed || node === parent.object;
|
|
7219
|
-
|
|
7220
|
-
// disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
|
|
7221
|
-
case 'MethodDefinition': return parent.computed;
|
|
7222
|
-
|
|
7223
|
-
// disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
|
|
7224
|
-
case 'PropertyDefinition': return parent.computed || node === parent.value;
|
|
7225
|
-
|
|
7226
|
-
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
|
|
7227
|
-
case 'Property': return parent.computed || node === parent.value;
|
|
7228
|
-
|
|
7229
|
-
// disregard the `bar` in `export { foo as bar }` or
|
|
7230
|
-
// the foo in `import { foo as bar }`
|
|
7231
|
-
case 'ExportSpecifier':
|
|
7232
|
-
case 'ImportSpecifier': return node === parent.local;
|
|
7233
|
-
|
|
7234
|
-
// disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
|
|
7235
|
-
case 'LabeledStatement':
|
|
7236
|
-
case 'BreakStatement':
|
|
7237
|
-
case 'ContinueStatement': return false;
|
|
7238
|
-
default: return true;
|
|
7239
|
-
}
|
|
7240
|
-
}
|
|
7241
|
-
|
|
7242
|
-
return false;
|
|
7243
|
-
}
|
|
7244
|
-
|
|
7245
|
-
/* eslint sort-keys: "off" */
|
|
7246
|
-
const ValueProperties = Symbol('Value Properties');
|
|
7247
|
-
const PURE = {
|
|
7248
|
-
hasEffectsWhenCalled() {
|
|
7249
|
-
return false;
|
|
7250
|
-
}
|
|
7251
|
-
};
|
|
7252
|
-
const IMPURE = {
|
|
7253
|
-
hasEffectsWhenCalled() {
|
|
7254
|
-
return true;
|
|
7255
|
-
}
|
|
7256
|
-
};
|
|
7257
|
-
// We use shortened variables to reduce file size here
|
|
7258
|
-
/* OBJECT */
|
|
7259
|
-
const O = {
|
|
7260
|
-
__proto__: null,
|
|
7261
|
-
[ValueProperties]: IMPURE
|
|
7262
|
-
};
|
|
7263
|
-
/* PURE FUNCTION */
|
|
7264
|
-
const PF = {
|
|
7265
|
-
__proto__: null,
|
|
7266
|
-
[ValueProperties]: PURE
|
|
7267
|
-
};
|
|
7268
|
-
/* FUNCTION THAT MUTATES FIRST ARG WITHOUT TRIGGERING ACCESSORS */
|
|
7269
|
-
const MUTATES_ARG_WITHOUT_ACCESSOR = {
|
|
7270
|
-
__proto__: null,
|
|
7271
|
-
[ValueProperties]: {
|
|
7272
|
-
hasEffectsWhenCalled(callOptions, context) {
|
|
7273
|
-
return (!callOptions.args.length ||
|
|
7274
|
-
callOptions.args[0].hasEffectsWhenAssignedAtPath(UNKNOWN_NON_ACCESSOR_PATH, context));
|
|
7275
|
-
}
|
|
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));
|
|
6706
|
+
}
|
|
7276
6707
|
}
|
|
7277
6708
|
};
|
|
7278
6709
|
/* CONSTRUCTOR */
|
|
@@ -8088,222 +7519,682 @@ const knownGlobals = {
|
|
|
8088
7519
|
for (const global of ['window', 'global', 'self', 'globalThis']) {
|
|
8089
7520
|
knownGlobals[global] = knownGlobals;
|
|
8090
7521
|
}
|
|
8091
|
-
function getGlobalAtPath(path) {
|
|
8092
|
-
let currentGlobal = knownGlobals;
|
|
8093
|
-
for (const pathSegment of path) {
|
|
8094
|
-
if (typeof pathSegment !== 'string') {
|
|
8095
|
-
return null;
|
|
7522
|
+
function getGlobalAtPath(path) {
|
|
7523
|
+
let currentGlobal = knownGlobals;
|
|
7524
|
+
for (const pathSegment of path) {
|
|
7525
|
+
if (typeof pathSegment !== 'string') {
|
|
7526
|
+
return null;
|
|
7527
|
+
}
|
|
7528
|
+
currentGlobal = currentGlobal[pathSegment];
|
|
7529
|
+
if (!currentGlobal) {
|
|
7530
|
+
return null;
|
|
7531
|
+
}
|
|
7532
|
+
}
|
|
7533
|
+
return currentGlobal[ValueProperties];
|
|
7534
|
+
}
|
|
7535
|
+
|
|
7536
|
+
class GlobalVariable extends Variable {
|
|
7537
|
+
constructor() {
|
|
7538
|
+
super(...arguments);
|
|
7539
|
+
// Ensure we use live-bindings for globals as we do not know if they have
|
|
7540
|
+
// been reassigned
|
|
7541
|
+
this.isReassigned = true;
|
|
7542
|
+
}
|
|
7543
|
+
hasEffectsWhenAccessedAtPath(path) {
|
|
7544
|
+
if (path.length === 0) {
|
|
7545
|
+
// Technically, "undefined" is a global variable of sorts
|
|
7546
|
+
return this.name !== 'undefined' && getGlobalAtPath([this.name]) === null;
|
|
7547
|
+
}
|
|
7548
|
+
return getGlobalAtPath([this.name, ...path].slice(0, -1)) === null;
|
|
7549
|
+
}
|
|
7550
|
+
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
7551
|
+
const globalAtPath = getGlobalAtPath([this.name, ...path]);
|
|
7552
|
+
return globalAtPath === null || globalAtPath.hasEffectsWhenCalled(callOptions, context);
|
|
7553
|
+
}
|
|
7554
|
+
}
|
|
7555
|
+
|
|
7556
|
+
const tdzVariableKinds = {
|
|
7557
|
+
__proto__: null,
|
|
7558
|
+
class: true,
|
|
7559
|
+
const: true,
|
|
7560
|
+
let: true,
|
|
7561
|
+
var: true
|
|
7562
|
+
};
|
|
7563
|
+
class Identifier extends NodeBase {
|
|
7564
|
+
constructor() {
|
|
7565
|
+
super(...arguments);
|
|
7566
|
+
this.variable = null;
|
|
7567
|
+
this.deoptimized = false;
|
|
7568
|
+
this.isTDZAccess = null;
|
|
7569
|
+
}
|
|
7570
|
+
addExportedVariables(variables, exportNamesByVariable) {
|
|
7571
|
+
if (this.variable !== null && exportNamesByVariable.has(this.variable)) {
|
|
7572
|
+
variables.push(this.variable);
|
|
7573
|
+
}
|
|
7574
|
+
}
|
|
7575
|
+
bind() {
|
|
7576
|
+
if (this.variable === null && is_reference(this, this.parent)) {
|
|
7577
|
+
this.variable = this.scope.findVariable(this.name);
|
|
7578
|
+
this.variable.addReference(this);
|
|
7579
|
+
}
|
|
7580
|
+
}
|
|
7581
|
+
declare(kind, init) {
|
|
7582
|
+
let variable;
|
|
7583
|
+
const { treeshake } = this.context.options;
|
|
7584
|
+
switch (kind) {
|
|
7585
|
+
case 'var':
|
|
7586
|
+
variable = this.scope.addDeclaration(this, this.context, init, true);
|
|
7587
|
+
if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
|
|
7588
|
+
// Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
|
|
7589
|
+
variable.markInitializersForDeoptimization();
|
|
7590
|
+
}
|
|
7591
|
+
break;
|
|
7592
|
+
case 'function':
|
|
7593
|
+
// in strict mode, functions are only hoisted within a scope but not across block scopes
|
|
7594
|
+
variable = this.scope.addDeclaration(this, this.context, init, false);
|
|
7595
|
+
break;
|
|
7596
|
+
case 'let':
|
|
7597
|
+
case 'const':
|
|
7598
|
+
case 'class':
|
|
7599
|
+
variable = this.scope.addDeclaration(this, this.context, init, false);
|
|
7600
|
+
break;
|
|
7601
|
+
case 'parameter':
|
|
7602
|
+
variable = this.scope.addParameterDeclaration(this);
|
|
7603
|
+
break;
|
|
7604
|
+
/* istanbul ignore next */
|
|
7605
|
+
default:
|
|
7606
|
+
/* istanbul ignore next */
|
|
7607
|
+
throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
|
|
7608
|
+
}
|
|
7609
|
+
variable.kind = kind;
|
|
7610
|
+
return [(this.variable = variable)];
|
|
7611
|
+
}
|
|
7612
|
+
deoptimizePath(path) {
|
|
7613
|
+
if (path.length === 0 && !this.scope.contains(this.name)) {
|
|
7614
|
+
this.disallowImportReassignment();
|
|
7615
|
+
}
|
|
7616
|
+
this.variable.deoptimizePath(path);
|
|
7617
|
+
}
|
|
7618
|
+
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
7619
|
+
this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
7620
|
+
}
|
|
7621
|
+
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
7622
|
+
return this.getVariableRespectingTDZ().getLiteralValueAtPath(path, recursionTracker, origin);
|
|
7623
|
+
}
|
|
7624
|
+
getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
|
|
7625
|
+
return this.getVariableRespectingTDZ().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
|
|
7626
|
+
}
|
|
7627
|
+
hasEffects() {
|
|
7628
|
+
if (!this.deoptimized)
|
|
7629
|
+
this.applyDeoptimizations();
|
|
7630
|
+
if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
|
|
7631
|
+
return true;
|
|
7632
|
+
}
|
|
7633
|
+
return (this.context.options.treeshake.unknownGlobalSideEffects &&
|
|
7634
|
+
this.variable instanceof GlobalVariable &&
|
|
7635
|
+
this.variable.hasEffectsWhenAccessedAtPath(EMPTY_PATH));
|
|
7636
|
+
}
|
|
7637
|
+
hasEffectsWhenAccessedAtPath(path, context) {
|
|
7638
|
+
return (this.variable !== null &&
|
|
7639
|
+
this.getVariableRespectingTDZ().hasEffectsWhenAccessedAtPath(path, context));
|
|
7640
|
+
}
|
|
7641
|
+
hasEffectsWhenAssignedAtPath(path, context) {
|
|
7642
|
+
return (!this.variable ||
|
|
7643
|
+
(path.length > 0
|
|
7644
|
+
? this.getVariableRespectingTDZ()
|
|
7645
|
+
: this.variable).hasEffectsWhenAssignedAtPath(path, context));
|
|
7646
|
+
}
|
|
7647
|
+
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
7648
|
+
return (!this.variable ||
|
|
7649
|
+
this.getVariableRespectingTDZ().hasEffectsWhenCalledAtPath(path, callOptions, context));
|
|
7650
|
+
}
|
|
7651
|
+
include() {
|
|
7652
|
+
if (!this.deoptimized)
|
|
7653
|
+
this.applyDeoptimizations();
|
|
7654
|
+
if (!this.included) {
|
|
7655
|
+
this.included = true;
|
|
7656
|
+
if (this.variable !== null) {
|
|
7657
|
+
this.context.includeVariableInModule(this.variable);
|
|
7658
|
+
}
|
|
7659
|
+
}
|
|
7660
|
+
}
|
|
7661
|
+
includeCallArguments(context, args) {
|
|
7662
|
+
this.getVariableRespectingTDZ().includeCallArguments(context, args);
|
|
7663
|
+
}
|
|
7664
|
+
isPossibleTDZ() {
|
|
7665
|
+
// return cached value to avoid issues with the next tree-shaking pass
|
|
7666
|
+
if (this.isTDZAccess !== null)
|
|
7667
|
+
return this.isTDZAccess;
|
|
7668
|
+
if (!(this.variable instanceof LocalVariable) ||
|
|
7669
|
+
!this.variable.kind ||
|
|
7670
|
+
!(this.variable.kind in tdzVariableKinds)) {
|
|
7671
|
+
return (this.isTDZAccess = false);
|
|
7672
|
+
}
|
|
7673
|
+
let decl_id;
|
|
7674
|
+
if (this.variable.declarations &&
|
|
7675
|
+
this.variable.declarations.length === 1 &&
|
|
7676
|
+
(decl_id = this.variable.declarations[0]) &&
|
|
7677
|
+
this.start < decl_id.start &&
|
|
7678
|
+
closestParentFunctionOrProgram(this) === closestParentFunctionOrProgram(decl_id)) {
|
|
7679
|
+
// a variable accessed before its declaration
|
|
7680
|
+
// in the same function or at top level of module
|
|
7681
|
+
return (this.isTDZAccess = true);
|
|
7682
|
+
}
|
|
7683
|
+
if (!this.variable.initReached) {
|
|
7684
|
+
// Either a const/let TDZ violation or
|
|
7685
|
+
// var use before declaration was encountered.
|
|
7686
|
+
return (this.isTDZAccess = true);
|
|
7687
|
+
}
|
|
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);
|
|
8096
7808
|
}
|
|
8097
|
-
|
|
8098
|
-
|
|
8099
|
-
|
|
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);
|
|
8100
7844
|
}
|
|
8101
7845
|
}
|
|
8102
|
-
|
|
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
|
+
}
|
|
8103
7896
|
}
|
|
8104
7897
|
|
|
8105
|
-
class
|
|
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 {
|
|
8106
7939
|
constructor() {
|
|
8107
7940
|
super(...arguments);
|
|
8108
|
-
|
|
8109
|
-
|
|
8110
|
-
|
|
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
|
+
}
|
|
8111
7948
|
}
|
|
8112
|
-
|
|
8113
|
-
|
|
7949
|
+
createScope(parentScope) {
|
|
7950
|
+
this.scope = this.parent.preventChildBlockScope
|
|
7951
|
+
? parentScope
|
|
7952
|
+
: new BlockScope(parentScope);
|
|
8114
7953
|
}
|
|
8115
|
-
|
|
8116
|
-
if (
|
|
8117
|
-
|
|
8118
|
-
|
|
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;
|
|
8119
7962
|
}
|
|
8120
|
-
return
|
|
7963
|
+
return false;
|
|
8121
7964
|
}
|
|
8122
|
-
|
|
8123
|
-
|
|
8124
|
-
|
|
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
|
+
}
|
|
7975
|
+
}
|
|
7976
|
+
}
|
|
7977
|
+
initialise() {
|
|
7978
|
+
const firstBodyStatement = this.body[0];
|
|
7979
|
+
this.deoptimizeBody =
|
|
7980
|
+
firstBodyStatement instanceof ExpressionStatement &&
|
|
7981
|
+
firstBodyStatement.directive === 'use asm';
|
|
7982
|
+
}
|
|
7983
|
+
render(code, options) {
|
|
7984
|
+
if (this.body.length) {
|
|
7985
|
+
renderStatementList(this.body, code, this.start + 1, this.end - 1, options);
|
|
7986
|
+
}
|
|
7987
|
+
else {
|
|
7988
|
+
super.render(code, options);
|
|
7989
|
+
}
|
|
8125
7990
|
}
|
|
8126
7991
|
}
|
|
8127
7992
|
|
|
8128
|
-
|
|
8129
|
-
__proto__: null,
|
|
8130
|
-
class: true,
|
|
8131
|
-
const: true,
|
|
8132
|
-
let: true,
|
|
8133
|
-
var: true
|
|
8134
|
-
};
|
|
8135
|
-
class Identifier extends NodeBase {
|
|
7993
|
+
class RestElement extends NodeBase {
|
|
8136
7994
|
constructor() {
|
|
8137
7995
|
super(...arguments);
|
|
8138
|
-
this.variable = null;
|
|
8139
7996
|
this.deoptimized = false;
|
|
8140
|
-
this.
|
|
7997
|
+
this.declarationInit = null;
|
|
8141
7998
|
}
|
|
8142
7999
|
addExportedVariables(variables, exportNamesByVariable) {
|
|
8143
|
-
|
|
8144
|
-
variables.push(this.variable);
|
|
8145
|
-
}
|
|
8000
|
+
this.argument.addExportedVariables(variables, exportNamesByVariable);
|
|
8146
8001
|
}
|
|
8147
|
-
|
|
8148
|
-
|
|
8149
|
-
|
|
8150
|
-
|
|
8002
|
+
declare(kind, init) {
|
|
8003
|
+
this.declarationInit = init;
|
|
8004
|
+
return this.argument.declare(kind, UNKNOWN_EXPRESSION);
|
|
8005
|
+
}
|
|
8006
|
+
deoptimizePath(path) {
|
|
8007
|
+
path.length === 0 && this.argument.deoptimizePath(EMPTY_PATH);
|
|
8008
|
+
}
|
|
8009
|
+
hasEffectsWhenAssignedAtPath(path, context) {
|
|
8010
|
+
return path.length > 0 || this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
|
|
8011
|
+
}
|
|
8012
|
+
markDeclarationReached() {
|
|
8013
|
+
this.argument.markDeclarationReached();
|
|
8014
|
+
}
|
|
8015
|
+
applyDeoptimizations() {
|
|
8016
|
+
this.deoptimized = true;
|
|
8017
|
+
if (this.declarationInit !== null) {
|
|
8018
|
+
this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
|
|
8019
|
+
this.context.requestTreeshakingPass();
|
|
8151
8020
|
}
|
|
8152
8021
|
}
|
|
8153
|
-
|
|
8154
|
-
|
|
8155
|
-
|
|
8156
|
-
|
|
8157
|
-
|
|
8158
|
-
|
|
8159
|
-
|
|
8160
|
-
// Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
|
|
8161
|
-
variable.markInitializersForDeoptimization();
|
|
8162
|
-
}
|
|
8163
|
-
break;
|
|
8164
|
-
case 'function':
|
|
8165
|
-
// in strict mode, functions are only hoisted within a scope but not across block scopes
|
|
8166
|
-
variable = this.scope.addDeclaration(this, this.context, init, false);
|
|
8167
|
-
break;
|
|
8168
|
-
case 'let':
|
|
8169
|
-
case 'const':
|
|
8170
|
-
case 'class':
|
|
8171
|
-
variable = this.scope.addDeclaration(this, this.context, init, false);
|
|
8172
|
-
break;
|
|
8173
|
-
case 'parameter':
|
|
8174
|
-
variable = this.scope.addParameterDeclaration(this);
|
|
8175
|
-
break;
|
|
8176
|
-
/* istanbul ignore next */
|
|
8177
|
-
default:
|
|
8178
|
-
/* istanbul ignore next */
|
|
8179
|
-
throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
|
|
8180
|
-
}
|
|
8181
|
-
variable.kind = kind;
|
|
8182
|
-
return [(this.variable = variable)];
|
|
8022
|
+
}
|
|
8023
|
+
|
|
8024
|
+
class FunctionBase extends NodeBase {
|
|
8025
|
+
constructor() {
|
|
8026
|
+
super(...arguments);
|
|
8027
|
+
this.objectEntity = null;
|
|
8028
|
+
this.deoptimizedReturn = false;
|
|
8183
8029
|
}
|
|
8184
8030
|
deoptimizePath(path) {
|
|
8185
|
-
|
|
8186
|
-
|
|
8031
|
+
this.getObjectEntity().deoptimizePath(path);
|
|
8032
|
+
if (path.length === 1 && path[0] === UnknownKey) {
|
|
8033
|
+
// A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
|
|
8034
|
+
// which means the return expression needs to be reassigned
|
|
8035
|
+
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
8187
8036
|
}
|
|
8188
|
-
this.variable.deoptimizePath(path);
|
|
8189
8037
|
}
|
|
8190
8038
|
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
8191
|
-
|
|
8039
|
+
if (path.length > 0) {
|
|
8040
|
+
this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
8041
|
+
}
|
|
8192
8042
|
}
|
|
8193
8043
|
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
8194
|
-
return this.
|
|
8044
|
+
return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
|
|
8195
8045
|
}
|
|
8196
8046
|
getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
|
|
8197
|
-
|
|
8198
|
-
|
|
8199
|
-
hasEffects() {
|
|
8200
|
-
if (!this.deoptimized)
|
|
8201
|
-
this.applyDeoptimizations();
|
|
8202
|
-
if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
|
|
8203
|
-
return true;
|
|
8047
|
+
if (path.length > 0) {
|
|
8048
|
+
return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
|
|
8204
8049
|
}
|
|
8205
|
-
|
|
8206
|
-
this.
|
|
8207
|
-
|
|
8050
|
+
if (this.async) {
|
|
8051
|
+
if (!this.deoptimizedReturn) {
|
|
8052
|
+
this.deoptimizedReturn = true;
|
|
8053
|
+
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
8054
|
+
this.context.requestTreeshakingPass();
|
|
8055
|
+
}
|
|
8056
|
+
return UNKNOWN_EXPRESSION;
|
|
8057
|
+
}
|
|
8058
|
+
return this.scope.getReturnExpression();
|
|
8208
8059
|
}
|
|
8209
8060
|
hasEffectsWhenAccessedAtPath(path, context) {
|
|
8210
|
-
|
|
8211
|
-
return (_a = this.getVariableRespectingTDZ()) === null || _a === void 0 ? void 0 : _a.hasEffectsWhenAccessedAtPath(path, context);
|
|
8061
|
+
return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
|
|
8212
8062
|
}
|
|
8213
8063
|
hasEffectsWhenAssignedAtPath(path, context) {
|
|
8214
|
-
return
|
|
8064
|
+
return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
|
|
8215
8065
|
}
|
|
8216
8066
|
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
8217
|
-
|
|
8218
|
-
|
|
8219
|
-
|
|
8220
|
-
if (
|
|
8221
|
-
this.
|
|
8222
|
-
|
|
8223
|
-
|
|
8224
|
-
if (
|
|
8225
|
-
|
|
8067
|
+
if (path.length > 0) {
|
|
8068
|
+
return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
8069
|
+
}
|
|
8070
|
+
if (this.async) {
|
|
8071
|
+
const { propertyReadSideEffects } = this.context.options
|
|
8072
|
+
.treeshake;
|
|
8073
|
+
const returnExpression = this.scope.getReturnExpression();
|
|
8074
|
+
if (returnExpression.hasEffectsWhenCalledAtPath(['then'], { args: NO_ARGS, thisParam: null, withNew: false }, context) ||
|
|
8075
|
+
(propertyReadSideEffects &&
|
|
8076
|
+
(propertyReadSideEffects === 'always' ||
|
|
8077
|
+
returnExpression.hasEffectsWhenAccessedAtPath(['then'], context)))) {
|
|
8078
|
+
return true;
|
|
8226
8079
|
}
|
|
8227
8080
|
}
|
|
8081
|
+
for (const param of this.params) {
|
|
8082
|
+
if (param.hasEffects(context))
|
|
8083
|
+
return true;
|
|
8084
|
+
}
|
|
8085
|
+
return false;
|
|
8228
8086
|
}
|
|
8229
|
-
|
|
8230
|
-
this.
|
|
8087
|
+
include(context, includeChildrenRecursively) {
|
|
8088
|
+
this.included = true;
|
|
8089
|
+
const { brokenFlow } = context;
|
|
8090
|
+
context.brokenFlow = BROKEN_FLOW_NONE;
|
|
8091
|
+
this.body.include(context, includeChildrenRecursively);
|
|
8092
|
+
context.brokenFlow = brokenFlow;
|
|
8231
8093
|
}
|
|
8232
|
-
|
|
8233
|
-
|
|
8234
|
-
|
|
8235
|
-
|
|
8236
|
-
|
|
8237
|
-
|
|
8238
|
-
|
|
8239
|
-
return (this.isTDZAccess = false);
|
|
8094
|
+
includeCallArguments(context, args) {
|
|
8095
|
+
this.scope.includeCallArguments(context, args);
|
|
8096
|
+
}
|
|
8097
|
+
initialise() {
|
|
8098
|
+
this.scope.addParameterVariables(this.params.map(param => param.declare('parameter', UNKNOWN_EXPRESSION)), this.params[this.params.length - 1] instanceof RestElement);
|
|
8099
|
+
if (this.body instanceof BlockStatement) {
|
|
8100
|
+
this.body.addImplicitReturnExpressionToScope();
|
|
8240
8101
|
}
|
|
8241
|
-
|
|
8242
|
-
|
|
8243
|
-
this.variable.declarations.length === 1 &&
|
|
8244
|
-
(decl_id = this.variable.declarations[0]) &&
|
|
8245
|
-
this.start < decl_id.start &&
|
|
8246
|
-
closestParentFunctionOrProgram(this) === closestParentFunctionOrProgram(decl_id)) {
|
|
8247
|
-
// a variable accessed before its declaration
|
|
8248
|
-
// in the same function or at top level of module
|
|
8249
|
-
return (this.isTDZAccess = true);
|
|
8102
|
+
else {
|
|
8103
|
+
this.scope.addReturnExpression(this.body);
|
|
8250
8104
|
}
|
|
8251
|
-
|
|
8252
|
-
|
|
8253
|
-
|
|
8254
|
-
|
|
8105
|
+
}
|
|
8106
|
+
parseNode(esTreeNode) {
|
|
8107
|
+
if (esTreeNode.body.type === BlockStatement$1) {
|
|
8108
|
+
this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
|
|
8255
8109
|
}
|
|
8256
|
-
|
|
8110
|
+
super.parseNode(esTreeNode);
|
|
8257
8111
|
}
|
|
8258
|
-
|
|
8259
|
-
|
|
8112
|
+
}
|
|
8113
|
+
FunctionBase.prototype.preventChildBlockScope = true;
|
|
8114
|
+
|
|
8115
|
+
class ArrowFunctionExpression extends FunctionBase {
|
|
8116
|
+
constructor() {
|
|
8117
|
+
super(...arguments);
|
|
8118
|
+
this.objectEntity = null;
|
|
8260
8119
|
}
|
|
8261
|
-
|
|
8262
|
-
|
|
8263
|
-
|
|
8264
|
-
|
|
8265
|
-
|
|
8266
|
-
|
|
8267
|
-
|
|
8268
|
-
|
|
8269
|
-
|
|
8270
|
-
|
|
8271
|
-
|
|
8272
|
-
|
|
8273
|
-
|
|
8274
|
-
|
|
8275
|
-
|
|
8276
|
-
|
|
8277
|
-
|
|
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);
|
|
8278
8147
|
}
|
|
8279
8148
|
}
|
|
8280
8149
|
}
|
|
8281
|
-
|
|
8282
|
-
this.
|
|
8283
|
-
|
|
8284
|
-
this.variable.consolidateInitializers();
|
|
8285
|
-
this.context.requestTreeshakingPass();
|
|
8150
|
+
getObjectEntity() {
|
|
8151
|
+
if (this.objectEntity !== null) {
|
|
8152
|
+
return this.objectEntity;
|
|
8286
8153
|
}
|
|
8154
|
+
return (this.objectEntity = new ObjectEntity([], OBJECT_PROTOTYPE));
|
|
8287
8155
|
}
|
|
8288
|
-
|
|
8289
|
-
|
|
8290
|
-
|
|
8291
|
-
|
|
8292
|
-
|
|
8156
|
+
}
|
|
8157
|
+
|
|
8158
|
+
function getSystemExportStatement(exportedVariables, { exportNamesByVariable, snippets: { _, getObject, getPropertyAccess } }, modifier = '') {
|
|
8159
|
+
if (exportedVariables.length === 1 &&
|
|
8160
|
+
exportNamesByVariable.get(exportedVariables[0]).length === 1) {
|
|
8161
|
+
const variable = exportedVariables[0];
|
|
8162
|
+
return `exports('${exportNamesByVariable.get(variable)}',${_}${variable.getName(getPropertyAccess)}${modifier})`;
|
|
8293
8163
|
}
|
|
8294
|
-
|
|
8295
|
-
|
|
8296
|
-
|
|
8164
|
+
else {
|
|
8165
|
+
const fields = [];
|
|
8166
|
+
for (const variable of exportedVariables) {
|
|
8167
|
+
for (const exportName of exportNamesByVariable.get(variable)) {
|
|
8168
|
+
fields.push([exportName, variable.getName(getPropertyAccess) + modifier]);
|
|
8169
|
+
}
|
|
8297
8170
|
}
|
|
8298
|
-
return
|
|
8171
|
+
return `exports(${getObject(fields, { lineBreakIndent: null })})`;
|
|
8299
8172
|
}
|
|
8300
8173
|
}
|
|
8301
|
-
function
|
|
8302
|
-
|
|
8303
|
-
|
|
8174
|
+
function renderSystemExportExpression(exportedVariable, expressionStart, expressionEnd, code, { exportNamesByVariable, snippets: { _ } }) {
|
|
8175
|
+
code.prependRight(expressionStart, `exports('${exportNamesByVariable.get(exportedVariable)}',${_}`);
|
|
8176
|
+
code.appendLeft(expressionEnd, ')');
|
|
8177
|
+
}
|
|
8178
|
+
function renderSystemExportFunction(exportedVariables, expressionStart, expressionEnd, needsParens, code, options) {
|
|
8179
|
+
const { _, getDirectReturnIifeLeft } = options.snippets;
|
|
8180
|
+
code.prependRight(expressionStart, getDirectReturnIifeLeft(['v'], `${getSystemExportStatement(exportedVariables, options)},${_}v`, { needsArrowReturnParens: true, needsWrappedFunction: needsParens }));
|
|
8181
|
+
code.appendLeft(expressionEnd, ')');
|
|
8182
|
+
}
|
|
8183
|
+
function renderSystemExportSequenceAfterExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options) {
|
|
8184
|
+
const { _, getPropertyAccess } = options.snippets;
|
|
8185
|
+
code.appendLeft(expressionEnd, `,${_}${getSystemExportStatement([exportedVariable], options)},${_}${exportedVariable.getName(getPropertyAccess)}`);
|
|
8186
|
+
if (needsParens) {
|
|
8187
|
+
code.prependRight(expressionStart, '(');
|
|
8188
|
+
code.appendLeft(expressionEnd, ')');
|
|
8189
|
+
}
|
|
8190
|
+
}
|
|
8191
|
+
function renderSystemExportSequenceBeforeExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options, modifier) {
|
|
8192
|
+
const { _ } = options.snippets;
|
|
8193
|
+
code.prependRight(expressionStart, `${getSystemExportStatement([exportedVariable], options, modifier)},${_}`);
|
|
8194
|
+
if (needsParens) {
|
|
8195
|
+
code.prependRight(expressionStart, '(');
|
|
8196
|
+
code.appendLeft(expressionEnd, ')');
|
|
8304
8197
|
}
|
|
8305
|
-
// one of: ArrowFunctionExpression, FunctionDeclaration, FunctionExpression or Program
|
|
8306
|
-
return node;
|
|
8307
8198
|
}
|
|
8308
8199
|
|
|
8309
8200
|
class ObjectPattern extends NodeBase {
|
|
@@ -8432,6 +8323,38 @@ class AssignmentExpression extends NodeBase {
|
|
|
8432
8323
|
}
|
|
8433
8324
|
}
|
|
8434
8325
|
|
|
8326
|
+
class AssignmentPattern extends NodeBase {
|
|
8327
|
+
constructor() {
|
|
8328
|
+
super(...arguments);
|
|
8329
|
+
this.deoptimized = false;
|
|
8330
|
+
}
|
|
8331
|
+
addExportedVariables(variables, exportNamesByVariable) {
|
|
8332
|
+
this.left.addExportedVariables(variables, exportNamesByVariable);
|
|
8333
|
+
}
|
|
8334
|
+
declare(kind, init) {
|
|
8335
|
+
return this.left.declare(kind, init);
|
|
8336
|
+
}
|
|
8337
|
+
deoptimizePath(path) {
|
|
8338
|
+
path.length === 0 && this.left.deoptimizePath(path);
|
|
8339
|
+
}
|
|
8340
|
+
hasEffectsWhenAssignedAtPath(path, context) {
|
|
8341
|
+
return path.length > 0 || this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
|
|
8342
|
+
}
|
|
8343
|
+
markDeclarationReached() {
|
|
8344
|
+
this.left.markDeclarationReached();
|
|
8345
|
+
}
|
|
8346
|
+
render(code, options, { isShorthandProperty } = BLANK) {
|
|
8347
|
+
this.left.render(code, options, { isShorthandProperty });
|
|
8348
|
+
this.right.render(code, options);
|
|
8349
|
+
}
|
|
8350
|
+
applyDeoptimizations() {
|
|
8351
|
+
this.deoptimized = true;
|
|
8352
|
+
this.left.deoptimizePath(EMPTY_PATH);
|
|
8353
|
+
this.right.deoptimizePath(UNKNOWN_PATH);
|
|
8354
|
+
this.context.requestTreeshakingPass();
|
|
8355
|
+
}
|
|
8356
|
+
}
|
|
8357
|
+
|
|
8435
8358
|
class ArgumentsVariable extends LocalVariable {
|
|
8436
8359
|
constructor(context) {
|
|
8437
8360
|
super('arguments', null, UNKNOWN_EXPRESSION, context);
|
|
@@ -8539,8 +8462,7 @@ class FunctionNode extends FunctionBase {
|
|
|
8539
8462
|
}
|
|
8540
8463
|
}
|
|
8541
8464
|
hasEffects() {
|
|
8542
|
-
|
|
8543
|
-
return (_a = this.id) === null || _a === void 0 ? void 0 : _a.hasEffects();
|
|
8465
|
+
return this.id !== null && this.id.hasEffects();
|
|
8544
8466
|
}
|
|
8545
8467
|
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
8546
8468
|
if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
|
|
@@ -8569,13 +8491,15 @@ class FunctionNode extends FunctionBase {
|
|
|
8569
8491
|
return false;
|
|
8570
8492
|
}
|
|
8571
8493
|
include(context, includeChildrenRecursively) {
|
|
8572
|
-
var _a;
|
|
8573
|
-
// This ensures that super.include will also include all parameters
|
|
8574
|
-
if (this.scope.argumentsVariable.included) {
|
|
8575
|
-
this.alwaysIncludeParameters = true;
|
|
8576
|
-
}
|
|
8577
|
-
(_a = this.id) === null || _a === void 0 ? void 0 : _a.include();
|
|
8578
8494
|
super.include(context, includeChildrenRecursively);
|
|
8495
|
+
if (this.id)
|
|
8496
|
+
this.id.include();
|
|
8497
|
+
const hasArguments = this.scope.argumentsVariable.included;
|
|
8498
|
+
for (const param of this.params) {
|
|
8499
|
+
if (!(param instanceof Identifier) || hasArguments) {
|
|
8500
|
+
param.include(context, includeChildrenRecursively);
|
|
8501
|
+
}
|
|
8502
|
+
}
|
|
8579
8503
|
}
|
|
8580
8504
|
initialise() {
|
|
8581
8505
|
var _a;
|
|
@@ -8622,6 +8546,11 @@ class AwaitExpression extends NodeBase {
|
|
|
8622
8546
|
}
|
|
8623
8547
|
this.argument.include(context, includeChildrenRecursively);
|
|
8624
8548
|
}
|
|
8549
|
+
applyDeoptimizations() {
|
|
8550
|
+
this.deoptimized = true;
|
|
8551
|
+
this.argument.deoptimizePath(UNKNOWN_PATH);
|
|
8552
|
+
this.context.requestTreeshakingPass();
|
|
8553
|
+
}
|
|
8625
8554
|
}
|
|
8626
8555
|
|
|
8627
8556
|
const binaryOperators = {
|
|
@@ -8655,10 +8584,10 @@ class BinaryExpression extends NodeBase {
|
|
|
8655
8584
|
if (path.length > 0)
|
|
8656
8585
|
return UnknownValue;
|
|
8657
8586
|
const leftValue = this.left.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
|
|
8658
|
-
if (
|
|
8587
|
+
if (leftValue === UnknownValue)
|
|
8659
8588
|
return UnknownValue;
|
|
8660
8589
|
const rightValue = this.right.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
|
|
8661
|
-
if (
|
|
8590
|
+
if (rightValue === UnknownValue)
|
|
8662
8591
|
return UnknownValue;
|
|
8663
8592
|
const operatorFn = binaryOperators[this.operator];
|
|
8664
8593
|
if (!operatorFn)
|
|
@@ -8949,15 +8878,12 @@ class MemberExpression extends NodeBase {
|
|
|
8949
8878
|
this.object.include(context, includeChildrenRecursively);
|
|
8950
8879
|
this.property.include(context, includeChildrenRecursively);
|
|
8951
8880
|
}
|
|
8952
|
-
|
|
8881
|
+
includeCallArguments(context, args) {
|
|
8953
8882
|
if (this.variable) {
|
|
8954
|
-
this.variable.
|
|
8883
|
+
this.variable.includeCallArguments(context, args);
|
|
8955
8884
|
}
|
|
8956
|
-
else
|
|
8957
|
-
super.
|
|
8958
|
-
}
|
|
8959
|
-
else if (path.length < MAX_PATH_DEPTH) {
|
|
8960
|
-
this.object.includeArgumentsWhenCalledAtPath([this.getPropertyKey(), ...path], context, args);
|
|
8885
|
+
else {
|
|
8886
|
+
super.includeCallArguments(context, args);
|
|
8961
8887
|
}
|
|
8962
8888
|
}
|
|
8963
8889
|
initialise() {
|
|
@@ -9019,7 +8945,7 @@ class MemberExpression extends NodeBase {
|
|
|
9019
8945
|
if (this.propertyKey === null) {
|
|
9020
8946
|
this.propertyKey = UnknownKey;
|
|
9021
8947
|
const value = this.property.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
|
|
9022
|
-
return (this.propertyKey =
|
|
8948
|
+
return (this.propertyKey = value === UnknownValue ? UnknownKey : String(value));
|
|
9023
8949
|
}
|
|
9024
8950
|
return this.propertyKey;
|
|
9025
8951
|
}
|
|
@@ -9046,13 +8972,39 @@ class MemberExpression extends NodeBase {
|
|
|
9046
8972
|
}
|
|
9047
8973
|
}
|
|
9048
8974
|
|
|
9049
|
-
class
|
|
8975
|
+
class CallExpression extends NodeBase {
|
|
9050
8976
|
constructor() {
|
|
9051
8977
|
super(...arguments);
|
|
9052
8978
|
this.deoptimized = false;
|
|
9053
|
-
this.returnExpression = null;
|
|
9054
8979
|
this.deoptimizableDependentExpressions = [];
|
|
9055
8980
|
this.expressionsToBeDeoptimized = new Set();
|
|
8981
|
+
this.returnExpression = null;
|
|
8982
|
+
}
|
|
8983
|
+
bind() {
|
|
8984
|
+
super.bind();
|
|
8985
|
+
if (this.callee instanceof Identifier) {
|
|
8986
|
+
const variable = this.scope.findVariable(this.callee.name);
|
|
8987
|
+
if (variable.isNamespace) {
|
|
8988
|
+
this.context.warn({
|
|
8989
|
+
code: 'CANNOT_CALL_NAMESPACE',
|
|
8990
|
+
message: `Cannot call a namespace ('${this.callee.name}')`
|
|
8991
|
+
}, this.start);
|
|
8992
|
+
}
|
|
8993
|
+
if (this.callee.name === 'eval') {
|
|
8994
|
+
this.context.warn({
|
|
8995
|
+
code: 'EVAL',
|
|
8996
|
+
message: `Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification`,
|
|
8997
|
+
url: 'https://rollupjs.org/guide/en/#avoiding-eval'
|
|
8998
|
+
}, this.start);
|
|
8999
|
+
}
|
|
9000
|
+
}
|
|
9001
|
+
this.callOptions = {
|
|
9002
|
+
args: this.arguments,
|
|
9003
|
+
thisParam: this.callee instanceof MemberExpression && !this.callee.variable
|
|
9004
|
+
? this.callee.object
|
|
9005
|
+
: null,
|
|
9006
|
+
withNew: false
|
|
9007
|
+
};
|
|
9056
9008
|
}
|
|
9057
9009
|
deoptimizeCache() {
|
|
9058
9010
|
if (this.returnExpression !== UNKNOWN_EXPRESSION) {
|
|
@@ -9107,47 +9059,6 @@ class CallExpressionBase extends NodeBase {
|
|
|
9107
9059
|
return returnExpression.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
|
|
9108
9060
|
}, UNKNOWN_EXPRESSION);
|
|
9109
9061
|
}
|
|
9110
|
-
hasEffectsWhenAccessedAtPath(path, context) {
|
|
9111
|
-
return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
|
|
9112
|
-
this.getReturnExpression().hasEffectsWhenAccessedAtPath(path, context));
|
|
9113
|
-
}
|
|
9114
|
-
hasEffectsWhenAssignedAtPath(path, context) {
|
|
9115
|
-
return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
|
|
9116
|
-
this.getReturnExpression().hasEffectsWhenAssignedAtPath(path, context));
|
|
9117
|
-
}
|
|
9118
|
-
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
9119
|
-
return (!(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
|
|
9120
|
-
this.getReturnExpression().hasEffectsWhenCalledAtPath(path, callOptions, context));
|
|
9121
|
-
}
|
|
9122
|
-
}
|
|
9123
|
-
|
|
9124
|
-
class CallExpression extends CallExpressionBase {
|
|
9125
|
-
bind() {
|
|
9126
|
-
super.bind();
|
|
9127
|
-
if (this.callee instanceof Identifier) {
|
|
9128
|
-
const variable = this.scope.findVariable(this.callee.name);
|
|
9129
|
-
if (variable.isNamespace) {
|
|
9130
|
-
this.context.warn({
|
|
9131
|
-
code: 'CANNOT_CALL_NAMESPACE',
|
|
9132
|
-
message: `Cannot call a namespace ('${this.callee.name}')`
|
|
9133
|
-
}, this.start);
|
|
9134
|
-
}
|
|
9135
|
-
if (this.callee.name === 'eval') {
|
|
9136
|
-
this.context.warn({
|
|
9137
|
-
code: 'EVAL',
|
|
9138
|
-
message: `Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification`,
|
|
9139
|
-
url: 'https://rollupjs.org/guide/en/#avoiding-eval'
|
|
9140
|
-
}, this.start);
|
|
9141
|
-
}
|
|
9142
|
-
}
|
|
9143
|
-
this.callOptions = {
|
|
9144
|
-
args: this.arguments,
|
|
9145
|
-
thisParam: this.callee instanceof MemberExpression && !this.callee.variable
|
|
9146
|
-
? this.callee.object
|
|
9147
|
-
: null,
|
|
9148
|
-
withNew: false
|
|
9149
|
-
};
|
|
9150
|
-
}
|
|
9151
9062
|
hasEffects(context) {
|
|
9152
9063
|
try {
|
|
9153
9064
|
for (const argument of this.arguments) {
|
|
@@ -9165,6 +9076,18 @@ class CallExpression extends CallExpressionBase {
|
|
|
9165
9076
|
this.applyDeoptimizations();
|
|
9166
9077
|
}
|
|
9167
9078
|
}
|
|
9079
|
+
hasEffectsWhenAccessedAtPath(path, context) {
|
|
9080
|
+
return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
|
|
9081
|
+
this.getReturnExpression().hasEffectsWhenAccessedAtPath(path, context));
|
|
9082
|
+
}
|
|
9083
|
+
hasEffectsWhenAssignedAtPath(path, context) {
|
|
9084
|
+
return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
|
|
9085
|
+
this.getReturnExpression().hasEffectsWhenAssignedAtPath(path, context));
|
|
9086
|
+
}
|
|
9087
|
+
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
9088
|
+
return (!(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
|
|
9089
|
+
this.getReturnExpression().hasEffectsWhenCalledAtPath(path, callOptions, context));
|
|
9090
|
+
}
|
|
9168
9091
|
include(context, includeChildrenRecursively) {
|
|
9169
9092
|
if (!this.deoptimized)
|
|
9170
9093
|
this.applyDeoptimizations();
|
|
@@ -9180,7 +9103,7 @@ class CallExpression extends CallExpressionBase {
|
|
|
9180
9103
|
this.included = true;
|
|
9181
9104
|
this.callee.include(context, false);
|
|
9182
9105
|
}
|
|
9183
|
-
this.callee.
|
|
9106
|
+
this.callee.includeCallArguments(context, this.arguments);
|
|
9184
9107
|
const returnExpression = this.getReturnExpression();
|
|
9185
9108
|
if (!returnExpression.included) {
|
|
9186
9109
|
returnExpression.include(context, false);
|
|
@@ -9351,9 +9274,6 @@ class MethodBase extends NodeBase {
|
|
|
9351
9274
|
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
9352
9275
|
return this.getAccessedValue().hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
9353
9276
|
}
|
|
9354
|
-
includeArgumentsWhenCalledAtPath(path, context, args) {
|
|
9355
|
-
this.getAccessedValue().includeArgumentsWhenCalledAtPath(path, context, args);
|
|
9356
|
-
}
|
|
9357
9277
|
getAccessedValue() {
|
|
9358
9278
|
if (this.accessedValue === null) {
|
|
9359
9279
|
if (this.kind === 'get') {
|
|
@@ -9390,6 +9310,8 @@ class ObjectMember extends ExpressionEntity {
|
|
|
9390
9310
|
return this.object.getReturnExpressionWhenCalledAtPath([this.key, ...path], callOptions, recursionTracker, origin);
|
|
9391
9311
|
}
|
|
9392
9312
|
hasEffectsWhenAccessedAtPath(path, context) {
|
|
9313
|
+
if (path.length === 0)
|
|
9314
|
+
return false;
|
|
9393
9315
|
return this.object.hasEffectsWhenAccessedAtPath([this.key, ...path], context);
|
|
9394
9316
|
}
|
|
9395
9317
|
hasEffectsWhenAssignedAtPath(path, context) {
|
|
@@ -9403,7 +9325,6 @@ class ObjectMember extends ExpressionEntity {
|
|
|
9403
9325
|
class ClassNode extends NodeBase {
|
|
9404
9326
|
constructor() {
|
|
9405
9327
|
super(...arguments);
|
|
9406
|
-
this.deoptimized = false;
|
|
9407
9328
|
this.objectEntity = null;
|
|
9408
9329
|
}
|
|
9409
9330
|
createScope(parentScope) {
|
|
@@ -9413,14 +9334,7 @@ class ClassNode extends NodeBase {
|
|
|
9413
9334
|
this.getObjectEntity().deoptimizeAllProperties();
|
|
9414
9335
|
}
|
|
9415
9336
|
deoptimizePath(path) {
|
|
9416
|
-
var _a, _b;
|
|
9417
9337
|
this.getObjectEntity().deoptimizePath(path);
|
|
9418
|
-
if (path.length === 1 && path[0] === UnknownKey) {
|
|
9419
|
-
// A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
|
|
9420
|
-
// which means the constructor needs to be reassigned
|
|
9421
|
-
(_a = this.classConstructor) === null || _a === void 0 ? void 0 : _a.deoptimizePath(UNKNOWN_PATH);
|
|
9422
|
-
(_b = this.superClass) === null || _b === void 0 ? void 0 : _b.deoptimizePath(UNKNOWN_PATH);
|
|
9423
|
-
}
|
|
9424
9338
|
}
|
|
9425
9339
|
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
9426
9340
|
this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
@@ -9433,8 +9347,6 @@ class ClassNode extends NodeBase {
|
|
|
9433
9347
|
}
|
|
9434
9348
|
hasEffects(context) {
|
|
9435
9349
|
var _a, _b;
|
|
9436
|
-
if (!this.deoptimized)
|
|
9437
|
-
this.applyDeoptimizations();
|
|
9438
9350
|
const initEffect = ((_a = this.superClass) === null || _a === void 0 ? void 0 : _a.hasEffects(context)) || this.body.hasEffects(context);
|
|
9439
9351
|
(_b = this.id) === null || _b === void 0 ? void 0 : _b.markDeclarationReached();
|
|
9440
9352
|
return initEffect || super.hasEffects(context);
|
|
@@ -9446,13 +9358,12 @@ class ClassNode extends NodeBase {
|
|
|
9446
9358
|
return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
|
|
9447
9359
|
}
|
|
9448
9360
|
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
9449
|
-
var _a;
|
|
9450
9361
|
if (path.length === 0) {
|
|
9451
9362
|
return (!callOptions.withNew ||
|
|
9452
9363
|
(this.classConstructor !== null
|
|
9453
9364
|
? this.classConstructor.hasEffectsWhenCalledAtPath(EMPTY_PATH, callOptions, context)
|
|
9454
|
-
:
|
|
9455
|
-
|
|
9365
|
+
: this.superClass !== null &&
|
|
9366
|
+
this.superClass.hasEffectsWhenCalledAtPath(path, callOptions, context)));
|
|
9456
9367
|
}
|
|
9457
9368
|
else {
|
|
9458
9369
|
return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
@@ -9460,8 +9371,6 @@ class ClassNode extends NodeBase {
|
|
|
9460
9371
|
}
|
|
9461
9372
|
include(context, includeChildrenRecursively) {
|
|
9462
9373
|
var _a;
|
|
9463
|
-
if (!this.deoptimized)
|
|
9464
|
-
this.applyDeoptimizations();
|
|
9465
9374
|
this.included = true;
|
|
9466
9375
|
(_a = this.superClass) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
|
|
9467
9376
|
this.body.include(context, includeChildrenRecursively);
|
|
@@ -9470,20 +9379,6 @@ class ClassNode extends NodeBase {
|
|
|
9470
9379
|
this.id.include();
|
|
9471
9380
|
}
|
|
9472
9381
|
}
|
|
9473
|
-
includeArgumentsWhenCalledAtPath(path, context, args) {
|
|
9474
|
-
var _a;
|
|
9475
|
-
if (path.length === 0) {
|
|
9476
|
-
if (this.classConstructor) {
|
|
9477
|
-
this.classConstructor.includeArgumentsWhenCalledAtPath(path, context, args);
|
|
9478
|
-
}
|
|
9479
|
-
else {
|
|
9480
|
-
(_a = this.superClass) === null || _a === void 0 ? void 0 : _a.includeArgumentsWhenCalledAtPath(path, context, args);
|
|
9481
|
-
}
|
|
9482
|
-
}
|
|
9483
|
-
else {
|
|
9484
|
-
this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
|
|
9485
|
-
}
|
|
9486
|
-
}
|
|
9487
9382
|
initialise() {
|
|
9488
9383
|
var _a;
|
|
9489
9384
|
(_a = this.id) === null || _a === void 0 ? void 0 : _a.declare('class', this);
|
|
@@ -9495,18 +9390,6 @@ class ClassNode extends NodeBase {
|
|
|
9495
9390
|
}
|
|
9496
9391
|
this.classConstructor = null;
|
|
9497
9392
|
}
|
|
9498
|
-
applyDeoptimizations() {
|
|
9499
|
-
this.deoptimized = true;
|
|
9500
|
-
for (const definition of this.body.body) {
|
|
9501
|
-
if (!(definition.static ||
|
|
9502
|
-
(definition instanceof MethodDefinition && definition.kind === 'constructor'))) {
|
|
9503
|
-
// Calls to methods are not tracked, ensure that parameter defaults are
|
|
9504
|
-
// included and the return value is deoptimized
|
|
9505
|
-
definition.deoptimizePath(UNKNOWN_PATH);
|
|
9506
|
-
}
|
|
9507
|
-
}
|
|
9508
|
-
this.context.requestTreeshakingPass();
|
|
9509
|
-
}
|
|
9510
9393
|
getObjectEntity() {
|
|
9511
9394
|
if (this.objectEntity !== null) {
|
|
9512
9395
|
return this.objectEntity;
|
|
@@ -9523,7 +9406,7 @@ class ClassNode extends NodeBase {
|
|
|
9523
9406
|
let key;
|
|
9524
9407
|
if (definition.computed) {
|
|
9525
9408
|
const keyValue = definition.key.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
|
|
9526
|
-
if (
|
|
9409
|
+
if (keyValue === UnknownValue) {
|
|
9527
9410
|
properties.push({ key: UnknownKey, kind, property: definition });
|
|
9528
9411
|
continue;
|
|
9529
9412
|
}
|
|
@@ -9719,14 +9602,14 @@ class ConditionalExpression extends NodeBase {
|
|
|
9719
9602
|
usedBranch.include(context, includeChildrenRecursively);
|
|
9720
9603
|
}
|
|
9721
9604
|
}
|
|
9722
|
-
|
|
9605
|
+
includeCallArguments(context, args) {
|
|
9723
9606
|
const usedBranch = this.getUsedBranch();
|
|
9724
9607
|
if (usedBranch === null) {
|
|
9725
|
-
this.consequent.
|
|
9726
|
-
this.alternate.
|
|
9608
|
+
this.consequent.includeCallArguments(context, args);
|
|
9609
|
+
this.alternate.includeCallArguments(context, args);
|
|
9727
9610
|
}
|
|
9728
9611
|
else {
|
|
9729
|
-
usedBranch.
|
|
9612
|
+
usedBranch.includeCallArguments(context, args);
|
|
9730
9613
|
}
|
|
9731
9614
|
}
|
|
9732
9615
|
render(code, options, { isCalleeOfRenderedParent, preventASI, renderedParentType, renderedSurroundingElement } = BLANK) {
|
|
@@ -9763,7 +9646,7 @@ class ConditionalExpression extends NodeBase {
|
|
|
9763
9646
|
}
|
|
9764
9647
|
this.isBranchResolutionAnalysed = true;
|
|
9765
9648
|
const testValue = this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
|
|
9766
|
-
return
|
|
9649
|
+
return testValue === UnknownValue
|
|
9767
9650
|
? null
|
|
9768
9651
|
: (this.usedBranch = testValue ? this.consequent : this.alternate);
|
|
9769
9652
|
}
|
|
@@ -9812,7 +9695,7 @@ class DoWhileStatement extends NodeBase {
|
|
|
9812
9695
|
this.included = true;
|
|
9813
9696
|
this.test.include(context, includeChildrenRecursively);
|
|
9814
9697
|
const { brokenFlow } = context;
|
|
9815
|
-
this.body.
|
|
9698
|
+
this.body.includeAsSingleStatement(context, includeChildrenRecursively);
|
|
9816
9699
|
context.brokenFlow = brokenFlow;
|
|
9817
9700
|
}
|
|
9818
9701
|
}
|
|
@@ -9940,13 +9823,12 @@ ExportDefaultDeclaration.prototype.needsBoundaries = true;
|
|
|
9940
9823
|
|
|
9941
9824
|
class ExportNamedDeclaration extends NodeBase {
|
|
9942
9825
|
bind() {
|
|
9943
|
-
var _a;
|
|
9944
9826
|
// Do not bind specifiers
|
|
9945
|
-
(
|
|
9827
|
+
if (this.declaration !== null)
|
|
9828
|
+
this.declaration.bind();
|
|
9946
9829
|
}
|
|
9947
9830
|
hasEffects(context) {
|
|
9948
|
-
|
|
9949
|
-
return (_a = this.declaration) === null || _a === void 0 ? void 0 : _a.hasEffects(context);
|
|
9831
|
+
return this.declaration !== null && this.declaration.hasEffects(context);
|
|
9950
9832
|
}
|
|
9951
9833
|
initialise() {
|
|
9952
9834
|
this.context.addExport(this);
|
|
@@ -10000,7 +9882,7 @@ class ForInStatement extends NodeBase {
|
|
|
10000
9882
|
this.left.include(context, includeChildrenRecursively || true);
|
|
10001
9883
|
this.right.include(context, includeChildrenRecursively);
|
|
10002
9884
|
const { brokenFlow } = context;
|
|
10003
|
-
this.body.
|
|
9885
|
+
this.body.includeAsSingleStatement(context, includeChildrenRecursively);
|
|
10004
9886
|
context.brokenFlow = brokenFlow;
|
|
10005
9887
|
}
|
|
10006
9888
|
render(code, options) {
|
|
@@ -10040,7 +9922,7 @@ class ForOfStatement extends NodeBase {
|
|
|
10040
9922
|
this.left.include(context, includeChildrenRecursively || true);
|
|
10041
9923
|
this.right.include(context, includeChildrenRecursively);
|
|
10042
9924
|
const { brokenFlow } = context;
|
|
10043
|
-
this.body.
|
|
9925
|
+
this.body.includeAsSingleStatement(context, includeChildrenRecursively);
|
|
10044
9926
|
context.brokenFlow = brokenFlow;
|
|
10045
9927
|
}
|
|
10046
9928
|
render(code, options) {
|
|
@@ -10064,10 +9946,9 @@ class ForStatement extends NodeBase {
|
|
|
10064
9946
|
this.scope = new BlockScope(parentScope);
|
|
10065
9947
|
}
|
|
10066
9948
|
hasEffects(context) {
|
|
10067
|
-
|
|
10068
|
-
|
|
10069
|
-
(
|
|
10070
|
-
((_c = this.update) === null || _c === void 0 ? void 0 : _c.hasEffects(context)))
|
|
9949
|
+
if ((this.init && this.init.hasEffects(context)) ||
|
|
9950
|
+
(this.test && this.test.hasEffects(context)) ||
|
|
9951
|
+
(this.update && this.update.hasEffects(context)))
|
|
10071
9952
|
return true;
|
|
10072
9953
|
const { brokenFlow, ignore: { breaks, continues } } = context;
|
|
10073
9954
|
context.ignore.breaks = true;
|
|
@@ -10080,20 +9961,24 @@ class ForStatement extends NodeBase {
|
|
|
10080
9961
|
return false;
|
|
10081
9962
|
}
|
|
10082
9963
|
include(context, includeChildrenRecursively) {
|
|
10083
|
-
var _a, _b, _c;
|
|
10084
9964
|
this.included = true;
|
|
10085
|
-
(
|
|
10086
|
-
|
|
9965
|
+
if (this.init)
|
|
9966
|
+
this.init.includeAsSingleStatement(context, includeChildrenRecursively);
|
|
9967
|
+
if (this.test)
|
|
9968
|
+
this.test.include(context, includeChildrenRecursively);
|
|
10087
9969
|
const { brokenFlow } = context;
|
|
10088
|
-
(
|
|
10089
|
-
|
|
9970
|
+
if (this.update)
|
|
9971
|
+
this.update.include(context, includeChildrenRecursively);
|
|
9972
|
+
this.body.includeAsSingleStatement(context, includeChildrenRecursively);
|
|
10090
9973
|
context.brokenFlow = brokenFlow;
|
|
10091
9974
|
}
|
|
10092
9975
|
render(code, options) {
|
|
10093
|
-
|
|
10094
|
-
|
|
10095
|
-
(
|
|
10096
|
-
|
|
9976
|
+
if (this.init)
|
|
9977
|
+
this.init.render(code, options, NO_SEMICOLON);
|
|
9978
|
+
if (this.test)
|
|
9979
|
+
this.test.render(code, options, NO_SEMICOLON);
|
|
9980
|
+
if (this.update)
|
|
9981
|
+
this.update.render(code, options, NO_SEMICOLON);
|
|
10097
9982
|
this.body.render(code, options);
|
|
10098
9983
|
}
|
|
10099
9984
|
}
|
|
@@ -10129,12 +10014,11 @@ class IfStatement extends NodeBase {
|
|
|
10129
10014
|
this.testValue = UnknownValue;
|
|
10130
10015
|
}
|
|
10131
10016
|
hasEffects(context) {
|
|
10132
|
-
var _a;
|
|
10133
10017
|
if (this.test.hasEffects(context)) {
|
|
10134
10018
|
return true;
|
|
10135
10019
|
}
|
|
10136
10020
|
const testValue = this.getTestValue();
|
|
10137
|
-
if (
|
|
10021
|
+
if (testValue === UnknownValue) {
|
|
10138
10022
|
const { brokenFlow } = context;
|
|
10139
10023
|
if (this.consequent.hasEffects(context))
|
|
10140
10024
|
return true;
|
|
@@ -10148,7 +10032,9 @@ class IfStatement extends NodeBase {
|
|
|
10148
10032
|
context.brokenFlow < consequentBrokenFlow ? context.brokenFlow : consequentBrokenFlow;
|
|
10149
10033
|
return false;
|
|
10150
10034
|
}
|
|
10151
|
-
return testValue
|
|
10035
|
+
return testValue
|
|
10036
|
+
? this.consequent.hasEffects(context)
|
|
10037
|
+
: this.alternate !== null && this.alternate.hasEffects(context);
|
|
10152
10038
|
}
|
|
10153
10039
|
include(context, includeChildrenRecursively) {
|
|
10154
10040
|
this.included = true;
|
|
@@ -10157,7 +10043,7 @@ class IfStatement extends NodeBase {
|
|
|
10157
10043
|
}
|
|
10158
10044
|
else {
|
|
10159
10045
|
const testValue = this.getTestValue();
|
|
10160
|
-
if (
|
|
10046
|
+
if (testValue === UnknownValue) {
|
|
10161
10047
|
this.includeUnknownTest(context);
|
|
10162
10048
|
}
|
|
10163
10049
|
else {
|
|
@@ -10187,7 +10073,7 @@ class IfStatement extends NodeBase {
|
|
|
10187
10073
|
else {
|
|
10188
10074
|
code.remove(this.start, this.consequent.start);
|
|
10189
10075
|
}
|
|
10190
|
-
if (this.consequent.included && (noTreeshake ||
|
|
10076
|
+
if (this.consequent.included && (noTreeshake || testValue === UnknownValue || testValue)) {
|
|
10191
10077
|
this.consequent.render(code, options);
|
|
10192
10078
|
}
|
|
10193
10079
|
else {
|
|
@@ -10195,7 +10081,7 @@ class IfStatement extends NodeBase {
|
|
|
10195
10081
|
hoistedDeclarations.push(...this.consequentScope.hoistedDeclarations);
|
|
10196
10082
|
}
|
|
10197
10083
|
if (this.alternate) {
|
|
10198
|
-
if (this.alternate.included && (noTreeshake ||
|
|
10084
|
+
if (this.alternate.included && (noTreeshake || testValue === UnknownValue || !testValue)) {
|
|
10199
10085
|
if (includesIfElse) {
|
|
10200
10086
|
if (code.original.charCodeAt(this.alternate.start - 1) === 101) {
|
|
10201
10087
|
code.prependLeft(this.alternate.start, ' ');
|
|
@@ -10225,35 +10111,34 @@ class IfStatement extends NodeBase {
|
|
|
10225
10111
|
return this.testValue;
|
|
10226
10112
|
}
|
|
10227
10113
|
includeKnownTest(context, testValue) {
|
|
10228
|
-
var _a;
|
|
10229
10114
|
if (this.test.shouldBeIncluded(context)) {
|
|
10230
10115
|
this.test.include(context, false);
|
|
10231
10116
|
}
|
|
10232
10117
|
if (testValue && this.consequent.shouldBeIncluded(context)) {
|
|
10233
|
-
this.consequent.
|
|
10118
|
+
this.consequent.includeAsSingleStatement(context, false);
|
|
10234
10119
|
}
|
|
10235
|
-
if (
|
|
10236
|
-
this.alternate.
|
|
10120
|
+
if (this.alternate !== null && !testValue && this.alternate.shouldBeIncluded(context)) {
|
|
10121
|
+
this.alternate.includeAsSingleStatement(context, false);
|
|
10237
10122
|
}
|
|
10238
10123
|
}
|
|
10239
10124
|
includeRecursively(includeChildrenRecursively, context) {
|
|
10240
|
-
var _a;
|
|
10241
10125
|
this.test.include(context, includeChildrenRecursively);
|
|
10242
10126
|
this.consequent.include(context, includeChildrenRecursively);
|
|
10243
|
-
(
|
|
10127
|
+
if (this.alternate !== null) {
|
|
10128
|
+
this.alternate.include(context, includeChildrenRecursively);
|
|
10129
|
+
}
|
|
10244
10130
|
}
|
|
10245
10131
|
includeUnknownTest(context) {
|
|
10246
|
-
var _a;
|
|
10247
10132
|
this.test.include(context, false);
|
|
10248
10133
|
const { brokenFlow } = context;
|
|
10249
10134
|
let consequentBrokenFlow = BROKEN_FLOW_NONE;
|
|
10250
10135
|
if (this.consequent.shouldBeIncluded(context)) {
|
|
10251
|
-
this.consequent.
|
|
10136
|
+
this.consequent.includeAsSingleStatement(context, false);
|
|
10252
10137
|
consequentBrokenFlow = context.brokenFlow;
|
|
10253
10138
|
context.brokenFlow = brokenFlow;
|
|
10254
10139
|
}
|
|
10255
|
-
if (
|
|
10256
|
-
this.alternate.
|
|
10140
|
+
if (this.alternate !== null && this.alternate.shouldBeIncluded(context)) {
|
|
10141
|
+
this.alternate.includeAsSingleStatement(context, false);
|
|
10257
10142
|
context.brokenFlow =
|
|
10258
10143
|
context.brokenFlow < consequentBrokenFlow ? context.brokenFlow : consequentBrokenFlow;
|
|
10259
10144
|
}
|
|
@@ -10840,7 +10725,7 @@ class LogicalExpression extends NodeBase {
|
|
|
10840
10725
|
if (!this.isBranchResolutionAnalysed) {
|
|
10841
10726
|
this.isBranchResolutionAnalysed = true;
|
|
10842
10727
|
const leftValue = this.left.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
|
|
10843
|
-
if (
|
|
10728
|
+
if (leftValue === UnknownValue) {
|
|
10844
10729
|
return null;
|
|
10845
10730
|
}
|
|
10846
10731
|
else {
|
|
@@ -11026,32 +10911,21 @@ class NewExpression extends NodeBase {
|
|
|
11026
10911
|
this.deoptimized = false;
|
|
11027
10912
|
}
|
|
11028
10913
|
hasEffects(context) {
|
|
11029
|
-
|
|
11030
|
-
|
|
11031
|
-
|
|
11032
|
-
|
|
11033
|
-
|
|
11034
|
-
if (this.context.options.treeshake.annotations &&
|
|
11035
|
-
this.annotations)
|
|
11036
|
-
return false;
|
|
11037
|
-
return (this.callee.hasEffects(context) ||
|
|
11038
|
-
this.callee.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
|
|
11039
|
-
}
|
|
11040
|
-
finally {
|
|
11041
|
-
if (!this.deoptimized)
|
|
11042
|
-
this.applyDeoptimizations();
|
|
10914
|
+
if (!this.deoptimized)
|
|
10915
|
+
this.applyDeoptimizations();
|
|
10916
|
+
for (const argument of this.arguments) {
|
|
10917
|
+
if (argument.hasEffects(context))
|
|
10918
|
+
return true;
|
|
11043
10919
|
}
|
|
10920
|
+
if (this.context.options.treeshake.annotations &&
|
|
10921
|
+
this.annotations)
|
|
10922
|
+
return false;
|
|
10923
|
+
return (this.callee.hasEffects(context) ||
|
|
10924
|
+
this.callee.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
|
|
11044
10925
|
}
|
|
11045
10926
|
hasEffectsWhenAccessedAtPath(path) {
|
|
11046
10927
|
return path.length > 0;
|
|
11047
10928
|
}
|
|
11048
|
-
include(context, includeChildrenRecursively) {
|
|
11049
|
-
if (!this.deoptimized)
|
|
11050
|
-
this.applyDeoptimizations();
|
|
11051
|
-
this.included = true;
|
|
11052
|
-
this.callee.include(context, includeChildrenRecursively);
|
|
11053
|
-
this.callee.includeArgumentsWhenCalledAtPath(EMPTY_PATH, context, this.arguments);
|
|
11054
|
-
}
|
|
11055
10929
|
initialise() {
|
|
11056
10930
|
this.callOptions = {
|
|
11057
10931
|
args: this.arguments,
|
|
@@ -11098,9 +10972,6 @@ class ObjectExpression extends NodeBase {
|
|
|
11098
10972
|
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
11099
10973
|
return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
11100
10974
|
}
|
|
11101
|
-
includeArgumentsWhenCalledAtPath(path, context, args) {
|
|
11102
|
-
this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
|
|
11103
|
-
}
|
|
11104
10975
|
render(code, options, { renderedSurroundingElement } = BLANK) {
|
|
11105
10976
|
super.render(code, options);
|
|
11106
10977
|
if (renderedSurroundingElement === ExpressionStatement$1 ||
|
|
@@ -11123,7 +10994,7 @@ class ObjectExpression extends NodeBase {
|
|
|
11123
10994
|
let key;
|
|
11124
10995
|
if (property.computed) {
|
|
11125
10996
|
const keyValue = property.key.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
|
|
11126
|
-
if (
|
|
10997
|
+
if (keyValue === UnknownValue) {
|
|
11127
10998
|
properties.push({ key: UnknownKey, kind: property.kind, property });
|
|
11128
10999
|
continue;
|
|
11129
11000
|
}
|
|
@@ -11244,8 +11115,8 @@ class PropertyDefinition extends NodeBase {
|
|
|
11244
11115
|
: UNKNOWN_EXPRESSION;
|
|
11245
11116
|
}
|
|
11246
11117
|
hasEffects(context) {
|
|
11247
|
-
|
|
11248
|
-
|
|
11118
|
+
return (this.key.hasEffects(context) ||
|
|
11119
|
+
(this.static && this.value !== null && this.value.hasEffects(context)));
|
|
11249
11120
|
}
|
|
11250
11121
|
hasEffectsWhenAccessedAtPath(path, context) {
|
|
11251
11122
|
return !this.value || this.value.hasEffectsWhenAccessedAtPath(path, context);
|
|
@@ -11256,24 +11127,21 @@ class PropertyDefinition extends NodeBase {
|
|
|
11256
11127
|
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
11257
11128
|
return !this.value || this.value.hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
11258
11129
|
}
|
|
11259
|
-
includeArgumentsWhenCalledAtPath(path, context, args) {
|
|
11260
|
-
var _a;
|
|
11261
|
-
(_a = this.value) === null || _a === void 0 ? void 0 : _a.includeArgumentsWhenCalledAtPath(path, context, args);
|
|
11262
|
-
}
|
|
11263
11130
|
}
|
|
11264
11131
|
|
|
11265
11132
|
class ReturnStatement extends NodeBase {
|
|
11266
11133
|
hasEffects(context) {
|
|
11267
|
-
|
|
11268
|
-
|
|
11134
|
+
if (!context.ignore.returnYield ||
|
|
11135
|
+
(this.argument !== null && this.argument.hasEffects(context)))
|
|
11269
11136
|
return true;
|
|
11270
11137
|
context.brokenFlow = BROKEN_FLOW_ERROR_RETURN_LABEL;
|
|
11271
11138
|
return false;
|
|
11272
11139
|
}
|
|
11273
11140
|
include(context, includeChildrenRecursively) {
|
|
11274
|
-
var _a;
|
|
11275
11141
|
this.included = true;
|
|
11276
|
-
(
|
|
11142
|
+
if (this.argument) {
|
|
11143
|
+
this.argument.include(context, includeChildrenRecursively);
|
|
11144
|
+
}
|
|
11277
11145
|
context.brokenFlow = BROKEN_FLOW_ERROR_RETURN_LABEL;
|
|
11278
11146
|
}
|
|
11279
11147
|
initialise() {
|
|
@@ -11393,9 +11261,6 @@ class Super extends NodeBase {
|
|
|
11393
11261
|
deoptimizePath(path) {
|
|
11394
11262
|
this.variable.deoptimizePath(path);
|
|
11395
11263
|
}
|
|
11396
|
-
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
11397
|
-
this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
11398
|
-
}
|
|
11399
11264
|
include() {
|
|
11400
11265
|
if (!this.included) {
|
|
11401
11266
|
this.included = true;
|
|
@@ -11406,8 +11271,7 @@ class Super extends NodeBase {
|
|
|
11406
11271
|
|
|
11407
11272
|
class SwitchCase extends NodeBase {
|
|
11408
11273
|
hasEffects(context) {
|
|
11409
|
-
|
|
11410
|
-
if ((_a = this.test) === null || _a === void 0 ? void 0 : _a.hasEffects(context))
|
|
11274
|
+
if (this.test && this.test.hasEffects(context))
|
|
11411
11275
|
return true;
|
|
11412
11276
|
for (const node of this.consequent) {
|
|
11413
11277
|
if (context.brokenFlow)
|
|
@@ -11418,9 +11282,9 @@ class SwitchCase extends NodeBase {
|
|
|
11418
11282
|
return false;
|
|
11419
11283
|
}
|
|
11420
11284
|
include(context, includeChildrenRecursively) {
|
|
11421
|
-
var _a;
|
|
11422
11285
|
this.included = true;
|
|
11423
|
-
(
|
|
11286
|
+
if (this.test)
|
|
11287
|
+
this.test.include(context, includeChildrenRecursively);
|
|
11424
11288
|
for (const node of this.consequent) {
|
|
11425
11289
|
if (includeChildrenRecursively || node.shouldBeIncluded(context))
|
|
11426
11290
|
node.include(context, includeChildrenRecursively);
|
|
@@ -11513,7 +11377,7 @@ class SwitchStatement extends NodeBase {
|
|
|
11513
11377
|
}
|
|
11514
11378
|
}
|
|
11515
11379
|
|
|
11516
|
-
class TaggedTemplateExpression extends
|
|
11380
|
+
class TaggedTemplateExpression extends NodeBase {
|
|
11517
11381
|
bind() {
|
|
11518
11382
|
super.bind();
|
|
11519
11383
|
if (this.tag.type === Identifier$1) {
|
|
@@ -11528,35 +11392,13 @@ class TaggedTemplateExpression extends CallExpressionBase {
|
|
|
11528
11392
|
}
|
|
11529
11393
|
}
|
|
11530
11394
|
hasEffects(context) {
|
|
11531
|
-
|
|
11532
|
-
|
|
11533
|
-
if (argument.hasEffects(context))
|
|
11534
|
-
return true;
|
|
11535
|
-
}
|
|
11536
|
-
return (this.tag.hasEffects(context) ||
|
|
11537
|
-
this.tag.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
|
|
11538
|
-
}
|
|
11539
|
-
finally {
|
|
11540
|
-
if (!this.deoptimized)
|
|
11541
|
-
this.applyDeoptimizations();
|
|
11542
|
-
}
|
|
11543
|
-
}
|
|
11544
|
-
include(context, includeChildrenRecursively) {
|
|
11545
|
-
if (!this.deoptimized)
|
|
11546
|
-
this.applyDeoptimizations();
|
|
11547
|
-
this.included = true;
|
|
11548
|
-
this.tag.include(context, includeChildrenRecursively);
|
|
11549
|
-
this.quasi.include(context, includeChildrenRecursively);
|
|
11550
|
-
this.tag.includeArgumentsWhenCalledAtPath(EMPTY_PATH, context, this.callOptions.args);
|
|
11551
|
-
const returnExpression = this.getReturnExpression();
|
|
11552
|
-
if (!returnExpression.included) {
|
|
11553
|
-
returnExpression.include(context, false);
|
|
11554
|
-
}
|
|
11395
|
+
return (super.hasEffects(context) ||
|
|
11396
|
+
this.tag.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
|
|
11555
11397
|
}
|
|
11556
11398
|
initialise() {
|
|
11557
11399
|
this.callOptions = {
|
|
11558
|
-
args:
|
|
11559
|
-
thisParam:
|
|
11400
|
+
args: NO_ARGS,
|
|
11401
|
+
thisParam: null,
|
|
11560
11402
|
withNew: false
|
|
11561
11403
|
};
|
|
11562
11404
|
}
|
|
@@ -11564,25 +11406,6 @@ class TaggedTemplateExpression extends CallExpressionBase {
|
|
|
11564
11406
|
this.tag.render(code, options, { isCalleeOfRenderedParent: true });
|
|
11565
11407
|
this.quasi.render(code, options);
|
|
11566
11408
|
}
|
|
11567
|
-
applyDeoptimizations() {
|
|
11568
|
-
this.deoptimized = true;
|
|
11569
|
-
const { thisParam } = this.callOptions;
|
|
11570
|
-
if (thisParam) {
|
|
11571
|
-
this.tag.deoptimizeThisOnEventAtPath(EVENT_CALLED, EMPTY_PATH, thisParam, SHARED_RECURSION_TRACKER);
|
|
11572
|
-
}
|
|
11573
|
-
for (const argument of this.quasi.expressions) {
|
|
11574
|
-
// This will make sure all properties of parameters behave as "unknown"
|
|
11575
|
-
argument.deoptimizePath(UNKNOWN_PATH);
|
|
11576
|
-
}
|
|
11577
|
-
this.context.requestTreeshakingPass();
|
|
11578
|
-
}
|
|
11579
|
-
getReturnExpression(recursionTracker = SHARED_RECURSION_TRACKER) {
|
|
11580
|
-
if (this.returnExpression === null) {
|
|
11581
|
-
this.returnExpression = UNKNOWN_EXPRESSION;
|
|
11582
|
-
return (this.returnExpression = this.tag.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.callOptions, recursionTracker, this));
|
|
11583
|
-
}
|
|
11584
|
-
return this.returnExpression;
|
|
11585
|
-
}
|
|
11586
11409
|
}
|
|
11587
11410
|
|
|
11588
11411
|
class TemplateElement extends NodeBase {
|
|
@@ -11794,15 +11617,13 @@ class TryStatement extends NodeBase {
|
|
|
11794
11617
|
this.includedLabelsAfterBlock = null;
|
|
11795
11618
|
}
|
|
11796
11619
|
hasEffects(context) {
|
|
11797
|
-
var _a;
|
|
11798
11620
|
return ((this.context.options.treeshake.tryCatchDeoptimization
|
|
11799
11621
|
? this.block.body.length > 0
|
|
11800
11622
|
: this.block.hasEffects(context)) ||
|
|
11801
|
-
(
|
|
11802
|
-
false);
|
|
11623
|
+
(this.finalizer !== null && this.finalizer.hasEffects(context)));
|
|
11803
11624
|
}
|
|
11804
11625
|
include(context, includeChildrenRecursively) {
|
|
11805
|
-
var _a
|
|
11626
|
+
var _a;
|
|
11806
11627
|
const tryCatchDeoptimization = (_a = this.context.options.treeshake) === null || _a === void 0 ? void 0 : _a.tryCatchDeoptimization;
|
|
11807
11628
|
const { brokenFlow } = context;
|
|
11808
11629
|
if (!this.directlyIncluded || !tryCatchDeoptimization) {
|
|
@@ -11823,7 +11644,9 @@ class TryStatement extends NodeBase {
|
|
|
11823
11644
|
this.handler.include(context, includeChildrenRecursively);
|
|
11824
11645
|
context.brokenFlow = brokenFlow;
|
|
11825
11646
|
}
|
|
11826
|
-
(
|
|
11647
|
+
if (this.finalizer !== null) {
|
|
11648
|
+
this.finalizer.include(context, includeChildrenRecursively);
|
|
11649
|
+
}
|
|
11827
11650
|
}
|
|
11828
11651
|
}
|
|
11829
11652
|
|
|
@@ -11845,7 +11668,7 @@ class UnaryExpression extends NodeBase {
|
|
|
11845
11668
|
if (path.length > 0)
|
|
11846
11669
|
return UnknownValue;
|
|
11847
11670
|
const argumentValue = this.argument.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
|
|
11848
|
-
if (
|
|
11671
|
+
if (argumentValue === UnknownValue)
|
|
11849
11672
|
return UnknownValue;
|
|
11850
11673
|
return unaryOperators[this.operator](argumentValue);
|
|
11851
11674
|
}
|
|
@@ -11959,12 +11782,18 @@ class VariableDeclaration extends NodeBase {
|
|
|
11959
11782
|
hasEffectsWhenAssignedAtPath() {
|
|
11960
11783
|
return false;
|
|
11961
11784
|
}
|
|
11962
|
-
include(context, includeChildrenRecursively
|
|
11785
|
+
include(context, includeChildrenRecursively) {
|
|
11963
11786
|
this.included = true;
|
|
11964
11787
|
for (const declarator of this.declarations) {
|
|
11965
11788
|
if (includeChildrenRecursively || declarator.shouldBeIncluded(context))
|
|
11966
11789
|
declarator.include(context, includeChildrenRecursively);
|
|
11967
|
-
|
|
11790
|
+
}
|
|
11791
|
+
}
|
|
11792
|
+
includeAsSingleStatement(context, includeChildrenRecursively) {
|
|
11793
|
+
this.included = true;
|
|
11794
|
+
for (const declarator of this.declarations) {
|
|
11795
|
+
if (includeChildrenRecursively || declarator.shouldBeIncluded(context)) {
|
|
11796
|
+
declarator.include(context, includeChildrenRecursively);
|
|
11968
11797
|
declarator.id.include(context, includeChildrenRecursively);
|
|
11969
11798
|
}
|
|
11970
11799
|
}
|
|
@@ -12112,15 +11941,15 @@ class VariableDeclarator extends NodeBase {
|
|
|
12112
11941
|
this.id.deoptimizePath(path);
|
|
12113
11942
|
}
|
|
12114
11943
|
hasEffects(context) {
|
|
12115
|
-
|
|
12116
|
-
const initEffect = (_a = this.init) === null || _a === void 0 ? void 0 : _a.hasEffects(context);
|
|
11944
|
+
const initEffect = this.init !== null && this.init.hasEffects(context);
|
|
12117
11945
|
this.id.markDeclarationReached();
|
|
12118
11946
|
return initEffect || this.id.hasEffects(context);
|
|
12119
11947
|
}
|
|
12120
11948
|
include(context, includeChildrenRecursively) {
|
|
12121
|
-
var _a;
|
|
12122
11949
|
this.included = true;
|
|
12123
|
-
(
|
|
11950
|
+
if (this.init) {
|
|
11951
|
+
this.init.include(context, includeChildrenRecursively);
|
|
11952
|
+
}
|
|
12124
11953
|
this.id.markDeclarationReached();
|
|
12125
11954
|
if (includeChildrenRecursively || this.id.shouldBeIncluded(context)) {
|
|
12126
11955
|
this.id.include(context, includeChildrenRecursively);
|
|
@@ -12164,7 +11993,7 @@ class WhileStatement extends NodeBase {
|
|
|
12164
11993
|
this.included = true;
|
|
12165
11994
|
this.test.include(context, includeChildrenRecursively);
|
|
12166
11995
|
const { brokenFlow } = context;
|
|
12167
|
-
this.body.
|
|
11996
|
+
this.body.includeAsSingleStatement(context, includeChildrenRecursively);
|
|
12168
11997
|
context.brokenFlow = brokenFlow;
|
|
12169
11998
|
}
|
|
12170
11999
|
}
|
|
@@ -12175,10 +12004,9 @@ class YieldExpression extends NodeBase {
|
|
|
12175
12004
|
this.deoptimized = false;
|
|
12176
12005
|
}
|
|
12177
12006
|
hasEffects(context) {
|
|
12178
|
-
var _a;
|
|
12179
12007
|
if (!this.deoptimized)
|
|
12180
12008
|
this.applyDeoptimizations();
|
|
12181
|
-
return !context.ignore.returnYield || (
|
|
12009
|
+
return (!context.ignore.returnYield || (this.argument !== null && this.argument.hasEffects(context)));
|
|
12182
12010
|
}
|
|
12183
12011
|
render(code, options) {
|
|
12184
12012
|
if (this.argument) {
|
|
@@ -12188,6 +12016,14 @@ class YieldExpression extends NodeBase {
|
|
|
12188
12016
|
}
|
|
12189
12017
|
}
|
|
12190
12018
|
}
|
|
12019
|
+
applyDeoptimizations() {
|
|
12020
|
+
this.deoptimized = true;
|
|
12021
|
+
const { argument } = this;
|
|
12022
|
+
if (argument) {
|
|
12023
|
+
argument.deoptimizePath(UNKNOWN_PATH);
|
|
12024
|
+
this.context.requestTreeshakingPass();
|
|
12025
|
+
}
|
|
12026
|
+
}
|
|
12191
12027
|
}
|
|
12192
12028
|
|
|
12193
12029
|
const nodeConstructors = {
|