rollup 4.3.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +223 -109
- package/dist/es/shared/parseAst.js +24 -6
- 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.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 +27 -5
- package/dist/shared/rollup.js +222 -108
- 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 +28 -27
package/dist/shared/rollup.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v4.
|
|
4
|
-
|
|
3
|
+
Rollup.js v4.4.0
|
|
4
|
+
Sun, 12 Nov 2023 07:49:26 GMT - commit 53d636051ac60da9b302c4bd6b7eaaccb4871f4b
|
|
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 = "4.
|
|
34
|
+
var version = "4.4.0";
|
|
35
35
|
|
|
36
36
|
function ensureArray$1(items) {
|
|
37
37
|
if (Array.isArray(items)) {
|
|
@@ -1169,6 +1169,7 @@ async function mergeOptions(config, watchMode, rawCommandOptions = EMPTY_COMMAND
|
|
|
1169
1169
|
'environment',
|
|
1170
1170
|
'failAfterWarnings',
|
|
1171
1171
|
'filterLogs',
|
|
1172
|
+
'forceExit',
|
|
1172
1173
|
'plugin',
|
|
1173
1174
|
'silent',
|
|
1174
1175
|
'stdin',
|
|
@@ -3374,12 +3375,18 @@ class Variable extends ExpressionEntity {
|
|
|
3374
3375
|
(this.forbiddenNames ||= new Set()).add(name);
|
|
3375
3376
|
}
|
|
3376
3377
|
getBaseVariableName() {
|
|
3377
|
-
return this.
|
|
3378
|
+
return (this.renderedLikeHoisted?.getBaseVariableName() ||
|
|
3379
|
+
this.renderBaseName ||
|
|
3380
|
+
this.renderName ||
|
|
3381
|
+
this.name);
|
|
3378
3382
|
}
|
|
3379
3383
|
getName(getPropertyAccess, useOriginalName) {
|
|
3380
3384
|
if (useOriginalName?.(this)) {
|
|
3381
3385
|
return this.name;
|
|
3382
3386
|
}
|
|
3387
|
+
if (this.renderedLikeHoisted) {
|
|
3388
|
+
return this.renderedLikeHoisted.getName(getPropertyAccess, useOriginalName);
|
|
3389
|
+
}
|
|
3383
3390
|
const name = this.renderName || this.name;
|
|
3384
3391
|
return this.renderBaseName ? `${this.renderBaseName}${getPropertyAccess(name)}` : name;
|
|
3385
3392
|
}
|
|
@@ -3394,6 +3401,14 @@ class Variable extends ExpressionEntity {
|
|
|
3394
3401
|
*/
|
|
3395
3402
|
include() {
|
|
3396
3403
|
this.included = true;
|
|
3404
|
+
this.renderedLikeHoisted?.include();
|
|
3405
|
+
}
|
|
3406
|
+
/**
|
|
3407
|
+
* Links the rendered name of this variable to another variable and includes
|
|
3408
|
+
* this variable if the other variable is included.
|
|
3409
|
+
*/
|
|
3410
|
+
renderLikeHoisted(variable) {
|
|
3411
|
+
this.renderedLikeHoisted = variable;
|
|
3397
3412
|
}
|
|
3398
3413
|
markCalledFromTryStatement() { }
|
|
3399
3414
|
setRenderNames(baseName, name) {
|
|
@@ -3419,10 +3434,8 @@ class ExternalVariable extends Variable {
|
|
|
3419
3434
|
return type !== INTERACTION_ACCESSED || path.length > (this.isNamespace ? 1 : 0);
|
|
3420
3435
|
}
|
|
3421
3436
|
include() {
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
this.module.used = true;
|
|
3425
|
-
}
|
|
3437
|
+
super.include();
|
|
3438
|
+
this.module.used = true;
|
|
3426
3439
|
}
|
|
3427
3440
|
}
|
|
3428
3441
|
|
|
@@ -6943,6 +6956,7 @@ class ArrayPattern extends NodeBase {
|
|
|
6943
6956
|
const ArrowFunctionExpression$1 = 'ArrowFunctionExpression';
|
|
6944
6957
|
const BlockStatement$1 = 'BlockStatement';
|
|
6945
6958
|
const CallExpression$1 = 'CallExpression';
|
|
6959
|
+
const CatchClause$1 = 'CatchClause';
|
|
6946
6960
|
const ExpressionStatement$1 = 'ExpressionStatement';
|
|
6947
6961
|
const Identifier$1 = 'Identifier';
|
|
6948
6962
|
const Program$1 = 'Program';
|
|
@@ -6950,7 +6964,7 @@ const Property$1 = 'Property';
|
|
|
6950
6964
|
const ReturnStatement$1 = 'ReturnStatement';
|
|
6951
6965
|
|
|
6952
6966
|
class LocalVariable extends Variable {
|
|
6953
|
-
constructor(name, declarator, init, context) {
|
|
6967
|
+
constructor(name, declarator, init, context, kind) {
|
|
6954
6968
|
super(name);
|
|
6955
6969
|
this.init = init;
|
|
6956
6970
|
this.calledFromTryStatement = false;
|
|
@@ -6959,6 +6973,7 @@ class LocalVariable extends Variable {
|
|
|
6959
6973
|
this.declarations = declarator ? [declarator] : [];
|
|
6960
6974
|
this.deoptimizationTracker = context.deoptimizationTracker;
|
|
6961
6975
|
this.module = context.module;
|
|
6976
|
+
this.kind = kind;
|
|
6962
6977
|
}
|
|
6963
6978
|
addDeclaration(identifier, init) {
|
|
6964
6979
|
this.declarations.push(identifier);
|
|
@@ -6985,15 +7000,13 @@ class LocalVariable extends Variable {
|
|
|
6985
7000
|
return;
|
|
6986
7001
|
}
|
|
6987
7002
|
if (path.length === 0) {
|
|
6988
|
-
|
|
6989
|
-
|
|
6990
|
-
|
|
6991
|
-
|
|
6992
|
-
|
|
6993
|
-
expression.deoptimizeCache();
|
|
6994
|
-
}
|
|
6995
|
-
this.init.deoptimizePath(UNKNOWN_PATH);
|
|
7003
|
+
this.isReassigned = true;
|
|
7004
|
+
const expressionsToBeDeoptimized = this.expressionsToBeDeoptimized;
|
|
7005
|
+
this.expressionsToBeDeoptimized = EMPTY_ARRAY;
|
|
7006
|
+
for (const expression of expressionsToBeDeoptimized) {
|
|
7007
|
+
expression.deoptimizeCache();
|
|
6996
7008
|
}
|
|
7009
|
+
this.init.deoptimizePath(UNKNOWN_PATH);
|
|
6997
7010
|
}
|
|
6998
7011
|
else {
|
|
6999
7012
|
this.init.deoptimizePath(path);
|
|
@@ -7045,7 +7058,7 @@ class LocalVariable extends Variable {
|
|
|
7045
7058
|
}
|
|
7046
7059
|
include() {
|
|
7047
7060
|
if (!this.included) {
|
|
7048
|
-
|
|
7061
|
+
super.include();
|
|
7049
7062
|
for (const declaration of this.declarations) {
|
|
7050
7063
|
// If node is a default export, it can save a tree-shaking run to include the full declaration now
|
|
7051
7064
|
if (!declaration.included)
|
|
@@ -7085,19 +7098,6 @@ class LocalVariable extends Variable {
|
|
|
7085
7098
|
}
|
|
7086
7099
|
return this.additionalInitializers;
|
|
7087
7100
|
}
|
|
7088
|
-
mergeDeclarations(variable) {
|
|
7089
|
-
const { declarations } = this;
|
|
7090
|
-
for (const declaration of variable.declarations) {
|
|
7091
|
-
declarations.push(declaration);
|
|
7092
|
-
}
|
|
7093
|
-
const additionalInitializers = this.markInitializersForDeoptimization();
|
|
7094
|
-
additionalInitializers.push(variable.init);
|
|
7095
|
-
if (variable.additionalInitializers) {
|
|
7096
|
-
for (const initializer of variable.additionalInitializers) {
|
|
7097
|
-
additionalInitializers.push(initializer);
|
|
7098
|
-
}
|
|
7099
|
-
}
|
|
7100
|
-
}
|
|
7101
7101
|
}
|
|
7102
7102
|
|
|
7103
7103
|
const MAX_TRACKED_INTERACTIONS = 20;
|
|
@@ -7107,7 +7107,7 @@ const EMPTY_PATH_TRACKER = new PathTracker();
|
|
|
7107
7107
|
const UNKNOWN_DEOPTIMIZED_ENTITY = new Set([UNKNOWN_EXPRESSION]);
|
|
7108
7108
|
class ParameterVariable extends LocalVariable {
|
|
7109
7109
|
constructor(name, declarator, context) {
|
|
7110
|
-
super(name, declarator, UNKNOWN_EXPRESSION, context);
|
|
7110
|
+
super(name, declarator, UNKNOWN_EXPRESSION, context, "parameter" /* VariableKind.parameter */);
|
|
7111
7111
|
this.deoptimizationInteractions = [];
|
|
7112
7112
|
this.deoptimizations = new PathTracker();
|
|
7113
7113
|
this.deoptimizedFields = new Set();
|
|
@@ -7215,22 +7215,42 @@ class Scope {
|
|
|
7215
7215
|
this.children = [];
|
|
7216
7216
|
this.variables = new Map();
|
|
7217
7217
|
}
|
|
7218
|
-
|
|
7218
|
+
/*
|
|
7219
|
+
Redeclaration rules:
|
|
7220
|
+
- var can redeclare var
|
|
7221
|
+
- var is hoisted across scopes, function remains in the scope it is declared
|
|
7222
|
+
- var and function can redeclare function parameters, but parameters cannot redeclare parameters
|
|
7223
|
+
- function cannot redeclare catch scope parameters
|
|
7224
|
+
- var can redeclare catch scope parameters in a way
|
|
7225
|
+
- if the parameter is an identifier and not a pattern
|
|
7226
|
+
- then the variable is still declared in the hoisted outer scope, but the initializer is assigned to the parameter
|
|
7227
|
+
- const, let, class, and function except in the cases above cannot redeclare anything
|
|
7228
|
+
*/
|
|
7229
|
+
addDeclaration(identifier, context, init, kind) {
|
|
7219
7230
|
const name = identifier.name;
|
|
7220
|
-
|
|
7221
|
-
if (
|
|
7222
|
-
|
|
7223
|
-
|
|
7224
|
-
|
|
7225
|
-
|
|
7226
|
-
|
|
7231
|
+
const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
|
|
7232
|
+
if (existingVariable) {
|
|
7233
|
+
const existingKind = existingVariable.kind;
|
|
7234
|
+
if ((kind === "var" /* VariableKind.var */ &&
|
|
7235
|
+
(existingKind === "var" /* VariableKind.var */ || existingKind === "parameter" /* VariableKind.parameter */)) ||
|
|
7236
|
+
(kind === "function" /* VariableKind.function */ && existingKind === "parameter" /* VariableKind.parameter */)) {
|
|
7237
|
+
existingVariable.addDeclaration(identifier, init);
|
|
7238
|
+
return existingVariable;
|
|
7239
|
+
}
|
|
7240
|
+
context.error(parseAst_js.logRedeclarationError(name), identifier.start);
|
|
7227
7241
|
}
|
|
7228
|
-
|
|
7242
|
+
const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
|
|
7243
|
+
this.variables.set(name, newVariable);
|
|
7244
|
+
return newVariable;
|
|
7245
|
+
}
|
|
7246
|
+
addHoistedVariable(name, variable) {
|
|
7247
|
+
(this.hoistedVariables ||= new Map()).set(name, variable);
|
|
7229
7248
|
}
|
|
7230
7249
|
contains(name) {
|
|
7231
7250
|
return this.variables.has(name);
|
|
7232
7251
|
}
|
|
7233
7252
|
findVariable(_name) {
|
|
7253
|
+
/* istanbul ignore next */
|
|
7234
7254
|
throw new Error('Internal Error: findVariable needs to be implemented by a subclass');
|
|
7235
7255
|
}
|
|
7236
7256
|
}
|
|
@@ -7238,9 +7258,9 @@ class Scope {
|
|
|
7238
7258
|
class ChildScope extends Scope {
|
|
7239
7259
|
constructor(parent, context) {
|
|
7240
7260
|
super();
|
|
7241
|
-
this.accessedOutsideVariables = new Map();
|
|
7242
7261
|
this.parent = parent;
|
|
7243
7262
|
this.context = context;
|
|
7263
|
+
this.accessedOutsideVariables = new Map();
|
|
7244
7264
|
parent.children.push(this);
|
|
7245
7265
|
}
|
|
7246
7266
|
addAccessedDynamicImport(importExpression) {
|
|
@@ -7318,26 +7338,89 @@ class ChildScope extends Scope {
|
|
|
7318
7338
|
}
|
|
7319
7339
|
}
|
|
7320
7340
|
|
|
7321
|
-
class
|
|
7341
|
+
class CatchBodyScope extends ChildScope {
|
|
7322
7342
|
constructor(parent, context) {
|
|
7343
|
+
super(parent, context);
|
|
7344
|
+
this.parent = parent;
|
|
7345
|
+
this.context = context;
|
|
7346
|
+
}
|
|
7347
|
+
addDeclaration(identifier, context, init, kind) {
|
|
7348
|
+
if (kind === "var" /* VariableKind.var */) {
|
|
7349
|
+
const name = identifier.name;
|
|
7350
|
+
const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
|
|
7351
|
+
if (existingVariable) {
|
|
7352
|
+
const existingKind = existingVariable.kind;
|
|
7353
|
+
if (existingKind === "parameter" /* VariableKind.parameter */ &&
|
|
7354
|
+
// If this is a destructured parameter, it is forbidden to redeclare
|
|
7355
|
+
existingVariable.declarations[0].parent.type === CatchClause$1) {
|
|
7356
|
+
// If this is a var with the same name as the catch scope parameter,
|
|
7357
|
+
// the assignment actually goes to the parameter and the var is
|
|
7358
|
+
// hoisted without assignment. Locally, it is shadowed by the
|
|
7359
|
+
// parameter
|
|
7360
|
+
const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, kind);
|
|
7361
|
+
// To avoid the need to rewrite the declaration, we link the variable
|
|
7362
|
+
// names. If we ever implement a logic that splits initialization and
|
|
7363
|
+
// assignment for hoisted vars, the "renderLikeHoisted" logic can be
|
|
7364
|
+
// removed again.
|
|
7365
|
+
// We do not need to check whether there already is a linked
|
|
7366
|
+
// variable because then declaredVariable would be that linked
|
|
7367
|
+
// variable.
|
|
7368
|
+
existingVariable.renderLikeHoisted(declaredVariable);
|
|
7369
|
+
this.addHoistedVariable(name, declaredVariable);
|
|
7370
|
+
return declaredVariable;
|
|
7371
|
+
}
|
|
7372
|
+
if (existingKind === "var" /* VariableKind.var */) {
|
|
7373
|
+
existingVariable.addDeclaration(identifier, init);
|
|
7374
|
+
return existingVariable;
|
|
7375
|
+
}
|
|
7376
|
+
return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
|
|
7377
|
+
}
|
|
7378
|
+
// We only add parameters to parameter scopes
|
|
7379
|
+
const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, kind);
|
|
7380
|
+
// Necessary to make sure the init is deoptimized for conditional declarations.
|
|
7381
|
+
// We cannot call deoptimizePath here.
|
|
7382
|
+
declaredVariable.markInitializersForDeoptimization();
|
|
7383
|
+
// We add the variable to this and all parent scopes to reliably detect conflicts
|
|
7384
|
+
this.addHoistedVariable(name, declaredVariable);
|
|
7385
|
+
return declaredVariable;
|
|
7386
|
+
}
|
|
7387
|
+
// Functions can never re-declare catch parameters
|
|
7388
|
+
if (kind === "function" /* VariableKind.function */) {
|
|
7389
|
+
const name = identifier.name;
|
|
7390
|
+
if (this.hoistedVariables?.get(name)) {
|
|
7391
|
+
context.error(parseAst_js.logRedeclarationError(name), identifier.start);
|
|
7392
|
+
}
|
|
7393
|
+
}
|
|
7394
|
+
return super.addDeclaration(identifier, context, init, kind);
|
|
7395
|
+
}
|
|
7396
|
+
}
|
|
7397
|
+
|
|
7398
|
+
class ParameterScope extends ChildScope {
|
|
7399
|
+
constructor(parent, context, isCatchScope) {
|
|
7323
7400
|
super(parent, context);
|
|
7324
7401
|
this.parameters = [];
|
|
7325
7402
|
this.hasRest = false;
|
|
7326
|
-
this.
|
|
7403
|
+
this.bodyScope = isCatchScope
|
|
7404
|
+
? new CatchBodyScope(this, context)
|
|
7405
|
+
: new ChildScope(this, context);
|
|
7327
7406
|
}
|
|
7328
7407
|
/**
|
|
7329
7408
|
* Adds a parameter to this scope. Parameters must be added in the correct
|
|
7330
7409
|
* order, i.e. from left to right.
|
|
7331
7410
|
*/
|
|
7332
7411
|
addParameterDeclaration(identifier) {
|
|
7333
|
-
const { name } = identifier;
|
|
7334
|
-
const
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
this.hoistedBodyVarScope.variables.set(name, variable);
|
|
7338
|
-
variable.mergeDeclarations(localVariable);
|
|
7412
|
+
const { name, start } = identifier;
|
|
7413
|
+
const existingParameter = this.variables.get(name);
|
|
7414
|
+
if (existingParameter) {
|
|
7415
|
+
return this.context.error(parseAst_js.logDuplicateArgumentNameError(name), start);
|
|
7339
7416
|
}
|
|
7417
|
+
const variable = new ParameterVariable(name, identifier, this.context);
|
|
7340
7418
|
this.variables.set(name, variable);
|
|
7419
|
+
// We also add it to the body scope to detect name conflicts with local
|
|
7420
|
+
// variables. We still need the intermediate scope, though, as parameter
|
|
7421
|
+
// defaults are NOT taken from the body scope but from the parameters or
|
|
7422
|
+
// outside scope.
|
|
7423
|
+
this.bodyScope.addHoistedVariable(name, variable);
|
|
7341
7424
|
return variable;
|
|
7342
7425
|
}
|
|
7343
7426
|
addParameterVariables(parameters, hasRest) {
|
|
@@ -8521,26 +8604,26 @@ class Identifier extends NodeBase {
|
|
|
8521
8604
|
let variable;
|
|
8522
8605
|
const { treeshake } = this.scope.context.options;
|
|
8523
8606
|
switch (kind) {
|
|
8524
|
-
case
|
|
8525
|
-
variable = this.scope.addDeclaration(this, this.scope.context, init,
|
|
8607
|
+
case "var" /* VariableKind.var */: {
|
|
8608
|
+
variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
|
|
8526
8609
|
if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
|
|
8527
8610
|
// Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
|
|
8528
8611
|
variable.markInitializersForDeoptimization();
|
|
8529
8612
|
}
|
|
8530
8613
|
break;
|
|
8531
8614
|
}
|
|
8532
|
-
case
|
|
8615
|
+
case "function" /* VariableKind.function */: {
|
|
8533
8616
|
// in strict mode, functions are only hoisted within a scope but not across block scopes
|
|
8534
|
-
variable = this.scope.addDeclaration(this, this.scope.context, init,
|
|
8617
|
+
variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
|
|
8535
8618
|
break;
|
|
8536
8619
|
}
|
|
8537
|
-
case
|
|
8538
|
-
case
|
|
8539
|
-
case
|
|
8540
|
-
variable = this.scope.addDeclaration(this, this.scope.context, init,
|
|
8620
|
+
case "let" /* VariableKind.let */:
|
|
8621
|
+
case "const" /* VariableKind.const */:
|
|
8622
|
+
case "class" /* VariableKind.class */: {
|
|
8623
|
+
variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
|
|
8541
8624
|
break;
|
|
8542
8625
|
}
|
|
8543
|
-
case
|
|
8626
|
+
case "parameter" /* VariableKind.parameter */: {
|
|
8544
8627
|
variable = this.scope.addParameterDeclaration(this);
|
|
8545
8628
|
break;
|
|
8546
8629
|
}
|
|
@@ -8550,13 +8633,15 @@ class Identifier extends NodeBase {
|
|
|
8550
8633
|
throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
|
|
8551
8634
|
}
|
|
8552
8635
|
}
|
|
8553
|
-
variable.kind = kind;
|
|
8554
8636
|
return [(this.variable = variable)];
|
|
8555
8637
|
}
|
|
8556
8638
|
deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
8557
8639
|
this.variable.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
|
|
8558
8640
|
}
|
|
8559
8641
|
deoptimizePath(path) {
|
|
8642
|
+
if (path.length === 0 && !this.scope.contains(this.name)) {
|
|
8643
|
+
this.disallowImportReassignment();
|
|
8644
|
+
}
|
|
8560
8645
|
// We keep conditional chaining because an unknown Node could have an
|
|
8561
8646
|
// Identifier as property that might be deoptimized by default
|
|
8562
8647
|
this.variable?.deoptimizePath(path);
|
|
@@ -8571,7 +8656,7 @@ class Identifier extends NodeBase {
|
|
|
8571
8656
|
hasEffects(context) {
|
|
8572
8657
|
if (!this.deoptimized)
|
|
8573
8658
|
this.applyDeoptimizations();
|
|
8574
|
-
if (this.isPossibleTDZ() && this.variable.kind !==
|
|
8659
|
+
if (this.isPossibleTDZ() && this.variable.kind !== "var" /* VariableKind.var */) {
|
|
8575
8660
|
return true;
|
|
8576
8661
|
}
|
|
8577
8662
|
return (this.scope.context.options.treeshake
|
|
@@ -8662,6 +8747,9 @@ class Identifier extends NodeBase {
|
|
|
8662
8747
|
}
|
|
8663
8748
|
}
|
|
8664
8749
|
}
|
|
8750
|
+
disallowImportReassignment() {
|
|
8751
|
+
return this.scope.context.error(parseAst_js.logIllegalImportReassignment(this.name, this.scope.context.module.id), this.start);
|
|
8752
|
+
}
|
|
8665
8753
|
applyDeoptimizations() {
|
|
8666
8754
|
this.deoptimized = true;
|
|
8667
8755
|
if (this.variable instanceof LocalVariable) {
|
|
@@ -8837,17 +8925,26 @@ function removeLineBreaks(code, start, end) {
|
|
|
8837
8925
|
}
|
|
8838
8926
|
|
|
8839
8927
|
class BlockScope extends ChildScope {
|
|
8840
|
-
addDeclaration(identifier, context, init,
|
|
8841
|
-
if (
|
|
8842
|
-
const
|
|
8928
|
+
addDeclaration(identifier, context, init, kind) {
|
|
8929
|
+
if (kind === "var" /* VariableKind.var */) {
|
|
8930
|
+
const name = identifier.name;
|
|
8931
|
+
const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
|
|
8932
|
+
if (existingVariable) {
|
|
8933
|
+
if (existingVariable.kind === "var" /* VariableKind.var */) {
|
|
8934
|
+
existingVariable.addDeclaration(identifier, init);
|
|
8935
|
+
return existingVariable;
|
|
8936
|
+
}
|
|
8937
|
+
return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
|
|
8938
|
+
}
|
|
8939
|
+
const declaredVariable = this.parent.addDeclaration(identifier, context, init, kind);
|
|
8843
8940
|
// Necessary to make sure the init is deoptimized for conditional declarations.
|
|
8844
8941
|
// We cannot call deoptimizePath here.
|
|
8845
|
-
|
|
8846
|
-
|
|
8847
|
-
|
|
8848
|
-
|
|
8849
|
-
return super.addDeclaration(identifier, context, init, false);
|
|
8942
|
+
declaredVariable.markInitializersForDeoptimization();
|
|
8943
|
+
// We add the variable to this and all parent scopes to reliably detect conflicts
|
|
8944
|
+
this.addHoistedVariable(name, declaredVariable);
|
|
8945
|
+
return declaredVariable;
|
|
8850
8946
|
}
|
|
8947
|
+
return super.addDeclaration(identifier, context, init, kind);
|
|
8851
8948
|
}
|
|
8852
8949
|
}
|
|
8853
8950
|
|
|
@@ -9085,7 +9182,6 @@ class FunctionBase extends NodeBase {
|
|
|
9085
9182
|
this.scope.includeCallArguments(context, parameters);
|
|
9086
9183
|
}
|
|
9087
9184
|
initialise() {
|
|
9088
|
-
this.scope.addParameterVariables(this.params.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), this.params[this.params.length - 1] instanceof RestElement);
|
|
9089
9185
|
if (this.body instanceof BlockStatement) {
|
|
9090
9186
|
this.body.addImplicitReturnExpressionToScope();
|
|
9091
9187
|
}
|
|
@@ -9094,9 +9190,18 @@ class FunctionBase extends NodeBase {
|
|
|
9094
9190
|
}
|
|
9095
9191
|
}
|
|
9096
9192
|
parseNode(esTreeNode) {
|
|
9097
|
-
|
|
9098
|
-
|
|
9099
|
-
}
|
|
9193
|
+
const { body, params } = esTreeNode;
|
|
9194
|
+
const parameters = (this.params = []);
|
|
9195
|
+
const { scope } = this;
|
|
9196
|
+
const { bodyScope, context } = scope;
|
|
9197
|
+
// We need to ensure that parameters are declared before the body is parsed
|
|
9198
|
+
// so that the scope already knows all parameters and can detect conflicts
|
|
9199
|
+
// when parsing the body.
|
|
9200
|
+
for (const parameter of params) {
|
|
9201
|
+
parameters.push(new (context.getNodeConstructor(parameter.type))(parameter, this, scope, false));
|
|
9202
|
+
}
|
|
9203
|
+
scope.addParameterVariables(parameters.map(parameter => parameter.declare("parameter" /* VariableKind.parameter */, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
|
|
9204
|
+
this.body = new (context.getNodeConstructor(body.type))(body, this, bodyScope);
|
|
9100
9205
|
super.parseNode(esTreeNode);
|
|
9101
9206
|
}
|
|
9102
9207
|
addArgumentToBeDeoptimized(_argument) { }
|
|
@@ -9110,7 +9215,7 @@ class ArrowFunctionExpression extends FunctionBase {
|
|
|
9110
9215
|
this.objectEntity = null;
|
|
9111
9216
|
}
|
|
9112
9217
|
createScope(parentScope) {
|
|
9113
|
-
this.scope = new ReturnValueScope(parentScope, this.scope.context);
|
|
9218
|
+
this.scope = new ReturnValueScope(parentScope, this.scope.context, false);
|
|
9114
9219
|
}
|
|
9115
9220
|
hasEffects() {
|
|
9116
9221
|
if (!this.deoptimized)
|
|
@@ -9354,7 +9459,7 @@ class AssignmentPattern extends NodeBase {
|
|
|
9354
9459
|
|
|
9355
9460
|
class ArgumentsVariable extends LocalVariable {
|
|
9356
9461
|
constructor(context) {
|
|
9357
|
-
super('arguments', null, UNKNOWN_EXPRESSION, context);
|
|
9462
|
+
super('arguments', null, UNKNOWN_EXPRESSION, context, "other" /* VariableKind.other */);
|
|
9358
9463
|
this.deoptimizedArguments = [];
|
|
9359
9464
|
}
|
|
9360
9465
|
addArgumentToBeDeoptimized(argument) {
|
|
@@ -9388,7 +9493,7 @@ class ThisVariable extends ParameterVariable {
|
|
|
9388
9493
|
|
|
9389
9494
|
class FunctionScope extends ReturnValueScope {
|
|
9390
9495
|
constructor(parent, context) {
|
|
9391
|
-
super(parent, context);
|
|
9496
|
+
super(parent, context, false);
|
|
9392
9497
|
this.variables.set('arguments', (this.argumentsVariable = new ArgumentsVariable(context)));
|
|
9393
9498
|
this.variables.set('this', (this.thisVariable = new ThisVariable(context)));
|
|
9394
9499
|
}
|
|
@@ -9476,7 +9581,7 @@ class FunctionNode extends FunctionBase {
|
|
|
9476
9581
|
}
|
|
9477
9582
|
initialise() {
|
|
9478
9583
|
super.initialise();
|
|
9479
|
-
this.id?.declare(
|
|
9584
|
+
this.id?.declare("function" /* VariableKind.function */, this);
|
|
9480
9585
|
}
|
|
9481
9586
|
addArgumentToBeDeoptimized(argument) {
|
|
9482
9587
|
this.scope.argumentsVariable.addArgumentToBeDeoptimized(argument);
|
|
@@ -10201,37 +10306,22 @@ class CallExpression extends CallExpressionBase {
|
|
|
10201
10306
|
}
|
|
10202
10307
|
}
|
|
10203
10308
|
|
|
10204
|
-
class CatchScope extends ParameterScope {
|
|
10205
|
-
addDeclaration(identifier, context, init, isHoisted) {
|
|
10206
|
-
const existingParameter = this.variables.get(identifier.name);
|
|
10207
|
-
if (existingParameter) {
|
|
10208
|
-
// While we still create a hoisted declaration, the initializer goes to
|
|
10209
|
-
// the parameter. Note that technically, the declaration now belongs to
|
|
10210
|
-
// two variables, which is not correct but should not cause issues.
|
|
10211
|
-
this.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, isHoisted);
|
|
10212
|
-
existingParameter.addDeclaration(identifier, init);
|
|
10213
|
-
return existingParameter;
|
|
10214
|
-
}
|
|
10215
|
-
return this.parent.addDeclaration(identifier, context, init, isHoisted);
|
|
10216
|
-
}
|
|
10217
|
-
}
|
|
10218
|
-
|
|
10219
10309
|
class CatchClause extends NodeBase {
|
|
10220
10310
|
createScope(parentScope) {
|
|
10221
|
-
this.scope = new
|
|
10311
|
+
this.scope = new ParameterScope(parentScope, this.scope.context, true);
|
|
10222
10312
|
}
|
|
10223
10313
|
parseNode(esTreeNode) {
|
|
10224
|
-
|
|
10225
|
-
|
|
10226
|
-
// name instead of the variable
|
|
10227
|
-
const { param } = esTreeNode;
|
|
10314
|
+
const { body, param, type } = esTreeNode;
|
|
10315
|
+
this.type = type;
|
|
10228
10316
|
if (param) {
|
|
10229
10317
|
this.param = new (this.scope.context.getNodeConstructor(param.type))(param, this, this.scope);
|
|
10230
|
-
this.param.declare(
|
|
10318
|
+
this.param.declare("parameter" /* VariableKind.parameter */, UNKNOWN_EXPRESSION);
|
|
10231
10319
|
}
|
|
10320
|
+
this.body = new BlockStatement(body, this, this.scope.bodyScope);
|
|
10232
10321
|
super.parseNode(esTreeNode);
|
|
10233
10322
|
}
|
|
10234
10323
|
}
|
|
10324
|
+
CatchClause.prototype.preventChildBlockScope = true;
|
|
10235
10325
|
|
|
10236
10326
|
class ChainExpression extends NodeBase {
|
|
10237
10327
|
// deoptimizations are not relevant as we are not caching values
|
|
@@ -10254,7 +10344,7 @@ class ChainExpression extends NodeBase {
|
|
|
10254
10344
|
class ClassBodyScope extends ChildScope {
|
|
10255
10345
|
constructor(parent, classNode, context) {
|
|
10256
10346
|
super(parent, context);
|
|
10257
|
-
this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, context)));
|
|
10347
|
+
this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, context, "other" /* VariableKind.other */)));
|
|
10258
10348
|
this.instanceScope = new ChildScope(this, context);
|
|
10259
10349
|
this.instanceScope.variables.set('this', new ThisVariable(context));
|
|
10260
10350
|
}
|
|
@@ -10438,7 +10528,7 @@ class ClassNode extends NodeBase {
|
|
|
10438
10528
|
}
|
|
10439
10529
|
}
|
|
10440
10530
|
initialise() {
|
|
10441
|
-
this.id?.declare(
|
|
10531
|
+
this.id?.declare("class" /* VariableKind.class */, this);
|
|
10442
10532
|
for (const method of this.body.body) {
|
|
10443
10533
|
if (method instanceof MethodDefinition && method.kind === 'constructor') {
|
|
10444
10534
|
this.classConstructor = method;
|
|
@@ -11078,9 +11168,9 @@ class TrackingScope extends BlockScope {
|
|
|
11078
11168
|
super(...arguments);
|
|
11079
11169
|
this.hoistedDeclarations = [];
|
|
11080
11170
|
}
|
|
11081
|
-
addDeclaration(identifier, context, init,
|
|
11171
|
+
addDeclaration(identifier, context, init, kind) {
|
|
11082
11172
|
this.hoistedDeclarations.push(identifier);
|
|
11083
|
-
return super.addDeclaration(identifier, context, init,
|
|
11173
|
+
return super.addDeclaration(identifier, context, init, kind);
|
|
11084
11174
|
}
|
|
11085
11175
|
}
|
|
11086
11176
|
|
|
@@ -12806,7 +12896,7 @@ class UndefinedVariable extends Variable {
|
|
|
12806
12896
|
|
|
12807
12897
|
class ExportDefaultVariable extends LocalVariable {
|
|
12808
12898
|
constructor(name, exportDefaultDeclaration, context) {
|
|
12809
|
-
super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context);
|
|
12899
|
+
super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context, "other" /* VariableKind.other */);
|
|
12810
12900
|
this.hasId = false;
|
|
12811
12901
|
this.originalId = null;
|
|
12812
12902
|
this.originalVariable = null;
|
|
@@ -12877,7 +12967,13 @@ class ExportDefaultVariable extends LocalVariable {
|
|
|
12877
12967
|
class ModuleScope extends ChildScope {
|
|
12878
12968
|
constructor(parent, context) {
|
|
12879
12969
|
super(parent, context);
|
|
12880
|
-
this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, context));
|
|
12970
|
+
this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, context, "other" /* VariableKind.other */));
|
|
12971
|
+
}
|
|
12972
|
+
addDeclaration(identifier, context, init, kind) {
|
|
12973
|
+
if (this.context.module.importDescriptions.has(identifier.name)) {
|
|
12974
|
+
context.error(parseAst_js.logRedeclarationError(identifier.name), identifier.start);
|
|
12975
|
+
}
|
|
12976
|
+
return super.addDeclaration(identifier, context, init, kind);
|
|
12881
12977
|
}
|
|
12882
12978
|
addExportDefaultDeclaration(name, exportDefaultDeclaration, context) {
|
|
12883
12979
|
const variable = new ExportDefaultVariable(name, exportDefaultDeclaration, context);
|
|
@@ -13474,7 +13570,7 @@ class NamespaceVariable extends Variable {
|
|
|
13474
13570
|
memberVariable.hasEffectsOnInteractionAtPath(path.slice(1), interaction, context));
|
|
13475
13571
|
}
|
|
13476
13572
|
include() {
|
|
13477
|
-
|
|
13573
|
+
super.include();
|
|
13478
13574
|
this.context.includeAllExports();
|
|
13479
13575
|
}
|
|
13480
13576
|
prepare(accessedGlobalsByScope) {
|
|
@@ -13568,7 +13664,7 @@ class SyntheticNamedExportVariable extends Variable {
|
|
|
13568
13664
|
return `${this.syntheticNamespace.getName(getPropertyAccess)}${getPropertyAccess(this.name)}`;
|
|
13569
13665
|
}
|
|
13570
13666
|
include() {
|
|
13571
|
-
|
|
13667
|
+
super.include();
|
|
13572
13668
|
this.context.includeVariableInModule(this.syntheticNamespace);
|
|
13573
13669
|
}
|
|
13574
13670
|
setRenderNames(baseName, name) {
|
|
@@ -14170,7 +14266,7 @@ class Module {
|
|
|
14170
14266
|
const removedExports = [];
|
|
14171
14267
|
for (const exportName of this.exports.keys()) {
|
|
14172
14268
|
const [variable] = this.getVariableForExportName(exportName);
|
|
14173
|
-
(variable
|
|
14269
|
+
(variable?.included ? renderedExports : removedExports).push(exportName);
|
|
14174
14270
|
}
|
|
14175
14271
|
return { removedExports, renderedExports };
|
|
14176
14272
|
}
|
|
@@ -14267,6 +14363,9 @@ class Module {
|
|
|
14267
14363
|
for (const exportName of this.exports.keys()) {
|
|
14268
14364
|
if (includeNamespaceMembers || exportName !== this.info.syntheticNamedExports) {
|
|
14269
14365
|
const variable = this.getVariableForExportName(exportName)[0];
|
|
14366
|
+
if (!variable) {
|
|
14367
|
+
return parseAst_js.error(parseAst_js.logMissingEntryExport(exportName, this.id));
|
|
14368
|
+
}
|
|
14270
14369
|
variable.deoptimizePath(UNKNOWN_PATH);
|
|
14271
14370
|
if (!variable.included) {
|
|
14272
14371
|
this.includeVariable(variable);
|
|
@@ -14504,9 +14603,15 @@ class Module {
|
|
|
14504
14603
|
}
|
|
14505
14604
|
this.dynamicImports.push({ argument, id: null, node, resolution: null });
|
|
14506
14605
|
}
|
|
14606
|
+
assertUniqueExportName(name, nodeStart) {
|
|
14607
|
+
if (this.exports.has(name) || this.reexportDescriptions.has(name)) {
|
|
14608
|
+
this.error(parseAst_js.logDuplicateExportError(name), nodeStart);
|
|
14609
|
+
}
|
|
14610
|
+
}
|
|
14507
14611
|
addExport(node) {
|
|
14508
14612
|
if (node instanceof ExportDefaultDeclaration) {
|
|
14509
14613
|
// export default foo;
|
|
14614
|
+
this.assertUniqueExportName('default', node.start);
|
|
14510
14615
|
this.exports.set('default', {
|
|
14511
14616
|
identifier: node.variable.getAssignedVariableName(),
|
|
14512
14617
|
localName: 'default'
|
|
@@ -14518,6 +14623,7 @@ class Module {
|
|
|
14518
14623
|
if (node.exported) {
|
|
14519
14624
|
// export * as name from './other'
|
|
14520
14625
|
const name = node.exported.name;
|
|
14626
|
+
this.assertUniqueExportName(name, node.exported.start);
|
|
14521
14627
|
this.reexportDescriptions.set(name, {
|
|
14522
14628
|
localName: '*',
|
|
14523
14629
|
module: null,
|
|
@@ -14536,6 +14642,7 @@ class Module {
|
|
|
14536
14642
|
this.addSource(source, node);
|
|
14537
14643
|
for (const { exported, local, start } of node.specifiers) {
|
|
14538
14644
|
const name = exported instanceof Literal ? exported.value : exported.name;
|
|
14645
|
+
this.assertUniqueExportName(name, start);
|
|
14539
14646
|
this.reexportDescriptions.set(name, {
|
|
14540
14647
|
localName: local instanceof Literal ? local.value : local.name,
|
|
14541
14648
|
module: null,
|
|
@@ -14551,6 +14658,7 @@ class Module {
|
|
|
14551
14658
|
// export var foo = 1, bar = 2;
|
|
14552
14659
|
for (const declarator of declaration.declarations) {
|
|
14553
14660
|
for (const localName of extractAssignedNames(declarator.id)) {
|
|
14661
|
+
this.assertUniqueExportName(localName, declarator.id.start);
|
|
14554
14662
|
this.exports.set(localName, { identifier: null, localName });
|
|
14555
14663
|
}
|
|
14556
14664
|
}
|
|
@@ -14558,6 +14666,7 @@ class Module {
|
|
|
14558
14666
|
else {
|
|
14559
14667
|
// export function foo () {}
|
|
14560
14668
|
const localName = declaration.id.name;
|
|
14669
|
+
this.assertUniqueExportName(localName, declaration.id.start);
|
|
14561
14670
|
this.exports.set(localName, { identifier: null, localName });
|
|
14562
14671
|
}
|
|
14563
14672
|
}
|
|
@@ -14567,6 +14676,7 @@ class Module {
|
|
|
14567
14676
|
// except for reexports, local must be an Identifier
|
|
14568
14677
|
const localName = local.name;
|
|
14569
14678
|
const exportedName = exported instanceof Identifier ? exported.name : exported.value;
|
|
14679
|
+
this.assertUniqueExportName(exportedName, exported.start);
|
|
14570
14680
|
this.exports.set(exportedName, { identifier: null, localName });
|
|
14571
14681
|
}
|
|
14572
14682
|
}
|
|
@@ -14575,6 +14685,10 @@ class Module {
|
|
|
14575
14685
|
const source = node.source.value;
|
|
14576
14686
|
this.addSource(source, node);
|
|
14577
14687
|
for (const specifier of node.specifiers) {
|
|
14688
|
+
const localName = specifier.local.name;
|
|
14689
|
+
if (this.scope.variables.has(localName) || this.importDescriptions.has(localName)) {
|
|
14690
|
+
this.error(parseAst_js.logRedeclarationError(localName), specifier.local.start);
|
|
14691
|
+
}
|
|
14578
14692
|
const name = specifier instanceof ImportDefaultSpecifier
|
|
14579
14693
|
? 'default'
|
|
14580
14694
|
: specifier instanceof ImportNamespaceSpecifier
|
|
@@ -14582,7 +14696,7 @@ class Module {
|
|
|
14582
14696
|
: specifier.imported instanceof Identifier
|
|
14583
14697
|
? specifier.imported.name
|
|
14584
14698
|
: specifier.imported.value;
|
|
14585
|
-
this.importDescriptions.set(
|
|
14699
|
+
this.importDescriptions.set(localName, {
|
|
14586
14700
|
module: null,
|
|
14587
14701
|
name,
|
|
14588
14702
|
source,
|