Render parentheses at the right position in docs

This commit is contained in:
Yuki Omoto 2023-03-27 19:49:06 +09:00
parent 33ed87cacb
commit 1be74346f4
No known key found for this signature in database
GPG key ID: 9A7D6C91D5219717

View file

@ -540,9 +540,7 @@ fn type_annotation_to_html(
type_annotation_to_html(indent_level, buf, extension, true);
}
TypeAnnotation::Function { args, output } => {
if needs_parens {
buf.push('(');
}
let mut paren_is_open = false;
let mut peekable_args = args.iter().peekable();
while let Some(arg) = peekable_args.next() {
if is_multiline {
@ -551,6 +549,10 @@ fn type_annotation_to_html(
}
indent(buf, indent_level + 1);
}
if needs_parens && !paren_is_open {
buf.push('(');
paren_is_open = true;
}
let child_needs_parens = match arg {
TypeAnnotation::Function { args: _, output: _ } => true,
@ -577,7 +579,7 @@ fn type_annotation_to_html(
}
type_annotation_to_html(next_indent_level, buf, output, false);
if needs_parens {
if needs_parens && paren_is_open {
buf.push(')');
}
}