rollup 3.3.0 → 3.4.0-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/rollup.js +2 -2
- package/dist/es/shared/rollup.js +115 -56
- package/dist/es/shared/watch.js +2 -2
- package/dist/loadConfigFile.js +2 -2
- package/dist/rollup.d.ts +1 -0
- package/dist/rollup.js +2 -2
- package/dist/shared/index.js +2 -2
- package/dist/shared/loadConfigFile.js +2 -2
- package/dist/shared/rollup.js +119 -60
- package/dist/shared/watch-cli.js +2 -2
- package/dist/shared/watch.js +2 -2
- package/package.json +1 -1
package/dist/bin/rollup
CHANGED
package/dist/es/rollup.js
CHANGED
package/dist/es/shared/rollup.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v3.
|
|
4
|
-
|
|
3
|
+
Rollup.js v3.4.0-1
|
|
4
|
+
Mon, 21 Nov 2022 05:22:41 GMT - commit f7a081a72fd85e7e80e3cbefa55fbfd88eb52a3f
|
|
5
5
|
|
|
6
6
|
https://github.com/rollup/rollup
|
|
7
7
|
|
|
@@ -16,7 +16,7 @@ import { promises } from 'node:fs';
|
|
|
16
16
|
import { EventEmitter } from 'node:events';
|
|
17
17
|
import * as tty from 'tty';
|
|
18
18
|
|
|
19
|
-
var version$1 = "3.
|
|
19
|
+
var version$1 = "3.4.0-1";
|
|
20
20
|
|
|
21
21
|
var charToInteger = {};
|
|
22
22
|
var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
@@ -1776,7 +1776,7 @@ class ExpressionEntity {
|
|
|
1776
1776
|
return UnknownValue;
|
|
1777
1777
|
}
|
|
1778
1778
|
getReturnExpressionWhenCalledAtPath(_path, _interaction, _recursionTracker, _origin) {
|
|
1779
|
-
return
|
|
1779
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
1780
1780
|
}
|
|
1781
1781
|
hasEffectsOnInteractionAtPath(_path, _interaction, _context) {
|
|
1782
1782
|
return true;
|
|
@@ -1795,6 +1795,10 @@ class ExpressionEntity {
|
|
|
1795
1795
|
}
|
|
1796
1796
|
const UNKNOWN_EXPRESSION = new (class UnknownExpression extends ExpressionEntity {
|
|
1797
1797
|
})();
|
|
1798
|
+
const UNKNOWN_RETURN_EXPRESSION = [
|
|
1799
|
+
UNKNOWN_EXPRESSION,
|
|
1800
|
+
false
|
|
1801
|
+
];
|
|
1798
1802
|
|
|
1799
1803
|
const INTERACTION_ACCESSED = 0;
|
|
1800
1804
|
const INTERACTION_ASSIGNED = 1;
|
|
@@ -4930,7 +4934,7 @@ const UNKNOWN_LITERAL_BOOLEAN = new (class UnknownBoolean extends ExpressionEnti
|
|
|
4930
4934
|
if (path.length === 1) {
|
|
4931
4935
|
return getMemberReturnExpressionWhenCalled(literalBooleanMembers, path[0]);
|
|
4932
4936
|
}
|
|
4933
|
-
return
|
|
4937
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
4934
4938
|
}
|
|
4935
4939
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
4936
4940
|
if (interaction.type === INTERACTION_ACCESSED) {
|
|
@@ -4953,7 +4957,7 @@ const UNKNOWN_LITERAL_NUMBER = new (class UnknownNumber extends ExpressionEntity
|
|
|
4953
4957
|
if (path.length === 1) {
|
|
4954
4958
|
return getMemberReturnExpressionWhenCalled(literalNumberMembers, path[0]);
|
|
4955
4959
|
}
|
|
4956
|
-
return
|
|
4960
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
4957
4961
|
}
|
|
4958
4962
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
4959
4963
|
if (interaction.type === INTERACTION_ACCESSED) {
|
|
@@ -4976,7 +4980,7 @@ const UNKNOWN_LITERAL_STRING = new (class UnknownString extends ExpressionEntity
|
|
|
4976
4980
|
if (path.length === 1) {
|
|
4977
4981
|
return getMemberReturnExpressionWhenCalled(literalStringMembers, path[0]);
|
|
4978
4982
|
}
|
|
4979
|
-
return
|
|
4983
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
4980
4984
|
}
|
|
4981
4985
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
4982
4986
|
if (interaction.type === INTERACTION_ACCESSED) {
|
|
@@ -5097,8 +5101,8 @@ function hasMemberEffectWhenCalled(members, memberName, interaction, context) {
|
|
|
5097
5101
|
}
|
|
5098
5102
|
function getMemberReturnExpressionWhenCalled(members, memberName) {
|
|
5099
5103
|
if (typeof memberName !== 'string' || !members[memberName])
|
|
5100
|
-
return
|
|
5101
|
-
return members[memberName].returns;
|
|
5104
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
5105
|
+
return [members[memberName].returns, false];
|
|
5102
5106
|
}
|
|
5103
5107
|
|
|
5104
5108
|
// AST walker module for Mozilla Parser API compatible trees
|
|
@@ -5748,12 +5752,15 @@ class Method extends ExpressionEntity {
|
|
|
5748
5752
|
}
|
|
5749
5753
|
getReturnExpressionWhenCalledAtPath(path, { thisArg }) {
|
|
5750
5754
|
if (path.length > 0) {
|
|
5751
|
-
return
|
|
5755
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
5752
5756
|
}
|
|
5753
|
-
return
|
|
5754
|
-
|
|
5755
|
-
|
|
5756
|
-
|
|
5757
|
+
return [
|
|
5758
|
+
this.description.returnsPrimitive ||
|
|
5759
|
+
(this.description.returns === 'self'
|
|
5760
|
+
? thisArg || UNKNOWN_EXPRESSION
|
|
5761
|
+
: this.description.returns()),
|
|
5762
|
+
false
|
|
5763
|
+
];
|
|
5757
5764
|
}
|
|
5758
5765
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
5759
5766
|
const { type } = interaction;
|
|
@@ -5996,7 +6003,7 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
5996
6003
|
}
|
|
5997
6004
|
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
5998
6005
|
if (path.length === 0) {
|
|
5999
|
-
return
|
|
6006
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
6000
6007
|
}
|
|
6001
6008
|
const [key, ...subPath] = path;
|
|
6002
6009
|
const expressionAtPath = this.getMemberExpressionAndTrackDeopt(key, origin);
|
|
@@ -6006,7 +6013,7 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
6006
6013
|
if (this.prototypeExpression) {
|
|
6007
6014
|
return this.prototypeExpression.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
|
|
6008
6015
|
}
|
|
6009
|
-
return
|
|
6016
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
6010
6017
|
}
|
|
6011
6018
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
6012
6019
|
const [key, ...subPath] = path;
|
|
@@ -6478,12 +6485,12 @@ class LocalVariable extends Variable {
|
|
|
6478
6485
|
}
|
|
6479
6486
|
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
6480
6487
|
if (this.isReassigned || !this.init) {
|
|
6481
|
-
return
|
|
6488
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
6482
6489
|
}
|
|
6483
6490
|
return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
|
|
6484
6491
|
this.expressionsToBeDeoptimized.push(origin);
|
|
6485
6492
|
return this.init.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
|
|
6486
|
-
},
|
|
6493
|
+
}, UNKNOWN_RETURN_EXPRESSION);
|
|
6487
6494
|
}
|
|
6488
6495
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
6489
6496
|
switch (interaction.type) {
|
|
@@ -6840,6 +6847,19 @@ function is_reference (node, parent) {
|
|
|
6840
6847
|
return false;
|
|
6841
6848
|
}
|
|
6842
6849
|
|
|
6850
|
+
const PureFunctionKey = Symbol('PureFunction');
|
|
6851
|
+
const getPureFunctions = ({ treeshake }) => {
|
|
6852
|
+
const pureFunctions = Object.create(null);
|
|
6853
|
+
for (const functionName of treeshake ? treeshake.manualPureFunctions : []) {
|
|
6854
|
+
let currentFunctions = pureFunctions;
|
|
6855
|
+
for (const pathSegment of functionName.split('.')) {
|
|
6856
|
+
currentFunctions = currentFunctions[pathSegment] || (currentFunctions[pathSegment] = Object.create(null));
|
|
6857
|
+
}
|
|
6858
|
+
currentFunctions[PureFunctionKey] = true;
|
|
6859
|
+
}
|
|
6860
|
+
return pureFunctions;
|
|
6861
|
+
};
|
|
6862
|
+
|
|
6843
6863
|
/* eslint sort-keys: "off" */
|
|
6844
6864
|
const ValueProperties = Symbol('Value Properties');
|
|
6845
6865
|
const getTruthyLiteralValue = () => UnknownTruthyValue;
|
|
@@ -7817,7 +7837,8 @@ class Identifier extends NodeBase {
|
|
|
7817
7837
|
return this.getVariableRespectingTDZ().getLiteralValueAtPath(path, recursionTracker, origin);
|
|
7818
7838
|
}
|
|
7819
7839
|
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
7820
|
-
|
|
7840
|
+
const [expression, isPure] = this.getVariableRespectingTDZ().getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
|
|
7841
|
+
return [expression, isPure || this.isPureFunction(path)];
|
|
7821
7842
|
}
|
|
7822
7843
|
hasEffects(context) {
|
|
7823
7844
|
if (!this.deoptimized)
|
|
@@ -7827,19 +7848,22 @@ class Identifier extends NodeBase {
|
|
|
7827
7848
|
}
|
|
7828
7849
|
return (this.context.options.treeshake.unknownGlobalSideEffects &&
|
|
7829
7850
|
this.variable instanceof GlobalVariable &&
|
|
7851
|
+
!this.isPureFunction(EMPTY_PATH) &&
|
|
7830
7852
|
this.variable.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_ACCESS, context));
|
|
7831
7853
|
}
|
|
7832
7854
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
7833
7855
|
switch (interaction.type) {
|
|
7834
7856
|
case INTERACTION_ACCESSED: {
|
|
7835
7857
|
return (this.variable !== null &&
|
|
7858
|
+
!this.isPureFunction(path) &&
|
|
7836
7859
|
this.getVariableRespectingTDZ().hasEffectsOnInteractionAtPath(path, interaction, context));
|
|
7837
7860
|
}
|
|
7838
7861
|
case INTERACTION_ASSIGNED: {
|
|
7839
7862
|
return (path.length > 0 ? this.getVariableRespectingTDZ() : this.variable).hasEffectsOnInteractionAtPath(path, interaction, context);
|
|
7840
7863
|
}
|
|
7841
7864
|
case INTERACTION_CALLED: {
|
|
7842
|
-
return this.
|
|
7865
|
+
return (!this.isPureFunction(path) &&
|
|
7866
|
+
this.getVariableRespectingTDZ().hasEffectsOnInteractionAtPath(path, interaction, context));
|
|
7843
7867
|
}
|
|
7844
7868
|
}
|
|
7845
7869
|
}
|
|
@@ -7921,6 +7945,21 @@ class Identifier extends NodeBase {
|
|
|
7921
7945
|
}
|
|
7922
7946
|
return this.variable;
|
|
7923
7947
|
}
|
|
7948
|
+
isPureFunction(path) {
|
|
7949
|
+
let currentPureFunction = this.context.manualPureFunctions[this.name];
|
|
7950
|
+
for (const segment of path) {
|
|
7951
|
+
if (currentPureFunction) {
|
|
7952
|
+
if (currentPureFunction[PureFunctionKey]) {
|
|
7953
|
+
return true;
|
|
7954
|
+
}
|
|
7955
|
+
currentPureFunction = currentPureFunction[segment];
|
|
7956
|
+
}
|
|
7957
|
+
else {
|
|
7958
|
+
return false;
|
|
7959
|
+
}
|
|
7960
|
+
}
|
|
7961
|
+
return currentPureFunction?.[PureFunctionKey];
|
|
7962
|
+
}
|
|
7924
7963
|
}
|
|
7925
7964
|
function closestParentFunctionOrProgram(node) {
|
|
7926
7965
|
while (node && !/^Program|Function/.test(node.type)) {
|
|
@@ -8242,9 +8281,9 @@ class FunctionBase extends NodeBase {
|
|
|
8242
8281
|
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
8243
8282
|
this.context.requestTreeshakingPass();
|
|
8244
8283
|
}
|
|
8245
|
-
return
|
|
8284
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
8246
8285
|
}
|
|
8247
|
-
return this.scope.getReturnExpression();
|
|
8286
|
+
return [this.scope.getReturnExpression(), false];
|
|
8248
8287
|
}
|
|
8249
8288
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
8250
8289
|
if (path.length > 0 || interaction.type !== INTERACTION_CALLED) {
|
|
@@ -8843,7 +8882,7 @@ class Literal extends NodeBase {
|
|
|
8843
8882
|
}
|
|
8844
8883
|
getReturnExpressionWhenCalledAtPath(path) {
|
|
8845
8884
|
if (path.length !== 1)
|
|
8846
|
-
return
|
|
8885
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
8847
8886
|
return getMemberReturnExpressionWhenCalled(this.members, path[0]);
|
|
8848
8887
|
}
|
|
8849
8888
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
@@ -8996,13 +9035,13 @@ class MemberExpression extends NodeBase {
|
|
|
8996
9035
|
return this.variable.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
|
|
8997
9036
|
}
|
|
8998
9037
|
if (this.isUndefined) {
|
|
8999
|
-
return UNDEFINED_EXPRESSION;
|
|
9038
|
+
return [UNDEFINED_EXPRESSION, false];
|
|
9000
9039
|
}
|
|
9001
9040
|
this.expressionsToBeDeoptimized.push(origin);
|
|
9002
9041
|
if (path.length < MAX_PATH_DEPTH) {
|
|
9003
9042
|
return this.object.getReturnExpressionWhenCalledAtPath([this.getPropertyKey(), ...path], interaction, recursionTracker, origin);
|
|
9004
9043
|
}
|
|
9005
|
-
return
|
|
9044
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
9006
9045
|
}
|
|
9007
9046
|
hasEffects(context) {
|
|
9008
9047
|
if (!this.deoptimized)
|
|
@@ -9179,8 +9218,8 @@ class CallExpressionBase extends NodeBase {
|
|
|
9179
9218
|
this.expressionsToBeDeoptimized = new Set();
|
|
9180
9219
|
}
|
|
9181
9220
|
deoptimizeCache() {
|
|
9182
|
-
if (this.returnExpression !== UNKNOWN_EXPRESSION) {
|
|
9183
|
-
this.returnExpression =
|
|
9221
|
+
if (this.returnExpression?.[0] !== UNKNOWN_EXPRESSION) {
|
|
9222
|
+
this.returnExpression = UNKNOWN_RETURN_EXPRESSION;
|
|
9184
9223
|
for (const expression of this.deoptimizableDependentExpressions) {
|
|
9185
9224
|
expression.deoptimizeCache();
|
|
9186
9225
|
}
|
|
@@ -9194,13 +9233,15 @@ class CallExpressionBase extends NodeBase {
|
|
|
9194
9233
|
this.context.deoptimizationTracker.trackEntityAtPathAndGetIfTracked(path, this)) {
|
|
9195
9234
|
return;
|
|
9196
9235
|
}
|
|
9197
|
-
const returnExpression = this.getReturnExpression();
|
|
9236
|
+
const [returnExpression] = this.getReturnExpression();
|
|
9198
9237
|
if (returnExpression !== UNKNOWN_EXPRESSION) {
|
|
9199
9238
|
returnExpression.deoptimizePath(path);
|
|
9200
9239
|
}
|
|
9201
9240
|
}
|
|
9202
9241
|
deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
9203
|
-
const returnExpression = this.getReturnExpression(recursionTracker);
|
|
9242
|
+
const [returnExpression, isPure] = this.getReturnExpression(recursionTracker);
|
|
9243
|
+
if (isPure)
|
|
9244
|
+
return;
|
|
9204
9245
|
if (returnExpression === UNKNOWN_EXPRESSION) {
|
|
9205
9246
|
interaction.thisArg.deoptimizePath(UNKNOWN_PATH);
|
|
9206
9247
|
}
|
|
@@ -9212,7 +9253,7 @@ class CallExpressionBase extends NodeBase {
|
|
|
9212
9253
|
}
|
|
9213
9254
|
}
|
|
9214
9255
|
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
9215
|
-
const returnExpression = this.getReturnExpression(recursionTracker);
|
|
9256
|
+
const [returnExpression] = this.getReturnExpression(recursionTracker);
|
|
9216
9257
|
if (returnExpression === UNKNOWN_EXPRESSION) {
|
|
9217
9258
|
return UnknownValue;
|
|
9218
9259
|
}
|
|
@@ -9223,13 +9264,14 @@ class CallExpressionBase extends NodeBase {
|
|
|
9223
9264
|
}
|
|
9224
9265
|
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
9225
9266
|
const returnExpression = this.getReturnExpression(recursionTracker);
|
|
9226
|
-
if (
|
|
9227
|
-
return
|
|
9267
|
+
if (returnExpression[0] === UNKNOWN_EXPRESSION) {
|
|
9268
|
+
return returnExpression;
|
|
9228
9269
|
}
|
|
9229
9270
|
return recursionTracker.withTrackedEntityAtPath(path, returnExpression, () => {
|
|
9230
9271
|
this.deoptimizableDependentExpressions.push(origin);
|
|
9231
|
-
|
|
9232
|
-
|
|
9272
|
+
const [expression, isPure] = returnExpression[0].getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
|
|
9273
|
+
return [expression, isPure || returnExpression[1]];
|
|
9274
|
+
}, UNKNOWN_RETURN_EXPRESSION);
|
|
9233
9275
|
}
|
|
9234
9276
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
9235
9277
|
const { type } = interaction;
|
|
@@ -9244,7 +9286,9 @@ class CallExpressionBase extends NodeBase {
|
|
|
9244
9286
|
: context.accessed).trackEntityAtPathAndGetIfTracked(path, this)) {
|
|
9245
9287
|
return false;
|
|
9246
9288
|
}
|
|
9247
|
-
|
|
9289
|
+
const [returnExpression, isPure] = this.getReturnExpression();
|
|
9290
|
+
return ((type === INTERACTION_ASSIGNED || !isPure) &&
|
|
9291
|
+
returnExpression.hasEffectsOnInteractionAtPath(path, interaction, context));
|
|
9248
9292
|
}
|
|
9249
9293
|
}
|
|
9250
9294
|
|
|
@@ -9323,7 +9367,7 @@ class CallExpression extends CallExpressionBase {
|
|
|
9323
9367
|
}
|
|
9324
9368
|
getReturnExpression(recursionTracker = SHARED_RECURSION_TRACKER) {
|
|
9325
9369
|
if (this.returnExpression === null) {
|
|
9326
|
-
this.returnExpression =
|
|
9370
|
+
this.returnExpression = UNKNOWN_RETURN_EXPRESSION;
|
|
9327
9371
|
return (this.returnExpression = this.callee.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.interaction, recursionTracker, this));
|
|
9328
9372
|
}
|
|
9329
9373
|
return this.returnExpression;
|
|
@@ -9407,7 +9451,7 @@ class MethodBase extends NodeBase {
|
|
|
9407
9451
|
// expressions, there is no known situation where a getter is deoptimized.
|
|
9408
9452
|
deoptimizeCache() { }
|
|
9409
9453
|
deoptimizePath(path) {
|
|
9410
|
-
this.getAccessedValue().deoptimizePath(path);
|
|
9454
|
+
this.getAccessedValue()[0].deoptimizePath(path);
|
|
9411
9455
|
}
|
|
9412
9456
|
deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
9413
9457
|
if (interaction.type === INTERACTION_ACCESSED && this.kind === 'get' && path.length === 0) {
|
|
@@ -9426,13 +9470,13 @@ class MethodBase extends NodeBase {
|
|
|
9426
9470
|
withNew: false
|
|
9427
9471
|
}, EMPTY_PATH, recursionTracker);
|
|
9428
9472
|
}
|
|
9429
|
-
this.getAccessedValue().deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
|
|
9473
|
+
this.getAccessedValue()[0].deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
|
|
9430
9474
|
}
|
|
9431
9475
|
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
9432
|
-
return this.getAccessedValue().getLiteralValueAtPath(path, recursionTracker, origin);
|
|
9476
|
+
return this.getAccessedValue()[0].getLiteralValueAtPath(path, recursionTracker, origin);
|
|
9433
9477
|
}
|
|
9434
9478
|
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
9435
|
-
return this.getAccessedValue().getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
|
|
9479
|
+
return this.getAccessedValue()[0].getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
|
|
9436
9480
|
}
|
|
9437
9481
|
hasEffects(context) {
|
|
9438
9482
|
return this.key.hasEffects(context);
|
|
@@ -9455,17 +9499,17 @@ class MethodBase extends NodeBase {
|
|
|
9455
9499
|
withNew: false
|
|
9456
9500
|
}, context);
|
|
9457
9501
|
}
|
|
9458
|
-
return this.getAccessedValue().hasEffectsOnInteractionAtPath(path, interaction, context);
|
|
9502
|
+
return this.getAccessedValue()[0].hasEffectsOnInteractionAtPath(path, interaction, context);
|
|
9459
9503
|
}
|
|
9460
9504
|
applyDeoptimizations() { }
|
|
9461
9505
|
getAccessedValue() {
|
|
9462
9506
|
if (this.accessedValue === null) {
|
|
9463
9507
|
if (this.kind === 'get') {
|
|
9464
|
-
this.accessedValue =
|
|
9508
|
+
this.accessedValue = UNKNOWN_RETURN_EXPRESSION;
|
|
9465
9509
|
return (this.accessedValue = this.value.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_CALL, SHARED_RECURSION_TRACKER, this));
|
|
9466
9510
|
}
|
|
9467
9511
|
else {
|
|
9468
|
-
return (this.accessedValue = this.value);
|
|
9512
|
+
return (this.accessedValue = [this.value, false]);
|
|
9469
9513
|
}
|
|
9470
9514
|
}
|
|
9471
9515
|
return this.accessedValue;
|
|
@@ -9678,7 +9722,10 @@ class MultiExpression extends ExpressionEntity {
|
|
|
9678
9722
|
}
|
|
9679
9723
|
}
|
|
9680
9724
|
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
9681
|
-
return
|
|
9725
|
+
return [
|
|
9726
|
+
new MultiExpression(this.expressions.map(expression => expression.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0])),
|
|
9727
|
+
false
|
|
9728
|
+
];
|
|
9682
9729
|
}
|
|
9683
9730
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
9684
9731
|
for (const expression of this.expressions) {
|
|
@@ -9730,10 +9777,13 @@ class ConditionalExpression extends NodeBase {
|
|
|
9730
9777
|
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
9731
9778
|
const usedBranch = this.getUsedBranch();
|
|
9732
9779
|
if (!usedBranch)
|
|
9733
|
-
return
|
|
9734
|
-
|
|
9735
|
-
|
|
9736
|
-
|
|
9780
|
+
return [
|
|
9781
|
+
new MultiExpression([
|
|
9782
|
+
this.consequent.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0],
|
|
9783
|
+
this.alternate.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0]
|
|
9784
|
+
]),
|
|
9785
|
+
false
|
|
9786
|
+
];
|
|
9737
9787
|
this.expressionsToBeDeoptimized.push(origin);
|
|
9738
9788
|
return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
|
|
9739
9789
|
}
|
|
@@ -10858,10 +10908,13 @@ class LogicalExpression extends NodeBase {
|
|
|
10858
10908
|
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
10859
10909
|
const usedBranch = this.getUsedBranch();
|
|
10860
10910
|
if (!usedBranch)
|
|
10861
|
-
return
|
|
10862
|
-
|
|
10863
|
-
|
|
10864
|
-
|
|
10911
|
+
return [
|
|
10912
|
+
new MultiExpression([
|
|
10913
|
+
this.left.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0],
|
|
10914
|
+
this.right.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0]
|
|
10915
|
+
]),
|
|
10916
|
+
false
|
|
10917
|
+
];
|
|
10865
10918
|
this.expressionsToBeDeoptimized.push(origin);
|
|
10866
10919
|
return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
|
|
10867
10920
|
}
|
|
@@ -11287,7 +11340,7 @@ class PropertyDefinition extends NodeBase {
|
|
|
11287
11340
|
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
11288
11341
|
return this.value
|
|
11289
11342
|
? this.value.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)
|
|
11290
|
-
:
|
|
11343
|
+
: UNKNOWN_RETURN_EXPRESSION;
|
|
11291
11344
|
}
|
|
11292
11345
|
hasEffects(context) {
|
|
11293
11346
|
return this.key.hasEffects(context) || (this.static && !!this.value?.hasEffects(context));
|
|
@@ -11578,7 +11631,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
|
|
|
11578
11631
|
this.quasi.include(context, includeChildrenRecursively);
|
|
11579
11632
|
}
|
|
11580
11633
|
this.tag.includeCallArguments(context, this.interaction.args);
|
|
11581
|
-
const returnExpression = this.getReturnExpression();
|
|
11634
|
+
const [returnExpression] = this.getReturnExpression();
|
|
11582
11635
|
if (!returnExpression.included) {
|
|
11583
11636
|
returnExpression.include(context, false);
|
|
11584
11637
|
}
|
|
@@ -11608,7 +11661,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
|
|
|
11608
11661
|
}
|
|
11609
11662
|
getReturnExpression(recursionTracker = SHARED_RECURSION_TRACKER) {
|
|
11610
11663
|
if (this.returnExpression === null) {
|
|
11611
|
-
this.returnExpression =
|
|
11664
|
+
this.returnExpression = UNKNOWN_RETURN_EXPRESSION;
|
|
11612
11665
|
return (this.returnExpression = this.tag.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.interaction, recursionTracker, this));
|
|
11613
11666
|
}
|
|
11614
11667
|
return this.returnExpression;
|
|
@@ -11641,7 +11694,7 @@ class TemplateLiteral extends NodeBase {
|
|
|
11641
11694
|
}
|
|
11642
11695
|
getReturnExpressionWhenCalledAtPath(path) {
|
|
11643
11696
|
if (path.length !== 1) {
|
|
11644
|
-
return
|
|
11697
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
11645
11698
|
}
|
|
11646
11699
|
return getMemberReturnExpressionWhenCalled(literalStringMembers, path[0]);
|
|
11647
11700
|
}
|
|
@@ -13155,6 +13208,7 @@ class Module {
|
|
|
13155
13208
|
includeDynamicImport: this.includeDynamicImport.bind(this),
|
|
13156
13209
|
includeVariableInModule: this.includeVariableInModule.bind(this),
|
|
13157
13210
|
magicString: this.magicString,
|
|
13211
|
+
manualPureFunctions: this.graph.pureFunctions,
|
|
13158
13212
|
module: this,
|
|
13159
13213
|
moduleContext: this.context,
|
|
13160
13214
|
options: this.options,
|
|
@@ -23476,6 +23530,7 @@ class Graph {
|
|
|
23476
23530
|
this.acornParser = Parser.extend(...options.acornInjectPlugins);
|
|
23477
23531
|
this.moduleLoader = new ModuleLoader(this, this.modulesById, this.options, this.pluginDriver);
|
|
23478
23532
|
this.fileOperationQueue = new Queue(options.maxParallelFileOps);
|
|
23533
|
+
this.pureFunctions = getPureFunctions(options);
|
|
23479
23534
|
}
|
|
23480
23535
|
async build() {
|
|
23481
23536
|
timeStart('generate module graph', 2);
|
|
@@ -23975,6 +24030,7 @@ const treeshakePresets = {
|
|
|
23975
24030
|
recommended: {
|
|
23976
24031
|
annotations: true,
|
|
23977
24032
|
correctVarValueBeforeDeclaration: false,
|
|
24033
|
+
manualPureFunctions: EMPTY_ARRAY,
|
|
23978
24034
|
moduleSideEffects: () => true,
|
|
23979
24035
|
propertyReadSideEffects: true,
|
|
23980
24036
|
tryCatchDeoptimization: true,
|
|
@@ -23983,6 +24039,7 @@ const treeshakePresets = {
|
|
|
23983
24039
|
safest: {
|
|
23984
24040
|
annotations: true,
|
|
23985
24041
|
correctVarValueBeforeDeclaration: true,
|
|
24042
|
+
manualPureFunctions: EMPTY_ARRAY,
|
|
23986
24043
|
moduleSideEffects: () => true,
|
|
23987
24044
|
propertyReadSideEffects: true,
|
|
23988
24045
|
tryCatchDeoptimization: true,
|
|
@@ -23991,6 +24048,7 @@ const treeshakePresets = {
|
|
|
23991
24048
|
smallest: {
|
|
23992
24049
|
annotations: true,
|
|
23993
24050
|
correctVarValueBeforeDeclaration: false,
|
|
24051
|
+
manualPureFunctions: EMPTY_ARRAY,
|
|
23994
24052
|
moduleSideEffects: () => false,
|
|
23995
24053
|
propertyReadSideEffects: false,
|
|
23996
24054
|
tryCatchDeoptimization: false,
|
|
@@ -24187,6 +24245,7 @@ const getTreeshake = (config) => {
|
|
|
24187
24245
|
return {
|
|
24188
24246
|
annotations: configWithPreset.annotations !== false,
|
|
24189
24247
|
correctVarValueBeforeDeclaration: configWithPreset.correctVarValueBeforeDeclaration === true,
|
|
24248
|
+
manualPureFunctions: configWithPreset.manualPureFunctions ?? EMPTY_ARRAY,
|
|
24190
24249
|
moduleSideEffects: getHasModuleSideEffects(configWithPreset.moduleSideEffects),
|
|
24191
24250
|
propertyReadSideEffects: configWithPreset.propertyReadSideEffects === 'always'
|
|
24192
24251
|
? 'always'
|
package/dist/es/shared/watch.js
CHANGED
package/dist/loadConfigFile.js
CHANGED
package/dist/rollup.d.ts
CHANGED
|
@@ -466,6 +466,7 @@ type TreeshakingPreset = 'smallest' | 'safest' | 'recommended';
|
|
|
466
466
|
export interface NormalizedTreeshakingOptions {
|
|
467
467
|
annotations: boolean;
|
|
468
468
|
correctVarValueBeforeDeclaration: boolean;
|
|
469
|
+
manualPureFunctions: readonly string[];
|
|
469
470
|
moduleSideEffects: HasModuleSideEffects;
|
|
470
471
|
propertyReadSideEffects: boolean | 'always';
|
|
471
472
|
tryCatchDeoptimization: boolean;
|
package/dist/rollup.js
CHANGED
package/dist/shared/index.js
CHANGED
package/dist/shared/rollup.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v3.
|
|
4
|
-
|
|
3
|
+
Rollup.js v3.4.0-1
|
|
4
|
+
Mon, 21 Nov 2022 05:22:41 GMT - commit f7a081a72fd85e7e80e3cbefa55fbfd88eb52a3f
|
|
5
5
|
|
|
6
6
|
https://github.com/rollup/rollup
|
|
7
7
|
|
|
@@ -31,7 +31,7 @@ function _interopNamespaceDefault(e) {
|
|
|
31
31
|
|
|
32
32
|
const tty__namespace = /*#__PURE__*/_interopNamespaceDefault(tty);
|
|
33
33
|
|
|
34
|
-
var version$1 = "3.
|
|
34
|
+
var version$1 = "3.4.0-1";
|
|
35
35
|
|
|
36
36
|
function ensureArray$1(items) {
|
|
37
37
|
if (Array.isArray(items)) {
|
|
@@ -50,6 +50,10 @@ async function asyncFlatten(array) {
|
|
|
50
50
|
return array;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
const BLANK = Object.freeze(Object.create(null));
|
|
54
|
+
const EMPTY_OBJECT = Object.freeze({});
|
|
55
|
+
const EMPTY_ARRAY = Object.freeze([]);
|
|
56
|
+
|
|
53
57
|
function getLocator$1(source, options) {
|
|
54
58
|
if (options === void 0) { options = {}; }
|
|
55
59
|
var offsetLine = options.offsetLine || 0;
|
|
@@ -814,6 +818,7 @@ const treeshakePresets = {
|
|
|
814
818
|
recommended: {
|
|
815
819
|
annotations: true,
|
|
816
820
|
correctVarValueBeforeDeclaration: false,
|
|
821
|
+
manualPureFunctions: EMPTY_ARRAY,
|
|
817
822
|
moduleSideEffects: () => true,
|
|
818
823
|
propertyReadSideEffects: true,
|
|
819
824
|
tryCatchDeoptimization: true,
|
|
@@ -822,6 +827,7 @@ const treeshakePresets = {
|
|
|
822
827
|
safest: {
|
|
823
828
|
annotations: true,
|
|
824
829
|
correctVarValueBeforeDeclaration: true,
|
|
830
|
+
manualPureFunctions: EMPTY_ARRAY,
|
|
825
831
|
moduleSideEffects: () => true,
|
|
826
832
|
propertyReadSideEffects: true,
|
|
827
833
|
tryCatchDeoptimization: true,
|
|
@@ -830,6 +836,7 @@ const treeshakePresets = {
|
|
|
830
836
|
smallest: {
|
|
831
837
|
annotations: true,
|
|
832
838
|
correctVarValueBeforeDeclaration: false,
|
|
839
|
+
manualPureFunctions: EMPTY_ARRAY,
|
|
833
840
|
moduleSideEffects: () => false,
|
|
834
841
|
propertyReadSideEffects: false,
|
|
835
842
|
tryCatchDeoptimization: false,
|
|
@@ -2916,7 +2923,7 @@ class ExpressionEntity {
|
|
|
2916
2923
|
return UnknownValue;
|
|
2917
2924
|
}
|
|
2918
2925
|
getReturnExpressionWhenCalledAtPath(_path, _interaction, _recursionTracker, _origin) {
|
|
2919
|
-
return
|
|
2926
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
2920
2927
|
}
|
|
2921
2928
|
hasEffectsOnInteractionAtPath(_path, _interaction, _context) {
|
|
2922
2929
|
return true;
|
|
@@ -2935,6 +2942,10 @@ class ExpressionEntity {
|
|
|
2935
2942
|
}
|
|
2936
2943
|
const UNKNOWN_EXPRESSION = new (class UnknownExpression extends ExpressionEntity {
|
|
2937
2944
|
})();
|
|
2945
|
+
const UNKNOWN_RETURN_EXPRESSION = [
|
|
2946
|
+
UNKNOWN_EXPRESSION,
|
|
2947
|
+
false
|
|
2948
|
+
];
|
|
2938
2949
|
|
|
2939
2950
|
const INTERACTION_ACCESSED = 0;
|
|
2940
2951
|
const INTERACTION_ASSIGNED = 1;
|
|
@@ -3035,10 +3046,6 @@ class ExternalVariable extends Variable {
|
|
|
3035
3046
|
}
|
|
3036
3047
|
}
|
|
3037
3048
|
|
|
3038
|
-
const BLANK = Object.freeze(Object.create(null));
|
|
3039
|
-
const EMPTY_OBJECT = Object.freeze({});
|
|
3040
|
-
const EMPTY_ARRAY = Object.freeze([]);
|
|
3041
|
-
|
|
3042
3049
|
const RESERVED_NAMES = new Set([
|
|
3043
3050
|
'await',
|
|
3044
3051
|
'break',
|
|
@@ -5442,7 +5449,7 @@ const UNKNOWN_LITERAL_BOOLEAN = new (class UnknownBoolean extends ExpressionEnti
|
|
|
5442
5449
|
if (path.length === 1) {
|
|
5443
5450
|
return getMemberReturnExpressionWhenCalled(literalBooleanMembers, path[0]);
|
|
5444
5451
|
}
|
|
5445
|
-
return
|
|
5452
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
5446
5453
|
}
|
|
5447
5454
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
5448
5455
|
if (interaction.type === INTERACTION_ACCESSED) {
|
|
@@ -5465,7 +5472,7 @@ const UNKNOWN_LITERAL_NUMBER = new (class UnknownNumber extends ExpressionEntity
|
|
|
5465
5472
|
if (path.length === 1) {
|
|
5466
5473
|
return getMemberReturnExpressionWhenCalled(literalNumberMembers, path[0]);
|
|
5467
5474
|
}
|
|
5468
|
-
return
|
|
5475
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
5469
5476
|
}
|
|
5470
5477
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
5471
5478
|
if (interaction.type === INTERACTION_ACCESSED) {
|
|
@@ -5488,7 +5495,7 @@ const UNKNOWN_LITERAL_STRING = new (class UnknownString extends ExpressionEntity
|
|
|
5488
5495
|
if (path.length === 1) {
|
|
5489
5496
|
return getMemberReturnExpressionWhenCalled(literalStringMembers, path[0]);
|
|
5490
5497
|
}
|
|
5491
|
-
return
|
|
5498
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
5492
5499
|
}
|
|
5493
5500
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
5494
5501
|
if (interaction.type === INTERACTION_ACCESSED) {
|
|
@@ -5609,8 +5616,8 @@ function hasMemberEffectWhenCalled(members, memberName, interaction, context) {
|
|
|
5609
5616
|
}
|
|
5610
5617
|
function getMemberReturnExpressionWhenCalled(members, memberName) {
|
|
5611
5618
|
if (typeof memberName !== 'string' || !members[memberName])
|
|
5612
|
-
return
|
|
5613
|
-
return members[memberName].returns;
|
|
5619
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
5620
|
+
return [members[memberName].returns, false];
|
|
5614
5621
|
}
|
|
5615
5622
|
|
|
5616
5623
|
// AST walker module for Mozilla Parser API compatible trees
|
|
@@ -6260,12 +6267,15 @@ class Method extends ExpressionEntity {
|
|
|
6260
6267
|
}
|
|
6261
6268
|
getReturnExpressionWhenCalledAtPath(path, { thisArg }) {
|
|
6262
6269
|
if (path.length > 0) {
|
|
6263
|
-
return
|
|
6270
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
6264
6271
|
}
|
|
6265
|
-
return
|
|
6266
|
-
|
|
6267
|
-
|
|
6268
|
-
|
|
6272
|
+
return [
|
|
6273
|
+
this.description.returnsPrimitive ||
|
|
6274
|
+
(this.description.returns === 'self'
|
|
6275
|
+
? thisArg || UNKNOWN_EXPRESSION
|
|
6276
|
+
: this.description.returns()),
|
|
6277
|
+
false
|
|
6278
|
+
];
|
|
6269
6279
|
}
|
|
6270
6280
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
6271
6281
|
const { type } = interaction;
|
|
@@ -6508,7 +6518,7 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
6508
6518
|
}
|
|
6509
6519
|
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
6510
6520
|
if (path.length === 0) {
|
|
6511
|
-
return
|
|
6521
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
6512
6522
|
}
|
|
6513
6523
|
const [key, ...subPath] = path;
|
|
6514
6524
|
const expressionAtPath = this.getMemberExpressionAndTrackDeopt(key, origin);
|
|
@@ -6518,7 +6528,7 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
6518
6528
|
if (this.prototypeExpression) {
|
|
6519
6529
|
return this.prototypeExpression.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
|
|
6520
6530
|
}
|
|
6521
|
-
return
|
|
6531
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
6522
6532
|
}
|
|
6523
6533
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
6524
6534
|
const [key, ...subPath] = path;
|
|
@@ -6990,12 +7000,12 @@ class LocalVariable extends Variable {
|
|
|
6990
7000
|
}
|
|
6991
7001
|
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
6992
7002
|
if (this.isReassigned || !this.init) {
|
|
6993
|
-
return
|
|
7003
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
6994
7004
|
}
|
|
6995
7005
|
return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
|
|
6996
7006
|
this.expressionsToBeDeoptimized.push(origin);
|
|
6997
7007
|
return this.init.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
|
|
6998
|
-
},
|
|
7008
|
+
}, UNKNOWN_RETURN_EXPRESSION);
|
|
6999
7009
|
}
|
|
7000
7010
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
7001
7011
|
switch (interaction.type) {
|
|
@@ -7352,6 +7362,19 @@ function is_reference (node, parent) {
|
|
|
7352
7362
|
return false;
|
|
7353
7363
|
}
|
|
7354
7364
|
|
|
7365
|
+
const PureFunctionKey = Symbol('PureFunction');
|
|
7366
|
+
const getPureFunctions = ({ treeshake }) => {
|
|
7367
|
+
const pureFunctions = Object.create(null);
|
|
7368
|
+
for (const functionName of treeshake ? treeshake.manualPureFunctions : []) {
|
|
7369
|
+
let currentFunctions = pureFunctions;
|
|
7370
|
+
for (const pathSegment of functionName.split('.')) {
|
|
7371
|
+
currentFunctions = currentFunctions[pathSegment] || (currentFunctions[pathSegment] = Object.create(null));
|
|
7372
|
+
}
|
|
7373
|
+
currentFunctions[PureFunctionKey] = true;
|
|
7374
|
+
}
|
|
7375
|
+
return pureFunctions;
|
|
7376
|
+
};
|
|
7377
|
+
|
|
7355
7378
|
/* eslint sort-keys: "off" */
|
|
7356
7379
|
const ValueProperties = Symbol('Value Properties');
|
|
7357
7380
|
const getTruthyLiteralValue = () => UnknownTruthyValue;
|
|
@@ -8329,7 +8352,8 @@ class Identifier extends NodeBase {
|
|
|
8329
8352
|
return this.getVariableRespectingTDZ().getLiteralValueAtPath(path, recursionTracker, origin);
|
|
8330
8353
|
}
|
|
8331
8354
|
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
8332
|
-
|
|
8355
|
+
const [expression, isPure] = this.getVariableRespectingTDZ().getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
|
|
8356
|
+
return [expression, isPure || this.isPureFunction(path)];
|
|
8333
8357
|
}
|
|
8334
8358
|
hasEffects(context) {
|
|
8335
8359
|
if (!this.deoptimized)
|
|
@@ -8339,19 +8363,22 @@ class Identifier extends NodeBase {
|
|
|
8339
8363
|
}
|
|
8340
8364
|
return (this.context.options.treeshake.unknownGlobalSideEffects &&
|
|
8341
8365
|
this.variable instanceof GlobalVariable &&
|
|
8366
|
+
!this.isPureFunction(EMPTY_PATH) &&
|
|
8342
8367
|
this.variable.hasEffectsOnInteractionAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_ACCESS, context));
|
|
8343
8368
|
}
|
|
8344
8369
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
8345
8370
|
switch (interaction.type) {
|
|
8346
8371
|
case INTERACTION_ACCESSED: {
|
|
8347
8372
|
return (this.variable !== null &&
|
|
8373
|
+
!this.isPureFunction(path) &&
|
|
8348
8374
|
this.getVariableRespectingTDZ().hasEffectsOnInteractionAtPath(path, interaction, context));
|
|
8349
8375
|
}
|
|
8350
8376
|
case INTERACTION_ASSIGNED: {
|
|
8351
8377
|
return (path.length > 0 ? this.getVariableRespectingTDZ() : this.variable).hasEffectsOnInteractionAtPath(path, interaction, context);
|
|
8352
8378
|
}
|
|
8353
8379
|
case INTERACTION_CALLED: {
|
|
8354
|
-
return this.
|
|
8380
|
+
return (!this.isPureFunction(path) &&
|
|
8381
|
+
this.getVariableRespectingTDZ().hasEffectsOnInteractionAtPath(path, interaction, context));
|
|
8355
8382
|
}
|
|
8356
8383
|
}
|
|
8357
8384
|
}
|
|
@@ -8433,6 +8460,21 @@ class Identifier extends NodeBase {
|
|
|
8433
8460
|
}
|
|
8434
8461
|
return this.variable;
|
|
8435
8462
|
}
|
|
8463
|
+
isPureFunction(path) {
|
|
8464
|
+
let currentPureFunction = this.context.manualPureFunctions[this.name];
|
|
8465
|
+
for (const segment of path) {
|
|
8466
|
+
if (currentPureFunction) {
|
|
8467
|
+
if (currentPureFunction[PureFunctionKey]) {
|
|
8468
|
+
return true;
|
|
8469
|
+
}
|
|
8470
|
+
currentPureFunction = currentPureFunction[segment];
|
|
8471
|
+
}
|
|
8472
|
+
else {
|
|
8473
|
+
return false;
|
|
8474
|
+
}
|
|
8475
|
+
}
|
|
8476
|
+
return currentPureFunction?.[PureFunctionKey];
|
|
8477
|
+
}
|
|
8436
8478
|
}
|
|
8437
8479
|
function closestParentFunctionOrProgram(node) {
|
|
8438
8480
|
while (node && !/^Program|Function/.test(node.type)) {
|
|
@@ -8754,9 +8796,9 @@ class FunctionBase extends NodeBase {
|
|
|
8754
8796
|
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
8755
8797
|
this.context.requestTreeshakingPass();
|
|
8756
8798
|
}
|
|
8757
|
-
return
|
|
8799
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
8758
8800
|
}
|
|
8759
|
-
return this.scope.getReturnExpression();
|
|
8801
|
+
return [this.scope.getReturnExpression(), false];
|
|
8760
8802
|
}
|
|
8761
8803
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
8762
8804
|
if (path.length > 0 || interaction.type !== INTERACTION_CALLED) {
|
|
@@ -9355,7 +9397,7 @@ class Literal extends NodeBase {
|
|
|
9355
9397
|
}
|
|
9356
9398
|
getReturnExpressionWhenCalledAtPath(path) {
|
|
9357
9399
|
if (path.length !== 1)
|
|
9358
|
-
return
|
|
9400
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
9359
9401
|
return getMemberReturnExpressionWhenCalled(this.members, path[0]);
|
|
9360
9402
|
}
|
|
9361
9403
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
@@ -9508,13 +9550,13 @@ class MemberExpression extends NodeBase {
|
|
|
9508
9550
|
return this.variable.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
|
|
9509
9551
|
}
|
|
9510
9552
|
if (this.isUndefined) {
|
|
9511
|
-
return UNDEFINED_EXPRESSION;
|
|
9553
|
+
return [UNDEFINED_EXPRESSION, false];
|
|
9512
9554
|
}
|
|
9513
9555
|
this.expressionsToBeDeoptimized.push(origin);
|
|
9514
9556
|
if (path.length < MAX_PATH_DEPTH) {
|
|
9515
9557
|
return this.object.getReturnExpressionWhenCalledAtPath([this.getPropertyKey(), ...path], interaction, recursionTracker, origin);
|
|
9516
9558
|
}
|
|
9517
|
-
return
|
|
9559
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
9518
9560
|
}
|
|
9519
9561
|
hasEffects(context) {
|
|
9520
9562
|
if (!this.deoptimized)
|
|
@@ -9691,8 +9733,8 @@ class CallExpressionBase extends NodeBase {
|
|
|
9691
9733
|
this.expressionsToBeDeoptimized = new Set();
|
|
9692
9734
|
}
|
|
9693
9735
|
deoptimizeCache() {
|
|
9694
|
-
if (this.returnExpression !== UNKNOWN_EXPRESSION) {
|
|
9695
|
-
this.returnExpression =
|
|
9736
|
+
if (this.returnExpression?.[0] !== UNKNOWN_EXPRESSION) {
|
|
9737
|
+
this.returnExpression = UNKNOWN_RETURN_EXPRESSION;
|
|
9696
9738
|
for (const expression of this.deoptimizableDependentExpressions) {
|
|
9697
9739
|
expression.deoptimizeCache();
|
|
9698
9740
|
}
|
|
@@ -9706,13 +9748,15 @@ class CallExpressionBase extends NodeBase {
|
|
|
9706
9748
|
this.context.deoptimizationTracker.trackEntityAtPathAndGetIfTracked(path, this)) {
|
|
9707
9749
|
return;
|
|
9708
9750
|
}
|
|
9709
|
-
const returnExpression = this.getReturnExpression();
|
|
9751
|
+
const [returnExpression] = this.getReturnExpression();
|
|
9710
9752
|
if (returnExpression !== UNKNOWN_EXPRESSION) {
|
|
9711
9753
|
returnExpression.deoptimizePath(path);
|
|
9712
9754
|
}
|
|
9713
9755
|
}
|
|
9714
9756
|
deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
9715
|
-
const returnExpression = this.getReturnExpression(recursionTracker);
|
|
9757
|
+
const [returnExpression, isPure] = this.getReturnExpression(recursionTracker);
|
|
9758
|
+
if (isPure)
|
|
9759
|
+
return;
|
|
9716
9760
|
if (returnExpression === UNKNOWN_EXPRESSION) {
|
|
9717
9761
|
interaction.thisArg.deoptimizePath(UNKNOWN_PATH);
|
|
9718
9762
|
}
|
|
@@ -9724,7 +9768,7 @@ class CallExpressionBase extends NodeBase {
|
|
|
9724
9768
|
}
|
|
9725
9769
|
}
|
|
9726
9770
|
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
9727
|
-
const returnExpression = this.getReturnExpression(recursionTracker);
|
|
9771
|
+
const [returnExpression] = this.getReturnExpression(recursionTracker);
|
|
9728
9772
|
if (returnExpression === UNKNOWN_EXPRESSION) {
|
|
9729
9773
|
return UnknownValue;
|
|
9730
9774
|
}
|
|
@@ -9735,13 +9779,14 @@ class CallExpressionBase extends NodeBase {
|
|
|
9735
9779
|
}
|
|
9736
9780
|
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
9737
9781
|
const returnExpression = this.getReturnExpression(recursionTracker);
|
|
9738
|
-
if (
|
|
9739
|
-
return
|
|
9782
|
+
if (returnExpression[0] === UNKNOWN_EXPRESSION) {
|
|
9783
|
+
return returnExpression;
|
|
9740
9784
|
}
|
|
9741
9785
|
return recursionTracker.withTrackedEntityAtPath(path, returnExpression, () => {
|
|
9742
9786
|
this.deoptimizableDependentExpressions.push(origin);
|
|
9743
|
-
|
|
9744
|
-
|
|
9787
|
+
const [expression, isPure] = returnExpression[0].getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
|
|
9788
|
+
return [expression, isPure || returnExpression[1]];
|
|
9789
|
+
}, UNKNOWN_RETURN_EXPRESSION);
|
|
9745
9790
|
}
|
|
9746
9791
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
9747
9792
|
const { type } = interaction;
|
|
@@ -9756,7 +9801,9 @@ class CallExpressionBase extends NodeBase {
|
|
|
9756
9801
|
: context.accessed).trackEntityAtPathAndGetIfTracked(path, this)) {
|
|
9757
9802
|
return false;
|
|
9758
9803
|
}
|
|
9759
|
-
|
|
9804
|
+
const [returnExpression, isPure] = this.getReturnExpression();
|
|
9805
|
+
return ((type === INTERACTION_ASSIGNED || !isPure) &&
|
|
9806
|
+
returnExpression.hasEffectsOnInteractionAtPath(path, interaction, context));
|
|
9760
9807
|
}
|
|
9761
9808
|
}
|
|
9762
9809
|
|
|
@@ -9835,7 +9882,7 @@ class CallExpression extends CallExpressionBase {
|
|
|
9835
9882
|
}
|
|
9836
9883
|
getReturnExpression(recursionTracker = SHARED_RECURSION_TRACKER) {
|
|
9837
9884
|
if (this.returnExpression === null) {
|
|
9838
|
-
this.returnExpression =
|
|
9885
|
+
this.returnExpression = UNKNOWN_RETURN_EXPRESSION;
|
|
9839
9886
|
return (this.returnExpression = this.callee.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.interaction, recursionTracker, this));
|
|
9840
9887
|
}
|
|
9841
9888
|
return this.returnExpression;
|
|
@@ -9919,7 +9966,7 @@ class MethodBase extends NodeBase {
|
|
|
9919
9966
|
// expressions, there is no known situation where a getter is deoptimized.
|
|
9920
9967
|
deoptimizeCache() { }
|
|
9921
9968
|
deoptimizePath(path) {
|
|
9922
|
-
this.getAccessedValue().deoptimizePath(path);
|
|
9969
|
+
this.getAccessedValue()[0].deoptimizePath(path);
|
|
9923
9970
|
}
|
|
9924
9971
|
deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
9925
9972
|
if (interaction.type === INTERACTION_ACCESSED && this.kind === 'get' && path.length === 0) {
|
|
@@ -9938,13 +9985,13 @@ class MethodBase extends NodeBase {
|
|
|
9938
9985
|
withNew: false
|
|
9939
9986
|
}, EMPTY_PATH, recursionTracker);
|
|
9940
9987
|
}
|
|
9941
|
-
this.getAccessedValue().deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
|
|
9988
|
+
this.getAccessedValue()[0].deoptimizeThisOnInteractionAtPath(interaction, path, recursionTracker);
|
|
9942
9989
|
}
|
|
9943
9990
|
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
9944
|
-
return this.getAccessedValue().getLiteralValueAtPath(path, recursionTracker, origin);
|
|
9991
|
+
return this.getAccessedValue()[0].getLiteralValueAtPath(path, recursionTracker, origin);
|
|
9945
9992
|
}
|
|
9946
9993
|
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
9947
|
-
return this.getAccessedValue().getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
|
|
9994
|
+
return this.getAccessedValue()[0].getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
|
|
9948
9995
|
}
|
|
9949
9996
|
hasEffects(context) {
|
|
9950
9997
|
return this.key.hasEffects(context);
|
|
@@ -9967,17 +10014,17 @@ class MethodBase extends NodeBase {
|
|
|
9967
10014
|
withNew: false
|
|
9968
10015
|
}, context);
|
|
9969
10016
|
}
|
|
9970
|
-
return this.getAccessedValue().hasEffectsOnInteractionAtPath(path, interaction, context);
|
|
10017
|
+
return this.getAccessedValue()[0].hasEffectsOnInteractionAtPath(path, interaction, context);
|
|
9971
10018
|
}
|
|
9972
10019
|
applyDeoptimizations() { }
|
|
9973
10020
|
getAccessedValue() {
|
|
9974
10021
|
if (this.accessedValue === null) {
|
|
9975
10022
|
if (this.kind === 'get') {
|
|
9976
|
-
this.accessedValue =
|
|
10023
|
+
this.accessedValue = UNKNOWN_RETURN_EXPRESSION;
|
|
9977
10024
|
return (this.accessedValue = this.value.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, NODE_INTERACTION_UNKNOWN_CALL, SHARED_RECURSION_TRACKER, this));
|
|
9978
10025
|
}
|
|
9979
10026
|
else {
|
|
9980
|
-
return (this.accessedValue = this.value);
|
|
10027
|
+
return (this.accessedValue = [this.value, false]);
|
|
9981
10028
|
}
|
|
9982
10029
|
}
|
|
9983
10030
|
return this.accessedValue;
|
|
@@ -10190,7 +10237,10 @@ class MultiExpression extends ExpressionEntity {
|
|
|
10190
10237
|
}
|
|
10191
10238
|
}
|
|
10192
10239
|
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
10193
|
-
return
|
|
10240
|
+
return [
|
|
10241
|
+
new MultiExpression(this.expressions.map(expression => expression.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0])),
|
|
10242
|
+
false
|
|
10243
|
+
];
|
|
10194
10244
|
}
|
|
10195
10245
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
10196
10246
|
for (const expression of this.expressions) {
|
|
@@ -10242,10 +10292,13 @@ class ConditionalExpression extends NodeBase {
|
|
|
10242
10292
|
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
10243
10293
|
const usedBranch = this.getUsedBranch();
|
|
10244
10294
|
if (!usedBranch)
|
|
10245
|
-
return
|
|
10246
|
-
|
|
10247
|
-
|
|
10248
|
-
|
|
10295
|
+
return [
|
|
10296
|
+
new MultiExpression([
|
|
10297
|
+
this.consequent.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0],
|
|
10298
|
+
this.alternate.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0]
|
|
10299
|
+
]),
|
|
10300
|
+
false
|
|
10301
|
+
];
|
|
10249
10302
|
this.expressionsToBeDeoptimized.push(origin);
|
|
10250
10303
|
return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
|
|
10251
10304
|
}
|
|
@@ -11370,10 +11423,13 @@ class LogicalExpression extends NodeBase {
|
|
|
11370
11423
|
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
11371
11424
|
const usedBranch = this.getUsedBranch();
|
|
11372
11425
|
if (!usedBranch)
|
|
11373
|
-
return
|
|
11374
|
-
|
|
11375
|
-
|
|
11376
|
-
|
|
11426
|
+
return [
|
|
11427
|
+
new MultiExpression([
|
|
11428
|
+
this.left.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0],
|
|
11429
|
+
this.right.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)[0]
|
|
11430
|
+
]),
|
|
11431
|
+
false
|
|
11432
|
+
];
|
|
11377
11433
|
this.expressionsToBeDeoptimized.push(origin);
|
|
11378
11434
|
return usedBranch.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
|
|
11379
11435
|
}
|
|
@@ -11799,7 +11855,7 @@ class PropertyDefinition extends NodeBase {
|
|
|
11799
11855
|
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
11800
11856
|
return this.value
|
|
11801
11857
|
? this.value.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)
|
|
11802
|
-
:
|
|
11858
|
+
: UNKNOWN_RETURN_EXPRESSION;
|
|
11803
11859
|
}
|
|
11804
11860
|
hasEffects(context) {
|
|
11805
11861
|
return this.key.hasEffects(context) || (this.static && !!this.value?.hasEffects(context));
|
|
@@ -12090,7 +12146,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
|
|
|
12090
12146
|
this.quasi.include(context, includeChildrenRecursively);
|
|
12091
12147
|
}
|
|
12092
12148
|
this.tag.includeCallArguments(context, this.interaction.args);
|
|
12093
|
-
const returnExpression = this.getReturnExpression();
|
|
12149
|
+
const [returnExpression] = this.getReturnExpression();
|
|
12094
12150
|
if (!returnExpression.included) {
|
|
12095
12151
|
returnExpression.include(context, false);
|
|
12096
12152
|
}
|
|
@@ -12120,7 +12176,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
|
|
|
12120
12176
|
}
|
|
12121
12177
|
getReturnExpression(recursionTracker = SHARED_RECURSION_TRACKER) {
|
|
12122
12178
|
if (this.returnExpression === null) {
|
|
12123
|
-
this.returnExpression =
|
|
12179
|
+
this.returnExpression = UNKNOWN_RETURN_EXPRESSION;
|
|
12124
12180
|
return (this.returnExpression = this.tag.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, this.interaction, recursionTracker, this));
|
|
12125
12181
|
}
|
|
12126
12182
|
return this.returnExpression;
|
|
@@ -12153,7 +12209,7 @@ class TemplateLiteral extends NodeBase {
|
|
|
12153
12209
|
}
|
|
12154
12210
|
getReturnExpressionWhenCalledAtPath(path) {
|
|
12155
12211
|
if (path.length !== 1) {
|
|
12156
|
-
return
|
|
12212
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
12157
12213
|
}
|
|
12158
12214
|
return getMemberReturnExpressionWhenCalled(literalStringMembers, path[0]);
|
|
12159
12215
|
}
|
|
@@ -13667,6 +13723,7 @@ class Module {
|
|
|
13667
13723
|
includeDynamicImport: this.includeDynamicImport.bind(this),
|
|
13668
13724
|
includeVariableInModule: this.includeVariableInModule.bind(this),
|
|
13669
13725
|
magicString: this.magicString,
|
|
13726
|
+
manualPureFunctions: this.graph.pureFunctions,
|
|
13670
13727
|
module: this,
|
|
13671
13728
|
moduleContext: this.context,
|
|
13672
13729
|
options: this.options,
|
|
@@ -23988,6 +24045,7 @@ class Graph {
|
|
|
23988
24045
|
this.acornParser = Parser.extend(...options.acornInjectPlugins);
|
|
23989
24046
|
this.moduleLoader = new ModuleLoader(this, this.modulesById, this.options, this.pluginDriver);
|
|
23990
24047
|
this.fileOperationQueue = new Queue(options.maxParallelFileOps);
|
|
24048
|
+
this.pureFunctions = getPureFunctions(options);
|
|
23991
24049
|
}
|
|
23992
24050
|
async build() {
|
|
23993
24051
|
timeStart('generate module graph', 2);
|
|
@@ -24605,6 +24663,7 @@ const getTreeshake = (config) => {
|
|
|
24605
24663
|
return {
|
|
24606
24664
|
annotations: configWithPreset.annotations !== false,
|
|
24607
24665
|
correctVarValueBeforeDeclaration: configWithPreset.correctVarValueBeforeDeclaration === true,
|
|
24666
|
+
manualPureFunctions: configWithPreset.manualPureFunctions ?? EMPTY_ARRAY,
|
|
24608
24667
|
moduleSideEffects: getHasModuleSideEffects(configWithPreset.moduleSideEffects),
|
|
24609
24668
|
propertyReadSideEffects: configWithPreset.propertyReadSideEffects === 'always'
|
|
24610
24669
|
? 'always'
|
package/dist/shared/watch-cli.js
CHANGED
package/dist/shared/watch.js
CHANGED