@rollup/wasm-node 4.0.0-23 → 4.0.0-25

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