rollup 2.58.0 → 2.59.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 +46 -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 +927 -884
- package/dist/es/shared/watch.js +2 -2
- package/dist/loadConfigFile.js +2 -2
- package/dist/rollup.browser.js +3 -3
- package/dist/rollup.browser.js.map +1 -1
- package/dist/rollup.js +2 -2
- package/dist/shared/index.js +2 -2
- package/dist/shared/loadConfigFile.js +2 -2
- package/dist/shared/mergeOptions.js +2 -2
- package/dist/shared/rollup.js +927 -884
- package/dist/shared/watch-cli.js +2 -2
- package/dist/shared/watch.js +2 -2
- package/package.json +2 -1
package/dist/shared/rollup.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v2.
|
|
4
|
-
|
|
3
|
+
Rollup.js v2.59.0
|
|
4
|
+
Mon, 01 Nov 2021 06:11:12 GMT - commit 66b3139b4be1d52342088dc00ef89fb9412f639a
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
https://github.com/rollup/rollup
|
|
@@ -26,7 +26,7 @@ function _interopNamespaceDefault(e) {
|
|
|
26
26
|
return n;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
var version$1 = "2.
|
|
29
|
+
var version$1 = "2.59.0";
|
|
30
30
|
|
|
31
31
|
function ensureArray$1(items) {
|
|
32
32
|
if (Array.isArray(items)) {
|
|
@@ -5103,13 +5103,11 @@ class NodeBase extends ExpressionEntity {
|
|
|
5103
5103
|
for (const child of value) {
|
|
5104
5104
|
this[key].push(child === null
|
|
5105
5105
|
? null
|
|
5106
|
-
: new (this.context.
|
|
5107
|
-
this.context.nodeConstructors.UnknownNode)(child, this, this.scope));
|
|
5106
|
+
: new (this.context.getNodeConstructor(child.type))(child, this, this.scope));
|
|
5108
5107
|
}
|
|
5109
5108
|
}
|
|
5110
5109
|
else {
|
|
5111
|
-
this[key] = new (this.context.
|
|
5112
|
-
this.context.nodeConstructors.UnknownNode)(value, this, this.scope);
|
|
5110
|
+
this[key] = new (this.context.getNodeConstructor(value.type))(value, this, this.scope);
|
|
5113
5111
|
}
|
|
5114
5112
|
}
|
|
5115
5113
|
}
|
|
@@ -5347,576 +5345,83 @@ function renderSystemExportSequenceBeforeExpression(exportedVariable, expression
|
|
|
5347
5345
|
}
|
|
5348
5346
|
}
|
|
5349
5347
|
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
outStr = chars[curDigit] + outStr;
|
|
5358
|
-
} while (num !== 0);
|
|
5359
|
-
return outStr;
|
|
5360
|
-
}
|
|
5348
|
+
//@ts-check
|
|
5349
|
+
/** @typedef { import('estree').Node} Node */
|
|
5350
|
+
/** @typedef {Node | {
|
|
5351
|
+
* type: 'PropertyDefinition';
|
|
5352
|
+
* computed: boolean;
|
|
5353
|
+
* value: Node
|
|
5354
|
+
* }} NodeWithPropertyDefinition */
|
|
5361
5355
|
|
|
5362
|
-
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
default: true,
|
|
5373
|
-
delete: true,
|
|
5374
|
-
do: true,
|
|
5375
|
-
else: true,
|
|
5376
|
-
enum: true,
|
|
5377
|
-
eval: true,
|
|
5378
|
-
export: true,
|
|
5379
|
-
extends: true,
|
|
5380
|
-
false: true,
|
|
5381
|
-
finally: true,
|
|
5382
|
-
for: true,
|
|
5383
|
-
function: true,
|
|
5384
|
-
if: true,
|
|
5385
|
-
implements: true,
|
|
5386
|
-
import: true,
|
|
5387
|
-
in: true,
|
|
5388
|
-
instanceof: true,
|
|
5389
|
-
interface: true,
|
|
5390
|
-
let: true,
|
|
5391
|
-
new: true,
|
|
5392
|
-
null: true,
|
|
5393
|
-
package: true,
|
|
5394
|
-
private: true,
|
|
5395
|
-
protected: true,
|
|
5396
|
-
public: true,
|
|
5397
|
-
return: true,
|
|
5398
|
-
static: true,
|
|
5399
|
-
super: true,
|
|
5400
|
-
switch: true,
|
|
5401
|
-
this: true,
|
|
5402
|
-
throw: true,
|
|
5403
|
-
true: true,
|
|
5404
|
-
try: true,
|
|
5405
|
-
typeof: true,
|
|
5406
|
-
undefined: true,
|
|
5407
|
-
var: true,
|
|
5408
|
-
void: true,
|
|
5409
|
-
while: true,
|
|
5410
|
-
with: true,
|
|
5411
|
-
yield: true
|
|
5412
|
-
};
|
|
5356
|
+
/**
|
|
5357
|
+
*
|
|
5358
|
+
* @param {NodeWithPropertyDefinition} node
|
|
5359
|
+
* @param {NodeWithPropertyDefinition} parent
|
|
5360
|
+
* @returns boolean
|
|
5361
|
+
*/
|
|
5362
|
+
function is_reference (node, parent) {
|
|
5363
|
+
if (node.type === 'MemberExpression') {
|
|
5364
|
+
return !node.computed && is_reference(node.object, node);
|
|
5365
|
+
}
|
|
5413
5366
|
|
|
5414
|
-
|
|
5415
|
-
|
|
5416
|
-
let count = 1;
|
|
5417
|
-
while (usedNames.has(safeName) || RESERVED_NAMES[safeName]) {
|
|
5418
|
-
safeName = `${baseName}$${toBase64(count++)}`;
|
|
5419
|
-
}
|
|
5420
|
-
usedNames.add(safeName);
|
|
5421
|
-
return safeName;
|
|
5422
|
-
}
|
|
5367
|
+
if (node.type === 'Identifier') {
|
|
5368
|
+
if (!parent) return true;
|
|
5423
5369
|
|
|
5424
|
-
|
|
5370
|
+
switch (parent.type) {
|
|
5371
|
+
// disregard `bar` in `foo.bar`
|
|
5372
|
+
case 'MemberExpression': return parent.computed || node === parent.object;
|
|
5425
5373
|
|
|
5426
|
-
|
|
5427
|
-
|
|
5374
|
+
// disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
|
|
5375
|
+
case 'MethodDefinition': return parent.computed;
|
|
5376
|
+
|
|
5377
|
+
// disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
|
|
5378
|
+
case 'PropertyDefinition': return parent.computed || node === parent.value;
|
|
5379
|
+
|
|
5380
|
+
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
|
|
5381
|
+
case 'Property': return parent.computed || node === parent.value;
|
|
5382
|
+
|
|
5383
|
+
// disregard the `bar` in `export { foo as bar }` or
|
|
5384
|
+
// the foo in `import { foo as bar }`
|
|
5385
|
+
case 'ExportSpecifier':
|
|
5386
|
+
case 'ImportSpecifier': return node === parent.local;
|
|
5387
|
+
|
|
5388
|
+
// disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
|
|
5389
|
+
case 'LabeledStatement':
|
|
5390
|
+
case 'BreakStatement':
|
|
5391
|
+
case 'ContinueStatement': return false;
|
|
5392
|
+
default: return true;
|
|
5393
|
+
}
|
|
5394
|
+
}
|
|
5395
|
+
|
|
5396
|
+
return false;
|
|
5428
5397
|
}
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
}
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5398
|
+
|
|
5399
|
+
/* eslint sort-keys: "off" */
|
|
5400
|
+
const ValueProperties = Symbol('Value Properties');
|
|
5401
|
+
const PURE = { pure: true };
|
|
5402
|
+
const IMPURE = { pure: false };
|
|
5403
|
+
// We use shortened variables to reduce file size here
|
|
5404
|
+
/* OBJECT */
|
|
5405
|
+
const O = {
|
|
5406
|
+
__proto__: null,
|
|
5407
|
+
[ValueProperties]: IMPURE
|
|
5439
5408
|
};
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
}
|
|
5445
|
-
return UNKNOWN_EXPRESSION;
|
|
5446
|
-
}
|
|
5447
|
-
hasEffectsWhenAccessedAtPath(path) {
|
|
5448
|
-
return path.length > 1;
|
|
5449
|
-
}
|
|
5450
|
-
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
5451
|
-
if (path.length === 1) {
|
|
5452
|
-
return hasMemberEffectWhenCalled(literalBooleanMembers, path[0], callOptions, context);
|
|
5453
|
-
}
|
|
5454
|
-
return true;
|
|
5455
|
-
}
|
|
5456
|
-
})();
|
|
5457
|
-
const returnsBoolean = {
|
|
5458
|
-
value: {
|
|
5459
|
-
callsArgs: null,
|
|
5460
|
-
returns: UNKNOWN_LITERAL_BOOLEAN
|
|
5461
|
-
}
|
|
5409
|
+
/* PURE FUNCTION */
|
|
5410
|
+
const PF = {
|
|
5411
|
+
__proto__: null,
|
|
5412
|
+
[ValueProperties]: PURE
|
|
5462
5413
|
};
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
|
-
|
|
5466
|
-
|
|
5467
|
-
|
|
5468
|
-
return UNKNOWN_EXPRESSION;
|
|
5469
|
-
}
|
|
5470
|
-
hasEffectsWhenAccessedAtPath(path) {
|
|
5471
|
-
return path.length > 1;
|
|
5472
|
-
}
|
|
5473
|
-
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
5474
|
-
if (path.length === 1) {
|
|
5475
|
-
return hasMemberEffectWhenCalled(literalNumberMembers, path[0], callOptions, context);
|
|
5476
|
-
}
|
|
5477
|
-
return true;
|
|
5478
|
-
}
|
|
5479
|
-
})();
|
|
5480
|
-
const returnsNumber = {
|
|
5481
|
-
value: {
|
|
5482
|
-
callsArgs: null,
|
|
5483
|
-
returns: UNKNOWN_LITERAL_NUMBER
|
|
5484
|
-
}
|
|
5414
|
+
/* CONSTRUCTOR */
|
|
5415
|
+
const C = {
|
|
5416
|
+
__proto__: null,
|
|
5417
|
+
[ValueProperties]: IMPURE,
|
|
5418
|
+
prototype: O
|
|
5485
5419
|
};
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
return UNKNOWN_EXPRESSION;
|
|
5492
|
-
}
|
|
5493
|
-
hasEffectsWhenAccessedAtPath(path) {
|
|
5494
|
-
return path.length > 1;
|
|
5495
|
-
}
|
|
5496
|
-
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
5497
|
-
if (path.length === 1) {
|
|
5498
|
-
return hasMemberEffectWhenCalled(literalStringMembers, path[0], callOptions, context);
|
|
5499
|
-
}
|
|
5500
|
-
return true;
|
|
5501
|
-
}
|
|
5502
|
-
})();
|
|
5503
|
-
const returnsString = {
|
|
5504
|
-
value: {
|
|
5505
|
-
callsArgs: null,
|
|
5506
|
-
returns: UNKNOWN_LITERAL_STRING
|
|
5507
|
-
}
|
|
5508
|
-
};
|
|
5509
|
-
const objectMembers = assembleMemberDescriptions({
|
|
5510
|
-
hasOwnProperty: returnsBoolean,
|
|
5511
|
-
isPrototypeOf: returnsBoolean,
|
|
5512
|
-
propertyIsEnumerable: returnsBoolean,
|
|
5513
|
-
toLocaleString: returnsString,
|
|
5514
|
-
toString: returnsString,
|
|
5515
|
-
valueOf: returnsUnknown
|
|
5516
|
-
});
|
|
5517
|
-
const literalBooleanMembers = assembleMemberDescriptions({
|
|
5518
|
-
valueOf: returnsBoolean
|
|
5519
|
-
}, objectMembers);
|
|
5520
|
-
const literalNumberMembers = assembleMemberDescriptions({
|
|
5521
|
-
toExponential: returnsString,
|
|
5522
|
-
toFixed: returnsString,
|
|
5523
|
-
toLocaleString: returnsString,
|
|
5524
|
-
toPrecision: returnsString,
|
|
5525
|
-
valueOf: returnsNumber
|
|
5526
|
-
}, objectMembers);
|
|
5527
|
-
const literalStringMembers = assembleMemberDescriptions({
|
|
5528
|
-
charAt: returnsString,
|
|
5529
|
-
charCodeAt: returnsNumber,
|
|
5530
|
-
codePointAt: returnsNumber,
|
|
5531
|
-
concat: returnsString,
|
|
5532
|
-
endsWith: returnsBoolean,
|
|
5533
|
-
includes: returnsBoolean,
|
|
5534
|
-
indexOf: returnsNumber,
|
|
5535
|
-
lastIndexOf: returnsNumber,
|
|
5536
|
-
localeCompare: returnsNumber,
|
|
5537
|
-
match: returnsBoolean,
|
|
5538
|
-
normalize: returnsString,
|
|
5539
|
-
padEnd: returnsString,
|
|
5540
|
-
padStart: returnsString,
|
|
5541
|
-
repeat: returnsString,
|
|
5542
|
-
replace: {
|
|
5543
|
-
value: {
|
|
5544
|
-
callsArgs: [1],
|
|
5545
|
-
returns: UNKNOWN_LITERAL_STRING
|
|
5546
|
-
}
|
|
5547
|
-
},
|
|
5548
|
-
search: returnsNumber,
|
|
5549
|
-
slice: returnsString,
|
|
5550
|
-
split: returnsUnknown,
|
|
5551
|
-
startsWith: returnsBoolean,
|
|
5552
|
-
substr: returnsString,
|
|
5553
|
-
substring: returnsString,
|
|
5554
|
-
toLocaleLowerCase: returnsString,
|
|
5555
|
-
toLocaleUpperCase: returnsString,
|
|
5556
|
-
toLowerCase: returnsString,
|
|
5557
|
-
toUpperCase: returnsString,
|
|
5558
|
-
trim: returnsString,
|
|
5559
|
-
valueOf: returnsString
|
|
5560
|
-
}, objectMembers);
|
|
5561
|
-
function getLiteralMembersForValue(value) {
|
|
5562
|
-
switch (typeof value) {
|
|
5563
|
-
case 'boolean':
|
|
5564
|
-
return literalBooleanMembers;
|
|
5565
|
-
case 'number':
|
|
5566
|
-
return literalNumberMembers;
|
|
5567
|
-
case 'string':
|
|
5568
|
-
return literalStringMembers;
|
|
5569
|
-
default:
|
|
5570
|
-
return Object.create(null);
|
|
5571
|
-
}
|
|
5572
|
-
}
|
|
5573
|
-
function hasMemberEffectWhenCalled(members, memberName, callOptions, context) {
|
|
5574
|
-
if (typeof memberName !== 'string' || !members[memberName]) {
|
|
5575
|
-
return true;
|
|
5576
|
-
}
|
|
5577
|
-
if (!members[memberName].callsArgs)
|
|
5578
|
-
return false;
|
|
5579
|
-
for (const argIndex of members[memberName].callsArgs) {
|
|
5580
|
-
if (callOptions.args[argIndex] &&
|
|
5581
|
-
callOptions.args[argIndex].hasEffectsWhenCalledAtPath(EMPTY_PATH, {
|
|
5582
|
-
args: NO_ARGS,
|
|
5583
|
-
thisParam: null,
|
|
5584
|
-
withNew: false
|
|
5585
|
-
}, context))
|
|
5586
|
-
return true;
|
|
5587
|
-
}
|
|
5588
|
-
return false;
|
|
5589
|
-
}
|
|
5590
|
-
function getMemberReturnExpressionWhenCalled(members, memberName) {
|
|
5591
|
-
if (typeof memberName !== 'string' || !members[memberName])
|
|
5592
|
-
return UNKNOWN_EXPRESSION;
|
|
5593
|
-
return members[memberName].returns;
|
|
5594
|
-
}
|
|
5595
|
-
|
|
5596
|
-
class LocalVariable extends Variable {
|
|
5597
|
-
constructor(name, declarator, init, context) {
|
|
5598
|
-
super(name);
|
|
5599
|
-
this.calledFromTryStatement = false;
|
|
5600
|
-
this.additionalInitializers = null;
|
|
5601
|
-
this.expressionsToBeDeoptimized = [];
|
|
5602
|
-
this.declarations = declarator ? [declarator] : [];
|
|
5603
|
-
this.init = init;
|
|
5604
|
-
this.deoptimizationTracker = context.deoptimizationTracker;
|
|
5605
|
-
this.module = context.module;
|
|
5606
|
-
}
|
|
5607
|
-
addDeclaration(identifier, init) {
|
|
5608
|
-
this.declarations.push(identifier);
|
|
5609
|
-
const additionalInitializers = this.markInitializersForDeoptimization();
|
|
5610
|
-
if (init !== null) {
|
|
5611
|
-
additionalInitializers.push(init);
|
|
5612
|
-
}
|
|
5613
|
-
}
|
|
5614
|
-
consolidateInitializers() {
|
|
5615
|
-
if (this.additionalInitializers !== null) {
|
|
5616
|
-
for (const initializer of this.additionalInitializers) {
|
|
5617
|
-
initializer.deoptimizePath(UNKNOWN_PATH);
|
|
5618
|
-
}
|
|
5619
|
-
this.additionalInitializers = null;
|
|
5620
|
-
}
|
|
5621
|
-
}
|
|
5622
|
-
deoptimizePath(path) {
|
|
5623
|
-
var _a, _b;
|
|
5624
|
-
if (this.isReassigned ||
|
|
5625
|
-
this.deoptimizationTracker.trackEntityAtPathAndGetIfTracked(path, this)) {
|
|
5626
|
-
return;
|
|
5627
|
-
}
|
|
5628
|
-
if (path.length === 0) {
|
|
5629
|
-
if (!this.isReassigned) {
|
|
5630
|
-
this.isReassigned = true;
|
|
5631
|
-
const expressionsToBeDeoptimized = this.expressionsToBeDeoptimized;
|
|
5632
|
-
this.expressionsToBeDeoptimized = [];
|
|
5633
|
-
for (const expression of expressionsToBeDeoptimized) {
|
|
5634
|
-
expression.deoptimizeCache();
|
|
5635
|
-
}
|
|
5636
|
-
(_a = this.init) === null || _a === void 0 ? void 0 : _a.deoptimizePath(UNKNOWN_PATH);
|
|
5637
|
-
}
|
|
5638
|
-
}
|
|
5639
|
-
else {
|
|
5640
|
-
(_b = this.init) === null || _b === void 0 ? void 0 : _b.deoptimizePath(path);
|
|
5641
|
-
}
|
|
5642
|
-
}
|
|
5643
|
-
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
5644
|
-
if (this.isReassigned || !this.init) {
|
|
5645
|
-
return thisParameter.deoptimizePath(UNKNOWN_PATH);
|
|
5646
|
-
}
|
|
5647
|
-
recursionTracker.withTrackedEntityAtPath(path, this.init, () => this.init.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker), undefined);
|
|
5648
|
-
}
|
|
5649
|
-
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
5650
|
-
if (this.isReassigned || !this.init) {
|
|
5651
|
-
return UnknownValue;
|
|
5652
|
-
}
|
|
5653
|
-
return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
|
|
5654
|
-
this.expressionsToBeDeoptimized.push(origin);
|
|
5655
|
-
return this.init.getLiteralValueAtPath(path, recursionTracker, origin);
|
|
5656
|
-
}, UnknownValue);
|
|
5657
|
-
}
|
|
5658
|
-
getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
|
|
5659
|
-
if (this.isReassigned || !this.init) {
|
|
5660
|
-
return UNKNOWN_EXPRESSION;
|
|
5661
|
-
}
|
|
5662
|
-
return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
|
|
5663
|
-
this.expressionsToBeDeoptimized.push(origin);
|
|
5664
|
-
return this.init.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
|
|
5665
|
-
}, UNKNOWN_EXPRESSION);
|
|
5666
|
-
}
|
|
5667
|
-
hasEffectsWhenAccessedAtPath(path, context) {
|
|
5668
|
-
if (this.isReassigned)
|
|
5669
|
-
return true;
|
|
5670
|
-
return (this.init &&
|
|
5671
|
-
!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
|
|
5672
|
-
this.init.hasEffectsWhenAccessedAtPath(path, context));
|
|
5673
|
-
}
|
|
5674
|
-
hasEffectsWhenAssignedAtPath(path, context) {
|
|
5675
|
-
if (this.included)
|
|
5676
|
-
return true;
|
|
5677
|
-
if (path.length === 0)
|
|
5678
|
-
return false;
|
|
5679
|
-
if (this.isReassigned)
|
|
5680
|
-
return true;
|
|
5681
|
-
return (this.init &&
|
|
5682
|
-
!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
|
|
5683
|
-
this.init.hasEffectsWhenAssignedAtPath(path, context));
|
|
5684
|
-
}
|
|
5685
|
-
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
5686
|
-
if (this.isReassigned)
|
|
5687
|
-
return true;
|
|
5688
|
-
return (this.init &&
|
|
5689
|
-
!(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
|
|
5690
|
-
this.init.hasEffectsWhenCalledAtPath(path, callOptions, context));
|
|
5691
|
-
}
|
|
5692
|
-
include() {
|
|
5693
|
-
if (!this.included) {
|
|
5694
|
-
this.included = true;
|
|
5695
|
-
for (const declaration of this.declarations) {
|
|
5696
|
-
// If node is a default export, it can save a tree-shaking run to include the full declaration now
|
|
5697
|
-
if (!declaration.included)
|
|
5698
|
-
declaration.include(createInclusionContext(), false);
|
|
5699
|
-
let node = declaration.parent;
|
|
5700
|
-
while (!node.included) {
|
|
5701
|
-
// We do not want to properly include parents in case they are part of a dead branch
|
|
5702
|
-
// in which case .include() might pull in more dead code
|
|
5703
|
-
node.included = true;
|
|
5704
|
-
if (node.type === Program$1)
|
|
5705
|
-
break;
|
|
5706
|
-
node = node.parent;
|
|
5707
|
-
}
|
|
5708
|
-
}
|
|
5709
|
-
}
|
|
5710
|
-
}
|
|
5711
|
-
includeCallArguments(context, args) {
|
|
5712
|
-
if (this.isReassigned || (this.init && context.includedCallArguments.has(this.init))) {
|
|
5713
|
-
for (const arg of args) {
|
|
5714
|
-
arg.include(context, false);
|
|
5715
|
-
}
|
|
5716
|
-
}
|
|
5717
|
-
else if (this.init) {
|
|
5718
|
-
context.includedCallArguments.add(this.init);
|
|
5719
|
-
this.init.includeCallArguments(context, args);
|
|
5720
|
-
context.includedCallArguments.delete(this.init);
|
|
5721
|
-
}
|
|
5722
|
-
}
|
|
5723
|
-
markCalledFromTryStatement() {
|
|
5724
|
-
this.calledFromTryStatement = true;
|
|
5725
|
-
}
|
|
5726
|
-
markInitializersForDeoptimization() {
|
|
5727
|
-
if (this.additionalInitializers === null) {
|
|
5728
|
-
this.additionalInitializers = this.init === null ? [] : [this.init];
|
|
5729
|
-
this.init = UNKNOWN_EXPRESSION;
|
|
5730
|
-
this.isReassigned = true;
|
|
5731
|
-
}
|
|
5732
|
-
return this.additionalInitializers;
|
|
5733
|
-
}
|
|
5734
|
-
}
|
|
5735
|
-
|
|
5736
|
-
class Scope$1 {
|
|
5737
|
-
constructor() {
|
|
5738
|
-
this.children = [];
|
|
5739
|
-
this.variables = new Map();
|
|
5740
|
-
}
|
|
5741
|
-
addDeclaration(identifier, context, init, _isHoisted) {
|
|
5742
|
-
const name = identifier.name;
|
|
5743
|
-
let variable = this.variables.get(name);
|
|
5744
|
-
if (variable) {
|
|
5745
|
-
variable.addDeclaration(identifier, init);
|
|
5746
|
-
}
|
|
5747
|
-
else {
|
|
5748
|
-
variable = new LocalVariable(identifier.name, identifier, init || UNDEFINED_EXPRESSION, context);
|
|
5749
|
-
this.variables.set(name, variable);
|
|
5750
|
-
}
|
|
5751
|
-
return variable;
|
|
5752
|
-
}
|
|
5753
|
-
contains(name) {
|
|
5754
|
-
return this.variables.has(name);
|
|
5755
|
-
}
|
|
5756
|
-
findVariable(_name) {
|
|
5757
|
-
throw new Error('Internal Error: findVariable needs to be implemented by a subclass');
|
|
5758
|
-
}
|
|
5759
|
-
}
|
|
5760
|
-
|
|
5761
|
-
class ChildScope extends Scope$1 {
|
|
5762
|
-
constructor(parent) {
|
|
5763
|
-
super();
|
|
5764
|
-
this.accessedOutsideVariables = new Map();
|
|
5765
|
-
this.parent = parent;
|
|
5766
|
-
parent.children.push(this);
|
|
5767
|
-
}
|
|
5768
|
-
addAccessedDynamicImport(importExpression) {
|
|
5769
|
-
(this.accessedDynamicImports || (this.accessedDynamicImports = new Set())).add(importExpression);
|
|
5770
|
-
if (this.parent instanceof ChildScope) {
|
|
5771
|
-
this.parent.addAccessedDynamicImport(importExpression);
|
|
5772
|
-
}
|
|
5773
|
-
}
|
|
5774
|
-
addAccessedGlobals(globals, accessedGlobalsByScope) {
|
|
5775
|
-
const accessedGlobals = accessedGlobalsByScope.get(this) || new Set();
|
|
5776
|
-
for (const name of globals) {
|
|
5777
|
-
accessedGlobals.add(name);
|
|
5778
|
-
}
|
|
5779
|
-
accessedGlobalsByScope.set(this, accessedGlobals);
|
|
5780
|
-
if (this.parent instanceof ChildScope) {
|
|
5781
|
-
this.parent.addAccessedGlobals(globals, accessedGlobalsByScope);
|
|
5782
|
-
}
|
|
5783
|
-
}
|
|
5784
|
-
addNamespaceMemberAccess(name, variable) {
|
|
5785
|
-
this.accessedOutsideVariables.set(name, variable);
|
|
5786
|
-
this.parent.addNamespaceMemberAccess(name, variable);
|
|
5787
|
-
}
|
|
5788
|
-
addReturnExpression(expression) {
|
|
5789
|
-
this.parent instanceof ChildScope && this.parent.addReturnExpression(expression);
|
|
5790
|
-
}
|
|
5791
|
-
addUsedOutsideNames(usedNames, format, exportNamesByVariable, accessedGlobalsByScope) {
|
|
5792
|
-
for (const variable of this.accessedOutsideVariables.values()) {
|
|
5793
|
-
if (variable.included) {
|
|
5794
|
-
usedNames.add(variable.getBaseVariableName());
|
|
5795
|
-
if (format === 'system' && exportNamesByVariable.has(variable)) {
|
|
5796
|
-
usedNames.add('exports');
|
|
5797
|
-
}
|
|
5798
|
-
}
|
|
5799
|
-
}
|
|
5800
|
-
const accessedGlobals = accessedGlobalsByScope.get(this);
|
|
5801
|
-
if (accessedGlobals) {
|
|
5802
|
-
for (const name of accessedGlobals) {
|
|
5803
|
-
usedNames.add(name);
|
|
5804
|
-
}
|
|
5805
|
-
}
|
|
5806
|
-
}
|
|
5807
|
-
contains(name) {
|
|
5808
|
-
return this.variables.has(name) || this.parent.contains(name);
|
|
5809
|
-
}
|
|
5810
|
-
deconflict(format, exportNamesByVariable, accessedGlobalsByScope) {
|
|
5811
|
-
const usedNames = new Set();
|
|
5812
|
-
this.addUsedOutsideNames(usedNames, format, exportNamesByVariable, accessedGlobalsByScope);
|
|
5813
|
-
if (this.accessedDynamicImports) {
|
|
5814
|
-
for (const importExpression of this.accessedDynamicImports) {
|
|
5815
|
-
if (importExpression.inlineNamespace) {
|
|
5816
|
-
usedNames.add(importExpression.inlineNamespace.getBaseVariableName());
|
|
5817
|
-
}
|
|
5818
|
-
}
|
|
5819
|
-
}
|
|
5820
|
-
for (const [name, variable] of this.variables) {
|
|
5821
|
-
if (variable.included || variable.alwaysRendered) {
|
|
5822
|
-
variable.setRenderNames(null, getSafeName(name, usedNames));
|
|
5823
|
-
}
|
|
5824
|
-
}
|
|
5825
|
-
for (const scope of this.children) {
|
|
5826
|
-
scope.deconflict(format, exportNamesByVariable, accessedGlobalsByScope);
|
|
5827
|
-
}
|
|
5828
|
-
}
|
|
5829
|
-
findLexicalBoundary() {
|
|
5830
|
-
return this.parent.findLexicalBoundary();
|
|
5831
|
-
}
|
|
5832
|
-
findVariable(name) {
|
|
5833
|
-
const knownVariable = this.variables.get(name) || this.accessedOutsideVariables.get(name);
|
|
5834
|
-
if (knownVariable) {
|
|
5835
|
-
return knownVariable;
|
|
5836
|
-
}
|
|
5837
|
-
const variable = this.parent.findVariable(name);
|
|
5838
|
-
this.accessedOutsideVariables.set(name, variable);
|
|
5839
|
-
return variable;
|
|
5840
|
-
}
|
|
5841
|
-
}
|
|
5842
|
-
|
|
5843
|
-
//@ts-check
|
|
5844
|
-
/** @typedef { import('estree').Node} Node */
|
|
5845
|
-
/** @typedef {Node | {
|
|
5846
|
-
* type: 'PropertyDefinition';
|
|
5847
|
-
* computed: boolean;
|
|
5848
|
-
* value: Node
|
|
5849
|
-
* }} NodeWithPropertyDefinition */
|
|
5850
|
-
|
|
5851
|
-
/**
|
|
5852
|
-
*
|
|
5853
|
-
* @param {NodeWithPropertyDefinition} node
|
|
5854
|
-
* @param {NodeWithPropertyDefinition} parent
|
|
5855
|
-
* @returns boolean
|
|
5856
|
-
*/
|
|
5857
|
-
function is_reference (node, parent) {
|
|
5858
|
-
if (node.type === 'MemberExpression') {
|
|
5859
|
-
return !node.computed && is_reference(node.object, node);
|
|
5860
|
-
}
|
|
5861
|
-
|
|
5862
|
-
if (node.type === 'Identifier') {
|
|
5863
|
-
if (!parent) return true;
|
|
5864
|
-
|
|
5865
|
-
switch (parent.type) {
|
|
5866
|
-
// disregard `bar` in `foo.bar`
|
|
5867
|
-
case 'MemberExpression': return parent.computed || node === parent.object;
|
|
5868
|
-
|
|
5869
|
-
// disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
|
|
5870
|
-
case 'MethodDefinition': return parent.computed;
|
|
5871
|
-
|
|
5872
|
-
// disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
|
|
5873
|
-
case 'PropertyDefinition': return parent.computed || node === parent.value;
|
|
5874
|
-
|
|
5875
|
-
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
|
|
5876
|
-
case 'Property': return parent.computed || node === parent.value;
|
|
5877
|
-
|
|
5878
|
-
// disregard the `bar` in `export { foo as bar }` or
|
|
5879
|
-
// the foo in `import { foo as bar }`
|
|
5880
|
-
case 'ExportSpecifier':
|
|
5881
|
-
case 'ImportSpecifier': return node === parent.local;
|
|
5882
|
-
|
|
5883
|
-
// disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
|
|
5884
|
-
case 'LabeledStatement':
|
|
5885
|
-
case 'BreakStatement':
|
|
5886
|
-
case 'ContinueStatement': return false;
|
|
5887
|
-
default: return true;
|
|
5888
|
-
}
|
|
5889
|
-
}
|
|
5890
|
-
|
|
5891
|
-
return false;
|
|
5892
|
-
}
|
|
5893
|
-
|
|
5894
|
-
/* eslint sort-keys: "off" */
|
|
5895
|
-
const ValueProperties = Symbol('Value Properties');
|
|
5896
|
-
const PURE = { pure: true };
|
|
5897
|
-
const IMPURE = { pure: false };
|
|
5898
|
-
// We use shortened variables to reduce file size here
|
|
5899
|
-
/* OBJECT */
|
|
5900
|
-
const O = {
|
|
5901
|
-
__proto__: null,
|
|
5902
|
-
[ValueProperties]: IMPURE
|
|
5903
|
-
};
|
|
5904
|
-
/* PURE FUNCTION */
|
|
5905
|
-
const PF = {
|
|
5906
|
-
__proto__: null,
|
|
5907
|
-
[ValueProperties]: PURE
|
|
5908
|
-
};
|
|
5909
|
-
/* CONSTRUCTOR */
|
|
5910
|
-
const C = {
|
|
5911
|
-
__proto__: null,
|
|
5912
|
-
[ValueProperties]: IMPURE,
|
|
5913
|
-
prototype: O
|
|
5914
|
-
};
|
|
5915
|
-
/* PURE CONSTRUCTOR */
|
|
5916
|
-
const PC = {
|
|
5917
|
-
__proto__: null,
|
|
5918
|
-
[ValueProperties]: PURE,
|
|
5919
|
-
prototype: O
|
|
5420
|
+
/* PURE CONSTRUCTOR */
|
|
5421
|
+
const PC = {
|
|
5422
|
+
__proto__: null,
|
|
5423
|
+
[ValueProperties]: PURE,
|
|
5424
|
+
prototype: O
|
|
5920
5425
|
};
|
|
5921
5426
|
const ARRAY_TYPE = {
|
|
5922
5427
|
__proto__: null,
|
|
@@ -6713,226 +6218,719 @@ const knownGlobals = {
|
|
|
6713
6218
|
for (const global of ['window', 'global', 'self', 'globalThis']) {
|
|
6714
6219
|
knownGlobals[global] = knownGlobals;
|
|
6715
6220
|
}
|
|
6716
|
-
function getGlobalAtPath(path) {
|
|
6717
|
-
let currentGlobal = knownGlobals;
|
|
6718
|
-
for (const pathSegment of path) {
|
|
6719
|
-
if (typeof pathSegment !== 'string') {
|
|
6720
|
-
return null;
|
|
6221
|
+
function getGlobalAtPath(path) {
|
|
6222
|
+
let currentGlobal = knownGlobals;
|
|
6223
|
+
for (const pathSegment of path) {
|
|
6224
|
+
if (typeof pathSegment !== 'string') {
|
|
6225
|
+
return null;
|
|
6226
|
+
}
|
|
6227
|
+
currentGlobal = currentGlobal[pathSegment];
|
|
6228
|
+
if (!currentGlobal) {
|
|
6229
|
+
return null;
|
|
6230
|
+
}
|
|
6231
|
+
}
|
|
6232
|
+
return currentGlobal[ValueProperties];
|
|
6233
|
+
}
|
|
6234
|
+
function isPureGlobal(path) {
|
|
6235
|
+
const globalAtPath = getGlobalAtPath(path);
|
|
6236
|
+
return globalAtPath !== null && globalAtPath.pure;
|
|
6237
|
+
}
|
|
6238
|
+
function isGlobalMember(path) {
|
|
6239
|
+
if (path.length === 1) {
|
|
6240
|
+
return path[0] === 'undefined' || getGlobalAtPath(path) !== null;
|
|
6241
|
+
}
|
|
6242
|
+
return getGlobalAtPath(path.slice(0, -1)) !== null;
|
|
6243
|
+
}
|
|
6244
|
+
|
|
6245
|
+
class GlobalVariable extends Variable {
|
|
6246
|
+
constructor() {
|
|
6247
|
+
super(...arguments);
|
|
6248
|
+
this.isReassigned = true;
|
|
6249
|
+
}
|
|
6250
|
+
hasEffectsWhenAccessedAtPath(path) {
|
|
6251
|
+
return !isGlobalMember([this.name, ...path]);
|
|
6252
|
+
}
|
|
6253
|
+
hasEffectsWhenCalledAtPath(path) {
|
|
6254
|
+
return !isPureGlobal([this.name, ...path]);
|
|
6255
|
+
}
|
|
6256
|
+
}
|
|
6257
|
+
|
|
6258
|
+
class LocalVariable extends Variable {
|
|
6259
|
+
constructor(name, declarator, init, context) {
|
|
6260
|
+
super(name);
|
|
6261
|
+
this.calledFromTryStatement = false;
|
|
6262
|
+
this.additionalInitializers = null;
|
|
6263
|
+
this.expressionsToBeDeoptimized = [];
|
|
6264
|
+
this.declarations = declarator ? [declarator] : [];
|
|
6265
|
+
this.init = init;
|
|
6266
|
+
this.deoptimizationTracker = context.deoptimizationTracker;
|
|
6267
|
+
this.module = context.module;
|
|
6268
|
+
}
|
|
6269
|
+
addDeclaration(identifier, init) {
|
|
6270
|
+
this.declarations.push(identifier);
|
|
6271
|
+
const additionalInitializers = this.markInitializersForDeoptimization();
|
|
6272
|
+
if (init !== null) {
|
|
6273
|
+
additionalInitializers.push(init);
|
|
6274
|
+
}
|
|
6275
|
+
}
|
|
6276
|
+
consolidateInitializers() {
|
|
6277
|
+
if (this.additionalInitializers !== null) {
|
|
6278
|
+
for (const initializer of this.additionalInitializers) {
|
|
6279
|
+
initializer.deoptimizePath(UNKNOWN_PATH);
|
|
6280
|
+
}
|
|
6281
|
+
this.additionalInitializers = null;
|
|
6282
|
+
}
|
|
6283
|
+
}
|
|
6284
|
+
deoptimizePath(path) {
|
|
6285
|
+
var _a, _b;
|
|
6286
|
+
if (this.isReassigned ||
|
|
6287
|
+
this.deoptimizationTracker.trackEntityAtPathAndGetIfTracked(path, this)) {
|
|
6288
|
+
return;
|
|
6289
|
+
}
|
|
6290
|
+
if (path.length === 0) {
|
|
6291
|
+
if (!this.isReassigned) {
|
|
6292
|
+
this.isReassigned = true;
|
|
6293
|
+
const expressionsToBeDeoptimized = this.expressionsToBeDeoptimized;
|
|
6294
|
+
this.expressionsToBeDeoptimized = [];
|
|
6295
|
+
for (const expression of expressionsToBeDeoptimized) {
|
|
6296
|
+
expression.deoptimizeCache();
|
|
6297
|
+
}
|
|
6298
|
+
(_a = this.init) === null || _a === void 0 ? void 0 : _a.deoptimizePath(UNKNOWN_PATH);
|
|
6299
|
+
}
|
|
6300
|
+
}
|
|
6301
|
+
else {
|
|
6302
|
+
(_b = this.init) === null || _b === void 0 ? void 0 : _b.deoptimizePath(path);
|
|
6303
|
+
}
|
|
6304
|
+
}
|
|
6305
|
+
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
6306
|
+
if (this.isReassigned || !this.init) {
|
|
6307
|
+
return thisParameter.deoptimizePath(UNKNOWN_PATH);
|
|
6308
|
+
}
|
|
6309
|
+
recursionTracker.withTrackedEntityAtPath(path, this.init, () => this.init.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker), undefined);
|
|
6310
|
+
}
|
|
6311
|
+
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
6312
|
+
if (this.isReassigned || !this.init) {
|
|
6313
|
+
return UnknownValue;
|
|
6314
|
+
}
|
|
6315
|
+
return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
|
|
6316
|
+
this.expressionsToBeDeoptimized.push(origin);
|
|
6317
|
+
return this.init.getLiteralValueAtPath(path, recursionTracker, origin);
|
|
6318
|
+
}, UnknownValue);
|
|
6319
|
+
}
|
|
6320
|
+
getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
|
|
6321
|
+
if (this.isReassigned || !this.init) {
|
|
6322
|
+
return UNKNOWN_EXPRESSION;
|
|
6323
|
+
}
|
|
6324
|
+
return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
|
|
6325
|
+
this.expressionsToBeDeoptimized.push(origin);
|
|
6326
|
+
return this.init.getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
|
|
6327
|
+
}, UNKNOWN_EXPRESSION);
|
|
6328
|
+
}
|
|
6329
|
+
hasEffectsWhenAccessedAtPath(path, context) {
|
|
6330
|
+
if (this.isReassigned)
|
|
6331
|
+
return true;
|
|
6332
|
+
return (this.init &&
|
|
6333
|
+
!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
|
|
6334
|
+
this.init.hasEffectsWhenAccessedAtPath(path, context));
|
|
6335
|
+
}
|
|
6336
|
+
hasEffectsWhenAssignedAtPath(path, context) {
|
|
6337
|
+
if (this.included)
|
|
6338
|
+
return true;
|
|
6339
|
+
if (path.length === 0)
|
|
6340
|
+
return false;
|
|
6341
|
+
if (this.isReassigned)
|
|
6342
|
+
return true;
|
|
6343
|
+
return (this.init &&
|
|
6344
|
+
!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
|
|
6345
|
+
this.init.hasEffectsWhenAssignedAtPath(path, context));
|
|
6346
|
+
}
|
|
6347
|
+
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
6348
|
+
if (this.isReassigned)
|
|
6349
|
+
return true;
|
|
6350
|
+
return (this.init &&
|
|
6351
|
+
!(callOptions.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, callOptions, this) &&
|
|
6352
|
+
this.init.hasEffectsWhenCalledAtPath(path, callOptions, context));
|
|
6353
|
+
}
|
|
6354
|
+
include() {
|
|
6355
|
+
if (!this.included) {
|
|
6356
|
+
this.included = true;
|
|
6357
|
+
for (const declaration of this.declarations) {
|
|
6358
|
+
// If node is a default export, it can save a tree-shaking run to include the full declaration now
|
|
6359
|
+
if (!declaration.included)
|
|
6360
|
+
declaration.include(createInclusionContext(), false);
|
|
6361
|
+
let node = declaration.parent;
|
|
6362
|
+
while (!node.included) {
|
|
6363
|
+
// We do not want to properly include parents in case they are part of a dead branch
|
|
6364
|
+
// in which case .include() might pull in more dead code
|
|
6365
|
+
node.included = true;
|
|
6366
|
+
if (node.type === Program$1)
|
|
6367
|
+
break;
|
|
6368
|
+
node = node.parent;
|
|
6369
|
+
}
|
|
6370
|
+
}
|
|
6371
|
+
}
|
|
6372
|
+
}
|
|
6373
|
+
includeCallArguments(context, args) {
|
|
6374
|
+
if (this.isReassigned || (this.init && context.includedCallArguments.has(this.init))) {
|
|
6375
|
+
for (const arg of args) {
|
|
6376
|
+
arg.include(context, false);
|
|
6377
|
+
}
|
|
6378
|
+
}
|
|
6379
|
+
else if (this.init) {
|
|
6380
|
+
context.includedCallArguments.add(this.init);
|
|
6381
|
+
this.init.includeCallArguments(context, args);
|
|
6382
|
+
context.includedCallArguments.delete(this.init);
|
|
6383
|
+
}
|
|
6384
|
+
}
|
|
6385
|
+
markCalledFromTryStatement() {
|
|
6386
|
+
this.calledFromTryStatement = true;
|
|
6387
|
+
}
|
|
6388
|
+
markInitializersForDeoptimization() {
|
|
6389
|
+
if (this.additionalInitializers === null) {
|
|
6390
|
+
this.additionalInitializers = this.init === null ? [] : [this.init];
|
|
6391
|
+
this.init = UNKNOWN_EXPRESSION;
|
|
6392
|
+
this.isReassigned = true;
|
|
6393
|
+
}
|
|
6394
|
+
return this.additionalInitializers;
|
|
6395
|
+
}
|
|
6396
|
+
}
|
|
6397
|
+
|
|
6398
|
+
const tdzVariableKinds = {
|
|
6399
|
+
__proto__: null,
|
|
6400
|
+
class: true,
|
|
6401
|
+
const: true,
|
|
6402
|
+
let: true,
|
|
6403
|
+
var: true
|
|
6404
|
+
};
|
|
6405
|
+
class Identifier extends NodeBase {
|
|
6406
|
+
constructor() {
|
|
6407
|
+
super(...arguments);
|
|
6408
|
+
this.variable = null;
|
|
6409
|
+
this.deoptimized = false;
|
|
6410
|
+
this.isTDZAccess = null;
|
|
6411
|
+
}
|
|
6412
|
+
addExportedVariables(variables, exportNamesByVariable) {
|
|
6413
|
+
if (this.variable !== null && exportNamesByVariable.has(this.variable)) {
|
|
6414
|
+
variables.push(this.variable);
|
|
6415
|
+
}
|
|
6416
|
+
}
|
|
6417
|
+
bind() {
|
|
6418
|
+
if (this.variable === null && is_reference(this, this.parent)) {
|
|
6419
|
+
this.variable = this.scope.findVariable(this.name);
|
|
6420
|
+
this.variable.addReference(this);
|
|
6421
|
+
}
|
|
6422
|
+
}
|
|
6423
|
+
declare(kind, init) {
|
|
6424
|
+
let variable;
|
|
6425
|
+
const { treeshake } = this.context.options;
|
|
6426
|
+
switch (kind) {
|
|
6427
|
+
case 'var':
|
|
6428
|
+
variable = this.scope.addDeclaration(this, this.context, init, true);
|
|
6429
|
+
if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
|
|
6430
|
+
// Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
|
|
6431
|
+
variable.markInitializersForDeoptimization();
|
|
6432
|
+
}
|
|
6433
|
+
break;
|
|
6434
|
+
case 'function':
|
|
6435
|
+
// in strict mode, functions are only hoisted within a scope but not across block scopes
|
|
6436
|
+
variable = this.scope.addDeclaration(this, this.context, init, false);
|
|
6437
|
+
break;
|
|
6438
|
+
case 'let':
|
|
6439
|
+
case 'const':
|
|
6440
|
+
case 'class':
|
|
6441
|
+
variable = this.scope.addDeclaration(this, this.context, init, false);
|
|
6442
|
+
break;
|
|
6443
|
+
case 'parameter':
|
|
6444
|
+
variable = this.scope.addParameterDeclaration(this);
|
|
6445
|
+
break;
|
|
6446
|
+
/* istanbul ignore next */
|
|
6447
|
+
default:
|
|
6448
|
+
/* istanbul ignore next */
|
|
6449
|
+
throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
|
|
6450
|
+
}
|
|
6451
|
+
variable.kind = kind;
|
|
6452
|
+
return [(this.variable = variable)];
|
|
6453
|
+
}
|
|
6454
|
+
deoptimizePath(path) {
|
|
6455
|
+
if (path.length === 0 && !this.scope.contains(this.name)) {
|
|
6456
|
+
this.disallowImportReassignment();
|
|
6457
|
+
}
|
|
6458
|
+
this.variable.deoptimizePath(path);
|
|
6459
|
+
}
|
|
6460
|
+
deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker) {
|
|
6461
|
+
this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
|
|
6462
|
+
}
|
|
6463
|
+
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
6464
|
+
return this.getVariableRespectingTDZ().getLiteralValueAtPath(path, recursionTracker, origin);
|
|
6465
|
+
}
|
|
6466
|
+
getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin) {
|
|
6467
|
+
return this.getVariableRespectingTDZ().getReturnExpressionWhenCalledAtPath(path, callOptions, recursionTracker, origin);
|
|
6468
|
+
}
|
|
6469
|
+
hasEffects() {
|
|
6470
|
+
if (!this.deoptimized)
|
|
6471
|
+
this.applyDeoptimizations();
|
|
6472
|
+
if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
|
|
6473
|
+
return true;
|
|
6474
|
+
}
|
|
6475
|
+
return (this.context.options.treeshake.unknownGlobalSideEffects &&
|
|
6476
|
+
this.variable instanceof GlobalVariable &&
|
|
6477
|
+
this.variable.hasEffectsWhenAccessedAtPath(EMPTY_PATH));
|
|
6478
|
+
}
|
|
6479
|
+
hasEffectsWhenAccessedAtPath(path, context) {
|
|
6480
|
+
return (this.variable !== null &&
|
|
6481
|
+
this.getVariableRespectingTDZ().hasEffectsWhenAccessedAtPath(path, context));
|
|
6482
|
+
}
|
|
6483
|
+
hasEffectsWhenAssignedAtPath(path, context) {
|
|
6484
|
+
return (!this.variable ||
|
|
6485
|
+
(path.length > 0
|
|
6486
|
+
? this.getVariableRespectingTDZ()
|
|
6487
|
+
: this.variable).hasEffectsWhenAssignedAtPath(path, context));
|
|
6488
|
+
}
|
|
6489
|
+
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
6490
|
+
return (!this.variable ||
|
|
6491
|
+
this.getVariableRespectingTDZ().hasEffectsWhenCalledAtPath(path, callOptions, context));
|
|
6492
|
+
}
|
|
6493
|
+
include() {
|
|
6494
|
+
if (!this.deoptimized)
|
|
6495
|
+
this.applyDeoptimizations();
|
|
6496
|
+
if (!this.included) {
|
|
6497
|
+
this.included = true;
|
|
6498
|
+
if (this.variable !== null) {
|
|
6499
|
+
this.context.includeVariableInModule(this.variable);
|
|
6500
|
+
}
|
|
6501
|
+
}
|
|
6502
|
+
}
|
|
6503
|
+
includeCallArguments(context, args) {
|
|
6504
|
+
this.getVariableRespectingTDZ().includeCallArguments(context, args);
|
|
6505
|
+
}
|
|
6506
|
+
isPossibleTDZ() {
|
|
6507
|
+
// return cached value to avoid issues with the next tree-shaking pass
|
|
6508
|
+
if (this.isTDZAccess !== null)
|
|
6509
|
+
return this.isTDZAccess;
|
|
6510
|
+
if (!(this.variable instanceof LocalVariable) ||
|
|
6511
|
+
!this.variable.kind ||
|
|
6512
|
+
!(this.variable.kind in tdzVariableKinds)) {
|
|
6513
|
+
return (this.isTDZAccess = false);
|
|
6514
|
+
}
|
|
6515
|
+
let decl_id;
|
|
6516
|
+
if (this.variable.declarations &&
|
|
6517
|
+
this.variable.declarations.length === 1 &&
|
|
6518
|
+
(decl_id = this.variable.declarations[0]) &&
|
|
6519
|
+
this.start < decl_id.start &&
|
|
6520
|
+
closestParentFunctionOrProgram(this) === closestParentFunctionOrProgram(decl_id)) {
|
|
6521
|
+
// a variable accessed before its declaration
|
|
6522
|
+
// in the same function or at top level of module
|
|
6523
|
+
return (this.isTDZAccess = true);
|
|
6524
|
+
}
|
|
6525
|
+
if (!this.variable.initReached) {
|
|
6526
|
+
// Either a const/let TDZ violation or
|
|
6527
|
+
// var use before declaration was encountered.
|
|
6528
|
+
return (this.isTDZAccess = true);
|
|
6529
|
+
}
|
|
6530
|
+
return (this.isTDZAccess = false);
|
|
6531
|
+
}
|
|
6532
|
+
markDeclarationReached() {
|
|
6533
|
+
this.variable.initReached = true;
|
|
6534
|
+
}
|
|
6535
|
+
render(code, { snippets: { getPropertyAccess } }, { renderedParentType, isCalleeOfRenderedParent, isShorthandProperty } = BLANK) {
|
|
6536
|
+
if (this.variable) {
|
|
6537
|
+
const name = this.variable.getName(getPropertyAccess);
|
|
6538
|
+
if (name !== this.name) {
|
|
6539
|
+
code.overwrite(this.start, this.end, name, {
|
|
6540
|
+
contentOnly: true,
|
|
6541
|
+
storeName: true
|
|
6542
|
+
});
|
|
6543
|
+
if (isShorthandProperty) {
|
|
6544
|
+
code.prependRight(this.start, `${this.name}: `);
|
|
6545
|
+
}
|
|
6546
|
+
}
|
|
6547
|
+
// In strict mode, any variable named "eval" must be the actual "eval" function
|
|
6548
|
+
if (name === 'eval' &&
|
|
6549
|
+
renderedParentType === CallExpression$1 &&
|
|
6550
|
+
isCalleeOfRenderedParent) {
|
|
6551
|
+
code.appendRight(this.start, '0, ');
|
|
6552
|
+
}
|
|
6721
6553
|
}
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6554
|
+
}
|
|
6555
|
+
applyDeoptimizations() {
|
|
6556
|
+
this.deoptimized = true;
|
|
6557
|
+
if (this.variable !== null && this.variable instanceof LocalVariable) {
|
|
6558
|
+
this.variable.consolidateInitializers();
|
|
6559
|
+
this.context.requestTreeshakingPass();
|
|
6725
6560
|
}
|
|
6726
6561
|
}
|
|
6727
|
-
|
|
6562
|
+
disallowImportReassignment() {
|
|
6563
|
+
return this.context.error({
|
|
6564
|
+
code: 'ILLEGAL_REASSIGNMENT',
|
|
6565
|
+
message: `Illegal reassignment to import '${this.name}'`
|
|
6566
|
+
}, this.start);
|
|
6567
|
+
}
|
|
6568
|
+
getVariableRespectingTDZ() {
|
|
6569
|
+
if (this.isPossibleTDZ()) {
|
|
6570
|
+
return UNKNOWN_EXPRESSION;
|
|
6571
|
+
}
|
|
6572
|
+
return this.variable;
|
|
6573
|
+
}
|
|
6728
6574
|
}
|
|
6729
|
-
function
|
|
6730
|
-
|
|
6731
|
-
|
|
6575
|
+
function closestParentFunctionOrProgram(node) {
|
|
6576
|
+
while (node && !/^Program|Function/.test(node.type)) {
|
|
6577
|
+
node = node.parent;
|
|
6578
|
+
}
|
|
6579
|
+
// one of: ArrowFunctionExpression, FunctionDeclaration, FunctionExpression or Program
|
|
6580
|
+
return node;
|
|
6732
6581
|
}
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6582
|
+
|
|
6583
|
+
const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$';
|
|
6584
|
+
const base = 64;
|
|
6585
|
+
function toBase64(num) {
|
|
6586
|
+
let outStr = '';
|
|
6587
|
+
do {
|
|
6588
|
+
const curDigit = num % base;
|
|
6589
|
+
num = Math.floor(num / base);
|
|
6590
|
+
outStr = chars[curDigit] + outStr;
|
|
6591
|
+
} while (num !== 0);
|
|
6592
|
+
return outStr;
|
|
6593
|
+
}
|
|
6594
|
+
|
|
6595
|
+
const RESERVED_NAMES = {
|
|
6596
|
+
__proto__: null,
|
|
6597
|
+
await: true,
|
|
6598
|
+
break: true,
|
|
6599
|
+
case: true,
|
|
6600
|
+
catch: true,
|
|
6601
|
+
class: true,
|
|
6602
|
+
const: true,
|
|
6603
|
+
continue: true,
|
|
6604
|
+
debugger: true,
|
|
6605
|
+
default: true,
|
|
6606
|
+
delete: true,
|
|
6607
|
+
do: true,
|
|
6608
|
+
else: true,
|
|
6609
|
+
enum: true,
|
|
6610
|
+
eval: true,
|
|
6611
|
+
export: true,
|
|
6612
|
+
extends: true,
|
|
6613
|
+
false: true,
|
|
6614
|
+
finally: true,
|
|
6615
|
+
for: true,
|
|
6616
|
+
function: true,
|
|
6617
|
+
if: true,
|
|
6618
|
+
implements: true,
|
|
6619
|
+
import: true,
|
|
6620
|
+
in: true,
|
|
6621
|
+
instanceof: true,
|
|
6622
|
+
interface: true,
|
|
6623
|
+
let: true,
|
|
6624
|
+
new: true,
|
|
6625
|
+
null: true,
|
|
6626
|
+
package: true,
|
|
6627
|
+
private: true,
|
|
6628
|
+
protected: true,
|
|
6629
|
+
public: true,
|
|
6630
|
+
return: true,
|
|
6631
|
+
static: true,
|
|
6632
|
+
super: true,
|
|
6633
|
+
switch: true,
|
|
6634
|
+
this: true,
|
|
6635
|
+
throw: true,
|
|
6636
|
+
true: true,
|
|
6637
|
+
try: true,
|
|
6638
|
+
typeof: true,
|
|
6639
|
+
undefined: true,
|
|
6640
|
+
var: true,
|
|
6641
|
+
void: true,
|
|
6642
|
+
while: true,
|
|
6643
|
+
with: true,
|
|
6644
|
+
yield: true
|
|
6645
|
+
};
|
|
6646
|
+
|
|
6647
|
+
function getSafeName(baseName, usedNames) {
|
|
6648
|
+
let safeName = baseName;
|
|
6649
|
+
let count = 1;
|
|
6650
|
+
while (usedNames.has(safeName) || RESERVED_NAMES[safeName]) {
|
|
6651
|
+
safeName = `${baseName}$${toBase64(count++)}`;
|
|
6652
|
+
}
|
|
6653
|
+
usedNames.add(safeName);
|
|
6654
|
+
return safeName;
|
|
6655
|
+
}
|
|
6656
|
+
|
|
6657
|
+
const NO_ARGS = [];
|
|
6658
|
+
|
|
6659
|
+
function assembleMemberDescriptions(memberDescriptions, inheritedDescriptions = null) {
|
|
6660
|
+
return Object.create(inheritedDescriptions, memberDescriptions);
|
|
6661
|
+
}
|
|
6662
|
+
const UNDEFINED_EXPRESSION = new (class UndefinedExpression extends ExpressionEntity {
|
|
6663
|
+
getLiteralValueAtPath() {
|
|
6664
|
+
return undefined;
|
|
6665
|
+
}
|
|
6666
|
+
})();
|
|
6667
|
+
const returnsUnknown = {
|
|
6668
|
+
value: {
|
|
6669
|
+
callsArgs: null,
|
|
6670
|
+
returns: UNKNOWN_EXPRESSION
|
|
6671
|
+
}
|
|
6672
|
+
};
|
|
6673
|
+
const UNKNOWN_LITERAL_BOOLEAN = new (class UnknownBoolean extends ExpressionEntity {
|
|
6674
|
+
getReturnExpressionWhenCalledAtPath(path) {
|
|
6675
|
+
if (path.length === 1) {
|
|
6676
|
+
return getMemberReturnExpressionWhenCalled(literalBooleanMembers, path[0]);
|
|
6677
|
+
}
|
|
6678
|
+
return UNKNOWN_EXPRESSION;
|
|
6679
|
+
}
|
|
6680
|
+
hasEffectsWhenAccessedAtPath(path) {
|
|
6681
|
+
return path.length > 1;
|
|
6682
|
+
}
|
|
6683
|
+
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
6684
|
+
if (path.length === 1) {
|
|
6685
|
+
return hasMemberEffectWhenCalled(literalBooleanMembers, path[0], callOptions, context);
|
|
6686
|
+
}
|
|
6687
|
+
return true;
|
|
6688
|
+
}
|
|
6689
|
+
})();
|
|
6690
|
+
const returnsBoolean = {
|
|
6691
|
+
value: {
|
|
6692
|
+
callsArgs: null,
|
|
6693
|
+
returns: UNKNOWN_LITERAL_BOOLEAN
|
|
6694
|
+
}
|
|
6695
|
+
};
|
|
6696
|
+
const UNKNOWN_LITERAL_NUMBER = new (class UnknownNumber extends ExpressionEntity {
|
|
6697
|
+
getReturnExpressionWhenCalledAtPath(path) {
|
|
6698
|
+
if (path.length === 1) {
|
|
6699
|
+
return getMemberReturnExpressionWhenCalled(literalNumberMembers, path[0]);
|
|
6700
|
+
}
|
|
6701
|
+
return UNKNOWN_EXPRESSION;
|
|
6702
|
+
}
|
|
6703
|
+
hasEffectsWhenAccessedAtPath(path) {
|
|
6704
|
+
return path.length > 1;
|
|
6705
|
+
}
|
|
6706
|
+
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
6707
|
+
if (path.length === 1) {
|
|
6708
|
+
return hasMemberEffectWhenCalled(literalNumberMembers, path[0], callOptions, context);
|
|
6709
|
+
}
|
|
6710
|
+
return true;
|
|
6711
|
+
}
|
|
6712
|
+
})();
|
|
6713
|
+
const returnsNumber = {
|
|
6714
|
+
value: {
|
|
6715
|
+
callsArgs: null,
|
|
6716
|
+
returns: UNKNOWN_LITERAL_NUMBER
|
|
6717
|
+
}
|
|
6718
|
+
};
|
|
6719
|
+
const UNKNOWN_LITERAL_STRING = new (class UnknownString extends ExpressionEntity {
|
|
6720
|
+
getReturnExpressionWhenCalledAtPath(path) {
|
|
6721
|
+
if (path.length === 1) {
|
|
6722
|
+
return getMemberReturnExpressionWhenCalled(literalStringMembers, path[0]);
|
|
6723
|
+
}
|
|
6724
|
+
return UNKNOWN_EXPRESSION;
|
|
6725
|
+
}
|
|
6726
|
+
hasEffectsWhenAccessedAtPath(path) {
|
|
6727
|
+
return path.length > 1;
|
|
6728
|
+
}
|
|
6729
|
+
hasEffectsWhenCalledAtPath(path, callOptions, context) {
|
|
6730
|
+
if (path.length === 1) {
|
|
6731
|
+
return hasMemberEffectWhenCalled(literalStringMembers, path[0], callOptions, context);
|
|
6732
|
+
}
|
|
6733
|
+
return true;
|
|
6734
|
+
}
|
|
6735
|
+
})();
|
|
6736
|
+
const returnsString = {
|
|
6737
|
+
value: {
|
|
6738
|
+
callsArgs: null,
|
|
6739
|
+
returns: UNKNOWN_LITERAL_STRING
|
|
6740
|
+
}
|
|
6741
|
+
};
|
|
6742
|
+
const objectMembers = assembleMemberDescriptions({
|
|
6743
|
+
hasOwnProperty: returnsBoolean,
|
|
6744
|
+
isPrototypeOf: returnsBoolean,
|
|
6745
|
+
propertyIsEnumerable: returnsBoolean,
|
|
6746
|
+
toLocaleString: returnsString,
|
|
6747
|
+
toString: returnsString,
|
|
6748
|
+
valueOf: returnsUnknown
|
|
6749
|
+
});
|
|
6750
|
+
const literalBooleanMembers = assembleMemberDescriptions({
|
|
6751
|
+
valueOf: returnsBoolean
|
|
6752
|
+
}, objectMembers);
|
|
6753
|
+
const literalNumberMembers = assembleMemberDescriptions({
|
|
6754
|
+
toExponential: returnsString,
|
|
6755
|
+
toFixed: returnsString,
|
|
6756
|
+
toLocaleString: returnsString,
|
|
6757
|
+
toPrecision: returnsString,
|
|
6758
|
+
valueOf: returnsNumber
|
|
6759
|
+
}, objectMembers);
|
|
6760
|
+
const literalStringMembers = assembleMemberDescriptions({
|
|
6761
|
+
charAt: returnsString,
|
|
6762
|
+
charCodeAt: returnsNumber,
|
|
6763
|
+
codePointAt: returnsNumber,
|
|
6764
|
+
concat: returnsString,
|
|
6765
|
+
endsWith: returnsBoolean,
|
|
6766
|
+
includes: returnsBoolean,
|
|
6767
|
+
indexOf: returnsNumber,
|
|
6768
|
+
lastIndexOf: returnsNumber,
|
|
6769
|
+
localeCompare: returnsNumber,
|
|
6770
|
+
match: returnsBoolean,
|
|
6771
|
+
normalize: returnsString,
|
|
6772
|
+
padEnd: returnsString,
|
|
6773
|
+
padStart: returnsString,
|
|
6774
|
+
repeat: returnsString,
|
|
6775
|
+
replace: {
|
|
6776
|
+
value: {
|
|
6777
|
+
callsArgs: [1],
|
|
6778
|
+
returns: UNKNOWN_LITERAL_STRING
|
|
6779
|
+
}
|
|
6780
|
+
},
|
|
6781
|
+
search: returnsNumber,
|
|
6782
|
+
slice: returnsString,
|
|
6783
|
+
split: returnsUnknown,
|
|
6784
|
+
startsWith: returnsBoolean,
|
|
6785
|
+
substr: returnsString,
|
|
6786
|
+
substring: returnsString,
|
|
6787
|
+
toLocaleLowerCase: returnsString,
|
|
6788
|
+
toLocaleUpperCase: returnsString,
|
|
6789
|
+
toLowerCase: returnsString,
|
|
6790
|
+
toUpperCase: returnsString,
|
|
6791
|
+
trim: returnsString,
|
|
6792
|
+
valueOf: returnsString
|
|
6793
|
+
}, objectMembers);
|
|
6794
|
+
function getLiteralMembersForValue(value) {
|
|
6795
|
+
switch (typeof value) {
|
|
6796
|
+
case 'boolean':
|
|
6797
|
+
return literalBooleanMembers;
|
|
6798
|
+
case 'number':
|
|
6799
|
+
return literalNumberMembers;
|
|
6800
|
+
case 'string':
|
|
6801
|
+
return literalStringMembers;
|
|
6802
|
+
default:
|
|
6803
|
+
return Object.create(null);
|
|
6736
6804
|
}
|
|
6737
|
-
return getGlobalAtPath(path.slice(0, -1)) !== null;
|
|
6738
6805
|
}
|
|
6739
|
-
|
|
6740
|
-
|
|
6741
|
-
|
|
6742
|
-
super(...arguments);
|
|
6743
|
-
this.isReassigned = true;
|
|
6744
|
-
}
|
|
6745
|
-
hasEffectsWhenAccessedAtPath(path) {
|
|
6746
|
-
return !isGlobalMember([this.name, ...path]);
|
|
6806
|
+
function hasMemberEffectWhenCalled(members, memberName, callOptions, context) {
|
|
6807
|
+
if (typeof memberName !== 'string' || !members[memberName]) {
|
|
6808
|
+
return true;
|
|
6747
6809
|
}
|
|
6748
|
-
|
|
6749
|
-
return
|
|
6810
|
+
if (!members[memberName].callsArgs)
|
|
6811
|
+
return false;
|
|
6812
|
+
for (const argIndex of members[memberName].callsArgs) {
|
|
6813
|
+
if (callOptions.args[argIndex] &&
|
|
6814
|
+
callOptions.args[argIndex].hasEffectsWhenCalledAtPath(EMPTY_PATH, {
|
|
6815
|
+
args: NO_ARGS,
|
|
6816
|
+
thisParam: null,
|
|
6817
|
+
withNew: false
|
|
6818
|
+
}, context))
|
|
6819
|
+
return true;
|
|
6750
6820
|
}
|
|
6821
|
+
return false;
|
|
6822
|
+
}
|
|
6823
|
+
function getMemberReturnExpressionWhenCalled(members, memberName) {
|
|
6824
|
+
if (typeof memberName !== 'string' || !members[memberName])
|
|
6825
|
+
return UNKNOWN_EXPRESSION;
|
|
6826
|
+
return members[memberName].returns;
|
|
6751
6827
|
}
|
|
6752
6828
|
|
|
6753
|
-
|
|
6754
|
-
__proto__: null,
|
|
6755
|
-
class: true,
|
|
6756
|
-
const: true,
|
|
6757
|
-
let: true,
|
|
6758
|
-
var: true
|
|
6759
|
-
};
|
|
6760
|
-
class Identifier extends NodeBase {
|
|
6829
|
+
class Scope$1 {
|
|
6761
6830
|
constructor() {
|
|
6762
|
-
|
|
6763
|
-
this.
|
|
6764
|
-
this.deoptimized = false;
|
|
6765
|
-
this.isTDZAccess = null;
|
|
6766
|
-
}
|
|
6767
|
-
addExportedVariables(variables, exportNamesByVariable) {
|
|
6768
|
-
if (this.variable !== null && exportNamesByVariable.has(this.variable)) {
|
|
6769
|
-
variables.push(this.variable);
|
|
6770
|
-
}
|
|
6771
|
-
}
|
|
6772
|
-
bind() {
|
|
6773
|
-
if (this.variable === null && is_reference(this, this.parent)) {
|
|
6774
|
-
this.variable = this.scope.findVariable(this.name);
|
|
6775
|
-
this.variable.addReference(this);
|
|
6776
|
-
}
|
|
6831
|
+
this.children = [];
|
|
6832
|
+
this.variables = new Map();
|
|
6777
6833
|
}
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
variable = this.scope.addDeclaration(this, this.context, init, true);
|
|
6784
|
-
if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
|
|
6785
|
-
// Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
|
|
6786
|
-
variable.markInitializersForDeoptimization();
|
|
6787
|
-
}
|
|
6788
|
-
break;
|
|
6789
|
-
case 'function':
|
|
6790
|
-
// in strict mode, functions are only hoisted within a scope but not across block scopes
|
|
6791
|
-
variable = this.scope.addDeclaration(this, this.context, init, false);
|
|
6792
|
-
break;
|
|
6793
|
-
case 'let':
|
|
6794
|
-
case 'const':
|
|
6795
|
-
case 'class':
|
|
6796
|
-
variable = this.scope.addDeclaration(this, this.context, init, false);
|
|
6797
|
-
break;
|
|
6798
|
-
case 'parameter':
|
|
6799
|
-
variable = this.scope.addParameterDeclaration(this);
|
|
6800
|
-
break;
|
|
6801
|
-
/* istanbul ignore next */
|
|
6802
|
-
default:
|
|
6803
|
-
/* istanbul ignore next */
|
|
6804
|
-
throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
|
|
6834
|
+
addDeclaration(identifier, context, init, _isHoisted) {
|
|
6835
|
+
const name = identifier.name;
|
|
6836
|
+
let variable = this.variables.get(name);
|
|
6837
|
+
if (variable) {
|
|
6838
|
+
variable.addDeclaration(identifier, init);
|
|
6805
6839
|
}
|
|
6806
|
-
|
|
6807
|
-
|
|
6808
|
-
|
|
6809
|
-
deoptimizePath(path) {
|
|
6810
|
-
if (path.length === 0 && !this.scope.contains(this.name)) {
|
|
6811
|
-
this.disallowImportReassignment();
|
|
6840
|
+
else {
|
|
6841
|
+
variable = new LocalVariable(identifier.name, identifier, init || UNDEFINED_EXPRESSION, context);
|
|
6842
|
+
this.variables.set(name, variable);
|
|
6812
6843
|
}
|
|
6813
|
-
|
|
6844
|
+
return variable;
|
|
6814
6845
|
}
|
|
6815
|
-
|
|
6816
|
-
this.
|
|
6846
|
+
contains(name) {
|
|
6847
|
+
return this.variables.has(name);
|
|
6817
6848
|
}
|
|
6818
|
-
|
|
6819
|
-
|
|
6849
|
+
findVariable(_name) {
|
|
6850
|
+
throw new Error('Internal Error: findVariable needs to be implemented by a subclass');
|
|
6820
6851
|
}
|
|
6821
|
-
|
|
6822
|
-
|
|
6852
|
+
}
|
|
6853
|
+
|
|
6854
|
+
class ChildScope extends Scope$1 {
|
|
6855
|
+
constructor(parent) {
|
|
6856
|
+
super();
|
|
6857
|
+
this.accessedOutsideVariables = new Map();
|
|
6858
|
+
this.parent = parent;
|
|
6859
|
+
parent.children.push(this);
|
|
6823
6860
|
}
|
|
6824
|
-
|
|
6825
|
-
|
|
6826
|
-
|
|
6827
|
-
|
|
6828
|
-
return true;
|
|
6861
|
+
addAccessedDynamicImport(importExpression) {
|
|
6862
|
+
(this.accessedDynamicImports || (this.accessedDynamicImports = new Set())).add(importExpression);
|
|
6863
|
+
if (this.parent instanceof ChildScope) {
|
|
6864
|
+
this.parent.addAccessedDynamicImport(importExpression);
|
|
6829
6865
|
}
|
|
6830
|
-
return (this.context.options.treeshake.unknownGlobalSideEffects &&
|
|
6831
|
-
this.variable instanceof GlobalVariable &&
|
|
6832
|
-
this.variable.hasEffectsWhenAccessedAtPath(EMPTY_PATH));
|
|
6833
6866
|
}
|
|
6834
|
-
|
|
6835
|
-
|
|
6836
|
-
|
|
6867
|
+
addAccessedGlobals(globals, accessedGlobalsByScope) {
|
|
6868
|
+
const accessedGlobals = accessedGlobalsByScope.get(this) || new Set();
|
|
6869
|
+
for (const name of globals) {
|
|
6870
|
+
accessedGlobals.add(name);
|
|
6871
|
+
}
|
|
6872
|
+
accessedGlobalsByScope.set(this, accessedGlobals);
|
|
6873
|
+
if (this.parent instanceof ChildScope) {
|
|
6874
|
+
this.parent.addAccessedGlobals(globals, accessedGlobalsByScope);
|
|
6875
|
+
}
|
|
6837
6876
|
}
|
|
6838
|
-
|
|
6839
|
-
|
|
6840
|
-
|
|
6841
|
-
? this.getVariableRespectingTDZ()
|
|
6842
|
-
: this.variable).hasEffectsWhenAssignedAtPath(path, context));
|
|
6877
|
+
addNamespaceMemberAccess(name, variable) {
|
|
6878
|
+
this.accessedOutsideVariables.set(name, variable);
|
|
6879
|
+
this.parent.addNamespaceMemberAccess(name, variable);
|
|
6843
6880
|
}
|
|
6844
|
-
|
|
6845
|
-
|
|
6846
|
-
this.getVariableRespectingTDZ().hasEffectsWhenCalledAtPath(path, callOptions, context));
|
|
6881
|
+
addReturnExpression(expression) {
|
|
6882
|
+
this.parent instanceof ChildScope && this.parent.addReturnExpression(expression);
|
|
6847
6883
|
}
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
|
|
6884
|
+
addUsedOutsideNames(usedNames, format, exportNamesByVariable, accessedGlobalsByScope) {
|
|
6885
|
+
for (const variable of this.accessedOutsideVariables.values()) {
|
|
6886
|
+
if (variable.included) {
|
|
6887
|
+
usedNames.add(variable.getBaseVariableName());
|
|
6888
|
+
if (format === 'system' && exportNamesByVariable.has(variable)) {
|
|
6889
|
+
usedNames.add('exports');
|
|
6890
|
+
}
|
|
6855
6891
|
}
|
|
6856
6892
|
}
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
|
|
6861
|
-
|
|
6862
|
-
// return cached value to avoid issues with the next tree-shaking pass
|
|
6863
|
-
if (this.isTDZAccess !== null)
|
|
6864
|
-
return this.isTDZAccess;
|
|
6865
|
-
if (!(this.variable instanceof LocalVariable) ||
|
|
6866
|
-
!this.variable.kind ||
|
|
6867
|
-
!(this.variable.kind in tdzVariableKinds)) {
|
|
6868
|
-
return (this.isTDZAccess = false);
|
|
6869
|
-
}
|
|
6870
|
-
let decl_id;
|
|
6871
|
-
if (this.variable.declarations &&
|
|
6872
|
-
this.variable.declarations.length === 1 &&
|
|
6873
|
-
(decl_id = this.variable.declarations[0]) &&
|
|
6874
|
-
this.start < decl_id.start &&
|
|
6875
|
-
closestParentFunctionOrProgram(this) === closestParentFunctionOrProgram(decl_id)) {
|
|
6876
|
-
// a variable accessed before its declaration
|
|
6877
|
-
// in the same function or at top level of module
|
|
6878
|
-
return (this.isTDZAccess = true);
|
|
6879
|
-
}
|
|
6880
|
-
if (!this.variable.initReached) {
|
|
6881
|
-
// Either a const/let TDZ violation or
|
|
6882
|
-
// var use before declaration was encountered.
|
|
6883
|
-
return (this.isTDZAccess = true);
|
|
6893
|
+
const accessedGlobals = accessedGlobalsByScope.get(this);
|
|
6894
|
+
if (accessedGlobals) {
|
|
6895
|
+
for (const name of accessedGlobals) {
|
|
6896
|
+
usedNames.add(name);
|
|
6897
|
+
}
|
|
6884
6898
|
}
|
|
6885
|
-
return (this.isTDZAccess = false);
|
|
6886
6899
|
}
|
|
6887
|
-
|
|
6888
|
-
this.
|
|
6900
|
+
contains(name) {
|
|
6901
|
+
return this.variables.has(name) || this.parent.contains(name);
|
|
6889
6902
|
}
|
|
6890
|
-
|
|
6891
|
-
|
|
6892
|
-
|
|
6893
|
-
|
|
6894
|
-
|
|
6895
|
-
|
|
6896
|
-
|
|
6897
|
-
});
|
|
6898
|
-
if (isShorthandProperty) {
|
|
6899
|
-
code.prependRight(this.start, `${this.name}: `);
|
|
6903
|
+
deconflict(format, exportNamesByVariable, accessedGlobalsByScope) {
|
|
6904
|
+
const usedNames = new Set();
|
|
6905
|
+
this.addUsedOutsideNames(usedNames, format, exportNamesByVariable, accessedGlobalsByScope);
|
|
6906
|
+
if (this.accessedDynamicImports) {
|
|
6907
|
+
for (const importExpression of this.accessedDynamicImports) {
|
|
6908
|
+
if (importExpression.inlineNamespace) {
|
|
6909
|
+
usedNames.add(importExpression.inlineNamespace.getBaseVariableName());
|
|
6900
6910
|
}
|
|
6901
6911
|
}
|
|
6902
|
-
// In strict mode, any variable named "eval" must be the actual "eval" function
|
|
6903
|
-
if (name === 'eval' &&
|
|
6904
|
-
renderedParentType === CallExpression$1 &&
|
|
6905
|
-
isCalleeOfRenderedParent) {
|
|
6906
|
-
code.appendRight(this.start, '0, ');
|
|
6907
|
-
}
|
|
6908
|
-
}
|
|
6909
|
-
}
|
|
6910
|
-
applyDeoptimizations() {
|
|
6911
|
-
this.deoptimized = true;
|
|
6912
|
-
if (this.variable !== null && this.variable instanceof LocalVariable) {
|
|
6913
|
-
this.variable.consolidateInitializers();
|
|
6914
|
-
this.context.requestTreeshakingPass();
|
|
6915
6912
|
}
|
|
6916
|
-
|
|
6917
|
-
|
|
6918
|
-
|
|
6919
|
-
|
|
6920
|
-
|
|
6921
|
-
|
|
6922
|
-
|
|
6923
|
-
getVariableRespectingTDZ() {
|
|
6924
|
-
if (this.isPossibleTDZ()) {
|
|
6925
|
-
return UNKNOWN_EXPRESSION;
|
|
6913
|
+
for (const [name, variable] of this.variables) {
|
|
6914
|
+
if (variable.included || variable.alwaysRendered) {
|
|
6915
|
+
variable.setRenderNames(null, getSafeName(name, usedNames));
|
|
6916
|
+
}
|
|
6917
|
+
}
|
|
6918
|
+
for (const scope of this.children) {
|
|
6919
|
+
scope.deconflict(format, exportNamesByVariable, accessedGlobalsByScope);
|
|
6926
6920
|
}
|
|
6927
|
-
return this.variable;
|
|
6928
6921
|
}
|
|
6929
|
-
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
6922
|
+
findLexicalBoundary() {
|
|
6923
|
+
return this.parent.findLexicalBoundary();
|
|
6924
|
+
}
|
|
6925
|
+
findVariable(name) {
|
|
6926
|
+
const knownVariable = this.variables.get(name) || this.accessedOutsideVariables.get(name);
|
|
6927
|
+
if (knownVariable) {
|
|
6928
|
+
return knownVariable;
|
|
6929
|
+
}
|
|
6930
|
+
const variable = this.parent.findVariable(name);
|
|
6931
|
+
this.accessedOutsideVariables.set(name, variable);
|
|
6932
|
+
return variable;
|
|
6933
6933
|
}
|
|
6934
|
-
// one of: ArrowFunctionExpression, FunctionDeclaration, FunctionExpression or Program
|
|
6935
|
-
return node;
|
|
6936
6934
|
}
|
|
6937
6935
|
|
|
6938
6936
|
const EVENT_ACCESSED = 0;
|
|
@@ -7628,7 +7626,7 @@ class ClassDeclaration extends ClassNode {
|
|
|
7628
7626
|
}
|
|
7629
7627
|
parseNode(esTreeNode) {
|
|
7630
7628
|
if (esTreeNode.id !== null) {
|
|
7631
|
-
this.id = new
|
|
7629
|
+
this.id = new Identifier(esTreeNode.id, this, this.scope.parent);
|
|
7632
7630
|
}
|
|
7633
7631
|
super.parseNode(esTreeNode);
|
|
7634
7632
|
}
|
|
@@ -7864,6 +7862,101 @@ class FunctionScope extends ReturnValueScope {
|
|
|
7864
7862
|
}
|
|
7865
7863
|
}
|
|
7866
7864
|
|
|
7865
|
+
class BlockScope extends ChildScope {
|
|
7866
|
+
addDeclaration(identifier, context, init, isHoisted) {
|
|
7867
|
+
if (isHoisted) {
|
|
7868
|
+
const variable = this.parent.addDeclaration(identifier, context, init, isHoisted);
|
|
7869
|
+
// Necessary to make sure the init is deoptimized for conditional declarations.
|
|
7870
|
+
// We cannot call deoptimizePath here.
|
|
7871
|
+
variable.markInitializersForDeoptimization();
|
|
7872
|
+
return variable;
|
|
7873
|
+
}
|
|
7874
|
+
else {
|
|
7875
|
+
return super.addDeclaration(identifier, context, init, false);
|
|
7876
|
+
}
|
|
7877
|
+
}
|
|
7878
|
+
}
|
|
7879
|
+
|
|
7880
|
+
class ExpressionStatement extends NodeBase {
|
|
7881
|
+
initialise() {
|
|
7882
|
+
if (this.directive &&
|
|
7883
|
+
this.directive !== 'use strict' &&
|
|
7884
|
+
this.parent.type === Program$1) {
|
|
7885
|
+
this.context.warn(
|
|
7886
|
+
// This is necessary, because either way (deleting or not) can lead to errors.
|
|
7887
|
+
{
|
|
7888
|
+
code: 'MODULE_LEVEL_DIRECTIVE',
|
|
7889
|
+
message: `Module level directives cause errors when bundled, '${this.directive}' was ignored.`
|
|
7890
|
+
}, this.start);
|
|
7891
|
+
}
|
|
7892
|
+
}
|
|
7893
|
+
render(code, options) {
|
|
7894
|
+
super.render(code, options);
|
|
7895
|
+
if (this.included)
|
|
7896
|
+
this.insertSemicolon(code);
|
|
7897
|
+
}
|
|
7898
|
+
shouldBeIncluded(context) {
|
|
7899
|
+
if (this.directive && this.directive !== 'use strict')
|
|
7900
|
+
return this.parent.type !== Program$1;
|
|
7901
|
+
return super.shouldBeIncluded(context);
|
|
7902
|
+
}
|
|
7903
|
+
}
|
|
7904
|
+
|
|
7905
|
+
class BlockStatement extends NodeBase {
|
|
7906
|
+
constructor() {
|
|
7907
|
+
super(...arguments);
|
|
7908
|
+
this.directlyIncluded = false;
|
|
7909
|
+
}
|
|
7910
|
+
addImplicitReturnExpressionToScope() {
|
|
7911
|
+
const lastStatement = this.body[this.body.length - 1];
|
|
7912
|
+
if (!lastStatement || lastStatement.type !== ReturnStatement$1) {
|
|
7913
|
+
this.scope.addReturnExpression(UNKNOWN_EXPRESSION);
|
|
7914
|
+
}
|
|
7915
|
+
}
|
|
7916
|
+
createScope(parentScope) {
|
|
7917
|
+
this.scope = this.parent.preventChildBlockScope
|
|
7918
|
+
? parentScope
|
|
7919
|
+
: new BlockScope(parentScope);
|
|
7920
|
+
}
|
|
7921
|
+
hasEffects(context) {
|
|
7922
|
+
if (this.deoptimizeBody)
|
|
7923
|
+
return true;
|
|
7924
|
+
for (const node of this.body) {
|
|
7925
|
+
if (context.brokenFlow)
|
|
7926
|
+
break;
|
|
7927
|
+
if (node.hasEffects(context))
|
|
7928
|
+
return true;
|
|
7929
|
+
}
|
|
7930
|
+
return false;
|
|
7931
|
+
}
|
|
7932
|
+
include(context, includeChildrenRecursively) {
|
|
7933
|
+
if (!(this.deoptimizeBody && this.directlyIncluded)) {
|
|
7934
|
+
this.included = true;
|
|
7935
|
+
this.directlyIncluded = true;
|
|
7936
|
+
if (this.deoptimizeBody)
|
|
7937
|
+
includeChildrenRecursively = true;
|
|
7938
|
+
for (const node of this.body) {
|
|
7939
|
+
if (includeChildrenRecursively || node.shouldBeIncluded(context))
|
|
7940
|
+
node.include(context, includeChildrenRecursively);
|
|
7941
|
+
}
|
|
7942
|
+
}
|
|
7943
|
+
}
|
|
7944
|
+
initialise() {
|
|
7945
|
+
const firstBodyStatement = this.body[0];
|
|
7946
|
+
this.deoptimizeBody =
|
|
7947
|
+
firstBodyStatement instanceof ExpressionStatement &&
|
|
7948
|
+
firstBodyStatement.directive === 'use asm';
|
|
7949
|
+
}
|
|
7950
|
+
render(code, options) {
|
|
7951
|
+
if (this.body.length) {
|
|
7952
|
+
renderStatementList(this.body, code, this.start + 1, this.end - 1, options);
|
|
7953
|
+
}
|
|
7954
|
+
else {
|
|
7955
|
+
super.render(code, options);
|
|
7956
|
+
}
|
|
7957
|
+
}
|
|
7958
|
+
}
|
|
7959
|
+
|
|
7867
7960
|
class RestElement extends NodeBase {
|
|
7868
7961
|
constructor() {
|
|
7869
7962
|
super(...arguments);
|
|
@@ -8023,7 +8116,7 @@ class FunctionNode extends NodeBase {
|
|
|
8023
8116
|
this.body.addImplicitReturnExpressionToScope();
|
|
8024
8117
|
}
|
|
8025
8118
|
parseNode(esTreeNode) {
|
|
8026
|
-
this.body = new
|
|
8119
|
+
this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
|
|
8027
8120
|
super.parseNode(esTreeNode);
|
|
8028
8121
|
}
|
|
8029
8122
|
}
|
|
@@ -8038,7 +8131,7 @@ class FunctionDeclaration extends FunctionNode {
|
|
|
8038
8131
|
}
|
|
8039
8132
|
parseNode(esTreeNode) {
|
|
8040
8133
|
if (esTreeNode.id !== null) {
|
|
8041
|
-
this.id = new
|
|
8134
|
+
this.id = new Identifier(esTreeNode.id, this, this.scope.parent);
|
|
8042
8135
|
}
|
|
8043
8136
|
super.parseNode(esTreeNode);
|
|
8044
8137
|
}
|
|
@@ -8629,101 +8722,6 @@ class ArrayPattern extends NodeBase {
|
|
|
8629
8722
|
}
|
|
8630
8723
|
}
|
|
8631
8724
|
|
|
8632
|
-
class BlockScope extends ChildScope {
|
|
8633
|
-
addDeclaration(identifier, context, init, isHoisted) {
|
|
8634
|
-
if (isHoisted) {
|
|
8635
|
-
const variable = this.parent.addDeclaration(identifier, context, init, isHoisted);
|
|
8636
|
-
// Necessary to make sure the init is deoptimized for conditional declarations.
|
|
8637
|
-
// We cannot call deoptimizePath here.
|
|
8638
|
-
variable.markInitializersForDeoptimization();
|
|
8639
|
-
return variable;
|
|
8640
|
-
}
|
|
8641
|
-
else {
|
|
8642
|
-
return super.addDeclaration(identifier, context, init, false);
|
|
8643
|
-
}
|
|
8644
|
-
}
|
|
8645
|
-
}
|
|
8646
|
-
|
|
8647
|
-
class ExpressionStatement extends NodeBase {
|
|
8648
|
-
initialise() {
|
|
8649
|
-
if (this.directive &&
|
|
8650
|
-
this.directive !== 'use strict' &&
|
|
8651
|
-
this.parent.type === Program$1) {
|
|
8652
|
-
this.context.warn(
|
|
8653
|
-
// This is necessary, because either way (deleting or not) can lead to errors.
|
|
8654
|
-
{
|
|
8655
|
-
code: 'MODULE_LEVEL_DIRECTIVE',
|
|
8656
|
-
message: `Module level directives cause errors when bundled, '${this.directive}' was ignored.`
|
|
8657
|
-
}, this.start);
|
|
8658
|
-
}
|
|
8659
|
-
}
|
|
8660
|
-
render(code, options) {
|
|
8661
|
-
super.render(code, options);
|
|
8662
|
-
if (this.included)
|
|
8663
|
-
this.insertSemicolon(code);
|
|
8664
|
-
}
|
|
8665
|
-
shouldBeIncluded(context) {
|
|
8666
|
-
if (this.directive && this.directive !== 'use strict')
|
|
8667
|
-
return this.parent.type !== Program$1;
|
|
8668
|
-
return super.shouldBeIncluded(context);
|
|
8669
|
-
}
|
|
8670
|
-
}
|
|
8671
|
-
|
|
8672
|
-
class BlockStatement extends NodeBase {
|
|
8673
|
-
constructor() {
|
|
8674
|
-
super(...arguments);
|
|
8675
|
-
this.directlyIncluded = false;
|
|
8676
|
-
}
|
|
8677
|
-
addImplicitReturnExpressionToScope() {
|
|
8678
|
-
const lastStatement = this.body[this.body.length - 1];
|
|
8679
|
-
if (!lastStatement || lastStatement.type !== ReturnStatement$1) {
|
|
8680
|
-
this.scope.addReturnExpression(UNKNOWN_EXPRESSION);
|
|
8681
|
-
}
|
|
8682
|
-
}
|
|
8683
|
-
createScope(parentScope) {
|
|
8684
|
-
this.scope = this.parent.preventChildBlockScope
|
|
8685
|
-
? parentScope
|
|
8686
|
-
: new BlockScope(parentScope);
|
|
8687
|
-
}
|
|
8688
|
-
hasEffects(context) {
|
|
8689
|
-
if (this.deoptimizeBody)
|
|
8690
|
-
return true;
|
|
8691
|
-
for (const node of this.body) {
|
|
8692
|
-
if (node.hasEffects(context))
|
|
8693
|
-
return true;
|
|
8694
|
-
if (context.brokenFlow)
|
|
8695
|
-
break;
|
|
8696
|
-
}
|
|
8697
|
-
return false;
|
|
8698
|
-
}
|
|
8699
|
-
include(context, includeChildrenRecursively) {
|
|
8700
|
-
if (!this.deoptimizeBody || !this.directlyIncluded) {
|
|
8701
|
-
this.included = true;
|
|
8702
|
-
this.directlyIncluded = true;
|
|
8703
|
-
if (this.deoptimizeBody)
|
|
8704
|
-
includeChildrenRecursively = true;
|
|
8705
|
-
for (const node of this.body) {
|
|
8706
|
-
if (includeChildrenRecursively || node.shouldBeIncluded(context))
|
|
8707
|
-
node.include(context, includeChildrenRecursively);
|
|
8708
|
-
}
|
|
8709
|
-
}
|
|
8710
|
-
}
|
|
8711
|
-
initialise() {
|
|
8712
|
-
const firstBodyStatement = this.body[0];
|
|
8713
|
-
this.deoptimizeBody =
|
|
8714
|
-
firstBodyStatement instanceof ExpressionStatement &&
|
|
8715
|
-
firstBodyStatement.directive === 'use asm';
|
|
8716
|
-
}
|
|
8717
|
-
render(code, options) {
|
|
8718
|
-
if (this.body.length) {
|
|
8719
|
-
renderStatementList(this.body, code, this.start + 1, this.end - 1, options);
|
|
8720
|
-
}
|
|
8721
|
-
else {
|
|
8722
|
-
super.render(code, options);
|
|
8723
|
-
}
|
|
8724
|
-
}
|
|
8725
|
-
}
|
|
8726
|
-
|
|
8727
8725
|
class ArrowFunctionExpression extends NodeBase {
|
|
8728
8726
|
constructor() {
|
|
8729
8727
|
super(...arguments);
|
|
@@ -8821,7 +8819,7 @@ class ArrowFunctionExpression extends NodeBase {
|
|
|
8821
8819
|
}
|
|
8822
8820
|
parseNode(esTreeNode) {
|
|
8823
8821
|
if (esTreeNode.body.type === BlockStatement$1) {
|
|
8824
|
-
this.body = new
|
|
8822
|
+
this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
|
|
8825
8823
|
}
|
|
8826
8824
|
super.parseNode(esTreeNode);
|
|
8827
8825
|
}
|
|
@@ -9597,8 +9595,7 @@ class CatchClause extends NodeBase {
|
|
|
9597
9595
|
// name instead of the variable
|
|
9598
9596
|
const { param } = esTreeNode;
|
|
9599
9597
|
if (param) {
|
|
9600
|
-
this.param = new (this.context.
|
|
9601
|
-
this.context.nodeConstructors.UnknownNode)(param, this, this.scope);
|
|
9598
|
+
this.param = new (this.context.getNodeConstructor(param.type))(param, this, this.scope);
|
|
9602
9599
|
this.param.declare('parameter', UNKNOWN_EXPRESSION);
|
|
9603
9600
|
}
|
|
9604
9601
|
super.parseNode(esTreeNode);
|
|
@@ -9634,7 +9631,7 @@ class ClassBody extends NodeBase {
|
|
|
9634
9631
|
parseNode(esTreeNode) {
|
|
9635
9632
|
const body = (this.body = []);
|
|
9636
9633
|
for (const definition of esTreeNode.body) {
|
|
9637
|
-
body.push(new this.context.
|
|
9634
|
+
body.push(new (this.context.getNodeConstructor(definition.type))(definition, this, definition.static ? this.scope : this.scope.instanceScope));
|
|
9638
9635
|
}
|
|
9639
9636
|
super.parseNode(esTreeNode);
|
|
9640
9637
|
}
|
|
@@ -10125,12 +10122,10 @@ class IfStatement extends NodeBase {
|
|
|
10125
10122
|
}
|
|
10126
10123
|
parseNode(esTreeNode) {
|
|
10127
10124
|
this.consequentScope = new TrackingScope(this.scope);
|
|
10128
|
-
this.consequent = new (this.context.
|
|
10129
|
-
this.context.nodeConstructors.UnknownNode)(esTreeNode.consequent, this, this.consequentScope);
|
|
10125
|
+
this.consequent = new (this.context.getNodeConstructor(esTreeNode.consequent.type))(esTreeNode.consequent, this, this.consequentScope);
|
|
10130
10126
|
if (esTreeNode.alternate) {
|
|
10131
10127
|
this.alternateScope = new TrackingScope(this.scope);
|
|
10132
|
-
this.alternate = new (this.context.
|
|
10133
|
-
this.context.nodeConstructors.UnknownNode)(esTreeNode.alternate, this, this.alternateScope);
|
|
10128
|
+
this.alternate = new (this.context.getNodeConstructor(esTreeNode.alternate.type))(esTreeNode.alternate, this, this.alternateScope);
|
|
10134
10129
|
}
|
|
10135
10130
|
super.parseNode(esTreeNode);
|
|
10136
10131
|
}
|
|
@@ -10362,13 +10357,18 @@ const HELPER_GENERATORS = {
|
|
|
10362
10357
|
`}${n}${n}`);
|
|
10363
10358
|
},
|
|
10364
10359
|
[MERGE_NAMESPACES_VARIABLE](t, snippets, liveBindings, freeze) {
|
|
10365
|
-
const { _, n } = snippets;
|
|
10360
|
+
const { _, cnst, n } = snippets;
|
|
10361
|
+
const useForEach = cnst === 'var' && liveBindings;
|
|
10366
10362
|
return (`function ${MERGE_NAMESPACES_VARIABLE}(n, m)${_}{${n}` +
|
|
10367
10363
|
`${t}${loopOverNamespaces(`{${n}` +
|
|
10368
10364
|
`${t}${t}${t}if${_}(k${_}!==${_}'default'${_}&&${_}!(k in n))${_}{${n}` +
|
|
10369
|
-
(liveBindings
|
|
10365
|
+
(liveBindings
|
|
10366
|
+
? useForEach
|
|
10367
|
+
? copyOwnPropertyLiveBinding
|
|
10368
|
+
: copyPropertyLiveBinding
|
|
10369
|
+
: copyPropertyStatic)(t, t + t + t + t, snippets) +
|
|
10370
10370
|
`${t}${t}${t}}${n}` +
|
|
10371
|
-
`${t}${t}}`,
|
|
10371
|
+
`${t}${t}}`, useForEach, t, snippets)}${n}` +
|
|
10372
10372
|
`${t}return ${getFrozen('n', freeze)};${n}` +
|
|
10373
10373
|
`}${n}${n}`);
|
|
10374
10374
|
}
|
|
@@ -10378,7 +10378,7 @@ const getDefaultStatic = ({ _, getPropertyAccess }) => `e${getPropertyAccess('de
|
|
|
10378
10378
|
const createNamespaceObject = (t, i, snippets, liveBindings, freeze, namespaceToStringTag) => {
|
|
10379
10379
|
const { _, cnst, getPropertyAccess, n, s } = snippets;
|
|
10380
10380
|
const copyProperty = `{${n}` +
|
|
10381
|
-
(liveBindings ?
|
|
10381
|
+
(liveBindings ? copyNonDefaultOwnPropertyLiveBinding : copyPropertyStatic)(t, i + t + t, snippets) +
|
|
10382
10382
|
`${i}${t}}`;
|
|
10383
10383
|
return (`${i}${cnst} n${_}=${_}${namespaceToStringTag
|
|
10384
10384
|
? `{__proto__:${_}null,${_}[Symbol.toStringTag]:${_}'Module'}`
|
|
@@ -10395,30 +10395,30 @@ const loopOverKeys = (body, allowVarLoopVariable, { _, cnst, getFunctionIntro, s
|
|
|
10395
10395
|
isAsync: false,
|
|
10396
10396
|
name: null
|
|
10397
10397
|
})}${body})${s}`;
|
|
10398
|
-
const loopOverNamespaces = (body,
|
|
10399
|
-
if (
|
|
10400
|
-
|
|
10401
|
-
|
|
10402
|
-
|
|
10403
|
-
}
|
|
10404
|
-
const [left, right] = getDirectReturnFunction(['e'], {
|
|
10405
|
-
functionReturn: false,
|
|
10406
|
-
lineBreakIndent: { base: t, t },
|
|
10407
|
-
name: null
|
|
10408
|
-
});
|
|
10409
|
-
return (`m.forEach(${left}` +
|
|
10410
|
-
`Object.keys(e).forEach(${getFunctionIntro(['k'], {
|
|
10411
|
-
isAsync: false,
|
|
10398
|
+
const loopOverNamespaces = (body, useForEach, t, { _, cnst, getDirectReturnFunction, getFunctionIntro, n }) => {
|
|
10399
|
+
if (useForEach) {
|
|
10400
|
+
const [left, right] = getDirectReturnFunction(['e'], {
|
|
10401
|
+
functionReturn: false,
|
|
10402
|
+
lineBreakIndent: { base: t, t },
|
|
10412
10403
|
name: null
|
|
10413
|
-
})
|
|
10404
|
+
});
|
|
10405
|
+
return (`m.forEach(${left}` +
|
|
10406
|
+
`e${_}&&${_}typeof e${_}!==${_}'string'${_}&&${_}!Array.isArray(e)${_}&&${_}Object.keys(e).forEach(${getFunctionIntro(['k'], {
|
|
10407
|
+
isAsync: false,
|
|
10408
|
+
name: null
|
|
10409
|
+
})}${body})${right});`);
|
|
10410
|
+
}
|
|
10411
|
+
return (`for${_}(var i${_}=${_}0;${_}i${_}<${_}m.length;${_}i++)${_}{${n}` +
|
|
10412
|
+
`${t}${t}${cnst} e${_}=${_}m[i];${n}` +
|
|
10413
|
+
`${t}${t}if${_}(typeof e${_}!==${_}'string'${_}&&${_}!Array.isArray(e))${_}{${_}for${_}(${cnst} k in e)${_}${body}${_}}${n}${t}}`);
|
|
10414
10414
|
};
|
|
10415
|
-
const
|
|
10415
|
+
const copyNonDefaultOwnPropertyLiveBinding = (t, i, snippets) => {
|
|
10416
10416
|
const { _, n } = snippets;
|
|
10417
10417
|
return (`${i}if${_}(k${_}!==${_}'default')${_}{${n}` +
|
|
10418
|
-
|
|
10418
|
+
copyOwnPropertyLiveBinding(t, i + t, snippets) +
|
|
10419
10419
|
`${i}}${n}`);
|
|
10420
10420
|
};
|
|
10421
|
-
const
|
|
10421
|
+
const copyOwnPropertyLiveBinding = (t, i, { _, cnst, getDirectReturnFunction, n }) => {
|
|
10422
10422
|
const [left, right] = getDirectReturnFunction([], {
|
|
10423
10423
|
functionReturn: true,
|
|
10424
10424
|
lineBreakIndent: null,
|
|
@@ -10430,6 +10430,20 @@ const copyPropertyLiveBinding = (t, i, { _, cnst, getDirectReturnFunction, n })
|
|
|
10430
10430
|
`${i}${t}get:${_}${left}e[k]${right}${n}` +
|
|
10431
10431
|
`${i}});${n}`);
|
|
10432
10432
|
};
|
|
10433
|
+
const copyPropertyLiveBinding = (t, i, { _, cnst, getDirectReturnFunction, n }) => {
|
|
10434
|
+
const [left, right] = getDirectReturnFunction([], {
|
|
10435
|
+
functionReturn: true,
|
|
10436
|
+
lineBreakIndent: null,
|
|
10437
|
+
name: null
|
|
10438
|
+
});
|
|
10439
|
+
return (`${i}${cnst} d${_}=${_}Object.getOwnPropertyDescriptor(e,${_}k);${n}` +
|
|
10440
|
+
`${i}if${_}(d)${_}{${n}` +
|
|
10441
|
+
`${i}${t}Object.defineProperty(n,${_}k,${_}d.get${_}?${_}d${_}:${_}{${n}` +
|
|
10442
|
+
`${i}${t}${t}enumerable:${_}true,${n}` +
|
|
10443
|
+
`${i}${t}${t}get:${_}${left}e[k]${right}${n}` +
|
|
10444
|
+
`${i}${t}});${n}` +
|
|
10445
|
+
`${i}}${n}`);
|
|
10446
|
+
};
|
|
10433
10447
|
const copyPropertyStatic = (_t, i, { _, n }) => `${i}n[k]${_}=${_}e[k];${n}`;
|
|
10434
10448
|
const getFrozen = (fragment, freeze) => freeze ? `Object.freeze(${fragment})` : fragment;
|
|
10435
10449
|
const HELPER_NAMES = Object.keys(HELPER_GENERATORS);
|
|
@@ -11241,6 +11255,34 @@ class SequenceExpression extends NodeBase {
|
|
|
11241
11255
|
}
|
|
11242
11256
|
}
|
|
11243
11257
|
|
|
11258
|
+
class StaticBlock extends NodeBase {
|
|
11259
|
+
createScope(parentScope) {
|
|
11260
|
+
this.scope = new BlockScope(parentScope);
|
|
11261
|
+
}
|
|
11262
|
+
hasEffects(context) {
|
|
11263
|
+
for (const node of this.body) {
|
|
11264
|
+
if (node.hasEffects(context))
|
|
11265
|
+
return true;
|
|
11266
|
+
}
|
|
11267
|
+
return false;
|
|
11268
|
+
}
|
|
11269
|
+
include(context, includeChildrenRecursively) {
|
|
11270
|
+
this.included = true;
|
|
11271
|
+
for (const node of this.body) {
|
|
11272
|
+
if (includeChildrenRecursively || node.shouldBeIncluded(context))
|
|
11273
|
+
node.include(context, includeChildrenRecursively);
|
|
11274
|
+
}
|
|
11275
|
+
}
|
|
11276
|
+
render(code, options) {
|
|
11277
|
+
if (this.body.length) {
|
|
11278
|
+
renderStatementList(this.body, code, this.start + 1, this.end - 1, options);
|
|
11279
|
+
}
|
|
11280
|
+
else {
|
|
11281
|
+
super.render(code, options);
|
|
11282
|
+
}
|
|
11283
|
+
}
|
|
11284
|
+
}
|
|
11285
|
+
|
|
11244
11286
|
class Super extends NodeBase {
|
|
11245
11287
|
bind() {
|
|
11246
11288
|
this.variable = this.scope.findVariable('this');
|
|
@@ -11873,6 +11915,7 @@ const nodeConstructors = {
|
|
|
11873
11915
|
ReturnStatement,
|
|
11874
11916
|
SequenceExpression,
|
|
11875
11917
|
SpreadElement,
|
|
11918
|
+
StaticBlock,
|
|
11876
11919
|
Super,
|
|
11877
11920
|
SwitchCase,
|
|
11878
11921
|
SwitchStatement,
|
|
@@ -12271,7 +12314,6 @@ class Module {
|
|
|
12271
12314
|
this.isExecuted = false;
|
|
12272
12315
|
this.isUserDefinedEntryPoint = false;
|
|
12273
12316
|
this.needsExportShim = false;
|
|
12274
|
-
this.preserveSignature = this.options.preserveEntrySignatures;
|
|
12275
12317
|
this.reexportDescriptions = Object.create(null);
|
|
12276
12318
|
this.sideEffectDependenciesByVariable = new Map();
|
|
12277
12319
|
this.sources = new Set();
|
|
@@ -12289,6 +12331,7 @@ class Module {
|
|
|
12289
12331
|
this.transitiveReexports = null;
|
|
12290
12332
|
this.excludeFromSourcemap = /\0/.test(id);
|
|
12291
12333
|
this.context = options.moduleContext(id);
|
|
12334
|
+
this.preserveSignature = this.options.preserveEntrySignatures;
|
|
12292
12335
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
12293
12336
|
const module = this;
|
|
12294
12337
|
this.info = {
|
|
@@ -12666,6 +12709,7 @@ class Module {
|
|
|
12666
12709
|
getExports: this.getExports.bind(this),
|
|
12667
12710
|
getModuleExecIndex: () => this.execIndex,
|
|
12668
12711
|
getModuleName: this.basename.bind(this),
|
|
12712
|
+
getNodeConstructor: (name) => nodeConstructors[name] || nodeConstructors.UnknownNode,
|
|
12669
12713
|
getReexports: this.getReexports.bind(this),
|
|
12670
12714
|
importDescriptions: this.importDescriptions,
|
|
12671
12715
|
includeAllExports: () => this.includeAllExports(true),
|
|
@@ -12674,7 +12718,6 @@ class Module {
|
|
|
12674
12718
|
magicString: this.magicString,
|
|
12675
12719
|
module: this,
|
|
12676
12720
|
moduleContext: this.context,
|
|
12677
|
-
nodeConstructors,
|
|
12678
12721
|
options: this.options,
|
|
12679
12722
|
requestTreeshakingPass: () => (this.graph.needsTreeshakingPass = true),
|
|
12680
12723
|
traceExport: this.getVariableForExportName.bind(this),
|