source: node_modules/rollup/dist/es/shared/parseAst.js@ 57e58a3

Last change on this file since 57e58a3 was 57e58a3, checked in by ste08 <sjovanoska@…>, 4 months ago

Initial commit

  • Property mode set to 100644
File size: 81.2 KB
Line 
1/*
2 @license
3 Rollup.js v4.34.4
4 Wed, 05 Feb 2025 21:30:40 GMT - commit 19312a762c3cda56a0f6dc80a0887a4499db2257
5
6 https://github.com/rollup/rollup
7
8 Released under the MIT License.
9*/
10import { parse, parseAsync } from '../../native.js';
11import { resolve, dirname, basename, extname } from 'node:path';
12
13// This file is generated by scripts/generate-node-types.js.
14// Do not edit this file directly.
15const ArrowFunctionExpression = 'ArrowFunctionExpression';
16const BlockStatement = 'BlockStatement';
17const CallExpression = 'CallExpression';
18const CatchClause = 'CatchClause';
19const ExportDefaultDeclaration = 'ExportDefaultDeclaration';
20const ExpressionStatement = 'ExpressionStatement';
21const Identifier = 'Identifier';
22const Literal = 'Literal';
23const ObjectExpression = 'ObjectExpression';
24const PanicError = 'PanicError';
25const ParseError = 'ParseError';
26const Program = 'Program';
27const Property = 'Property';
28const RestElement = 'RestElement';
29const ReturnStatement = 'ReturnStatement';
30const StaticBlock = 'StaticBlock';
31const TemplateLiteral = 'TemplateLiteral';
32const VariableDeclarator = 'VariableDeclarator';
33
34const BLANK = Object.freeze(Object.create(null));
35const EMPTY_OBJECT = Object.freeze({});
36const EMPTY_ARRAY = Object.freeze([]);
37const EMPTY_SET = Object.freeze(new (class extends Set {
38 add() {
39 throw new Error('Cannot add to empty set');
40 }
41})());
42
43// This file is generated by scripts/generate-string-constants.js.
44// Do not edit this file directly.
45const FIXED_STRINGS = [
46 'var',
47 'let',
48 'const',
49 'init',
50 'get',
51 'set',
52 'constructor',
53 'method',
54 '-',
55 '+',
56 '!',
57 '~',
58 'typeof',
59 'void',
60 'delete',
61 '++',
62 '--',
63 '==',
64 '!=',
65 '===',
66 '!==',
67 '<',
68 '<=',
69 '>',
70 '>=',
71 '<<',
72 '>>',
73 '>>>',
74 '+',
75 '-',
76 '*',
77 '/',
78 '%',
79 '|',
80 '^',
81 '&',
82 '||',
83 '&&',
84 'in',
85 'instanceof',
86 '**',
87 '??',
88 '=',
89 '+=',
90 '-=',
91 '*=',
92 '/=',
93 '%=',
94 '<<=',
95 '>>=',
96 '>>>=',
97 '|=',
98 '^=',
99 '&=',
100 '**=',
101 '&&=',
102 '||=',
103 '??=',
104 'pure',
105 'noSideEffects',
106 'sourcemap',
107 'using',
108 'await using'
109];
110
111const ANNOTATION_KEY = '_rollupAnnotations';
112const INVALID_ANNOTATION_KEY = '_rollupRemoved';
113const convertAnnotations = (position, buffer) => {
114 if (position === 0)
115 return EMPTY_ARRAY;
116 const length = buffer[position++];
117 const list = new Array(length);
118 for (let index = 0; index < length; index++) {
119 list[index] = convertAnnotation(buffer[position++], buffer);
120 }
121 return list;
122};
123const convertAnnotation = (position, buffer) => {
124 const start = buffer[position++];
125 const end = buffer[position++];
126 const type = FIXED_STRINGS[buffer[position]];
127 return { end, start, type };
128};
129
130/** @typedef {import('./types').Location} Location */
131
132/**
133 * @param {import('./types').Range} range
134 * @param {number} index
135 */
136function rangeContains(range, index) {
137 return range.start <= index && index < range.end;
138}
139
140/**
141 * @param {string} source
142 * @param {import('./types').Options} [options]
143 */
144function getLocator(source, options = {}) {
145 const { offsetLine = 0, offsetColumn = 0 } = options;
146
147 let start = 0;
148 const ranges = source.split('\n').map((line, i) => {
149 const end = start + line.length + 1;
150
151 /** @type {import('./types').Range} */
152 const range = { start, end, line: i };
153
154 start = end;
155 return range;
156 });
157
158 let i = 0;
159
160 /**
161 * @param {string | number} search
162 * @param {number} [index]
163 * @returns {Location | undefined}
164 */
165 function locator(search, index) {
166 if (typeof search === 'string') {
167 search = source.indexOf(search, index ?? 0);
168 }
169
170 if (search === -1) return undefined;
171
172 let range = ranges[i];
173
174 const d = search >= range.end ? 1 : -1;
175
176 while (range) {
177 if (rangeContains(range, search)) {
178 return {
179 line: offsetLine + range.line,
180 column: offsetColumn + search - range.start,
181 character: search
182 };
183 }
184
185 i += d;
186 range = ranges[i];
187 }
188 }
189
190 return locator;
191}
192
193/**
194 * @param {string} source
195 * @param {string | number} search
196 * @param {import('./types').Options} [options]
197 * @returns {Location | undefined}
198 */
199function locate(source, search, options) {
200 return getLocator(source, options)(search, options && options.startIndex);
201}
202
203function spaces(index) {
204 let result = '';
205 while (index--)
206 result += ' ';
207 return result;
208}
209function tabsToSpaces(value) {
210 return value.replace(/^\t+/, match => match.split('\t').join(' '));
211}
212const LINE_TRUNCATE_LENGTH = 120;
213const MIN_CHARACTERS_SHOWN_AFTER_LOCATION = 10;
214const ELLIPSIS = '...';
215function getCodeFrame(source, line, column) {
216 let lines = source.split('\n');
217 // Needed if a plugin did not generate correct sourcemaps
218 if (line > lines.length)
219 return '';
220 const maxLineLength = Math.max(tabsToSpaces(lines[line - 1].slice(0, column)).length +
221 MIN_CHARACTERS_SHOWN_AFTER_LOCATION +
222 ELLIPSIS.length, LINE_TRUNCATE_LENGTH);
223 const frameStart = Math.max(0, line - 3);
224 let frameEnd = Math.min(line + 2, lines.length);
225 lines = lines.slice(frameStart, frameEnd);
226 while (!/\S/.test(lines[lines.length - 1])) {
227 lines.pop();
228 frameEnd -= 1;
229 }
230 const digits = String(frameEnd).length;
231 return lines
232 .map((sourceLine, index) => {
233 const isErrorLine = frameStart + index + 1 === line;
234 let lineNumber = String(index + frameStart + 1);
235 while (lineNumber.length < digits)
236 lineNumber = ` ${lineNumber}`;
237 let displayedLine = tabsToSpaces(sourceLine);
238 if (displayedLine.length > maxLineLength) {
239 displayedLine = `${displayedLine.slice(0, maxLineLength - ELLIPSIS.length)}${ELLIPSIS}`;
240 }
241 if (isErrorLine) {
242 const indicator = spaces(digits + 2 + tabsToSpaces(sourceLine.slice(0, column)).length) + '^';
243 return `${lineNumber}: ${displayedLine}\n${indicator}`;
244 }
245 return `${lineNumber}: ${displayedLine}`;
246 })
247 .join('\n');
248}
249
250const LOGLEVEL_SILENT = 'silent';
251const LOGLEVEL_ERROR = 'error';
252const LOGLEVEL_WARN = 'warn';
253const LOGLEVEL_INFO = 'info';
254const LOGLEVEL_DEBUG = 'debug';
255const logLevelPriority = {
256 [LOGLEVEL_DEBUG]: 0,
257 [LOGLEVEL_INFO]: 1,
258 [LOGLEVEL_SILENT]: 3,
259 [LOGLEVEL_WARN]: 2
260};
261
262const ABSOLUTE_PATH_REGEX = /^(?:\/|(?:[A-Za-z]:)?[/\\|])/;
263const RELATIVE_PATH_REGEX = /^\.?\.(\/|$)/;
264function isAbsolute(path) {
265 return ABSOLUTE_PATH_REGEX.test(path);
266}
267function isRelative(path) {
268 return RELATIVE_PATH_REGEX.test(path);
269}
270const BACKSLASH_REGEX = /\\/g;
271function normalize(path) {
272 return path.replace(BACKSLASH_REGEX, '/');
273}
274
275function printQuotedStringList(list, verbs) {
276 const isSingleItem = list.length <= 1;
277 const quotedList = list.map(item => `"${item}"`);
278 let output = isSingleItem
279 ? quotedList[0]
280 : `${quotedList.slice(0, -1).join(', ')} and ${quotedList.slice(-1)[0]}`;
281 if (verbs) {
282 output += ` ${isSingleItem ? verbs[0] : verbs[1]}`;
283 }
284 return output;
285}
286
287const ANY_SLASH_REGEX = /[/\\]/;
288function relative(from, to) {
289 const fromParts = from.split(ANY_SLASH_REGEX).filter(Boolean);
290 const toParts = to.split(ANY_SLASH_REGEX).filter(Boolean);
291 if (fromParts[0] === '.')
292 fromParts.shift();
293 if (toParts[0] === '.')
294 toParts.shift();
295 while (fromParts[0] && toParts[0] && fromParts[0] === toParts[0]) {
296 fromParts.shift();
297 toParts.shift();
298 }
299 while (toParts[0] === '..' && fromParts.length > 0) {
300 toParts.shift();
301 fromParts.pop();
302 }
303 while (fromParts.pop()) {
304 toParts.unshift('..');
305 }
306 return toParts.join('/');
307}
308
309function getAliasName(id) {
310 const base = basename(id);
311 return base.slice(0, Math.max(0, base.length - extname(id).length));
312}
313function relativeId(id) {
314 if (!isAbsolute(id))
315 return id;
316 return relative(resolve(), id);
317}
318function isPathFragment(name) {
319 // starting with "/", "./", "../", "C:/"
320 return (name[0] === '/' || (name[0] === '.' && (name[1] === '/' || name[1] === '.')) || isAbsolute(name));
321}
322const UPPER_DIR_REGEX = /^(\.\.\/)*\.\.$/;
323function getImportPath(importerId, targetPath, stripJsExtension, ensureFileName) {
324 while (targetPath.startsWith('../')) {
325 targetPath = targetPath.slice(3);
326 importerId = '_/' + importerId;
327 }
328 let relativePath = normalize(relative(dirname(importerId), targetPath));
329 if (stripJsExtension && relativePath.endsWith('.js')) {
330 relativePath = relativePath.slice(0, -3);
331 }
332 if (ensureFileName) {
333 if (relativePath === '')
334 return '../' + basename(targetPath);
335 if (UPPER_DIR_REGEX.test(relativePath)) {
336 return [...relativePath.split('/'), '..', basename(targetPath)].join('/');
337 }
338 }
339 return relativePath ? (relativePath.startsWith('..') ? relativePath : './' + relativePath) : '.';
340}
341
342function isValidUrl(url) {
343 try {
344 new URL(url);
345 }
346 catch {
347 return false;
348 }
349 return true;
350}
351function getRollupUrl(snippet) {
352 return `https://rollupjs.org/${snippet}`;
353}
354function addTrailingSlashIfMissed(url) {
355 if (!url.endsWith('/')) {
356 return url + '/';
357 }
358 return url;
359}
360
361// troubleshooting
362const URL_AVOIDING_EVAL = 'troubleshooting/#avoiding-eval';
363const URL_NAME_IS_NOT_EXPORTED = 'troubleshooting/#error-name-is-not-exported-by-module';
364const URL_THIS_IS_UNDEFINED = 'troubleshooting/#error-this-is-undefined';
365const URL_TREATING_MODULE_AS_EXTERNAL_DEPENDENCY = 'troubleshooting/#warning-treating-module-as-external-dependency';
366const URL_SOURCEMAP_IS_LIKELY_TO_BE_INCORRECT = 'troubleshooting/#warning-sourcemap-is-likely-to-be-incorrect';
367// configuration-options
368const URL_JSX = 'configuration-options/#jsx';
369const URL_OUTPUT_AMD_ID = 'configuration-options/#output-amd-id';
370const URL_OUTPUT_AMD_BASEPATH = 'configuration-options/#output-amd-basepath';
371const URL_OUTPUT_DIR = 'configuration-options/#output-dir';
372const URL_OUTPUT_EXPORTS = 'configuration-options/#output-exports';
373const URL_OUTPUT_EXTEND = 'configuration-options/#output-extend';
374const URL_OUTPUT_EXTERNALIMPORTATTRIBUTES = 'configuration-options/#output-externalimportattributes';
375const URL_OUTPUT_FORMAT = 'configuration-options/#output-format';
376const URL_OUTPUT_GENERATEDCODE = 'configuration-options/#output-generatedcode';
377const URL_OUTPUT_GLOBALS = 'configuration-options/#output-globals';
378const URL_OUTPUT_INLINEDYNAMICIMPORTS = 'configuration-options/#output-inlinedynamicimports';
379const URL_OUTPUT_INTEROP = 'configuration-options/#output-interop';
380const URL_OUTPUT_MANUALCHUNKS = 'configuration-options/#output-manualchunks';
381const URL_OUTPUT_NAME = 'configuration-options/#output-name';
382const URL_OUTPUT_SOURCEMAPBASEURL = 'configuration-options/#output-sourcemapbaseurl';
383const URL_OUTPUT_SOURCEMAPFILE = 'configuration-options/#output-sourcemapfile';
384const URL_PRESERVEENTRYSIGNATURES = 'configuration-options/#preserveentrysignatures';
385const URL_TREESHAKE = 'configuration-options/#treeshake';
386const URL_TREESHAKE_PURE = 'configuration-options/#pure';
387const URL_TREESHAKE_NOSIDEEFFECTS = 'configuration-options/#no-side-effects';
388const URL_TREESHAKE_MODULESIDEEFFECTS = 'configuration-options/#treeshake-modulesideeffects';
389const URL_WATCH = 'configuration-options/#watch';
390const URL_GENERATEBUNDLE = 'plugin-development/#generatebundle';
391
392function error(base) {
393 throw base instanceof Error ? base : getRollupError(base);
394}
395function getRollupError(base) {
396 augmentLogMessage(base);
397 const errorInstance = Object.assign(new Error(base.message), base);
398 Object.defineProperty(errorInstance, 'name', {
399 value: 'RollupError',
400 writable: true
401 });
402 return errorInstance;
403}
404function augmentCodeLocation(properties, pos, source, id) {
405 if (typeof pos === 'object') {
406 const { line, column } = pos;
407 properties.loc = { column, file: id, line };
408 }
409 else {
410 properties.pos = pos;
411 const location = locate(source, pos, { offsetLine: 1 });
412 if (!location) {
413 return;
414 }
415 const { line, column } = location;
416 properties.loc = { column, file: id, line };
417 }
418 if (properties.frame === undefined) {
419 const { line, column } = properties.loc;
420 properties.frame = getCodeFrame(source, line, column);
421 }
422}
423const symbolAugmented = Symbol('augmented');
424function augmentLogMessage(log) {
425 // Make sure to only augment the log message once
426 if (!(log.plugin || log.loc) || log[symbolAugmented]) {
427 return;
428 }
429 log[symbolAugmented] = true;
430 let prefix = '';
431 if (log.plugin) {
432 prefix += `[plugin ${log.plugin}] `;
433 }
434 const id = log.id || log.loc?.file;
435 if (id) {
436 const position = log.loc ? ` (${log.loc.line}:${log.loc.column})` : '';
437 prefix += `${relativeId(id)}${position}: `;
438 }
439 const oldMessage = log.message;
440 log.message = prefix + log.message;
441 tweakStackMessage(log, oldMessage);
442}
443// Error codes should be sorted alphabetically while errors should be sorted by
444// error code below
445const ADDON_ERROR = 'ADDON_ERROR', ALREADY_CLOSED = 'ALREADY_CLOSED', AMBIGUOUS_EXTERNAL_NAMESPACES = 'AMBIGUOUS_EXTERNAL_NAMESPACES', ANONYMOUS_PLUGIN_CACHE = 'ANONYMOUS_PLUGIN_CACHE', ASSET_NOT_FINALISED = 'ASSET_NOT_FINALISED', ASSET_NOT_FOUND = 'ASSET_NOT_FOUND', ASSET_SOURCE_ALREADY_SET = 'ASSET_SOURCE_ALREADY_SET', ASSET_SOURCE_MISSING = 'ASSET_SOURCE_MISSING', BAD_LOADER = 'BAD_LOADER', CANNOT_CALL_NAMESPACE = 'CANNOT_CALL_NAMESPACE', CANNOT_EMIT_FROM_OPTIONS_HOOK = 'CANNOT_EMIT_FROM_OPTIONS_HOOK', CHUNK_NOT_GENERATED = 'CHUNK_NOT_GENERATED', CHUNK_INVALID = 'CHUNK_INVALID', CIRCULAR_DEPENDENCY = 'CIRCULAR_DEPENDENCY', CIRCULAR_REEXPORT = 'CIRCULAR_REEXPORT', CONST_REASSIGN = 'CONST_REASSIGN', CYCLIC_CROSS_CHUNK_REEXPORT = 'CYCLIC_CROSS_CHUNK_REEXPORT', DEPRECATED_FEATURE = 'DEPRECATED_FEATURE', DUPLICATE_ARGUMENT_NAME = 'DUPLICATE_ARGUMENT_NAME', DUPLICATE_EXPORT = 'DUPLICATE_EXPORT', DUPLICATE_PLUGIN_NAME = 'DUPLICATE_PLUGIN_NAME', EMPTY_BUNDLE = 'EMPTY_BUNDLE', EVAL = 'EVAL', EXTERNAL_MODULES_CANNOT_BE_INCLUDED_IN_MANUAL_CHUNKS = 'EXTERNAL_MODULES_CANNOT_BE_INCLUDED_IN_MANUAL_CHUNKS', EXTERNAL_MODULES_CANNOT_BE_TRANSFORMED_TO_MODULES = 'EXTERNAL_MODULES_CANNOT_BE_TRANSFORMED_TO_MODULES', EXTERNAL_SYNTHETIC_EXPORTS = 'EXTERNAL_SYNTHETIC_EXPORTS', FILE_NAME_CONFLICT = 'FILE_NAME_CONFLICT', FILE_NOT_FOUND = 'FILE_NOT_FOUND', FIRST_SIDE_EFFECT = 'FIRST_SIDE_EFFECT', ILLEGAL_IDENTIFIER_AS_NAME = 'ILLEGAL_IDENTIFIER_AS_NAME', ILLEGAL_REASSIGNMENT = 'ILLEGAL_REASSIGNMENT', INCONSISTENT_IMPORT_ATTRIBUTES = 'INCONSISTENT_IMPORT_ATTRIBUTES', INVALID_ANNOTATION = 'INVALID_ANNOTATION', INPUT_HOOK_IN_OUTPUT_PLUGIN = 'INPUT_HOOK_IN_OUTPUT_PLUGIN', INVALID_CHUNK = 'INVALID_CHUNK', INVALID_EXPORT_OPTION = 'INVALID_EXPORT_OPTION', INVALID_EXTERNAL_ID = 'INVALID_EXTERNAL_ID', INVALID_IMPORT_ATTRIBUTE = 'INVALID_IMPORT_ATTRIBUTE', INVALID_LOG_POSITION = 'INVALID_LOG_POSITION', INVALID_OPTION = 'INVALID_OPTION', INVALID_PLUGIN_HOOK = 'INVALID_PLUGIN_HOOK', INVALID_ROLLUP_PHASE = 'INVALID_ROLLUP_PHASE', INVALID_SETASSETSOURCE = 'INVALID_SETASSETSOURCE', INVALID_TLA_FORMAT = 'INVALID_TLA_FORMAT', MISSING_EXPORT = 'MISSING_EXPORT', MISSING_GLOBAL_NAME = 'MISSING_GLOBAL_NAME', MISSING_IMPLICIT_DEPENDANT = 'MISSING_IMPLICIT_DEPENDANT', MISSING_JSX_EXPORT = 'MISSING_JSX_EXPORT', MISSING_NAME_OPTION_FOR_IIFE_EXPORT = 'MISSING_NAME_OPTION_FOR_IIFE_EXPORT', MISSING_NODE_BUILTINS = 'MISSING_NODE_BUILTINS', MISSING_OPTION = 'MISSING_OPTION', MIXED_EXPORTS = 'MIXED_EXPORTS', MODULE_LEVEL_DIRECTIVE = 'MODULE_LEVEL_DIRECTIVE', NAMESPACE_CONFLICT = 'NAMESPACE_CONFLICT', NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE = 'NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE', OPTIMIZE_CHUNK_STATUS = 'OPTIMIZE_CHUNK_STATUS', PARSE_ERROR = 'PARSE_ERROR', PLUGIN_ERROR = 'PLUGIN_ERROR', REDECLARATION_ERROR = 'REDECLARATION_ERROR', RESERVED_NAMESPACE = 'RESERVED_NAMESPACE', SHIMMED_EXPORT = 'SHIMMED_EXPORT', SOURCEMAP_BROKEN = 'SOURCEMAP_BROKEN', SOURCEMAP_ERROR = 'SOURCEMAP_ERROR', SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT = 'SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT', THIS_IS_UNDEFINED = 'THIS_IS_UNDEFINED', UNEXPECTED_NAMED_IMPORT = 'UNEXPECTED_NAMED_IMPORT', UNKNOWN_OPTION = 'UNKNOWN_OPTION', UNRESOLVED_ENTRY = 'UNRESOLVED_ENTRY', UNRESOLVED_IMPORT = 'UNRESOLVED_IMPORT', UNUSED_EXTERNAL_IMPORT = 'UNUSED_EXTERNAL_IMPORT', VALIDATION_ERROR = 'VALIDATION_ERROR';
446function logAddonNotGenerated(message, hook, plugin) {
447 return {
448 code: ADDON_ERROR,
449 message: `Could not retrieve "${hook}". Check configuration of plugin "${plugin}".
450\tError Message: ${message}`
451 };
452}
453function logAlreadyClosed() {
454 return {
455 code: ALREADY_CLOSED,
456 message: 'Bundle is already closed, no more calls to "generate" or "write" are allowed.'
457 };
458}
459function logAmbiguousExternalNamespaces(binding, reexportingModule, usedModule, sources) {
460 return {
461 binding,
462 code: AMBIGUOUS_EXTERNAL_NAMESPACES,
463 ids: sources,
464 message: `Ambiguous external namespace resolution: "${relativeId(reexportingModule)}" re-exports "${binding}" from one of the external modules ${printQuotedStringList(sources.map(module => relativeId(module)))}, guessing "${relativeId(usedModule)}".`,
465 reexporter: reexportingModule
466 };
467}
468function logAnonymousPluginCache() {
469 return {
470 code: ANONYMOUS_PLUGIN_CACHE,
471 message: 'A plugin is trying to use the Rollup cache but is not declaring a plugin name or cacheKey.'
472 };
473}
474function logAssetNotFinalisedForFileName(name) {
475 return {
476 code: ASSET_NOT_FINALISED,
477 message: `Plugin error - Unable to get file name for asset "${name}". Ensure that the source is set and that generate is called first. If you reference assets via import.meta.ROLLUP_FILE_URL_<referenceId>, you need to either have set their source after "renderStart" or need to provide an explicit "fileName" when emitting them.`
478 };
479}
480function logAssetReferenceIdNotFoundForSetSource(assetReferenceId) {
481 return {
482 code: ASSET_NOT_FOUND,
483 message: `Plugin error - Unable to set the source for unknown asset "${assetReferenceId}".`
484 };
485}
486function logAssetSourceAlreadySet(name) {
487 return {
488 code: ASSET_SOURCE_ALREADY_SET,
489 message: `Unable to set the source for asset "${name}", source already set.`
490 };
491}
492function logNoAssetSourceSet(assetName) {
493 return {
494 code: ASSET_SOURCE_MISSING,
495 message: `Plugin error creating asset "${assetName}" - no asset source set.`
496 };
497}
498function logBadLoader(id) {
499 return {
500 code: BAD_LOADER,
501 message: `Error loading "${relativeId(id)}": plugin load hook should return a string, a { code, map } object, or nothing/null.`
502 };
503}
504function logCannotCallNamespace(name) {
505 return {
506 code: CANNOT_CALL_NAMESPACE,
507 message: `Cannot call a namespace ("${name}").`
508 };
509}
510function logCannotEmitFromOptionsHook() {
511 return {
512 code: CANNOT_EMIT_FROM_OPTIONS_HOOK,
513 message: `Cannot emit files or set asset sources in the "outputOptions" hook, use the "renderStart" hook instead.`
514 };
515}
516function logChunkNotGeneratedForFileName(name) {
517 return {
518 code: CHUNK_NOT_GENERATED,
519 message: `Plugin error - Unable to get file name for emitted chunk "${name}". You can only get file names once chunks have been generated after the "renderStart" hook.`
520 };
521}
522function logChunkInvalid({ fileName, code }, { pos, message }) {
523 const errorProperties = {
524 code: CHUNK_INVALID,
525 message: `Chunk "${fileName}" is not valid JavaScript: ${message}.`
526 };
527 augmentCodeLocation(errorProperties, pos, code, fileName);
528 return errorProperties;
529}
530function logCircularDependency(cyclePath) {
531 return {
532 code: CIRCULAR_DEPENDENCY,
533 ids: cyclePath,
534 message: `Circular dependency: ${cyclePath.map(relativeId).join(' -> ')}`
535 };
536}
537function logCircularReexport(exportName, exporter) {
538 return {
539 code: CIRCULAR_REEXPORT,
540 exporter,
541 message: `"${exportName}" cannot be exported from "${relativeId(exporter)}" as it is a reexport that references itself.`
542 };
543}
544function logCyclicCrossChunkReexport(exportName, exporter, reexporter, importer, preserveModules) {
545 return {
546 code: CYCLIC_CROSS_CHUNK_REEXPORT,
547 exporter,
548 id: importer,
549 message: `Export "${exportName}" of module "${relativeId(exporter)}" was reexported through module "${relativeId(reexporter)}" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.\nEither change the import in "${relativeId(importer)}" to point directly to the exporting module or ${preserveModules ? 'do not use "output.preserveModules"' : 'reconfigure "output.manualChunks"'} to ensure these modules end up in the same chunk.`,
550 reexporter
551 };
552}
553function logDeprecation(deprecation, urlSnippet, plugin) {
554 return {
555 code: DEPRECATED_FEATURE,
556 message: deprecation,
557 url: getRollupUrl(urlSnippet),
558 ...({})
559 };
560}
561function logConstVariableReassignError() {
562 return {
563 code: CONST_REASSIGN,
564 message: 'Cannot reassign a variable declared with `const`'
565 };
566}
567function logDuplicateArgumentNameError(name) {
568 return {
569 code: DUPLICATE_ARGUMENT_NAME,
570 message: `Duplicate argument name "${name}"`
571 };
572}
573function logDuplicateExportError(name) {
574 return { code: DUPLICATE_EXPORT, message: `Duplicate export "${name}"` };
575}
576function logDuplicatePluginName(plugin) {
577 return {
578 code: DUPLICATE_PLUGIN_NAME,
579 message: `The plugin name ${plugin} is being used twice in the same build. Plugin names must be distinct or provide a cacheKey (please post an issue to the plugin if you are a plugin user).`
580 };
581}
582function logEmptyChunk(chunkName) {
583 return {
584 code: EMPTY_BUNDLE,
585 message: `Generated an empty chunk: "${chunkName}".`,
586 names: [chunkName]
587 };
588}
589function logEval(id) {
590 return {
591 code: EVAL,
592 id,
593 message: `Use of eval in "${relativeId(id)}" is strongly discouraged as it poses security risks and may cause issues with minification.`,
594 url: getRollupUrl(URL_AVOIDING_EVAL)
595 };
596}
597function logExternalSyntheticExports(id, importer) {
598 return {
599 code: EXTERNAL_SYNTHETIC_EXPORTS,
600 exporter: id,
601 message: `External "${id}" cannot have "syntheticNamedExports" enabled (imported by "${relativeId(importer)}").`
602 };
603}
604function logFileNameConflict(fileName) {
605 return {
606 code: FILE_NAME_CONFLICT,
607 message: `The emitted file "${fileName}" overwrites a previously emitted file of the same name.`
608 };
609}
610function logFileReferenceIdNotFoundForFilename(assetReferenceId) {
611 return {
612 code: FILE_NOT_FOUND,
613 message: `Plugin error - Unable to get file name for unknown file "${assetReferenceId}".`
614 };
615}
616function logFirstSideEffect(source, id, { line, column }) {
617 return {
618 code: FIRST_SIDE_EFFECT,
619 message: `First side effect in ${relativeId(id)} is at (${line}:${column})\n${getCodeFrame(source, line, column)}`
620 };
621}
622function logIllegalIdentifierAsName(name) {
623 return {
624 code: ILLEGAL_IDENTIFIER_AS_NAME,
625 message: `Given name "${name}" is not a legal JS identifier. If you need this, you can try "output.extend: true".`,
626 url: getRollupUrl(URL_OUTPUT_EXTEND)
627 };
628}
629function logIllegalImportReassignment(name, importingId) {
630 return {
631 code: ILLEGAL_REASSIGNMENT,
632 message: `Illegal reassignment of import "${name}" in "${relativeId(importingId)}".`
633 };
634}
635function logInconsistentImportAttributes(existingAttributes, newAttributes, source, importer) {
636 return {
637 code: INCONSISTENT_IMPORT_ATTRIBUTES,
638 message: `Module "${relativeId(importer)}" tried to import "${relativeId(source)}" with ${formatAttributes(newAttributes)} attributes, but it was already imported elsewhere with ${formatAttributes(existingAttributes)} attributes. Please ensure that import attributes for the same module are always consistent.`
639 };
640}
641const formatAttributes = (attributes) => {
642 const entries = Object.entries(attributes);
643 if (entries.length === 0)
644 return 'no';
645 return entries.map(([key, value]) => `"${key}": "${value}"`).join(', ');
646};
647function logInvalidAnnotation(comment, id, type) {
648 return {
649 code: INVALID_ANNOTATION,
650 id,
651 message: `A comment\n\n"${comment}"\n\nin "${relativeId(id)}" contains an annotation that Rollup cannot interpret due to the position of the comment. The comment will be removed to avoid issues.`,
652 url: getRollupUrl(type === 'noSideEffects' ? URL_TREESHAKE_NOSIDEEFFECTS : URL_TREESHAKE_PURE)
653 };
654}
655function logInputHookInOutputPlugin(pluginName, hookName) {
656 return {
657 code: INPUT_HOOK_IN_OUTPUT_PLUGIN,
658 message: `The "${hookName}" hook used by the output plugin ${pluginName} is a build time hook and will not be run for that plugin. Either this plugin cannot be used as an output plugin, or it should have an option to configure it as an output plugin.`
659 };
660}
661function logCannotAssignModuleToChunk(moduleId, assignToAlias, currentAlias) {
662 return {
663 code: INVALID_CHUNK,
664 message: `Cannot assign "${relativeId(moduleId)}" to the "${assignToAlias}" chunk as it is already in the "${currentAlias}" chunk.`
665 };
666}
667function tweakStackMessage(error, oldMessage) {
668 if (!error.stack) {
669 return error;
670 }
671 error.stack = error.stack.replace(oldMessage, error.message);
672 return error;
673}
674function logInvalidExportOptionValue(optionValue) {
675 return {
676 code: INVALID_EXPORT_OPTION,
677 message: `"output.exports" must be "default", "named", "none", "auto", or left unspecified (defaults to "auto"), received "${optionValue}".`,
678 url: getRollupUrl(URL_OUTPUT_EXPORTS)
679 };
680}
681function logIncompatibleExportOptionValue(optionValue, keys, entryModule) {
682 return {
683 code: INVALID_EXPORT_OPTION,
684 message: `"${optionValue}" was specified for "output.exports", but entry module "${relativeId(entryModule)}" has the following exports: ${printQuotedStringList(keys)}`,
685 url: getRollupUrl(URL_OUTPUT_EXPORTS)
686 };
687}
688function logInternalIdCannotBeExternal(source, importer) {
689 return {
690 code: INVALID_EXTERNAL_ID,
691 message: `"${source}" is imported as an external by "${relativeId(importer)}", but is already an existing non-external module id.`
692 };
693}
694function logImportOptionsAreInvalid(importer) {
695 return {
696 code: INVALID_IMPORT_ATTRIBUTE,
697 message: `Rollup could not statically analyze the options argument of a dynamic import in "${relativeId(importer)}". Dynamic import options need to be an object with a nested attributes object.`
698 };
699}
700function logImportAttributeIsInvalid(importer) {
701 return {
702 code: INVALID_IMPORT_ATTRIBUTE,
703 message: `Rollup could not statically analyze an import attribute of a dynamic import in "${relativeId(importer)}". Import attributes need to have string keys and values. The attribute will be removed.`
704 };
705}
706function logInvalidLogPosition(plugin) {
707 return {
708 code: INVALID_LOG_POSITION,
709 message: `Plugin "${plugin}" tried to add a file position to a log or warning. This is only supported in the "transform" hook at the moment and will be ignored.`
710 };
711}
712function logInvalidOption(option, urlSnippet, explanation, value) {
713 return {
714 code: INVALID_OPTION,
715 message: `Invalid value ${value === undefined ? '' : `${JSON.stringify(value)} `}for option "${option}" - ${explanation}.`,
716 url: getRollupUrl(urlSnippet)
717 };
718}
719function logInvalidAddonPluginHook(hook, plugin) {
720 return {
721 code: INVALID_PLUGIN_HOOK,
722 hook,
723 message: `Error running plugin hook "${hook}" for plugin "${plugin}", expected a string, a function hook or an object with a "handler" string or function.`,
724 plugin
725 };
726}
727function logInvalidFunctionPluginHook(hook, plugin) {
728 return {
729 code: INVALID_PLUGIN_HOOK,
730 hook,
731 message: `Error running plugin hook "${hook}" for plugin "${plugin}", expected a function hook or an object with a "handler" function.`,
732 plugin
733 };
734}
735function logInvalidRollupPhaseForChunkEmission() {
736 return {
737 code: INVALID_ROLLUP_PHASE,
738 message: `Cannot emit chunks after module loading has finished.`
739 };
740}
741function logInvalidSetAssetSourceCall() {
742 return {
743 code: INVALID_SETASSETSOURCE,
744 message: `setAssetSource cannot be called in transform for caching reasons. Use emitFile with a source, or call setAssetSource in another hook.`
745 };
746}
747function logInvalidFormatForTopLevelAwait(id, format) {
748 return {
749 code: INVALID_TLA_FORMAT,
750 id,
751 message: `Module format "${format}" does not support top-level await. Use the "es" or "system" output formats rather.`
752 };
753}
754function logMissingEntryExport(binding, exporter) {
755 return {
756 binding,
757 code: MISSING_EXPORT,
758 exporter,
759 message: `Exported variable "${binding}" is not defined in "${relativeId(exporter)}".`,
760 url: getRollupUrl(URL_NAME_IS_NOT_EXPORTED)
761 };
762}
763function logMissingExport(binding, importingModule, exporter) {
764 const isJson = extname(exporter) === '.json';
765 return {
766 binding,
767 code: MISSING_EXPORT,
768 exporter,
769 id: importingModule,
770 message: `"${binding}" is not exported by "${relativeId(exporter)}", imported by "${relativeId(importingModule)}".${isJson ? ' (Note that you need @rollup/plugin-json to import JSON files)' : ''}`,
771 url: getRollupUrl(URL_NAME_IS_NOT_EXPORTED)
772 };
773}
774function logMissingGlobalName(externalId, guess) {
775 return {
776 code: MISSING_GLOBAL_NAME,
777 id: externalId,
778 message: `No name was provided for external module "${externalId}" in "output.globals" – guessing "${guess}".`,
779 names: [guess],
780 url: getRollupUrl(URL_OUTPUT_GLOBALS)
781 };
782}
783function logImplicitDependantCannotBeExternal(unresolvedId, implicitlyLoadedBefore) {
784 return {
785 code: MISSING_IMPLICIT_DEPENDANT,
786 message: `Module "${relativeId(unresolvedId)}" that should be implicitly loaded before "${relativeId(implicitlyLoadedBefore)}" cannot be external.`
787 };
788}
789function logUnresolvedImplicitDependant(unresolvedId, implicitlyLoadedBefore) {
790 return {
791 code: MISSING_IMPLICIT_DEPENDANT,
792 message: `Module "${relativeId(unresolvedId)}" that should be implicitly loaded before "${relativeId(implicitlyLoadedBefore)}" could not be resolved.`
793 };
794}
795function logImplicitDependantIsNotIncluded(module) {
796 const implicitDependencies = [...module.implicitlyLoadedBefore]
797 .map(dependency => relativeId(dependency.id))
798 .sort();
799 return {
800 code: MISSING_IMPLICIT_DEPENDANT,
801 message: `Module "${relativeId(module.id)}" that should be implicitly loaded before ${printQuotedStringList(implicitDependencies)} is not included in the module graph. Either it was not imported by an included module or only via a tree-shaken dynamic import, or no imported bindings were used and it had otherwise no side-effects.`
802 };
803}
804function logMissingJsxExport(name, exporter, importer) {
805 return {
806 code: MISSING_JSX_EXPORT,
807 exporter,
808 id: importer,
809 message: `Export "${name}" is not defined in module "${relativeId(exporter)}" even though it is needed in "${relativeId(importer)}" to provide JSX syntax. Please check your "jsx" option.`,
810 names: [name],
811 url: getRollupUrl(URL_JSX)
812 };
813}
814function logMissingNameOptionForIifeExport() {
815 return {
816 code: MISSING_NAME_OPTION_FOR_IIFE_EXPORT,
817 message: `If you do not supply "output.name", you may not be able to access the exports of an IIFE bundle.`,
818 url: getRollupUrl(URL_OUTPUT_NAME)
819 };
820}
821function logMissingNameOptionForUmdExport() {
822 return {
823 code: MISSING_NAME_OPTION_FOR_IIFE_EXPORT,
824 message: 'You must supply "output.name" for UMD bundles that have exports so that the exports are accessible in environments without a module loader.',
825 url: getRollupUrl(URL_OUTPUT_NAME)
826 };
827}
828function logMissingNodeBuiltins(externalBuiltins) {
829 return {
830 code: MISSING_NODE_BUILTINS,
831 ids: externalBuiltins,
832 message: `Creating a browser bundle that depends on Node.js built-in modules (${printQuotedStringList(externalBuiltins)}). You might need to include https://github.com/FredKSchott/rollup-plugin-polyfill-node`
833 };
834}
835function logMissingFileOrDirOption() {
836 return {
837 code: MISSING_OPTION,
838 message: 'You must specify "output.file" or "output.dir" for the build.',
839 url: getRollupUrl(URL_OUTPUT_DIR)
840 };
841}
842function logMixedExport(facadeModuleId, name) {
843 return {
844 code: MIXED_EXPORTS,
845 id: facadeModuleId,
846 message: `Entry module "${relativeId(facadeModuleId)}" is using named and default exports together. Consumers of your bundle will have to use \`${name || 'chunk'}.default\` to access the default export, which may not be what you want. Use \`output.exports: "named"\` to disable this warning.`,
847 url: getRollupUrl(URL_OUTPUT_EXPORTS)
848 };
849}
850function logModuleLevelDirective(directive, id) {
851 return {
852 code: MODULE_LEVEL_DIRECTIVE,
853 id,
854 message: `Module level directives cause errors when bundled, "${directive}" in "${relativeId(id)}" was ignored.`
855 };
856}
857function logNamespaceConflict(binding, reexportingModuleId, sources) {
858 return {
859 binding,
860 code: NAMESPACE_CONFLICT,
861 ids: sources,
862 message: `Conflicting namespaces: "${relativeId(reexportingModuleId)}" re-exports "${binding}" from one of the modules ${printQuotedStringList(sources.map(moduleId => relativeId(moduleId)))} (will be ignored).`,
863 reexporter: reexportingModuleId
864 };
865}
866function logNoTransformMapOrAstWithoutCode(pluginName) {
867 return {
868 code: NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE,
869 message: `The plugin "${pluginName}" returned a "map" or "ast" without returning ` +
870 'a "code". This will be ignored.'
871 };
872}
873function logOptimizeChunkStatus(chunks, smallChunks, pointInTime) {
874 return {
875 code: OPTIMIZE_CHUNK_STATUS,
876 message: `${pointInTime}, there are\n` +
877 `${chunks} chunks, of which\n` +
878 `${smallChunks} are below minChunkSize.`
879 };
880}
881function logParseError(message, pos) {
882 return { code: PARSE_ERROR, message, pos };
883}
884function logRedeclarationError(name) {
885 return {
886 code: REDECLARATION_ERROR,
887 message: `Identifier "${name}" has already been declared`
888 };
889}
890function logReservedNamespace(namespace) {
891 return {
892 code: RESERVED_NAMESPACE,
893 message: `You have overided reserved namespace "${namespace}"`
894 };
895}
896function logModuleParseError(error, moduleId) {
897 let message = error.message.replace(/ \(\d+:\d+\)$/, '');
898 if (moduleId.endsWith('.json')) {
899 message += ' (Note that you need @rollup/plugin-json to import JSON files)';
900 }
901 else if (!moduleId.endsWith('.js')) {
902 message += ' (Note that you need plugins to import files that are not JavaScript)';
903 }
904 return tweakStackMessage({
905 cause: error,
906 code: PARSE_ERROR,
907 id: moduleId,
908 message,
909 stack: error.stack
910 }, error.message);
911}
912function logPluginError(error, plugin, { hook, id } = {}) {
913 const code = error.code;
914 if (!error.pluginCode &&
915 code != null &&
916 (typeof code !== 'string' || !code.startsWith('PLUGIN_'))) {
917 error.pluginCode = code;
918 }
919 error.code = PLUGIN_ERROR;
920 error.plugin = plugin;
921 if (hook) {
922 error.hook = hook;
923 }
924 if (id) {
925 error.id = id;
926 }
927 return error;
928}
929function logShimmedExport(id, binding) {
930 return {
931 binding,
932 code: SHIMMED_EXPORT,
933 exporter: id,
934 message: `Missing export "${binding}" has been shimmed in module "${relativeId(id)}".`
935 };
936}
937function logSourcemapBroken(plugin) {
938 return {
939 code: SOURCEMAP_BROKEN,
940 message: `Sourcemap is likely to be incorrect: a plugin (${plugin}) was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help`,
941 plugin,
942 url: getRollupUrl(URL_SOURCEMAP_IS_LIKELY_TO_BE_INCORRECT)
943 };
944}
945function logConflictingSourcemapSources(filename) {
946 return {
947 code: SOURCEMAP_BROKEN,
948 message: `Multiple conflicting contents for sourcemap source ${filename}`
949 };
950}
951function logInvalidSourcemapForError(error, id, column, line, pos) {
952 return {
953 cause: error,
954 code: SOURCEMAP_ERROR,
955 id,
956 loc: {
957 column,
958 file: id,
959 line
960 },
961 message: `Error when using sourcemap for reporting an error: ${error.message}`,
962 pos
963 };
964}
965function logSyntheticNamedExportsNeedNamespaceExport(id, syntheticNamedExportsOption) {
966 return {
967 code: SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT,
968 exporter: id,
969 message: `Module "${relativeId(id)}" that is marked with \`syntheticNamedExports: ${JSON.stringify(syntheticNamedExportsOption)}\` needs ${typeof syntheticNamedExportsOption === 'string' && syntheticNamedExportsOption !== 'default'
970 ? `an explicit export named "${syntheticNamedExportsOption}"`
971 : 'a default export'} that does not reexport an unresolved named export of the same module.`
972 };
973}
974function logThisIsUndefined() {
975 return {
976 code: THIS_IS_UNDEFINED,
977 message: `The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten`,
978 url: getRollupUrl(URL_THIS_IS_UNDEFINED)
979 };
980}
981function logUnexpectedNamedImport(id, imported, isReexport) {
982 const importType = isReexport ? 'reexport' : 'import';
983 return {
984 code: UNEXPECTED_NAMED_IMPORT,
985 exporter: id,
986 message: `The named export "${imported}" was ${importType}ed from the external module "${relativeId(id)}" even though its interop type is "defaultOnly". Either remove or change this ${importType} or change the value of the "output.interop" option.`,
987 url: getRollupUrl(URL_OUTPUT_INTEROP)
988 };
989}
990function logUnexpectedNamespaceReexport(id) {
991 return {
992 code: UNEXPECTED_NAMED_IMPORT,
993 exporter: id,
994 message: `There was a namespace "*" reexport from the external module "${relativeId(id)}" even though its interop type is "defaultOnly". This will be ignored as namespace reexports only reexport named exports. If this is not intended, either remove or change this reexport or change the value of the "output.interop" option.`,
995 url: getRollupUrl(URL_OUTPUT_INTEROP)
996 };
997}
998function logUnknownOption(optionType, unknownOptions, validOptions) {
999 return {
1000 code: UNKNOWN_OPTION,
1001 message: `Unknown ${optionType}: ${unknownOptions.join(', ')}. Allowed options: ${validOptions.join(', ')}`
1002 };
1003}
1004function logEntryCannotBeExternal(unresolvedId) {
1005 return {
1006 code: UNRESOLVED_ENTRY,
1007 message: `Entry module "${relativeId(unresolvedId)}" cannot be external.`
1008 };
1009}
1010function logExternalModulesCannotBeIncludedInManualChunks(source) {
1011 return {
1012 code: EXTERNAL_MODULES_CANNOT_BE_INCLUDED_IN_MANUAL_CHUNKS,
1013 message: `"${source}" cannot be included in manualChunks because it is resolved as an external module by the "external" option or plugins.`
1014 };
1015}
1016function logExternalModulesCannotBeTransformedToModules(source) {
1017 return {
1018 code: EXTERNAL_MODULES_CANNOT_BE_TRANSFORMED_TO_MODULES,
1019 message: `${source} is resolved as a module now, but it was an external module before. Please check whether there are conflicts in your Rollup options "external" and "manualChunks", manualChunks cannot include external modules.`
1020 };
1021}
1022function logUnresolvedEntry(unresolvedId) {
1023 return {
1024 code: UNRESOLVED_ENTRY,
1025 message: `Could not resolve entry module "${relativeId(unresolvedId)}".`
1026 };
1027}
1028function logUnresolvedImport(source, importer) {
1029 return {
1030 code: UNRESOLVED_IMPORT,
1031 exporter: source,
1032 id: importer,
1033 message: `Could not resolve "${source}" from "${relativeId(importer)}"`
1034 };
1035}
1036function logUnresolvedImportTreatedAsExternal(source, importer) {
1037 return {
1038 code: UNRESOLVED_IMPORT,
1039 exporter: source,
1040 id: importer,
1041 message: `"${source}" is imported by "${relativeId(importer)}", but could not be resolved – treating it as an external dependency.`,
1042 url: getRollupUrl(URL_TREATING_MODULE_AS_EXTERNAL_DEPENDENCY)
1043 };
1044}
1045function logUnusedExternalImports(externalId, names, importers) {
1046 return {
1047 code: UNUSED_EXTERNAL_IMPORT,
1048 exporter: externalId,
1049 ids: importers,
1050 message: `${printQuotedStringList(names, [
1051 'is',
1052 'are'
1053 ])} imported from external module "${externalId}" but never used in ${printQuotedStringList(importers.map(importer => relativeId(importer)))}.`,
1054 names
1055 };
1056}
1057function logFailedValidation(message) {
1058 return {
1059 code: VALIDATION_ERROR,
1060 message
1061 };
1062}
1063function warnDeprecation(deprecation, urlSnippet, activeDeprecation, options, plugin) {
1064 warnDeprecationWithOptions(deprecation, urlSnippet, activeDeprecation, options.onLog, options.strictDeprecations);
1065}
1066function warnDeprecationWithOptions(deprecation, urlSnippet, activeDeprecation, log, strictDeprecations, plugin) {
1067 if (activeDeprecation || strictDeprecations) {
1068 const warning = logDeprecation(deprecation, urlSnippet);
1069 if (strictDeprecations) {
1070 return error(warning);
1071 }
1072 log(LOGLEVEL_WARN, warning);
1073 }
1074}
1075
1076// This file is generated by scripts/generate-buffer-to-ast.js.
1077// Do not edit this file directly.
1078function convertProgram(buffer) {
1079 const node = convertNode(0, buffer);
1080 switch (node.type) {
1081 case PanicError: {
1082 return error(getRollupError(logParseError(node.message)));
1083 }
1084 case ParseError: {
1085 return error(getRollupError(logParseError(node.message, node.start)));
1086 }
1087 default: {
1088 return node;
1089 }
1090 }
1091}
1092/* eslint-disable sort-keys */
1093const nodeConverters = [
1094 function panicError(position, buffer) {
1095 return {
1096 type: 'PanicError',
1097 start: buffer[position],
1098 end: buffer[position + 1],
1099 message: buffer.convertString(buffer[position + 2])
1100 };
1101 },
1102 function parseError(position, buffer) {
1103 return {
1104 type: 'ParseError',
1105 start: buffer[position],
1106 end: buffer[position + 1],
1107 message: buffer.convertString(buffer[position + 2])
1108 };
1109 },
1110 function arrayExpression(position, buffer) {
1111 return {
1112 type: 'ArrayExpression',
1113 start: buffer[position],
1114 end: buffer[position + 1],
1115 elements: convertNodeList(buffer[position + 2], buffer)
1116 };
1117 },
1118 function arrayPattern(position, buffer) {
1119 return {
1120 type: 'ArrayPattern',
1121 start: buffer[position],
1122 end: buffer[position + 1],
1123 elements: convertNodeList(buffer[position + 2], buffer)
1124 };
1125 },
1126 function arrowFunctionExpression(position, buffer) {
1127 const flags = buffer[position + 2];
1128 const annotations = convertAnnotations(buffer[position + 3], buffer);
1129 return {
1130 type: 'ArrowFunctionExpression',
1131 start: buffer[position],
1132 end: buffer[position + 1],
1133 async: (flags & 1) === 1,
1134 expression: (flags & 2) === 2,
1135 generator: (flags & 4) === 4,
1136 ...(annotations.length > 0 ? { [ANNOTATION_KEY]: annotations } : {}),
1137 params: convertNodeList(buffer[position + 4], buffer),
1138 body: convertNode(buffer[position + 5], buffer),
1139 id: null
1140 };
1141 },
1142 function assignmentExpression(position, buffer) {
1143 return {
1144 type: 'AssignmentExpression',
1145 start: buffer[position],
1146 end: buffer[position + 1],
1147 operator: FIXED_STRINGS[buffer[position + 2]],
1148 left: convertNode(buffer[position + 3], buffer),
1149 right: convertNode(buffer[position + 4], buffer)
1150 };
1151 },
1152 function assignmentPattern(position, buffer) {
1153 return {
1154 type: 'AssignmentPattern',
1155 start: buffer[position],
1156 end: buffer[position + 1],
1157 left: convertNode(buffer[position + 2], buffer),
1158 right: convertNode(buffer[position + 3], buffer)
1159 };
1160 },
1161 function awaitExpression(position, buffer) {
1162 return {
1163 type: 'AwaitExpression',
1164 start: buffer[position],
1165 end: buffer[position + 1],
1166 argument: convertNode(buffer[position + 2], buffer)
1167 };
1168 },
1169 function binaryExpression(position, buffer) {
1170 return {
1171 type: 'BinaryExpression',
1172 start: buffer[position],
1173 end: buffer[position + 1],
1174 operator: FIXED_STRINGS[buffer[position + 2]],
1175 left: convertNode(buffer[position + 3], buffer),
1176 right: convertNode(buffer[position + 4], buffer)
1177 };
1178 },
1179 function blockStatement(position, buffer) {
1180 return {
1181 type: 'BlockStatement',
1182 start: buffer[position],
1183 end: buffer[position + 1],
1184 body: convertNodeList(buffer[position + 2], buffer)
1185 };
1186 },
1187 function breakStatement(position, buffer) {
1188 const labelPosition = buffer[position + 2];
1189 return {
1190 type: 'BreakStatement',
1191 start: buffer[position],
1192 end: buffer[position + 1],
1193 label: labelPosition === 0 ? null : convertNode(labelPosition, buffer)
1194 };
1195 },
1196 function callExpression(position, buffer) {
1197 const flags = buffer[position + 2];
1198 const annotations = convertAnnotations(buffer[position + 3], buffer);
1199 return {
1200 type: 'CallExpression',
1201 start: buffer[position],
1202 end: buffer[position + 1],
1203 optional: (flags & 1) === 1,
1204 ...(annotations.length > 0 ? { [ANNOTATION_KEY]: annotations } : {}),
1205 callee: convertNode(buffer[position + 4], buffer),
1206 arguments: convertNodeList(buffer[position + 5], buffer)
1207 };
1208 },
1209 function catchClause(position, buffer) {
1210 const parameterPosition = buffer[position + 2];
1211 return {
1212 type: 'CatchClause',
1213 start: buffer[position],
1214 end: buffer[position + 1],
1215 param: parameterPosition === 0 ? null : convertNode(parameterPosition, buffer),
1216 body: convertNode(buffer[position + 3], buffer)
1217 };
1218 },
1219 function chainExpression(position, buffer) {
1220 return {
1221 type: 'ChainExpression',
1222 start: buffer[position],
1223 end: buffer[position + 1],
1224 expression: convertNode(buffer[position + 2], buffer)
1225 };
1226 },
1227 function classBody(position, buffer) {
1228 return {
1229 type: 'ClassBody',
1230 start: buffer[position],
1231 end: buffer[position + 1],
1232 body: convertNodeList(buffer[position + 2], buffer)
1233 };
1234 },
1235 function classDeclaration(position, buffer) {
1236 const idPosition = buffer[position + 3];
1237 const superClassPosition = buffer[position + 4];
1238 return {
1239 type: 'ClassDeclaration',
1240 start: buffer[position],
1241 end: buffer[position + 1],
1242 decorators: convertNodeList(buffer[position + 2], buffer),
1243 id: idPosition === 0 ? null : convertNode(idPosition, buffer),
1244 superClass: superClassPosition === 0 ? null : convertNode(superClassPosition, buffer),
1245 body: convertNode(buffer[position + 5], buffer)
1246 };
1247 },
1248 function classExpression(position, buffer) {
1249 const idPosition = buffer[position + 3];
1250 const superClassPosition = buffer[position + 4];
1251 return {
1252 type: 'ClassExpression',
1253 start: buffer[position],
1254 end: buffer[position + 1],
1255 decorators: convertNodeList(buffer[position + 2], buffer),
1256 id: idPosition === 0 ? null : convertNode(idPosition, buffer),
1257 superClass: superClassPosition === 0 ? null : convertNode(superClassPosition, buffer),
1258 body: convertNode(buffer[position + 5], buffer)
1259 };
1260 },
1261 function conditionalExpression(position, buffer) {
1262 return {
1263 type: 'ConditionalExpression',
1264 start: buffer[position],
1265 end: buffer[position + 1],
1266 test: convertNode(buffer[position + 2], buffer),
1267 consequent: convertNode(buffer[position + 3], buffer),
1268 alternate: convertNode(buffer[position + 4], buffer)
1269 };
1270 },
1271 function continueStatement(position, buffer) {
1272 const labelPosition = buffer[position + 2];
1273 return {
1274 type: 'ContinueStatement',
1275 start: buffer[position],
1276 end: buffer[position + 1],
1277 label: labelPosition === 0 ? null : convertNode(labelPosition, buffer)
1278 };
1279 },
1280 function debuggerStatement(position, buffer) {
1281 return {
1282 type: 'DebuggerStatement',
1283 start: buffer[position],
1284 end: buffer[position + 1]
1285 };
1286 },
1287 function decorator(position, buffer) {
1288 return {
1289 type: 'Decorator',
1290 start: buffer[position],
1291 end: buffer[position + 1],
1292 expression: convertNode(buffer[position + 2], buffer)
1293 };
1294 },
1295 function directive(position, buffer) {
1296 return {
1297 type: 'ExpressionStatement',
1298 start: buffer[position],
1299 end: buffer[position + 1],
1300 directive: buffer.convertString(buffer[position + 2]),
1301 expression: convertNode(buffer[position + 3], buffer)
1302 };
1303 },
1304 function doWhileStatement(position, buffer) {
1305 return {
1306 type: 'DoWhileStatement',
1307 start: buffer[position],
1308 end: buffer[position + 1],
1309 body: convertNode(buffer[position + 2], buffer),
1310 test: convertNode(buffer[position + 3], buffer)
1311 };
1312 },
1313 function emptyStatement(position, buffer) {
1314 return {
1315 type: 'EmptyStatement',
1316 start: buffer[position],
1317 end: buffer[position + 1]
1318 };
1319 },
1320 function exportAllDeclaration(position, buffer) {
1321 const exportedPosition = buffer[position + 2];
1322 return {
1323 type: 'ExportAllDeclaration',
1324 start: buffer[position],
1325 end: buffer[position + 1],
1326 exported: exportedPosition === 0 ? null : convertNode(exportedPosition, buffer),
1327 source: convertNode(buffer[position + 3], buffer),
1328 attributes: convertNodeList(buffer[position + 4], buffer)
1329 };
1330 },
1331 function exportDefaultDeclaration(position, buffer) {
1332 return {
1333 type: 'ExportDefaultDeclaration',
1334 start: buffer[position],
1335 end: buffer[position + 1],
1336 declaration: convertNode(buffer[position + 2], buffer)
1337 };
1338 },
1339 function exportNamedDeclaration(position, buffer) {
1340 const sourcePosition = buffer[position + 3];
1341 const declarationPosition = buffer[position + 5];
1342 return {
1343 type: 'ExportNamedDeclaration',
1344 start: buffer[position],
1345 end: buffer[position + 1],
1346 specifiers: convertNodeList(buffer[position + 2], buffer),
1347 source: sourcePosition === 0 ? null : convertNode(sourcePosition, buffer),
1348 attributes: convertNodeList(buffer[position + 4], buffer),
1349 declaration: declarationPosition === 0 ? null : convertNode(declarationPosition, buffer)
1350 };
1351 },
1352 function exportSpecifier(position, buffer) {
1353 const local = convertNode(buffer[position + 2], buffer);
1354 const exportedPosition = buffer[position + 3];
1355 return {
1356 type: 'ExportSpecifier',
1357 start: buffer[position],
1358 end: buffer[position + 1],
1359 local,
1360 exported: exportedPosition === 0 ? { ...local } : convertNode(exportedPosition, buffer)
1361 };
1362 },
1363 function expressionStatement(position, buffer) {
1364 return {
1365 type: 'ExpressionStatement',
1366 start: buffer[position],
1367 end: buffer[position + 1],
1368 expression: convertNode(buffer[position + 2], buffer)
1369 };
1370 },
1371 function forInStatement(position, buffer) {
1372 return {
1373 type: 'ForInStatement',
1374 start: buffer[position],
1375 end: buffer[position + 1],
1376 left: convertNode(buffer[position + 2], buffer),
1377 right: convertNode(buffer[position + 3], buffer),
1378 body: convertNode(buffer[position + 4], buffer)
1379 };
1380 },
1381 function forOfStatement(position, buffer) {
1382 const flags = buffer[position + 2];
1383 return {
1384 type: 'ForOfStatement',
1385 start: buffer[position],
1386 end: buffer[position + 1],
1387 await: (flags & 1) === 1,
1388 left: convertNode(buffer[position + 3], buffer),
1389 right: convertNode(buffer[position + 4], buffer),
1390 body: convertNode(buffer[position + 5], buffer)
1391 };
1392 },
1393 function forStatement(position, buffer) {
1394 const initPosition = buffer[position + 2];
1395 const testPosition = buffer[position + 3];
1396 const updatePosition = buffer[position + 4];
1397 return {
1398 type: 'ForStatement',
1399 start: buffer[position],
1400 end: buffer[position + 1],
1401 init: initPosition === 0 ? null : convertNode(initPosition, buffer),
1402 test: testPosition === 0 ? null : convertNode(testPosition, buffer),
1403 update: updatePosition === 0 ? null : convertNode(updatePosition, buffer),
1404 body: convertNode(buffer[position + 5], buffer)
1405 };
1406 },
1407 function functionDeclaration(position, buffer) {
1408 const flags = buffer[position + 2];
1409 const annotations = convertAnnotations(buffer[position + 3], buffer);
1410 const idPosition = buffer[position + 4];
1411 return {
1412 type: 'FunctionDeclaration',
1413 start: buffer[position],
1414 end: buffer[position + 1],
1415 async: (flags & 1) === 1,
1416 generator: (flags & 2) === 2,
1417 ...(annotations.length > 0 ? { [ANNOTATION_KEY]: annotations } : {}),
1418 id: idPosition === 0 ? null : convertNode(idPosition, buffer),
1419 params: convertNodeList(buffer[position + 5], buffer),
1420 body: convertNode(buffer[position + 6], buffer),
1421 expression: false
1422 };
1423 },
1424 function functionExpression(position, buffer) {
1425 const flags = buffer[position + 2];
1426 const annotations = convertAnnotations(buffer[position + 3], buffer);
1427 const idPosition = buffer[position + 4];
1428 return {
1429 type: 'FunctionExpression',
1430 start: buffer[position],
1431 end: buffer[position + 1],
1432 async: (flags & 1) === 1,
1433 generator: (flags & 2) === 2,
1434 ...(annotations.length > 0 ? { [ANNOTATION_KEY]: annotations } : {}),
1435 id: idPosition === 0 ? null : convertNode(idPosition, buffer),
1436 params: convertNodeList(buffer[position + 5], buffer),
1437 body: convertNode(buffer[position + 6], buffer),
1438 expression: false
1439 };
1440 },
1441 function identifier(position, buffer) {
1442 return {
1443 type: 'Identifier',
1444 start: buffer[position],
1445 end: buffer[position + 1],
1446 name: buffer.convertString(buffer[position + 2])
1447 };
1448 },
1449 function ifStatement(position, buffer) {
1450 const alternatePosition = buffer[position + 4];
1451 return {
1452 type: 'IfStatement',
1453 start: buffer[position],
1454 end: buffer[position + 1],
1455 test: convertNode(buffer[position + 2], buffer),
1456 consequent: convertNode(buffer[position + 3], buffer),
1457 alternate: alternatePosition === 0 ? null : convertNode(alternatePosition, buffer)
1458 };
1459 },
1460 function importAttribute(position, buffer) {
1461 return {
1462 type: 'ImportAttribute',
1463 start: buffer[position],
1464 end: buffer[position + 1],
1465 key: convertNode(buffer[position + 2], buffer),
1466 value: convertNode(buffer[position + 3], buffer)
1467 };
1468 },
1469 function importDeclaration(position, buffer) {
1470 return {
1471 type: 'ImportDeclaration',
1472 start: buffer[position],
1473 end: buffer[position + 1],
1474 specifiers: convertNodeList(buffer[position + 2], buffer),
1475 source: convertNode(buffer[position + 3], buffer),
1476 attributes: convertNodeList(buffer[position + 4], buffer)
1477 };
1478 },
1479 function importDefaultSpecifier(position, buffer) {
1480 return {
1481 type: 'ImportDefaultSpecifier',
1482 start: buffer[position],
1483 end: buffer[position + 1],
1484 local: convertNode(buffer[position + 2], buffer)
1485 };
1486 },
1487 function importExpression(position, buffer) {
1488 const optionsPosition = buffer[position + 3];
1489 return {
1490 type: 'ImportExpression',
1491 start: buffer[position],
1492 end: buffer[position + 1],
1493 source: convertNode(buffer[position + 2], buffer),
1494 options: optionsPosition === 0 ? null : convertNode(optionsPosition, buffer)
1495 };
1496 },
1497 function importNamespaceSpecifier(position, buffer) {
1498 return {
1499 type: 'ImportNamespaceSpecifier',
1500 start: buffer[position],
1501 end: buffer[position + 1],
1502 local: convertNode(buffer[position + 2], buffer)
1503 };
1504 },
1505 function importSpecifier(position, buffer) {
1506 const importedPosition = buffer[position + 2];
1507 const local = convertNode(buffer[position + 3], buffer);
1508 return {
1509 type: 'ImportSpecifier',
1510 start: buffer[position],
1511 end: buffer[position + 1],
1512 imported: importedPosition === 0 ? { ...local } : convertNode(importedPosition, buffer),
1513 local
1514 };
1515 },
1516 function jsxAttribute(position, buffer) {
1517 const valuePosition = buffer[position + 3];
1518 return {
1519 type: 'JSXAttribute',
1520 start: buffer[position],
1521 end: buffer[position + 1],
1522 name: convertNode(buffer[position + 2], buffer),
1523 value: valuePosition === 0 ? null : convertNode(valuePosition, buffer)
1524 };
1525 },
1526 function jsxClosingElement(position, buffer) {
1527 return {
1528 type: 'JSXClosingElement',
1529 start: buffer[position],
1530 end: buffer[position + 1],
1531 name: convertNode(buffer[position + 2], buffer)
1532 };
1533 },
1534 function jsxClosingFragment(position, buffer) {
1535 return {
1536 type: 'JSXClosingFragment',
1537 start: buffer[position],
1538 end: buffer[position + 1]
1539 };
1540 },
1541 function jsxElement(position, buffer) {
1542 const closingElementPosition = buffer[position + 4];
1543 return {
1544 type: 'JSXElement',
1545 start: buffer[position],
1546 end: buffer[position + 1],
1547 openingElement: convertNode(buffer[position + 2], buffer),
1548 children: convertNodeList(buffer[position + 3], buffer),
1549 closingElement: closingElementPosition === 0 ? null : convertNode(closingElementPosition, buffer)
1550 };
1551 },
1552 function jsxEmptyExpression(position, buffer) {
1553 return {
1554 type: 'JSXEmptyExpression',
1555 start: buffer[position],
1556 end: buffer[position + 1]
1557 };
1558 },
1559 function jsxExpressionContainer(position, buffer) {
1560 return {
1561 type: 'JSXExpressionContainer',
1562 start: buffer[position],
1563 end: buffer[position + 1],
1564 expression: convertNode(buffer[position + 2], buffer)
1565 };
1566 },
1567 function jsxFragment(position, buffer) {
1568 return {
1569 type: 'JSXFragment',
1570 start: buffer[position],
1571 end: buffer[position + 1],
1572 openingFragment: convertNode(buffer[position + 2], buffer),
1573 children: convertNodeList(buffer[position + 3], buffer),
1574 closingFragment: convertNode(buffer[position + 4], buffer)
1575 };
1576 },
1577 function jsxIdentifier(position, buffer) {
1578 return {
1579 type: 'JSXIdentifier',
1580 start: buffer[position],
1581 end: buffer[position + 1],
1582 name: buffer.convertString(buffer[position + 2])
1583 };
1584 },
1585 function jsxMemberExpression(position, buffer) {
1586 return {
1587 type: 'JSXMemberExpression',
1588 start: buffer[position],
1589 end: buffer[position + 1],
1590 object: convertNode(buffer[position + 2], buffer),
1591 property: convertNode(buffer[position + 3], buffer)
1592 };
1593 },
1594 function jsxNamespacedName(position, buffer) {
1595 return {
1596 type: 'JSXNamespacedName',
1597 start: buffer[position],
1598 end: buffer[position + 1],
1599 namespace: convertNode(buffer[position + 2], buffer),
1600 name: convertNode(buffer[position + 3], buffer)
1601 };
1602 },
1603 function jsxOpeningElement(position, buffer) {
1604 const flags = buffer[position + 2];
1605 return {
1606 type: 'JSXOpeningElement',
1607 start: buffer[position],
1608 end: buffer[position + 1],
1609 selfClosing: (flags & 1) === 1,
1610 name: convertNode(buffer[position + 3], buffer),
1611 attributes: convertNodeList(buffer[position + 4], buffer)
1612 };
1613 },
1614 function jsxOpeningFragment(position, buffer) {
1615 return {
1616 type: 'JSXOpeningFragment',
1617 start: buffer[position],
1618 end: buffer[position + 1],
1619 attributes: [],
1620 selfClosing: false
1621 };
1622 },
1623 function jsxSpreadAttribute(position, buffer) {
1624 return {
1625 type: 'JSXSpreadAttribute',
1626 start: buffer[position],
1627 end: buffer[position + 1],
1628 argument: convertNode(buffer[position + 2], buffer)
1629 };
1630 },
1631 function jsxSpreadChild(position, buffer) {
1632 return {
1633 type: 'JSXSpreadChild',
1634 start: buffer[position],
1635 end: buffer[position + 1],
1636 expression: convertNode(buffer[position + 2], buffer)
1637 };
1638 },
1639 function jsxText(position, buffer) {
1640 return {
1641 type: 'JSXText',
1642 start: buffer[position],
1643 end: buffer[position + 1],
1644 value: buffer.convertString(buffer[position + 2]),
1645 raw: buffer.convertString(buffer[position + 3])
1646 };
1647 },
1648 function labeledStatement(position, buffer) {
1649 return {
1650 type: 'LabeledStatement',
1651 start: buffer[position],
1652 end: buffer[position + 1],
1653 label: convertNode(buffer[position + 2], buffer),
1654 body: convertNode(buffer[position + 3], buffer)
1655 };
1656 },
1657 function literalBigInt(position, buffer) {
1658 const bigint = buffer.convertString(buffer[position + 2]);
1659 return {
1660 type: 'Literal',
1661 start: buffer[position],
1662 end: buffer[position + 1],
1663 bigint,
1664 raw: buffer.convertString(buffer[position + 3]),
1665 value: BigInt(bigint)
1666 };
1667 },
1668 function literalBoolean(position, buffer) {
1669 const flags = buffer[position + 2];
1670 const value = (flags & 1) === 1;
1671 return {
1672 type: 'Literal',
1673 start: buffer[position],
1674 end: buffer[position + 1],
1675 value,
1676 raw: value ? 'true' : 'false'
1677 };
1678 },
1679 function literalNull(position, buffer) {
1680 return {
1681 type: 'Literal',
1682 start: buffer[position],
1683 end: buffer[position + 1],
1684 raw: 'null',
1685 value: null
1686 };
1687 },
1688 function literalNumber(position, buffer) {
1689 const rawPosition = buffer[position + 2];
1690 return {
1691 type: 'Literal',
1692 start: buffer[position],
1693 end: buffer[position + 1],
1694 raw: rawPosition === 0 ? undefined : buffer.convertString(rawPosition),
1695 value: new DataView(buffer.buffer).getFloat64((position + 3) << 2, true)
1696 };
1697 },
1698 function literalRegExp(position, buffer) {
1699 const flags = buffer.convertString(buffer[position + 2]);
1700 const pattern = buffer.convertString(buffer[position + 3]);
1701 return {
1702 type: 'Literal',
1703 start: buffer[position],
1704 end: buffer[position + 1],
1705 raw: `/${pattern}/${flags}`,
1706 regex: { flags, pattern },
1707 value: new RegExp(pattern, flags)
1708 };
1709 },
1710 function literalString(position, buffer) {
1711 const rawPosition = buffer[position + 3];
1712 return {
1713 type: 'Literal',
1714 start: buffer[position],
1715 end: buffer[position + 1],
1716 value: buffer.convertString(buffer[position + 2]),
1717 raw: rawPosition === 0 ? undefined : buffer.convertString(rawPosition)
1718 };
1719 },
1720 function logicalExpression(position, buffer) {
1721 return {
1722 type: 'LogicalExpression',
1723 start: buffer[position],
1724 end: buffer[position + 1],
1725 operator: FIXED_STRINGS[buffer[position + 2]],
1726 left: convertNode(buffer[position + 3], buffer),
1727 right: convertNode(buffer[position + 4], buffer)
1728 };
1729 },
1730 function memberExpression(position, buffer) {
1731 const flags = buffer[position + 2];
1732 return {
1733 type: 'MemberExpression',
1734 start: buffer[position],
1735 end: buffer[position + 1],
1736 computed: (flags & 1) === 1,
1737 optional: (flags & 2) === 2,
1738 object: convertNode(buffer[position + 3], buffer),
1739 property: convertNode(buffer[position + 4], buffer)
1740 };
1741 },
1742 function metaProperty(position, buffer) {
1743 return {
1744 type: 'MetaProperty',
1745 start: buffer[position],
1746 end: buffer[position + 1],
1747 meta: convertNode(buffer[position + 2], buffer),
1748 property: convertNode(buffer[position + 3], buffer)
1749 };
1750 },
1751 function methodDefinition(position, buffer) {
1752 const flags = buffer[position + 2];
1753 return {
1754 type: 'MethodDefinition',
1755 start: buffer[position],
1756 end: buffer[position + 1],
1757 static: (flags & 1) === 1,
1758 computed: (flags & 2) === 2,
1759 decorators: convertNodeList(buffer[position + 3], buffer),
1760 key: convertNode(buffer[position + 4], buffer),
1761 value: convertNode(buffer[position + 5], buffer),
1762 kind: FIXED_STRINGS[buffer[position + 6]]
1763 };
1764 },
1765 function newExpression(position, buffer) {
1766 const annotations = convertAnnotations(buffer[position + 2], buffer);
1767 return {
1768 type: 'NewExpression',
1769 start: buffer[position],
1770 end: buffer[position + 1],
1771 ...(annotations.length > 0 ? { [ANNOTATION_KEY]: annotations } : {}),
1772 callee: convertNode(buffer[position + 3], buffer),
1773 arguments: convertNodeList(buffer[position + 4], buffer)
1774 };
1775 },
1776 function objectExpression(position, buffer) {
1777 return {
1778 type: 'ObjectExpression',
1779 start: buffer[position],
1780 end: buffer[position + 1],
1781 properties: convertNodeList(buffer[position + 2], buffer)
1782 };
1783 },
1784 function objectPattern(position, buffer) {
1785 return {
1786 type: 'ObjectPattern',
1787 start: buffer[position],
1788 end: buffer[position + 1],
1789 properties: convertNodeList(buffer[position + 2], buffer)
1790 };
1791 },
1792 function privateIdentifier(position, buffer) {
1793 return {
1794 type: 'PrivateIdentifier',
1795 start: buffer[position],
1796 end: buffer[position + 1],
1797 name: buffer.convertString(buffer[position + 2])
1798 };
1799 },
1800 function program(position, buffer) {
1801 const invalidAnnotations = convertAnnotations(buffer[position + 3], buffer);
1802 return {
1803 type: 'Program',
1804 start: buffer[position],
1805 end: buffer[position + 1],
1806 body: convertNodeList(buffer[position + 2], buffer),
1807 ...(invalidAnnotations.length > 0 ? { [INVALID_ANNOTATION_KEY]: invalidAnnotations } : {}),
1808 sourceType: 'module'
1809 };
1810 },
1811 function property(position, buffer) {
1812 const flags = buffer[position + 2];
1813 const keyPosition = buffer[position + 3];
1814 const value = convertNode(buffer[position + 4], buffer);
1815 return {
1816 type: 'Property',
1817 start: buffer[position],
1818 end: buffer[position + 1],
1819 method: (flags & 1) === 1,
1820 shorthand: (flags & 2) === 2,
1821 computed: (flags & 4) === 4,
1822 key: keyPosition === 0 ? { ...value } : convertNode(keyPosition, buffer),
1823 value,
1824 kind: FIXED_STRINGS[buffer[position + 5]]
1825 };
1826 },
1827 function propertyDefinition(position, buffer) {
1828 const flags = buffer[position + 2];
1829 const valuePosition = buffer[position + 5];
1830 return {
1831 type: 'PropertyDefinition',
1832 start: buffer[position],
1833 end: buffer[position + 1],
1834 static: (flags & 1) === 1,
1835 computed: (flags & 2) === 2,
1836 decorators: convertNodeList(buffer[position + 3], buffer),
1837 key: convertNode(buffer[position + 4], buffer),
1838 value: valuePosition === 0 ? null : convertNode(valuePosition, buffer)
1839 };
1840 },
1841 function restElement(position, buffer) {
1842 return {
1843 type: 'RestElement',
1844 start: buffer[position],
1845 end: buffer[position + 1],
1846 argument: convertNode(buffer[position + 2], buffer)
1847 };
1848 },
1849 function returnStatement(position, buffer) {
1850 const argumentPosition = buffer[position + 2];
1851 return {
1852 type: 'ReturnStatement',
1853 start: buffer[position],
1854 end: buffer[position + 1],
1855 argument: argumentPosition === 0 ? null : convertNode(argumentPosition, buffer)
1856 };
1857 },
1858 function sequenceExpression(position, buffer) {
1859 return {
1860 type: 'SequenceExpression',
1861 start: buffer[position],
1862 end: buffer[position + 1],
1863 expressions: convertNodeList(buffer[position + 2], buffer)
1864 };
1865 },
1866 function spreadElement(position, buffer) {
1867 return {
1868 type: 'SpreadElement',
1869 start: buffer[position],
1870 end: buffer[position + 1],
1871 argument: convertNode(buffer[position + 2], buffer)
1872 };
1873 },
1874 function staticBlock(position, buffer) {
1875 return {
1876 type: 'StaticBlock',
1877 start: buffer[position],
1878 end: buffer[position + 1],
1879 body: convertNodeList(buffer[position + 2], buffer)
1880 };
1881 },
1882 function superElement(position, buffer) {
1883 return {
1884 type: 'Super',
1885 start: buffer[position],
1886 end: buffer[position + 1]
1887 };
1888 },
1889 function switchCase(position, buffer) {
1890 const testPosition = buffer[position + 2];
1891 return {
1892 type: 'SwitchCase',
1893 start: buffer[position],
1894 end: buffer[position + 1],
1895 test: testPosition === 0 ? null : convertNode(testPosition, buffer),
1896 consequent: convertNodeList(buffer[position + 3], buffer)
1897 };
1898 },
1899 function switchStatement(position, buffer) {
1900 return {
1901 type: 'SwitchStatement',
1902 start: buffer[position],
1903 end: buffer[position + 1],
1904 discriminant: convertNode(buffer[position + 2], buffer),
1905 cases: convertNodeList(buffer[position + 3], buffer)
1906 };
1907 },
1908 function taggedTemplateExpression(position, buffer) {
1909 return {
1910 type: 'TaggedTemplateExpression',
1911 start: buffer[position],
1912 end: buffer[position + 1],
1913 tag: convertNode(buffer[position + 2], buffer),
1914 quasi: convertNode(buffer[position + 3], buffer)
1915 };
1916 },
1917 function templateElement(position, buffer) {
1918 const flags = buffer[position + 2];
1919 const cookedPosition = buffer[position + 3];
1920 const cooked = cookedPosition === 0 ? undefined : buffer.convertString(cookedPosition);
1921 const raw = buffer.convertString(buffer[position + 4]);
1922 return {
1923 type: 'TemplateElement',
1924 start: buffer[position],
1925 end: buffer[position + 1],
1926 tail: (flags & 1) === 1,
1927 value: { cooked, raw }
1928 };
1929 },
1930 function templateLiteral(position, buffer) {
1931 return {
1932 type: 'TemplateLiteral',
1933 start: buffer[position],
1934 end: buffer[position + 1],
1935 quasis: convertNodeList(buffer[position + 2], buffer),
1936 expressions: convertNodeList(buffer[position + 3], buffer)
1937 };
1938 },
1939 function thisExpression(position, buffer) {
1940 return {
1941 type: 'ThisExpression',
1942 start: buffer[position],
1943 end: buffer[position + 1]
1944 };
1945 },
1946 function throwStatement(position, buffer) {
1947 return {
1948 type: 'ThrowStatement',
1949 start: buffer[position],
1950 end: buffer[position + 1],
1951 argument: convertNode(buffer[position + 2], buffer)
1952 };
1953 },
1954 function tryStatement(position, buffer) {
1955 const handlerPosition = buffer[position + 3];
1956 const finalizerPosition = buffer[position + 4];
1957 return {
1958 type: 'TryStatement',
1959 start: buffer[position],
1960 end: buffer[position + 1],
1961 block: convertNode(buffer[position + 2], buffer),
1962 handler: handlerPosition === 0 ? null : convertNode(handlerPosition, buffer),
1963 finalizer: finalizerPosition === 0 ? null : convertNode(finalizerPosition, buffer)
1964 };
1965 },
1966 function unaryExpression(position, buffer) {
1967 return {
1968 type: 'UnaryExpression',
1969 start: buffer[position],
1970 end: buffer[position + 1],
1971 operator: FIXED_STRINGS[buffer[position + 2]],
1972 argument: convertNode(buffer[position + 3], buffer),
1973 prefix: true
1974 };
1975 },
1976 function updateExpression(position, buffer) {
1977 const flags = buffer[position + 2];
1978 return {
1979 type: 'UpdateExpression',
1980 start: buffer[position],
1981 end: buffer[position + 1],
1982 prefix: (flags & 1) === 1,
1983 operator: FIXED_STRINGS[buffer[position + 3]],
1984 argument: convertNode(buffer[position + 4], buffer)
1985 };
1986 },
1987 function variableDeclaration(position, buffer) {
1988 return {
1989 type: 'VariableDeclaration',
1990 start: buffer[position],
1991 end: buffer[position + 1],
1992 kind: FIXED_STRINGS[buffer[position + 2]],
1993 declarations: convertNodeList(buffer[position + 3], buffer)
1994 };
1995 },
1996 function variableDeclarator(position, buffer) {
1997 const initPosition = buffer[position + 3];
1998 return {
1999 type: 'VariableDeclarator',
2000 start: buffer[position],
2001 end: buffer[position + 1],
2002 id: convertNode(buffer[position + 2], buffer),
2003 init: initPosition === 0 ? null : convertNode(initPosition, buffer)
2004 };
2005 },
2006 function whileStatement(position, buffer) {
2007 return {
2008 type: 'WhileStatement',
2009 start: buffer[position],
2010 end: buffer[position + 1],
2011 test: convertNode(buffer[position + 2], buffer),
2012 body: convertNode(buffer[position + 3], buffer)
2013 };
2014 },
2015 function yieldExpression(position, buffer) {
2016 const flags = buffer[position + 2];
2017 const argumentPosition = buffer[position + 3];
2018 return {
2019 type: 'YieldExpression',
2020 start: buffer[position],
2021 end: buffer[position + 1],
2022 delegate: (flags & 1) === 1,
2023 argument: argumentPosition === 0 ? null : convertNode(argumentPosition, buffer)
2024 };
2025 }
2026];
2027function convertNode(position, buffer) {
2028 const nodeType = buffer[position];
2029 const converter = nodeConverters[nodeType];
2030 /* istanbul ignore if: This should never be executed but is a safeguard against faulty buffers */
2031 if (!converter) {
2032 console.trace();
2033 throw new Error(`Unknown node type: ${nodeType}`);
2034 }
2035 return converter(position + 1, buffer);
2036}
2037function convertNodeList(position, buffer) {
2038 if (position === 0)
2039 return EMPTY_ARRAY;
2040 const length = buffer[position++];
2041 const list = new Array(length);
2042 for (let index = 0; index < length; index++) {
2043 const nodePosition = buffer[position++];
2044 list[index] = nodePosition ? convertNode(nodePosition, buffer) : null;
2045 }
2046 return list;
2047}
2048
2049function getAstBuffer(astBuffer) {
2050 const array = new Uint32Array(astBuffer.buffer);
2051 let convertString;
2052 if (typeof Buffer !== 'undefined' && astBuffer instanceof Buffer) {
2053 convertString = (position) => {
2054 const length = array[position++];
2055 const bytePosition = position << 2;
2056 return astBuffer.toString('utf8', bytePosition, bytePosition + length);
2057 };
2058 }
2059 else {
2060 const textDecoder = new TextDecoder();
2061 convertString = (position) => {
2062 const length = array[position++];
2063 const bytePosition = position << 2;
2064 return textDecoder.decode(astBuffer.subarray(bytePosition, bytePosition + length));
2065 };
2066 }
2067 return Object.assign(array, { convertString });
2068}
2069
2070const parseAst = (input, { allowReturnOutsideFunction = false, jsx = false } = {}) => convertProgram(getAstBuffer(parse(input, allowReturnOutsideFunction, jsx)));
2071const parseAstAsync = async (input, { allowReturnOutsideFunction = false, jsx = false, signal } = {}) => convertProgram(getAstBuffer(await parseAsync(input, allowReturnOutsideFunction, jsx, signal)));
2072
2073export { ANNOTATION_KEY, ArrowFunctionExpression, BLANK, BlockStatement, CallExpression, CatchClause, EMPTY_ARRAY, EMPTY_OBJECT, EMPTY_SET, ExportDefaultDeclaration, ExpressionStatement, FIXED_STRINGS, INVALID_ANNOTATION_KEY, Identifier, LOGLEVEL_DEBUG, LOGLEVEL_ERROR, LOGLEVEL_INFO, LOGLEVEL_WARN, Literal, ObjectExpression, Program, Property, RestElement, ReturnStatement, StaticBlock, TemplateLiteral, URL_GENERATEBUNDLE, URL_JSX, URL_OUTPUT_AMD_BASEPATH, URL_OUTPUT_AMD_ID, URL_OUTPUT_DIR, URL_OUTPUT_EXTERNALIMPORTATTRIBUTES, URL_OUTPUT_FORMAT, URL_OUTPUT_GENERATEDCODE, URL_OUTPUT_INLINEDYNAMICIMPORTS, URL_OUTPUT_INTEROP, URL_OUTPUT_MANUALCHUNKS, URL_OUTPUT_SOURCEMAPBASEURL, URL_OUTPUT_SOURCEMAPFILE, URL_PRESERVEENTRYSIGNATURES, URL_TREESHAKE, URL_TREESHAKE_MODULESIDEEFFECTS, URL_WATCH, VariableDeclarator, addTrailingSlashIfMissed, augmentCodeLocation, augmentLogMessage, convertAnnotations, convertNode, error, getAliasName, getAstBuffer, getImportPath, getRollupError, isAbsolute, isPathFragment, isRelative, isValidUrl, locate, logAddonNotGenerated, logAlreadyClosed, logAmbiguousExternalNamespaces, logAnonymousPluginCache, logAssetNotFinalisedForFileName, logAssetReferenceIdNotFoundForSetSource, logAssetSourceAlreadySet, logBadLoader, logCannotAssignModuleToChunk, logCannotCallNamespace, logCannotEmitFromOptionsHook, logChunkInvalid, logChunkNotGeneratedForFileName, logCircularDependency, logCircularReexport, logConflictingSourcemapSources, logConstVariableReassignError, logCyclicCrossChunkReexport, logDuplicateArgumentNameError, logDuplicateExportError, logDuplicatePluginName, logEmptyChunk, logEntryCannotBeExternal, logEval, logExternalModulesCannotBeIncludedInManualChunks, logExternalModulesCannotBeTransformedToModules, logExternalSyntheticExports, logFailedValidation, logFileNameConflict, logFileReferenceIdNotFoundForFilename, logFirstSideEffect, logIllegalIdentifierAsName, logIllegalImportReassignment, logImplicitDependantCannotBeExternal, logImplicitDependantIsNotIncluded, logImportAttributeIsInvalid, logImportOptionsAreInvalid, logIncompatibleExportOptionValue, logInconsistentImportAttributes, logInputHookInOutputPlugin, logInternalIdCannotBeExternal, logInvalidAddonPluginHook, logInvalidAnnotation, logInvalidExportOptionValue, logInvalidFormatForTopLevelAwait, logInvalidFunctionPluginHook, logInvalidLogPosition, logInvalidOption, logInvalidRollupPhaseForChunkEmission, logInvalidSetAssetSourceCall, logInvalidSourcemapForError, logLevelPriority, logMissingEntryExport, logMissingExport, logMissingFileOrDirOption, logMissingGlobalName, logMissingJsxExport, logMissingNameOptionForIifeExport, logMissingNameOptionForUmdExport, logMissingNodeBuiltins, logMixedExport, logModuleLevelDirective, logModuleParseError, logNamespaceConflict, logNoAssetSourceSet, logNoTransformMapOrAstWithoutCode, logOptimizeChunkStatus, logParseError, logPluginError, logRedeclarationError, logReservedNamespace, logShimmedExport, logSourcemapBroken, logSyntheticNamedExportsNeedNamespaceExport, logThisIsUndefined, logUnexpectedNamedImport, logUnexpectedNamespaceReexport, logUnknownOption, logUnresolvedEntry, logUnresolvedImplicitDependant, logUnresolvedImport, logUnresolvedImportTreatedAsExternal, logUnusedExternalImports, normalize, parseAst, parseAstAsync, printQuotedStringList, relative, relativeId, warnDeprecation };
Note: See TracBrowser for help on using the repository browser.