rollup 4.55.2 → 4.56.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,13 +1,13 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v4.55.2
4
- Mon, 19 Jan 2026 10:12:51 GMT - commit bd293ba3739e20b00a520e2a77acbb2377c76732
3
+ Rollup.js v4.56.0
4
+ Thu, 22 Jan 2026 05:37:20 GMT - commit 1cbac18d9fb153db123d8f266947c5a5acfa387f
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
8
8
  Released under the MIT License.
9
9
  */
10
- import { EMPTY_OBJECT, ExportDefaultDeclaration as ExportDefaultDeclaration$1, CallExpression as CallExpression$1, EMPTY_ARRAY, LOGLEVEL_WARN, logUnusedExternalImports, ANNOTATION_KEY, INVALID_ANNOTATION_KEY, ArrowFunctionExpression as ArrowFunctionExpression$1, FunctionExpression as FunctionExpression$1, MemberExpression as MemberExpression$1, Identifier as Identifier$1, ImportExpression as ImportExpression$1, AwaitExpression as AwaitExpression$1, ObjectExpression as ObjectExpression$1, Property as Property$1, Program as Program$1, logIllegalImportReassignment, BLANK, logRedeclarationError, StaticBlock as StaticBlock$1, CatchClause as CatchClause$1, logDuplicateArgumentNameError, logModuleLevelDirective, ReturnStatement as ReturnStatement$1, VariableDeclarator as VariableDeclarator$1, ExpressionStatement as ExpressionStatement$1, logMissingExport, normalize, getImportPath, logMissingNodeBuiltins, logReservedNamespace, error, logIllegalIdentifierAsName, logMissingNameOptionForIifeExport, logMissingNameOptionForUmdExport, RestElement as RestElement$1, logConstVariableReassignError, EMPTY_SET, logCannotCallNamespace, logEval, BlockStatement as BlockStatement$1, getRollupError, logModuleParseError, logParseError, LOGLEVEL_INFO, logFirstSideEffect, locate, logInvalidAnnotation, logThisIsUndefined, getAstBuffer, convertAnnotations, FIXED_STRINGS, convertNode as convertNode$1, logImportAttributeIsInvalid, logImportOptionsAreInvalid, logSyntheticNamedExportsNeedNamespaceExport, logMissingEntryExport, logDuplicateExportError, logInvalidSourcemapForError, augmentCodeLocation, logInconsistentImportAttributes, logMissingJsxExport, logNamespaceConflict, logAmbiguousExternalNamespaces, logShimmedExport, parseAst, logInvalidFormatForTopLevelAwait, TemplateLiteral as TemplateLiteral$1, Literal as Literal$1, logCircularReexport, logAddonNotGenerated, logIncompatibleExportOptionValue, logMixedExport, logFailedValidation, isPathFragment, logCyclicCrossChunkReexport, getAliasName, logUnexpectedNamedImport, isAbsolute as isAbsolute$1, relative as relative$1, logUnexpectedNamespaceReexport, logEmptyChunk, logMissingGlobalName, logOptimizeChunkStatus, logSourcemapBroken, logConflictingSourcemapSources, logChunkInvalid, logInvalidOption, URL_OUTPUT_FORMAT, URL_OUTPUT_DIR, URL_OUTPUT_SOURCEMAPFILE, URL_OUTPUT_AMD_ID, logCannotAssignModuleToChunk, logCircularChunk, logAnonymousPluginCache, logDuplicatePluginName, logUnknownOption, LOGLEVEL_ERROR, logLevelPriority, LOGLEVEL_DEBUG, printQuotedStringList, logInvalidSetAssetSourceCall, logPluginError, logNoTransformMapOrAstWithoutCode, relativeId, logBadLoader, logExternalModulesCannotBeTransformedToModules, logInternalIdCannotBeExternal, isRelative, logUnresolvedImport, logUnresolvedImportTreatedAsExternal, logExternalSyntheticExports, logUnresolvedEntry, logUnresolvedImplicitDependant, logExternalModulesCannotBeIncludedInManualChunks, logEntryCannotBeExternal, logImplicitDependantCannotBeExternal, logNoAssetSourceSet, logFileReferenceIdNotFoundForFilename, logAssetReferenceIdNotFoundForSetSource, logAssetSourceAlreadySet, logInvalidRollupPhaseForChunkEmission, warnDeprecation, logChunkNotGeneratedForFileName, logAssetNotFinalisedForFileName, logFileNameConflict, URL_GENERATEBUNDLE, logInvalidLogPosition, logInputHookInOutputPlugin, logInvalidAddonPluginHook, logInvalidFunctionPluginHook, logImplicitDependantIsNotIncluded, logCircularDependency, augmentLogMessage, URL_JSX, URL_TREESHAKE_MODULESIDEEFFECTS, URL_TREESHAKE, URL_OUTPUT_INLINEDYNAMICIMPORTS, URL_PRESERVEENTRYSIGNATURES, URL_OUTPUT_GENERATEDCODE, isValidUrl, addTrailingSlashIfMissed, URL_OUTPUT_SOURCEMAPBASEURL, URL_OUTPUT_MANUALCHUNKS, logInvalidExportOptionValue, URL_OUTPUT_AMD_BASEPATH, URL_OUTPUT_INTEROP, URL_OUTPUT_EXTERNALIMPORTATTRIBUTES, logAlreadyClosed, logMissingFileOrDirOption, logCannotEmitFromOptionsHook, URL_WATCH } from './parseAst.js';
10
+ import { EMPTY_OBJECT, ExportDefaultDeclaration as ExportDefaultDeclaration$1, CallExpression as CallExpression$1, EMPTY_ARRAY, LOGLEVEL_WARN, logUnusedExternalImports, ANNOTATION_KEY, INVALID_ANNOTATION_KEY, ExpressionStatement as ExpressionStatement$1, AwaitExpression as AwaitExpression$1, MemberExpression as MemberExpression$1, Identifier as Identifier$1, FunctionExpression as FunctionExpression$1, ArrowFunctionExpression as ArrowFunctionExpression$1, ObjectExpression as ObjectExpression$1, Property as Property$1, Program as Program$1, logIllegalImportReassignment, BLANK, logRedeclarationError, StaticBlock as StaticBlock$1, CatchClause as CatchClause$1, logDuplicateArgumentNameError, logModuleLevelDirective, ReturnStatement as ReturnStatement$1, VariableDeclarator as VariableDeclarator$1, logMissingExport, normalize, getImportPath, logMissingNodeBuiltins, logReservedNamespace, error, logIllegalIdentifierAsName, logMissingNameOptionForIifeExport, logMissingNameOptionForUmdExport, RestElement as RestElement$1, logConstVariableReassignError, EMPTY_SET, logCannotCallNamespace, logEval, BlockStatement as BlockStatement$1, getRollupError, logModuleParseError, logParseError, LOGLEVEL_INFO, logFirstSideEffect, locate, logInvalidAnnotation, logThisIsUndefined, getAstBuffer, convertAnnotations, FIXED_STRINGS, convertNode as convertNode$1, logImportAttributeIsInvalid, logImportOptionsAreInvalid, logMissingEntryExport, logSyntheticNamedExportsNeedNamespaceExport, logDuplicateExportError, logInvalidSourcemapForError, augmentCodeLocation, logInconsistentImportAttributes, logMissingJsxExport, logNamespaceConflict, logAmbiguousExternalNamespaces, logShimmedExport, parseAst, TemplateLiteral as TemplateLiteral$1, Literal as Literal$1, logCircularReexport, logInvalidFormatForTopLevelAwait, logAddonNotGenerated, logIncompatibleExportOptionValue, logMixedExport, logFailedValidation, isPathFragment, logCyclicCrossChunkReexport, getAliasName, logUnexpectedNamedImport, isAbsolute as isAbsolute$1, relative as relative$1, logUnexpectedNamespaceReexport, logEmptyChunk, logMissingGlobalName, logOptimizeChunkStatus, logSourcemapBroken, logConflictingSourcemapSources, logChunkInvalid, logInvalidOption, URL_OUTPUT_FORMAT, URL_OUTPUT_DIR, URL_OUTPUT_SOURCEMAPFILE, URL_OUTPUT_AMD_ID, logCannotAssignModuleToChunk, logCircularChunk, logAnonymousPluginCache, logDuplicatePluginName, logUnknownOption, printQuotedStringList, LOGLEVEL_ERROR, logLevelPriority, LOGLEVEL_DEBUG, logInvalidSetAssetSourceCall, logPluginError, logNoTransformMapOrAstWithoutCode, relativeId, logBadLoader, logInternalIdCannotBeExternal, isRelative, logUnresolvedImport, logUnresolvedImportTreatedAsExternal, logExternalSyntheticExports, logUnresolvedEntry, logUnresolvedImplicitDependant, logExternalModulesCannotBeIncludedInManualChunks, logEntryCannotBeExternal, logImplicitDependantCannotBeExternal, logExternalModulesCannotBeTransformedToModules, logNoAssetSourceSet, logFileReferenceIdNotFoundForFilename, logAssetReferenceIdNotFoundForSetSource, logAssetSourceAlreadySet, logInvalidRollupPhaseForChunkEmission, warnDeprecation, logChunkNotGeneratedForFileName, logAssetNotFinalisedForFileName, logFileNameConflict, URL_GENERATEBUNDLE, logInvalidLogPosition, logInputHookInOutputPlugin, logInvalidAddonPluginHook, logInvalidFunctionPluginHook, logImplicitDependantIsNotIncluded, logCircularDependency, augmentLogMessage, URL_JSX, URL_TREESHAKE, URL_TREESHAKE_MODULESIDEEFFECTS, URL_OUTPUT_INLINEDYNAMICIMPORTS, URL_PRESERVEENTRYSIGNATURES, URL_OUTPUT_GENERATEDCODE, isValidUrl, addTrailingSlashIfMissed, URL_OUTPUT_SOURCEMAPBASEURL, URL_OUTPUT_MANUALCHUNKS, logInvalidExportOptionValue, URL_OUTPUT_AMD_BASEPATH, URL_OUTPUT_INTEROP, URL_OUTPUT_EXTERNALIMPORTATTRIBUTES, logAlreadyClosed, logMissingFileOrDirOption, logCannotEmitFromOptionsHook, URL_WATCH } from './parseAst.js';
11
11
  import { relative, dirname, basename, extname, resolve as resolve$1 } from 'node:path';
12
12
  import { posix, isAbsolute, resolve, win32 } from 'path';
13
13
  import { parseAsync, xxhashBase16, xxhashBase64Url, xxhashBase36 } from '../../native.js';
@@ -27,7 +27,7 @@ function _mergeNamespaces(n, m) {
27
27
  return Object.defineProperty(n, Symbol.toStringTag, { value: 'Module' });
28
28
  }
29
29
 
30
- var version = "4.55.2";
30
+ var version = "4.56.0";
31
31
 
32
32
  // src/vlq.ts
33
33
  var comma = ",".charCodeAt(0);
@@ -3027,15 +3027,15 @@ function isCallExpressionNode(node) {
3027
3027
  function isMemberExpressionNode(node) {
3028
3028
  return node instanceof NodeBase && node.type === MemberExpression$1;
3029
3029
  }
3030
- function isImportExpressionNode(node) {
3031
- return node instanceof NodeBase && node.type === ImportExpression$1;
3032
- }
3033
3030
  function isAwaitExpressionNode(node) {
3034
3031
  return node instanceof NodeBase && node.type === AwaitExpression$1;
3035
3032
  }
3036
3033
  function isIdentifierNode(node) {
3037
3034
  return node instanceof NodeBase && node.type === Identifier$1;
3038
3035
  }
3036
+ function isExpressionStatementNode(node) {
3037
+ return node instanceof NodeBase && node.type === ExpressionStatement$1;
3038
+ }
3039
3039
 
3040
3040
  function assembleMemberDescriptions(memberDescriptions, inheritedDescriptions = null) {
3041
3041
  return Object.create(inheritedDescriptions, memberDescriptions);
@@ -5193,21 +5193,6 @@ class LocalVariable extends Variable {
5193
5193
  break;
5194
5194
  node = node.parent;
5195
5195
  }
5196
- /**
5197
- * import('foo').then(m => {
5198
- * console.log(m.foo)
5199
- * })
5200
- */
5201
- if (this.kind === 'parameter' &&
5202
- (isArrowFunctionExpressionNode(declaration.parent) ||
5203
- isFunctionExpressionNode(declaration.parent)) &&
5204
- isCallExpressionNode(declaration.parent.parent) &&
5205
- isMemberExpressionNode(declaration.parent.parent.callee) &&
5206
- isIdentifierNode(declaration.parent.parent.callee.property) &&
5207
- declaration.parent.parent.callee.property.name === 'then' &&
5208
- isImportExpressionNode(declaration.parent.parent.callee.object)) {
5209
- declaration.parent.parent.callee.object.includePath(path, context);
5210
- }
5211
5196
  }
5212
5197
  // We need to make sure we include the correct path of the init
5213
5198
  if (path.length > 0) {
@@ -6533,7 +6518,7 @@ class ExpressionStatement extends NodeBase {
6533
6518
  render(code, options) {
6534
6519
  super.render(code, options);
6535
6520
  if (code.original[this.end - 1] !== ';') {
6536
- code.appendRight(this.end, ';');
6521
+ code.appendLeft(this.end, ';');
6537
6522
  }
6538
6523
  }
6539
6524
  shouldBeIncluded(context) {
@@ -7367,6 +7352,7 @@ function getStringFromPath(path) {
7367
7352
  class MemberExpression extends NodeBase {
7368
7353
  constructor() {
7369
7354
  super(...arguments);
7355
+ this.promiseHandler = null;
7370
7356
  this.variable = null;
7371
7357
  this.expressionsToBeDeoptimized = [];
7372
7358
  }
@@ -7422,7 +7408,10 @@ class MemberExpression extends NodeBase {
7422
7408
  }
7423
7409
  }
7424
7410
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
7425
- if (this.variable) {
7411
+ if (this.promiseHandler) {
7412
+ this.promiseHandler.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
7413
+ }
7414
+ else if (this.variable) {
7426
7415
  this.variable.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
7427
7416
  }
7428
7417
  else if (!this.isUndefined) {
@@ -7612,25 +7601,14 @@ class MemberExpression extends NodeBase {
7612
7601
  this.property.include(context, includeChildrenRecursively);
7613
7602
  }
7614
7603
  includeCallArguments(interaction, context) {
7615
- if (this.variable) {
7604
+ if (this.promiseHandler) {
7605
+ this.promiseHandler.includeCallArguments(interaction, context);
7606
+ }
7607
+ else if (this.variable) {
7616
7608
  this.variable.includeCallArguments(interaction, context);
7617
7609
  }
7618
7610
  else {
7619
- if (isImportExpressionNode(this.object) ||
7620
- /**
7621
- * const c = await import('foo')
7622
- * c.foo();
7623
- */
7624
- (this.object.variable &&
7625
- !this.object.variable.isReassigned &&
7626
- this.object.variable instanceof LocalVariable &&
7627
- isAwaitExpressionNode(this.object.variable.init) &&
7628
- isImportExpressionNode(this.object.variable.init.argument))) {
7629
- includeInteractionWithoutThis(interaction, context);
7630
- }
7631
- else {
7632
- includeInteraction(interaction, context);
7633
- }
7611
+ includeInteraction(interaction, context);
7634
7612
  }
7635
7613
  }
7636
7614
  includeDestructuredIfNecessary() {
@@ -7678,7 +7656,7 @@ class MemberExpression extends NodeBase {
7678
7656
  // Namespaces are not bound and should not be deoptimized
7679
7657
  this.bound &&
7680
7658
  propertyReadSideEffects &&
7681
- !(this.variable || this.isUndefined)) {
7659
+ !(this.variable || this.isUndefined || this.promiseHandler)) {
7682
7660
  this.object.deoptimizeArgumentsOnInteractionAtPath(this.accessInteraction, [this.propertyKey], SHARED_RECURSION_TRACKER);
7683
7661
  this.scope.context.requestTreeshakingPass();
7684
7662
  }
@@ -7986,8 +7964,9 @@ class ExportDefaultVariable extends LocalVariable {
7986
7964
  class NamespaceVariable extends Variable {
7987
7965
  constructor(context) {
7988
7966
  super(context.getModuleName());
7989
- this.memberVariables = null;
7967
+ this.areAllMembersDeoptimized = false;
7990
7968
  this.mergedNamespaces = [];
7969
+ this.nonExplicitNamespacesIncluded = false;
7991
7970
  this.referencedEarly = false;
7992
7971
  this.references = [];
7993
7972
  this.context = context;
@@ -8001,7 +7980,10 @@ class NamespaceVariable extends Variable {
8001
7980
  if (path.length > 1 || (path.length === 1 && interaction.type === INTERACTION_CALLED)) {
8002
7981
  const key = path[0];
8003
7982
  if (typeof key === 'string') {
8004
- this.getMemberVariables()[key]?.deoptimizeArgumentsOnInteractionAtPath(interaction, path.slice(1), recursionTracker);
7983
+ this.module
7984
+ .getExportedVariablesByName()
7985
+ .get(key)
7986
+ ?.deoptimizeArgumentsOnInteractionAtPath(interaction, path.slice(1), recursionTracker);
8005
7987
  }
8006
7988
  else {
8007
7989
  deoptimizeInteraction(interaction);
@@ -8012,7 +7994,13 @@ class NamespaceVariable extends Variable {
8012
7994
  if (path.length > 1) {
8013
7995
  const key = path[0];
8014
7996
  if (typeof key === 'string') {
8015
- this.getMemberVariables()[key]?.deoptimizePath(path.slice(1));
7997
+ this.module.getExportedVariablesByName().get(key)?.deoptimizePath(path.slice(1));
7998
+ }
7999
+ else if (!this.areAllMembersDeoptimized) {
8000
+ this.areAllMembersDeoptimized = true;
8001
+ for (const variable of this.module.getExportedVariablesByName().values()) {
8002
+ variable.deoptimizePath(UNKNOWN_PATH);
8003
+ }
8016
8004
  }
8017
8005
  }
8018
8006
  }
@@ -8022,22 +8010,6 @@ class NamespaceVariable extends Variable {
8022
8010
  }
8023
8011
  return UnknownValue;
8024
8012
  }
8025
- getMemberVariables() {
8026
- if (this.memberVariables) {
8027
- return this.memberVariables;
8028
- }
8029
- const memberVariables = Object.create(null);
8030
- const sortedExports = [...this.context.getExports(), ...this.context.getReexports()].sort();
8031
- for (const name of sortedExports) {
8032
- if (name[0] !== '*' && name !== this.module.info.syntheticNamedExports) {
8033
- const [exportedVariable] = this.context.traceExport(name);
8034
- if (exportedVariable) {
8035
- memberVariables[name] = exportedVariable;
8036
- }
8037
- }
8038
- }
8039
- return (this.memberVariables = memberVariables);
8040
- }
8041
8013
  hasEffectsOnInteractionAtPath(path, interaction, context) {
8042
8014
  const { type } = interaction;
8043
8015
  if (path.length === 0) {
@@ -8051,13 +8023,31 @@ class NamespaceVariable extends Variable {
8051
8023
  if (typeof key !== 'string') {
8052
8024
  return true;
8053
8025
  }
8054
- const memberVariable = this.getMemberVariables()[key];
8026
+ const memberVariable = this.module.getExportedVariablesByName().get(key);
8055
8027
  return (!memberVariable ||
8056
8028
  memberVariable.hasEffectsOnInteractionAtPath(path.slice(1), interaction, context));
8057
8029
  }
8058
8030
  includePath(path, context) {
8059
8031
  super.includePath(path, context);
8060
- this.context.includeAllExports();
8032
+ this.includeMemberPath(path, context);
8033
+ }
8034
+ includeMemberPath(path, context) {
8035
+ if (path.length > 0) {
8036
+ const [name, ...remainingPath] = path;
8037
+ if (typeof name === 'string') {
8038
+ const variable = this.module.getExportedVariablesByName().get(name);
8039
+ if (variable) {
8040
+ this.context.includeVariableInModule(variable, remainingPath, context);
8041
+ }
8042
+ else {
8043
+ this.includeNonExplicitNamespaces();
8044
+ }
8045
+ }
8046
+ else if (name) {
8047
+ this.module.includeAllExports();
8048
+ this.includeNonExplicitNamespaces();
8049
+ }
8050
+ }
8061
8051
  }
8062
8052
  prepare(accessedGlobalsByScope) {
8063
8053
  if (this.mergedNamespaces.length > 0) {
@@ -8066,9 +8056,9 @@ class NamespaceVariable extends Variable {
8066
8056
  }
8067
8057
  renderBlock(options) {
8068
8058
  const { exportNamesByVariable, format, freeze, indent: t, symbols, snippets: { _, cnst, getObject, getPropertyAccess, n, s } } = options;
8069
- const memberVariables = this.getMemberVariables();
8070
- const members = Object.entries(memberVariables)
8071
- .filter(([_, variable]) => variable.included)
8059
+ const memberVariables = this.module.getExportedVariablesByName();
8060
+ const members = [...memberVariables.entries()]
8061
+ .filter(([name, variable]) => !name.startsWith('*') && variable.included)
8072
8062
  .map(([name, variable]) => {
8073
8063
  if (this.referencedEarly || variable.isReassigned || variable === this) {
8074
8064
  return [
@@ -8114,8 +8104,22 @@ class NamespaceVariable extends Variable {
8114
8104
  }
8115
8105
  }
8116
8106
  }
8107
+ includeNonExplicitNamespaces() {
8108
+ if (!this.nonExplicitNamespacesIncluded) {
8109
+ this.nonExplicitNamespacesIncluded = true;
8110
+ this.setMergedNamespaces(this.module.includeAndGetAdditionalMergedNamespaces());
8111
+ }
8112
+ }
8117
8113
  }
8118
8114
  NamespaceVariable.prototype.isNamespace = true;
8115
+ // This is a proxy that does not include the namespace object when a path is included
8116
+ const getDynamicNamespaceVariable = (namespace) => Object.create(namespace, {
8117
+ includePath: {
8118
+ value(path, context) {
8119
+ namespace.includeMemberPath(path, context);
8120
+ }
8121
+ }
8122
+ });
8119
8123
 
8120
8124
  class SyntheticNamedExportVariable extends Variable {
8121
8125
  constructor(context, name, syntheticNamespace) {
@@ -8151,7 +8155,7 @@ class SyntheticNamedExportVariable extends Variable {
8151
8155
  }
8152
8156
  includePath(path, context) {
8153
8157
  super.includePath(path, context);
8154
- this.context.includeVariableInModule(this.syntheticNamespace, path, context);
8158
+ this.context.includeVariableInModule(this.syntheticNamespace, [this.name, ...path], context);
8155
8159
  }
8156
8160
  setRenderNames(baseName, name) {
8157
8161
  super.setRenderNames(baseName, name);
@@ -11832,6 +11836,9 @@ class AssignmentPattern extends NodeBase {
11832
11836
  }
11833
11837
 
11834
11838
  class AwaitExpression extends NodeBase {
11839
+ deoptimizePath(path) {
11840
+ this.argument.deoptimizePath(path);
11841
+ }
11835
11842
  hasEffects() {
11836
11843
  if (!this.deoptimized)
11837
11844
  this.applyDeoptimizations();
@@ -12234,11 +12241,10 @@ class CallExpression extends CallExpressionBase {
12234
12241
  this.callee.includeCallArguments(this.interaction, context);
12235
12242
  }
12236
12243
  }
12237
- includeNode(context) {
12244
+ includeNode(_context) {
12238
12245
  this.included = true;
12239
12246
  if (!this.deoptimized)
12240
12247
  this.applyDeoptimizations();
12241
- this.callee.includePath(UNKNOWN_PATH, context);
12242
12248
  }
12243
12249
  initialise() {
12244
12250
  super.initialise();
@@ -13096,95 +13102,41 @@ class ImportDefaultSpecifier extends NodeBase {
13096
13102
  ImportDefaultSpecifier.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
13097
13103
  ImportDefaultSpecifier.prototype.applyDeoptimizations = doNotDeoptimize;
13098
13104
 
13099
- function isReassignedExportsMember(variable, exportNamesByVariable) {
13100
- return (variable.renderBaseName !== null && exportNamesByVariable.has(variable) && variable.isReassigned);
13101
- }
13102
-
13103
- class VariableDeclarator extends NodeBase {
13104
- declareDeclarator(kind) {
13105
- this.isUsingDeclaration = kind === 'using';
13106
- this.isAsyncUsingDeclaration = kind === 'await using';
13107
- this.id.declare(kind, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION);
13108
- }
13109
- deoptimizePath(path) {
13110
- this.id.deoptimizePath(path);
13111
- }
13112
- hasEffects(context) {
13113
- const initEffect = this.init?.hasEffects(context);
13114
- this.id.markDeclarationReached();
13115
- return (initEffect ||
13116
- this.isUsingDeclaration ||
13117
- this.isAsyncUsingDeclaration ||
13118
- this.id.hasEffects(context) ||
13119
- (this.scope.context.options.treeshake
13120
- .propertyReadSideEffects &&
13121
- this.id.hasEffectsWhenDestructuring(context, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION)));
13105
+ class ObjectPromiseHandler {
13106
+ constructor(resolvedVariable) {
13107
+ this.interaction = {
13108
+ args: [null, resolvedVariable],
13109
+ type: INTERACTION_CALLED,
13110
+ withNew: false
13111
+ };
13122
13112
  }
13123
- include(context, includeChildrenRecursively) {
13124
- const { id, init } = this;
13125
- if (!this.included)
13126
- this.includeNode(context);
13127
- init?.include(context, includeChildrenRecursively);
13128
- id.markDeclarationReached();
13129
- if (includeChildrenRecursively) {
13130
- id.include(context, includeChildrenRecursively);
13131
- }
13132
- else {
13133
- id.includeDestructuredIfNecessary(context, EMPTY_PATH, init || UNDEFINED_EXPRESSION);
13113
+ deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
13114
+ deoptimizeInteraction(interaction);
13115
+ if (interaction.type === INTERACTION_CALLED &&
13116
+ path.length === 0 &&
13117
+ (isFunctionExpressionNode(interaction.args[1]) ||
13118
+ isArrowFunctionExpressionNode(interaction.args[1]))) {
13119
+ interaction.args[1].deoptimizeArgumentsOnInteractionAtPath(this.interaction, [], recursionTracker);
13134
13120
  }
13135
13121
  }
13136
- removeAnnotations(code) {
13137
- this.init?.removeAnnotations(code);
13138
- }
13139
- render(code, options) {
13140
- const { exportNamesByVariable, snippets: { _, getPropertyAccess } } = options;
13141
- const { end, id, init, start } = this;
13142
- const renderId = id.included || this.isUsingDeclaration || this.isAsyncUsingDeclaration;
13143
- if (renderId) {
13144
- id.render(code, options);
13145
- }
13146
- else {
13147
- const operatorPos = findFirstOccurrenceOutsideComment(code.original, '=', id.end);
13148
- code.remove(start, findNonWhiteSpace(code.original, operatorPos + 1));
13149
- }
13150
- if (init) {
13151
- if (id instanceof Identifier && init instanceof ClassExpression && !init.id) {
13152
- const renderedVariable = id.variable.getName(getPropertyAccess);
13153
- if (renderedVariable !== id.name) {
13154
- code.appendLeft(init.start + 5, ` ${id.name}`);
13155
- }
13156
- }
13157
- init.render(code, options, renderId ? BLANK : { renderedSurroundingElement: ExpressionStatement$1 });
13158
- }
13159
- else if (id instanceof Identifier &&
13160
- isReassignedExportsMember(id.variable, exportNamesByVariable)) {
13161
- code.appendLeft(end, `${_}=${_}void 0`);
13122
+ includeCallArguments(interaction, context) {
13123
+ // This includes the function call itself
13124
+ includeInteractionWithoutThis(interaction, context);
13125
+ if (interaction.type === INTERACTION_CALLED &&
13126
+ (isFunctionExpressionNode(interaction.args[1]) ||
13127
+ isArrowFunctionExpressionNode(interaction.args[1]))) {
13128
+ interaction.args[1].includeCallArguments(this.interaction, context);
13162
13129
  }
13163
13130
  }
13164
- includeNode(context) {
13165
- this.included = true;
13166
- const { id, init } = this;
13167
- if (init) {
13168
- if (this.isUsingDeclaration) {
13169
- init.includePath(SYMBOL_DISPOSE_PATH, context);
13170
- }
13171
- else if (this.isAsyncUsingDeclaration) {
13172
- init.includePath(SYMBOL_ASYNC_DISPOSE_PATH, context);
13173
- }
13174
- if (id instanceof Identifier && init instanceof ClassExpression && !init.id) {
13175
- const { name, variable } = id;
13176
- for (const accessedVariable of init.scope.accessedOutsideVariables.values()) {
13177
- if (accessedVariable !== variable) {
13178
- accessedVariable.forbidName(name);
13179
- }
13180
- }
13181
- }
13182
- }
13131
+ }
13132
+ class EmptyPromiseHandler {
13133
+ deoptimizeArgumentsOnInteractionAtPath(interaction) {
13134
+ deoptimizeInteraction(interaction);
13135
+ }
13136
+ includeCallArguments(interaction, context) {
13137
+ includeInteractionWithoutThis(interaction, context);
13183
13138
  }
13184
13139
  }
13185
- VariableDeclarator.prototype.applyDeoptimizations = doNotDeoptimize;
13186
- const SYMBOL_DISPOSE_PATH = [SymbolDispose];
13187
- const SYMBOL_ASYNC_DISPOSE_PATH = [SymbolAsyncDispose];
13188
13140
 
13189
13141
  function getChunkInfoWithPath(chunk) {
13190
13142
  return { fileName: chunk.getFileName(), ...chunk.getPreRenderedChunkInfo() };
@@ -13193,12 +13145,11 @@ class ImportExpression extends NodeBase {
13193
13145
  constructor() {
13194
13146
  super(...arguments);
13195
13147
  this.inlineNamespace = null;
13196
- this.hasUnknownAccessedKey = false;
13197
- this.accessedPropKey = new Set();
13148
+ this.resolution = null;
13198
13149
  this.attributes = null;
13199
13150
  this.mechanism = null;
13200
13151
  this.namespaceExportName = undefined;
13201
- this.resolution = null;
13152
+ this.localResolution = null;
13202
13153
  this.resolutionString = null;
13203
13154
  }
13204
13155
  get shouldIncludeDynamicAttributes() {
@@ -13208,84 +13159,65 @@ class ImportExpression extends NodeBase {
13208
13159
  this.flags = setFlag(this.flags, 268435456 /* Flag.shouldIncludeDynamicAttributes */, value);
13209
13160
  }
13210
13161
  bind() {
13211
- this.source.bind();
13212
- this.options?.bind();
13213
- }
13214
- /**
13215
- * Get imported variables for deterministic usage, valid cases are:
13216
- *
13217
- * 1. `const { foo } = await import('bar')`.
13218
- * 2. `(await import('bar')).foo`
13219
- * 3. `import('bar').then(({ foo }) => {})`
13220
- *
13221
- * Returns empty array if it's side-effect only import.
13222
- * Returns undefined if it's not fully deterministic.
13223
- */
13224
- getDeterministicImportedNames() {
13225
- const parent1 = this.parent;
13226
- // Side-effect only: import('bar')
13227
- if (parent1 instanceof ExpressionStatement) {
13228
- return EMPTY_ARRAY;
13229
- }
13230
- if (parent1 instanceof AwaitExpression) {
13231
- const parent2 = parent1.parent;
13232
- // Side effect only: await import('bar')
13233
- if (parent2 instanceof ExpressionStatement) {
13234
- return EMPTY_ARRAY;
13235
- }
13236
- // Case 1: const { foo } / module = await import('bar')
13237
- if (parent2 instanceof VariableDeclarator) {
13238
- const declaration = parent2.id;
13239
- if (declaration instanceof Identifier) {
13240
- return this.hasUnknownAccessedKey ? undefined : [...this.accessedPropKey];
13241
- }
13242
- if (declaration instanceof ObjectPattern) {
13243
- return getDeterministicObjectDestructure(declaration);
13244
- }
13245
- }
13246
- // Case 2: (await import('bar')).foo
13247
- if (parent2 instanceof MemberExpression) {
13248
- const id = parent2.property;
13249
- if (!parent2.computed && id instanceof Identifier) {
13250
- return [id.name];
13251
- }
13252
- }
13162
+ const { options, parent, resolution, source } = this;
13163
+ source.bind();
13164
+ options?.bind();
13165
+ // Check if we resolved to a Module without using instanceof
13166
+ if (typeof resolution !== 'object' || !resolution || !('namespace' in resolution)) {
13253
13167
  return;
13254
13168
  }
13255
- if (parent1 instanceof MemberExpression) {
13256
- const callExpression = parent1.parent;
13257
- const property = parent1.property;
13258
- if (!(callExpression instanceof CallExpression) || !(property instanceof Identifier)) {
13259
- return;
13260
- }
13261
- const memberName = property.name;
13262
- // side-effect only, when only chaining .catch or .finally
13263
- if (callExpression.parent instanceof ExpressionStatement &&
13264
- ['catch', 'finally'].includes(memberName)) {
13265
- return EMPTY_ARRAY;
13266
- }
13267
- if (memberName !== 'then')
13268
- return;
13269
- // Side-effect only: import('bar').then()
13270
- if (callExpression.arguments.length === 0) {
13271
- return EMPTY_ARRAY;
13272
- }
13273
- const thenCallback = callExpression.arguments[0];
13274
- if (callExpression.arguments.length !== 1 ||
13275
- !(thenCallback instanceof ArrowFunctionExpression ||
13276
- thenCallback instanceof FunctionExpression)) {
13277
- return;
13169
+ // In these cases, we can track exactly what is included or deoptimized:
13170
+ // * import('foo'); // as statement
13171
+ // * await import('foo') // use as awaited expression in any way
13172
+ // * import('foo').then(n => {...}) // only if .then is called directly on the import()
13173
+ if (isExpressionStatementNode(parent) || isAwaitExpressionNode(parent)) {
13174
+ this.localResolution = { resolution, tracked: true };
13175
+ return;
13176
+ }
13177
+ if (!isMemberExpressionNode(parent)) {
13178
+ this.localResolution = { resolution, tracked: false };
13179
+ return;
13180
+ }
13181
+ let currentParent = parent;
13182
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
13183
+ let callExpression = this;
13184
+ while (true) {
13185
+ if (currentParent.computed ||
13186
+ currentParent.object !== callExpression ||
13187
+ !isIdentifierNode(currentParent.property) ||
13188
+ !isCallExpressionNode(currentParent.parent)) {
13189
+ break;
13278
13190
  }
13279
- // Side-effect only: import('bar').then(() => {})
13280
- if (thenCallback.params.length === 0) {
13281
- return EMPTY_ARRAY;
13191
+ const propertyName = currentParent.property.name;
13192
+ callExpression = currentParent.parent;
13193
+ if (propertyName === 'then') {
13194
+ const firstArgument = callExpression.arguments[0];
13195
+ if (firstArgument === undefined ||
13196
+ isFunctionExpressionNode(firstArgument) ||
13197
+ isArrowFunctionExpressionNode(firstArgument)) {
13198
+ currentParent.promiseHandler = new ObjectPromiseHandler(getDynamicNamespaceVariable(resolution.namespace));
13199
+ this.localResolution = { resolution, tracked: true };
13200
+ return;
13201
+ }
13282
13202
  }
13283
- const declaration = thenCallback.params[0];
13284
- if (thenCallback.params.length === 1 && declaration instanceof ObjectPattern) {
13285
- return getDeterministicObjectDestructure(declaration);
13203
+ else if (propertyName === 'catch' || propertyName === 'finally') {
13204
+ if (isMemberExpressionNode(callExpression.parent)) {
13205
+ currentParent.promiseHandler = new EmptyPromiseHandler();
13206
+ currentParent = callExpression.parent;
13207
+ continue;
13208
+ }
13209
+ if (isExpressionStatementNode(callExpression.parent)) {
13210
+ currentParent.promiseHandler = new EmptyPromiseHandler();
13211
+ this.localResolution = { resolution, tracked: true };
13212
+ return;
13213
+ }
13286
13214
  }
13287
- return this.hasUnknownAccessedKey ? undefined : [...this.accessedPropKey];
13215
+ break;
13288
13216
  }
13217
+ this.localResolution = { resolution, tracked: false };
13218
+ }
13219
+ deoptimizePath(path) {
13220
+ this.localResolution?.resolution?.namespace.deoptimizePath(path);
13289
13221
  }
13290
13222
  hasEffects() {
13291
13223
  return true;
@@ -13294,30 +13226,31 @@ class ImportExpression extends NodeBase {
13294
13226
  if (!this.included)
13295
13227
  this.includeNode(context);
13296
13228
  this.source.include(context, includeChildrenRecursively);
13297
- if (this.shouldIncludeDynamicAttributes)
13229
+ if (this.shouldIncludeDynamicAttributes) {
13298
13230
  this.options?.include(context, includeChildrenRecursively);
13231
+ }
13299
13232
  }
13300
13233
  includeNode(context) {
13301
13234
  this.included = true;
13302
- if (this.shouldIncludeDynamicAttributes)
13235
+ const { localResolution, scope, shouldIncludeDynamicAttributes } = this;
13236
+ if (shouldIncludeDynamicAttributes) {
13303
13237
  this.options?.includePath(UNKNOWN_PATH, context);
13304
- this.scope.context.includeDynamicImport(this);
13305
- this.scope.addAccessedDynamicImport(this);
13238
+ }
13239
+ scope.context.includeDynamicImport(this);
13240
+ scope.addAccessedDynamicImport(this);
13241
+ if (localResolution) {
13242
+ if (localResolution.tracked) {
13243
+ localResolution.resolution.includeModuleInExecution();
13244
+ }
13245
+ else {
13246
+ localResolution.resolution.includeAllExports();
13247
+ }
13248
+ }
13306
13249
  }
13307
13250
  includePath(path, context) {
13308
13251
  if (!this.included)
13309
13252
  this.includeNode(context);
13310
- // Technically, this is not correct as dynamic imports return a Promise.
13311
- if (this.hasUnknownAccessedKey)
13312
- return;
13313
- if (path[0] === UnknownKey) {
13314
- this.hasUnknownAccessedKey = true;
13315
- }
13316
- else if (typeof path[0] === 'string') {
13317
- this.accessedPropKey.add(path[0]);
13318
- }
13319
- // Update included paths
13320
- this.scope.context.includeDynamicImport(this);
13253
+ this.localResolution?.resolution?.namespace.includeMemberPath(path, context);
13321
13254
  }
13322
13255
  initialise() {
13323
13256
  super.initialise();
@@ -13367,16 +13300,15 @@ class ImportExpression extends NodeBase {
13367
13300
  }
13368
13301
  }
13369
13302
  }
13370
- setExternalResolution(exportMode, resolution, options, snippets, pluginDriver, accessedGlobalsByScope, resolutionString, namespaceExportName, attributes, ownChunk, targetChunk) {
13303
+ setExternalResolution(exportMode, options, snippets, pluginDriver, accessedGlobalsByScope, resolutionString, namespaceExportName, attributes, ownChunk, targetChunk) {
13371
13304
  const { format } = options;
13372
13305
  this.inlineNamespace = null;
13373
- this.resolution = resolution;
13374
13306
  this.resolutionString = resolutionString;
13375
13307
  this.namespaceExportName = namespaceExportName;
13376
13308
  this.attributes = attributes;
13377
13309
  const accessedGlobals = [...(accessedImportGlobals[format] || [])];
13378
13310
  let helper;
13379
- ({ helper, mechanism: this.mechanism } = this.getDynamicImportMechanismAndHelper(resolution, exportMode, options, snippets, pluginDriver, ownChunk, targetChunk));
13311
+ ({ helper, mechanism: this.mechanism } = this.getDynamicImportMechanismAndHelper(exportMode, options, snippets, pluginDriver, ownChunk, targetChunk));
13380
13312
  if (helper) {
13381
13313
  accessedGlobals.push(helper);
13382
13314
  }
@@ -13387,11 +13319,12 @@ class ImportExpression extends NodeBase {
13387
13319
  setInternalResolution(inlineNamespace) {
13388
13320
  this.inlineNamespace = inlineNamespace;
13389
13321
  }
13390
- getDynamicImportMechanismAndHelper(resolution, exportMode, { compact, dynamicImportInCjs, format, generatedCode: { arrowFunctions }, interop }, { _, getDirectReturnFunction, getDirectReturnIifeLeft }, pluginDriver, ownChunk, targetChunk) {
13322
+ getDynamicImportMechanismAndHelper(exportMode, { compact, dynamicImportInCjs, format, generatedCode: { arrowFunctions }, interop }, { _, getDirectReturnFunction, getDirectReturnIifeLeft }, pluginDriver, ownChunk, targetChunk) {
13323
+ const { resolution, scope } = this;
13391
13324
  const mechanism = pluginDriver.hookFirstSync('renderDynamicImport', [
13392
13325
  {
13393
13326
  chunk: getChunkInfoWithPath(ownChunk),
13394
- customResolution: typeof this.resolution === 'string' ? this.resolution : null,
13327
+ customResolution: typeof resolution === 'string' ? resolution : null,
13395
13328
  format,
13396
13329
  getTargetChunkImports() {
13397
13330
  if (targetChunk === null)
@@ -13418,15 +13351,15 @@ class ImportExpression extends NodeBase {
13418
13351
  }
13419
13352
  return chunkInfos;
13420
13353
  },
13421
- moduleId: this.scope.context.module.id,
13354
+ moduleId: scope.context.module.id,
13422
13355
  targetChunk: targetChunk ? getChunkInfoWithPath(targetChunk) : null,
13423
- targetModuleId: this.resolution && typeof this.resolution !== 'string' ? this.resolution.id : null
13356
+ targetModuleId: resolution && typeof resolution !== 'string' ? resolution.id : null
13424
13357
  }
13425
13358
  ]);
13426
13359
  if (mechanism) {
13427
13360
  return { helper: null, mechanism };
13428
13361
  }
13429
- const hasDynamicTarget = !this.resolution || typeof this.resolution === 'string';
13362
+ const hasDynamicTarget = !resolution || typeof resolution === 'string';
13430
13363
  switch (format) {
13431
13364
  case 'cjs': {
13432
13365
  if (dynamicImportInCjs &&
@@ -13516,15 +13449,6 @@ const accessedImportGlobals = {
13516
13449
  cjs: ['require'],
13517
13450
  system: ['module']
13518
13451
  };
13519
- function getDeterministicObjectDestructure(objectPattern) {
13520
- const variables = [];
13521
- for (const property of objectPattern.properties) {
13522
- if (property.type === 'RestElement' || property.computed || property.key.type !== 'Identifier')
13523
- return;
13524
- variables.push(property.key.name);
13525
- }
13526
- return variables;
13527
- }
13528
13452
 
13529
13453
  class ImportNamespaceSpecifier extends NodeBase {
13530
13454
  }
@@ -13880,9 +13804,9 @@ class JSXElement extends JSXElementBase {
13880
13804
  }
13881
13805
  renderAutomaticMode(code, options) {
13882
13806
  const { snippets: { getPropertyAccess }, useOriginalName } = options;
13883
- const { closingElement, end, factoryVariable, openingElement: { end: openindEnd, selfClosing } } = this;
13807
+ const { closingElement, end, factoryVariable, openingElement: { end: openingEnd, selfClosing } } = this;
13884
13808
  let { firstAttribute, hasAttributes, hasSpread, inObject, keyAttribute, previousEnd } = this.renderAttributes(code, options, factoryVariable.getName(getPropertyAccess, useOriginalName), true);
13885
- const { firstChild, hasMultipleChildren, childrenEnd } = this.renderChildren(code, options, openindEnd);
13809
+ const { firstChild, hasMultipleChildren, childrenEnd } = this.renderChildren(code, options, openingEnd);
13886
13810
  if (firstChild) {
13887
13811
  code.prependRight(firstChild.start, `children: ${hasMultipleChildren ? '[' : ''}`);
13888
13812
  if (!inObject) {
@@ -13894,16 +13818,21 @@ class JSXElement extends JSXElementBase {
13894
13818
  code.appendLeft(previousEnd, ']');
13895
13819
  }
13896
13820
  }
13897
- this.wrapAttributes(code, inObject, hasAttributes || !!firstChild, hasSpread, firstAttribute || firstChild, '{}', childrenEnd);
13821
+ // This ensures that attributesEnd never corresponds to this.end. This is
13822
+ // important because we must never use code.move with this.end as target.
13823
+ // Otherwise, this would interfere with parent elements that try to append
13824
+ // code to this.end, which would appear BEFORE the moved code.
13825
+ const attributesEnd = firstChild ? childrenEnd : previousEnd;
13826
+ this.wrapAttributes(code, inObject, hasAttributes || !!firstChild, hasSpread, firstAttribute || firstChild, '{}', attributesEnd);
13898
13827
  if (keyAttribute) {
13899
13828
  const { value } = keyAttribute;
13900
13829
  // This will appear to the left of the moved code...
13901
- code.appendLeft(childrenEnd, ', ');
13830
+ code.appendLeft(attributesEnd, ', ');
13902
13831
  if (value) {
13903
- code.move(value.start, value.end, childrenEnd);
13832
+ code.move(value.start, value.end, attributesEnd);
13904
13833
  }
13905
13834
  else {
13906
- code.appendLeft(childrenEnd, 'true');
13835
+ code.appendLeft(attributesEnd, 'true');
13907
13836
  }
13908
13837
  }
13909
13838
  if (selfClosing) {
@@ -13953,9 +13882,7 @@ class JSXElement extends JSXElementBase {
13953
13882
  hasSpread = true;
13954
13883
  }
13955
13884
  previousEnd = attribute.end;
13956
- if (!firstAttribute) {
13957
- firstAttribute = attribute;
13958
- }
13885
+ firstAttribute ??= attribute;
13959
13886
  }
13960
13887
  code.remove(attributes.at(-1)?.end || previousEnd, openingEnd);
13961
13888
  return { firstAttribute, hasAttributes, hasSpread, inObject, keyAttribute, previousEnd };
@@ -14516,7 +14443,7 @@ ObjectExpression.prototype.applyDeoptimizations = doNotDeoptimize;
14516
14443
 
14517
14444
  class PanicError extends NodeBase {
14518
14445
  initialise() {
14519
- const id = this.scope.context.module.id;
14446
+ const { id } = this.scope.context.module;
14520
14447
  // This simulates the current nested error structure. We could also just
14521
14448
  // replace it with a flat error.
14522
14449
  const parseError = getRollupError(logParseError(this.message));
@@ -14528,7 +14455,7 @@ class PanicError extends NodeBase {
14528
14455
  class ParseError extends NodeBase {
14529
14456
  initialise() {
14530
14457
  const pos = this.start;
14531
- const id = this.scope.context.module.id;
14458
+ const { id } = this.scope.context.module;
14532
14459
  // This simulates the current nested error structure. We could also just
14533
14460
  // replace it with a flat error.
14534
14461
  const parseError = getRollupError(logParseError(this.message, pos));
@@ -14987,9 +14914,6 @@ class TaggedTemplateExpression extends CallExpressionBase {
14987
14914
  set hasCheckedForWarnings(value) {
14988
14915
  this.flags = setFlag(this.flags, 134217728 /* Flag.checkedForWarnings */, value);
14989
14916
  }
14990
- bind() {
14991
- super.bind();
14992
- }
14993
14917
  hasEffects(context) {
14994
14918
  if (!this.deoptimized)
14995
14919
  this.applyDeoptimizations();
@@ -15109,12 +15033,13 @@ class TemplateLiteral extends NodeBase {
15109
15033
  }
15110
15034
 
15111
15035
  class ModuleScope extends ChildScope {
15112
- constructor(parent, context) {
15036
+ constructor(parent, context, importDescriptions) {
15113
15037
  super(parent, context);
15038
+ this.importDescriptions = importDescriptions;
15114
15039
  this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, EMPTY_PATH, context, 'other'));
15115
15040
  }
15116
15041
  addDeclaration(identifier, context, init, destructuredInitPath, kind) {
15117
- if (this.context.module.importDescriptions.has(identifier.name)) {
15042
+ if (this.importDescriptions.has(identifier.name)) {
15118
15043
  context.error(logRedeclarationError(identifier.name), identifier.start);
15119
15044
  }
15120
15045
  return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
@@ -15426,6 +15351,10 @@ class UpdateExpression extends NodeBase {
15426
15351
  }
15427
15352
  UpdateExpression.prototype.includeNode = onlyIncludeSelf;
15428
15353
 
15354
+ function isReassignedExportsMember(variable, exportNamesByVariable) {
15355
+ return (variable.renderBaseName !== null && exportNamesByVariable.has(variable) && variable.isReassigned);
15356
+ }
15357
+
15429
15358
  class VariableDeclaration extends NodeBase {
15430
15359
  deoptimizePath() {
15431
15360
  for (const declarator of this.declarations) {
@@ -15611,6 +15540,92 @@ function gatherSystemExportsAndGetSingleExport(separatedNodes, options, aggregat
15611
15540
  VariableDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
15612
15541
  VariableDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
15613
15542
 
15543
+ class VariableDeclarator extends NodeBase {
15544
+ declareDeclarator(kind) {
15545
+ this.isUsingDeclaration = kind === 'using';
15546
+ this.isAsyncUsingDeclaration = kind === 'await using';
15547
+ this.id.declare(kind, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION);
15548
+ }
15549
+ deoptimizePath(path) {
15550
+ this.id.deoptimizePath(path);
15551
+ }
15552
+ hasEffects(context) {
15553
+ const initEffect = this.init?.hasEffects(context);
15554
+ this.id.markDeclarationReached();
15555
+ return (initEffect ||
15556
+ this.isUsingDeclaration ||
15557
+ this.isAsyncUsingDeclaration ||
15558
+ this.id.hasEffects(context) ||
15559
+ (this.scope.context.options.treeshake
15560
+ .propertyReadSideEffects &&
15561
+ this.id.hasEffectsWhenDestructuring(context, EMPTY_PATH, this.init || UNDEFINED_EXPRESSION)));
15562
+ }
15563
+ include(context, includeChildrenRecursively) {
15564
+ const { id, init } = this;
15565
+ if (!this.included)
15566
+ this.includeNode(context);
15567
+ init?.include(context, includeChildrenRecursively);
15568
+ id.markDeclarationReached();
15569
+ if (includeChildrenRecursively) {
15570
+ id.include(context, includeChildrenRecursively);
15571
+ }
15572
+ else {
15573
+ id.includeDestructuredIfNecessary(context, EMPTY_PATH, init || UNDEFINED_EXPRESSION);
15574
+ }
15575
+ }
15576
+ removeAnnotations(code) {
15577
+ this.init?.removeAnnotations(code);
15578
+ }
15579
+ render(code, options) {
15580
+ const { exportNamesByVariable, snippets: { _, getPropertyAccess } } = options;
15581
+ const { end, id, init, start } = this;
15582
+ const renderId = id.included || this.isUsingDeclaration || this.isAsyncUsingDeclaration;
15583
+ if (renderId) {
15584
+ id.render(code, options);
15585
+ }
15586
+ else {
15587
+ const operatorPos = findFirstOccurrenceOutsideComment(code.original, '=', id.end);
15588
+ code.remove(start, findNonWhiteSpace(code.original, operatorPos + 1));
15589
+ }
15590
+ if (init) {
15591
+ if (id instanceof Identifier && init instanceof ClassExpression && !init.id) {
15592
+ const renderedVariable = id.variable.getName(getPropertyAccess);
15593
+ if (renderedVariable !== id.name) {
15594
+ code.appendLeft(init.start + 5, ` ${id.name}`);
15595
+ }
15596
+ }
15597
+ init.render(code, options, renderId ? BLANK : { renderedSurroundingElement: ExpressionStatement$1 });
15598
+ }
15599
+ else if (id instanceof Identifier &&
15600
+ isReassignedExportsMember(id.variable, exportNamesByVariable)) {
15601
+ code.appendLeft(end, `${_}=${_}void 0`);
15602
+ }
15603
+ }
15604
+ includeNode(context) {
15605
+ this.included = true;
15606
+ const { id, init } = this;
15607
+ if (init) {
15608
+ if (this.isUsingDeclaration) {
15609
+ init.includePath(SYMBOL_DISPOSE_PATH, context);
15610
+ }
15611
+ else if (this.isAsyncUsingDeclaration) {
15612
+ init.includePath(SYMBOL_ASYNC_DISPOSE_PATH, context);
15613
+ }
15614
+ if (id instanceof Identifier && init instanceof ClassExpression && !init.id) {
15615
+ const { name, variable } = id;
15616
+ for (const accessedVariable of init.scope.accessedOutsideVariables.values()) {
15617
+ if (accessedVariable !== variable) {
15618
+ accessedVariable.forbidName(name);
15619
+ }
15620
+ }
15621
+ }
15622
+ }
15623
+ }
15624
+ }
15625
+ VariableDeclarator.prototype.applyDeoptimizations = doNotDeoptimize;
15626
+ const SYMBOL_DISPOSE_PATH = [SymbolDispose];
15627
+ const SYMBOL_ASYNC_DISPOSE_PATH = [SymbolAsyncDispose];
15628
+
15614
15629
  class WhileStatement extends NodeBase {
15615
15630
  hasEffects(context) {
15616
15631
  if (this.test.hasEffects(context))
@@ -16898,27 +16913,26 @@ class Module {
16898
16913
  this.needsExportShim = false;
16899
16914
  this.sideEffectDependenciesByVariable = new Map();
16900
16915
  this.sourcesWithAttributes = new Map();
16901
- this.allExportNames = null;
16902
16916
  this.allExportsIncluded = false;
16903
16917
  this.ast = null;
16904
16918
  this.exportAllModules = [];
16905
16919
  this.exportAllSources = new Set();
16920
+ this.exportDescriptions = new Map();
16921
+ this.exportedVariablesByName = null;
16906
16922
  this.exportNamesByVariable = null;
16907
16923
  this.exportShimVariable = new ExportShimVariable(this);
16908
- this.exports = new Map();
16909
16924
  this.namespaceReexportsByName = new Map();
16910
16925
  this.reexportDescriptions = new Map();
16911
16926
  this.relevantDependencies = null;
16912
16927
  this.syntheticExports = new Map();
16913
16928
  this.syntheticNamespace = null;
16914
16929
  this.transformDependencies = [];
16915
- this.transitiveReexports = null;
16916
16930
  this.excludeFromSourcemap = /\0/.test(id);
16917
16931
  this.context = options.moduleContext(id);
16918
16932
  this.preserveSignature = this.options.preserveEntrySignatures;
16919
16933
  // eslint-disable-next-line @typescript-eslint/no-this-alias
16920
16934
  const module = this;
16921
- const { dynamicImports, dynamicImporters, exportAllSources, exports: exports$1, implicitlyLoadedAfter, implicitlyLoadedBefore, importers, reexportDescriptions, sourcesWithAttributes } = this;
16935
+ const { dynamicImports, dynamicImporters, exportAllSources, exportDescriptions, implicitlyLoadedAfter, implicitlyLoadedBefore, importers, reexportDescriptions, sourcesWithAttributes } = this;
16922
16936
  this.info = {
16923
16937
  ast: null,
16924
16938
  attributes,
@@ -16937,7 +16951,7 @@ class Module {
16937
16951
  return dynamicImporters.sort();
16938
16952
  },
16939
16953
  get exportedBindings() {
16940
- const exportBindings = { '.': [...exports$1.keys()] };
16954
+ const exportBindings = { '.': [...exportDescriptions.keys()] };
16941
16955
  for (const [name, { source }] of reexportDescriptions) {
16942
16956
  (exportBindings[source] ??= []).push(name);
16943
16957
  }
@@ -16948,7 +16962,7 @@ class Module {
16948
16962
  },
16949
16963
  get exports() {
16950
16964
  return [
16951
- ...exports$1.keys(),
16965
+ ...exportDescriptions.keys(),
16952
16966
  ...reexportDescriptions.keys(),
16953
16967
  ...[...exportAllSources].map(() => '*')
16954
16968
  ];
@@ -16958,7 +16972,7 @@ class Module {
16958
16972
  if (!module.ast) {
16959
16973
  return null;
16960
16974
  }
16961
- return module.exports.has('default') || reexportDescriptions.has('default');
16975
+ return module.exportDescriptions.has('default') || reexportDescriptions.has('default');
16962
16976
  },
16963
16977
  id,
16964
16978
  get implicitlyLoadedAfterOneOf() {
@@ -17031,28 +17045,6 @@ class Module {
17031
17045
  }
17032
17046
  return size;
17033
17047
  }
17034
- getAllExportNames() {
17035
- if (this.allExportNames) {
17036
- return this.allExportNames;
17037
- }
17038
- this.allExportNames = new Set([...this.exports.keys(), ...this.reexportDescriptions.keys()]);
17039
- for (const module of this.exportAllModules) {
17040
- if (module instanceof ExternalModule) {
17041
- this.allExportNames.add(`*${module.id}`);
17042
- continue;
17043
- }
17044
- for (const name of module.getAllExportNames()) {
17045
- if (name !== 'default')
17046
- this.allExportNames.add(name);
17047
- }
17048
- }
17049
- // We do not count the synthetic namespace as a regular export to hide it
17050
- // from entry signatures and namespace objects
17051
- if (typeof this.info.syntheticNamedExports === 'string') {
17052
- this.allExportNames.delete(this.info.syntheticNamedExports);
17053
- }
17054
- return this.allExportNames;
17055
- }
17056
17048
  getDependenciesToBeIncluded() {
17057
17049
  if (this.relevantDependencies)
17058
17050
  return this.relevantDependencies;
@@ -17064,10 +17056,9 @@ class Module {
17064
17056
  this.includedDynamicImporters.length > 0 ||
17065
17057
  this.namespace.included ||
17066
17058
  this.implicitlyLoadedAfter.size > 0) {
17067
- for (const exportName of [...this.getReexports(), ...this.getExports()]) {
17068
- const [exportedVariable] = this.getVariableForExportName(exportName);
17069
- if (exportedVariable?.included) {
17070
- dependencyVariables.add(exportedVariable);
17059
+ for (const variable of this.getExportedVariablesByName().values()) {
17060
+ if (variable.included) {
17061
+ dependencyVariables.add(variable);
17071
17062
  }
17072
17063
  }
17073
17064
  }
@@ -17099,18 +17090,56 @@ class Module {
17099
17090
  }
17100
17091
  return this.relevantDependencies;
17101
17092
  }
17093
+ getExportedVariablesByName() {
17094
+ if (this.exportedVariablesByName) {
17095
+ return this.exportedVariablesByName;
17096
+ }
17097
+ const exportedVariablesByName = (this.exportedVariablesByName = new Map());
17098
+ for (const name of this.exportDescriptions.keys()) {
17099
+ // We do not count the synthetic namespace as a regular export to hide it
17100
+ // from entry signatures and namespace objects
17101
+ if (name !== this.info.syntheticNamedExports) {
17102
+ const [exportedVariable] = this.getVariableForExportName(name);
17103
+ if (exportedVariable) {
17104
+ exportedVariablesByName.set(name, exportedVariable);
17105
+ }
17106
+ else {
17107
+ return error(logMissingEntryExport(name, this.id));
17108
+ }
17109
+ }
17110
+ }
17111
+ for (const name of this.reexportDescriptions.keys()) {
17112
+ const [exportedVariable] = this.getVariableForExportName(name);
17113
+ if (exportedVariable) {
17114
+ exportedVariablesByName.set(name, exportedVariable);
17115
+ }
17116
+ }
17117
+ for (const module of this.exportAllModules) {
17118
+ if (module instanceof ExternalModule) {
17119
+ exportedVariablesByName.set(`*${module.id}`, module.getVariableForExportName('*', {
17120
+ importChain: [this.id]
17121
+ })[0]);
17122
+ continue;
17123
+ }
17124
+ for (const name of module.getExportedVariablesByName().keys()) {
17125
+ if (name !== 'default' && !exportedVariablesByName.has(name)) {
17126
+ const [exportedVariable] = this.getVariableForExportName(name);
17127
+ if (exportedVariable) {
17128
+ exportedVariablesByName.set(name, exportedVariable);
17129
+ }
17130
+ }
17131
+ }
17132
+ }
17133
+ return (this.exportedVariablesByName = new Map([...exportedVariablesByName].sort(sortExportedVariables)));
17134
+ }
17102
17135
  getExportNamesByVariable() {
17103
17136
  if (this.exportNamesByVariable) {
17104
17137
  return this.exportNamesByVariable;
17105
17138
  }
17106
17139
  const exportNamesByVariable = new Map();
17107
- for (const exportName of this.getAllExportNames()) {
17108
- let [tracedVariable] = this.getVariableForExportName(exportName);
17109
- if (tracedVariable instanceof ExportDefaultVariable) {
17110
- tracedVariable = tracedVariable.getOriginalVariable();
17111
- }
17112
- if (!tracedVariable ||
17113
- !(tracedVariable.included || tracedVariable instanceof ExternalVariable)) {
17140
+ for (const [exportName, variable] of this.getExportedVariablesByName().entries()) {
17141
+ const tracedVariable = variable instanceof ExportDefaultVariable ? variable.getOriginalVariable() : variable;
17142
+ if (!variable || !(variable.included || variable instanceof ExternalVariable)) {
17114
17143
  continue;
17115
17144
  }
17116
17145
  const existingExportNames = exportNamesByVariable.get(tracedVariable);
@@ -17123,36 +17152,14 @@ class Module {
17123
17152
  }
17124
17153
  return (this.exportNamesByVariable = exportNamesByVariable);
17125
17154
  }
17126
- getExports() {
17127
- return [...this.exports.keys()];
17128
- }
17129
- getReexports() {
17130
- if (this.transitiveReexports) {
17131
- return this.transitiveReexports;
17132
- }
17133
- // to avoid infinite recursion when using circular `export * from X`
17134
- this.transitiveReexports = [];
17135
- const reexports = new Set(this.reexportDescriptions.keys());
17136
- for (const module of this.exportAllModules) {
17137
- if (module instanceof ExternalModule) {
17138
- reexports.add(`*${module.id}`);
17139
- }
17140
- else {
17141
- for (const name of [...module.getReexports(), ...module.getExports()]) {
17142
- if (name !== 'default')
17143
- reexports.add(name);
17144
- }
17145
- }
17146
- }
17147
- return (this.transitiveReexports = [...reexports]);
17148
- }
17149
17155
  getRenderedExports() {
17150
17156
  // only direct exports are counted here, not reexports at all
17151
17157
  const renderedExports = [];
17152
17158
  const removedExports = [];
17153
- for (const exportName of this.exports.keys()) {
17154
- const [variable] = this.getVariableForExportName(exportName);
17155
- (variable?.included ? renderedExports : removedExports).push(exportName);
17159
+ for (const exportName of this.exportDescriptions.keys()) {
17160
+ (this.getExportedVariablesByName().get(exportName)?.included
17161
+ ? renderedExports
17162
+ : removedExports).push(exportName);
17156
17163
  }
17157
17164
  return { removedExports, renderedExports };
17158
17165
  }
@@ -17195,7 +17202,7 @@ class Module {
17195
17202
  }
17196
17203
  return [variable];
17197
17204
  }
17198
- const exportDeclaration = this.exports.get(name);
17205
+ const exportDeclaration = this.exportDescriptions.get(name);
17199
17206
  if (exportDeclaration) {
17200
17207
  if (exportDeclaration === MISSING_EXPORT_SHIM_DESCRIPTION) {
17201
17208
  return [this.exportShimVariable];
@@ -17246,63 +17253,29 @@ class Module {
17246
17253
  if (this.ast.shouldBeIncluded(context))
17247
17254
  this.ast.include(context, false);
17248
17255
  }
17249
- includeAllExports(includeNamespaceMembers) {
17250
- if (includeNamespaceMembers) {
17251
- this.namespace.setMergedNamespaces(this.includeAndGetAdditionalMergedNamespaces());
17252
- }
17256
+ includeAllExports() {
17253
17257
  if (this.allExportsIncluded)
17254
17258
  return;
17255
17259
  this.allExportsIncluded = true;
17256
- if (!this.isExecuted) {
17257
- markModuleAndImpureDependenciesAsExecuted(this);
17258
- this.graph.needsTreeshakingPass = true;
17259
- }
17260
+ this.includeModuleInExecution();
17260
17261
  const inclusionContext = createInclusionContext();
17261
- for (const exportName of this.exports.keys()) {
17262
- if (includeNamespaceMembers || exportName !== this.info.syntheticNamedExports) {
17263
- const variable = this.getVariableForExportName(exportName)[0];
17264
- if (!variable) {
17265
- return error(logMissingEntryExport(exportName, this.id));
17266
- }
17267
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
17268
- variable.deoptimizePath(UNKNOWN_PATH);
17269
- }
17270
- }
17271
- for (const name of this.getReexports()) {
17272
- const [variable] = this.getVariableForExportName(name);
17273
- if (variable) {
17274
- variable.deoptimizePath(UNKNOWN_PATH);
17275
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
17276
- if (variable instanceof ExternalVariable) {
17277
- variable.module.reexported = true;
17278
- }
17262
+ for (const variable of this.getExportedVariablesByName().values()) {
17263
+ this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
17264
+ variable.deoptimizePath(UNKNOWN_PATH);
17265
+ if (variable instanceof ExternalVariable) {
17266
+ variable.module.reexported = true;
17279
17267
  }
17280
17268
  }
17281
17269
  }
17282
17270
  includeAllInBundle() {
17283
17271
  this.ast.include(createInclusionContext(), true);
17284
- this.includeAllExports(false);
17272
+ this.includeAllExports();
17285
17273
  }
17286
- includeExportsByNames(names) {
17274
+ includeModuleInExecution() {
17287
17275
  if (!this.isExecuted) {
17288
17276
  markModuleAndImpureDependenciesAsExecuted(this);
17289
17277
  this.graph.needsTreeshakingPass = true;
17290
17278
  }
17291
- let includeNamespaceMembers = false;
17292
- const inclusionContext = createInclusionContext();
17293
- for (const name of names) {
17294
- const variable = this.getVariableForExportName(name)[0];
17295
- if (variable) {
17296
- variable.deoptimizePath(UNKNOWN_PATH);
17297
- this.includeVariable(variable, UNKNOWN_PATH, inclusionContext);
17298
- }
17299
- if (!this.exports.has(name) && !this.reexportDescriptions.has(name)) {
17300
- includeNamespaceMembers = true;
17301
- }
17302
- }
17303
- if (includeNamespaceMembers) {
17304
- this.namespace.setMergedNamespaces(this.includeAndGetAdditionalMergedNamespaces());
17305
- }
17306
17279
  }
17307
17280
  isIncluded() {
17308
17281
  // Modules where this.ast is missing have been loaded via this.load and are
@@ -17381,14 +17354,11 @@ class Module {
17381
17354
  deoptimizationTracker: this.graph.deoptimizationTracker,
17382
17355
  error: this.error.bind(this),
17383
17356
  fileName, // Needed for warnings
17384
- getExports: this.getExports.bind(this),
17385
17357
  getImportedJsxFactoryVariable: this.getImportedJsxFactoryVariable.bind(this),
17386
17358
  getModuleExecIndex: () => this.execIndex,
17387
17359
  getModuleName: this.basename.bind(this),
17388
17360
  getNodeConstructor: (name) => nodeConstructors[name] || nodeConstructors.UnknownNode,
17389
- getReexports: this.getReexports.bind(this),
17390
17361
  importDescriptions: this.importDescriptions,
17391
- includeAllExports: () => this.includeAllExports(true),
17392
17362
  includeDynamicImport: this.includeDynamicImport.bind(this),
17393
17363
  includeVariableInModule: this.includeVariableInModule.bind(this),
17394
17364
  log: this.log.bind(this),
@@ -17403,7 +17373,7 @@ class Module {
17403
17373
  traceVariable: this.traceVariable.bind(this),
17404
17374
  usesTopLevelAwait: false
17405
17375
  };
17406
- this.scope = new ModuleScope(this.graph.scope, this.astContext);
17376
+ this.scope = new ModuleScope(this.graph.scope, this.astContext, this.importDescriptions);
17407
17377
  this.namespace = new NamespaceVariable(this.astContext);
17408
17378
  const programParent = { context: this.astContext, type: 'Module' };
17409
17379
  if (ast) {
@@ -17504,10 +17474,10 @@ class Module {
17504
17474
  typeof argument.value === 'string') {
17505
17475
  argument = argument.value;
17506
17476
  }
17507
- this.dynamicImports.push({ argument, id: null, node, resolution: null });
17477
+ this.dynamicImports.push({ argument, id: null, node });
17508
17478
  }
17509
17479
  assertUniqueExportName(name, nodeStart) {
17510
- if (this.exports.has(name) || this.reexportDescriptions.has(name)) {
17480
+ if (this.exportDescriptions.has(name) || this.reexportDescriptions.has(name)) {
17511
17481
  this.error(logDuplicateExportError(name), nodeStart);
17512
17482
  }
17513
17483
  }
@@ -17515,7 +17485,7 @@ class Module {
17515
17485
  if (node instanceof ExportDefaultDeclaration) {
17516
17486
  // export default foo;
17517
17487
  this.assertUniqueExportName('default', node.start);
17518
- this.exports.set('default', {
17488
+ this.exportDescriptions.set('default', {
17519
17489
  identifier: node.variable.getAssignedVariableName(),
17520
17490
  localName: 'default'
17521
17491
  });
@@ -17562,7 +17532,7 @@ class Module {
17562
17532
  for (const declarator of declaration.declarations) {
17563
17533
  for (const localName of extractAssignedNames(declarator.id)) {
17564
17534
  this.assertUniqueExportName(localName, declarator.id.start);
17565
- this.exports.set(localName, { identifier: null, localName });
17535
+ this.exportDescriptions.set(localName, { identifier: null, localName });
17566
17536
  }
17567
17537
  }
17568
17538
  }
@@ -17570,7 +17540,7 @@ class Module {
17570
17540
  // export function foo () {}
17571
17541
  const localName = declaration.id.name;
17572
17542
  this.assertUniqueExportName(localName, declaration.id.start);
17573
- this.exports.set(localName, { identifier: null, localName });
17543
+ this.exportDescriptions.set(localName, { identifier: null, localName });
17574
17544
  }
17575
17545
  }
17576
17546
  else {
@@ -17580,7 +17550,7 @@ class Module {
17580
17550
  const localName = local.name;
17581
17551
  const exportedName = exported instanceof Identifier ? exported.name : exported.value;
17582
17552
  this.assertUniqueExportName(exportedName, exported.start);
17583
- this.exports.set(exportedName, { identifier: null, localName });
17553
+ this.exportDescriptions.set(exportedName, { identifier: null, localName });
17584
17554
  }
17585
17555
  }
17586
17556
  }
@@ -17754,7 +17724,7 @@ class Module {
17754
17724
  return [...syntheticNamespaces, ...externalNamespaces];
17755
17725
  }
17756
17726
  includeDynamicImport(node) {
17757
- const resolution = this.dynamicImports.find(dynamicImport => dynamicImport.node === node).resolution;
17727
+ const { resolution } = node;
17758
17728
  if (resolution instanceof Module) {
17759
17729
  if (!resolution.includedDynamicImporters.includes(this)) {
17760
17730
  resolution.includedDynamicImporters.push(this);
@@ -17764,15 +17734,6 @@ class Module {
17764
17734
  resolution.includedTopLevelAwaitingDynamicImporters.add(this);
17765
17735
  }
17766
17736
  }
17767
- const importedNames = this.options.treeshake
17768
- ? node.getDeterministicImportedNames()
17769
- : undefined;
17770
- if (importedNames) {
17771
- resolution.includeExportsByNames(importedNames);
17772
- }
17773
- else {
17774
- resolution.includeAllExports(true);
17775
- }
17776
17737
  }
17777
17738
  }
17778
17739
  includeVariable(variable, path, context) {
@@ -17782,21 +17743,17 @@ class Module {
17782
17743
  if (variableModule instanceof Module && variableModule !== this) {
17783
17744
  getAndExtendSideEffectModules(variable, this);
17784
17745
  }
17746
+ return;
17785
17747
  }
17786
- else {
17787
- this.graph.needsTreeshakingPass = true;
17788
- if (variableModule instanceof Module) {
17789
- if (!variableModule.isExecuted) {
17790
- markModuleAndImpureDependenciesAsExecuted(variableModule);
17791
- }
17792
- if (variableModule !== this) {
17793
- const sideEffectModules = getAndExtendSideEffectModules(variable, this);
17794
- for (const module of sideEffectModules) {
17795
- if (!module.isExecuted) {
17796
- markModuleAndImpureDependenciesAsExecuted(module);
17797
- }
17798
- }
17799
- }
17748
+ this.graph.needsTreeshakingPass = true;
17749
+ if (!(variableModule instanceof Module)) {
17750
+ return;
17751
+ }
17752
+ variableModule.includeModuleInExecution();
17753
+ if (variableModule !== this) {
17754
+ const sideEffectModules = getAndExtendSideEffectModules(variable, this);
17755
+ for (const module of sideEffectModules) {
17756
+ module.includeModuleInExecution();
17800
17757
  }
17801
17758
  }
17802
17759
  }
@@ -17809,7 +17766,7 @@ class Module {
17809
17766
  }
17810
17767
  shimMissingExport(name) {
17811
17768
  this.options.onLog(LOGLEVEL_WARN, logShimmedExport(this.id, name));
17812
- this.exports.set(name, MISSING_EXPORT_SHIM_DESCRIPTION);
17769
+ this.exportDescriptions.set(name, MISSING_EXPORT_SHIM_DESCRIPTION);
17813
17770
  }
17814
17771
  tryParse() {
17815
17772
  try {
@@ -17839,6 +17796,7 @@ function setAlternativeExporterIfCyclic(variable, importer, reexporter) {
17839
17796
  }
17840
17797
  const copyNameToModulesMap = (searchedNamesAndModules) => searchedNamesAndModules &&
17841
17798
  new Map(Array.from(searchedNamesAndModules, ([name, modules]) => [name, new Set(modules)]));
17799
+ const sortExportedVariables = ([a], [b]) => a < b ? -1 : a > b ? 1 : 0;
17842
17800
 
17843
17801
  const concatSeparator = (out, next) => (next ? `${out}\n${next}` : out);
17844
17802
  const concatDblSeparator = (out, next) => (next ? `${out}\n\n${next}` : out);
@@ -18330,6 +18288,8 @@ class Chunk {
18330
18288
  includedNamespaces.add(module);
18331
18289
  this.exports.add(module.namespace);
18332
18290
  }
18291
+ // This only needs to run once
18292
+ break;
18333
18293
  }
18334
18294
  }
18335
18295
  if (module.implicitlyLoadedAfter.size > 0) {
@@ -18967,10 +18927,11 @@ class Chunk {
18967
18927
  }
18968
18928
  const includedDynamicImports = [];
18969
18929
  for (const module of this.orderedModules) {
18970
- for (const { node, resolution } of module.dynamicImports) {
18930
+ for (const { node } of module.dynamicImports) {
18971
18931
  if (!node.included) {
18972
18932
  continue;
18973
18933
  }
18934
+ const { resolution } = node;
18974
18935
  includedDynamicImports.push(resolution instanceof Module
18975
18936
  ? {
18976
18937
  chunk: this.chunkByModule.get(resolution),
@@ -19228,13 +19189,13 @@ class Chunk {
19228
19189
  node.setInternalResolution(resolution.namespace);
19229
19190
  }
19230
19191
  else {
19231
- node.setExternalResolution((facadeChunk || chunk).exportMode, resolution, outputOptions, snippets, pluginDriver, accessedGlobalsByScope, `'${(facadeChunk || chunk).getImportPath(fileName)}'`, !facadeChunk?.strictFacade && chunk.exportNamesByVariable.get(resolution.namespace)[0], null, this, facadeChunk || chunk);
19192
+ node.setExternalResolution((facadeChunk || chunk).exportMode, outputOptions, snippets, pluginDriver, accessedGlobalsByScope, `'${(facadeChunk || chunk).getImportPath(fileName)}'`, !facadeChunk?.strictFacade && chunk.exportNamesByVariable.get(resolution.namespace)[0], null, this, facadeChunk || chunk);
19232
19193
  }
19233
19194
  }
19234
19195
  else {
19235
19196
  const { node, resolution } = resolvedDynamicImport;
19236
19197
  const [resolutionString, attributes] = this.getDynamicImportStringAndAttributes(resolution, fileName, node);
19237
- node.setExternalResolution('external', resolution, outputOptions, snippets, pluginDriver, accessedGlobalsByScope, resolutionString, false, attributes, this, null);
19198
+ node.setExternalResolution('external', outputOptions, snippets, pluginDriver, accessedGlobalsByScope, resolutionString, false, attributes, this, null);
19238
19199
  }
19239
19200
  }
19240
19201
  }
@@ -19287,8 +19248,7 @@ class Chunk {
19287
19248
  // when we are not preserving modules, we need to make all namespace variables available for
19288
19249
  // rendering the namespace object
19289
19250
  if (!this.outputOptions.preserveModules && this.includedNamespaces.has(module)) {
19290
- const memberVariables = module.namespace.getMemberVariables();
19291
- for (const variable of Object.values(memberVariables)) {
19251
+ for (const variable of module.getExportedVariablesByName().values()) {
19292
19252
  if (variable.included) {
19293
19253
  moduleImports.add(variable);
19294
19254
  }
@@ -19319,8 +19279,8 @@ class Chunk {
19319
19279
  module.includedDynamicImporters.some(importer => this.chunkByModule.get(importer) !== this)) {
19320
19280
  this.ensureReexportsAreAvailableForModule(module);
19321
19281
  }
19322
- for (const { node, resolution } of module.dynamicImports) {
19323
- if (node.included &&
19282
+ for (const { node: { included, resolution } } of module.dynamicImports) {
19283
+ if (included &&
19324
19284
  resolution instanceof Module &&
19325
19285
  this.chunkByModule.get(resolution) === this &&
19326
19286
  !this.includedNamespaces.has(resolution)) {
@@ -19551,7 +19511,7 @@ function analyzeModuleGraph(entries) {
19551
19511
  staticDependencies.add(dependency);
19552
19512
  }
19553
19513
  }
19554
- for (const { resolution } of module.dynamicImports) {
19514
+ for (const { node: { resolution } } of module.dynamicImports) {
19555
19515
  if (resolution instanceof Module &&
19556
19516
  resolution.includedDynamicImporters.length > 0 &&
19557
19517
  !allEntriesSet.has(resolution)) {
@@ -20092,9 +20052,9 @@ function analyseModuleExecution(entryModules) {
20092
20052
  for (const dependency of module.implicitlyLoadedBefore) {
20093
20053
  dynamicImports.add(dependency);
20094
20054
  }
20095
- for (const { resolution, node } of module.dynamicImports) {
20055
+ for (const { node: { resolution, scope } } of module.dynamicImports) {
20096
20056
  if (resolution instanceof Module) {
20097
- if (node.scope.context.usesTopLevelAwait) {
20057
+ if (scope.context.usesTopLevelAwait) {
20098
20058
  handleSyncLoadedModule(resolution, module);
20099
20059
  }
20100
20060
  else {
@@ -21511,14 +21471,14 @@ class ModuleLoader {
21511
21471
  return loadNewModulesPromise;
21512
21472
  }
21513
21473
  async fetchDynamicDependencies(module, resolveDynamicImportPromises) {
21514
- const dependencies = await Promise.all(resolveDynamicImportPromises.map(resolveDynamicImportPromise => resolveDynamicImportPromise.then(async ([dynamicImport, resolvedId]) => {
21474
+ const dependencies = await Promise.all(resolveDynamicImportPromises.map(resolveDynamicImportPromise => resolveDynamicImportPromise.then(async ([{ node }, resolvedId]) => {
21515
21475
  if (resolvedId === null)
21516
21476
  return null;
21517
21477
  if (typeof resolvedId === 'string') {
21518
- dynamicImport.resolution = resolvedId;
21478
+ node.resolution = resolvedId;
21519
21479
  return null;
21520
21480
  }
21521
- return (dynamicImport.resolution = await this.fetchResolvedDependency(relativeId(resolvedId.id), module.id, resolvedId));
21481
+ return (node.resolution = await this.fetchResolvedDependency(relativeId(resolvedId.id), module.id, resolvedId));
21522
21482
  })));
21523
21483
  for (const dependency of dependencies) {
21524
21484
  if (dependency) {
@@ -22757,7 +22717,7 @@ class Graph {
22757
22717
  timeEnd('generate module graph', 2);
22758
22718
  timeStart('sort and bind modules', 2);
22759
22719
  this.phase = BuildPhase.ANALYSE;
22760
- this.sortModules();
22720
+ this.sortAndBindModules();
22761
22721
  timeEnd('sort and bind modules', 2);
22762
22722
  timeStart('mark included statements', 2);
22763
22723
  this.includeStatements();
@@ -22830,7 +22790,7 @@ class Graph {
22830
22790
  // the TDZ detection logic
22831
22791
  for (const module of entryModules) {
22832
22792
  if (module.preserveSignature !== false) {
22833
- module.includeAllExports(false);
22793
+ module.includeAllExports();
22834
22794
  this.needsTreeshakingPass = true;
22835
22795
  }
22836
22796
  }
@@ -22852,7 +22812,7 @@ class Graph {
22852
22812
  }
22853
22813
  }
22854
22814
  }
22855
- sortModules() {
22815
+ sortAndBindModules() {
22856
22816
  const { orderedModules, cyclePaths } = analyseModuleExecution(this.entryModules);
22857
22817
  for (const cyclePath of cyclePaths) {
22858
22818
  this.options.onLog(LOGLEVEL_WARN, logCircularDependency(cyclePath));