rollup 4.64.0 → 4.64.6

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.64.0
4
- Fri, 02 Oct 2026 15:38:16 GMT - commit 77773bf8ee9130c4edbde14c017855c41e500692
3
+ Rollup.js v4.64.6
4
+ Tue, 13 Oct 2026 09:01:30 GMT - commit 3ba51901a0f41d8e6d4152c407cba036fb599feb
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -42,7 +42,7 @@ function _mergeNamespaces(n, m) {
42
42
 
43
43
  const promises__namespace = /*#__PURE__*/_interopNamespaceDefault(promises);
44
44
 
45
- var version = "4.64.0";
45
+ var version = "4.64.6";
46
46
  const package_ = {
47
47
  version: version};
48
48
 
@@ -5438,7 +5438,7 @@ var MagicString = class MagicString {
5438
5438
  while (chunk !== last) {
5439
5439
  if (chunk.next !== this.byStart.get(chunk.end)) throw new MagicStringError("cannot overwrite across a split point");
5440
5440
  chunk = chunk.next;
5441
- chunk.edit("", false);
5441
+ chunk.edit("", false, !overwrite);
5442
5442
  }
5443
5443
  first.edit(content, storeName, !overwrite);
5444
5444
  } else {
@@ -5792,8 +5792,8 @@ var MagicString = class MagicString {
5792
5792
  if (this._hasRemovedContent(match.index, match.index + match[0].length)) return false;
5793
5793
  const replacement = getReplacement(match, this.original);
5794
5794
  if (replacement === match[0]) return true;
5795
- if (match[0].length === 0) this.appendRight(match.index, replacement);
5796
- else this.overwrite(match.index, match.index + match[0].length, replacement);
5795
+ if (match[0].length === 0) this.appendRight(match.index - this.offset, replacement);
5796
+ else this.overwrite(match.index - this.offset, match.index + match[0].length - this.offset, replacement);
5797
5797
  return true;
5798
5798
  };
5799
5799
  if (searchValue.global) {
@@ -5820,8 +5820,8 @@ var MagicString = class MagicString {
5820
5820
  if (typeof replacement === "function") replacement = replacement(string, index, original);
5821
5821
  else replacement = expandReplacement(replacement, string, index, original, [], void 0);
5822
5822
  if (string !== replacement) {
5823
- if (string.length === 0) this.appendRight(index, replacement);
5824
- else this.overwrite(index, index + string.length, replacement);
5823
+ if (string.length === 0) this.appendRight(index - this.offset, replacement);
5824
+ else this.overwrite(index - this.offset, index + string.length - this.offset, replacement);
5825
5825
  }
5826
5826
  break;
5827
5827
  }
@@ -5842,7 +5842,7 @@ var MagicString = class MagicString {
5842
5842
  for (let index = 0; index <= original.length; index += 1) {
5843
5843
  if (this._hasRemovedContent(index, index)) continue;
5844
5844
  const _replacement = typeof replacement === "function" ? replacement("", index, original) : expandReplacement(replacement, "", index, original, [], void 0);
5845
- if (_replacement !== "") this.appendRight(index, _replacement);
5845
+ if (_replacement !== "") this.appendRight(index - this.offset, _replacement);
5846
5846
  }
5847
5847
  return this;
5848
5848
  }
@@ -5850,7 +5850,7 @@ var MagicString = class MagicString {
5850
5850
  if (this._hasRemovedContent(index, index + stringLength)) continue;
5851
5851
  const previous = original.slice(index, index + stringLength);
5852
5852
  const _replacement = typeof replacement === "function" ? replacement(previous, index, original) : expandReplacement(replacement, previous, index, original, [], void 0);
5853
- if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
5853
+ if (previous !== _replacement) this.overwrite(index - this.offset, index + stringLength - this.offset, _replacement);
5854
5854
  }
5855
5855
  return this;
5856
5856
  }
@@ -6611,7 +6611,6 @@ function createInclusionContext() {
6611
6611
  hasBreak: false,
6612
6612
  hasContinue: false,
6613
6613
  includedCallArguments: new Set(),
6614
- includedCallArgumentsOfPossibleValues: null,
6615
6614
  includedLabels: new Set()
6616
6615
  };
6617
6616
  }
@@ -6760,6 +6759,9 @@ class Variable extends ExpressionEntity {
6760
6759
  markReassigned() {
6761
6760
  this.isReassigned = true;
6762
6761
  }
6762
+ markTargetOfAssignment() {
6763
+ this.isTargetOfAssignment = true;
6764
+ }
6763
6765
  constructor(name) {
6764
6766
  super();
6765
6767
  this.name = name;
@@ -6772,6 +6774,9 @@ class Variable extends ExpressionEntity {
6772
6774
  this.renderBaseName = null;
6773
6775
  this.renderName = null;
6774
6776
  this.isReassigned = false;
6777
+ // Unlike isReassigned, set eagerly during binding for every assignment,
6778
+ // including ones that are never included
6779
+ this.isTargetOfAssignment = false;
6775
6780
  this.onlyFunctionCallUsed = true;
6776
6781
  }
6777
6782
  /**
@@ -9497,10 +9502,9 @@ class LocalVariable extends Variable {
9497
9502
  this.kind = kind;
9498
9503
  this.calledFromTryStatement = false;
9499
9504
  this.additionalInitializers = null;
9500
- // A possibly incomplete list of values assigned to this variable after its
9501
- // declaration; as it is incomplete, it must never be used for value queries
9502
- // but only to forward call arguments to possible values
9503
- this.reassignedValues = null;
9505
+ // A possibly incomplete list of functions assigned to this variable; only used
9506
+ // to retain call arguments of assigned try-catch helpers, never for value queries
9507
+ this.assignedFunctions = null;
9504
9508
  this.includedPathTracker = new IncludedFullPathTracker();
9505
9509
  this.expressionsToBeDeoptimized = [];
9506
9510
  this.declarations = declarator ? [declarator] : [];
@@ -9626,16 +9630,12 @@ class LocalVariable extends Variable {
9626
9630
  }
9627
9631
  includeCallArgumentsWhenCalledAtPath(path, interaction, context) {
9628
9632
  if (this.isReassigned) {
9629
- // Even when the value is unknown, it may be one of the assigned values;
9630
- // forwarding to all of them retains the arguments of try-catch helpers
9633
+ // The value may still be one of the assigned functions, whose try-catch
9634
+ // helpers need their call arguments retained
9631
9635
  includeInteraction(interaction, context);
9632
- // Each possible value is visited at most once per path and call
9633
- // per traversal so that dense assignment graphs do not repeat work
9634
- // for every simple path
9635
- const previousTracker = context.includedCallArgumentsOfPossibleValues;
9636
- context.includedCallArgumentsOfPossibleValues ??= new DiscriminatedPathTracker();
9637
- this.includeCallArgumentsOfPossibleValues(path, interaction, context, context.includedCallArgumentsOfPossibleValues);
9638
- context.includedCallArgumentsOfPossibleValues = previousTracker;
9636
+ if (path.length === 0) {
9637
+ this.includeCallArgumentsOfAssignedTryCatchHelpers(interaction, context);
9638
+ }
9639
9639
  return;
9640
9640
  }
9641
9641
  if (context.includedCallArguments.has(this.init) ||
@@ -9647,25 +9647,25 @@ class LocalVariable extends Variable {
9647
9647
  this.init.includeCallArgumentsWhenCalledAtPath([...this.initPath, ...path], interaction, context);
9648
9648
  context.includedCallArguments.delete(this.init);
9649
9649
  }
9650
- includeCallArgumentsOfPossibleValues(path, interaction, context, tracker) {
9651
- if (this.reassignedValues === null || path.length + this.initPath.length > MAX_PATH_DEPTH) {
9652
- return;
9650
+ includeCallArgumentsOfAssignedTryCatchHelpers(interaction, context) {
9651
+ if (this.initPath.length === 0) {
9652
+ this.includeCallArgumentsOfTryCatchHelper(this.init, interaction, context);
9653
9653
  }
9654
- this.includeCallArgumentsOfPossibleValue(this.init, [...this.initPath, ...path], interaction, context, tracker);
9655
- for (const entity of this.reassignedValues) {
9656
- this.includeCallArgumentsOfPossibleValue(entity, path, interaction, context, tracker);
9654
+ for (const assignedFunction of this.assignedFunctions ?? parseAst_js.EMPTY_ARRAY) {
9655
+ this.includeCallArgumentsOfTryCatchHelper(assignedFunction, interaction, context);
9657
9656
  }
9658
9657
  }
9659
- includeCallArgumentsOfPossibleValue(entity, path, interaction, context, tracker) {
9660
- if (entity === UNKNOWN_EXPRESSION ||
9661
- entity === UNDEFINED_EXPRESSION ||
9662
- tracker.trackEntityAtPathAndGetIfTracked(path, interaction, entity)) {
9663
- return;
9658
+ includeCallArgumentsOfTryCatchHelper(value, interaction, context) {
9659
+ if (isArrowFunctionExpressionNode(value) || isFunctionExpressionNode(value)) {
9660
+ if (value.scope.hasParameterCalledFromTryStatement()) {
9661
+ value.scope.includeCallArguments(interaction, context);
9662
+ }
9664
9663
  }
9665
- entity.includeCallArgumentsWhenCalledAtPath(path, interaction, context);
9666
9664
  }
9667
9665
  addReassignedValue(value) {
9668
- (this.reassignedValues ??= []).push(value);
9666
+ if (isArrowFunctionExpressionNode(value) || isFunctionExpressionNode(value)) {
9667
+ (this.assignedFunctions ??= []).push(value);
9668
+ }
9669
9669
  }
9670
9670
  markCalledFromTryStatement() {
9671
9671
  this.calledFromTryStatement = true;
@@ -9899,6 +9899,9 @@ class Identifier extends IdentifierBase {
9899
9899
  this.variable = this.scope.findVariable(this.name);
9900
9900
  this.variable.addReference(this);
9901
9901
  this.isVariableReference = true;
9902
+ if (this.assignmentInteraction) {
9903
+ this.variable.markTargetOfAssignment();
9904
+ }
9902
9905
  }
9903
9906
  }
9904
9907
  declare(kind, destructuredInitPath, init) {
@@ -10221,6 +10224,47 @@ class MethodDefinition extends MethodBase {
10221
10224
  }
10222
10225
  }
10223
10226
 
10227
+ class PropertyDefinition extends NodeBase {
10228
+ get computed() {
10229
+ return isFlagSet(this.flags, 1024 /* Flag.computed */);
10230
+ }
10231
+ set computed(value) {
10232
+ this.flags = setFlag(this.flags, 1024 /* Flag.computed */, value);
10233
+ }
10234
+ deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
10235
+ this.value?.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
10236
+ }
10237
+ deoptimizePath(path) {
10238
+ this.value?.deoptimizePath(path);
10239
+ }
10240
+ getLiteralValueAtPath(path, recursionTracker, origin) {
10241
+ return this.value
10242
+ ? this.value.getLiteralValueAtPath(path, recursionTracker, origin)
10243
+ : UnknownValue;
10244
+ }
10245
+ getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
10246
+ return this.value
10247
+ ? this.value.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)
10248
+ : UNKNOWN_RETURN_EXPRESSION;
10249
+ }
10250
+ hasEffects(context) {
10251
+ return (this.key.hasEffects(context) ||
10252
+ (this.static && !!this.value?.hasEffects(context)) ||
10253
+ checkEffectForNodes(this.decorators, context));
10254
+ }
10255
+ hasEffectsOnInteractionAtPath(path, interaction, context) {
10256
+ return !this.value || this.value.hasEffectsOnInteractionAtPath(path, interaction, context);
10257
+ }
10258
+ includeNode(context) {
10259
+ this.included = true;
10260
+ this.value?.includePath(UNKNOWN_PATH, context);
10261
+ for (const decorator of this.decorators) {
10262
+ decorator.includePath(UNKNOWN_PATH, context);
10263
+ }
10264
+ }
10265
+ }
10266
+ PropertyDefinition.prototype.applyDeoptimizations = doNotDeoptimize;
10267
+
10224
10268
  class BlockScope extends ChildScope {
10225
10269
  constructor(parent) {
10226
10270
  super(parent, parent.context);
@@ -10286,6 +10330,7 @@ function isStaticBlock(statement) {
10286
10330
  class ClassNode extends NodeBase {
10287
10331
  constructor() {
10288
10332
  super(...arguments);
10333
+ this.instanceFieldValues = null;
10289
10334
  this.objectEntity = null;
10290
10335
  }
10291
10336
  createScope(parentScope) {
@@ -10319,7 +10364,7 @@ class ClassNode extends NodeBase {
10319
10364
  (this.classConstructor === null
10320
10365
  ? this.superClass?.hasEffectsOnInteractionAtPath(path, interaction, context)
10321
10366
  : this.classConstructor.hasEffectsOnInteractionAtPath(path, interaction, context)) ||
10322
- false
10367
+ this.hasEffectsOnInstanceFieldInitialization(context)
10323
10368
  : this.getObjectEntity().hasEffectsOnInteractionAtPath(path, interaction, context);
10324
10369
  }
10325
10370
  include(context, includeChildrenRecursively) {
@@ -10337,6 +10382,10 @@ class ClassNode extends NodeBase {
10337
10382
  initialise() {
10338
10383
  super.initialise();
10339
10384
  this.id?.declare('class', EMPTY_PATH, this);
10385
+ this.instanceEntity = new ObjectEntity(new Map(), new ObjectMember(this, ['prototype']));
10386
+ // This makes sure that all deoptimizations of "this" are applied to the
10387
+ // instance entity, even if the class is only instantiated by unknown code.
10388
+ this.body.scope.instanceThisVariable.addArgumentForDeoptimization(this.instanceEntity);
10340
10389
  for (const method of this.body.body) {
10341
10390
  if (method instanceof MethodDefinition && method.kind === 'constructor') {
10342
10391
  this.classConstructor = method;
@@ -10357,6 +10406,36 @@ class ClassNode extends NodeBase {
10357
10406
  }
10358
10407
  this.scope.context.requestTreeshakingPass();
10359
10408
  }
10409
+ hasEffectsOnInstanceFieldInitialization(context) {
10410
+ const fieldValues = this.getInstanceFieldValues();
10411
+ if (fieldValues.length === 0)
10412
+ return false;
10413
+ const { replacedVariableInits } = context;
10414
+ const thisVariable = this.body.scope.instanceThisVariable;
10415
+ const thisInit = replacedVariableInits.get(thisVariable);
10416
+ replacedVariableInits.set(thisVariable, this.instanceEntity);
10417
+ const hasEffects = fieldValues.some(value => value.hasEffects(context));
10418
+ if (thisInit) {
10419
+ replacedVariableInits.set(thisVariable, thisInit);
10420
+ }
10421
+ else {
10422
+ replacedVariableInits.delete(thisVariable);
10423
+ }
10424
+ return hasEffects;
10425
+ }
10426
+ getInstanceFieldValues() {
10427
+ if (this.instanceFieldValues === null) {
10428
+ this.instanceFieldValues = [];
10429
+ for (const definition of this.body.body) {
10430
+ if (definition instanceof PropertyDefinition &&
10431
+ !definition.static &&
10432
+ definition.value !== null) {
10433
+ this.instanceFieldValues.push(definition.value);
10434
+ }
10435
+ }
10436
+ }
10437
+ return this.instanceFieldValues;
10438
+ }
10360
10439
  getObjectEntity() {
10361
10440
  if (this.objectEntity !== null) {
10362
10441
  return this.objectEntity;
@@ -10683,6 +10762,31 @@ class ThisVariable extends ParameterVariable {
10683
10762
  }
10684
10763
  }
10685
10764
 
10765
+ /**
10766
+ * Represents the return value of a function where all return statements return
10767
+ * the same variable that is the target of an assignment. As the assigned value
10768
+ * may replace the declaration initializer before the function returns, value
10769
+ * queries resolve to unknown, and call arguments are deoptimized directly
10770
+ * instead of being forwarded to the initializer alone.
10771
+ */
10772
+ class ReturnedIdentifier extends ExpressionEntity {
10773
+ constructor(returnedIdentifier) {
10774
+ super();
10775
+ this.returnedIdentifier = returnedIdentifier;
10776
+ }
10777
+ deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
10778
+ // The initializer may never be the value that is returned
10779
+ deoptimizeInteraction(interaction);
10780
+ this.returnedIdentifier.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
10781
+ }
10782
+ deoptimizePath(path) {
10783
+ this.returnedIdentifier.deoptimizePath(path);
10784
+ }
10785
+ includeCallArgumentsWhenCalledAtPath(path, interaction, context) {
10786
+ this.returnedIdentifier.includeCallArgumentsWhenCalledAtPath(path, interaction, context);
10787
+ }
10788
+ }
10789
+
10686
10790
  class CatchBodyScope extends ChildScope {
10687
10791
  constructor(parent) {
10688
10792
  super(parent, parent.context);
@@ -10791,6 +10895,9 @@ class ParameterScope extends ChildScope {
10791
10895
  }
10792
10896
  this.hasRest = hasRest;
10793
10897
  }
10898
+ hasParameterCalledFromTryStatement() {
10899
+ return this.parameters.some(parameterVariables => parameterVariables.some(variable => variable.calledFromTryStatement));
10900
+ }
10794
10901
  includeCallArguments({ args }, context) {
10795
10902
  let calledFromTryStatement = false;
10796
10903
  let argumentIncluded = false;
@@ -10914,21 +11021,21 @@ class ReturnValueScope extends ParameterScope {
10914
11021
  addArgumentToBeDeoptimized(_argument) { }
10915
11022
  updateReturnExpression() {
10916
11023
  const { returnExpressions } = this;
10917
- if (returnExpressions.length === 1) {
10918
- this.returnExpression = returnExpressions[0];
11024
+ const [firstExpression] = returnExpressions;
11025
+ // A single return, or the same variable returned on all paths, can be
11026
+ // resolved to that variable
11027
+ if (firstExpression && this.returnExpressionsResolveToSameVariable(firstExpression)) {
11028
+ this.returnExpression = firstExpression.variable.isTargetOfAssignment
11029
+ ? new ReturnedIdentifier(firstExpression)
11030
+ : firstExpression;
11031
+ }
11032
+ else if (returnExpressions.length === 1) {
11033
+ this.returnExpression = firstExpression;
10919
11034
  }
10920
11035
  else {
10921
- // Returning the same variable on all paths is equivalent to a single
10922
- // return, so the return expression can be resolved to that variable
10923
- const [firstExpression] = returnExpressions;
10924
- if (firstExpression && this.returnExpressionsResolveToSameVariable(firstExpression)) {
10925
- this.returnExpression = firstExpression;
10926
- }
10927
- else {
10928
- this.returnExpression = UNKNOWN_EXPRESSION;
10929
- for (const expression of returnExpressions) {
10930
- expression.deoptimizePath(UNKNOWN_PATH);
10931
- }
11036
+ this.returnExpression = UNKNOWN_EXPRESSION;
11037
+ for (const expression of returnExpressions) {
11038
+ expression.deoptimizePath(UNKNOWN_PATH);
10932
11039
  }
10933
11040
  }
10934
11041
  }
@@ -11109,6 +11216,9 @@ class RestElement extends NodeBase {
11109
11216
  markDeclarationReached() {
11110
11217
  this.argument.markDeclarationReached();
11111
11218
  }
11219
+ setAssignedValue(value) {
11220
+ this.argument.setAssignedValue(value);
11221
+ }
11112
11222
  applyDeoptimizations() {
11113
11223
  this.deoptimized = true;
11114
11224
  if (this.declarationInit !== null) {
@@ -13845,6 +13955,14 @@ class ArrayPattern extends NodeBase {
13845
13955
  }
13846
13956
  }
13847
13957
  }
13958
+ setAssignedValue(value) {
13959
+ super.setAssignedValue(value);
13960
+ // Destructuring assigns each target only some subpath of the assigned
13961
+ // value, which is not tracked
13962
+ for (const element of this.elements) {
13963
+ element?.setAssignedValue(UNKNOWN_EXPRESSION);
13964
+ }
13965
+ }
13848
13966
  markDeclarationReached() {
13849
13967
  for (const element of this.elements) {
13850
13968
  element?.markDeclarationReached();
@@ -14015,6 +14133,14 @@ class ObjectPattern extends NodeBase {
14015
14133
  }
14016
14134
  }
14017
14135
  }
14136
+ setAssignedValue(value) {
14137
+ super.setAssignedValue(value);
14138
+ // Destructuring assigns each target only some subpath of the assigned
14139
+ // value, which is not tracked
14140
+ for (const property of this.properties) {
14141
+ property.setAssignedValue(UNKNOWN_EXPRESSION);
14142
+ }
14143
+ }
14018
14144
  }
14019
14145
  ObjectPattern.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
14020
14146
  ObjectPattern.prototype.applyDeoptimizations = doNotDeoptimize;
@@ -14179,6 +14305,9 @@ class AssignmentPattern extends NodeBase {
14179
14305
  this.left.render(code, options, { isShorthandProperty });
14180
14306
  this.right.render(code, options);
14181
14307
  }
14308
+ setAssignedValue(value) {
14309
+ this.left.setAssignedValue(value);
14310
+ }
14182
14311
  applyDeoptimizations() {
14183
14312
  this.deoptimized = true;
14184
14313
  this.left.deoptimizePath(EMPTY_PATH);
@@ -14187,6 +14316,17 @@ class AssignmentPattern extends NodeBase {
14187
14316
  }
14188
14317
  }
14189
14318
 
14319
+ function markTopLevelAwait(node) {
14320
+ if (node.scope.context.usesTopLevelAwait)
14321
+ return;
14322
+ let parent = node.parent;
14323
+ do {
14324
+ if (parent instanceof FunctionBase)
14325
+ return;
14326
+ } while ((parent = parent.parent));
14327
+ node.scope.context.usesTopLevelAwait = true;
14328
+ }
14329
+
14190
14330
  class AwaitExpression extends NodeBase {
14191
14331
  deoptimizePath(path) {
14192
14332
  this.argument.deoptimizePath(path);
@@ -14198,12 +14338,7 @@ class AwaitExpression extends NodeBase {
14198
14338
  }
14199
14339
  initialise() {
14200
14340
  super.initialise();
14201
- let parent = this.parent;
14202
- do {
14203
- if (parent instanceof FunctionNode || parent instanceof ArrowFunctionExpression)
14204
- return;
14205
- } while ((parent = parent.parent));
14206
- this.scope.context.usesTopLevelAwait = true;
14341
+ markTopLevelAwait(this);
14207
14342
  }
14208
14343
  include(context, includeChildrenRecursively) {
14209
14344
  if (!this.included)
@@ -14694,7 +14829,8 @@ class ClassBodyScope extends ChildScope {
14694
14829
  super(parent, context);
14695
14830
  this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, EMPTY_PATH, context, 'other')));
14696
14831
  this.instanceScope = new ChildScope(this, context);
14697
- this.instanceScope.variables.set('this', new ThisVariable(context));
14832
+ this.instanceThisVariable = new ThisVariable(context);
14833
+ this.instanceScope.variables.set('this', this.instanceThisVariable);
14698
14834
  }
14699
14835
  findLexicalBoundary() {
14700
14836
  return this;
@@ -15194,6 +15330,8 @@ class ForOfStatement extends NodeBase {
15194
15330
  }
15195
15331
  initialise() {
15196
15332
  super.initialise();
15333
+ if (this.await)
15334
+ markTopLevelAwait(this);
15197
15335
  this.left.setAssignedValue(UNKNOWN_EXPRESSION);
15198
15336
  }
15199
15337
  render(code, options) {
@@ -16978,6 +17116,9 @@ class Property extends MethodBase {
16978
17116
  }
16979
17117
  this.value.render(code, options, { isShorthandProperty: this.shorthand });
16980
17118
  }
17119
+ setAssignedValue(value) {
17120
+ this.value.setAssignedValue(value);
17121
+ }
16981
17122
  getPathInProperty(destructuredInitPath) {
16982
17123
  return destructuredInitPath.at(-1) === UnknownKey
16983
17124
  ? destructuredInitPath
@@ -16993,47 +17134,6 @@ class Property extends MethodBase {
16993
17134
  Property.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
16994
17135
  Property.prototype.applyDeoptimizations = doNotDeoptimize;
16995
17136
 
16996
- class PropertyDefinition extends NodeBase {
16997
- get computed() {
16998
- return isFlagSet(this.flags, 1024 /* Flag.computed */);
16999
- }
17000
- set computed(value) {
17001
- this.flags = setFlag(this.flags, 1024 /* Flag.computed */, value);
17002
- }
17003
- deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
17004
- this.value?.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
17005
- }
17006
- deoptimizePath(path) {
17007
- this.value?.deoptimizePath(path);
17008
- }
17009
- getLiteralValueAtPath(path, recursionTracker, origin) {
17010
- return this.value
17011
- ? this.value.getLiteralValueAtPath(path, recursionTracker, origin)
17012
- : UnknownValue;
17013
- }
17014
- getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
17015
- return this.value
17016
- ? this.value.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)
17017
- : UNKNOWN_RETURN_EXPRESSION;
17018
- }
17019
- hasEffects(context) {
17020
- return (this.key.hasEffects(context) ||
17021
- (this.static && !!this.value?.hasEffects(context)) ||
17022
- checkEffectForNodes(this.decorators, context));
17023
- }
17024
- hasEffectsOnInteractionAtPath(path, interaction, context) {
17025
- return !this.value || this.value.hasEffectsOnInteractionAtPath(path, interaction, context);
17026
- }
17027
- includeNode(context) {
17028
- this.included = true;
17029
- this.value?.includePath(UNKNOWN_PATH, context);
17030
- for (const decorator of this.decorators) {
17031
- decorator.includePath(UNKNOWN_PATH, context);
17032
- }
17033
- }
17034
- }
17035
- PropertyDefinition.prototype.applyDeoptimizations = doNotDeoptimize;
17036
-
17037
17137
  class ReturnStatement extends NodeBase {
17038
17138
  hasEffects(context) {
17039
17139
  if (!context.ignore.returnYield || this.argument?.hasEffects(context))
@@ -17761,6 +17861,8 @@ class VariableDeclaration extends NodeBase {
17761
17861
  }
17762
17862
  initialise() {
17763
17863
  super.initialise();
17864
+ if (this.kind === 'await using')
17865
+ markTopLevelAwait(this);
17764
17866
  for (const declarator of this.declarations) {
17765
17867
  declarator.declareDeclarator(this.kind);
17766
17868
  }
@@ -19647,6 +19749,9 @@ class Module {
19647
19749
  hasEffects() {
19648
19750
  return this.info.moduleSideEffects === 'no-treeshake' || this.ast.hasCachedEffects();
19649
19751
  }
19752
+ hasTopLevelAwait() {
19753
+ return this.astContext.usesTopLevelAwait;
19754
+ }
19650
19755
  include() {
19651
19756
  const context = createInclusionContext();
19652
19757
  if (this.ast.shouldBeIncluded(context))
@@ -20917,6 +21022,7 @@ class Chunk {
20917
21022
  const { accessedGlobals, indent, magicString, renderedSource, usedModules, usesTopLevelAwait } = this.renderModules(preliminaryFileName.fileName);
20918
21023
  const renderedDependencies = [...this.getRenderedDependencies().values()];
20919
21024
  const renderedExports = exportMode === 'none' ? [] : this.getChunkExportDeclarations(format);
21025
+ const renderedExportNames = format === 'es' && new Set(renderedExports.map(({ exported }) => exported));
20920
21026
  let hasExports = renderedExports.length > 0;
20921
21027
  let hasDefaultExport = false;
20922
21028
  for (const renderedDependency of renderedDependencies) {
@@ -20926,8 +21032,8 @@ class Chunk {
20926
21032
  if (!hasDefaultExport && reexports.some(reexport => reexport.reexported === 'default')) {
20927
21033
  hasDefaultExport = true;
20928
21034
  }
20929
- if (format === 'es') {
20930
- renderedDependency.reexports = reexports.filter(({ reexported }) => !renderedExports.find(({ exported }) => exported === reexported));
21035
+ if (renderedExportNames) {
21036
+ renderedDependency.reexports = reexports.filter(({ reexported }) => !renderedExportNames.has(reexported));
20931
21037
  }
20932
21038
  }
20933
21039
  }
@@ -21798,7 +21904,8 @@ function getChunkAssignments(entries, manualChunkAliasByEntry, minChunkSize, log
21798
21904
  // Warning: This will consume dynamicallyDependentEntriesByDynamicEntry.
21799
21905
  // If we no longer want this, we should make a copy here.
21800
21906
  const alreadyLoadedAtomsByEntry = getAlreadyLoadedAtomsByEntry(staticDependencyAtomsByEntry, dynamicallyDependentEntriesByDynamicEntry, dynamicImportsByEntry, entriesAndManualChunksCount);
21801
- const awaitedAlreadyLoadedAtomsByEntry = getAlreadyLoadedAtomsByEntry(staticDependencyAtomsByEntry, dynamicallyDependentEntriesByAwaitedDynamicEntry, awaitedDynamicImportsByEntry, entriesAndManualChunksCount);
21907
+ // Warning: This will consume dynamicallyDependentEntriesByAwaitedDynamicEntry.
21908
+ const awaitedAlreadyLoadedAtomsByEntry = getAwaitedAlreadyLoadedAtomsByEntry(staticDependencyAtomsByEntry, dynamicallyDependentEntriesByAwaitedDynamicEntry, awaitedDynamicImportsByEntry, entriesAndManualChunksCount);
21802
21909
  // This mutates the dependentEntries in chunkAtoms
21803
21910
  removeUnnecessaryDependentEntries(chunkAtoms, alreadyLoadedAtomsByEntry, awaitedAlreadyLoadedAtomsByEntry);
21804
21911
  const { chunks, sideEffectAtoms, sizeByAtom } = getChunksWithSameDependentEntriesAndCorrelatedAtoms(chunkAtoms, staticDependencyAtomsByEntry, alreadyLoadedAtomsByEntry, minChunkSize);
@@ -21861,13 +21968,16 @@ function analyzeModuleGraph(entries, manualChunkModules, manualChunkModulesByMod
21861
21968
  for (const currentEntryModules of allEntriesAndManualChunks) {
21862
21969
  const dynamicImportsForCurrentEntry = new Set();
21863
21970
  const awaitedDynamicImportsForCurrentEntry = new Set();
21971
+ const dynamicEntriesForCurrentEntry = new Set();
21864
21972
  dynamicImportModulesByEntry[entryOrManualChunkIndex] = dynamicImportsForCurrentEntry;
21865
21973
  awaitedDynamicImportModulesByEntry[entryOrManualChunkIndex] =
21866
21974
  awaitedDynamicImportsForCurrentEntry;
21867
21975
  const staticDependencies = new Set(currentEntryModules);
21976
+ let hasTopLevelAwait = false;
21868
21977
  // If we have a very large manual chunk, tracking if it is already added to the dependencies will improve performance
21869
21978
  const addedManualChunks = new Set();
21870
21979
  for (const module of staticDependencies) {
21980
+ hasTopLevelAwait ||= module.hasTopLevelAwait();
21871
21981
  getOrCreate(dependentEntriesByModule, module, (getNewSet)).add(entryOrManualChunkIndex);
21872
21982
  const manualChunkMembers = manualChunkModulesByModule.get(module);
21873
21983
  if (manualChunkMembers && !addedManualChunks.has(manualChunkMembers)) {
@@ -21884,17 +21994,13 @@ function analyzeModuleGraph(entries, manualChunkModules, manualChunkModulesByMod
21884
21994
  for (const { node: { resolution } } of module.dynamicImports) {
21885
21995
  if (resolution instanceof Module &&
21886
21996
  resolution.includedDynamicImporters.length > 0 &&
21887
- !allEntriesSet.has(resolution)) {
21888
- dynamicEntryModules.add(resolution);
21889
- allEntriesSet.add(resolution);
21890
- allEntriesAndManualChunks.push([resolution]);
21891
- dynamicImportsForCurrentEntry.add(resolution);
21892
- for (const includedTopLevelAwaitingDynamicImporter of resolution.includedTopLevelAwaitingDynamicImporters) {
21893
- if (staticDependencies.has(includedTopLevelAwaitingDynamicImporter)) {
21894
- awaitedDynamicEntryModules.add(resolution);
21895
- awaitedDynamicImportsForCurrentEntry.add(resolution);
21896
- break;
21897
- }
21997
+ (dynamicEntryModules.has(resolution) || !allEntriesSet.has(resolution))) {
21998
+ dynamicEntriesForCurrentEntry.add(resolution);
21999
+ if (!allEntriesSet.has(resolution)) {
22000
+ dynamicEntryModules.add(resolution);
22001
+ allEntriesSet.add(resolution);
22002
+ allEntriesAndManualChunks.push([resolution]);
22003
+ dynamicImportsForCurrentEntry.add(resolution);
21898
22004
  }
21899
22005
  }
21900
22006
  }
@@ -21906,13 +22012,20 @@ function analyzeModuleGraph(entries, manualChunkModules, manualChunkModulesByMod
21906
22012
  }
21907
22013
  }
21908
22014
  }
22015
+ // A dynamic import can be awaited indirectly through a static dependency.
22016
+ if (hasTopLevelAwait) {
22017
+ for (const dynamicEntry of dynamicEntriesForCurrentEntry) {
22018
+ awaitedDynamicEntryModules.add(dynamicEntry);
22019
+ awaitedDynamicImportsForCurrentEntry.add(dynamicEntry);
22020
+ }
22021
+ }
21909
22022
  entryOrManualChunkIndex++;
21910
22023
  }
21911
22024
  const { awaitedDynamicEntries, awaitedDynamicImportsByEntry, dynamicEntries, dynamicImportsByEntry } = getDynamicEntries(allEntriesAndManualChunks, dynamicEntryModules, dynamicImportModulesByEntry, awaitedDynamicEntryModules, awaitedDynamicImportModulesByEntry);
21912
22025
  return {
21913
22026
  awaitedDynamicImportsByEntry,
21914
22027
  dependentEntriesByModule,
21915
- dynamicallyDependentEntriesByAwaitedDynamicEntry: getDynamicallyDependentEntriesByDynamicEntry(dependentEntriesByModule, awaitedDynamicEntries, allEntriesAndManualChunks, dynamicEntry => dynamicEntry.includedTopLevelAwaitingDynamicImporters),
22028
+ dynamicallyDependentEntriesByAwaitedDynamicEntry: addAwaitingEntries(getDynamicallyDependentEntriesByDynamicEntry(dependentEntriesByModule, awaitedDynamicEntries, allEntriesAndManualChunks, dynamicEntry => dynamicEntry.includedTopLevelAwaitingDynamicImporters), awaitedDynamicImportsByEntry),
21916
22029
  dynamicallyDependentEntriesByDynamicEntry: getDynamicallyDependentEntriesByDynamicEntry(dependentEntriesByModule, dynamicEntries, allEntriesAndManualChunks, dynamicEntry => dynamicEntry.includedDynamicImporters),
21917
22030
  dynamicImportsByEntry,
21918
22031
  entriesAndManualChunksCount: allEntriesAndManualChunks.length
@@ -21954,6 +22067,18 @@ function getDynamicImportsByEntry(dynamicImportModulesByEntry, entryIndexByModul
21954
22067
  }
21955
22068
  return dynamicImportsByEntry;
21956
22069
  }
22070
+ // A dynamic entry can be awaited by an entry even if the importing module does
22071
+ // not have a top-level await itself, e.g. if the import is inside a function
22072
+ // that is awaited in the entry. In that case, the entry is still evaluating
22073
+ // when the dynamic entry is executed, so we add all awaiting entries here.
22074
+ function addAwaitingEntries(dynamicallyDependentEntriesByAwaitedDynamicEntry, awaitedDynamicImportsByEntry) {
22075
+ for (const [entryIndex, awaitedDynamicImports] of awaitedDynamicImportsByEntry.entries()) {
22076
+ for (const dynamicEntryIndex of awaitedDynamicImports) {
22077
+ getOrCreate(dynamicallyDependentEntriesByAwaitedDynamicEntry, dynamicEntryIndex, (getNewSet)).add(entryIndex);
22078
+ }
22079
+ }
22080
+ return dynamicallyDependentEntriesByAwaitedDynamicEntry;
22081
+ }
21957
22082
  function getDynamicallyDependentEntriesByDynamicEntry(dependentEntriesByModule, dynamicEntries, allEntriesAndManualChunks, getDynamicImporters) {
21958
22083
  const dynamicallyDependentEntriesByDynamicEntry = new Map();
21959
22084
  for (const dynamicEntryIndex of dynamicEntries) {
@@ -22048,6 +22173,34 @@ function getAlreadyLoadedAtomsByEntry(staticDependencyAtomsByEntry, dynamicallyD
22048
22173
  }
22049
22174
  return alreadyLoadedAtomsByEntry;
22050
22175
  }
22176
+ // Warning: This will consume dynamicallyDependentEntriesByAwaitedDynamicEntry.
22177
+ function getAwaitedAlreadyLoadedAtomsByEntry(staticDependencyAtomsByEntry, dynamicallyDependentEntriesByAwaitedDynamicEntry, awaitedDynamicImportsByEntry, allEntriesCount) {
22178
+ // Unlike already loaded atoms, this is a union and not an intersection: If
22179
+ // any importer that is still evaluating while it awaits a dynamic entry has
22180
+ // loaded an atom, merging that atom into the chunk of this importer would
22181
+ // create a cycle. Entries that are not awaited have no such atoms.
22182
+ const awaitedAlreadyLoadedAtomsByEntry = new Array(allEntriesCount).fill(0n);
22183
+ for (const [dynamicEntryIndex, dynamicallyDependentEntries] of dynamicallyDependentEntriesByAwaitedDynamicEntry) {
22184
+ // We delete here so that they can be added again if necessary to be handled
22185
+ // again by the loop
22186
+ dynamicallyDependentEntriesByAwaitedDynamicEntry.delete(dynamicEntryIndex);
22187
+ const knownLoadedAtoms = awaitedAlreadyLoadedAtomsByEntry[dynamicEntryIndex];
22188
+ let updatedLoadedAtoms = knownLoadedAtoms;
22189
+ for (const entryIndex of dynamicallyDependentEntries) {
22190
+ updatedLoadedAtoms |=
22191
+ staticDependencyAtomsByEntry[entryIndex] | awaitedAlreadyLoadedAtomsByEntry[entryIndex];
22192
+ }
22193
+ // If the knownLoadedAtoms changed, all awaited dynamic imports of this
22194
+ // entry need to be updated again
22195
+ if (updatedLoadedAtoms !== knownLoadedAtoms) {
22196
+ awaitedAlreadyLoadedAtomsByEntry[dynamicEntryIndex] = updatedLoadedAtoms;
22197
+ for (const dynamicImport of awaitedDynamicImportsByEntry[dynamicEntryIndex]) {
22198
+ getOrCreate(dynamicallyDependentEntriesByAwaitedDynamicEntry, dynamicImport, (getNewSet)).add(dynamicEntryIndex);
22199
+ }
22200
+ }
22201
+ }
22202
+ return awaitedAlreadyLoadedAtomsByEntry;
22203
+ }
22051
22204
  /**
22052
22205
  * This removes all unnecessary dynamic entries from the dependentEntries in its
22053
22206
  * first argument if a chunk is already loaded without that entry.
@@ -24692,17 +24845,17 @@ async function rollupInternal(rawInputOptions, registerWatchHooks) {
24692
24845
  ...error_,
24693
24846
  message: `There was an error during the build:\n ${error_.message}\nAdditionally, handling the error in the 'buildEnd' hook caused the following error:\n ${buildEndError.message}`
24694
24847
  });
24695
- await graph.pluginDriver.hookParallel('closeBundle', [compoundError]);
24848
+ await graph.pluginDriver.hookParallel('closeBundle', [compoundError]).catch(() => { });
24696
24849
  throw compoundError;
24697
24850
  }
24698
- await graph.pluginDriver.hookParallel('closeBundle', [error_]);
24851
+ await graph.pluginDriver.hookParallel('closeBundle', [error_]).catch(() => { });
24699
24852
  throw error_;
24700
24853
  }
24701
24854
  try {
24702
24855
  await graph.pluginDriver.hookParallel('buildEnd', []);
24703
24856
  }
24704
24857
  catch (buildEndError) {
24705
- await graph.pluginDriver.hookParallel('closeBundle', [buildEndError]);
24858
+ await graph.pluginDriver.hookParallel('closeBundle', [buildEndError]).catch(() => { });
24706
24859
  throw buildEndError;
24707
24860
  }
24708
24861
  });