2024-01-05 12:14:38 +00:00
/ *
@ license
2024-01-31 06:33:19 +00:00
Rollup . js v4 . 9.6
Sun , 21 Jan 2024 05 : 51 : 51 GMT - commit ecb6b0a430098052781aa6ee04ec92ee70960321
2024-01-05 12:14:38 +00:00
https : //github.com/rollup/rollup
Released under the MIT License .
* /
'use strict' ;
const native _js = require ( '../native.js' ) ;
const node _path = require ( 'node:path' ) ;
/** @typedef {import('./types').Location} Location */
/ * *
* @ param { import ( './types' ) . Range } range
* @ param { number } index
* /
function rangeContains ( range , index ) {
return range . start <= index && index < range . end ;
}
/ * *
* @ param { string } source
* @ param { import ( './types' ) . Options } [ options ]
* /
function getLocator ( source , options = { } ) {
const { offsetLine = 0 , offsetColumn = 0 } = options ;
let start = 0 ;
const ranges = source . split ( '\n' ) . map ( ( line , i ) => {
const end = start + line . length + 1 ;
/** @type {import('./types').Range} */
const range = { start , end , line : i } ;
start = end ;
return range ;
} ) ;
let i = 0 ;
/ * *
* @ param { string | number } search
* @ param { number } [ index ]
* @ returns { Location | undefined }
* /
function locator ( search , index ) {
if ( typeof search === 'string' ) {
search = source . indexOf ( search , index ? ? 0 ) ;
}
if ( search === - 1 ) return undefined ;
let range = ranges [ i ] ;
const d = search >= range . end ? 1 : - 1 ;
while ( range ) {
if ( rangeContains ( range , search ) ) {
return {
line : offsetLine + range . line ,
column : offsetColumn + search - range . start ,
character : search
} ;
}
i += d ;
range = ranges [ i ] ;
}
}
return locator ;
}
/ * *
* @ param { string } source
* @ param { string | number } search
* @ param { import ( './types' ) . Options } [ options ]
* @ returns { Location | undefined }
* /
function locate ( source , search , options ) {
return getLocator ( source , options ) ( search , options && options . startIndex ) ;
}
function spaces ( index ) {
let result = '' ;
while ( index -- )
result += ' ' ;
return result ;
}
function tabsToSpaces ( value ) {
return value . replace ( /^\t+/ , match => match . split ( '\t' ) . join ( ' ' ) ) ;
}
const LINE _TRUNCATE _LENGTH = 120 ;
const MIN _CHARACTERS _SHOWN _AFTER _LOCATION = 10 ;
const ELLIPSIS = '...' ;
function getCodeFrame ( source , line , column ) {
let lines = source . split ( '\n' ) ;
// Needed if a plugin did not generate correct sourcemaps
if ( line > lines . length )
return '' ;
const maxLineLength = Math . max ( tabsToSpaces ( lines [ line - 1 ] . slice ( 0 , column ) ) . length +
MIN _CHARACTERS _SHOWN _AFTER _LOCATION +
ELLIPSIS . length , LINE _TRUNCATE _LENGTH ) ;
const frameStart = Math . max ( 0 , line - 3 ) ;
let frameEnd = Math . min ( line + 2 , lines . length ) ;
lines = lines . slice ( frameStart , frameEnd ) ;
while ( ! /\S/ . test ( lines [ lines . length - 1 ] ) ) {
lines . pop ( ) ;
frameEnd -= 1 ;
}
const digits = String ( frameEnd ) . length ;
return lines
. map ( ( sourceLine , index ) => {
const isErrorLine = frameStart + index + 1 === line ;
let lineNumber = String ( index + frameStart + 1 ) ;
while ( lineNumber . length < digits )
lineNumber = ` ${ lineNumber } ` ;
let displayedLine = tabsToSpaces ( sourceLine ) ;
if ( displayedLine . length > maxLineLength ) {
displayedLine = ` ${ displayedLine . slice ( 0 , maxLineLength - ELLIPSIS . length ) } ${ ELLIPSIS } ` ;
}
if ( isErrorLine ) {
const indicator = spaces ( digits + 2 + tabsToSpaces ( sourceLine . slice ( 0 , column ) ) . length ) + '^' ;
return ` ${ lineNumber } : ${ displayedLine } \n ${ indicator } ` ;
}
return ` ${ lineNumber } : ${ displayedLine } ` ;
} )
. join ( '\n' ) ;
}
const LOGLEVEL _SILENT = 'silent' ;
const LOGLEVEL _ERROR = 'error' ;
const LOGLEVEL _WARN = 'warn' ;
const LOGLEVEL _INFO = 'info' ;
const LOGLEVEL _DEBUG = 'debug' ;
const logLevelPriority = {
[ LOGLEVEL _DEBUG ] : 0 ,
[ LOGLEVEL _INFO ] : 1 ,
[ LOGLEVEL _SILENT ] : 3 ,
[ LOGLEVEL _WARN ] : 2
} ;
const ABSOLUTE _PATH _REGEX = /^(?:\/|(?:[A-Za-z]:)?[/\\|])/ ;
const RELATIVE _PATH _REGEX = /^\.?\.(\/|$)/ ;
function isAbsolute ( path ) {
return ABSOLUTE _PATH _REGEX . test ( path ) ;
}
function isRelative ( path ) {
return RELATIVE _PATH _REGEX . test ( path ) ;
}
const BACKSLASH _REGEX = /\\/g ;
function normalize ( path ) {
return path . replace ( BACKSLASH _REGEX , '/' ) ;
}
function printQuotedStringList ( list , verbs ) {
const isSingleItem = list . length <= 1 ;
const quotedList = list . map ( item => ` " ${ item } " ` ) ;
let output = isSingleItem
? quotedList [ 0 ]
: ` ${ quotedList . slice ( 0 , - 1 ) . join ( ', ' ) } and ${ quotedList . slice ( - 1 ) [ 0 ] } ` ;
if ( verbs ) {
output += ` ${ isSingleItem ? verbs [ 0 ] : verbs [ 1 ] } ` ;
}
return output ;
}
const ANY _SLASH _REGEX = /[/\\]/ ;
function relative ( from , to ) {
const fromParts = from . split ( ANY _SLASH _REGEX ) . filter ( Boolean ) ;
const toParts = to . split ( ANY _SLASH _REGEX ) . filter ( Boolean ) ;
if ( fromParts [ 0 ] === '.' )
fromParts . shift ( ) ;
if ( toParts [ 0 ] === '.' )
toParts . shift ( ) ;
while ( fromParts [ 0 ] && toParts [ 0 ] && fromParts [ 0 ] === toParts [ 0 ] ) {
fromParts . shift ( ) ;
toParts . shift ( ) ;
}
while ( toParts [ 0 ] === '..' && fromParts . length > 0 ) {
toParts . shift ( ) ;
fromParts . pop ( ) ;
}
while ( fromParts . pop ( ) ) {
toParts . unshift ( '..' ) ;
}
return toParts . join ( '/' ) ;
}
function getAliasName ( id ) {
const base = node _path . basename ( id ) ;
return base . slice ( 0 , Math . max ( 0 , base . length - node _path . extname ( id ) . length ) ) ;
}
function relativeId ( id ) {
if ( ! isAbsolute ( id ) )
return id ;
return relative ( node _path . resolve ( ) , id ) ;
}
function isPathFragment ( name ) {
// starting with "/", "./", "../", "C:/"
return ( name [ 0 ] === '/' || ( name [ 0 ] === '.' && ( name [ 1 ] === '/' || name [ 1 ] === '.' ) ) || isAbsolute ( name ) ) ;
}
const UPPER _DIR _REGEX = /^(\.\.\/)*\.\.$/ ;
function getImportPath ( importerId , targetPath , stripJsExtension , ensureFileName ) {
while ( targetPath . startsWith ( '../' ) ) {
targetPath = targetPath . slice ( 3 ) ;
importerId = '_/' + importerId ;
}
let relativePath = normalize ( relative ( node _path . dirname ( importerId ) , targetPath ) ) ;
if ( stripJsExtension && relativePath . endsWith ( '.js' ) ) {
relativePath = relativePath . slice ( 0 , - 3 ) ;
}
if ( ensureFileName ) {
if ( relativePath === '' )
return '../' + node _path . basename ( targetPath ) ;
if ( UPPER _DIR _REGEX . test ( relativePath ) ) {
return [ ... relativePath . split ( '/' ) , '..' , node _path . basename ( targetPath ) ] . join ( '/' ) ;
}
}
return relativePath ? ( relativePath . startsWith ( '..' ) ? relativePath : './' + relativePath ) : '.' ;
}
function isValidUrl ( url ) {
try {
new URL ( url ) ;
}
catch {
return false ;
}
return true ;
}
function getRollupUrl ( snippet ) {
return ` https://rollupjs.org/ ${ snippet } ` ;
}
function addTrailingSlashIfMissed ( url ) {
if ( ! url . endsWith ( '/' ) ) {
return url + '/' ;
}
return url ;
}
// troubleshooting
const URL _AVOIDING _EVAL = 'troubleshooting/#avoiding-eval' ;
const URL _NAME _IS _NOT _EXPORTED = 'troubleshooting/#error-name-is-not-exported-by-module' ;
const URL _THIS _IS _UNDEFINED = 'troubleshooting/#error-this-is-undefined' ;
const URL _TREATING _MODULE _AS _EXTERNAL _DEPENDENCY = 'troubleshooting/#warning-treating-module-as-external-dependency' ;
const URL _SOURCEMAP _IS _LIKELY _TO _BE _INCORRECT = 'troubleshooting/#warning-sourcemap-is-likely-to-be-incorrect' ;
const URL _OUTPUT _AMD _ID = 'configuration-options/#output-amd-id' ;
const URL _OUTPUT _AMD _BASEPATH = 'configuration-options/#output-amd-basepath' ;
const URL _OUTPUT _DIR = 'configuration-options/#output-dir' ;
const URL _OUTPUT _EXPORTS = 'configuration-options/#output-exports' ;
const URL _OUTPUT _EXTEND = 'configuration-options/#output-extend' ;
const URL _OUTPUT _EXTERNALIMPORTATTRIBUTES = 'configuration-options/#output-externalimportattributes' ;
const URL _OUTPUT _FORMAT = 'configuration-options/#output-format' ;
const URL _OUTPUT _GENERATEDCODE = 'configuration-options/#output-generatedcode' ;
const URL _OUTPUT _GLOBALS = 'configuration-options/#output-globals' ;
const URL _OUTPUT _INLINEDYNAMICIMPORTS = 'configuration-options/#output-inlinedynamicimports' ;
const URL _OUTPUT _INTEROP = 'configuration-options/#output-interop' ;
const URL _OUTPUT _MANUALCHUNKS = 'configuration-options/#output-manualchunks' ;
const URL _OUTPUT _NAME = 'configuration-options/#output-name' ;
const URL _OUTPUT _SOURCEMAPBASEURL = 'configuration-options/#output-sourcemapbaseurl' ;
const URL _OUTPUT _SOURCEMAPFILE = 'configuration-options/#output-sourcemapfile' ;
const URL _PRESERVEENTRYSIGNATURES = 'configuration-options/#preserveentrysignatures' ;
const URL _TREESHAKE = 'configuration-options/#treeshake' ;
const URL _TREESHAKE _PURE = 'configuration-options/#pure' ;
const URL _TREESHAKE _NOSIDEEFFECTS = 'configuration-options/#no-side-effects' ;
const URL _TREESHAKE _MODULESIDEEFFECTS = 'configuration-options/#treeshake-modulesideeffects' ;
const URL _WATCH = 'configuration-options/#watch' ;
// command-line-interface
const URL _BUNDLE _CONFIG _AS _CJS = 'command-line-interface/#bundleconfigascjs' ;
const URL _CONFIGURATION _FILES = 'command-line-interface/#configuration-files' ;
function error ( base ) {
if ( ! ( base instanceof Error ) ) {
base = Object . assign ( new Error ( base . message ) , base ) ;
Object . defineProperty ( base , 'name' , { value : 'RollupError' , writable : true } ) ;
}
throw base ;
}
function augmentCodeLocation ( properties , pos , source , id ) {
if ( typeof pos === 'object' ) {
const { line , column } = pos ;
properties . loc = { column , file : id , line } ;
}
else {
properties . pos = pos ;
const location = locate ( source , pos , { offsetLine : 1 } ) ;
if ( ! location ) {
return ;
}
const { line , column } = location ;
properties . loc = { column , file : id , line } ;
}
if ( properties . frame === undefined ) {
const { line , column } = properties . loc ;
properties . frame = getCodeFrame ( source , line , column ) ;
}
}
// Error codes should be sorted alphabetically while errors should be sorted by
// error code below
const ADDON _ERROR = 'ADDON_ERROR' , ALREADY _CLOSED = 'ALREADY_CLOSED' , AMBIGUOUS _EXTERNAL _NAMESPACES = 'AMBIGUOUS_EXTERNAL_NAMESPACES' , ANONYMOUS _PLUGIN _CACHE = 'ANONYMOUS_PLUGIN_CACHE' , ASSET _NOT _FINALISED = 'ASSET_NOT_FINALISED' , ASSET _NOT _FOUND = 'ASSET_NOT_FOUND' , ASSET _SOURCE _ALREADY _SET = 'ASSET_SOURCE_ALREADY_SET' , ASSET _SOURCE _MISSING = 'ASSET_SOURCE_MISSING' , BAD _LOADER = 'BAD_LOADER' , CANNOT _CALL _NAMESPACE = 'CANNOT_CALL_NAMESPACE' , CANNOT _EMIT _FROM _OPTIONS _HOOK = 'CANNOT_EMIT_FROM_OPTIONS_HOOK' , CHUNK _NOT _GENERATED = 'CHUNK_NOT_GENERATED' , CHUNK _INVALID = 'CHUNK_INVALID' , CIRCULAR _DEPENDENCY = 'CIRCULAR_DEPENDENCY' , CIRCULAR _REEXPORT = 'CIRCULAR_REEXPORT' , CYCLIC _CROSS _CHUNK _REEXPORT = 'CYCLIC_CROSS_CHUNK_REEXPORT' , DEPRECATED _FEATURE = 'DEPRECATED_FEATURE' , DUPLICATE _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 _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' , 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' ;
function logAddonNotGenerated ( message , hook , plugin ) {
return {
code : ADDON _ERROR ,
message : ` Could not retrieve " ${ hook } ". Check configuration of plugin " ${ plugin } ".
\ tError Message : $ { message } `
} ;
}
function logAlreadyClosed ( ) {
return {
code : ALREADY _CLOSED ,
message : 'Bundle is already closed, no more calls to "generate" or "write" are allowed.'
} ;
}
function logAmbiguousExternalNamespaces ( binding , reexportingModule , usedModule , sources ) {
return {
binding ,
code : AMBIGUOUS _EXTERNAL _NAMESPACES ,
ids : sources ,
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 ) } ". ` ,
reexporter : reexportingModule
} ;
}
function logAnonymousPluginCache ( ) {
return {
code : ANONYMOUS _PLUGIN _CACHE ,
message : 'A plugin is trying to use the Rollup cache but is not declaring a plugin name or cacheKey.'
} ;
}
function logAssetNotFinalisedForFileName ( name ) {
return {
code : ASSET _NOT _FINALISED ,
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. `
} ;
}
function logAssetReferenceIdNotFoundForSetSource ( assetReferenceId ) {
return {
code : ASSET _NOT _FOUND ,
message : ` Plugin error - Unable to set the source for unknown asset " ${ assetReferenceId } ". `
} ;
}
function logAssetSourceAlreadySet ( name ) {
return {
code : ASSET _SOURCE _ALREADY _SET ,
message : ` Unable to set the source for asset " ${ name } ", source already set. `
} ;
}
function logNoAssetSourceSet ( assetName ) {
return {
code : ASSET _SOURCE _MISSING ,
message : ` Plugin error creating asset " ${ assetName } " - no asset source set. `
} ;
}
function logBadLoader ( id ) {
return {
code : BAD _LOADER ,
message : ` Error loading " ${ relativeId ( id ) } ": plugin load hook should return a string, a { code, map } object, or nothing/null. `
} ;
}
function logCannotCallNamespace ( name ) {
return {
code : CANNOT _CALL _NAMESPACE ,
message : ` Cannot call a namespace (" ${ name } "). `
} ;
}
function logCannotEmitFromOptionsHook ( ) {
return {
code : CANNOT _EMIT _FROM _OPTIONS _HOOK ,
message : ` Cannot emit files or set asset sources in the "outputOptions" hook, use the "renderStart" hook instead. `
} ;
}
function logChunkNotGeneratedForFileName ( name ) {
return {
code : CHUNK _NOT _GENERATED ,
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. `
} ;
}
function logChunkInvalid ( { fileName , code } , { pos , message } ) {
const errorProperties = {
code : CHUNK _INVALID ,
message : ` Chunk " ${ fileName } " is not valid JavaScript: ${ message } . `
} ;
augmentCodeLocation ( errorProperties , pos , code , fileName ) ;
return errorProperties ;
}
function logCircularDependency ( cyclePath ) {
return {
code : CIRCULAR _DEPENDENCY ,
ids : cyclePath ,
message : ` Circular dependency: ${ cyclePath . map ( relativeId ) . join ( ' -> ' ) } `
} ;
}
function logCircularReexport ( exportName , exporter ) {
return {
code : CIRCULAR _REEXPORT ,
exporter ,
message : ` " ${ exportName } " cannot be exported from " ${ relativeId ( exporter ) } " as it is a reexport that references itself. `
} ;
}
function logCyclicCrossChunkReexport ( exportName , exporter , reexporter , importer , preserveModules ) {
return {
code : CYCLIC _CROSS _CHUNK _REEXPORT ,
exporter ,
id : importer ,
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. \n Either 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. ` ,
reexporter
} ;
}
function logDeprecation ( deprecation , urlSnippet , plugin ) {
return {
code : DEPRECATED _FEATURE ,
message : deprecation ,
url : getRollupUrl ( urlSnippet ) ,
... ( plugin ? { plugin } : { } )
} ;
}
function logDuplicateArgumentNameError ( name ) {
return { code : DUPLICATE _ARGUMENT _NAME , message : ` Duplicate argument name " ${ name } " ` } ;
}
function logDuplicateExportError ( name ) {
return { code : DUPLICATE _EXPORT , message : ` Duplicate export " ${ name } " ` } ;
}
function logDuplicateImportOptions ( ) {
return {
code : DUPLICATE _IMPORT _OPTIONS ,
message : 'Either use --input, or pass input path as argument'
} ;
}
function logDuplicatePluginName ( plugin ) {
return {
code : DUPLICATE _PLUGIN _NAME ,
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). `
} ;
}
function logEmptyChunk ( chunkName ) {
return {
code : EMPTY _BUNDLE ,
message : ` Generated an empty chunk: " ${ chunkName } ". ` ,
names : [ chunkName ]
} ;
}
function logEval ( id ) {
return {
code : EVAL ,
id ,
message : ` Use of eval in " ${ relativeId ( id ) } " is strongly discouraged as it poses security risks and may cause issues with minification. ` ,
url : getRollupUrl ( URL _AVOIDING _EVAL )
} ;
}
function logExternalSyntheticExports ( id , importer ) {
return {
code : EXTERNAL _SYNTHETIC _EXPORTS ,
exporter : id ,
message : ` External " ${ id } " cannot have "syntheticNamedExports" enabled (imported by " ${ relativeId ( importer ) } "). `
} ;
}
function logFailAfterWarnings ( ) {
return {
code : FAIL _AFTER _WARNINGS ,
message : 'Warnings occurred and --failAfterWarnings flag present.'
} ;
}
function logFileNameConflict ( fileName ) {
return {
code : FILE _NAME _CONFLICT ,
message : ` The emitted file " ${ fileName } " overwrites a previously emitted file of the same name. `
} ;
}
function logFileReferenceIdNotFoundForFilename ( assetReferenceId ) {
return {
code : FILE _NOT _FOUND ,
message : ` Plugin error - Unable to get file name for unknown file " ${ assetReferenceId } ". `
} ;
}
function logFirstSideEffect ( source , id , { line , column } ) {
return {
code : FIRST _SIDE _EFFECT ,
message : ` First side effect in ${ relativeId ( id ) } is at ( ${ line } : ${ column } ) \n ${ getCodeFrame ( source , line , column ) } `
} ;
}
function logIllegalIdentifierAsName ( name ) {
return {
code : ILLEGAL _IDENTIFIER _AS _NAME ,
message : ` Given name " ${ name } " is not a legal JS identifier. If you need this, you can try "output.extend: true". ` ,
url : getRollupUrl ( URL _OUTPUT _EXTEND )
} ;
}
function logIllegalImportReassignment ( name , importingId ) {
return {
code : ILLEGAL _REASSIGNMENT ,
message : ` Illegal reassignment of import " ${ name } " in " ${ relativeId ( importingId ) } ". `
} ;
}
function logInconsistentImportAttributes ( existingAttributes , newAttributes , source , importer ) {
return {
code : INCONSISTENT _IMPORT _ATTRIBUTES ,
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. `
} ;
}
const formatAttributes = ( attributes ) => {
const entries = Object . entries ( attributes ) ;
if ( entries . length === 0 )
return 'no' ;
return entries . map ( ( [ key , value ] ) => ` " ${ key } ": " ${ value } " ` ) . join ( ', ' ) ;
} ;
function logInvalidAnnotation ( comment , id , type ) {
return {
code : INVALID _ANNOTATION ,
id ,
message : ` A comment \n \n " ${ comment } " \n \n in " ${ relativeId ( id ) } " contains an annotation that Rollup cannot interpret due to the position of the comment. The comment will be removed to avoid issues. ` ,
url : getRollupUrl ( type === 'noSideEffects' ? URL _TREESHAKE _NOSIDEEFFECTS : URL _TREESHAKE _PURE )
} ;
}
function logInputHookInOutputPlugin ( pluginName , hookName ) {
return {
code : INPUT _HOOK _IN _OUTPUT _PLUGIN ,
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. `
} ;
}
function logCannotAssignModuleToChunk ( moduleId , assignToAlias , currentAlias ) {
return {
code : INVALID _CHUNK ,
message : ` Cannot assign " ${ relativeId ( moduleId ) } " to the " ${ assignToAlias } " chunk as it is already in the " ${ currentAlias } " chunk. `
} ;
}
function logCannotBundleConfigAsEsm ( originalError ) {
return {
cause : originalError ,
code : INVALID _CONFIG _MODULE _FORMAT ,
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 \n Original error: ${ originalError . message } ` ,
stack : originalError . stack ,
url : getRollupUrl ( URL _BUNDLE _CONFIG _AS _CJS )
} ;
}
function logCannotLoadConfigAsCjs ( originalError ) {
return {
cause : originalError ,
code : INVALID _CONFIG _MODULE _FORMAT ,
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 \n Original error: ${ originalError . message } ` ,
stack : originalError . stack ,
url : getRollupUrl ( URL _BUNDLE _CONFIG _AS _CJS )
} ;
}
function logCannotLoadConfigAsEsm ( originalError ) {
return {
cause : originalError ,
code : INVALID _CONFIG _MODULE _FORMAT ,
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 \n Original error: ${ originalError . message } ` ,
stack : originalError . stack ,
url : getRollupUrl ( URL _BUNDLE _CONFIG _AS _CJS )
} ;
}
function logInvalidExportOptionValue ( optionValue ) {
return {
code : INVALID _EXPORT _OPTION ,
message : ` "output.exports" must be "default", "named", "none", "auto", or left unspecified (defaults to "auto"), received " ${ optionValue } ". ` ,
url : getRollupUrl ( URL _OUTPUT _EXPORTS )
} ;
}
function logIncompatibleExportOptionValue ( optionValue , keys , entryModule ) {
return {
code : INVALID _EXPORT _OPTION ,
message : ` " ${ optionValue } " was specified for "output.exports", but entry module " ${ relativeId ( entryModule ) } " has the following exports: ${ printQuotedStringList ( keys ) } ` ,
url : getRollupUrl ( URL _OUTPUT _EXPORTS )
} ;
}
function logInternalIdCannotBeExternal ( source , importer ) {
return {
code : INVALID _EXTERNAL _ID ,
message : ` " ${ source } " is imported as an external by " ${ relativeId ( importer ) } ", but is already an existing non-external module id. `
} ;
}
function logImportOptionsAreInvalid ( importer ) {
return {
code : INVALID _IMPORT _ATTRIBUTE ,
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. `
} ;
}
function logImportAttributeIsInvalid ( importer ) {
return {
code : INVALID _IMPORT _ATTRIBUTE ,
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. `
} ;
}
function logInvalidLogPosition ( plugin ) {
return {
code : INVALID _LOG _POSITION ,
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. `
} ;
}
function logInvalidOption ( option , urlSnippet , explanation , value ) {
return {
code : INVALID _OPTION ,
message : ` Invalid value ${ value === undefined ? '' : ` ${ JSON . stringify ( value ) } ` } for option " ${ option } " - ${ explanation } . ` ,
url : getRollupUrl ( urlSnippet )
} ;
}
function logInvalidAddonPluginHook ( hook , plugin ) {
return {
code : INVALID _PLUGIN _HOOK ,
hook ,
message : ` Error running plugin hook " ${ hook } " for plugin " ${ plugin } ", expected a string, a function hook or an object with a "handler" string or function. ` ,
plugin
} ;
}
function logInvalidFunctionPluginHook ( hook , plugin ) {
return {
code : INVALID _PLUGIN _HOOK ,
hook ,
message : ` Error running plugin hook " ${ hook } " for plugin " ${ plugin } ", expected a function hook or an object with a "handler" function. ` ,
plugin
} ;
}
function logInvalidRollupPhaseForChunkEmission ( ) {
return {
code : INVALID _ROLLUP _PHASE ,
message : ` Cannot emit chunks after module loading has finished. `
} ;
}
function logInvalidSetAssetSourceCall ( ) {
return {
code : INVALID _SETASSETSOURCE ,
message : ` setAssetSource cannot be called in transform for caching reasons. Use emitFile with a source, or call setAssetSource in another hook. `
} ;
}
function logInvalidFormatForTopLevelAwait ( id , format ) {
return {
code : INVALID _TLA _FORMAT ,
id ,
message : ` Module format " ${ format } " does not support top-level await. Use the "es" or "system" output formats rather. `
} ;
}
function logMissingConfig ( ) {
return {
code : MISSING _CONFIG ,
message : 'Config file must export an options object, or an array of options objects' ,
url : getRollupUrl ( URL _CONFIGURATION _FILES )
} ;
}
function logMissingEntryExport ( binding , exporter ) {
return {
binding ,
code : MISSING _EXPORT ,
exporter ,
message : ` Exported variable " ${ binding } " is not defined in " ${ relativeId ( exporter ) } ". ` ,
url : getRollupUrl ( URL _NAME _IS _NOT _EXPORTED )
} ;
}
function logMissingExport ( binding , importingModule , exporter ) {
const isJson = node _path . extname ( exporter ) === '.json' ;
return {
binding ,
code : MISSING _EXPORT ,
exporter ,
id : importingModule ,
message : ` " ${ binding } " is not exported by " ${ relativeId ( exporter ) } ", imported by " ${ relativeId ( importingModule ) } ". ${ isJson ? ' (Note that you need @rollup/plugin-json to import JSON files)' : '' } ` ,
url : getRollupUrl ( URL _NAME _IS _NOT _EXPORTED )
} ;
}
function logMissingExternalConfig ( file ) {
return {
code : MISSING _EXTERNAL _CONFIG ,
message : ` Could not resolve config file " ${ file } " `
} ;
}
function logMissingGlobalName ( externalId , guess ) {
return {
code : MISSING _GLOBAL _NAME ,
id : externalId ,
message : ` No name was provided for external module " ${ externalId } " in "output.globals" – guessing " ${ guess } ". ` ,
names : [ guess ] ,
url : getRollupUrl ( URL _OUTPUT _GLOBALS )
} ;
}
function logImplicitDependantCannotBeExternal ( unresolvedId , implicitlyLoadedBefore ) {
return {
code : MISSING _IMPLICIT _DEPENDANT ,
message : ` Module " ${ relativeId ( unresolvedId ) } " that should be implicitly loaded before " ${ relativeId ( implicitlyLoadedBefore ) } " cannot be external. `
} ;
}
function logUnresolvedImplicitDependant ( unresolvedId , implicitlyLoadedBefore ) {
return {
code : MISSING _IMPLICIT _DEPENDANT ,
message : ` Module " ${ relativeId ( unresolvedId ) } " that should be implicitly loaded before " ${ relativeId ( implicitlyLoadedBefore ) } " could not be resolved. `
} ;
}
function logImplicitDependantIsNotIncluded ( module ) {
const implicitDependencies = [ ... module . implicitlyLoadedBefore ]
. map ( dependency => relativeId ( dependency . id ) )
. sort ( ) ;
return {
code : MISSING _IMPLICIT _DEPENDANT ,
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. `
} ;
}
function logMissingNameOptionForIifeExport ( ) {
return {
code : MISSING _NAME _OPTION _FOR _IIFE _EXPORT ,
message : ` If you do not supply "output.name", you may not be able to access the exports of an IIFE bundle. ` ,
url : getRollupUrl ( URL _OUTPUT _NAME )
} ;
}
function logMissingNameOptionForUmdExport ( ) {
return {
code : MISSING _NAME _OPTION _FOR _IIFE _EXPORT ,
message : 'You must supply "output.name" for UMD bundles that have exports so that the exports are accessible in environments without a module loader.' ,
url : getRollupUrl ( URL _OUTPUT _NAME )
} ;
}
function logMissingNodeBuiltins ( externalBuiltins ) {
return {
code : MISSING _NODE _BUILTINS ,
ids : externalBuiltins ,
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 `
} ;
}
// eslint-disable-next-line unicorn/prevent-abbreviations
function logMissingFileOrDirOption ( ) {
return {
code : MISSING _OPTION ,
message : 'You must specify "output.file" or "output.dir" for the build.' ,
url : getRollupUrl ( URL _OUTPUT _DIR )
} ;
}
function logMixedExport ( facadeModuleId , name ) {
return {
code : MIXED _EXPORTS ,
id : facadeModuleId ,
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. ` ,
url : getRollupUrl ( URL _OUTPUT _EXPORTS )
} ;
}
function logModuleLevelDirective ( directive , id ) {
return {
code : MODULE _LEVEL _DIRECTIVE ,
id ,
message : ` Module level directives cause errors when bundled, " ${ directive } " in " ${ relativeId ( id ) } " was ignored. `
} ;
}
function logNamespaceConflict ( binding , reexportingModuleId , sources ) {
return {
binding ,
code : NAMESPACE _CONFLICT ,
ids : sources ,
message : ` Conflicting namespaces: " ${ relativeId ( reexportingModuleId ) } " re-exports " ${ binding } " from one of the modules ${ printQuotedStringList ( sources . map ( moduleId => relativeId ( moduleId ) ) ) } (will be ignored). ` ,
reexporter : reexportingModuleId
} ;
}
function logNoTransformMapOrAstWithoutCode ( pluginName ) {
return {
code : NO _TRANSFORM _MAP _OR _AST _WITHOUT _CODE ,
message : ` The plugin " ${ pluginName } " returned a "map" or "ast" without returning ` +
'a "code". This will be ignored.'
} ;
}
function logOnlyInlineSourcemapsForStdout ( ) {
return {
code : ONLY _INLINE _SOURCEMAPS ,
message : 'Only inline sourcemaps are supported when bundling to stdout.'
} ;
}
function logOptimizeChunkStatus ( chunks , smallChunks , pointInTime ) {
return {
code : OPTIMIZE _CHUNK _STATUS ,
message : ` ${ pointInTime } , there are \n ` +
` ${ chunks } chunks, of which \n ` +
` ${ smallChunks } are below minChunkSize. `
} ;
}
function logParseError ( message , pos ) {
return { code : PARSE _ERROR , message , pos } ;
}
function logRedeclarationError ( name ) {
return { code : REDECLARATION _ERROR , message : ` Identifier " ${ name } " has already been declared ` } ;
}
function logModuleParseError ( error , moduleId ) {
let message = error . message . replace ( / \(\d+:\d+\)$/ , '' ) ;
if ( moduleId . endsWith ( '.json' ) ) {
message += ' (Note that you need @rollup/plugin-json to import JSON files)' ;
}
else if ( ! moduleId . endsWith ( '.js' ) ) {
message += ' (Note that you need plugins to import files that are not JavaScript)' ;
}
return {
cause : error ,
code : PARSE _ERROR ,
id : moduleId ,
message ,
stack : error . stack
} ;
}
function logPluginError ( error , plugin , { hook , id } = { } ) {
const code = error . code ;
if ( ! error . pluginCode &&
code != null &&
( typeof code !== 'string' || ! code . startsWith ( 'PLUGIN_' ) ) ) {
error . pluginCode = code ;
}
error . code = PLUGIN _ERROR ;
error . plugin = plugin ;
if ( hook ) {
error . hook = hook ;
}
if ( id ) {
error . id = id ;
}
return error ;
}
function logShimmedExport ( id , binding ) {
return {
binding ,
code : SHIMMED _EXPORT ,
exporter : id ,
message : ` Missing export " ${ binding } " has been shimmed in module " ${ relativeId ( id ) } ". `
} ;
}
function logSourcemapBroken ( plugin ) {
return {
code : SOURCEMAP _BROKEN ,
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 ` ,
plugin ,
url : getRollupUrl ( URL _SOURCEMAP _IS _LIKELY _TO _BE _INCORRECT )
} ;
}
function logConflictingSourcemapSources ( filename ) {
return {
code : SOURCEMAP _BROKEN ,
message : ` Multiple conflicting contents for sourcemap source ${ filename } `
} ;
}
function logInvalidSourcemapForError ( error , id , column , line , pos ) {
return {
cause : error ,
code : SOURCEMAP _ERROR ,
id ,
loc : {
column ,
file : id ,
line
} ,
message : ` Error when using sourcemap for reporting an error: ${ error . message } ` ,
pos
} ;
}
function logSyntheticNamedExportsNeedNamespaceExport ( id , syntheticNamedExportsOption ) {
return {
code : SYNTHETIC _NAMED _EXPORTS _NEED _NAMESPACE _EXPORT ,
exporter : id ,
message : ` Module " ${ relativeId ( id ) } " that is marked with \` syntheticNamedExports: ${ JSON . stringify ( syntheticNamedExportsOption ) } \` needs ${ typeof syntheticNamedExportsOption === 'string' && syntheticNamedExportsOption !== 'default'
? ` an explicit export named " ${ syntheticNamedExportsOption } " `
: 'a default export' } that does not reexport an unresolved named export of the same module . `
} ;
}
function logThisIsUndefined ( ) {
return {
code : THIS _IS _UNDEFINED ,
message : ` The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten ` ,
url : getRollupUrl ( URL _THIS _IS _UNDEFINED )
} ;
}
function logUnexpectedNamedImport ( id , imported , isReexport ) {
const importType = isReexport ? 'reexport' : 'import' ;
return {
code : UNEXPECTED _NAMED _IMPORT ,
exporter : id ,
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. ` ,
url : getRollupUrl ( URL _OUTPUT _INTEROP )
} ;
}
function logUnexpectedNamespaceReexport ( id ) {
return {
code : UNEXPECTED _NAMED _IMPORT ,
exporter : id ,
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. ` ,
url : getRollupUrl ( URL _OUTPUT _INTEROP )
} ;
}
function logUnknownOption ( optionType , unknownOptions , validOptions ) {
return {
code : UNKNOWN _OPTION ,
message : ` Unknown ${ optionType } : ${ unknownOptions . join ( ', ' ) } . Allowed options: ${ validOptions . join ( ', ' ) } `
} ;
}
function logEntryCannotBeExternal ( unresolvedId ) {
return {
code : UNRESOLVED _ENTRY ,
message : ` Entry module " ${ relativeId ( unresolvedId ) } " cannot be external. `
} ;
}
function logExternalModulesCannotBeIncludedInManualChunks ( source ) {
return {
code : EXTERNAL _MODULES _CANNOT _BE _INCLUDED _IN _MANUAL _CHUNKS ,
message : ` " ${ source } " cannot be included in manualChunks because it is resolved as an external module by the "external" option or plugins. `
} ;
}
function logExternalModulesCannotBeTransformedToModules ( source ) {
return {
code : EXTERNAL _MODULES _CANNOT _BE _TRANSFORMED _TO _MODULES ,
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. `
} ;
}
function logUnresolvedEntry ( unresolvedId ) {
return {
code : UNRESOLVED _ENTRY ,
message : ` Could not resolve entry module " ${ relativeId ( unresolvedId ) } ". `
} ;
}
function logUnresolvedImport ( source , importer ) {
return {
code : UNRESOLVED _IMPORT ,
exporter : source ,
id : importer ,
message : ` Could not resolve " ${ source } " from " ${ relativeId ( importer ) } " `
} ;
}
function logUnresolvedImportTreatedAsExternal ( source , importer ) {
return {
code : UNRESOLVED _IMPORT ,
exporter : source ,
id : importer ,
message : ` " ${ source } " is imported by " ${ relativeId ( importer ) } ", but could not be resolved – treating it as an external dependency. ` ,
url : getRollupUrl ( URL _TREATING _MODULE _AS _EXTERNAL _DEPENDENCY )
} ;
}
function logUnusedExternalImports ( externalId , names , importers ) {
return {
code : UNUSED _EXTERNAL _IMPORT ,
exporter : externalId ,
ids : importers ,
message : ` ${ printQuotedStringList ( names , [
'is' ,
'are'
] ) } imported from external module "${externalId}" but never used in $ { printQuotedStringList ( importers . map ( importer => relativeId ( importer ) ) ) } . ` ,
names
} ;
}
function logFailedValidation ( message ) {
return {
code : VALIDATION _ERROR ,
message
} ;
}
function warnDeprecation ( deprecation , urlSnippet , activeDeprecation , options , plugin ) {
warnDeprecationWithOptions ( deprecation , urlSnippet , activeDeprecation , options . onLog , options . strictDeprecations , plugin ) ;
}
function warnDeprecationWithOptions ( deprecation , urlSnippet , activeDeprecation , log , strictDeprecations , plugin ) {
if ( activeDeprecation || strictDeprecations ) {
const warning = logDeprecation ( deprecation , urlSnippet , plugin ) ;
if ( strictDeprecations ) {
return error ( warning ) ;
}
log ( LOGLEVEL _WARN , warning ) ;
}
}
const FIXED _STRINGS = [
'var' ,
'let' ,
'const' ,
'init' ,
'get' ,
'set' ,
'constructor' ,
'method' ,
'-' ,
'+' ,
'!' ,
'~' ,
'typeof' ,
'void' ,
'delete' ,
'++' ,
'--' ,
'==' ,
'!=' ,
'===' ,
'!==' ,
'<' ,
'<=' ,
'>' ,
'>=' ,
'<<' ,
'>>' ,
'>>>' ,
'+' ,
'-' ,
'*' ,
'/' ,
'%' ,
'|' ,
'^' ,
'&' ,
'||' ,
'&&' ,
'in' ,
'instanceof' ,
'**' ,
'??' ,
'=' ,
'+=' ,
'-=' ,
'*=' ,
'/=' ,
'%=' ,
'<<=' ,
'>>=' ,
'>>>=' ,
'|=' ,
'^=' ,
'&=' ,
'**=' ,
'&&=' ,
'||=' ,
'??=' ,
'pure' ,
'noSideEffects'
] ;
2024-01-31 06:33:19 +00:00
// This file is generated by scripts/generate-ast-converters.js.
// Do not edit this file directly.
const ANNOTATION _KEY = '_rollupAnnotations' ;
const INVALID _ANNOTATION _KEY = '_rollupRemoved' ;
function convertProgram ( buffer , readString ) {
return convertNode ( 0 , new Uint32Array ( buffer ) , readString ) ;
}
2024-01-05 12:14:38 +00:00
/* eslint-disable sort-keys */
const nodeConverters = [
2024-01-31 06:33:19 +00:00
function parseError ( position , buffer , readString ) {
const pos = buffer [ position ++ ] ;
const message = convertString ( position , buffer , readString ) ;
error ( logParseError ( message , pos ) ) ;
} ,
function arrayExpression ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const elements = convertNodeList ( position , buffer , readString ) ;
return {
type : 'ArrayExpression' ,
start ,
end ,
elements
} ;
} ,
2024-01-31 06:33:19 +00:00
function arrayPattern ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const elements = convertNodeList ( position , buffer , readString ) ;
return {
type : 'ArrayPattern' ,
start ,
end ,
elements
} ;
} ,
2024-01-31 06:33:19 +00:00
function arrowFunctionExpression ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const flags = buffer [ position ++ ] ;
const async = ( flags & 1 ) === 1 ;
const expression = ( flags & 2 ) === 2 ;
const generator = ( flags & 4 ) === 4 ;
2024-01-05 12:14:38 +00:00
const parameters = convertNodeList ( buffer [ position ++ ] , buffer , readString ) ;
const body = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
2024-01-31 06:33:19 +00:00
const annotations = convertAnnotations ( position , buffer ) ;
return {
2024-01-05 12:14:38 +00:00
type : 'ArrowFunctionExpression' ,
start ,
end ,
async ,
expression ,
generator ,
2024-01-31 06:33:19 +00:00
... ( annotations . length > 0 ? { [ ANNOTATION _KEY ] : annotations } : { } ) ,
params : parameters ,
body ,
id : null
} ;
2024-01-05 12:14:38 +00:00
} ,
2024-01-31 06:33:19 +00:00
function assignmentExpression ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const operator = FIXED _STRINGS [ buffer [ position ++ ] ] ;
const right = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const left = convertNode ( position , buffer , readString ) ;
return {
type : 'AssignmentExpression' ,
start ,
end ,
operator ,
2024-01-31 06:33:19 +00:00
left ,
2024-01-05 12:14:38 +00:00
right
} ;
} ,
2024-01-31 06:33:19 +00:00
function assignmentPattern ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const right = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const left = convertNode ( position , buffer , readString ) ;
return {
type : 'AssignmentPattern' ,
start ,
end ,
left ,
right
} ;
} ,
2024-01-31 06:33:19 +00:00
function awaitExpression ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const argument = convertNode ( position , buffer , readString ) ;
return {
type : 'AwaitExpression' ,
start ,
2024-01-31 06:33:19 +00:00
end ,
argument
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function binaryExpression ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const operator = FIXED _STRINGS [ buffer [ position ++ ] ] ;
const right = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const left = convertNode ( position , buffer , readString ) ;
return {
type : 'BinaryExpression' ,
start ,
end ,
operator ,
2024-01-31 06:33:19 +00:00
left ,
2024-01-05 12:14:38 +00:00
right
} ;
} ,
2024-01-31 06:33:19 +00:00
function blockStatement ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const body = convertNodeList ( position , buffer , readString ) ;
return {
type : 'BlockStatement' ,
start ,
2024-01-31 06:33:19 +00:00
end ,
body
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function breakStatement ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const labelPosition = buffer [ position ] ;
const label = labelPosition === 0 ? null : convertNode ( labelPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
return {
type : 'BreakStatement' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
label
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function callExpression ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const flags = buffer [ position ++ ] ;
const optional = ( flags & 1 ) === 1 ;
2024-01-05 12:14:38 +00:00
const callee = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
2024-01-31 06:33:19 +00:00
const callArguments = convertNodeList ( buffer [ position ++ ] , buffer , readString ) ;
const annotations = convertAnnotations ( position , buffer ) ;
return {
2024-01-05 12:14:38 +00:00
type : 'CallExpression' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
optional ,
... ( annotations . length > 0 ? { [ ANNOTATION _KEY ] : annotations } : { } ) ,
2024-01-05 12:14:38 +00:00
callee ,
2024-01-31 06:33:19 +00:00
arguments : callArguments
} ;
2024-01-05 12:14:38 +00:00
} ,
2024-01-31 06:33:19 +00:00
function catchClause ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const parameterPosition = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const parameter = parameterPosition === 0 ? null : convertNode ( parameterPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const body = convertNode ( buffer [ position ] , buffer , readString ) ;
return {
type : 'CatchClause' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
param : parameter ,
body
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function chainExpression ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const expression = convertNode ( position , buffer , readString ) ;
return {
type : 'ChainExpression' ,
start ,
end ,
expression
} ;
} ,
2024-01-31 06:33:19 +00:00
function classBody ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const body = convertNodeList ( position , buffer , readString ) ;
return {
type : 'ClassBody' ,
start ,
end ,
body
} ;
} ,
2024-01-31 06:33:19 +00:00
function classDeclaration ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const idPosition = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const id = idPosition === 0 ? null : convertNode ( idPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const superClassPosition = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const superClass = superClassPosition === 0 ? null : convertNode ( superClassPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const body = convertNode ( buffer [ position ] , buffer , readString ) ;
return {
type : 'ClassDeclaration' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
id ,
superClass ,
body
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function classExpression ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const idPosition = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const id = idPosition === 0 ? null : convertNode ( idPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const superClassPosition = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const superClass = superClassPosition === 0 ? null : convertNode ( superClassPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const body = convertNode ( buffer [ position ] , buffer , readString ) ;
return {
type : 'ClassExpression' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
id ,
superClass ,
body
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function conditionalExpression ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const consequent = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const alternate = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const test = convertNode ( position , buffer , readString ) ;
return {
type : 'ConditionalExpression' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
test ,
2024-01-05 12:14:38 +00:00
consequent ,
2024-01-31 06:33:19 +00:00
alternate
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function continueStatement ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const labelPosition = buffer [ position ] ;
2024-01-31 06:33:19 +00:00
const label = labelPosition === 0 ? null : convertNode ( labelPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
return {
type : 'ContinueStatement' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
label
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function debuggerStatement ( position , buffer ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
return {
type : 'DebuggerStatement' ,
start ,
end
} ;
} ,
2024-01-31 06:33:19 +00:00
function directive ( position , buffer , readString ) {
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const expression = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const directive = convertString ( position , buffer , readString ) ;
return {
type : 'ExpressionStatement' ,
start ,
end ,
directive ,
expression
} ;
} ,
function doWhileStatement ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const test = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const body = convertNode ( position , buffer , readString ) ;
return {
type : 'DoWhileStatement' ,
start ,
end ,
body ,
test
} ;
} ,
2024-01-31 06:33:19 +00:00
function emptyStatement ( position , buffer ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
return {
type : 'EmptyStatement' ,
start ,
end
} ;
} ,
2024-01-31 06:33:19 +00:00
function exportAllDeclaration ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const exportedPosition = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const exported = exportedPosition === 0 ? null : convertNode ( exportedPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const source = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const attributes = convertNodeList ( buffer [ position ] , buffer , readString ) ;
return {
type : 'ExportAllDeclaration' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
exported ,
2024-01-05 12:14:38 +00:00
source ,
attributes
} ;
} ,
2024-01-31 06:33:19 +00:00
function exportDefaultDeclaration ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const declaration = convertNode ( position , buffer , readString ) ;
return {
type : 'ExportDefaultDeclaration' ,
start ,
end ,
declaration
} ;
} ,
2024-01-31 06:33:19 +00:00
function exportNamedDeclaration ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const sourcePosition = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const source = sourcePosition === 0 ? null : convertNode ( sourcePosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const attributes = convertNodeList ( buffer [ position ++ ] , buffer , readString ) ;
2024-01-31 06:33:19 +00:00
const declarationPosition = buffer [ position ++ ] ;
const declaration = declarationPosition === 0 ? null : convertNode ( declarationPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const specifiers = convertNodeList ( position , buffer , readString ) ;
return {
type : 'ExportNamedDeclaration' ,
start ,
end ,
specifiers ,
2024-01-31 06:33:19 +00:00
source ,
attributes ,
declaration
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function exportSpecifier ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const exportedPosition = buffer [ position ++ ] ;
const local = convertNode ( position , buffer , readString ) ;
return {
type : 'ExportSpecifier' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
local ,
exported : exportedPosition === 0 ? { ... local } : convertNode ( exportedPosition , buffer , readString )
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function expressionStatement ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const expression = convertNode ( position , buffer , readString ) ;
return {
type : 'ExpressionStatement' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
expression
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function forInStatement ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const right = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const body = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const left = convertNode ( position , buffer , readString ) ;
return {
type : 'ForInStatement' ,
start ,
end ,
left ,
2024-01-31 06:33:19 +00:00
right ,
body
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function forOfStatement ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const flags = buffer [ position ++ ] ;
const awaited = ( flags & 1 ) === 1 ;
2024-01-05 12:14:38 +00:00
const right = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const body = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const left = convertNode ( position , buffer , readString ) ;
return {
type : 'ForOfStatement' ,
start ,
end ,
await : awaited ,
left ,
2024-01-31 06:33:19 +00:00
right ,
body
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function forStatement ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const initPosition = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const init = initPosition === 0 ? null : convertNode ( initPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const testPosition = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const test = testPosition === 0 ? null : convertNode ( testPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const updatePosition = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const update = updatePosition === 0 ? null : convertNode ( updatePosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const body = convertNode ( buffer [ position ] , buffer , readString ) ;
return {
type : 'ForStatement' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
init ,
test ,
update ,
body
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function functionDeclaration ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const flags = buffer [ position ++ ] ;
const async = ( flags & 1 ) === 1 ;
const generator = ( flags & 2 ) === 2 ;
2024-01-05 12:14:38 +00:00
const idPosition = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const id = idPosition === 0 ? null : convertNode ( idPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const parameters = convertNodeList ( buffer [ position ++ ] , buffer , readString ) ;
const body = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
2024-01-31 06:33:19 +00:00
const annotations = convertAnnotations ( position , buffer ) ;
return {
2024-01-05 12:14:38 +00:00
type : 'FunctionDeclaration' ,
start ,
end ,
async ,
generator ,
2024-01-31 06:33:19 +00:00
... ( annotations . length > 0 ? { [ ANNOTATION _KEY ] : annotations } : { } ) ,
id ,
params : parameters ,
body ,
expression : false
} ;
2024-01-05 12:14:38 +00:00
} ,
2024-01-31 06:33:19 +00:00
function functionExpression ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const flags = buffer [ position ++ ] ;
const async = ( flags & 1 ) === 1 ;
const generator = ( flags & 2 ) === 2 ;
2024-01-05 12:14:38 +00:00
const idPosition = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const id = idPosition === 0 ? null : convertNode ( idPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const parameters = convertNodeList ( buffer [ position ++ ] , buffer , readString ) ;
const body = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
2024-01-31 06:33:19 +00:00
const annotations = convertAnnotations ( position , buffer ) ;
return {
2024-01-05 12:14:38 +00:00
type : 'FunctionExpression' ,
start ,
end ,
async ,
generator ,
2024-01-31 06:33:19 +00:00
... ( annotations . length > 0 ? { [ ANNOTATION _KEY ] : annotations } : { } ) ,
id ,
params : parameters ,
body ,
expression : false
} ;
2024-01-05 12:14:38 +00:00
} ,
2024-01-31 06:33:19 +00:00
function identifier ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const name = convertString ( position , buffer , readString ) ;
return {
type : 'Identifier' ,
start ,
end ,
name
} ;
} ,
2024-01-31 06:33:19 +00:00
function ifStatement ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const consequent = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const alternatePosition = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const alternate = alternatePosition === 0 ? null : convertNode ( alternatePosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const test = convertNode ( position , buffer , readString ) ;
return {
type : 'IfStatement' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
test ,
2024-01-05 12:14:38 +00:00
consequent ,
2024-01-31 06:33:19 +00:00
alternate
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function importAttribute ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const value = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const key = convertNode ( position , buffer , readString ) ;
return {
type : 'ImportAttribute' ,
start ,
end ,
key ,
value
} ;
} ,
2024-01-31 06:33:19 +00:00
function importDeclaration ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const source = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const attributes = convertNodeList ( buffer [ position ++ ] , buffer , readString ) ;
const specifiers = convertNodeList ( position , buffer , readString ) ;
return {
type : 'ImportDeclaration' ,
start ,
end ,
specifiers ,
2024-01-31 06:33:19 +00:00
source ,
2024-01-05 12:14:38 +00:00
attributes
} ;
} ,
2024-01-31 06:33:19 +00:00
function importDefaultSpecifier ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const local = convertNode ( position , buffer , readString ) ;
return {
type : 'ImportDefaultSpecifier' ,
start ,
end ,
local
} ;
} ,
2024-01-31 06:33:19 +00:00
function importExpression ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const optionsPosition = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const options = optionsPosition === 0 ? null : convertNode ( optionsPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const source = convertNode ( position , buffer , readString ) ;
return {
type : 'ImportExpression' ,
start ,
end ,
source ,
2024-01-31 06:33:19 +00:00
options
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function importNamespaceSpecifier ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const local = convertNode ( position , buffer , readString ) ;
return {
type : 'ImportNamespaceSpecifier' ,
start ,
end ,
local
} ;
} ,
2024-01-31 06:33:19 +00:00
function importSpecifier ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const importedPosition = buffer [ position ++ ] ;
const local = convertNode ( buffer [ position ] , buffer , readString ) ;
return {
type : 'ImportSpecifier' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
imported : importedPosition === 0 ? { ... local } : convertNode ( importedPosition , buffer , readString ) ,
2024-01-05 12:14:38 +00:00
local
} ;
} ,
2024-01-31 06:33:19 +00:00
function labeledStatement ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const body = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const label = convertNode ( position , buffer , readString ) ;
return {
type : 'LabeledStatement' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
label ,
body
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function literalBigInt ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const raw = convertString ( buffer [ position ++ ] , buffer , readString ) ;
const bigint = convertString ( position , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
return {
type : 'Literal' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
bigint ,
2024-01-05 12:14:38 +00:00
raw ,
2024-01-31 06:33:19 +00:00
value : BigInt ( bigint )
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function literalBoolean ( position , buffer ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const flags = buffer [ position ++ ] ;
const value = ( flags & 1 ) === 1 ;
2024-01-05 12:14:38 +00:00
return {
type : 'Literal' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
value ,
raw : value ? 'true' : 'false'
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function literalNull ( position , buffer ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
return {
type : 'Literal' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
raw : 'null' ,
value : null
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function literalNumber ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const rawPosition = buffer [ position ++ ] ;
const raw = rawPosition === 0 ? undefined : convertString ( rawPosition , buffer , readString ) ;
const value = new DataView ( buffer . buffer ) . getFloat64 ( position << 2 , true ) ;
2024-01-05 12:14:38 +00:00
return {
type : 'Literal' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
raw ,
value
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function literalRegExp ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const pattern = convertString ( buffer [ position ++ ] , buffer , readString ) ;
const flags = convertString ( position , buffer , readString ) ;
return {
type : 'Literal' ,
start ,
end ,
raw : ` / ${ pattern } / ${ flags } ` ,
2024-01-31 06:33:19 +00:00
regex : { flags , pattern } ,
2024-01-05 12:14:38 +00:00
value : new RegExp ( pattern , flags )
} ;
} ,
2024-01-31 06:33:19 +00:00
function literalString ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const rawPosition = buffer [ position ++ ] ;
const raw = rawPosition === 0 ? undefined : convertString ( rawPosition , buffer , readString ) ;
const value = convertString ( position , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
return {
type : 'Literal' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
value ,
raw
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function logicalExpression ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const operator = FIXED _STRINGS [ buffer [ position ++ ] ] ;
const right = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const left = convertNode ( position , buffer , readString ) ;
return {
type : 'LogicalExpression' ,
start ,
end ,
operator ,
2024-01-31 06:33:19 +00:00
left ,
2024-01-05 12:14:38 +00:00
right
} ;
} ,
2024-01-31 06:33:19 +00:00
function memberExpression ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const flags = buffer [ position ++ ] ;
const computed = ( flags & 1 ) === 1 ;
const optional = ( flags & 2 ) === 2 ;
2024-01-05 12:14:38 +00:00
const property = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const object = convertNode ( position , buffer , readString ) ;
return {
type : 'MemberExpression' ,
start ,
end ,
computed ,
optional ,
2024-01-31 06:33:19 +00:00
object ,
2024-01-05 12:14:38 +00:00
property
} ;
} ,
2024-01-31 06:33:19 +00:00
function metaProperty ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const property = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const meta = convertNode ( position , buffer , readString ) ;
return {
type : 'MetaProperty' ,
start ,
end ,
meta ,
property
} ;
} ,
2024-01-31 06:33:19 +00:00
function methodDefinition ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const flags = buffer [ position ++ ] ;
const computed = ( flags & 1 ) === 1 ;
const isStatic = ( flags & 2 ) === 2 ;
2024-01-05 12:14:38 +00:00
const value = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
2024-01-31 06:33:19 +00:00
const kind = FIXED _STRINGS [ buffer [ position ++ ] ] ;
2024-01-05 12:14:38 +00:00
const key = convertNode ( position , buffer , readString ) ;
return {
type : 'MethodDefinition' ,
start ,
end ,
computed ,
static : isStatic ,
2024-01-31 06:33:19 +00:00
key ,
value ,
kind
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function newExpression ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const callee = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
2024-01-31 06:33:19 +00:00
const callArguments = convertNodeList ( buffer [ position ++ ] , buffer , readString ) ;
const annotations = convertAnnotations ( position , buffer ) ;
return {
2024-01-05 12:14:38 +00:00
type : 'NewExpression' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
... ( annotations . length > 0 ? { [ ANNOTATION _KEY ] : annotations } : { } ) ,
callee ,
arguments : callArguments
} ;
2024-01-05 12:14:38 +00:00
} ,
2024-01-31 06:33:19 +00:00
function objectExpression ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const properties = convertNodeList ( position , buffer , readString ) ;
return {
type : 'ObjectExpression' ,
start ,
end ,
properties
} ;
} ,
2024-01-31 06:33:19 +00:00
function objectPattern ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const properties = convertNodeList ( position , buffer , readString ) ;
return {
type : 'ObjectPattern' ,
start ,
end ,
properties
} ;
} ,
2024-01-31 06:33:19 +00:00
function privateIdentifier ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const name = convertString ( position , buffer , readString ) ;
return {
type : 'PrivateIdentifier' ,
start ,
end ,
name
} ;
} ,
2024-01-31 06:33:19 +00:00
function program ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const annotations = convertAnnotations ( buffer [ position ++ ] , buffer ) ;
2024-01-05 12:14:38 +00:00
const body = convertNodeList ( position , buffer , readString ) ;
2024-01-31 06:33:19 +00:00
return {
2024-01-05 12:14:38 +00:00
type : 'Program' ,
start ,
end ,
body ,
2024-01-31 06:33:19 +00:00
... ( annotations . length > 0 ? { [ INVALID _ANNOTATION _KEY ] : annotations } : { } ) ,
2024-01-05 12:14:38 +00:00
sourceType : 'module'
2024-01-31 06:33:19 +00:00
} ;
2024-01-05 12:14:38 +00:00
} ,
2024-01-31 06:33:19 +00:00
function property ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const flags = buffer [ position ++ ] ;
const method = ( flags & 1 ) === 1 ;
const shorthand = ( flags & 2 ) === 2 ;
const computed = ( flags & 4 ) === 4 ;
const keyPosition = buffer [ position ++ ] ;
const value = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const kind = FIXED _STRINGS [ buffer [ position ] ] ;
2024-01-05 12:14:38 +00:00
return {
type : 'Property' ,
start ,
end ,
method ,
shorthand ,
2024-01-31 06:33:19 +00:00
computed ,
key : keyPosition === 0 ? { ... value } : convertNode ( keyPosition , buffer , readString ) ,
value ,
kind
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function propertyDefinition ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const flags = buffer [ position ++ ] ;
const computed = ( flags & 1 ) === 1 ;
const isStatic = ( flags & 2 ) === 2 ;
2024-01-05 12:14:38 +00:00
const valuePosition = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const value = valuePosition === 0 ? null : convertNode ( valuePosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const key = convertNode ( position , buffer , readString ) ;
return {
type : 'PropertyDefinition' ,
start ,
end ,
computed ,
static : isStatic ,
2024-01-31 06:33:19 +00:00
key ,
value
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function restElement ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const argument = convertNode ( position , buffer , readString ) ;
return {
type : 'RestElement' ,
start ,
end ,
argument
} ;
} ,
2024-01-31 06:33:19 +00:00
function returnStatement ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const argumentPosition = buffer [ position ] ;
2024-01-31 06:33:19 +00:00
const argument = argumentPosition === 0 ? null : convertNode ( argumentPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
return {
type : 'ReturnStatement' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
argument
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function sequenceExpression ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const expressions = convertNodeList ( position , buffer , readString ) ;
return {
type : 'SequenceExpression' ,
start ,
end ,
expressions
} ;
} ,
2024-01-31 06:33:19 +00:00
function spreadElement ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const argument = convertNode ( position , buffer , readString ) ;
return {
type : 'SpreadElement' ,
start ,
end ,
argument
} ;
} ,
2024-01-31 06:33:19 +00:00
function staticBlock ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const body = convertNodeList ( position , buffer , readString ) ;
return {
type : 'StaticBlock' ,
start ,
end ,
body
} ;
} ,
2024-01-31 06:33:19 +00:00
function superElement ( position , buffer ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
return {
type : 'Super' ,
start ,
end
} ;
} ,
2024-01-31 06:33:19 +00:00
function switchCase ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const testPosition = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const test = testPosition === 0 ? null : convertNode ( testPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const consequent = convertNodeList ( buffer [ position ] , buffer , readString ) ;
return {
type : 'SwitchCase' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
test ,
consequent
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function switchStatement ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const cases = convertNodeList ( buffer [ position ++ ] , buffer , readString ) ;
const discriminant = convertNode ( position , buffer , readString ) ;
return {
type : 'SwitchStatement' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
discriminant ,
cases
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function taggedTemplateExpression ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const quasi = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const tag = convertNode ( position , buffer , readString ) ;
return {
type : 'TaggedTemplateExpression' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
tag ,
quasi
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function templateElement ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const flags = buffer [ position ++ ] ;
const tail = ( flags & 1 ) === 1 ;
2024-01-05 12:14:38 +00:00
const cookedPosition = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const cooked = cookedPosition === 0 ? undefined : convertString ( cookedPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const raw = convertString ( position , buffer , readString ) ;
return {
type : 'TemplateElement' ,
start ,
end ,
tail ,
2024-01-31 06:33:19 +00:00
value : { cooked , raw }
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function templateLiteral ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const expressions = convertNodeList ( buffer [ position ++ ] , buffer , readString ) ;
const quasis = convertNodeList ( position , buffer , readString ) ;
return {
type : 'TemplateLiteral' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
quasis ,
expressions
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function thisExpression ( position , buffer ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
return {
type : 'ThisExpression' ,
start ,
end
} ;
} ,
2024-01-31 06:33:19 +00:00
function throwStatement ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const argument = convertNode ( position , buffer , readString ) ;
return {
type : 'ThrowStatement' ,
start ,
end ,
argument
} ;
} ,
2024-01-31 06:33:19 +00:00
function tryStatement ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const handlerPosition = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const handler = handlerPosition === 0 ? null : convertNode ( handlerPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const finalizerPosition = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const finalizer = finalizerPosition === 0 ? null : convertNode ( finalizerPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const block = convertNode ( position , buffer , readString ) ;
return {
type : 'TryStatement' ,
start ,
end ,
block ,
2024-01-31 06:33:19 +00:00
handler ,
finalizer
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function unaryExpression ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const operator = FIXED _STRINGS [ buffer [ position ++ ] ] ;
const argument = convertNode ( position , buffer , readString ) ;
return {
type : 'UnaryExpression' ,
start ,
end ,
operator ,
2024-01-31 06:33:19 +00:00
argument ,
2024-01-05 12:14:38 +00:00
prefix : true
} ;
} ,
2024-01-31 06:33:19 +00:00
function updateExpression ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const flags = buffer [ position ++ ] ;
const prefix = ( flags & 1 ) === 1 ;
2024-01-05 12:14:38 +00:00
const operator = FIXED _STRINGS [ buffer [ position ++ ] ] ;
const argument = convertNode ( position , buffer , readString ) ;
return {
type : 'UpdateExpression' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
prefix ,
2024-01-05 12:14:38 +00:00
operator ,
2024-01-31 06:33:19 +00:00
argument
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function variableDeclaration ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const kind = FIXED _STRINGS [ buffer [ position ++ ] ] ;
const declarations = convertNodeList ( position , buffer , readString ) ;
return {
type : 'VariableDeclaration' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
kind ,
declarations
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function variableDeclarator ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const initPosition = buffer [ position ++ ] ;
const init = initPosition === 0 ? null : convertNode ( initPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
const id = convertNode ( position , buffer , readString ) ;
return {
type : 'VariableDeclarator' ,
start ,
end ,
id ,
2024-01-31 06:33:19 +00:00
init
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function whileStatement ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const body = convertNode ( buffer [ position ++ ] , buffer , readString ) ;
const test = convertNode ( position , buffer , readString ) ;
return {
type : 'WhileStatement' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
test ,
body
2024-01-05 12:14:38 +00:00
} ;
} ,
2024-01-31 06:33:19 +00:00
function yieldExpression ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
2024-01-31 06:33:19 +00:00
const flags = buffer [ position ++ ] ;
const delegate = ( flags & 1 ) === 1 ;
2024-01-05 12:14:38 +00:00
const argumentPosition = buffer [ position ] ;
2024-01-31 06:33:19 +00:00
const argument = argumentPosition === 0 ? null : convertNode ( argumentPosition , buffer , readString ) ;
2024-01-05 12:14:38 +00:00
return {
type : 'YieldExpression' ,
start ,
end ,
2024-01-31 06:33:19 +00:00
delegate ,
argument
2024-01-05 12:14:38 +00:00
} ;
}
] ;
2024-01-31 06:33:19 +00:00
function convertNode ( position , buffer , readString ) {
const nodeType = buffer [ position ] ;
const converter = nodeConverters [ nodeType ] ;
/* istanbul ignore if: This should never be executed but is a safeguard against faulty buffers */
if ( ! converter ) {
console . trace ( ) ;
throw new Error ( ` Unknown node type: ${ nodeType } ` ) ;
}
return converter ( position + 1 , buffer , readString ) ;
}
function convertNodeList ( position , buffer , readString ) {
2024-01-05 12:14:38 +00:00
const length = buffer [ position ++ ] ;
const list = [ ] ;
for ( let index = 0 ; index < length ; index ++ ) {
const nodePosition = buffer [ position ++ ] ;
list . push ( nodePosition ? convertNode ( nodePosition , buffer , readString ) : null ) ;
}
return list ;
2024-01-31 06:33:19 +00:00
}
const convertAnnotations = ( position , buffer ) => {
2024-01-05 12:14:38 +00:00
const length = buffer [ position ++ ] ;
const list = [ ] ;
for ( let index = 0 ; index < length ; index ++ ) {
list . push ( convertAnnotation ( buffer [ position ++ ] , buffer ) ) ;
}
return list ;
} ;
const convertAnnotation = ( position , buffer ) => {
const start = buffer [ position ++ ] ;
const end = buffer [ position ++ ] ;
const type = FIXED _STRINGS [ buffer [ position ] ] ;
return { end , start , type } ;
} ;
const convertString = ( position , buffer , readString ) => {
const length = buffer [ position ++ ] ;
const bytePosition = position << 2 ;
return readString ( bytePosition , length ) ;
} ;
function getReadStringFunction ( astBuffer ) {
if ( typeof Buffer !== 'undefined' && astBuffer instanceof Buffer ) {
return function readString ( start , length ) {
return astBuffer . toString ( 'utf8' , start , start + length ) ;
} ;
}
else {
const textDecoder = new TextDecoder ( ) ;
return function readString ( start , length ) {
return textDecoder . decode ( astBuffer . subarray ( start , start + length ) ) ;
} ;
}
}
const parseAst = ( input , { allowReturnOutsideFunction = false } = { } ) => {
const astBuffer = native _js . parse ( input , allowReturnOutsideFunction ) ;
2024-01-31 06:33:19 +00:00
return convertProgram ( astBuffer . buffer , getReadStringFunction ( astBuffer ) ) ;
2024-01-05 12:14:38 +00:00
} ;
const parseAstAsync = async ( input , { allowReturnOutsideFunction = false , signal } = { } ) => {
const astBuffer = await native _js . parseAsync ( input , allowReturnOutsideFunction , signal ) ;
2024-01-31 06:33:19 +00:00
return convertProgram ( astBuffer . buffer , getReadStringFunction ( astBuffer ) ) ;
2024-01-05 12:14:38 +00:00
} ;
exports . ANNOTATION _KEY = ANNOTATION _KEY ;
exports . INVALID _ANNOTATION _KEY = INVALID _ANNOTATION _KEY ;
exports . LOGLEVEL _DEBUG = LOGLEVEL _DEBUG ;
exports . LOGLEVEL _ERROR = LOGLEVEL _ERROR ;
exports . LOGLEVEL _INFO = LOGLEVEL _INFO ;
exports . LOGLEVEL _WARN = LOGLEVEL _WARN ;
exports . URL _AVOIDING _EVAL = URL _AVOIDING _EVAL ;
exports . URL _NAME _IS _NOT _EXPORTED = URL _NAME _IS _NOT _EXPORTED ;
exports . URL _OUTPUT _AMD _BASEPATH = URL _OUTPUT _AMD _BASEPATH ;
exports . URL _OUTPUT _AMD _ID = URL _OUTPUT _AMD _ID ;
exports . URL _OUTPUT _DIR = URL _OUTPUT _DIR ;
exports . URL _OUTPUT _EXPORTS = URL _OUTPUT _EXPORTS ;
exports . URL _OUTPUT _EXTERNALIMPORTATTRIBUTES = URL _OUTPUT _EXTERNALIMPORTATTRIBUTES ;
exports . URL _OUTPUT _FORMAT = URL _OUTPUT _FORMAT ;
exports . URL _OUTPUT _GENERATEDCODE = URL _OUTPUT _GENERATEDCODE ;
exports . URL _OUTPUT _GLOBALS = URL _OUTPUT _GLOBALS ;
exports . URL _OUTPUT _INLINEDYNAMICIMPORTS = URL _OUTPUT _INLINEDYNAMICIMPORTS ;
exports . URL _OUTPUT _INTEROP = URL _OUTPUT _INTEROP ;
exports . URL _OUTPUT _MANUALCHUNKS = URL _OUTPUT _MANUALCHUNKS ;
exports . URL _OUTPUT _SOURCEMAPBASEURL = URL _OUTPUT _SOURCEMAPBASEURL ;
exports . URL _OUTPUT _SOURCEMAPFILE = URL _OUTPUT _SOURCEMAPFILE ;
exports . URL _PRESERVEENTRYSIGNATURES = URL _PRESERVEENTRYSIGNATURES ;
exports . URL _SOURCEMAP _IS _LIKELY _TO _BE _INCORRECT = URL _SOURCEMAP _IS _LIKELY _TO _BE _INCORRECT ;
exports . URL _THIS _IS _UNDEFINED = URL _THIS _IS _UNDEFINED ;
exports . URL _TREATING _MODULE _AS _EXTERNAL _DEPENDENCY = URL _TREATING _MODULE _AS _EXTERNAL _DEPENDENCY ;
exports . URL _TREESHAKE = URL _TREESHAKE ;
exports . URL _TREESHAKE _MODULESIDEEFFECTS = URL _TREESHAKE _MODULESIDEEFFECTS ;
exports . URL _WATCH = URL _WATCH ;
exports . addTrailingSlashIfMissed = addTrailingSlashIfMissed ;
exports . augmentCodeLocation = augmentCodeLocation ;
exports . error = error ;
exports . getAliasName = getAliasName ;
exports . getImportPath = getImportPath ;
exports . getRollupUrl = getRollupUrl ;
exports . isAbsolute = isAbsolute ;
exports . isPathFragment = isPathFragment ;
exports . isRelative = isRelative ;
exports . isValidUrl = isValidUrl ;
exports . locate = locate ;
exports . logAddonNotGenerated = logAddonNotGenerated ;
exports . logAlreadyClosed = logAlreadyClosed ;
exports . logAmbiguousExternalNamespaces = logAmbiguousExternalNamespaces ;
exports . logAnonymousPluginCache = logAnonymousPluginCache ;
exports . logAssetNotFinalisedForFileName = logAssetNotFinalisedForFileName ;
exports . logAssetReferenceIdNotFoundForSetSource = logAssetReferenceIdNotFoundForSetSource ;
exports . logAssetSourceAlreadySet = logAssetSourceAlreadySet ;
exports . logBadLoader = logBadLoader ;
exports . logCannotAssignModuleToChunk = logCannotAssignModuleToChunk ;
exports . logCannotBundleConfigAsEsm = logCannotBundleConfigAsEsm ;
exports . logCannotCallNamespace = logCannotCallNamespace ;
exports . logCannotEmitFromOptionsHook = logCannotEmitFromOptionsHook ;
exports . logCannotLoadConfigAsCjs = logCannotLoadConfigAsCjs ;
exports . logCannotLoadConfigAsEsm = logCannotLoadConfigAsEsm ;
exports . logChunkInvalid = logChunkInvalid ;
exports . logChunkNotGeneratedForFileName = logChunkNotGeneratedForFileName ;
exports . logCircularDependency = logCircularDependency ;
exports . logCircularReexport = logCircularReexport ;
exports . logConflictingSourcemapSources = logConflictingSourcemapSources ;
exports . logCyclicCrossChunkReexport = logCyclicCrossChunkReexport ;
exports . logDuplicateArgumentNameError = logDuplicateArgumentNameError ;
exports . logDuplicateExportError = logDuplicateExportError ;
exports . logDuplicateImportOptions = logDuplicateImportOptions ;
exports . logDuplicatePluginName = logDuplicatePluginName ;
exports . logEmptyChunk = logEmptyChunk ;
exports . logEntryCannotBeExternal = logEntryCannotBeExternal ;
exports . logEval = logEval ;
exports . logExternalModulesCannotBeIncludedInManualChunks = logExternalModulesCannotBeIncludedInManualChunks ;
exports . logExternalModulesCannotBeTransformedToModules = logExternalModulesCannotBeTransformedToModules ;
exports . logExternalSyntheticExports = logExternalSyntheticExports ;
exports . logFailAfterWarnings = logFailAfterWarnings ;
exports . logFailedValidation = logFailedValidation ;
exports . logFileNameConflict = logFileNameConflict ;
exports . logFileReferenceIdNotFoundForFilename = logFileReferenceIdNotFoundForFilename ;
exports . logFirstSideEffect = logFirstSideEffect ;
exports . logIllegalIdentifierAsName = logIllegalIdentifierAsName ;
exports . logIllegalImportReassignment = logIllegalImportReassignment ;
exports . logImplicitDependantCannotBeExternal = logImplicitDependantCannotBeExternal ;
exports . logImplicitDependantIsNotIncluded = logImplicitDependantIsNotIncluded ;
exports . logImportAttributeIsInvalid = logImportAttributeIsInvalid ;
exports . logImportOptionsAreInvalid = logImportOptionsAreInvalid ;
exports . logIncompatibleExportOptionValue = logIncompatibleExportOptionValue ;
exports . logInconsistentImportAttributes = logInconsistentImportAttributes ;
exports . logInputHookInOutputPlugin = logInputHookInOutputPlugin ;
exports . logInternalIdCannotBeExternal = logInternalIdCannotBeExternal ;
exports . logInvalidAddonPluginHook = logInvalidAddonPluginHook ;
exports . logInvalidAnnotation = logInvalidAnnotation ;
exports . logInvalidExportOptionValue = logInvalidExportOptionValue ;
exports . logInvalidFormatForTopLevelAwait = logInvalidFormatForTopLevelAwait ;
exports . logInvalidFunctionPluginHook = logInvalidFunctionPluginHook ;
exports . logInvalidLogPosition = logInvalidLogPosition ;
exports . logInvalidOption = logInvalidOption ;
exports . logInvalidRollupPhaseForChunkEmission = logInvalidRollupPhaseForChunkEmission ;
exports . logInvalidSetAssetSourceCall = logInvalidSetAssetSourceCall ;
exports . logInvalidSourcemapForError = logInvalidSourcemapForError ;
exports . logLevelPriority = logLevelPriority ;
exports . logMissingConfig = logMissingConfig ;
exports . logMissingEntryExport = logMissingEntryExport ;
exports . logMissingExport = logMissingExport ;
exports . logMissingExternalConfig = logMissingExternalConfig ;
exports . logMissingFileOrDirOption = logMissingFileOrDirOption ;
exports . logMissingGlobalName = logMissingGlobalName ;
exports . logMissingNameOptionForIifeExport = logMissingNameOptionForIifeExport ;
exports . logMissingNameOptionForUmdExport = logMissingNameOptionForUmdExport ;
exports . logMissingNodeBuiltins = logMissingNodeBuiltins ;
exports . logMixedExport = logMixedExport ;
exports . logModuleLevelDirective = logModuleLevelDirective ;
exports . logModuleParseError = logModuleParseError ;
exports . logNamespaceConflict = logNamespaceConflict ;
exports . logNoAssetSourceSet = logNoAssetSourceSet ;
exports . logNoTransformMapOrAstWithoutCode = logNoTransformMapOrAstWithoutCode ;
exports . logOnlyInlineSourcemapsForStdout = logOnlyInlineSourcemapsForStdout ;
exports . logOptimizeChunkStatus = logOptimizeChunkStatus ;
exports . logPluginError = logPluginError ;
exports . logRedeclarationError = logRedeclarationError ;
exports . logShimmedExport = logShimmedExport ;
exports . logSourcemapBroken = logSourcemapBroken ;
exports . logSyntheticNamedExportsNeedNamespaceExport = logSyntheticNamedExportsNeedNamespaceExport ;
exports . logThisIsUndefined = logThisIsUndefined ;
exports . logUnexpectedNamedImport = logUnexpectedNamedImport ;
exports . logUnexpectedNamespaceReexport = logUnexpectedNamespaceReexport ;
exports . logUnknownOption = logUnknownOption ;
exports . logUnresolvedEntry = logUnresolvedEntry ;
exports . logUnresolvedImplicitDependant = logUnresolvedImplicitDependant ;
exports . logUnresolvedImport = logUnresolvedImport ;
exports . logUnresolvedImportTreatedAsExternal = logUnresolvedImportTreatedAsExternal ;
exports . logUnusedExternalImports = logUnusedExternalImports ;
exports . normalize = normalize ;
exports . parseAst = parseAst ;
exports . parseAstAsync = parseAstAsync ;
exports . printQuotedStringList = printQuotedStringList ;
exports . relative = relative ;
exports . relativeId = relativeId ;
exports . warnDeprecation = warnDeprecation ;
//# sourceMappingURL=parseAst.js.map