2020-03-28 14:16:57 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-04-03 12:35:03 -04:00
|
|
|
use crate::swc_ecma_ast;
|
2020-03-28 14:16:57 -04:00
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
use super::parser::DocParser;
|
|
|
|
use super::DocNode;
|
|
|
|
use super::DocNodeKind;
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Clone)]
|
|
|
|
pub struct NamespaceDef {
|
|
|
|
pub elements: Vec<DocNode>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_doc_for_ts_namespace_decl(
|
|
|
|
doc_parser: &DocParser,
|
|
|
|
ts_namespace_decl: &swc_ecma_ast::TsNamespaceDecl,
|
|
|
|
) -> DocNode {
|
|
|
|
let js_doc = doc_parser.js_doc_for_span(ts_namespace_decl.span);
|
|
|
|
let location = doc_parser
|
2020-04-27 09:46:39 -04:00
|
|
|
.ast_parser
|
|
|
|
.get_span_location(ts_namespace_decl.span)
|
2020-03-28 14:16:57 -04:00
|
|
|
.into();
|
|
|
|
let namespace_name = ts_namespace_decl.id.sym.to_string();
|
|
|
|
|
2020-04-03 12:35:03 -04:00
|
|
|
use crate::swc_ecma_ast::TsNamespaceBody::*;
|
2020-03-28 14:16:57 -04:00
|
|
|
|
|
|
|
let elements = match &*ts_namespace_decl.body {
|
|
|
|
TsModuleBlock(ts_module_block) => {
|
|
|
|
doc_parser.get_doc_nodes_for_module_body(ts_module_block.body.clone())
|
|
|
|
}
|
|
|
|
TsNamespaceDecl(ts_namespace_decl) => {
|
|
|
|
vec![get_doc_for_ts_namespace_decl(doc_parser, ts_namespace_decl)]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let ns_def = NamespaceDef { elements };
|
|
|
|
|
|
|
|
DocNode {
|
|
|
|
kind: DocNodeKind::Namespace,
|
|
|
|
name: namespace_name,
|
|
|
|
location,
|
|
|
|
js_doc,
|
|
|
|
namespace_def: Some(ns_def),
|
|
|
|
function_def: None,
|
|
|
|
variable_def: None,
|
|
|
|
enum_def: None,
|
|
|
|
class_def: None,
|
|
|
|
type_alias_def: None,
|
|
|
|
interface_def: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_doc_for_ts_module(
|
|
|
|
doc_parser: &DocParser,
|
|
|
|
ts_module_decl: &swc_ecma_ast::TsModuleDecl,
|
|
|
|
) -> (String, NamespaceDef) {
|
2020-04-03 12:35:03 -04:00
|
|
|
use crate::swc_ecma_ast::TsModuleName;
|
2020-03-28 14:16:57 -04:00
|
|
|
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 {
|
2020-04-03 12:35:03 -04:00
|
|
|
use crate::swc_ecma_ast::TsNamespaceBody::*;
|
2020-03-28 14:16:57 -04:00
|
|
|
|
|
|
|
match &body {
|
|
|
|
TsModuleBlock(ts_module_block) => {
|
|
|
|
doc_parser.get_doc_nodes_for_module_body(ts_module_block.body.clone())
|
|
|
|
}
|
|
|
|
TsNamespaceDecl(ts_namespace_decl) => {
|
|
|
|
vec![get_doc_for_ts_namespace_decl(doc_parser, ts_namespace_decl)]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
vec![]
|
|
|
|
};
|
|
|
|
|
|
|
|
let ns_def = NamespaceDef { elements };
|
|
|
|
|
|
|
|
(namespace_name, ns_def)
|
|
|
|
}
|