rollup 4.0.2 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/rollup +2 -2
- package/dist/es/getLogFilter.js +2 -2
- package/dist/es/parseAst.js +2 -2
- package/dist/es/rollup.js +2 -2
- package/dist/es/shared/node-entry.js +300 -145
- package/dist/es/shared/parseAst.js +2 -2
- package/dist/es/shared/watch.js +2 -2
- package/dist/getLogFilter.js +2 -2
- package/dist/loadConfigFile.js +2 -2
- package/dist/parseAst.js +2 -2
- package/dist/rollup.d.ts +3 -3
- package/dist/rollup.js +2 -2
- package/dist/shared/fsevents-importer.js +2 -2
- package/dist/shared/index.js +2 -2
- package/dist/shared/loadConfigFile.js +2 -2
- package/dist/shared/parseAst.js +2 -2
- package/dist/shared/rollup.js +300 -145
- package/dist/shared/watch-cli.js +2 -2
- package/dist/shared/watch-proxy.js +2 -2
- package/dist/shared/watch.js +2 -2
- package/package.json +31 -31
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v4.
|
|
4
|
-
|
|
3
|
+
Rollup.js v4.1.1
|
|
4
|
+
Sun, 15 Oct 2023 06:30:58 GMT - commit d8b31a202a246758b8d67eefe77361a894d37005
|
|
5
5
|
|
|
6
6
|
https://github.com/rollup/rollup
|
|
7
7
|
|
|
@@ -16,7 +16,7 @@ import { xxhashBase64Url } from '../../native.js';
|
|
|
16
16
|
import { lstat, realpath, readdir, readFile, mkdir, writeFile } from 'node:fs/promises';
|
|
17
17
|
import * as tty from 'tty';
|
|
18
18
|
|
|
19
|
-
var version = "4.
|
|
19
|
+
var version = "4.1.1";
|
|
20
20
|
|
|
21
21
|
const comma = ','.charCodeAt(0);
|
|
22
22
|
const semicolon = ';'.charCodeAt(0);
|
|
@@ -1810,11 +1810,24 @@ class DiscriminatedPathTracker {
|
|
|
1810
1810
|
}
|
|
1811
1811
|
}
|
|
1812
1812
|
|
|
1813
|
+
function isFlagSet(flags, flag) {
|
|
1814
|
+
return (flags & flag) !== 0;
|
|
1815
|
+
}
|
|
1816
|
+
function setFlag(flags, flag, value) {
|
|
1817
|
+
return (flags & ~flag) | (-value & flag);
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1813
1820
|
const UnknownValue = Symbol('Unknown Value');
|
|
1814
1821
|
const UnknownTruthyValue = Symbol('Unknown Truthy Value');
|
|
1815
1822
|
class ExpressionEntity {
|
|
1816
1823
|
constructor() {
|
|
1817
|
-
this.
|
|
1824
|
+
this.flags = 0;
|
|
1825
|
+
}
|
|
1826
|
+
get included() {
|
|
1827
|
+
return isFlagSet(this.flags, 1 /* Flag.included */);
|
|
1828
|
+
}
|
|
1829
|
+
set included(value) {
|
|
1830
|
+
this.flags = setFlag(this.flags, 1 /* Flag.included */, value);
|
|
1818
1831
|
}
|
|
1819
1832
|
deoptimizeArgumentsOnInteractionAtPath(interaction, _path, _recursionTracker) {
|
|
1820
1833
|
deoptimizeInteraction(interaction);
|
|
@@ -4548,33 +4561,40 @@ const keys = {
|
|
|
4548
4561
|
Literal: [],
|
|
4549
4562
|
Program: ['body']
|
|
4550
4563
|
};
|
|
4551
|
-
function
|
|
4552
|
-
|
|
4553
|
-
return keys[esTreeNode.type];
|
|
4564
|
+
function createKeysForNode(esTreeNode) {
|
|
4565
|
+
return Object.keys(esTreeNode).filter(key => typeof esTreeNode[key] === 'object' && key.charCodeAt(0) !== 95 /* _ */);
|
|
4554
4566
|
}
|
|
4555
4567
|
|
|
4556
4568
|
const INCLUDE_PARAMETERS = 'variables';
|
|
4557
4569
|
class NodeBase extends ExpressionEntity {
|
|
4570
|
+
/**
|
|
4571
|
+
* Nodes can apply custom deoptimizations once they become part of the
|
|
4572
|
+
* executed code. To do this, they must initialize this as false, implement
|
|
4573
|
+
* applyDeoptimizations and call this from include and hasEffects if they have
|
|
4574
|
+
* custom handlers
|
|
4575
|
+
*/
|
|
4576
|
+
get deoptimized() {
|
|
4577
|
+
return isFlagSet(this.flags, 2 /* Flag.deoptimized */);
|
|
4578
|
+
}
|
|
4579
|
+
set deoptimized(value) {
|
|
4580
|
+
this.flags = setFlag(this.flags, 2 /* Flag.deoptimized */, value);
|
|
4581
|
+
}
|
|
4558
4582
|
constructor(esTreeNode, parent, parentScope, keepEsTreeNode = false) {
|
|
4559
4583
|
super();
|
|
4560
|
-
/**
|
|
4561
|
-
* Nodes can apply custom deoptimizations once they become part of the
|
|
4562
|
-
* executed code. To do this, they must initialize this as false, implement
|
|
4563
|
-
* applyDeoptimizations and call this from include and hasEffects if they have
|
|
4564
|
-
* custom handlers
|
|
4565
|
-
*/
|
|
4566
|
-
this.deoptimized = false;
|
|
4567
4584
|
// Nodes can opt-in to keep the AST if needed during the build pipeline.
|
|
4568
4585
|
// Avoid true when possible as large AST takes up memory.
|
|
4569
|
-
|
|
4570
|
-
|
|
4586
|
+
if (keepEsTreeNode) {
|
|
4587
|
+
this.esTreeNode = esTreeNode;
|
|
4588
|
+
}
|
|
4589
|
+
const { type } = esTreeNode;
|
|
4590
|
+
keys[type] ||= createKeysForNode(esTreeNode);
|
|
4571
4591
|
this.parent = parent;
|
|
4572
|
-
this.
|
|
4592
|
+
this.scope = parentScope;
|
|
4573
4593
|
this.createScope(parentScope);
|
|
4574
4594
|
this.parseNode(esTreeNode);
|
|
4575
4595
|
this.initialise();
|
|
4576
|
-
this.context.magicString.addSourcemapLocation(this.start);
|
|
4577
|
-
this.context.magicString.addSourcemapLocation(this.end);
|
|
4596
|
+
this.scope.context.magicString.addSourcemapLocation(this.start);
|
|
4597
|
+
this.scope.context.magicString.addSourcemapLocation(this.end);
|
|
4578
4598
|
}
|
|
4579
4599
|
addExportedVariables(_variables, _exportNamesByVariable) { }
|
|
4580
4600
|
/**
|
|
@@ -4582,7 +4602,7 @@ class NodeBase extends ExpressionEntity {
|
|
|
4582
4602
|
* that require the scopes to be populated with variables.
|
|
4583
4603
|
*/
|
|
4584
4604
|
bind() {
|
|
4585
|
-
for (const key of this.
|
|
4605
|
+
for (const key of keys[this.type]) {
|
|
4586
4606
|
const value = this[key];
|
|
4587
4607
|
if (Array.isArray(value)) {
|
|
4588
4608
|
for (const child of value) {
|
|
@@ -4604,7 +4624,7 @@ class NodeBase extends ExpressionEntity {
|
|
|
4604
4624
|
hasEffects(context) {
|
|
4605
4625
|
if (!this.deoptimized)
|
|
4606
4626
|
this.applyDeoptimizations();
|
|
4607
|
-
for (const key of this.
|
|
4627
|
+
for (const key of keys[this.type]) {
|
|
4608
4628
|
const value = this[key];
|
|
4609
4629
|
if (value === null)
|
|
4610
4630
|
continue;
|
|
@@ -4627,7 +4647,7 @@ class NodeBase extends ExpressionEntity {
|
|
|
4627
4647
|
if (!this.deoptimized)
|
|
4628
4648
|
this.applyDeoptimizations();
|
|
4629
4649
|
this.included = true;
|
|
4630
|
-
for (const key of this.
|
|
4650
|
+
for (const key of keys[this.type]) {
|
|
4631
4651
|
const value = this[key];
|
|
4632
4652
|
if (value === null)
|
|
4633
4653
|
continue;
|
|
@@ -4651,23 +4671,26 @@ class NodeBase extends ExpressionEntity {
|
|
|
4651
4671
|
initialise() { }
|
|
4652
4672
|
parseNode(esTreeNode, keepEsTreeNodeKeys) {
|
|
4653
4673
|
for (const [key, value] of Object.entries(esTreeNode)) {
|
|
4654
|
-
//
|
|
4674
|
+
// Skip properties defined on the class already.
|
|
4675
|
+
// This way, we can override this function to add custom initialisation and then call super.parseNode
|
|
4676
|
+
// Note: this doesn't skip properties with defined getters/setters which we use to pack wrap booleans
|
|
4677
|
+
// in bitfields. Those are still assigned from the value in the esTreeNode.
|
|
4655
4678
|
if (this.hasOwnProperty(key))
|
|
4656
4679
|
continue;
|
|
4657
4680
|
if (key.charCodeAt(0) === 95 /* _ */) {
|
|
4658
4681
|
if (key === ANNOTATION_KEY) {
|
|
4659
4682
|
const annotations = value;
|
|
4660
4683
|
this.annotations = annotations;
|
|
4661
|
-
if (this.context.options.treeshake.annotations) {
|
|
4684
|
+
if (this.scope.context.options.treeshake.annotations) {
|
|
4662
4685
|
this.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
|
|
4663
4686
|
this.annotationPure = annotations.some(comment => comment.type === 'pure');
|
|
4664
4687
|
}
|
|
4665
4688
|
}
|
|
4666
4689
|
else if (key === INVALID_ANNOTATION_KEY) {
|
|
4667
4690
|
for (const { start, end, type } of value) {
|
|
4668
|
-
this.context.magicString.remove(start, end);
|
|
4691
|
+
this.scope.context.magicString.remove(start, end);
|
|
4669
4692
|
if (type === 'pure' || type === 'noSideEffects') {
|
|
4670
|
-
this.context.log(LOGLEVEL_WARN, logInvalidAnnotation(this.context.code.slice(start, end), this.context.module.id, type), start);
|
|
4693
|
+
this.scope.context.log(LOGLEVEL_WARN, logInvalidAnnotation(this.scope.context.code.slice(start, end), this.scope.context.module.id, type), start);
|
|
4671
4694
|
}
|
|
4672
4695
|
}
|
|
4673
4696
|
}
|
|
@@ -4680,11 +4703,11 @@ class NodeBase extends ExpressionEntity {
|
|
|
4680
4703
|
for (const child of value) {
|
|
4681
4704
|
this[key].push(child === null
|
|
4682
4705
|
? null
|
|
4683
|
-
: new (this.context.getNodeConstructor(child.type))(child, this, this.scope, keepEsTreeNodeKeys?.includes(key)));
|
|
4706
|
+
: new (this.scope.context.getNodeConstructor(child.type))(child, this, this.scope, keepEsTreeNodeKeys?.includes(key)));
|
|
4684
4707
|
}
|
|
4685
4708
|
}
|
|
4686
4709
|
else {
|
|
4687
|
-
this[key] = new (this.context.getNodeConstructor(value.type))(value, this, this.scope, keepEsTreeNodeKeys?.includes(key));
|
|
4710
|
+
this[key] = new (this.scope.context.getNodeConstructor(value.type))(value, this, this.scope, keepEsTreeNodeKeys?.includes(key));
|
|
4688
4711
|
}
|
|
4689
4712
|
}
|
|
4690
4713
|
}
|
|
@@ -4696,7 +4719,7 @@ class NodeBase extends ExpressionEntity {
|
|
|
4696
4719
|
}
|
|
4697
4720
|
}
|
|
4698
4721
|
render(code, options) {
|
|
4699
|
-
for (const key of this.
|
|
4722
|
+
for (const key of keys[this.type]) {
|
|
4700
4723
|
const value = this[key];
|
|
4701
4724
|
if (value === null)
|
|
4702
4725
|
continue;
|
|
@@ -4723,7 +4746,7 @@ class NodeBase extends ExpressionEntity {
|
|
|
4723
4746
|
*/
|
|
4724
4747
|
applyDeoptimizations() {
|
|
4725
4748
|
this.deoptimized = true;
|
|
4726
|
-
for (const key of this.
|
|
4749
|
+
for (const key of keys[this.type]) {
|
|
4727
4750
|
const value = this[key];
|
|
4728
4751
|
if (value === null)
|
|
4729
4752
|
continue;
|
|
@@ -4736,7 +4759,7 @@ class NodeBase extends ExpressionEntity {
|
|
|
4736
4759
|
value.deoptimizePath(UNKNOWN_PATH);
|
|
4737
4760
|
}
|
|
4738
4761
|
}
|
|
4739
|
-
this.context.requestTreeshakingPass();
|
|
4762
|
+
this.scope.context.requestTreeshakingPass();
|
|
4740
4763
|
}
|
|
4741
4764
|
}
|
|
4742
4765
|
|
|
@@ -4749,7 +4772,7 @@ class SpreadElement extends NodeBase {
|
|
|
4749
4772
|
hasEffects(context) {
|
|
4750
4773
|
if (!this.deoptimized)
|
|
4751
4774
|
this.applyDeoptimizations();
|
|
4752
|
-
const { propertyReadSideEffects } = this.context.options
|
|
4775
|
+
const { propertyReadSideEffects } = this.scope.context.options
|
|
4753
4776
|
.treeshake;
|
|
4754
4777
|
return (this.argument.hasEffects(context) ||
|
|
4755
4778
|
(propertyReadSideEffects &&
|
|
@@ -4761,7 +4784,7 @@ class SpreadElement extends NodeBase {
|
|
|
4761
4784
|
// Only properties of properties of the argument could become subject to reassignment
|
|
4762
4785
|
// This will also reassign the return values of iterators
|
|
4763
4786
|
this.argument.deoptimizePath([UnknownKey, UnknownKey]);
|
|
4764
|
-
this.context.requestTreeshakingPass();
|
|
4787
|
+
this.scope.context.requestTreeshakingPass();
|
|
4765
4788
|
}
|
|
4766
4789
|
}
|
|
4767
4790
|
|
|
@@ -4844,6 +4867,24 @@ const METHOD_RETURNS_UNKNOWN = [
|
|
|
4844
4867
|
|
|
4845
4868
|
const INTEGER_REG_EXP = /^\d+$/;
|
|
4846
4869
|
class ObjectEntity extends ExpressionEntity {
|
|
4870
|
+
get hasLostTrack() {
|
|
4871
|
+
return isFlagSet(this.flags, 2048 /* Flag.hasLostTrack */);
|
|
4872
|
+
}
|
|
4873
|
+
set hasLostTrack(value) {
|
|
4874
|
+
this.flags = setFlag(this.flags, 2048 /* Flag.hasLostTrack */, value);
|
|
4875
|
+
}
|
|
4876
|
+
get hasUnknownDeoptimizedInteger() {
|
|
4877
|
+
return isFlagSet(this.flags, 4096 /* Flag.hasUnknownDeoptimizedInteger */);
|
|
4878
|
+
}
|
|
4879
|
+
set hasUnknownDeoptimizedInteger(value) {
|
|
4880
|
+
this.flags = setFlag(this.flags, 4096 /* Flag.hasUnknownDeoptimizedInteger */, value);
|
|
4881
|
+
}
|
|
4882
|
+
get hasUnknownDeoptimizedProperty() {
|
|
4883
|
+
return isFlagSet(this.flags, 8192 /* Flag.hasUnknownDeoptimizedProperty */);
|
|
4884
|
+
}
|
|
4885
|
+
set hasUnknownDeoptimizedProperty(value) {
|
|
4886
|
+
this.flags = setFlag(this.flags, 8192 /* Flag.hasUnknownDeoptimizedProperty */, value);
|
|
4887
|
+
}
|
|
4847
4888
|
// If a PropertyMap is used, this will be taken as propertiesAndGettersByKey
|
|
4848
4889
|
// and we assume there are no setters or getters
|
|
4849
4890
|
constructor(properties, prototypeExpression, immutable = false) {
|
|
@@ -4855,9 +4896,6 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
4855
4896
|
this.deoptimizedPaths = Object.create(null);
|
|
4856
4897
|
this.expressionsToBeDeoptimizedByKey = Object.create(null);
|
|
4857
4898
|
this.gettersByKey = Object.create(null);
|
|
4858
|
-
this.hasLostTrack = false;
|
|
4859
|
-
this.hasUnknownDeoptimizedInteger = false;
|
|
4860
|
-
this.hasUnknownDeoptimizedProperty = false;
|
|
4861
4899
|
this.propertiesAndGettersByKey = Object.create(null);
|
|
4862
4900
|
this.propertiesAndSettersByKey = Object.create(null);
|
|
4863
4901
|
this.settersByKey = Object.create(null);
|
|
@@ -5389,7 +5427,7 @@ class ArrayExpression extends NodeBase {
|
|
|
5389
5427
|
element.deoptimizePath(UNKNOWN_PATH);
|
|
5390
5428
|
}
|
|
5391
5429
|
}
|
|
5392
|
-
this.context.requestTreeshakingPass();
|
|
5430
|
+
this.scope.context.requestTreeshakingPass();
|
|
5393
5431
|
}
|
|
5394
5432
|
getObjectEntity() {
|
|
5395
5433
|
if (this.objectEntity !== null) {
|
|
@@ -5762,10 +5800,11 @@ class Scope {
|
|
|
5762
5800
|
}
|
|
5763
5801
|
|
|
5764
5802
|
class ChildScope extends Scope {
|
|
5765
|
-
constructor(parent) {
|
|
5803
|
+
constructor(parent, context) {
|
|
5766
5804
|
super();
|
|
5767
5805
|
this.accessedOutsideVariables = new Map();
|
|
5768
5806
|
this.parent = parent;
|
|
5807
|
+
this.context = context;
|
|
5769
5808
|
parent.children.push(this);
|
|
5770
5809
|
}
|
|
5771
5810
|
addAccessedDynamicImport(importExpression) {
|
|
@@ -5845,11 +5884,10 @@ class ChildScope extends Scope {
|
|
|
5845
5884
|
|
|
5846
5885
|
class ParameterScope extends ChildScope {
|
|
5847
5886
|
constructor(parent, context) {
|
|
5848
|
-
super(parent);
|
|
5887
|
+
super(parent, context);
|
|
5849
5888
|
this.parameters = [];
|
|
5850
5889
|
this.hasRest = false;
|
|
5851
|
-
this.
|
|
5852
|
-
this.hoistedBodyVarScope = new ChildScope(this);
|
|
5890
|
+
this.hoistedBodyVarScope = new ChildScope(this, context);
|
|
5853
5891
|
}
|
|
5854
5892
|
/**
|
|
5855
5893
|
* Adds a parameter to this scope. Parameters must be added in the correct
|
|
@@ -7023,7 +7061,16 @@ class Identifier extends NodeBase {
|
|
|
7023
7061
|
constructor() {
|
|
7024
7062
|
super(...arguments);
|
|
7025
7063
|
this.variable = null;
|
|
7026
|
-
|
|
7064
|
+
}
|
|
7065
|
+
get isTDZAccess() {
|
|
7066
|
+
if (!isFlagSet(this.flags, 4 /* Flag.tdzAccessDefined */)) {
|
|
7067
|
+
return null;
|
|
7068
|
+
}
|
|
7069
|
+
return isFlagSet(this.flags, 8 /* Flag.tdzAccess */);
|
|
7070
|
+
}
|
|
7071
|
+
set isTDZAccess(value) {
|
|
7072
|
+
this.flags = setFlag(this.flags, 4 /* Flag.tdzAccessDefined */, true);
|
|
7073
|
+
this.flags = setFlag(this.flags, 8 /* Flag.tdzAccess */, value);
|
|
7027
7074
|
}
|
|
7028
7075
|
addExportedVariables(variables, exportNamesByVariable) {
|
|
7029
7076
|
if (exportNamesByVariable.has(this.variable)) {
|
|
@@ -7038,10 +7085,10 @@ class Identifier extends NodeBase {
|
|
|
7038
7085
|
}
|
|
7039
7086
|
declare(kind, init) {
|
|
7040
7087
|
let variable;
|
|
7041
|
-
const { treeshake } = this.context.options;
|
|
7088
|
+
const { treeshake } = this.scope.context.options;
|
|
7042
7089
|
switch (kind) {
|
|
7043
7090
|
case 'var': {
|
|
7044
|
-
variable = this.scope.addDeclaration(this, this.context, init, true);
|
|
7091
|
+
variable = this.scope.addDeclaration(this, this.scope.context, init, true);
|
|
7045
7092
|
if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
|
|
7046
7093
|
// Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
|
|
7047
7094
|
variable.markInitializersForDeoptimization();
|
|
@@ -7050,13 +7097,13 @@ class Identifier extends NodeBase {
|
|
|
7050
7097
|
}
|
|
7051
7098
|
case 'function': {
|
|
7052
7099
|
// in strict mode, functions are only hoisted within a scope but not across block scopes
|
|
7053
|
-
variable = this.scope.addDeclaration(this, this.context, init, false);
|
|
7100
|
+
variable = this.scope.addDeclaration(this, this.scope.context, init, false);
|
|
7054
7101
|
break;
|
|
7055
7102
|
}
|
|
7056
7103
|
case 'let':
|
|
7057
7104
|
case 'const':
|
|
7058
7105
|
case 'class': {
|
|
7059
|
-
variable = this.scope.addDeclaration(this, this.context, init, false);
|
|
7106
|
+
variable = this.scope.addDeclaration(this, this.scope.context, init, false);
|
|
7060
7107
|
break;
|
|
7061
7108
|
}
|
|
7062
7109
|
case 'parameter': {
|
|
@@ -7093,7 +7140,8 @@ class Identifier extends NodeBase {
|
|
|
7093
7140
|
if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
|
|
7094
7141
|
return true;
|
|
7095
7142
|
}
|
|
7096
|
-
return (this.context.options.treeshake
|
|
7143
|
+
return (this.scope.context.options.treeshake
|
|
7144
|
+
.unknownGlobalSideEffects &&
|
|
7097
7145
|
this.variable instanceof GlobalVariable &&
|
|
7098
7146
|
!this.isPureFunction(EMPTY_PATH) &&
|
|
7099
7147
|
this.variable.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_ACCESS, context));
|
|
@@ -7120,7 +7168,7 @@ class Identifier extends NodeBase {
|
|
|
7120
7168
|
if (!this.included) {
|
|
7121
7169
|
this.included = true;
|
|
7122
7170
|
if (this.variable !== null) {
|
|
7123
|
-
this.context.includeVariableInModule(this.variable);
|
|
7171
|
+
this.scope.context.includeVariableInModule(this.variable);
|
|
7124
7172
|
}
|
|
7125
7173
|
}
|
|
7126
7174
|
}
|
|
@@ -7129,14 +7177,15 @@ class Identifier extends NodeBase {
|
|
|
7129
7177
|
}
|
|
7130
7178
|
isPossibleTDZ() {
|
|
7131
7179
|
// return cached value to avoid issues with the next tree-shaking pass
|
|
7132
|
-
|
|
7133
|
-
|
|
7180
|
+
const cachedTdzAccess = this.isTDZAccess;
|
|
7181
|
+
if (cachedTdzAccess !== null)
|
|
7182
|
+
return cachedTdzAccess;
|
|
7134
7183
|
if (!(this.variable instanceof LocalVariable &&
|
|
7135
7184
|
this.variable.kind &&
|
|
7136
7185
|
this.variable.kind in tdzVariableKinds &&
|
|
7137
7186
|
// we ignore possible TDZs due to circular module dependencies as
|
|
7138
7187
|
// otherwise we get many false positives
|
|
7139
|
-
this.variable.module === this.context.module)) {
|
|
7188
|
+
this.variable.module === this.scope.context.module)) {
|
|
7140
7189
|
return (this.isTDZAccess = false);
|
|
7141
7190
|
}
|
|
7142
7191
|
let decl_id;
|
|
@@ -7183,7 +7232,7 @@ class Identifier extends NodeBase {
|
|
|
7183
7232
|
this.deoptimized = true;
|
|
7184
7233
|
if (this.variable instanceof LocalVariable) {
|
|
7185
7234
|
this.variable.consolidateInitializers();
|
|
7186
|
-
this.context.requestTreeshakingPass();
|
|
7235
|
+
this.scope.context.requestTreeshakingPass();
|
|
7187
7236
|
}
|
|
7188
7237
|
}
|
|
7189
7238
|
getVariableRespectingTDZ() {
|
|
@@ -7193,7 +7242,7 @@ class Identifier extends NodeBase {
|
|
|
7193
7242
|
return this.variable;
|
|
7194
7243
|
}
|
|
7195
7244
|
isPureFunction(path) {
|
|
7196
|
-
let currentPureFunction = this.context.manualPureFunctions[this.name];
|
|
7245
|
+
let currentPureFunction = this.scope.context.manualPureFunctions[this.name];
|
|
7197
7246
|
for (const segment of path) {
|
|
7198
7247
|
if (currentPureFunction) {
|
|
7199
7248
|
if (currentPureFunction[PureFunctionKey]) {
|
|
@@ -7373,9 +7422,9 @@ class ExpressionStatement extends NodeBase {
|
|
|
7373
7422
|
if (this.directive &&
|
|
7374
7423
|
this.directive !== 'use strict' &&
|
|
7375
7424
|
this.parent.type === Program$1) {
|
|
7376
|
-
this.context.log(LOGLEVEL_WARN,
|
|
7425
|
+
this.scope.context.log(LOGLEVEL_WARN,
|
|
7377
7426
|
// This is necessary, because either way (deleting or not) can lead to errors.
|
|
7378
|
-
logModuleLevelDirective(this.directive, this.context.module.id), this.start);
|
|
7427
|
+
logModuleLevelDirective(this.directive, this.scope.context.module.id), this.start);
|
|
7379
7428
|
}
|
|
7380
7429
|
}
|
|
7381
7430
|
removeAnnotations(code) {
|
|
@@ -7396,9 +7445,17 @@ class ExpressionStatement extends NodeBase {
|
|
|
7396
7445
|
}
|
|
7397
7446
|
|
|
7398
7447
|
class BlockStatement extends NodeBase {
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
|
|
7448
|
+
get deoptimizeBody() {
|
|
7449
|
+
return isFlagSet(this.flags, 32768 /* Flag.deoptimizeBody */);
|
|
7450
|
+
}
|
|
7451
|
+
set deoptimizeBody(value) {
|
|
7452
|
+
this.flags = setFlag(this.flags, 32768 /* Flag.deoptimizeBody */, value);
|
|
7453
|
+
}
|
|
7454
|
+
get directlyIncluded() {
|
|
7455
|
+
return isFlagSet(this.flags, 16384 /* Flag.directlyIncluded */);
|
|
7456
|
+
}
|
|
7457
|
+
set directlyIncluded(value) {
|
|
7458
|
+
this.flags = setFlag(this.flags, 16384 /* Flag.directlyIncluded */, value);
|
|
7402
7459
|
}
|
|
7403
7460
|
addImplicitReturnExpressionToScope() {
|
|
7404
7461
|
const lastStatement = this.body[this.body.length - 1];
|
|
@@ -7409,7 +7466,7 @@ class BlockStatement extends NodeBase {
|
|
|
7409
7466
|
createScope(parentScope) {
|
|
7410
7467
|
this.scope = this.parent.preventChildBlockScope
|
|
7411
7468
|
? parentScope
|
|
7412
|
-
: new BlockScope(parentScope);
|
|
7469
|
+
: new BlockScope(parentScope, this.scope.context);
|
|
7413
7470
|
}
|
|
7414
7471
|
hasEffects(context) {
|
|
7415
7472
|
if (this.deoptimizeBody)
|
|
@@ -7476,7 +7533,7 @@ class RestElement extends NodeBase {
|
|
|
7476
7533
|
this.deoptimized = true;
|
|
7477
7534
|
if (this.declarationInit !== null) {
|
|
7478
7535
|
this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
|
|
7479
|
-
this.context.requestTreeshakingPass();
|
|
7536
|
+
this.scope.context.requestTreeshakingPass();
|
|
7480
7537
|
}
|
|
7481
7538
|
}
|
|
7482
7539
|
}
|
|
@@ -7485,7 +7542,18 @@ class FunctionBase extends NodeBase {
|
|
|
7485
7542
|
constructor() {
|
|
7486
7543
|
super(...arguments);
|
|
7487
7544
|
this.objectEntity = null;
|
|
7488
|
-
|
|
7545
|
+
}
|
|
7546
|
+
get async() {
|
|
7547
|
+
return isFlagSet(this.flags, 256 /* Flag.async */);
|
|
7548
|
+
}
|
|
7549
|
+
set async(value) {
|
|
7550
|
+
this.flags = setFlag(this.flags, 256 /* Flag.async */, value);
|
|
7551
|
+
}
|
|
7552
|
+
get deoptimizedReturn() {
|
|
7553
|
+
return isFlagSet(this.flags, 512 /* Flag.deoptimizedReturn */);
|
|
7554
|
+
}
|
|
7555
|
+
set deoptimizedReturn(value) {
|
|
7556
|
+
this.flags = setFlag(this.flags, 512 /* Flag.deoptimizedReturn */, value);
|
|
7489
7557
|
}
|
|
7490
7558
|
deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
7491
7559
|
if (interaction.type === INTERACTION_CALLED) {
|
|
@@ -7540,7 +7608,7 @@ class FunctionBase extends NodeBase {
|
|
|
7540
7608
|
if (!this.deoptimizedReturn) {
|
|
7541
7609
|
this.deoptimizedReturn = true;
|
|
7542
7610
|
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
7543
|
-
this.context.requestTreeshakingPass();
|
|
7611
|
+
this.scope.context.requestTreeshakingPass();
|
|
7544
7612
|
}
|
|
7545
7613
|
return UNKNOWN_RETURN_EXPRESSION;
|
|
7546
7614
|
}
|
|
@@ -7554,7 +7622,7 @@ class FunctionBase extends NodeBase {
|
|
|
7554
7622
|
return false;
|
|
7555
7623
|
}
|
|
7556
7624
|
if (this.async) {
|
|
7557
|
-
const { propertyReadSideEffects } = this.context.options
|
|
7625
|
+
const { propertyReadSideEffects } = this.scope.context.options
|
|
7558
7626
|
.treeshake;
|
|
7559
7627
|
const returnExpression = this.scope.getReturnExpression();
|
|
7560
7628
|
if (returnExpression.hasEffectsOnInteractionAtPath(['then'], NODE_INTERACTION_UNKNOWN_CALL, context) ||
|
|
@@ -7608,7 +7676,7 @@ class ArrowFunctionExpression extends FunctionBase {
|
|
|
7608
7676
|
this.objectEntity = null;
|
|
7609
7677
|
}
|
|
7610
7678
|
createScope(parentScope) {
|
|
7611
|
-
this.scope = new ReturnValueScope(parentScope, this.context);
|
|
7679
|
+
this.scope = new ReturnValueScope(parentScope, this.scope.context);
|
|
7612
7680
|
}
|
|
7613
7681
|
hasEffects() {
|
|
7614
7682
|
if (!this.deoptimized)
|
|
@@ -7818,7 +7886,7 @@ class AssignmentExpression extends NodeBase {
|
|
|
7818
7886
|
this.deoptimized = true;
|
|
7819
7887
|
this.left.deoptimizePath(EMPTY_PATH);
|
|
7820
7888
|
this.right.deoptimizePath(UNKNOWN_PATH);
|
|
7821
|
-
this.context.requestTreeshakingPass();
|
|
7889
|
+
this.scope.context.requestTreeshakingPass();
|
|
7822
7890
|
}
|
|
7823
7891
|
}
|
|
7824
7892
|
|
|
@@ -7846,7 +7914,7 @@ class AssignmentPattern extends NodeBase {
|
|
|
7846
7914
|
this.deoptimized = true;
|
|
7847
7915
|
this.left.deoptimizePath(EMPTY_PATH);
|
|
7848
7916
|
this.right.deoptimizePath(UNKNOWN_PATH);
|
|
7849
|
-
this.context.requestTreeshakingPass();
|
|
7917
|
+
this.scope.context.requestTreeshakingPass();
|
|
7850
7918
|
}
|
|
7851
7919
|
}
|
|
7852
7920
|
|
|
@@ -7911,7 +7979,7 @@ class FunctionNode extends FunctionBase {
|
|
|
7911
7979
|
this.objectEntity = null;
|
|
7912
7980
|
}
|
|
7913
7981
|
createScope(parentScope) {
|
|
7914
|
-
this.scope = new FunctionScope(parentScope, this.context);
|
|
7982
|
+
this.scope = new FunctionScope(parentScope, this.scope.context);
|
|
7915
7983
|
this.constructedEntity = new ObjectEntity(Object.create(null), OBJECT_PROTOTYPE);
|
|
7916
7984
|
// This makes sure that all deoptimizations of "this" are applied to the
|
|
7917
7985
|
// constructed entity.
|
|
@@ -8004,13 +8072,13 @@ class AwaitExpression extends NodeBase {
|
|
|
8004
8072
|
this.applyDeoptimizations();
|
|
8005
8073
|
if (!this.included) {
|
|
8006
8074
|
this.included = true;
|
|
8007
|
-
checkTopLevelAwait: if (!this.context.usesTopLevelAwait) {
|
|
8075
|
+
checkTopLevelAwait: if (!this.scope.context.usesTopLevelAwait) {
|
|
8008
8076
|
let parent = this.parent;
|
|
8009
8077
|
do {
|
|
8010
8078
|
if (parent instanceof FunctionNode || parent instanceof ArrowFunctionExpression)
|
|
8011
8079
|
break checkTopLevelAwait;
|
|
8012
8080
|
} while ((parent = parent.parent));
|
|
8013
|
-
this.context.usesTopLevelAwait = true;
|
|
8081
|
+
this.scope.context.usesTopLevelAwait = true;
|
|
8014
8082
|
}
|
|
8015
8083
|
}
|
|
8016
8084
|
this.argument.include(context, includeChildrenRecursively);
|
|
@@ -8138,10 +8206,10 @@ class Literal extends NodeBase {
|
|
|
8138
8206
|
getLiteralValueAtPath(path) {
|
|
8139
8207
|
if (path.length > 0 ||
|
|
8140
8208
|
// unknown literals can also be null but do not start with an "n"
|
|
8141
|
-
(this.value === null && this.context.code.charCodeAt(this.start) !== 110) ||
|
|
8209
|
+
(this.value === null && this.scope.context.code.charCodeAt(this.start) !== 110) ||
|
|
8142
8210
|
typeof this.value === 'bigint' ||
|
|
8143
8211
|
// to support shims for regular expressions
|
|
8144
|
-
this.context.code.charCodeAt(this.start) === 47) {
|
|
8212
|
+
this.scope.context.code.charCodeAt(this.start) === 47) {
|
|
8145
8213
|
return UnknownValue;
|
|
8146
8214
|
}
|
|
8147
8215
|
return this.value;
|
|
@@ -8226,17 +8294,44 @@ class MemberExpression extends NodeBase {
|
|
|
8226
8294
|
constructor() {
|
|
8227
8295
|
super(...arguments);
|
|
8228
8296
|
this.variable = null;
|
|
8229
|
-
this.assignmentDeoptimized = false;
|
|
8230
|
-
this.bound = false;
|
|
8231
8297
|
this.expressionsToBeDeoptimized = [];
|
|
8232
|
-
|
|
8298
|
+
}
|
|
8299
|
+
get computed() {
|
|
8300
|
+
return isFlagSet(this.flags, 1024 /* Flag.computed */);
|
|
8301
|
+
}
|
|
8302
|
+
set computed(value) {
|
|
8303
|
+
this.flags = setFlag(this.flags, 1024 /* Flag.computed */, value);
|
|
8304
|
+
}
|
|
8305
|
+
get optional() {
|
|
8306
|
+
return isFlagSet(this.flags, 128 /* Flag.optional */);
|
|
8307
|
+
}
|
|
8308
|
+
set optional(value) {
|
|
8309
|
+
this.flags = setFlag(this.flags, 128 /* Flag.optional */, value);
|
|
8310
|
+
}
|
|
8311
|
+
get assignmentDeoptimized() {
|
|
8312
|
+
return isFlagSet(this.flags, 16 /* Flag.assignmentDeoptimized */);
|
|
8313
|
+
}
|
|
8314
|
+
set assignmentDeoptimized(value) {
|
|
8315
|
+
this.flags = setFlag(this.flags, 16 /* Flag.assignmentDeoptimized */, value);
|
|
8316
|
+
}
|
|
8317
|
+
get bound() {
|
|
8318
|
+
return isFlagSet(this.flags, 32 /* Flag.bound */);
|
|
8319
|
+
}
|
|
8320
|
+
set bound(value) {
|
|
8321
|
+
this.flags = setFlag(this.flags, 32 /* Flag.bound */, value);
|
|
8322
|
+
}
|
|
8323
|
+
get isUndefined() {
|
|
8324
|
+
return isFlagSet(this.flags, 64 /* Flag.isUndefined */);
|
|
8325
|
+
}
|
|
8326
|
+
set isUndefined(value) {
|
|
8327
|
+
this.flags = setFlag(this.flags, 64 /* Flag.isUndefined */, value);
|
|
8233
8328
|
}
|
|
8234
8329
|
bind() {
|
|
8235
8330
|
this.bound = true;
|
|
8236
8331
|
const path = getPathIfNotComputed(this);
|
|
8237
8332
|
const baseVariable = path && this.scope.findVariable(path[0].key);
|
|
8238
8333
|
if (baseVariable?.isNamespace) {
|
|
8239
|
-
const resolvedVariable = resolveNamespaceVariables(baseVariable, path.slice(1), this.context);
|
|
8334
|
+
const resolvedVariable = resolveNamespaceVariables(baseVariable, path.slice(1), this.scope.context);
|
|
8240
8335
|
if (!resolvedVariable) {
|
|
8241
8336
|
super.bind();
|
|
8242
8337
|
}
|
|
@@ -8404,7 +8499,7 @@ class MemberExpression extends NodeBase {
|
|
|
8404
8499
|
}
|
|
8405
8500
|
applyDeoptimizations() {
|
|
8406
8501
|
this.deoptimized = true;
|
|
8407
|
-
const { propertyReadSideEffects } = this.context.options
|
|
8502
|
+
const { propertyReadSideEffects } = this.scope.context.options
|
|
8408
8503
|
.treeshake;
|
|
8409
8504
|
if (
|
|
8410
8505
|
// Namespaces are not bound and should not be deoptimized
|
|
@@ -8413,12 +8508,12 @@ class MemberExpression extends NodeBase {
|
|
|
8413
8508
|
!(this.variable || this.isUndefined)) {
|
|
8414
8509
|
const propertyKey = this.getPropertyKey();
|
|
8415
8510
|
this.object.deoptimizeArgumentsOnInteractionAtPath(this.accessInteraction, [propertyKey], SHARED_RECURSION_TRACKER);
|
|
8416
|
-
this.context.requestTreeshakingPass();
|
|
8511
|
+
this.scope.context.requestTreeshakingPass();
|
|
8417
8512
|
}
|
|
8418
8513
|
}
|
|
8419
8514
|
applyAssignmentDeoptimization() {
|
|
8420
8515
|
this.assignmentDeoptimized = true;
|
|
8421
|
-
const { propertyReadSideEffects } = this.context.options
|
|
8516
|
+
const { propertyReadSideEffects } = this.scope.context.options
|
|
8422
8517
|
.treeshake;
|
|
8423
8518
|
if (
|
|
8424
8519
|
// Namespaces are not bound and should not be deoptimized
|
|
@@ -8426,7 +8521,7 @@ class MemberExpression extends NodeBase {
|
|
|
8426
8521
|
propertyReadSideEffects &&
|
|
8427
8522
|
!(this.variable || this.isUndefined)) {
|
|
8428
8523
|
this.object.deoptimizeArgumentsOnInteractionAtPath(this.assignmentInteraction, [this.getPropertyKey()], SHARED_RECURSION_TRACKER);
|
|
8429
|
-
this.context.requestTreeshakingPass();
|
|
8524
|
+
this.scope.context.requestTreeshakingPass();
|
|
8430
8525
|
}
|
|
8431
8526
|
}
|
|
8432
8527
|
disallowNamespaceReassignment() {
|
|
@@ -8434,9 +8529,9 @@ class MemberExpression extends NodeBase {
|
|
|
8434
8529
|
const variable = this.scope.findVariable(this.object.name);
|
|
8435
8530
|
if (variable.isNamespace) {
|
|
8436
8531
|
if (this.variable) {
|
|
8437
|
-
this.context.includeVariableInModule(this.variable);
|
|
8532
|
+
this.scope.context.includeVariableInModule(this.variable);
|
|
8438
8533
|
}
|
|
8439
|
-
this.context.log(LOGLEVEL_WARN, logIllegalImportReassignment(this.object.name, this.context.module.id), this.start);
|
|
8534
|
+
this.scope.context.log(LOGLEVEL_WARN, logIllegalImportReassignment(this.object.name, this.scope.context.module.id), this.start);
|
|
8440
8535
|
}
|
|
8441
8536
|
}
|
|
8442
8537
|
}
|
|
@@ -8454,7 +8549,7 @@ class MemberExpression extends NodeBase {
|
|
|
8454
8549
|
return this.propertyKey;
|
|
8455
8550
|
}
|
|
8456
8551
|
hasAccessEffect(context) {
|
|
8457
|
-
const { propertyReadSideEffects } = this.context.options
|
|
8552
|
+
const { propertyReadSideEffects } = this.scope.context.options
|
|
8458
8553
|
.treeshake;
|
|
8459
8554
|
return (!(this.variable || this.isUndefined) &&
|
|
8460
8555
|
propertyReadSideEffects &&
|
|
@@ -8465,7 +8560,7 @@ class MemberExpression extends NodeBase {
|
|
|
8465
8560
|
if (!this.included) {
|
|
8466
8561
|
this.included = true;
|
|
8467
8562
|
if (this.variable) {
|
|
8468
|
-
this.context.includeVariableInModule(this.variable);
|
|
8563
|
+
this.scope.context.includeVariableInModule(this.variable);
|
|
8469
8564
|
}
|
|
8470
8565
|
}
|
|
8471
8566
|
this.object.include(context, includeChildrenRecursively);
|
|
@@ -8535,7 +8630,7 @@ class CallExpressionBase extends NodeBase {
|
|
|
8535
8630
|
}
|
|
8536
8631
|
deoptimizePath(path) {
|
|
8537
8632
|
if (path.length === 0 ||
|
|
8538
|
-
this.context.deoptimizationTracker.trackEntityAtPathAndGetIfTracked(path, this)) {
|
|
8633
|
+
this.scope.context.deoptimizationTracker.trackEntityAtPathAndGetIfTracked(path, this)) {
|
|
8539
8634
|
return;
|
|
8540
8635
|
}
|
|
8541
8636
|
const [returnExpression] = this.getReturnExpression();
|
|
@@ -8584,15 +8679,21 @@ class CallExpressionBase extends NodeBase {
|
|
|
8584
8679
|
}
|
|
8585
8680
|
|
|
8586
8681
|
class CallExpression extends CallExpressionBase {
|
|
8682
|
+
get optional() {
|
|
8683
|
+
return isFlagSet(this.flags, 128 /* Flag.optional */);
|
|
8684
|
+
}
|
|
8685
|
+
set optional(value) {
|
|
8686
|
+
this.flags = setFlag(this.flags, 128 /* Flag.optional */, value);
|
|
8687
|
+
}
|
|
8587
8688
|
bind() {
|
|
8588
8689
|
super.bind();
|
|
8589
8690
|
if (this.callee instanceof Identifier) {
|
|
8590
8691
|
const variable = this.scope.findVariable(this.callee.name);
|
|
8591
8692
|
if (variable.isNamespace) {
|
|
8592
|
-
this.context.log(LOGLEVEL_WARN, logCannotCallNamespace(this.callee.name), this.start);
|
|
8693
|
+
this.scope.context.log(LOGLEVEL_WARN, logCannotCallNamespace(this.callee.name), this.start);
|
|
8593
8694
|
}
|
|
8594
8695
|
if (this.callee.name === 'eval') {
|
|
8595
|
-
this.context.log(LOGLEVEL_WARN, logEval(this.context.module.id), this.start);
|
|
8696
|
+
this.scope.context.log(LOGLEVEL_WARN, logEval(this.scope.context.module.id), this.start);
|
|
8596
8697
|
}
|
|
8597
8698
|
}
|
|
8598
8699
|
this.interaction = {
|
|
@@ -8655,7 +8756,7 @@ class CallExpression extends CallExpressionBase {
|
|
|
8655
8756
|
applyDeoptimizations() {
|
|
8656
8757
|
this.deoptimized = true;
|
|
8657
8758
|
this.callee.deoptimizeArgumentsOnInteractionAtPath(this.interaction, EMPTY_PATH, SHARED_RECURSION_TRACKER);
|
|
8658
|
-
this.context.requestTreeshakingPass();
|
|
8759
|
+
this.scope.context.requestTreeshakingPass();
|
|
8659
8760
|
}
|
|
8660
8761
|
getReturnExpression(recursionTracker = SHARED_RECURSION_TRACKER) {
|
|
8661
8762
|
if (this.returnExpression === null) {
|
|
@@ -8683,7 +8784,7 @@ class CatchScope extends ParameterScope {
|
|
|
8683
8784
|
|
|
8684
8785
|
class CatchClause extends NodeBase {
|
|
8685
8786
|
createScope(parentScope) {
|
|
8686
|
-
this.scope = new CatchScope(parentScope, this.context);
|
|
8787
|
+
this.scope = new CatchScope(parentScope, this.scope.context);
|
|
8687
8788
|
}
|
|
8688
8789
|
parseNode(esTreeNode) {
|
|
8689
8790
|
// Parameters need to be declared first as the logic is that initializers
|
|
@@ -8691,7 +8792,7 @@ class CatchClause extends NodeBase {
|
|
|
8691
8792
|
// name instead of the variable
|
|
8692
8793
|
const { param } = esTreeNode;
|
|
8693
8794
|
if (param) {
|
|
8694
|
-
this.param = new (this.context.getNodeConstructor(param.type))(param, this, this.scope);
|
|
8795
|
+
this.param = new (this.scope.context.getNodeConstructor(param.type))(param, this, this.scope);
|
|
8695
8796
|
this.param.declare('parameter', UNKNOWN_EXPRESSION);
|
|
8696
8797
|
}
|
|
8697
8798
|
super.parseNode(esTreeNode);
|
|
@@ -8718,9 +8819,9 @@ class ChainExpression extends NodeBase {
|
|
|
8718
8819
|
|
|
8719
8820
|
class ClassBodyScope extends ChildScope {
|
|
8720
8821
|
constructor(parent, classNode, context) {
|
|
8721
|
-
super(parent);
|
|
8822
|
+
super(parent, context);
|
|
8722
8823
|
this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, context)));
|
|
8723
|
-
this.instanceScope = new ChildScope(this);
|
|
8824
|
+
this.instanceScope = new ChildScope(this, context);
|
|
8724
8825
|
this.instanceScope.variables.set('this', new ThisVariable(context));
|
|
8725
8826
|
}
|
|
8726
8827
|
findLexicalBoundary() {
|
|
@@ -8730,11 +8831,11 @@ class ClassBodyScope extends ChildScope {
|
|
|
8730
8831
|
|
|
8731
8832
|
class ClassBody extends NodeBase {
|
|
8732
8833
|
createScope(parentScope) {
|
|
8733
|
-
this.scope = new ClassBodyScope(parentScope, this.parent, this.context);
|
|
8834
|
+
this.scope = new ClassBodyScope(parentScope, this.parent, this.scope.context);
|
|
8734
8835
|
}
|
|
8735
8836
|
include(context, includeChildrenRecursively) {
|
|
8736
8837
|
this.included = true;
|
|
8737
|
-
this.context.includeVariableInModule(this.scope.thisVariable);
|
|
8838
|
+
this.scope.context.includeVariableInModule(this.scope.thisVariable);
|
|
8738
8839
|
for (const definition of this.body) {
|
|
8739
8840
|
definition.include(context, includeChildrenRecursively);
|
|
8740
8841
|
}
|
|
@@ -8742,7 +8843,7 @@ class ClassBody extends NodeBase {
|
|
|
8742
8843
|
parseNode(esTreeNode) {
|
|
8743
8844
|
const body = (this.body = []);
|
|
8744
8845
|
for (const definition of esTreeNode.body) {
|
|
8745
|
-
body.push(new (this.context.getNodeConstructor(definition.type))(definition, this, definition.static ? this.scope : this.scope.instanceScope));
|
|
8846
|
+
body.push(new (this.scope.context.getNodeConstructor(definition.type))(definition, this, definition.static ? this.scope : this.scope.instanceScope));
|
|
8746
8847
|
}
|
|
8747
8848
|
super.parseNode(esTreeNode);
|
|
8748
8849
|
}
|
|
@@ -8754,6 +8855,12 @@ class MethodBase extends NodeBase {
|
|
|
8754
8855
|
super(...arguments);
|
|
8755
8856
|
this.accessedValue = null;
|
|
8756
8857
|
}
|
|
8858
|
+
get computed() {
|
|
8859
|
+
return isFlagSet(this.flags, 1024 /* Flag.computed */);
|
|
8860
|
+
}
|
|
8861
|
+
set computed(value) {
|
|
8862
|
+
this.flags = setFlag(this.flags, 1024 /* Flag.computed */, value);
|
|
8863
|
+
}
|
|
8757
8864
|
deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
8758
8865
|
if (interaction.type === INTERACTION_ACCESSED && this.kind === 'get' && path.length === 0) {
|
|
8759
8866
|
return this.value.deoptimizeArgumentsOnInteractionAtPath({
|
|
@@ -8852,7 +8959,7 @@ class ClassNode extends NodeBase {
|
|
|
8852
8959
|
this.objectEntity = null;
|
|
8853
8960
|
}
|
|
8854
8961
|
createScope(parentScope) {
|
|
8855
|
-
this.scope = new ChildScope(parentScope);
|
|
8962
|
+
this.scope = new ChildScope(parentScope, this.scope.context);
|
|
8856
8963
|
}
|
|
8857
8964
|
deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
8858
8965
|
this.getObjectEntity().deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
|
|
@@ -8915,7 +9022,7 @@ class ClassNode extends NodeBase {
|
|
|
8915
9022
|
definition.deoptimizePath(UNKNOWN_PATH);
|
|
8916
9023
|
}
|
|
8917
9024
|
}
|
|
8918
|
-
this.context.requestTreeshakingPass();
|
|
9025
|
+
this.scope.context.requestTreeshakingPass();
|
|
8919
9026
|
}
|
|
8920
9027
|
getObjectEntity() {
|
|
8921
9028
|
if (this.objectEntity !== null) {
|
|
@@ -9020,7 +9127,6 @@ class MultiExpression extends ExpressionEntity {
|
|
|
9020
9127
|
constructor(expressions) {
|
|
9021
9128
|
super();
|
|
9022
9129
|
this.expressions = expressions;
|
|
9023
|
-
this.included = false;
|
|
9024
9130
|
}
|
|
9025
9131
|
deoptimizePath(path) {
|
|
9026
9132
|
for (const expression of this.expressions) {
|
|
@@ -9046,9 +9152,14 @@ class ConditionalExpression extends NodeBase {
|
|
|
9046
9152
|
constructor() {
|
|
9047
9153
|
super(...arguments);
|
|
9048
9154
|
this.expressionsToBeDeoptimized = [];
|
|
9049
|
-
this.isBranchResolutionAnalysed = false;
|
|
9050
9155
|
this.usedBranch = null;
|
|
9051
9156
|
}
|
|
9157
|
+
get isBranchResolutionAnalysed() {
|
|
9158
|
+
return isFlagSet(this.flags, 65536 /* Flag.isBranchResolutionAnalysed */);
|
|
9159
|
+
}
|
|
9160
|
+
set isBranchResolutionAnalysed(value) {
|
|
9161
|
+
this.flags = setFlag(this.flags, 65536 /* Flag.isBranchResolutionAnalysed */, value);
|
|
9162
|
+
}
|
|
9052
9163
|
deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
9053
9164
|
this.consequent.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
|
|
9054
9165
|
this.alternate.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
|
|
@@ -9255,7 +9366,7 @@ class ExportAllDeclaration extends NodeBase {
|
|
|
9255
9366
|
return false;
|
|
9256
9367
|
}
|
|
9257
9368
|
initialise() {
|
|
9258
|
-
this.context.addExport(this);
|
|
9369
|
+
this.scope.context.addExport(this);
|
|
9259
9370
|
}
|
|
9260
9371
|
render(code, _options, nodeRenderOptions) {
|
|
9261
9372
|
code.remove(nodeRenderOptions.start, nodeRenderOptions.end);
|
|
@@ -9296,15 +9407,15 @@ class ExportDefaultDeclaration extends NodeBase {
|
|
|
9296
9407
|
include(context, includeChildrenRecursively) {
|
|
9297
9408
|
super.include(context, includeChildrenRecursively);
|
|
9298
9409
|
if (includeChildrenRecursively) {
|
|
9299
|
-
this.context.includeVariableInModule(this.variable);
|
|
9410
|
+
this.scope.context.includeVariableInModule(this.variable);
|
|
9300
9411
|
}
|
|
9301
9412
|
}
|
|
9302
9413
|
initialise() {
|
|
9303
9414
|
const declaration = this.declaration;
|
|
9304
9415
|
this.declarationName =
|
|
9305
9416
|
(declaration.id && declaration.id.name) || this.declaration.name;
|
|
9306
|
-
this.variable = this.scope.addExportDefaultDeclaration(this.declarationName || this.context.getModuleName(), this, this.context);
|
|
9307
|
-
this.context.addExport(this);
|
|
9417
|
+
this.variable = this.scope.addExportDefaultDeclaration(this.declarationName || this.scope.context.getModuleName(), this, this.scope.context);
|
|
9418
|
+
this.scope.context.addExport(this);
|
|
9308
9419
|
}
|
|
9309
9420
|
removeAnnotations(code) {
|
|
9310
9421
|
this.declaration.removeAnnotations(code);
|
|
@@ -9383,7 +9494,7 @@ class ExportNamedDeclaration extends NodeBase {
|
|
|
9383
9494
|
return !!this.declaration?.hasEffects(context);
|
|
9384
9495
|
}
|
|
9385
9496
|
initialise() {
|
|
9386
|
-
this.context.addExport(this);
|
|
9497
|
+
this.scope.context.addExport(this);
|
|
9387
9498
|
}
|
|
9388
9499
|
removeAnnotations(code) {
|
|
9389
9500
|
this.declaration?.removeAnnotations(code);
|
|
@@ -9408,7 +9519,7 @@ class ExportSpecifier extends NodeBase {
|
|
|
9408
9519
|
|
|
9409
9520
|
class ForInStatement extends NodeBase {
|
|
9410
9521
|
createScope(parentScope) {
|
|
9411
|
-
this.scope = new BlockScope(parentScope);
|
|
9522
|
+
this.scope = new BlockScope(parentScope, this.scope.context);
|
|
9412
9523
|
}
|
|
9413
9524
|
hasEffects(context) {
|
|
9414
9525
|
const { body, deoptimized, left, right } = this;
|
|
@@ -9442,13 +9553,19 @@ class ForInStatement extends NodeBase {
|
|
|
9442
9553
|
applyDeoptimizations() {
|
|
9443
9554
|
this.deoptimized = true;
|
|
9444
9555
|
this.left.deoptimizePath(EMPTY_PATH);
|
|
9445
|
-
this.context.requestTreeshakingPass();
|
|
9556
|
+
this.scope.context.requestTreeshakingPass();
|
|
9446
9557
|
}
|
|
9447
9558
|
}
|
|
9448
9559
|
|
|
9449
9560
|
class ForOfStatement extends NodeBase {
|
|
9561
|
+
get await() {
|
|
9562
|
+
return isFlagSet(this.flags, 131072 /* Flag.await */);
|
|
9563
|
+
}
|
|
9564
|
+
set await(value) {
|
|
9565
|
+
this.flags = setFlag(this.flags, 131072 /* Flag.await */, value);
|
|
9566
|
+
}
|
|
9450
9567
|
createScope(parentScope) {
|
|
9451
|
-
this.scope = new BlockScope(parentScope);
|
|
9568
|
+
this.scope = new BlockScope(parentScope, this.scope.context);
|
|
9452
9569
|
}
|
|
9453
9570
|
hasEffects() {
|
|
9454
9571
|
if (!this.deoptimized)
|
|
@@ -9481,13 +9598,13 @@ class ForOfStatement extends NodeBase {
|
|
|
9481
9598
|
this.deoptimized = true;
|
|
9482
9599
|
this.left.deoptimizePath(EMPTY_PATH);
|
|
9483
9600
|
this.right.deoptimizePath(UNKNOWN_PATH);
|
|
9484
|
-
this.context.requestTreeshakingPass();
|
|
9601
|
+
this.scope.context.requestTreeshakingPass();
|
|
9485
9602
|
}
|
|
9486
9603
|
}
|
|
9487
9604
|
|
|
9488
9605
|
class ForStatement extends NodeBase {
|
|
9489
9606
|
createScope(parentScope) {
|
|
9490
|
-
this.scope = new BlockScope(parentScope);
|
|
9607
|
+
this.scope = new BlockScope(parentScope, this.scope.context);
|
|
9491
9608
|
}
|
|
9492
9609
|
hasEffects(context) {
|
|
9493
9610
|
if (this.init?.hasEffects(context) ||
|
|
@@ -9580,11 +9697,11 @@ class IfStatement extends NodeBase {
|
|
|
9580
9697
|
}
|
|
9581
9698
|
}
|
|
9582
9699
|
parseNode(esTreeNode) {
|
|
9583
|
-
this.consequentScope = new TrackingScope(this.scope);
|
|
9584
|
-
this.consequent = new (this.context.getNodeConstructor(esTreeNode.consequent.type))(esTreeNode.consequent, this, this.consequentScope);
|
|
9700
|
+
this.consequentScope = new TrackingScope(this.scope, this.scope.context);
|
|
9701
|
+
this.consequent = new (this.scope.context.getNodeConstructor(esTreeNode.consequent.type))(esTreeNode.consequent, this, this.consequentScope);
|
|
9585
9702
|
if (esTreeNode.alternate) {
|
|
9586
|
-
this.alternateScope = new TrackingScope(this.scope);
|
|
9587
|
-
this.alternate = new (this.context.getNodeConstructor(esTreeNode.alternate.type))(esTreeNode.alternate, this, this.alternateScope);
|
|
9703
|
+
this.alternateScope = new TrackingScope(this.scope, this.scope.context);
|
|
9704
|
+
this.alternate = new (this.scope.context.getNodeConstructor(esTreeNode.alternate.type))(esTreeNode.alternate, this, this.alternateScope);
|
|
9588
9705
|
}
|
|
9589
9706
|
super.parseNode(esTreeNode);
|
|
9590
9707
|
}
|
|
@@ -9594,7 +9711,7 @@ class IfStatement extends NodeBase {
|
|
|
9594
9711
|
const testValue = this.getTestValue();
|
|
9595
9712
|
const hoistedDeclarations = [];
|
|
9596
9713
|
const includesIfElse = this.test.included;
|
|
9597
|
-
const noTreeshake = !this.context.options.treeshake;
|
|
9714
|
+
const noTreeshake = !this.scope.context.options.treeshake;
|
|
9598
9715
|
if (includesIfElse) {
|
|
9599
9716
|
this.test.render(code, options);
|
|
9600
9717
|
}
|
|
@@ -9714,7 +9831,7 @@ class ImportDeclaration extends NodeBase {
|
|
|
9714
9831
|
return false;
|
|
9715
9832
|
}
|
|
9716
9833
|
initialise() {
|
|
9717
|
-
this.context.addImport(this);
|
|
9834
|
+
this.scope.context.addImport(this);
|
|
9718
9835
|
}
|
|
9719
9836
|
render(code, _options, nodeRenderOptions) {
|
|
9720
9837
|
code.remove(nodeRenderOptions.start, nodeRenderOptions.end);
|
|
@@ -10098,13 +10215,13 @@ class ImportExpression extends NodeBase {
|
|
|
10098
10215
|
include(context, includeChildrenRecursively) {
|
|
10099
10216
|
if (!this.included) {
|
|
10100
10217
|
this.included = true;
|
|
10101
|
-
this.context.includeDynamicImport(this);
|
|
10218
|
+
this.scope.context.includeDynamicImport(this);
|
|
10102
10219
|
this.scope.addAccessedDynamicImport(this);
|
|
10103
10220
|
}
|
|
10104
10221
|
this.source.include(context, includeChildrenRecursively);
|
|
10105
10222
|
}
|
|
10106
10223
|
initialise() {
|
|
10107
|
-
this.context.addDynamicImport(this);
|
|
10224
|
+
this.scope.context.addDynamicImport(this);
|
|
10108
10225
|
}
|
|
10109
10226
|
parseNode(esTreeNode) {
|
|
10110
10227
|
// Keep the source AST to be used by renderDynamicImport
|
|
@@ -10176,7 +10293,7 @@ class ImportExpression extends NodeBase {
|
|
|
10176
10293
|
{
|
|
10177
10294
|
customResolution: typeof this.resolution === 'string' ? this.resolution : null,
|
|
10178
10295
|
format,
|
|
10179
|
-
moduleId: this.context.module.id,
|
|
10296
|
+
moduleId: this.scope.context.module.id,
|
|
10180
10297
|
targetModuleId: this.resolution && typeof this.resolution !== 'string' ? this.resolution.id : null
|
|
10181
10298
|
}
|
|
10182
10299
|
]);
|
|
@@ -10329,9 +10446,15 @@ class LogicalExpression extends NodeBase {
|
|
|
10329
10446
|
super(...arguments);
|
|
10330
10447
|
// We collect deoptimization information if usedBranch !== null
|
|
10331
10448
|
this.expressionsToBeDeoptimized = [];
|
|
10332
|
-
this.isBranchResolutionAnalysed = false;
|
|
10333
10449
|
this.usedBranch = null;
|
|
10334
10450
|
}
|
|
10451
|
+
//private isBranchResolutionAnalysed = false;
|
|
10452
|
+
get isBranchResolutionAnalysed() {
|
|
10453
|
+
return isFlagSet(this.flags, 65536 /* Flag.isBranchResolutionAnalysed */);
|
|
10454
|
+
}
|
|
10455
|
+
set isBranchResolutionAnalysed(value) {
|
|
10456
|
+
this.flags = setFlag(this.flags, 65536 /* Flag.isBranchResolutionAnalysed */, value);
|
|
10457
|
+
}
|
|
10335
10458
|
deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
10336
10459
|
this.left.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
|
|
10337
10460
|
this.right.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
|
|
@@ -10341,7 +10464,7 @@ class LogicalExpression extends NodeBase {
|
|
|
10341
10464
|
const unusedBranch = this.usedBranch === this.left ? this.right : this.left;
|
|
10342
10465
|
this.usedBranch = null;
|
|
10343
10466
|
unusedBranch.deoptimizePath(UNKNOWN_PATH);
|
|
10344
|
-
const { context, expressionsToBeDeoptimized } = this;
|
|
10467
|
+
const { scope: { context }, expressionsToBeDeoptimized } = this;
|
|
10345
10468
|
this.expressionsToBeDeoptimized = EMPTY_ARRAY;
|
|
10346
10469
|
for (const expression of expressionsToBeDeoptimized) {
|
|
10347
10470
|
expression.deoptimizeCache();
|
|
@@ -10489,7 +10612,7 @@ class MetaProperty extends NodeBase {
|
|
|
10489
10612
|
if (!this.included) {
|
|
10490
10613
|
this.included = true;
|
|
10491
10614
|
if (this.meta.name === IMPORT) {
|
|
10492
|
-
this.context.addImportMeta(this);
|
|
10615
|
+
this.scope.context.addImportMeta(this);
|
|
10493
10616
|
const parent = this.parent;
|
|
10494
10617
|
const metaProperty = (this.metaProperty =
|
|
10495
10618
|
parent instanceof MemberExpression && typeof parent.propertyKey === 'string'
|
|
@@ -10503,7 +10626,7 @@ class MetaProperty extends NodeBase {
|
|
|
10503
10626
|
}
|
|
10504
10627
|
render(code, renderOptions) {
|
|
10505
10628
|
const { format, pluginDriver, snippets } = renderOptions;
|
|
10506
|
-
const { context: { module }, meta: { name }, metaProperty, parent, preliminaryChunkId, referenceId, start, end } = this;
|
|
10629
|
+
const { scope: { context: { module } }, meta: { name }, metaProperty, parent, preliminaryChunkId, referenceId, start, end } = this;
|
|
10507
10630
|
const { id: moduleId } = module;
|
|
10508
10631
|
if (name !== IMPORT)
|
|
10509
10632
|
return;
|
|
@@ -10640,7 +10763,7 @@ class NewExpression extends NodeBase {
|
|
|
10640
10763
|
applyDeoptimizations() {
|
|
10641
10764
|
this.deoptimized = true;
|
|
10642
10765
|
this.callee.deoptimizeArgumentsOnInteractionAtPath(this.interaction, EMPTY_PATH, SHARED_RECURSION_TRACKER);
|
|
10643
|
-
this.context.requestTreeshakingPass();
|
|
10766
|
+
this.scope.context.requestTreeshakingPass();
|
|
10644
10767
|
}
|
|
10645
10768
|
}
|
|
10646
10769
|
|
|
@@ -10737,9 +10860,9 @@ class Program extends NodeBase {
|
|
|
10737
10860
|
hasEffects(context) {
|
|
10738
10861
|
for (const node of this.body) {
|
|
10739
10862
|
if (node.hasEffects(context)) {
|
|
10740
|
-
if (this.context.options.experimentalLogSideEffects && !this.hasLoggedEffect) {
|
|
10863
|
+
if (this.scope.context.options.experimentalLogSideEffects && !this.hasLoggedEffect) {
|
|
10741
10864
|
this.hasLoggedEffect = true;
|
|
10742
|
-
const { code, log, module } = this.context;
|
|
10865
|
+
const { code, log, module } = this.scope.context;
|
|
10743
10866
|
log(LOGLEVEL_INFO, logFirstSideEffect(code, module.id, locate(code, node.start, { offsetLine: 1 })), node.start);
|
|
10744
10867
|
}
|
|
10745
10868
|
return (this.hasCachedEffect = true);
|
|
@@ -10784,6 +10907,20 @@ class Property extends MethodBase {
|
|
|
10784
10907
|
super(...arguments);
|
|
10785
10908
|
this.declarationInit = null;
|
|
10786
10909
|
}
|
|
10910
|
+
//declare method: boolean;
|
|
10911
|
+
get method() {
|
|
10912
|
+
return isFlagSet(this.flags, 262144 /* Flag.method */);
|
|
10913
|
+
}
|
|
10914
|
+
set method(value) {
|
|
10915
|
+
this.flags = setFlag(this.flags, 262144 /* Flag.method */, value);
|
|
10916
|
+
}
|
|
10917
|
+
//declare shorthand: boolean;
|
|
10918
|
+
get shorthand() {
|
|
10919
|
+
return isFlagSet(this.flags, 524288 /* Flag.shorthand */);
|
|
10920
|
+
}
|
|
10921
|
+
set shorthand(value) {
|
|
10922
|
+
this.flags = setFlag(this.flags, 524288 /* Flag.shorthand */, value);
|
|
10923
|
+
}
|
|
10787
10924
|
declare(kind, init) {
|
|
10788
10925
|
this.declarationInit = init;
|
|
10789
10926
|
return this.value.declare(kind, UNKNOWN_EXPRESSION);
|
|
@@ -10791,8 +10928,7 @@ class Property extends MethodBase {
|
|
|
10791
10928
|
hasEffects(context) {
|
|
10792
10929
|
if (!this.deoptimized)
|
|
10793
10930
|
this.applyDeoptimizations();
|
|
10794
|
-
const propertyReadSideEffects = this.context.options.treeshake
|
|
10795
|
-
.propertyReadSideEffects;
|
|
10931
|
+
const propertyReadSideEffects = this.scope.context.options.treeshake.propertyReadSideEffects;
|
|
10796
10932
|
return ((this.parent.type === 'ObjectPattern' && propertyReadSideEffects === 'always') ||
|
|
10797
10933
|
this.key.hasEffects(context) ||
|
|
10798
10934
|
this.value.hasEffects(context));
|
|
@@ -10810,12 +10946,18 @@ class Property extends MethodBase {
|
|
|
10810
10946
|
this.deoptimized = true;
|
|
10811
10947
|
if (this.declarationInit !== null) {
|
|
10812
10948
|
this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
|
|
10813
|
-
this.context.requestTreeshakingPass();
|
|
10949
|
+
this.scope.context.requestTreeshakingPass();
|
|
10814
10950
|
}
|
|
10815
10951
|
}
|
|
10816
10952
|
}
|
|
10817
10953
|
|
|
10818
10954
|
class PropertyDefinition extends NodeBase {
|
|
10955
|
+
get computed() {
|
|
10956
|
+
return isFlagSet(this.flags, 1024 /* Flag.computed */);
|
|
10957
|
+
}
|
|
10958
|
+
set computed(value) {
|
|
10959
|
+
this.flags = setFlag(this.flags, 1024 /* Flag.computed */, value);
|
|
10960
|
+
}
|
|
10819
10961
|
deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
10820
10962
|
this.value?.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
|
|
10821
10963
|
}
|
|
@@ -10933,7 +11075,7 @@ class SequenceExpression extends NodeBase {
|
|
|
10933
11075
|
|
|
10934
11076
|
class StaticBlock extends NodeBase {
|
|
10935
11077
|
createScope(parentScope) {
|
|
10936
|
-
this.scope = new BlockScope(parentScope);
|
|
11078
|
+
this.scope = new BlockScope(parentScope, this.scope.context);
|
|
10937
11079
|
}
|
|
10938
11080
|
hasEffects(context) {
|
|
10939
11081
|
for (const node of this.body) {
|
|
@@ -10973,7 +11115,7 @@ class Super extends NodeBase {
|
|
|
10973
11115
|
include() {
|
|
10974
11116
|
if (!this.included) {
|
|
10975
11117
|
this.included = true;
|
|
10976
|
-
this.context.includeVariableInModule(this.variable);
|
|
11118
|
+
this.scope.context.includeVariableInModule(this.variable);
|
|
10977
11119
|
}
|
|
10978
11120
|
}
|
|
10979
11121
|
}
|
|
@@ -11017,7 +11159,7 @@ SwitchCase.prototype.needsBoundaries = true;
|
|
|
11017
11159
|
class SwitchStatement extends NodeBase {
|
|
11018
11160
|
createScope(parentScope) {
|
|
11019
11161
|
this.parentScope = parentScope;
|
|
11020
|
-
this.scope = new BlockScope(parentScope);
|
|
11162
|
+
this.scope = new BlockScope(parentScope, this.scope.context);
|
|
11021
11163
|
}
|
|
11022
11164
|
hasEffects(context) {
|
|
11023
11165
|
if (this.discriminant.hasEffects(context))
|
|
@@ -11086,7 +11228,7 @@ class SwitchStatement extends NodeBase {
|
|
|
11086
11228
|
this.defaultCase = null;
|
|
11087
11229
|
}
|
|
11088
11230
|
parseNode(esTreeNode) {
|
|
11089
|
-
this.discriminant = new (this.context.getNodeConstructor(esTreeNode.discriminant.type))(esTreeNode.discriminant, this, this.parentScope);
|
|
11231
|
+
this.discriminant = new (this.scope.context.getNodeConstructor(esTreeNode.discriminant.type))(esTreeNode.discriminant, this, this.parentScope);
|
|
11090
11232
|
super.parseNode(esTreeNode);
|
|
11091
11233
|
}
|
|
11092
11234
|
render(code, options) {
|
|
@@ -11104,7 +11246,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
|
|
|
11104
11246
|
const name = this.tag.name;
|
|
11105
11247
|
const variable = this.scope.findVariable(name);
|
|
11106
11248
|
if (variable.isNamespace) {
|
|
11107
|
-
this.context.log(LOGLEVEL_WARN, logCannotCallNamespace(name), this.start);
|
|
11249
|
+
this.scope.context.log(LOGLEVEL_WARN, logCannotCallNamespace(name), this.start);
|
|
11108
11250
|
}
|
|
11109
11251
|
}
|
|
11110
11252
|
}
|
|
@@ -11157,7 +11299,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
|
|
|
11157
11299
|
applyDeoptimizations() {
|
|
11158
11300
|
this.deoptimized = true;
|
|
11159
11301
|
this.tag.deoptimizeArgumentsOnInteractionAtPath(this.interaction, EMPTY_PATH, SHARED_RECURSION_TRACKER);
|
|
11160
|
-
this.context.requestTreeshakingPass();
|
|
11302
|
+
this.scope.context.requestTreeshakingPass();
|
|
11161
11303
|
}
|
|
11162
11304
|
getReturnExpression(recursionTracker = SHARED_RECURSION_TRACKER) {
|
|
11163
11305
|
if (this.returnExpression === null) {
|
|
@@ -11169,6 +11311,12 @@ class TaggedTemplateExpression extends CallExpressionBase {
|
|
|
11169
11311
|
}
|
|
11170
11312
|
|
|
11171
11313
|
class TemplateElement extends NodeBase {
|
|
11314
|
+
get tail() {
|
|
11315
|
+
return isFlagSet(this.flags, 1048576 /* Flag.tail */);
|
|
11316
|
+
}
|
|
11317
|
+
set tail(value) {
|
|
11318
|
+
this.flags = setFlag(this.flags, 1048576 /* Flag.tail */, value);
|
|
11319
|
+
}
|
|
11172
11320
|
// Do not try to bind value
|
|
11173
11321
|
bind() { }
|
|
11174
11322
|
hasEffects() {
|
|
@@ -11294,8 +11442,7 @@ class ExportDefaultVariable extends LocalVariable {
|
|
|
11294
11442
|
|
|
11295
11443
|
class ModuleScope extends ChildScope {
|
|
11296
11444
|
constructor(parent, context) {
|
|
11297
|
-
super(parent);
|
|
11298
|
-
this.context = context;
|
|
11445
|
+
super(parent, context);
|
|
11299
11446
|
this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, context));
|
|
11300
11447
|
}
|
|
11301
11448
|
addExportDefaultDeclaration(name, exportDefaultDeclaration, context) {
|
|
@@ -11344,14 +11491,16 @@ class ThisExpression extends NodeBase {
|
|
|
11344
11491
|
include() {
|
|
11345
11492
|
if (!this.included) {
|
|
11346
11493
|
this.included = true;
|
|
11347
|
-
this.context.includeVariableInModule(this.variable);
|
|
11494
|
+
this.scope.context.includeVariableInModule(this.variable);
|
|
11348
11495
|
}
|
|
11349
11496
|
}
|
|
11350
11497
|
initialise() {
|
|
11351
11498
|
this.alias =
|
|
11352
|
-
this.scope.findLexicalBoundary() instanceof ModuleScope
|
|
11499
|
+
this.scope.findLexicalBoundary() instanceof ModuleScope
|
|
11500
|
+
? this.scope.context.moduleContext
|
|
11501
|
+
: null;
|
|
11353
11502
|
if (this.alias === 'undefined') {
|
|
11354
|
-
this.context.log(LOGLEVEL_WARN, logThisIsUndefined(), this.start);
|
|
11503
|
+
this.scope.context.log(LOGLEVEL_WARN, logThisIsUndefined(), this.start);
|
|
11355
11504
|
}
|
|
11356
11505
|
}
|
|
11357
11506
|
render(code) {
|
|
@@ -11388,13 +11537,12 @@ class TryStatement extends NodeBase {
|
|
|
11388
11537
|
this.includedLabelsAfterBlock = null;
|
|
11389
11538
|
}
|
|
11390
11539
|
hasEffects(context) {
|
|
11391
|
-
return ((this.context.options.treeshake.tryCatchDeoptimization
|
|
11540
|
+
return ((this.scope.context.options.treeshake.tryCatchDeoptimization
|
|
11392
11541
|
? this.block.body.length > 0
|
|
11393
11542
|
: this.block.hasEffects(context)) || !!this.finalizer?.hasEffects(context));
|
|
11394
11543
|
}
|
|
11395
11544
|
include(context, includeChildrenRecursively) {
|
|
11396
|
-
const tryCatchDeoptimization = this.context.options.treeshake
|
|
11397
|
-
?.tryCatchDeoptimization;
|
|
11545
|
+
const tryCatchDeoptimization = this.scope.context.options.treeshake?.tryCatchDeoptimization;
|
|
11398
11546
|
const { brokenFlow, includedLabels } = context;
|
|
11399
11547
|
if (!this.directlyIncluded || !tryCatchDeoptimization) {
|
|
11400
11548
|
this.included = true;
|
|
@@ -11428,6 +11576,12 @@ const unaryOperators = {
|
|
|
11428
11576
|
'~': value => ~value
|
|
11429
11577
|
};
|
|
11430
11578
|
class UnaryExpression extends NodeBase {
|
|
11579
|
+
get prefix() {
|
|
11580
|
+
return isFlagSet(this.flags, 2097152 /* Flag.prefix */);
|
|
11581
|
+
}
|
|
11582
|
+
set prefix(value) {
|
|
11583
|
+
this.flags = setFlag(this.flags, 2097152 /* Flag.prefix */, value);
|
|
11584
|
+
}
|
|
11431
11585
|
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
11432
11586
|
if (path.length > 0)
|
|
11433
11587
|
return UnknownValue;
|
|
@@ -11452,7 +11606,7 @@ class UnaryExpression extends NodeBase {
|
|
|
11452
11606
|
this.deoptimized = true;
|
|
11453
11607
|
if (this.operator === 'delete') {
|
|
11454
11608
|
this.argument.deoptimizePath(EMPTY_PATH);
|
|
11455
|
-
this.context.requestTreeshakingPass();
|
|
11609
|
+
this.scope.context.requestTreeshakingPass();
|
|
11456
11610
|
}
|
|
11457
11611
|
}
|
|
11458
11612
|
}
|
|
@@ -11513,7 +11667,7 @@ class UpdateExpression extends NodeBase {
|
|
|
11513
11667
|
const variable = this.scope.findVariable(this.argument.name);
|
|
11514
11668
|
variable.isReassigned = true;
|
|
11515
11669
|
}
|
|
11516
|
-
this.context.requestTreeshakingPass();
|
|
11670
|
+
this.scope.context.requestTreeshakingPass();
|
|
11517
11671
|
}
|
|
11518
11672
|
}
|
|
11519
11673
|
|
|
@@ -11937,7 +12091,8 @@ class NamespaceVariable extends Variable {
|
|
|
11937
12091
|
this.mergedNamespaces = mergedNamespaces;
|
|
11938
12092
|
const moduleExecIndex = this.context.getModuleExecIndex();
|
|
11939
12093
|
for (const identifier of this.references) {
|
|
11940
|
-
|
|
12094
|
+
const { context } = identifier.scope;
|
|
12095
|
+
if (context.getModuleExecIndex() <= moduleExecIndex) {
|
|
11941
12096
|
this.referencedEarly = true;
|
|
11942
12097
|
break;
|
|
11943
12098
|
}
|
|
@@ -12093,7 +12248,7 @@ function getOriginalLocation(sourcemapChain, location) {
|
|
|
12093
12248
|
|
|
12094
12249
|
const ATTRIBUTE_KEYWORDS = new Set(['assert', 'with']);
|
|
12095
12250
|
function getAttributesFromImportExpression(node) {
|
|
12096
|
-
const { context, options, start } = node;
|
|
12251
|
+
const { scope: { context }, options, start } = node;
|
|
12097
12252
|
if (!(options instanceof ObjectExpression)) {
|
|
12098
12253
|
if (options) {
|
|
12099
12254
|
context.module.log(LOGLEVEL_WARN, logImportAttributeIsInvalid(context.module.id), start);
|