1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-27 17:49:08 -05:00

fix(doc): crash on formatting type predicate (#5651)

This commit is contained in:
Ryan Dahl 2020-05-19 18:55:06 -04:00 committed by GitHub
parent 949061c4b6
commit 0fb5f23466
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View file

@ -127,6 +127,9 @@ fn render_params(params: Vec<doc::ParamDef>) -> String {
}
fn render_ts_type(ts_type: doc::ts_type::TsTypeDef) -> String {
if ts_type.kind.is_none() {
return "<UNIMPLEMENTED>".to_string();
}
let kind = ts_type.kind.unwrap();
match kind {
TsTypeDefKind::Array => {

View file

@ -161,6 +161,19 @@ export function foo(a: string, b?: number, cb: (...cbArgs: unknown[]) => void, .
);
}
#[tokio::test]
async fn format_type_predicate() {
let source_code = r#"
export function isFish(pet: Fish | Bird): pet is Fish {
return (pet as Fish).swim !== undefined;
}
"#;
let loader =
TestLoader::new(vec![("test.ts".to_string(), source_code.to_string())]);
let entries = DocParser::new(loader).parse("test.ts").await.unwrap();
super::printer::format(entries);
}
#[tokio::test]
async fn export_fn2() {
let source_code = r#"