summaryrefslogtreecommitdiff
path: root/cli/doc/function.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/doc/function.rs')
-rw-r--r--cli/doc/function.rs43
1 files changed, 14 insertions, 29 deletions
diff --git a/cli/doc/function.rs b/cli/doc/function.rs
index fbfd2d015..4c101ab08 100644
--- a/cli/doc/function.rs
+++ b/cli/doc/function.rs
@@ -1,11 +1,12 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-use crate::swc_ecma_ast;
-use serde::Serialize;
-
-use super::parser::DocParser;
+use super::params::pat_to_param_def;
use super::ts_type::ts_type_ann_to_def;
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)]
#[serde(rename_all = "camelCase")]
@@ -14,57 +15,41 @@ pub struct FunctionDef {
pub return_type: Option<TsTypeDef>,
pub is_async: bool,
pub is_generator: bool,
- // TODO: type_params, decorators
+ pub type_params: Vec<TsTypeParamDef>,
+ // TODO(bartlomieju): decorators
}
pub fn function_to_function_def(
- doc_parser: &DocParser,
function: &swc_ecma_ast::Function,
) -> FunctionDef {
let mut params = vec![];
for param in &function.params {
- use crate::swc_ecma_ast::Pat;
-
- let param_def = match param {
- Pat::Ident(ident) => {
- let ts_type = ident
- .type_ann
- .as_ref()
- .map(|rt| ts_type_ann_to_def(&doc_parser.source_map, rt));
-
- ParamDef {
- name: ident.sym.to_string(),
- ts_type,
- }
- }
- _ => ParamDef {
- name: "<TODO>".to_string(),
- ts_type: None,
- },
- };
-
+ let param_def = pat_to_param_def(param);
params.push(param_def);
}
let maybe_return_type = function
.return_type
.as_ref()
- .map(|rt| ts_type_ann_to_def(&doc_parser.source_map, rt));
+ .map(|rt| ts_type_ann_to_def(rt));
+
+ let type_params =
+ maybe_type_param_decl_to_type_param_defs(function.type_params.as_ref());
FunctionDef {
params,
return_type: maybe_return_type,
is_async: function.is_async,
is_generator: function.is_generator,
+ type_params,
}
}
pub fn get_doc_for_fn_decl(
- doc_parser: &DocParser,
fn_decl: &swc_ecma_ast::FnDecl,
) -> (String, FunctionDef) {
let name = fn_decl.ident.sym.to_string();
- let fn_def = function_to_function_def(doc_parser, &fn_decl.function);
+ let fn_def = function_to_function_def(&fn_decl.function);
(name, fn_def)
}