rollup 4.3.1 → 4.4.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.
@@ -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.1
4
+ Tue, 14 Nov 2023 05:24:21 GMT - commit 01d8c9d1b68919c2c429427ae7e60f503a8bb5f4
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.1";
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,41 @@ 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
+ - in function scopes, function and var can redeclare function and var
7222
+ - var is hoisted across scopes, function remains in the scope it is declared
7223
+ - var and function can redeclare function parameters, but parameters cannot redeclare parameters
7224
+ - function cannot redeclare catch scope parameters
7225
+ - var can redeclare catch scope parameters in a way
7226
+ - if the parameter is an identifier and not a pattern
7227
+ - then the variable is still declared in the hoisted outer scope, but the initializer is assigned to the parameter
7228
+ - const, let, class, and function except in the cases above cannot redeclare anything
7229
+ */
7230
+ addDeclaration(identifier, context, init, kind) {
7220
7231
  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);
7232
+ const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
7233
+ if (existingVariable) {
7234
+ const existingKind = existingVariable.kind;
7235
+ if (kind === "var" /* VariableKind.var */ && existingKind === "var" /* VariableKind.var */) {
7236
+ existingVariable.addDeclaration(identifier, init);
7237
+ return existingVariable;
7238
+ }
7239
+ context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7228
7240
  }
7229
- return variable;
7241
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
7242
+ this.variables.set(name, newVariable);
7243
+ return newVariable;
7244
+ }
7245
+ addHoistedVariable(name, variable) {
7246
+ (this.hoistedVariables ||= new Map()).set(name, variable);
7230
7247
  }
7231
7248
  contains(name) {
7232
7249
  return this.variables.has(name);
7233
7250
  }
7234
7251
  findVariable(_name) {
7252
+ /* istanbul ignore next */
7235
7253
  throw new Error('Internal Error: findVariable needs to be implemented by a subclass');
7236
7254
  }
7237
7255
  }
@@ -7239,9 +7257,9 @@ class Scope {
7239
7257
  class ChildScope extends Scope {
7240
7258
  constructor(parent, context) {
7241
7259
  super();
7242
- this.accessedOutsideVariables = new Map();
7243
7260
  this.parent = parent;
7244
7261
  this.context = context;
7262
+ this.accessedOutsideVariables = new Map();
7245
7263
  parent.children.push(this);
7246
7264
  }
7247
7265
  addAccessedDynamicImport(importExpression) {
@@ -7319,26 +7337,110 @@ class ChildScope extends Scope {
7319
7337
  }
7320
7338
  }
7321
7339
 
7322
- class ParameterScope extends ChildScope {
7340
+ class CatchBodyScope extends ChildScope {
7323
7341
  constructor(parent, context) {
7342
+ super(parent, context);
7343
+ this.parent = parent;
7344
+ this.context = context;
7345
+ }
7346
+ addDeclaration(identifier, context, init, kind) {
7347
+ if (kind === "var" /* VariableKind.var */) {
7348
+ const name = identifier.name;
7349
+ const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
7350
+ if (existingVariable) {
7351
+ const existingKind = existingVariable.kind;
7352
+ if (existingKind === "parameter" /* VariableKind.parameter */ &&
7353
+ // If this is a destructured parameter, it is forbidden to redeclare
7354
+ existingVariable.declarations[0].parent.type === CatchClause$1) {
7355
+ // If this is a var with the same name as the catch scope parameter,
7356
+ // the assignment actually goes to the parameter and the var is
7357
+ // hoisted without assignment. Locally, it is shadowed by the
7358
+ // parameter
7359
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, UNDEFINED_EXPRESSION, kind);
7360
+ // To avoid the need to rewrite the declaration, we link the variable
7361
+ // names. If we ever implement a logic that splits initialization and
7362
+ // assignment for hoisted vars, the "renderLikeHoisted" logic can be
7363
+ // removed again.
7364
+ // We do not need to check whether there already is a linked
7365
+ // variable because then declaredVariable would be that linked
7366
+ // variable.
7367
+ existingVariable.renderLikeHoisted(declaredVariable);
7368
+ this.addHoistedVariable(name, declaredVariable);
7369
+ return declaredVariable;
7370
+ }
7371
+ if (existingKind === "var" /* VariableKind.var */) {
7372
+ existingVariable.addDeclaration(identifier, init);
7373
+ return existingVariable;
7374
+ }
7375
+ return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7376
+ }
7377
+ // We only add parameters to parameter scopes
7378
+ const declaredVariable = this.parent.parent.addDeclaration(identifier, context, init, kind);
7379
+ // Necessary to make sure the init is deoptimized for conditional declarations.
7380
+ // We cannot call deoptimizePath here.
7381
+ declaredVariable.markInitializersForDeoptimization();
7382
+ // We add the variable to this and all parent scopes to reliably detect conflicts
7383
+ this.addHoistedVariable(name, declaredVariable);
7384
+ return declaredVariable;
7385
+ }
7386
+ return super.addDeclaration(identifier, context, init, kind);
7387
+ }
7388
+ }
7389
+
7390
+ class FunctionBodyScope extends ChildScope {
7391
+ constructor(parent, context) {
7392
+ super(parent, context);
7393
+ this.parent = parent;
7394
+ this.context = context;
7395
+ }
7396
+ // There is stuff that is only allowed in function scopes, i.e. functions can
7397
+ // be redeclared, functions and var can redeclare each other
7398
+ addDeclaration(identifier, context, init, kind) {
7399
+ const name = identifier.name;
7400
+ const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
7401
+ if (existingVariable) {
7402
+ const existingKind = existingVariable.kind;
7403
+ if ((kind === "var" /* VariableKind.var */ || kind === "function" /* VariableKind.function */) &&
7404
+ (existingKind === "var" /* VariableKind.var */ ||
7405
+ existingKind === "function" /* VariableKind.function */ ||
7406
+ existingKind === "parameter" /* VariableKind.parameter */)) {
7407
+ existingVariable.addDeclaration(identifier, init);
7408
+ return existingVariable;
7409
+ }
7410
+ context.error(parseAst_js.logRedeclarationError(name), identifier.start);
7411
+ }
7412
+ const newVariable = new LocalVariable(identifier.name, identifier, init, context, kind);
7413
+ this.variables.set(name, newVariable);
7414
+ return newVariable;
7415
+ }
7416
+ }
7417
+
7418
+ class ParameterScope extends ChildScope {
7419
+ constructor(parent, context, isCatchScope) {
7324
7420
  super(parent, context);
7325
7421
  this.parameters = [];
7326
7422
  this.hasRest = false;
7327
- this.hoistedBodyVarScope = new ChildScope(this, context);
7423
+ this.bodyScope = isCatchScope
7424
+ ? new CatchBodyScope(this, context)
7425
+ : new FunctionBodyScope(this, context);
7328
7426
  }
7329
7427
  /**
7330
7428
  * Adds a parameter to this scope. Parameters must be added in the correct
7331
7429
  * order, i.e. from left to right.
7332
7430
  */
7333
7431
  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);
7432
+ const { name, start } = identifier;
7433
+ const existingParameter = this.variables.get(name);
7434
+ if (existingParameter) {
7435
+ return this.context.error(parseAst_js.logDuplicateArgumentNameError(name), start);
7340
7436
  }
7437
+ const variable = new ParameterVariable(name, identifier, this.context);
7341
7438
  this.variables.set(name, variable);
7439
+ // We also add it to the body scope to detect name conflicts with local
7440
+ // variables. We still need the intermediate scope, though, as parameter
7441
+ // defaults are NOT taken from the body scope but from the parameters or
7442
+ // outside scope.
7443
+ this.bodyScope.addHoistedVariable(name, variable);
7342
7444
  return variable;
7343
7445
  }
7344
7446
  addParameterVariables(parameters, hasRest) {
@@ -8522,26 +8624,26 @@ class Identifier extends NodeBase {
8522
8624
  let variable;
8523
8625
  const { treeshake } = this.scope.context.options;
8524
8626
  switch (kind) {
8525
- case 'var': {
8526
- variable = this.scope.addDeclaration(this, this.scope.context, init, true);
8627
+ case "var" /* VariableKind.var */: {
8628
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
8527
8629
  if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
8528
8630
  // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
8529
8631
  variable.markInitializersForDeoptimization();
8530
8632
  }
8531
8633
  break;
8532
8634
  }
8533
- case 'function': {
8635
+ case "function" /* VariableKind.function */: {
8534
8636
  // 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);
8637
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
8536
8638
  break;
8537
8639
  }
8538
- case 'let':
8539
- case 'const':
8540
- case 'class': {
8541
- variable = this.scope.addDeclaration(this, this.scope.context, init, false);
8640
+ case "let" /* VariableKind.let */:
8641
+ case "const" /* VariableKind.const */:
8642
+ case "class" /* VariableKind.class */: {
8643
+ variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
8542
8644
  break;
8543
8645
  }
8544
- case 'parameter': {
8646
+ case "parameter" /* VariableKind.parameter */: {
8545
8647
  variable = this.scope.addParameterDeclaration(this);
8546
8648
  break;
8547
8649
  }
@@ -8551,13 +8653,15 @@ class Identifier extends NodeBase {
8551
8653
  throw new Error(`Internal Error: Unexpected identifier kind ${kind}.`);
8552
8654
  }
8553
8655
  }
8554
- variable.kind = kind;
8555
8656
  return [(this.variable = variable)];
8556
8657
  }
8557
8658
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
8558
8659
  this.variable.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
8559
8660
  }
8560
8661
  deoptimizePath(path) {
8662
+ if (path.length === 0 && !this.scope.contains(this.name)) {
8663
+ this.disallowImportReassignment();
8664
+ }
8561
8665
  // We keep conditional chaining because an unknown Node could have an
8562
8666
  // Identifier as property that might be deoptimized by default
8563
8667
  this.variable?.deoptimizePath(path);
@@ -8572,7 +8676,7 @@ class Identifier extends NodeBase {
8572
8676
  hasEffects(context) {
8573
8677
  if (!this.deoptimized)
8574
8678
  this.applyDeoptimizations();
8575
- if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
8679
+ if (this.isPossibleTDZ() && this.variable.kind !== "var" /* VariableKind.var */) {
8576
8680
  return true;
8577
8681
  }
8578
8682
  return (this.scope.context.options.treeshake
@@ -8663,6 +8767,9 @@ class Identifier extends NodeBase {
8663
8767
  }
8664
8768
  }
8665
8769
  }
8770
+ disallowImportReassignment() {
8771
+ return this.scope.context.error(parseAst_js.logIllegalImportReassignment(this.name, this.scope.context.module.id), this.start);
8772
+ }
8666
8773
  applyDeoptimizations() {
8667
8774
  this.deoptimized = true;
8668
8775
  if (this.variable instanceof LocalVariable) {
@@ -8838,17 +8945,26 @@ function removeLineBreaks(code, start, end) {
8838
8945
  }
8839
8946
 
8840
8947
  class BlockScope extends ChildScope {
8841
- addDeclaration(identifier, context, init, isHoisted) {
8842
- if (isHoisted) {
8843
- const variable = this.parent.addDeclaration(identifier, context, init, isHoisted);
8948
+ addDeclaration(identifier, context, init, kind) {
8949
+ if (kind === "var" /* VariableKind.var */) {
8950
+ const name = identifier.name;
8951
+ const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
8952
+ if (existingVariable) {
8953
+ if (existingVariable.kind === "var" /* VariableKind.var */) {
8954
+ existingVariable.addDeclaration(identifier, init);
8955
+ return existingVariable;
8956
+ }
8957
+ return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
8958
+ }
8959
+ const declaredVariable = this.parent.addDeclaration(identifier, context, init, kind);
8844
8960
  // Necessary to make sure the init is deoptimized for conditional declarations.
8845
8961
  // We cannot call deoptimizePath here.
8846
- variable.markInitializersForDeoptimization();
8847
- return variable;
8848
- }
8849
- else {
8850
- return super.addDeclaration(identifier, context, init, false);
8962
+ declaredVariable.markInitializersForDeoptimization();
8963
+ // We add the variable to this and all parent scopes to reliably detect conflicts
8964
+ this.addHoistedVariable(name, declaredVariable);
8965
+ return declaredVariable;
8851
8966
  }
8967
+ return super.addDeclaration(identifier, context, init, kind);
8852
8968
  }
8853
8969
  }
8854
8970
 
@@ -9086,7 +9202,6 @@ class FunctionBase extends NodeBase {
9086
9202
  this.scope.includeCallArguments(context, parameters);
9087
9203
  }
9088
9204
  initialise() {
9089
- this.scope.addParameterVariables(this.params.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), this.params[this.params.length - 1] instanceof RestElement);
9090
9205
  if (this.body instanceof BlockStatement) {
9091
9206
  this.body.addImplicitReturnExpressionToScope();
9092
9207
  }
@@ -9095,9 +9210,18 @@ class FunctionBase extends NodeBase {
9095
9210
  }
9096
9211
  }
9097
9212
  parseNode(esTreeNode) {
9098
- if (esTreeNode.body.type === BlockStatement$1) {
9099
- this.body = new BlockStatement(esTreeNode.body, this, this.scope.hoistedBodyVarScope);
9100
- }
9213
+ const { body, params } = esTreeNode;
9214
+ const parameters = (this.params = []);
9215
+ const { scope } = this;
9216
+ const { bodyScope, context } = scope;
9217
+ // We need to ensure that parameters are declared before the body is parsed
9218
+ // so that the scope already knows all parameters and can detect conflicts
9219
+ // when parsing the body.
9220
+ for (const parameter of params) {
9221
+ parameters.push(new (context.getNodeConstructor(parameter.type))(parameter, this, scope, false));
9222
+ }
9223
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare("parameter" /* VariableKind.parameter */, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
9224
+ this.body = new (context.getNodeConstructor(body.type))(body, this, bodyScope);
9101
9225
  super.parseNode(esTreeNode);
9102
9226
  }
9103
9227
  addArgumentToBeDeoptimized(_argument) { }
@@ -9111,7 +9235,7 @@ class ArrowFunctionExpression extends FunctionBase {
9111
9235
  this.objectEntity = null;
9112
9236
  }
9113
9237
  createScope(parentScope) {
9114
- this.scope = new ReturnValueScope(parentScope, this.scope.context);
9238
+ this.scope = new ReturnValueScope(parentScope, this.scope.context, false);
9115
9239
  }
9116
9240
  hasEffects() {
9117
9241
  if (!this.deoptimized)
@@ -9355,7 +9479,7 @@ class AssignmentPattern extends NodeBase {
9355
9479
 
9356
9480
  class ArgumentsVariable extends LocalVariable {
9357
9481
  constructor(context) {
9358
- super('arguments', null, UNKNOWN_EXPRESSION, context);
9482
+ super('arguments', null, UNKNOWN_EXPRESSION, context, "other" /* VariableKind.other */);
9359
9483
  this.deoptimizedArguments = [];
9360
9484
  }
9361
9485
  addArgumentToBeDeoptimized(argument) {
@@ -9389,7 +9513,7 @@ class ThisVariable extends ParameterVariable {
9389
9513
 
9390
9514
  class FunctionScope extends ReturnValueScope {
9391
9515
  constructor(parent, context) {
9392
- super(parent, context);
9516
+ super(parent, context, false);
9393
9517
  this.variables.set('arguments', (this.argumentsVariable = new ArgumentsVariable(context)));
9394
9518
  this.variables.set('this', (this.thisVariable = new ThisVariable(context)));
9395
9519
  }
@@ -9477,7 +9601,7 @@ class FunctionNode extends FunctionBase {
9477
9601
  }
9478
9602
  initialise() {
9479
9603
  super.initialise();
9480
- this.id?.declare('function', this);
9604
+ this.id?.declare("function" /* VariableKind.function */, this);
9481
9605
  }
9482
9606
  addArgumentToBeDeoptimized(argument) {
9483
9607
  this.scope.argumentsVariable.addArgumentToBeDeoptimized(argument);
@@ -10202,37 +10326,22 @@ class CallExpression extends CallExpressionBase {
10202
10326
  }
10203
10327
  }
10204
10328
 
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
10329
  class CatchClause extends NodeBase {
10221
10330
  createScope(parentScope) {
10222
- this.scope = new CatchScope(parentScope, this.scope.context);
10331
+ this.scope = new ParameterScope(parentScope, this.scope.context, true);
10223
10332
  }
10224
10333
  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;
10334
+ const { body, param, type } = esTreeNode;
10335
+ this.type = type;
10229
10336
  if (param) {
10230
10337
  this.param = new (this.scope.context.getNodeConstructor(param.type))(param, this, this.scope);
10231
- this.param.declare('parameter', UNKNOWN_EXPRESSION);
10338
+ this.param.declare("parameter" /* VariableKind.parameter */, UNKNOWN_EXPRESSION);
10232
10339
  }
10340
+ this.body = new BlockStatement(body, this, this.scope.bodyScope);
10233
10341
  super.parseNode(esTreeNode);
10234
10342
  }
10235
10343
  }
10344
+ CatchClause.prototype.preventChildBlockScope = true;
10236
10345
 
10237
10346
  class ChainExpression extends NodeBase {
10238
10347
  // deoptimizations are not relevant as we are not caching values
@@ -10255,7 +10364,7 @@ class ChainExpression extends NodeBase {
10255
10364
  class ClassBodyScope extends ChildScope {
10256
10365
  constructor(parent, classNode, context) {
10257
10366
  super(parent, context);
10258
- this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, context)));
10367
+ this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, context, "other" /* VariableKind.other */)));
10259
10368
  this.instanceScope = new ChildScope(this, context);
10260
10369
  this.instanceScope.variables.set('this', new ThisVariable(context));
10261
10370
  }
@@ -10439,7 +10548,7 @@ class ClassNode extends NodeBase {
10439
10548
  }
10440
10549
  }
10441
10550
  initialise() {
10442
- this.id?.declare('class', this);
10551
+ this.id?.declare("class" /* VariableKind.class */, this);
10443
10552
  for (const method of this.body.body) {
10444
10553
  if (method instanceof MethodDefinition && method.kind === 'constructor') {
10445
10554
  this.classConstructor = method;
@@ -11079,9 +11188,9 @@ class TrackingScope extends BlockScope {
11079
11188
  super(...arguments);
11080
11189
  this.hoistedDeclarations = [];
11081
11190
  }
11082
- addDeclaration(identifier, context, init, isHoisted) {
11191
+ addDeclaration(identifier, context, init, kind) {
11083
11192
  this.hoistedDeclarations.push(identifier);
11084
- return super.addDeclaration(identifier, context, init, isHoisted);
11193
+ return super.addDeclaration(identifier, context, init, kind);
11085
11194
  }
11086
11195
  }
11087
11196
 
@@ -12807,7 +12916,7 @@ class UndefinedVariable extends Variable {
12807
12916
 
12808
12917
  class ExportDefaultVariable extends LocalVariable {
12809
12918
  constructor(name, exportDefaultDeclaration, context) {
12810
- super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context);
12919
+ super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context, "other" /* VariableKind.other */);
12811
12920
  this.hasId = false;
12812
12921
  this.originalId = null;
12813
12922
  this.originalVariable = null;
@@ -12878,7 +12987,13 @@ class ExportDefaultVariable extends LocalVariable {
12878
12987
  class ModuleScope extends ChildScope {
12879
12988
  constructor(parent, context) {
12880
12989
  super(parent, context);
12881
- this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, context));
12990
+ this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, context, "other" /* VariableKind.other */));
12991
+ }
12992
+ addDeclaration(identifier, context, init, kind) {
12993
+ if (this.context.module.importDescriptions.has(identifier.name)) {
12994
+ context.error(parseAst_js.logRedeclarationError(identifier.name), identifier.start);
12995
+ }
12996
+ return super.addDeclaration(identifier, context, init, kind);
12882
12997
  }
12883
12998
  addExportDefaultDeclaration(name, exportDefaultDeclaration, context) {
12884
12999
  const variable = new ExportDefaultVariable(name, exportDefaultDeclaration, context);
@@ -13475,7 +13590,7 @@ class NamespaceVariable extends Variable {
13475
13590
  memberVariable.hasEffectsOnInteractionAtPath(path.slice(1), interaction, context));
13476
13591
  }
13477
13592
  include() {
13478
- this.included = true;
13593
+ super.include();
13479
13594
  this.context.includeAllExports();
13480
13595
  }
13481
13596
  prepare(accessedGlobalsByScope) {
@@ -13569,7 +13684,7 @@ class SyntheticNamedExportVariable extends Variable {
13569
13684
  return `${this.syntheticNamespace.getName(getPropertyAccess)}${getPropertyAccess(this.name)}`;
13570
13685
  }
13571
13686
  include() {
13572
- this.included = true;
13687
+ super.include();
13573
13688
  this.context.includeVariableInModule(this.syntheticNamespace);
13574
13689
  }
13575
13690
  setRenderNames(baseName, name) {
@@ -14171,7 +14286,7 @@ class Module {
14171
14286
  const removedExports = [];
14172
14287
  for (const exportName of this.exports.keys()) {
14173
14288
  const [variable] = this.getVariableForExportName(exportName);
14174
- (variable && variable.included ? renderedExports : removedExports).push(exportName);
14289
+ (variable?.included ? renderedExports : removedExports).push(exportName);
14175
14290
  }
14176
14291
  return { removedExports, renderedExports };
14177
14292
  }
@@ -14268,6 +14383,9 @@ class Module {
14268
14383
  for (const exportName of this.exports.keys()) {
14269
14384
  if (includeNamespaceMembers || exportName !== this.info.syntheticNamedExports) {
14270
14385
  const variable = this.getVariableForExportName(exportName)[0];
14386
+ if (!variable) {
14387
+ return parseAst_js.error(parseAst_js.logMissingEntryExport(exportName, this.id));
14388
+ }
14271
14389
  variable.deoptimizePath(UNKNOWN_PATH);
14272
14390
  if (!variable.included) {
14273
14391
  this.includeVariable(variable);
@@ -14505,9 +14623,15 @@ class Module {
14505
14623
  }
14506
14624
  this.dynamicImports.push({ argument, id: null, node, resolution: null });
14507
14625
  }
14626
+ assertUniqueExportName(name, nodeStart) {
14627
+ if (this.exports.has(name) || this.reexportDescriptions.has(name)) {
14628
+ this.error(parseAst_js.logDuplicateExportError(name), nodeStart);
14629
+ }
14630
+ }
14508
14631
  addExport(node) {
14509
14632
  if (node instanceof ExportDefaultDeclaration) {
14510
14633
  // export default foo;
14634
+ this.assertUniqueExportName('default', node.start);
14511
14635
  this.exports.set('default', {
14512
14636
  identifier: node.variable.getAssignedVariableName(),
14513
14637
  localName: 'default'
@@ -14519,6 +14643,7 @@ class Module {
14519
14643
  if (node.exported) {
14520
14644
  // export * as name from './other'
14521
14645
  const name = node.exported.name;
14646
+ this.assertUniqueExportName(name, node.exported.start);
14522
14647
  this.reexportDescriptions.set(name, {
14523
14648
  localName: '*',
14524
14649
  module: null,
@@ -14537,6 +14662,7 @@ class Module {
14537
14662
  this.addSource(source, node);
14538
14663
  for (const { exported, local, start } of node.specifiers) {
14539
14664
  const name = exported instanceof Literal ? exported.value : exported.name;
14665
+ this.assertUniqueExportName(name, start);
14540
14666
  this.reexportDescriptions.set(name, {
14541
14667
  localName: local instanceof Literal ? local.value : local.name,
14542
14668
  module: null,
@@ -14552,6 +14678,7 @@ class Module {
14552
14678
  // export var foo = 1, bar = 2;
14553
14679
  for (const declarator of declaration.declarations) {
14554
14680
  for (const localName of extractAssignedNames(declarator.id)) {
14681
+ this.assertUniqueExportName(localName, declarator.id.start);
14555
14682
  this.exports.set(localName, { identifier: null, localName });
14556
14683
  }
14557
14684
  }
@@ -14559,6 +14686,7 @@ class Module {
14559
14686
  else {
14560
14687
  // export function foo () {}
14561
14688
  const localName = declaration.id.name;
14689
+ this.assertUniqueExportName(localName, declaration.id.start);
14562
14690
  this.exports.set(localName, { identifier: null, localName });
14563
14691
  }
14564
14692
  }
@@ -14568,6 +14696,7 @@ class Module {
14568
14696
  // except for reexports, local must be an Identifier
14569
14697
  const localName = local.name;
14570
14698
  const exportedName = exported instanceof Identifier ? exported.name : exported.value;
14699
+ this.assertUniqueExportName(exportedName, exported.start);
14571
14700
  this.exports.set(exportedName, { identifier: null, localName });
14572
14701
  }
14573
14702
  }
@@ -14576,6 +14705,10 @@ class Module {
14576
14705
  const source = node.source.value;
14577
14706
  this.addSource(source, node);
14578
14707
  for (const specifier of node.specifiers) {
14708
+ const localName = specifier.local.name;
14709
+ if (this.scope.variables.has(localName) || this.importDescriptions.has(localName)) {
14710
+ this.error(parseAst_js.logRedeclarationError(localName), specifier.local.start);
14711
+ }
14579
14712
  const name = specifier instanceof ImportDefaultSpecifier
14580
14713
  ? 'default'
14581
14714
  : specifier instanceof ImportNamespaceSpecifier
@@ -14583,7 +14716,7 @@ class Module {
14583
14716
  : specifier.imported instanceof Identifier
14584
14717
  ? specifier.imported.name
14585
14718
  : specifier.imported.value;
14586
- this.importDescriptions.set(specifier.local.name, {
14719
+ this.importDescriptions.set(localName, {
14587
14720
  module: null,
14588
14721
  name,
14589
14722
  source,