From baf022cb3464ec6bbdad63fa59062ee5b646b5de Mon Sep 17 00:00:00 2001 From: divy-work Date: Sun, 26 Jul 2020 20:15:57 +0530 Subject: [PATCH 01/24] feat: add ast parser op --- cli/ops/runtime_compiler.rs | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs index e70b69de73a70e..538d1ab19b2412 100644 --- a/cli/ops/runtime_compiler.rs +++ b/cli/ops/runtime_compiler.rs @@ -2,17 +2,21 @@ use super::dispatch_json::{Deserialize, JsonOp, Value}; use crate::futures::FutureExt; use crate::op_error::OpError; +use crate::permissions::Permissions; use crate::state::State; +use crate::swc_util::AstParser; use crate::tsc::runtime_bundle; use crate::tsc::runtime_compile; use crate::tsc::runtime_transpile; use deno_core::CoreIsolate; +use deno_core::ModuleSpecifier; use deno_core::ZeroCopyBuf; use std::collections::HashMap; pub fn init(i: &mut CoreIsolate, s: &State) { i.register_op("op_compile", s.stateful_json_op(op_compile)); i.register_op("op_transpile", s.stateful_json_op(op_transpile)); + i.register_op("op_parse", s.stateful_json_op(op_parse)); } #[derive(Deserialize, Debug)] @@ -84,3 +88,40 @@ fn op_transpile( .boxed_local(); Ok(JsonOp::Async(fut)) } + +#[derive(Deserialize, Debug)] +struct ParseArgs { + source_file: String, +} + +fn op_parse( + state: &State, + args: Value, + _zero_copy: &mut [ZeroCopyBuf], +) -> Result { + state.check_unstable("Deno.ast"); + let args: ParseArgs = serde_json::from_value(args)?; + let s = state.borrow(); + let global_state = s.global_state.clone(); + let module_specifier = + ModuleSpecifier::resolve_url_or_path(&args.source_file)?; + let fut = async move { + let out = global_state + .file_fetcher + .fetch_source_file(&module_specifier, None, Permissions::allow_all()) + .await?; + let src = std::str::from_utf8(&out.source_code).unwrap(); + let parser = AstParser::new(); + parser.parse_module::<_, Result>( + &module_specifier.to_string(), + out.media_type, + &src, + |parse_result| { + let module = parse_result.unwrap(); + Ok(serde_json::to_value(module)?) + }, + ) + } + .boxed_local(); + Ok(JsonOp::Async(fut)) +} From 77c128d29a5b02b3d3b13b502b460ae1faa4e941 Mon Sep 17 00:00:00 2001 From: divy-work Date: Sun, 26 Jul 2020 20:18:52 +0530 Subject: [PATCH 02/24] feat: pass state perms to module specifier --- cli/ops/runtime_compiler.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs index 538d1ab19b2412..7cf590f46c92a1 100644 --- a/cli/ops/runtime_compiler.rs +++ b/cli/ops/runtime_compiler.rs @@ -2,7 +2,6 @@ use super::dispatch_json::{Deserialize, JsonOp, Value}; use crate::futures::FutureExt; use crate::op_error::OpError; -use crate::permissions::Permissions; use crate::state::State; use crate::swc_util::AstParser; use crate::tsc::runtime_bundle; @@ -105,10 +104,11 @@ fn op_parse( let global_state = s.global_state.clone(); let module_specifier = ModuleSpecifier::resolve_url_or_path(&args.source_file)?; + let permissions = s.permissions.clone(); let fut = async move { let out = global_state .file_fetcher - .fetch_source_file(&module_specifier, None, Permissions::allow_all()) + .fetch_source_file(&module_specifier, None, permissions) .await?; let src = std::str::from_utf8(&out.source_code).unwrap(); let parser = AstParser::new(); From 99ccc934b54a6de0cdea273882247467c0812e1f Mon Sep 17 00:00:00 2001 From: divy-work Date: Mon, 27 Jul 2020 13:25:19 +0530 Subject: [PATCH 03/24] todo --- cli/ops/runtime_compiler.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs index 7cf590f46c92a1..26d30628d7adbf 100644 --- a/cli/ops/runtime_compiler.rs +++ b/cli/ops/runtime_compiler.rs @@ -93,6 +93,8 @@ struct ParseArgs { source_file: String, } +// TODO(divy-work): Should we take swc parse options? +// TODO(divy-work): Accept multiple source_files to parse fn op_parse( state: &State, args: Value, From 180938d3f4ea9ed36e9e0ef07f8b88fac697a93f Mon Sep 17 00:00:00 2001 From: divy-work Date: Mon, 27 Jul 2020 16:50:48 +0530 Subject: [PATCH 04/24] feat: add ast to compiler_api.js --- cli/rt/40_compiler_api.js | 14 ++++++++++++++ cli/rt/90_deno_ns.js | 1 + 2 files changed, 15 insertions(+) diff --git a/cli/rt/40_compiler_api.js b/cli/rt/40_compiler_api.js index 8a2aa759a57f7b..d0133e14448de5 100644 --- a/cli/rt/40_compiler_api.js +++ b/cli/rt/40_compiler_api.js @@ -10,6 +10,10 @@ return sendAsync("op_compile", request); } + function opAst(request) { + return sendAsync("op_parse", request); + } + function opTranspile( request, ) { @@ -22,6 +26,15 @@ : `./${specifier}`; } + // TODO(divy-work): Use AST type interface from swc? + function ast(source_file) { + util.log("Deno.ast", { source_file }); + const payload = { + source_file, + }; + return opAst(payload); + } + // TODO(bartlomieju): change return type to interface? function transpileOnly( sources, @@ -96,5 +109,6 @@ bundle, compile, transpileOnly, + ast, }; })(this); diff --git a/cli/rt/90_deno_ns.js b/cli/rt/90_deno_ns.js index bb556146c172f5..d283f325a3ae1e 100644 --- a/cli/rt/90_deno_ns.js +++ b/cli/rt/90_deno_ns.js @@ -89,6 +89,7 @@ __bootstrap.denoNsUnstable = { signals: __bootstrap.signals.signals, Signal: __bootstrap.signals.Signal, SignalStream: __bootstrap.signals.SignalStream, + ast: __bootstrap.compilerApi.ast, transpileOnly: __bootstrap.compilerApi.transpileOnly, compile: __bootstrap.compilerApi.compile, bundle: __bootstrap.compilerApi.bundle, From 89e241f5f0d2faed82a18c4ba0e130a03d38da0c Mon Sep 17 00:00:00 2001 From: divy-work Date: Mon, 27 Jul 2020 17:03:48 +0530 Subject: [PATCH 05/24] fix: eslint --- cli/ops/runtime_compiler.rs | 6 ++---- cli/rt/40_compiler_api.js | 8 ++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs index 26d30628d7adbf..e0e2444e47ff6c 100644 --- a/cli/ops/runtime_compiler.rs +++ b/cli/ops/runtime_compiler.rs @@ -90,11 +90,10 @@ fn op_transpile( #[derive(Deserialize, Debug)] struct ParseArgs { - source_file: String, + source: String, } // TODO(divy-work): Should we take swc parse options? -// TODO(divy-work): Accept multiple source_files to parse fn op_parse( state: &State, args: Value, @@ -104,8 +103,7 @@ fn op_parse( let args: ParseArgs = serde_json::from_value(args)?; let s = state.borrow(); let global_state = s.global_state.clone(); - let module_specifier = - ModuleSpecifier::resolve_url_or_path(&args.source_file)?; + let module_specifier = ModuleSpecifier::resolve_url_or_path(&args.source)?; let permissions = s.permissions.clone(); let fut = async move { let out = global_state diff --git a/cli/rt/40_compiler_api.js b/cli/rt/40_compiler_api.js index d0133e14448de5..23d9c8bed2a455 100644 --- a/cli/rt/40_compiler_api.js +++ b/cli/rt/40_compiler_api.js @@ -26,11 +26,11 @@ : `./${specifier}`; } - // TODO(divy-work): Use AST type interface from swc? - function ast(source_file) { - util.log("Deno.ast", { source_file }); + // TODO(divy-work): Use AST type interface from swc as return type? + function ast(source) { + util.log("Deno.ast", { source }); const payload = { - source_file, + source, }; return opAst(payload); } From fbe6bdeb9d7a91049e5ae609ab46f980696e63f1 Mon Sep 17 00:00:00 2001 From: divy-work Date: Mon, 27 Jul 2020 18:01:17 +0530 Subject: [PATCH 06/24] feat: add swc program types --- cli/dts/lib.deno.unstable.d.ts | 18 +- cli/dts/swc.d.ts | 1569 ++++++++++++++++++++++++++++++++ 2 files changed, 1586 insertions(+), 1 deletion(-) create mode 100644 cli/dts/swc.d.ts diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index d23536c428d14f..81fad00746b029 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -2,6 +2,7 @@ /// /// +/// declare namespace Deno { /** @@ -456,7 +457,22 @@ declare namespace Deno { sources: Record, options?: CompilerOptions, ): Promise>; - + + /** **UNSTABLE**: new API, yet to be vetted. + * Returns the AST for the provided source file. + * The extension of the module name will be used to determine the media type of the module. + * + * ```ts + * const ast = await Deno.ast("foo.ts"); + * ``` + * + * @param source A source file to be parsed. The extension of the key will determine + * the media type of the file when processing. + */ + export function ast( + source: string, + ): Promise; + /** **UNSTABLE**: new API, yet to be vetted. * * Takes a root module name, and optionally a record set of sources. Resolves diff --git a/cli/dts/swc.d.ts b/cli/dts/swc.d.ts new file mode 100644 index 00000000000000..90a1c5e45dbac7 --- /dev/null +++ b/cli/dts/swc.d.ts @@ -0,0 +1,1569 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +/// +/// + +declare namespace swc { + export interface Span { + start: number; + end: number; + ctxt: number; + } + + export interface Node { + type: string; + } + + export interface HasSpan { + span: Span; + } + + export interface HasDecorator { + decorators?: Decorator[]; + } + + export interface Class extends HasSpan, HasDecorator { + body: ClassMember[]; + + superClass?: Expression; + + is_abstract: boolean; + + typeParams: TsTypeParameterDeclaration; + + superTypeParams?: TsTypeParameterInstantiation; + + implements: TsExpressionWithTypeArguments[]; + } + + export type ClassMember = + | Constructor + | ClassMethod + | PrivateMethod + | ClassProperty + | PrivateProperty + | TsIndexSignature; + + export interface ClassPropertyBase extends Node, HasSpan, HasDecorator { + value?: Expression; + + typeAnnotation?: TsTypeAnnotation; + + is_static: boolean; + + computed: boolean; + + accessibility?: Accessibility; + + /// Typescript extension. + is_abstract: boolean; + + is_optional: boolean; + + readonly: boolean; + + definite: boolean; + } + + export interface ClassProperty extends ClassPropertyBase { + type: "ClassProperty"; + + key: Expression; + } + + export interface PrivateProperty extends ClassPropertyBase { + type: "PrivateProperty"; + + key: PrivateName; + } + + export interface Param extends Node, HasSpan, HasDecorator { + type: 'Parameter' + pat: Pattern + } + + export interface Constructor extends Node, HasSpan { + type: "Constructor"; + + key: PropertyName; + + params: (Param | TsParameterProperty)[]; + + body: BlockStatement; + + accessibility?: Accessibility; + + is_optional: boolean; + } + + export interface ClassMethodBase extends Node, HasSpan { + function: Fn; + + kind: MethodKind; + + is_static: boolean; + + accessibility?: Accessibility; + + is_abstract: boolean; + + is_optional: boolean; + } + + export interface ClassMethod extends ClassMethodBase { + type: "ClassMethod"; + + key: PropertyName; + } + + export interface PrivateMethod extends ClassMethodBase { + type: "PrivateMethod"; + + key: PrivateName; + } + + export interface Decorator extends Node, HasSpan { + type: "Decorator"; + + expression: Expression; + } + + export type MethodKind = "method" | "setter" | "getter"; + + export type Declaration = + | ClassDeclaration + | FunctionDeclaration + | VariableDeclaration + | TsInterfaceDeclaration + | TsTypeAliasDeclaration + | TsEnumDeclaration + | TsModuleDeclaration; + + export interface FunctionDeclaration extends Fn { + type: "FunctionDeclaration"; + + ident: Identifier; + + declare: boolean; + } + + export interface ClassDeclaration extends Class, Node { + type: "ClassDeclaration"; + + identifier: Identifier; + + declare: boolean; + } + + export interface VariableDeclaration extends Node, HasSpan { + type: "VariableDeclaration"; + + kind: VariableDeclarationKind; + + declare: boolean; + + declarations: VariableDeclarator[]; + } + + export type VariableDeclarationKind = "get" | "let" | "const"; + + export interface VariableDeclarator extends Node, HasSpan { + type: "VariableDeclarator"; + + id: Pattern; + + /// Initialization expresion. + init?: Expression; + + /// Typescript only + definite: boolean; + } + + export type Expression = + | ThisExpression + | ArrayExpression + | ObjectExpression + | FunctionExpression + | UnaryExpression + | UpdateExpression + | BinaryExpression + | AssignmentExpression + | MemberExpression + | ConditionalExpression + | CallExpression + | NewExpression + | SequenceExpression + | Identifier + | Literal + | TemplateLiteral + | TaggedTemplateExpression + | ArrowFunctionExpression + | ClassExpression + | YieldExpression + | MetaProperty + | AwaitExpression + | ParenthesisExpression + | JSXMemberExpression + | JSXNamespacedName + | JSXEmptyExpression + | JSXElement + | JSXFragment + | TsTypeAssertion + | TsNonNullExpression + | TsTypeCastExpression + | TsAsExpression + | PrivateName + | OptionalChainingExpression + | Invalid; + + interface ExpressionBase extends Node, HasSpan { } + + export interface OptionalChainingExpression extends ExpressionBase { + type: "OptionalChainingExpression"; + /** + * Call expression or member expression. + */ + expr: Expression; + } + + export interface ThisExpression extends ExpressionBase { + type: "ThisExpression"; + } + + export interface ArrayExpression extends ExpressionBase { + type: "ArrayExpression"; + + elements: (Expression | SpreadElement | undefined)[]; + } + + export interface ObjectExpression extends ExpressionBase { + type: "ObjectExpression"; + + properties: (Property | SpreadElement)[]; + } + + export interface Argument { + spread: Span; + expression: Expression; + } + + export type PropertOrSpread = Property | SpreadElement; + + export interface SpreadElement extends Node { + type: "SpreadElement"; + + spread: Span; + + arguments: Expression; + } + + export interface UnaryExpression extends ExpressionBase { + type: "UnaryExpression"; + + operator: UnaryOperator; + + argument: Expression; + } + + export interface UpdateExpression extends ExpressionBase { + type: "UpdateExpression"; + + operator: UpdateOperator; + + prefix: boolean; + + argument: Expression; + } + + export interface BinaryExpression extends ExpressionBase { + type: "BinaryExpression"; + + operator: BinaryOperator; + + left: Expression; + + right: Expression; + } + + export interface FunctionExpression extends Fn, ExpressionBase { + type: "FunctionExpression"; + + identifier: Identifier; + } + + export interface ClassExpression extends Class, ExpressionBase { + type: "ClassExpression"; + + identifier: Identifier; + } + + export interface AssignmentExpression extends ExpressionBase { + type: "AssignmentExpression"; + + operator: AssignmentOperator; + + left: Pattern | Expression; + + right: Expression; + } + + export interface MemberExpression extends ExpressionBase { + type: "MemberExpression"; + + object: Expression | Super; + + property: Expression; + + computed: boolean; + } + + export interface ConditionalExpression extends ExpressionBase { + type: "ConditionalExpression"; + + test: Expression; + + consequent: Expression; + + alternate: Expression; + } + + export interface Super extends Node, HasSpan { + type: "Super"; + } + + export interface CallExpression extends ExpressionBase { + type: "CallExpression"; + + callee: Expression | Super; + + arguments: Argument[]; + + typeArguments?: TsTypeParameterInstantiation; + } + + export interface NewExpression extends ExpressionBase { + type: "NewExpression"; + + callee: Expression; + + arguments: Argument[]; + + typeArguments?: TsTypeParameterInstantiation; + } + + export interface SequenceExpression extends ExpressionBase { + type: "SequenceExpression"; + + expressions: Expression[]; + } + + export interface ArrowFunctionExpression extends ExpressionBase { + type: "ArrowFunctionExpression"; + + params: Pattern[]; + + body: BlockStatement | Expression; + + async: boolean; + + generator: boolean; + + typeParameters?: TsTypeParameterDeclaration; + + returnType?: TsTypeAnnotation; + } + + export interface YieldExpression extends ExpressionBase { + type: "YieldExpression"; + + argument?: Expression; + + delegate: boolean; + } + + export interface MetaProperty extends Node { + type: "MetaProperty"; + + meta: Identifier; + + property: Identifier; + } + + export interface AwaitExpression extends ExpressionBase { + type: "AwaitExpression"; + + argument: Expression; + } + + export interface TplBase { + expressions: Expression[]; + + quasis: TemplateElement[]; + } + + export interface TemplateLiteral extends ExpressionBase, TplBase { + type: "TemplateLiteral"; + } + + export interface TaggedTemplateExpression extends ExpressionBase, TplBase { + type: "TaggedTemplateExpression"; + + tag: Expression; + + typeParameters: TsTypeParameterInstantiation; + } + + export interface TemplateElement extends ExpressionBase { + type: "TemplateElement"; + + tail: boolean; + cooked: StringLiteral; + raw: StringLiteral; + } + + export interface ParenthesisExpression extends ExpressionBase { + type: "ParenthesisExpression"; + + expression: Expression; + } + + export interface Fn extends HasSpan, HasDecorator { + params: Param[]; + + body: BlockStatement; + + generator: boolean; + + async: boolean; + + typeParameters?: TsTypeParameterDeclaration; + + returnType?: TsTypeAnnotation; + } + + interface PatternBase { + typeAnnotation?: TsTypeAnnotation; + } + + export interface Identifier extends HasSpan, PatternBase { + type: "Identifier"; + + value: string; + + /// TypeScript only. Used in case of an optional parameter. + optional: boolean; + } + + export interface PrivateName extends ExpressionBase { + type: "PrivateName"; + + id: Identifier; + } + + export type JSXObject = JSXMemberExpression | Identifier; + + export interface JSXMemberExpression extends Node { + type: "JSXMemberExpression"; + + object: JSXObject; + property: Identifier; + } + + /** + * XML-based namespace syntax: + */ + export interface JSXNamespacedName extends Node { + type: "JSXNamespacedName"; + + namespace: Identifier; + name: Identifier; + } + + export interface JSXEmptyExpression extends Node, HasSpan { + type: "JSXEmptyExpression"; + } + + export interface JSXExpressionContainer extends Node { + type: "JSXExpressionContainer"; + + expression: JSXExpression; + } + + export type JSXExpression = JSXEmptyExpression | Expression; + + export interface JSXSpreadChild extends Node { + type: "JSXSpreadChild"; + + expression: Expression; + } + + export type JSXElementName = + | Identifier + | JSXMemberExpression + | JSXNamespacedName; + + export interface JSXOpeningElement extends Node, HasSpan { + type: "JSXOpeningElement"; + + name: JSXElementName; + + attrs?: JSXAttributeOrSpread[]; + + selfClosing: boolean; + + typeArguments?: TsTypeParameterInstantiation; + } + + export type JSXAttributeOrSpread = JSXAttribute | SpreadElement; + + export interface JSXClosingElement extends Node, HasSpan { + type: "JSXClosingElement"; + + name: JSXElementName; + } + + export interface JSXAttribute extends Node, HasSpan { + type: "JSXAttribute"; + + name: JSXAttributeName; + + value?: JSXAttrValue; + } + + export type JSXAttributeName = Identifier | JSXNamespacedName; + + export type JSXAttrValue = + | Literal + | JSXExpressionContainer + | JSXElement + | JSXFragment; + + export interface JSXText extends Node, HasSpan { + type: "JSXText"; + + value: string; + raw: string; + } + + export interface JSXElement extends Node, HasSpan { + type: "JSXElement"; + + opening: JSXOpeningElement; + children: JSXElementChild[]; + closing?: JSXClosingElement; + } + + export type JSXElementChild = + | JSXText + | JSXExpressionContainer + | JSXSpreadChild + | JSXElement + | JSXFragment; + + export interface JSXFragment extends Node, HasSpan { + type: "JSXFragment"; + + opening: JSXOpeningFragment; + + children: JSXElementChild[]; + + closing: JSXClosingFragment; + } + + export interface JSXOpeningFragment extends Node, HasSpan { + type: "JSXOpeningFragment"; + } + + export interface JSXClosingFragment extends Node, HasSpan { + type: "JSXClosingFragment"; + } + + export type Literal = + | StringLiteral + | BooleanLiteral + | NullLiteral + | NumericLiteral + | RegExpLiteral + | JSXText; + + export interface StringLiteral extends Node, HasSpan { + type: "StringLiteral"; + + value: string; + has_escape: boolean; + } + + export interface BooleanLiteral extends Node, HasSpan { + type: "BooleanLiteral"; + + value: boolean; + } + + export interface NullLiteral extends Node, HasSpan { + type: "NullLiteral"; + } + + export interface RegExpLiteral extends Node, HasSpan { + type: "RegExpLiteral"; + + pattern: string; + flags: string; + } + + export interface NumericLiteral extends Node, HasSpan { + type: "NumericLiteral"; + + value: number; + } + + export type ModuleDeclaration = + | ImportDeclaration + | ExportDeclaration + | ExportNamedDeclaration + | ExportDefaultDeclaration + | ExportDefaultExpression + | ExportAllDeclaration + | TsImportEqualsDeclaration + | TsExportAssignment + | TsNamespaceExportDeclaration; + + export interface ExportDefaultExpression extends Node, HasSpan { + type: "ExportDefaultExpression"; + + expression: Expression; + } + + export interface ExportDeclaration extends Node, HasSpan { + type: "ExportDeclaration"; + + declaration: Declaration; + } + + export interface ImportDeclaration extends Node, HasSpan { + type: "ImportDeclaration"; + + specifiers: ImporSpecifier[]; + + source: StringLiteral; + } + + export type ImporSpecifier = + | ImportDefaultSpecifier + | NamedImportSpecifier + | ImportNamespaceSpecifier; + + export interface ExportAllDeclaration extends Node, HasSpan { + type: "ExportAllDeclaration"; + + source: StringLiteral; + } + + /** + * - `export { foo } from 'mod'` + * - `export { foo as bar } from 'mod'` + */ + export interface ExportNamedDeclaration extends Node, HasSpan { + type: "ExportNamedDeclaration"; + + specifiers: ExportSpecifier[]; + + source?: StringLiteral; + } + + export interface ExportDefaultDeclaration extends Node, HasSpan { + type: "ExportDefaultDeclaration"; + + decl: DefaultDecl; + } + + export type DefaultDecl = + | ClassExpression + | FunctionExpression + | TsInterfaceDeclaration; + + export type ImportSpecifier = + | NamedImportSpecifier + | ImportDefaultSpecifier + | ImportNamespaceSpecifier; + + /** + * e.g. `import foo from 'mod.js'` + */ + export interface ImportDefaultSpecifier extends Node, HasSpan { + type: "ImportDefaultSpecifier"; + local: Identifier; + } + + /** + * e.g. `import * as foo from 'mod.js'`. + */ + export interface ImportNamespaceSpecifier extends Node, HasSpan { + type: "ImportNamespaceSpecifier"; + + local: Identifier; + } + + /** + * e.g. - `import { foo } from 'mod.js'` + * + * local = foo, imported = None + * + * e.g. `import { foo as bar } from 'mod.js'` + * + * local = bar, imported = Some(foo) for + */ + export interface NamedImportSpecifier extends Node, HasSpan { + type: "ImportSpecifier"; + local: Identifier; + imported: Identifier; + } + + export type ExportSpecifier = + | ExportNamespaceSpecifer + | ExportDefaultSpecifier + | NamedExportSpecifier; + + /** + * `export * as foo from 'src';` + */ + export interface ExportNamespaceSpecifer extends Node, HasSpan { + type: "ExportNamespaceSpecifer"; + + name: Identifier; + } + + export interface ExportDefaultSpecifier extends Node, HasSpan { + type: "ExportDefaultSpecifier"; + + exported: Identifier; + } + + export interface NamedExportSpecifier extends Node, HasSpan { + type: "ExportSpecifier"; + + orig: Identifier; + /** + * `Some(bar)` in `export { foo as bar }` + */ + exported: Identifier; + } + + interface HasInterpreter { + /** + * e.g. `/usr/bin/node` for `#!/usr/bin/node` + */ + interpreter: string; + } + + export type Program = Module | Script; + + export interface Module extends Node, HasSpan, HasInterpreter { + type: "Module"; + + body: ModuleItem[]; + } + + export interface Script extends Node, HasSpan, HasInterpreter { + type: "Script"; + + body: Statement[]; + } + + export type ModuleItem = ModuleDeclaration | Statement; + + export type BinaryOperator = + | "==" + | "!=" + | "===" + | "!==" + | "<" + | "<=" + | ">" + | ">=" + | "<<" + | ">>" + | ">>>" + | "+" + | "-" + | "*" + | "/" + | "%" + | "**" + | "|" + | "^" + | "&" + | "||" + | "&&" + | "in" + | "instanceof" + | "??"; + + export type AssignmentOperator = + | "=" + | "+=" + | "-=" + | "*=" + | "/=" + | "%=" + | "**=" + | "<<=" + | ">>=" + | ">>>=" + | "|=" + | "^=" + | "&="; + + export type UpdateOperator = "++" | "--"; + + export type UnaryOperator = + | "-" + | "+" + | "!" + | "~" + | "typeof" + | "void" + | "delete"; + + export type Pattern = + | Identifier + | ArrayPattern + | RestElement + | ObjectPattern + | AssignmentPattern + | Invalid + | Expression; + + export interface ArrayPattern extends Node, HasSpan, PatternBase { + type: "ArrayPattern"; + + elements: (Pattern | undefined)[]; + } + + export interface ObjectPattern extends Node, HasSpan, PatternBase { + type: "ObjectPattern"; + + props: ObjectPatternProperty[]; + } + + export interface AssignmentPattern extends Node, HasSpan, PatternBase { + type: "AssignmentPattern"; + + left: Pattern; + right: Expression; + } + + export interface RestElement extends Node, HasSpan, PatternBase { + type: "RestElement"; + + rest: Span; + + argument: Pattern; + } + + export type ObjectPatternProperty = + | KeyValuePatternProperty + | AssignmentPatternProperty + | RestElement; + + /** + * `{key: value}` + */ + export interface KeyValuePatternProperty extends Node { + type: "KeyValuePatternProperty"; + + key: PropertyName; + value: Pattern; + } + + /** + * `{key}` or `{key = value}` + */ + export interface AssignmentPatternProperty extends Node, HasSpan { + type: "AssignmentPatternProperty"; + + key: Identifier; + value?: Expression; + } + + /** Identifier is `a` in `{ a, }` */ + export type Property = + | Identifier + | KeyValueProperty + | AssignmentProperty + | GetterProperty + | SetterProperty + | MethodProperty; + + interface PropBase extends Node { + key: PropertyName; + } + + export interface KeyValueProperty extends PropBase { + type: "KeyValueProperty"; + + value: Expression; + } + + export interface AssignmentProperty extends Node { + type: "AssignmentProperty"; + + key: Identifier; + value: Expression; + } + + export interface GetterProperty extends PropBase, HasSpan { + type: "GetterProperty"; + + typeAnnotation?: TsTypeAnnotation; + + body: BlockStatement; + } + + export interface SetterProperty extends PropBase, HasSpan { + type: "SetterProperty"; + + param: Pattern; + body: BlockStatement; + } + + export interface MethodProperty extends PropBase, Fn { + type: "MethodProperty"; + } + + export type PropertyName = + | Identifier + | StringLiteral + | NumericLiteral + | ComputedPropName; + + export interface ComputedPropName extends Node, HasSpan { + type: "Computed"; + expression: Expression; + } + + export interface BlockStatement extends Node, HasSpan { + type: "BlockStatement"; + + stmts: Statement[]; + } + + export interface ExpressionStatement extends Node, HasSpan { + type: "ExpressionStatement"; + expression: Expression; + } + + export type Statement = + | ExpressionStatement + | BlockStatement + | EmptyStatement + | DebuggerStatement + | WithStatement + | ReturnStatement + | LabeledStatement + | BreakStatement + | ContinueStatement + | IfStatement + | SwitchStatement + | ThrowStatement + | TryStatement + | WhileStatement + | DoWhileStatement + | ForStatement + | ForInStatement + | ForOfStatement + | Declaration; + + export interface EmptyStatement extends Node, HasSpan { + type: "EmptyStatement"; + } + + export interface DebuggerStatement extends Node, HasSpan { + type: "DebuggerStatement"; + } + + export interface WithStatement extends Node, HasSpan { + type: "WithStatement"; + + object: Expression; + body: Statement; + } + + export interface ReturnStatement extends Node, HasSpan { + type: "ReturnStatement"; + + argument: Expression; + } + + export interface LabeledStatement extends Node, HasSpan { + type: "LabeledStatement"; + + label: Identifier; + body: Statement; + } + + export interface BreakStatement extends Node, HasSpan { + type: "BreakStatement"; + + label: Identifier; + } + + export interface ContinueStatement extends Node, HasSpan { + type: "ContinueStatement"; + + label: Identifier; + } + + export interface IfStatement extends Node, HasSpan { + type: "IfStatement"; + + test: Expression; + consequent: Statement; + alternate?: Statement; + } + + export interface SwitchStatement extends Node, HasSpan { + type: "SwitchStatement"; + + discriminant: Expression; + cases: SwitchCase[]; + } + + export interface ThrowStatement extends Node, HasSpan { + type: "ThrowStatement"; + + argument: Expression; + } + + export interface TryStatement extends Node, HasSpan { + type: "TryStatement"; + + block: BlockStatement; + handler?: CatchClause; + finalizer: BlockStatement; + } + + export interface WhileStatement extends Node, HasSpan { + type: "WhileStatement"; + + test: Expression; + body: Statement; + } + + export interface DoWhileStatement extends Node, HasSpan { + type: "DoWhileStatement"; + + test: Expression; + body: Statement; + } + + export interface ForStatement extends Node, HasSpan { + type: "ForStatement"; + + init?: VariableDeclaration | Expression; + test?: Expression; + update?: Expression; + body: Statement; + } + + export interface ForInStatement extends Node, HasSpan { + type: "ForInStatement"; + + left: VariableDeclaration | Pattern; + right: Expression; + body: Statement; + } + + export interface ForOfStatement extends Node, HasSpan { + type: "ForOfStatement"; + + /** + * Span of the await token. + * + * es2018 for-await-of statements, e.g., `for await (const x of xs) {` + */ + await: Span; + left: VariableDeclaration | Pattern; + right: Expression; + body: Statement; + } + + export interface SwitchCase extends Node, HasSpan { + type: "SwitchCase"; + + /** + * Undefined for default case + */ + test?: Expression; + consequent: Statement[]; + } + + export interface CatchClause extends Node, HasSpan { + type: "CatchClause"; + + /** + * The param is `undefined` if the catch binding is omitted. E.g., `try { foo() } catch {}` + */ + param: Pattern; + body: BlockStatement; + } + + export interface TsTypeAnnotation extends Node, HasSpan { + type: "TsTypeAnnotation"; + + typeAnnotation: TsType; + } + + export interface TsTypeParameterDeclaration extends Node, HasSpan { + type: "TsTypeParameterDeclaration"; + + parameters: TsTypeParameter[]; + } + + export interface TsTypeParameter extends Node, HasSpan { + type: "TsTypeParameter"; + + name: Identifier; + constraint: TsType; + default: TsType; + } + + export interface TsTypeParameterInstantiation extends Node, HasSpan { + type: "TsTypeParameterInstantiation"; + + params: TsType[]; + } + + export interface TsTypeCastExpression extends Node, HasSpan { + type: "TsTypeCastExpression"; + + expression: Expression; + typeAnnotation: TsTypeAnnotation; + } + + export interface TsParameterProperty extends Node, HasSpan, HasDecorator { + type: "TsParameterProperty"; + + accessibility?: Accessibility; + readonly: boolean; + param: TsParameterPropertyParameter; + } + + export type TsParameterPropertyParameter = Identifier | AssignmentPattern; + + export interface TsQualifiedName extends Node { + type: "TsQualifiedName"; + + left: TsEntityName; + right: Identifier; + } + + export type TsEntityName = TsQualifiedName | Identifier; + + export type TsSignatureDeclaration = + | TsCallSignatureDeclaration + | TsConstructSignatureDeclaration + | TsMethodSignature + | TsFunctionType + | TsConstructorType; + + export type TsTypeElement = + | TsCallSignatureDeclaration + | TsConstructSignatureDeclaration + | TsPropertySignature + | TsMethodSignature + | TsIndexSignature; + + export interface TsCallSignatureDeclaration extends Node, HasSpan { + type: "TsCallSignatureDeclaration"; + + params: TsFnParameter[]; + typeAnnotation: TsTypeAnnotation; + typeParams: TsTypeParameterDeclaration; + } + + export interface TsConstructSignatureDeclaration extends Node, HasSpan { + type: "TsConstructSignatureDeclaration"; + + params: TsFnParameter[]; + typeAnnotation: TsTypeAnnotation; + typeParams: TsTypeParameterDeclaration; + } + + export interface TsPropertySignature extends Node, HasSpan { + type: "TsPropertySignature"; + + readonly: boolean; + key: Expression; + computed: boolean; + optional: boolean; + + init: Expression; + params: TsFnParameter[]; + + typeAnnotation?: TsTypeAnnotation; + typeParams: TsTypeParameterDeclaration; + } + + export interface TsMethodSignature extends Node, HasSpan { + type: "TsMethodSignature"; + + readonly: boolean; + key: Expression; + computed: boolean; + optional: boolean; + params: TsFnParameter[]; + + typeAnnotation: TsTypeAnnotation; + typeParams: TsTypeParameterDeclaration; + } + + export interface TsIndexSignature extends Node, HasSpan { + type: "TsIndexSignature"; + + readonly: boolean; + params: TsFnParameter[]; + + typeAnnotation?: TsTypeAnnotation; + } + + export type TsType = + | TsKeywordType + | TsThisType + | TsFnOrConstructorType + | TsTypeReference + | TsTypeQuery + | TsTypeLiteral + | TsArrayType + | TsTupleType + | TsOptionalType + | TsRestType + | TsUnionOrIntersectionType + | TsConditionalType + | TsInferType + | TsParenthesizedType + | TsTypeOperator + | TsIndexedAccessType + | TsMappedType + | TsLiteralType + | TsImportType + | TsTypePredicate; + + export type TsFnOrConstructorType = TsFunctionType | TsConstructorType; + + export interface TsKeywordType extends Node, HasSpan { + type: "TsKeywordType"; + + kind: TsKeywordTypeKind; + } + + export type TsKeywordTypeKind = + | "any" + | "unknown" + | "number" + | "object" + | "boolean" + | "bigint" + | "string" + | "symbol" + | "void" + | "undefined" + | "null" + | "never"; + + export interface TsThisType extends Node, HasSpan { + type: "TsThisType"; + } + + export type TsFnParameter = Identifier | RestElement | ObjectPattern; + + export interface TsFunctionType extends Node, HasSpan { + type: "TsFunctionType"; + + typeParams: TsTypeParameterDeclaration; + typeAnnotation: TsTypeAnnotation; + } + + export interface TsConstructorType extends Node, HasSpan { + type: "TsConstructorType"; + + params: TsFnParameter[]; + + typeParams: TsTypeParameterDeclaration; + typeAnnotation: TsTypeAnnotation; + } + + export interface TsTypeReference extends Node, HasSpan { + type: "TsTypeReference"; + + typeName: TsEntityName; + typeParams: TsTypeParameterInstantiation; + } + + export interface TsTypePredicate extends Node, HasSpan { + type: "TsTypePredicate"; + + asserts: boolean; + + paramName: TsThisTypeOrIdent; + typeAnnotation: TsTypeAnnotation; + } + + export type TsThisTypeOrIdent = TsThisType | Identifier; + + export interface TsImportType extends Node, HasSpan { + argument: StringLiteral; + qualifier?: TsEntityName; + typeArguments?: TsTypeParameterInstantiation; + } + + /** + * `typeof` operator + */ + export interface TsTypeQuery extends Node, HasSpan { + type: "TsTypeQuery"; + + exprName: TsTypeQueryExpr; + } + + export type TsTypeQueryExpr = TsEntityName | TsImportType; + + export interface TsTypeLiteral extends Node, HasSpan { + type: "TsTypeLiteral"; + + members: TsTypeElement[]; + } + + export interface TsArrayType extends Node, HasSpan { + type: "TsArrayType"; + + elemType: TsType; + } + + export interface TsTupleType extends Node, HasSpan { + type: "TsTupleType"; + + elemTypes: TsType[]; + } + + export interface TsOptionalType extends Node, HasSpan { + type: "TsOptionalType"; + + typeAnnotation: TsType; + } + + export interface TsRestType extends Node, HasSpan { + type: "TsRestType"; + + typeAnnotation: TsType; + } + + export type TsUnionOrIntersectionType = TsUnionType | TsIntersectionType; + + export interface TsUnionType extends Node, HasSpan { + type: "TsUnionType"; + + types: TsType[]; + } + + export interface TsIntersectionType extends Node, HasSpan { + type: "TsIntersectionType"; + + types: TsType[]; + } + + export interface TsConditionalType extends Node, HasSpan { + type: "TsConditionalType"; + + checkType: TsType; + extendsType: TsType; + trueType: TsType; + falseType: TsType; + } + + export interface TsInferType extends Node, HasSpan { + type: "TsInferType"; + + typeParam: TsTypeParameter; + } + + export interface TsParenthesizedType extends Node, HasSpan { + type: "TsParenthesizedType"; + + typeAnnotation: TsType; + } + + export interface TsTypeOperator extends Node, HasSpan { + type: "TsTypeOperator"; + + op: TsTypeOperatorOp; + typeAnnotation: TsType; + } + + export type TsTypeOperatorOp = "keyof" | "unique"; + + export interface TsIndexedAccessType extends Node, HasSpan { + type: "TsIndexedAccessType"; + + objectType: TsType; + indexType: TsType; + } + + export type TruePlusMinus = true | "+" | "-"; + + export interface TsMappedType extends Node, HasSpan { + type: "TsMappedType"; + + readonly: TruePlusMinus; + typeParam: TsTypeParameter; + optional: TruePlusMinus; + typeAnnotation: TsType; + } + + export interface TsLiteralType extends Node, HasSpan { + type: "TsLiteralType"; + + literal: TsLiteral; + } + + export type TsLiteral = NumericLiteral | StringLiteral | BooleanLiteral | TemplateLiteral; + + // // ================ + // // TypeScript declarations + // // ================ + + export interface TsInterfaceDeclaration extends Node, HasSpan { + type: "TsInterfaceDeclaration"; + + id: Identifier; + declare: boolean; + typeParams?: TsTypeParameterDeclaration; + extends: TsExpressionWithTypeArguments[]; + body: TsInterfaceBody; + } + + export interface TsInterfaceBody extends Node, HasSpan { + type: "TsInterfaceBody"; + + body: TsTypeElement[]; + } + + export interface TsExpressionWithTypeArguments extends Node, HasSpan { + type: "TsExpressionWithTypeArguments"; + + expression: TsEntityName; + typeArguments?: TsTypeParameterInstantiation; + } + + export interface TsTypeAliasDeclaration extends Node, HasSpan { + type: "TsTypeAliasDeclaration"; + + declare: boolean; + id: Identifier; + typeParams?: TsTypeParameterDeclaration; + typeAnnotation: TsType; + } + + export interface TsEnumDeclaration extends Node, HasSpan { + type: "TsEnumDeclaration"; + + declare: boolean; + is_const: boolean; + id: Identifier; + member: TsEnumMember[]; + } + + export interface TsEnumMember extends Node, HasSpan { + type: "TsEnumMember"; + + id: TsEnumMemberId; + init?: Expression; + } + + export type TsEnumMemberId = Identifier | StringLiteral; + + export interface TsModuleDeclaration extends Node, HasSpan { + type: "TsModuleDeclaration"; + + declare: boolean; + global: boolean; + id: TsModuleName; + body?: TsNamespaceBody; + } + + /** + * `namespace A.B { }` is a namespace named `A` with another TsNamespaceDecl as its body. + */ + export type TsNamespaceBody = TsModuleBlock | TsNamespaceDeclaration; + + export interface TsModuleBlock extends Node, HasSpan { + type: "TsModuleBlock"; + + body: ModuleItem[]; + } + + export interface TsNamespaceDeclaration extends Node, HasSpan { + type: "TsNamespaceDeclaration"; + + declare: boolean; + global: boolean; + id: Identifier; + body: TsNamespaceBody; + } + + export type TsModuleName = Identifier | StringLiteral; + + export interface TsImportEqualsDeclaration extends Node, HasSpan { + type: "TsImportEqualsDeclaration"; + + declare: boolean; + is_export: boolean; + id: Identifier; + moduleRef: TsModuleReference; + } + + export type TsModuleReference = TsEntityName | TsExternalModuleReference; + + export interface TsExternalModuleReference extends Node, HasSpan { + type: "TsExternalModuleReference"; + + expression: Expression; + } + + export interface TsExportAssignment extends Node, HasSpan { + type: "TsExportAssignment"; + + expression: Expression; + } + + export interface TsNamespaceExportDeclaration extends Node, HasSpan { + type: "TsNamespaceExportDeclaration"; + + id: Identifier; + } + + export interface TsAsExpression extends ExpressionBase { + type: "TsAsExpression"; + + expression: Expression; + typeAnnotation: TsType; + } + + export interface TsTypeAssertion extends ExpressionBase { + type: "TsTypeAssertion"; + + expression: Expression; + typeAnnotation: TsType; + } + + export interface TsNonNullExpression extends ExpressionBase { + type: "TsNonNullExpression"; + + expression: Expression; + } + + export type Accessibility = "public" | "protected" | "private"; + + export interface Invalid extends Node, HasSpan { + type: "Invalid"; + } +} From 70b24c8394a98f3a838d3ecb56285912bd072787 Mon Sep 17 00:00:00 2001 From: divy-work Date: Tue, 28 Jul 2020 11:38:38 +0530 Subject: [PATCH 07/24] lint --- cli/dts/lib.deno.unstable.d.ts | 4 +- cli/dts/swc.d.ts | 2522 ++++++++++++++++---------------- 2 files changed, 1262 insertions(+), 1264 deletions(-) diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index 81fad00746b029..1168fca9289341 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -2,7 +2,7 @@ /// /// -/// +/// _ declare namespace Deno { /** @@ -471,7 +471,7 @@ declare namespace Deno { */ export function ast( source: string, - ): Promise; + ): Promise; /** **UNSTABLE**: new API, yet to be vetted. * diff --git a/cli/dts/swc.d.ts b/cli/dts/swc.d.ts index 90a1c5e45dbac7..783d9d9cc25e41 100644 --- a/cli/dts/swc.d.ts +++ b/cli/dts/swc.d.ts @@ -1,1569 +1,1567 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. /// -/// +/// -declare namespace swc { - export interface Span { - start: number; - end: number; - ctxt: number; - } +export interface Span { + start: number; + end: number; + ctxt: number; +} + +export interface Node { + type: string; +} + +export interface HasSpan { + span: Span; +} + +export interface HasDecorator { + decorators?: Decorator[]; +} + +export interface Class extends HasSpan, HasDecorator { + body: ClassMember[]; + + superClass?: Expression; + + is_abstract: boolean; + + typeParams: TsTypeParameterDeclaration; + + superTypeParams?: TsTypeParameterInstantiation; + + implements: TsExpressionWithTypeArguments[]; +} + +export type ClassMember = + | Constructor + | ClassMethod + | PrivateMethod + | ClassProperty + | PrivateProperty + | TsIndexSignature; + +export interface ClassPropertyBase extends Node, HasSpan, HasDecorator { + value?: Expression; + + typeAnnotation?: TsTypeAnnotation; + + is_static: boolean; + + computed: boolean; + + accessibility?: Accessibility; + + /// Typescript extension. + is_abstract: boolean; + + is_optional: boolean; + + readonly: boolean; + + definite: boolean; +} + +export interface ClassProperty extends ClassPropertyBase { + type: "ClassProperty"; + + key: Expression; +} + +export interface PrivateProperty extends ClassPropertyBase { + type: "PrivateProperty"; + + key: PrivateName; +} + +export interface Param extends Node, HasSpan, HasDecorator { + type: 'Parameter' + pat: Pattern +} + +export interface Constructor extends Node, HasSpan { + type: "Constructor"; + + key: PropertyName; + + params: (Param | TsParameterProperty)[]; + + body: BlockStatement; + + accessibility?: Accessibility; + + is_optional: boolean; +} + +export interface ClassMethodBase extends Node, HasSpan { + function: Fn; + + kind: MethodKind; + + is_static: boolean; + + accessibility?: Accessibility; + + is_abstract: boolean; + + is_optional: boolean; +} + +export interface ClassMethod extends ClassMethodBase { + type: "ClassMethod"; + + key: PropertyName; +} + +export interface PrivateMethod extends ClassMethodBase { + type: "PrivateMethod"; + + key: PrivateName; +} + +export interface Decorator extends Node, HasSpan { + type: "Decorator"; + + expression: Expression; +} + +export type MethodKind = "method" | "setter" | "getter"; + +export type Declaration = + | ClassDeclaration + | FunctionDeclaration + | VariableDeclaration + | TsInterfaceDeclaration + | TsTypeAliasDeclaration + | TsEnumDeclaration + | TsModuleDeclaration; + +export interface FunctionDeclaration extends Fn { + type: "FunctionDeclaration"; + + ident: Identifier; + + declare: boolean; +} + +export interface ClassDeclaration extends Class, Node { + type: "ClassDeclaration"; + + identifier: Identifier; + + declare: boolean; +} + +export interface VariableDeclaration extends Node, HasSpan { + type: "VariableDeclaration"; + + kind: VariableDeclarationKind; + + declare: boolean; + + declarations: VariableDeclarator[]; +} + +export type VariableDeclarationKind = "get" | "let" | "const"; + +export interface VariableDeclarator extends Node, HasSpan { + type: "VariableDeclarator"; + + id: Pattern; + + /// Initialization expresion. + init?: Expression; + + /// Typescript only + definite: boolean; +} + +export type Expression = + | ThisExpression + | ArrayExpression + | ObjectExpression + | FunctionExpression + | UnaryExpression + | UpdateExpression + | BinaryExpression + | AssignmentExpression + | MemberExpression + | ConditionalExpression + | CallExpression + | NewExpression + | SequenceExpression + | Identifier + | Literal + | TemplateLiteral + | TaggedTemplateExpression + | ArrowFunctionExpression + | ClassExpression + | YieldExpression + | MetaProperty + | AwaitExpression + | ParenthesisExpression + | JSXMemberExpression + | JSXNamespacedName + | JSXEmptyExpression + | JSXElement + | JSXFragment + | TsTypeAssertion + | TsNonNullExpression + | TsTypeCastExpression + | TsAsExpression + | PrivateName + | OptionalChainingExpression + | Invalid; + +interface ExpressionBase extends Node, HasSpan { } + +export interface OptionalChainingExpression extends ExpressionBase { + type: "OptionalChainingExpression"; + /** + * Call expression or member expression. + */ + expr: Expression; +} + +export interface ThisExpression extends ExpressionBase { + type: "ThisExpression"; +} + +export interface ArrayExpression extends ExpressionBase { + type: "ArrayExpression"; + + elements: (Expression | SpreadElement | undefined)[]; +} + +export interface ObjectExpression extends ExpressionBase { + type: "ObjectExpression"; + + properties: (Property | SpreadElement)[]; +} + +export interface Argument { + spread: Span; + expression: Expression; +} + +export type PropertOrSpread = Property | SpreadElement; + +export interface SpreadElement extends Node { + type: "SpreadElement"; + + spread: Span; + + arguments: Expression; +} + +export interface UnaryExpression extends ExpressionBase { + type: "UnaryExpression"; + + operator: UnaryOperator; + + argument: Expression; +} + +export interface UpdateExpression extends ExpressionBase { + type: "UpdateExpression"; + + operator: UpdateOperator; + + prefix: boolean; + + argument: Expression; +} + +export interface BinaryExpression extends ExpressionBase { + type: "BinaryExpression"; + + operator: BinaryOperator; + + left: Expression; + + right: Expression; +} + +export interface FunctionExpression extends Fn, ExpressionBase { + type: "FunctionExpression"; + + identifier: Identifier; +} + +export interface ClassExpression extends Class, ExpressionBase { + type: "ClassExpression"; + + identifier: Identifier; +} + +export interface AssignmentExpression extends ExpressionBase { + type: "AssignmentExpression"; + + operator: AssignmentOperator; + + left: Pattern | Expression; + + right: Expression; +} + +export interface MemberExpression extends ExpressionBase { + type: "MemberExpression"; + + object: Expression | Super; + + property: Expression; + + computed: boolean; +} + +export interface ConditionalExpression extends ExpressionBase { + type: "ConditionalExpression"; + + test: Expression; + + consequent: Expression; + + alternate: Expression; +} + +export interface Super extends Node, HasSpan { + type: "Super"; +} + +export interface CallExpression extends ExpressionBase { + type: "CallExpression"; + + callee: Expression | Super; + + arguments: Argument[]; - export interface Node { - type: string; - } + typeArguments?: TsTypeParameterInstantiation; +} - export interface HasSpan { - span: Span; - } +export interface NewExpression extends ExpressionBase { + type: "NewExpression"; - export interface HasDecorator { - decorators?: Decorator[]; - } + callee: Expression; - export interface Class extends HasSpan, HasDecorator { - body: ClassMember[]; + arguments: Argument[]; - superClass?: Expression; + typeArguments?: TsTypeParameterInstantiation; +} - is_abstract: boolean; +export interface SequenceExpression extends ExpressionBase { + type: "SequenceExpression"; - typeParams: TsTypeParameterDeclaration; + expressions: Expression[]; +} - superTypeParams?: TsTypeParameterInstantiation; +export interface ArrowFunctionExpression extends ExpressionBase { + type: "ArrowFunctionExpression"; - implements: TsExpressionWithTypeArguments[]; - } + params: Pattern[]; - export type ClassMember = - | Constructor - | ClassMethod - | PrivateMethod - | ClassProperty - | PrivateProperty - | TsIndexSignature; + body: BlockStatement | Expression; - export interface ClassPropertyBase extends Node, HasSpan, HasDecorator { - value?: Expression; + async: boolean; - typeAnnotation?: TsTypeAnnotation; + generator: boolean; - is_static: boolean; + typeParameters?: TsTypeParameterDeclaration; - computed: boolean; + returnType?: TsTypeAnnotation; +} - accessibility?: Accessibility; +export interface YieldExpression extends ExpressionBase { + type: "YieldExpression"; - /// Typescript extension. - is_abstract: boolean; + argument?: Expression; - is_optional: boolean; + delegate: boolean; +} - readonly: boolean; +export interface MetaProperty extends Node { + type: "MetaProperty"; - definite: boolean; - } + meta: Identifier; - export interface ClassProperty extends ClassPropertyBase { - type: "ClassProperty"; + property: Identifier; +} - key: Expression; - } +export interface AwaitExpression extends ExpressionBase { + type: "AwaitExpression"; - export interface PrivateProperty extends ClassPropertyBase { - type: "PrivateProperty"; + argument: Expression; +} - key: PrivateName; - } +export interface TplBase { + expressions: Expression[]; - export interface Param extends Node, HasSpan, HasDecorator { - type: 'Parameter' - pat: Pattern - } + quasis: TemplateElement[]; +} - export interface Constructor extends Node, HasSpan { - type: "Constructor"; +export interface TemplateLiteral extends ExpressionBase, TplBase { + type: "TemplateLiteral"; +} - key: PropertyName; +export interface TaggedTemplateExpression extends ExpressionBase, TplBase { + type: "TaggedTemplateExpression"; - params: (Param | TsParameterProperty)[]; + tag: Expression; - body: BlockStatement; + typeParameters: TsTypeParameterInstantiation; +} - accessibility?: Accessibility; +export interface TemplateElement extends ExpressionBase { + type: "TemplateElement"; - is_optional: boolean; - } + tail: boolean; + cooked: StringLiteral; + raw: StringLiteral; +} - export interface ClassMethodBase extends Node, HasSpan { - function: Fn; +export interface ParenthesisExpression extends ExpressionBase { + type: "ParenthesisExpression"; - kind: MethodKind; + expression: Expression; +} - is_static: boolean; +export interface Fn extends HasSpan, HasDecorator { + params: Param[]; - accessibility?: Accessibility; + body: BlockStatement; - is_abstract: boolean; + generator: boolean; - is_optional: boolean; - } + async: boolean; - export interface ClassMethod extends ClassMethodBase { - type: "ClassMethod"; + typeParameters?: TsTypeParameterDeclaration; - key: PropertyName; - } + returnType?: TsTypeAnnotation; +} - export interface PrivateMethod extends ClassMethodBase { - type: "PrivateMethod"; +interface PatternBase { + typeAnnotation?: TsTypeAnnotation; +} - key: PrivateName; - } +export interface Identifier extends HasSpan, PatternBase { + type: "Identifier"; - export interface Decorator extends Node, HasSpan { - type: "Decorator"; + value: string; - expression: Expression; - } + /// TypeScript only. Used in case of an optional parameter. + optional: boolean; +} - export type MethodKind = "method" | "setter" | "getter"; +export interface PrivateName extends ExpressionBase { + type: "PrivateName"; - export type Declaration = - | ClassDeclaration - | FunctionDeclaration - | VariableDeclaration - | TsInterfaceDeclaration - | TsTypeAliasDeclaration - | TsEnumDeclaration - | TsModuleDeclaration; + id: Identifier; +} - export interface FunctionDeclaration extends Fn { - type: "FunctionDeclaration"; +export type JSXObject = JSXMemberExpression | Identifier; - ident: Identifier; +export interface JSXMemberExpression extends Node { + type: "JSXMemberExpression"; - declare: boolean; - } + object: JSXObject; + property: Identifier; +} - export interface ClassDeclaration extends Class, Node { - type: "ClassDeclaration"; +/** + * XML-based namespace syntax: + */ +export interface JSXNamespacedName extends Node { + type: "JSXNamespacedName"; - identifier: Identifier; + namespace: Identifier; + name: Identifier; +} - declare: boolean; - } +export interface JSXEmptyExpression extends Node, HasSpan { + type: "JSXEmptyExpression"; +} - export interface VariableDeclaration extends Node, HasSpan { - type: "VariableDeclaration"; +export interface JSXExpressionContainer extends Node { + type: "JSXExpressionContainer"; - kind: VariableDeclarationKind; + expression: JSXExpression; +} - declare: boolean; +export type JSXExpression = JSXEmptyExpression | Expression; - declarations: VariableDeclarator[]; - } +export interface JSXSpreadChild extends Node { + type: "JSXSpreadChild"; - export type VariableDeclarationKind = "get" | "let" | "const"; + expression: Expression; +} - export interface VariableDeclarator extends Node, HasSpan { - type: "VariableDeclarator"; +export type JSXElementName = + | Identifier + | JSXMemberExpression + | JSXNamespacedName; - id: Pattern; +export interface JSXOpeningElement extends Node, HasSpan { + type: "JSXOpeningElement"; - /// Initialization expresion. - init?: Expression; + name: JSXElementName; - /// Typescript only - definite: boolean; - } + attrs?: JSXAttributeOrSpread[]; - export type Expression = - | ThisExpression - | ArrayExpression - | ObjectExpression - | FunctionExpression - | UnaryExpression - | UpdateExpression - | BinaryExpression - | AssignmentExpression - | MemberExpression - | ConditionalExpression - | CallExpression - | NewExpression - | SequenceExpression - | Identifier - | Literal - | TemplateLiteral - | TaggedTemplateExpression - | ArrowFunctionExpression - | ClassExpression - | YieldExpression - | MetaProperty - | AwaitExpression - | ParenthesisExpression - | JSXMemberExpression - | JSXNamespacedName - | JSXEmptyExpression - | JSXElement - | JSXFragment - | TsTypeAssertion - | TsNonNullExpression - | TsTypeCastExpression - | TsAsExpression - | PrivateName - | OptionalChainingExpression - | Invalid; + selfClosing: boolean; - interface ExpressionBase extends Node, HasSpan { } + typeArguments?: TsTypeParameterInstantiation; +} - export interface OptionalChainingExpression extends ExpressionBase { - type: "OptionalChainingExpression"; - /** - * Call expression or member expression. - */ - expr: Expression; - } +export type JSXAttributeOrSpread = JSXAttribute | SpreadElement; - export interface ThisExpression extends ExpressionBase { - type: "ThisExpression"; - } +export interface JSXClosingElement extends Node, HasSpan { + type: "JSXClosingElement"; - export interface ArrayExpression extends ExpressionBase { - type: "ArrayExpression"; + name: JSXElementName; +} - elements: (Expression | SpreadElement | undefined)[]; - } +export interface JSXAttribute extends Node, HasSpan { + type: "JSXAttribute"; - export interface ObjectExpression extends ExpressionBase { - type: "ObjectExpression"; + name: JSXAttributeName; - properties: (Property | SpreadElement)[]; - } + value?: JSXAttrValue; +} - export interface Argument { - spread: Span; - expression: Expression; - } +export type JSXAttributeName = Identifier | JSXNamespacedName; - export type PropertOrSpread = Property | SpreadElement; +export type JSXAttrValue = + | Literal + | JSXExpressionContainer + | JSXElement + | JSXFragment; - export interface SpreadElement extends Node { - type: "SpreadElement"; +export interface JSXText extends Node, HasSpan { + type: "JSXText"; - spread: Span; + value: string; + raw: string; +} - arguments: Expression; - } +export interface JSXElement extends Node, HasSpan { + type: "JSXElement"; - export interface UnaryExpression extends ExpressionBase { - type: "UnaryExpression"; + opening: JSXOpeningElement; + children: JSXElementChild[]; + closing?: JSXClosingElement; +} - operator: UnaryOperator; +export type JSXElementChild = + | JSXText + | JSXExpressionContainer + | JSXSpreadChild + | JSXElement + | JSXFragment; - argument: Expression; - } +export interface JSXFragment extends Node, HasSpan { + type: "JSXFragment"; - export interface UpdateExpression extends ExpressionBase { - type: "UpdateExpression"; + opening: JSXOpeningFragment; - operator: UpdateOperator; + children: JSXElementChild[]; - prefix: boolean; + closing: JSXClosingFragment; +} - argument: Expression; - } +export interface JSXOpeningFragment extends Node, HasSpan { + type: "JSXOpeningFragment"; +} - export interface BinaryExpression extends ExpressionBase { - type: "BinaryExpression"; +export interface JSXClosingFragment extends Node, HasSpan { + type: "JSXClosingFragment"; +} - operator: BinaryOperator; +export type Literal = + | StringLiteral + | BooleanLiteral + | NullLiteral + | NumericLiteral + | RegExpLiteral + | JSXText; - left: Expression; +export interface StringLiteral extends Node, HasSpan { + type: "StringLiteral"; - right: Expression; - } + value: string; + has_escape: boolean; +} - export interface FunctionExpression extends Fn, ExpressionBase { - type: "FunctionExpression"; +export interface BooleanLiteral extends Node, HasSpan { + type: "BooleanLiteral"; - identifier: Identifier; - } + value: boolean; +} - export interface ClassExpression extends Class, ExpressionBase { - type: "ClassExpression"; +export interface NullLiteral extends Node, HasSpan { + type: "NullLiteral"; +} - identifier: Identifier; - } +export interface RegExpLiteral extends Node, HasSpan { + type: "RegExpLiteral"; - export interface AssignmentExpression extends ExpressionBase { - type: "AssignmentExpression"; + pattern: string; + flags: string; +} - operator: AssignmentOperator; +export interface NumericLiteral extends Node, HasSpan { + type: "NumericLiteral"; - left: Pattern | Expression; + value: number; +} - right: Expression; - } +export type ModuleDeclaration = + | ImportDeclaration + | ExportDeclaration + | ExportNamedDeclaration + | ExportDefaultDeclaration + | ExportDefaultExpression + | ExportAllDeclaration + | TsImportEqualsDeclaration + | TsExportAssignment + | TsNamespaceExportDeclaration; + +export interface ExportDefaultExpression extends Node, HasSpan { + type: "ExportDefaultExpression"; + + expression: Expression; +} - export interface MemberExpression extends ExpressionBase { - type: "MemberExpression"; +export interface ExportDeclaration extends Node, HasSpan { + type: "ExportDeclaration"; - object: Expression | Super; + declaration: Declaration; +} - property: Expression; +export interface ImportDeclaration extends Node, HasSpan { + type: "ImportDeclaration"; - computed: boolean; - } + specifiers: ImporSpecifier[]; - export interface ConditionalExpression extends ExpressionBase { - type: "ConditionalExpression"; + source: StringLiteral; +} - test: Expression; +export type ImporSpecifier = + | ImportDefaultSpecifier + | NamedImportSpecifier + | ImportNamespaceSpecifier; - consequent: Expression; +export interface ExportAllDeclaration extends Node, HasSpan { + type: "ExportAllDeclaration"; - alternate: Expression; - } + source: StringLiteral; +} - export interface Super extends Node, HasSpan { - type: "Super"; - } +/** + * - `export { foo } from 'mod'` + * - `export { foo as bar } from 'mod'` + */ +export interface ExportNamedDeclaration extends Node, HasSpan { + type: "ExportNamedDeclaration"; - export interface CallExpression extends ExpressionBase { - type: "CallExpression"; + specifiers: ExportSpecifier[]; - callee: Expression | Super; + source?: StringLiteral; +} - arguments: Argument[]; +export interface ExportDefaultDeclaration extends Node, HasSpan { + type: "ExportDefaultDeclaration"; - typeArguments?: TsTypeParameterInstantiation; - } + decl: DefaultDecl; +} - export interface NewExpression extends ExpressionBase { - type: "NewExpression"; +export type DefaultDecl = + | ClassExpression + | FunctionExpression + | TsInterfaceDeclaration; + +export type ImportSpecifier = + | NamedImportSpecifier + | ImportDefaultSpecifier + | ImportNamespaceSpecifier; + +/** + * e.g. `import foo from 'mod.js'` + */ +export interface ImportDefaultSpecifier extends Node, HasSpan { + type: "ImportDefaultSpecifier"; + local: Identifier; +} - callee: Expression; +/** + * e.g. `import * as foo from 'mod.js'`. + */ +export interface ImportNamespaceSpecifier extends Node, HasSpan { + type: "ImportNamespaceSpecifier"; - arguments: Argument[]; + local: Identifier; +} - typeArguments?: TsTypeParameterInstantiation; - } +/** + * e.g. - `import { foo } from 'mod.js'` + * + * local = foo, imported = None + * + * e.g. `import { foo as bar } from 'mod.js'` + * + * local = bar, imported = Some(foo) for + */ +export interface NamedImportSpecifier extends Node, HasSpan { + type: "ImportSpecifier"; + local: Identifier; + imported: Identifier; +} - export interface SequenceExpression extends ExpressionBase { - type: "SequenceExpression"; +export type ExportSpecifier = + | ExportNamespaceSpecifer + | ExportDefaultSpecifier + | NamedExportSpecifier; - expressions: Expression[]; - } +/** + * `export * as foo from 'src';` + */ +export interface ExportNamespaceSpecifer extends Node, HasSpan { + type: "ExportNamespaceSpecifer"; - export interface ArrowFunctionExpression extends ExpressionBase { - type: "ArrowFunctionExpression"; + name: Identifier; +} - params: Pattern[]; +export interface ExportDefaultSpecifier extends Node, HasSpan { + type: "ExportDefaultSpecifier"; - body: BlockStatement | Expression; + exported: Identifier; +} - async: boolean; +export interface NamedExportSpecifier extends Node, HasSpan { + type: "ExportSpecifier"; - generator: boolean; + orig: Identifier; + /** + * `Some(bar)` in `export { foo as bar }` + */ + exported: Identifier; +} - typeParameters?: TsTypeParameterDeclaration; +interface HasInterpreter { + /** + * e.g. `/usr/bin/node` for `#!/usr/bin/node` + */ + interpreter: string; +} - returnType?: TsTypeAnnotation; - } +export type Program = Module | Script; - export interface YieldExpression extends ExpressionBase { - type: "YieldExpression"; +export interface Module extends Node, HasSpan, HasInterpreter { + type: "Module"; - argument?: Expression; + body: ModuleItem[]; +} - delegate: boolean; - } +export interface Script extends Node, HasSpan, HasInterpreter { + type: "Script"; - export interface MetaProperty extends Node { - type: "MetaProperty"; + body: Statement[]; +} - meta: Identifier; +export type ModuleItem = ModuleDeclaration | Statement; + +export type BinaryOperator = + | "==" + | "!=" + | "===" + | "!==" + | "<" + | "<=" + | ">" + | ">=" + | "<<" + | ">>" + | ">>>" + | "+" + | "-" + | "*" + | "/" + | "%" + | "**" + | "|" + | "^" + | "&" + | "||" + | "&&" + | "in" + | "instanceof" + | "??"; + +export type AssignmentOperator = + | "=" + | "+=" + | "-=" + | "*=" + | "/=" + | "%=" + | "**=" + | "<<=" + | ">>=" + | ">>>=" + | "|=" + | "^=" + | "&="; + +export type UpdateOperator = "++" | "--"; + +export type UnaryOperator = + | "-" + | "+" + | "!" + | "~" + | "typeof" + | "void" + | "delete"; + +export type Pattern = + | Identifier + | ArrayPattern + | RestElement + | ObjectPattern + | AssignmentPattern + | Invalid + | Expression; + +export interface ArrayPattern extends Node, HasSpan, PatternBase { + type: "ArrayPattern"; + + elements: (Pattern | undefined)[]; +} - property: Identifier; - } +export interface ObjectPattern extends Node, HasSpan, PatternBase { + type: "ObjectPattern"; - export interface AwaitExpression extends ExpressionBase { - type: "AwaitExpression"; + props: ObjectPatternProperty[]; +} - argument: Expression; - } +export interface AssignmentPattern extends Node, HasSpan, PatternBase { + type: "AssignmentPattern"; - export interface TplBase { - expressions: Expression[]; + left: Pattern; + right: Expression; +} + +export interface RestElement extends Node, HasSpan, PatternBase { + type: "RestElement"; - quasis: TemplateElement[]; - } + rest: Span; + + argument: Pattern; +} - export interface TemplateLiteral extends ExpressionBase, TplBase { - type: "TemplateLiteral"; - } +export type ObjectPatternProperty = + | KeyValuePatternProperty + | AssignmentPatternProperty + | RestElement; - export interface TaggedTemplateExpression extends ExpressionBase, TplBase { - type: "TaggedTemplateExpression"; +/** + * `{key: value}` + */ +export interface KeyValuePatternProperty extends Node { + type: "KeyValuePatternProperty"; - tag: Expression; + key: PropertyName; + value: Pattern; +} - typeParameters: TsTypeParameterInstantiation; - } +/** + * `{key}` or `{key = value}` + */ +export interface AssignmentPatternProperty extends Node, HasSpan { + type: "AssignmentPatternProperty"; - export interface TemplateElement extends ExpressionBase { - type: "TemplateElement"; + key: Identifier; + value?: Expression; +} - tail: boolean; - cooked: StringLiteral; - raw: StringLiteral; - } +/** Identifier is `a` in `{ a, }` */ +export type Property = + | Identifier + | KeyValueProperty + | AssignmentProperty + | GetterProperty + | SetterProperty + | MethodProperty; + +interface PropBase extends Node { + key: PropertyName; +} - export interface ParenthesisExpression extends ExpressionBase { - type: "ParenthesisExpression"; +export interface KeyValueProperty extends PropBase { + type: "KeyValueProperty"; - expression: Expression; - } + value: Expression; +} - export interface Fn extends HasSpan, HasDecorator { - params: Param[]; +export interface AssignmentProperty extends Node { + type: "AssignmentProperty"; - body: BlockStatement; + key: Identifier; + value: Expression; +} - generator: boolean; +export interface GetterProperty extends PropBase, HasSpan { + type: "GetterProperty"; - async: boolean; + typeAnnotation?: TsTypeAnnotation; - typeParameters?: TsTypeParameterDeclaration; + body: BlockStatement; +} - returnType?: TsTypeAnnotation; - } +export interface SetterProperty extends PropBase, HasSpan { + type: "SetterProperty"; - interface PatternBase { - typeAnnotation?: TsTypeAnnotation; - } + param: Pattern; + body: BlockStatement; +} - export interface Identifier extends HasSpan, PatternBase { - type: "Identifier"; +export interface MethodProperty extends PropBase, Fn { + type: "MethodProperty"; +} - value: string; +export type PropertyName = + | Identifier + | StringLiteral + | NumericLiteral + | ComputedPropName; - /// TypeScript only. Used in case of an optional parameter. - optional: boolean; - } +export interface ComputedPropName extends Node, HasSpan { + type: "Computed"; + expression: Expression; +} - export interface PrivateName extends ExpressionBase { - type: "PrivateName"; +export interface BlockStatement extends Node, HasSpan { + type: "BlockStatement"; - id: Identifier; - } + stmts: Statement[]; +} - export type JSXObject = JSXMemberExpression | Identifier; +export interface ExpressionStatement extends Node, HasSpan { + type: "ExpressionStatement"; + expression: Expression; +} - export interface JSXMemberExpression extends Node { - type: "JSXMemberExpression"; +export type Statement = + | ExpressionStatement + | BlockStatement + | EmptyStatement + | DebuggerStatement + | WithStatement + | ReturnStatement + | LabeledStatement + | BreakStatement + | ContinueStatement + | IfStatement + | SwitchStatement + | ThrowStatement + | TryStatement + | WhileStatement + | DoWhileStatement + | ForStatement + | ForInStatement + | ForOfStatement + | Declaration; + +export interface EmptyStatement extends Node, HasSpan { + type: "EmptyStatement"; +} - object: JSXObject; - property: Identifier; - } +export interface DebuggerStatement extends Node, HasSpan { + type: "DebuggerStatement"; +} - /** - * XML-based namespace syntax: - */ - export interface JSXNamespacedName extends Node { - type: "JSXNamespacedName"; +export interface WithStatement extends Node, HasSpan { + type: "WithStatement"; - namespace: Identifier; - name: Identifier; - } + object: Expression; + body: Statement; +} - export interface JSXEmptyExpression extends Node, HasSpan { - type: "JSXEmptyExpression"; - } +export interface ReturnStatement extends Node, HasSpan { + type: "ReturnStatement"; - export interface JSXExpressionContainer extends Node { - type: "JSXExpressionContainer"; + argument: Expression; +} - expression: JSXExpression; - } +export interface LabeledStatement extends Node, HasSpan { + type: "LabeledStatement"; - export type JSXExpression = JSXEmptyExpression | Expression; + label: Identifier; + body: Statement; +} - export interface JSXSpreadChild extends Node { - type: "JSXSpreadChild"; +export interface BreakStatement extends Node, HasSpan { + type: "BreakStatement"; - expression: Expression; - } + label: Identifier; +} - export type JSXElementName = - | Identifier - | JSXMemberExpression - | JSXNamespacedName; +export interface ContinueStatement extends Node, HasSpan { + type: "ContinueStatement"; - export interface JSXOpeningElement extends Node, HasSpan { - type: "JSXOpeningElement"; + label: Identifier; +} - name: JSXElementName; +export interface IfStatement extends Node, HasSpan { + type: "IfStatement"; - attrs?: JSXAttributeOrSpread[]; + test: Expression; + consequent: Statement; + alternate?: Statement; +} - selfClosing: boolean; +export interface SwitchStatement extends Node, HasSpan { + type: "SwitchStatement"; - typeArguments?: TsTypeParameterInstantiation; - } + discriminant: Expression; + cases: SwitchCase[]; +} - export type JSXAttributeOrSpread = JSXAttribute | SpreadElement; +export interface ThrowStatement extends Node, HasSpan { + type: "ThrowStatement"; - export interface JSXClosingElement extends Node, HasSpan { - type: "JSXClosingElement"; + argument: Expression; +} - name: JSXElementName; - } +export interface TryStatement extends Node, HasSpan { + type: "TryStatement"; - export interface JSXAttribute extends Node, HasSpan { - type: "JSXAttribute"; + block: BlockStatement; + handler?: CatchClause; + finalizer: BlockStatement; +} - name: JSXAttributeName; +export interface WhileStatement extends Node, HasSpan { + type: "WhileStatement"; - value?: JSXAttrValue; - } + test: Expression; + body: Statement; +} - export type JSXAttributeName = Identifier | JSXNamespacedName; +export interface DoWhileStatement extends Node, HasSpan { + type: "DoWhileStatement"; - export type JSXAttrValue = - | Literal - | JSXExpressionContainer - | JSXElement - | JSXFragment; + test: Expression; + body: Statement; +} - export interface JSXText extends Node, HasSpan { - type: "JSXText"; +export interface ForStatement extends Node, HasSpan { + type: "ForStatement"; - value: string; - raw: string; - } + init?: VariableDeclaration | Expression; + test?: Expression; + update?: Expression; + body: Statement; +} - export interface JSXElement extends Node, HasSpan { - type: "JSXElement"; +export interface ForInStatement extends Node, HasSpan { + type: "ForInStatement"; - opening: JSXOpeningElement; - children: JSXElementChild[]; - closing?: JSXClosingElement; - } + left: VariableDeclaration | Pattern; + right: Expression; + body: Statement; +} - export type JSXElementChild = - | JSXText - | JSXExpressionContainer - | JSXSpreadChild - | JSXElement - | JSXFragment; +export interface ForOfStatement extends Node, HasSpan { + type: "ForOfStatement"; + + /** + * Span of the await token. + * + * es2018 for-await-of statements, e.g., `for await (const x of xs) {` + */ + await: Span; + left: VariableDeclaration | Pattern; + right: Expression; + body: Statement; +} - export interface JSXFragment extends Node, HasSpan { - type: "JSXFragment"; +export interface SwitchCase extends Node, HasSpan { + type: "SwitchCase"; - opening: JSXOpeningFragment; + /** + * Undefined for default case + */ + test?: Expression; + consequent: Statement[]; +} - children: JSXElementChild[]; +export interface CatchClause extends Node, HasSpan { + type: "CatchClause"; - closing: JSXClosingFragment; - } + /** + * The param is `undefined` if the catch binding is omitted. E.g., `try { foo() } catch {}` + */ + param: Pattern; + body: BlockStatement; +} - export interface JSXOpeningFragment extends Node, HasSpan { - type: "JSXOpeningFragment"; - } +export interface TsTypeAnnotation extends Node, HasSpan { + type: "TsTypeAnnotation"; - export interface JSXClosingFragment extends Node, HasSpan { - type: "JSXClosingFragment"; - } + typeAnnotation: TsType; +} - export type Literal = - | StringLiteral - | BooleanLiteral - | NullLiteral - | NumericLiteral - | RegExpLiteral - | JSXText; +export interface TsTypeParameterDeclaration extends Node, HasSpan { + type: "TsTypeParameterDeclaration"; - export interface StringLiteral extends Node, HasSpan { - type: "StringLiteral"; + parameters: TsTypeParameter[]; +} - value: string; - has_escape: boolean; - } +export interface TsTypeParameter extends Node, HasSpan { + type: "TsTypeParameter"; - export interface BooleanLiteral extends Node, HasSpan { - type: "BooleanLiteral"; + name: Identifier; + constraint: TsType; + default: TsType; +} - value: boolean; - } +export interface TsTypeParameterInstantiation extends Node, HasSpan { + type: "TsTypeParameterInstantiation"; - export interface NullLiteral extends Node, HasSpan { - type: "NullLiteral"; - } + params: TsType[]; +} - export interface RegExpLiteral extends Node, HasSpan { - type: "RegExpLiteral"; +export interface TsTypeCastExpression extends Node, HasSpan { + type: "TsTypeCastExpression"; - pattern: string; - flags: string; - } + expression: Expression; + typeAnnotation: TsTypeAnnotation; +} - export interface NumericLiteral extends Node, HasSpan { - type: "NumericLiteral"; +export interface TsParameterProperty extends Node, HasSpan, HasDecorator { + type: "TsParameterProperty"; - value: number; - } + accessibility?: Accessibility; + readonly: boolean; + param: TsParameterPropertyParameter; +} - export type ModuleDeclaration = - | ImportDeclaration - | ExportDeclaration - | ExportNamedDeclaration - | ExportDefaultDeclaration - | ExportDefaultExpression - | ExportAllDeclaration - | TsImportEqualsDeclaration - | TsExportAssignment - | TsNamespaceExportDeclaration; - - export interface ExportDefaultExpression extends Node, HasSpan { - type: "ExportDefaultExpression"; - - expression: Expression; - } - - export interface ExportDeclaration extends Node, HasSpan { - type: "ExportDeclaration"; - - declaration: Declaration; - } - - export interface ImportDeclaration extends Node, HasSpan { - type: "ImportDeclaration"; - - specifiers: ImporSpecifier[]; - - source: StringLiteral; - } - - export type ImporSpecifier = - | ImportDefaultSpecifier - | NamedImportSpecifier - | ImportNamespaceSpecifier; - - export interface ExportAllDeclaration extends Node, HasSpan { - type: "ExportAllDeclaration"; - - source: StringLiteral; - } - - /** - * - `export { foo } from 'mod'` - * - `export { foo as bar } from 'mod'` - */ - export interface ExportNamedDeclaration extends Node, HasSpan { - type: "ExportNamedDeclaration"; - - specifiers: ExportSpecifier[]; - - source?: StringLiteral; - } - - export interface ExportDefaultDeclaration extends Node, HasSpan { - type: "ExportDefaultDeclaration"; - - decl: DefaultDecl; - } - - export type DefaultDecl = - | ClassExpression - | FunctionExpression - | TsInterfaceDeclaration; - - export type ImportSpecifier = - | NamedImportSpecifier - | ImportDefaultSpecifier - | ImportNamespaceSpecifier; - - /** - * e.g. `import foo from 'mod.js'` - */ - export interface ImportDefaultSpecifier extends Node, HasSpan { - type: "ImportDefaultSpecifier"; - local: Identifier; - } - - /** - * e.g. `import * as foo from 'mod.js'`. - */ - export interface ImportNamespaceSpecifier extends Node, HasSpan { - type: "ImportNamespaceSpecifier"; - - local: Identifier; - } - - /** - * e.g. - `import { foo } from 'mod.js'` - * - * local = foo, imported = None - * - * e.g. `import { foo as bar } from 'mod.js'` - * - * local = bar, imported = Some(foo) for - */ - export interface NamedImportSpecifier extends Node, HasSpan { - type: "ImportSpecifier"; - local: Identifier; - imported: Identifier; - } - - export type ExportSpecifier = - | ExportNamespaceSpecifer - | ExportDefaultSpecifier - | NamedExportSpecifier; - - /** - * `export * as foo from 'src';` - */ - export interface ExportNamespaceSpecifer extends Node, HasSpan { - type: "ExportNamespaceSpecifer"; - - name: Identifier; - } - - export interface ExportDefaultSpecifier extends Node, HasSpan { - type: "ExportDefaultSpecifier"; - - exported: Identifier; - } - - export interface NamedExportSpecifier extends Node, HasSpan { - type: "ExportSpecifier"; - - orig: Identifier; - /** - * `Some(bar)` in `export { foo as bar }` - */ - exported: Identifier; - } - - interface HasInterpreter { - /** - * e.g. `/usr/bin/node` for `#!/usr/bin/node` - */ - interpreter: string; - } - - export type Program = Module | Script; - - export interface Module extends Node, HasSpan, HasInterpreter { - type: "Module"; - - body: ModuleItem[]; - } - - export interface Script extends Node, HasSpan, HasInterpreter { - type: "Script"; - - body: Statement[]; - } - - export type ModuleItem = ModuleDeclaration | Statement; - - export type BinaryOperator = - | "==" - | "!=" - | "===" - | "!==" - | "<" - | "<=" - | ">" - | ">=" - | "<<" - | ">>" - | ">>>" - | "+" - | "-" - | "*" - | "/" - | "%" - | "**" - | "|" - | "^" - | "&" - | "||" - | "&&" - | "in" - | "instanceof" - | "??"; - - export type AssignmentOperator = - | "=" - | "+=" - | "-=" - | "*=" - | "/=" - | "%=" - | "**=" - | "<<=" - | ">>=" - | ">>>=" - | "|=" - | "^=" - | "&="; - - export type UpdateOperator = "++" | "--"; - - export type UnaryOperator = - | "-" - | "+" - | "!" - | "~" - | "typeof" - | "void" - | "delete"; - - export type Pattern = - | Identifier - | ArrayPattern - | RestElement - | ObjectPattern - | AssignmentPattern - | Invalid - | Expression; - - export interface ArrayPattern extends Node, HasSpan, PatternBase { - type: "ArrayPattern"; - - elements: (Pattern | undefined)[]; - } - - export interface ObjectPattern extends Node, HasSpan, PatternBase { - type: "ObjectPattern"; - - props: ObjectPatternProperty[]; - } - - export interface AssignmentPattern extends Node, HasSpan, PatternBase { - type: "AssignmentPattern"; - - left: Pattern; - right: Expression; - } - - export interface RestElement extends Node, HasSpan, PatternBase { - type: "RestElement"; - - rest: Span; - - argument: Pattern; - } - - export type ObjectPatternProperty = - | KeyValuePatternProperty - | AssignmentPatternProperty - | RestElement; - - /** - * `{key: value}` - */ - export interface KeyValuePatternProperty extends Node { - type: "KeyValuePatternProperty"; - - key: PropertyName; - value: Pattern; - } - - /** - * `{key}` or `{key = value}` - */ - export interface AssignmentPatternProperty extends Node, HasSpan { - type: "AssignmentPatternProperty"; - - key: Identifier; - value?: Expression; - } - - /** Identifier is `a` in `{ a, }` */ - export type Property = - | Identifier - | KeyValueProperty - | AssignmentProperty - | GetterProperty - | SetterProperty - | MethodProperty; - - interface PropBase extends Node { - key: PropertyName; - } - - export interface KeyValueProperty extends PropBase { - type: "KeyValueProperty"; - - value: Expression; - } - - export interface AssignmentProperty extends Node { - type: "AssignmentProperty"; - - key: Identifier; - value: Expression; - } - - export interface GetterProperty extends PropBase, HasSpan { - type: "GetterProperty"; - - typeAnnotation?: TsTypeAnnotation; - - body: BlockStatement; - } - - export interface SetterProperty extends PropBase, HasSpan { - type: "SetterProperty"; - - param: Pattern; - body: BlockStatement; - } - - export interface MethodProperty extends PropBase, Fn { - type: "MethodProperty"; - } - - export type PropertyName = - | Identifier - | StringLiteral - | NumericLiteral - | ComputedPropName; +export type TsParameterPropertyParameter = Identifier | AssignmentPattern; - export interface ComputedPropName extends Node, HasSpan { - type: "Computed"; - expression: Expression; - } - - export interface BlockStatement extends Node, HasSpan { - type: "BlockStatement"; - - stmts: Statement[]; - } - - export interface ExpressionStatement extends Node, HasSpan { - type: "ExpressionStatement"; - expression: Expression; - } +export interface TsQualifiedName extends Node { + type: "TsQualifiedName"; - export type Statement = - | ExpressionStatement - | BlockStatement - | EmptyStatement - | DebuggerStatement - | WithStatement - | ReturnStatement - | LabeledStatement - | BreakStatement - | ContinueStatement - | IfStatement - | SwitchStatement - | ThrowStatement - | TryStatement - | WhileStatement - | DoWhileStatement - | ForStatement - | ForInStatement - | ForOfStatement - | Declaration; - - export interface EmptyStatement extends Node, HasSpan { - type: "EmptyStatement"; - } - - export interface DebuggerStatement extends Node, HasSpan { - type: "DebuggerStatement"; - } - - export interface WithStatement extends Node, HasSpan { - type: "WithStatement"; - - object: Expression; - body: Statement; - } - - export interface ReturnStatement extends Node, HasSpan { - type: "ReturnStatement"; - - argument: Expression; - } - - export interface LabeledStatement extends Node, HasSpan { - type: "LabeledStatement"; - - label: Identifier; - body: Statement; - } - - export interface BreakStatement extends Node, HasSpan { - type: "BreakStatement"; - - label: Identifier; - } - - export interface ContinueStatement extends Node, HasSpan { - type: "ContinueStatement"; - - label: Identifier; - } - - export interface IfStatement extends Node, HasSpan { - type: "IfStatement"; - - test: Expression; - consequent: Statement; - alternate?: Statement; - } - - export interface SwitchStatement extends Node, HasSpan { - type: "SwitchStatement"; - - discriminant: Expression; - cases: SwitchCase[]; - } - - export interface ThrowStatement extends Node, HasSpan { - type: "ThrowStatement"; - - argument: Expression; - } - - export interface TryStatement extends Node, HasSpan { - type: "TryStatement"; - - block: BlockStatement; - handler?: CatchClause; - finalizer: BlockStatement; - } - - export interface WhileStatement extends Node, HasSpan { - type: "WhileStatement"; - - test: Expression; - body: Statement; - } - - export interface DoWhileStatement extends Node, HasSpan { - type: "DoWhileStatement"; - - test: Expression; - body: Statement; - } - - export interface ForStatement extends Node, HasSpan { - type: "ForStatement"; + left: TsEntityName; + right: Identifier; +} - init?: VariableDeclaration | Expression; - test?: Expression; - update?: Expression; - body: Statement; - } +export type TsEntityName = TsQualifiedName | Identifier; - export interface ForInStatement extends Node, HasSpan { - type: "ForInStatement"; +export type TsSignatureDeclaration = + | TsCallSignatureDeclaration + | TsConstructSignatureDeclaration + | TsMethodSignature + | TsFunctionType + | TsConstructorType; - left: VariableDeclaration | Pattern; - right: Expression; - body: Statement; - } +export type TsTypeElement = + | TsCallSignatureDeclaration + | TsConstructSignatureDeclaration + | TsPropertySignature + | TsMethodSignature + | TsIndexSignature; - export interface ForOfStatement extends Node, HasSpan { - type: "ForOfStatement"; +export interface TsCallSignatureDeclaration extends Node, HasSpan { + type: "TsCallSignatureDeclaration"; - /** - * Span of the await token. - * - * es2018 for-await-of statements, e.g., `for await (const x of xs) {` - */ - await: Span; - left: VariableDeclaration | Pattern; - right: Expression; - body: Statement; - } + params: TsFnParameter[]; + typeAnnotation: TsTypeAnnotation; + typeParams: TsTypeParameterDeclaration; +} - export interface SwitchCase extends Node, HasSpan { - type: "SwitchCase"; +export interface TsConstructSignatureDeclaration extends Node, HasSpan { + type: "TsConstructSignatureDeclaration"; - /** - * Undefined for default case - */ - test?: Expression; - consequent: Statement[]; - } + params: TsFnParameter[]; + typeAnnotation: TsTypeAnnotation; + typeParams: TsTypeParameterDeclaration; +} - export interface CatchClause extends Node, HasSpan { - type: "CatchClause"; +export interface TsPropertySignature extends Node, HasSpan { + type: "TsPropertySignature"; - /** - * The param is `undefined` if the catch binding is omitted. E.g., `try { foo() } catch {}` - */ - param: Pattern; - body: BlockStatement; - } + readonly: boolean; + key: Expression; + computed: boolean; + optional: boolean; - export interface TsTypeAnnotation extends Node, HasSpan { - type: "TsTypeAnnotation"; + init: Expression; + params: TsFnParameter[]; - typeAnnotation: TsType; - } + typeAnnotation?: TsTypeAnnotation; + typeParams: TsTypeParameterDeclaration; +} - export interface TsTypeParameterDeclaration extends Node, HasSpan { - type: "TsTypeParameterDeclaration"; +export interface TsMethodSignature extends Node, HasSpan { + type: "TsMethodSignature"; - parameters: TsTypeParameter[]; - } + readonly: boolean; + key: Expression; + computed: boolean; + optional: boolean; + params: TsFnParameter[]; - export interface TsTypeParameter extends Node, HasSpan { - type: "TsTypeParameter"; + typeAnnotation: TsTypeAnnotation; + typeParams: TsTypeParameterDeclaration; +} - name: Identifier; - constraint: TsType; - default: TsType; - } +export interface TsIndexSignature extends Node, HasSpan { + type: "TsIndexSignature"; - export interface TsTypeParameterInstantiation extends Node, HasSpan { - type: "TsTypeParameterInstantiation"; + readonly: boolean; + params: TsFnParameter[]; - params: TsType[]; - } - - export interface TsTypeCastExpression extends Node, HasSpan { - type: "TsTypeCastExpression"; - - expression: Expression; - typeAnnotation: TsTypeAnnotation; - } - - export interface TsParameterProperty extends Node, HasSpan, HasDecorator { - type: "TsParameterProperty"; - - accessibility?: Accessibility; - readonly: boolean; - param: TsParameterPropertyParameter; - } - - export type TsParameterPropertyParameter = Identifier | AssignmentPattern; - - export interface TsQualifiedName extends Node { - type: "TsQualifiedName"; - - left: TsEntityName; - right: Identifier; - } - - export type TsEntityName = TsQualifiedName | Identifier; - - export type TsSignatureDeclaration = - | TsCallSignatureDeclaration - | TsConstructSignatureDeclaration - | TsMethodSignature - | TsFunctionType - | TsConstructorType; - - export type TsTypeElement = - | TsCallSignatureDeclaration - | TsConstructSignatureDeclaration - | TsPropertySignature - | TsMethodSignature - | TsIndexSignature; - - export interface TsCallSignatureDeclaration extends Node, HasSpan { - type: "TsCallSignatureDeclaration"; - - params: TsFnParameter[]; - typeAnnotation: TsTypeAnnotation; - typeParams: TsTypeParameterDeclaration; - } - - export interface TsConstructSignatureDeclaration extends Node, HasSpan { - type: "TsConstructSignatureDeclaration"; - - params: TsFnParameter[]; - typeAnnotation: TsTypeAnnotation; - typeParams: TsTypeParameterDeclaration; - } - - export interface TsPropertySignature extends Node, HasSpan { - type: "TsPropertySignature"; - - readonly: boolean; - key: Expression; - computed: boolean; - optional: boolean; - - init: Expression; - params: TsFnParameter[]; - - typeAnnotation?: TsTypeAnnotation; - typeParams: TsTypeParameterDeclaration; - } - - export interface TsMethodSignature extends Node, HasSpan { - type: "TsMethodSignature"; - - readonly: boolean; - key: Expression; - computed: boolean; - optional: boolean; - params: TsFnParameter[]; - - typeAnnotation: TsTypeAnnotation; - typeParams: TsTypeParameterDeclaration; - } - - export interface TsIndexSignature extends Node, HasSpan { - type: "TsIndexSignature"; - - readonly: boolean; - params: TsFnParameter[]; - - typeAnnotation?: TsTypeAnnotation; - } - - export type TsType = - | TsKeywordType - | TsThisType - | TsFnOrConstructorType - | TsTypeReference - | TsTypeQuery - | TsTypeLiteral - | TsArrayType - | TsTupleType - | TsOptionalType - | TsRestType - | TsUnionOrIntersectionType - | TsConditionalType - | TsInferType - | TsParenthesizedType - | TsTypeOperator - | TsIndexedAccessType - | TsMappedType - | TsLiteralType - | TsImportType - | TsTypePredicate; + typeAnnotation?: TsTypeAnnotation; +} - export type TsFnOrConstructorType = TsFunctionType | TsConstructorType; - - export interface TsKeywordType extends Node, HasSpan { - type: "TsKeywordType"; - - kind: TsKeywordTypeKind; - } - - export type TsKeywordTypeKind = - | "any" - | "unknown" - | "number" - | "object" - | "boolean" - | "bigint" - | "string" - | "symbol" - | "void" - | "undefined" - | "null" - | "never"; +export type TsType = + | TsKeywordType + | TsThisType + | TsFnOrConstructorType + | TsTypeReference + | TsTypeQuery + | TsTypeLiteral + | TsArrayType + | TsTupleType + | TsOptionalType + | TsRestType + | TsUnionOrIntersectionType + | TsConditionalType + | TsInferType + | TsParenthesizedType + | TsTypeOperator + | TsIndexedAccessType + | TsMappedType + | TsLiteralType + | TsImportType + | TsTypePredicate; + +export type TsFnOrConstructorType = TsFunctionType | TsConstructorType; + +export interface TsKeywordType extends Node, HasSpan { + type: "TsKeywordType"; + + kind: TsKeywordTypeKind; +} - export interface TsThisType extends Node, HasSpan { - type: "TsThisType"; - } +export type TsKeywordTypeKind = + | "any" + | "unknown" + | "number" + | "object" + | "boolean" + | "bigint" + | "string" + | "symbol" + | "void" + | "undefined" + | "null" + | "never"; + +export interface TsThisType extends Node, HasSpan { + type: "TsThisType"; +} - export type TsFnParameter = Identifier | RestElement | ObjectPattern; +export type TsFnParameter = Identifier | RestElement | ObjectPattern; - export interface TsFunctionType extends Node, HasSpan { - type: "TsFunctionType"; +export interface TsFunctionType extends Node, HasSpan { + type: "TsFunctionType"; - typeParams: TsTypeParameterDeclaration; - typeAnnotation: TsTypeAnnotation; - } + typeParams: TsTypeParameterDeclaration; + typeAnnotation: TsTypeAnnotation; +} - export interface TsConstructorType extends Node, HasSpan { - type: "TsConstructorType"; +export interface TsConstructorType extends Node, HasSpan { + type: "TsConstructorType"; - params: TsFnParameter[]; + params: TsFnParameter[]; - typeParams: TsTypeParameterDeclaration; - typeAnnotation: TsTypeAnnotation; - } + typeParams: TsTypeParameterDeclaration; + typeAnnotation: TsTypeAnnotation; +} - export interface TsTypeReference extends Node, HasSpan { - type: "TsTypeReference"; +export interface TsTypeReference extends Node, HasSpan { + type: "TsTypeReference"; - typeName: TsEntityName; - typeParams: TsTypeParameterInstantiation; - } + typeName: TsEntityName; + typeParams: TsTypeParameterInstantiation; +} - export interface TsTypePredicate extends Node, HasSpan { - type: "TsTypePredicate"; +export interface TsTypePredicate extends Node, HasSpan { + type: "TsTypePredicate"; - asserts: boolean; + asserts: boolean; - paramName: TsThisTypeOrIdent; - typeAnnotation: TsTypeAnnotation; - } + paramName: TsThisTypeOrIdent; + typeAnnotation: TsTypeAnnotation; +} - export type TsThisTypeOrIdent = TsThisType | Identifier; +export type TsThisTypeOrIdent = TsThisType | Identifier; - export interface TsImportType extends Node, HasSpan { - argument: StringLiteral; - qualifier?: TsEntityName; - typeArguments?: TsTypeParameterInstantiation; - } +export interface TsImportType extends Node, HasSpan { + argument: StringLiteral; + qualifier?: TsEntityName; + typeArguments?: TsTypeParameterInstantiation; +} - /** - * `typeof` operator - */ - export interface TsTypeQuery extends Node, HasSpan { - type: "TsTypeQuery"; +/** + * `typeof` operator + */ +export interface TsTypeQuery extends Node, HasSpan { + type: "TsTypeQuery"; - exprName: TsTypeQueryExpr; - } + exprName: TsTypeQueryExpr; +} - export type TsTypeQueryExpr = TsEntityName | TsImportType; +export type TsTypeQueryExpr = TsEntityName | TsImportType; - export interface TsTypeLiteral extends Node, HasSpan { - type: "TsTypeLiteral"; +export interface TsTypeLiteral extends Node, HasSpan { + type: "TsTypeLiteral"; - members: TsTypeElement[]; - } + members: TsTypeElement[]; +} - export interface TsArrayType extends Node, HasSpan { - type: "TsArrayType"; +export interface TsArrayType extends Node, HasSpan { + type: "TsArrayType"; - elemType: TsType; - } + elemType: TsType; +} - export interface TsTupleType extends Node, HasSpan { - type: "TsTupleType"; +export interface TsTupleType extends Node, HasSpan { + type: "TsTupleType"; - elemTypes: TsType[]; - } + elemTypes: TsType[]; +} - export interface TsOptionalType extends Node, HasSpan { - type: "TsOptionalType"; +export interface TsOptionalType extends Node, HasSpan { + type: "TsOptionalType"; - typeAnnotation: TsType; - } + typeAnnotation: TsType; +} - export interface TsRestType extends Node, HasSpan { - type: "TsRestType"; +export interface TsRestType extends Node, HasSpan { + type: "TsRestType"; - typeAnnotation: TsType; - } + typeAnnotation: TsType; +} - export type TsUnionOrIntersectionType = TsUnionType | TsIntersectionType; +export type TsUnionOrIntersectionType = TsUnionType | TsIntersectionType; - export interface TsUnionType extends Node, HasSpan { - type: "TsUnionType"; +export interface TsUnionType extends Node, HasSpan { + type: "TsUnionType"; - types: TsType[]; - } + types: TsType[]; +} - export interface TsIntersectionType extends Node, HasSpan { - type: "TsIntersectionType"; +export interface TsIntersectionType extends Node, HasSpan { + type: "TsIntersectionType"; - types: TsType[]; - } + types: TsType[]; +} - export interface TsConditionalType extends Node, HasSpan { - type: "TsConditionalType"; +export interface TsConditionalType extends Node, HasSpan { + type: "TsConditionalType"; - checkType: TsType; - extendsType: TsType; - trueType: TsType; - falseType: TsType; - } + checkType: TsType; + extendsType: TsType; + trueType: TsType; + falseType: TsType; +} - export interface TsInferType extends Node, HasSpan { - type: "TsInferType"; +export interface TsInferType extends Node, HasSpan { + type: "TsInferType"; - typeParam: TsTypeParameter; - } + typeParam: TsTypeParameter; +} - export interface TsParenthesizedType extends Node, HasSpan { - type: "TsParenthesizedType"; +export interface TsParenthesizedType extends Node, HasSpan { + type: "TsParenthesizedType"; - typeAnnotation: TsType; - } + typeAnnotation: TsType; +} - export interface TsTypeOperator extends Node, HasSpan { - type: "TsTypeOperator"; +export interface TsTypeOperator extends Node, HasSpan { + type: "TsTypeOperator"; - op: TsTypeOperatorOp; - typeAnnotation: TsType; - } + op: TsTypeOperatorOp; + typeAnnotation: TsType; +} - export type TsTypeOperatorOp = "keyof" | "unique"; +export type TsTypeOperatorOp = "keyof" | "unique"; - export interface TsIndexedAccessType extends Node, HasSpan { - type: "TsIndexedAccessType"; +export interface TsIndexedAccessType extends Node, HasSpan { + type: "TsIndexedAccessType"; - objectType: TsType; - indexType: TsType; - } + objectType: TsType; + indexType: TsType; +} - export type TruePlusMinus = true | "+" | "-"; +export type TruePlusMinus = true | "+" | "-"; - export interface TsMappedType extends Node, HasSpan { - type: "TsMappedType"; +export interface TsMappedType extends Node, HasSpan { + type: "TsMappedType"; - readonly: TruePlusMinus; - typeParam: TsTypeParameter; - optional: TruePlusMinus; - typeAnnotation: TsType; - } + readonly: TruePlusMinus; + typeParam: TsTypeParameter; + optional: TruePlusMinus; + typeAnnotation: TsType; +} - export interface TsLiteralType extends Node, HasSpan { - type: "TsLiteralType"; +export interface TsLiteralType extends Node, HasSpan { + type: "TsLiteralType"; - literal: TsLiteral; - } + literal: TsLiteral; +} - export type TsLiteral = NumericLiteral | StringLiteral | BooleanLiteral | TemplateLiteral; +export type TsLiteral = NumericLiteral | StringLiteral | BooleanLiteral | TemplateLiteral; - // // ================ - // // TypeScript declarations - // // ================ +// // ================ +// // TypeScript declarations +// // ================ - export interface TsInterfaceDeclaration extends Node, HasSpan { - type: "TsInterfaceDeclaration"; +export interface TsInterfaceDeclaration extends Node, HasSpan { + type: "TsInterfaceDeclaration"; - id: Identifier; - declare: boolean; - typeParams?: TsTypeParameterDeclaration; - extends: TsExpressionWithTypeArguments[]; - body: TsInterfaceBody; - } + id: Identifier; + declare: boolean; + typeParams?: TsTypeParameterDeclaration; + extends: TsExpressionWithTypeArguments[]; + body: TsInterfaceBody; +} - export interface TsInterfaceBody extends Node, HasSpan { - type: "TsInterfaceBody"; +export interface TsInterfaceBody extends Node, HasSpan { + type: "TsInterfaceBody"; - body: TsTypeElement[]; - } + body: TsTypeElement[]; +} - export interface TsExpressionWithTypeArguments extends Node, HasSpan { - type: "TsExpressionWithTypeArguments"; +export interface TsExpressionWithTypeArguments extends Node, HasSpan { + type: "TsExpressionWithTypeArguments"; - expression: TsEntityName; - typeArguments?: TsTypeParameterInstantiation; - } + expression: TsEntityName; + typeArguments?: TsTypeParameterInstantiation; +} - export interface TsTypeAliasDeclaration extends Node, HasSpan { - type: "TsTypeAliasDeclaration"; +export interface TsTypeAliasDeclaration extends Node, HasSpan { + type: "TsTypeAliasDeclaration"; - declare: boolean; - id: Identifier; - typeParams?: TsTypeParameterDeclaration; - typeAnnotation: TsType; - } + declare: boolean; + id: Identifier; + typeParams?: TsTypeParameterDeclaration; + typeAnnotation: TsType; +} - export interface TsEnumDeclaration extends Node, HasSpan { - type: "TsEnumDeclaration"; +export interface TsEnumDeclaration extends Node, HasSpan { + type: "TsEnumDeclaration"; - declare: boolean; - is_const: boolean; - id: Identifier; - member: TsEnumMember[]; - } + declare: boolean; + is_const: boolean; + id: Identifier; + member: TsEnumMember[]; +} - export interface TsEnumMember extends Node, HasSpan { - type: "TsEnumMember"; +export interface TsEnumMember extends Node, HasSpan { + type: "TsEnumMember"; - id: TsEnumMemberId; - init?: Expression; - } + id: TsEnumMemberId; + init?: Expression; +} - export type TsEnumMemberId = Identifier | StringLiteral; +export type TsEnumMemberId = Identifier | StringLiteral; - export interface TsModuleDeclaration extends Node, HasSpan { - type: "TsModuleDeclaration"; +export interface TsModuleDeclaration extends Node, HasSpan { + type: "TsModuleDeclaration"; - declare: boolean; - global: boolean; - id: TsModuleName; - body?: TsNamespaceBody; - } + declare: boolean; + global: boolean; + id: TsModuleName; + body?: TsNamespaceBody; +} - /** - * `namespace A.B { }` is a namespace named `A` with another TsNamespaceDecl as its body. - */ - export type TsNamespaceBody = TsModuleBlock | TsNamespaceDeclaration; +/** + * `namespace A.B { }` is a namespace named `A` with another TsNamespaceDecl as its body. + */ +export type TsNamespaceBody = TsModuleBlock | TsNamespaceDeclaration; - export interface TsModuleBlock extends Node, HasSpan { - type: "TsModuleBlock"; +export interface TsModuleBlock extends Node, HasSpan { + type: "TsModuleBlock"; - body: ModuleItem[]; - } + body: ModuleItem[]; +} - export interface TsNamespaceDeclaration extends Node, HasSpan { - type: "TsNamespaceDeclaration"; +export interface TsNamespaceDeclaration extends Node, HasSpan { + type: "TsNamespaceDeclaration"; - declare: boolean; - global: boolean; - id: Identifier; - body: TsNamespaceBody; - } + declare: boolean; + global: boolean; + id: Identifier; + body: TsNamespaceBody; +} - export type TsModuleName = Identifier | StringLiteral; +export type TsModuleName = Identifier | StringLiteral; - export interface TsImportEqualsDeclaration extends Node, HasSpan { - type: "TsImportEqualsDeclaration"; +export interface TsImportEqualsDeclaration extends Node, HasSpan { + type: "TsImportEqualsDeclaration"; - declare: boolean; - is_export: boolean; - id: Identifier; - moduleRef: TsModuleReference; - } + declare: boolean; + is_export: boolean; + id: Identifier; + moduleRef: TsModuleReference; +} - export type TsModuleReference = TsEntityName | TsExternalModuleReference; +export type TsModuleReference = TsEntityName | TsExternalModuleReference; - export interface TsExternalModuleReference extends Node, HasSpan { - type: "TsExternalModuleReference"; +export interface TsExternalModuleReference extends Node, HasSpan { + type: "TsExternalModuleReference"; - expression: Expression; - } + expression: Expression; +} - export interface TsExportAssignment extends Node, HasSpan { - type: "TsExportAssignment"; +export interface TsExportAssignment extends Node, HasSpan { + type: "TsExportAssignment"; - expression: Expression; - } + expression: Expression; +} - export interface TsNamespaceExportDeclaration extends Node, HasSpan { - type: "TsNamespaceExportDeclaration"; +export interface TsNamespaceExportDeclaration extends Node, HasSpan { + type: "TsNamespaceExportDeclaration"; - id: Identifier; - } + id: Identifier; +} - export interface TsAsExpression extends ExpressionBase { - type: "TsAsExpression"; +export interface TsAsExpression extends ExpressionBase { + type: "TsAsExpression"; - expression: Expression; - typeAnnotation: TsType; - } + expression: Expression; + typeAnnotation: TsType; +} - export interface TsTypeAssertion extends ExpressionBase { - type: "TsTypeAssertion"; +export interface TsTypeAssertion extends ExpressionBase { + type: "TsTypeAssertion"; - expression: Expression; - typeAnnotation: TsType; - } + expression: Expression; + typeAnnotation: TsType; +} - export interface TsNonNullExpression extends ExpressionBase { - type: "TsNonNullExpression"; +export interface TsNonNullExpression extends ExpressionBase { + type: "TsNonNullExpression"; - expression: Expression; - } + expression: Expression; +} - export type Accessibility = "public" | "protected" | "private"; +export type Accessibility = "public" | "protected" | "private"; - export interface Invalid extends Node, HasSpan { - type: "Invalid"; - } +export interface Invalid extends Node, HasSpan { + type: "Invalid"; } From 6030ec1d84c9b7c6ab389a6b2bc7a9673f9e5a4b Mon Sep 17 00:00:00 2001 From: divy-work Date: Tue, 28 Jul 2020 11:57:00 +0530 Subject: [PATCH 08/24] add ast types to unstable d.ts --- cli/dts/lib.deno.unstable.d.ts | 1565 ++++++++++++++++++++++++++++++- cli/dts/swc.d.ts | 1567 -------------------------------- 2 files changed, 1564 insertions(+), 1568 deletions(-) delete mode 100644 cli/dts/swc.d.ts diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index 1168fca9289341..8ff3358d4b423b 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -2,7 +2,6 @@ /// /// -/// _ declare namespace Deno { /** @@ -1231,3 +1230,1567 @@ declare namespace Deno { */ export const ppid: number; } + +// --- AST Nodes --- + +export interface Span { + start: number; + end: number; + ctxt: number; +} + +export interface Node { + type: string; +} + +export interface HasSpan { + span: Span; +} + +export interface HasDecorator { + decorators?: Decorator[]; +} + +export interface Class extends HasSpan, HasDecorator { + body: ClassMember[]; + + superClass?: Expression; + + is_abstract: boolean; + + typeParams: TsTypeParameterDeclaration; + + superTypeParams?: TsTypeParameterInstantiation; + + implements: TsExpressionWithTypeArguments[]; +} + +export type ClassMember = + | Constructor + | ClassMethod + | PrivateMethod + | ClassProperty + | PrivateProperty + | TsIndexSignature; + +export interface ClassPropertyBase extends Node, HasSpan, HasDecorator { + value?: Expression; + + typeAnnotation?: TsTypeAnnotation; + + is_static: boolean; + + computed: boolean; + + accessibility?: Accessibility; + + /// Typescript extension. + is_abstract: boolean; + + is_optional: boolean; + + readonly: boolean; + + definite: boolean; +} + +export interface ClassProperty extends ClassPropertyBase { + type: "ClassProperty"; + + key: Expression; +} + +export interface PrivateProperty extends ClassPropertyBase { + type: "PrivateProperty"; + + key: PrivateName; +} + +export interface Param extends Node, HasSpan, HasDecorator { + type: 'Parameter' + pat: Pattern +} + +export interface Constructor extends Node, HasSpan { + type: "Constructor"; + + key: PropertyName; + + params: (Param | TsParameterProperty)[]; + + body: BlockStatement; + + accessibility?: Accessibility; + + is_optional: boolean; +} + +export interface ClassMethodBase extends Node, HasSpan { + function: Fn; + + kind: MethodKind; + + is_static: boolean; + + accessibility?: Accessibility; + + is_abstract: boolean; + + is_optional: boolean; +} + +export interface ClassMethod extends ClassMethodBase { + type: "ClassMethod"; + + key: PropertyName; +} + +export interface PrivateMethod extends ClassMethodBase { + type: "PrivateMethod"; + + key: PrivateName; +} + +export interface Decorator extends Node, HasSpan { + type: "Decorator"; + + expression: Expression; +} + +export type MethodKind = "method" | "setter" | "getter"; + +export type Declaration = + | ClassDeclaration + | FunctionDeclaration + | VariableDeclaration + | TsInterfaceDeclaration + | TsTypeAliasDeclaration + | TsEnumDeclaration + | TsModuleDeclaration; + +export interface FunctionDeclaration extends Fn { + type: "FunctionDeclaration"; + + ident: Identifier; + + declare: boolean; +} + +export interface ClassDeclaration extends Class, Node { + type: "ClassDeclaration"; + + identifier: Identifier; + + declare: boolean; +} + +export interface VariableDeclaration extends Node, HasSpan { + type: "VariableDeclaration"; + + kind: VariableDeclarationKind; + + declare: boolean; + + declarations: VariableDeclarator[]; +} + +export type VariableDeclarationKind = "get" | "let" | "const"; + +export interface VariableDeclarator extends Node, HasSpan { + type: "VariableDeclarator"; + + id: Pattern; + + /// Initialization expresion. + init?: Expression; + + /// Typescript only + definite: boolean; +} + +export type Expression = + | ThisExpression + | ArrayExpression + | ObjectExpression + | FunctionExpression + | UnaryExpression + | UpdateExpression + | BinaryExpression + | AssignmentExpression + | MemberExpression + | ConditionalExpression + | CallExpression + | NewExpression + | SequenceExpression + | Identifier + | Literal + | TemplateLiteral + | TaggedTemplateExpression + | ArrowFunctionExpression + | ClassExpression + | YieldExpression + | MetaProperty + | AwaitExpression + | ParenthesisExpression + | JSXMemberExpression + | JSXNamespacedName + | JSXEmptyExpression + | JSXElement + | JSXFragment + | TsTypeAssertion + | TsNonNullExpression + | TsTypeCastExpression + | TsAsExpression + | PrivateName + | OptionalChainingExpression + | Invalid; + +interface ExpressionBase extends Node, HasSpan { } + +export interface OptionalChainingExpression extends ExpressionBase { + type: "OptionalChainingExpression"; + /** + * Call expression or member expression. + */ + expr: Expression; +} + +export interface ThisExpression extends ExpressionBase { + type: "ThisExpression"; +} + +export interface ArrayExpression extends ExpressionBase { + type: "ArrayExpression"; + + elements: (Expression | SpreadElement | undefined)[]; +} + +export interface ObjectExpression extends ExpressionBase { + type: "ObjectExpression"; + + properties: (Property | SpreadElement)[]; +} + +export interface Argument { + spread: Span; + expression: Expression; +} + +export type PropertOrSpread = Property | SpreadElement; + +export interface SpreadElement extends Node { + type: "SpreadElement"; + + spread: Span; + + arguments: Expression; +} + +export interface UnaryExpression extends ExpressionBase { + type: "UnaryExpression"; + + operator: UnaryOperator; + + argument: Expression; +} + +export interface UpdateExpression extends ExpressionBase { + type: "UpdateExpression"; + + operator: UpdateOperator; + + prefix: boolean; + + argument: Expression; +} + +export interface BinaryExpression extends ExpressionBase { + type: "BinaryExpression"; + + operator: BinaryOperator; + + left: Expression; + + right: Expression; +} + +export interface FunctionExpression extends Fn, ExpressionBase { + type: "FunctionExpression"; + + identifier: Identifier; +} + +export interface ClassExpression extends Class, ExpressionBase { + type: "ClassExpression"; + + identifier: Identifier; +} + +export interface AssignmentExpression extends ExpressionBase { + type: "AssignmentExpression"; + + operator: AssignmentOperator; + + left: Pattern | Expression; + + right: Expression; +} + +export interface MemberExpression extends ExpressionBase { + type: "MemberExpression"; + + object: Expression | Super; + + property: Expression; + + computed: boolean; +} + +export interface ConditionalExpression extends ExpressionBase { + type: "ConditionalExpression"; + + test: Expression; + + consequent: Expression; + + alternate: Expression; +} + +export interface Super extends Node, HasSpan { + type: "Super"; +} + +export interface CallExpression extends ExpressionBase { + type: "CallExpression"; + + callee: Expression | Super; + + arguments: Argument[]; + + typeArguments?: TsTypeParameterInstantiation; +} + +export interface NewExpression extends ExpressionBase { + type: "NewExpression"; + + callee: Expression; + + arguments: Argument[]; + + typeArguments?: TsTypeParameterInstantiation; +} + +export interface SequenceExpression extends ExpressionBase { + type: "SequenceExpression"; + + expressions: Expression[]; +} + +export interface ArrowFunctionExpression extends ExpressionBase { + type: "ArrowFunctionExpression"; + + params: Pattern[]; + + body: BlockStatement | Expression; + + async: boolean; + + generator: boolean; + + typeParameters?: TsTypeParameterDeclaration; + + returnType?: TsTypeAnnotation; +} + +export interface YieldExpression extends ExpressionBase { + type: "YieldExpression"; + + argument?: Expression; + + delegate: boolean; +} + +export interface MetaProperty extends Node { + type: "MetaProperty"; + + meta: Identifier; + + property: Identifier; +} + +export interface AwaitExpression extends ExpressionBase { + type: "AwaitExpression"; + + argument: Expression; +} + +export interface TplBase { + expressions: Expression[]; + + quasis: TemplateElement[]; +} + +export interface TemplateLiteral extends ExpressionBase, TplBase { + type: "TemplateLiteral"; +} + +export interface TaggedTemplateExpression extends ExpressionBase, TplBase { + type: "TaggedTemplateExpression"; + + tag: Expression; + + typeParameters: TsTypeParameterInstantiation; +} + +export interface TemplateElement extends ExpressionBase { + type: "TemplateElement"; + + tail: boolean; + cooked: StringLiteral; + raw: StringLiteral; +} + +export interface ParenthesisExpression extends ExpressionBase { + type: "ParenthesisExpression"; + + expression: Expression; +} + +export interface Fn extends HasSpan, HasDecorator { + params: Param[]; + + body: BlockStatement; + + generator: boolean; + + async: boolean; + + typeParameters?: TsTypeParameterDeclaration; + + returnType?: TsTypeAnnotation; +} + +interface PatternBase { + typeAnnotation?: TsTypeAnnotation; +} + +export interface Identifier extends HasSpan, PatternBase { + type: "Identifier"; + + value: string; + + /// TypeScript only. Used in case of an optional parameter. + optional: boolean; +} + +export interface PrivateName extends ExpressionBase { + type: "PrivateName"; + + id: Identifier; +} + +export type JSXObject = JSXMemberExpression | Identifier; + +export interface JSXMemberExpression extends Node { + type: "JSXMemberExpression"; + + object: JSXObject; + property: Identifier; +} + +/** + * XML-based namespace syntax: + */ +export interface JSXNamespacedName extends Node { + type: "JSXNamespacedName"; + + namespace: Identifier; + name: Identifier; +} + +export interface JSXEmptyExpression extends Node, HasSpan { + type: "JSXEmptyExpression"; +} + +export interface JSXExpressionContainer extends Node { + type: "JSXExpressionContainer"; + + expression: JSXExpression; +} + +export type JSXExpression = JSXEmptyExpression | Expression; + +export interface JSXSpreadChild extends Node { + type: "JSXSpreadChild"; + + expression: Expression; +} + +export type JSXElementName = + | Identifier + | JSXMemberExpression + | JSXNamespacedName; + +export interface JSXOpeningElement extends Node, HasSpan { + type: "JSXOpeningElement"; + + name: JSXElementName; + + attrs?: JSXAttributeOrSpread[]; + + selfClosing: boolean; + + typeArguments?: TsTypeParameterInstantiation; +} + +export type JSXAttributeOrSpread = JSXAttribute | SpreadElement; + +export interface JSXClosingElement extends Node, HasSpan { + type: "JSXClosingElement"; + + name: JSXElementName; +} + +export interface JSXAttribute extends Node, HasSpan { + type: "JSXAttribute"; + + name: JSXAttributeName; + + value?: JSXAttrValue; +} + +export type JSXAttributeName = Identifier | JSXNamespacedName; + +export type JSXAttrValue = + | Literal + | JSXExpressionContainer + | JSXElement + | JSXFragment; + +export interface JSXText extends Node, HasSpan { + type: "JSXText"; + + value: string; + raw: string; +} + +export interface JSXElement extends Node, HasSpan { + type: "JSXElement"; + + opening: JSXOpeningElement; + children: JSXElementChild[]; + closing?: JSXClosingElement; +} + +export type JSXElementChild = + | JSXText + | JSXExpressionContainer + | JSXSpreadChild + | JSXElement + | JSXFragment; + +export interface JSXFragment extends Node, HasSpan { + type: "JSXFragment"; + + opening: JSXOpeningFragment; + + children: JSXElementChild[]; + + closing: JSXClosingFragment; +} + +export interface JSXOpeningFragment extends Node, HasSpan { + type: "JSXOpeningFragment"; +} + +export interface JSXClosingFragment extends Node, HasSpan { + type: "JSXClosingFragment"; +} + +export type Literal = + | StringLiteral + | BooleanLiteral + | NullLiteral + | NumericLiteral + | RegExpLiteral + | JSXText; + +export interface StringLiteral extends Node, HasSpan { + type: "StringLiteral"; + + value: string; + has_escape: boolean; +} + +export interface BooleanLiteral extends Node, HasSpan { + type: "BooleanLiteral"; + + value: boolean; +} + +export interface NullLiteral extends Node, HasSpan { + type: "NullLiteral"; +} + +export interface RegExpLiteral extends Node, HasSpan { + type: "RegExpLiteral"; + + pattern: string; + flags: string; +} + +export interface NumericLiteral extends Node, HasSpan { + type: "NumericLiteral"; + + value: number; +} + +export type ModuleDeclaration = + | ImportDeclaration + | ExportDeclaration + | ExportNamedDeclaration + | ExportDefaultDeclaration + | ExportDefaultExpression + | ExportAllDeclaration + | TsImportEqualsDeclaration + | TsExportAssignment + | TsNamespaceExportDeclaration; + +export interface ExportDefaultExpression extends Node, HasSpan { + type: "ExportDefaultExpression"; + + expression: Expression; +} + +export interface ExportDeclaration extends Node, HasSpan { + type: "ExportDeclaration"; + + declaration: Declaration; +} + +export interface ImportDeclaration extends Node, HasSpan { + type: "ImportDeclaration"; + + specifiers: ImporSpecifier[]; + + source: StringLiteral; +} + +export type ImporSpecifier = + | ImportDefaultSpecifier + | NamedImportSpecifier + | ImportNamespaceSpecifier; + +export interface ExportAllDeclaration extends Node, HasSpan { + type: "ExportAllDeclaration"; + + source: StringLiteral; +} + +/** + * - `export { foo } from 'mod'` + * - `export { foo as bar } from 'mod'` + */ +export interface ExportNamedDeclaration extends Node, HasSpan { + type: "ExportNamedDeclaration"; + + specifiers: ExportSpecifier[]; + + source?: StringLiteral; +} + +export interface ExportDefaultDeclaration extends Node, HasSpan { + type: "ExportDefaultDeclaration"; + + decl: DefaultDecl; +} + +export type DefaultDecl = + | ClassExpression + | FunctionExpression + | TsInterfaceDeclaration; + +export type ImportSpecifier = + | NamedImportSpecifier + | ImportDefaultSpecifier + | ImportNamespaceSpecifier; + +/** + * e.g. `import foo from 'mod.js'` + */ +export interface ImportDefaultSpecifier extends Node, HasSpan { + type: "ImportDefaultSpecifier"; + local: Identifier; +} + +/** + * e.g. `import * as foo from 'mod.js'`. + */ +export interface ImportNamespaceSpecifier extends Node, HasSpan { + type: "ImportNamespaceSpecifier"; + + local: Identifier; +} + +/** + * e.g. - `import { foo } from 'mod.js'` + * + * local = foo, imported = None + * + * e.g. `import { foo as bar } from 'mod.js'` + * + * local = bar, imported = Some(foo) for + */ +export interface NamedImportSpecifier extends Node, HasSpan { + type: "ImportSpecifier"; + local: Identifier; + imported: Identifier; +} + +export type ExportSpecifier = + | ExportNamespaceSpecifer + | ExportDefaultSpecifier + | NamedExportSpecifier; + +/** + * `export * as foo from 'src';` + */ +export interface ExportNamespaceSpecifer extends Node, HasSpan { + type: "ExportNamespaceSpecifer"; + + name: Identifier; +} + +export interface ExportDefaultSpecifier extends Node, HasSpan { + type: "ExportDefaultSpecifier"; + + exported: Identifier; +} + +export interface NamedExportSpecifier extends Node, HasSpan { + type: "ExportSpecifier"; + + orig: Identifier; + /** + * `Some(bar)` in `export { foo as bar }` + */ + exported: Identifier; +} + +interface HasInterpreter { + /** + * e.g. `/usr/bin/node` for `#!/usr/bin/node` + */ + interpreter: string; +} + +export type Program = Module | Script; + +export interface Module extends Node, HasSpan, HasInterpreter { + type: "Module"; + + body: ModuleItem[]; +} + +export interface Script extends Node, HasSpan, HasInterpreter { + type: "Script"; + + body: Statement[]; +} + +export type ModuleItem = ModuleDeclaration | Statement; + +export type BinaryOperator = + | "==" + | "!=" + | "===" + | "!==" + | "<" + | "<=" + | ">" + | ">=" + | "<<" + | ">>" + | ">>>" + | "+" + | "-" + | "*" + | "/" + | "%" + | "**" + | "|" + | "^" + | "&" + | "||" + | "&&" + | "in" + | "instanceof" + | "??"; + +export type AssignmentOperator = + | "=" + | "+=" + | "-=" + | "*=" + | "/=" + | "%=" + | "**=" + | "<<=" + | ">>=" + | ">>>=" + | "|=" + | "^=" + | "&="; + +export type UpdateOperator = "++" | "--"; + +export type UnaryOperator = + | "-" + | "+" + | "!" + | "~" + | "typeof" + | "void" + | "delete"; + +export type Pattern = + | Identifier + | ArrayPattern + | RestElement + | ObjectPattern + | AssignmentPattern + | Invalid + | Expression; + +export interface ArrayPattern extends Node, HasSpan, PatternBase { + type: "ArrayPattern"; + + elements: (Pattern | undefined)[]; +} + +export interface ObjectPattern extends Node, HasSpan, PatternBase { + type: "ObjectPattern"; + + props: ObjectPatternProperty[]; +} + +export interface AssignmentPattern extends Node, HasSpan, PatternBase { + type: "AssignmentPattern"; + + left: Pattern; + right: Expression; +} + +export interface RestElement extends Node, HasSpan, PatternBase { + type: "RestElement"; + + rest: Span; + + argument: Pattern; +} + +export type ObjectPatternProperty = + | KeyValuePatternProperty + | AssignmentPatternProperty + | RestElement; + +/** + * `{key: value}` + */ +export interface KeyValuePatternProperty extends Node { + type: "KeyValuePatternProperty"; + + key: PropertyName; + value: Pattern; +} + +/** + * `{key}` or `{key = value}` + */ +export interface AssignmentPatternProperty extends Node, HasSpan { + type: "AssignmentPatternProperty"; + + key: Identifier; + value?: Expression; +} + +/** Identifier is `a` in `{ a, }` */ +export type Property = + | Identifier + | KeyValueProperty + | AssignmentProperty + | GetterProperty + | SetterProperty + | MethodProperty; + +interface PropBase extends Node { + key: PropertyName; +} + +export interface KeyValueProperty extends PropBase { + type: "KeyValueProperty"; + + value: Expression; +} + +export interface AssignmentProperty extends Node { + type: "AssignmentProperty"; + + key: Identifier; + value: Expression; +} + +export interface GetterProperty extends PropBase, HasSpan { + type: "GetterProperty"; + + typeAnnotation?: TsTypeAnnotation; + + body: BlockStatement; +} + +export interface SetterProperty extends PropBase, HasSpan { + type: "SetterProperty"; + + param: Pattern; + body: BlockStatement; +} + +export interface MethodProperty extends PropBase, Fn { + type: "MethodProperty"; +} + +export type PropertyName = + | Identifier + | StringLiteral + | NumericLiteral + | ComputedPropName; + +export interface ComputedPropName extends Node, HasSpan { + type: "Computed"; + expression: Expression; +} + +export interface BlockStatement extends Node, HasSpan { + type: "BlockStatement"; + + stmts: Statement[]; +} + +export interface ExpressionStatement extends Node, HasSpan { + type: "ExpressionStatement"; + expression: Expression; +} + +export type Statement = + | ExpressionStatement + | BlockStatement + | EmptyStatement + | DebuggerStatement + | WithStatement + | ReturnStatement + | LabeledStatement + | BreakStatement + | ContinueStatement + | IfStatement + | SwitchStatement + | ThrowStatement + | TryStatement + | WhileStatement + | DoWhileStatement + | ForStatement + | ForInStatement + | ForOfStatement + | Declaration; + +export interface EmptyStatement extends Node, HasSpan { + type: "EmptyStatement"; +} + +export interface DebuggerStatement extends Node, HasSpan { + type: "DebuggerStatement"; +} + +export interface WithStatement extends Node, HasSpan { + type: "WithStatement"; + + object: Expression; + body: Statement; +} + +export interface ReturnStatement extends Node, HasSpan { + type: "ReturnStatement"; + + argument: Expression; +} + +export interface LabeledStatement extends Node, HasSpan { + type: "LabeledStatement"; + + label: Identifier; + body: Statement; +} + +export interface BreakStatement extends Node, HasSpan { + type: "BreakStatement"; + + label: Identifier; +} + +export interface ContinueStatement extends Node, HasSpan { + type: "ContinueStatement"; + + label: Identifier; +} + +export interface IfStatement extends Node, HasSpan { + type: "IfStatement"; + + test: Expression; + consequent: Statement; + alternate?: Statement; +} + +export interface SwitchStatement extends Node, HasSpan { + type: "SwitchStatement"; + + discriminant: Expression; + cases: SwitchCase[]; +} + +export interface ThrowStatement extends Node, HasSpan { + type: "ThrowStatement"; + + argument: Expression; +} + +export interface TryStatement extends Node, HasSpan { + type: "TryStatement"; + + block: BlockStatement; + handler?: CatchClause; + finalizer: BlockStatement; +} + +export interface WhileStatement extends Node, HasSpan { + type: "WhileStatement"; + + test: Expression; + body: Statement; +} + +export interface DoWhileStatement extends Node, HasSpan { + type: "DoWhileStatement"; + + test: Expression; + body: Statement; +} + +export interface ForStatement extends Node, HasSpan { + type: "ForStatement"; + + init?: VariableDeclaration | Expression; + test?: Expression; + update?: Expression; + body: Statement; +} + +export interface ForInStatement extends Node, HasSpan { + type: "ForInStatement"; + + left: VariableDeclaration | Pattern; + right: Expression; + body: Statement; +} + +export interface ForOfStatement extends Node, HasSpan { + type: "ForOfStatement"; + + /** + * Span of the await token. + * + * es2018 for-await-of statements, e.g., `for await (const x of xs) {` + */ + await: Span; + left: VariableDeclaration | Pattern; + right: Expression; + body: Statement; +} + +export interface SwitchCase extends Node, HasSpan { + type: "SwitchCase"; + + /** + * Undefined for default case + */ + test?: Expression; + consequent: Statement[]; +} + +export interface CatchClause extends Node, HasSpan { + type: "CatchClause"; + + /** + * The param is `undefined` if the catch binding is omitted. E.g., `try { foo() } catch {}` + */ + param: Pattern; + body: BlockStatement; +} + +export interface TsTypeAnnotation extends Node, HasSpan { + type: "TsTypeAnnotation"; + + typeAnnotation: TsType; +} + +export interface TsTypeParameterDeclaration extends Node, HasSpan { + type: "TsTypeParameterDeclaration"; + + parameters: TsTypeParameter[]; +} + +export interface TsTypeParameter extends Node, HasSpan { + type: "TsTypeParameter"; + + name: Identifier; + constraint: TsType; + default: TsType; +} + +export interface TsTypeParameterInstantiation extends Node, HasSpan { + type: "TsTypeParameterInstantiation"; + + params: TsType[]; +} + +export interface TsTypeCastExpression extends Node, HasSpan { + type: "TsTypeCastExpression"; + + expression: Expression; + typeAnnotation: TsTypeAnnotation; +} + +export interface TsParameterProperty extends Node, HasSpan, HasDecorator { + type: "TsParameterProperty"; + + accessibility?: Accessibility; + readonly: boolean; + param: TsParameterPropertyParameter; +} + +export type TsParameterPropertyParameter = Identifier | AssignmentPattern; + +export interface TsQualifiedName extends Node { + type: "TsQualifiedName"; + + left: TsEntityName; + right: Identifier; +} + +export type TsEntityName = TsQualifiedName | Identifier; + +export type TsSignatureDeclaration = + | TsCallSignatureDeclaration + | TsConstructSignatureDeclaration + | TsMethodSignature + | TsFunctionType + | TsConstructorType; + +export type TsTypeElement = + | TsCallSignatureDeclaration + | TsConstructSignatureDeclaration + | TsPropertySignature + | TsMethodSignature + | TsIndexSignature; + +export interface TsCallSignatureDeclaration extends Node, HasSpan { + type: "TsCallSignatureDeclaration"; + + params: TsFnParameter[]; + typeAnnotation: TsTypeAnnotation; + typeParams: TsTypeParameterDeclaration; +} + +export interface TsConstructSignatureDeclaration extends Node, HasSpan { + type: "TsConstructSignatureDeclaration"; + + params: TsFnParameter[]; + typeAnnotation: TsTypeAnnotation; + typeParams: TsTypeParameterDeclaration; +} + +export interface TsPropertySignature extends Node, HasSpan { + type: "TsPropertySignature"; + + readonly: boolean; + key: Expression; + computed: boolean; + optional: boolean; + + init: Expression; + params: TsFnParameter[]; + + typeAnnotation?: TsTypeAnnotation; + typeParams: TsTypeParameterDeclaration; +} + +export interface TsMethodSignature extends Node, HasSpan { + type: "TsMethodSignature"; + + readonly: boolean; + key: Expression; + computed: boolean; + optional: boolean; + params: TsFnParameter[]; + + typeAnnotation: TsTypeAnnotation; + typeParams: TsTypeParameterDeclaration; +} + +export interface TsIndexSignature extends Node, HasSpan { + type: "TsIndexSignature"; + + readonly: boolean; + params: TsFnParameter[]; + + typeAnnotation?: TsTypeAnnotation; +} + +export type TsType = + | TsKeywordType + | TsThisType + | TsFnOrConstructorType + | TsTypeReference + | TsTypeQuery + | TsTypeLiteral + | TsArrayType + | TsTupleType + | TsOptionalType + | TsRestType + | TsUnionOrIntersectionType + | TsConditionalType + | TsInferType + | TsParenthesizedType + | TsTypeOperator + | TsIndexedAccessType + | TsMappedType + | TsLiteralType + | TsImportType + | TsTypePredicate; + +export type TsFnOrConstructorType = TsFunctionType | TsConstructorType; + +export interface TsKeywordType extends Node, HasSpan { + type: "TsKeywordType"; + + kind: TsKeywordTypeKind; +} + +export type TsKeywordTypeKind = + | "any" + | "unknown" + | "number" + | "object" + | "boolean" + | "bigint" + | "string" + | "symbol" + | "void" + | "undefined" + | "null" + | "never"; + +export interface TsThisType extends Node, HasSpan { + type: "TsThisType"; +} + +export type TsFnParameter = Identifier | RestElement | ObjectPattern; + +export interface TsFunctionType extends Node, HasSpan { + type: "TsFunctionType"; + + typeParams: TsTypeParameterDeclaration; + typeAnnotation: TsTypeAnnotation; +} + +export interface TsConstructorType extends Node, HasSpan { + type: "TsConstructorType"; + + params: TsFnParameter[]; + + typeParams: TsTypeParameterDeclaration; + typeAnnotation: TsTypeAnnotation; +} + +export interface TsTypeReference extends Node, HasSpan { + type: "TsTypeReference"; + + typeName: TsEntityName; + typeParams: TsTypeParameterInstantiation; +} + +export interface TsTypePredicate extends Node, HasSpan { + type: "TsTypePredicate"; + + asserts: boolean; + + paramName: TsThisTypeOrIdent; + typeAnnotation: TsTypeAnnotation; +} + +export type TsThisTypeOrIdent = TsThisType | Identifier; + +export interface TsImportType extends Node, HasSpan { + argument: StringLiteral; + qualifier?: TsEntityName; + typeArguments?: TsTypeParameterInstantiation; +} + +/** + * `typeof` operator + */ +export interface TsTypeQuery extends Node, HasSpan { + type: "TsTypeQuery"; + + exprName: TsTypeQueryExpr; +} + +export type TsTypeQueryExpr = TsEntityName | TsImportType; + +export interface TsTypeLiteral extends Node, HasSpan { + type: "TsTypeLiteral"; + + members: TsTypeElement[]; +} + +export interface TsArrayType extends Node, HasSpan { + type: "TsArrayType"; + + elemType: TsType; +} + +export interface TsTupleType extends Node, HasSpan { + type: "TsTupleType"; + + elemTypes: TsType[]; +} + +export interface TsOptionalType extends Node, HasSpan { + type: "TsOptionalType"; + + typeAnnotation: TsType; +} + +export interface TsRestType extends Node, HasSpan { + type: "TsRestType"; + + typeAnnotation: TsType; +} + +export type TsUnionOrIntersectionType = TsUnionType | TsIntersectionType; + +export interface TsUnionType extends Node, HasSpan { + type: "TsUnionType"; + + types: TsType[]; +} + +export interface TsIntersectionType extends Node, HasSpan { + type: "TsIntersectionType"; + + types: TsType[]; +} + +export interface TsConditionalType extends Node, HasSpan { + type: "TsConditionalType"; + + checkType: TsType; + extendsType: TsType; + trueType: TsType; + falseType: TsType; +} + +export interface TsInferType extends Node, HasSpan { + type: "TsInferType"; + + typeParam: TsTypeParameter; +} + +export interface TsParenthesizedType extends Node, HasSpan { + type: "TsParenthesizedType"; + + typeAnnotation: TsType; +} + +export interface TsTypeOperator extends Node, HasSpan { + type: "TsTypeOperator"; + + op: TsTypeOperatorOp; + typeAnnotation: TsType; +} + +export type TsTypeOperatorOp = "keyof" | "unique"; + +export interface TsIndexedAccessType extends Node, HasSpan { + type: "TsIndexedAccessType"; + + objectType: TsType; + indexType: TsType; +} + +export type TruePlusMinus = true | "+" | "-"; + +export interface TsMappedType extends Node, HasSpan { + type: "TsMappedType"; + + readonly: TruePlusMinus; + typeParam: TsTypeParameter; + optional: TruePlusMinus; + typeAnnotation: TsType; +} + +export interface TsLiteralType extends Node, HasSpan { + type: "TsLiteralType"; + + literal: TsLiteral; +} + +export type TsLiteral = NumericLiteral | StringLiteral | BooleanLiteral | TemplateLiteral; + +// // ================ +// // TypeScript declarations +// // ================ + +export interface TsInterfaceDeclaration extends Node, HasSpan { + type: "TsInterfaceDeclaration"; + + id: Identifier; + declare: boolean; + typeParams?: TsTypeParameterDeclaration; + extends: TsExpressionWithTypeArguments[]; + body: TsInterfaceBody; +} + +export interface TsInterfaceBody extends Node, HasSpan { + type: "TsInterfaceBody"; + + body: TsTypeElement[]; +} + +export interface TsExpressionWithTypeArguments extends Node, HasSpan { + type: "TsExpressionWithTypeArguments"; + + expression: TsEntityName; + typeArguments?: TsTypeParameterInstantiation; +} + +export interface TsTypeAliasDeclaration extends Node, HasSpan { + type: "TsTypeAliasDeclaration"; + + declare: boolean; + id: Identifier; + typeParams?: TsTypeParameterDeclaration; + typeAnnotation: TsType; +} + +export interface TsEnumDeclaration extends Node, HasSpan { + type: "TsEnumDeclaration"; + + declare: boolean; + is_const: boolean; + id: Identifier; + member: TsEnumMember[]; +} + +export interface TsEnumMember extends Node, HasSpan { + type: "TsEnumMember"; + + id: TsEnumMemberId; + init?: Expression; +} + +export type TsEnumMemberId = Identifier | StringLiteral; + +export interface TsModuleDeclaration extends Node, HasSpan { + type: "TsModuleDeclaration"; + + declare: boolean; + global: boolean; + id: TsModuleName; + body?: TsNamespaceBody; +} + +/** + * `namespace A.B { }` is a namespace named `A` with another TsNamespaceDecl as its body. + */ +export type TsNamespaceBody = TsModuleBlock | TsNamespaceDeclaration; + +export interface TsModuleBlock extends Node, HasSpan { + type: "TsModuleBlock"; + + body: ModuleItem[]; +} + +export interface TsNamespaceDeclaration extends Node, HasSpan { + type: "TsNamespaceDeclaration"; + + declare: boolean; + global: boolean; + id: Identifier; + body: TsNamespaceBody; +} + +export type TsModuleName = Identifier | StringLiteral; + +export interface TsImportEqualsDeclaration extends Node, HasSpan { + type: "TsImportEqualsDeclaration"; + + declare: boolean; + is_export: boolean; + id: Identifier; + moduleRef: TsModuleReference; +} + +export type TsModuleReference = TsEntityName | TsExternalModuleReference; + +export interface TsExternalModuleReference extends Node, HasSpan { + type: "TsExternalModuleReference"; + + expression: Expression; +} + +export interface TsExportAssignment extends Node, HasSpan { + type: "TsExportAssignment"; + + expression: Expression; +} + +export interface TsNamespaceExportDeclaration extends Node, HasSpan { + type: "TsNamespaceExportDeclaration"; + + id: Identifier; +} + +export interface TsAsExpression extends ExpressionBase { + type: "TsAsExpression"; + + expression: Expression; + typeAnnotation: TsType; +} + +export interface TsTypeAssertion extends ExpressionBase { + type: "TsTypeAssertion"; + + expression: Expression; + typeAnnotation: TsType; +} + +export interface TsNonNullExpression extends ExpressionBase { + type: "TsNonNullExpression"; + + expression: Expression; +} + +export type Accessibility = "public" | "protected" | "private"; + +export interface Invalid extends Node, HasSpan { + type: "Invalid"; diff --git a/cli/dts/swc.d.ts b/cli/dts/swc.d.ts deleted file mode 100644 index 783d9d9cc25e41..00000000000000 --- a/cli/dts/swc.d.ts +++ /dev/null @@ -1,1567 +0,0 @@ -// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. - -/// -/// - -export interface Span { - start: number; - end: number; - ctxt: number; -} - -export interface Node { - type: string; -} - -export interface HasSpan { - span: Span; -} - -export interface HasDecorator { - decorators?: Decorator[]; -} - -export interface Class extends HasSpan, HasDecorator { - body: ClassMember[]; - - superClass?: Expression; - - is_abstract: boolean; - - typeParams: TsTypeParameterDeclaration; - - superTypeParams?: TsTypeParameterInstantiation; - - implements: TsExpressionWithTypeArguments[]; -} - -export type ClassMember = - | Constructor - | ClassMethod - | PrivateMethod - | ClassProperty - | PrivateProperty - | TsIndexSignature; - -export interface ClassPropertyBase extends Node, HasSpan, HasDecorator { - value?: Expression; - - typeAnnotation?: TsTypeAnnotation; - - is_static: boolean; - - computed: boolean; - - accessibility?: Accessibility; - - /// Typescript extension. - is_abstract: boolean; - - is_optional: boolean; - - readonly: boolean; - - definite: boolean; -} - -export interface ClassProperty extends ClassPropertyBase { - type: "ClassProperty"; - - key: Expression; -} - -export interface PrivateProperty extends ClassPropertyBase { - type: "PrivateProperty"; - - key: PrivateName; -} - -export interface Param extends Node, HasSpan, HasDecorator { - type: 'Parameter' - pat: Pattern -} - -export interface Constructor extends Node, HasSpan { - type: "Constructor"; - - key: PropertyName; - - params: (Param | TsParameterProperty)[]; - - body: BlockStatement; - - accessibility?: Accessibility; - - is_optional: boolean; -} - -export interface ClassMethodBase extends Node, HasSpan { - function: Fn; - - kind: MethodKind; - - is_static: boolean; - - accessibility?: Accessibility; - - is_abstract: boolean; - - is_optional: boolean; -} - -export interface ClassMethod extends ClassMethodBase { - type: "ClassMethod"; - - key: PropertyName; -} - -export interface PrivateMethod extends ClassMethodBase { - type: "PrivateMethod"; - - key: PrivateName; -} - -export interface Decorator extends Node, HasSpan { - type: "Decorator"; - - expression: Expression; -} - -export type MethodKind = "method" | "setter" | "getter"; - -export type Declaration = - | ClassDeclaration - | FunctionDeclaration - | VariableDeclaration - | TsInterfaceDeclaration - | TsTypeAliasDeclaration - | TsEnumDeclaration - | TsModuleDeclaration; - -export interface FunctionDeclaration extends Fn { - type: "FunctionDeclaration"; - - ident: Identifier; - - declare: boolean; -} - -export interface ClassDeclaration extends Class, Node { - type: "ClassDeclaration"; - - identifier: Identifier; - - declare: boolean; -} - -export interface VariableDeclaration extends Node, HasSpan { - type: "VariableDeclaration"; - - kind: VariableDeclarationKind; - - declare: boolean; - - declarations: VariableDeclarator[]; -} - -export type VariableDeclarationKind = "get" | "let" | "const"; - -export interface VariableDeclarator extends Node, HasSpan { - type: "VariableDeclarator"; - - id: Pattern; - - /// Initialization expresion. - init?: Expression; - - /// Typescript only - definite: boolean; -} - -export type Expression = - | ThisExpression - | ArrayExpression - | ObjectExpression - | FunctionExpression - | UnaryExpression - | UpdateExpression - | BinaryExpression - | AssignmentExpression - | MemberExpression - | ConditionalExpression - | CallExpression - | NewExpression - | SequenceExpression - | Identifier - | Literal - | TemplateLiteral - | TaggedTemplateExpression - | ArrowFunctionExpression - | ClassExpression - | YieldExpression - | MetaProperty - | AwaitExpression - | ParenthesisExpression - | JSXMemberExpression - | JSXNamespacedName - | JSXEmptyExpression - | JSXElement - | JSXFragment - | TsTypeAssertion - | TsNonNullExpression - | TsTypeCastExpression - | TsAsExpression - | PrivateName - | OptionalChainingExpression - | Invalid; - -interface ExpressionBase extends Node, HasSpan { } - -export interface OptionalChainingExpression extends ExpressionBase { - type: "OptionalChainingExpression"; - /** - * Call expression or member expression. - */ - expr: Expression; -} - -export interface ThisExpression extends ExpressionBase { - type: "ThisExpression"; -} - -export interface ArrayExpression extends ExpressionBase { - type: "ArrayExpression"; - - elements: (Expression | SpreadElement | undefined)[]; -} - -export interface ObjectExpression extends ExpressionBase { - type: "ObjectExpression"; - - properties: (Property | SpreadElement)[]; -} - -export interface Argument { - spread: Span; - expression: Expression; -} - -export type PropertOrSpread = Property | SpreadElement; - -export interface SpreadElement extends Node { - type: "SpreadElement"; - - spread: Span; - - arguments: Expression; -} - -export interface UnaryExpression extends ExpressionBase { - type: "UnaryExpression"; - - operator: UnaryOperator; - - argument: Expression; -} - -export interface UpdateExpression extends ExpressionBase { - type: "UpdateExpression"; - - operator: UpdateOperator; - - prefix: boolean; - - argument: Expression; -} - -export interface BinaryExpression extends ExpressionBase { - type: "BinaryExpression"; - - operator: BinaryOperator; - - left: Expression; - - right: Expression; -} - -export interface FunctionExpression extends Fn, ExpressionBase { - type: "FunctionExpression"; - - identifier: Identifier; -} - -export interface ClassExpression extends Class, ExpressionBase { - type: "ClassExpression"; - - identifier: Identifier; -} - -export interface AssignmentExpression extends ExpressionBase { - type: "AssignmentExpression"; - - operator: AssignmentOperator; - - left: Pattern | Expression; - - right: Expression; -} - -export interface MemberExpression extends ExpressionBase { - type: "MemberExpression"; - - object: Expression | Super; - - property: Expression; - - computed: boolean; -} - -export interface ConditionalExpression extends ExpressionBase { - type: "ConditionalExpression"; - - test: Expression; - - consequent: Expression; - - alternate: Expression; -} - -export interface Super extends Node, HasSpan { - type: "Super"; -} - -export interface CallExpression extends ExpressionBase { - type: "CallExpression"; - - callee: Expression | Super; - - arguments: Argument[]; - - typeArguments?: TsTypeParameterInstantiation; -} - -export interface NewExpression extends ExpressionBase { - type: "NewExpression"; - - callee: Expression; - - arguments: Argument[]; - - typeArguments?: TsTypeParameterInstantiation; -} - -export interface SequenceExpression extends ExpressionBase { - type: "SequenceExpression"; - - expressions: Expression[]; -} - -export interface ArrowFunctionExpression extends ExpressionBase { - type: "ArrowFunctionExpression"; - - params: Pattern[]; - - body: BlockStatement | Expression; - - async: boolean; - - generator: boolean; - - typeParameters?: TsTypeParameterDeclaration; - - returnType?: TsTypeAnnotation; -} - -export interface YieldExpression extends ExpressionBase { - type: "YieldExpression"; - - argument?: Expression; - - delegate: boolean; -} - -export interface MetaProperty extends Node { - type: "MetaProperty"; - - meta: Identifier; - - property: Identifier; -} - -export interface AwaitExpression extends ExpressionBase { - type: "AwaitExpression"; - - argument: Expression; -} - -export interface TplBase { - expressions: Expression[]; - - quasis: TemplateElement[]; -} - -export interface TemplateLiteral extends ExpressionBase, TplBase { - type: "TemplateLiteral"; -} - -export interface TaggedTemplateExpression extends ExpressionBase, TplBase { - type: "TaggedTemplateExpression"; - - tag: Expression; - - typeParameters: TsTypeParameterInstantiation; -} - -export interface TemplateElement extends ExpressionBase { - type: "TemplateElement"; - - tail: boolean; - cooked: StringLiteral; - raw: StringLiteral; -} - -export interface ParenthesisExpression extends ExpressionBase { - type: "ParenthesisExpression"; - - expression: Expression; -} - -export interface Fn extends HasSpan, HasDecorator { - params: Param[]; - - body: BlockStatement; - - generator: boolean; - - async: boolean; - - typeParameters?: TsTypeParameterDeclaration; - - returnType?: TsTypeAnnotation; -} - -interface PatternBase { - typeAnnotation?: TsTypeAnnotation; -} - -export interface Identifier extends HasSpan, PatternBase { - type: "Identifier"; - - value: string; - - /// TypeScript only. Used in case of an optional parameter. - optional: boolean; -} - -export interface PrivateName extends ExpressionBase { - type: "PrivateName"; - - id: Identifier; -} - -export type JSXObject = JSXMemberExpression | Identifier; - -export interface JSXMemberExpression extends Node { - type: "JSXMemberExpression"; - - object: JSXObject; - property: Identifier; -} - -/** - * XML-based namespace syntax: - */ -export interface JSXNamespacedName extends Node { - type: "JSXNamespacedName"; - - namespace: Identifier; - name: Identifier; -} - -export interface JSXEmptyExpression extends Node, HasSpan { - type: "JSXEmptyExpression"; -} - -export interface JSXExpressionContainer extends Node { - type: "JSXExpressionContainer"; - - expression: JSXExpression; -} - -export type JSXExpression = JSXEmptyExpression | Expression; - -export interface JSXSpreadChild extends Node { - type: "JSXSpreadChild"; - - expression: Expression; -} - -export type JSXElementName = - | Identifier - | JSXMemberExpression - | JSXNamespacedName; - -export interface JSXOpeningElement extends Node, HasSpan { - type: "JSXOpeningElement"; - - name: JSXElementName; - - attrs?: JSXAttributeOrSpread[]; - - selfClosing: boolean; - - typeArguments?: TsTypeParameterInstantiation; -} - -export type JSXAttributeOrSpread = JSXAttribute | SpreadElement; - -export interface JSXClosingElement extends Node, HasSpan { - type: "JSXClosingElement"; - - name: JSXElementName; -} - -export interface JSXAttribute extends Node, HasSpan { - type: "JSXAttribute"; - - name: JSXAttributeName; - - value?: JSXAttrValue; -} - -export type JSXAttributeName = Identifier | JSXNamespacedName; - -export type JSXAttrValue = - | Literal - | JSXExpressionContainer - | JSXElement - | JSXFragment; - -export interface JSXText extends Node, HasSpan { - type: "JSXText"; - - value: string; - raw: string; -} - -export interface JSXElement extends Node, HasSpan { - type: "JSXElement"; - - opening: JSXOpeningElement; - children: JSXElementChild[]; - closing?: JSXClosingElement; -} - -export type JSXElementChild = - | JSXText - | JSXExpressionContainer - | JSXSpreadChild - | JSXElement - | JSXFragment; - -export interface JSXFragment extends Node, HasSpan { - type: "JSXFragment"; - - opening: JSXOpeningFragment; - - children: JSXElementChild[]; - - closing: JSXClosingFragment; -} - -export interface JSXOpeningFragment extends Node, HasSpan { - type: "JSXOpeningFragment"; -} - -export interface JSXClosingFragment extends Node, HasSpan { - type: "JSXClosingFragment"; -} - -export type Literal = - | StringLiteral - | BooleanLiteral - | NullLiteral - | NumericLiteral - | RegExpLiteral - | JSXText; - -export interface StringLiteral extends Node, HasSpan { - type: "StringLiteral"; - - value: string; - has_escape: boolean; -} - -export interface BooleanLiteral extends Node, HasSpan { - type: "BooleanLiteral"; - - value: boolean; -} - -export interface NullLiteral extends Node, HasSpan { - type: "NullLiteral"; -} - -export interface RegExpLiteral extends Node, HasSpan { - type: "RegExpLiteral"; - - pattern: string; - flags: string; -} - -export interface NumericLiteral extends Node, HasSpan { - type: "NumericLiteral"; - - value: number; -} - -export type ModuleDeclaration = - | ImportDeclaration - | ExportDeclaration - | ExportNamedDeclaration - | ExportDefaultDeclaration - | ExportDefaultExpression - | ExportAllDeclaration - | TsImportEqualsDeclaration - | TsExportAssignment - | TsNamespaceExportDeclaration; - -export interface ExportDefaultExpression extends Node, HasSpan { - type: "ExportDefaultExpression"; - - expression: Expression; -} - -export interface ExportDeclaration extends Node, HasSpan { - type: "ExportDeclaration"; - - declaration: Declaration; -} - -export interface ImportDeclaration extends Node, HasSpan { - type: "ImportDeclaration"; - - specifiers: ImporSpecifier[]; - - source: StringLiteral; -} - -export type ImporSpecifier = - | ImportDefaultSpecifier - | NamedImportSpecifier - | ImportNamespaceSpecifier; - -export interface ExportAllDeclaration extends Node, HasSpan { - type: "ExportAllDeclaration"; - - source: StringLiteral; -} - -/** - * - `export { foo } from 'mod'` - * - `export { foo as bar } from 'mod'` - */ -export interface ExportNamedDeclaration extends Node, HasSpan { - type: "ExportNamedDeclaration"; - - specifiers: ExportSpecifier[]; - - source?: StringLiteral; -} - -export interface ExportDefaultDeclaration extends Node, HasSpan { - type: "ExportDefaultDeclaration"; - - decl: DefaultDecl; -} - -export type DefaultDecl = - | ClassExpression - | FunctionExpression - | TsInterfaceDeclaration; - -export type ImportSpecifier = - | NamedImportSpecifier - | ImportDefaultSpecifier - | ImportNamespaceSpecifier; - -/** - * e.g. `import foo from 'mod.js'` - */ -export interface ImportDefaultSpecifier extends Node, HasSpan { - type: "ImportDefaultSpecifier"; - local: Identifier; -} - -/** - * e.g. `import * as foo from 'mod.js'`. - */ -export interface ImportNamespaceSpecifier extends Node, HasSpan { - type: "ImportNamespaceSpecifier"; - - local: Identifier; -} - -/** - * e.g. - `import { foo } from 'mod.js'` - * - * local = foo, imported = None - * - * e.g. `import { foo as bar } from 'mod.js'` - * - * local = bar, imported = Some(foo) for - */ -export interface NamedImportSpecifier extends Node, HasSpan { - type: "ImportSpecifier"; - local: Identifier; - imported: Identifier; -} - -export type ExportSpecifier = - | ExportNamespaceSpecifer - | ExportDefaultSpecifier - | NamedExportSpecifier; - -/** - * `export * as foo from 'src';` - */ -export interface ExportNamespaceSpecifer extends Node, HasSpan { - type: "ExportNamespaceSpecifer"; - - name: Identifier; -} - -export interface ExportDefaultSpecifier extends Node, HasSpan { - type: "ExportDefaultSpecifier"; - - exported: Identifier; -} - -export interface NamedExportSpecifier extends Node, HasSpan { - type: "ExportSpecifier"; - - orig: Identifier; - /** - * `Some(bar)` in `export { foo as bar }` - */ - exported: Identifier; -} - -interface HasInterpreter { - /** - * e.g. `/usr/bin/node` for `#!/usr/bin/node` - */ - interpreter: string; -} - -export type Program = Module | Script; - -export interface Module extends Node, HasSpan, HasInterpreter { - type: "Module"; - - body: ModuleItem[]; -} - -export interface Script extends Node, HasSpan, HasInterpreter { - type: "Script"; - - body: Statement[]; -} - -export type ModuleItem = ModuleDeclaration | Statement; - -export type BinaryOperator = - | "==" - | "!=" - | "===" - | "!==" - | "<" - | "<=" - | ">" - | ">=" - | "<<" - | ">>" - | ">>>" - | "+" - | "-" - | "*" - | "/" - | "%" - | "**" - | "|" - | "^" - | "&" - | "||" - | "&&" - | "in" - | "instanceof" - | "??"; - -export type AssignmentOperator = - | "=" - | "+=" - | "-=" - | "*=" - | "/=" - | "%=" - | "**=" - | "<<=" - | ">>=" - | ">>>=" - | "|=" - | "^=" - | "&="; - -export type UpdateOperator = "++" | "--"; - -export type UnaryOperator = - | "-" - | "+" - | "!" - | "~" - | "typeof" - | "void" - | "delete"; - -export type Pattern = - | Identifier - | ArrayPattern - | RestElement - | ObjectPattern - | AssignmentPattern - | Invalid - | Expression; - -export interface ArrayPattern extends Node, HasSpan, PatternBase { - type: "ArrayPattern"; - - elements: (Pattern | undefined)[]; -} - -export interface ObjectPattern extends Node, HasSpan, PatternBase { - type: "ObjectPattern"; - - props: ObjectPatternProperty[]; -} - -export interface AssignmentPattern extends Node, HasSpan, PatternBase { - type: "AssignmentPattern"; - - left: Pattern; - right: Expression; -} - -export interface RestElement extends Node, HasSpan, PatternBase { - type: "RestElement"; - - rest: Span; - - argument: Pattern; -} - -export type ObjectPatternProperty = - | KeyValuePatternProperty - | AssignmentPatternProperty - | RestElement; - -/** - * `{key: value}` - */ -export interface KeyValuePatternProperty extends Node { - type: "KeyValuePatternProperty"; - - key: PropertyName; - value: Pattern; -} - -/** - * `{key}` or `{key = value}` - */ -export interface AssignmentPatternProperty extends Node, HasSpan { - type: "AssignmentPatternProperty"; - - key: Identifier; - value?: Expression; -} - -/** Identifier is `a` in `{ a, }` */ -export type Property = - | Identifier - | KeyValueProperty - | AssignmentProperty - | GetterProperty - | SetterProperty - | MethodProperty; - -interface PropBase extends Node { - key: PropertyName; -} - -export interface KeyValueProperty extends PropBase { - type: "KeyValueProperty"; - - value: Expression; -} - -export interface AssignmentProperty extends Node { - type: "AssignmentProperty"; - - key: Identifier; - value: Expression; -} - -export interface GetterProperty extends PropBase, HasSpan { - type: "GetterProperty"; - - typeAnnotation?: TsTypeAnnotation; - - body: BlockStatement; -} - -export interface SetterProperty extends PropBase, HasSpan { - type: "SetterProperty"; - - param: Pattern; - body: BlockStatement; -} - -export interface MethodProperty extends PropBase, Fn { - type: "MethodProperty"; -} - -export type PropertyName = - | Identifier - | StringLiteral - | NumericLiteral - | ComputedPropName; - -export interface ComputedPropName extends Node, HasSpan { - type: "Computed"; - expression: Expression; -} - -export interface BlockStatement extends Node, HasSpan { - type: "BlockStatement"; - - stmts: Statement[]; -} - -export interface ExpressionStatement extends Node, HasSpan { - type: "ExpressionStatement"; - expression: Expression; -} - -export type Statement = - | ExpressionStatement - | BlockStatement - | EmptyStatement - | DebuggerStatement - | WithStatement - | ReturnStatement - | LabeledStatement - | BreakStatement - | ContinueStatement - | IfStatement - | SwitchStatement - | ThrowStatement - | TryStatement - | WhileStatement - | DoWhileStatement - | ForStatement - | ForInStatement - | ForOfStatement - | Declaration; - -export interface EmptyStatement extends Node, HasSpan { - type: "EmptyStatement"; -} - -export interface DebuggerStatement extends Node, HasSpan { - type: "DebuggerStatement"; -} - -export interface WithStatement extends Node, HasSpan { - type: "WithStatement"; - - object: Expression; - body: Statement; -} - -export interface ReturnStatement extends Node, HasSpan { - type: "ReturnStatement"; - - argument: Expression; -} - -export interface LabeledStatement extends Node, HasSpan { - type: "LabeledStatement"; - - label: Identifier; - body: Statement; -} - -export interface BreakStatement extends Node, HasSpan { - type: "BreakStatement"; - - label: Identifier; -} - -export interface ContinueStatement extends Node, HasSpan { - type: "ContinueStatement"; - - label: Identifier; -} - -export interface IfStatement extends Node, HasSpan { - type: "IfStatement"; - - test: Expression; - consequent: Statement; - alternate?: Statement; -} - -export interface SwitchStatement extends Node, HasSpan { - type: "SwitchStatement"; - - discriminant: Expression; - cases: SwitchCase[]; -} - -export interface ThrowStatement extends Node, HasSpan { - type: "ThrowStatement"; - - argument: Expression; -} - -export interface TryStatement extends Node, HasSpan { - type: "TryStatement"; - - block: BlockStatement; - handler?: CatchClause; - finalizer: BlockStatement; -} - -export interface WhileStatement extends Node, HasSpan { - type: "WhileStatement"; - - test: Expression; - body: Statement; -} - -export interface DoWhileStatement extends Node, HasSpan { - type: "DoWhileStatement"; - - test: Expression; - body: Statement; -} - -export interface ForStatement extends Node, HasSpan { - type: "ForStatement"; - - init?: VariableDeclaration | Expression; - test?: Expression; - update?: Expression; - body: Statement; -} - -export interface ForInStatement extends Node, HasSpan { - type: "ForInStatement"; - - left: VariableDeclaration | Pattern; - right: Expression; - body: Statement; -} - -export interface ForOfStatement extends Node, HasSpan { - type: "ForOfStatement"; - - /** - * Span of the await token. - * - * es2018 for-await-of statements, e.g., `for await (const x of xs) {` - */ - await: Span; - left: VariableDeclaration | Pattern; - right: Expression; - body: Statement; -} - -export interface SwitchCase extends Node, HasSpan { - type: "SwitchCase"; - - /** - * Undefined for default case - */ - test?: Expression; - consequent: Statement[]; -} - -export interface CatchClause extends Node, HasSpan { - type: "CatchClause"; - - /** - * The param is `undefined` if the catch binding is omitted. E.g., `try { foo() } catch {}` - */ - param: Pattern; - body: BlockStatement; -} - -export interface TsTypeAnnotation extends Node, HasSpan { - type: "TsTypeAnnotation"; - - typeAnnotation: TsType; -} - -export interface TsTypeParameterDeclaration extends Node, HasSpan { - type: "TsTypeParameterDeclaration"; - - parameters: TsTypeParameter[]; -} - -export interface TsTypeParameter extends Node, HasSpan { - type: "TsTypeParameter"; - - name: Identifier; - constraint: TsType; - default: TsType; -} - -export interface TsTypeParameterInstantiation extends Node, HasSpan { - type: "TsTypeParameterInstantiation"; - - params: TsType[]; -} - -export interface TsTypeCastExpression extends Node, HasSpan { - type: "TsTypeCastExpression"; - - expression: Expression; - typeAnnotation: TsTypeAnnotation; -} - -export interface TsParameterProperty extends Node, HasSpan, HasDecorator { - type: "TsParameterProperty"; - - accessibility?: Accessibility; - readonly: boolean; - param: TsParameterPropertyParameter; -} - -export type TsParameterPropertyParameter = Identifier | AssignmentPattern; - -export interface TsQualifiedName extends Node { - type: "TsQualifiedName"; - - left: TsEntityName; - right: Identifier; -} - -export type TsEntityName = TsQualifiedName | Identifier; - -export type TsSignatureDeclaration = - | TsCallSignatureDeclaration - | TsConstructSignatureDeclaration - | TsMethodSignature - | TsFunctionType - | TsConstructorType; - -export type TsTypeElement = - | TsCallSignatureDeclaration - | TsConstructSignatureDeclaration - | TsPropertySignature - | TsMethodSignature - | TsIndexSignature; - -export interface TsCallSignatureDeclaration extends Node, HasSpan { - type: "TsCallSignatureDeclaration"; - - params: TsFnParameter[]; - typeAnnotation: TsTypeAnnotation; - typeParams: TsTypeParameterDeclaration; -} - -export interface TsConstructSignatureDeclaration extends Node, HasSpan { - type: "TsConstructSignatureDeclaration"; - - params: TsFnParameter[]; - typeAnnotation: TsTypeAnnotation; - typeParams: TsTypeParameterDeclaration; -} - -export interface TsPropertySignature extends Node, HasSpan { - type: "TsPropertySignature"; - - readonly: boolean; - key: Expression; - computed: boolean; - optional: boolean; - - init: Expression; - params: TsFnParameter[]; - - typeAnnotation?: TsTypeAnnotation; - typeParams: TsTypeParameterDeclaration; -} - -export interface TsMethodSignature extends Node, HasSpan { - type: "TsMethodSignature"; - - readonly: boolean; - key: Expression; - computed: boolean; - optional: boolean; - params: TsFnParameter[]; - - typeAnnotation: TsTypeAnnotation; - typeParams: TsTypeParameterDeclaration; -} - -export interface TsIndexSignature extends Node, HasSpan { - type: "TsIndexSignature"; - - readonly: boolean; - params: TsFnParameter[]; - - typeAnnotation?: TsTypeAnnotation; -} - -export type TsType = - | TsKeywordType - | TsThisType - | TsFnOrConstructorType - | TsTypeReference - | TsTypeQuery - | TsTypeLiteral - | TsArrayType - | TsTupleType - | TsOptionalType - | TsRestType - | TsUnionOrIntersectionType - | TsConditionalType - | TsInferType - | TsParenthesizedType - | TsTypeOperator - | TsIndexedAccessType - | TsMappedType - | TsLiteralType - | TsImportType - | TsTypePredicate; - -export type TsFnOrConstructorType = TsFunctionType | TsConstructorType; - -export interface TsKeywordType extends Node, HasSpan { - type: "TsKeywordType"; - - kind: TsKeywordTypeKind; -} - -export type TsKeywordTypeKind = - | "any" - | "unknown" - | "number" - | "object" - | "boolean" - | "bigint" - | "string" - | "symbol" - | "void" - | "undefined" - | "null" - | "never"; - -export interface TsThisType extends Node, HasSpan { - type: "TsThisType"; -} - -export type TsFnParameter = Identifier | RestElement | ObjectPattern; - -export interface TsFunctionType extends Node, HasSpan { - type: "TsFunctionType"; - - typeParams: TsTypeParameterDeclaration; - typeAnnotation: TsTypeAnnotation; -} - -export interface TsConstructorType extends Node, HasSpan { - type: "TsConstructorType"; - - params: TsFnParameter[]; - - typeParams: TsTypeParameterDeclaration; - typeAnnotation: TsTypeAnnotation; -} - -export interface TsTypeReference extends Node, HasSpan { - type: "TsTypeReference"; - - typeName: TsEntityName; - typeParams: TsTypeParameterInstantiation; -} - -export interface TsTypePredicate extends Node, HasSpan { - type: "TsTypePredicate"; - - asserts: boolean; - - paramName: TsThisTypeOrIdent; - typeAnnotation: TsTypeAnnotation; -} - -export type TsThisTypeOrIdent = TsThisType | Identifier; - -export interface TsImportType extends Node, HasSpan { - argument: StringLiteral; - qualifier?: TsEntityName; - typeArguments?: TsTypeParameterInstantiation; -} - -/** - * `typeof` operator - */ -export interface TsTypeQuery extends Node, HasSpan { - type: "TsTypeQuery"; - - exprName: TsTypeQueryExpr; -} - -export type TsTypeQueryExpr = TsEntityName | TsImportType; - -export interface TsTypeLiteral extends Node, HasSpan { - type: "TsTypeLiteral"; - - members: TsTypeElement[]; -} - -export interface TsArrayType extends Node, HasSpan { - type: "TsArrayType"; - - elemType: TsType; -} - -export interface TsTupleType extends Node, HasSpan { - type: "TsTupleType"; - - elemTypes: TsType[]; -} - -export interface TsOptionalType extends Node, HasSpan { - type: "TsOptionalType"; - - typeAnnotation: TsType; -} - -export interface TsRestType extends Node, HasSpan { - type: "TsRestType"; - - typeAnnotation: TsType; -} - -export type TsUnionOrIntersectionType = TsUnionType | TsIntersectionType; - -export interface TsUnionType extends Node, HasSpan { - type: "TsUnionType"; - - types: TsType[]; -} - -export interface TsIntersectionType extends Node, HasSpan { - type: "TsIntersectionType"; - - types: TsType[]; -} - -export interface TsConditionalType extends Node, HasSpan { - type: "TsConditionalType"; - - checkType: TsType; - extendsType: TsType; - trueType: TsType; - falseType: TsType; -} - -export interface TsInferType extends Node, HasSpan { - type: "TsInferType"; - - typeParam: TsTypeParameter; -} - -export interface TsParenthesizedType extends Node, HasSpan { - type: "TsParenthesizedType"; - - typeAnnotation: TsType; -} - -export interface TsTypeOperator extends Node, HasSpan { - type: "TsTypeOperator"; - - op: TsTypeOperatorOp; - typeAnnotation: TsType; -} - -export type TsTypeOperatorOp = "keyof" | "unique"; - -export interface TsIndexedAccessType extends Node, HasSpan { - type: "TsIndexedAccessType"; - - objectType: TsType; - indexType: TsType; -} - -export type TruePlusMinus = true | "+" | "-"; - -export interface TsMappedType extends Node, HasSpan { - type: "TsMappedType"; - - readonly: TruePlusMinus; - typeParam: TsTypeParameter; - optional: TruePlusMinus; - typeAnnotation: TsType; -} - -export interface TsLiteralType extends Node, HasSpan { - type: "TsLiteralType"; - - literal: TsLiteral; -} - -export type TsLiteral = NumericLiteral | StringLiteral | BooleanLiteral | TemplateLiteral; - -// // ================ -// // TypeScript declarations -// // ================ - -export interface TsInterfaceDeclaration extends Node, HasSpan { - type: "TsInterfaceDeclaration"; - - id: Identifier; - declare: boolean; - typeParams?: TsTypeParameterDeclaration; - extends: TsExpressionWithTypeArguments[]; - body: TsInterfaceBody; -} - -export interface TsInterfaceBody extends Node, HasSpan { - type: "TsInterfaceBody"; - - body: TsTypeElement[]; -} - -export interface TsExpressionWithTypeArguments extends Node, HasSpan { - type: "TsExpressionWithTypeArguments"; - - expression: TsEntityName; - typeArguments?: TsTypeParameterInstantiation; -} - -export interface TsTypeAliasDeclaration extends Node, HasSpan { - type: "TsTypeAliasDeclaration"; - - declare: boolean; - id: Identifier; - typeParams?: TsTypeParameterDeclaration; - typeAnnotation: TsType; -} - -export interface TsEnumDeclaration extends Node, HasSpan { - type: "TsEnumDeclaration"; - - declare: boolean; - is_const: boolean; - id: Identifier; - member: TsEnumMember[]; -} - -export interface TsEnumMember extends Node, HasSpan { - type: "TsEnumMember"; - - id: TsEnumMemberId; - init?: Expression; -} - -export type TsEnumMemberId = Identifier | StringLiteral; - -export interface TsModuleDeclaration extends Node, HasSpan { - type: "TsModuleDeclaration"; - - declare: boolean; - global: boolean; - id: TsModuleName; - body?: TsNamespaceBody; -} - -/** - * `namespace A.B { }` is a namespace named `A` with another TsNamespaceDecl as its body. - */ -export type TsNamespaceBody = TsModuleBlock | TsNamespaceDeclaration; - -export interface TsModuleBlock extends Node, HasSpan { - type: "TsModuleBlock"; - - body: ModuleItem[]; -} - -export interface TsNamespaceDeclaration extends Node, HasSpan { - type: "TsNamespaceDeclaration"; - - declare: boolean; - global: boolean; - id: Identifier; - body: TsNamespaceBody; -} - -export type TsModuleName = Identifier | StringLiteral; - -export interface TsImportEqualsDeclaration extends Node, HasSpan { - type: "TsImportEqualsDeclaration"; - - declare: boolean; - is_export: boolean; - id: Identifier; - moduleRef: TsModuleReference; -} - -export type TsModuleReference = TsEntityName | TsExternalModuleReference; - -export interface TsExternalModuleReference extends Node, HasSpan { - type: "TsExternalModuleReference"; - - expression: Expression; -} - -export interface TsExportAssignment extends Node, HasSpan { - type: "TsExportAssignment"; - - expression: Expression; -} - -export interface TsNamespaceExportDeclaration extends Node, HasSpan { - type: "TsNamespaceExportDeclaration"; - - id: Identifier; -} - -export interface TsAsExpression extends ExpressionBase { - type: "TsAsExpression"; - - expression: Expression; - typeAnnotation: TsType; -} - -export interface TsTypeAssertion extends ExpressionBase { - type: "TsTypeAssertion"; - - expression: Expression; - typeAnnotation: TsType; -} - -export interface TsNonNullExpression extends ExpressionBase { - type: "TsNonNullExpression"; - - expression: Expression; -} - -export type Accessibility = "public" | "protected" | "private"; - -export interface Invalid extends Node, HasSpan { - type: "Invalid"; -} From 453322953cb32294fd850c7a26b977df145deecb Mon Sep 17 00:00:00 2001 From: divy-work Date: Tue, 28 Jul 2020 12:37:29 +0530 Subject: [PATCH 09/24] feat: format options to swc_parser --- cli/doc/parser.rs | 1 + cli/dts/lib.deno.unstable.d.ts | 1 + cli/ops/runtime_compiler.rs | 4 +- cli/rt/40_compiler_api.js | 5 +- cli/swc_util.rs | 21 ++++++- cli/tsc.rs | 102 +++++++++++++++++---------------- 6 files changed, 81 insertions(+), 53 deletions(-) diff --git a/cli/doc/parser.rs b/cli/doc/parser.rs index 59fa2b7342a763..2149e4d296179d 100644 --- a/cli/doc/parser.rs +++ b/cli/doc/parser.rs @@ -66,6 +66,7 @@ impl DocParser { file_name, media_type, source_code, + None, |parse_result| { let module = parse_result?; let doc_entries = diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index 8ff3358d4b423b..b4848f12eb67c1 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -2794,3 +2794,4 @@ export type Accessibility = "public" | "protected" | "private"; export interface Invalid extends Node, HasSpan { type: "Invalid"; +} diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs index e0e2444e47ff6c..ae83bfdcc5be06 100644 --- a/cli/ops/runtime_compiler.rs +++ b/cli/ops/runtime_compiler.rs @@ -3,7 +3,7 @@ use super::dispatch_json::{Deserialize, JsonOp, Value}; use crate::futures::FutureExt; use crate::op_error::OpError; use crate::state::State; -use crate::swc_util::AstParser; +use crate::swc_util::{AstParser, ParseOptions}; use crate::tsc::runtime_bundle; use crate::tsc::runtime_compile; use crate::tsc::runtime_transpile; @@ -91,6 +91,7 @@ fn op_transpile( #[derive(Deserialize, Debug)] struct ParseArgs { source: String, + options: Option, } // TODO(divy-work): Should we take swc parse options? @@ -116,6 +117,7 @@ fn op_parse( &module_specifier.to_string(), out.media_type, &src, + args.options, |parse_result| { let module = parse_result.unwrap(); Ok(serde_json::to_value(module)?) diff --git a/cli/rt/40_compiler_api.js b/cli/rt/40_compiler_api.js index 23d9c8bed2a455..56a7b60c2b4641 100644 --- a/cli/rt/40_compiler_api.js +++ b/cli/rt/40_compiler_api.js @@ -27,11 +27,12 @@ } // TODO(divy-work): Use AST type interface from swc as return type? - function ast(source) { - util.log("Deno.ast", { source }); + function ast(source, options = {}) { + util.log("Deno.ast", { source, options }); const payload = { source, }; + if (Object.keys(options) > 0) payload.options = options; return opAst(payload); } diff --git a/cli/swc_util.rs b/cli/swc_util.rs index 906d9f9bddab71..b6b9a34ee0186f 100644 --- a/cli/swc_util.rs +++ b/cli/swc_util.rs @@ -20,11 +20,21 @@ use crate::swc_ecma_parser::Session; use crate::swc_ecma_parser::SourceFileInput; use crate::swc_ecma_parser::Syntax; use crate::swc_ecma_parser::TsConfig; +use serde::{Deserialize, Serialize}; use std::error::Error; use std::fmt; use std::sync::Arc; use std::sync::RwLock; +#[derive(Debug, Default, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ParseOptions { + #[serde(flatten)] + pub syntax: Syntax, + #[serde(default)] + pub target: JscTarget, +} + fn get_default_es_config() -> EsConfig { let mut config = EsConfig::default(); config.num_sep = true; @@ -167,6 +177,7 @@ impl AstParser { file_name: &str, media_type: MediaType, source_code: &str, + options: Option, callback: F, ) -> R where @@ -183,12 +194,18 @@ impl AstParser { handler: &self.handler, }; - let syntax = get_syntax_for_media_type(media_type); + let mut syntax = get_syntax_for_media_type(media_type); + let mut target = JscTarget::Es2019; + + if let Some(opt) = options { + syntax = opt.syntax; + target = opt.target; + } let lexer = Lexer::new( session, syntax, - JscTarget::Es2019, + target, SourceFileInput::from(&*swc_source_file), Some(&self.comments), ); diff --git a/cli/tsc.rs b/cli/tsc.rs index 2ce498e3f1d543..606d708d51a59a 100644 --- a/cli/tsc.rs +++ b/cli/tsc.rs @@ -1419,61 +1419,67 @@ pub fn pre_process_file( analyze_dynamic_imports: bool, ) -> Result<(Vec, Vec), SwcDiagnosticBuffer> { let parser = AstParser::new(); - parser.parse_module(file_name, media_type, source_code, |parse_result| { - let module = parse_result?; - let mut collector = DependencyVisitor { - dependencies: vec![], - }; - let module_span = module.span; - collector.visit_module(&module, &module); + parser.parse_module( + file_name, + media_type, + source_code, + None, + |parse_result| { + let module = parse_result?; + let mut collector = DependencyVisitor { + dependencies: vec![], + }; + let module_span = module.span; + collector.visit_module(&module, &module); - let dependency_descriptors = collector.dependencies; + let dependency_descriptors = collector.dependencies; - // for each import check if there's relevant @deno-types directive - let imports = dependency_descriptors - .iter() - .filter(|desc| { - if analyze_dynamic_imports { - return true; - } + // for each import check if there's relevant @deno-types directive + let imports = dependency_descriptors + .iter() + .filter(|desc| { + if analyze_dynamic_imports { + return true; + } - desc.kind != DependencyKind::DynamicImport - }) - .map(|desc| { - let location = parser.get_span_location(desc.span); - let deno_types = get_deno_types(&parser, desc.span); - ImportDesc { - specifier: desc.specifier.to_string(), - deno_types, - location: location.into(), - } - }) - .collect(); + desc.kind != DependencyKind::DynamicImport + }) + .map(|desc| { + let location = parser.get_span_location(desc.span); + let deno_types = get_deno_types(&parser, desc.span); + ImportDesc { + specifier: desc.specifier.to_string(), + deno_types, + location: location.into(), + } + }) + .collect(); - // analyze comment from beginning of the file and find TS directives - let comments = parser - .comments - .take_leading_comments(module_span.lo()) - .unwrap_or_else(Vec::new); + // analyze comment from beginning of the file and find TS directives + let comments = parser + .comments + .take_leading_comments(module_span.lo()) + .unwrap_or_else(Vec::new); - let mut references = vec![]; - for comment in comments { - if comment.kind != CommentKind::Line { - continue; - } + let mut references = vec![]; + for comment in comments { + if comment.kind != CommentKind::Line { + continue; + } - let text = comment.text.to_string(); - if let Some((kind, specifier)) = parse_ts_reference(text.trim()) { - let location = parser.get_span_location(comment.span); - references.push(TsReferenceDesc { - kind, - specifier, - location: location.into(), - }); + let text = comment.text.to_string(); + if let Some((kind, specifier)) = parse_ts_reference(text.trim()) { + let location = parser.get_span_location(comment.span); + references.push(TsReferenceDesc { + kind, + specifier, + location: location.into(), + }); + } } - } - Ok((imports, references)) - }) + Ok((imports, references)) + }, + ) } fn get_deno_types(parser: &AstParser, span: Span) -> Option { From e54ca4a41db64e274846ad414fe67944a5e5f75d Mon Sep 17 00:00:00 2001 From: divy-work Date: Tue, 28 Jul 2020 13:18:34 +0530 Subject: [PATCH 10/24] feat: use passed options with default when null --- cli/swc_util.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/cli/swc_util.rs b/cli/swc_util.rs index b6b9a34ee0186f..dde78b9b9d0c00 100644 --- a/cli/swc_util.rs +++ b/cli/swc_util.rs @@ -35,6 +35,15 @@ pub struct ParseOptions { pub target: JscTarget, } +impl ParseOptions { + pub fn default(media_type: MediaType) -> Self { + ParseOptions { + syntax: get_syntax_for_media_type(media_type), + target: JscTarget::Es2019, + } + } +} + fn get_default_es_config() -> EsConfig { let mut config = EsConfig::default(); config.num_sep = true; @@ -194,18 +203,12 @@ impl AstParser { handler: &self.handler, }; - let mut syntax = get_syntax_for_media_type(media_type); - let mut target = JscTarget::Es2019; - - if let Some(opt) = options { - syntax = opt.syntax; - target = opt.target; - } + let parse_options = options.unwrap_or(ParseOptions::default(media_type)); let lexer = Lexer::new( session, - syntax, - target, + parse_options.syntax, + parse_options.target, SourceFileInput::from(&*swc_source_file), Some(&self.comments), ); From 5647c84c16146b50d5e60a35b89a6fb0f6d8f946 Mon Sep 17 00:00:00 2001 From: divy-work Date: Tue, 28 Jul 2020 13:46:08 +0530 Subject: [PATCH 11/24] fix: passing parse options --- cli/dts/lib.deno.unstable.d.ts | 1566 +------------------------------ cli/dts/lib.swc.d.ts | 1568 ++++++++++++++++++++++++++++++++ cli/ops/runtime_compiler.rs | 1 - cli/rt/40_compiler_api.js | 5 +- 4 files changed, 1571 insertions(+), 1569 deletions(-) create mode 100644 cli/dts/lib.swc.d.ts diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index b4848f12eb67c1..cdca0cbecb1eaa 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -2,6 +2,7 @@ /// /// +/// declare namespace Deno { /** @@ -1230,1568 +1231,3 @@ declare namespace Deno { */ export const ppid: number; } - -// --- AST Nodes --- - -export interface Span { - start: number; - end: number; - ctxt: number; -} - -export interface Node { - type: string; -} - -export interface HasSpan { - span: Span; -} - -export interface HasDecorator { - decorators?: Decorator[]; -} - -export interface Class extends HasSpan, HasDecorator { - body: ClassMember[]; - - superClass?: Expression; - - is_abstract: boolean; - - typeParams: TsTypeParameterDeclaration; - - superTypeParams?: TsTypeParameterInstantiation; - - implements: TsExpressionWithTypeArguments[]; -} - -export type ClassMember = - | Constructor - | ClassMethod - | PrivateMethod - | ClassProperty - | PrivateProperty - | TsIndexSignature; - -export interface ClassPropertyBase extends Node, HasSpan, HasDecorator { - value?: Expression; - - typeAnnotation?: TsTypeAnnotation; - - is_static: boolean; - - computed: boolean; - - accessibility?: Accessibility; - - /// Typescript extension. - is_abstract: boolean; - - is_optional: boolean; - - readonly: boolean; - - definite: boolean; -} - -export interface ClassProperty extends ClassPropertyBase { - type: "ClassProperty"; - - key: Expression; -} - -export interface PrivateProperty extends ClassPropertyBase { - type: "PrivateProperty"; - - key: PrivateName; -} - -export interface Param extends Node, HasSpan, HasDecorator { - type: 'Parameter' - pat: Pattern -} - -export interface Constructor extends Node, HasSpan { - type: "Constructor"; - - key: PropertyName; - - params: (Param | TsParameterProperty)[]; - - body: BlockStatement; - - accessibility?: Accessibility; - - is_optional: boolean; -} - -export interface ClassMethodBase extends Node, HasSpan { - function: Fn; - - kind: MethodKind; - - is_static: boolean; - - accessibility?: Accessibility; - - is_abstract: boolean; - - is_optional: boolean; -} - -export interface ClassMethod extends ClassMethodBase { - type: "ClassMethod"; - - key: PropertyName; -} - -export interface PrivateMethod extends ClassMethodBase { - type: "PrivateMethod"; - - key: PrivateName; -} - -export interface Decorator extends Node, HasSpan { - type: "Decorator"; - - expression: Expression; -} - -export type MethodKind = "method" | "setter" | "getter"; - -export type Declaration = - | ClassDeclaration - | FunctionDeclaration - | VariableDeclaration - | TsInterfaceDeclaration - | TsTypeAliasDeclaration - | TsEnumDeclaration - | TsModuleDeclaration; - -export interface FunctionDeclaration extends Fn { - type: "FunctionDeclaration"; - - ident: Identifier; - - declare: boolean; -} - -export interface ClassDeclaration extends Class, Node { - type: "ClassDeclaration"; - - identifier: Identifier; - - declare: boolean; -} - -export interface VariableDeclaration extends Node, HasSpan { - type: "VariableDeclaration"; - - kind: VariableDeclarationKind; - - declare: boolean; - - declarations: VariableDeclarator[]; -} - -export type VariableDeclarationKind = "get" | "let" | "const"; - -export interface VariableDeclarator extends Node, HasSpan { - type: "VariableDeclarator"; - - id: Pattern; - - /// Initialization expresion. - init?: Expression; - - /// Typescript only - definite: boolean; -} - -export type Expression = - | ThisExpression - | ArrayExpression - | ObjectExpression - | FunctionExpression - | UnaryExpression - | UpdateExpression - | BinaryExpression - | AssignmentExpression - | MemberExpression - | ConditionalExpression - | CallExpression - | NewExpression - | SequenceExpression - | Identifier - | Literal - | TemplateLiteral - | TaggedTemplateExpression - | ArrowFunctionExpression - | ClassExpression - | YieldExpression - | MetaProperty - | AwaitExpression - | ParenthesisExpression - | JSXMemberExpression - | JSXNamespacedName - | JSXEmptyExpression - | JSXElement - | JSXFragment - | TsTypeAssertion - | TsNonNullExpression - | TsTypeCastExpression - | TsAsExpression - | PrivateName - | OptionalChainingExpression - | Invalid; - -interface ExpressionBase extends Node, HasSpan { } - -export interface OptionalChainingExpression extends ExpressionBase { - type: "OptionalChainingExpression"; - /** - * Call expression or member expression. - */ - expr: Expression; -} - -export interface ThisExpression extends ExpressionBase { - type: "ThisExpression"; -} - -export interface ArrayExpression extends ExpressionBase { - type: "ArrayExpression"; - - elements: (Expression | SpreadElement | undefined)[]; -} - -export interface ObjectExpression extends ExpressionBase { - type: "ObjectExpression"; - - properties: (Property | SpreadElement)[]; -} - -export interface Argument { - spread: Span; - expression: Expression; -} - -export type PropertOrSpread = Property | SpreadElement; - -export interface SpreadElement extends Node { - type: "SpreadElement"; - - spread: Span; - - arguments: Expression; -} - -export interface UnaryExpression extends ExpressionBase { - type: "UnaryExpression"; - - operator: UnaryOperator; - - argument: Expression; -} - -export interface UpdateExpression extends ExpressionBase { - type: "UpdateExpression"; - - operator: UpdateOperator; - - prefix: boolean; - - argument: Expression; -} - -export interface BinaryExpression extends ExpressionBase { - type: "BinaryExpression"; - - operator: BinaryOperator; - - left: Expression; - - right: Expression; -} - -export interface FunctionExpression extends Fn, ExpressionBase { - type: "FunctionExpression"; - - identifier: Identifier; -} - -export interface ClassExpression extends Class, ExpressionBase { - type: "ClassExpression"; - - identifier: Identifier; -} - -export interface AssignmentExpression extends ExpressionBase { - type: "AssignmentExpression"; - - operator: AssignmentOperator; - - left: Pattern | Expression; - - right: Expression; -} - -export interface MemberExpression extends ExpressionBase { - type: "MemberExpression"; - - object: Expression | Super; - - property: Expression; - - computed: boolean; -} - -export interface ConditionalExpression extends ExpressionBase { - type: "ConditionalExpression"; - - test: Expression; - - consequent: Expression; - - alternate: Expression; -} - -export interface Super extends Node, HasSpan { - type: "Super"; -} - -export interface CallExpression extends ExpressionBase { - type: "CallExpression"; - - callee: Expression | Super; - - arguments: Argument[]; - - typeArguments?: TsTypeParameterInstantiation; -} - -export interface NewExpression extends ExpressionBase { - type: "NewExpression"; - - callee: Expression; - - arguments: Argument[]; - - typeArguments?: TsTypeParameterInstantiation; -} - -export interface SequenceExpression extends ExpressionBase { - type: "SequenceExpression"; - - expressions: Expression[]; -} - -export interface ArrowFunctionExpression extends ExpressionBase { - type: "ArrowFunctionExpression"; - - params: Pattern[]; - - body: BlockStatement | Expression; - - async: boolean; - - generator: boolean; - - typeParameters?: TsTypeParameterDeclaration; - - returnType?: TsTypeAnnotation; -} - -export interface YieldExpression extends ExpressionBase { - type: "YieldExpression"; - - argument?: Expression; - - delegate: boolean; -} - -export interface MetaProperty extends Node { - type: "MetaProperty"; - - meta: Identifier; - - property: Identifier; -} - -export interface AwaitExpression extends ExpressionBase { - type: "AwaitExpression"; - - argument: Expression; -} - -export interface TplBase { - expressions: Expression[]; - - quasis: TemplateElement[]; -} - -export interface TemplateLiteral extends ExpressionBase, TplBase { - type: "TemplateLiteral"; -} - -export interface TaggedTemplateExpression extends ExpressionBase, TplBase { - type: "TaggedTemplateExpression"; - - tag: Expression; - - typeParameters: TsTypeParameterInstantiation; -} - -export interface TemplateElement extends ExpressionBase { - type: "TemplateElement"; - - tail: boolean; - cooked: StringLiteral; - raw: StringLiteral; -} - -export interface ParenthesisExpression extends ExpressionBase { - type: "ParenthesisExpression"; - - expression: Expression; -} - -export interface Fn extends HasSpan, HasDecorator { - params: Param[]; - - body: BlockStatement; - - generator: boolean; - - async: boolean; - - typeParameters?: TsTypeParameterDeclaration; - - returnType?: TsTypeAnnotation; -} - -interface PatternBase { - typeAnnotation?: TsTypeAnnotation; -} - -export interface Identifier extends HasSpan, PatternBase { - type: "Identifier"; - - value: string; - - /// TypeScript only. Used in case of an optional parameter. - optional: boolean; -} - -export interface PrivateName extends ExpressionBase { - type: "PrivateName"; - - id: Identifier; -} - -export type JSXObject = JSXMemberExpression | Identifier; - -export interface JSXMemberExpression extends Node { - type: "JSXMemberExpression"; - - object: JSXObject; - property: Identifier; -} - -/** - * XML-based namespace syntax: - */ -export interface JSXNamespacedName extends Node { - type: "JSXNamespacedName"; - - namespace: Identifier; - name: Identifier; -} - -export interface JSXEmptyExpression extends Node, HasSpan { - type: "JSXEmptyExpression"; -} - -export interface JSXExpressionContainer extends Node { - type: "JSXExpressionContainer"; - - expression: JSXExpression; -} - -export type JSXExpression = JSXEmptyExpression | Expression; - -export interface JSXSpreadChild extends Node { - type: "JSXSpreadChild"; - - expression: Expression; -} - -export type JSXElementName = - | Identifier - | JSXMemberExpression - | JSXNamespacedName; - -export interface JSXOpeningElement extends Node, HasSpan { - type: "JSXOpeningElement"; - - name: JSXElementName; - - attrs?: JSXAttributeOrSpread[]; - - selfClosing: boolean; - - typeArguments?: TsTypeParameterInstantiation; -} - -export type JSXAttributeOrSpread = JSXAttribute | SpreadElement; - -export interface JSXClosingElement extends Node, HasSpan { - type: "JSXClosingElement"; - - name: JSXElementName; -} - -export interface JSXAttribute extends Node, HasSpan { - type: "JSXAttribute"; - - name: JSXAttributeName; - - value?: JSXAttrValue; -} - -export type JSXAttributeName = Identifier | JSXNamespacedName; - -export type JSXAttrValue = - | Literal - | JSXExpressionContainer - | JSXElement - | JSXFragment; - -export interface JSXText extends Node, HasSpan { - type: "JSXText"; - - value: string; - raw: string; -} - -export interface JSXElement extends Node, HasSpan { - type: "JSXElement"; - - opening: JSXOpeningElement; - children: JSXElementChild[]; - closing?: JSXClosingElement; -} - -export type JSXElementChild = - | JSXText - | JSXExpressionContainer - | JSXSpreadChild - | JSXElement - | JSXFragment; - -export interface JSXFragment extends Node, HasSpan { - type: "JSXFragment"; - - opening: JSXOpeningFragment; - - children: JSXElementChild[]; - - closing: JSXClosingFragment; -} - -export interface JSXOpeningFragment extends Node, HasSpan { - type: "JSXOpeningFragment"; -} - -export interface JSXClosingFragment extends Node, HasSpan { - type: "JSXClosingFragment"; -} - -export type Literal = - | StringLiteral - | BooleanLiteral - | NullLiteral - | NumericLiteral - | RegExpLiteral - | JSXText; - -export interface StringLiteral extends Node, HasSpan { - type: "StringLiteral"; - - value: string; - has_escape: boolean; -} - -export interface BooleanLiteral extends Node, HasSpan { - type: "BooleanLiteral"; - - value: boolean; -} - -export interface NullLiteral extends Node, HasSpan { - type: "NullLiteral"; -} - -export interface RegExpLiteral extends Node, HasSpan { - type: "RegExpLiteral"; - - pattern: string; - flags: string; -} - -export interface NumericLiteral extends Node, HasSpan { - type: "NumericLiteral"; - - value: number; -} - -export type ModuleDeclaration = - | ImportDeclaration - | ExportDeclaration - | ExportNamedDeclaration - | ExportDefaultDeclaration - | ExportDefaultExpression - | ExportAllDeclaration - | TsImportEqualsDeclaration - | TsExportAssignment - | TsNamespaceExportDeclaration; - -export interface ExportDefaultExpression extends Node, HasSpan { - type: "ExportDefaultExpression"; - - expression: Expression; -} - -export interface ExportDeclaration extends Node, HasSpan { - type: "ExportDeclaration"; - - declaration: Declaration; -} - -export interface ImportDeclaration extends Node, HasSpan { - type: "ImportDeclaration"; - - specifiers: ImporSpecifier[]; - - source: StringLiteral; -} - -export type ImporSpecifier = - | ImportDefaultSpecifier - | NamedImportSpecifier - | ImportNamespaceSpecifier; - -export interface ExportAllDeclaration extends Node, HasSpan { - type: "ExportAllDeclaration"; - - source: StringLiteral; -} - -/** - * - `export { foo } from 'mod'` - * - `export { foo as bar } from 'mod'` - */ -export interface ExportNamedDeclaration extends Node, HasSpan { - type: "ExportNamedDeclaration"; - - specifiers: ExportSpecifier[]; - - source?: StringLiteral; -} - -export interface ExportDefaultDeclaration extends Node, HasSpan { - type: "ExportDefaultDeclaration"; - - decl: DefaultDecl; -} - -export type DefaultDecl = - | ClassExpression - | FunctionExpression - | TsInterfaceDeclaration; - -export type ImportSpecifier = - | NamedImportSpecifier - | ImportDefaultSpecifier - | ImportNamespaceSpecifier; - -/** - * e.g. `import foo from 'mod.js'` - */ -export interface ImportDefaultSpecifier extends Node, HasSpan { - type: "ImportDefaultSpecifier"; - local: Identifier; -} - -/** - * e.g. `import * as foo from 'mod.js'`. - */ -export interface ImportNamespaceSpecifier extends Node, HasSpan { - type: "ImportNamespaceSpecifier"; - - local: Identifier; -} - -/** - * e.g. - `import { foo } from 'mod.js'` - * - * local = foo, imported = None - * - * e.g. `import { foo as bar } from 'mod.js'` - * - * local = bar, imported = Some(foo) for - */ -export interface NamedImportSpecifier extends Node, HasSpan { - type: "ImportSpecifier"; - local: Identifier; - imported: Identifier; -} - -export type ExportSpecifier = - | ExportNamespaceSpecifer - | ExportDefaultSpecifier - | NamedExportSpecifier; - -/** - * `export * as foo from 'src';` - */ -export interface ExportNamespaceSpecifer extends Node, HasSpan { - type: "ExportNamespaceSpecifer"; - - name: Identifier; -} - -export interface ExportDefaultSpecifier extends Node, HasSpan { - type: "ExportDefaultSpecifier"; - - exported: Identifier; -} - -export interface NamedExportSpecifier extends Node, HasSpan { - type: "ExportSpecifier"; - - orig: Identifier; - /** - * `Some(bar)` in `export { foo as bar }` - */ - exported: Identifier; -} - -interface HasInterpreter { - /** - * e.g. `/usr/bin/node` for `#!/usr/bin/node` - */ - interpreter: string; -} - -export type Program = Module | Script; - -export interface Module extends Node, HasSpan, HasInterpreter { - type: "Module"; - - body: ModuleItem[]; -} - -export interface Script extends Node, HasSpan, HasInterpreter { - type: "Script"; - - body: Statement[]; -} - -export type ModuleItem = ModuleDeclaration | Statement; - -export type BinaryOperator = - | "==" - | "!=" - | "===" - | "!==" - | "<" - | "<=" - | ">" - | ">=" - | "<<" - | ">>" - | ">>>" - | "+" - | "-" - | "*" - | "/" - | "%" - | "**" - | "|" - | "^" - | "&" - | "||" - | "&&" - | "in" - | "instanceof" - | "??"; - -export type AssignmentOperator = - | "=" - | "+=" - | "-=" - | "*=" - | "/=" - | "%=" - | "**=" - | "<<=" - | ">>=" - | ">>>=" - | "|=" - | "^=" - | "&="; - -export type UpdateOperator = "++" | "--"; - -export type UnaryOperator = - | "-" - | "+" - | "!" - | "~" - | "typeof" - | "void" - | "delete"; - -export type Pattern = - | Identifier - | ArrayPattern - | RestElement - | ObjectPattern - | AssignmentPattern - | Invalid - | Expression; - -export interface ArrayPattern extends Node, HasSpan, PatternBase { - type: "ArrayPattern"; - - elements: (Pattern | undefined)[]; -} - -export interface ObjectPattern extends Node, HasSpan, PatternBase { - type: "ObjectPattern"; - - props: ObjectPatternProperty[]; -} - -export interface AssignmentPattern extends Node, HasSpan, PatternBase { - type: "AssignmentPattern"; - - left: Pattern; - right: Expression; -} - -export interface RestElement extends Node, HasSpan, PatternBase { - type: "RestElement"; - - rest: Span; - - argument: Pattern; -} - -export type ObjectPatternProperty = - | KeyValuePatternProperty - | AssignmentPatternProperty - | RestElement; - -/** - * `{key: value}` - */ -export interface KeyValuePatternProperty extends Node { - type: "KeyValuePatternProperty"; - - key: PropertyName; - value: Pattern; -} - -/** - * `{key}` or `{key = value}` - */ -export interface AssignmentPatternProperty extends Node, HasSpan { - type: "AssignmentPatternProperty"; - - key: Identifier; - value?: Expression; -} - -/** Identifier is `a` in `{ a, }` */ -export type Property = - | Identifier - | KeyValueProperty - | AssignmentProperty - | GetterProperty - | SetterProperty - | MethodProperty; - -interface PropBase extends Node { - key: PropertyName; -} - -export interface KeyValueProperty extends PropBase { - type: "KeyValueProperty"; - - value: Expression; -} - -export interface AssignmentProperty extends Node { - type: "AssignmentProperty"; - - key: Identifier; - value: Expression; -} - -export interface GetterProperty extends PropBase, HasSpan { - type: "GetterProperty"; - - typeAnnotation?: TsTypeAnnotation; - - body: BlockStatement; -} - -export interface SetterProperty extends PropBase, HasSpan { - type: "SetterProperty"; - - param: Pattern; - body: BlockStatement; -} - -export interface MethodProperty extends PropBase, Fn { - type: "MethodProperty"; -} - -export type PropertyName = - | Identifier - | StringLiteral - | NumericLiteral - | ComputedPropName; - -export interface ComputedPropName extends Node, HasSpan { - type: "Computed"; - expression: Expression; -} - -export interface BlockStatement extends Node, HasSpan { - type: "BlockStatement"; - - stmts: Statement[]; -} - -export interface ExpressionStatement extends Node, HasSpan { - type: "ExpressionStatement"; - expression: Expression; -} - -export type Statement = - | ExpressionStatement - | BlockStatement - | EmptyStatement - | DebuggerStatement - | WithStatement - | ReturnStatement - | LabeledStatement - | BreakStatement - | ContinueStatement - | IfStatement - | SwitchStatement - | ThrowStatement - | TryStatement - | WhileStatement - | DoWhileStatement - | ForStatement - | ForInStatement - | ForOfStatement - | Declaration; - -export interface EmptyStatement extends Node, HasSpan { - type: "EmptyStatement"; -} - -export interface DebuggerStatement extends Node, HasSpan { - type: "DebuggerStatement"; -} - -export interface WithStatement extends Node, HasSpan { - type: "WithStatement"; - - object: Expression; - body: Statement; -} - -export interface ReturnStatement extends Node, HasSpan { - type: "ReturnStatement"; - - argument: Expression; -} - -export interface LabeledStatement extends Node, HasSpan { - type: "LabeledStatement"; - - label: Identifier; - body: Statement; -} - -export interface BreakStatement extends Node, HasSpan { - type: "BreakStatement"; - - label: Identifier; -} - -export interface ContinueStatement extends Node, HasSpan { - type: "ContinueStatement"; - - label: Identifier; -} - -export interface IfStatement extends Node, HasSpan { - type: "IfStatement"; - - test: Expression; - consequent: Statement; - alternate?: Statement; -} - -export interface SwitchStatement extends Node, HasSpan { - type: "SwitchStatement"; - - discriminant: Expression; - cases: SwitchCase[]; -} - -export interface ThrowStatement extends Node, HasSpan { - type: "ThrowStatement"; - - argument: Expression; -} - -export interface TryStatement extends Node, HasSpan { - type: "TryStatement"; - - block: BlockStatement; - handler?: CatchClause; - finalizer: BlockStatement; -} - -export interface WhileStatement extends Node, HasSpan { - type: "WhileStatement"; - - test: Expression; - body: Statement; -} - -export interface DoWhileStatement extends Node, HasSpan { - type: "DoWhileStatement"; - - test: Expression; - body: Statement; -} - -export interface ForStatement extends Node, HasSpan { - type: "ForStatement"; - - init?: VariableDeclaration | Expression; - test?: Expression; - update?: Expression; - body: Statement; -} - -export interface ForInStatement extends Node, HasSpan { - type: "ForInStatement"; - - left: VariableDeclaration | Pattern; - right: Expression; - body: Statement; -} - -export interface ForOfStatement extends Node, HasSpan { - type: "ForOfStatement"; - - /** - * Span of the await token. - * - * es2018 for-await-of statements, e.g., `for await (const x of xs) {` - */ - await: Span; - left: VariableDeclaration | Pattern; - right: Expression; - body: Statement; -} - -export interface SwitchCase extends Node, HasSpan { - type: "SwitchCase"; - - /** - * Undefined for default case - */ - test?: Expression; - consequent: Statement[]; -} - -export interface CatchClause extends Node, HasSpan { - type: "CatchClause"; - - /** - * The param is `undefined` if the catch binding is omitted. E.g., `try { foo() } catch {}` - */ - param: Pattern; - body: BlockStatement; -} - -export interface TsTypeAnnotation extends Node, HasSpan { - type: "TsTypeAnnotation"; - - typeAnnotation: TsType; -} - -export interface TsTypeParameterDeclaration extends Node, HasSpan { - type: "TsTypeParameterDeclaration"; - - parameters: TsTypeParameter[]; -} - -export interface TsTypeParameter extends Node, HasSpan { - type: "TsTypeParameter"; - - name: Identifier; - constraint: TsType; - default: TsType; -} - -export interface TsTypeParameterInstantiation extends Node, HasSpan { - type: "TsTypeParameterInstantiation"; - - params: TsType[]; -} - -export interface TsTypeCastExpression extends Node, HasSpan { - type: "TsTypeCastExpression"; - - expression: Expression; - typeAnnotation: TsTypeAnnotation; -} - -export interface TsParameterProperty extends Node, HasSpan, HasDecorator { - type: "TsParameterProperty"; - - accessibility?: Accessibility; - readonly: boolean; - param: TsParameterPropertyParameter; -} - -export type TsParameterPropertyParameter = Identifier | AssignmentPattern; - -export interface TsQualifiedName extends Node { - type: "TsQualifiedName"; - - left: TsEntityName; - right: Identifier; -} - -export type TsEntityName = TsQualifiedName | Identifier; - -export type TsSignatureDeclaration = - | TsCallSignatureDeclaration - | TsConstructSignatureDeclaration - | TsMethodSignature - | TsFunctionType - | TsConstructorType; - -export type TsTypeElement = - | TsCallSignatureDeclaration - | TsConstructSignatureDeclaration - | TsPropertySignature - | TsMethodSignature - | TsIndexSignature; - -export interface TsCallSignatureDeclaration extends Node, HasSpan { - type: "TsCallSignatureDeclaration"; - - params: TsFnParameter[]; - typeAnnotation: TsTypeAnnotation; - typeParams: TsTypeParameterDeclaration; -} - -export interface TsConstructSignatureDeclaration extends Node, HasSpan { - type: "TsConstructSignatureDeclaration"; - - params: TsFnParameter[]; - typeAnnotation: TsTypeAnnotation; - typeParams: TsTypeParameterDeclaration; -} - -export interface TsPropertySignature extends Node, HasSpan { - type: "TsPropertySignature"; - - readonly: boolean; - key: Expression; - computed: boolean; - optional: boolean; - - init: Expression; - params: TsFnParameter[]; - - typeAnnotation?: TsTypeAnnotation; - typeParams: TsTypeParameterDeclaration; -} - -export interface TsMethodSignature extends Node, HasSpan { - type: "TsMethodSignature"; - - readonly: boolean; - key: Expression; - computed: boolean; - optional: boolean; - params: TsFnParameter[]; - - typeAnnotation: TsTypeAnnotation; - typeParams: TsTypeParameterDeclaration; -} - -export interface TsIndexSignature extends Node, HasSpan { - type: "TsIndexSignature"; - - readonly: boolean; - params: TsFnParameter[]; - - typeAnnotation?: TsTypeAnnotation; -} - -export type TsType = - | TsKeywordType - | TsThisType - | TsFnOrConstructorType - | TsTypeReference - | TsTypeQuery - | TsTypeLiteral - | TsArrayType - | TsTupleType - | TsOptionalType - | TsRestType - | TsUnionOrIntersectionType - | TsConditionalType - | TsInferType - | TsParenthesizedType - | TsTypeOperator - | TsIndexedAccessType - | TsMappedType - | TsLiteralType - | TsImportType - | TsTypePredicate; - -export type TsFnOrConstructorType = TsFunctionType | TsConstructorType; - -export interface TsKeywordType extends Node, HasSpan { - type: "TsKeywordType"; - - kind: TsKeywordTypeKind; -} - -export type TsKeywordTypeKind = - | "any" - | "unknown" - | "number" - | "object" - | "boolean" - | "bigint" - | "string" - | "symbol" - | "void" - | "undefined" - | "null" - | "never"; - -export interface TsThisType extends Node, HasSpan { - type: "TsThisType"; -} - -export type TsFnParameter = Identifier | RestElement | ObjectPattern; - -export interface TsFunctionType extends Node, HasSpan { - type: "TsFunctionType"; - - typeParams: TsTypeParameterDeclaration; - typeAnnotation: TsTypeAnnotation; -} - -export interface TsConstructorType extends Node, HasSpan { - type: "TsConstructorType"; - - params: TsFnParameter[]; - - typeParams: TsTypeParameterDeclaration; - typeAnnotation: TsTypeAnnotation; -} - -export interface TsTypeReference extends Node, HasSpan { - type: "TsTypeReference"; - - typeName: TsEntityName; - typeParams: TsTypeParameterInstantiation; -} - -export interface TsTypePredicate extends Node, HasSpan { - type: "TsTypePredicate"; - - asserts: boolean; - - paramName: TsThisTypeOrIdent; - typeAnnotation: TsTypeAnnotation; -} - -export type TsThisTypeOrIdent = TsThisType | Identifier; - -export interface TsImportType extends Node, HasSpan { - argument: StringLiteral; - qualifier?: TsEntityName; - typeArguments?: TsTypeParameterInstantiation; -} - -/** - * `typeof` operator - */ -export interface TsTypeQuery extends Node, HasSpan { - type: "TsTypeQuery"; - - exprName: TsTypeQueryExpr; -} - -export type TsTypeQueryExpr = TsEntityName | TsImportType; - -export interface TsTypeLiteral extends Node, HasSpan { - type: "TsTypeLiteral"; - - members: TsTypeElement[]; -} - -export interface TsArrayType extends Node, HasSpan { - type: "TsArrayType"; - - elemType: TsType; -} - -export interface TsTupleType extends Node, HasSpan { - type: "TsTupleType"; - - elemTypes: TsType[]; -} - -export interface TsOptionalType extends Node, HasSpan { - type: "TsOptionalType"; - - typeAnnotation: TsType; -} - -export interface TsRestType extends Node, HasSpan { - type: "TsRestType"; - - typeAnnotation: TsType; -} - -export type TsUnionOrIntersectionType = TsUnionType | TsIntersectionType; - -export interface TsUnionType extends Node, HasSpan { - type: "TsUnionType"; - - types: TsType[]; -} - -export interface TsIntersectionType extends Node, HasSpan { - type: "TsIntersectionType"; - - types: TsType[]; -} - -export interface TsConditionalType extends Node, HasSpan { - type: "TsConditionalType"; - - checkType: TsType; - extendsType: TsType; - trueType: TsType; - falseType: TsType; -} - -export interface TsInferType extends Node, HasSpan { - type: "TsInferType"; - - typeParam: TsTypeParameter; -} - -export interface TsParenthesizedType extends Node, HasSpan { - type: "TsParenthesizedType"; - - typeAnnotation: TsType; -} - -export interface TsTypeOperator extends Node, HasSpan { - type: "TsTypeOperator"; - - op: TsTypeOperatorOp; - typeAnnotation: TsType; -} - -export type TsTypeOperatorOp = "keyof" | "unique"; - -export interface TsIndexedAccessType extends Node, HasSpan { - type: "TsIndexedAccessType"; - - objectType: TsType; - indexType: TsType; -} - -export type TruePlusMinus = true | "+" | "-"; - -export interface TsMappedType extends Node, HasSpan { - type: "TsMappedType"; - - readonly: TruePlusMinus; - typeParam: TsTypeParameter; - optional: TruePlusMinus; - typeAnnotation: TsType; -} - -export interface TsLiteralType extends Node, HasSpan { - type: "TsLiteralType"; - - literal: TsLiteral; -} - -export type TsLiteral = NumericLiteral | StringLiteral | BooleanLiteral | TemplateLiteral; - -// // ================ -// // TypeScript declarations -// // ================ - -export interface TsInterfaceDeclaration extends Node, HasSpan { - type: "TsInterfaceDeclaration"; - - id: Identifier; - declare: boolean; - typeParams?: TsTypeParameterDeclaration; - extends: TsExpressionWithTypeArguments[]; - body: TsInterfaceBody; -} - -export interface TsInterfaceBody extends Node, HasSpan { - type: "TsInterfaceBody"; - - body: TsTypeElement[]; -} - -export interface TsExpressionWithTypeArguments extends Node, HasSpan { - type: "TsExpressionWithTypeArguments"; - - expression: TsEntityName; - typeArguments?: TsTypeParameterInstantiation; -} - -export interface TsTypeAliasDeclaration extends Node, HasSpan { - type: "TsTypeAliasDeclaration"; - - declare: boolean; - id: Identifier; - typeParams?: TsTypeParameterDeclaration; - typeAnnotation: TsType; -} - -export interface TsEnumDeclaration extends Node, HasSpan { - type: "TsEnumDeclaration"; - - declare: boolean; - is_const: boolean; - id: Identifier; - member: TsEnumMember[]; -} - -export interface TsEnumMember extends Node, HasSpan { - type: "TsEnumMember"; - - id: TsEnumMemberId; - init?: Expression; -} - -export type TsEnumMemberId = Identifier | StringLiteral; - -export interface TsModuleDeclaration extends Node, HasSpan { - type: "TsModuleDeclaration"; - - declare: boolean; - global: boolean; - id: TsModuleName; - body?: TsNamespaceBody; -} - -/** - * `namespace A.B { }` is a namespace named `A` with another TsNamespaceDecl as its body. - */ -export type TsNamespaceBody = TsModuleBlock | TsNamespaceDeclaration; - -export interface TsModuleBlock extends Node, HasSpan { - type: "TsModuleBlock"; - - body: ModuleItem[]; -} - -export interface TsNamespaceDeclaration extends Node, HasSpan { - type: "TsNamespaceDeclaration"; - - declare: boolean; - global: boolean; - id: Identifier; - body: TsNamespaceBody; -} - -export type TsModuleName = Identifier | StringLiteral; - -export interface TsImportEqualsDeclaration extends Node, HasSpan { - type: "TsImportEqualsDeclaration"; - - declare: boolean; - is_export: boolean; - id: Identifier; - moduleRef: TsModuleReference; -} - -export type TsModuleReference = TsEntityName | TsExternalModuleReference; - -export interface TsExternalModuleReference extends Node, HasSpan { - type: "TsExternalModuleReference"; - - expression: Expression; -} - -export interface TsExportAssignment extends Node, HasSpan { - type: "TsExportAssignment"; - - expression: Expression; -} - -export interface TsNamespaceExportDeclaration extends Node, HasSpan { - type: "TsNamespaceExportDeclaration"; - - id: Identifier; -} - -export interface TsAsExpression extends ExpressionBase { - type: "TsAsExpression"; - - expression: Expression; - typeAnnotation: TsType; -} - -export interface TsTypeAssertion extends ExpressionBase { - type: "TsTypeAssertion"; - - expression: Expression; - typeAnnotation: TsType; -} - -export interface TsNonNullExpression extends ExpressionBase { - type: "TsNonNullExpression"; - - expression: Expression; -} - -export type Accessibility = "public" | "protected" | "private"; - -export interface Invalid extends Node, HasSpan { - type: "Invalid"; -} diff --git a/cli/dts/lib.swc.d.ts b/cli/dts/lib.swc.d.ts new file mode 100644 index 00000000000000..9d3ee90ac8edc1 --- /dev/null +++ b/cli/dts/lib.swc.d.ts @@ -0,0 +1,1568 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +/// + +// --- AST Nodes --- + +export interface Span { + start: number; + end: number; + ctxt: number; +} + +export interface Node { + type: string; +} + +export interface HasSpan { + span: Span; +} + +export interface HasDecorator { + decorators?: Decorator[]; +} + +export interface Class extends HasSpan, HasDecorator { + body: ClassMember[]; + + superClass?: Expression; + + is_abstract: boolean; + + typeParams: TsTypeParameterDeclaration; + + superTypeParams?: TsTypeParameterInstantiation; + + implements: TsExpressionWithTypeArguments[]; +} + +export type ClassMember = + | Constructor + | ClassMethod + | PrivateMethod + | ClassProperty + | PrivateProperty + | TsIndexSignature; + +export interface ClassPropertyBase extends Node, HasSpan, HasDecorator { + value?: Expression; + + typeAnnotation?: TsTypeAnnotation; + + is_static: boolean; + + computed: boolean; + + accessibility?: Accessibility; + + /// Typescript extension. + is_abstract: boolean; + + is_optional: boolean; + + readonly: boolean; + + definite: boolean; +} + +export interface ClassProperty extends ClassPropertyBase { + type: "ClassProperty"; + + key: Expression; +} + +export interface PrivateProperty extends ClassPropertyBase { + type: "PrivateProperty"; + + key: PrivateName; +} + +export interface Param extends Node, HasSpan, HasDecorator { + type: 'Parameter' + pat: Pattern +} + +export interface Constructor extends Node, HasSpan { + type: "Constructor"; + + key: PropertyName; + + params: (Param | TsParameterProperty)[]; + + body: BlockStatement; + + accessibility?: Accessibility; + + is_optional: boolean; +} + +export interface ClassMethodBase extends Node, HasSpan { + function: Fn; + + kind: MethodKind; + + is_static: boolean; + + accessibility?: Accessibility; + + is_abstract: boolean; + + is_optional: boolean; +} + +export interface ClassMethod extends ClassMethodBase { + type: "ClassMethod"; + + key: PropertyName; +} + +export interface PrivateMethod extends ClassMethodBase { + type: "PrivateMethod"; + + key: PrivateName; +} + +export interface Decorator extends Node, HasSpan { + type: "Decorator"; + + expression: Expression; +} + +export type MethodKind = "method" | "setter" | "getter"; + +export type Declaration = + | ClassDeclaration + | FunctionDeclaration + | VariableDeclaration + | TsInterfaceDeclaration + | TsTypeAliasDeclaration + | TsEnumDeclaration + | TsModuleDeclaration; + +export interface FunctionDeclaration extends Fn { + type: "FunctionDeclaration"; + + ident: Identifier; + + declare: boolean; +} + +export interface ClassDeclaration extends Class, Node { + type: "ClassDeclaration"; + + identifier: Identifier; + + declare: boolean; +} + +export interface VariableDeclaration extends Node, HasSpan { + type: "VariableDeclaration"; + + kind: VariableDeclarationKind; + + declare: boolean; + + declarations: VariableDeclarator[]; +} + +export type VariableDeclarationKind = "get" | "let" | "const"; + +export interface VariableDeclarator extends Node, HasSpan { + type: "VariableDeclarator"; + + id: Pattern; + + /// Initialization expresion. + init?: Expression; + + /// Typescript only + definite: boolean; +} + +export type Expression = + | ThisExpression + | ArrayExpression + | ObjectExpression + | FunctionExpression + | UnaryExpression + | UpdateExpression + | BinaryExpression + | AssignmentExpression + | MemberExpression + | ConditionalExpression + | CallExpression + | NewExpression + | SequenceExpression + | Identifier + | Literal + | TemplateLiteral + | TaggedTemplateExpression + | ArrowFunctionExpression + | ClassExpression + | YieldExpression + | MetaProperty + | AwaitExpression + | ParenthesisExpression + | JSXMemberExpression + | JSXNamespacedName + | JSXEmptyExpression + | JSXElement + | JSXFragment + | TsTypeAssertion + | TsNonNullExpression + | TsTypeCastExpression + | TsAsExpression + | PrivateName + | OptionalChainingExpression + | Invalid; + +interface ExpressionBase extends Node, HasSpan { } + +export interface OptionalChainingExpression extends ExpressionBase { + type: "OptionalChainingExpression"; + /** + * Call expression or member expression. + */ + expr: Expression; +} + +export interface ThisExpression extends ExpressionBase { + type: "ThisExpression"; +} + +export interface ArrayExpression extends ExpressionBase { + type: "ArrayExpression"; + + elements: (Expression | SpreadElement | undefined)[]; +} + +export interface ObjectExpression extends ExpressionBase { + type: "ObjectExpression"; + + properties: (Property | SpreadElement)[]; +} + +export interface Argument { + spread: Span; + expression: Expression; +} + +export type PropertOrSpread = Property | SpreadElement; + +export interface SpreadElement extends Node { + type: "SpreadElement"; + + spread: Span; + + arguments: Expression; +} + +export interface UnaryExpression extends ExpressionBase { + type: "UnaryExpression"; + + operator: UnaryOperator; + + argument: Expression; +} + +export interface UpdateExpression extends ExpressionBase { + type: "UpdateExpression"; + + operator: UpdateOperator; + + prefix: boolean; + + argument: Expression; +} + +export interface BinaryExpression extends ExpressionBase { + type: "BinaryExpression"; + + operator: BinaryOperator; + + left: Expression; + + right: Expression; +} + +export interface FunctionExpression extends Fn, ExpressionBase { + type: "FunctionExpression"; + + identifier: Identifier; +} + +export interface ClassExpression extends Class, ExpressionBase { + type: "ClassExpression"; + + identifier: Identifier; +} + +export interface AssignmentExpression extends ExpressionBase { + type: "AssignmentExpression"; + + operator: AssignmentOperator; + + left: Pattern | Expression; + + right: Expression; +} + +export interface MemberExpression extends ExpressionBase { + type: "MemberExpression"; + + object: Expression | Super; + + property: Expression; + + computed: boolean; +} + +export interface ConditionalExpression extends ExpressionBase { + type: "ConditionalExpression"; + + test: Expression; + + consequent: Expression; + + alternate: Expression; +} + +export interface Super extends Node, HasSpan { + type: "Super"; +} + +export interface CallExpression extends ExpressionBase { + type: "CallExpression"; + + callee: Expression | Super; + + arguments: Argument[]; + + typeArguments?: TsTypeParameterInstantiation; +} + +export interface NewExpression extends ExpressionBase { + type: "NewExpression"; + + callee: Expression; + + arguments: Argument[]; + + typeArguments?: TsTypeParameterInstantiation; +} + +export interface SequenceExpression extends ExpressionBase { + type: "SequenceExpression"; + + expressions: Expression[]; +} + +export interface ArrowFunctionExpression extends ExpressionBase { + type: "ArrowFunctionExpression"; + + params: Pattern[]; + + body: BlockStatement | Expression; + + async: boolean; + + generator: boolean; + + typeParameters?: TsTypeParameterDeclaration; + + returnType?: TsTypeAnnotation; +} + +export interface YieldExpression extends ExpressionBase { + type: "YieldExpression"; + + argument?: Expression; + + delegate: boolean; +} + +export interface MetaProperty extends Node { + type: "MetaProperty"; + + meta: Identifier; + + property: Identifier; +} + +export interface AwaitExpression extends ExpressionBase { + type: "AwaitExpression"; + + argument: Expression; +} + +export interface TplBase { + expressions: Expression[]; + + quasis: TemplateElement[]; +} + +export interface TemplateLiteral extends ExpressionBase, TplBase { + type: "TemplateLiteral"; +} + +export interface TaggedTemplateExpression extends ExpressionBase, TplBase { + type: "TaggedTemplateExpression"; + + tag: Expression; + + typeParameters: TsTypeParameterInstantiation; +} + +export interface TemplateElement extends ExpressionBase { + type: "TemplateElement"; + + tail: boolean; + cooked: StringLiteral; + raw: StringLiteral; +} + +export interface ParenthesisExpression extends ExpressionBase { + type: "ParenthesisExpression"; + + expression: Expression; +} + +export interface Fn extends HasSpan, HasDecorator { + params: Param[]; + + body: BlockStatement; + + generator: boolean; + + async: boolean; + + typeParameters?: TsTypeParameterDeclaration; + + returnType?: TsTypeAnnotation; +} + +interface PatternBase { + typeAnnotation?: TsTypeAnnotation; +} + +export interface Identifier extends HasSpan, PatternBase { + type: "Identifier"; + + value: string; + + /// TypeScript only. Used in case of an optional parameter. + optional: boolean; +} + +export interface PrivateName extends ExpressionBase { + type: "PrivateName"; + + id: Identifier; +} + +export type JSXObject = JSXMemberExpression | Identifier; + +export interface JSXMemberExpression extends Node { + type: "JSXMemberExpression"; + + object: JSXObject; + property: Identifier; +} + +/** + * XML-based namespace syntax: + */ +export interface JSXNamespacedName extends Node { + type: "JSXNamespacedName"; + + namespace: Identifier; + name: Identifier; +} + +export interface JSXEmptyExpression extends Node, HasSpan { + type: "JSXEmptyExpression"; +} + +export interface JSXExpressionContainer extends Node { + type: "JSXExpressionContainer"; + + expression: JSXExpression; +} + +export type JSXExpression = JSXEmptyExpression | Expression; + +export interface JSXSpreadChild extends Node { + type: "JSXSpreadChild"; + + expression: Expression; +} + +export type JSXElementName = + | Identifier + | JSXMemberExpression + | JSXNamespacedName; + +export interface JSXOpeningElement extends Node, HasSpan { + type: "JSXOpeningElement"; + + name: JSXElementName; + + attrs?: JSXAttributeOrSpread[]; + + selfClosing: boolean; + + typeArguments?: TsTypeParameterInstantiation; +} + +export type JSXAttributeOrSpread = JSXAttribute | SpreadElement; + +export interface JSXClosingElement extends Node, HasSpan { + type: "JSXClosingElement"; + + name: JSXElementName; +} + +export interface JSXAttribute extends Node, HasSpan { + type: "JSXAttribute"; + + name: JSXAttributeName; + + value?: JSXAttrValue; +} + +export type JSXAttributeName = Identifier | JSXNamespacedName; + +export type JSXAttrValue = + | Literal + | JSXExpressionContainer + | JSXElement + | JSXFragment; + +export interface JSXText extends Node, HasSpan { + type: "JSXText"; + + value: string; + raw: string; +} + +export interface JSXElement extends Node, HasSpan { + type: "JSXElement"; + + opening: JSXOpeningElement; + children: JSXElementChild[]; + closing?: JSXClosingElement; +} + +export type JSXElementChild = + | JSXText + | JSXExpressionContainer + | JSXSpreadChild + | JSXElement + | JSXFragment; + +export interface JSXFragment extends Node, HasSpan { + type: "JSXFragment"; + + opening: JSXOpeningFragment; + + children: JSXElementChild[]; + + closing: JSXClosingFragment; +} + +export interface JSXOpeningFragment extends Node, HasSpan { + type: "JSXOpeningFragment"; +} + +export interface JSXClosingFragment extends Node, HasSpan { + type: "JSXClosingFragment"; +} + +export type Literal = + | StringLiteral + | BooleanLiteral + | NullLiteral + | NumericLiteral + | RegExpLiteral + | JSXText; + +export interface StringLiteral extends Node, HasSpan { + type: "StringLiteral"; + + value: string; + has_escape: boolean; +} + +export interface BooleanLiteral extends Node, HasSpan { + type: "BooleanLiteral"; + + value: boolean; +} + +export interface NullLiteral extends Node, HasSpan { + type: "NullLiteral"; +} + +export interface RegExpLiteral extends Node, HasSpan { + type: "RegExpLiteral"; + + pattern: string; + flags: string; +} + +export interface NumericLiteral extends Node, HasSpan { + type: "NumericLiteral"; + + value: number; +} + +export type ModuleDeclaration = + | ImportDeclaration + | ExportDeclaration + | ExportNamedDeclaration + | ExportDefaultDeclaration + | ExportDefaultExpression + | ExportAllDeclaration + | TsImportEqualsDeclaration + | TsExportAssignment + | TsNamespaceExportDeclaration; + +export interface ExportDefaultExpression extends Node, HasSpan { + type: "ExportDefaultExpression"; + + expression: Expression; +} + +export interface ExportDeclaration extends Node, HasSpan { + type: "ExportDeclaration"; + + declaration: Declaration; +} + +export interface ImportDeclaration extends Node, HasSpan { + type: "ImportDeclaration"; + + specifiers: ImporSpecifier[]; + + source: StringLiteral; +} + +export type ImporSpecifier = + | ImportDefaultSpecifier + | NamedImportSpecifier + | ImportNamespaceSpecifier; + +export interface ExportAllDeclaration extends Node, HasSpan { + type: "ExportAllDeclaration"; + + source: StringLiteral; +} + +/** + * - `export { foo } from 'mod'` + * - `export { foo as bar } from 'mod'` + */ +export interface ExportNamedDeclaration extends Node, HasSpan { + type: "ExportNamedDeclaration"; + + specifiers: ExportSpecifier[]; + + source?: StringLiteral; +} + +export interface ExportDefaultDeclaration extends Node, HasSpan { + type: "ExportDefaultDeclaration"; + + decl: DefaultDecl; +} + +export type DefaultDecl = + | ClassExpression + | FunctionExpression + | TsInterfaceDeclaration; + +export type ImportSpecifier = + | NamedImportSpecifier + | ImportDefaultSpecifier + | ImportNamespaceSpecifier; + +/** + * e.g. `import foo from 'mod.js'` + */ +export interface ImportDefaultSpecifier extends Node, HasSpan { + type: "ImportDefaultSpecifier"; + local: Identifier; +} + +/** + * e.g. `import * as foo from 'mod.js'`. + */ +export interface ImportNamespaceSpecifier extends Node, HasSpan { + type: "ImportNamespaceSpecifier"; + + local: Identifier; +} + +/** + * e.g. - `import { foo } from 'mod.js'` + * + * local = foo, imported = None + * + * e.g. `import { foo as bar } from 'mod.js'` + * + * local = bar, imported = Some(foo) for + */ +export interface NamedImportSpecifier extends Node, HasSpan { + type: "ImportSpecifier"; + local: Identifier; + imported: Identifier; +} + +export type ExportSpecifier = + | ExportNamespaceSpecifer + | ExportDefaultSpecifier + | NamedExportSpecifier; + +/** + * `export * as foo from 'src';` + */ +export interface ExportNamespaceSpecifer extends Node, HasSpan { + type: "ExportNamespaceSpecifer"; + + name: Identifier; +} + +export interface ExportDefaultSpecifier extends Node, HasSpan { + type: "ExportDefaultSpecifier"; + + exported: Identifier; +} + +export interface NamedExportSpecifier extends Node, HasSpan { + type: "ExportSpecifier"; + + orig: Identifier; + /** + * `Some(bar)` in `export { foo as bar }` + */ + exported: Identifier; +} + +interface HasInterpreter { + /** + * e.g. `/usr/bin/node` for `#!/usr/bin/node` + */ + interpreter: string; +} + +export type Program = Module | Script; + +export interface Module extends Node, HasSpan, HasInterpreter { + type: "Module"; + + body: ModuleItem[]; +} + +export interface Script extends Node, HasSpan, HasInterpreter { + type: "Script"; + + body: Statement[]; +} + +export type ModuleItem = ModuleDeclaration | Statement; + +export type BinaryOperator = + | "==" + | "!=" + | "===" + | "!==" + | "<" + | "<=" + | ">" + | ">=" + | "<<" + | ">>" + | ">>>" + | "+" + | "-" + | "*" + | "/" + | "%" + | "**" + | "|" + | "^" + | "&" + | "||" + | "&&" + | "in" + | "instanceof" + | "??"; + +export type AssignmentOperator = + | "=" + | "+=" + | "-=" + | "*=" + | "/=" + | "%=" + | "**=" + | "<<=" + | ">>=" + | ">>>=" + | "|=" + | "^=" + | "&="; + +export type UpdateOperator = "++" | "--"; + +export type UnaryOperator = + | "-" + | "+" + | "!" + | "~" + | "typeof" + | "void" + | "delete"; + +export type Pattern = + | Identifier + | ArrayPattern + | RestElement + | ObjectPattern + | AssignmentPattern + | Invalid + | Expression; + +export interface ArrayPattern extends Node, HasSpan, PatternBase { + type: "ArrayPattern"; + + elements: (Pattern | undefined)[]; +} + +export interface ObjectPattern extends Node, HasSpan, PatternBase { + type: "ObjectPattern"; + + props: ObjectPatternProperty[]; +} + +export interface AssignmentPattern extends Node, HasSpan, PatternBase { + type: "AssignmentPattern"; + + left: Pattern; + right: Expression; +} + +export interface RestElement extends Node, HasSpan, PatternBase { + type: "RestElement"; + + rest: Span; + + argument: Pattern; +} + +export type ObjectPatternProperty = + | KeyValuePatternProperty + | AssignmentPatternProperty + | RestElement; + +/** + * `{key: value}` + */ +export interface KeyValuePatternProperty extends Node { + type: "KeyValuePatternProperty"; + + key: PropertyName; + value: Pattern; +} + +/** + * `{key}` or `{key = value}` + */ +export interface AssignmentPatternProperty extends Node, HasSpan { + type: "AssignmentPatternProperty"; + + key: Identifier; + value?: Expression; +} + +/** Identifier is `a` in `{ a, }` */ +export type Property = + | Identifier + | KeyValueProperty + | AssignmentProperty + | GetterProperty + | SetterProperty + | MethodProperty; + +interface PropBase extends Node { + key: PropertyName; +} + +export interface KeyValueProperty extends PropBase { + type: "KeyValueProperty"; + + value: Expression; +} + +export interface AssignmentProperty extends Node { + type: "AssignmentProperty"; + + key: Identifier; + value: Expression; +} + +export interface GetterProperty extends PropBase, HasSpan { + type: "GetterProperty"; + + typeAnnotation?: TsTypeAnnotation; + + body: BlockStatement; +} + +export interface SetterProperty extends PropBase, HasSpan { + type: "SetterProperty"; + + param: Pattern; + body: BlockStatement; +} + +export interface MethodProperty extends PropBase, Fn { + type: "MethodProperty"; +} + +export type PropertyName = + | Identifier + | StringLiteral + | NumericLiteral + | ComputedPropName; + +export interface ComputedPropName extends Node, HasSpan { + type: "Computed"; + expression: Expression; +} + +export interface BlockStatement extends Node, HasSpan { + type: "BlockStatement"; + + stmts: Statement[]; +} + +export interface ExpressionStatement extends Node, HasSpan { + type: "ExpressionStatement"; + expression: Expression; +} + +export type Statement = + | ExpressionStatement + | BlockStatement + | EmptyStatement + | DebuggerStatement + | WithStatement + | ReturnStatement + | LabeledStatement + | BreakStatement + | ContinueStatement + | IfStatement + | SwitchStatement + | ThrowStatement + | TryStatement + | WhileStatement + | DoWhileStatement + | ForStatement + | ForInStatement + | ForOfStatement + | Declaration; + +export interface EmptyStatement extends Node, HasSpan { + type: "EmptyStatement"; +} + +export interface DebuggerStatement extends Node, HasSpan { + type: "DebuggerStatement"; +} + +export interface WithStatement extends Node, HasSpan { + type: "WithStatement"; + + object: Expression; + body: Statement; +} + +export interface ReturnStatement extends Node, HasSpan { + type: "ReturnStatement"; + + argument: Expression; +} + +export interface LabeledStatement extends Node, HasSpan { + type: "LabeledStatement"; + + label: Identifier; + body: Statement; +} + +export interface BreakStatement extends Node, HasSpan { + type: "BreakStatement"; + + label: Identifier; +} + +export interface ContinueStatement extends Node, HasSpan { + type: "ContinueStatement"; + + label: Identifier; +} + +export interface IfStatement extends Node, HasSpan { + type: "IfStatement"; + + test: Expression; + consequent: Statement; + alternate?: Statement; +} + +export interface SwitchStatement extends Node, HasSpan { + type: "SwitchStatement"; + + discriminant: Expression; + cases: SwitchCase[]; +} + +export interface ThrowStatement extends Node, HasSpan { + type: "ThrowStatement"; + + argument: Expression; +} + +export interface TryStatement extends Node, HasSpan { + type: "TryStatement"; + + block: BlockStatement; + handler?: CatchClause; + finalizer: BlockStatement; +} + +export interface WhileStatement extends Node, HasSpan { + type: "WhileStatement"; + + test: Expression; + body: Statement; +} + +export interface DoWhileStatement extends Node, HasSpan { + type: "DoWhileStatement"; + + test: Expression; + body: Statement; +} + +export interface ForStatement extends Node, HasSpan { + type: "ForStatement"; + + init?: VariableDeclaration | Expression; + test?: Expression; + update?: Expression; + body: Statement; +} + +export interface ForInStatement extends Node, HasSpan { + type: "ForInStatement"; + + left: VariableDeclaration | Pattern; + right: Expression; + body: Statement; +} + +export interface ForOfStatement extends Node, HasSpan { + type: "ForOfStatement"; + + /** + * Span of the await token. + * + * es2018 for-await-of statements, e.g., `for await (const x of xs) {` + */ + await: Span; + left: VariableDeclaration | Pattern; + right: Expression; + body: Statement; +} + +export interface SwitchCase extends Node, HasSpan { + type: "SwitchCase"; + + /** + * Undefined for default case + */ + test?: Expression; + consequent: Statement[]; +} + +export interface CatchClause extends Node, HasSpan { + type: "CatchClause"; + + /** + * The param is `undefined` if the catch binding is omitted. E.g., `try { foo() } catch {}` + */ + param: Pattern; + body: BlockStatement; +} + +export interface TsTypeAnnotation extends Node, HasSpan { + type: "TsTypeAnnotation"; + + typeAnnotation: TsType; +} + +export interface TsTypeParameterDeclaration extends Node, HasSpan { + type: "TsTypeParameterDeclaration"; + + parameters: TsTypeParameter[]; +} + +export interface TsTypeParameter extends Node, HasSpan { + type: "TsTypeParameter"; + + name: Identifier; + constraint: TsType; + default: TsType; +} + +export interface TsTypeParameterInstantiation extends Node, HasSpan { + type: "TsTypeParameterInstantiation"; + + params: TsType[]; +} + +export interface TsTypeCastExpression extends Node, HasSpan { + type: "TsTypeCastExpression"; + + expression: Expression; + typeAnnotation: TsTypeAnnotation; +} + +export interface TsParameterProperty extends Node, HasSpan, HasDecorator { + type: "TsParameterProperty"; + + accessibility?: Accessibility; + readonly: boolean; + param: TsParameterPropertyParameter; +} + +export type TsParameterPropertyParameter = Identifier | AssignmentPattern; + +export interface TsQualifiedName extends Node { + type: "TsQualifiedName"; + + left: TsEntityName; + right: Identifier; +} + +export type TsEntityName = TsQualifiedName | Identifier; + +export type TsSignatureDeclaration = + | TsCallSignatureDeclaration + | TsConstructSignatureDeclaration + | TsMethodSignature + | TsFunctionType + | TsConstructorType; + +export type TsTypeElement = + | TsCallSignatureDeclaration + | TsConstructSignatureDeclaration + | TsPropertySignature + | TsMethodSignature + | TsIndexSignature; + +export interface TsCallSignatureDeclaration extends Node, HasSpan { + type: "TsCallSignatureDeclaration"; + + params: TsFnParameter[]; + typeAnnotation: TsTypeAnnotation; + typeParams: TsTypeParameterDeclaration; +} + +export interface TsConstructSignatureDeclaration extends Node, HasSpan { + type: "TsConstructSignatureDeclaration"; + + params: TsFnParameter[]; + typeAnnotation: TsTypeAnnotation; + typeParams: TsTypeParameterDeclaration; +} + +export interface TsPropertySignature extends Node, HasSpan { + type: "TsPropertySignature"; + + readonly: boolean; + key: Expression; + computed: boolean; + optional: boolean; + + init: Expression; + params: TsFnParameter[]; + + typeAnnotation?: TsTypeAnnotation; + typeParams: TsTypeParameterDeclaration; +} + +export interface TsMethodSignature extends Node, HasSpan { + type: "TsMethodSignature"; + + readonly: boolean; + key: Expression; + computed: boolean; + optional: boolean; + params: TsFnParameter[]; + + typeAnnotation: TsTypeAnnotation; + typeParams: TsTypeParameterDeclaration; +} + +export interface TsIndexSignature extends Node, HasSpan { + type: "TsIndexSignature"; + + readonly: boolean; + params: TsFnParameter[]; + + typeAnnotation?: TsTypeAnnotation; +} + +export type TsType = + | TsKeywordType + | TsThisType + | TsFnOrConstructorType + | TsTypeReference + | TsTypeQuery + | TsTypeLiteral + | TsArrayType + | TsTupleType + | TsOptionalType + | TsRestType + | TsUnionOrIntersectionType + | TsConditionalType + | TsInferType + | TsParenthesizedType + | TsTypeOperator + | TsIndexedAccessType + | TsMappedType + | TsLiteralType + | TsImportType + | TsTypePredicate; + +export type TsFnOrConstructorType = TsFunctionType | TsConstructorType; + +export interface TsKeywordType extends Node, HasSpan { + type: "TsKeywordType"; + + kind: TsKeywordTypeKind; +} + +export type TsKeywordTypeKind = + | "any" + | "unknown" + | "number" + | "object" + | "boolean" + | "bigint" + | "string" + | "symbol" + | "void" + | "undefined" + | "null" + | "never"; + +export interface TsThisType extends Node, HasSpan { + type: "TsThisType"; +} + +export type TsFnParameter = Identifier | RestElement | ObjectPattern; + +export interface TsFunctionType extends Node, HasSpan { + type: "TsFunctionType"; + + typeParams: TsTypeParameterDeclaration; + typeAnnotation: TsTypeAnnotation; +} + +export interface TsConstructorType extends Node, HasSpan { + type: "TsConstructorType"; + + params: TsFnParameter[]; + + typeParams: TsTypeParameterDeclaration; + typeAnnotation: TsTypeAnnotation; +} + +export interface TsTypeReference extends Node, HasSpan { + type: "TsTypeReference"; + + typeName: TsEntityName; + typeParams: TsTypeParameterInstantiation; +} + +export interface TsTypePredicate extends Node, HasSpan { + type: "TsTypePredicate"; + + asserts: boolean; + + paramName: TsThisTypeOrIdent; + typeAnnotation: TsTypeAnnotation; +} + +export type TsThisTypeOrIdent = TsThisType | Identifier; + +export interface TsImportType extends Node, HasSpan { + argument: StringLiteral; + qualifier?: TsEntityName; + typeArguments?: TsTypeParameterInstantiation; +} + +/** + * `typeof` operator + */ +export interface TsTypeQuery extends Node, HasSpan { + type: "TsTypeQuery"; + + exprName: TsTypeQueryExpr; +} + +export type TsTypeQueryExpr = TsEntityName | TsImportType; + +export interface TsTypeLiteral extends Node, HasSpan { + type: "TsTypeLiteral"; + + members: TsTypeElement[]; +} + +export interface TsArrayType extends Node, HasSpan { + type: "TsArrayType"; + + elemType: TsType; +} + +export interface TsTupleType extends Node, HasSpan { + type: "TsTupleType"; + + elemTypes: TsType[]; +} + +export interface TsOptionalType extends Node, HasSpan { + type: "TsOptionalType"; + + typeAnnotation: TsType; +} + +export interface TsRestType extends Node, HasSpan { + type: "TsRestType"; + + typeAnnotation: TsType; +} + +export type TsUnionOrIntersectionType = TsUnionType | TsIntersectionType; + +export interface TsUnionType extends Node, HasSpan { + type: "TsUnionType"; + + types: TsType[]; +} + +export interface TsIntersectionType extends Node, HasSpan { + type: "TsIntersectionType"; + + types: TsType[]; +} + +export interface TsConditionalType extends Node, HasSpan { + type: "TsConditionalType"; + + checkType: TsType; + extendsType: TsType; + trueType: TsType; + falseType: TsType; +} + +export interface TsInferType extends Node, HasSpan { + type: "TsInferType"; + + typeParam: TsTypeParameter; +} + +export interface TsParenthesizedType extends Node, HasSpan { + type: "TsParenthesizedType"; + + typeAnnotation: TsType; +} + +export interface TsTypeOperator extends Node, HasSpan { + type: "TsTypeOperator"; + + op: TsTypeOperatorOp; + typeAnnotation: TsType; +} + +export type TsTypeOperatorOp = "keyof" | "unique"; + +export interface TsIndexedAccessType extends Node, HasSpan { + type: "TsIndexedAccessType"; + + objectType: TsType; + indexType: TsType; +} + +export type TruePlusMinus = true | "+" | "-"; + +export interface TsMappedType extends Node, HasSpan { + type: "TsMappedType"; + + readonly: TruePlusMinus; + typeParam: TsTypeParameter; + optional: TruePlusMinus; + typeAnnotation: TsType; +} + +export interface TsLiteralType extends Node, HasSpan { + type: "TsLiteralType"; + + literal: TsLiteral; +} + +export type TsLiteral = NumericLiteral | StringLiteral | BooleanLiteral | TemplateLiteral; + +// // ================ +// // TypeScript declarations +// // ================ + +export interface TsInterfaceDeclaration extends Node, HasSpan { + type: "TsInterfaceDeclaration"; + + id: Identifier; + declare: boolean; + typeParams?: TsTypeParameterDeclaration; + extends: TsExpressionWithTypeArguments[]; + body: TsInterfaceBody; +} + +export interface TsInterfaceBody extends Node, HasSpan { + type: "TsInterfaceBody"; + + body: TsTypeElement[]; +} + +export interface TsExpressionWithTypeArguments extends Node, HasSpan { + type: "TsExpressionWithTypeArguments"; + + expression: TsEntityName; + typeArguments?: TsTypeParameterInstantiation; +} + +export interface TsTypeAliasDeclaration extends Node, HasSpan { + type: "TsTypeAliasDeclaration"; + + declare: boolean; + id: Identifier; + typeParams?: TsTypeParameterDeclaration; + typeAnnotation: TsType; +} + +export interface TsEnumDeclaration extends Node, HasSpan { + type: "TsEnumDeclaration"; + + declare: boolean; + is_const: boolean; + id: Identifier; + member: TsEnumMember[]; +} + +export interface TsEnumMember extends Node, HasSpan { + type: "TsEnumMember"; + + id: TsEnumMemberId; + init?: Expression; +} + +export type TsEnumMemberId = Identifier | StringLiteral; + +export interface TsModuleDeclaration extends Node, HasSpan { + type: "TsModuleDeclaration"; + + declare: boolean; + global: boolean; + id: TsModuleName; + body?: TsNamespaceBody; +} + +/** + * `namespace A.B { }` is a namespace named `A` with another TsNamespaceDecl as its body. + */ +export type TsNamespaceBody = TsModuleBlock | TsNamespaceDeclaration; + +export interface TsModuleBlock extends Node, HasSpan { + type: "TsModuleBlock"; + + body: ModuleItem[]; +} + +export interface TsNamespaceDeclaration extends Node, HasSpan { + type: "TsNamespaceDeclaration"; + + declare: boolean; + global: boolean; + id: Identifier; + body: TsNamespaceBody; +} + +export type TsModuleName = Identifier | StringLiteral; + +export interface TsImportEqualsDeclaration extends Node, HasSpan { + type: "TsImportEqualsDeclaration"; + + declare: boolean; + is_export: boolean; + id: Identifier; + moduleRef: TsModuleReference; +} + +export type TsModuleReference = TsEntityName | TsExternalModuleReference; + +export interface TsExternalModuleReference extends Node, HasSpan { + type: "TsExternalModuleReference"; + + expression: Expression; +} + +export interface TsExportAssignment extends Node, HasSpan { + type: "TsExportAssignment"; + + expression: Expression; +} + +export interface TsNamespaceExportDeclaration extends Node, HasSpan { + type: "TsNamespaceExportDeclaration"; + + id: Identifier; +} + +export interface TsAsExpression extends ExpressionBase { + type: "TsAsExpression"; + + expression: Expression; + typeAnnotation: TsType; +} + +export interface TsTypeAssertion extends ExpressionBase { + type: "TsTypeAssertion"; + + expression: Expression; + typeAnnotation: TsType; +} + +export interface TsNonNullExpression extends ExpressionBase { + type: "TsNonNullExpression"; + + expression: Expression; +} + +export type Accessibility = "public" | "protected" | "private"; + +export interface Invalid extends Node, HasSpan { + type: "Invalid"; +} diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs index ae83bfdcc5be06..4dfd33cfd7111a 100644 --- a/cli/ops/runtime_compiler.rs +++ b/cli/ops/runtime_compiler.rs @@ -94,7 +94,6 @@ struct ParseArgs { options: Option, } -// TODO(divy-work): Should we take swc parse options? fn op_parse( state: &State, args: Value, diff --git a/cli/rt/40_compiler_api.js b/cli/rt/40_compiler_api.js index 56a7b60c2b4641..b19540fde464ac 100644 --- a/cli/rt/40_compiler_api.js +++ b/cli/rt/40_compiler_api.js @@ -26,13 +26,12 @@ : `./${specifier}`; } - // TODO(divy-work): Use AST type interface from swc as return type? - function ast(source, options = {}) { + async function ast(source, options) { util.log("Deno.ast", { source, options }); const payload = { source, }; - if (Object.keys(options) > 0) payload.options = options; + if (options) payload.options = options; return opAst(payload); } From d3d55e75a6fce6499b6c9d97706f9da8df963db7 Mon Sep 17 00:00:00 2001 From: divy-work Date: Tue, 28 Jul 2020 13:49:14 +0530 Subject: [PATCH 12/24] fix: eslint --- cli/rt/40_compiler_api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/rt/40_compiler_api.js b/cli/rt/40_compiler_api.js index b19540fde464ac..5d486731063fe8 100644 --- a/cli/rt/40_compiler_api.js +++ b/cli/rt/40_compiler_api.js @@ -26,7 +26,7 @@ : `./${specifier}`; } - async function ast(source, options) { + function ast(source, options) { util.log("Deno.ast", { source, options }); const payload = { source, From 7bb5a1486261797d3761f85a6c5e0036ce4d6aa8 Mon Sep 17 00:00:00 2001 From: divy-work Date: Tue, 28 Jul 2020 13:52:53 +0530 Subject: [PATCH 13/24] fix: clippy (again) --- cli/swc_util.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/swc_util.rs b/cli/swc_util.rs index dde78b9b9d0c00..804b1cadfea3cf 100644 --- a/cli/swc_util.rs +++ b/cli/swc_util.rs @@ -203,7 +203,8 @@ impl AstParser { handler: &self.handler, }; - let parse_options = options.unwrap_or(ParseOptions::default(media_type)); + let parse_options = + options.unwrap_or_else(|| ParseOptions::default(media_type)); let lexer = Lexer::new( session, From 85a8c72909bcaeedecaef21b0e6607c5b38f9d9d Mon Sep 17 00:00:00 2001 From: divy-work Date: Tue, 28 Jul 2020 14:09:31 +0530 Subject: [PATCH 14/24] dts: reference path to swc types --- cli/dts/lib.deno.unstable.d.ts | 2 +- cli/dts/{lib.swc.d.ts => swc.d.ts} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename cli/dts/{lib.swc.d.ts => swc.d.ts} (100%) diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index cdca0cbecb1eaa..2ce487b269558e 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -2,7 +2,7 @@ /// /// -/// +/// declare namespace Deno { /** diff --git a/cli/dts/lib.swc.d.ts b/cli/dts/swc.d.ts similarity index 100% rename from cli/dts/lib.swc.d.ts rename to cli/dts/swc.d.ts From 20f2372c3061c5796e0b7e20a45297c08b0ed217 Mon Sep 17 00:00:00 2001 From: divy-work Date: Tue, 28 Jul 2020 14:38:27 +0530 Subject: [PATCH 15/24] fix: swc.d.ts to op_assert --- cli/op_fetch_asset.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/op_fetch_asset.rs b/cli/op_fetch_asset.rs index d89ae20b39c777..2942bd8a367e20 100644 --- a/cli/op_fetch_asset.rs +++ b/cli/op_fetch_asset.rs @@ -20,6 +20,7 @@ fn get_asset(name: &str) -> Option<&'static str> { "system_loader_es5.js" => Some(include_str!("system_loader_es5.js")), "bootstrap.ts" => Some("console.log(\"hello deno\");"), "typescript.d.ts" => inc!("typescript.d.ts"), + "swc.d.ts" => inc!("swc.d.ts"), "lib.dom.d.ts" => inc!("lib.dom.d.ts"), "lib.dom.iterable.d.ts" => inc!("lib.dom.iterable.d.ts"), "lib.es5.d.ts" => inc!("lib.es5.d.ts"), From 76145065d101106f1b257fafcd8452bf61ad5335 Mon Sep 17 00:00:00 2001 From: divy-work Date: Tue, 28 Jul 2020 15:13:07 +0530 Subject: [PATCH 16/24] fix: declare type --- cli/dts/swc.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/dts/swc.d.ts b/cli/dts/swc.d.ts index 9d3ee90ac8edc1..583aa2b1193073 100644 --- a/cli/dts/swc.d.ts +++ b/cli/dts/swc.d.ts @@ -755,7 +755,7 @@ interface HasInterpreter { interpreter: string; } -export type Program = Module | Script; +declare type Program = Module | Script; export interface Module extends Node, HasSpan, HasInterpreter { type: "Module"; From 780f0eaef72f2318cb316f72a91f069911f18a36 Mon Sep 17 00:00:00 2001 From: divy-work Date: Tue, 28 Jul 2020 15:24:57 +0530 Subject: [PATCH 17/24] fix: maybe --- cli/dts/lib.deno.unstable.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index 2ce487b269558e..8c093bd430fa87 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -2,7 +2,7 @@ /// /// -/// +/// declare namespace Deno { /** From 3ef812760cfda0ec9d297d1deba9d94aafd4459d Mon Sep 17 00:00:00 2001 From: divy-work Date: Tue, 28 Jul 2020 16:00:14 +0530 Subject: [PATCH 18/24] add swc.d.ts to build.rs --- cli/build.rs | 1 + cli/dts/lib.deno.unstable.d.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/cli/build.rs b/cli/build.rs index 777e7455860c0e..7dcf0e2858adbf 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -58,6 +58,7 @@ fn create_compiler_snapshot( "lib.deno.unstable.d.ts".to_string(), cwd.join("dts/lib.deno.unstable.d.ts"), ); + custom_libs.insert("swc.d.ts".to_string(), cwd.join("dts/swc.d.ts")); runtime_isolate.register_op( "op_fetch_asset", op_fetch_asset::op_fetch_asset(custom_libs), diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index 8c093bd430fa87..5694c84bcc7b84 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -471,6 +471,7 @@ declare namespace Deno { */ export function ast( source: string, + options: object, ): Promise; /** **UNSTABLE**: new API, yet to be vetted. From 0e44fb1d3e856defe6b3bd0498ee80a9f19f6891 Mon Sep 17 00:00:00 2001 From: divy-work Date: Tue, 28 Jul 2020 16:08:06 +0530 Subject: [PATCH 19/24] rever back to not using parse options --- cli/doc/parser.rs | 1 - cli/dts/lib.deno.unstable.d.ts | 1 - cli/ops/runtime_compiler.rs | 4 +- cli/rt/40_compiler_api.js | 5 +- cli/swc_util.rs | 17 +----- cli/tsc.rs | 102 ++++++++++++++++----------------- 6 files changed, 54 insertions(+), 76 deletions(-) diff --git a/cli/doc/parser.rs b/cli/doc/parser.rs index 2149e4d296179d..59fa2b7342a763 100644 --- a/cli/doc/parser.rs +++ b/cli/doc/parser.rs @@ -66,7 +66,6 @@ impl DocParser { file_name, media_type, source_code, - None, |parse_result| { let module = parse_result?; let doc_entries = diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index 5694c84bcc7b84..8c093bd430fa87 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -471,7 +471,6 @@ declare namespace Deno { */ export function ast( source: string, - options: object, ): Promise; /** **UNSTABLE**: new API, yet to be vetted. diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs index 4dfd33cfd7111a..33dbf78112e31c 100644 --- a/cli/ops/runtime_compiler.rs +++ b/cli/ops/runtime_compiler.rs @@ -3,7 +3,7 @@ use super::dispatch_json::{Deserialize, JsonOp, Value}; use crate::futures::FutureExt; use crate::op_error::OpError; use crate::state::State; -use crate::swc_util::{AstParser, ParseOptions}; +use crate::swc_util::AstParser; use crate::tsc::runtime_bundle; use crate::tsc::runtime_compile; use crate::tsc::runtime_transpile; @@ -91,7 +91,6 @@ fn op_transpile( #[derive(Deserialize, Debug)] struct ParseArgs { source: String, - options: Option, } fn op_parse( @@ -116,7 +115,6 @@ fn op_parse( &module_specifier.to_string(), out.media_type, &src, - args.options, |parse_result| { let module = parse_result.unwrap(); Ok(serde_json::to_value(module)?) diff --git a/cli/rt/40_compiler_api.js b/cli/rt/40_compiler_api.js index 5d486731063fe8..855659619cc5b5 100644 --- a/cli/rt/40_compiler_api.js +++ b/cli/rt/40_compiler_api.js @@ -26,12 +26,11 @@ : `./${specifier}`; } - function ast(source, options) { - util.log("Deno.ast", { source, options }); + function ast(source) { + util.log("Deno.ast", { source }); const payload = { source, }; - if (options) payload.options = options; return opAst(payload); } diff --git a/cli/swc_util.rs b/cli/swc_util.rs index 804b1cadfea3cf..929a21aa425159 100644 --- a/cli/swc_util.rs +++ b/cli/swc_util.rs @@ -26,15 +26,6 @@ use std::fmt; use std::sync::Arc; use std::sync::RwLock; -#[derive(Debug, Default, Clone, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ParseOptions { - #[serde(flatten)] - pub syntax: Syntax, - #[serde(default)] - pub target: JscTarget, -} - impl ParseOptions { pub fn default(media_type: MediaType) -> Self { ParseOptions { @@ -186,7 +177,6 @@ impl AstParser { file_name: &str, media_type: MediaType, source_code: &str, - options: Option, callback: F, ) -> R where @@ -203,13 +193,12 @@ impl AstParser { handler: &self.handler, }; - let parse_options = - options.unwrap_or_else(|| ParseOptions::default(media_type)); + let syntax = get_syntax_for_media_type(media_type); let lexer = Lexer::new( session, - parse_options.syntax, - parse_options.target, + syntax, + JscTarget::Es2019, SourceFileInput::from(&*swc_source_file), Some(&self.comments), ); diff --git a/cli/tsc.rs b/cli/tsc.rs index 606d708d51a59a..2ce498e3f1d543 100644 --- a/cli/tsc.rs +++ b/cli/tsc.rs @@ -1419,67 +1419,61 @@ pub fn pre_process_file( analyze_dynamic_imports: bool, ) -> Result<(Vec, Vec), SwcDiagnosticBuffer> { let parser = AstParser::new(); - parser.parse_module( - file_name, - media_type, - source_code, - None, - |parse_result| { - let module = parse_result?; - let mut collector = DependencyVisitor { - dependencies: vec![], - }; - let module_span = module.span; - collector.visit_module(&module, &module); + parser.parse_module(file_name, media_type, source_code, |parse_result| { + let module = parse_result?; + let mut collector = DependencyVisitor { + dependencies: vec![], + }; + let module_span = module.span; + collector.visit_module(&module, &module); - let dependency_descriptors = collector.dependencies; + let dependency_descriptors = collector.dependencies; - // for each import check if there's relevant @deno-types directive - let imports = dependency_descriptors - .iter() - .filter(|desc| { - if analyze_dynamic_imports { - return true; - } + // for each import check if there's relevant @deno-types directive + let imports = dependency_descriptors + .iter() + .filter(|desc| { + if analyze_dynamic_imports { + return true; + } - desc.kind != DependencyKind::DynamicImport - }) - .map(|desc| { - let location = parser.get_span_location(desc.span); - let deno_types = get_deno_types(&parser, desc.span); - ImportDesc { - specifier: desc.specifier.to_string(), - deno_types, - location: location.into(), - } - }) - .collect(); + desc.kind != DependencyKind::DynamicImport + }) + .map(|desc| { + let location = parser.get_span_location(desc.span); + let deno_types = get_deno_types(&parser, desc.span); + ImportDesc { + specifier: desc.specifier.to_string(), + deno_types, + location: location.into(), + } + }) + .collect(); - // analyze comment from beginning of the file and find TS directives - let comments = parser - .comments - .take_leading_comments(module_span.lo()) - .unwrap_or_else(Vec::new); + // analyze comment from beginning of the file and find TS directives + let comments = parser + .comments + .take_leading_comments(module_span.lo()) + .unwrap_or_else(Vec::new); - let mut references = vec![]; - for comment in comments { - if comment.kind != CommentKind::Line { - continue; - } + let mut references = vec![]; + for comment in comments { + if comment.kind != CommentKind::Line { + continue; + } - let text = comment.text.to_string(); - if let Some((kind, specifier)) = parse_ts_reference(text.trim()) { - let location = parser.get_span_location(comment.span); - references.push(TsReferenceDesc { - kind, - specifier, - location: location.into(), - }); - } + let text = comment.text.to_string(); + if let Some((kind, specifier)) = parse_ts_reference(text.trim()) { + let location = parser.get_span_location(comment.span); + references.push(TsReferenceDesc { + kind, + specifier, + location: location.into(), + }); } - Ok((imports, references)) - }, - ) + } + Ok((imports, references)) + }) } fn get_deno_types(parser: &AstParser, span: Span) -> Option { From a96cddc671baa6348f3538448b38419e97aebb9e Mon Sep 17 00:00:00 2001 From: divy-work Date: Tue, 28 Jul 2020 16:10:12 +0530 Subject: [PATCH 20/24] remove traces --- cli/swc_util.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/cli/swc_util.rs b/cli/swc_util.rs index 929a21aa425159..906d9f9bddab71 100644 --- a/cli/swc_util.rs +++ b/cli/swc_util.rs @@ -20,21 +20,11 @@ use crate::swc_ecma_parser::Session; use crate::swc_ecma_parser::SourceFileInput; use crate::swc_ecma_parser::Syntax; use crate::swc_ecma_parser::TsConfig; -use serde::{Deserialize, Serialize}; use std::error::Error; use std::fmt; use std::sync::Arc; use std::sync::RwLock; -impl ParseOptions { - pub fn default(media_type: MediaType) -> Self { - ParseOptions { - syntax: get_syntax_for_media_type(media_type), - target: JscTarget::Es2019, - } - } -} - fn get_default_es_config() -> EsConfig { let mut config = EsConfig::default(); config.num_sep = true; From 4f8c2a8ea992ab9b625e1683be245084acd3f485 Mon Sep 17 00:00:00 2001 From: divy-work Date: Tue, 28 Jul 2020 16:31:21 +0530 Subject: [PATCH 21/24] feat: add op_error impl and add swc.d.ts to compiler --- cli/op_error.rs | 19 +++++++++++++++++++ cli/ops/runtime_compiler.rs | 2 +- cli/tsc/99_main_compiler.js | 6 +++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/cli/op_error.rs b/cli/op_error.rs index 73f7640a8e301e..e64776f5824412 100644 --- a/cli/op_error.rs +++ b/cli/op_error.rs @@ -15,6 +15,7 @@ //! exceptions. use crate::import_map::ImportMapError; +use crate::swc_util; use deno_core::ErrBox; use deno_core::ModuleResolutionError; use rustyline::error::ReadlineError; @@ -212,6 +213,24 @@ impl From<&io::Error> for OpError { } } +impl From<&swc_util::SwcDiagnosticBuffer> for OpError { + fn from(error: &swc_util::SwcDiagnosticBuffer) -> Self { + Self { + kind: ErrorKind::InvalidData, + msg: error.diagnostics.join(","), + } + } +} + +impl From for OpError { + fn from(error: swc_util::SwcDiagnosticBuffer) -> Self { + Self { + kind: ErrorKind::InvalidData, + msg: error.diagnostics.join(","), + } + } +} + impl From for OpError { fn from(error: url::ParseError) -> Self { OpError::from(&error) diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs index 33dbf78112e31c..2417373c07fc2e 100644 --- a/cli/ops/runtime_compiler.rs +++ b/cli/ops/runtime_compiler.rs @@ -116,7 +116,7 @@ fn op_parse( out.media_type, &src, |parse_result| { - let module = parse_result.unwrap(); + let module = parse_result?; Ok(serde_json::to_value(module)?) }, ) diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index 04638d60c3aaba..bd53000f3ccb45 100644 --- a/cli/tsc/99_main_compiler.js +++ b/cli/tsc/99_main_compiler.js @@ -808,7 +808,7 @@ delete Object.prototype.__proto__; ts.libMap.set("deno.worker", "lib.deno.worker.d.ts"); ts.libMap.set("deno.shared_globals", "lib.deno.shared_globals.d.ts"); ts.libMap.set("deno.unstable", "lib.deno.unstable.d.ts"); - + ts.libMap.set("swc", "swc.d.ts"); // this pre-populates the cache at snapshot time of our library files, so they // are available in the future when needed. SNAPSHOT_HOST.getSourceFile( @@ -831,6 +831,10 @@ delete Object.prototype.__proto__; `${ASSETS}/lib.deno.unstable.d.ts`, ts.ScriptTarget.ESNext, ); + SNAPSHOT_HOST.getSourceFile( + `${ASSETS}/swc.d.ts`, + ts.ScriptTarget.ESNext, + ); // We never use this program; it's only created // during snapshotting to hydrate and populate From 40567339a2c32232f7a68e6d91311b2da39bc968 Mon Sep 17 00:00:00 2001 From: divy-work Date: Tue, 28 Jul 2020 16:41:37 +0530 Subject: [PATCH 22/24] fix: clippy --- cli/swc_util.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cli/swc_util.rs b/cli/swc_util.rs index 906d9f9bddab71..0c39bb5ac21f1d 100644 --- a/cli/swc_util.rs +++ b/cli/swc_util.rs @@ -140,6 +140,12 @@ pub struct AstParser { pub globals: Globals, } +impl Default for AstParser { + fn default() -> Self { + Self::new() + } +} + impl AstParser { pub fn new() -> Self { let buffered_error = SwcErrorBuffer::default(); From 1dcceeefeb35e4174069da0871a994bf441024c3 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Tue, 28 Jul 2020 22:21:33 +0530 Subject: [PATCH 23/24] fix: export declare type --- cli/dts/swc.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/dts/swc.d.ts b/cli/dts/swc.d.ts index 583aa2b1193073..4591edb0e9ac0f 100644 --- a/cli/dts/swc.d.ts +++ b/cli/dts/swc.d.ts @@ -755,15 +755,15 @@ interface HasInterpreter { interpreter: string; } -declare type Program = Module | Script; +export declare type Program = Module | Script; -export interface Module extends Node, HasSpan, HasInterpreter { +export declare interface Module extends Node, HasSpan, HasInterpreter { type: "Module"; body: ModuleItem[]; } -export interface Script extends Node, HasSpan, HasInterpreter { +export declare interface Script extends Node, HasSpan, HasInterpreter { type: "Script"; body: Statement[]; From 0f9d80906a9015fbf8efed96a7929e53b36a536a Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Tue, 28 Jul 2020 22:57:34 +0530 Subject: [PATCH 24/24] use Module instead of Program --- cli/dts/lib.deno.unstable.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index 8c093bd430fa87..3b43bec1f6d187 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -471,7 +471,7 @@ declare namespace Deno { */ export function ast( source: string, - ): Promise; + ): Promise; /** **UNSTABLE**: new API, yet to be vetted. *