summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Anger <syrupthinker@gryphno.de>2020-06-28 16:35:12 +0200
committerGitHub <noreply@github.com>2020-06-28 10:35:12 -0400
commit660f86f1a21298f7795760a24b91b7bd8788afc3 (patch)
tree1750174db894c09a0933f5068fc66d30038c0597
parent89ebe2079bf51ec55c89c093ab16c3179ccd43fe (diff)
fix(cli/doc): doc printer missing [] around tuple type (#6523)
-rw-r--r--cli/doc/printer.rs3
-rw-r--r--cli/doc/tests.rs17
2 files changed, 19 insertions, 1 deletions
diff --git a/cli/doc/printer.rs b/cli/doc/printer.rs
index d24e65901..8525a52e9 100644
--- a/cli/doc/printer.rs
+++ b/cli/doc/printer.rs
@@ -206,7 +206,7 @@ fn render_ts_type(ts_type: doc::ts_type::TsTypeDef) -> String {
TsTypeDefKind::This => "this".to_string(),
TsTypeDefKind::Tuple => {
let tuple = ts_type.tuple.unwrap();
- let mut output = "".to_string();
+ let mut output = "[".to_string();
if !tuple.is_empty() {
for ts_type in tuple {
output += render_ts_type(ts_type).as_str();
@@ -214,6 +214,7 @@ fn render_ts_type(ts_type: doc::ts_type::TsTypeDef) -> String {
}
output.truncate(output.len() - 2);
}
+ output += "]";
output
}
TsTypeDefKind::TypeLiteral => {
diff --git a/cli/doc/tests.rs b/cli/doc/tests.rs
index 8886f76be..7efc3857b 100644
--- a/cli/doc/tests.rs
+++ b/cli/doc/tests.rs
@@ -1605,3 +1605,20 @@ export namespace Deno {
let found = find_nodes_by_name_recursively(entries, "a.b.c".to_string());
assert_eq!(found.len(), 0);
}
+
+#[tokio::test]
+async fn generic_instantiated_with_tuple_type() {
+ let source_code = r#"
+interface Generic<T> {}
+export function f(): Generic<[string, number]> { return {}; }
+ "#;
+
+ let loader =
+ TestLoader::new(vec![("test.ts".to_string(), source_code.to_string())]);
+ let entries = DocParser::new(loader).parse("test.ts").await.unwrap();
+
+ assert!(colors::strip_ansi_codes(
+ crate::doc::printer::format(entries).as_str()
+ )
+ .contains("Generic<[string, number]>"))
+}