mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 23:34:47 -05:00
deno doc
parses super-class names (#4595)
Co-Authored-By: Luca Casonato <luca.casonato@antipy.com>
This commit is contained in:
parent
c8fc29fcca
commit
b57d075c07
3 changed files with 32 additions and 5 deletions
|
@ -60,6 +60,7 @@ pub struct ClassDef {
|
|||
pub constructors: Vec<ClassConstructorDef>,
|
||||
pub properties: Vec<ClassPropertyDef>,
|
||||
pub methods: Vec<ClassMethodDef>,
|
||||
pub super_class: Option<String>,
|
||||
}
|
||||
|
||||
fn prop_name_to_string(
|
||||
|
@ -85,6 +86,18 @@ pub fn get_doc_for_class_decl(
|
|||
let mut methods = vec![];
|
||||
let mut properties = vec![];
|
||||
|
||||
let super_class: Option<String> = match &class_decl.class.super_class {
|
||||
Some(boxed) => {
|
||||
use swc_ecma_ast::Expr;
|
||||
let expr: &Expr = &**boxed;
|
||||
match expr {
|
||||
Expr::Ident(ident) => Some(ident.sym.to_string()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
|
||||
for member in &class_decl.class.body {
|
||||
use swc_ecma_ast::ClassMember::*;
|
||||
|
||||
|
@ -198,6 +211,7 @@ pub fn get_doc_for_class_decl(
|
|||
let class_name = class_decl.ident.sym.to_string();
|
||||
let class_def = ClassDef {
|
||||
is_abstract: class_decl.class.is_abstract,
|
||||
super_class,
|
||||
constructors,
|
||||
properties,
|
||||
methods,
|
||||
|
|
|
@ -427,11 +427,23 @@ fn format_function_signature(node: &doc::DocNode, indent: i64) -> String {
|
|||
}
|
||||
|
||||
fn format_class_signature(node: &doc::DocNode, indent: i64) -> String {
|
||||
let class_def = node.class_def.clone().unwrap();
|
||||
let super_suffix = if let Some(super_class) = class_def.super_class {
|
||||
format!(
|
||||
" {} {}",
|
||||
colors::magenta("extends".to_string()),
|
||||
colors::bold(super_class)
|
||||
)
|
||||
} else {
|
||||
String::from("")
|
||||
};
|
||||
|
||||
add_indent(
|
||||
format!(
|
||||
"{} {}\n",
|
||||
"{} {}{}\n",
|
||||
colors::magenta("class".to_string()),
|
||||
colors::bold(node.name.clone())
|
||||
colors::bold(node.name.clone()),
|
||||
super_suffix
|
||||
),
|
||||
indent,
|
||||
)
|
||||
|
|
|
@ -8,9 +8,9 @@ use serde_json::json;
|
|||
fn export_fn() {
|
||||
let source_code = r#"/**
|
||||
* Hello there, this is a multiline JSdoc.
|
||||
*
|
||||
*
|
||||
* It has many lines
|
||||
*
|
||||
*
|
||||
* Or not that many?
|
||||
*/
|
||||
export function foo(a: string, b: number): void {
|
||||
|
@ -139,6 +139,7 @@ export class Foobar extends Fizz implements Buzz {
|
|||
"jsDoc": "Class doc",
|
||||
"classDef": {
|
||||
"isAbstract": false,
|
||||
"superClass": "Fizz",
|
||||
"constructors": [
|
||||
{
|
||||
"jsDoc": "Constructor js doc",
|
||||
|
@ -308,7 +309,7 @@ export class Foobar extends Fizz implements Buzz {
|
|||
|
||||
assert!(
|
||||
colors::strip_ansi_codes(super::printer::format(entries).as_str())
|
||||
.contains("class Foobar")
|
||||
.contains("class Foobar extends Fizz")
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue