@rollup/wasm-node 4.10.0 → 4.12.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,22 +1,22 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v4.10.0
4
- Sat, 10 Feb 2024 05:58:12 GMT - commit 762420860765e8e46e24d48b38f5b98ca31735fa
3
+ Rollup.js v4.12.0
4
+ Fri, 16 Feb 2024 13:31:42 GMT - commit 0146b84be33a8416b4df4b9382549a7ca19dd64a
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
8
8
  Released under the MIT License.
9
9
  */
10
- import { normalize, getImportPath, LOGLEVEL_WARN, logUnusedExternalImports, ANNOTATION_KEY, INVALID_ANNOTATION_KEY, logInvalidAnnotation, logRedeclarationError, logDuplicateArgumentNameError, logIllegalImportReassignment, logModuleLevelDirective, logMissingExport, logCannotCallNamespace, logEval, LOGLEVEL_INFO, logFirstSideEffect, locate, logThisIsUndefined, logImportAttributeIsInvalid, logImportOptionsAreInvalid, error, logSyntheticNamedExportsNeedNamespaceExport, logMissingEntryExport, logInvalidFormatForTopLevelAwait, logDuplicateExportError, logInvalidSourcemapForError, augmentCodeLocation, logInconsistentImportAttributes, logNamespaceConflict, logAmbiguousExternalNamespaces, logShimmedExport, parseAst, logModuleParseError, parseAstAsync, logCircularReexport, logMissingNodeBuiltins, logIllegalIdentifierAsName, logMissingNameOptionForIifeExport, logMissingNameOptionForUmdExport, 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, logAnonymousPluginCache, logDuplicatePluginName, LOGLEVEL_ERROR, logLevelPriority, relativeId, LOGLEVEL_DEBUG, logUnknownOption, printQuotedStringList, logInvalidSetAssetSourceCall, logPluginError, logNoTransformMapOrAstWithoutCode, logBadLoader, logExternalModulesCannotBeTransformedToModules, logInternalIdCannotBeExternal, isRelative, logUnresolvedImport, logUnresolvedImportTreatedAsExternal, logExternalSyntheticExports, logUnresolvedEntry, logUnresolvedImplicitDependant, logExternalModulesCannotBeIncludedInManualChunks, logEntryCannotBeExternal, logImplicitDependantCannotBeExternal, logNoAssetSourceSet, logFileReferenceIdNotFoundForFilename, logAssetReferenceIdNotFoundForSetSource, logAssetSourceAlreadySet, logInvalidRollupPhaseForChunkEmission, logFileNameConflict, logAssetNotFinalisedForFileName, logChunkNotGeneratedForFileName, logInvalidLogPosition, logInputHookInOutputPlugin, logInvalidFunctionPluginHook, logInvalidAddonPluginHook, logImplicitDependantIsNotIncluded, logCircularDependency, URL_TREESHAKE_MODULESIDEEFFECTS, URL_TREESHAKE, URL_OUTPUT_INLINEDYNAMICIMPORTS, URL_PRESERVEENTRYSIGNATURES, URL_OUTPUT_AMD_BASEPATH, logInvalidExportOptionValue, warnDeprecation, URL_OUTPUT_INTEROP, URL_OUTPUT_MANUALCHUNKS, isValidUrl, addTrailingSlashIfMissed, URL_OUTPUT_SOURCEMAPBASEURL, URL_OUTPUT_GENERATEDCODE, URL_OUTPUT_EXTERNALIMPORTATTRIBUTES, logAlreadyClosed, logMissingFileOrDirOption, logCannotEmitFromOptionsHook, URL_WATCH } from './parseAst.js';
10
+ import { normalize, getImportPath, LOGLEVEL_WARN, logUnusedExternalImports, ANNOTATION_KEY, INVALID_ANNOTATION_KEY, Program as Program$1, logRedeclarationError, CatchClause as CatchClause$1, logDuplicateArgumentNameError, CallExpression as CallExpression$1, logIllegalImportReassignment, logModuleLevelDirective, ReturnStatement as ReturnStatement$1, Property as Property$1, logConstVariableReassignError, ExpressionStatement as ExpressionStatement$1, ArrowFunctionExpression as ArrowFunctionExpression$1, logMissingExport, logCannotCallNamespace, logEval, BlockStatement as BlockStatement$1, getRollupEror, logParseError, logModuleParseError, error, LOGLEVEL_INFO, logFirstSideEffect, locate, logInvalidAnnotation, Identifier as Identifier$1, logThisIsUndefined, getReadStringFunction, convertString, convertAnnotations, FIXED_STRINGS, convertNode as convertNode$1, logImportAttributeIsInvalid, logImportOptionsAreInvalid, logSyntheticNamedExportsNeedNamespaceExport, logMissingEntryExport, logInvalidFormatForTopLevelAwait, logDuplicateExportError, logInvalidSourcemapForError, augmentCodeLocation, logInconsistentImportAttributes, logNamespaceConflict, logAmbiguousExternalNamespaces, logShimmedExport, parseAst, logCircularReexport, TemplateLiteral as TemplateLiteral$1, Literal as Literal$1, logMissingNodeBuiltins, logIllegalIdentifierAsName, logMissingNameOptionForIifeExport, logMissingNameOptionForUmdExport, 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, logAnonymousPluginCache, logDuplicatePluginName, LOGLEVEL_ERROR, logLevelPriority, relativeId, LOGLEVEL_DEBUG, logUnknownOption, printQuotedStringList, logInvalidSetAssetSourceCall, logPluginError, logNoTransformMapOrAstWithoutCode, logBadLoader, logExternalModulesCannotBeTransformedToModules, logInternalIdCannotBeExternal, isRelative, logUnresolvedImport, logUnresolvedImportTreatedAsExternal, logExternalSyntheticExports, logUnresolvedEntry, logUnresolvedImplicitDependant, logExternalModulesCannotBeIncludedInManualChunks, logEntryCannotBeExternal, logImplicitDependantCannotBeExternal, logNoAssetSourceSet, logFileReferenceIdNotFoundForFilename, logAssetReferenceIdNotFoundForSetSource, logAssetSourceAlreadySet, logInvalidRollupPhaseForChunkEmission, logFileNameConflict, logAssetNotFinalisedForFileName, logChunkNotGeneratedForFileName, logInvalidLogPosition, logInputHookInOutputPlugin, logInvalidFunctionPluginHook, logInvalidAddonPluginHook, logImplicitDependantIsNotIncluded, logCircularDependency, URL_TREESHAKE_MODULESIDEEFFECTS, URL_TREESHAKE, URL_OUTPUT_INLINEDYNAMICIMPORTS, URL_PRESERVEENTRYSIGNATURES, URL_OUTPUT_AMD_BASEPATH, logInvalidExportOptionValue, warnDeprecation, URL_OUTPUT_INTEROP, URL_OUTPUT_MANUALCHUNKS, isValidUrl, addTrailingSlashIfMissed, URL_OUTPUT_SOURCEMAPBASEURL, URL_OUTPUT_GENERATEDCODE, 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 require$$0$1, { win32, posix, isAbsolute, resolve } from 'path';
13
+ import { parseAsync, xxhashBase64Url, xxhashBase36, xxhashBase16 } from '../../native.js';
13
14
  import process$1, { env as env$1 } from 'node:process';
14
15
  import { performance } from 'node:perf_hooks';
15
- import { xxhashBase64Url, xxhashBase36, xxhashBase16 } from '../../native.js';
16
16
  import { lstat, realpath, readdir, readFile, mkdir, writeFile } from 'node:fs/promises';
17
17
  import * as tty from 'tty';
18
18
 
19
- var version = "4.10.0";
19
+ var version = "4.12.0";
20
20
 
21
21
  const comma = ','.charCodeAt(0);
22
22
  const semicolon = ';'.charCodeAt(0);
@@ -4617,13 +4617,83 @@ function getMemberReturnExpressionWhenCalled(members, memberName) {
4617
4617
  return [members[memberName].returns, false];
4618
4618
  }
4619
4619
 
4620
- const keys = {
4620
+ // This file is generated by scripts/generate-ast-converters.js.
4621
+ // Do not edit this file directly.
4622
+ const childNodeKeys = {
4623
+ ArrayExpression: ['elements'],
4624
+ ArrayPattern: ['elements'],
4625
+ ArrowFunctionExpression: ['params', 'body'],
4626
+ AssignmentExpression: ['left', 'right'],
4627
+ AssignmentPattern: ['left', 'right'],
4628
+ AwaitExpression: ['argument'],
4629
+ BinaryExpression: ['left', 'right'],
4630
+ BlockStatement: ['body'],
4631
+ BreakStatement: ['label'],
4632
+ CallExpression: ['callee', 'arguments'],
4633
+ CatchClause: ['param', 'body'],
4634
+ ChainExpression: ['expression'],
4635
+ ClassBody: ['body'],
4636
+ ClassDeclaration: ['id', 'superClass', 'body'],
4637
+ ClassExpression: ['id', 'superClass', 'body'],
4638
+ ConditionalExpression: ['test', 'consequent', 'alternate'],
4639
+ ContinueStatement: ['label'],
4640
+ DebuggerStatement: [],
4641
+ DoWhileStatement: ['body', 'test'],
4642
+ EmptyStatement: [],
4643
+ ExportAllDeclaration: ['exported', 'source', 'attributes'],
4644
+ ExportDefaultDeclaration: ['declaration'],
4645
+ ExportNamedDeclaration: ['specifiers', 'source', 'attributes', 'declaration'],
4646
+ ExportSpecifier: ['local', 'exported'],
4647
+ ExpressionStatement: ['expression'],
4648
+ ForInStatement: ['left', 'right', 'body'],
4649
+ ForOfStatement: ['left', 'right', 'body'],
4650
+ ForStatement: ['init', 'test', 'update', 'body'],
4651
+ FunctionDeclaration: ['id', 'params', 'body'],
4652
+ FunctionExpression: ['id', 'params', 'body'],
4653
+ Identifier: [],
4654
+ IfStatement: ['test', 'consequent', 'alternate'],
4655
+ ImportAttribute: ['key', 'value'],
4656
+ ImportDeclaration: ['specifiers', 'source', 'attributes'],
4657
+ ImportDefaultSpecifier: ['local'],
4658
+ ImportExpression: ['source', 'options'],
4659
+ ImportNamespaceSpecifier: ['local'],
4660
+ ImportSpecifier: ['imported', 'local'],
4661
+ LabeledStatement: ['label', 'body'],
4621
4662
  Literal: [],
4622
- Program: ['body']
4663
+ LogicalExpression: ['left', 'right'],
4664
+ MemberExpression: ['object', 'property'],
4665
+ MetaProperty: ['meta', 'property'],
4666
+ MethodDefinition: ['key', 'value'],
4667
+ NewExpression: ['callee', 'arguments'],
4668
+ ObjectExpression: ['properties'],
4669
+ ObjectPattern: ['properties'],
4670
+ PanicError: [],
4671
+ ParseError: [],
4672
+ PrivateIdentifier: [],
4673
+ Program: ['body'],
4674
+ Property: ['key', 'value'],
4675
+ PropertyDefinition: ['key', 'value'],
4676
+ RestElement: ['argument'],
4677
+ ReturnStatement: ['argument'],
4678
+ SequenceExpression: ['expressions'],
4679
+ SpreadElement: ['argument'],
4680
+ StaticBlock: ['body'],
4681
+ Super: [],
4682
+ SwitchCase: ['test', 'consequent'],
4683
+ SwitchStatement: ['discriminant', 'cases'],
4684
+ TaggedTemplateExpression: ['tag', 'quasi'],
4685
+ TemplateElement: [],
4686
+ TemplateLiteral: ['quasis', 'expressions'],
4687
+ ThisExpression: [],
4688
+ ThrowStatement: ['argument'],
4689
+ TryStatement: ['block', 'handler', 'finalizer'],
4690
+ UnaryExpression: ['argument'],
4691
+ UpdateExpression: ['argument'],
4692
+ VariableDeclaration: ['declarations'],
4693
+ VariableDeclarator: ['id', 'init'],
4694
+ WhileStatement: ['test', 'body'],
4695
+ YieldExpression: ['argument']
4623
4696
  };
4624
- function createKeysForNode(esTreeNode) {
4625
- return Object.keys(esTreeNode).filter(key => typeof esTreeNode[key] === 'object' && key.charCodeAt(0) !== 95 /* _ */);
4626
- }
4627
4697
 
4628
4698
  const INCLUDE_PARAMETERS = 'variables';
4629
4699
  class NodeBase extends ExpressionEntity {
@@ -4639,22 +4709,11 @@ class NodeBase extends ExpressionEntity {
4639
4709
  set deoptimized(value) {
4640
4710
  this.flags = setFlag(this.flags, 2 /* Flag.deoptimized */, value);
4641
4711
  }
4642
- constructor(esTreeNode, parent, parentScope, keepEsTreeNode = false) {
4712
+ constructor(parent, parentScope) {
4643
4713
  super();
4644
- // Nodes can opt-in to keep the AST if needed during the build pipeline.
4645
- // Avoid true when possible as large AST takes up memory.
4646
- if (keepEsTreeNode) {
4647
- this.esTreeNode = esTreeNode;
4648
- }
4649
- const { type } = esTreeNode;
4650
- keys[type] ||= createKeysForNode(esTreeNode);
4651
4714
  this.parent = parent;
4652
4715
  this.scope = parentScope;
4653
4716
  this.createScope(parentScope);
4654
- this.parseNode(esTreeNode);
4655
- this.initialise();
4656
- this.scope.context.magicString.addSourcemapLocation(this.start);
4657
- this.scope.context.magicString.addSourcemapLocation(this.end);
4658
4717
  }
4659
4718
  addExportedVariables(_variables, _exportNamesByVariable) { }
4660
4719
  /**
@@ -4662,7 +4721,7 @@ class NodeBase extends ExpressionEntity {
4662
4721
  * that require the scopes to be populated with variables.
4663
4722
  */
4664
4723
  bind() {
4665
- for (const key of keys[this.type]) {
4724
+ for (const key of childNodeKeys[this.type]) {
4666
4725
  const value = this[key];
4667
4726
  if (Array.isArray(value)) {
4668
4727
  for (const child of value) {
@@ -4684,7 +4743,7 @@ class NodeBase extends ExpressionEntity {
4684
4743
  hasEffects(context) {
4685
4744
  if (!this.deoptimized)
4686
4745
  this.applyDeoptimizations();
4687
- for (const key of keys[this.type]) {
4746
+ for (const key of childNodeKeys[this.type]) {
4688
4747
  const value = this[key];
4689
4748
  if (value === null)
4690
4749
  continue;
@@ -4707,7 +4766,7 @@ class NodeBase extends ExpressionEntity {
4707
4766
  if (!this.deoptimized)
4708
4767
  this.applyDeoptimizations();
4709
4768
  this.included = true;
4710
- for (const key of keys[this.type]) {
4769
+ for (const key of childNodeKeys[this.type]) {
4711
4770
  const value = this[key];
4712
4771
  if (value === null)
4713
4772
  continue;
@@ -4728,8 +4787,11 @@ class NodeBase extends ExpressionEntity {
4728
4787
  * Override to perform special initialisation steps after the scope is
4729
4788
  * initialised
4730
4789
  */
4731
- initialise() { }
4732
- parseNode(esTreeNode, keepEsTreeNodeKeys) {
4790
+ initialise() {
4791
+ this.scope.context.magicString.addSourcemapLocation(this.start);
4792
+ this.scope.context.magicString.addSourcemapLocation(this.end);
4793
+ }
4794
+ parseNode(esTreeNode) {
4733
4795
  for (const [key, value] of Object.entries(esTreeNode)) {
4734
4796
  // Skip properties defined on the class already.
4735
4797
  // This way, we can override this function to add custom initialisation and then call super.parseNode
@@ -4739,20 +4801,10 @@ class NodeBase extends ExpressionEntity {
4739
4801
  continue;
4740
4802
  if (key.charCodeAt(0) === 95 /* _ */) {
4741
4803
  if (key === ANNOTATION_KEY) {
4742
- const annotations = value;
4743
- this.annotations = annotations;
4744
- if (this.scope.context.options.treeshake.annotations) {
4745
- this.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
4746
- this.annotationPure = annotations.some(comment => comment.type === 'pure');
4747
- }
4804
+ this.annotations = value;
4748
4805
  }
4749
4806
  else if (key === INVALID_ANNOTATION_KEY) {
4750
- for (const { start, end, type } of value) {
4751
- this.scope.context.magicString.remove(start, end);
4752
- if (type === 'pure' || type === 'noSideEffects') {
4753
- this.scope.context.log(LOGLEVEL_WARN, logInvalidAnnotation(this.scope.context.code.slice(start, end), this.scope.context.module.id, type), start);
4754
- }
4755
- }
4807
+ this.invalidAnnotations = value;
4756
4808
  }
4757
4809
  }
4758
4810
  else if (typeof value !== 'object' || value === null) {
@@ -4763,13 +4815,17 @@ class NodeBase extends ExpressionEntity {
4763
4815
  for (const child of value) {
4764
4816
  this[key].push(child === null
4765
4817
  ? null
4766
- : new (this.scope.context.getNodeConstructor(child.type))(child, this, this.scope, keepEsTreeNodeKeys?.includes(key)));
4818
+ : new (this.scope.context.getNodeConstructor(child.type))(this, this.scope).parseNode(child));
4767
4819
  }
4768
4820
  }
4769
4821
  else {
4770
- this[key] = new (this.scope.context.getNodeConstructor(value.type))(value, this, this.scope, keepEsTreeNodeKeys?.includes(key));
4822
+ this[key] = new (this.scope.context.getNodeConstructor(value.type))(this, this.scope).parseNode(value);
4771
4823
  }
4772
4824
  }
4825
+ // extend child keys for unknown node types
4826
+ childNodeKeys[esTreeNode.type] ||= createChildNodeKeysForNode(esTreeNode);
4827
+ this.initialise();
4828
+ return this;
4773
4829
  }
4774
4830
  removeAnnotations(code) {
4775
4831
  if (this.annotations) {
@@ -4779,7 +4835,7 @@ class NodeBase extends ExpressionEntity {
4779
4835
  }
4780
4836
  }
4781
4837
  render(code, options) {
4782
- for (const key of keys[this.type]) {
4838
+ for (const key of childNodeKeys[this.type]) {
4783
4839
  const value = this[key];
4784
4840
  if (value === null)
4785
4841
  continue;
@@ -4806,7 +4862,7 @@ class NodeBase extends ExpressionEntity {
4806
4862
  */
4807
4863
  applyDeoptimizations() {
4808
4864
  this.deoptimized = true;
4809
- for (const key of keys[this.type]) {
4865
+ for (const key of childNodeKeys[this.type]) {
4810
4866
  const value = this[key];
4811
4867
  if (value === null)
4812
4868
  continue;
@@ -4822,6 +4878,9 @@ class NodeBase extends ExpressionEntity {
4822
4878
  this.scope.context.requestTreeshakingPass();
4823
4879
  }
4824
4880
  }
4881
+ function createChildNodeKeysForNode(esTreeNode) {
4882
+ return Object.keys(esTreeNode).filter(key => typeof esTreeNode[key] === 'object' && key.charCodeAt(0) !== 95 /* _ */);
4883
+ }
4825
4884
 
4826
4885
  class SpreadElement extends NodeBase {
4827
4886
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
@@ -5574,16 +5633,6 @@ class ArrayPattern extends NodeBase {
5574
5633
  }
5575
5634
  }
5576
5635
 
5577
- const ArrowFunctionExpression$1 = 'ArrowFunctionExpression';
5578
- const BlockStatement$1 = 'BlockStatement';
5579
- const CallExpression$1 = 'CallExpression';
5580
- const CatchClause$1 = 'CatchClause';
5581
- const ExpressionStatement$1 = 'ExpressionStatement';
5582
- const Identifier$1 = 'Identifier';
5583
- const Program$1 = 'Program';
5584
- const Property$1 = 'Property';
5585
- const ReturnStatement$1 = 'ReturnStatement';
5586
-
5587
5636
  class LocalVariable extends Variable {
5588
5637
  constructor(name, declarator, init, context, kind) {
5589
5638
  super(name);
@@ -5728,7 +5777,7 @@ const EMPTY_PATH_TRACKER = new PathTracker();
5728
5777
  const UNKNOWN_DEOPTIMIZED_ENTITY = new Set([UNKNOWN_EXPRESSION]);
5729
5778
  class ParameterVariable extends LocalVariable {
5730
5779
  constructor(name, declarator, context) {
5731
- super(name, declarator, UNKNOWN_EXPRESSION, context, "parameter" /* VariableKind.parameter */);
5780
+ super(name, declarator, UNKNOWN_EXPRESSION, context, 'parameter');
5732
5781
  this.deoptimizationInteractions = [];
5733
5782
  this.deoptimizations = new PathTracker();
5734
5783
  this.deoptimizedFields = new Set();
@@ -5865,7 +5914,7 @@ class Scope {
5865
5914
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
5866
5915
  if (existingVariable) {
5867
5916
  const existingKind = existingVariable.kind;
5868
- if (kind === "var" /* VariableKind.var */ && existingKind === "var" /* VariableKind.var */) {
5917
+ if (kind === 'var' && existingKind === 'var') {
5869
5918
  existingVariable.addDeclaration(identifier, init);
5870
5919
  return existingVariable;
5871
5920
  }
@@ -5976,12 +6025,12 @@ class CatchBodyScope extends ChildScope {
5976
6025
  this.parent = parent;
5977
6026
  }
5978
6027
  addDeclaration(identifier, context, init, kind) {
5979
- if (kind === "var" /* VariableKind.var */) {
6028
+ if (kind === 'var') {
5980
6029
  const name = identifier.name;
5981
6030
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
5982
6031
  if (existingVariable) {
5983
6032
  const existingKind = existingVariable.kind;
5984
- if (existingKind === "parameter" /* VariableKind.parameter */ &&
6033
+ if (existingKind === 'parameter' &&
5985
6034
  // If this is a destructured parameter, it is forbidden to redeclare
5986
6035
  existingVariable.declarations[0].parent.type === CatchClause$1) {
5987
6036
  // If this is a var with the same name as the catch scope parameter,
@@ -6000,7 +6049,7 @@ class CatchBodyScope extends ChildScope {
6000
6049
  this.addHoistedVariable(name, declaredVariable);
6001
6050
  return declaredVariable;
6002
6051
  }
6003
- if (existingKind === "var" /* VariableKind.var */) {
6052
+ if (existingKind === 'var') {
6004
6053
  existingVariable.addDeclaration(identifier, init);
6005
6054
  return existingVariable;
6006
6055
  }
@@ -6030,10 +6079,8 @@ class FunctionBodyScope extends ChildScope {
6030
6079
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
6031
6080
  if (existingVariable) {
6032
6081
  const existingKind = existingVariable.kind;
6033
- if ((kind === "var" /* VariableKind.var */ || kind === "function" /* VariableKind.function */) &&
6034
- (existingKind === "var" /* VariableKind.var */ ||
6035
- existingKind === "function" /* VariableKind.function */ ||
6036
- existingKind === "parameter" /* VariableKind.parameter */)) {
6082
+ if ((kind === 'var' || kind === 'function') &&
6083
+ (existingKind === 'var' || existingKind === 'function' || existingKind === 'parameter')) {
6037
6084
  existingVariable.addDeclaration(identifier, init);
6038
6085
  return existingVariable;
6039
6086
  }
@@ -7254,7 +7301,7 @@ class Identifier extends NodeBase {
7254
7301
  let variable;
7255
7302
  const { treeshake } = this.scope.context.options;
7256
7303
  switch (kind) {
7257
- case "var" /* VariableKind.var */: {
7304
+ case 'var': {
7258
7305
  variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
7259
7306
  if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
7260
7307
  // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
@@ -7262,18 +7309,18 @@ class Identifier extends NodeBase {
7262
7309
  }
7263
7310
  break;
7264
7311
  }
7265
- case "function" /* VariableKind.function */: {
7312
+ case 'function': {
7266
7313
  // in strict mode, functions are only hoisted within a scope but not across block scopes
7267
7314
  variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
7268
7315
  break;
7269
7316
  }
7270
- case "let" /* VariableKind.let */:
7271
- case "const" /* VariableKind.const */:
7272
- case "class" /* VariableKind.class */: {
7317
+ case 'let':
7318
+ case 'const':
7319
+ case 'class': {
7273
7320
  variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
7274
7321
  break;
7275
7322
  }
7276
- case "parameter" /* VariableKind.parameter */: {
7323
+ case 'parameter': {
7277
7324
  variable = this.scope.addParameterDeclaration(this);
7278
7325
  break;
7279
7326
  }
@@ -7306,7 +7353,7 @@ class Identifier extends NodeBase {
7306
7353
  hasEffects(context) {
7307
7354
  if (!this.deoptimized)
7308
7355
  this.applyDeoptimizations();
7309
- if (this.isPossibleTDZ() && this.variable.kind !== "var" /* VariableKind.var */) {
7356
+ if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
7310
7357
  return true;
7311
7358
  }
7312
7359
  return (this.scope.context.options.treeshake
@@ -7581,12 +7628,12 @@ class BlockScope extends ChildScope {
7581
7628
  super(parent, parent.context);
7582
7629
  }
7583
7630
  addDeclaration(identifier, context, init, kind) {
7584
- if (kind === "var" /* VariableKind.var */) {
7631
+ if (kind === 'var') {
7585
7632
  const name = identifier.name;
7586
7633
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
7587
7634
  if (existingVariable) {
7588
- if (existingVariable.kind === "var" /* VariableKind.var */ ||
7589
- (kind === "var" /* VariableKind.var */ && existingVariable.kind === "parameter" /* VariableKind.parameter */)) {
7635
+ if (existingVariable.kind === 'var' ||
7636
+ (kind === 'var' && existingVariable.kind === 'parameter')) {
7590
7637
  existingVariable.addDeclaration(identifier, init);
7591
7638
  return existingVariable;
7592
7639
  }
@@ -7606,6 +7653,7 @@ class BlockScope extends ChildScope {
7606
7653
 
7607
7654
  class ExpressionStatement extends NodeBase {
7608
7655
  initialise() {
7656
+ super.initialise();
7609
7657
  if (this.directive &&
7610
7658
  this.directive !== 'use strict' &&
7611
7659
  this.parent.type === Program$1) {
@@ -7679,6 +7727,7 @@ class BlockStatement extends NodeBase {
7679
7727
  }
7680
7728
  }
7681
7729
  initialise() {
7730
+ super.initialise();
7682
7731
  const firstBodyStatement = this.body[0];
7683
7732
  this.deoptimizeBody =
7684
7733
  firstBodyStatement instanceof ExpressionStatement &&
@@ -7742,6 +7791,12 @@ class FunctionBase extends NodeBase {
7742
7791
  set deoptimizedReturn(value) {
7743
7792
  this.flags = setFlag(this.flags, 512 /* Flag.deoptimizedReturn */, value);
7744
7793
  }
7794
+ get generator() {
7795
+ return isFlagSet(this.flags, 4194304 /* Flag.generator */);
7796
+ }
7797
+ set generator(value) {
7798
+ this.flags = setFlag(this.flags, 4194304 /* Flag.generator */, value);
7799
+ }
7745
7800
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
7746
7801
  if (interaction.type === INTERACTION_CALLED) {
7747
7802
  const { parameters } = this.scope;
@@ -7838,12 +7893,17 @@ class FunctionBase extends NodeBase {
7838
7893
  this.scope.includeCallArguments(context, parameters);
7839
7894
  }
7840
7895
  initialise() {
7896
+ super.initialise();
7841
7897
  if (this.body instanceof BlockStatement) {
7842
7898
  this.body.addImplicitReturnExpressionToScope();
7843
7899
  }
7844
7900
  else {
7845
7901
  this.scope.addReturnExpression(this.body);
7846
7902
  }
7903
+ if (this.annotations &&
7904
+ this.scope.context.options.treeshake.annotations) {
7905
+ this.annotationNoSideEffects = this.annotations.some(comment => comment.type === 'noSideEffects');
7906
+ }
7847
7907
  }
7848
7908
  parseNode(esTreeNode) {
7849
7909
  const { body, params } = esTreeNode;
@@ -7854,11 +7914,11 @@ class FunctionBase extends NodeBase {
7854
7914
  // so that the scope already knows all parameters and can detect conflicts
7855
7915
  // when parsing the body.
7856
7916
  for (const parameter of params) {
7857
- parameters.push(new (context.getNodeConstructor(parameter.type))(parameter, this, scope, false));
7917
+ parameters.push(new (context.getNodeConstructor(parameter.type))(this, scope).parseNode(parameter));
7858
7918
  }
7859
- scope.addParameterVariables(parameters.map(parameter => parameter.declare("parameter" /* VariableKind.parameter */, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
7860
- this.body = new (context.getNodeConstructor(body.type))(body, this, bodyScope);
7861
- super.parseNode(esTreeNode);
7919
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
7920
+ this.body = new (context.getNodeConstructor(body.type))(this, bodyScope).parseNode(body);
7921
+ return super.parseNode(esTreeNode);
7862
7922
  }
7863
7923
  addArgumentToBeDeoptimized(_argument) { }
7864
7924
  applyDeoptimizations() { }
@@ -7870,6 +7930,12 @@ class ArrowFunctionExpression extends FunctionBase {
7870
7930
  super(...arguments);
7871
7931
  this.objectEntity = null;
7872
7932
  }
7933
+ get expression() {
7934
+ return isFlagSet(this.flags, 8388608 /* Flag.expression */);
7935
+ }
7936
+ set expression(value) {
7937
+ this.flags = setFlag(this.flags, 8388608 /* Flag.expression */, value);
7938
+ }
7873
7939
  createScope(parentScope) {
7874
7940
  this.scope = new ReturnValueScope(parentScope, false);
7875
7941
  }
@@ -8028,6 +8094,13 @@ class AssignmentExpression extends NodeBase {
8028
8094
  right.include(context, includeChildrenRecursively);
8029
8095
  }
8030
8096
  initialise() {
8097
+ super.initialise();
8098
+ if (this.left instanceof Identifier) {
8099
+ const variable = this.scope.variables.get(this.left.name);
8100
+ if (variable?.kind === 'const') {
8101
+ this.scope.context.error(logConstVariableReassignError(), this.left.start);
8102
+ }
8103
+ }
8031
8104
  this.left.setAssignedValue(this.right);
8032
8105
  }
8033
8106
  render(code, options, { preventASI, renderedParentType, renderedSurroundingElement } = BLANK) {
@@ -8116,7 +8189,7 @@ class AssignmentPattern extends NodeBase {
8116
8189
 
8117
8190
  class ArgumentsVariable extends LocalVariable {
8118
8191
  constructor(context) {
8119
- super('arguments', null, UNKNOWN_EXPRESSION, context, "other" /* VariableKind.other */);
8192
+ super('arguments', null, UNKNOWN_EXPRESSION, context, 'other');
8120
8193
  this.deoptimizedArguments = [];
8121
8194
  }
8122
8195
  addArgumentToBeDeoptimized(argument) {
@@ -8239,7 +8312,7 @@ class FunctionNode extends FunctionBase {
8239
8312
  }
8240
8313
  initialise() {
8241
8314
  super.initialise();
8242
- this.id?.declare("function" /* VariableKind.function */, this);
8315
+ this.id?.declare('function', this);
8243
8316
  }
8244
8317
  addArgumentToBeDeoptimized(argument) {
8245
8318
  this.scope.argumentsVariable.addArgumentToBeDeoptimized(argument);
@@ -8436,12 +8509,13 @@ class Literal extends NodeBase {
8436
8509
  }
8437
8510
  }
8438
8511
  initialise() {
8512
+ super.initialise();
8439
8513
  this.members = getLiteralMembersForValue(this.value);
8440
8514
  }
8441
8515
  parseNode(esTreeNode) {
8442
8516
  this.value = esTreeNode.value;
8443
8517
  this.regex = esTreeNode.regex;
8444
- super.parseNode(esTreeNode);
8518
+ return super.parseNode(esTreeNode);
8445
8519
  }
8446
8520
  render(code) {
8447
8521
  if (typeof this.value === 'string') {
@@ -8659,6 +8733,7 @@ class MemberExpression extends NodeBase {
8659
8733
  }
8660
8734
  }
8661
8735
  initialise() {
8736
+ super.initialise();
8662
8737
  this.propertyKey = getResolvablePropertyKey(this);
8663
8738
  this.accessInteraction = { args: [this.object], type: INTERACTION_ACCESSED };
8664
8739
  }
@@ -8938,6 +9013,13 @@ class CallExpression extends CallExpressionBase {
8938
9013
  }
8939
9014
  this.callee.includeCallArguments(context, this.arguments);
8940
9015
  }
9016
+ initialise() {
9017
+ super.initialise();
9018
+ if (this.annotations &&
9019
+ this.scope.context.options.treeshake.annotations) {
9020
+ this.annotationPure = this.annotations.some(comment => comment.type === 'pure');
9021
+ }
9022
+ }
8941
9023
  isSkippedAsOptional(origin) {
8942
9024
  return (this.callee.isSkippedAsOptional?.(origin) ||
8943
9025
  (this.optional &&
@@ -8972,11 +9054,11 @@ class CatchClause extends NodeBase {
8972
9054
  const { body, param, type } = esTreeNode;
8973
9055
  this.type = type;
8974
9056
  if (param) {
8975
- this.param = new (this.scope.context.getNodeConstructor(param.type))(param, this, this.scope);
8976
- this.param.declare("parameter" /* VariableKind.parameter */, UNKNOWN_EXPRESSION);
9057
+ this.param = new (this.scope.context.getNodeConstructor(param.type))(this, this.scope).parseNode(param);
9058
+ this.param.declare('parameter', UNKNOWN_EXPRESSION);
8977
9059
  }
8978
- this.body = new BlockStatement(body, this, this.scope.bodyScope);
8979
- super.parseNode(esTreeNode);
9060
+ this.body = new BlockStatement(this, this.scope.bodyScope).parseNode(body);
9061
+ return super.parseNode(esTreeNode);
8980
9062
  }
8981
9063
  }
8982
9064
  CatchClause.prototype.preventChildBlockScope = true;
@@ -9003,7 +9085,7 @@ class ClassBodyScope extends ChildScope {
9003
9085
  constructor(parent, classNode) {
9004
9086
  const { context } = parent;
9005
9087
  super(parent, context);
9006
- this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, context, "other" /* VariableKind.other */)));
9088
+ this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, context, 'other')));
9007
9089
  this.instanceScope = new ChildScope(this, context);
9008
9090
  this.instanceScope.variables.set('this', new ThisVariable(context));
9009
9091
  }
@@ -9026,9 +9108,9 @@ class ClassBody extends NodeBase {
9026
9108
  parseNode(esTreeNode) {
9027
9109
  const body = (this.body = []);
9028
9110
  for (const definition of esTreeNode.body) {
9029
- body.push(new (this.scope.context.getNodeConstructor(definition.type))(definition, this, definition.static ? this.scope : this.scope.instanceScope));
9111
+ body.push(new (this.scope.context.getNodeConstructor(definition.type))(this, definition.static ? this.scope : this.scope.instanceScope).parseNode(definition));
9030
9112
  }
9031
- super.parseNode(esTreeNode);
9113
+ return super.parseNode(esTreeNode);
9032
9114
  }
9033
9115
  applyDeoptimizations() { }
9034
9116
  }
@@ -9187,7 +9269,8 @@ class ClassNode extends NodeBase {
9187
9269
  }
9188
9270
  }
9189
9271
  initialise() {
9190
- this.id?.declare("class" /* VariableKind.class */, this);
9272
+ super.initialise();
9273
+ this.id?.declare('class', this);
9191
9274
  for (const method of this.body.body) {
9192
9275
  if (method instanceof MethodDefinition && method.kind === 'constructor') {
9193
9276
  this.classConstructor = method;
@@ -9257,9 +9340,9 @@ class ClassDeclaration extends ClassNode {
9257
9340
  }
9258
9341
  parseNode(esTreeNode) {
9259
9342
  if (esTreeNode.id !== null) {
9260
- this.id = new Identifier(esTreeNode.id, this, this.scope.parent);
9343
+ this.id = new Identifier(this, this.scope.parent).parseNode(esTreeNode.id);
9261
9344
  }
9262
- super.parseNode(esTreeNode);
9345
+ return super.parseNode(esTreeNode);
9263
9346
  }
9264
9347
  render(code, options) {
9265
9348
  const { exportNamesByVariable, format, snippets: { _, getPropertyAccess } } = options;
@@ -9499,6 +9582,12 @@ class ContinueStatement extends NodeBase {
9499
9582
  }
9500
9583
  }
9501
9584
 
9585
+ class DebuggerStatement extends NodeBase {
9586
+ hasEffects() {
9587
+ return true;
9588
+ }
9589
+ }
9590
+
9502
9591
  function hasLoopBodyEffects(context, body) {
9503
9592
  const { brokenFlow, hasBreak, hasContinue, ignore } = context;
9504
9593
  const { breaks, continues } = ignore;
@@ -9549,6 +9638,7 @@ class ExportAllDeclaration extends NodeBase {
9549
9638
  return false;
9550
9639
  }
9551
9640
  initialise() {
9641
+ super.initialise();
9552
9642
  this.scope.context.addExport(this);
9553
9643
  }
9554
9644
  render(code, _options, nodeRenderOptions) {
@@ -9567,9 +9657,9 @@ class FunctionDeclaration extends FunctionNode {
9567
9657
  }
9568
9658
  parseNode(esTreeNode) {
9569
9659
  if (esTreeNode.id !== null) {
9570
- this.id = new Identifier(esTreeNode.id, this, this.scope.parent);
9660
+ this.id = new Identifier(this, this.scope.parent).parseNode(esTreeNode.id);
9571
9661
  }
9572
- super.parseNode(esTreeNode);
9662
+ return super.parseNode(esTreeNode);
9573
9663
  }
9574
9664
  }
9575
9665
 
@@ -9594,6 +9684,7 @@ class ExportDefaultDeclaration extends NodeBase {
9594
9684
  }
9595
9685
  }
9596
9686
  initialise() {
9687
+ super.initialise();
9597
9688
  const declaration = this.declaration;
9598
9689
  this.declarationName =
9599
9690
  (declaration.id && declaration.id.name) || this.declaration.name;
@@ -9677,6 +9768,7 @@ class ExportNamedDeclaration extends NodeBase {
9677
9768
  return !!this.declaration?.hasEffects(context);
9678
9769
  }
9679
9770
  initialise() {
9771
+ super.initialise();
9680
9772
  this.scope.context.addExport(this);
9681
9773
  }
9682
9774
  removeAnnotations(code) {
@@ -9722,6 +9814,7 @@ class ForInStatement extends NodeBase {
9722
9814
  includeLoopBody(context, body, includeChildrenRecursively);
9723
9815
  }
9724
9816
  initialise() {
9817
+ super.initialise();
9725
9818
  this.left.setAssignedValue(UNKNOWN_EXPRESSION);
9726
9819
  }
9727
9820
  render(code, options) {
@@ -9766,6 +9859,7 @@ class ForOfStatement extends NodeBase {
9766
9859
  includeLoopBody(context, body, includeChildrenRecursively);
9767
9860
  }
9768
9861
  initialise() {
9862
+ super.initialise();
9769
9863
  this.left.setAssignedValue(UNKNOWN_EXPRESSION);
9770
9864
  }
9771
9865
  render(code, options) {
@@ -9818,9 +9912,9 @@ class FunctionExpression extends FunctionNode {
9818
9912
  }
9819
9913
  parseNode(esTreeNode) {
9820
9914
  if (esTreeNode.id !== null) {
9821
- this.id = new Identifier(esTreeNode.id, this, this.idScope);
9915
+ this.id = new Identifier(this, this.idScope).parseNode(esTreeNode.id);
9822
9916
  }
9823
- super.parseNode(esTreeNode);
9917
+ return super.parseNode(esTreeNode);
9824
9918
  }
9825
9919
  render(code, options, { renderedSurroundingElement } = BLANK) {
9826
9920
  super.render(code, options);
@@ -9887,13 +9981,11 @@ class IfStatement extends NodeBase {
9887
9981
  }
9888
9982
  }
9889
9983
  parseNode(esTreeNode) {
9890
- this.consequentScope = new TrackingScope(this.scope);
9891
- this.consequent = new (this.scope.context.getNodeConstructor(esTreeNode.consequent.type))(esTreeNode.consequent, this, this.consequentScope);
9984
+ this.consequent = new (this.scope.context.getNodeConstructor(esTreeNode.consequent.type))(this, (this.consequentScope = new TrackingScope(this.scope))).parseNode(esTreeNode.consequent);
9892
9985
  if (esTreeNode.alternate) {
9893
- this.alternateScope = new TrackingScope(this.scope);
9894
- this.alternate = new (this.scope.context.getNodeConstructor(esTreeNode.alternate.type))(esTreeNode.alternate, this, this.alternateScope);
9986
+ this.alternate = new (this.scope.context.getNodeConstructor(esTreeNode.alternate.type))(this, (this.alternateScope = new TrackingScope(this.scope))).parseNode(esTreeNode.alternate);
9895
9987
  }
9896
- super.parseNode(esTreeNode);
9988
+ return super.parseNode(esTreeNode);
9897
9989
  }
9898
9990
  render(code, options) {
9899
9991
  const { snippets: { getPropertyAccess } } = options;
@@ -10019,6 +10111,7 @@ class ImportDeclaration extends NodeBase {
10019
10111
  return false;
10020
10112
  }
10021
10113
  initialise() {
10114
+ super.initialise();
10022
10115
  this.scope.context.addImport(this);
10023
10116
  }
10024
10117
  render(code, _options, nodeRenderOptions) {
@@ -10409,11 +10502,12 @@ class ImportExpression extends NodeBase {
10409
10502
  this.source.include(context, includeChildrenRecursively);
10410
10503
  }
10411
10504
  initialise() {
10505
+ super.initialise();
10412
10506
  this.scope.context.addDynamicImport(this);
10413
10507
  }
10414
10508
  parseNode(esTreeNode) {
10415
- // Keep the source AST to be used by renderDynamicImport
10416
- super.parseNode(esTreeNode, ['source']);
10509
+ this.sourceAstNode = esTreeNode.source;
10510
+ return super.parseNode(esTreeNode);
10417
10511
  }
10418
10512
  render(code, options) {
10419
10513
  const { snippets: { _, getDirectReturnFunction, getObject, getPropertyAccess } } = options;
@@ -10946,11 +11040,16 @@ class NewExpression extends NodeBase {
10946
11040
  this.callee.includeCallArguments(context, this.arguments);
10947
11041
  }
10948
11042
  initialise() {
11043
+ super.initialise();
10949
11044
  this.interaction = {
10950
11045
  args: [null, ...this.arguments],
10951
11046
  type: INTERACTION_CALLED,
10952
11047
  withNew: true
10953
11048
  };
11049
+ if (this.annotations &&
11050
+ this.scope.context.options.treeshake.annotations) {
11051
+ this.annotationPure = this.annotations.some(comment => comment.type === 'pure');
11052
+ }
10954
11053
  }
10955
11054
  render(code, options) {
10956
11055
  this.callee.render(code, options);
@@ -11036,6 +11135,29 @@ class ObjectExpression extends NodeBase {
11036
11135
  }
11037
11136
  }
11038
11137
 
11138
+ class PanicError extends NodeBase {
11139
+ initialise() {
11140
+ const id = this.scope.context.module.id;
11141
+ // This simulates the current nested error structure. We could also just
11142
+ // replace it with a flat error.
11143
+ const parseError = getRollupEror(logParseError(this.message));
11144
+ const moduleParseError = logModuleParseError(parseError, id);
11145
+ return error(moduleParseError);
11146
+ }
11147
+ }
11148
+
11149
+ class ParseError extends NodeBase {
11150
+ initialise() {
11151
+ const pos = this.start;
11152
+ const id = this.scope.context.module.id;
11153
+ // This simulates the current nested error structure. We could also just
11154
+ // replace it with a flat error.
11155
+ const parseError = getRollupEror(logParseError(this.message, pos));
11156
+ const moduleParseError = logModuleParseError(parseError, id);
11157
+ this.scope.context.error(moduleParseError, pos);
11158
+ }
11159
+ }
11160
+
11039
11161
  class PrivateIdentifier extends NodeBase {
11040
11162
  }
11041
11163
 
@@ -11074,6 +11196,16 @@ class Program extends NodeBase {
11074
11196
  }
11075
11197
  }
11076
11198
  }
11199
+ initialise() {
11200
+ super.initialise();
11201
+ if (this.invalidAnnotations)
11202
+ for (const { start, end, type } of this.invalidAnnotations) {
11203
+ this.scope.context.magicString.remove(start, end);
11204
+ if (type === 'pure' || type === 'noSideEffects') {
11205
+ this.scope.context.log(LOGLEVEL_WARN, logInvalidAnnotation(this.scope.context.code.slice(start, end), this.scope.context.module.id, type), start);
11206
+ }
11207
+ }
11208
+ }
11077
11209
  render(code, options) {
11078
11210
  let start = this.start;
11079
11211
  if (code.original.startsWith('#!')) {
@@ -11192,6 +11324,7 @@ class ReturnStatement extends NodeBase {
11192
11324
  context.brokenFlow = true;
11193
11325
  }
11194
11326
  initialise() {
11327
+ super.initialise();
11195
11328
  this.scope.addReturnExpression(this.argument || UNKNOWN_EXPRESSION);
11196
11329
  }
11197
11330
  render(code, options) {
@@ -11413,6 +11546,7 @@ class SwitchStatement extends NodeBase {
11413
11546
  context.hasBreak = hasBreak;
11414
11547
  }
11415
11548
  initialise() {
11549
+ super.initialise();
11416
11550
  for (let caseIndex = 0; caseIndex < this.cases.length; caseIndex++) {
11417
11551
  if (this.cases[caseIndex].test === null) {
11418
11552
  this.defaultCase = caseIndex;
@@ -11422,8 +11556,8 @@ class SwitchStatement extends NodeBase {
11422
11556
  this.defaultCase = null;
11423
11557
  }
11424
11558
  parseNode(esTreeNode) {
11425
- this.discriminant = new (this.scope.context.getNodeConstructor(esTreeNode.discriminant.type))(esTreeNode.discriminant, this, this.parentScope);
11426
- super.parseNode(esTreeNode);
11559
+ this.discriminant = new (this.scope.context.getNodeConstructor(esTreeNode.discriminant.type))(this, this.parentScope).parseNode(esTreeNode.discriminant);
11560
+ return super.parseNode(esTreeNode);
11427
11561
  }
11428
11562
  render(code, options) {
11429
11563
  this.discriminant.render(code, options);
@@ -11476,6 +11610,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
11476
11610
  }
11477
11611
  }
11478
11612
  initialise() {
11613
+ super.initialise();
11479
11614
  this.args = [UNKNOWN_EXPRESSION, ...this.quasi.expressions];
11480
11615
  this.interaction = {
11481
11616
  args: [
@@ -11521,7 +11656,7 @@ class TemplateElement extends NodeBase {
11521
11656
  }
11522
11657
  parseNode(esTreeNode) {
11523
11658
  this.value = esTreeNode.value;
11524
- super.parseNode(esTreeNode);
11659
+ return super.parseNode(esTreeNode);
11525
11660
  }
11526
11661
  render() { }
11527
11662
  }
@@ -11566,7 +11701,7 @@ class UndefinedVariable extends Variable {
11566
11701
 
11567
11702
  class ExportDefaultVariable extends LocalVariable {
11568
11703
  constructor(name, exportDefaultDeclaration, context) {
11569
- super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context, "other" /* VariableKind.other */);
11704
+ super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context, 'other');
11570
11705
  this.hasId = false;
11571
11706
  this.originalId = null;
11572
11707
  this.originalVariable = null;
@@ -11637,7 +11772,7 @@ class ExportDefaultVariable extends LocalVariable {
11637
11772
  class ModuleScope extends ChildScope {
11638
11773
  constructor(parent, context) {
11639
11774
  super(parent, context);
11640
- this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, context, "other" /* VariableKind.other */));
11775
+ this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, context, 'other'));
11641
11776
  }
11642
11777
  addDeclaration(identifier, context, init, kind) {
11643
11778
  if (this.context.module.importDescriptions.has(identifier.name)) {
@@ -11695,6 +11830,7 @@ class ThisExpression extends NodeBase {
11695
11830
  }
11696
11831
  }
11697
11832
  initialise() {
11833
+ super.initialise();
11698
11834
  this.alias =
11699
11835
  this.scope.findLexicalBoundary() instanceof ModuleScope
11700
11836
  ? this.scope.context.moduleContext
@@ -11811,15 +11947,6 @@ class UnaryExpression extends NodeBase {
11811
11947
  }
11812
11948
  }
11813
11949
 
11814
- class UnknownNode extends NodeBase {
11815
- hasEffects() {
11816
- return true;
11817
- }
11818
- include(context) {
11819
- super.include(context, true);
11820
- }
11821
- }
11822
-
11823
11950
  class UpdateExpression extends NodeBase {
11824
11951
  hasEffects(context) {
11825
11952
  if (!this.deoptimized)
@@ -11836,6 +11963,7 @@ class UpdateExpression extends NodeBase {
11836
11963
  this.argument.includeAsAssignmentTarget(context, includeChildrenRecursively, true);
11837
11964
  }
11838
11965
  initialise() {
11966
+ super.initialise();
11839
11967
  this.argument.setAssignedValue(UNKNOWN_EXPRESSION);
11840
11968
  }
11841
11969
  render(code, options) {
@@ -11915,6 +12043,7 @@ class VariableDeclaration extends NodeBase {
11915
12043
  }
11916
12044
  }
11917
12045
  initialise() {
12046
+ super.initialise();
11918
12047
  for (const declarator of this.declarations) {
11919
12048
  declarator.declareDeclarator(this.kind);
11920
12049
  }
@@ -12080,6 +12209,711 @@ class YieldExpression extends NodeBase {
12080
12209
  }
12081
12210
  }
12082
12211
 
12212
+ // This file is generated by scripts/generate-ast-converters.js.
12213
+ // Do not edit this file directly.
12214
+ function convertProgram(buffer, parent, parentScope) {
12215
+ return convertNode(parent, parentScope, 0, new Uint32Array(buffer.buffer), getReadStringFunction(buffer));
12216
+ }
12217
+ const nodeTypeStrings = [
12218
+ 'PanicError',
12219
+ 'ParseError',
12220
+ 'ArrayExpression',
12221
+ 'ArrayPattern',
12222
+ 'ArrowFunctionExpression',
12223
+ 'AssignmentExpression',
12224
+ 'AssignmentPattern',
12225
+ 'AwaitExpression',
12226
+ 'BinaryExpression',
12227
+ 'BlockStatement',
12228
+ 'BreakStatement',
12229
+ 'CallExpression',
12230
+ 'CatchClause',
12231
+ 'ChainExpression',
12232
+ 'ClassBody',
12233
+ 'ClassDeclaration',
12234
+ 'ClassExpression',
12235
+ 'ConditionalExpression',
12236
+ 'ContinueStatement',
12237
+ 'DebuggerStatement',
12238
+ 'ExpressionStatement',
12239
+ 'DoWhileStatement',
12240
+ 'EmptyStatement',
12241
+ 'ExportAllDeclaration',
12242
+ 'ExportDefaultDeclaration',
12243
+ 'ExportNamedDeclaration',
12244
+ 'ExportSpecifier',
12245
+ 'ExpressionStatement',
12246
+ 'ForInStatement',
12247
+ 'ForOfStatement',
12248
+ 'ForStatement',
12249
+ 'FunctionDeclaration',
12250
+ 'FunctionExpression',
12251
+ 'Identifier',
12252
+ 'IfStatement',
12253
+ 'ImportAttribute',
12254
+ 'ImportDeclaration',
12255
+ 'ImportDefaultSpecifier',
12256
+ 'ImportExpression',
12257
+ 'ImportNamespaceSpecifier',
12258
+ 'ImportSpecifier',
12259
+ 'LabeledStatement',
12260
+ 'Literal',
12261
+ 'Literal',
12262
+ 'Literal',
12263
+ 'Literal',
12264
+ 'Literal',
12265
+ 'Literal',
12266
+ 'LogicalExpression',
12267
+ 'MemberExpression',
12268
+ 'MetaProperty',
12269
+ 'MethodDefinition',
12270
+ 'NewExpression',
12271
+ 'ObjectExpression',
12272
+ 'ObjectPattern',
12273
+ 'PrivateIdentifier',
12274
+ 'Program',
12275
+ 'Property',
12276
+ 'PropertyDefinition',
12277
+ 'RestElement',
12278
+ 'ReturnStatement',
12279
+ 'SequenceExpression',
12280
+ 'SpreadElement',
12281
+ 'StaticBlock',
12282
+ 'Super',
12283
+ 'SwitchCase',
12284
+ 'SwitchStatement',
12285
+ 'TaggedTemplateExpression',
12286
+ 'TemplateElement',
12287
+ 'TemplateLiteral',
12288
+ 'ThisExpression',
12289
+ 'ThrowStatement',
12290
+ 'TryStatement',
12291
+ 'UnaryExpression',
12292
+ 'UpdateExpression',
12293
+ 'VariableDeclaration',
12294
+ 'VariableDeclarator',
12295
+ 'WhileStatement',
12296
+ 'YieldExpression'
12297
+ ];
12298
+ const nodeConstructors$1 = [
12299
+ PanicError,
12300
+ ParseError,
12301
+ ArrayExpression,
12302
+ ArrayPattern,
12303
+ ArrowFunctionExpression,
12304
+ AssignmentExpression,
12305
+ AssignmentPattern,
12306
+ AwaitExpression,
12307
+ BinaryExpression,
12308
+ BlockStatement,
12309
+ BreakStatement,
12310
+ CallExpression,
12311
+ CatchClause,
12312
+ ChainExpression,
12313
+ ClassBody,
12314
+ ClassDeclaration,
12315
+ ClassExpression,
12316
+ ConditionalExpression,
12317
+ ContinueStatement,
12318
+ DebuggerStatement,
12319
+ ExpressionStatement,
12320
+ DoWhileStatement,
12321
+ EmptyStatement,
12322
+ ExportAllDeclaration,
12323
+ ExportDefaultDeclaration,
12324
+ ExportNamedDeclaration,
12325
+ ExportSpecifier,
12326
+ ExpressionStatement,
12327
+ ForInStatement,
12328
+ ForOfStatement,
12329
+ ForStatement,
12330
+ FunctionDeclaration,
12331
+ FunctionExpression,
12332
+ Identifier,
12333
+ IfStatement,
12334
+ ImportAttribute,
12335
+ ImportDeclaration,
12336
+ ImportDefaultSpecifier,
12337
+ ImportExpression,
12338
+ ImportNamespaceSpecifier,
12339
+ ImportSpecifier,
12340
+ LabeledStatement,
12341
+ Literal,
12342
+ Literal,
12343
+ Literal,
12344
+ Literal,
12345
+ Literal,
12346
+ Literal,
12347
+ LogicalExpression,
12348
+ MemberExpression,
12349
+ MetaProperty,
12350
+ MethodDefinition,
12351
+ NewExpression,
12352
+ ObjectExpression,
12353
+ ObjectPattern,
12354
+ PrivateIdentifier,
12355
+ Program,
12356
+ Property,
12357
+ PropertyDefinition,
12358
+ RestElement,
12359
+ ReturnStatement,
12360
+ SequenceExpression,
12361
+ SpreadElement,
12362
+ StaticBlock,
12363
+ Super,
12364
+ SwitchCase,
12365
+ SwitchStatement,
12366
+ TaggedTemplateExpression,
12367
+ TemplateElement,
12368
+ TemplateLiteral,
12369
+ ThisExpression,
12370
+ ThrowStatement,
12371
+ TryStatement,
12372
+ UnaryExpression,
12373
+ UpdateExpression,
12374
+ VariableDeclaration,
12375
+ VariableDeclarator,
12376
+ WhileStatement,
12377
+ YieldExpression
12378
+ ];
12379
+ const bufferParsers = [
12380
+ function panicError(node, position, buffer, readString) {
12381
+ node.message = convertString(position, buffer, readString);
12382
+ },
12383
+ function parseError(node, position, buffer, readString) {
12384
+ node.message = convertString(position, buffer, readString);
12385
+ },
12386
+ function arrayExpression(node, position, buffer, readString) {
12387
+ const { scope } = node;
12388
+ node.elements = convertNodeList(node, scope, position, buffer, readString);
12389
+ },
12390
+ function arrayPattern(node, position, buffer, readString) {
12391
+ const { scope } = node;
12392
+ node.elements = convertNodeList(node, scope, position, buffer, readString);
12393
+ },
12394
+ function arrowFunctionExpression(node, position, buffer, readString) {
12395
+ const { scope } = node;
12396
+ const flags = buffer[position];
12397
+ node.async = (flags & 1) === 1;
12398
+ node.expression = (flags & 2) === 2;
12399
+ node.generator = (flags & 4) === 4;
12400
+ const parameters = (node.params = convertNodeList(node, scope, buffer[position + 1], buffer, readString));
12401
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
12402
+ node.body = convertNode(node, scope.bodyScope, buffer[position + 2], buffer, readString);
12403
+ const annotations = (node.annotations = convertAnnotations(position + 3, buffer));
12404
+ node.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
12405
+ },
12406
+ function assignmentExpression(node, position, buffer, readString) {
12407
+ const { scope } = node;
12408
+ node.operator = FIXED_STRINGS[buffer[position]];
12409
+ node.right = convertNode(node, scope, buffer[position + 1], buffer, readString);
12410
+ node.left = convertNode(node, scope, position + 2, buffer, readString);
12411
+ },
12412
+ function assignmentPattern(node, position, buffer, readString) {
12413
+ const { scope } = node;
12414
+ node.right = convertNode(node, scope, buffer[position], buffer, readString);
12415
+ node.left = convertNode(node, scope, position + 1, buffer, readString);
12416
+ },
12417
+ function awaitExpression(node, position, buffer, readString) {
12418
+ const { scope } = node;
12419
+ node.argument = convertNode(node, scope, position, buffer, readString);
12420
+ },
12421
+ function binaryExpression(node, position, buffer, readString) {
12422
+ const { scope } = node;
12423
+ node.operator = FIXED_STRINGS[buffer[position]];
12424
+ node.right = convertNode(node, scope, buffer[position + 1], buffer, readString);
12425
+ node.left = convertNode(node, scope, position + 2, buffer, readString);
12426
+ },
12427
+ function blockStatement(node, position, buffer, readString) {
12428
+ const { scope } = node;
12429
+ node.body = convertNodeList(node, scope, position, buffer, readString);
12430
+ },
12431
+ function breakStatement(node, position, buffer, readString) {
12432
+ const { scope } = node;
12433
+ const labelPosition = buffer[position];
12434
+ node.label =
12435
+ labelPosition === 0 ? null : convertNode(node, scope, labelPosition, buffer, readString);
12436
+ },
12437
+ function callExpression(node, position, buffer, readString) {
12438
+ const { scope } = node;
12439
+ const flags = buffer[position];
12440
+ node.optional = (flags & 1) === 1;
12441
+ node.callee = convertNode(node, scope, buffer[position + 1], buffer, readString);
12442
+ node.arguments = convertNodeList(node, scope, buffer[position + 2], buffer, readString);
12443
+ node.annotations = convertAnnotations(position + 3, buffer);
12444
+ },
12445
+ function catchClause(node, position, buffer, readString) {
12446
+ const { scope } = node;
12447
+ const parameterPosition = buffer[position];
12448
+ const parameter = (node.param =
12449
+ parameterPosition === 0
12450
+ ? null
12451
+ : convertNode(node, scope, parameterPosition, buffer, readString));
12452
+ parameter?.declare('parameter', UNKNOWN_EXPRESSION);
12453
+ node.body = convertNode(node, scope.bodyScope, buffer[position + 1], buffer, readString);
12454
+ },
12455
+ function chainExpression(node, position, buffer, readString) {
12456
+ const { scope } = node;
12457
+ node.expression = convertNode(node, scope, position, buffer, readString);
12458
+ },
12459
+ function classBody(node, position, buffer, readString) {
12460
+ const { scope } = node;
12461
+ const length = buffer[position];
12462
+ const body = (node.body = []);
12463
+ for (let index = 0; index < length; index++) {
12464
+ const nodePosition = buffer[position + 1 + index];
12465
+ body.push(convertNode(node, (buffer[nodePosition + 3] & 1) === 0 ? scope.instanceScope : scope, nodePosition, buffer, readString));
12466
+ }
12467
+ },
12468
+ function classDeclaration(node, position, buffer, readString) {
12469
+ const { scope } = node;
12470
+ const idPosition = buffer[position];
12471
+ node.id =
12472
+ idPosition === 0
12473
+ ? null
12474
+ : convertNode(node, scope.parent, idPosition, buffer, readString);
12475
+ const superClassPosition = buffer[position + 1];
12476
+ node.superClass =
12477
+ superClassPosition === 0
12478
+ ? null
12479
+ : convertNode(node, scope, superClassPosition, buffer, readString);
12480
+ node.body = convertNode(node, scope, buffer[position + 2], buffer, readString);
12481
+ },
12482
+ function classExpression(node, position, buffer, readString) {
12483
+ const { scope } = node;
12484
+ const idPosition = buffer[position];
12485
+ node.id = idPosition === 0 ? null : convertNode(node, scope, idPosition, buffer, readString);
12486
+ const superClassPosition = buffer[position + 1];
12487
+ node.superClass =
12488
+ superClassPosition === 0
12489
+ ? null
12490
+ : convertNode(node, scope, superClassPosition, buffer, readString);
12491
+ node.body = convertNode(node, scope, buffer[position + 2], buffer, readString);
12492
+ },
12493
+ function conditionalExpression(node, position, buffer, readString) {
12494
+ const { scope } = node;
12495
+ node.consequent = convertNode(node, scope, buffer[position], buffer, readString);
12496
+ node.alternate = convertNode(node, scope, buffer[position + 1], buffer, readString);
12497
+ node.test = convertNode(node, scope, position + 2, buffer, readString);
12498
+ },
12499
+ function continueStatement(node, position, buffer, readString) {
12500
+ const { scope } = node;
12501
+ const labelPosition = buffer[position];
12502
+ node.label =
12503
+ labelPosition === 0 ? null : convertNode(node, scope, labelPosition, buffer, readString);
12504
+ },
12505
+ function debuggerStatement() { },
12506
+ function directive(node, position, buffer, readString) {
12507
+ const { scope } = node;
12508
+ node.expression = convertNode(node, scope, buffer[position], buffer, readString);
12509
+ node.directive = convertString(position + 1, buffer, readString);
12510
+ },
12511
+ function doWhileStatement(node, position, buffer, readString) {
12512
+ const { scope } = node;
12513
+ node.test = convertNode(node, scope, buffer[position], buffer, readString);
12514
+ node.body = convertNode(node, scope, position + 1, buffer, readString);
12515
+ },
12516
+ function emptyStatement() { },
12517
+ function exportAllDeclaration(node, position, buffer, readString) {
12518
+ const { scope } = node;
12519
+ const exportedPosition = buffer[position];
12520
+ node.exported =
12521
+ exportedPosition === 0
12522
+ ? null
12523
+ : convertNode(node, scope, exportedPosition, buffer, readString);
12524
+ node.source = convertNode(node, scope, buffer[position + 1], buffer, readString);
12525
+ node.attributes = convertNodeList(node, scope, buffer[position + 2], buffer, readString);
12526
+ },
12527
+ function exportDefaultDeclaration(node, position, buffer, readString) {
12528
+ const { scope } = node;
12529
+ node.declaration = convertNode(node, scope, position, buffer, readString);
12530
+ },
12531
+ function exportNamedDeclaration(node, position, buffer, readString) {
12532
+ const { scope } = node;
12533
+ const sourcePosition = buffer[position];
12534
+ node.source =
12535
+ sourcePosition === 0 ? null : convertNode(node, scope, sourcePosition, buffer, readString);
12536
+ node.attributes = convertNodeList(node, scope, buffer[position + 1], buffer, readString);
12537
+ const declarationPosition = buffer[position + 2];
12538
+ node.declaration =
12539
+ declarationPosition === 0
12540
+ ? null
12541
+ : convertNode(node, scope, declarationPosition, buffer, readString);
12542
+ node.specifiers = convertNodeList(node, scope, position + 3, buffer, readString);
12543
+ },
12544
+ function exportSpecifier(node, position, buffer, readString) {
12545
+ const { scope } = node;
12546
+ const exportedPosition = buffer[position];
12547
+ node.local = convertNode(node, scope, position + 1, buffer, readString);
12548
+ node.exported =
12549
+ exportedPosition === 0
12550
+ ? node.local
12551
+ : convertNode(node, scope, exportedPosition, buffer, readString);
12552
+ },
12553
+ function expressionStatement(node, position, buffer, readString) {
12554
+ const { scope } = node;
12555
+ node.expression = convertNode(node, scope, position, buffer, readString);
12556
+ },
12557
+ function forInStatement(node, position, buffer, readString) {
12558
+ const { scope } = node;
12559
+ node.right = convertNode(node, scope, buffer[position], buffer, readString);
12560
+ node.body = convertNode(node, scope, buffer[position + 1], buffer, readString);
12561
+ node.left = convertNode(node, scope, position + 2, buffer, readString);
12562
+ },
12563
+ function forOfStatement(node, position, buffer, readString) {
12564
+ const { scope } = node;
12565
+ const flags = buffer[position];
12566
+ node.await = (flags & 1) === 1;
12567
+ node.right = convertNode(node, scope, buffer[position + 1], buffer, readString);
12568
+ node.body = convertNode(node, scope, buffer[position + 2], buffer, readString);
12569
+ node.left = convertNode(node, scope, position + 3, buffer, readString);
12570
+ },
12571
+ function forStatement(node, position, buffer, readString) {
12572
+ const { scope } = node;
12573
+ const initPosition = buffer[position];
12574
+ node.init =
12575
+ initPosition === 0 ? null : convertNode(node, scope, initPosition, buffer, readString);
12576
+ const testPosition = buffer[position + 1];
12577
+ node.test =
12578
+ testPosition === 0 ? null : convertNode(node, scope, testPosition, buffer, readString);
12579
+ const updatePosition = buffer[position + 2];
12580
+ node.update =
12581
+ updatePosition === 0 ? null : convertNode(node, scope, updatePosition, buffer, readString);
12582
+ node.body = convertNode(node, scope, buffer[position + 3], buffer, readString);
12583
+ },
12584
+ function functionDeclaration(node, position, buffer, readString) {
12585
+ const { scope } = node;
12586
+ const flags = buffer[position];
12587
+ node.async = (flags & 1) === 1;
12588
+ node.generator = (flags & 2) === 2;
12589
+ const idPosition = buffer[position + 1];
12590
+ node.id =
12591
+ idPosition === 0
12592
+ ? null
12593
+ : convertNode(node, scope.parent, idPosition, buffer, readString);
12594
+ const parameters = (node.params = convertNodeList(node, scope, buffer[position + 2], buffer, readString));
12595
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
12596
+ node.body = convertNode(node, scope.bodyScope, buffer[position + 3], buffer, readString);
12597
+ const annotations = (node.annotations = convertAnnotations(position + 4, buffer));
12598
+ node.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
12599
+ },
12600
+ function functionExpression(node, position, buffer, readString) {
12601
+ const { scope } = node;
12602
+ const flags = buffer[position];
12603
+ node.async = (flags & 1) === 1;
12604
+ node.generator = (flags & 2) === 2;
12605
+ const idPosition = buffer[position + 1];
12606
+ node.id =
12607
+ idPosition === 0 ? null : convertNode(node, node.idScope, idPosition, buffer, readString);
12608
+ const parameters = (node.params = convertNodeList(node, scope, buffer[position + 2], buffer, readString));
12609
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
12610
+ node.body = convertNode(node, scope.bodyScope, buffer[position + 3], buffer, readString);
12611
+ const annotations = (node.annotations = convertAnnotations(position + 4, buffer));
12612
+ node.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
12613
+ },
12614
+ function identifier(node, position, buffer, readString) {
12615
+ node.name = convertString(position, buffer, readString);
12616
+ },
12617
+ function ifStatement(node, position, buffer, readString) {
12618
+ const { scope } = node;
12619
+ node.consequent = convertNode(node, (node.consequentScope = new TrackingScope(scope)), buffer[position], buffer, readString);
12620
+ const alternatePosition = buffer[position + 1];
12621
+ node.alternate =
12622
+ alternatePosition === 0
12623
+ ? null
12624
+ : convertNode(node, (node.alternateScope = new TrackingScope(scope)), alternatePosition, buffer, readString);
12625
+ node.test = convertNode(node, scope, position + 2, buffer, readString);
12626
+ },
12627
+ function importAttribute(node, position, buffer, readString) {
12628
+ const { scope } = node;
12629
+ node.value = convertNode(node, scope, buffer[position], buffer, readString);
12630
+ node.key = convertNode(node, scope, position + 1, buffer, readString);
12631
+ },
12632
+ function importDeclaration(node, position, buffer, readString) {
12633
+ const { scope } = node;
12634
+ node.source = convertNode(node, scope, buffer[position], buffer, readString);
12635
+ node.attributes = convertNodeList(node, scope, buffer[position + 1], buffer, readString);
12636
+ node.specifiers = convertNodeList(node, scope, position + 2, buffer, readString);
12637
+ },
12638
+ function importDefaultSpecifier(node, position, buffer, readString) {
12639
+ const { scope } = node;
12640
+ node.local = convertNode(node, scope, position, buffer, readString);
12641
+ },
12642
+ function importExpression(node, position, buffer, readString) {
12643
+ const { scope } = node;
12644
+ const optionsPosition = buffer[position];
12645
+ node.options =
12646
+ optionsPosition === 0 ? null : convertNode(node, scope, optionsPosition, buffer, readString);
12647
+ node.source = convertNode(node, scope, position + 1, buffer, readString);
12648
+ node.sourceAstNode = convertNode$1(position + 1, buffer, readString);
12649
+ },
12650
+ function importNamespaceSpecifier(node, position, buffer, readString) {
12651
+ const { scope } = node;
12652
+ node.local = convertNode(node, scope, position, buffer, readString);
12653
+ },
12654
+ function importSpecifier(node, position, buffer, readString) {
12655
+ const { scope } = node;
12656
+ const importedPosition = buffer[position];
12657
+ node.local = convertNode(node, scope, buffer[position + 1], buffer, readString);
12658
+ node.imported =
12659
+ importedPosition === 0
12660
+ ? node.local
12661
+ : convertNode(node, scope, importedPosition, buffer, readString);
12662
+ },
12663
+ function labeledStatement(node, position, buffer, readString) {
12664
+ const { scope } = node;
12665
+ node.body = convertNode(node, scope, buffer[position], buffer, readString);
12666
+ node.label = convertNode(node, scope, position + 1, buffer, readString);
12667
+ },
12668
+ function literalBigInt(node, position, buffer, readString) {
12669
+ node.raw = convertString(buffer[position], buffer, readString);
12670
+ const bigint = (node.bigint = convertString(position + 1, buffer, readString));
12671
+ node.value = BigInt(bigint);
12672
+ },
12673
+ function literalBoolean(node, position, buffer) {
12674
+ const flags = buffer[position];
12675
+ const value = (node.value = (flags & 1) === 1);
12676
+ node.raw = value ? 'true' : 'false';
12677
+ },
12678
+ function literalNull(node) {
12679
+ node.value = null;
12680
+ },
12681
+ function literalNumber(node, position, buffer, readString) {
12682
+ const rawPosition = buffer[position];
12683
+ node.raw = rawPosition === 0 ? undefined : convertString(rawPosition, buffer, readString);
12684
+ node.value = new DataView(buffer.buffer).getFloat64((position + 1) << 2, true);
12685
+ },
12686
+ function literalRegExp(node, position, buffer, readString) {
12687
+ const pattern = convertString(buffer[position], buffer, readString);
12688
+ const flags = convertString(position + 1, buffer, readString);
12689
+ node.raw = `/${pattern}/${flags}`;
12690
+ node.regex = { flags, pattern };
12691
+ node.value = new RegExp(pattern, flags);
12692
+ },
12693
+ function literalString(node, position, buffer, readString) {
12694
+ const rawPosition = buffer[position];
12695
+ node.raw = rawPosition === 0 ? undefined : convertString(rawPosition, buffer, readString);
12696
+ node.value = convertString(position + 1, buffer, readString);
12697
+ },
12698
+ function logicalExpression(node, position, buffer, readString) {
12699
+ const { scope } = node;
12700
+ node.operator = FIXED_STRINGS[buffer[position]];
12701
+ node.right = convertNode(node, scope, buffer[position + 1], buffer, readString);
12702
+ node.left = convertNode(node, scope, position + 2, buffer, readString);
12703
+ },
12704
+ function memberExpression(node, position, buffer, readString) {
12705
+ const { scope } = node;
12706
+ const flags = buffer[position];
12707
+ node.computed = (flags & 1) === 1;
12708
+ node.optional = (flags & 2) === 2;
12709
+ node.property = convertNode(node, scope, buffer[position + 1], buffer, readString);
12710
+ node.object = convertNode(node, scope, position + 2, buffer, readString);
12711
+ },
12712
+ function metaProperty(node, position, buffer, readString) {
12713
+ const { scope } = node;
12714
+ node.property = convertNode(node, scope, buffer[position], buffer, readString);
12715
+ node.meta = convertNode(node, scope, position + 1, buffer, readString);
12716
+ },
12717
+ function methodDefinition(node, position, buffer, readString) {
12718
+ const { scope } = node;
12719
+ const flags = buffer[position];
12720
+ node.static = (flags & 1) === 1;
12721
+ node.computed = (flags & 2) === 2;
12722
+ node.value = convertNode(node, scope, buffer[position + 1], buffer, readString);
12723
+ node.kind = FIXED_STRINGS[buffer[position + 2]];
12724
+ node.key = convertNode(node, scope, position + 3, buffer, readString);
12725
+ },
12726
+ function newExpression(node, position, buffer, readString) {
12727
+ const { scope } = node;
12728
+ node.callee = convertNode(node, scope, buffer[position], buffer, readString);
12729
+ node.arguments = convertNodeList(node, scope, buffer[position + 1], buffer, readString);
12730
+ node.annotations = convertAnnotations(position + 2, buffer);
12731
+ },
12732
+ function objectExpression(node, position, buffer, readString) {
12733
+ const { scope } = node;
12734
+ node.properties = convertNodeList(node, scope, position, buffer, readString);
12735
+ },
12736
+ function objectPattern(node, position, buffer, readString) {
12737
+ const { scope } = node;
12738
+ node.properties = convertNodeList(node, scope, position, buffer, readString);
12739
+ },
12740
+ function privateIdentifier(node, position, buffer, readString) {
12741
+ node.name = convertString(position, buffer, readString);
12742
+ },
12743
+ function program(node, position, buffer, readString) {
12744
+ const { scope } = node;
12745
+ node.invalidAnnotations = convertAnnotations(buffer[position], buffer);
12746
+ node.body = convertNodeList(node, scope, position + 1, buffer, readString);
12747
+ },
12748
+ function property(node, position, buffer, readString) {
12749
+ const { scope } = node;
12750
+ const flags = buffer[position];
12751
+ node.method = (flags & 1) === 1;
12752
+ node.shorthand = (flags & 2) === 2;
12753
+ node.computed = (flags & 4) === 4;
12754
+ const keyPosition = buffer[position + 1];
12755
+ node.value = convertNode(node, scope, buffer[position + 2], buffer, readString);
12756
+ node.kind = FIXED_STRINGS[buffer[position + 3]];
12757
+ node.key =
12758
+ keyPosition === 0 ? node.value : convertNode(node, scope, keyPosition, buffer, readString);
12759
+ },
12760
+ function propertyDefinition(node, position, buffer, readString) {
12761
+ const { scope } = node;
12762
+ const flags = buffer[position];
12763
+ node.static = (flags & 1) === 1;
12764
+ node.computed = (flags & 2) === 2;
12765
+ const valuePosition = buffer[position + 1];
12766
+ node.value =
12767
+ valuePosition === 0 ? null : convertNode(node, scope, valuePosition, buffer, readString);
12768
+ node.key = convertNode(node, scope, position + 2, buffer, readString);
12769
+ },
12770
+ function restElement(node, position, buffer, readString) {
12771
+ const { scope } = node;
12772
+ node.argument = convertNode(node, scope, position, buffer, readString);
12773
+ },
12774
+ function returnStatement(node, position, buffer, readString) {
12775
+ const { scope } = node;
12776
+ const argumentPosition = buffer[position];
12777
+ node.argument =
12778
+ argumentPosition === 0
12779
+ ? null
12780
+ : convertNode(node, scope, argumentPosition, buffer, readString);
12781
+ },
12782
+ function sequenceExpression(node, position, buffer, readString) {
12783
+ const { scope } = node;
12784
+ node.expressions = convertNodeList(node, scope, position, buffer, readString);
12785
+ },
12786
+ function spreadElement(node, position, buffer, readString) {
12787
+ const { scope } = node;
12788
+ node.argument = convertNode(node, scope, position, buffer, readString);
12789
+ },
12790
+ function staticBlock(node, position, buffer, readString) {
12791
+ const { scope } = node;
12792
+ node.body = convertNodeList(node, scope, position, buffer, readString);
12793
+ },
12794
+ function superElement() { },
12795
+ function switchCase(node, position, buffer, readString) {
12796
+ const { scope } = node;
12797
+ const testPosition = buffer[position];
12798
+ node.test =
12799
+ testPosition === 0 ? null : convertNode(node, scope, testPosition, buffer, readString);
12800
+ node.consequent = convertNodeList(node, scope, buffer[position + 1], buffer, readString);
12801
+ },
12802
+ function switchStatement(node, position, buffer, readString) {
12803
+ const { scope } = node;
12804
+ node.cases = convertNodeList(node, scope, buffer[position], buffer, readString);
12805
+ node.discriminant = convertNode(node, node.parentScope, position + 1, buffer, readString);
12806
+ },
12807
+ function taggedTemplateExpression(node, position, buffer, readString) {
12808
+ const { scope } = node;
12809
+ node.quasi = convertNode(node, scope, buffer[position], buffer, readString);
12810
+ node.tag = convertNode(node, scope, position + 1, buffer, readString);
12811
+ },
12812
+ function templateElement(node, position, buffer, readString) {
12813
+ const flags = buffer[position];
12814
+ node.tail = (flags & 1) === 1;
12815
+ const cookedPosition = buffer[position + 1];
12816
+ const cooked = cookedPosition === 0 ? undefined : convertString(cookedPosition, buffer, readString);
12817
+ const raw = convertString(position + 2, buffer, readString);
12818
+ node.value = { cooked, raw };
12819
+ },
12820
+ function templateLiteral(node, position, buffer, readString) {
12821
+ const { scope } = node;
12822
+ node.expressions = convertNodeList(node, scope, buffer[position], buffer, readString);
12823
+ node.quasis = convertNodeList(node, scope, position + 1, buffer, readString);
12824
+ },
12825
+ function thisExpression() { },
12826
+ function throwStatement(node, position, buffer, readString) {
12827
+ const { scope } = node;
12828
+ node.argument = convertNode(node, scope, position, buffer, readString);
12829
+ },
12830
+ function tryStatement(node, position, buffer, readString) {
12831
+ const { scope } = node;
12832
+ const handlerPosition = buffer[position];
12833
+ node.handler =
12834
+ handlerPosition === 0 ? null : convertNode(node, scope, handlerPosition, buffer, readString);
12835
+ const finalizerPosition = buffer[position + 1];
12836
+ node.finalizer =
12837
+ finalizerPosition === 0
12838
+ ? null
12839
+ : convertNode(node, scope, finalizerPosition, buffer, readString);
12840
+ node.block = convertNode(node, scope, position + 2, buffer, readString);
12841
+ },
12842
+ function unaryExpression(node, position, buffer, readString) {
12843
+ const { scope } = node;
12844
+ node.operator = FIXED_STRINGS[buffer[position]];
12845
+ node.argument = convertNode(node, scope, position + 1, buffer, readString);
12846
+ },
12847
+ function updateExpression(node, position, buffer, readString) {
12848
+ const { scope } = node;
12849
+ const flags = buffer[position];
12850
+ node.prefix = (flags & 1) === 1;
12851
+ node.operator = FIXED_STRINGS[buffer[position + 1]];
12852
+ node.argument = convertNode(node, scope, position + 2, buffer, readString);
12853
+ },
12854
+ function variableDeclaration(node, position, buffer, readString) {
12855
+ const { scope } = node;
12856
+ node.kind = FIXED_STRINGS[buffer[position]];
12857
+ node.declarations = convertNodeList(node, scope, position + 1, buffer, readString);
12858
+ },
12859
+ function variableDeclarator(node, position, buffer, readString) {
12860
+ const { scope } = node;
12861
+ const initPosition = buffer[position];
12862
+ node.init =
12863
+ initPosition === 0 ? null : convertNode(node, scope, initPosition, buffer, readString);
12864
+ node.id = convertNode(node, scope, position + 1, buffer, readString);
12865
+ },
12866
+ function whileStatement(node, position, buffer, readString) {
12867
+ const { scope } = node;
12868
+ node.body = convertNode(node, scope, buffer[position], buffer, readString);
12869
+ node.test = convertNode(node, scope, position + 1, buffer, readString);
12870
+ },
12871
+ function yieldExpression(node, position, buffer, readString) {
12872
+ const { scope } = node;
12873
+ const flags = buffer[position];
12874
+ node.delegate = (flags & 1) === 1;
12875
+ const argumentPosition = buffer[position + 1];
12876
+ node.argument =
12877
+ argumentPosition === 0
12878
+ ? null
12879
+ : convertNode(node, scope, argumentPosition, buffer, readString);
12880
+ }
12881
+ ];
12882
+ function convertNode(parent, parentScope, position, buffer, readString) {
12883
+ const nodeType = buffer[position];
12884
+ const NodeConstructor = nodeConstructors$1[nodeType];
12885
+ /* istanbul ignore if: This should never be executed but is a safeguard against faulty buffers */
12886
+ if (!NodeConstructor) {
12887
+ console.trace();
12888
+ throw new Error(`Unknown node type: ${nodeType}`);
12889
+ }
12890
+ const node = new NodeConstructor(parent, parentScope);
12891
+ node.type = nodeTypeStrings[nodeType];
12892
+ node.start = buffer[position + 1];
12893
+ node.end = buffer[position + 2];
12894
+ bufferParsers[nodeType](node, position + 3, buffer, readString);
12895
+ node.initialise();
12896
+ return node;
12897
+ }
12898
+ function convertNodeList(parent, parentScope, position, buffer, readString) {
12899
+ const length = buffer[position++];
12900
+ const list = [];
12901
+ for (let index = 0; index < length; index++) {
12902
+ const nodePosition = buffer[position++];
12903
+ list.push(nodePosition ? convertNode(parent, parentScope, nodePosition, buffer, readString) : null);
12904
+ }
12905
+ return list;
12906
+ }
12907
+
12908
+ class UnknownNode extends NodeBase {
12909
+ hasEffects() {
12910
+ return true;
12911
+ }
12912
+ include(context) {
12913
+ super.include(context, true);
12914
+ }
12915
+ }
12916
+
12083
12917
  const nodeConstructors = {
12084
12918
  ArrayExpression,
12085
12919
  ArrayPattern,
@@ -12127,6 +12961,8 @@ const nodeConstructors = {
12127
12961
  NewExpression,
12128
12962
  ObjectExpression,
12129
12963
  ObjectPattern,
12964
+ PanicError,
12965
+ ParseError,
12130
12966
  PrivateIdentifier,
12131
12967
  Program,
12132
12968
  Property,
@@ -12481,7 +13317,9 @@ function getAttributesFromImportExpression(node) {
12481
13317
  }
12482
13318
  const getPropertyKey = (property) => {
12483
13319
  const key = property.key;
12484
- return (key && !property.computed && (key.name || key.value));
13320
+ return (key &&
13321
+ !property.computed &&
13322
+ (key.name || key.value));
12485
13323
  };
12486
13324
  function getAttributesFromImportExportDeclaration(attributes) {
12487
13325
  return attributes?.length
@@ -13129,11 +13967,11 @@ class Module {
13129
13967
  return { source, usesTopLevelAwait };
13130
13968
  }
13131
13969
  async setSource({ ast, code, customTransformCache, originalCode, originalSourcemap, resolvedIds, sourcemapChain, transformDependencies, transformFiles, ...moduleOptions }) {
13970
+ timeStart('generate ast', 3);
13132
13971
  if (code.startsWith('#!')) {
13133
13972
  const shebangEndPosition = code.indexOf('\n');
13134
13973
  this.shebang = code.slice(2, shebangEndPosition);
13135
13974
  }
13136
- timeStart('generate ast', 3);
13137
13975
  this.info.code = code;
13138
13976
  this.originalCode = originalCode;
13139
13977
  // We need to call decodedSourcemap on the input in case they were hydrated from json in the cache and don't
@@ -13149,9 +13987,6 @@ class Module {
13149
13987
  this.transformDependencies = transformDependencies;
13150
13988
  this.customTransformCache = customTransformCache;
13151
13989
  this.updateOptions(moduleOptions);
13152
- const moduleAst = ast ?? (await this.tryParseAsync());
13153
- timeEnd('generate ast', 3);
13154
- timeStart('analyze ast', 3);
13155
13990
  this.resolvedIds = resolvedIds ?? Object.create(null);
13156
13991
  // By default, `id` is the file name. Custom resolvers and loaders
13157
13992
  // can change that, but it makes sense to use it for the source file name
@@ -13191,13 +14026,17 @@ class Module {
13191
14026
  };
13192
14027
  this.scope = new ModuleScope(this.graph.scope, this.astContext);
13193
14028
  this.namespace = new NamespaceVariable(this.astContext);
13194
- this.ast = new Program(moduleAst, { context: this.astContext, type: 'Module' }, this.scope);
13195
- // Assign AST directly if has existing one as there's no way to drop it from memory.
13196
- // If cache is enabled, also assign directly as otherwise it takes more CPU and memory to re-compute.
13197
- if (ast || this.options.cache !== false) {
13198
- this.info.ast = moduleAst;
14029
+ const programParent = { context: this.astContext, type: 'Module' };
14030
+ if (ast) {
14031
+ this.ast = new nodeConstructors[ast.type](programParent, this.scope).parseNode(ast);
14032
+ this.info.ast = ast;
13199
14033
  }
13200
14034
  else {
14035
+ // Measuring asynchronous code does not provide reasonable results
14036
+ timeEnd('generate ast', 3);
14037
+ const astBuffer = await parseAsync(code, false);
14038
+ timeStart('generate ast', 3);
14039
+ this.ast = convertProgram(astBuffer, programParent, this.scope);
13201
14040
  // Make lazy and apply LRU cache to not hog the memory
13202
14041
  Object.defineProperty(this.info, 'ast', {
13203
14042
  get: () => {
@@ -13206,13 +14045,23 @@ class Module {
13206
14045
  }
13207
14046
  else {
13208
14047
  const parsedAst = this.tryParse();
14048
+ // If the cache is not disabled, we need to keep the AST in memory
14049
+ // until the end when the cache is generated
14050
+ if (this.options.cache !== false) {
14051
+ Object.defineProperty(this.info, 'ast', {
14052
+ value: parsedAst
14053
+ });
14054
+ return parsedAst;
14055
+ }
14056
+ // Otherwise, we keep it in a small LRU cache to not hog too much
14057
+ // memory but allow the same AST to be requested several times.
13209
14058
  this.graph.astLru.set(fileName, parsedAst);
13210
14059
  return parsedAst;
13211
14060
  }
13212
14061
  }
13213
14062
  });
13214
14063
  }
13215
- timeEnd('analyze ast', 3);
14064
+ timeEnd('generate ast', 3);
13216
14065
  }
13217
14066
  toJSON() {
13218
14067
  return {
@@ -13265,13 +14114,15 @@ class Module {
13265
14114
  }
13266
14115
  }
13267
14116
  addDynamicImport(node) {
13268
- let argument = node.source;
13269
- if (argument instanceof TemplateLiteral) {
13270
- if (argument.quasis.length === 1 && argument.quasis[0].value.cooked) {
14117
+ let argument = node.sourceAstNode;
14118
+ if (argument.type === TemplateLiteral$1) {
14119
+ if (argument.quasis.length === 1 &&
14120
+ typeof argument.quasis[0].value.cooked === 'string') {
13271
14121
  argument = argument.quasis[0].value.cooked;
13272
14122
  }
13273
14123
  }
13274
- else if (argument instanceof Literal && typeof argument.value === 'string') {
14124
+ else if (argument.type === Literal$1 &&
14125
+ typeof argument.value === 'string') {
13275
14126
  argument = argument.value;
13276
14127
  }
13277
14128
  this.dynamicImports.push({ argument, id: null, node, resolution: null });
@@ -13566,14 +14417,6 @@ class Module {
13566
14417
  return this.error(logModuleParseError(error_, this.id), error_.pos);
13567
14418
  }
13568
14419
  }
13569
- async tryParseAsync() {
13570
- try {
13571
- return await parseAstAsync(this.info.code);
13572
- }
13573
- catch (error_) {
13574
- return this.error(logModuleParseError(error_, this.id), error_.pos);
13575
- }
13576
- }
13577
14420
  }
13578
14421
  // if there is a cyclic import in the reexport chain, we should not
13579
14422
  // import from the original module but from the cyclic module to not
@@ -13607,7 +14450,7 @@ function getCompleteAmdId(options, chunkId) {
13607
14450
  return options.id ?? '';
13608
14451
  }
13609
14452
 
13610
- function getExportBlock$1(exports, dependencies, namedExportsMode, interop, snippets, t, externalLiveBindings, mechanism = 'return ') {
14453
+ function getExportBlock$1(exports, dependencies, namedExportsMode, interop, snippets, t, externalLiveBindings, reexportProtoFromExternal, mechanism = 'return ') {
13611
14454
  const { _, getDirectReturnFunction, getFunctionIntro, getPropertyAccess, n, s } = snippets;
13612
14455
  if (!namedExportsMode) {
13613
14456
  return `${n}${n}${mechanism}${getSingleDefaultExport(exports, dependencies, interop, externalLiveBindings, getPropertyAccess)};`;
@@ -13664,6 +14507,16 @@ function getExportBlock$1(exports, dependencies, namedExportsMode, interop, snip
13664
14507
  if (specifier.reexported === '*') {
13665
14508
  if (exportBlock)
13666
14509
  exportBlock += n;
14510
+ if (!specifier.needsLiveBinding && reexportProtoFromExternal) {
14511
+ const protoString = "'__proto__'";
14512
+ exportBlock +=
14513
+ `Object.prototype.hasOwnProperty.call(${name},${_}${protoString})${_}&&${n}` +
14514
+ `${t}!Object.prototype.hasOwnProperty.call(exports,${_}${protoString})${_}&&${n}` +
14515
+ `${t}Object.defineProperty(exports,${_}${protoString},${_}{${n}` +
14516
+ `${t}${t}enumerable:${_}true,${n}` +
14517
+ `${t}${t}value:${_}${name}[${protoString}]${n}` +
14518
+ `${t}});${n}${n}`;
14519
+ }
13667
14520
  const copyPropertyIfNecessary = `{${n}${t}if${_}(k${_}!==${_}'default'${_}&&${_}!Object.prototype.hasOwnProperty.call(exports,${_}k))${_}${getDefineProperty(name, specifier.needsLiveBinding, t, snippets)}${s}${n}}`;
13668
14521
  exportBlock += `Object.keys(${name}).forEach(${getFunctionIntro(['k'], {
13669
14522
  isAsync: false,
@@ -13747,9 +14600,7 @@ const getDefineProperty = (name, needsLiveBinding, t, { _, getDirectReturnFuncti
13747
14600
  `${t}${t}enumerable:${_}true,${n}` +
13748
14601
  `${t}${t}get:${_}${left}${name}[k]${right}${n}${t}})`);
13749
14602
  }
13750
- return (`k${_}===${_}'__proto__'${_}?${_}Object.defineProperty(exports,${_}k,${_}{${n}` +
13751
- `${t}${t}enumerable:${_}true,${n}` +
13752
- `${t}${t}value:${_}${name}[k]${n}${t}})${_}:${_}exports[k]${_}=${_}${name}[k]`);
14603
+ return `exports[k]${_}=${_}${name}[k]`;
13753
14604
  };
13754
14605
 
13755
14606
  function getInteropBlock(dependencies, interop, externalLiveBindings, freeze, symbols, accessedGlobals, indent, snippets) {
@@ -13894,7 +14745,7 @@ function warnOnBuiltins(log, dependencies) {
13894
14745
  log(LOGLEVEL_WARN, logMissingNodeBuiltins(externalBuiltins));
13895
14746
  }
13896
14747
 
13897
- function amd(magicString, { accessedGlobals, dependencies, exports, hasDefaultExport, hasExports, id, indent: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, log, outro, snippets }, { amd, esModule, externalLiveBindings, freeze, generatedCode: { symbols }, interop, strict }) {
14748
+ function amd(magicString, { accessedGlobals, dependencies, exports, hasDefaultExport, hasExports, id, indent: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, log, outro, snippets }, { amd, esModule, externalLiveBindings, freeze, generatedCode: { symbols }, interop, reexportProtoFromExternal, strict }) {
13898
14749
  warnOnBuiltins(log, dependencies);
13899
14750
  const deps = dependencies.map(m => `'${updateExtensionForRelativeAmdId(m.importPath, amd.forceJsExtensionForImports)}'`);
13900
14751
  const parameters = dependencies.map(m => m.name);
@@ -13916,7 +14767,7 @@ function amd(magicString, { accessedGlobals, dependencies, exports, hasDefaultEx
13916
14767
  (deps.length > 0 ? `[${deps.join(`,${_}`)}],${_}` : ``);
13917
14768
  const useStrict = strict ? `${_}'use strict';` : '';
13918
14769
  magicString.prepend(`${intro}${getInteropBlock(dependencies, interop, externalLiveBindings, freeze, symbols, accessedGlobals, t, snippets)}`);
13919
- const exportBlock = getExportBlock$1(exports, dependencies, namedExportsMode, interop, snippets, t, externalLiveBindings);
14770
+ const exportBlock = getExportBlock$1(exports, dependencies, namedExportsMode, interop, snippets, t, externalLiveBindings, reexportProtoFromExternal);
13920
14771
  let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, isEntryFacade && (esModule === true || (esModule === 'if-default-prop' && hasDefaultExport)), isModuleFacade && symbols, snippets);
13921
14772
  if (namespaceMarkers) {
13922
14773
  namespaceMarkers = n + n + namespaceMarkers;
@@ -13933,7 +14784,7 @@ function amd(magicString, { accessedGlobals, dependencies, exports, hasDefaultEx
13933
14784
  .append(`${n}${n}}));`);
13934
14785
  }
13935
14786
 
13936
- function cjs(magicString, { accessedGlobals, dependencies, exports, hasDefaultExport, hasExports, indent: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, outro, snippets }, { compact, esModule, externalLiveBindings, freeze, interop, generatedCode: { symbols }, strict }) {
14787
+ function cjs(magicString, { accessedGlobals, dependencies, exports, hasDefaultExport, hasExports, indent: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, outro, snippets }, { compact, esModule, externalLiveBindings, freeze, interop, generatedCode: { symbols }, reexportProtoFromExternal, strict }) {
13937
14788
  const { _, n } = snippets;
13938
14789
  const useStrict = strict ? `'use strict';${n}${n}` : '';
13939
14790
  let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, isEntryFacade && (esModule === true || (esModule === 'if-default-prop' && hasDefaultExport)), isModuleFacade && symbols, snippets);
@@ -13943,7 +14794,7 @@ function cjs(magicString, { accessedGlobals, dependencies, exports, hasDefaultEx
13943
14794
  const importBlock = getImportBlock$1(dependencies, snippets, compact);
13944
14795
  const interopBlock = getInteropBlock(dependencies, interop, externalLiveBindings, freeze, symbols, accessedGlobals, t, snippets);
13945
14796
  magicString.prepend(`${useStrict}${intro}${namespaceMarkers}${importBlock}${interopBlock}`);
13946
- const exportBlock = getExportBlock$1(exports, dependencies, namedExportsMode, interop, snippets, t, externalLiveBindings, `module.exports${_}=${_}`);
14797
+ const exportBlock = getExportBlock$1(exports, dependencies, namedExportsMode, interop, snippets, t, externalLiveBindings, reexportProtoFromExternal, `module.exports${_}=${_}`);
13947
14798
  magicString.append(`${exportBlock}${outro}`);
13948
14799
  }
13949
14800
  function getImportBlock$1(dependencies, { _, cnst, n }, compact) {
@@ -14122,7 +14973,7 @@ function trimEmptyImports(dependencies) {
14122
14973
  return [];
14123
14974
  }
14124
14975
 
14125
- function iife(magicString, { accessedGlobals, dependencies, exports, hasDefaultExport, hasExports, indent: t, intro, namedExportsMode, log, outro, snippets }, { compact, esModule, extend, freeze, externalLiveBindings, globals, interop, name, generatedCode: { symbols }, strict }) {
14976
+ function iife(magicString, { accessedGlobals, dependencies, exports, hasDefaultExport, hasExports, indent: t, intro, namedExportsMode, log, outro, snippets }, { compact, esModule, extend, freeze, externalLiveBindings, reexportProtoFromExternal, globals, interop, name, generatedCode: { symbols }, strict }) {
14126
14977
  const { _, getNonArrowFunctionIntro, getPropertyAccess, n } = snippets;
14127
14978
  const isNamespaced = name && name.includes('.');
14128
14979
  const useVariableAssignment = !extend && !isNamespaced;
@@ -14167,7 +15018,7 @@ function iife(magicString, { accessedGlobals, dependencies, exports, hasDefaultE
14167
15018
  if (hasExports && !extend && namedExportsMode) {
14168
15019
  wrapperOutro = `${n}${n}${t}return exports;${wrapperOutro}`;
14169
15020
  }
14170
- const exportBlock = getExportBlock$1(exports, dependencies, namedExportsMode, interop, snippets, t, externalLiveBindings);
15021
+ const exportBlock = getExportBlock$1(exports, dependencies, namedExportsMode, interop, snippets, t, externalLiveBindings, reexportProtoFromExternal);
14171
15022
  let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, esModule === true || (esModule === 'if-default-prop' && hasDefaultExport), symbols, snippets);
14172
15023
  if (namespaceMarkers) {
14173
15024
  namespaceMarkers = n + n + namespaceMarkers;
@@ -14340,7 +15191,7 @@ function safeAccess(name, globalVariable, { _, getPropertyAccess }) {
14340
15191
  .map(part => (propertyPath += getPropertyAccess(part)))
14341
15192
  .join(`${_}&&${_}`);
14342
15193
  }
14343
- function umd(magicString, { accessedGlobals, dependencies, exports, hasDefaultExport, hasExports, id, indent: t, intro, namedExportsMode, log, outro, snippets }, { amd, compact, esModule, extend, externalLiveBindings, freeze, interop, name, generatedCode: { symbols }, globals, noConflict, strict }) {
15194
+ function umd(magicString, { accessedGlobals, dependencies, exports, hasDefaultExport, hasExports, id, indent: t, intro, namedExportsMode, log, outro, snippets }, { amd, compact, esModule, extend, externalLiveBindings, freeze, interop, name, generatedCode: { symbols }, globals, noConflict, reexportProtoFromExternal, strict }) {
14344
15195
  const { _, cnst, getFunctionIntro, getNonArrowFunctionIntro, getPropertyAccess, n, s } = snippets;
14345
15196
  const factoryVariable = compact ? 'f' : 'factory';
14346
15197
  const globalVariable = compact ? 'g' : 'global';
@@ -14421,7 +15272,7 @@ function umd(magicString, { accessedGlobals, dependencies, exports, hasDefaultEx
14421
15272
  })}{${useStrict}${n}`;
14422
15273
  const wrapperOutro = n + n + '}));';
14423
15274
  magicString.prepend(`${intro}${getInteropBlock(dependencies, interop, externalLiveBindings, freeze, symbols, accessedGlobals, t, snippets)}`);
14424
- const exportBlock = getExportBlock$1(exports, dependencies, namedExportsMode, interop, snippets, t, externalLiveBindings);
15275
+ const exportBlock = getExportBlock$1(exports, dependencies, namedExportsMode, interop, snippets, t, externalLiveBindings, reexportProtoFromExternal);
14425
15276
  let namespaceMarkers = getNamespaceMarkers(namedExportsMode && hasExports, esModule === true || (esModule === 'if-default-prop' && hasDefaultExport), symbols, snippets);
14426
15277
  if (namespaceMarkers) {
14427
15278
  namespaceMarkers = n + n + namespaceMarkers;
@@ -17817,7 +18668,6 @@ class ModuleLoader {
17817
18668
  ? source
17818
18669
  : error(logBadLoader(id));
17819
18670
  const code = sourceDescription.code;
17820
- /* eslint-disable-next-line unicorn/number-literal-case */
17821
18671
  if (code.charCodeAt(0) === 65279) {
17822
18672
  sourceDescription.code = code.slice(1);
17823
18673
  }
@@ -18001,9 +18851,7 @@ class ModuleLoader {
18001
18851
  }
18002
18852
  getResolveDynamicImportPromises(module) {
18003
18853
  return module.dynamicImports.map(async (dynamicImport) => {
18004
- const resolvedId = await this.resolveDynamicImport(module, typeof dynamicImport.argument === 'string'
18005
- ? dynamicImport.argument
18006
- : dynamicImport.argument.esTreeNode, module.id, getAttributesFromImportExpression(dynamicImport.node));
18854
+ const resolvedId = await this.resolveDynamicImport(module, dynamicImport.argument, module.id, getAttributesFromImportExpression(dynamicImport.node));
18007
18855
  if (resolvedId && typeof resolvedId === 'object') {
18008
18856
  dynamicImport.id = resolvedId.id;
18009
18857
  }
@@ -19312,6 +20160,7 @@ async function normalizeOutputOptions(config, inputOptions, unsetInputOptions) {
19312
20160
  plugins: await normalizePluginOption(config.plugins),
19313
20161
  preserveModules,
19314
20162
  preserveModulesRoot: getPreserveModulesRoot(config),
20163
+ reexportProtoFromExternal: config.reexportProtoFromExternal ?? true,
19315
20164
  sanitizeFileName: typeof config.sanitizeFileName === 'function'
19316
20165
  ? config.sanitizeFileName
19317
20166
  : config.sanitizeFileName === false
@@ -20013,6 +20862,7 @@ async function mergeOutputOptions(config, overrides, log) {
20013
20862
  plugins: await normalizePluginOption(config.plugins),
20014
20863
  preserveModules: getOption('preserveModules'),
20015
20864
  preserveModulesRoot: getOption('preserveModulesRoot'),
20865
+ reexportProtoFromExternal: getOption('reexportProtoFromExternal'),
20016
20866
  sanitizeFileName: getOption('sanitizeFileName'),
20017
20867
  sourcemap: getOption('sourcemap'),
20018
20868
  sourcemapBaseUrl: getOption('sourcemapBaseUrl'),