mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 07:44:48 -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 constructors: Vec<ClassConstructorDef>,
|
||||||
pub properties: Vec<ClassPropertyDef>,
|
pub properties: Vec<ClassPropertyDef>,
|
||||||
pub methods: Vec<ClassMethodDef>,
|
pub methods: Vec<ClassMethodDef>,
|
||||||
|
pub super_class: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prop_name_to_string(
|
fn prop_name_to_string(
|
||||||
|
@ -85,6 +86,18 @@ pub fn get_doc_for_class_decl(
|
||||||
let mut methods = vec![];
|
let mut methods = vec![];
|
||||||
let mut properties = 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 {
|
for member in &class_decl.class.body {
|
||||||
use swc_ecma_ast::ClassMember::*;
|
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_name = class_decl.ident.sym.to_string();
|
||||||
let class_def = ClassDef {
|
let class_def = ClassDef {
|
||||||
is_abstract: class_decl.class.is_abstract,
|
is_abstract: class_decl.class.is_abstract,
|
||||||
|
super_class,
|
||||||
constructors,
|
constructors,
|
||||||
properties,
|
properties,
|
||||||
methods,
|
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 {
|
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(
|
add_indent(
|
||||||
format!(
|
format!(
|
||||||
"{} {}\n",
|
"{} {}{}\n",
|
||||||
colors::magenta("class".to_string()),
|
colors::magenta("class".to_string()),
|
||||||
colors::bold(node.name.clone())
|
colors::bold(node.name.clone()),
|
||||||
|
super_suffix
|
||||||
),
|
),
|
||||||
indent,
|
indent,
|
||||||
)
|
)
|
||||||
|
|
|
@ -139,6 +139,7 @@ export class Foobar extends Fizz implements Buzz {
|
||||||
"jsDoc": "Class doc",
|
"jsDoc": "Class doc",
|
||||||
"classDef": {
|
"classDef": {
|
||||||
"isAbstract": false,
|
"isAbstract": false,
|
||||||
|
"superClass": "Fizz",
|
||||||
"constructors": [
|
"constructors": [
|
||||||
{
|
{
|
||||||
"jsDoc": "Constructor js doc",
|
"jsDoc": "Constructor js doc",
|
||||||
|
@ -308,7 +309,7 @@ export class Foobar extends Fizz implements Buzz {
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
colors::strip_ansi_codes(super::printer::format(entries).as_str())
|
colors::strip_ansi_codes(super::printer::format(entries).as_str())
|
||||||
.contains("class Foobar")
|
.contains("class Foobar extends Fizz")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue