rollup 4.3.1 → 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.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v4.3.1
4
- Sat, 11 Nov 2023 07:57:25 GMT - commit 52c55bb1e17154ae6d01fb40e0e4a3589bc20a8f
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.3.1";
34
+ var version = "4.4.0";
35
35
 
36
36
  function ensureArray$1(items) {
37
37
  if (Array.isArray(items)) {
@@ -3375,12 +3375,18 @@ class Variable extends ExpressionEntity {
3375
3375
  (this.forbiddenNames ||= new Set()).add(name);
3376
3376
  }
3377
3377
  getBaseVariableName() {
3378
- return this.renderBaseName || this.renderName || this.name;
3378
+ return (this.renderedLikeHoisted?.getBaseVariableName() ||
3379
+ this.renderBaseName ||
3380
+ this.renderName ||
3381
+ this.name);
3379
3382
  }
3380
3383
  getName(getPropertyAccess, useOriginalName) {
3381
3384
  if (useOriginalName?.(this)) {
3382
3385
  return this.name;
3383
3386
  }
3387
+ if (this.renderedLikeHoisted) {
3388
+ return this.renderedLikeHoisted.getName(getPropertyAccess, useOriginalName);
3389
+ }
3384
3390
  const name = this.renderName || this.name;
3385
3391
  return this.renderBaseName ? `${this.renderBaseName}${getPropertyAccess(name)}` : name;
3386
3392
  }
@@ -3395,6 +3401,14 @@ class Variable extends ExpressionEntity {
3395
3401
  */
3396
3402
  include() {
3397
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;
3398
3412
  }
3399
3413
  markCalledFromTryStatement() { }
3400
3414
  setRenderNames(baseName, name) {
@@ -3420,10 +3434,8 @@ class ExternalVariable extends Variable {
3420
3434
  return type !== INTERACTION_ACCESSED || path.length > (this.isNamespace ? 1 : 0);
3421
3435
  }
3422
3436
  include() {
3423
- if (!this.included) {
3424
- this.included = true;
3425
- this.module.used = true;
3426
- }
3437
+ super.include();
3438
+ this.module.used = true;
3427
3439
  }
3428
3440
  }
3429
3441
 
@@ -6944,6 +6956,7 @@ class ArrayPattern extends NodeBase {
6944
6956
  const ArrowFunctionExpression$1 = 'ArrowFunctionExpression';
6945
6957
  const BlockStatement$1 = 'BlockStatement';
6946
6958
  const CallExpression$1 = 'CallExpression';
6959
+ const CatchClause$1 = 'CatchClause';
6947
6960
  const ExpressionStatement$1 = 'ExpressionStatement';
6948
6961
  const Identifier$1 = 'Identifier';
6949
6962
  const Program$1 = 'Program';
@@ -6951,7 +6964,7 @@ const Property$1 = 'Property';
6951
6964
  const ReturnStatement$1 = 'ReturnStatement';
6952
6965
 
6953
6966
  class LocalVariable extends Variable {
6954
- constructor(name, declarator, init, context) {
6967
+ constructor(name, declarator, init, context, kind) {
6955
6968
  super(name);
6956
6969
  this.init = init;
6957
6970
  this.calledFromTryStatement = false;
@@ -6960,6 +6973,7 @@ class LocalVariable extends Variable {
6960
6973
  this.declarations = declarator ? [declarator] : [];
6961
6974
  this.deoptimizationTracker = context.deoptimizationTracker;
6962
6975
  this.module = context.module;
6976
+ this.kind = kind;
6963
6977
  }
6964
6978
  addDeclaration(identifier, init) {
6965
6979
  this.declarations.push(identifier);
@@ -6986,15 +7000,13 @@ class LocalVariable extends Variable {
6986
7000
  return;
6987
7001
  }
6988
7002
  if (path.length === 0) {
6989
- if (!this.isReassigned) {
6990
- this.isReassigned = true;
6991
- const expressionsToBeDeoptimized = this.expressionsToBeDeoptimized;
6992
- this.expressionsToBeDeoptimized = EMPTY_ARRAY;
6993
- for (const expression of expressionsToBeDeoptimized) {
6994
- expression.deoptimizeCache();
6995
- }
6996
- 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();
6997
7008
  }
7009
+ this.init.deoptimizePath(UNKNOWN_PATH);
6998
7010
  }
6999
7011
  else {
7000
7012
  this.init.deoptimizePath(path);
@@ -7046,7 +7058,7 @@ class LocalVariable extends Variable {
7046
7058
  }
7047
7059
  include() {
7048
7060
  if (!this.included) {
7049
- this.included = true;
7061
+ super.include();
7050
7062
  for (const declaration of this.declarations) {
7051
7063
  // If node is a default export, it can save a tree-shaking run to include the full declaration now
7052
7064
  if (!declaration.included)
@@ -7086,19 +7098,6 @@ class LocalVariable extends Variable {
7086
7098
  }
7087
7099
  return this.additionalInitializers;
7088
7100
  }
7089
- mergeDeclarations(variable) {
7090
- const { declarations } = this;
7091
- for (const declaration of variable.declarations) {
7092
- declarations.push(declaration);
7093
- }
7094
- const additionalInitializers = this.markInitializersForDeoptimization();
7095
- additionalInitializers.push(variable.init);
7096
- if (variable.additionalInitializers) {
7097
- for (const initializer of variable.additionalInitializers) {
7098
- additionalInitializers.push(initializer);
7099
- }
7100
- }
7101
- }
7102
7101
  }
7103
7102
 
7104
7103
  const MAX_TRACKED_INTERACTIONS = 20;
@@ -7108,7 +7107,7 @@ const EMPTY_PATH_TRACKER = new PathTracker();
7108
7107
  const UNKNOWN_DEOPTIMIZED_ENTITY = new Set([UNKNOWN_EXPRESSION]);
7109
7108
  class ParameterVariable extends LocalVariable {
7110
7109
  constructor(name, declarator, context) {
7111
- super(name, declarator, UNKNOWN_EXPRESSION, context);
7110
+ super(name, declarator, UNKNOWN_EXPRESSION, context, "parameter" /* VariableKind.parameter */);
7112
7111
  this.deoptimizationInteractions = [];
7113
7112
  this.deoptimizations = new PathTracker();
7114
7113
  this.deoptimizedFields = new Set();
@@ -7216,22 +7215,42 @@ class Scope {
7216
7215
  this.children = [];
7217
7216
  this.variables = new Map();
7218
7217
  }
7219
- addDeclaration(identifier, context, init, _isHoisted) {
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) {
7220
7230
  const name = identifier.name;
7221
- let variable = this.variables.get(name);
7222
- if (variable) {
7223
- variable.addDeclaration(identifier, init);
7224
- }
7225
- else {
7226
- variable = new LocalVariable(identifier.name, identifier, init || UNDEFINED_EXPRESSION, context);
7227
- this.variables.set(name, variable);
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);
7228
7241
  }
7229
- return variable;
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);
7230
7248
  }
7231
7249
  contains(name) {
7232
7250
  return this.variables.has(name);
7233
7251
  }
7234
7252
  findVariable(_name) {
7253
+ /* istanbul ignore next */
7235
7254
  throw new Error('Internal Error: findVariable needs to be implemented by a subclass');
7236
7255
  }
7237
7256
  }
@@ -7239,9 +7258,9 @@ class Scope {
7239
7258
  class ChildScope extends Scope {
7240
7259
  constructor(parent, context) {
7241
7260
  super();
7242
- this.accessedOutsideVariables = new Map();
7243
7261
  this.parent = parent;
7244
7262
  this.context = context;
7263
+ this.accessedOutsideVariables = new Map();
7245
7264
  parent.children.push(this);
7246
7265
  }
7247
7266
  addAccessedDynamicImport(importExpression) {
@@ -7319,26 +7338,89 @@ class ChildScope extends Scope {
7319
7338
  }
7320
7339
  }
7321
7340
 
7322
- class ParameterScope extends ChildScope {
7341
+ class CatchBodyScope extends ChildScope {
7323
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) {
7324
7400
  super(parent, context);
7325
7401
  this.parameters = [];
7326
7402
  this.hasRest = false;
7327
- this.hoistedBodyVarScope = new ChildScope(this, context);
7403
+ this.bodyScope = isCatchScope
7404
+ ? new CatchBodyScope(this, context)
7405
+ : new ChildScope(this, context);
7328
7406
  }
7329
7407
  /**
7330
7408
  * Adds a parameter to this scope. Parameters must be added in the correct
7331
7409
  * order, i.e. from left to right.
7332
7410
  */
7333
7411
  addParameterDeclaration(identifier) {
7334
- const { name } = identifier;
7335
- const variable = new ParameterVariable(name, identifier, this.context);
7336
- const localVariable = this.hoistedBodyVarScope.variables.get(name);
7337
- if (localVariable) {
7338
- this.hoistedBodyVarScope.variables.set(name, variable);
7339
- 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);
7340
7416
  }
7417
+ const variable = new ParameterVariable(name, identifier, this.context);
7341
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);
7342
7424
  return variable;
7343
7425
  }
7344
7426
  addParameterVariables(parameters, hasRest) {
@@ -8522,26 +8604,26 @@ class Identifier extends NodeBase {
8522
8604
  let variable;
8523
8605
  const { treeshake } = this.scope.context.options;
8524
8606
  switch (kind) {
8525
- case 'var': {
8526
- variable = this.scope.addDeclaration(this, this.scope.context, init, true);
8607
+ case "var" /* VariableKind.var */: {
8608
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
8527
8609
  if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
8528
8610
  // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
8529
8611
  variable.markInitializersForDeoptimization();
8530
8612
  }
8531
8613
  break;
8532
8614
  }
8533
- case 'function': {
8615
+ case "function" /* VariableKind.function */: {
8534
8616
  // in strict mode, functions are only hoisted within a scope but not across block scopes
8535
- variable = this.scope.addDeclaration(this, this.scope.context, init, false);
8617
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
8536
8618
  break;
8537
8619
  }
8538
- case 'let':
8539
- case 'const':
8540
- case 'class': {
8541
- variable = this.scope.addDeclaration(this, this.scope.context, init, false);
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);
8542
8624
  break;
8543
8625
  }
8544
- case 'parameter': {
8626
+ case "parameter" /* VariableKind.parameter */: {
8545
8627
  variable = this.scope.addParameterDeclaration(this);
8546
8628
  break;
8547
8629
  }
@@ -8551,13 +8633,15 @@ class Identifier extends NodeBase {
8551
8633
  throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
8552
8634
  }
8553
8635
  }
8554
- variable.kind = kind;
8555
8636
  return [(this.variable = variable)];
8556
8637
  }
8557
8638
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
8558
8639
  this.variable.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
8559
8640
  }
8560
8641
  deoptimizePath(path) {
8642
+ if (path.length === 0 && !this.scope.contains(this.name)) {
8643
+ this.disallowImportReassignment();
8644
+ }
8561
8645
  // We keep conditional chaining because an unknown Node could have an
8562
8646
  // Identifier as property that might be deoptimized by default
8563
8647
  this.variable?.deoptimizePath(path);
@@ -8572,7 +8656,7 @@ class Identifier extends NodeBase {
8572
8656
  hasEffects(context) {
8573
8657
  if (!this.deoptimized)
8574
8658
  this.applyDeoptimizations();
8575
- if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
8659
+ if (this.isPossibleTDZ() && this.variable.kind !== "var" /* VariableKind.var */) {
8576
8660
  return true;
8577
8661
  }
8578
8662
  return (this.scope.context.options.treeshake
@@ -8663,6 +8747,9 @@ class Identifier extends NodeBase {
8663
8747
  }
8664
8748
  }
8665
8749
  }
8750
+ disallowImportReassignment() {
8751
+ return this.scope.context.error(parseAst_js.logIllegalImportReassignment(this.name, this.scope.context.module.id), this.start);
8752
+ }
8666
8753
  applyDeoptimizations() {
8667
8754
  this.deoptimized = true;
8668
8755
  if (this.variable instanceof LocalVariable) {
@@ -8838,17 +8925,26 @@ function removeLineBreaks(code, start, end) {
8838
8925
  }
8839
8926
 
8840
8927
  class BlockScope extends ChildScope {
8841
- addDeclaration(identifier, context, init, isHoisted) {
8842
- if (isHoisted) {
8843
- const variable = this.parent.addDeclaration(identifier, context, init, isHoisted);
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);
8844
8940
  // Necessary to make sure the init is deoptimized for conditional declarations.
8845
8941
  // We cannot call deoptimizePath here.
8846
- variable.markInitializersForDeoptimization();
8847
- return variable;
8848
- }
8849
- else {
8850
- 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;
8851
8946
  }
8947
+ return super.addDeclaration(identifier, context, init, kind);
8852
8948
  }
8853
8949
  }
8854
8950
 
@@ -9086,7 +9182,6 @@ class FunctionBase extends NodeBase {
9086
9182
  this.scope.includeCallArguments(context, parameters);
9087
9183
  }
9088
9184
  initialise() {
9089
- this.scope.addParameterVariables(this.params.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), this.params[this.params.length - 1] instanceof RestElement);
9090
9185
  if (this.body instanceof BlockStatement) {
9091
9186
  this.body.addImplicitReturnExpressionToScope();
9092
9187
  }
@@ -9095,9 +9190,18 @@ class FunctionBase extends NodeBase {
9095
9190
  }
9096
9191
  }
9097
9192
  parseNode(esTreeNode) {
9098
- if (esTreeNode.body.type === BlockStatement$1) {
9099
- this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
9100
- }
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);
9101
9205
  super.parseNode(esTreeNode);
9102
9206
  }
9103
9207
  addArgumentToBeDeoptimized(_argument) { }
@@ -9111,7 +9215,7 @@ class ArrowFunctionExpression extends FunctionBase {
9111
9215
  this.objectEntity = null;
9112
9216
  }
9113
9217
  createScope(parentScope) {
9114
- this.scope = new ReturnValueScope(parentScope, this.scope.context);
9218
+ this.scope = new ReturnValueScope(parentScope, this.scope.context, false);
9115
9219
  }
9116
9220
  hasEffects() {
9117
9221
  if (!this.deoptimized)
@@ -9355,7 +9459,7 @@ class AssignmentPattern extends NodeBase {
9355
9459
 
9356
9460
  class ArgumentsVariable extends LocalVariable {
9357
9461
  constructor(context) {
9358
- super('arguments', null, UNKNOWN_EXPRESSION, context);
9462
+ super('arguments', null, UNKNOWN_EXPRESSION, context, "other" /* VariableKind.other */);
9359
9463
  this.deoptimizedArguments = [];
9360
9464
  }
9361
9465
  addArgumentToBeDeoptimized(argument) {
@@ -9389,7 +9493,7 @@ class ThisVariable extends ParameterVariable {
9389
9493
 
9390
9494
  class FunctionScope extends ReturnValueScope {
9391
9495
  constructor(parent, context) {
9392
- super(parent, context);
9496
+ super(parent, context, false);
9393
9497
  this.variables.set('arguments', (this.argumentsVariable = new ArgumentsVariable(context)));
9394
9498
  this.variables.set('this', (this.thisVariable = new ThisVariable(context)));
9395
9499
  }
@@ -9477,7 +9581,7 @@ class FunctionNode extends FunctionBase {
9477
9581
  }
9478
9582
  initialise() {
9479
9583
  super.initialise();
9480
- this.id?.declare('function', this);
9584
+ this.id?.declare("function" /* VariableKind.function */, this);
9481
9585
  }
9482
9586
  addArgumentToBeDeoptimized(argument) {
9483
9587
  this.scope.argumentsVariable.addArgumentToBeDeoptimized(argument);
@@ -10202,37 +10306,22 @@ class CallExpression extends CallExpressionBase {
10202
10306
  }
10203
10307
  }
10204
10308
 
10205
- class CatchScope extends ParameterScope {
10206
- addDeclaration(identifier, context, init, isHoisted) {
10207
- const existingParameter = this.variables.get(identifier.name);
10208
- if (existingParameter) {
10209
- // While we still create a hoisted declaration, the initializer goes to
10210
- // the parameter. Note that technically, the declaration now belongs to
10211
- // two variables, which is not correct but should not cause issues.
10212
- this.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, isHoisted);
10213
- existingParameter.addDeclaration(identifier, init);
10214
- return existingParameter;
10215
- }
10216
- return this.parent.addDeclaration(identifier, context, init, isHoisted);
10217
- }
10218
- }
10219
-
10220
10309
  class CatchClause extends NodeBase {
10221
10310
  createScope(parentScope) {
10222
- this.scope = new CatchScope(parentScope, this.scope.context);
10311
+ this.scope = new ParameterScope(parentScope, this.scope.context, true);
10223
10312
  }
10224
10313
  parseNode(esTreeNode) {
10225
- // Parameters need to be declared first as the logic is that initializers
10226
- // of hoisted body variables are associated with parameters of the same
10227
- // name instead of the variable
10228
- const { param } = esTreeNode;
10314
+ const { body, param, type } = esTreeNode;
10315
+ this.type = type;
10229
10316
  if (param) {
10230
10317
  this.param = new (this.scope.context.getNodeConstructor(param.type))(param, this, this.scope);
10231
- this.param.declare('parameter', UNKNOWN_EXPRESSION);
10318
+ this.param.declare("parameter" /* VariableKind.parameter */, UNKNOWN_EXPRESSION);
10232
10319
  }
10320
+ this.body = new BlockStatement(body, this, this.scope.bodyScope);
10233
10321
  super.parseNode(esTreeNode);
10234
10322
  }
10235
10323
  }
10324
+ CatchClause.prototype.preventChildBlockScope = true;
10236
10325
 
10237
10326
  class ChainExpression extends NodeBase {
10238
10327
  // deoptimizations are not relevant as we are not caching values
@@ -10255,7 +10344,7 @@ class ChainExpression extends NodeBase {
10255
10344
  class ClassBodyScope extends ChildScope {
10256
10345
  constructor(parent, classNode, context) {
10257
10346
  super(parent, context);
10258
- 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 */)));
10259
10348
  this.instanceScope = new ChildScope(this, context);
10260
10349
  this.instanceScope.variables.set('this', new ThisVariable(context));
10261
10350
  }
@@ -10439,7 +10528,7 @@ class ClassNode extends NodeBase {
10439
10528
  }
10440
10529
  }
10441
10530
  initialise() {
10442
- this.id?.declare('class', this);
10531
+ this.id?.declare("class" /* VariableKind.class */, this);
10443
10532
  for (const method of this.body.body) {
10444
10533
  if (method instanceof MethodDefinition && method.kind === 'constructor') {
10445
10534
  this.classConstructor = method;
@@ -11079,9 +11168,9 @@ class TrackingScope extends BlockScope {
11079
11168
  super(...arguments);
11080
11169
  this.hoistedDeclarations = [];
11081
11170
  }
11082
- addDeclaration(identifier, context, init, isHoisted) {
11171
+ addDeclaration(identifier, context, init, kind) {
11083
11172
  this.hoistedDeclarations.push(identifier);
11084
- return super.addDeclaration(identifier, context, init, isHoisted);
11173
+ return super.addDeclaration(identifier, context, init, kind);
11085
11174
  }
11086
11175
  }
11087
11176
 
@@ -12807,7 +12896,7 @@ class UndefinedVariable extends Variable {
12807
12896
 
12808
12897
  class ExportDefaultVariable extends LocalVariable {
12809
12898
  constructor(name, exportDefaultDeclaration, context) {
12810
- super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context);
12899
+ super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context, "other" /* VariableKind.other */);
12811
12900
  this.hasId = false;
12812
12901
  this.originalId = null;
12813
12902
  this.originalVariable = null;
@@ -12878,7 +12967,13 @@ class ExportDefaultVariable extends LocalVariable {
12878
12967
  class ModuleScope extends ChildScope {
12879
12968
  constructor(parent, context) {
12880
12969
  super(parent, context);
12881
- 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);
12882
12977
  }
12883
12978
  addExportDefaultDeclaration(name, exportDefaultDeclaration, context) {
12884
12979
  const variable = new ExportDefaultVariable(name, exportDefaultDeclaration, context);
@@ -13475,7 +13570,7 @@ class NamespaceVariable extends Variable {
13475
13570
  memberVariable.hasEffectsOnInteractionAtPath(path.slice(1), interaction, context));
13476
13571
  }
13477
13572
  include() {
13478
- this.included = true;
13573
+ super.include();
13479
13574
  this.context.includeAllExports();
13480
13575
  }
13481
13576
  prepare(accessedGlobalsByScope) {
@@ -13569,7 +13664,7 @@ class SyntheticNamedExportVariable extends Variable {
13569
13664
  return `${this.syntheticNamespace.getName(getPropertyAccess)}${getPropertyAccess(this.name)}`;
13570
13665
  }
13571
13666
  include() {
13572
- this.included = true;
13667
+ super.include();
13573
13668
  this.context.includeVariableInModule(this.syntheticNamespace);
13574
13669
  }
13575
13670
  setRenderNames(baseName, name) {
@@ -14171,7 +14266,7 @@ class Module {
14171
14266
  const removedExports = [];
14172
14267
  for (const exportName of this.exports.keys()) {
14173
14268
  const [variable] = this.getVariableForExportName(exportName);
14174
- (variable && variable.included ? renderedExports : removedExports).push(exportName);
14269
+ (variable?.included ? renderedExports : removedExports).push(exportName);
14175
14270
  }
14176
14271
  return { removedExports, renderedExports };
14177
14272
  }
@@ -14268,6 +14363,9 @@ class Module {
14268
14363
  for (const exportName of this.exports.keys()) {
14269
14364
  if (includeNamespaceMembers || exportName !== this.info.syntheticNamedExports) {
14270
14365
  const variable = this.getVariableForExportName(exportName)[0];
14366
+ if (!variable) {
14367
+ return parseAst_js.error(parseAst_js.logMissingEntryExport(exportName, this.id));
14368
+ }
14271
14369
  variable.deoptimizePath(UNKNOWN_PATH);
14272
14370
  if (!variable.included) {
14273
14371
  this.includeVariable(variable);
@@ -14505,9 +14603,15 @@ class Module {
14505
14603
  }
14506
14604
  this.dynamicImports.push({ argument, id: null, node, resolution: null });
14507
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
+ }
14508
14611
  addExport(node) {
14509
14612
  if (node instanceof ExportDefaultDeclaration) {
14510
14613
  // export default foo;
14614
+ this.assertUniqueExportName('default', node.start);
14511
14615
  this.exports.set('default', {
14512
14616
  identifier: node.variable.getAssignedVariableName(),
14513
14617
  localName: 'default'
@@ -14519,6 +14623,7 @@ class Module {
14519
14623
  if (node.exported) {
14520
14624
  // export * as name from './other'
14521
14625
  const name = node.exported.name;
14626
+ this.assertUniqueExportName(name, node.exported.start);
14522
14627
  this.reexportDescriptions.set(name, {
14523
14628
  localName: '*',
14524
14629
  module: null,
@@ -14537,6 +14642,7 @@ class Module {
14537
14642
  this.addSource(source, node);
14538
14643
  for (const { exported, local, start } of node.specifiers) {
14539
14644
  const name = exported instanceof Literal ? exported.value : exported.name;
14645
+ this.assertUniqueExportName(name, start);
14540
14646
  this.reexportDescriptions.set(name, {
14541
14647
  localName: local instanceof Literal ? local.value : local.name,
14542
14648
  module: null,
@@ -14552,6 +14658,7 @@ class Module {
14552
14658
  // export var foo = 1, bar = 2;
14553
14659
  for (const declarator of declaration.declarations) {
14554
14660
  for (const localName of extractAssignedNames(declarator.id)) {
14661
+ this.assertUniqueExportName(localName, declarator.id.start);
14555
14662
  this.exports.set(localName, { identifier: null, localName });
14556
14663
  }
14557
14664
  }
@@ -14559,6 +14666,7 @@ class Module {
14559
14666
  else {
14560
14667
  // export function foo () {}
14561
14668
  const localName = declaration.id.name;
14669
+ this.assertUniqueExportName(localName, declaration.id.start);
14562
14670
  this.exports.set(localName, { identifier: null, localName });
14563
14671
  }
14564
14672
  }
@@ -14568,6 +14676,7 @@ class Module {
14568
14676
  // except for reexports, local must be an Identifier
14569
14677
  const localName = local.name;
14570
14678
  const exportedName = exported instanceof Identifier ? exported.name : exported.value;
14679
+ this.assertUniqueExportName(exportedName, exported.start);
14571
14680
  this.exports.set(exportedName, { identifier: null, localName });
14572
14681
  }
14573
14682
  }
@@ -14576,6 +14685,10 @@ class Module {
14576
14685
  const source = node.source.value;
14577
14686
  this.addSource(source, node);
14578
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
+ }
14579
14692
  const name = specifier instanceof ImportDefaultSpecifier
14580
14693
  ? 'default'
14581
14694
  : specifier instanceof ImportNamespaceSpecifier
@@ -14583,7 +14696,7 @@ class Module {
14583
14696
  : specifier.imported instanceof Identifier
14584
14697
  ? specifier.imported.name
14585
14698
  : specifier.imported.value;
14586
- this.importDescriptions.set(specifier.local.name, {
14699
+ this.importDescriptions.set(localName, {
14587
14700
  module: null,
14588
14701
  name,
14589
14702
  source,