Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix doc printer missing [] around tuple type #6523

Merged
merged 4 commits into from Jun 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion cli/doc/printer.rs
Expand Up @@ -206,14 +206,15 @@ 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();
output += ", "
}
output.truncate(output.len() - 2);
}
output += "]";
output
}
TsTypeDefKind::TypeLiteral => {
Expand Down
17 changes: 17 additions & 0 deletions cli/doc/tests.rs
Expand Up @@ -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]>"))
}