123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856 |
- export interface Node {
- start: number
- end: number
- type: string
- range?: [number, number]
- loc?: SourceLocation | null
- }
- export interface SourceLocation {
- source?: string | null
- start: Position
- end: Position
- }
- export interface Position {
- /** 1-based */
- line: number
- /** 0-based */
- column: number
- }
- export interface Identifier extends Node {
- type: "Identifier"
- name: string
- }
- export interface Literal extends Node {
- type: "Literal"
- value?: string | boolean | null | number | RegExp | bigint
- raw?: string
- regex?: {
- pattern: string
- flags: string
- }
- bigint?: string
- }
- export interface Program extends Node {
- type: "Program"
- body: Array<Statement | ModuleDeclaration>
- sourceType: "script" | "module"
- }
- export interface Function extends Node {
- id?: Identifier | null
- params: Array<Pattern>
- body: BlockStatement | Expression
- generator: boolean
- expression: boolean
- async: boolean
- }
- export interface ExpressionStatement extends Node {
- type: "ExpressionStatement"
- expression: Expression | Literal
- directive?: string
- }
- export interface BlockStatement extends Node {
- type: "BlockStatement"
- body: Array<Statement>
- }
- export interface EmptyStatement extends Node {
- type: "EmptyStatement"
- }
- export interface DebuggerStatement extends Node {
- type: "DebuggerStatement"
- }
- export interface WithStatement extends Node {
- type: "WithStatement"
- object: Expression
- body: Statement
- }
- export interface ReturnStatement extends Node {
- type: "ReturnStatement"
- argument?: Expression | null
- }
- export interface LabeledStatement extends Node {
- type: "LabeledStatement"
- label: Identifier
- body: Statement
- }
- export interface BreakStatement extends Node {
- type: "BreakStatement"
- label?: Identifier | null
- }
- export interface ContinueStatement extends Node {
- type: "ContinueStatement"
- label?: Identifier | null
- }
- export interface IfStatement extends Node {
- type: "IfStatement"
- test: Expression
- consequent: Statement
- alternate?: Statement | null
- }
- export interface SwitchStatement extends Node {
- type: "SwitchStatement"
- discriminant: Expression
- cases: Array<SwitchCase>
- }
- export interface SwitchCase extends Node {
- type: "SwitchCase"
- test?: Expression | null
- consequent: Array<Statement>
- }
- export interface ThrowStatement extends Node {
- type: "ThrowStatement"
- argument: Expression
- }
- export interface TryStatement extends Node {
- type: "TryStatement"
- block: BlockStatement
- handler?: CatchClause | null
- finalizer?: BlockStatement | null
- }
- export interface CatchClause extends Node {
- type: "CatchClause"
- param?: Pattern | null
- body: BlockStatement
- }
- export interface WhileStatement extends Node {
- type: "WhileStatement"
- test: Expression
- body: Statement
- }
- export interface DoWhileStatement extends Node {
- type: "DoWhileStatement"
- body: Statement
- test: Expression
- }
- export interface ForStatement extends Node {
- type: "ForStatement"
- init?: VariableDeclaration | Expression | null
- test?: Expression | null
- update?: Expression | null
- body: Statement
- }
- export interface ForInStatement extends Node {
- type: "ForInStatement"
- left: VariableDeclaration | Pattern
- right: Expression
- body: Statement
- }
- export interface FunctionDeclaration extends Function {
- type: "FunctionDeclaration"
- id: Identifier
- body: BlockStatement
- }
- export interface VariableDeclaration extends Node {
- type: "VariableDeclaration"
- declarations: Array<VariableDeclarator>
- kind: "var" | "let" | "const"
- }
- export interface VariableDeclarator extends Node {
- type: "VariableDeclarator"
- id: Pattern
- init?: Expression | null
- }
- export interface ThisExpression extends Node {
- type: "ThisExpression"
- }
- export interface ArrayExpression extends Node {
- type: "ArrayExpression"
- elements: Array<Expression | SpreadElement | null>
- }
- export interface ObjectExpression extends Node {
- type: "ObjectExpression"
- properties: Array<Property | SpreadElement>
- }
- export interface Property extends Node {
- type: "Property"
- key: Expression
- value: Expression
- kind: "init" | "get" | "set"
- method: boolean
- shorthand: boolean
- computed: boolean
- }
- export interface FunctionExpression extends Function {
- type: "FunctionExpression"
- body: BlockStatement
- }
- export interface UnaryExpression extends Node {
- type: "UnaryExpression"
- operator: UnaryOperator
- prefix: boolean
- argument: Expression
- }
- export type UnaryOperator = "-" | "+" | "!" | "~" | "typeof" | "void" | "delete"
- export interface UpdateExpression extends Node {
- type: "UpdateExpression"
- operator: UpdateOperator
- argument: Expression
- prefix: boolean
- }
- export type UpdateOperator = "++" | "--"
- export interface BinaryExpression extends Node {
- type: "BinaryExpression"
- operator: BinaryOperator
- left: Expression | PrivateIdentifier
- right: Expression
- }
- export type BinaryOperator = "==" | "!=" | "===" | "!==" | "<" | "<=" | ">" | ">=" | "<<" | ">>" | ">>>" | "+" | "-" | "*" | "/" | "%" | "|" | "^" | "&" | "in" | "instanceof" | "**"
- export interface AssignmentExpression extends Node {
- type: "AssignmentExpression"
- operator: AssignmentOperator
- left: Pattern
- right: Expression
- }
- export type AssignmentOperator = "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "<<=" | ">>=" | ">>>=" | "|=" | "^=" | "&=" | "**=" | "||=" | "&&=" | "??="
- export interface LogicalExpression extends Node {
- type: "LogicalExpression"
- operator: LogicalOperator
- left: Expression
- right: Expression
- }
- export type LogicalOperator = "||" | "&&" | "??"
- export interface MemberExpression extends Node {
- type: "MemberExpression"
- object: Expression | Super
- property: Expression | PrivateIdentifier
- computed: boolean
- optional: boolean
- }
- export interface ConditionalExpression extends Node {
- type: "ConditionalExpression"
- test: Expression
- alternate: Expression
- consequent: Expression
- }
- export interface CallExpression extends Node {
- type: "CallExpression"
- callee: Expression | Super
- arguments: Array<Expression | SpreadElement>
- optional: boolean
- }
- export interface NewExpression extends Node {
- type: "NewExpression"
- callee: Expression
- arguments: Array<Expression | SpreadElement>
- }
- export interface SequenceExpression extends Node {
- type: "SequenceExpression"
- expressions: Array<Expression>
- }
- export interface ForOfStatement extends Node {
- type: "ForOfStatement"
- left: VariableDeclaration | Pattern
- right: Expression
- body: Statement
- await: boolean
- }
- export interface Super extends Node {
- type: "Super"
- }
- export interface SpreadElement extends Node {
- type: "SpreadElement"
- argument: Expression
- }
- export interface ArrowFunctionExpression extends Function {
- type: "ArrowFunctionExpression"
- }
- export interface YieldExpression extends Node {
- type: "YieldExpression"
- argument?: Expression | null
- delegate: boolean
- }
- export interface TemplateLiteral extends Node {
- type: "TemplateLiteral"
- quasis: Array<TemplateElement>
- expressions: Array<Expression>
- }
- export interface TaggedTemplateExpression extends Node {
- type: "TaggedTemplateExpression"
- tag: Expression
- quasi: TemplateLiteral
- }
- export interface TemplateElement extends Node {
- type: "TemplateElement"
- tail: boolean
- value: {
- cooked?: string | null
- raw: string
- }
- }
- export interface AssignmentProperty extends Node {
- type: "Property"
- key: Expression
- value: Pattern
- kind: "init"
- method: false
- shorthand: boolean
- computed: boolean
- }
- export interface ObjectPattern extends Node {
- type: "ObjectPattern"
- properties: Array<AssignmentProperty | RestElement>
- }
- export interface ArrayPattern extends Node {
- type: "ArrayPattern"
- elements: Array<Pattern | null>
- }
- export interface RestElement extends Node {
- type: "RestElement"
- argument: Pattern
- }
- export interface AssignmentPattern extends Node {
- type: "AssignmentPattern"
- left: Pattern
- right: Expression
- }
- export interface Class extends Node {
- id?: Identifier | null
- superClass?: Expression | null
- body: ClassBody
- }
- export interface ClassBody extends Node {
- type: "ClassBody"
- body: Array<MethodDefinition | PropertyDefinition | StaticBlock>
- }
- export interface MethodDefinition extends Node {
- type: "MethodDefinition"
- key: Expression | PrivateIdentifier
- value: FunctionExpression
- kind: "constructor" | "method" | "get" | "set"
- computed: boolean
- static: boolean
- }
- export interface ClassDeclaration extends Class {
- type: "ClassDeclaration"
- id: Identifier
- }
- export interface ClassExpression extends Class {
- type: "ClassExpression"
- }
- export interface MetaProperty extends Node {
- type: "MetaProperty"
- meta: Identifier
- property: Identifier
- }
- export interface ImportDeclaration extends Node {
- type: "ImportDeclaration"
- specifiers: Array<ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier>
- source: Literal
- }
- export interface ImportSpecifier extends Node {
- type: "ImportSpecifier"
- imported: Identifier | Literal
- local: Identifier
- }
- export interface ImportDefaultSpecifier extends Node {
- type: "ImportDefaultSpecifier"
- local: Identifier
- }
- export interface ImportNamespaceSpecifier extends Node {
- type: "ImportNamespaceSpecifier"
- local: Identifier
- }
- export interface ExportNamedDeclaration extends Node {
- type: "ExportNamedDeclaration"
- declaration?: Declaration | null
- specifiers: Array<ExportSpecifier>
- source?: Literal | null
- }
- export interface ExportSpecifier extends Node {
- type: "ExportSpecifier"
- exported: Identifier | Literal
- local: Identifier | Literal
- }
- export interface AnonymousFunctionDeclaration extends Function {
- type: "FunctionDeclaration"
- id: null
- body: BlockStatement
- }
- export interface AnonymousClassDeclaration extends Class {
- type: "ClassDeclaration"
- id: null
- }
- export interface ExportDefaultDeclaration extends Node {
- type: "ExportDefaultDeclaration"
- declaration: AnonymousFunctionDeclaration | FunctionDeclaration | AnonymousClassDeclaration | ClassDeclaration | Expression
- }
- export interface ExportAllDeclaration extends Node {
- type: "ExportAllDeclaration"
- source: Literal
- exported?: Identifier | Literal | null
- }
- export interface AwaitExpression extends Node {
- type: "AwaitExpression"
- argument: Expression
- }
- export interface ChainExpression extends Node {
- type: "ChainExpression"
- expression: MemberExpression | CallExpression
- }
- export interface ImportExpression extends Node {
- type: "ImportExpression"
- source: Expression
- }
- export interface ParenthesizedExpression extends Node {
- type: "ParenthesizedExpression"
- expression: Expression
- }
- export interface PropertyDefinition extends Node {
- type: "PropertyDefinition"
- key: Expression | PrivateIdentifier
- value?: Expression | null
- computed: boolean
- static: boolean
- }
- export interface PrivateIdentifier extends Node {
- type: "PrivateIdentifier"
- name: string
- }
- export interface StaticBlock extends Node {
- type: "StaticBlock"
- body: Array<Statement>
- }
- export type Statement =
- | ExpressionStatement
- | BlockStatement
- | EmptyStatement
- | DebuggerStatement
- | WithStatement
- | ReturnStatement
- | LabeledStatement
- | BreakStatement
- | ContinueStatement
- | IfStatement
- | SwitchStatement
- | ThrowStatement
- | TryStatement
- | WhileStatement
- | DoWhileStatement
- | ForStatement
- | ForInStatement
- | ForOfStatement
- | Declaration
- export type Declaration =
- | FunctionDeclaration
- | VariableDeclaration
- | ClassDeclaration
- export type Expression =
- | Identifier
- | Literal
- | ThisExpression
- | ArrayExpression
- | ObjectExpression
- | FunctionExpression
- | UnaryExpression
- | UpdateExpression
- | BinaryExpression
- | AssignmentExpression
- | LogicalExpression
- | MemberExpression
- | ConditionalExpression
- | CallExpression
- | NewExpression
- | SequenceExpression
- | ArrowFunctionExpression
- | YieldExpression
- | TemplateLiteral
- | TaggedTemplateExpression
- | ClassExpression
- | MetaProperty
- | AwaitExpression
- | ChainExpression
- | ImportExpression
- | ParenthesizedExpression
- export type Pattern =
- | Identifier
- | MemberExpression
- | ObjectPattern
- | ArrayPattern
- | RestElement
- | AssignmentPattern
- export type ModuleDeclaration =
- | ImportDeclaration
- | ExportNamedDeclaration
- | ExportDefaultDeclaration
- | ExportAllDeclaration
- export type AnyNode = Statement | Expression | Declaration | ModuleDeclaration | Literal | Program | SwitchCase | CatchClause | Property | Super | SpreadElement | TemplateElement | AssignmentProperty | ObjectPattern | ArrayPattern | RestElement | AssignmentPattern | ClassBody | MethodDefinition | MetaProperty | ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier | ExportSpecifier | AnonymousFunctionDeclaration | AnonymousClassDeclaration | PropertyDefinition | PrivateIdentifier | StaticBlock | VariableDeclarator
- export function parse(input: string, options: Options): Program
- export function parseExpressionAt(input: string, pos: number, options: Options): Expression
- export function tokenizer(input: string, options: Options): {
- getToken(): Token
- [Symbol.iterator](): Iterator<Token>
- }
- export type ecmaVersion = 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 2024 | 2025 | "latest"
- export interface Options {
- /**
- * `ecmaVersion` indicates the ECMAScript version to parse. Can be a
- * number, either in year (`2022`) or plain version number (`6`) form,
- * or `"latest"` (the latest the library supports). This influences
- * support for strict mode, the set of reserved words, and support for
- * new syntax features.
- */
- ecmaVersion: ecmaVersion
- /**
- * `sourceType` indicates the mode the code should be parsed in.
- * Can be either `"script"` or `"module"`. This influences global
- * strict mode and parsing of `import` and `export` declarations.
- */
- sourceType?: "script" | "module"
- /**
- * a callback that will be called when a semicolon is automatically inserted.
- * @param lastTokEnd the position of the comma as an offset
- * @param lastTokEndLoc location if {@link locations} is enabled
- */
- onInsertedSemicolon?: (lastTokEnd: number, lastTokEndLoc?: Position) => void
- /**
- * similar to `onInsertedSemicolon`, but for trailing commas
- * @param lastTokEnd the position of the comma as an offset
- * @param lastTokEndLoc location if `locations` is enabled
- */
- onTrailingComma?: (lastTokEnd: number, lastTokEndLoc?: Position) => void
- /**
- * By default, reserved words are only enforced if ecmaVersion >= 5.
- * Set `allowReserved` to a boolean value to explicitly turn this on
- * an off. When this option has the value "never", reserved words
- * and keywords can also not be used as property names.
- */
- allowReserved?: boolean | "never"
- /**
- * When enabled, a return at the top level is not considered an error.
- */
- allowReturnOutsideFunction?: boolean
- /**
- * When enabled, import/export statements are not constrained to
- * appearing at the top of the program, and an import.meta expression
- * in a script isn't considered an error.
- */
- allowImportExportEverywhere?: boolean
- /**
- * By default, `await` identifiers are allowed to appear at the top-level scope only if {@link ecmaVersion} >= 2022.
- * When enabled, await identifiers are allowed to appear at the top-level scope,
- * but they are still not allowed in non-async functions.
- */
- allowAwaitOutsideFunction?: boolean
- /**
- * When enabled, super identifiers are not constrained to
- * appearing in methods and do not raise an error when they appear elsewhere.
- */
- allowSuperOutsideMethod?: boolean
- /**
- * When enabled, hashbang directive in the beginning of file is
- * allowed and treated as a line comment. Enabled by default when
- * {@link ecmaVersion} >= 2023.
- */
- allowHashBang?: boolean
- /**
- * By default, the parser will verify that private properties are
- * only used in places where they are valid and have been declared.
- * Set this to false to turn such checks off.
- */
- checkPrivateFields?: boolean
- /**
- * When `locations` is on, `loc` properties holding objects with
- * `start` and `end` properties as {@link Position} objects will be attached to the
- * nodes.
- */
- locations?: boolean
- /**
- * a callback that will cause Acorn to call that export function with object in the same
- * format as tokens returned from `tokenizer().getToken()`. Note
- * that you are not allowed to call the parser from the
- * callback—that will corrupt its internal state.
- */
- onToken?: ((token: Token) => void) | Token[]
- /**
- * This takes a export function or an array.
- *
- * When a export function is passed, Acorn will call that export function with `(block, text, start,
- * end)` parameters whenever a comment is skipped. `block` is a
- * boolean indicating whether this is a block (`/* *\/`) comment,
- * `text` is the content of the comment, and `start` and `end` are
- * character offsets that denote the start and end of the comment.
- * When the {@link locations} option is on, two more parameters are
- * passed, the full locations of {@link Position} export type of the start and
- * end of the comments.
- *
- * When a array is passed, each found comment of {@link Comment} export type is pushed to the array.
- *
- * Note that you are not allowed to call the
- * parser from the callback—that will corrupt its internal state.
- */
- onComment?: ((
- isBlock: boolean, text: string, start: number, end: number, startLoc?: Position,
- endLoc?: Position
- ) => void) | Comment[]
- /**
- * Nodes have their start and end characters offsets recorded in
- * `start` and `end` properties (directly on the node, rather than
- * the `loc` object, which holds line/column data. To also add a
- * [semi-standardized][range] `range` property holding a `[start,
- * end]` array with the same numbers, set the `ranges` option to
- * `true`.
- */
- ranges?: boolean
- /**
- * It is possible to parse multiple files into a single AST by
- * passing the tree produced by parsing the first file as
- * `program` option in subsequent parses. This will add the
- * toplevel forms of the parsed file to the `Program` (top) node
- * of an existing parse tree.
- */
- program?: Node
- /**
- * When {@link locations} is on, you can pass this to record the source
- * file in every node's `loc` object.
- */
- sourceFile?: string
- /**
- * This value, if given, is stored in every node, whether {@link locations} is on or off.
- */
- directSourceFile?: string
- /**
- * When enabled, parenthesized expressions are represented by
- * (non-standard) ParenthesizedExpression nodes
- */
- preserveParens?: boolean
- }
-
- export class Parser {
- options: Options
- input: string
-
- protected constructor(options: Options, input: string, startPos?: number)
- parse(): Program
-
- static parse(input: string, options: Options): Program
- static parseExpressionAt(input: string, pos: number, options: Options): Expression
- static tokenizer(input: string, options: Options): {
- getToken(): Token
- [Symbol.iterator](): Iterator<Token>
- }
- static extend(...plugins: ((BaseParser: typeof Parser) => typeof Parser)[]): typeof Parser
- }
- export const defaultOptions: Options
- export function getLineInfo(input: string, offset: number): Position
- export class TokenType {
- label: string
- keyword: string | undefined
- }
- export const tokTypes: {
- num: TokenType
- regexp: TokenType
- string: TokenType
- name: TokenType
- privateId: TokenType
- eof: TokenType
- bracketL: TokenType
- bracketR: TokenType
- braceL: TokenType
- braceR: TokenType
- parenL: TokenType
- parenR: TokenType
- comma: TokenType
- semi: TokenType
- colon: TokenType
- dot: TokenType
- question: TokenType
- questionDot: TokenType
- arrow: TokenType
- template: TokenType
- invalidTemplate: TokenType
- ellipsis: TokenType
- backQuote: TokenType
- dollarBraceL: TokenType
- eq: TokenType
- assign: TokenType
- incDec: TokenType
- prefix: TokenType
- logicalOR: TokenType
- logicalAND: TokenType
- bitwiseOR: TokenType
- bitwiseXOR: TokenType
- bitwiseAND: TokenType
- equality: TokenType
- relational: TokenType
- bitShift: TokenType
- plusMin: TokenType
- modulo: TokenType
- star: TokenType
- slash: TokenType
- starstar: TokenType
- coalesce: TokenType
- _break: TokenType
- _case: TokenType
- _catch: TokenType
- _continue: TokenType
- _debugger: TokenType
- _default: TokenType
- _do: TokenType
- _else: TokenType
- _finally: TokenType
- _for: TokenType
- _function: TokenType
- _if: TokenType
- _return: TokenType
- _switch: TokenType
- _throw: TokenType
- _try: TokenType
- _var: TokenType
- _const: TokenType
- _while: TokenType
- _with: TokenType
- _new: TokenType
- _this: TokenType
- _super: TokenType
- _class: TokenType
- _extends: TokenType
- _export: TokenType
- _import: TokenType
- _null: TokenType
- _true: TokenType
- _false: TokenType
- _in: TokenType
- _instanceof: TokenType
- _typeof: TokenType
- _void: TokenType
- _delete: TokenType
- }
- export interface Comment {
- type: "Line" | "Block"
- value: string
- start: number
- end: number
- loc?: SourceLocation
- range?: [number, number]
- }
- export class Token {
- type: TokenType
- start: number
- end: number
- loc?: SourceLocation
- range?: [number, number]
- }
- export const version: string
|