|
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 { |
|
|
|
line: number |
|
|
|
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 |
|
|
|
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 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 2024 | "latest" |
|
|
|
export interface Options { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ecmaVersion: ecmaVersion |
|
|
|
|
|
|
|
|
|
|
|
|
|
sourceType?: "script" | "module" |
|
|
|
|
|
|
|
|
|
|
|
|
|
onInsertedSemicolon?: (lastTokEnd: number, lastTokEndLoc?: Position) => void |
|
|
|
|
|
|
|
|
|
|
|
|
|
onTrailingComma?: (lastTokEnd: number, lastTokEndLoc?: Position) => void |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
allowReserved?: boolean | "never" |
|
|
|
|
|
|
|
|
|
allowReturnOutsideFunction?: boolean |
|
|
|
|
|
|
|
|
|
|
|
|
|
allowImportExportEverywhere?: boolean |
|
|
|
|
|
|
|
|
|
|
|
|
|
allowAwaitOutsideFunction?: boolean |
|
|
|
|
|
|
|
|
|
|
|
allowSuperOutsideMethod?: boolean |
|
|
|
|
|
|
|
|
|
|
|
|
|
allowHashBang?: boolean |
|
|
|
|
|
|
|
|
|
|
|
|
|
checkPrivateFields?: boolean |
|
|
|
|
|
|
|
|
|
|
|
|
|
locations?: boolean |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onToken?: ((token: Token) => void) | Token[] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onComment?: (( |
|
isBlock: boolean, text: string, start: number, end: number, startLoc?: Position, |
|
endLoc?: Position |
|
) => void) | Comment[] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ranges?: boolean |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
program?: Node |
|
|
|
|
|
|
|
|
|
|
|
sourceFile?: string |
|
|
|
|
|
|
|
|
|
directSourceFile?: string |
|
|
|
|
|
|
|
|
|
|
|
preserveParens?: boolean |
|
} |
|
|
|
export class Parser { |
|
options: Options |
|
input: string |
|
|
|
private 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 |
|
|