import { type Position } from "./tokenizer.js"; import { type ExportDefaultDeclaration, type ExportNamedDeclaration } from "./parse-export.js"; export type { ExportDefaultDeclaration, ExportNamedDeclaration } from "./parse-export.js"; export type SourceSpan = { start: Position; end: Position; }; export declare class DisallowedSyntaxError extends Error { constructor(syntax: string, position: Position); } type BaseNode = { nodeId?: number; type: string; span: SourceSpan; }; export type Identifier = BaseNode & { type: "Identifier"; name: string; }; export type ThisExpression = BaseNode & { type: "ThisExpression"; }; export type NumericLiteral = BaseNode & { type: "NumericLiteral"; raw: string; value: number; }; export type StringLiteral = BaseNode & { type: "StringLiteral"; raw: string; value: string; }; export type RegexLiteral = BaseNode & { type: "RegexLiteral"; raw: string; }; export type BooleanLiteral = BaseNode & { type: "BooleanLiteral"; raw: "true" | "false"; value: boolean; }; export type NullLiteral = BaseNode & { type: "NullLiteral"; raw: "null"; value: null; }; export type UndefinedLiteral = BaseNode & { type: "UndefinedLiteral"; raw: "undefined"; value: undefined; elision?: true; }; export type TemplateElement = BaseNode & { type: "TemplateElement"; tail: boolean; value: { raw: string; cooked: string | undefined; }; }; export type TemplateLiteral = BaseNode & { type: "TemplateLiteral"; expressions: Expression[]; quasis: TemplateElement[]; }; export type TaggedTemplateExpression = BaseNode & { type: "TaggedTemplateExpression"; tag: Expression; quasi: TemplateLiteral; }; export type SpreadElement = BaseNode & { type: "SpreadElement"; argument: Expression; }; export type Property = BaseNode & { type: "Property"; computed: boolean; shorthand: boolean; key: Expression; value: Expression; }; export type PatternTarget = ArrayPattern | Identifier | MemberExpression | ObjectPattern; export type AssignmentTarget = MetaProperty | PatternTarget; export type UpdateTarget = Identifier | MemberExpression; export type AssignmentPattern = BaseNode & { type: "AssignmentPattern"; left: PatternTarget; right: Expression; }; export type RestElement = BaseNode & { type: "RestElement"; argument: PatternTarget; }; export type AssignmentProperty = BaseNode & { type: "AssignmentProperty"; computed: boolean; shorthand: boolean; key: Expression; value: AssignmentPattern | ArrayPattern | Identifier | MemberExpression | ObjectPattern; }; export type ArrayPattern = BaseNode & { type: "ArrayPattern"; elements: Array; }; export type ObjectPattern = BaseNode & { type: "ObjectPattern"; properties: Array; }; export type ArrayExpression = BaseNode & { type: "ArrayExpression"; elements: Array; }; export type ObjectExpression = BaseNode & { type: "ObjectExpression"; properties: Array; }; export type UnaryOperator = "!" | "+" | "-" | "~" | "delete" | "typeof" | "void"; export type UnaryExpression = BaseNode & { type: "UnaryExpression"; operator: UnaryOperator; prefix: true; argument: Expression; }; export type UpdateOperator = "++" | "--"; export type UpdateExpression = BaseNode & { type: "UpdateExpression"; operator: UpdateOperator; prefix: boolean; argument: UpdateTarget; }; export type AwaitExpression = BaseNode & { type: "AwaitExpression"; argument: Expression; }; export type YieldExpression = BaseNode & { type: "YieldExpression"; argument?: Expression; delegate: boolean; }; export type BinaryOperator = "!=" | "!==" | "%" | "&" | "*" | "**" | "+" | "-" | "/" | "<" | "<<" | "<=" | "==" | "===" | ">" | ">=" | ">>" | ">>>" | "instanceof" | "in" | "^" | "|"; export type BinaryExpression = BaseNode & { type: "BinaryExpression"; operator: BinaryOperator; left: Expression; right: Expression; }; export type LogicalOperator = "&&" | "??" | "||"; export type LogicalExpression = BaseNode & { type: "LogicalExpression"; operator: LogicalOperator; left: Expression; right: Expression; }; export type ConditionalExpression = BaseNode & { type: "ConditionalExpression"; test: Expression; consequent: Expression; alternate: Expression; }; export type SequenceExpression = BaseNode & { type: "SequenceExpression"; expressions: Expression[]; }; export type MemberExpression = BaseNode & { type: "MemberExpression"; computed: boolean; object: Expression; optional: boolean; property: Expression; }; export type MetaProperty = BaseNode & { type: "MetaProperty"; meta: Identifier & { name: "import"; }; property: Identifier & { name: "meta"; }; }; export type AssignmentOperator = "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "**=" | "&=" | "|=" | "^=" | "<<=" | ">>=" | ">>>=" | "&&=" | "||=" | "??="; export type AssignmentExpression = BaseNode & { type: "AssignmentExpression"; operator: AssignmentOperator; left: AssignmentTarget; right: Expression; }; export type CallExpression = BaseNode & { type: "CallExpression"; arguments: Array; callee: Expression; optional: boolean; }; export type NewExpression = BaseNode & { type: "NewExpression"; arguments: Array; callee: Expression; }; export type VariableDeclarator = BaseNode & { type: "VariableDeclarator"; id: ArrayPattern | Identifier | ObjectPattern; init?: Expression; }; export type VariableDeclarationKind = "const" | "let" | "var"; export type VariableDeclaration = BaseNode & { type: "VariableDeclaration"; declarations: VariableDeclarator[]; kind: VariableDeclarationKind; }; export type ReturnStatement = BaseNode & { type: "ReturnStatement"; argument?: Expression; }; export type BreakStatement = BaseNode & { type: "BreakStatement"; label?: string; }; export type ContinueStatement = BaseNode & { type: "ContinueStatement"; label?: string; }; export type ExpressionStatement = BaseNode & { type: "ExpressionStatement"; expression: Expression; }; export type EmptyStatement = BaseNode & { type: "EmptyStatement"; }; export type BlockStatement = BaseNode & { type: "BlockStatement"; body: Statement[]; }; export type FunctionDeclaration = BaseNode & { type: "FunctionDeclaration"; async: boolean; body: BlockStatement; generator: boolean; id: Identifier; params: ArrowFunctionExpression["params"]; }; export type FunctionExpression = BaseNode & { type: "FunctionExpression"; async: boolean; body: BlockStatement; generator: boolean; id?: Identifier; method?: true; params: ArrowFunctionExpression["params"]; }; export type IfStatement = BaseNode & { type: "IfStatement"; test: Expression; consequent: Statement; alternate?: Statement; }; export type ForStatement = BaseNode & { type: "ForStatement"; init?: Expression | VariableDeclaration; test?: Expression; update?: Expression; body: Statement; label?: string; labels?: string[]; }; export type ForOfStatement = BaseNode & { type: "ForOfStatement"; left: PatternTarget | VariableDeclaration; right: Expression; body: Statement; label?: string; labels?: string[]; }; export type ForInStatement = BaseNode & { type: "ForInStatement"; left: Identifier | VariableDeclaration; right: Expression; body: Statement; label?: string; labels?: string[]; }; export type WhileStatement = BaseNode & { type: "WhileStatement"; test: Expression; body: Statement; label?: string; labels?: string[]; }; export type DoWhileStatement = BaseNode & { type: "DoWhileStatement"; body: Statement; test: Expression; label?: string; labels?: string[]; }; export type ThrowStatement = BaseNode & { type: "ThrowStatement"; argument: Expression; }; export type CatchClause = BaseNode & { type: "CatchClause"; param?: ArrayPattern | Identifier | ObjectPattern; body: BlockStatement; }; export type TryStatement = BaseNode & { type: "TryStatement"; block: BlockStatement; handler?: CatchClause; finalizer?: BlockStatement; }; export type SwitchCase = BaseNode & { type: "SwitchCase"; test?: Expression; consequent: Statement[]; }; export type SwitchStatement = BaseNode & { type: "SwitchStatement"; discriminant: Expression; cases: SwitchCase[]; }; export type ImportSpecifier = BaseNode & { type: "ImportSpecifier"; imported: Identifier; local: Identifier; }; export type ImportDefaultSpecifier = BaseNode & { type: "ImportDefaultSpecifier"; local: Identifier; }; export type ImportNamespaceSpecifier = BaseNode & { type: "ImportNamespaceSpecifier"; local: Identifier; }; export type ImportDeclaration = BaseNode & { type: "ImportDeclaration"; specifiers: Array; source: StringLiteral; }; export type Module = BaseNode & { type: "Module"; body: Statement[]; }; export type Statement = BlockStatement | BreakStatement | DoWhileStatement | ExportDefaultDeclaration | ExportNamedDeclaration | ImportDeclaration | TryStatement | ContinueStatement | EmptyStatement | ExpressionStatement | FunctionDeclaration | ForInStatement | ForOfStatement | ForStatement | IfStatement | ReturnStatement | SwitchStatement | ThrowStatement | VariableDeclaration | WhileStatement; export type ArrowFunctionExpression = BaseNode & { type: "ArrowFunctionExpression"; async: boolean; body: BlockStatement | Expression; expression: boolean; params: Array; }; export type Expression = ArrowFunctionExpression | AssignmentExpression | ArrayExpression | AwaitExpression | BinaryExpression | BooleanLiteral | CallExpression | ConditionalExpression | FunctionExpression | Identifier | LogicalExpression | MemberExpression | MetaProperty | NewExpression | NullLiteral | NumericLiteral | ObjectExpression | RegexLiteral | SequenceExpression | StringLiteral | TaggedTemplateExpression | TemplateLiteral | ThisExpression | UnaryExpression | UpdateExpression | UndefinedLiteral | YieldExpression; export type ParseResult = Expression | Statement; export declare function parse(source: string, filename?: string): ParseResult; export declare function parseModule(source: string, filename?: string): Module; export declare function parseExecutableModule(source: string, filename?: string): Module;