source: imaps-frontend/node_modules/rollup/dist/es/shared/parseAst.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

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