diff options
Diffstat (limited to 'cli/doc')
-rw-r--r-- | cli/doc/class.rs | 23 | ||||
-rw-r--r-- | cli/doc/display.rs | 19 | ||||
-rw-r--r-- | cli/doc/enum.rs | 5 | ||||
-rw-r--r-- | cli/doc/function.rs | 5 | ||||
-rw-r--r-- | cli/doc/interface.rs | 11 | ||||
-rw-r--r-- | cli/doc/module.rs | 7 | ||||
-rw-r--r-- | cli/doc/namespace.rs | 11 | ||||
-rw-r--r-- | cli/doc/node.rs | 3 | ||||
-rw-r--r-- | cli/doc/params.rs | 23 | ||||
-rw-r--r-- | cli/doc/parser.rs | 53 | ||||
-rw-r--r-- | cli/doc/printer.rs | 15 | ||||
-rw-r--r-- | cli/doc/ts_type.rs | 25 | ||||
-rw-r--r-- | cli/doc/ts_type_param.rs | 4 | ||||
-rw-r--r-- | cli/doc/type_alias.rs | 3 | ||||
-rw-r--r-- | cli/doc/variable.rs | 9 |
15 files changed, 100 insertions, 116 deletions
diff --git a/cli/doc/class.rs b/cli/doc/class.rs index d8fa29ded..292aa4b97 100644 --- a/cli/doc/class.rs +++ b/cli/doc/class.rs @@ -5,9 +5,8 @@ use crate::doc::display::{ display_method, display_optional, display_readonly, display_static, SliceDisplayer, }; -use crate::swc_common::Spanned; -use crate::swc_ecma_ast; use serde::Serialize; +use swc_common::Spanned; use super::function::function_to_function_def; use super::function::FunctionDef; @@ -31,7 +30,7 @@ use std::fmt::{Display, Formatter, Result as FmtResult}; #[serde(rename_all = "camelCase")] pub struct ClassConstructorDef { pub js_doc: Option<String>, - pub accessibility: Option<swc_ecma_ast::Accessibility>, + pub accessibility: Option<swc_ecmascript::ast::Accessibility>, pub name: String, pub params: Vec<ParamDef>, pub location: Location, @@ -55,7 +54,7 @@ pub struct ClassPropertyDef { pub js_doc: Option<String>, pub ts_type: Option<TsTypeDef>, pub readonly: bool, - pub accessibility: Option<swc_ecma_ast::Accessibility>, + pub accessibility: Option<swc_ecmascript::ast::Accessibility>, pub optional: bool, pub is_abstract: bool, pub is_static: bool, @@ -109,12 +108,12 @@ impl Display for ClassIndexSignatureDef { #[serde(rename_all = "camelCase")] pub struct ClassMethodDef { pub js_doc: Option<String>, - pub accessibility: Option<swc_ecma_ast::Accessibility>, + pub accessibility: Option<swc_ecmascript::ast::Accessibility>, pub optional: bool, pub is_abstract: bool, pub is_static: bool, pub name: String, - pub kind: swc_ecma_ast::MethodKind, + pub kind: swc_ecmascript::ast::MethodKind, pub function_def: FunctionDef, pub location: Location, } @@ -158,7 +157,7 @@ pub struct ClassDef { pub fn class_to_class_def( doc_parser: &DocParser, - class: &swc_ecma_ast::Class, + class: &swc_ecmascript::ast::Class, ) -> ClassDef { let mut constructors = vec![]; let mut methods = vec![]; @@ -167,7 +166,7 @@ pub fn class_to_class_def( let extends: Option<String> = match &class.super_class { Some(boxed) => { - use crate::swc_ecma_ast::Expr; + use swc_ecmascript::ast::Expr; let expr: &Expr = &**boxed; match expr { Expr::Ident(ident) => Some(ident.sym.to_string()), @@ -184,7 +183,7 @@ pub fn class_to_class_def( .collect::<Vec<TsTypeDef>>(); for member in &class.body { - use crate::swc_ecma_ast::ClassMember::*; + use swc_ecmascript::ast::ClassMember::*; match member { Constructor(ctor) => { @@ -197,7 +196,7 @@ pub fn class_to_class_def( let mut params = vec![]; for param in &ctor.params { - use crate::swc_ecma_ast::ParamOrTsParamProp::*; + use swc_ecmascript::ast::ParamOrTsParamProp::*; let param_def = match param { Param(param) => pat_to_param_def( @@ -205,7 +204,7 @@ pub fn class_to_class_def( Some(&doc_parser.ast_parser.source_map), ), TsParamProp(ts_param_prop) => { - use swc_ecma_ast::TsParamPropParam; + use swc_ecmascript::ast::TsParamPropParam; match &ts_param_prop.param { TsParamPropParam::Ident(ident) => ident_to_param_def( @@ -331,7 +330,7 @@ pub fn class_to_class_def( pub fn get_doc_for_class_decl( doc_parser: &DocParser, - class_decl: &swc_ecma_ast::ClassDecl, + class_decl: &swc_ecmascript::ast::ClassDecl, ) -> (String, ClassDef) { let class_name = class_decl.ident.sym.to_string(); let class_def = class_to_class_def(doc_parser, &class_decl.class); diff --git a/cli/doc/display.rs b/cli/doc/display.rs index 9da04363f..44ed62415 100644 --- a/cli/doc/display.rs +++ b/cli/doc/display.rs @@ -1,6 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use crate::colors; -use crate::swc_ecma_ast; use std::fmt::{Display, Formatter, Result}; pub(crate) struct Indent(pub i64); @@ -50,13 +49,13 @@ pub(crate) fn display_abstract(is_abstract: bool) -> impl Display { } pub(crate) fn display_accessibility( - accessibility: Option<swc_ecma_ast::Accessibility>, + accessibility: Option<swc_ecmascript::ast::Accessibility>, ) -> impl Display { colors::magenta( - match accessibility.unwrap_or(swc_ecma_ast::Accessibility::Public) { - swc_ecma_ast::Accessibility::Public => "", - swc_ecma_ast::Accessibility::Protected => "protected ", - swc_ecma_ast::Accessibility::Private => "private ", + match accessibility.unwrap_or(swc_ecmascript::ast::Accessibility::Public) { + swc_ecmascript::ast::Accessibility::Public => "", + swc_ecmascript::ast::Accessibility::Protected => "protected ", + swc_ecmascript::ast::Accessibility::Private => "private ", }, ) } @@ -69,10 +68,12 @@ pub(crate) fn display_generator(is_generator: bool) -> impl Display { colors::magenta(if is_generator { "*" } else { "" }) } -pub(crate) fn display_method(method: swc_ecma_ast::MethodKind) -> impl Display { +pub(crate) fn display_method( + method: swc_ecmascript::ast::MethodKind, +) -> impl Display { colors::magenta(match method { - swc_ecma_ast::MethodKind::Getter => "get ", - swc_ecma_ast::MethodKind::Setter => "set ", + swc_ecmascript::ast::MethodKind::Getter => "get ", + swc_ecmascript::ast::MethodKind::Setter => "set ", _ => "", }) } diff --git a/cli/doc/enum.rs b/cli/doc/enum.rs index bf561cf94..8161337ce 100644 --- a/cli/doc/enum.rs +++ b/cli/doc/enum.rs @@ -1,5 +1,4 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -use crate::swc_ecma_ast; use serde::Serialize; use super::parser::DocParser; @@ -18,13 +17,13 @@ pub struct EnumDef { pub fn get_doc_for_ts_enum_decl( _doc_parser: &DocParser, - enum_decl: &swc_ecma_ast::TsEnumDecl, + enum_decl: &swc_ecmascript::ast::TsEnumDecl, ) -> (String, EnumDef) { let enum_name = enum_decl.id.sym.to_string(); let mut members = vec![]; for enum_member in &enum_decl.members { - use crate::swc_ecma_ast::TsEnumMemberId::*; + use swc_ecmascript::ast::TsEnumMemberId::*; let member_name = match &enum_member.id { Ident(ident) => ident.sym.to_string(), diff --git a/cli/doc/function.rs b/cli/doc/function.rs index ede8bdbbd..ab6430ec6 100644 --- a/cli/doc/function.rs +++ b/cli/doc/function.rs @@ -6,7 +6,6 @@ use super::ts_type::TsTypeDef; use super::ts_type_param::maybe_type_param_decl_to_type_param_defs; use super::ts_type_param::TsTypeParamDef; use super::ParamDef; -use crate::swc_ecma_ast; use serde::Serialize; #[derive(Debug, Serialize, Clone)] @@ -22,7 +21,7 @@ pub struct FunctionDef { pub fn function_to_function_def( doc_parser: &DocParser, - function: &swc_ecma_ast::Function, + function: &swc_ecmascript::ast::Function, ) -> FunctionDef { let mut params = vec![]; @@ -51,7 +50,7 @@ pub fn function_to_function_def( pub fn get_doc_for_fn_decl( doc_parser: &DocParser, - fn_decl: &swc_ecma_ast::FnDecl, + fn_decl: &swc_ecmascript::ast::FnDecl, ) -> (String, FunctionDef) { let name = fn_decl.ident.sym.to_string(); let fn_def = function_to_function_def(&doc_parser, &fn_decl.function); diff --git a/cli/doc/interface.rs b/cli/doc/interface.rs index d3caa8748..3c72bac23 100644 --- a/cli/doc/interface.rs +++ b/cli/doc/interface.rs @@ -1,7 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use crate::colors; use crate::doc::display::{display_optional, display_readonly, SliceDisplayer}; -use crate::swc_ecma_ast; use serde::Serialize; use super::params::ts_fn_param_to_param_def; @@ -115,9 +114,9 @@ pub struct InterfaceDef { pub type_params: Vec<TsTypeParamDef>, } -pub fn expr_to_name(expr: &swc_ecma_ast::Expr) -> String { - use crate::swc_ecma_ast::Expr::*; - use crate::swc_ecma_ast::ExprOrSuper::*; +pub fn expr_to_name(expr: &swc_ecmascript::ast::Expr) -> String { + use swc_ecmascript::ast::Expr::*; + use swc_ecmascript::ast::ExprOrSuper::*; match expr { Ident(ident) => ident.sym.to_string(), @@ -135,7 +134,7 @@ pub fn expr_to_name(expr: &swc_ecma_ast::Expr) -> String { pub fn get_doc_for_ts_interface_decl( doc_parser: &DocParser, - interface_decl: &swc_ecma_ast::TsInterfaceDecl, + interface_decl: &swc_ecmascript::ast::TsInterfaceDecl, ) -> (String, InterfaceDef) { let interface_name = interface_decl.id.sym.to_string(); @@ -145,7 +144,7 @@ pub fn get_doc_for_ts_interface_decl( let mut index_signatures = vec![]; for type_element in &interface_decl.body.body { - use crate::swc_ecma_ast::TsTypeElement::*; + use swc_ecmascript::ast::TsTypeElement::*; match &type_element { TsMethodSignature(ts_method_sig) => { diff --git a/cli/doc/module.rs b/cli/doc/module.rs index 79b1b92be..74d5361eb 100644 --- a/cli/doc/module.rs +++ b/cli/doc/module.rs @@ -1,6 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -use crate::swc_common::Spanned; -use crate::swc_ecma_ast; +use swc_common::Spanned; use super::parser::DocParser; use super::DocNode; @@ -8,10 +7,10 @@ use super::DocNodeKind; pub fn get_doc_node_for_export_decl( doc_parser: &DocParser, - export_decl: &swc_ecma_ast::ExportDecl, + export_decl: &swc_ecmascript::ast::ExportDecl, ) -> DocNode { let export_span = export_decl.span(); - use crate::swc_ecma_ast::Decl; + use swc_ecmascript::ast::Decl; let js_doc = doc_parser.js_doc_for_span(export_span); let location = doc_parser.ast_parser.get_span_location(export_span).into(); diff --git a/cli/doc/namespace.rs b/cli/doc/namespace.rs index 6cbc619e8..35f9233fd 100644 --- a/cli/doc/namespace.rs +++ b/cli/doc/namespace.rs @@ -1,5 +1,4 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -use crate::swc_ecma_ast; use serde::Serialize; use super::parser::DocParser; @@ -13,7 +12,7 @@ pub struct NamespaceDef { pub fn get_doc_for_ts_namespace_decl( doc_parser: &DocParser, - ts_namespace_decl: &swc_ecma_ast::TsNamespaceDecl, + ts_namespace_decl: &swc_ecmascript::ast::TsNamespaceDecl, ) -> DocNode { let js_doc = doc_parser.js_doc_for_span(ts_namespace_decl.span); let location = doc_parser @@ -22,7 +21,7 @@ pub fn get_doc_for_ts_namespace_decl( .into(); let namespace_name = ts_namespace_decl.id.sym.to_string(); - use crate::swc_ecma_ast::TsNamespaceBody::*; + use swc_ecmascript::ast::TsNamespaceBody::*; let elements = match &*ts_namespace_decl.body { TsModuleBlock(ts_module_block) => { @@ -52,16 +51,16 @@ pub fn get_doc_for_ts_namespace_decl( pub fn get_doc_for_ts_module( doc_parser: &DocParser, - ts_module_decl: &swc_ecma_ast::TsModuleDecl, + ts_module_decl: &swc_ecmascript::ast::TsModuleDecl, ) -> (String, NamespaceDef) { - use crate::swc_ecma_ast::TsModuleName; + use swc_ecmascript::ast::TsModuleName; let namespace_name = match &ts_module_decl.id { TsModuleName::Ident(ident) => ident.sym.to_string(), TsModuleName::Str(str_) => str_.value.to_string(), }; let elements = if let Some(body) = &ts_module_decl.body { - use crate::swc_ecma_ast::TsNamespaceBody::*; + use swc_ecmascript::ast::TsNamespaceBody::*; match &body { TsModuleBlock(ts_module_block) => { diff --git a/cli/doc/node.rs b/cli/doc/node.rs index 690221ed0..4946924c6 100644 --- a/cli/doc/node.rs +++ b/cli/doc/node.rs @@ -1,5 +1,4 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -use crate::swc_common; use serde::Serialize; #[derive(Debug, PartialEq, Serialize, Clone)] @@ -23,7 +22,7 @@ pub struct Location { impl Into<Location> for swc_common::Loc { fn into(self) -> Location { - use crate::swc_common::FileName::*; + use swc_common::FileName::*; let filename = match &self.file.name { Real(path_buf) => path_buf.to_string_lossy().to_string(), diff --git a/cli/doc/params.rs b/cli/doc/params.rs index 3e7967c81..088a4e283 100644 --- a/cli/doc/params.rs +++ b/cli/doc/params.rs @@ -1,11 +1,10 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use super::display::{display_optional, SliceDisplayer}; use super::ts_type::{ts_type_ann_to_def, TsTypeDef}; -use crate::swc_common::SourceMap; -use crate::swc_ecma_ast; -use crate::swc_ecma_ast::{ObjectPatProp, Pat, TsFnParam}; use serde::Serialize; use std::fmt::{Display, Formatter, Result as FmtResult}; +use swc_common::SourceMap; +use swc_ecmascript::ast::{ObjectPatProp, Pat, TsFnParam}; #[derive(Debug, Serialize, Clone)] #[serde(rename_all = "camelCase")] @@ -146,7 +145,7 @@ impl Display for ObjectPatPropDef { } pub fn ident_to_param_def( - ident: &swc_ecma_ast::Ident, + ident: &swc_ecmascript::ast::Ident, _source_map: Option<&SourceMap>, ) -> ParamDef { let ts_type = ident.type_ann.as_ref().map(|rt| ts_type_ann_to_def(rt)); @@ -159,7 +158,7 @@ pub fn ident_to_param_def( } fn rest_pat_to_param_def( - rest_pat: &swc_ecma_ast::RestPat, + rest_pat: &swc_ecmascript::ast::RestPat, source_map: Option<&SourceMap>, ) -> ParamDef { let ts_type = rest_pat.type_ann.as_ref().map(|rt| ts_type_ann_to_def(rt)); @@ -190,7 +189,7 @@ fn object_pat_prop_to_def( } fn object_pat_to_param_def( - object_pat: &swc_ecma_ast::ObjectPat, + object_pat: &swc_ecmascript::ast::ObjectPat, source_map: Option<&SourceMap>, ) -> ParamDef { let props = object_pat @@ -211,7 +210,7 @@ fn object_pat_to_param_def( } fn array_pat_to_param_def( - array_pat: &swc_ecma_ast::ArrayPat, + array_pat: &swc_ecmascript::ast::ArrayPat, source_map: Option<&SourceMap>, ) -> ParamDef { let elements = array_pat @@ -229,7 +228,7 @@ fn array_pat_to_param_def( } pub fn assign_pat_to_param_def( - assign_pat: &swc_ecma_ast::AssignPat, + assign_pat: &swc_ecmascript::ast::AssignPat, source_map: Option<&SourceMap>, ) -> ParamDef { let ts_type = assign_pat @@ -245,7 +244,7 @@ pub fn assign_pat_to_param_def( } pub fn pat_to_param_def( - pat: &swc_ecma_ast::Pat, + pat: &swc_ecmascript::ast::Pat, source_map: Option<&SourceMap>, ) -> ParamDef { match pat { @@ -259,7 +258,7 @@ pub fn pat_to_param_def( } pub fn ts_fn_param_to_param_def( - ts_fn_param: &swc_ecma_ast::TsFnParam, + ts_fn_param: &swc_ecmascript::ast::TsFnParam, source_map: Option<&SourceMap>, ) -> ParamDef { match ts_fn_param { @@ -275,10 +274,10 @@ pub fn ts_fn_param_to_param_def( } pub fn prop_name_to_string( - prop_name: &swc_ecma_ast::PropName, + prop_name: &swc_ecmascript::ast::PropName, source_map: Option<&SourceMap>, ) -> String { - use crate::swc_ecma_ast::PropName; + use swc_ecmascript::ast::PropName; match prop_name { PropName::Ident(ident) => ident.sym.to_string(), PropName::Str(str_) => str_.value.to_string(), diff --git a/cli/doc/parser.rs b/cli/doc/parser.rs index 14e921237..e185e5bff 100644 --- a/cli/doc/parser.rs +++ b/cli/doc/parser.rs @@ -1,15 +1,14 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use crate::file_fetcher::map_file_extension; use crate::op_error::OpError; -use crate::swc_common::comments::CommentKind; -use crate::swc_common::Span; -use crate::swc_ecma_ast; -use crate::swc_ecma_ast::Decl; -use crate::swc_ecma_ast::DefaultDecl; -use crate::swc_ecma_ast::ModuleDecl; -use crate::swc_ecma_ast::Stmt; use crate::swc_util::AstParser; use crate::swc_util::SwcDiagnosticBuffer; +use swc_common::comments::CommentKind; +use swc_common::Span; +use swc_ecmascript::ast::Decl; +use swc_ecmascript::ast::DefaultDecl; +use swc_ecmascript::ast::ModuleDecl; +use swc_ecmascript::ast::Stmt; use deno_core::ErrBox; use deno_core::ModuleSpecifier; @@ -62,22 +61,18 @@ impl DocParser { source_code: &str, ) -> Result<ModuleDoc, SwcDiagnosticBuffer> { let media_type = map_file_extension(&PathBuf::from(file_name)); - self.ast_parser.parse_module( - file_name, - media_type, - source_code, - |parse_result| { - let module = parse_result?; - let doc_entries = - self.get_doc_nodes_for_module_body(module.body.clone()); - let reexports = self.get_reexports_for_module_body(module.body); - let module_doc = ModuleDoc { - definitions: doc_entries, - reexports, - }; - Ok(module_doc) - }, - ) + let parse_result = + self + .ast_parser + .parse_module(file_name, media_type, source_code); + let module = parse_result?; + let doc_entries = self.get_doc_nodes_for_module_body(module.body.clone()); + let reexports = self.get_reexports_for_module_body(module.body); + let module_doc = ModuleDoc { + definitions: doc_entries, + reexports, + }; + Ok(module_doc) } pub async fn parse(&self, file_name: &str) -> Result<Vec<DocNode>, ErrBox> { @@ -452,14 +447,14 @@ impl DocParser { pub fn get_reexports_for_module_body( &self, - module_body: Vec<swc_ecma_ast::ModuleItem>, + module_body: Vec<swc_ecmascript::ast::ModuleItem>, ) -> Vec<node::Reexport> { - use swc_ecma_ast::ExportSpecifier::*; + use swc_ecmascript::ast::ExportSpecifier::*; let mut reexports: Vec<node::Reexport> = vec![]; for node in module_body.iter() { - if let swc_ecma_ast::ModuleItem::ModuleDecl(module_decl) = node { + if let swc_ecmascript::ast::ModuleItem::ModuleDecl(module_decl) = node { let r = match module_decl { ModuleDecl::ExportNamed(named_export) => { if let Some(src) = &named_export.src { @@ -513,16 +508,16 @@ impl DocParser { pub fn get_doc_nodes_for_module_body( &self, - module_body: Vec<swc_ecma_ast::ModuleItem>, + module_body: Vec<swc_ecmascript::ast::ModuleItem>, ) -> Vec<DocNode> { let mut doc_entries: Vec<DocNode> = vec![]; for node in module_body.iter() { match node { - swc_ecma_ast::ModuleItem::ModuleDecl(module_decl) => { + swc_ecmascript::ast::ModuleItem::ModuleDecl(module_decl) => { doc_entries .extend(self.get_doc_nodes_for_module_exports(module_decl)); } - swc_ecma_ast::ModuleItem::Stmt(stmt) => { + swc_ecmascript::ast::ModuleItem::Stmt(stmt) => { if let Some(doc_node) = self.get_doc_node_for_stmt(stmt) { doc_entries.push(doc_node); } diff --git a/cli/doc/printer.rs b/cli/doc/printer.rs index 2e55c752a..a3ecd2718 100644 --- a/cli/doc/printer.rs +++ b/cli/doc/printer.rs @@ -16,7 +16,6 @@ use crate::doc::display::{ display_abstract, display_async, display_generator, Indent, SliceDisplayer, }; use crate::doc::DocNodeKind; -use crate::swc_ecma_ast; use std::fmt::{Display, Formatter, Result as FmtResult}; pub struct DocPrinter<'a> { @@ -193,8 +192,8 @@ impl<'a> DocPrinter<'a> { self.private || node .accessibility - .unwrap_or(swc_ecma_ast::Accessibility::Public) - != swc_ecma_ast::Accessibility::Private + .unwrap_or(swc_ecmascript::ast::Accessibility::Public) + != swc_ecmascript::ast::Accessibility::Private }) { writeln!(w, "{}{}", Indent(1), node,)?; if let Some(js_doc) = &node.js_doc { @@ -208,8 +207,8 @@ impl<'a> DocPrinter<'a> { self.private || node .accessibility - .unwrap_or(swc_ecma_ast::Accessibility::Public) - != swc_ecma_ast::Accessibility::Private + .unwrap_or(swc_ecmascript::ast::Accessibility::Public) + != swc_ecmascript::ast::Accessibility::Private }) { writeln!(w, "{}{}", Indent(1), node,)?; if let Some(js_doc) = &node.js_doc { @@ -454,9 +453,9 @@ impl<'a> DocPrinter<'a> { "{}{} {}", Indent(indent), colors::magenta(match variable_def.kind { - swc_ecma_ast::VarDeclKind::Const => "const", - swc_ecma_ast::VarDeclKind::Let => "let", - swc_ecma_ast::VarDeclKind::Var => "var", + swc_ecmascript::ast::VarDeclKind::Const => "const", + swc_ecmascript::ast::VarDeclKind::Let => "let", + swc_ecmascript::ast::VarDeclKind::Var => "var", }), colors::bold(&node.name), )?; diff --git a/cli/doc/ts_type.rs b/cli/doc/ts_type.rs index 36502ee5e..b2eb3438d 100644 --- a/cli/doc/ts_type.rs +++ b/cli/doc/ts_type.rs @@ -7,16 +7,15 @@ use super::ts_type_param::TsTypeParamDef; use super::ParamDef; use crate::colors; use crate::doc; -use crate::swc_ecma_ast; -use crate::swc_ecma_ast::{ +use serde::Serialize; +use std::fmt::{Display, Formatter, Result as FmtResult}; +use swc_ecmascript::ast::{ TsArrayType, TsConditionalType, TsExprWithTypeArgs, TsFnOrConstructorType, TsIndexedAccessType, TsKeywordType, TsLit, TsLitType, TsOptionalType, TsParenthesizedType, TsRestType, TsThisType, TsTupleType, TsType, TsTypeAnn, TsTypeLit, TsTypeOperator, TsTypeParamInstantiation, TsTypeQuery, TsTypeRef, TsUnionOrIntersectionType, }; -use serde::Serialize; -use std::fmt::{Display, Formatter, Result as FmtResult}; // pub enum TsType { // * TsKeywordType(TsKeywordType), @@ -129,7 +128,7 @@ impl Into<TsTypeDef> for &TsTupleType { impl Into<TsTypeDef> for &TsUnionOrIntersectionType { fn into(self) -> TsTypeDef { - use crate::swc_ecma_ast::TsUnionOrIntersectionType::*; + use swc_ecmascript::ast::TsUnionOrIntersectionType::*; match self { TsUnionType(union_type) => { @@ -168,7 +167,7 @@ impl Into<TsTypeDef> for &TsUnionOrIntersectionType { impl Into<TsTypeDef> for &TsKeywordType { fn into(self) -> TsTypeDef { - use crate::swc_ecma_ast::TsKeywordTypeKind::*; + use swc_ecmascript::ast::TsKeywordTypeKind::*; let keyword_str = match self.kind { TsAnyKeyword => "any", @@ -258,9 +257,9 @@ impl Into<TsTypeDef> for &TsThisType { } pub fn ts_entity_name_to_name( - entity_name: &swc_ecma_ast::TsEntityName, + entity_name: &swc_ecmascript::ast::TsEntityName, ) -> String { - use crate::swc_ecma_ast::TsEntityName::*; + use swc_ecmascript::ast::TsEntityName::*; match entity_name { Ident(ident) => ident.sym.to_string(), @@ -274,7 +273,7 @@ pub fn ts_entity_name_to_name( impl Into<TsTypeDef> for &TsTypeQuery { fn into(self) -> TsTypeDef { - use crate::swc_ecma_ast::TsTypeQueryExpr::*; + use swc_ecmascript::ast::TsTypeQueryExpr::*; let type_name = match &self.expr_name { TsEntityName(entity_name) => ts_entity_name_to_name(&*entity_name), @@ -374,7 +373,7 @@ impl Into<TsTypeDef> for &TsTypeLit { let mut index_signatures = vec![]; for type_element in &self.members { - use crate::swc_ecma_ast::TsTypeElement::*; + use swc_ecmascript::ast::TsTypeElement::*; match &type_element { TsMethodSignature(ts_method_sig) => { @@ -511,7 +510,7 @@ impl Into<TsTypeDef> for &TsConditionalType { impl Into<TsTypeDef> for &TsFnOrConstructorType { fn into(self) -> TsTypeDef { - use crate::swc_ecma_ast::TsFnOrConstructorType::*; + use swc_ecmascript::ast::TsFnOrConstructorType::*; let fn_def = match self { TsFnType(ts_fn_type) => { @@ -563,7 +562,7 @@ impl Into<TsTypeDef> for &TsFnOrConstructorType { impl Into<TsTypeDef> for &TsType { fn into(self) -> TsTypeDef { - use crate::swc_ecma_ast::TsType::*; + use swc_ecmascript::ast::TsType::*; match self { TsKeywordType(ref keyword_type) => keyword_type.into(), @@ -829,7 +828,7 @@ pub struct TsTypeDef { } pub fn ts_type_ann_to_def(type_ann: &TsTypeAnn) -> TsTypeDef { - use crate::swc_ecma_ast::TsType::*; + use swc_ecmascript::ast::TsType::*; match &*type_ann.type_ann { TsKeywordType(keyword_type) => keyword_type.into(), diff --git a/cli/doc/ts_type_param.rs b/cli/doc/ts_type_param.rs index 0483708b6..52ecb74cc 100644 --- a/cli/doc/ts_type_param.rs +++ b/cli/doc/ts_type_param.rs @@ -1,9 +1,9 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use super::ts_type::TsTypeDef; -use crate::swc_ecma_ast::TsTypeParam; -use crate::swc_ecma_ast::TsTypeParamDecl; use serde::Serialize; use std::fmt::{Display, Formatter, Result as FmtResult}; +use swc_ecmascript::ast::TsTypeParam; +use swc_ecmascript::ast::TsTypeParamDecl; #[derive(Debug, Serialize, Clone)] #[serde(rename_all = "camelCase")] diff --git a/cli/doc/type_alias.rs b/cli/doc/type_alias.rs index b26395c3f..446e8fbec 100644 --- a/cli/doc/type_alias.rs +++ b/cli/doc/type_alias.rs @@ -3,7 +3,6 @@ use super::parser::DocParser; use super::ts_type::TsTypeDef; use super::ts_type_param::maybe_type_param_decl_to_type_param_defs; use super::ts_type_param::TsTypeParamDef; -use crate::swc_ecma_ast; use serde::Serialize; #[derive(Debug, Serialize, Clone)] @@ -15,7 +14,7 @@ pub struct TypeAliasDef { pub fn get_doc_for_ts_type_alias_decl( _doc_parser: &DocParser, - type_alias_decl: &swc_ecma_ast::TsTypeAliasDecl, + type_alias_decl: &swc_ecmascript::ast::TsTypeAliasDecl, ) -> (String, TypeAliasDef) { let alias_name = type_alias_decl.id.sym.to_string(); let ts_type = type_alias_decl.type_ann.as_ref().into(); diff --git a/cli/doc/variable.rs b/cli/doc/variable.rs index 0b9c28a42..4c2fcea14 100644 --- a/cli/doc/variable.rs +++ b/cli/doc/variable.rs @@ -1,5 +1,4 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -use crate::swc_ecma_ast; use serde::Serialize; use super::ts_type::ts_type_ann_to_def; @@ -9,23 +8,23 @@ use super::ts_type::TsTypeDef; #[serde(rename_all = "camelCase")] pub struct VariableDef { pub ts_type: Option<TsTypeDef>, - pub kind: swc_ecma_ast::VarDeclKind, + pub kind: swc_ecmascript::ast::VarDeclKind, } // TODO: change this function to return Vec<(String, VariableDef)> as single // var declaration can have multiple declarators pub fn get_doc_for_var_decl( - var_decl: &swc_ecma_ast::VarDecl, + var_decl: &swc_ecmascript::ast::VarDecl, ) -> (String, VariableDef) { assert!(!var_decl.decls.is_empty()); let var_declarator = var_decl.decls.get(0).unwrap(); let var_name = match &var_declarator.name { - swc_ecma_ast::Pat::Ident(ident) => ident.sym.to_string(), + swc_ecmascript::ast::Pat::Ident(ident) => ident.sym.to_string(), _ => "<TODO>".to_string(), }; let maybe_ts_type = match &var_declarator.name { - swc_ecma_ast::Pat::Ident(ident) => { + swc_ecmascript::ast::Pat::Ident(ident) => { ident.type_ann.as_ref().map(|rt| ts_type_ann_to_def(rt)) } _ => None, |