@rollup/wasm-node 4.11.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,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v4.11.0
4
- Thu, 15 Feb 2024 06:09:01 GMT - commit 90ad652b745c5fe7167d92b4ad671cc387577a99
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
 
@@ -14,8 +14,8 @@ const process$1 = require('node:process');
14
14
  const tty = require('tty');
15
15
  const node_path = require('node:path');
16
16
  const require$$0$1 = require('path');
17
- const node_perf_hooks = require('node:perf_hooks');
18
17
  const native_js = require('../native.js');
18
+ const node_perf_hooks = require('node:perf_hooks');
19
19
  const promises = require('node:fs/promises');
20
20
 
21
21
  function _interopNamespaceDefault(e) {
@@ -31,7 +31,7 @@ function _interopNamespaceDefault(e) {
31
31
 
32
32
  const tty__namespace = /*#__PURE__*/_interopNamespaceDefault(tty);
33
33
 
34
- var version = "4.11.0";
34
+ var version = "4.12.0";
35
35
 
36
36
  function ensureArray$1(items) {
37
37
  if (Array.isArray(items)) {
@@ -6069,13 +6069,83 @@ function getMemberReturnExpressionWhenCalled(members, memberName) {
6069
6069
  return [members[memberName].returns, false];
6070
6070
  }
6071
6071
 
6072
- const keys = {
6072
+ // This file is generated by scripts/generate-ast-converters.js.
6073
+ // Do not edit this file directly.
6074
+ const childNodeKeys = {
6075
+ ArrayExpression: ['elements'],
6076
+ ArrayPattern: ['elements'],
6077
+ ArrowFunctionExpression: ['params', 'body'],
6078
+ AssignmentExpression: ['left', 'right'],
6079
+ AssignmentPattern: ['left', 'right'],
6080
+ AwaitExpression: ['argument'],
6081
+ BinaryExpression: ['left', 'right'],
6082
+ BlockStatement: ['body'],
6083
+ BreakStatement: ['label'],
6084
+ CallExpression: ['callee', 'arguments'],
6085
+ CatchClause: ['param', 'body'],
6086
+ ChainExpression: ['expression'],
6087
+ ClassBody: ['body'],
6088
+ ClassDeclaration: ['id', 'superClass', 'body'],
6089
+ ClassExpression: ['id', 'superClass', 'body'],
6090
+ ConditionalExpression: ['test', 'consequent', 'alternate'],
6091
+ ContinueStatement: ['label'],
6092
+ DebuggerStatement: [],
6093
+ DoWhileStatement: ['body', 'test'],
6094
+ EmptyStatement: [],
6095
+ ExportAllDeclaration: ['exported', 'source', 'attributes'],
6096
+ ExportDefaultDeclaration: ['declaration'],
6097
+ ExportNamedDeclaration: ['specifiers', 'source', 'attributes', 'declaration'],
6098
+ ExportSpecifier: ['local', 'exported'],
6099
+ ExpressionStatement: ['expression'],
6100
+ ForInStatement: ['left', 'right', 'body'],
6101
+ ForOfStatement: ['left', 'right', 'body'],
6102
+ ForStatement: ['init', 'test', 'update', 'body'],
6103
+ FunctionDeclaration: ['id', 'params', 'body'],
6104
+ FunctionExpression: ['id', 'params', 'body'],
6105
+ Identifier: [],
6106
+ IfStatement: ['test', 'consequent', 'alternate'],
6107
+ ImportAttribute: ['key', 'value'],
6108
+ ImportDeclaration: ['specifiers', 'source', 'attributes'],
6109
+ ImportDefaultSpecifier: ['local'],
6110
+ ImportExpression: ['source', 'options'],
6111
+ ImportNamespaceSpecifier: ['local'],
6112
+ ImportSpecifier: ['imported', 'local'],
6113
+ LabeledStatement: ['label', 'body'],
6073
6114
  Literal: [],
6074
- Program: ['body']
6115
+ LogicalExpression: ['left', 'right'],
6116
+ MemberExpression: ['object', 'property'],
6117
+ MetaProperty: ['meta', 'property'],
6118
+ MethodDefinition: ['key', 'value'],
6119
+ NewExpression: ['callee', 'arguments'],
6120
+ ObjectExpression: ['properties'],
6121
+ ObjectPattern: ['properties'],
6122
+ PanicError: [],
6123
+ ParseError: [],
6124
+ PrivateIdentifier: [],
6125
+ Program: ['body'],
6126
+ Property: ['key', 'value'],
6127
+ PropertyDefinition: ['key', 'value'],
6128
+ RestElement: ['argument'],
6129
+ ReturnStatement: ['argument'],
6130
+ SequenceExpression: ['expressions'],
6131
+ SpreadElement: ['argument'],
6132
+ StaticBlock: ['body'],
6133
+ Super: [],
6134
+ SwitchCase: ['test', 'consequent'],
6135
+ SwitchStatement: ['discriminant', 'cases'],
6136
+ TaggedTemplateExpression: ['tag', 'quasi'],
6137
+ TemplateElement: [],
6138
+ TemplateLiteral: ['quasis', 'expressions'],
6139
+ ThisExpression: [],
6140
+ ThrowStatement: ['argument'],
6141
+ TryStatement: ['block', 'handler', 'finalizer'],
6142
+ UnaryExpression: ['argument'],
6143
+ UpdateExpression: ['argument'],
6144
+ VariableDeclaration: ['declarations'],
6145
+ VariableDeclarator: ['id', 'init'],
6146
+ WhileStatement: ['test', 'body'],
6147
+ YieldExpression: ['argument']
6075
6148
  };
6076
- function createKeysForNode(esTreeNode) {
6077
- return Object.keys(esTreeNode).filter(key => typeof esTreeNode[key] === 'object' && key.charCodeAt(0) !== 95 /* _ */);
6078
- }
6079
6149
 
6080
6150
  const INCLUDE_PARAMETERS = 'variables';
6081
6151
  class NodeBase extends ExpressionEntity {
@@ -6091,22 +6161,11 @@ class NodeBase extends ExpressionEntity {
6091
6161
  set deoptimized(value) {
6092
6162
  this.flags = setFlag(this.flags, 2 /* Flag.deoptimized */, value);
6093
6163
  }
6094
- constructor(esTreeNode, parent, parentScope, keepEsTreeNode = false) {
6164
+ constructor(parent, parentScope) {
6095
6165
  super();
6096
- // Nodes can opt-in to keep the AST if needed during the build pipeline.
6097
- // Avoid true when possible as large AST takes up memory.
6098
- if (keepEsTreeNode) {
6099
- this.esTreeNode = esTreeNode;
6100
- }
6101
- const { type } = esTreeNode;
6102
- keys[type] ||= createKeysForNode(esTreeNode);
6103
6166
  this.parent = parent;
6104
6167
  this.scope = parentScope;
6105
6168
  this.createScope(parentScope);
6106
- this.parseNode(esTreeNode);
6107
- this.initialise();
6108
- this.scope.context.magicString.addSourcemapLocation(this.start);
6109
- this.scope.context.magicString.addSourcemapLocation(this.end);
6110
6169
  }
6111
6170
  addExportedVariables(_variables, _exportNamesByVariable) { }
6112
6171
  /**
@@ -6114,7 +6173,7 @@ class NodeBase extends ExpressionEntity {
6114
6173
  * that require the scopes to be populated with variables.
6115
6174
  */
6116
6175
  bind() {
6117
- for (const key of keys[this.type]) {
6176
+ for (const key of childNodeKeys[this.type]) {
6118
6177
  const value = this[key];
6119
6178
  if (Array.isArray(value)) {
6120
6179
  for (const child of value) {
@@ -6136,7 +6195,7 @@ class NodeBase extends ExpressionEntity {
6136
6195
  hasEffects(context) {
6137
6196
  if (!this.deoptimized)
6138
6197
  this.applyDeoptimizations();
6139
- for (const key of keys[this.type]) {
6198
+ for (const key of childNodeKeys[this.type]) {
6140
6199
  const value = this[key];
6141
6200
  if (value === null)
6142
6201
  continue;
@@ -6159,7 +6218,7 @@ class NodeBase extends ExpressionEntity {
6159
6218
  if (!this.deoptimized)
6160
6219
  this.applyDeoptimizations();
6161
6220
  this.included = true;
6162
- for (const key of keys[this.type]) {
6221
+ for (const key of childNodeKeys[this.type]) {
6163
6222
  const value = this[key];
6164
6223
  if (value === null)
6165
6224
  continue;
@@ -6180,8 +6239,11 @@ class NodeBase extends ExpressionEntity {
6180
6239
  * Override to perform special initialisation steps after the scope is
6181
6240
  * initialised
6182
6241
  */
6183
- initialise() { }
6184
- parseNode(esTreeNode, keepEsTreeNodeKeys) {
6242
+ initialise() {
6243
+ this.scope.context.magicString.addSourcemapLocation(this.start);
6244
+ this.scope.context.magicString.addSourcemapLocation(this.end);
6245
+ }
6246
+ parseNode(esTreeNode) {
6185
6247
  for (const [key, value] of Object.entries(esTreeNode)) {
6186
6248
  // Skip properties defined on the class already.
6187
6249
  // This way, we can override this function to add custom initialisation and then call super.parseNode
@@ -6191,20 +6253,10 @@ class NodeBase extends ExpressionEntity {
6191
6253
  continue;
6192
6254
  if (key.charCodeAt(0) === 95 /* _ */) {
6193
6255
  if (key === parseAst_js.ANNOTATION_KEY) {
6194
- const annotations = value;
6195
- this.annotations = annotations;
6196
- if (this.scope.context.options.treeshake.annotations) {
6197
- this.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
6198
- this.annotationPure = annotations.some(comment => comment.type === 'pure');
6199
- }
6256
+ this.annotations = value;
6200
6257
  }
6201
6258
  else if (key === parseAst_js.INVALID_ANNOTATION_KEY) {
6202
- for (const { start, end, type } of value) {
6203
- this.scope.context.magicString.remove(start, end);
6204
- if (type === 'pure' || type === 'noSideEffects') {
6205
- this.scope.context.log(parseAst_js.LOGLEVEL_WARN, parseAst_js.logInvalidAnnotation(this.scope.context.code.slice(start, end), this.scope.context.module.id, type), start);
6206
- }
6207
- }
6259
+ this.invalidAnnotations = value;
6208
6260
  }
6209
6261
  }
6210
6262
  else if (typeof value !== 'object' || value === null) {
@@ -6215,13 +6267,17 @@ class NodeBase extends ExpressionEntity {
6215
6267
  for (const child of value) {
6216
6268
  this[key].push(child === null
6217
6269
  ? null
6218
- : new (this.scope.context.getNodeConstructor(child.type))(child, this, this.scope, keepEsTreeNodeKeys?.includes(key)));
6270
+ : new (this.scope.context.getNodeConstructor(child.type))(this, this.scope).parseNode(child));
6219
6271
  }
6220
6272
  }
6221
6273
  else {
6222
- this[key] = new (this.scope.context.getNodeConstructor(value.type))(value, this, this.scope, keepEsTreeNodeKeys?.includes(key));
6274
+ this[key] = new (this.scope.context.getNodeConstructor(value.type))(this, this.scope).parseNode(value);
6223
6275
  }
6224
6276
  }
6277
+ // extend child keys for unknown node types
6278
+ childNodeKeys[esTreeNode.type] ||= createChildNodeKeysForNode(esTreeNode);
6279
+ this.initialise();
6280
+ return this;
6225
6281
  }
6226
6282
  removeAnnotations(code) {
6227
6283
  if (this.annotations) {
@@ -6231,7 +6287,7 @@ class NodeBase extends ExpressionEntity {
6231
6287
  }
6232
6288
  }
6233
6289
  render(code, options) {
6234
- for (const key of keys[this.type]) {
6290
+ for (const key of childNodeKeys[this.type]) {
6235
6291
  const value = this[key];
6236
6292
  if (value === null)
6237
6293
  continue;
@@ -6258,7 +6314,7 @@ class NodeBase extends ExpressionEntity {
6258
6314
  */
6259
6315
  applyDeoptimizations() {
6260
6316
  this.deoptimized = true;
6261
- for (const key of keys[this.type]) {
6317
+ for (const key of childNodeKeys[this.type]) {
6262
6318
  const value = this[key];
6263
6319
  if (value === null)
6264
6320
  continue;
@@ -6274,6 +6330,9 @@ class NodeBase extends ExpressionEntity {
6274
6330
  this.scope.context.requestTreeshakingPass();
6275
6331
  }
6276
6332
  }
6333
+ function createChildNodeKeysForNode(esTreeNode) {
6334
+ return Object.keys(esTreeNode).filter(key => typeof esTreeNode[key] === 'object' && key.charCodeAt(0) !== 95 /* _ */);
6335
+ }
6277
6336
 
6278
6337
  class SpreadElement extends NodeBase {
6279
6338
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
@@ -7026,16 +7085,6 @@ class ArrayPattern extends NodeBase {
7026
7085
  }
7027
7086
  }
7028
7087
 
7029
- const ArrowFunctionExpression$1 = 'ArrowFunctionExpression';
7030
- const BlockStatement$1 = 'BlockStatement';
7031
- const CallExpression$1 = 'CallExpression';
7032
- const CatchClause$1 = 'CatchClause';
7033
- const ExpressionStatement$1 = 'ExpressionStatement';
7034
- const Identifier$1 = 'Identifier';
7035
- const Program$1 = 'Program';
7036
- const Property$1 = 'Property';
7037
- const ReturnStatement$1 = 'ReturnStatement';
7038
-
7039
7088
  class LocalVariable extends Variable {
7040
7089
  constructor(name, declarator, init, context, kind) {
7041
7090
  super(name);
@@ -7141,7 +7190,7 @@ class LocalVariable extends Variable {
7141
7190
  // We do not want to properly include parents in case they are part of a dead branch
7142
7191
  // in which case .include() might pull in more dead code
7143
7192
  node.included = true;
7144
- if (node.type === Program$1)
7193
+ if (node.type === parseAst_js.Program)
7145
7194
  break;
7146
7195
  node = node.parent;
7147
7196
  }
@@ -7180,7 +7229,7 @@ const EMPTY_PATH_TRACKER = new PathTracker();
7180
7229
  const UNKNOWN_DEOPTIMIZED_ENTITY = new Set([UNKNOWN_EXPRESSION]);
7181
7230
  class ParameterVariable extends LocalVariable {
7182
7231
  constructor(name, declarator, context) {
7183
- super(name, declarator, UNKNOWN_EXPRESSION, context, "parameter" /* VariableKind.parameter */);
7232
+ super(name, declarator, UNKNOWN_EXPRESSION, context, 'parameter');
7184
7233
  this.deoptimizationInteractions = [];
7185
7234
  this.deoptimizations = new PathTracker();
7186
7235
  this.deoptimizedFields = new Set();
@@ -7305,7 +7354,7 @@ class Scope {
7305
7354
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
7306
7355
  if (existingVariable) {
7307
7356
  const existingKind = existingVariable.kind;
7308
- if (kind === "var" /* VariableKind.var */ && existingKind === "var" /* VariableKind.var */) {
7357
+ if (kind === 'var' && existingKind === 'var') {
7309
7358
  existingVariable.addDeclaration(identifier, init);
7310
7359
  return existingVariable;
7311
7360
  }
@@ -7416,14 +7465,14 @@ class CatchBodyScope extends ChildScope {
7416
7465
  this.parent = parent;
7417
7466
  }
7418
7467
  addDeclaration(identifier, context, init, kind) {
7419
- if (kind === "var" /* VariableKind.var */) {
7468
+ if (kind === 'var') {
7420
7469
  const name = identifier.name;
7421
7470
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
7422
7471
  if (existingVariable) {
7423
7472
  const existingKind = existingVariable.kind;
7424
- if (existingKind === "parameter" /* VariableKind.parameter */ &&
7473
+ if (existingKind === 'parameter' &&
7425
7474
  // If this is a destructured parameter, it is forbidden to redeclare
7426
- existingVariable.declarations[0].parent.type === CatchClause$1) {
7475
+ existingVariable.declarations[0].parent.type === parseAst_js.CatchClause) {
7427
7476
  // If this is a var with the same name as the catch scope parameter,
7428
7477
  // the assignment actually goes to the parameter and the var is
7429
7478
  // hoisted without assignment. Locally, it is shadowed by the
@@ -7440,7 +7489,7 @@ class CatchBodyScope extends ChildScope {
7440
7489
  this.addHoistedVariable(name, declaredVariable);
7441
7490
  return declaredVariable;
7442
7491
  }
7443
- if (existingKind === "var" /* VariableKind.var */) {
7492
+ if (existingKind === 'var') {
7444
7493
  existingVariable.addDeclaration(identifier, init);
7445
7494
  return existingVariable;
7446
7495
  }
@@ -7470,10 +7519,8 @@ class FunctionBodyScope extends ChildScope {
7470
7519
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
7471
7520
  if (existingVariable) {
7472
7521
  const existingKind = existingVariable.kind;
7473
- if ((kind === "var" /* VariableKind.var */ || kind === "function" /* VariableKind.function */) &&
7474
- (existingKind === "var" /* VariableKind.var */ ||
7475
- existingKind === "function" /* VariableKind.function */ ||
7476
- existingKind === "parameter" /* VariableKind.parameter */)) {
7522
+ if ((kind === 'var' || kind === 'function') &&
7523
+ (existingKind === 'var' || existingKind === 'function' || existingKind === 'parameter')) {
7477
7524
  existingVariable.addDeclaration(identifier, init);
7478
7525
  return existingVariable;
7479
7526
  }
@@ -8692,7 +8739,7 @@ class Identifier extends NodeBase {
8692
8739
  let variable;
8693
8740
  const { treeshake } = this.scope.context.options;
8694
8741
  switch (kind) {
8695
- case "var" /* VariableKind.var */: {
8742
+ case 'var': {
8696
8743
  variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
8697
8744
  if (treeshake && treeshake.correctVarValueBeforeDeclaration) {
8698
8745
  // Necessary to make sure the init is deoptimized. We cannot call deoptimizePath here.
@@ -8700,18 +8747,18 @@ class Identifier extends NodeBase {
8700
8747
  }
8701
8748
  break;
8702
8749
  }
8703
- case "function" /* VariableKind.function */: {
8750
+ case 'function': {
8704
8751
  // in strict mode, functions are only hoisted within a scope but not across block scopes
8705
8752
  variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
8706
8753
  break;
8707
8754
  }
8708
- case "let" /* VariableKind.let */:
8709
- case "const" /* VariableKind.const */:
8710
- case "class" /* VariableKind.class */: {
8755
+ case 'let':
8756
+ case 'const':
8757
+ case 'class': {
8711
8758
  variable = this.scope.addDeclaration(this, this.scope.context, init, kind);
8712
8759
  break;
8713
8760
  }
8714
- case "parameter" /* VariableKind.parameter */: {
8761
+ case 'parameter': {
8715
8762
  variable = this.scope.addParameterDeclaration(this);
8716
8763
  break;
8717
8764
  }
@@ -8744,7 +8791,7 @@ class Identifier extends NodeBase {
8744
8791
  hasEffects(context) {
8745
8792
  if (!this.deoptimized)
8746
8793
  this.applyDeoptimizations();
8747
- if (this.isPossibleTDZ() && this.variable.kind !== "var" /* VariableKind.var */) {
8794
+ if (this.isPossibleTDZ() && this.variable.kind !== 'var') {
8748
8795
  return true;
8749
8796
  }
8750
8797
  return (this.scope.context.options.treeshake
@@ -8831,7 +8878,7 @@ class Identifier extends NodeBase {
8831
8878
  }
8832
8879
  // In strict mode, any variable named "eval" must be the actual "eval" function
8833
8880
  if (name === 'eval' &&
8834
- renderedParentType === CallExpression$1 &&
8881
+ renderedParentType === parseAst_js.CallExpression &&
8835
8882
  isCalleeOfRenderedParent) {
8836
8883
  code.appendRight(this.start, '0, ');
8837
8884
  }
@@ -9019,12 +9066,12 @@ class BlockScope extends ChildScope {
9019
9066
  super(parent, parent.context);
9020
9067
  }
9021
9068
  addDeclaration(identifier, context, init, kind) {
9022
- if (kind === "var" /* VariableKind.var */) {
9069
+ if (kind === 'var') {
9023
9070
  const name = identifier.name;
9024
9071
  const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
9025
9072
  if (existingVariable) {
9026
- if (existingVariable.kind === "var" /* VariableKind.var */ ||
9027
- (kind === "var" /* VariableKind.var */ && existingVariable.kind === "parameter" /* VariableKind.parameter */)) {
9073
+ if (existingVariable.kind === 'var' ||
9074
+ (kind === 'var' && existingVariable.kind === 'parameter')) {
9028
9075
  existingVariable.addDeclaration(identifier, init);
9029
9076
  return existingVariable;
9030
9077
  }
@@ -9044,9 +9091,10 @@ class BlockScope extends ChildScope {
9044
9091
 
9045
9092
  class ExpressionStatement extends NodeBase {
9046
9093
  initialise() {
9094
+ super.initialise();
9047
9095
  if (this.directive &&
9048
9096
  this.directive !== 'use strict' &&
9049
- this.parent.type === Program$1) {
9097
+ this.parent.type === parseAst_js.Program) {
9050
9098
  this.scope.context.log(parseAst_js.LOGLEVEL_WARN,
9051
9099
  // This is necessary, because either way (deleting or not) can lead to errors.
9052
9100
  parseAst_js.logModuleLevelDirective(this.directive, this.scope.context.module.id), this.start);
@@ -9063,7 +9111,7 @@ class ExpressionStatement extends NodeBase {
9063
9111
  }
9064
9112
  shouldBeIncluded(context) {
9065
9113
  if (this.directive && this.directive !== 'use strict')
9066
- return this.parent.type !== Program$1;
9114
+ return this.parent.type !== parseAst_js.Program;
9067
9115
  return super.shouldBeIncluded(context);
9068
9116
  }
9069
9117
  applyDeoptimizations() { }
@@ -9084,7 +9132,7 @@ class BlockStatement extends NodeBase {
9084
9132
  }
9085
9133
  addImplicitReturnExpressionToScope() {
9086
9134
  const lastStatement = this.body[this.body.length - 1];
9087
- if (!lastStatement || lastStatement.type !== ReturnStatement$1) {
9135
+ if (!lastStatement || lastStatement.type !== parseAst_js.ReturnStatement) {
9088
9136
  this.scope.addReturnExpression(UNKNOWN_EXPRESSION);
9089
9137
  }
9090
9138
  }
@@ -9117,6 +9165,7 @@ class BlockStatement extends NodeBase {
9117
9165
  }
9118
9166
  }
9119
9167
  initialise() {
9168
+ super.initialise();
9120
9169
  const firstBodyStatement = this.body[0];
9121
9170
  this.deoptimizeBody =
9122
9171
  firstBodyStatement instanceof ExpressionStatement &&
@@ -9180,6 +9229,12 @@ class FunctionBase extends NodeBase {
9180
9229
  set deoptimizedReturn(value) {
9181
9230
  this.flags = setFlag(this.flags, 512 /* Flag.deoptimizedReturn */, value);
9182
9231
  }
9232
+ get generator() {
9233
+ return isFlagSet(this.flags, 4194304 /* Flag.generator */);
9234
+ }
9235
+ set generator(value) {
9236
+ this.flags = setFlag(this.flags, 4194304 /* Flag.generator */, value);
9237
+ }
9183
9238
  deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
9184
9239
  if (interaction.type === INTERACTION_CALLED) {
9185
9240
  const { parameters } = this.scope;
@@ -9276,12 +9331,17 @@ class FunctionBase extends NodeBase {
9276
9331
  this.scope.includeCallArguments(context, parameters);
9277
9332
  }
9278
9333
  initialise() {
9334
+ super.initialise();
9279
9335
  if (this.body instanceof BlockStatement) {
9280
9336
  this.body.addImplicitReturnExpressionToScope();
9281
9337
  }
9282
9338
  else {
9283
9339
  this.scope.addReturnExpression(this.body);
9284
9340
  }
9341
+ if (this.annotations &&
9342
+ this.scope.context.options.treeshake.annotations) {
9343
+ this.annotationNoSideEffects = this.annotations.some(comment => comment.type === 'noSideEffects');
9344
+ }
9285
9345
  }
9286
9346
  parseNode(esTreeNode) {
9287
9347
  const { body, params } = esTreeNode;
@@ -9292,11 +9352,11 @@ class FunctionBase extends NodeBase {
9292
9352
  // so that the scope already knows all parameters and can detect conflicts
9293
9353
  // when parsing the body.
9294
9354
  for (const parameter of params) {
9295
- parameters.push(new (context.getNodeConstructor(parameter.type))(parameter, this, scope, false));
9355
+ parameters.push(new (context.getNodeConstructor(parameter.type))(this, scope).parseNode(parameter));
9296
9356
  }
9297
- scope.addParameterVariables(parameters.map(parameter => parameter.declare("parameter" /* VariableKind.parameter */, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
9298
- this.body = new (context.getNodeConstructor(body.type))(body, this, bodyScope);
9299
- super.parseNode(esTreeNode);
9357
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
9358
+ this.body = new (context.getNodeConstructor(body.type))(this, bodyScope).parseNode(body);
9359
+ return super.parseNode(esTreeNode);
9300
9360
  }
9301
9361
  addArgumentToBeDeoptimized(_argument) { }
9302
9362
  applyDeoptimizations() { }
@@ -9308,6 +9368,12 @@ class ArrowFunctionExpression extends FunctionBase {
9308
9368
  super(...arguments);
9309
9369
  this.objectEntity = null;
9310
9370
  }
9371
+ get expression() {
9372
+ return isFlagSet(this.flags, 8388608 /* Flag.expression */);
9373
+ }
9374
+ set expression(value) {
9375
+ this.flags = setFlag(this.flags, 8388608 /* Flag.expression */, value);
9376
+ }
9311
9377
  createScope(parentScope) {
9312
9378
  this.scope = new ReturnValueScope(parentScope, false);
9313
9379
  }
@@ -9401,7 +9467,7 @@ function renderSystemExportSequenceBeforeExpression(exportedVariable, expression
9401
9467
  class ObjectPattern extends NodeBase {
9402
9468
  addExportedVariables(variables, exportNamesByVariable) {
9403
9469
  for (const property of this.properties) {
9404
- if (property.type === Property$1) {
9470
+ if (property.type === parseAst_js.Property) {
9405
9471
  property.value.addExportedVariables(variables, exportNamesByVariable);
9406
9472
  }
9407
9473
  else {
@@ -9466,6 +9532,7 @@ class AssignmentExpression extends NodeBase {
9466
9532
  right.include(context, includeChildrenRecursively);
9467
9533
  }
9468
9534
  initialise() {
9535
+ super.initialise();
9469
9536
  if (this.left instanceof Identifier) {
9470
9537
  const variable = this.scope.variables.get(this.left.name);
9471
9538
  if (variable?.kind === 'const') {
@@ -9500,7 +9567,7 @@ class AssignmentExpression extends NodeBase {
9500
9567
  renderSystemExportExpression(variable, start, end, code, options);
9501
9568
  }
9502
9569
  else {
9503
- renderSystemExportSequenceAfterExpression(variable, start, end, parent.type !== ExpressionStatement$1, code, options);
9570
+ renderSystemExportSequenceAfterExpression(variable, start, end, parent.type !== parseAst_js.ExpressionStatement, code, options);
9504
9571
  }
9505
9572
  return;
9506
9573
  }
@@ -9509,15 +9576,15 @@ class AssignmentExpression extends NodeBase {
9509
9576
  const systemPatternExports = [];
9510
9577
  left.addExportedVariables(systemPatternExports, options.exportNamesByVariable);
9511
9578
  if (systemPatternExports.length > 0) {
9512
- renderSystemExportFunction(systemPatternExports, start, end, renderedSurroundingElement === ExpressionStatement$1, code, options);
9579
+ renderSystemExportFunction(systemPatternExports, start, end, renderedSurroundingElement === parseAst_js.ExpressionStatement, code, options);
9513
9580
  return;
9514
9581
  }
9515
9582
  }
9516
9583
  }
9517
9584
  if (left.included &&
9518
9585
  left instanceof ObjectPattern &&
9519
- (renderedSurroundingElement === ExpressionStatement$1 ||
9520
- renderedSurroundingElement === ArrowFunctionExpression$1)) {
9586
+ (renderedSurroundingElement === parseAst_js.ExpressionStatement ||
9587
+ renderedSurroundingElement === parseAst_js.ArrowFunctionExpression)) {
9521
9588
  code.appendRight(start, '(');
9522
9589
  code.prependLeft(end, ')');
9523
9590
  }
@@ -9560,7 +9627,7 @@ class AssignmentPattern extends NodeBase {
9560
9627
 
9561
9628
  class ArgumentsVariable extends LocalVariable {
9562
9629
  constructor(context) {
9563
- super('arguments', null, UNKNOWN_EXPRESSION, context, "other" /* VariableKind.other */);
9630
+ super('arguments', null, UNKNOWN_EXPRESSION, context, 'other');
9564
9631
  this.deoptimizedArguments = [];
9565
9632
  }
9566
9633
  addArgumentToBeDeoptimized(argument) {
@@ -9683,7 +9750,7 @@ class FunctionNode extends FunctionBase {
9683
9750
  }
9684
9751
  initialise() {
9685
9752
  super.initialise();
9686
- this.id?.declare("function" /* VariableKind.function */, this);
9753
+ this.id?.declare('function', this);
9687
9754
  }
9688
9755
  addArgumentToBeDeoptimized(argument) {
9689
9756
  this.scope.argumentsVariable.addArgumentToBeDeoptimized(argument);
@@ -9880,12 +9947,13 @@ class Literal extends NodeBase {
9880
9947
  }
9881
9948
  }
9882
9949
  initialise() {
9950
+ super.initialise();
9883
9951
  this.members = getLiteralMembersForValue(this.value);
9884
9952
  }
9885
9953
  parseNode(esTreeNode) {
9886
9954
  this.value = esTreeNode.value;
9887
9955
  this.regex = esTreeNode.regex;
9888
- super.parseNode(esTreeNode);
9956
+ return super.parseNode(esTreeNode);
9889
9957
  }
9890
9958
  render(code) {
9891
9959
  if (typeof this.value === 'string') {
@@ -10103,6 +10171,7 @@ class MemberExpression extends NodeBase {
10103
10171
  }
10104
10172
  }
10105
10173
  initialise() {
10174
+ super.initialise();
10106
10175
  this.propertyKey = getResolvablePropertyKey(this);
10107
10176
  this.accessInteraction = { args: [this.object], type: INTERACTION_ACCESSED };
10108
10177
  }
@@ -10382,6 +10451,13 @@ class CallExpression extends CallExpressionBase {
10382
10451
  }
10383
10452
  this.callee.includeCallArguments(context, this.arguments);
10384
10453
  }
10454
+ initialise() {
10455
+ super.initialise();
10456
+ if (this.annotations &&
10457
+ this.scope.context.options.treeshake.annotations) {
10458
+ this.annotationPure = this.annotations.some(comment => comment.type === 'pure');
10459
+ }
10460
+ }
10385
10461
  isSkippedAsOptional(origin) {
10386
10462
  return (this.callee.isSkippedAsOptional?.(origin) ||
10387
10463
  (this.optional &&
@@ -10416,11 +10492,11 @@ class CatchClause extends NodeBase {
10416
10492
  const { body, param, type } = esTreeNode;
10417
10493
  this.type = type;
10418
10494
  if (param) {
10419
- this.param = new (this.scope.context.getNodeConstructor(param.type))(param, this, this.scope);
10420
- this.param.declare("parameter" /* VariableKind.parameter */, UNKNOWN_EXPRESSION);
10495
+ this.param = new (this.scope.context.getNodeConstructor(param.type))(this, this.scope).parseNode(param);
10496
+ this.param.declare('parameter', UNKNOWN_EXPRESSION);
10421
10497
  }
10422
- this.body = new BlockStatement(body, this, this.scope.bodyScope);
10423
- super.parseNode(esTreeNode);
10498
+ this.body = new BlockStatement(this, this.scope.bodyScope).parseNode(body);
10499
+ return super.parseNode(esTreeNode);
10424
10500
  }
10425
10501
  }
10426
10502
  CatchClause.prototype.preventChildBlockScope = true;
@@ -10447,7 +10523,7 @@ class ClassBodyScope extends ChildScope {
10447
10523
  constructor(parent, classNode) {
10448
10524
  const { context } = parent;
10449
10525
  super(parent, context);
10450
- this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, context, "other" /* VariableKind.other */)));
10526
+ this.variables.set('this', (this.thisVariable = new LocalVariable('this', null, classNode, context, 'other')));
10451
10527
  this.instanceScope = new ChildScope(this, context);
10452
10528
  this.instanceScope.variables.set('this', new ThisVariable(context));
10453
10529
  }
@@ -10470,9 +10546,9 @@ class ClassBody extends NodeBase {
10470
10546
  parseNode(esTreeNode) {
10471
10547
  const body = (this.body = []);
10472
10548
  for (const definition of esTreeNode.body) {
10473
- body.push(new (this.scope.context.getNodeConstructor(definition.type))(definition, this, definition.static ? this.scope : this.scope.instanceScope));
10549
+ body.push(new (this.scope.context.getNodeConstructor(definition.type))(this, definition.static ? this.scope : this.scope.instanceScope).parseNode(definition));
10474
10550
  }
10475
- super.parseNode(esTreeNode);
10551
+ return super.parseNode(esTreeNode);
10476
10552
  }
10477
10553
  applyDeoptimizations() { }
10478
10554
  }
@@ -10631,7 +10707,8 @@ class ClassNode extends NodeBase {
10631
10707
  }
10632
10708
  }
10633
10709
  initialise() {
10634
- this.id?.declare("class" /* VariableKind.class */, this);
10710
+ super.initialise();
10711
+ this.id?.declare('class', this);
10635
10712
  for (const method of this.body.body) {
10636
10713
  if (method instanceof MethodDefinition && method.kind === 'constructor') {
10637
10714
  this.classConstructor = method;
@@ -10701,9 +10778,9 @@ class ClassDeclaration extends ClassNode {
10701
10778
  }
10702
10779
  parseNode(esTreeNode) {
10703
10780
  if (esTreeNode.id !== null) {
10704
- this.id = new Identifier(esTreeNode.id, this, this.scope.parent);
10781
+ this.id = new Identifier(this, this.scope.parent).parseNode(esTreeNode.id);
10705
10782
  }
10706
- super.parseNode(esTreeNode);
10783
+ return super.parseNode(esTreeNode);
10707
10784
  }
10708
10785
  render(code, options) {
10709
10786
  const { exportNamesByVariable, format, snippets: { _, getPropertyAccess } } = options;
@@ -10743,7 +10820,7 @@ class ClassDeclaration extends ClassNode {
10743
10820
  class ClassExpression extends ClassNode {
10744
10821
  render(code, options, { renderedSurroundingElement } = BLANK) {
10745
10822
  super.render(code, options);
10746
- if (renderedSurroundingElement === ExpressionStatement$1) {
10823
+ if (renderedSurroundingElement === parseAst_js.ExpressionStatement) {
10747
10824
  code.appendRight(this.start, '(');
10748
10825
  code.prependLeft(this.end, ')');
10749
10826
  }
@@ -10943,6 +11020,12 @@ class ContinueStatement extends NodeBase {
10943
11020
  }
10944
11021
  }
10945
11022
 
11023
+ class DebuggerStatement extends NodeBase {
11024
+ hasEffects() {
11025
+ return true;
11026
+ }
11027
+ }
11028
+
10946
11029
  function hasLoopBodyEffects(context, body) {
10947
11030
  const { brokenFlow, hasBreak, hasContinue, ignore } = context;
10948
11031
  const { breaks, continues } = ignore;
@@ -10993,6 +11076,7 @@ class ExportAllDeclaration extends NodeBase {
10993
11076
  return false;
10994
11077
  }
10995
11078
  initialise() {
11079
+ super.initialise();
10996
11080
  this.scope.context.addExport(this);
10997
11081
  }
10998
11082
  render(code, _options, nodeRenderOptions) {
@@ -11011,9 +11095,9 @@ class FunctionDeclaration extends FunctionNode {
11011
11095
  }
11012
11096
  parseNode(esTreeNode) {
11013
11097
  if (esTreeNode.id !== null) {
11014
- this.id = new Identifier(esTreeNode.id, this, this.scope.parent);
11098
+ this.id = new Identifier(this, this.scope.parent).parseNode(esTreeNode.id);
11015
11099
  }
11016
- super.parseNode(esTreeNode);
11100
+ return super.parseNode(esTreeNode);
11017
11101
  }
11018
11102
  }
11019
11103
 
@@ -11038,6 +11122,7 @@ class ExportDefaultDeclaration extends NodeBase {
11038
11122
  }
11039
11123
  }
11040
11124
  initialise() {
11125
+ super.initialise();
11041
11126
  const declaration = this.declaration;
11042
11127
  this.declarationName =
11043
11128
  (declaration.id && declaration.id.name) || this.declaration.name;
@@ -11071,7 +11156,7 @@ class ExportDefaultDeclaration extends NodeBase {
11071
11156
  else {
11072
11157
  code.remove(this.start, declarationStart);
11073
11158
  this.declaration.render(code, options, {
11074
- renderedSurroundingElement: ExpressionStatement$1
11159
+ renderedSurroundingElement: parseAst_js.ExpressionStatement
11075
11160
  });
11076
11161
  if (code.original[this.end - 1] !== ';') {
11077
11162
  code.appendLeft(this.end, ';');
@@ -11121,6 +11206,7 @@ class ExportNamedDeclaration extends NodeBase {
11121
11206
  return !!this.declaration?.hasEffects(context);
11122
11207
  }
11123
11208
  initialise() {
11209
+ super.initialise();
11124
11210
  this.scope.context.addExport(this);
11125
11211
  }
11126
11212
  removeAnnotations(code) {
@@ -11166,6 +11252,7 @@ class ForInStatement extends NodeBase {
11166
11252
  includeLoopBody(context, body, includeChildrenRecursively);
11167
11253
  }
11168
11254
  initialise() {
11255
+ super.initialise();
11169
11256
  this.left.setAssignedValue(UNKNOWN_EXPRESSION);
11170
11257
  }
11171
11258
  render(code, options) {
@@ -11210,6 +11297,7 @@ class ForOfStatement extends NodeBase {
11210
11297
  includeLoopBody(context, body, includeChildrenRecursively);
11211
11298
  }
11212
11299
  initialise() {
11300
+ super.initialise();
11213
11301
  this.left.setAssignedValue(UNKNOWN_EXPRESSION);
11214
11302
  }
11215
11303
  render(code, options) {
@@ -11262,13 +11350,13 @@ class FunctionExpression extends FunctionNode {
11262
11350
  }
11263
11351
  parseNode(esTreeNode) {
11264
11352
  if (esTreeNode.id !== null) {
11265
- this.id = new Identifier(esTreeNode.id, this, this.idScope);
11353
+ this.id = new Identifier(this, this.idScope).parseNode(esTreeNode.id);
11266
11354
  }
11267
- super.parseNode(esTreeNode);
11355
+ return super.parseNode(esTreeNode);
11268
11356
  }
11269
11357
  render(code, options, { renderedSurroundingElement } = BLANK) {
11270
11358
  super.render(code, options);
11271
- if (renderedSurroundingElement === ExpressionStatement$1) {
11359
+ if (renderedSurroundingElement === parseAst_js.ExpressionStatement) {
11272
11360
  code.appendRight(this.start, '(');
11273
11361
  code.prependLeft(this.end, ')');
11274
11362
  }
@@ -11331,13 +11419,11 @@ class IfStatement extends NodeBase {
11331
11419
  }
11332
11420
  }
11333
11421
  parseNode(esTreeNode) {
11334
- this.consequentScope = new TrackingScope(this.scope);
11335
- this.consequent = new (this.scope.context.getNodeConstructor(esTreeNode.consequent.type))(esTreeNode.consequent, this, this.consequentScope);
11422
+ this.consequent = new (this.scope.context.getNodeConstructor(esTreeNode.consequent.type))(this, (this.consequentScope = new TrackingScope(this.scope))).parseNode(esTreeNode.consequent);
11336
11423
  if (esTreeNode.alternate) {
11337
- this.alternateScope = new TrackingScope(this.scope);
11338
- this.alternate = new (this.scope.context.getNodeConstructor(esTreeNode.alternate.type))(esTreeNode.alternate, this, this.alternateScope);
11424
+ this.alternate = new (this.scope.context.getNodeConstructor(esTreeNode.alternate.type))(this, (this.alternateScope = new TrackingScope(this.scope))).parseNode(esTreeNode.alternate);
11339
11425
  }
11340
- super.parseNode(esTreeNode);
11426
+ return super.parseNode(esTreeNode);
11341
11427
  }
11342
11428
  render(code, options) {
11343
11429
  const { snippets: { getPropertyAccess } } = options;
@@ -11431,7 +11517,7 @@ class IfStatement extends NodeBase {
11431
11517
  .join(', ');
11432
11518
  if (hoistedVariables) {
11433
11519
  const parentType = this.parent.type;
11434
- const needsBraces = parentType !== Program$1 && parentType !== BlockStatement$1;
11520
+ const needsBraces = parentType !== parseAst_js.Program && parentType !== parseAst_js.BlockStatement;
11435
11521
  code.prependRight(this.start, `${needsBraces ? '{ ' : ''}var ${hoistedVariables}; `);
11436
11522
  if (needsBraces) {
11437
11523
  code.appendLeft(this.end, ` }`);
@@ -11463,6 +11549,7 @@ class ImportDeclaration extends NodeBase {
11463
11549
  return false;
11464
11550
  }
11465
11551
  initialise() {
11552
+ super.initialise();
11466
11553
  this.scope.context.addImport(this);
11467
11554
  }
11468
11555
  render(code, _options, nodeRenderOptions) {
@@ -11733,7 +11820,7 @@ class VariableDeclarator extends NodeBase {
11733
11820
  code.appendLeft(init.start + 5, ` ${id.name}`);
11734
11821
  }
11735
11822
  }
11736
- init.render(code, options, renderId ? BLANK : { renderedSurroundingElement: ExpressionStatement$1 });
11823
+ init.render(code, options, renderId ? BLANK : { renderedSurroundingElement: parseAst_js.ExpressionStatement });
11737
11824
  }
11738
11825
  else if (id instanceof Identifier &&
11739
11826
  isReassignedExportsMember(id.variable, exportNamesByVariable)) {
@@ -11853,11 +11940,12 @@ class ImportExpression extends NodeBase {
11853
11940
  this.source.include(context, includeChildrenRecursively);
11854
11941
  }
11855
11942
  initialise() {
11943
+ super.initialise();
11856
11944
  this.scope.context.addDynamicImport(this);
11857
11945
  }
11858
11946
  parseNode(esTreeNode) {
11859
- // Keep the source AST to be used by renderDynamicImport
11860
- super.parseNode(esTreeNode, ['source']);
11947
+ this.sourceAstNode = esTreeNode.source;
11948
+ return super.parseNode(esTreeNode);
11861
11949
  }
11862
11950
  render(code, options) {
11863
11951
  const { snippets: { _, getDirectReturnFunction, getObject, getPropertyAccess } } = options;
@@ -12390,11 +12478,16 @@ class NewExpression extends NodeBase {
12390
12478
  this.callee.includeCallArguments(context, this.arguments);
12391
12479
  }
12392
12480
  initialise() {
12481
+ super.initialise();
12393
12482
  this.interaction = {
12394
12483
  args: [null, ...this.arguments],
12395
12484
  type: INTERACTION_CALLED,
12396
12485
  withNew: true
12397
12486
  };
12487
+ if (this.annotations &&
12488
+ this.scope.context.options.treeshake.annotations) {
12489
+ this.annotationPure = this.annotations.some(comment => comment.type === 'pure');
12490
+ }
12398
12491
  }
12399
12492
  render(code, options) {
12400
12493
  this.callee.render(code, options);
@@ -12432,8 +12525,8 @@ class ObjectExpression extends NodeBase {
12432
12525
  }
12433
12526
  render(code, options, { renderedSurroundingElement } = BLANK) {
12434
12527
  super.render(code, options);
12435
- if (renderedSurroundingElement === ExpressionStatement$1 ||
12436
- renderedSurroundingElement === ArrowFunctionExpression$1) {
12528
+ if (renderedSurroundingElement === parseAst_js.ExpressionStatement ||
12529
+ renderedSurroundingElement === parseAst_js.ArrowFunctionExpression) {
12437
12530
  code.appendRight(this.start, '(');
12438
12531
  code.prependLeft(this.end, ')');
12439
12532
  }
@@ -12480,6 +12573,29 @@ class ObjectExpression extends NodeBase {
12480
12573
  }
12481
12574
  }
12482
12575
 
12576
+ class PanicError extends NodeBase {
12577
+ initialise() {
12578
+ const id = this.scope.context.module.id;
12579
+ // This simulates the current nested error structure. We could also just
12580
+ // replace it with a flat error.
12581
+ const parseError = parseAst_js.getRollupEror(parseAst_js.logParseError(this.message));
12582
+ const moduleParseError = parseAst_js.logModuleParseError(parseError, id);
12583
+ return parseAst_js.error(moduleParseError);
12584
+ }
12585
+ }
12586
+
12587
+ class ParseError extends NodeBase {
12588
+ initialise() {
12589
+ const pos = this.start;
12590
+ const id = this.scope.context.module.id;
12591
+ // This simulates the current nested error structure. We could also just
12592
+ // replace it with a flat error.
12593
+ const parseError = parseAst_js.getRollupEror(parseAst_js.logParseError(this.message, pos));
12594
+ const moduleParseError = parseAst_js.logModuleParseError(parseError, id);
12595
+ this.scope.context.error(moduleParseError, pos);
12596
+ }
12597
+ }
12598
+
12483
12599
  class PrivateIdentifier extends NodeBase {
12484
12600
  }
12485
12601
 
@@ -12518,6 +12634,16 @@ class Program extends NodeBase {
12518
12634
  }
12519
12635
  }
12520
12636
  }
12637
+ initialise() {
12638
+ super.initialise();
12639
+ if (this.invalidAnnotations)
12640
+ for (const { start, end, type } of this.invalidAnnotations) {
12641
+ this.scope.context.magicString.remove(start, end);
12642
+ if (type === 'pure' || type === 'noSideEffects') {
12643
+ this.scope.context.log(parseAst_js.LOGLEVEL_WARN, parseAst_js.logInvalidAnnotation(this.scope.context.code.slice(start, end), this.scope.context.module.id, type), start);
12644
+ }
12645
+ }
12646
+ }
12521
12647
  render(code, options) {
12522
12648
  let start = this.start;
12523
12649
  if (code.original.startsWith('#!')) {
@@ -12636,6 +12762,7 @@ class ReturnStatement extends NodeBase {
12636
12762
  context.brokenFlow = true;
12637
12763
  }
12638
12764
  initialise() {
12765
+ super.initialise();
12639
12766
  this.scope.addReturnExpression(this.argument || UNKNOWN_EXPRESSION);
12640
12767
  }
12641
12768
  render(code, options) {
@@ -12857,6 +12984,7 @@ class SwitchStatement extends NodeBase {
12857
12984
  context.hasBreak = hasBreak;
12858
12985
  }
12859
12986
  initialise() {
12987
+ super.initialise();
12860
12988
  for (let caseIndex = 0; caseIndex < this.cases.length; caseIndex++) {
12861
12989
  if (this.cases[caseIndex].test === null) {
12862
12990
  this.defaultCase = caseIndex;
@@ -12866,8 +12994,8 @@ class SwitchStatement extends NodeBase {
12866
12994
  this.defaultCase = null;
12867
12995
  }
12868
12996
  parseNode(esTreeNode) {
12869
- this.discriminant = new (this.scope.context.getNodeConstructor(esTreeNode.discriminant.type))(esTreeNode.discriminant, this, this.parentScope);
12870
- super.parseNode(esTreeNode);
12997
+ this.discriminant = new (this.scope.context.getNodeConstructor(esTreeNode.discriminant.type))(this, this.parentScope).parseNode(esTreeNode.discriminant);
12998
+ return super.parseNode(esTreeNode);
12871
12999
  }
12872
13000
  render(code, options) {
12873
13001
  this.discriminant.render(code, options);
@@ -12880,7 +13008,7 @@ class SwitchStatement extends NodeBase {
12880
13008
  class TaggedTemplateExpression extends CallExpressionBase {
12881
13009
  bind() {
12882
13010
  super.bind();
12883
- if (this.tag.type === Identifier$1) {
13011
+ if (this.tag.type === parseAst_js.Identifier) {
12884
13012
  const name = this.tag.name;
12885
13013
  const variable = this.scope.findVariable(name);
12886
13014
  if (variable.isNamespace) {
@@ -12920,6 +13048,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
12920
13048
  }
12921
13049
  }
12922
13050
  initialise() {
13051
+ super.initialise();
12923
13052
  this.args = [UNKNOWN_EXPRESSION, ...this.quasi.expressions];
12924
13053
  this.interaction = {
12925
13054
  args: [
@@ -12965,7 +13094,7 @@ class TemplateElement extends NodeBase {
12965
13094
  }
12966
13095
  parseNode(esTreeNode) {
12967
13096
  this.value = esTreeNode.value;
12968
- super.parseNode(esTreeNode);
13097
+ return super.parseNode(esTreeNode);
12969
13098
  }
12970
13099
  render() { }
12971
13100
  }
@@ -13010,7 +13139,7 @@ class UndefinedVariable extends Variable {
13010
13139
 
13011
13140
  class ExportDefaultVariable extends LocalVariable {
13012
13141
  constructor(name, exportDefaultDeclaration, context) {
13013
- super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context, "other" /* VariableKind.other */);
13142
+ super(name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, context, 'other');
13014
13143
  this.hasId = false;
13015
13144
  this.originalId = null;
13016
13145
  this.originalVariable = null;
@@ -13081,7 +13210,7 @@ class ExportDefaultVariable extends LocalVariable {
13081
13210
  class ModuleScope extends ChildScope {
13082
13211
  constructor(parent, context) {
13083
13212
  super(parent, context);
13084
- this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, context, "other" /* VariableKind.other */));
13213
+ this.variables.set('this', new LocalVariable('this', null, UNDEFINED_EXPRESSION, context, 'other'));
13085
13214
  }
13086
13215
  addDeclaration(identifier, context, init, kind) {
13087
13216
  if (this.context.module.importDescriptions.has(identifier.name)) {
@@ -13139,6 +13268,7 @@ class ThisExpression extends NodeBase {
13139
13268
  }
13140
13269
  }
13141
13270
  initialise() {
13271
+ super.initialise();
13142
13272
  this.alias =
13143
13273
  this.scope.findLexicalBoundary() instanceof ModuleScope
13144
13274
  ? this.scope.context.moduleContext
@@ -13255,15 +13385,6 @@ class UnaryExpression extends NodeBase {
13255
13385
  }
13256
13386
  }
13257
13387
 
13258
- class UnknownNode extends NodeBase {
13259
- hasEffects() {
13260
- return true;
13261
- }
13262
- include(context) {
13263
- super.include(context, true);
13264
- }
13265
- }
13266
-
13267
13388
  class UpdateExpression extends NodeBase {
13268
13389
  hasEffects(context) {
13269
13390
  if (!this.deoptimized)
@@ -13280,6 +13401,7 @@ class UpdateExpression extends NodeBase {
13280
13401
  this.argument.includeAsAssignmentTarget(context, includeChildrenRecursively, true);
13281
13402
  }
13282
13403
  initialise() {
13404
+ super.initialise();
13283
13405
  this.argument.setAssignedValue(UNKNOWN_EXPRESSION);
13284
13406
  }
13285
13407
  render(code, options) {
@@ -13294,12 +13416,12 @@ class UpdateExpression extends NodeBase {
13294
13416
  renderSystemExportExpression(variable, this.start, this.end, code, options);
13295
13417
  }
13296
13418
  else {
13297
- renderSystemExportSequenceAfterExpression(variable, this.start, this.end, this.parent.type !== ExpressionStatement$1, code, options);
13419
+ renderSystemExportSequenceAfterExpression(variable, this.start, this.end, this.parent.type !== parseAst_js.ExpressionStatement, code, options);
13298
13420
  }
13299
13421
  }
13300
13422
  else {
13301
13423
  const operator = this.operator[0];
13302
- renderSystemExportSequenceBeforeExpression(variable, this.start, this.end, this.parent.type !== ExpressionStatement$1, code, options, `${_}${operator}${_}1`);
13424
+ renderSystemExportSequenceBeforeExpression(variable, this.start, this.end, this.parent.type !== parseAst_js.ExpressionStatement, code, options, `${_}${operator}${_}1`);
13303
13425
  }
13304
13426
  }
13305
13427
  }
@@ -13319,7 +13441,7 @@ function areAllDeclarationsIncludedAndNotExported(declarations, exportNamesByVar
13319
13441
  for (const declarator of declarations) {
13320
13442
  if (!declarator.id.included)
13321
13443
  return false;
13322
- if (declarator.id.type === Identifier$1) {
13444
+ if (declarator.id.type === parseAst_js.Identifier) {
13323
13445
  if (exportNamesByVariable.has(declarator.id.variable))
13324
13446
  return false;
13325
13447
  }
@@ -13359,6 +13481,7 @@ class VariableDeclaration extends NodeBase {
13359
13481
  }
13360
13482
  }
13361
13483
  initialise() {
13484
+ super.initialise();
13362
13485
  for (const declarator of this.declarations) {
13363
13486
  declarator.declareDeclarator(this.kind);
13364
13487
  }
@@ -13524,6 +13647,711 @@ class YieldExpression extends NodeBase {
13524
13647
  }
13525
13648
  }
13526
13649
 
13650
+ // This file is generated by scripts/generate-ast-converters.js.
13651
+ // Do not edit this file directly.
13652
+ function convertProgram(buffer, parent, parentScope) {
13653
+ return convertNode(parent, parentScope, 0, new Uint32Array(buffer.buffer), parseAst_js.getReadStringFunction(buffer));
13654
+ }
13655
+ const nodeTypeStrings = [
13656
+ 'PanicError',
13657
+ 'ParseError',
13658
+ 'ArrayExpression',
13659
+ 'ArrayPattern',
13660
+ 'ArrowFunctionExpression',
13661
+ 'AssignmentExpression',
13662
+ 'AssignmentPattern',
13663
+ 'AwaitExpression',
13664
+ 'BinaryExpression',
13665
+ 'BlockStatement',
13666
+ 'BreakStatement',
13667
+ 'CallExpression',
13668
+ 'CatchClause',
13669
+ 'ChainExpression',
13670
+ 'ClassBody',
13671
+ 'ClassDeclaration',
13672
+ 'ClassExpression',
13673
+ 'ConditionalExpression',
13674
+ 'ContinueStatement',
13675
+ 'DebuggerStatement',
13676
+ 'ExpressionStatement',
13677
+ 'DoWhileStatement',
13678
+ 'EmptyStatement',
13679
+ 'ExportAllDeclaration',
13680
+ 'ExportDefaultDeclaration',
13681
+ 'ExportNamedDeclaration',
13682
+ 'ExportSpecifier',
13683
+ 'ExpressionStatement',
13684
+ 'ForInStatement',
13685
+ 'ForOfStatement',
13686
+ 'ForStatement',
13687
+ 'FunctionDeclaration',
13688
+ 'FunctionExpression',
13689
+ 'Identifier',
13690
+ 'IfStatement',
13691
+ 'ImportAttribute',
13692
+ 'ImportDeclaration',
13693
+ 'ImportDefaultSpecifier',
13694
+ 'ImportExpression',
13695
+ 'ImportNamespaceSpecifier',
13696
+ 'ImportSpecifier',
13697
+ 'LabeledStatement',
13698
+ 'Literal',
13699
+ 'Literal',
13700
+ 'Literal',
13701
+ 'Literal',
13702
+ 'Literal',
13703
+ 'Literal',
13704
+ 'LogicalExpression',
13705
+ 'MemberExpression',
13706
+ 'MetaProperty',
13707
+ 'MethodDefinition',
13708
+ 'NewExpression',
13709
+ 'ObjectExpression',
13710
+ 'ObjectPattern',
13711
+ 'PrivateIdentifier',
13712
+ 'Program',
13713
+ 'Property',
13714
+ 'PropertyDefinition',
13715
+ 'RestElement',
13716
+ 'ReturnStatement',
13717
+ 'SequenceExpression',
13718
+ 'SpreadElement',
13719
+ 'StaticBlock',
13720
+ 'Super',
13721
+ 'SwitchCase',
13722
+ 'SwitchStatement',
13723
+ 'TaggedTemplateExpression',
13724
+ 'TemplateElement',
13725
+ 'TemplateLiteral',
13726
+ 'ThisExpression',
13727
+ 'ThrowStatement',
13728
+ 'TryStatement',
13729
+ 'UnaryExpression',
13730
+ 'UpdateExpression',
13731
+ 'VariableDeclaration',
13732
+ 'VariableDeclarator',
13733
+ 'WhileStatement',
13734
+ 'YieldExpression'
13735
+ ];
13736
+ const nodeConstructors$1 = [
13737
+ PanicError,
13738
+ ParseError,
13739
+ ArrayExpression,
13740
+ ArrayPattern,
13741
+ ArrowFunctionExpression,
13742
+ AssignmentExpression,
13743
+ AssignmentPattern,
13744
+ AwaitExpression,
13745
+ BinaryExpression,
13746
+ BlockStatement,
13747
+ BreakStatement,
13748
+ CallExpression,
13749
+ CatchClause,
13750
+ ChainExpression,
13751
+ ClassBody,
13752
+ ClassDeclaration,
13753
+ ClassExpression,
13754
+ ConditionalExpression,
13755
+ ContinueStatement,
13756
+ DebuggerStatement,
13757
+ ExpressionStatement,
13758
+ DoWhileStatement,
13759
+ EmptyStatement,
13760
+ ExportAllDeclaration,
13761
+ ExportDefaultDeclaration,
13762
+ ExportNamedDeclaration,
13763
+ ExportSpecifier,
13764
+ ExpressionStatement,
13765
+ ForInStatement,
13766
+ ForOfStatement,
13767
+ ForStatement,
13768
+ FunctionDeclaration,
13769
+ FunctionExpression,
13770
+ Identifier,
13771
+ IfStatement,
13772
+ ImportAttribute,
13773
+ ImportDeclaration,
13774
+ ImportDefaultSpecifier,
13775
+ ImportExpression,
13776
+ ImportNamespaceSpecifier,
13777
+ ImportSpecifier,
13778
+ LabeledStatement,
13779
+ Literal,
13780
+ Literal,
13781
+ Literal,
13782
+ Literal,
13783
+ Literal,
13784
+ Literal,
13785
+ LogicalExpression,
13786
+ MemberExpression,
13787
+ MetaProperty,
13788
+ MethodDefinition,
13789
+ NewExpression,
13790
+ ObjectExpression,
13791
+ ObjectPattern,
13792
+ PrivateIdentifier,
13793
+ Program,
13794
+ Property,
13795
+ PropertyDefinition,
13796
+ RestElement,
13797
+ ReturnStatement,
13798
+ SequenceExpression,
13799
+ SpreadElement,
13800
+ StaticBlock,
13801
+ Super,
13802
+ SwitchCase,
13803
+ SwitchStatement,
13804
+ TaggedTemplateExpression,
13805
+ TemplateElement,
13806
+ TemplateLiteral,
13807
+ ThisExpression,
13808
+ ThrowStatement,
13809
+ TryStatement,
13810
+ UnaryExpression,
13811
+ UpdateExpression,
13812
+ VariableDeclaration,
13813
+ VariableDeclarator,
13814
+ WhileStatement,
13815
+ YieldExpression
13816
+ ];
13817
+ const bufferParsers = [
13818
+ function panicError(node, position, buffer, readString) {
13819
+ node.message = parseAst_js.convertString(position, buffer, readString);
13820
+ },
13821
+ function parseError(node, position, buffer, readString) {
13822
+ node.message = parseAst_js.convertString(position, buffer, readString);
13823
+ },
13824
+ function arrayExpression(node, position, buffer, readString) {
13825
+ const { scope } = node;
13826
+ node.elements = convertNodeList(node, scope, position, buffer, readString);
13827
+ },
13828
+ function arrayPattern(node, position, buffer, readString) {
13829
+ const { scope } = node;
13830
+ node.elements = convertNodeList(node, scope, position, buffer, readString);
13831
+ },
13832
+ function arrowFunctionExpression(node, position, buffer, readString) {
13833
+ const { scope } = node;
13834
+ const flags = buffer[position];
13835
+ node.async = (flags & 1) === 1;
13836
+ node.expression = (flags & 2) === 2;
13837
+ node.generator = (flags & 4) === 4;
13838
+ const parameters = (node.params = convertNodeList(node, scope, buffer[position + 1], buffer, readString));
13839
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
13840
+ node.body = convertNode(node, scope.bodyScope, buffer[position + 2], buffer, readString);
13841
+ const annotations = (node.annotations = parseAst_js.convertAnnotations(position + 3, buffer));
13842
+ node.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
13843
+ },
13844
+ function assignmentExpression(node, position, buffer, readString) {
13845
+ const { scope } = node;
13846
+ node.operator = parseAst_js.FIXED_STRINGS[buffer[position]];
13847
+ node.right = convertNode(node, scope, buffer[position + 1], buffer, readString);
13848
+ node.left = convertNode(node, scope, position + 2, buffer, readString);
13849
+ },
13850
+ function assignmentPattern(node, position, buffer, readString) {
13851
+ const { scope } = node;
13852
+ node.right = convertNode(node, scope, buffer[position], buffer, readString);
13853
+ node.left = convertNode(node, scope, position + 1, buffer, readString);
13854
+ },
13855
+ function awaitExpression(node, position, buffer, readString) {
13856
+ const { scope } = node;
13857
+ node.argument = convertNode(node, scope, position, buffer, readString);
13858
+ },
13859
+ function binaryExpression(node, position, buffer, readString) {
13860
+ const { scope } = node;
13861
+ node.operator = parseAst_js.FIXED_STRINGS[buffer[position]];
13862
+ node.right = convertNode(node, scope, buffer[position + 1], buffer, readString);
13863
+ node.left = convertNode(node, scope, position + 2, buffer, readString);
13864
+ },
13865
+ function blockStatement(node, position, buffer, readString) {
13866
+ const { scope } = node;
13867
+ node.body = convertNodeList(node, scope, position, buffer, readString);
13868
+ },
13869
+ function breakStatement(node, position, buffer, readString) {
13870
+ const { scope } = node;
13871
+ const labelPosition = buffer[position];
13872
+ node.label =
13873
+ labelPosition === 0 ? null : convertNode(node, scope, labelPosition, buffer, readString);
13874
+ },
13875
+ function callExpression(node, position, buffer, readString) {
13876
+ const { scope } = node;
13877
+ const flags = buffer[position];
13878
+ node.optional = (flags & 1) === 1;
13879
+ node.callee = convertNode(node, scope, buffer[position + 1], buffer, readString);
13880
+ node.arguments = convertNodeList(node, scope, buffer[position + 2], buffer, readString);
13881
+ node.annotations = parseAst_js.convertAnnotations(position + 3, buffer);
13882
+ },
13883
+ function catchClause(node, position, buffer, readString) {
13884
+ const { scope } = node;
13885
+ const parameterPosition = buffer[position];
13886
+ const parameter = (node.param =
13887
+ parameterPosition === 0
13888
+ ? null
13889
+ : convertNode(node, scope, parameterPosition, buffer, readString));
13890
+ parameter?.declare('parameter', UNKNOWN_EXPRESSION);
13891
+ node.body = convertNode(node, scope.bodyScope, buffer[position + 1], buffer, readString);
13892
+ },
13893
+ function chainExpression(node, position, buffer, readString) {
13894
+ const { scope } = node;
13895
+ node.expression = convertNode(node, scope, position, buffer, readString);
13896
+ },
13897
+ function classBody(node, position, buffer, readString) {
13898
+ const { scope } = node;
13899
+ const length = buffer[position];
13900
+ const body = (node.body = []);
13901
+ for (let index = 0; index < length; index++) {
13902
+ const nodePosition = buffer[position + 1 + index];
13903
+ body.push(convertNode(node, (buffer[nodePosition + 3] & 1) === 0 ? scope.instanceScope : scope, nodePosition, buffer, readString));
13904
+ }
13905
+ },
13906
+ function classDeclaration(node, position, buffer, readString) {
13907
+ const { scope } = node;
13908
+ const idPosition = buffer[position];
13909
+ node.id =
13910
+ idPosition === 0
13911
+ ? null
13912
+ : convertNode(node, scope.parent, idPosition, buffer, readString);
13913
+ const superClassPosition = buffer[position + 1];
13914
+ node.superClass =
13915
+ superClassPosition === 0
13916
+ ? null
13917
+ : convertNode(node, scope, superClassPosition, buffer, readString);
13918
+ node.body = convertNode(node, scope, buffer[position + 2], buffer, readString);
13919
+ },
13920
+ function classExpression(node, position, buffer, readString) {
13921
+ const { scope } = node;
13922
+ const idPosition = buffer[position];
13923
+ node.id = idPosition === 0 ? null : convertNode(node, scope, idPosition, buffer, readString);
13924
+ const superClassPosition = buffer[position + 1];
13925
+ node.superClass =
13926
+ superClassPosition === 0
13927
+ ? null
13928
+ : convertNode(node, scope, superClassPosition, buffer, readString);
13929
+ node.body = convertNode(node, scope, buffer[position + 2], buffer, readString);
13930
+ },
13931
+ function conditionalExpression(node, position, buffer, readString) {
13932
+ const { scope } = node;
13933
+ node.consequent = convertNode(node, scope, buffer[position], buffer, readString);
13934
+ node.alternate = convertNode(node, scope, buffer[position + 1], buffer, readString);
13935
+ node.test = convertNode(node, scope, position + 2, buffer, readString);
13936
+ },
13937
+ function continueStatement(node, position, buffer, readString) {
13938
+ const { scope } = node;
13939
+ const labelPosition = buffer[position];
13940
+ node.label =
13941
+ labelPosition === 0 ? null : convertNode(node, scope, labelPosition, buffer, readString);
13942
+ },
13943
+ function debuggerStatement() { },
13944
+ function directive(node, position, buffer, readString) {
13945
+ const { scope } = node;
13946
+ node.expression = convertNode(node, scope, buffer[position], buffer, readString);
13947
+ node.directive = parseAst_js.convertString(position + 1, buffer, readString);
13948
+ },
13949
+ function doWhileStatement(node, position, buffer, readString) {
13950
+ const { scope } = node;
13951
+ node.test = convertNode(node, scope, buffer[position], buffer, readString);
13952
+ node.body = convertNode(node, scope, position + 1, buffer, readString);
13953
+ },
13954
+ function emptyStatement() { },
13955
+ function exportAllDeclaration(node, position, buffer, readString) {
13956
+ const { scope } = node;
13957
+ const exportedPosition = buffer[position];
13958
+ node.exported =
13959
+ exportedPosition === 0
13960
+ ? null
13961
+ : convertNode(node, scope, exportedPosition, buffer, readString);
13962
+ node.source = convertNode(node, scope, buffer[position + 1], buffer, readString);
13963
+ node.attributes = convertNodeList(node, scope, buffer[position + 2], buffer, readString);
13964
+ },
13965
+ function exportDefaultDeclaration(node, position, buffer, readString) {
13966
+ const { scope } = node;
13967
+ node.declaration = convertNode(node, scope, position, buffer, readString);
13968
+ },
13969
+ function exportNamedDeclaration(node, position, buffer, readString) {
13970
+ const { scope } = node;
13971
+ const sourcePosition = buffer[position];
13972
+ node.source =
13973
+ sourcePosition === 0 ? null : convertNode(node, scope, sourcePosition, buffer, readString);
13974
+ node.attributes = convertNodeList(node, scope, buffer[position + 1], buffer, readString);
13975
+ const declarationPosition = buffer[position + 2];
13976
+ node.declaration =
13977
+ declarationPosition === 0
13978
+ ? null
13979
+ : convertNode(node, scope, declarationPosition, buffer, readString);
13980
+ node.specifiers = convertNodeList(node, scope, position + 3, buffer, readString);
13981
+ },
13982
+ function exportSpecifier(node, position, buffer, readString) {
13983
+ const { scope } = node;
13984
+ const exportedPosition = buffer[position];
13985
+ node.local = convertNode(node, scope, position + 1, buffer, readString);
13986
+ node.exported =
13987
+ exportedPosition === 0
13988
+ ? node.local
13989
+ : convertNode(node, scope, exportedPosition, buffer, readString);
13990
+ },
13991
+ function expressionStatement(node, position, buffer, readString) {
13992
+ const { scope } = node;
13993
+ node.expression = convertNode(node, scope, position, buffer, readString);
13994
+ },
13995
+ function forInStatement(node, position, buffer, readString) {
13996
+ const { scope } = node;
13997
+ node.right = convertNode(node, scope, buffer[position], buffer, readString);
13998
+ node.body = convertNode(node, scope, buffer[position + 1], buffer, readString);
13999
+ node.left = convertNode(node, scope, position + 2, buffer, readString);
14000
+ },
14001
+ function forOfStatement(node, position, buffer, readString) {
14002
+ const { scope } = node;
14003
+ const flags = buffer[position];
14004
+ node.await = (flags & 1) === 1;
14005
+ node.right = convertNode(node, scope, buffer[position + 1], buffer, readString);
14006
+ node.body = convertNode(node, scope, buffer[position + 2], buffer, readString);
14007
+ node.left = convertNode(node, scope, position + 3, buffer, readString);
14008
+ },
14009
+ function forStatement(node, position, buffer, readString) {
14010
+ const { scope } = node;
14011
+ const initPosition = buffer[position];
14012
+ node.init =
14013
+ initPosition === 0 ? null : convertNode(node, scope, initPosition, buffer, readString);
14014
+ const testPosition = buffer[position + 1];
14015
+ node.test =
14016
+ testPosition === 0 ? null : convertNode(node, scope, testPosition, buffer, readString);
14017
+ const updatePosition = buffer[position + 2];
14018
+ node.update =
14019
+ updatePosition === 0 ? null : convertNode(node, scope, updatePosition, buffer, readString);
14020
+ node.body = convertNode(node, scope, buffer[position + 3], buffer, readString);
14021
+ },
14022
+ function functionDeclaration(node, position, buffer, readString) {
14023
+ const { scope } = node;
14024
+ const flags = buffer[position];
14025
+ node.async = (flags & 1) === 1;
14026
+ node.generator = (flags & 2) === 2;
14027
+ const idPosition = buffer[position + 1];
14028
+ node.id =
14029
+ idPosition === 0
14030
+ ? null
14031
+ : convertNode(node, scope.parent, idPosition, buffer, readString);
14032
+ const parameters = (node.params = convertNodeList(node, scope, buffer[position + 2], buffer, readString));
14033
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
14034
+ node.body = convertNode(node, scope.bodyScope, buffer[position + 3], buffer, readString);
14035
+ const annotations = (node.annotations = parseAst_js.convertAnnotations(position + 4, buffer));
14036
+ node.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
14037
+ },
14038
+ function functionExpression(node, position, buffer, readString) {
14039
+ const { scope } = node;
14040
+ const flags = buffer[position];
14041
+ node.async = (flags & 1) === 1;
14042
+ node.generator = (flags & 2) === 2;
14043
+ const idPosition = buffer[position + 1];
14044
+ node.id =
14045
+ idPosition === 0 ? null : convertNode(node, node.idScope, idPosition, buffer, readString);
14046
+ const parameters = (node.params = convertNodeList(node, scope, buffer[position + 2], buffer, readString));
14047
+ scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
14048
+ node.body = convertNode(node, scope.bodyScope, buffer[position + 3], buffer, readString);
14049
+ const annotations = (node.annotations = parseAst_js.convertAnnotations(position + 4, buffer));
14050
+ node.annotationNoSideEffects = annotations.some(comment => comment.type === 'noSideEffects');
14051
+ },
14052
+ function identifier(node, position, buffer, readString) {
14053
+ node.name = parseAst_js.convertString(position, buffer, readString);
14054
+ },
14055
+ function ifStatement(node, position, buffer, readString) {
14056
+ const { scope } = node;
14057
+ node.consequent = convertNode(node, (node.consequentScope = new TrackingScope(scope)), buffer[position], buffer, readString);
14058
+ const alternatePosition = buffer[position + 1];
14059
+ node.alternate =
14060
+ alternatePosition === 0
14061
+ ? null
14062
+ : convertNode(node, (node.alternateScope = new TrackingScope(scope)), alternatePosition, buffer, readString);
14063
+ node.test = convertNode(node, scope, position + 2, buffer, readString);
14064
+ },
14065
+ function importAttribute(node, position, buffer, readString) {
14066
+ const { scope } = node;
14067
+ node.value = convertNode(node, scope, buffer[position], buffer, readString);
14068
+ node.key = convertNode(node, scope, position + 1, buffer, readString);
14069
+ },
14070
+ function importDeclaration(node, position, buffer, readString) {
14071
+ const { scope } = node;
14072
+ node.source = convertNode(node, scope, buffer[position], buffer, readString);
14073
+ node.attributes = convertNodeList(node, scope, buffer[position + 1], buffer, readString);
14074
+ node.specifiers = convertNodeList(node, scope, position + 2, buffer, readString);
14075
+ },
14076
+ function importDefaultSpecifier(node, position, buffer, readString) {
14077
+ const { scope } = node;
14078
+ node.local = convertNode(node, scope, position, buffer, readString);
14079
+ },
14080
+ function importExpression(node, position, buffer, readString) {
14081
+ const { scope } = node;
14082
+ const optionsPosition = buffer[position];
14083
+ node.options =
14084
+ optionsPosition === 0 ? null : convertNode(node, scope, optionsPosition, buffer, readString);
14085
+ node.source = convertNode(node, scope, position + 1, buffer, readString);
14086
+ node.sourceAstNode = parseAst_js.convertNode(position + 1, buffer, readString);
14087
+ },
14088
+ function importNamespaceSpecifier(node, position, buffer, readString) {
14089
+ const { scope } = node;
14090
+ node.local = convertNode(node, scope, position, buffer, readString);
14091
+ },
14092
+ function importSpecifier(node, position, buffer, readString) {
14093
+ const { scope } = node;
14094
+ const importedPosition = buffer[position];
14095
+ node.local = convertNode(node, scope, buffer[position + 1], buffer, readString);
14096
+ node.imported =
14097
+ importedPosition === 0
14098
+ ? node.local
14099
+ : convertNode(node, scope, importedPosition, buffer, readString);
14100
+ },
14101
+ function labeledStatement(node, position, buffer, readString) {
14102
+ const { scope } = node;
14103
+ node.body = convertNode(node, scope, buffer[position], buffer, readString);
14104
+ node.label = convertNode(node, scope, position + 1, buffer, readString);
14105
+ },
14106
+ function literalBigInt(node, position, buffer, readString) {
14107
+ node.raw = parseAst_js.convertString(buffer[position], buffer, readString);
14108
+ const bigint = (node.bigint = parseAst_js.convertString(position + 1, buffer, readString));
14109
+ node.value = BigInt(bigint);
14110
+ },
14111
+ function literalBoolean(node, position, buffer) {
14112
+ const flags = buffer[position];
14113
+ const value = (node.value = (flags & 1) === 1);
14114
+ node.raw = value ? 'true' : 'false';
14115
+ },
14116
+ function literalNull(node) {
14117
+ node.value = null;
14118
+ },
14119
+ function literalNumber(node, position, buffer, readString) {
14120
+ const rawPosition = buffer[position];
14121
+ node.raw = rawPosition === 0 ? undefined : parseAst_js.convertString(rawPosition, buffer, readString);
14122
+ node.value = new DataView(buffer.buffer).getFloat64((position + 1) << 2, true);
14123
+ },
14124
+ function literalRegExp(node, position, buffer, readString) {
14125
+ const pattern = parseAst_js.convertString(buffer[position], buffer, readString);
14126
+ const flags = parseAst_js.convertString(position + 1, buffer, readString);
14127
+ node.raw = `/${pattern}/${flags}`;
14128
+ node.regex = { flags, pattern };
14129
+ node.value = new RegExp(pattern, flags);
14130
+ },
14131
+ function literalString(node, position, buffer, readString) {
14132
+ const rawPosition = buffer[position];
14133
+ node.raw = rawPosition === 0 ? undefined : parseAst_js.convertString(rawPosition, buffer, readString);
14134
+ node.value = parseAst_js.convertString(position + 1, buffer, readString);
14135
+ },
14136
+ function logicalExpression(node, position, buffer, readString) {
14137
+ const { scope } = node;
14138
+ node.operator = parseAst_js.FIXED_STRINGS[buffer[position]];
14139
+ node.right = convertNode(node, scope, buffer[position + 1], buffer, readString);
14140
+ node.left = convertNode(node, scope, position + 2, buffer, readString);
14141
+ },
14142
+ function memberExpression(node, position, buffer, readString) {
14143
+ const { scope } = node;
14144
+ const flags = buffer[position];
14145
+ node.computed = (flags & 1) === 1;
14146
+ node.optional = (flags & 2) === 2;
14147
+ node.property = convertNode(node, scope, buffer[position + 1], buffer, readString);
14148
+ node.object = convertNode(node, scope, position + 2, buffer, readString);
14149
+ },
14150
+ function metaProperty(node, position, buffer, readString) {
14151
+ const { scope } = node;
14152
+ node.property = convertNode(node, scope, buffer[position], buffer, readString);
14153
+ node.meta = convertNode(node, scope, position + 1, buffer, readString);
14154
+ },
14155
+ function methodDefinition(node, position, buffer, readString) {
14156
+ const { scope } = node;
14157
+ const flags = buffer[position];
14158
+ node.static = (flags & 1) === 1;
14159
+ node.computed = (flags & 2) === 2;
14160
+ node.value = convertNode(node, scope, buffer[position + 1], buffer, readString);
14161
+ node.kind = parseAst_js.FIXED_STRINGS[buffer[position + 2]];
14162
+ node.key = convertNode(node, scope, position + 3, buffer, readString);
14163
+ },
14164
+ function newExpression(node, position, buffer, readString) {
14165
+ const { scope } = node;
14166
+ node.callee = convertNode(node, scope, buffer[position], buffer, readString);
14167
+ node.arguments = convertNodeList(node, scope, buffer[position + 1], buffer, readString);
14168
+ node.annotations = parseAst_js.convertAnnotations(position + 2, buffer);
14169
+ },
14170
+ function objectExpression(node, position, buffer, readString) {
14171
+ const { scope } = node;
14172
+ node.properties = convertNodeList(node, scope, position, buffer, readString);
14173
+ },
14174
+ function objectPattern(node, position, buffer, readString) {
14175
+ const { scope } = node;
14176
+ node.properties = convertNodeList(node, scope, position, buffer, readString);
14177
+ },
14178
+ function privateIdentifier(node, position, buffer, readString) {
14179
+ node.name = parseAst_js.convertString(position, buffer, readString);
14180
+ },
14181
+ function program(node, position, buffer, readString) {
14182
+ const { scope } = node;
14183
+ node.invalidAnnotations = parseAst_js.convertAnnotations(buffer[position], buffer);
14184
+ node.body = convertNodeList(node, scope, position + 1, buffer, readString);
14185
+ },
14186
+ function property(node, position, buffer, readString) {
14187
+ const { scope } = node;
14188
+ const flags = buffer[position];
14189
+ node.method = (flags & 1) === 1;
14190
+ node.shorthand = (flags & 2) === 2;
14191
+ node.computed = (flags & 4) === 4;
14192
+ const keyPosition = buffer[position + 1];
14193
+ node.value = convertNode(node, scope, buffer[position + 2], buffer, readString);
14194
+ node.kind = parseAst_js.FIXED_STRINGS[buffer[position + 3]];
14195
+ node.key =
14196
+ keyPosition === 0 ? node.value : convertNode(node, scope, keyPosition, buffer, readString);
14197
+ },
14198
+ function propertyDefinition(node, position, buffer, readString) {
14199
+ const { scope } = node;
14200
+ const flags = buffer[position];
14201
+ node.static = (flags & 1) === 1;
14202
+ node.computed = (flags & 2) === 2;
14203
+ const valuePosition = buffer[position + 1];
14204
+ node.value =
14205
+ valuePosition === 0 ? null : convertNode(node, scope, valuePosition, buffer, readString);
14206
+ node.key = convertNode(node, scope, position + 2, buffer, readString);
14207
+ },
14208
+ function restElement(node, position, buffer, readString) {
14209
+ const { scope } = node;
14210
+ node.argument = convertNode(node, scope, position, buffer, readString);
14211
+ },
14212
+ function returnStatement(node, position, buffer, readString) {
14213
+ const { scope } = node;
14214
+ const argumentPosition = buffer[position];
14215
+ node.argument =
14216
+ argumentPosition === 0
14217
+ ? null
14218
+ : convertNode(node, scope, argumentPosition, buffer, readString);
14219
+ },
14220
+ function sequenceExpression(node, position, buffer, readString) {
14221
+ const { scope } = node;
14222
+ node.expressions = convertNodeList(node, scope, position, buffer, readString);
14223
+ },
14224
+ function spreadElement(node, position, buffer, readString) {
14225
+ const { scope } = node;
14226
+ node.argument = convertNode(node, scope, position, buffer, readString);
14227
+ },
14228
+ function staticBlock(node, position, buffer, readString) {
14229
+ const { scope } = node;
14230
+ node.body = convertNodeList(node, scope, position, buffer, readString);
14231
+ },
14232
+ function superElement() { },
14233
+ function switchCase(node, position, buffer, readString) {
14234
+ const { scope } = node;
14235
+ const testPosition = buffer[position];
14236
+ node.test =
14237
+ testPosition === 0 ? null : convertNode(node, scope, testPosition, buffer, readString);
14238
+ node.consequent = convertNodeList(node, scope, buffer[position + 1], buffer, readString);
14239
+ },
14240
+ function switchStatement(node, position, buffer, readString) {
14241
+ const { scope } = node;
14242
+ node.cases = convertNodeList(node, scope, buffer[position], buffer, readString);
14243
+ node.discriminant = convertNode(node, node.parentScope, position + 1, buffer, readString);
14244
+ },
14245
+ function taggedTemplateExpression(node, position, buffer, readString) {
14246
+ const { scope } = node;
14247
+ node.quasi = convertNode(node, scope, buffer[position], buffer, readString);
14248
+ node.tag = convertNode(node, scope, position + 1, buffer, readString);
14249
+ },
14250
+ function templateElement(node, position, buffer, readString) {
14251
+ const flags = buffer[position];
14252
+ node.tail = (flags & 1) === 1;
14253
+ const cookedPosition = buffer[position + 1];
14254
+ const cooked = cookedPosition === 0 ? undefined : parseAst_js.convertString(cookedPosition, buffer, readString);
14255
+ const raw = parseAst_js.convertString(position + 2, buffer, readString);
14256
+ node.value = { cooked, raw };
14257
+ },
14258
+ function templateLiteral(node, position, buffer, readString) {
14259
+ const { scope } = node;
14260
+ node.expressions = convertNodeList(node, scope, buffer[position], buffer, readString);
14261
+ node.quasis = convertNodeList(node, scope, position + 1, buffer, readString);
14262
+ },
14263
+ function thisExpression() { },
14264
+ function throwStatement(node, position, buffer, readString) {
14265
+ const { scope } = node;
14266
+ node.argument = convertNode(node, scope, position, buffer, readString);
14267
+ },
14268
+ function tryStatement(node, position, buffer, readString) {
14269
+ const { scope } = node;
14270
+ const handlerPosition = buffer[position];
14271
+ node.handler =
14272
+ handlerPosition === 0 ? null : convertNode(node, scope, handlerPosition, buffer, readString);
14273
+ const finalizerPosition = buffer[position + 1];
14274
+ node.finalizer =
14275
+ finalizerPosition === 0
14276
+ ? null
14277
+ : convertNode(node, scope, finalizerPosition, buffer, readString);
14278
+ node.block = convertNode(node, scope, position + 2, buffer, readString);
14279
+ },
14280
+ function unaryExpression(node, position, buffer, readString) {
14281
+ const { scope } = node;
14282
+ node.operator = parseAst_js.FIXED_STRINGS[buffer[position]];
14283
+ node.argument = convertNode(node, scope, position + 1, buffer, readString);
14284
+ },
14285
+ function updateExpression(node, position, buffer, readString) {
14286
+ const { scope } = node;
14287
+ const flags = buffer[position];
14288
+ node.prefix = (flags & 1) === 1;
14289
+ node.operator = parseAst_js.FIXED_STRINGS[buffer[position + 1]];
14290
+ node.argument = convertNode(node, scope, position + 2, buffer, readString);
14291
+ },
14292
+ function variableDeclaration(node, position, buffer, readString) {
14293
+ const { scope } = node;
14294
+ node.kind = parseAst_js.FIXED_STRINGS[buffer[position]];
14295
+ node.declarations = convertNodeList(node, scope, position + 1, buffer, readString);
14296
+ },
14297
+ function variableDeclarator(node, position, buffer, readString) {
14298
+ const { scope } = node;
14299
+ const initPosition = buffer[position];
14300
+ node.init =
14301
+ initPosition === 0 ? null : convertNode(node, scope, initPosition, buffer, readString);
14302
+ node.id = convertNode(node, scope, position + 1, buffer, readString);
14303
+ },
14304
+ function whileStatement(node, position, buffer, readString) {
14305
+ const { scope } = node;
14306
+ node.body = convertNode(node, scope, buffer[position], buffer, readString);
14307
+ node.test = convertNode(node, scope, position + 1, buffer, readString);
14308
+ },
14309
+ function yieldExpression(node, position, buffer, readString) {
14310
+ const { scope } = node;
14311
+ const flags = buffer[position];
14312
+ node.delegate = (flags & 1) === 1;
14313
+ const argumentPosition = buffer[position + 1];
14314
+ node.argument =
14315
+ argumentPosition === 0
14316
+ ? null
14317
+ : convertNode(node, scope, argumentPosition, buffer, readString);
14318
+ }
14319
+ ];
14320
+ function convertNode(parent, parentScope, position, buffer, readString) {
14321
+ const nodeType = buffer[position];
14322
+ const NodeConstructor = nodeConstructors$1[nodeType];
14323
+ /* istanbul ignore if: This should never be executed but is a safeguard against faulty buffers */
14324
+ if (!NodeConstructor) {
14325
+ console.trace();
14326
+ throw new Error(`Unknown node type: ${nodeType}`);
14327
+ }
14328
+ const node = new NodeConstructor(parent, parentScope);
14329
+ node.type = nodeTypeStrings[nodeType];
14330
+ node.start = buffer[position + 1];
14331
+ node.end = buffer[position + 2];
14332
+ bufferParsers[nodeType](node, position + 3, buffer, readString);
14333
+ node.initialise();
14334
+ return node;
14335
+ }
14336
+ function convertNodeList(parent, parentScope, position, buffer, readString) {
14337
+ const length = buffer[position++];
14338
+ const list = [];
14339
+ for (let index = 0; index < length; index++) {
14340
+ const nodePosition = buffer[position++];
14341
+ list.push(nodePosition ? convertNode(parent, parentScope, nodePosition, buffer, readString) : null);
14342
+ }
14343
+ return list;
14344
+ }
14345
+
14346
+ class UnknownNode extends NodeBase {
14347
+ hasEffects() {
14348
+ return true;
14349
+ }
14350
+ include(context) {
14351
+ super.include(context, true);
14352
+ }
14353
+ }
14354
+
13527
14355
  const nodeConstructors = {
13528
14356
  ArrayExpression,
13529
14357
  ArrayPattern,
@@ -13571,6 +14399,8 @@ const nodeConstructors = {
13571
14399
  NewExpression,
13572
14400
  ObjectExpression,
13573
14401
  ObjectPattern,
14402
+ PanicError,
14403
+ ParseError,
13574
14404
  PrivateIdentifier,
13575
14405
  Program,
13576
14406
  Property,
@@ -13918,7 +14748,9 @@ function getAttributesFromImportExpression(node) {
13918
14748
  }
13919
14749
  const getPropertyKey = (property) => {
13920
14750
  const key = property.key;
13921
- return (key && !property.computed && (key.name || key.value));
14751
+ return (key &&
14752
+ !property.computed &&
14753
+ (key.name || key.value));
13922
14754
  };
13923
14755
  function getAttributesFromImportExportDeclaration(attributes) {
13924
14756
  return attributes?.length
@@ -14566,11 +15398,11 @@ class Module {
14566
15398
  return { source, usesTopLevelAwait };
14567
15399
  }
14568
15400
  async setSource({ ast, code, customTransformCache, originalCode, originalSourcemap, resolvedIds, sourcemapChain, transformDependencies, transformFiles, ...moduleOptions }) {
15401
+ timeStart('generate ast', 3);
14569
15402
  if (code.startsWith('#!')) {
14570
15403
  const shebangEndPosition = code.indexOf('\n');
14571
15404
  this.shebang = code.slice(2, shebangEndPosition);
14572
15405
  }
14573
- timeStart('generate ast', 3);
14574
15406
  this.info.code = code;
14575
15407
  this.originalCode = originalCode;
14576
15408
  // We need to call decodedSourcemap on the input in case they were hydrated from json in the cache and don't
@@ -14586,9 +15418,6 @@ class Module {
14586
15418
  this.transformDependencies = transformDependencies;
14587
15419
  this.customTransformCache = customTransformCache;
14588
15420
  this.updateOptions(moduleOptions);
14589
- const moduleAst = ast ?? (await this.tryParseAsync());
14590
- timeEnd('generate ast', 3);
14591
- timeStart('analyze ast', 3);
14592
15421
  this.resolvedIds = resolvedIds ?? Object.create(null);
14593
15422
  // By default, `id` is the file name. Custom resolvers and loaders
14594
15423
  // can change that, but it makes sense to use it for the source file name
@@ -14628,13 +15457,17 @@ class Module {
14628
15457
  };
14629
15458
  this.scope = new ModuleScope(this.graph.scope, this.astContext);
14630
15459
  this.namespace = new NamespaceVariable(this.astContext);
14631
- this.ast = new Program(moduleAst, { context: this.astContext, type: 'Module' }, this.scope);
14632
- // Assign AST directly if has existing one as there's no way to drop it from memory.
14633
- // If cache is enabled, also assign directly as otherwise it takes more CPU and memory to re-compute.
14634
- if (ast || this.options.cache !== false) {
14635
- this.info.ast = moduleAst;
15460
+ const programParent = { context: this.astContext, type: 'Module' };
15461
+ if (ast) {
15462
+ this.ast = new nodeConstructors[ast.type](programParent, this.scope).parseNode(ast);
15463
+ this.info.ast = ast;
14636
15464
  }
14637
15465
  else {
15466
+ // Measuring asynchronous code does not provide reasonable results
15467
+ timeEnd('generate ast', 3);
15468
+ const astBuffer = await native_js.parseAsync(code, false);
15469
+ timeStart('generate ast', 3);
15470
+ this.ast = convertProgram(astBuffer, programParent, this.scope);
14638
15471
  // Make lazy and apply LRU cache to not hog the memory
14639
15472
  Object.defineProperty(this.info, 'ast', {
14640
15473
  get: () => {
@@ -14643,13 +15476,23 @@ class Module {
14643
15476
  }
14644
15477
  else {
14645
15478
  const parsedAst = this.tryParse();
15479
+ // If the cache is not disabled, we need to keep the AST in memory
15480
+ // until the end when the cache is generated
15481
+ if (this.options.cache !== false) {
15482
+ Object.defineProperty(this.info, 'ast', {
15483
+ value: parsedAst
15484
+ });
15485
+ return parsedAst;
15486
+ }
15487
+ // Otherwise, we keep it in a small LRU cache to not hog too much
15488
+ // memory but allow the same AST to be requested several times.
14646
15489
  this.graph.astLru.set(fileName, parsedAst);
14647
15490
  return parsedAst;
14648
15491
  }
14649
15492
  }
14650
15493
  });
14651
15494
  }
14652
- timeEnd('analyze ast', 3);
15495
+ timeEnd('generate ast', 3);
14653
15496
  }
14654
15497
  toJSON() {
14655
15498
  return {
@@ -14702,13 +15545,15 @@ class Module {
14702
15545
  }
14703
15546
  }
14704
15547
  addDynamicImport(node) {
14705
- let argument = node.source;
14706
- if (argument instanceof TemplateLiteral) {
14707
- if (argument.quasis.length === 1 && argument.quasis[0].value.cooked) {
15548
+ let argument = node.sourceAstNode;
15549
+ if (argument.type === parseAst_js.TemplateLiteral) {
15550
+ if (argument.quasis.length === 1 &&
15551
+ typeof argument.quasis[0].value.cooked === 'string') {
14708
15552
  argument = argument.quasis[0].value.cooked;
14709
15553
  }
14710
15554
  }
14711
- else if (argument instanceof Literal && typeof argument.value === 'string') {
15555
+ else if (argument.type === parseAst_js.Literal &&
15556
+ typeof argument.value === 'string') {
14712
15557
  argument = argument.value;
14713
15558
  }
14714
15559
  this.dynamicImports.push({ argument, id: null, node, resolution: null });
@@ -15003,14 +15848,6 @@ class Module {
15003
15848
  return this.error(parseAst_js.logModuleParseError(error_, this.id), error_.pos);
15004
15849
  }
15005
15850
  }
15006
- async tryParseAsync() {
15007
- try {
15008
- return await parseAst_js.parseAstAsync(this.info.code);
15009
- }
15010
- catch (error_) {
15011
- return this.error(parseAst_js.logModuleParseError(error_, this.id), error_.pos);
15012
- }
15013
- }
15014
15851
  }
15015
15852
  // if there is a cyclic import in the reexport chain, we should not
15016
15853
  // import from the original module but from the cyclic module to not
@@ -18907,7 +19744,6 @@ class ModuleLoader {
18907
19744
  ? source
18908
19745
  : parseAst_js.error(parseAst_js.logBadLoader(id));
18909
19746
  const code = sourceDescription.code;
18910
- /* eslint-disable-next-line unicorn/number-literal-case */
18911
19747
  if (code.charCodeAt(0) === 65279) {
18912
19748
  sourceDescription.code = code.slice(1);
18913
19749
  }
@@ -19091,9 +19927,7 @@ class ModuleLoader {
19091
19927
  }
19092
19928
  getResolveDynamicImportPromises(module) {
19093
19929
  return module.dynamicImports.map(async (dynamicImport) => {
19094
- const resolvedId = await this.resolveDynamicImport(module, typeof dynamicImport.argument === 'string'
19095
- ? dynamicImport.argument
19096
- : dynamicImport.argument.esTreeNode, module.id, getAttributesFromImportExpression(dynamicImport.node));
19930
+ const resolvedId = await this.resolveDynamicImport(module, dynamicImport.argument, module.id, getAttributesFromImportExpression(dynamicImport.node));
19097
19931
  if (resolvedId && typeof resolvedId === 'object') {
19098
19932
  dynamicImport.id = resolvedId.id;
19099
19933
  }