parseAst.js 90 KB

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