rollup 2.72.0 → 2.74.0
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 +53 -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 +881 -675
- package/dist/es/shared/watch.js +5 -5
- package/dist/loadConfigFile.js +3 -3
- package/dist/rollup.browser.js +3 -3
- package/dist/rollup.browser.js.map +1 -1
- package/dist/rollup.js +2 -2
- package/dist/shared/index.js +4 -4
- package/dist/shared/loadConfigFile.js +4 -5
- package/dist/shared/mergeOptions.js +2 -2
- package/dist/shared/rollup.js +881 -675
- package/dist/shared/watch-cli.js +2 -2
- package/dist/shared/watch.js +2 -2
- package/package.json +1 -1
package/dist/es/shared/rollup.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v2.
|
|
4
|
-
Thu,
|
|
3
|
+
Rollup.js v2.74.0
|
|
4
|
+
Thu, 19 May 2022 05:01:43 GMT - commit fc99e96e09d26798f1c0aabdd7429307cc908c8e
|
|
5
5
|
|
|
6
6
|
https://github.com/rollup/rollup
|
|
7
7
|
|
|
@@ -14,7 +14,7 @@ import { createHash as createHash$1 } from 'crypto';
|
|
|
14
14
|
import { promises } from 'fs';
|
|
15
15
|
import { EventEmitter } from 'events';
|
|
16
16
|
|
|
17
|
-
var version$1 = "2.
|
|
17
|
+
var version$1 = "2.74.0";
|
|
18
18
|
|
|
19
19
|
var charToInteger = {};
|
|
20
20
|
var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
@@ -1209,7 +1209,7 @@ class MagicString {
|
|
|
1209
1209
|
const hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1210
1210
|
|
|
1211
1211
|
class Bundle$1 {
|
|
1212
|
-
constructor(options
|
|
1212
|
+
constructor(options) {
|
|
1213
1213
|
this.intro = options.intro || '';
|
|
1214
1214
|
this.separator = options.separator !== undefined ? options.separator : '\n';
|
|
1215
1215
|
this.sources = [];
|
|
@@ -1521,9 +1521,16 @@ function getOrCreate(map, key, init) {
|
|
|
1521
1521
|
}
|
|
1522
1522
|
|
|
1523
1523
|
const UnknownKey = Symbol('Unknown Key');
|
|
1524
|
+
const UnknownNonAccessorKey = Symbol('Unknown Non-Accessor Key');
|
|
1524
1525
|
const UnknownInteger = Symbol('Unknown Integer');
|
|
1525
1526
|
const EMPTY_PATH = [];
|
|
1526
1527
|
const UNKNOWN_PATH = [UnknownKey];
|
|
1528
|
+
// For deoptimizations, this means we are modifying an unknown property but did
|
|
1529
|
+
// not lose track of the object or are creating a setter/getter;
|
|
1530
|
+
// For assignment effects it means we do not check for setter/getter effects
|
|
1531
|
+
// but only if something is mutated that is included, which is relevant for
|
|
1532
|
+
// Object.defineProperty
|
|
1533
|
+
const UNKNOWN_NON_ACCESSOR_PATH = [UnknownNonAccessorKey];
|
|
1527
1534
|
const UNKNOWN_INTEGER_PATH = [UnknownInteger];
|
|
1528
1535
|
const EntitiesKey = Symbol('Entities');
|
|
1529
1536
|
class PathTracker {
|
|
@@ -1581,6 +1588,7 @@ class DiscriminatedPathTracker {
|
|
|
1581
1588
|
}
|
|
1582
1589
|
|
|
1583
1590
|
const UnknownValue = Symbol('Unknown Value');
|
|
1591
|
+
const UnknownTruthyValue = Symbol('Unknown Truthy Value');
|
|
1584
1592
|
class ExpressionEntity {
|
|
1585
1593
|
constructor() {
|
|
1586
1594
|
this.included = false;
|
|
@@ -1609,14 +1617,17 @@ class ExpressionEntity {
|
|
|
1609
1617
|
hasEffectsWhenCalledAtPath(_path, _callOptions, _context) {
|
|
1610
1618
|
return true;
|
|
1611
1619
|
}
|
|
1612
|
-
include(_context, _includeChildrenRecursively) {
|
|
1620
|
+
include(_context, _includeChildrenRecursively, _options) {
|
|
1613
1621
|
this.included = true;
|
|
1614
1622
|
}
|
|
1615
|
-
|
|
1623
|
+
includeArgumentsWhenCalledAtPath(_path, context, args) {
|
|
1616
1624
|
for (const arg of args) {
|
|
1617
1625
|
arg.include(context, false);
|
|
1618
1626
|
}
|
|
1619
1627
|
}
|
|
1628
|
+
shouldBeIncluded(_context) {
|
|
1629
|
+
return true;
|
|
1630
|
+
}
|
|
1620
1631
|
}
|
|
1621
1632
|
const UNKNOWN_EXPRESSION = new (class UnknownExpression extends ExpressionEntity {
|
|
1622
1633
|
})();
|
|
@@ -4580,7 +4591,7 @@ const UNDEFINED_EXPRESSION = new (class UndefinedExpression extends ExpressionEn
|
|
|
4580
4591
|
})();
|
|
4581
4592
|
const returnsUnknown = {
|
|
4582
4593
|
value: {
|
|
4583
|
-
|
|
4594
|
+
hasEffectsWhenCalled: null,
|
|
4584
4595
|
returns: UNKNOWN_EXPRESSION
|
|
4585
4596
|
}
|
|
4586
4597
|
};
|
|
@@ -4603,7 +4614,7 @@ const UNKNOWN_LITERAL_BOOLEAN = new (class UnknownBoolean extends ExpressionEnti
|
|
|
4603
4614
|
})();
|
|
4604
4615
|
const returnsBoolean = {
|
|
4605
4616
|
value: {
|
|
4606
|
-
|
|
4617
|
+
hasEffectsWhenCalled: null,
|
|
4607
4618
|
returns: UNKNOWN_LITERAL_BOOLEAN
|
|
4608
4619
|
}
|
|
4609
4620
|
};
|
|
@@ -4626,7 +4637,7 @@ const UNKNOWN_LITERAL_NUMBER = new (class UnknownNumber extends ExpressionEntity
|
|
|
4626
4637
|
})();
|
|
4627
4638
|
const returnsNumber = {
|
|
4628
4639
|
value: {
|
|
4629
|
-
|
|
4640
|
+
hasEffectsWhenCalled: null,
|
|
4630
4641
|
returns: UNKNOWN_LITERAL_NUMBER
|
|
4631
4642
|
}
|
|
4632
4643
|
};
|
|
@@ -4649,7 +4660,24 @@ const UNKNOWN_LITERAL_STRING = new (class UnknownString extends ExpressionEntity
|
|
|
4649
4660
|
})();
|
|
4650
4661
|
const returnsString = {
|
|
4651
4662
|
value: {
|
|
4652
|
-
|
|
4663
|
+
hasEffectsWhenCalled: null,
|
|
4664
|
+
returns: UNKNOWN_LITERAL_STRING
|
|
4665
|
+
}
|
|
4666
|
+
};
|
|
4667
|
+
const stringReplace = {
|
|
4668
|
+
value: {
|
|
4669
|
+
hasEffectsWhenCalled(callOptions, context) {
|
|
4670
|
+
const arg1 = callOptions.args[1];
|
|
4671
|
+
return (callOptions.args.length < 2 ||
|
|
4672
|
+
(typeof arg1.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, {
|
|
4673
|
+
deoptimizeCache() { }
|
|
4674
|
+
}) === 'symbol' &&
|
|
4675
|
+
arg1.hasEffectsWhenCalledAtPath(EMPTY_PATH, {
|
|
4676
|
+
args: NO_ARGS,
|
|
4677
|
+
thisParam: null,
|
|
4678
|
+
withNew: false
|
|
4679
|
+
}, context)));
|
|
4680
|
+
},
|
|
4653
4681
|
returns: UNKNOWN_LITERAL_STRING
|
|
4654
4682
|
}
|
|
4655
4683
|
};
|
|
@@ -4697,18 +4725,8 @@ const literalStringMembers = assembleMemberDescriptions({
|
|
|
4697
4725
|
padEnd: returnsString,
|
|
4698
4726
|
padStart: returnsString,
|
|
4699
4727
|
repeat: returnsString,
|
|
4700
|
-
replace:
|
|
4701
|
-
|
|
4702
|
-
callsArgs: [1],
|
|
4703
|
-
returns: UNKNOWN_LITERAL_STRING
|
|
4704
|
-
}
|
|
4705
|
-
},
|
|
4706
|
-
replaceAll: {
|
|
4707
|
-
value: {
|
|
4708
|
-
callsArgs: [1],
|
|
4709
|
-
returns: UNKNOWN_LITERAL_STRING
|
|
4710
|
-
}
|
|
4711
|
-
},
|
|
4728
|
+
replace: stringReplace,
|
|
4729
|
+
replaceAll: stringReplace,
|
|
4712
4730
|
search: returnsNumber,
|
|
4713
4731
|
slice: returnsString,
|
|
4714
4732
|
small: returnsString,
|
|
@@ -4743,21 +4761,11 @@ function getLiteralMembersForValue(value) {
|
|
|
4743
4761
|
return Object.create(null);
|
|
4744
4762
|
}
|
|
4745
4763
|
function hasMemberEffectWhenCalled(members, memberName, callOptions, context) {
|
|
4764
|
+
var _a, _b;
|
|
4746
4765
|
if (typeof memberName !== 'string' || !members[memberName]) {
|
|
4747
4766
|
return true;
|
|
4748
4767
|
}
|
|
4749
|
-
|
|
4750
|
-
return false;
|
|
4751
|
-
for (const argIndex of members[memberName].callsArgs) {
|
|
4752
|
-
if (callOptions.args[argIndex] &&
|
|
4753
|
-
callOptions.args[argIndex].hasEffectsWhenCalledAtPath(EMPTY_PATH, {
|
|
4754
|
-
args: NO_ARGS,
|
|
4755
|
-
thisParam: null,
|
|
4756
|
-
withNew: false
|
|
4757
|
-
}, context))
|
|
4758
|
-
return true;
|
|
4759
|
-
}
|
|
4760
|
-
return false;
|
|
4768
|
+
return ((_b = (_a = members[memberName]).hasEffectsWhenCalled) === null || _b === void 0 ? void 0 : _b.call(_a, callOptions, context)) || false;
|
|
4761
4769
|
}
|
|
4762
4770
|
function getMemberReturnExpressionWhenCalled(members, memberName) {
|
|
4763
4771
|
if (typeof memberName !== 'string' || !members[memberName])
|
|
@@ -5218,8 +5226,7 @@ class NodeBase extends ExpressionEntity {
|
|
|
5218
5226
|
continue;
|
|
5219
5227
|
if (Array.isArray(value)) {
|
|
5220
5228
|
for (const child of value) {
|
|
5221
|
-
|
|
5222
|
-
child.bind();
|
|
5229
|
+
child === null || child === void 0 ? void 0 : child.bind();
|
|
5223
5230
|
}
|
|
5224
5231
|
}
|
|
5225
5232
|
else {
|
|
@@ -5242,7 +5249,7 @@ class NodeBase extends ExpressionEntity {
|
|
|
5242
5249
|
continue;
|
|
5243
5250
|
if (Array.isArray(value)) {
|
|
5244
5251
|
for (const child of value) {
|
|
5245
|
-
if (child
|
|
5252
|
+
if (child === null || child === void 0 ? void 0 : child.hasEffects(context))
|
|
5246
5253
|
return true;
|
|
5247
5254
|
}
|
|
5248
5255
|
}
|
|
@@ -5251,7 +5258,7 @@ class NodeBase extends ExpressionEntity {
|
|
|
5251
5258
|
}
|
|
5252
5259
|
return false;
|
|
5253
5260
|
}
|
|
5254
|
-
include(context, includeChildrenRecursively) {
|
|
5261
|
+
include(context, includeChildrenRecursively, _options) {
|
|
5255
5262
|
if (this.deoptimized === false)
|
|
5256
5263
|
this.applyDeoptimizations();
|
|
5257
5264
|
this.included = true;
|
|
@@ -5261,8 +5268,7 @@ class NodeBase extends ExpressionEntity {
|
|
|
5261
5268
|
continue;
|
|
5262
5269
|
if (Array.isArray(value)) {
|
|
5263
5270
|
for (const child of value) {
|
|
5264
|
-
|
|
5265
|
-
child.include(context, includeChildrenRecursively);
|
|
5271
|
+
child === null || child === void 0 ? void 0 : child.include(context, includeChildrenRecursively);
|
|
5266
5272
|
}
|
|
5267
5273
|
}
|
|
5268
5274
|
else {
|
|
@@ -5270,9 +5276,6 @@ class NodeBase extends ExpressionEntity {
|
|
|
5270
5276
|
}
|
|
5271
5277
|
}
|
|
5272
5278
|
}
|
|
5273
|
-
includeAsSingleStatement(context, includeChildrenRecursively) {
|
|
5274
|
-
this.include(context, includeChildrenRecursively);
|
|
5275
|
-
}
|
|
5276
5279
|
/**
|
|
5277
5280
|
* Override to perform special initialisation steps after the scope is initialised
|
|
5278
5281
|
*/
|
|
@@ -5319,8 +5322,7 @@ class NodeBase extends ExpressionEntity {
|
|
|
5319
5322
|
continue;
|
|
5320
5323
|
if (Array.isArray(value)) {
|
|
5321
5324
|
for (const child of value) {
|
|
5322
|
-
|
|
5323
|
-
child.render(code, options);
|
|
5325
|
+
child === null || child === void 0 ? void 0 : child.render(code, options);
|
|
5324
5326
|
}
|
|
5325
5327
|
}
|
|
5326
5328
|
else {
|
|
@@ -5331,7 +5333,28 @@ class NodeBase extends ExpressionEntity {
|
|
|
5331
5333
|
shouldBeIncluded(context) {
|
|
5332
5334
|
return this.included || (!context.brokenFlow && this.hasEffects(createHasEffectsContext()));
|
|
5333
5335
|
}
|
|
5334
|
-
|
|
5336
|
+
/**
|
|
5337
|
+
* Just deoptimize everything by default so that when e.g. we do not track
|
|
5338
|
+
* something properly, it is deoptimized.
|
|
5339
|
+
* @protected
|
|
5340
|
+
*/
|
|
5341
|
+
applyDeoptimizations() {
|
|
5342
|
+
this.deoptimized = true;
|
|
5343
|
+
for (const key of this.keys) {
|
|
5344
|
+
const value = this[key];
|
|
5345
|
+
if (value === null)
|
|
5346
|
+
continue;
|
|
5347
|
+
if (Array.isArray(value)) {
|
|
5348
|
+
for (const child of value) {
|
|
5349
|
+
child === null || child === void 0 ? void 0 : child.deoptimizePath(UNKNOWN_PATH);
|
|
5350
|
+
}
|
|
5351
|
+
}
|
|
5352
|
+
else {
|
|
5353
|
+
value.deoptimizePath(UNKNOWN_PATH);
|
|
5354
|
+
}
|
|
5355
|
+
}
|
|
5356
|
+
this.context.requestTreeshakingPass();
|
|
5357
|
+
}
|
|
5335
5358
|
}
|
|
5336
5359
|
|
|
5337
5360
|
class SpreadElement extends NodeBase {
|
|
@@ -5413,7 +5436,7 @@ class Method extends ExpressionEntity {
|
|
|
5413
5436
|
}
|
|
5414
5437
|
return false;
|
|
5415
5438
|
}
|
|
5416
|
-
|
|
5439
|
+
includeArgumentsWhenCalledAtPath(_path, context, args) {
|
|
5417
5440
|
for (const arg of args) {
|
|
5418
5441
|
arg.include(context, false);
|
|
5419
5442
|
}
|
|
@@ -5464,6 +5487,7 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5464
5487
|
this.deoptimizedPaths = Object.create(null);
|
|
5465
5488
|
this.expressionsToBeDeoptimizedByKey = Object.create(null);
|
|
5466
5489
|
this.gettersByKey = Object.create(null);
|
|
5490
|
+
this.hasLostTrack = false;
|
|
5467
5491
|
this.hasUnknownDeoptimizedInteger = false;
|
|
5468
5492
|
this.hasUnknownDeoptimizedProperty = false;
|
|
5469
5493
|
this.propertiesAndGettersByKey = Object.create(null);
|
|
@@ -5484,12 +5508,18 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5484
5508
|
}
|
|
5485
5509
|
}
|
|
5486
5510
|
}
|
|
5487
|
-
deoptimizeAllProperties() {
|
|
5511
|
+
deoptimizeAllProperties(noAccessors) {
|
|
5488
5512
|
var _a;
|
|
5489
|
-
|
|
5513
|
+
const isDeoptimized = this.hasLostTrack || this.hasUnknownDeoptimizedProperty;
|
|
5514
|
+
if (noAccessors) {
|
|
5515
|
+
this.hasUnknownDeoptimizedProperty = true;
|
|
5516
|
+
}
|
|
5517
|
+
else {
|
|
5518
|
+
this.hasLostTrack = true;
|
|
5519
|
+
}
|
|
5520
|
+
if (isDeoptimized) {
|
|
5490
5521
|
return;
|
|
5491
5522
|
}
|
|
5492
|
-
this.hasUnknownDeoptimizedProperty = true;
|
|
5493
5523
|
for (const properties of Object.values(this.propertiesAndGettersByKey).concat(Object.values(this.settersByKey))) {
|
|
5494
5524
|
for (const property of properties) {
|
|
5495
5525
|
property.deoptimizePath(UNKNOWN_PATH);
|
|
@@ -5500,7 +5530,9 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5500
5530
|
this.deoptimizeCachedEntities();
|
|
5501
5531
|
}
|
|
5502
5532
|
deoptimizeIntegerProperties() {
|
|
5503
|
-
if (this.
|
|
5533
|
+
if (this.hasLostTrack ||
|
|
5534
|
+
this.hasUnknownDeoptimizedProperty ||
|
|
5535
|
+
this.hasUnknownDeoptimizedInteger) {
|
|
5504
5536
|
return;
|
|
5505
5537
|
}
|
|
5506
5538
|
this.hasUnknownDeoptimizedInteger = true;
|
|
@@ -5513,17 +5545,19 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5513
5545
|
}
|
|
5514
5546
|
this.deoptimizeCachedIntegerEntities();
|
|
5515
5547
|
}
|
|
5548
|
+
// Assumption: If only a specific path is deoptimized, no accessors are created
|
|
5516
5549
|
deoptimizePath(path) {
|
|
5517
5550
|
var _a;
|
|
5518
|
-
if (this.
|
|
5551
|
+
if (this.hasLostTrack || this.immutable) {
|
|
5519
5552
|
return;
|
|
5553
|
+
}
|
|
5520
5554
|
const key = path[0];
|
|
5521
5555
|
if (path.length === 1) {
|
|
5522
5556
|
if (typeof key !== 'string') {
|
|
5523
5557
|
if (key === UnknownInteger) {
|
|
5524
5558
|
return this.deoptimizeIntegerProperties();
|
|
5525
5559
|
}
|
|
5526
|
-
return this.deoptimizeAllProperties();
|
|
5560
|
+
return this.deoptimizeAllProperties(key === UnknownNonAccessorKey);
|
|
5527
5561
|
}
|
|
5528
5562
|
if (!this.deoptimizedPaths[key]) {
|
|
5529
5563
|
this.deoptimizedPaths[key] = true;
|
|
@@ -5543,16 +5577,16 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5543
5577
|
: this.allProperties) {
|
|
5544
5578
|
property.deoptimizePath(subPath);
|
|
5545
5579
|
}
|
|
5546
|
-
(_a = this.prototypeExpression) === null || _a === void 0 ? void 0 : _a.deoptimizePath(path.length === 1 ? [
|
|
5580
|
+
(_a = this.prototypeExpression) === null || _a === void 0 ? void 0 : _a.deoptimizePath(path.length === 1 ? [...path, UnknownKey] : path);
|
|
5547
5581
|
}
|
|
5548
5582
|
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
5549
5583
|
var _a;
|
|
5550
5584
|
const [key, ...subPath] = path;
|
|
5551
|
-
if (this.
|
|
5585
|
+
if (this.hasLostTrack ||
|
|
5552
5586
|
// single paths that are deoptimized will not become getters or setters
|
|
5553
5587
|
((event === EVENT_CALLED || path.length > 1) &&
|
|
5554
|
-
|
|
5555
|
-
|
|
5588
|
+
(this.hasUnknownDeoptimizedProperty ||
|
|
5589
|
+
(typeof key === 'string' && this.deoptimizedPaths[key])))) {
|
|
5556
5590
|
thisParameter.deoptimizePath(UNKNOWN_PATH);
|
|
5557
5591
|
return;
|
|
5558
5592
|
}
|
|
@@ -5606,7 +5640,7 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5606
5640
|
}
|
|
5607
5641
|
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
5608
5642
|
if (path.length === 0) {
|
|
5609
|
-
return
|
|
5643
|
+
return UnknownTruthyValue;
|
|
5610
5644
|
}
|
|
5611
5645
|
const key = path[0];
|
|
5612
5646
|
const expressionAtPath = this.getMemberExpressionAndTrackDeopt(key, origin);
|
|
@@ -5650,7 +5684,7 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5650
5684
|
}
|
|
5651
5685
|
return true;
|
|
5652
5686
|
}
|
|
5653
|
-
if (this.
|
|
5687
|
+
if (this.hasLostTrack)
|
|
5654
5688
|
return true;
|
|
5655
5689
|
if (typeof key === 'string') {
|
|
5656
5690
|
if (this.propertiesAndGettersByKey[key]) {
|
|
@@ -5697,9 +5731,10 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5697
5731
|
}
|
|
5698
5732
|
return true;
|
|
5699
5733
|
}
|
|
5700
|
-
if (
|
|
5734
|
+
if (key === UnknownNonAccessorKey)
|
|
5735
|
+
return false;
|
|
5736
|
+
if (this.hasLostTrack)
|
|
5701
5737
|
return true;
|
|
5702
|
-
// We do not need to test for unknown properties as in that case, hasUnknownDeoptimizedProperty is true
|
|
5703
5738
|
if (typeof key === 'string') {
|
|
5704
5739
|
if (this.propertiesAndSettersByKey[key]) {
|
|
5705
5740
|
const setters = this.settersByKey[key];
|
|
@@ -5717,6 +5752,14 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5717
5752
|
}
|
|
5718
5753
|
}
|
|
5719
5754
|
}
|
|
5755
|
+
else {
|
|
5756
|
+
for (const setters of Object.values(this.settersByKey).concat([this.unmatchableSetters])) {
|
|
5757
|
+
for (const setter of setters) {
|
|
5758
|
+
if (setter.hasEffectsWhenAssignedAtPath(subPath, context))
|
|
5759
|
+
return true;
|
|
5760
|
+
}
|
|
5761
|
+
}
|
|
5762
|
+
}
|
|
5720
5763
|
if (this.prototypeExpression) {
|
|
5721
5764
|
return this.prototypeExpression.hasEffectsWhenAssignedAtPath(path, context);
|
|
5722
5765
|
}
|
|
@@ -5733,6 +5776,16 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5733
5776
|
}
|
|
5734
5777
|
return true;
|
|
5735
5778
|
}
|
|
5779
|
+
includeArgumentsWhenCalledAtPath(path, context, args) {
|
|
5780
|
+
const key = path[0];
|
|
5781
|
+
const expressionAtPath = this.getMemberExpression(key);
|
|
5782
|
+
if (expressionAtPath) {
|
|
5783
|
+
return expressionAtPath.includeArgumentsWhenCalledAtPath(path.slice(1), context, args);
|
|
5784
|
+
}
|
|
5785
|
+
if (this.prototypeExpression) {
|
|
5786
|
+
return this.prototypeExpression.includeArgumentsWhenCalledAtPath(path, context, args);
|
|
5787
|
+
}
|
|
5788
|
+
}
|
|
5736
5789
|
buildPropertyMaps(properties) {
|
|
5737
5790
|
const { allProperties, propertiesAndGettersByKey, propertiesAndSettersByKey, settersByKey, gettersByKey, unknownIntegerProps, unmatchablePropertiesAndGetters, unmatchableGetters, unmatchableSetters } = this;
|
|
5738
5791
|
const unmatchablePropertiesAndSetters = [];
|
|
@@ -5800,7 +5853,8 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5800
5853
|
}
|
|
5801
5854
|
}
|
|
5802
5855
|
getMemberExpression(key) {
|
|
5803
|
-
if (this.
|
|
5856
|
+
if (this.hasLostTrack ||
|
|
5857
|
+
this.hasUnknownDeoptimizedProperty ||
|
|
5804
5858
|
typeof key !== 'string' ||
|
|
5805
5859
|
(this.hasUnknownDeoptimizedInteger && INTEGER_REG_EXP.test(key)) ||
|
|
5806
5860
|
this.deoptimizedPaths[key]) {
|
|
@@ -6001,6 +6055,7 @@ const ARRAY_PROTOTYPE = new ObjectEntity({
|
|
|
6001
6055
|
class ArrayExpression extends NodeBase {
|
|
6002
6056
|
constructor() {
|
|
6003
6057
|
super(...arguments);
|
|
6058
|
+
this.deoptimized = false;
|
|
6004
6059
|
this.objectEntity = null;
|
|
6005
6060
|
}
|
|
6006
6061
|
deoptimizePath(path) {
|
|
@@ -6024,6 +6079,23 @@ class ArrayExpression extends NodeBase {
|
|
|
6024
6079
|
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
6025
6080
|
return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
6026
6081
|
}
|
|
6082
|
+
includeArgumentsWhenCalledAtPath(path, context, args) {
|
|
6083
|
+
this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
|
|
6084
|
+
}
|
|
6085
|
+
applyDeoptimizations() {
|
|
6086
|
+
this.deoptimized = true;
|
|
6087
|
+
let hasSpread = false;
|
|
6088
|
+
for (let index = 0; index < this.elements.length; index++) {
|
|
6089
|
+
const element = this.elements[index];
|
|
6090
|
+
if (hasSpread || element instanceof SpreadElement) {
|
|
6091
|
+
if (element) {
|
|
6092
|
+
hasSpread = true;
|
|
6093
|
+
element.deoptimizePath(UNKNOWN_PATH);
|
|
6094
|
+
}
|
|
6095
|
+
}
|
|
6096
|
+
}
|
|
6097
|
+
this.context.requestTreeshakingPass();
|
|
6098
|
+
}
|
|
6027
6099
|
getObjectEntity() {
|
|
6028
6100
|
if (this.objectEntity !== null) {
|
|
6029
6101
|
return this.objectEntity;
|
|
@@ -6034,7 +6106,7 @@ class ArrayExpression extends NodeBase {
|
|
|
6034
6106
|
let hasSpread = false;
|
|
6035
6107
|
for (let index = 0; index < this.elements.length; index++) {
|
|
6036
6108
|
const element = this.elements[index];
|
|
6037
|
-
if (element instanceof SpreadElement
|
|
6109
|
+
if (hasSpread || element instanceof SpreadElement) {
|
|
6038
6110
|
if (element) {
|
|
6039
6111
|
hasSpread = true;
|
|
6040
6112
|
properties.unshift({ key: UnknownInteger, kind: 'init', property: element });
|
|
@@ -6054,9 +6126,7 @@ class ArrayExpression extends NodeBase {
|
|
|
6054
6126
|
class ArrayPattern extends NodeBase {
|
|
6055
6127
|
addExportedVariables(variables, exportNamesByVariable) {
|
|
6056
6128
|
for (const element of this.elements) {
|
|
6057
|
-
|
|
6058
|
-
element.addExportedVariables(variables, exportNamesByVariable);
|
|
6059
|
-
}
|
|
6129
|
+
element === null || element === void 0 ? void 0 : element.addExportedVariables(variables, exportNamesByVariable);
|
|
6060
6130
|
}
|
|
6061
6131
|
}
|
|
6062
6132
|
declare(kind) {
|
|
@@ -6068,29 +6138,23 @@ class ArrayPattern extends NodeBase {
|
|
|
6068
6138
|
}
|
|
6069
6139
|
return variables;
|
|
6070
6140
|
}
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
element.deoptimizePath(path);
|
|
6076
|
-
}
|
|
6077
|
-
}
|
|
6141
|
+
// Patterns can only be deoptimized at the empty path at the moment
|
|
6142
|
+
deoptimizePath() {
|
|
6143
|
+
for (const element of this.elements) {
|
|
6144
|
+
element === null || element === void 0 ? void 0 : element.deoptimizePath(EMPTY_PATH);
|
|
6078
6145
|
}
|
|
6079
6146
|
}
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
return true;
|
|
6147
|
+
// Patterns are only checked at the emtpy path at the moment
|
|
6148
|
+
hasEffectsWhenAssignedAtPath(_path, context) {
|
|
6083
6149
|
for (const element of this.elements) {
|
|
6084
|
-
if (element
|
|
6150
|
+
if (element === null || element === void 0 ? void 0 : element.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context))
|
|
6085
6151
|
return true;
|
|
6086
6152
|
}
|
|
6087
6153
|
return false;
|
|
6088
6154
|
}
|
|
6089
6155
|
markDeclarationReached() {
|
|
6090
6156
|
for (const element of this.elements) {
|
|
6091
|
-
|
|
6092
|
-
element.markDeclarationReached();
|
|
6093
|
-
}
|
|
6157
|
+
element === null || element === void 0 ? void 0 : element.markDeclarationReached();
|
|
6094
6158
|
}
|
|
6095
6159
|
}
|
|
6096
6160
|
}
|
|
@@ -6210,7 +6274,7 @@ class LocalVariable extends Variable {
|
|
|
6210
6274
|
}
|
|
6211
6275
|
}
|
|
6212
6276
|
}
|
|
6213
|
-
|
|
6277
|
+
includeArgumentsWhenCalledAtPath(path, context, args) {
|
|
6214
6278
|
if (this.isReassigned || (this.init && context.includedCallArguments.has(this.init))) {
|
|
6215
6279
|
for (const arg of args) {
|
|
6216
6280
|
arg.include(context, false);
|
|
@@ -6218,7 +6282,7 @@ class LocalVariable extends Variable {
|
|
|
6218
6282
|
}
|
|
6219
6283
|
else if (this.init) {
|
|
6220
6284
|
context.includedCallArguments.add(this.init);
|
|
6221
|
-
this.init.
|
|
6285
|
+
this.init.includeArgumentsWhenCalledAtPath(path, context, args);
|
|
6222
6286
|
context.includedCallArguments.delete(this.init);
|
|
6223
6287
|
}
|
|
6224
6288
|
}
|
|
@@ -6466,6 +6530,48 @@ class ReturnValueScope extends ParameterScope {
|
|
|
6466
6530
|
}
|
|
6467
6531
|
}
|
|
6468
6532
|
|
|
6533
|
+
class AssignmentPattern extends NodeBase {
|
|
6534
|
+
constructor() {
|
|
6535
|
+
super(...arguments);
|
|
6536
|
+
this.deoptimized = false;
|
|
6537
|
+
}
|
|
6538
|
+
addExportedVariables(variables, exportNamesByVariable) {
|
|
6539
|
+
this.left.addExportedVariables(variables, exportNamesByVariable);
|
|
6540
|
+
}
|
|
6541
|
+
declare(kind, init) {
|
|
6542
|
+
return this.left.declare(kind, init);
|
|
6543
|
+
}
|
|
6544
|
+
deoptimizePath(path) {
|
|
6545
|
+
path.length === 0 && this.left.deoptimizePath(path);
|
|
6546
|
+
}
|
|
6547
|
+
hasEffectsWhenAssignedAtPath(path, context) {
|
|
6548
|
+
return path.length > 0 || this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
|
|
6549
|
+
}
|
|
6550
|
+
include(context, includeChildrenRecursively) {
|
|
6551
|
+
this.included = true;
|
|
6552
|
+
this.left.include(context, includeChildrenRecursively);
|
|
6553
|
+
this.right.include(context, includeChildrenRecursively);
|
|
6554
|
+
}
|
|
6555
|
+
markDeclarationReached() {
|
|
6556
|
+
this.left.markDeclarationReached();
|
|
6557
|
+
}
|
|
6558
|
+
render(code, options, { isShorthandProperty } = BLANK) {
|
|
6559
|
+
this.left.render(code, options, { isShorthandProperty });
|
|
6560
|
+
if (this.right.included) {
|
|
6561
|
+
this.right.render(code, options);
|
|
6562
|
+
}
|
|
6563
|
+
else {
|
|
6564
|
+
code.remove(this.left.end, this.end);
|
|
6565
|
+
}
|
|
6566
|
+
}
|
|
6567
|
+
applyDeoptimizations() {
|
|
6568
|
+
this.deoptimized = true;
|
|
6569
|
+
this.left.deoptimizePath(EMPTY_PATH);
|
|
6570
|
+
this.right.deoptimizePath(UNKNOWN_PATH);
|
|
6571
|
+
this.context.requestTreeshakingPass();
|
|
6572
|
+
}
|
|
6573
|
+
}
|
|
6574
|
+
|
|
6469
6575
|
function treeshakeNode(node, code, start, end) {
|
|
6470
6576
|
code.remove(start, end);
|
|
6471
6577
|
if (node.annotations) {
|
|
@@ -6718,109 +6824,363 @@ class BlockStatement extends NodeBase {
|
|
|
6718
6824
|
}
|
|
6719
6825
|
}
|
|
6720
6826
|
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
6740
|
-
|
|
6741
|
-
|
|
6742
|
-
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
|
|
6748
|
-
|
|
6749
|
-
|
|
6750
|
-
// disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
|
|
6751
|
-
case 'PropertyDefinition': return parent.computed || node === parent.value;
|
|
6752
|
-
|
|
6753
|
-
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
|
|
6754
|
-
case 'Property': return parent.computed || node === parent.value;
|
|
6755
|
-
|
|
6756
|
-
// disregard the `bar` in `export { foo as bar }` or
|
|
6757
|
-
// the foo in `import { foo as bar }`
|
|
6758
|
-
case 'ExportSpecifier':
|
|
6759
|
-
case 'ImportSpecifier': return node === parent.local;
|
|
6760
|
-
|
|
6761
|
-
// disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
|
|
6762
|
-
case 'LabeledStatement':
|
|
6763
|
-
case 'BreakStatement':
|
|
6764
|
-
case 'ContinueStatement': return false;
|
|
6765
|
-
default: return true;
|
|
6766
|
-
}
|
|
6767
|
-
}
|
|
6768
|
-
|
|
6769
|
-
return false;
|
|
6827
|
+
class RestElement extends NodeBase {
|
|
6828
|
+
constructor() {
|
|
6829
|
+
super(...arguments);
|
|
6830
|
+
this.deoptimized = false;
|
|
6831
|
+
this.declarationInit = null;
|
|
6832
|
+
}
|
|
6833
|
+
addExportedVariables(variables, exportNamesByVariable) {
|
|
6834
|
+
this.argument.addExportedVariables(variables, exportNamesByVariable);
|
|
6835
|
+
}
|
|
6836
|
+
declare(kind, init) {
|
|
6837
|
+
this.declarationInit = init;
|
|
6838
|
+
return this.argument.declare(kind, UNKNOWN_EXPRESSION);
|
|
6839
|
+
}
|
|
6840
|
+
deoptimizePath(path) {
|
|
6841
|
+
path.length === 0 && this.argument.deoptimizePath(EMPTY_PATH);
|
|
6842
|
+
}
|
|
6843
|
+
hasEffectsWhenAssignedAtPath(path, context) {
|
|
6844
|
+
return path.length > 0 || this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
|
|
6845
|
+
}
|
|
6846
|
+
markDeclarationReached() {
|
|
6847
|
+
this.argument.markDeclarationReached();
|
|
6848
|
+
}
|
|
6849
|
+
applyDeoptimizations() {
|
|
6850
|
+
this.deoptimized = true;
|
|
6851
|
+
if (this.declarationInit !== null) {
|
|
6852
|
+
this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
|
|
6853
|
+
this.context.requestTreeshakingPass();
|
|
6854
|
+
}
|
|
6855
|
+
}
|
|
6770
6856
|
}
|
|
6771
6857
|
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
|
|
6793
|
-
|
|
6794
|
-
|
|
6795
|
-
|
|
6796
|
-
|
|
6797
|
-
|
|
6798
|
-
|
|
6799
|
-
|
|
6800
|
-
|
|
6801
|
-
|
|
6802
|
-
|
|
6803
|
-
|
|
6804
|
-
|
|
6805
|
-
|
|
6806
|
-
|
|
6807
|
-
|
|
6808
|
-
|
|
6809
|
-
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
|
|
6814
|
-
|
|
6815
|
-
|
|
6816
|
-
|
|
6817
|
-
|
|
6818
|
-
|
|
6819
|
-
|
|
6820
|
-
|
|
6821
|
-
|
|
6822
|
-
|
|
6823
|
-
|
|
6858
|
+
class FunctionBase extends NodeBase {
|
|
6859
|
+
constructor() {
|
|
6860
|
+
super(...arguments);
|
|
6861
|
+
// By default, parameters are included via includeArgumentsWhenCalledAtPath
|
|
6862
|
+
this.alwaysIncludeParameters = false;
|
|
6863
|
+
this.objectEntity = null;
|
|
6864
|
+
this.deoptimizedReturn = false;
|
|
6865
|
+
}
|
|
6866
|
+
deoptimizeCache() {
|
|
6867
|
+
this.alwaysIncludeParameters = true;
|
|
6868
|
+
}
|
|
6869
|
+
deoptimizePath(path) {
|
|
6870
|
+
this.getObjectEntity().deoptimizePath(path);
|
|
6871
|
+
if (path.length === 1 && path[0] === UnknownKey) {
|
|
6872
|
+
// A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
|
|
6873
|
+
// which means the return expression needs to be reassigned
|
|
6874
|
+
this.alwaysIncludeParameters = true;
|
|
6875
|
+
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
6876
|
+
}
|
|
6877
|
+
}
|
|
6878
|
+
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
6879
|
+
if (path.length > 0) {
|
|
6880
|
+
this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
6881
|
+
}
|
|
6882
|
+
}
|
|
6883
|
+
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
6884
|
+
return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
|
|
6885
|
+
}
|
|
6886
|
+
getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
|
|
6887
|
+
if (path.length > 0) {
|
|
6888
|
+
return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
|
|
6889
|
+
}
|
|
6890
|
+
if (this.async) {
|
|
6891
|
+
if (!this.deoptimizedReturn) {
|
|
6892
|
+
this.deoptimizedReturn = true;
|
|
6893
|
+
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
6894
|
+
this.context.requestTreeshakingPass();
|
|
6895
|
+
}
|
|
6896
|
+
return UNKNOWN_EXPRESSION;
|
|
6897
|
+
}
|
|
6898
|
+
return this.scope.getReturnExpression();
|
|
6899
|
+
}
|
|
6900
|
+
hasEffectsWhenAccessedAtPath(path, context) {
|
|
6901
|
+
return this.getObjectEntity().hasEffectsWhenAccessedAtPath(path, context);
|
|
6902
|
+
}
|
|
6903
|
+
hasEffectsWhenAssignedAtPath(path, context) {
|
|
6904
|
+
return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
|
|
6905
|
+
}
|
|
6906
|
+
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
6907
|
+
if (path.length > 0) {
|
|
6908
|
+
return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
6909
|
+
}
|
|
6910
|
+
if (this.async) {
|
|
6911
|
+
const { propertyReadSideEffects } = this.context.options
|
|
6912
|
+
.treeshake;
|
|
6913
|
+
const returnExpression = this.scope.getReturnExpression();
|
|
6914
|
+
if (returnExpression.hasEffectsWhenCalledAtPath(['then'], { args: NO_ARGS, thisParam: null, withNew: false }, context) ||
|
|
6915
|
+
(propertyReadSideEffects &&
|
|
6916
|
+
(propertyReadSideEffects === 'always' ||
|
|
6917
|
+
returnExpression.hasEffectsWhenAccessedAtPath(['then'], context)))) {
|
|
6918
|
+
return true;
|
|
6919
|
+
}
|
|
6920
|
+
}
|
|
6921
|
+
for (const param of this.params) {
|
|
6922
|
+
if (param.hasEffects(context))
|
|
6923
|
+
return true;
|
|
6924
|
+
}
|
|
6925
|
+
return false;
|
|
6926
|
+
}
|
|
6927
|
+
include(context, includeChildrenRecursively) {
|
|
6928
|
+
this.included = true;
|
|
6929
|
+
const { brokenFlow } = context;
|
|
6930
|
+
context.brokenFlow = BROKEN_FLOW_NONE;
|
|
6931
|
+
this.body.include(context, includeChildrenRecursively);
|
|
6932
|
+
context.brokenFlow = brokenFlow;
|
|
6933
|
+
if (includeChildrenRecursively || this.alwaysIncludeParameters) {
|
|
6934
|
+
for (const param of this.params) {
|
|
6935
|
+
param.include(context, includeChildrenRecursively);
|
|
6936
|
+
}
|
|
6937
|
+
}
|
|
6938
|
+
}
|
|
6939
|
+
includeArgumentsWhenCalledAtPath(path, context, args) {
|
|
6940
|
+
var _a;
|
|
6941
|
+
if (path.length === 0) {
|
|
6942
|
+
for (let position = 0; position < this.params.length; position++) {
|
|
6943
|
+
const parameter = this.params[position];
|
|
6944
|
+
if (parameter instanceof AssignmentPattern) {
|
|
6945
|
+
if (parameter.left.shouldBeIncluded(context)) {
|
|
6946
|
+
parameter.left.include(context, false);
|
|
6947
|
+
}
|
|
6948
|
+
const argumentValue = (_a = args[position]) === null || _a === void 0 ? void 0 : _a.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
|
|
6949
|
+
// If argumentValue === UnknownTruthyValue, then we do not need to
|
|
6950
|
+
// include the default
|
|
6951
|
+
if ((argumentValue === undefined || argumentValue === UnknownValue) &&
|
|
6952
|
+
(this.parameterVariables[position].some(variable => variable.included) ||
|
|
6953
|
+
parameter.right.shouldBeIncluded(context))) {
|
|
6954
|
+
parameter.right.include(context, false);
|
|
6955
|
+
}
|
|
6956
|
+
}
|
|
6957
|
+
else if (parameter.shouldBeIncluded(context)) {
|
|
6958
|
+
parameter.include(context, false);
|
|
6959
|
+
}
|
|
6960
|
+
}
|
|
6961
|
+
this.scope.includeCallArguments(context, args);
|
|
6962
|
+
}
|
|
6963
|
+
else {
|
|
6964
|
+
this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
|
|
6965
|
+
}
|
|
6966
|
+
}
|
|
6967
|
+
initialise() {
|
|
6968
|
+
this.parameterVariables = this.params.map(param => param.declare('parameter', UNKNOWN_EXPRESSION));
|
|
6969
|
+
this.scope.addParameterVariables(this.parameterVariables, this.params[this.params.length - 1] instanceof RestElement);
|
|
6970
|
+
if (this.body instanceof BlockStatement) {
|
|
6971
|
+
this.body.addImplicitReturnExpressionToScope();
|
|
6972
|
+
}
|
|
6973
|
+
else {
|
|
6974
|
+
this.scope.addReturnExpression(this.body);
|
|
6975
|
+
}
|
|
6976
|
+
}
|
|
6977
|
+
parseNode(esTreeNode) {
|
|
6978
|
+
if (esTreeNode.body.type === BlockStatement$1) {
|
|
6979
|
+
this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
|
|
6980
|
+
}
|
|
6981
|
+
super.parseNode(esTreeNode);
|
|
6982
|
+
}
|
|
6983
|
+
}
|
|
6984
|
+
FunctionBase.prototype.preventChildBlockScope = true;
|
|
6985
|
+
|
|
6986
|
+
class ArrowFunctionExpression extends FunctionBase {
|
|
6987
|
+
constructor() {
|
|
6988
|
+
super(...arguments);
|
|
6989
|
+
this.objectEntity = null;
|
|
6990
|
+
}
|
|
6991
|
+
createScope(parentScope) {
|
|
6992
|
+
this.scope = new ReturnValueScope(parentScope, this.context);
|
|
6993
|
+
}
|
|
6994
|
+
hasEffects() {
|
|
6995
|
+
return false;
|
|
6996
|
+
}
|
|
6997
|
+
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
6998
|
+
if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
|
|
6999
|
+
return true;
|
|
7000
|
+
const { ignore, brokenFlow } = context;
|
|
7001
|
+
context.ignore = {
|
|
7002
|
+
breaks: false,
|
|
7003
|
+
continues: false,
|
|
7004
|
+
labels: new Set(),
|
|
7005
|
+
returnYield: true
|
|
7006
|
+
};
|
|
7007
|
+
if (this.body.hasEffects(context))
|
|
7008
|
+
return true;
|
|
7009
|
+
context.ignore = ignore;
|
|
7010
|
+
context.brokenFlow = brokenFlow;
|
|
7011
|
+
return false;
|
|
7012
|
+
}
|
|
7013
|
+
getObjectEntity() {
|
|
7014
|
+
if (this.objectEntity !== null) {
|
|
7015
|
+
return this.objectEntity;
|
|
7016
|
+
}
|
|
7017
|
+
return (this.objectEntity = new ObjectEntity([], OBJECT_PROTOTYPE));
|
|
7018
|
+
}
|
|
7019
|
+
}
|
|
7020
|
+
|
|
7021
|
+
function getSystemExportStatement(exportedVariables, { exportNamesByVariable, snippets: { _, getObject, getPropertyAccess } }, modifier = '') {
|
|
7022
|
+
if (exportedVariables.length === 1 &&
|
|
7023
|
+
exportNamesByVariable.get(exportedVariables[0]).length === 1) {
|
|
7024
|
+
const variable = exportedVariables[0];
|
|
7025
|
+
return `exports('${exportNamesByVariable.get(variable)}',${_}${variable.getName(getPropertyAccess)}${modifier})`;
|
|
7026
|
+
}
|
|
7027
|
+
else {
|
|
7028
|
+
const fields = [];
|
|
7029
|
+
for (const variable of exportedVariables) {
|
|
7030
|
+
for (const exportName of exportNamesByVariable.get(variable)) {
|
|
7031
|
+
fields.push([exportName, variable.getName(getPropertyAccess) + modifier]);
|
|
7032
|
+
}
|
|
7033
|
+
}
|
|
7034
|
+
return `exports(${getObject(fields, { lineBreakIndent: null })})`;
|
|
7035
|
+
}
|
|
7036
|
+
}
|
|
7037
|
+
function renderSystemExportExpression(exportedVariable, expressionStart, expressionEnd, code, { exportNamesByVariable, snippets: { _ } }) {
|
|
7038
|
+
code.prependRight(expressionStart, `exports('${exportNamesByVariable.get(exportedVariable)}',${_}`);
|
|
7039
|
+
code.appendLeft(expressionEnd, ')');
|
|
7040
|
+
}
|
|
7041
|
+
function renderSystemExportFunction(exportedVariables, expressionStart, expressionEnd, needsParens, code, options) {
|
|
7042
|
+
const { _, getDirectReturnIifeLeft } = options.snippets;
|
|
7043
|
+
code.prependRight(expressionStart, getDirectReturnIifeLeft(['v'], `${getSystemExportStatement(exportedVariables, options)},${_}v`, { needsArrowReturnParens: true, needsWrappedFunction: needsParens }));
|
|
7044
|
+
code.appendLeft(expressionEnd, ')');
|
|
7045
|
+
}
|
|
7046
|
+
function renderSystemExportSequenceAfterExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options) {
|
|
7047
|
+
const { _, getPropertyAccess } = options.snippets;
|
|
7048
|
+
code.appendLeft(expressionEnd, `,${_}${getSystemExportStatement([exportedVariable], options)},${_}${exportedVariable.getName(getPropertyAccess)}`);
|
|
7049
|
+
if (needsParens) {
|
|
7050
|
+
code.prependRight(expressionStart, '(');
|
|
7051
|
+
code.appendLeft(expressionEnd, ')');
|
|
7052
|
+
}
|
|
7053
|
+
}
|
|
7054
|
+
function renderSystemExportSequenceBeforeExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options, modifier) {
|
|
7055
|
+
const { _ } = options.snippets;
|
|
7056
|
+
code.prependRight(expressionStart, `${getSystemExportStatement([exportedVariable], options, modifier)},${_}`);
|
|
7057
|
+
if (needsParens) {
|
|
7058
|
+
code.prependRight(expressionStart, '(');
|
|
7059
|
+
code.appendLeft(expressionEnd, ')');
|
|
7060
|
+
}
|
|
7061
|
+
}
|
|
7062
|
+
|
|
7063
|
+
//@ts-check
|
|
7064
|
+
/** @typedef { import('estree').Node} Node */
|
|
7065
|
+
/** @typedef {Node | {
|
|
7066
|
+
* type: 'PropertyDefinition';
|
|
7067
|
+
* computed: boolean;
|
|
7068
|
+
* value: Node
|
|
7069
|
+
* }} NodeWithPropertyDefinition */
|
|
7070
|
+
|
|
7071
|
+
/**
|
|
7072
|
+
*
|
|
7073
|
+
* @param {NodeWithPropertyDefinition} node
|
|
7074
|
+
* @param {NodeWithPropertyDefinition} parent
|
|
7075
|
+
* @returns boolean
|
|
7076
|
+
*/
|
|
7077
|
+
function is_reference (node, parent) {
|
|
7078
|
+
if (node.type === 'MemberExpression') {
|
|
7079
|
+
return !node.computed && is_reference(node.object, node);
|
|
7080
|
+
}
|
|
7081
|
+
|
|
7082
|
+
if (node.type === 'Identifier') {
|
|
7083
|
+
if (!parent) return true;
|
|
7084
|
+
|
|
7085
|
+
switch (parent.type) {
|
|
7086
|
+
// disregard `bar` in `foo.bar`
|
|
7087
|
+
case 'MemberExpression': return parent.computed || node === parent.object;
|
|
7088
|
+
|
|
7089
|
+
// disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
|
|
7090
|
+
case 'MethodDefinition': return parent.computed;
|
|
7091
|
+
|
|
7092
|
+
// disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
|
|
7093
|
+
case 'PropertyDefinition': return parent.computed || node === parent.value;
|
|
7094
|
+
|
|
7095
|
+
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
|
|
7096
|
+
case 'Property': return parent.computed || node === parent.value;
|
|
7097
|
+
|
|
7098
|
+
// disregard the `bar` in `export { foo as bar }` or
|
|
7099
|
+
// the foo in `import { foo as bar }`
|
|
7100
|
+
case 'ExportSpecifier':
|
|
7101
|
+
case 'ImportSpecifier': return node === parent.local;
|
|
7102
|
+
|
|
7103
|
+
// disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
|
|
7104
|
+
case 'LabeledStatement':
|
|
7105
|
+
case 'BreakStatement':
|
|
7106
|
+
case 'ContinueStatement': return false;
|
|
7107
|
+
default: return true;
|
|
7108
|
+
}
|
|
7109
|
+
}
|
|
7110
|
+
|
|
7111
|
+
return false;
|
|
7112
|
+
}
|
|
7113
|
+
|
|
7114
|
+
/* eslint sort-keys: "off" */
|
|
7115
|
+
const ValueProperties = Symbol('Value Properties');
|
|
7116
|
+
const PURE = {
|
|
7117
|
+
hasEffectsWhenCalled() {
|
|
7118
|
+
return false;
|
|
7119
|
+
}
|
|
7120
|
+
};
|
|
7121
|
+
const IMPURE = {
|
|
7122
|
+
hasEffectsWhenCalled() {
|
|
7123
|
+
return true;
|
|
7124
|
+
}
|
|
7125
|
+
};
|
|
7126
|
+
// We use shortened variables to reduce file size here
|
|
7127
|
+
/* OBJECT */
|
|
7128
|
+
const O = {
|
|
7129
|
+
__proto__: null,
|
|
7130
|
+
[ValueProperties]: IMPURE
|
|
7131
|
+
};
|
|
7132
|
+
/* PURE FUNCTION */
|
|
7133
|
+
const PF = {
|
|
7134
|
+
__proto__: null,
|
|
7135
|
+
[ValueProperties]: PURE
|
|
7136
|
+
};
|
|
7137
|
+
/* FUNCTION THAT MUTATES FIRST ARG WITHOUT TRIGGERING ACCESSORS */
|
|
7138
|
+
const MUTATES_ARG_WITHOUT_ACCESSOR = {
|
|
7139
|
+
__proto__: null,
|
|
7140
|
+
[ValueProperties]: {
|
|
7141
|
+
hasEffectsWhenCalled(callOptions, context) {
|
|
7142
|
+
return (!callOptions.args.length ||
|
|
7143
|
+
callOptions.args[0].hasEffectsWhenAssignedAtPath(UNKNOWN_NON_ACCESSOR_PATH, context));
|
|
7144
|
+
}
|
|
7145
|
+
}
|
|
7146
|
+
};
|
|
7147
|
+
/* CONSTRUCTOR */
|
|
7148
|
+
const C = {
|
|
7149
|
+
__proto__: null,
|
|
7150
|
+
[ValueProperties]: IMPURE,
|
|
7151
|
+
prototype: O
|
|
7152
|
+
};
|
|
7153
|
+
/* PURE CONSTRUCTOR */
|
|
7154
|
+
const PC = {
|
|
7155
|
+
__proto__: null,
|
|
7156
|
+
[ValueProperties]: PURE,
|
|
7157
|
+
prototype: O
|
|
7158
|
+
};
|
|
7159
|
+
const ARRAY_TYPE = {
|
|
7160
|
+
__proto__: null,
|
|
7161
|
+
[ValueProperties]: PURE,
|
|
7162
|
+
from: PF,
|
|
7163
|
+
of: PF,
|
|
7164
|
+
prototype: O
|
|
7165
|
+
};
|
|
7166
|
+
const INTL_MEMBER = {
|
|
7167
|
+
__proto__: null,
|
|
7168
|
+
[ValueProperties]: PURE,
|
|
7169
|
+
supportedLocalesOf: PC
|
|
7170
|
+
};
|
|
7171
|
+
const knownGlobals = {
|
|
7172
|
+
// Placeholders for global objects to avoid shape mutations
|
|
7173
|
+
global: O,
|
|
7174
|
+
globalThis: O,
|
|
7175
|
+
self: O,
|
|
7176
|
+
window: O,
|
|
7177
|
+
// Common globals
|
|
7178
|
+
__proto__: null,
|
|
7179
|
+
[ValueProperties]: IMPURE,
|
|
7180
|
+
Array: {
|
|
7181
|
+
__proto__: null,
|
|
7182
|
+
[ValueProperties]: IMPURE,
|
|
7183
|
+
from: O,
|
|
6824
7184
|
isArray: PF,
|
|
6825
7185
|
of: PF,
|
|
6826
7186
|
prototype: O
|
|
@@ -6922,6 +7282,11 @@ const knownGlobals = {
|
|
|
6922
7282
|
__proto__: null,
|
|
6923
7283
|
[ValueProperties]: PURE,
|
|
6924
7284
|
create: PF,
|
|
7285
|
+
// Technically those can throw in certain situations, but we ignore this as
|
|
7286
|
+
// code that relies on this will hopefully wrap this in a try-catch, which
|
|
7287
|
+
// deoptimizes everything anyway
|
|
7288
|
+
defineProperty: MUTATES_ARG_WITHOUT_ACCESSOR,
|
|
7289
|
+
defineProperties: MUTATES_ARG_WITHOUT_ACCESSOR,
|
|
6925
7290
|
getOwnPropertyDescriptor: PF,
|
|
6926
7291
|
getOwnPropertyNames: PF,
|
|
6927
7292
|
getOwnPropertySymbols: PF,
|
|
@@ -7605,27 +7970,27 @@ function getGlobalAtPath(path) {
|
|
|
7605
7970
|
}
|
|
7606
7971
|
return currentGlobal[ValueProperties];
|
|
7607
7972
|
}
|
|
7608
|
-
function isPureGlobal(path) {
|
|
7609
|
-
const globalAtPath = getGlobalAtPath(path);
|
|
7610
|
-
return globalAtPath !== null && globalAtPath.pure;
|
|
7611
|
-
}
|
|
7612
|
-
function isGlobalMember(path) {
|
|
7613
|
-
if (path.length === 1) {
|
|
7614
|
-
return path[0] === 'undefined' || getGlobalAtPath(path) !== null;
|
|
7615
|
-
}
|
|
7616
|
-
return getGlobalAtPath(path.slice(0, -1)) !== null;
|
|
7617
|
-
}
|
|
7618
7973
|
|
|
7619
7974
|
class GlobalVariable extends Variable {
|
|
7620
7975
|
constructor() {
|
|
7621
7976
|
super(...arguments);
|
|
7977
|
+
// Ensure we use live-bindings for globals as we do not know if they have
|
|
7978
|
+
// been reassigned
|
|
7622
7979
|
this.isReassigned = true;
|
|
7623
7980
|
}
|
|
7981
|
+
getLiteralValueAtPath(path, _recursionTracker, _origin) {
|
|
7982
|
+
return getGlobalAtPath([this.name, ...path]) ? UnknownTruthyValue : UnknownValue;
|
|
7983
|
+
}
|
|
7624
7984
|
hasEffectsWhenAccessedAtPath(path) {
|
|
7625
|
-
|
|
7985
|
+
if (path.length === 0) {
|
|
7986
|
+
// Technically, "undefined" is a global variable of sorts
|
|
7987
|
+
return this.name !== 'undefined' && !getGlobalAtPath([this.name]);
|
|
7988
|
+
}
|
|
7989
|
+
return !getGlobalAtPath([this.name, ...path].slice(0, -1));
|
|
7626
7990
|
}
|
|
7627
|
-
hasEffectsWhenCalledAtPath(path) {
|
|
7628
|
-
|
|
7991
|
+
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
7992
|
+
const globalAtPath = getGlobalAtPath([this.name, ...path]);
|
|
7993
|
+
return !globalAtPath || globalAtPath.hasEffectsWhenCalled(callOptions, context);
|
|
7629
7994
|
}
|
|
7630
7995
|
}
|
|
7631
7996
|
|
|
@@ -7644,12 +8009,12 @@ class Identifier extends NodeBase {
|
|
|
7644
8009
|
this.isTDZAccess = null;
|
|
7645
8010
|
}
|
|
7646
8011
|
addExportedVariables(variables, exportNamesByVariable) {
|
|
7647
|
-
if (
|
|
8012
|
+
if (exportNamesByVariable.has(this.variable)) {
|
|
7648
8013
|
variables.push(this.variable);
|
|
7649
8014
|
}
|
|
7650
8015
|
}
|
|
7651
8016
|
bind() {
|
|
7652
|
-
if (this.variable
|
|
8017
|
+
if (!this.variable && is_reference(this, this.parent)) {
|
|
7653
8018
|
this.variable = this.scope.findVariable(this.name);
|
|
7654
8019
|
this.variable.addReference(this);
|
|
7655
8020
|
}
|
|
@@ -7711,18 +8076,14 @@ class Identifier extends NodeBase {
|
|
|
7711
8076
|
this.variable.hasEffectsWhenAccessedAtPath(EMPTY_PATH));
|
|
7712
8077
|
}
|
|
7713
8078
|
hasEffectsWhenAccessedAtPath(path, context) {
|
|
7714
|
-
|
|
7715
|
-
|
|
8079
|
+
var _a;
|
|
8080
|
+
return (_a = this.getVariableRespectingTDZ()) === null || _a === void 0 ? void 0 : _a.hasEffectsWhenAccessedAtPath(path, context);
|
|
7716
8081
|
}
|
|
7717
8082
|
hasEffectsWhenAssignedAtPath(path, context) {
|
|
7718
|
-
return (
|
|
7719
|
-
(path.length > 0
|
|
7720
|
-
? this.getVariableRespectingTDZ()
|
|
7721
|
-
: this.variable).hasEffectsWhenAssignedAtPath(path, context));
|
|
8083
|
+
return (path.length > 0 ? this.getVariableRespectingTDZ() : this.variable).hasEffectsWhenAssignedAtPath(path, context);
|
|
7722
8084
|
}
|
|
7723
8085
|
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
7724
|
-
return
|
|
7725
|
-
this.getVariableRespectingTDZ().hasEffectsWhenCalledAtPath(path, callOptions, context));
|
|
8086
|
+
return this.getVariableRespectingTDZ().hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
7726
8087
|
}
|
|
7727
8088
|
include() {
|
|
7728
8089
|
if (!this.deoptimized)
|
|
@@ -7734,8 +8095,8 @@ class Identifier extends NodeBase {
|
|
|
7734
8095
|
}
|
|
7735
8096
|
}
|
|
7736
8097
|
}
|
|
7737
|
-
|
|
7738
|
-
this.
|
|
8098
|
+
includeArgumentsWhenCalledAtPath(path, context, args) {
|
|
8099
|
+
this.variable.includeArgumentsWhenCalledAtPath(path, context, args);
|
|
7739
8100
|
}
|
|
7740
8101
|
isPossibleTDZ() {
|
|
7741
8102
|
// return cached value to avoid issues with the next tree-shaking pass
|
|
@@ -7788,7 +8149,7 @@ class Identifier extends NodeBase {
|
|
|
7788
8149
|
}
|
|
7789
8150
|
applyDeoptimizations() {
|
|
7790
8151
|
this.deoptimized = true;
|
|
7791
|
-
if (this.variable
|
|
8152
|
+
if (this.variable instanceof LocalVariable) {
|
|
7792
8153
|
this.variable.consolidateInitializers();
|
|
7793
8154
|
this.context.requestTreeshakingPass();
|
|
7794
8155
|
}
|
|
@@ -7814,183 +8175,6 @@ function closestParentFunctionOrProgram(node) {
|
|
|
7814
8175
|
return node;
|
|
7815
8176
|
}
|
|
7816
8177
|
|
|
7817
|
-
class RestElement extends NodeBase {
|
|
7818
|
-
constructor() {
|
|
7819
|
-
super(...arguments);
|
|
7820
|
-
this.deoptimized = false;
|
|
7821
|
-
this.declarationInit = null;
|
|
7822
|
-
}
|
|
7823
|
-
addExportedVariables(variables, exportNamesByVariable) {
|
|
7824
|
-
this.argument.addExportedVariables(variables, exportNamesByVariable);
|
|
7825
|
-
}
|
|
7826
|
-
declare(kind, init) {
|
|
7827
|
-
this.declarationInit = init;
|
|
7828
|
-
return this.argument.declare(kind, UNKNOWN_EXPRESSION);
|
|
7829
|
-
}
|
|
7830
|
-
deoptimizePath(path) {
|
|
7831
|
-
path.length === 0 && this.argument.deoptimizePath(EMPTY_PATH);
|
|
7832
|
-
}
|
|
7833
|
-
hasEffectsWhenAssignedAtPath(path, context) {
|
|
7834
|
-
return path.length > 0 || this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
|
|
7835
|
-
}
|
|
7836
|
-
markDeclarationReached() {
|
|
7837
|
-
this.argument.markDeclarationReached();
|
|
7838
|
-
}
|
|
7839
|
-
applyDeoptimizations() {
|
|
7840
|
-
this.deoptimized = true;
|
|
7841
|
-
if (this.declarationInit !== null) {
|
|
7842
|
-
this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
|
|
7843
|
-
this.context.requestTreeshakingPass();
|
|
7844
|
-
}
|
|
7845
|
-
}
|
|
7846
|
-
}
|
|
7847
|
-
|
|
7848
|
-
class ArrowFunctionExpression extends NodeBase {
|
|
7849
|
-
constructor() {
|
|
7850
|
-
super(...arguments);
|
|
7851
|
-
this.deoptimizedReturn = false;
|
|
7852
|
-
}
|
|
7853
|
-
createScope(parentScope) {
|
|
7854
|
-
this.scope = new ReturnValueScope(parentScope, this.context);
|
|
7855
|
-
}
|
|
7856
|
-
deoptimizePath(path) {
|
|
7857
|
-
// A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
|
|
7858
|
-
// which means the return expression needs to be reassigned
|
|
7859
|
-
if (path.length === 1 && path[0] === UnknownKey) {
|
|
7860
|
-
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
7861
|
-
}
|
|
7862
|
-
}
|
|
7863
|
-
// Arrow functions do not mutate their context
|
|
7864
|
-
deoptimizeThisOnEventAtPath() { }
|
|
7865
|
-
getReturnExpressionWhenCalledAtPath(path) {
|
|
7866
|
-
if (path.length !== 0) {
|
|
7867
|
-
return UNKNOWN_EXPRESSION;
|
|
7868
|
-
}
|
|
7869
|
-
if (this.async) {
|
|
7870
|
-
if (!this.deoptimizedReturn) {
|
|
7871
|
-
this.deoptimizedReturn = true;
|
|
7872
|
-
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
7873
|
-
this.context.requestTreeshakingPass();
|
|
7874
|
-
}
|
|
7875
|
-
return UNKNOWN_EXPRESSION;
|
|
7876
|
-
}
|
|
7877
|
-
return this.scope.getReturnExpression();
|
|
7878
|
-
}
|
|
7879
|
-
hasEffects() {
|
|
7880
|
-
return false;
|
|
7881
|
-
}
|
|
7882
|
-
hasEffectsWhenAccessedAtPath(path) {
|
|
7883
|
-
return path.length > 1;
|
|
7884
|
-
}
|
|
7885
|
-
hasEffectsWhenAssignedAtPath(path) {
|
|
7886
|
-
return path.length > 1;
|
|
7887
|
-
}
|
|
7888
|
-
hasEffectsWhenCalledAtPath(path, _callOptions, context) {
|
|
7889
|
-
if (path.length > 0)
|
|
7890
|
-
return true;
|
|
7891
|
-
if (this.async) {
|
|
7892
|
-
const { propertyReadSideEffects } = this.context.options
|
|
7893
|
-
.treeshake;
|
|
7894
|
-
const returnExpression = this.scope.getReturnExpression();
|
|
7895
|
-
if (returnExpression.hasEffectsWhenCalledAtPath(['then'], { args: NO_ARGS, thisParam: null, withNew: false }, context) ||
|
|
7896
|
-
(propertyReadSideEffects &&
|
|
7897
|
-
(propertyReadSideEffects === 'always' ||
|
|
7898
|
-
returnExpression.hasEffectsWhenAccessedAtPath(['then'], context)))) {
|
|
7899
|
-
return true;
|
|
7900
|
-
}
|
|
7901
|
-
}
|
|
7902
|
-
for (const param of this.params) {
|
|
7903
|
-
if (param.hasEffects(context))
|
|
7904
|
-
return true;
|
|
7905
|
-
}
|
|
7906
|
-
const { ignore, brokenFlow } = context;
|
|
7907
|
-
context.ignore = {
|
|
7908
|
-
breaks: false,
|
|
7909
|
-
continues: false,
|
|
7910
|
-
labels: new Set(),
|
|
7911
|
-
returnYield: true
|
|
7912
|
-
};
|
|
7913
|
-
if (this.body.hasEffects(context))
|
|
7914
|
-
return true;
|
|
7915
|
-
context.ignore = ignore;
|
|
7916
|
-
context.brokenFlow = brokenFlow;
|
|
7917
|
-
return false;
|
|
7918
|
-
}
|
|
7919
|
-
include(context, includeChildrenRecursively) {
|
|
7920
|
-
this.included = true;
|
|
7921
|
-
for (const param of this.params) {
|
|
7922
|
-
if (!(param instanceof Identifier)) {
|
|
7923
|
-
param.include(context, includeChildrenRecursively);
|
|
7924
|
-
}
|
|
7925
|
-
}
|
|
7926
|
-
const { brokenFlow } = context;
|
|
7927
|
-
context.brokenFlow = BROKEN_FLOW_NONE;
|
|
7928
|
-
this.body.include(context, includeChildrenRecursively);
|
|
7929
|
-
context.brokenFlow = brokenFlow;
|
|
7930
|
-
}
|
|
7931
|
-
includeCallArguments(context, args) {
|
|
7932
|
-
this.scope.includeCallArguments(context, args);
|
|
7933
|
-
}
|
|
7934
|
-
initialise() {
|
|
7935
|
-
this.scope.addParameterVariables(this.params.map(param => param.declare('parameter', UNKNOWN_EXPRESSION)), this.params[this.params.length - 1] instanceof RestElement);
|
|
7936
|
-
if (this.body instanceof BlockStatement) {
|
|
7937
|
-
this.body.addImplicitReturnExpressionToScope();
|
|
7938
|
-
}
|
|
7939
|
-
else {
|
|
7940
|
-
this.scope.addReturnExpression(this.body);
|
|
7941
|
-
}
|
|
7942
|
-
}
|
|
7943
|
-
parseNode(esTreeNode) {
|
|
7944
|
-
if (esTreeNode.body.type === BlockStatement$1) {
|
|
7945
|
-
this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
|
|
7946
|
-
}
|
|
7947
|
-
super.parseNode(esTreeNode);
|
|
7948
|
-
}
|
|
7949
|
-
}
|
|
7950
|
-
ArrowFunctionExpression.prototype.preventChildBlockScope = true;
|
|
7951
|
-
|
|
7952
|
-
function getSystemExportStatement(exportedVariables, { exportNamesByVariable, snippets: { _, getObject, getPropertyAccess } }, modifier = '') {
|
|
7953
|
-
if (exportedVariables.length === 1 &&
|
|
7954
|
-
exportNamesByVariable.get(exportedVariables[0]).length === 1) {
|
|
7955
|
-
const variable = exportedVariables[0];
|
|
7956
|
-
return `exports('${exportNamesByVariable.get(variable)}',${_}${variable.getName(getPropertyAccess)}${modifier})`;
|
|
7957
|
-
}
|
|
7958
|
-
else {
|
|
7959
|
-
const fields = [];
|
|
7960
|
-
for (const variable of exportedVariables) {
|
|
7961
|
-
for (const exportName of exportNamesByVariable.get(variable)) {
|
|
7962
|
-
fields.push([exportName, variable.getName(getPropertyAccess) + modifier]);
|
|
7963
|
-
}
|
|
7964
|
-
}
|
|
7965
|
-
return `exports(${getObject(fields, { lineBreakIndent: null })})`;
|
|
7966
|
-
}
|
|
7967
|
-
}
|
|
7968
|
-
function renderSystemExportExpression(exportedVariable, expressionStart, expressionEnd, code, { exportNamesByVariable, snippets: { _ } }) {
|
|
7969
|
-
code.prependRight(expressionStart, `exports('${exportNamesByVariable.get(exportedVariable)}',${_}`);
|
|
7970
|
-
code.appendLeft(expressionEnd, ')');
|
|
7971
|
-
}
|
|
7972
|
-
function renderSystemExportFunction(exportedVariables, expressionStart, expressionEnd, needsParens, code, options) {
|
|
7973
|
-
const { _, getDirectReturnIifeLeft } = options.snippets;
|
|
7974
|
-
code.prependRight(expressionStart, getDirectReturnIifeLeft(['v'], `${getSystemExportStatement(exportedVariables, options)},${_}v`, { needsArrowReturnParens: true, needsWrappedFunction: needsParens }));
|
|
7975
|
-
code.appendLeft(expressionEnd, ')');
|
|
7976
|
-
}
|
|
7977
|
-
function renderSystemExportSequenceAfterExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options) {
|
|
7978
|
-
const { _, getPropertyAccess } = options.snippets;
|
|
7979
|
-
code.appendLeft(expressionEnd, `,${_}${getSystemExportStatement([exportedVariable], options)},${_}${exportedVariable.getName(getPropertyAccess)}`);
|
|
7980
|
-
if (needsParens) {
|
|
7981
|
-
code.prependRight(expressionStart, '(');
|
|
7982
|
-
code.appendLeft(expressionEnd, ')');
|
|
7983
|
-
}
|
|
7984
|
-
}
|
|
7985
|
-
function renderSystemExportSequenceBeforeExpression(exportedVariable, expressionStart, expressionEnd, needsParens, code, options, modifier) {
|
|
7986
|
-
const { _ } = options.snippets;
|
|
7987
|
-
code.prependRight(expressionStart, `${getSystemExportStatement([exportedVariable], options, modifier)},${_}`);
|
|
7988
|
-
if (needsParens) {
|
|
7989
|
-
code.prependRight(expressionStart, '(');
|
|
7990
|
-
code.appendLeft(expressionEnd, ')');
|
|
7991
|
-
}
|
|
7992
|
-
}
|
|
7993
|
-
|
|
7994
8178
|
class ObjectPattern extends NodeBase {
|
|
7995
8179
|
addExportedVariables(variables, exportNamesByVariable) {
|
|
7996
8180
|
for (const property of this.properties) {
|
|
@@ -8117,38 +8301,6 @@ class AssignmentExpression extends NodeBase {
|
|
|
8117
8301
|
}
|
|
8118
8302
|
}
|
|
8119
8303
|
|
|
8120
|
-
class AssignmentPattern extends NodeBase {
|
|
8121
|
-
constructor() {
|
|
8122
|
-
super(...arguments);
|
|
8123
|
-
this.deoptimized = false;
|
|
8124
|
-
}
|
|
8125
|
-
addExportedVariables(variables, exportNamesByVariable) {
|
|
8126
|
-
this.left.addExportedVariables(variables, exportNamesByVariable);
|
|
8127
|
-
}
|
|
8128
|
-
declare(kind, init) {
|
|
8129
|
-
return this.left.declare(kind, init);
|
|
8130
|
-
}
|
|
8131
|
-
deoptimizePath(path) {
|
|
8132
|
-
path.length === 0 && this.left.deoptimizePath(path);
|
|
8133
|
-
}
|
|
8134
|
-
hasEffectsWhenAssignedAtPath(path, context) {
|
|
8135
|
-
return path.length > 0 || this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, context);
|
|
8136
|
-
}
|
|
8137
|
-
markDeclarationReached() {
|
|
8138
|
-
this.left.markDeclarationReached();
|
|
8139
|
-
}
|
|
8140
|
-
render(code, options, { isShorthandProperty } = BLANK) {
|
|
8141
|
-
this.left.render(code, options, { isShorthandProperty });
|
|
8142
|
-
this.right.render(code, options);
|
|
8143
|
-
}
|
|
8144
|
-
applyDeoptimizations() {
|
|
8145
|
-
this.deoptimized = true;
|
|
8146
|
-
this.left.deoptimizePath(EMPTY_PATH);
|
|
8147
|
-
this.right.deoptimizePath(UNKNOWN_PATH);
|
|
8148
|
-
this.context.requestTreeshakingPass();
|
|
8149
|
-
}
|
|
8150
|
-
}
|
|
8151
|
-
|
|
8152
8304
|
class ArgumentsVariable extends LocalVariable {
|
|
8153
8305
|
constructor(context) {
|
|
8154
8306
|
super('arguments', null, UNKNOWN_EXPRESSION, context);
|
|
@@ -8241,85 +8393,27 @@ class FunctionScope extends ReturnValueScope {
|
|
|
8241
8393
|
}
|
|
8242
8394
|
}
|
|
8243
8395
|
|
|
8244
|
-
class FunctionNode extends
|
|
8396
|
+
class FunctionNode extends FunctionBase {
|
|
8245
8397
|
constructor() {
|
|
8246
8398
|
super(...arguments);
|
|
8247
|
-
this.
|
|
8248
|
-
this.isPrototypeDeoptimized = false;
|
|
8399
|
+
this.objectEntity = null;
|
|
8249
8400
|
}
|
|
8250
8401
|
createScope(parentScope) {
|
|
8251
8402
|
this.scope = new FunctionScope(parentScope, this.context);
|
|
8252
8403
|
}
|
|
8253
|
-
|
|
8254
|
-
|
|
8255
|
-
|
|
8256
|
-
|
|
8257
|
-
}
|
|
8258
|
-
else if (path[0] === UnknownKey) {
|
|
8259
|
-
this.isPrototypeDeoptimized = true;
|
|
8260
|
-
// A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
|
|
8261
|
-
// which means the return expression needs to be reassigned as well
|
|
8262
|
-
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
8263
|
-
}
|
|
8264
|
-
}
|
|
8265
|
-
}
|
|
8266
|
-
// TODO for completeness, we should also track other events here
|
|
8267
|
-
deoptimizeThisOnEventAtPath(event, path, thisParameter) {
|
|
8268
|
-
if (event === EVENT_CALLED) {
|
|
8269
|
-
if (path.length > 0) {
|
|
8270
|
-
thisParameter.deoptimizePath(UNKNOWN_PATH);
|
|
8271
|
-
}
|
|
8272
|
-
else {
|
|
8273
|
-
this.scope.thisVariable.addEntityToBeDeoptimized(thisParameter);
|
|
8274
|
-
}
|
|
8275
|
-
}
|
|
8276
|
-
}
|
|
8277
|
-
getReturnExpressionWhenCalledAtPath(path) {
|
|
8278
|
-
if (path.length !== 0) {
|
|
8279
|
-
return UNKNOWN_EXPRESSION;
|
|
8280
|
-
}
|
|
8281
|
-
if (this.async) {
|
|
8282
|
-
if (!this.deoptimizedReturn) {
|
|
8283
|
-
this.deoptimizedReturn = true;
|
|
8284
|
-
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
8285
|
-
this.context.requestTreeshakingPass();
|
|
8286
|
-
}
|
|
8287
|
-
return UNKNOWN_EXPRESSION;
|
|
8404
|
+
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
8405
|
+
super.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
8406
|
+
if (event === EVENT_CALLED && path.length === 0) {
|
|
8407
|
+
this.scope.thisVariable.addEntityToBeDeoptimized(thisParameter);
|
|
8288
8408
|
}
|
|
8289
|
-
return this.scope.getReturnExpression();
|
|
8290
8409
|
}
|
|
8291
8410
|
hasEffects() {
|
|
8292
|
-
|
|
8293
|
-
|
|
8294
|
-
hasEffectsWhenAccessedAtPath(path) {
|
|
8295
|
-
if (path.length <= 1)
|
|
8296
|
-
return false;
|
|
8297
|
-
return path.length > 2 || path[0] !== 'prototype' || this.isPrototypeDeoptimized;
|
|
8298
|
-
}
|
|
8299
|
-
hasEffectsWhenAssignedAtPath(path) {
|
|
8300
|
-
if (path.length <= 1) {
|
|
8301
|
-
return false;
|
|
8302
|
-
}
|
|
8303
|
-
return path.length > 2 || path[0] !== 'prototype' || this.isPrototypeDeoptimized;
|
|
8411
|
+
var _a;
|
|
8412
|
+
return (_a = this.id) === null || _a === void 0 ? void 0 : _a.hasEffects();
|
|
8304
8413
|
}
|
|
8305
8414
|
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
8306
|
-
if (path
|
|
8307
|
-
return true;
|
|
8308
|
-
if (this.async) {
|
|
8309
|
-
const { propertyReadSideEffects } = this.context.options
|
|
8310
|
-
.treeshake;
|
|
8311
|
-
const returnExpression = this.scope.getReturnExpression();
|
|
8312
|
-
if (returnExpression.hasEffectsWhenCalledAtPath(['then'], { args: NO_ARGS, thisParam: null, withNew: false }, context) ||
|
|
8313
|
-
(propertyReadSideEffects &&
|
|
8314
|
-
(propertyReadSideEffects === 'always' ||
|
|
8315
|
-
returnExpression.hasEffectsWhenAccessedAtPath(['then'], context)))) {
|
|
8316
|
-
return true;
|
|
8317
|
-
}
|
|
8318
|
-
}
|
|
8319
|
-
for (const param of this.params) {
|
|
8320
|
-
if (param.hasEffects(context))
|
|
8321
|
-
return true;
|
|
8322
|
-
}
|
|
8415
|
+
if (super.hasEffectsWhenCalledAtPath(path, callOptions, context))
|
|
8416
|
+
return true;
|
|
8323
8417
|
const thisInit = context.replacedVariableInits.get(this.scope.thisVariable);
|
|
8324
8418
|
context.replacedVariableInits.set(this.scope.thisVariable, callOptions.withNew
|
|
8325
8419
|
? new ObjectEntity(Object.create(null), OBJECT_PROTOTYPE)
|
|
@@ -8344,36 +8438,32 @@ class FunctionNode extends NodeBase {
|
|
|
8344
8438
|
return false;
|
|
8345
8439
|
}
|
|
8346
8440
|
include(context, includeChildrenRecursively) {
|
|
8347
|
-
|
|
8348
|
-
|
|
8349
|
-
|
|
8350
|
-
|
|
8351
|
-
for (const param of this.params) {
|
|
8352
|
-
if (!(param instanceof Identifier) || hasArguments) {
|
|
8353
|
-
param.include(context, includeChildrenRecursively);
|
|
8354
|
-
}
|
|
8441
|
+
var _a;
|
|
8442
|
+
// This ensures that super.include will also include all parameters
|
|
8443
|
+
if (this.scope.argumentsVariable.included) {
|
|
8444
|
+
this.alwaysIncludeParameters = true;
|
|
8355
8445
|
}
|
|
8356
|
-
|
|
8357
|
-
context
|
|
8358
|
-
this.body.include(context, includeChildrenRecursively);
|
|
8359
|
-
context.brokenFlow = brokenFlow;
|
|
8360
|
-
}
|
|
8361
|
-
includeCallArguments(context, args) {
|
|
8362
|
-
this.scope.includeCallArguments(context, args);
|
|
8446
|
+
(_a = this.id) === null || _a === void 0 ? void 0 : _a.include();
|
|
8447
|
+
super.include(context, includeChildrenRecursively);
|
|
8363
8448
|
}
|
|
8364
8449
|
initialise() {
|
|
8365
|
-
|
|
8366
|
-
|
|
8367
|
-
|
|
8368
|
-
this.scope.addParameterVariables(this.params.map(param => param.declare('parameter', UNKNOWN_EXPRESSION)), this.params[this.params.length - 1] instanceof RestElement);
|
|
8369
|
-
this.body.addImplicitReturnExpressionToScope();
|
|
8450
|
+
var _a;
|
|
8451
|
+
super.initialise();
|
|
8452
|
+
(_a = this.id) === null || _a === void 0 ? void 0 : _a.declare('function', this);
|
|
8370
8453
|
}
|
|
8371
|
-
|
|
8372
|
-
|
|
8373
|
-
|
|
8454
|
+
getObjectEntity() {
|
|
8455
|
+
if (this.objectEntity !== null) {
|
|
8456
|
+
return this.objectEntity;
|
|
8457
|
+
}
|
|
8458
|
+
return (this.objectEntity = new ObjectEntity([
|
|
8459
|
+
{
|
|
8460
|
+
key: 'prototype',
|
|
8461
|
+
kind: 'init',
|
|
8462
|
+
property: new ObjectEntity([], OBJECT_PROTOTYPE)
|
|
8463
|
+
}
|
|
8464
|
+
], OBJECT_PROTOTYPE));
|
|
8374
8465
|
}
|
|
8375
8466
|
}
|
|
8376
|
-
FunctionNode.prototype.preventChildBlockScope = true;
|
|
8377
8467
|
|
|
8378
8468
|
class AwaitExpression extends NodeBase {
|
|
8379
8469
|
constructor() {
|
|
@@ -8401,11 +8491,6 @@ class AwaitExpression extends NodeBase {
|
|
|
8401
8491
|
}
|
|
8402
8492
|
this.argument.include(context, includeChildrenRecursively);
|
|
8403
8493
|
}
|
|
8404
|
-
applyDeoptimizations() {
|
|
8405
|
-
this.deoptimized = true;
|
|
8406
|
-
this.argument.deoptimizePath(UNKNOWN_PATH);
|
|
8407
|
-
this.context.requestTreeshakingPass();
|
|
8408
|
-
}
|
|
8409
8494
|
}
|
|
8410
8495
|
|
|
8411
8496
|
const binaryOperators = {
|
|
@@ -8439,10 +8524,10 @@ class BinaryExpression extends NodeBase {
|
|
|
8439
8524
|
if (path.length > 0)
|
|
8440
8525
|
return UnknownValue;
|
|
8441
8526
|
const leftValue = this.left.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
|
|
8442
|
-
if (leftValue ===
|
|
8527
|
+
if (typeof leftValue === 'symbol')
|
|
8443
8528
|
return UnknownValue;
|
|
8444
8529
|
const rightValue = this.right.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
|
|
8445
|
-
if (rightValue ===
|
|
8530
|
+
if (typeof rightValue === 'symbol')
|
|
8446
8531
|
return UnknownValue;
|
|
8447
8532
|
const operatorFn = binaryOperators[this.operator];
|
|
8448
8533
|
if (!operatorFn)
|
|
@@ -8623,7 +8708,11 @@ class MemberExpression extends NodeBase {
|
|
|
8623
8708
|
}
|
|
8624
8709
|
else if (!this.replacement) {
|
|
8625
8710
|
if (path.length < MAX_PATH_DEPTH) {
|
|
8626
|
-
this.
|
|
8711
|
+
const propertyKey = this.getPropertyKey();
|
|
8712
|
+
this.object.deoptimizePath([
|
|
8713
|
+
propertyKey === UnknownKey ? UnknownNonAccessorKey : propertyKey,
|
|
8714
|
+
...path
|
|
8715
|
+
]);
|
|
8627
8716
|
}
|
|
8628
8717
|
}
|
|
8629
8718
|
}
|
|
@@ -8729,12 +8818,15 @@ class MemberExpression extends NodeBase {
|
|
|
8729
8818
|
this.object.include(context, includeChildrenRecursively);
|
|
8730
8819
|
this.property.include(context, includeChildrenRecursively);
|
|
8731
8820
|
}
|
|
8732
|
-
|
|
8821
|
+
includeArgumentsWhenCalledAtPath(path, context, args) {
|
|
8733
8822
|
if (this.variable) {
|
|
8734
|
-
this.variable.
|
|
8823
|
+
this.variable.includeArgumentsWhenCalledAtPath(path, context, args);
|
|
8735
8824
|
}
|
|
8736
|
-
else {
|
|
8737
|
-
super.
|
|
8825
|
+
else if (this.replacement) {
|
|
8826
|
+
super.includeArgumentsWhenCalledAtPath(path, context, args);
|
|
8827
|
+
}
|
|
8828
|
+
else if (path.length < MAX_PATH_DEPTH) {
|
|
8829
|
+
this.object.includeArgumentsWhenCalledAtPath([this.getPropertyKey(), ...path], context, args);
|
|
8738
8830
|
}
|
|
8739
8831
|
}
|
|
8740
8832
|
initialise() {
|
|
@@ -8796,7 +8888,7 @@ class MemberExpression extends NodeBase {
|
|
|
8796
8888
|
if (this.propertyKey === null) {
|
|
8797
8889
|
this.propertyKey = UnknownKey;
|
|
8798
8890
|
const value = this.property.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
|
|
8799
|
-
return (this.propertyKey = value ===
|
|
8891
|
+
return (this.propertyKey = typeof value === 'symbol' ? UnknownKey : String(value));
|
|
8800
8892
|
}
|
|
8801
8893
|
return this.propertyKey;
|
|
8802
8894
|
}
|
|
@@ -8823,39 +8915,13 @@ class MemberExpression extends NodeBase {
|
|
|
8823
8915
|
}
|
|
8824
8916
|
}
|
|
8825
8917
|
|
|
8826
|
-
class
|
|
8918
|
+
class CallExpressionBase extends NodeBase {
|
|
8827
8919
|
constructor() {
|
|
8828
8920
|
super(...arguments);
|
|
8829
8921
|
this.deoptimized = false;
|
|
8922
|
+
this.returnExpression = null;
|
|
8830
8923
|
this.deoptimizableDependentExpressions = [];
|
|
8831
8924
|
this.expressionsToBeDeoptimized = new Set();
|
|
8832
|
-
this.returnExpression = null;
|
|
8833
|
-
}
|
|
8834
|
-
bind() {
|
|
8835
|
-
super.bind();
|
|
8836
|
-
if (this.callee instanceof Identifier) {
|
|
8837
|
-
const variable = this.scope.findVariable(this.callee.name);
|
|
8838
|
-
if (variable.isNamespace) {
|
|
8839
|
-
this.context.warn({
|
|
8840
|
-
code: 'CANNOT_CALL_NAMESPACE',
|
|
8841
|
-
message: `Cannot call a namespace ('${this.callee.name}')`
|
|
8842
|
-
}, this.start);
|
|
8843
|
-
}
|
|
8844
|
-
if (this.callee.name === 'eval') {
|
|
8845
|
-
this.context.warn({
|
|
8846
|
-
code: 'EVAL',
|
|
8847
|
-
message: `Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification`,
|
|
8848
|
-
url: 'https://rollupjs.org/guide/en/#avoiding-eval'
|
|
8849
|
-
}, this.start);
|
|
8850
|
-
}
|
|
8851
|
-
}
|
|
8852
|
-
this.callOptions = {
|
|
8853
|
-
args: this.arguments,
|
|
8854
|
-
thisParam: this.callee instanceof MemberExpression && !this.callee.variable
|
|
8855
|
-
? this.callee.object
|
|
8856
|
-
: null,
|
|
8857
|
-
withNew: false
|
|
8858
|
-
};
|
|
8859
8925
|
}
|
|
8860
8926
|
deoptimizeCache() {
|
|
8861
8927
|
if (this.returnExpression !== UNKNOWN_EXPRESSION) {
|
|
@@ -8910,6 +8976,47 @@ class CallExpression extends NodeBase {
|
|
|
8910
8976
|
return returnExpression.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
|
|
8911
8977
|
}, UNKNOWN_EXPRESSION);
|
|
8912
8978
|
}
|
|
8979
|
+
hasEffectsWhenAccessedAtPath(path, context) {
|
|
8980
|
+
return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
|
|
8981
|
+
this.getReturnExpression().hasEffectsWhenAccessedAtPath(path, context));
|
|
8982
|
+
}
|
|
8983
|
+
hasEffectsWhenAssignedAtPath(path, context) {
|
|
8984
|
+
return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
|
|
8985
|
+
this.getReturnExpression().hasEffectsWhenAssignedAtPath(path, context));
|
|
8986
|
+
}
|
|
8987
|
+
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
8988
|
+
return (!(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
|
|
8989
|
+
this.getReturnExpression().hasEffectsWhenCalledAtPath(path, callOptions, context));
|
|
8990
|
+
}
|
|
8991
|
+
}
|
|
8992
|
+
|
|
8993
|
+
class CallExpression extends CallExpressionBase {
|
|
8994
|
+
bind() {
|
|
8995
|
+
super.bind();
|
|
8996
|
+
if (this.callee instanceof Identifier) {
|
|
8997
|
+
const variable = this.scope.findVariable(this.callee.name);
|
|
8998
|
+
if (variable.isNamespace) {
|
|
8999
|
+
this.context.warn({
|
|
9000
|
+
code: 'CANNOT_CALL_NAMESPACE',
|
|
9001
|
+
message: `Cannot call a namespace ('${this.callee.name}')`
|
|
9002
|
+
}, this.start);
|
|
9003
|
+
}
|
|
9004
|
+
if (this.callee.name === 'eval') {
|
|
9005
|
+
this.context.warn({
|
|
9006
|
+
code: 'EVAL',
|
|
9007
|
+
message: `Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification`,
|
|
9008
|
+
url: 'https://rollupjs.org/guide/en/#avoiding-eval'
|
|
9009
|
+
}, this.start);
|
|
9010
|
+
}
|
|
9011
|
+
}
|
|
9012
|
+
this.callOptions = {
|
|
9013
|
+
args: this.arguments,
|
|
9014
|
+
thisParam: this.callee instanceof MemberExpression && !this.callee.variable
|
|
9015
|
+
? this.callee.object
|
|
9016
|
+
: null,
|
|
9017
|
+
withNew: false
|
|
9018
|
+
};
|
|
9019
|
+
}
|
|
8913
9020
|
hasEffects(context) {
|
|
8914
9021
|
try {
|
|
8915
9022
|
for (const argument of this.arguments) {
|
|
@@ -8927,18 +9034,6 @@ class CallExpression extends NodeBase {
|
|
|
8927
9034
|
this.applyDeoptimizations();
|
|
8928
9035
|
}
|
|
8929
9036
|
}
|
|
8930
|
-
hasEffectsWhenAccessedAtPath(path, context) {
|
|
8931
|
-
return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
|
|
8932
|
-
this.getReturnExpression().hasEffectsWhenAccessedAtPath(path, context));
|
|
8933
|
-
}
|
|
8934
|
-
hasEffectsWhenAssignedAtPath(path, context) {
|
|
8935
|
-
return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
|
|
8936
|
-
this.getReturnExpression().hasEffectsWhenAssignedAtPath(path, context));
|
|
8937
|
-
}
|
|
8938
|
-
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
8939
|
-
return (!(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
|
|
8940
|
-
this.getReturnExpression().hasEffectsWhenCalledAtPath(path, callOptions, context));
|
|
8941
|
-
}
|
|
8942
9037
|
include(context, includeChildrenRecursively) {
|
|
8943
9038
|
if (!this.deoptimized)
|
|
8944
9039
|
this.applyDeoptimizations();
|
|
@@ -8954,7 +9049,7 @@ class CallExpression extends NodeBase {
|
|
|
8954
9049
|
this.included = true;
|
|
8955
9050
|
this.callee.include(context, false);
|
|
8956
9051
|
}
|
|
8957
|
-
this.callee.
|
|
9052
|
+
this.callee.includeArgumentsWhenCalledAtPath(EMPTY_PATH, context, this.arguments);
|
|
8958
9053
|
const returnExpression = this.getReturnExpression();
|
|
8959
9054
|
if (!returnExpression.included) {
|
|
8960
9055
|
returnExpression.include(context, false);
|
|
@@ -9125,6 +9220,9 @@ class MethodBase extends NodeBase {
|
|
|
9125
9220
|
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
9126
9221
|
return this.getAccessedValue().hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
9127
9222
|
}
|
|
9223
|
+
includeArgumentsWhenCalledAtPath(path, context, args) {
|
|
9224
|
+
this.getAccessedValue().includeArgumentsWhenCalledAtPath(path, context, args);
|
|
9225
|
+
}
|
|
9128
9226
|
getAccessedValue() {
|
|
9129
9227
|
if (this.accessedValue === null) {
|
|
9130
9228
|
if (this.kind === 'get') {
|
|
@@ -9161,8 +9259,6 @@ class ObjectMember extends ExpressionEntity {
|
|
|
9161
9259
|
return this.object.getReturnExpressionWhenCalledAtPath([this.key, ...path], callOptions, recursionTracker, origin);
|
|
9162
9260
|
}
|
|
9163
9261
|
hasEffectsWhenAccessedAtPath(path, context) {
|
|
9164
|
-
if (path.length === 0)
|
|
9165
|
-
return false;
|
|
9166
9262
|
return this.object.hasEffectsWhenAccessedAtPath([this.key, ...path], context);
|
|
9167
9263
|
}
|
|
9168
9264
|
hasEffectsWhenAssignedAtPath(path, context) {
|
|
@@ -9176,6 +9272,7 @@ class ObjectMember extends ExpressionEntity {
|
|
|
9176
9272
|
class ClassNode extends NodeBase {
|
|
9177
9273
|
constructor() {
|
|
9178
9274
|
super(...arguments);
|
|
9275
|
+
this.deoptimized = false;
|
|
9179
9276
|
this.objectEntity = null;
|
|
9180
9277
|
}
|
|
9181
9278
|
createScope(parentScope) {
|
|
@@ -9185,7 +9282,14 @@ class ClassNode extends NodeBase {
|
|
|
9185
9282
|
this.getObjectEntity().deoptimizeAllProperties();
|
|
9186
9283
|
}
|
|
9187
9284
|
deoptimizePath(path) {
|
|
9285
|
+
var _a, _b;
|
|
9188
9286
|
this.getObjectEntity().deoptimizePath(path);
|
|
9287
|
+
if (path.length === 1 && path[0] === UnknownKey) {
|
|
9288
|
+
// A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
|
|
9289
|
+
// which means the constructor needs to be reassigned
|
|
9290
|
+
(_a = this.classConstructor) === null || _a === void 0 ? void 0 : _a.deoptimizePath(UNKNOWN_PATH);
|
|
9291
|
+
(_b = this.superClass) === null || _b === void 0 ? void 0 : _b.deoptimizePath(UNKNOWN_PATH);
|
|
9292
|
+
}
|
|
9189
9293
|
}
|
|
9190
9294
|
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
9191
9295
|
this.getObjectEntity().deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
@@ -9198,6 +9302,8 @@ class ClassNode extends NodeBase {
|
|
|
9198
9302
|
}
|
|
9199
9303
|
hasEffects(context) {
|
|
9200
9304
|
var _a, _b;
|
|
9305
|
+
if (!this.deoptimized)
|
|
9306
|
+
this.applyDeoptimizations();
|
|
9201
9307
|
const initEffect = ((_a = this.superClass) === null || _a === void 0 ? void 0 : _a.hasEffects(context)) || this.body.hasEffects(context);
|
|
9202
9308
|
(_b = this.id) === null || _b === void 0 ? void 0 : _b.markDeclarationReached();
|
|
9203
9309
|
return initEffect || super.hasEffects(context);
|
|
@@ -9209,12 +9315,13 @@ class ClassNode extends NodeBase {
|
|
|
9209
9315
|
return this.getObjectEntity().hasEffectsWhenAssignedAtPath(path, context);
|
|
9210
9316
|
}
|
|
9211
9317
|
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
9318
|
+
var _a;
|
|
9212
9319
|
if (path.length === 0) {
|
|
9213
9320
|
return (!callOptions.withNew ||
|
|
9214
9321
|
(this.classConstructor !== null
|
|
9215
9322
|
? this.classConstructor.hasEffectsWhenCalledAtPath(EMPTY_PATH, callOptions, context)
|
|
9216
|
-
: this.superClass
|
|
9217
|
-
|
|
9323
|
+
: (_a = this.superClass) === null || _a === void 0 ? void 0 : _a.hasEffectsWhenCalledAtPath(path, callOptions, context)) ||
|
|
9324
|
+
false);
|
|
9218
9325
|
}
|
|
9219
9326
|
else {
|
|
9220
9327
|
return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
@@ -9222,6 +9329,8 @@ class ClassNode extends NodeBase {
|
|
|
9222
9329
|
}
|
|
9223
9330
|
include(context, includeChildrenRecursively) {
|
|
9224
9331
|
var _a;
|
|
9332
|
+
if (!this.deoptimized)
|
|
9333
|
+
this.applyDeoptimizations();
|
|
9225
9334
|
this.included = true;
|
|
9226
9335
|
(_a = this.superClass) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
|
|
9227
9336
|
this.body.include(context, includeChildrenRecursively);
|
|
@@ -9230,6 +9339,20 @@ class ClassNode extends NodeBase {
|
|
|
9230
9339
|
this.id.include();
|
|
9231
9340
|
}
|
|
9232
9341
|
}
|
|
9342
|
+
includeArgumentsWhenCalledAtPath(path, context, args) {
|
|
9343
|
+
var _a;
|
|
9344
|
+
if (path.length === 0) {
|
|
9345
|
+
if (this.classConstructor) {
|
|
9346
|
+
this.classConstructor.includeArgumentsWhenCalledAtPath(path, context, args);
|
|
9347
|
+
}
|
|
9348
|
+
else {
|
|
9349
|
+
(_a = this.superClass) === null || _a === void 0 ? void 0 : _a.includeArgumentsWhenCalledAtPath(path, context, args);
|
|
9350
|
+
}
|
|
9351
|
+
}
|
|
9352
|
+
else {
|
|
9353
|
+
this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
|
|
9354
|
+
}
|
|
9355
|
+
}
|
|
9233
9356
|
initialise() {
|
|
9234
9357
|
var _a;
|
|
9235
9358
|
(_a = this.id) === null || _a === void 0 ? void 0 : _a.declare('class', this);
|
|
@@ -9241,6 +9364,18 @@ class ClassNode extends NodeBase {
|
|
|
9241
9364
|
}
|
|
9242
9365
|
this.classConstructor = null;
|
|
9243
9366
|
}
|
|
9367
|
+
applyDeoptimizations() {
|
|
9368
|
+
this.deoptimized = true;
|
|
9369
|
+
for (const definition of this.body.body) {
|
|
9370
|
+
if (!(definition.static ||
|
|
9371
|
+
(definition instanceof MethodDefinition && definition.kind === 'constructor'))) {
|
|
9372
|
+
// Calls to methods are not tracked, ensure that parameter defaults are
|
|
9373
|
+
// included and the return value is deoptimized
|
|
9374
|
+
definition.deoptimizePath(UNKNOWN_PATH);
|
|
9375
|
+
}
|
|
9376
|
+
}
|
|
9377
|
+
this.context.requestTreeshakingPass();
|
|
9378
|
+
}
|
|
9244
9379
|
getObjectEntity() {
|
|
9245
9380
|
if (this.objectEntity !== null) {
|
|
9246
9381
|
return this.objectEntity;
|
|
@@ -9257,7 +9392,7 @@ class ClassNode extends NodeBase {
|
|
|
9257
9392
|
let key;
|
|
9258
9393
|
if (definition.computed) {
|
|
9259
9394
|
const keyValue = definition.key.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
|
|
9260
|
-
if (keyValue ===
|
|
9395
|
+
if (typeof keyValue === 'symbol') {
|
|
9261
9396
|
properties.push({ key: UnknownKey, kind, property: definition });
|
|
9262
9397
|
continue;
|
|
9263
9398
|
}
|
|
@@ -9453,14 +9588,14 @@ class ConditionalExpression extends NodeBase {
|
|
|
9453
9588
|
usedBranch.include(context, includeChildrenRecursively);
|
|
9454
9589
|
}
|
|
9455
9590
|
}
|
|
9456
|
-
|
|
9591
|
+
includeArgumentsWhenCalledAtPath(path, context, args) {
|
|
9457
9592
|
const usedBranch = this.getUsedBranch();
|
|
9458
9593
|
if (usedBranch === null) {
|
|
9459
|
-
this.consequent.
|
|
9460
|
-
this.alternate.
|
|
9594
|
+
this.consequent.includeArgumentsWhenCalledAtPath(path, context, args);
|
|
9595
|
+
this.alternate.includeArgumentsWhenCalledAtPath(path, context, args);
|
|
9461
9596
|
}
|
|
9462
9597
|
else {
|
|
9463
|
-
usedBranch.
|
|
9598
|
+
usedBranch.includeArgumentsWhenCalledAtPath(path, context, args);
|
|
9464
9599
|
}
|
|
9465
9600
|
}
|
|
9466
9601
|
render(code, options, { isCalleeOfRenderedParent, preventASI, renderedParentType, renderedSurroundingElement } = BLANK) {
|
|
@@ -9497,7 +9632,7 @@ class ConditionalExpression extends NodeBase {
|
|
|
9497
9632
|
}
|
|
9498
9633
|
this.isBranchResolutionAnalysed = true;
|
|
9499
9634
|
const testValue = this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
|
|
9500
|
-
return testValue ===
|
|
9635
|
+
return typeof testValue === 'symbol'
|
|
9501
9636
|
? null
|
|
9502
9637
|
: (this.usedBranch = testValue ? this.consequent : this.alternate);
|
|
9503
9638
|
}
|
|
@@ -9546,7 +9681,7 @@ class DoWhileStatement extends NodeBase {
|
|
|
9546
9681
|
this.included = true;
|
|
9547
9682
|
this.test.include(context, includeChildrenRecursively);
|
|
9548
9683
|
const { brokenFlow } = context;
|
|
9549
|
-
this.body.
|
|
9684
|
+
this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
|
|
9550
9685
|
context.brokenFlow = brokenFlow;
|
|
9551
9686
|
}
|
|
9552
9687
|
}
|
|
@@ -9674,12 +9809,13 @@ ExportDefaultDeclaration.prototype.needsBoundaries = true;
|
|
|
9674
9809
|
|
|
9675
9810
|
class ExportNamedDeclaration extends NodeBase {
|
|
9676
9811
|
bind() {
|
|
9812
|
+
var _a;
|
|
9677
9813
|
// Do not bind specifiers
|
|
9678
|
-
|
|
9679
|
-
this.declaration.bind();
|
|
9814
|
+
(_a = this.declaration) === null || _a === void 0 ? void 0 : _a.bind();
|
|
9680
9815
|
}
|
|
9681
9816
|
hasEffects(context) {
|
|
9682
|
-
|
|
9817
|
+
var _a;
|
|
9818
|
+
return (_a = this.declaration) === null || _a === void 0 ? void 0 : _a.hasEffects(context);
|
|
9683
9819
|
}
|
|
9684
9820
|
initialise() {
|
|
9685
9821
|
this.context.addExport(this);
|
|
@@ -9733,7 +9869,7 @@ class ForInStatement extends NodeBase {
|
|
|
9733
9869
|
this.left.include(context, includeChildrenRecursively || true);
|
|
9734
9870
|
this.right.include(context, includeChildrenRecursively);
|
|
9735
9871
|
const { brokenFlow } = context;
|
|
9736
|
-
this.body.
|
|
9872
|
+
this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
|
|
9737
9873
|
context.brokenFlow = brokenFlow;
|
|
9738
9874
|
}
|
|
9739
9875
|
render(code, options) {
|
|
@@ -9773,7 +9909,7 @@ class ForOfStatement extends NodeBase {
|
|
|
9773
9909
|
this.left.include(context, includeChildrenRecursively || true);
|
|
9774
9910
|
this.right.include(context, includeChildrenRecursively);
|
|
9775
9911
|
const { brokenFlow } = context;
|
|
9776
|
-
this.body.
|
|
9912
|
+
this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
|
|
9777
9913
|
context.brokenFlow = brokenFlow;
|
|
9778
9914
|
}
|
|
9779
9915
|
render(code, options) {
|
|
@@ -9797,9 +9933,10 @@ class ForStatement extends NodeBase {
|
|
|
9797
9933
|
this.scope = new BlockScope(parentScope);
|
|
9798
9934
|
}
|
|
9799
9935
|
hasEffects(context) {
|
|
9800
|
-
|
|
9801
|
-
|
|
9802
|
-
(this.
|
|
9936
|
+
var _a, _b, _c;
|
|
9937
|
+
if (((_a = this.init) === null || _a === void 0 ? void 0 : _a.hasEffects(context)) ||
|
|
9938
|
+
((_b = this.test) === null || _b === void 0 ? void 0 : _b.hasEffects(context)) ||
|
|
9939
|
+
((_c = this.update) === null || _c === void 0 ? void 0 : _c.hasEffects(context)))
|
|
9803
9940
|
return true;
|
|
9804
9941
|
const { brokenFlow, ignore: { breaks, continues } } = context;
|
|
9805
9942
|
context.ignore.breaks = true;
|
|
@@ -9812,24 +9949,20 @@ class ForStatement extends NodeBase {
|
|
|
9812
9949
|
return false;
|
|
9813
9950
|
}
|
|
9814
9951
|
include(context, includeChildrenRecursively) {
|
|
9952
|
+
var _a, _b, _c;
|
|
9815
9953
|
this.included = true;
|
|
9816
|
-
|
|
9817
|
-
|
|
9818
|
-
if (this.test)
|
|
9819
|
-
this.test.include(context, includeChildrenRecursively);
|
|
9954
|
+
(_a = this.init) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively, { asSingleStatement: true });
|
|
9955
|
+
(_b = this.test) === null || _b === void 0 ? void 0 : _b.include(context, includeChildrenRecursively);
|
|
9820
9956
|
const { brokenFlow } = context;
|
|
9821
|
-
|
|
9822
|
-
|
|
9823
|
-
this.body.includeAsSingleStatement(context, includeChildrenRecursively);
|
|
9957
|
+
(_c = this.update) === null || _c === void 0 ? void 0 : _c.include(context, includeChildrenRecursively);
|
|
9958
|
+
this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
|
|
9824
9959
|
context.brokenFlow = brokenFlow;
|
|
9825
9960
|
}
|
|
9826
9961
|
render(code, options) {
|
|
9827
|
-
|
|
9828
|
-
|
|
9829
|
-
|
|
9830
|
-
|
|
9831
|
-
if (this.update)
|
|
9832
|
-
this.update.render(code, options, NO_SEMICOLON);
|
|
9962
|
+
var _a, _b, _c;
|
|
9963
|
+
(_a = this.init) === null || _a === void 0 ? void 0 : _a.render(code, options, NO_SEMICOLON);
|
|
9964
|
+
(_b = this.test) === null || _b === void 0 ? void 0 : _b.render(code, options, NO_SEMICOLON);
|
|
9965
|
+
(_c = this.update) === null || _c === void 0 ? void 0 : _c.render(code, options, NO_SEMICOLON);
|
|
9833
9966
|
this.body.render(code, options);
|
|
9834
9967
|
}
|
|
9835
9968
|
}
|
|
@@ -9865,11 +9998,12 @@ class IfStatement extends NodeBase {
|
|
|
9865
9998
|
this.testValue = UnknownValue;
|
|
9866
9999
|
}
|
|
9867
10000
|
hasEffects(context) {
|
|
10001
|
+
var _a;
|
|
9868
10002
|
if (this.test.hasEffects(context)) {
|
|
9869
10003
|
return true;
|
|
9870
10004
|
}
|
|
9871
10005
|
const testValue = this.getTestValue();
|
|
9872
|
-
if (testValue ===
|
|
10006
|
+
if (typeof testValue === 'symbol') {
|
|
9873
10007
|
const { brokenFlow } = context;
|
|
9874
10008
|
if (this.consequent.hasEffects(context))
|
|
9875
10009
|
return true;
|
|
@@ -9883,9 +10017,7 @@ class IfStatement extends NodeBase {
|
|
|
9883
10017
|
context.brokenFlow < consequentBrokenFlow ? context.brokenFlow : consequentBrokenFlow;
|
|
9884
10018
|
return false;
|
|
9885
10019
|
}
|
|
9886
|
-
return testValue
|
|
9887
|
-
? this.consequent.hasEffects(context)
|
|
9888
|
-
: this.alternate !== null && this.alternate.hasEffects(context);
|
|
10020
|
+
return testValue ? this.consequent.hasEffects(context) : (_a = this.alternate) === null || _a === void 0 ? void 0 : _a.hasEffects(context);
|
|
9889
10021
|
}
|
|
9890
10022
|
include(context, includeChildrenRecursively) {
|
|
9891
10023
|
this.included = true;
|
|
@@ -9894,7 +10026,7 @@ class IfStatement extends NodeBase {
|
|
|
9894
10026
|
}
|
|
9895
10027
|
else {
|
|
9896
10028
|
const testValue = this.getTestValue();
|
|
9897
|
-
if (testValue ===
|
|
10029
|
+
if (typeof testValue === 'symbol') {
|
|
9898
10030
|
this.includeUnknownTest(context);
|
|
9899
10031
|
}
|
|
9900
10032
|
else {
|
|
@@ -9924,7 +10056,7 @@ class IfStatement extends NodeBase {
|
|
|
9924
10056
|
else {
|
|
9925
10057
|
code.remove(this.start, this.consequent.start);
|
|
9926
10058
|
}
|
|
9927
|
-
if (this.consequent.included && (noTreeshake || testValue ===
|
|
10059
|
+
if (this.consequent.included && (noTreeshake || typeof testValue === 'symbol' || testValue)) {
|
|
9928
10060
|
this.consequent.render(code, options);
|
|
9929
10061
|
}
|
|
9930
10062
|
else {
|
|
@@ -9932,7 +10064,7 @@ class IfStatement extends NodeBase {
|
|
|
9932
10064
|
hoistedDeclarations.push(...this.consequentScope.hoistedDeclarations);
|
|
9933
10065
|
}
|
|
9934
10066
|
if (this.alternate) {
|
|
9935
|
-
if (this.alternate.included && (noTreeshake || testValue ===
|
|
10067
|
+
if (this.alternate.included && (noTreeshake || typeof testValue === 'symbol' || !testValue)) {
|
|
9936
10068
|
if (includesIfElse) {
|
|
9937
10069
|
if (code.original.charCodeAt(this.alternate.start - 1) === 101) {
|
|
9938
10070
|
code.prependLeft(this.alternate.start, ' ');
|
|
@@ -9962,34 +10094,35 @@ class IfStatement extends NodeBase {
|
|
|
9962
10094
|
return this.testValue;
|
|
9963
10095
|
}
|
|
9964
10096
|
includeKnownTest(context, testValue) {
|
|
10097
|
+
var _a;
|
|
9965
10098
|
if (this.test.shouldBeIncluded(context)) {
|
|
9966
10099
|
this.test.include(context, false);
|
|
9967
10100
|
}
|
|
9968
10101
|
if (testValue && this.consequent.shouldBeIncluded(context)) {
|
|
9969
|
-
this.consequent.
|
|
10102
|
+
this.consequent.include(context, false, { asSingleStatement: true });
|
|
9970
10103
|
}
|
|
9971
|
-
if (this.alternate
|
|
9972
|
-
this.alternate.
|
|
10104
|
+
if (!testValue && ((_a = this.alternate) === null || _a === void 0 ? void 0 : _a.shouldBeIncluded(context))) {
|
|
10105
|
+
this.alternate.include(context, false, { asSingleStatement: true });
|
|
9973
10106
|
}
|
|
9974
10107
|
}
|
|
9975
10108
|
includeRecursively(includeChildrenRecursively, context) {
|
|
10109
|
+
var _a;
|
|
9976
10110
|
this.test.include(context, includeChildrenRecursively);
|
|
9977
10111
|
this.consequent.include(context, includeChildrenRecursively);
|
|
9978
|
-
|
|
9979
|
-
this.alternate.include(context, includeChildrenRecursively);
|
|
9980
|
-
}
|
|
10112
|
+
(_a = this.alternate) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
|
|
9981
10113
|
}
|
|
9982
10114
|
includeUnknownTest(context) {
|
|
10115
|
+
var _a;
|
|
9983
10116
|
this.test.include(context, false);
|
|
9984
10117
|
const { brokenFlow } = context;
|
|
9985
10118
|
let consequentBrokenFlow = BROKEN_FLOW_NONE;
|
|
9986
10119
|
if (this.consequent.shouldBeIncluded(context)) {
|
|
9987
|
-
this.consequent.
|
|
10120
|
+
this.consequent.include(context, false, { asSingleStatement: true });
|
|
9988
10121
|
consequentBrokenFlow = context.brokenFlow;
|
|
9989
10122
|
context.brokenFlow = brokenFlow;
|
|
9990
10123
|
}
|
|
9991
|
-
if (this.alternate
|
|
9992
|
-
this.alternate.
|
|
10124
|
+
if ((_a = this.alternate) === null || _a === void 0 ? void 0 : _a.shouldBeIncluded(context)) {
|
|
10125
|
+
this.alternate.include(context, false, { asSingleStatement: true });
|
|
9993
10126
|
context.brokenFlow =
|
|
9994
10127
|
context.brokenFlow < consequentBrokenFlow ? context.brokenFlow : consequentBrokenFlow;
|
|
9995
10128
|
}
|
|
@@ -10576,7 +10709,7 @@ class LogicalExpression extends NodeBase {
|
|
|
10576
10709
|
if (!this.isBranchResolutionAnalysed) {
|
|
10577
10710
|
this.isBranchResolutionAnalysed = true;
|
|
10578
10711
|
const leftValue = this.left.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
|
|
10579
|
-
if (leftValue ===
|
|
10712
|
+
if (typeof leftValue === 'symbol') {
|
|
10580
10713
|
return null;
|
|
10581
10714
|
}
|
|
10582
10715
|
else {
|
|
@@ -10762,21 +10895,32 @@ class NewExpression extends NodeBase {
|
|
|
10762
10895
|
this.deoptimized = false;
|
|
10763
10896
|
}
|
|
10764
10897
|
hasEffects(context) {
|
|
10765
|
-
|
|
10766
|
-
this.
|
|
10767
|
-
|
|
10768
|
-
|
|
10769
|
-
|
|
10898
|
+
try {
|
|
10899
|
+
for (const argument of this.arguments) {
|
|
10900
|
+
if (argument.hasEffects(context))
|
|
10901
|
+
return true;
|
|
10902
|
+
}
|
|
10903
|
+
if (this.context.options.treeshake.annotations &&
|
|
10904
|
+
this.annotations)
|
|
10905
|
+
return false;
|
|
10906
|
+
return (this.callee.hasEffects(context) ||
|
|
10907
|
+
this.callee.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
|
|
10908
|
+
}
|
|
10909
|
+
finally {
|
|
10910
|
+
if (!this.deoptimized)
|
|
10911
|
+
this.applyDeoptimizations();
|
|
10770
10912
|
}
|
|
10771
|
-
if (this.context.options.treeshake.annotations &&
|
|
10772
|
-
this.annotations)
|
|
10773
|
-
return false;
|
|
10774
|
-
return (this.callee.hasEffects(context) ||
|
|
10775
|
-
this.callee.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
|
|
10776
10913
|
}
|
|
10777
10914
|
hasEffectsWhenAccessedAtPath(path) {
|
|
10778
10915
|
return path.length > 0;
|
|
10779
10916
|
}
|
|
10917
|
+
include(context, includeChildrenRecursively) {
|
|
10918
|
+
if (!this.deoptimized)
|
|
10919
|
+
this.applyDeoptimizations();
|
|
10920
|
+
this.included = true;
|
|
10921
|
+
this.callee.include(context, includeChildrenRecursively);
|
|
10922
|
+
this.callee.includeArgumentsWhenCalledAtPath(EMPTY_PATH, context, this.arguments);
|
|
10923
|
+
}
|
|
10780
10924
|
initialise() {
|
|
10781
10925
|
this.callOptions = {
|
|
10782
10926
|
args: this.arguments,
|
|
@@ -10823,6 +10967,9 @@ class ObjectExpression extends NodeBase {
|
|
|
10823
10967
|
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
10824
10968
|
return this.getObjectEntity().hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
10825
10969
|
}
|
|
10970
|
+
includeArgumentsWhenCalledAtPath(path, context, args) {
|
|
10971
|
+
this.getObjectEntity().includeArgumentsWhenCalledAtPath(path, context, args);
|
|
10972
|
+
}
|
|
10826
10973
|
render(code, options, { renderedSurroundingElement } = BLANK) {
|
|
10827
10974
|
super.render(code, options);
|
|
10828
10975
|
if (renderedSurroundingElement === ExpressionStatement$1 ||
|
|
@@ -10845,7 +10992,7 @@ class ObjectExpression extends NodeBase {
|
|
|
10845
10992
|
let key;
|
|
10846
10993
|
if (property.computed) {
|
|
10847
10994
|
const keyValue = property.key.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this);
|
|
10848
|
-
if (keyValue ===
|
|
10995
|
+
if (typeof keyValue === 'symbol') {
|
|
10849
10996
|
properties.push({ key: UnknownKey, kind: property.kind, property });
|
|
10850
10997
|
continue;
|
|
10851
10998
|
}
|
|
@@ -10966,8 +11113,8 @@ class PropertyDefinition extends NodeBase {
|
|
|
10966
11113
|
: UNKNOWN_EXPRESSION;
|
|
10967
11114
|
}
|
|
10968
11115
|
hasEffects(context) {
|
|
10969
|
-
|
|
10970
|
-
|
|
11116
|
+
var _a;
|
|
11117
|
+
return this.key.hasEffects(context) || (this.static && ((_a = this.value) === null || _a === void 0 ? void 0 : _a.hasEffects(context)));
|
|
10971
11118
|
}
|
|
10972
11119
|
hasEffectsWhenAccessedAtPath(path, context) {
|
|
10973
11120
|
return !this.value || this.value.hasEffectsWhenAccessedAtPath(path, context);
|
|
@@ -10978,21 +11125,24 @@ class PropertyDefinition extends NodeBase {
|
|
|
10978
11125
|
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
10979
11126
|
return !this.value || this.value.hasEffectsWhenCalledAtPath(path, callOptions, context);
|
|
10980
11127
|
}
|
|
11128
|
+
includeArgumentsWhenCalledAtPath(path, context, args) {
|
|
11129
|
+
var _a;
|
|
11130
|
+
(_a = this.value) === null || _a === void 0 ? void 0 : _a.includeArgumentsWhenCalledAtPath(path, context, args);
|
|
11131
|
+
}
|
|
10981
11132
|
}
|
|
10982
11133
|
|
|
10983
11134
|
class ReturnStatement extends NodeBase {
|
|
10984
11135
|
hasEffects(context) {
|
|
10985
|
-
|
|
10986
|
-
|
|
11136
|
+
var _a;
|
|
11137
|
+
if (!context.ignore.returnYield || ((_a = this.argument) === null || _a === void 0 ? void 0 : _a.hasEffects(context)))
|
|
10987
11138
|
return true;
|
|
10988
11139
|
context.brokenFlow = BROKEN_FLOW_ERROR_RETURN_LABEL;
|
|
10989
11140
|
return false;
|
|
10990
11141
|
}
|
|
10991
11142
|
include(context, includeChildrenRecursively) {
|
|
11143
|
+
var _a;
|
|
10992
11144
|
this.included = true;
|
|
10993
|
-
|
|
10994
|
-
this.argument.include(context, includeChildrenRecursively);
|
|
10995
|
-
}
|
|
11145
|
+
(_a = this.argument) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
|
|
10996
11146
|
context.brokenFlow = BROKEN_FLOW_ERROR_RETURN_LABEL;
|
|
10997
11147
|
}
|
|
10998
11148
|
initialise() {
|
|
@@ -11112,6 +11262,9 @@ class Super extends NodeBase {
|
|
|
11112
11262
|
deoptimizePath(path) {
|
|
11113
11263
|
this.variable.deoptimizePath(path);
|
|
11114
11264
|
}
|
|
11265
|
+
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
11266
|
+
this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
11267
|
+
}
|
|
11115
11268
|
include() {
|
|
11116
11269
|
if (!this.included) {
|
|
11117
11270
|
this.included = true;
|
|
@@ -11122,7 +11275,8 @@ class Super extends NodeBase {
|
|
|
11122
11275
|
|
|
11123
11276
|
class SwitchCase extends NodeBase {
|
|
11124
11277
|
hasEffects(context) {
|
|
11125
|
-
|
|
11278
|
+
var _a;
|
|
11279
|
+
if ((_a = this.test) === null || _a === void 0 ? void 0 : _a.hasEffects(context))
|
|
11126
11280
|
return true;
|
|
11127
11281
|
for (const node of this.consequent) {
|
|
11128
11282
|
if (context.brokenFlow)
|
|
@@ -11133,9 +11287,9 @@ class SwitchCase extends NodeBase {
|
|
|
11133
11287
|
return false;
|
|
11134
11288
|
}
|
|
11135
11289
|
include(context, includeChildrenRecursively) {
|
|
11290
|
+
var _a;
|
|
11136
11291
|
this.included = true;
|
|
11137
|
-
|
|
11138
|
-
this.test.include(context, includeChildrenRecursively);
|
|
11292
|
+
(_a = this.test) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
|
|
11139
11293
|
for (const node of this.consequent) {
|
|
11140
11294
|
if (includeChildrenRecursively || node.shouldBeIncluded(context))
|
|
11141
11295
|
node.include(context, includeChildrenRecursively);
|
|
@@ -11228,7 +11382,7 @@ class SwitchStatement extends NodeBase {
|
|
|
11228
11382
|
}
|
|
11229
11383
|
}
|
|
11230
11384
|
|
|
11231
|
-
class TaggedTemplateExpression extends
|
|
11385
|
+
class TaggedTemplateExpression extends CallExpressionBase {
|
|
11232
11386
|
bind() {
|
|
11233
11387
|
super.bind();
|
|
11234
11388
|
if (this.tag.type === Identifier$1) {
|
|
@@ -11243,13 +11397,35 @@ class TaggedTemplateExpression extends NodeBase {
|
|
|
11243
11397
|
}
|
|
11244
11398
|
}
|
|
11245
11399
|
hasEffects(context) {
|
|
11246
|
-
|
|
11247
|
-
|
|
11400
|
+
try {
|
|
11401
|
+
for (const argument of this.quasi.expressions) {
|
|
11402
|
+
if (argument.hasEffects(context))
|
|
11403
|
+
return true;
|
|
11404
|
+
}
|
|
11405
|
+
return (this.tag.hasEffects(context) ||
|
|
11406
|
+
this.tag.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context));
|
|
11407
|
+
}
|
|
11408
|
+
finally {
|
|
11409
|
+
if (!this.deoptimized)
|
|
11410
|
+
this.applyDeoptimizations();
|
|
11411
|
+
}
|
|
11412
|
+
}
|
|
11413
|
+
include(context, includeChildrenRecursively) {
|
|
11414
|
+
if (!this.deoptimized)
|
|
11415
|
+
this.applyDeoptimizations();
|
|
11416
|
+
this.included = true;
|
|
11417
|
+
this.tag.include(context, includeChildrenRecursively);
|
|
11418
|
+
this.quasi.include(context, includeChildrenRecursively);
|
|
11419
|
+
this.tag.includeArgumentsWhenCalledAtPath(EMPTY_PATH, context, this.callOptions.args);
|
|
11420
|
+
const returnExpression = this.getReturnExpression();
|
|
11421
|
+
if (!returnExpression.included) {
|
|
11422
|
+
returnExpression.include(context, false);
|
|
11423
|
+
}
|
|
11248
11424
|
}
|
|
11249
11425
|
initialise() {
|
|
11250
11426
|
this.callOptions = {
|
|
11251
|
-
args:
|
|
11252
|
-
thisParam: null,
|
|
11427
|
+
args: [UNKNOWN_EXPRESSION, ...this.quasi.expressions],
|
|
11428
|
+
thisParam: this.tag instanceof MemberExpression && !this.tag.variable ? this.tag.object : null,
|
|
11253
11429
|
withNew: false
|
|
11254
11430
|
};
|
|
11255
11431
|
}
|
|
@@ -11257,6 +11433,25 @@ class TaggedTemplateExpression extends NodeBase {
|
|
|
11257
11433
|
this.tag.render(code, options, { isCalleeOfRenderedParent: true });
|
|
11258
11434
|
this.quasi.render(code, options);
|
|
11259
11435
|
}
|
|
11436
|
+
applyDeoptimizations() {
|
|
11437
|
+
this.deoptimized = true;
|
|
11438
|
+
const { thisParam } = this.callOptions;
|
|
11439
|
+
if (thisParam) {
|
|
11440
|
+
this.tag.deoptimizeThisOnEventAtPath(EVENT_CALLED, EMPTY_PATH, thisParam, SHARED_RECURSION_TRACKER);
|
|
11441
|
+
}
|
|
11442
|
+
for (const argument of this.quasi.expressions) {
|
|
11443
|
+
// This will make sure all properties of parameters behave as "unknown"
|
|
11444
|
+
argument.deoptimizePath(UNKNOWN_PATH);
|
|
11445
|
+
}
|
|
11446
|
+
this.context.requestTreeshakingPass();
|
|
11447
|
+
}
|
|
11448
|
+
getReturnExpression(recursionTracker = SHARED_RECURSION_TRACKER) {
|
|
11449
|
+
if (this.returnExpression === null) {
|
|
11450
|
+
this.returnExpression = UNKNOWN_EXPRESSION;
|
|
11451
|
+
return (this.returnExpression = this.tag.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.callOptions, recursionTracker, this));
|
|
11452
|
+
}
|
|
11453
|
+
return this.returnExpression;
|
|
11454
|
+
}
|
|
11260
11455
|
}
|
|
11261
11456
|
|
|
11262
11457
|
class TemplateElement extends NodeBase {
|
|
@@ -11468,13 +11663,15 @@ class TryStatement extends NodeBase {
|
|
|
11468
11663
|
this.includedLabelsAfterBlock = null;
|
|
11469
11664
|
}
|
|
11470
11665
|
hasEffects(context) {
|
|
11666
|
+
var _a;
|
|
11471
11667
|
return ((this.context.options.treeshake.tryCatchDeoptimization
|
|
11472
11668
|
? this.block.body.length > 0
|
|
11473
11669
|
: this.block.hasEffects(context)) ||
|
|
11474
|
-
(this.finalizer
|
|
11670
|
+
((_a = this.finalizer) === null || _a === void 0 ? void 0 : _a.hasEffects(context)) ||
|
|
11671
|
+
false);
|
|
11475
11672
|
}
|
|
11476
11673
|
include(context, includeChildrenRecursively) {
|
|
11477
|
-
var _a;
|
|
11674
|
+
var _a, _b;
|
|
11478
11675
|
const tryCatchDeoptimization = (_a = this.context.options.treeshake) === null || _a === void 0 ? void 0 : _a.tryCatchDeoptimization;
|
|
11479
11676
|
const { brokenFlow } = context;
|
|
11480
11677
|
if (!this.directlyIncluded || !tryCatchDeoptimization) {
|
|
@@ -11495,9 +11692,7 @@ class TryStatement extends NodeBase {
|
|
|
11495
11692
|
this.handler.include(context, includeChildrenRecursively);
|
|
11496
11693
|
context.brokenFlow = brokenFlow;
|
|
11497
11694
|
}
|
|
11498
|
-
|
|
11499
|
-
this.finalizer.include(context, includeChildrenRecursively);
|
|
11500
|
-
}
|
|
11695
|
+
(_b = this.finalizer) === null || _b === void 0 ? void 0 : _b.include(context, includeChildrenRecursively);
|
|
11501
11696
|
}
|
|
11502
11697
|
}
|
|
11503
11698
|
|
|
@@ -11519,7 +11714,7 @@ class UnaryExpression extends NodeBase {
|
|
|
11519
11714
|
if (path.length > 0)
|
|
11520
11715
|
return UnknownValue;
|
|
11521
11716
|
const argumentValue = this.argument.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
|
|
11522
|
-
if (argumentValue ===
|
|
11717
|
+
if (typeof argumentValue === 'symbol')
|
|
11523
11718
|
return UnknownValue;
|
|
11524
11719
|
return unaryOperators[this.operator](argumentValue);
|
|
11525
11720
|
}
|
|
@@ -11633,18 +11828,12 @@ class VariableDeclaration extends NodeBase {
|
|
|
11633
11828
|
hasEffectsWhenAssignedAtPath() {
|
|
11634
11829
|
return false;
|
|
11635
11830
|
}
|
|
11636
|
-
include(context, includeChildrenRecursively) {
|
|
11831
|
+
include(context, includeChildrenRecursively, { asSingleStatement } = BLANK) {
|
|
11637
11832
|
this.included = true;
|
|
11638
11833
|
for (const declarator of this.declarations) {
|
|
11639
11834
|
if (includeChildrenRecursively || declarator.shouldBeIncluded(context))
|
|
11640
11835
|
declarator.include(context, includeChildrenRecursively);
|
|
11641
|
-
|
|
11642
|
-
}
|
|
11643
|
-
includeAsSingleStatement(context, includeChildrenRecursively) {
|
|
11644
|
-
this.included = true;
|
|
11645
|
-
for (const declarator of this.declarations) {
|
|
11646
|
-
if (includeChildrenRecursively || declarator.shouldBeIncluded(context)) {
|
|
11647
|
-
declarator.include(context, includeChildrenRecursively);
|
|
11836
|
+
if (asSingleStatement) {
|
|
11648
11837
|
declarator.id.include(context, includeChildrenRecursively);
|
|
11649
11838
|
}
|
|
11650
11839
|
}
|
|
@@ -11792,15 +11981,15 @@ class VariableDeclarator extends NodeBase {
|
|
|
11792
11981
|
this.id.deoptimizePath(path);
|
|
11793
11982
|
}
|
|
11794
11983
|
hasEffects(context) {
|
|
11795
|
-
|
|
11984
|
+
var _a;
|
|
11985
|
+
const initEffect = (_a = this.init) === null || _a === void 0 ? void 0 : _a.hasEffects(context);
|
|
11796
11986
|
this.id.markDeclarationReached();
|
|
11797
11987
|
return initEffect || this.id.hasEffects(context);
|
|
11798
11988
|
}
|
|
11799
11989
|
include(context, includeChildrenRecursively) {
|
|
11990
|
+
var _a;
|
|
11800
11991
|
this.included = true;
|
|
11801
|
-
|
|
11802
|
-
this.init.include(context, includeChildrenRecursively);
|
|
11803
|
-
}
|
|
11992
|
+
(_a = this.init) === null || _a === void 0 ? void 0 : _a.include(context, includeChildrenRecursively);
|
|
11804
11993
|
this.id.markDeclarationReached();
|
|
11805
11994
|
if (includeChildrenRecursively || this.id.shouldBeIncluded(context)) {
|
|
11806
11995
|
this.id.include(context, includeChildrenRecursively);
|
|
@@ -11844,7 +12033,7 @@ class WhileStatement extends NodeBase {
|
|
|
11844
12033
|
this.included = true;
|
|
11845
12034
|
this.test.include(context, includeChildrenRecursively);
|
|
11846
12035
|
const { brokenFlow } = context;
|
|
11847
|
-
this.body.
|
|
12036
|
+
this.body.include(context, includeChildrenRecursively, { asSingleStatement: true });
|
|
11848
12037
|
context.brokenFlow = brokenFlow;
|
|
11849
12038
|
}
|
|
11850
12039
|
}
|
|
@@ -11855,9 +12044,10 @@ class YieldExpression extends NodeBase {
|
|
|
11855
12044
|
this.deoptimized = false;
|
|
11856
12045
|
}
|
|
11857
12046
|
hasEffects(context) {
|
|
12047
|
+
var _a;
|
|
11858
12048
|
if (!this.deoptimized)
|
|
11859
12049
|
this.applyDeoptimizations();
|
|
11860
|
-
return
|
|
12050
|
+
return !context.ignore.returnYield || ((_a = this.argument) === null || _a === void 0 ? void 0 : _a.hasEffects(context));
|
|
11861
12051
|
}
|
|
11862
12052
|
render(code, options) {
|
|
11863
12053
|
if (this.argument) {
|
|
@@ -11867,14 +12057,6 @@ class YieldExpression extends NodeBase {
|
|
|
11867
12057
|
}
|
|
11868
12058
|
}
|
|
11869
12059
|
}
|
|
11870
|
-
applyDeoptimizations() {
|
|
11871
|
-
this.deoptimized = true;
|
|
11872
|
-
const { argument } = this;
|
|
11873
|
-
if (argument) {
|
|
11874
|
-
argument.deoptimizePath(UNKNOWN_PATH);
|
|
11875
|
-
this.context.requestTreeshakingPass();
|
|
11876
|
-
}
|
|
11877
|
-
}
|
|
11878
12060
|
}
|
|
11879
12061
|
|
|
11880
12062
|
const nodeConstructors = {
|
|
@@ -12303,8 +12485,8 @@ class Module {
|
|
|
12303
12485
|
this.importMetas = [];
|
|
12304
12486
|
this.importedFromNotTreeshaken = false;
|
|
12305
12487
|
this.importers = [];
|
|
12306
|
-
this.imports = new Set();
|
|
12307
12488
|
this.includedDynamicImporters = [];
|
|
12489
|
+
this.includedImports = new Set();
|
|
12308
12490
|
this.isExecuted = false;
|
|
12309
12491
|
this.isUserDefinedEntryPoint = false;
|
|
12310
12492
|
this.needsExportShim = false;
|
|
@@ -12433,7 +12615,7 @@ class Module {
|
|
|
12433
12615
|
this.relevantDependencies = new Set();
|
|
12434
12616
|
const necessaryDependencies = new Set();
|
|
12435
12617
|
const alwaysCheckedDependencies = new Set();
|
|
12436
|
-
const dependencyVariables = new Set(this.
|
|
12618
|
+
const dependencyVariables = new Set(this.includedImports);
|
|
12437
12619
|
if (this.info.isEntry ||
|
|
12438
12620
|
this.includedDynamicImporters.length > 0 ||
|
|
12439
12621
|
this.namespace.included ||
|
|
@@ -13011,13 +13193,13 @@ class Module {
|
|
|
13011
13193
|
if (module instanceof ExternalModule) {
|
|
13012
13194
|
const [externalVariable] = module.getVariableForExportName('*');
|
|
13013
13195
|
externalVariable.include();
|
|
13014
|
-
this.
|
|
13196
|
+
this.includedImports.add(externalVariable);
|
|
13015
13197
|
externalNamespaces.add(externalVariable);
|
|
13016
13198
|
}
|
|
13017
13199
|
else if (module.info.syntheticNamedExports) {
|
|
13018
13200
|
const syntheticNamespace = module.getSyntheticNamespace();
|
|
13019
13201
|
syntheticNamespace.include();
|
|
13020
|
-
this.
|
|
13202
|
+
this.includedImports.add(syntheticNamespace);
|
|
13021
13203
|
syntheticNamespaces.add(syntheticNamespace);
|
|
13022
13204
|
}
|
|
13023
13205
|
}
|
|
@@ -13054,7 +13236,7 @@ class Module {
|
|
|
13054
13236
|
this.includeVariable(variable);
|
|
13055
13237
|
const variableModule = variable.module;
|
|
13056
13238
|
if (variableModule && variableModule !== this) {
|
|
13057
|
-
this.
|
|
13239
|
+
this.includedImports.add(variable);
|
|
13058
13240
|
}
|
|
13059
13241
|
}
|
|
13060
13242
|
shimMissingExport(name) {
|
|
@@ -14386,6 +14568,7 @@ class Chunk {
|
|
|
14386
14568
|
this.implicitEntryModules = [];
|
|
14387
14569
|
this.implicitlyLoadedBefore = new Set();
|
|
14388
14570
|
this.imports = new Set();
|
|
14571
|
+
this.includedReexportsByModule = new Map();
|
|
14389
14572
|
this.indentString = undefined;
|
|
14390
14573
|
// This may only be updated in the constructor
|
|
14391
14574
|
this.isEmpty = true;
|
|
@@ -14557,6 +14740,9 @@ class Chunk {
|
|
|
14557
14740
|
this.exports.add(module.namespace);
|
|
14558
14741
|
}
|
|
14559
14742
|
}
|
|
14743
|
+
if (!this.outputOptions.preserveModules) {
|
|
14744
|
+
this.addNecessaryImportsForFacades();
|
|
14745
|
+
}
|
|
14560
14746
|
return facades;
|
|
14561
14747
|
}
|
|
14562
14748
|
generateId(addons, options, existingNames, includeHash) {
|
|
@@ -14899,6 +15085,15 @@ class Chunk {
|
|
|
14899
15085
|
}
|
|
14900
15086
|
}
|
|
14901
15087
|
}
|
|
15088
|
+
addNecessaryImportsForFacades() {
|
|
15089
|
+
for (const [module, variables] of this.includedReexportsByModule) {
|
|
15090
|
+
if (this.includedNamespaces.has(module)) {
|
|
15091
|
+
for (const variable of variables) {
|
|
15092
|
+
this.imports.add(variable);
|
|
15093
|
+
}
|
|
15094
|
+
}
|
|
15095
|
+
}
|
|
15096
|
+
}
|
|
14902
15097
|
assignFacadeName({ fileName, name }, facadedModule) {
|
|
14903
15098
|
if (fileName) {
|
|
14904
15099
|
this.fileName = fileName;
|
|
@@ -14946,6 +15141,7 @@ class Chunk {
|
|
|
14946
15141
|
return hash.digest('hex').substr(0, 8);
|
|
14947
15142
|
}
|
|
14948
15143
|
ensureReexportsAreAvailableForModule(module) {
|
|
15144
|
+
const includedReexports = [];
|
|
14949
15145
|
const map = module.getExportNamesByVariable();
|
|
14950
15146
|
for (const exportedVariable of map.keys()) {
|
|
14951
15147
|
const isSynthetic = exportedVariable instanceof SyntheticNamedExportVariable;
|
|
@@ -14959,6 +15155,7 @@ class Chunk {
|
|
|
14959
15155
|
const chunk = this.chunkByModule.get(exportingModule);
|
|
14960
15156
|
if (chunk && chunk !== this) {
|
|
14961
15157
|
chunk.exports.add(importedVariable);
|
|
15158
|
+
includedReexports.push(importedVariable);
|
|
14962
15159
|
if (isSynthetic) {
|
|
14963
15160
|
this.imports.add(importedVariable);
|
|
14964
15161
|
}
|
|
@@ -14966,6 +15163,9 @@ class Chunk {
|
|
|
14966
15163
|
}
|
|
14967
15164
|
}
|
|
14968
15165
|
}
|
|
15166
|
+
if (includedReexports.length) {
|
|
15167
|
+
this.includedReexportsByModule.set(module, includedReexports);
|
|
15168
|
+
}
|
|
14969
15169
|
}
|
|
14970
15170
|
finaliseDynamicImports(options, snippets) {
|
|
14971
15171
|
const stripKnownJsExtensions = options.format === 'amd';
|
|
@@ -15321,7 +15521,7 @@ class Chunk {
|
|
|
15321
15521
|
deconflictChunk(this.orderedModules, this.getDependenciesToBeDeconflicted(format !== 'es' && format !== 'system', format === 'amd' || format === 'umd' || format === 'iife', interop), this.imports, usedNames, format, interop, this.outputOptions.preserveModules, this.outputOptions.externalLiveBindings, this.chunkByModule, syntheticExports, this.exportNamesByVariable, this.accessedGlobalsByScope, this.includedNamespaces);
|
|
15322
15522
|
}
|
|
15323
15523
|
setUpChunkImportsAndExportsForModule(module) {
|
|
15324
|
-
const moduleImports = new Set(module.
|
|
15524
|
+
const moduleImports = new Set(module.includedImports);
|
|
15325
15525
|
// when we are not preserving modules, we need to make all namespace variables available for
|
|
15326
15526
|
// rendering the namespace object
|
|
15327
15527
|
if (!this.outputOptions.preserveModules) {
|
|
@@ -22998,6 +23198,12 @@ function formatAction([pluginName, hookName, args]) {
|
|
|
22998
23198
|
}
|
|
22999
23199
|
return action;
|
|
23000
23200
|
}
|
|
23201
|
+
// We do not directly listen on process to avoid max listeners warnings for
|
|
23202
|
+
// complicated build processes
|
|
23203
|
+
const beforeExitEvent = 'beforeExit';
|
|
23204
|
+
const beforeExitEmitter = new EventEmitter();
|
|
23205
|
+
beforeExitEmitter.setMaxListeners(0);
|
|
23206
|
+
process$1.on(beforeExitEvent, () => beforeExitEmitter.emit(beforeExitEvent));
|
|
23001
23207
|
async function catchUnfinishedHookActions(pluginDriver, callback) {
|
|
23002
23208
|
let handleEmptyEventLoop;
|
|
23003
23209
|
const emptyEventLoopPromise = new Promise((_, reject) => {
|
|
@@ -23006,10 +23212,10 @@ async function catchUnfinishedHookActions(pluginDriver, callback) {
|
|
|
23006
23212
|
reject(new Error(`Unexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit:\n` +
|
|
23007
23213
|
[...unfulfilledActions].map(formatAction).join('\n')));
|
|
23008
23214
|
};
|
|
23009
|
-
|
|
23215
|
+
beforeExitEmitter.once(beforeExitEvent, handleEmptyEventLoop);
|
|
23010
23216
|
});
|
|
23011
23217
|
const result = await Promise.race([callback(), emptyEventLoopPromise]);
|
|
23012
|
-
|
|
23218
|
+
beforeExitEmitter.off(beforeExitEvent, handleEmptyEventLoop);
|
|
23013
23219
|
return result;
|
|
23014
23220
|
}
|
|
23015
23221
|
|