mirror of
https://github.com/denoland/deno.git
synced 2025-09-29 13:44:47 +00:00
fix(doc): Added extends field to interface (#4739)
This commit is contained in:
parent
a9923f3f93
commit
c915e4d77d
4 changed files with 42 additions and 14 deletions
|
@ -64,7 +64,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>,
|
pub extends: Option<String>,
|
||||||
pub implements: Vec<String>,
|
pub implements: Vec<String>,
|
||||||
pub type_params: Vec<TsTypeParamDef>,
|
pub type_params: Vec<TsTypeParamDef>,
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ 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 {
|
let extends: Option<String> = match &class_decl.class.super_class {
|
||||||
Some(boxed) => {
|
Some(boxed) => {
|
||||||
use crate::swc_ecma_ast::Expr;
|
use crate::swc_ecma_ast::Expr;
|
||||||
let expr: &Expr = &**boxed;
|
let expr: &Expr = &**boxed;
|
||||||
|
@ -217,7 +217,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,
|
extends,
|
||||||
implements,
|
implements,
|
||||||
constructors,
|
constructors,
|
||||||
properties,
|
properties,
|
||||||
|
|
|
@ -4,6 +4,7 @@ use serde::Serialize;
|
||||||
|
|
||||||
use super::params::ts_fn_param_to_param_def;
|
use super::params::ts_fn_param_to_param_def;
|
||||||
use super::parser::DocParser;
|
use super::parser::DocParser;
|
||||||
|
use super::ts_type::ts_entity_name_to_name;
|
||||||
use super::ts_type::ts_type_ann_to_def;
|
use super::ts_type::ts_type_ann_to_def;
|
||||||
use super::ts_type::TsTypeDef;
|
use super::ts_type::TsTypeDef;
|
||||||
use super::ts_type_param::maybe_type_param_decl_to_type_param_defs;
|
use super::ts_type_param::maybe_type_param_decl_to_type_param_defs;
|
||||||
|
@ -49,7 +50,7 @@ pub struct InterfaceCallSignatureDef {
|
||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct InterfaceDef {
|
pub struct InterfaceDef {
|
||||||
// TODO(bartlomieju): extends
|
pub extends: Vec<String>,
|
||||||
pub methods: Vec<InterfaceMethodDef>,
|
pub methods: Vec<InterfaceMethodDef>,
|
||||||
pub properties: Vec<InterfacePropertyDef>,
|
pub properties: Vec<InterfacePropertyDef>,
|
||||||
pub call_signatures: Vec<InterfaceCallSignatureDef>,
|
pub call_signatures: Vec<InterfaceCallSignatureDef>,
|
||||||
|
@ -201,7 +202,14 @@ pub fn get_doc_for_ts_interface_decl(
|
||||||
interface_decl.type_params.as_ref(),
|
interface_decl.type_params.as_ref(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let extends: Vec<String> = interface_decl
|
||||||
|
.extends
|
||||||
|
.iter()
|
||||||
|
.map(|expr| ts_entity_name_to_name(&expr.expr))
|
||||||
|
.collect();
|
||||||
|
|
||||||
let interface_def = InterfaceDef {
|
let interface_def = InterfaceDef {
|
||||||
|
extends,
|
||||||
methods,
|
methods,
|
||||||
properties,
|
properties,
|
||||||
call_signatures,
|
call_signatures,
|
||||||
|
|
|
@ -444,11 +444,11 @@ 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 class_def = node.class_def.clone().unwrap();
|
||||||
let super_suffix = if let Some(super_class) = class_def.super_class {
|
let extends_suffix = if let Some(extends) = class_def.extends {
|
||||||
format!(
|
format!(
|
||||||
" {} {}",
|
" {} {}",
|
||||||
colors::magenta("extends".to_string()),
|
colors::magenta("extends".to_string()),
|
||||||
colors::bold(super_class)
|
colors::bold(extends)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
String::from("")
|
String::from("")
|
||||||
|
@ -470,7 +470,7 @@ fn format_class_signature(node: &doc::DocNode, indent: i64) -> String {
|
||||||
"{} {}{}{}\n",
|
"{} {}{}{}\n",
|
||||||
colors::magenta("class".to_string()),
|
colors::magenta("class".to_string()),
|
||||||
colors::bold(node.name.clone()),
|
colors::bold(node.name.clone()),
|
||||||
super_suffix,
|
extends_suffix,
|
||||||
implements_suffix,
|
implements_suffix,
|
||||||
),
|
),
|
||||||
indent,
|
indent,
|
||||||
|
@ -510,11 +510,23 @@ fn format_enum_signature(node: &doc::DocNode, indent: i64) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_interface_signature(node: &doc::DocNode, indent: i64) -> String {
|
fn format_interface_signature(node: &doc::DocNode, indent: i64) -> String {
|
||||||
|
let interface_def = node.interface_def.clone().unwrap();
|
||||||
|
let extends = &interface_def.extends;
|
||||||
|
let extends_suffix = if !extends.is_empty() {
|
||||||
|
format!(
|
||||||
|
" {} {}",
|
||||||
|
colors::magenta("extends".to_string()),
|
||||||
|
colors::bold(extends.join(", "))
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
String::from("")
|
||||||
|
};
|
||||||
add_indent(
|
add_indent(
|
||||||
format!(
|
format!(
|
||||||
"{} {}\n",
|
"{} {}{}\n",
|
||||||
colors::magenta("interface".to_string()),
|
colors::magenta("interface".to_string()),
|
||||||
colors::bold(node.name.clone())
|
colors::bold(node.name.clone()),
|
||||||
|
extends_suffix
|
||||||
),
|
),
|
||||||
indent,
|
indent,
|
||||||
)
|
)
|
||||||
|
|
|
@ -316,7 +316,7 @@ export class Foobar extends Fizz implements Buzz, Aldrin {
|
||||||
"jsDoc": "Class doc",
|
"jsDoc": "Class doc",
|
||||||
"classDef": {
|
"classDef": {
|
||||||
"isAbstract": false,
|
"isAbstract": false,
|
||||||
"superClass": "Fizz",
|
"extends": "Fizz",
|
||||||
"implements": ["Buzz", "Aldrin"],
|
"implements": ["Buzz", "Aldrin"],
|
||||||
"typeParams": [],
|
"typeParams": [],
|
||||||
"constructors": [
|
"constructors": [
|
||||||
|
@ -522,10 +522,16 @@ export class Foobar extends Fizz implements Buzz, Aldrin {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn export_interface() {
|
async fn export_interface() {
|
||||||
let source_code = r#"
|
let source_code = r#"
|
||||||
|
interface Foo {
|
||||||
|
foo(): void;
|
||||||
|
}
|
||||||
|
interface Bar {
|
||||||
|
bar(): void;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Interface js doc
|
* Interface js doc
|
||||||
*/
|
*/
|
||||||
export interface Reader {
|
export interface Reader extends Foo, Bar {
|
||||||
/** Read n bytes */
|
/** Read n bytes */
|
||||||
read?(buf: Uint8Array, something: unknown): Promise<number>
|
read?(buf: Uint8Array, something: unknown): Promise<number>
|
||||||
}
|
}
|
||||||
|
@ -540,17 +546,18 @@ export interface Reader {
|
||||||
"name": "Reader",
|
"name": "Reader",
|
||||||
"location": {
|
"location": {
|
||||||
"filename": "test.ts",
|
"filename": "test.ts",
|
||||||
"line": 5,
|
"line": 11,
|
||||||
"col": 0
|
"col": 0
|
||||||
},
|
},
|
||||||
"jsDoc": "Interface js doc",
|
"jsDoc": "Interface js doc",
|
||||||
"interfaceDef": {
|
"interfaceDef": {
|
||||||
|
"extends": ["Foo", "Bar"],
|
||||||
"methods": [
|
"methods": [
|
||||||
{
|
{
|
||||||
"name": "read",
|
"name": "read",
|
||||||
"location": {
|
"location": {
|
||||||
"filename": "test.ts",
|
"filename": "test.ts",
|
||||||
"line": 7,
|
"line": 13,
|
||||||
"col": 4
|
"col": 4
|
||||||
},
|
},
|
||||||
"optional": true,
|
"optional": true,
|
||||||
|
@ -607,7 +614,7 @@ export interface Reader {
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
colors::strip_ansi_codes(super::printer::format(entries).as_str())
|
colors::strip_ansi_codes(super::printer::format(entries).as_str())
|
||||||
.contains("interface Reader")
|
.contains("interface Reader extends Foo, Bar")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -633,6 +640,7 @@ export interface TypedIface<T> {
|
||||||
},
|
},
|
||||||
"jsDoc": null,
|
"jsDoc": null,
|
||||||
"interfaceDef": {
|
"interfaceDef": {
|
||||||
|
"extends": [],
|
||||||
"methods": [
|
"methods": [
|
||||||
{
|
{
|
||||||
"name": "something",
|
"name": "something",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue