Move TypeAnnotation::Apply to to_node

This commit is contained in:
Joshua Warner 2024-12-19 17:36:20 -05:00
parent f169329c0e
commit 13ec99c16b
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
2 changed files with 46 additions and 54 deletions

View file

@ -56,6 +56,7 @@ pub enum Node<'a> {
DelimitedSequence(Braces, &'a [(Sp<'a>, Node<'a>)], Sp<'a>),
CommaSequence {
allow_blank_lines: bool,
indent_rest: bool,
first: &'a Node<'a>,
rest: &'a [Item<'a>],
},
@ -160,6 +161,7 @@ impl<'a> Formattable for Node<'a> {
}
Node::CommaSequence {
allow_blank_lines: _,
indent_rest: _,
first,
rest,
} => first.is_multiline() || rest.iter().any(|item| item.is_multiline()),
@ -205,10 +207,16 @@ impl<'a> Formattable for Node<'a> {
}
Node::CommaSequence {
allow_blank_lines,
indent_rest,
first,
rest,
} => {
buf.indent(indent);
let inner_indent = if *indent_rest {
indent + INDENT
} else {
indent
};
first.format_with_options(buf, parens, newlines, indent);
for item in *rest {
@ -218,14 +226,15 @@ impl<'a> Formattable for Node<'a> {
if *allow_blank_lines {
fmt_spaces(buf, item.before.iter(), indent);
} else {
fmt_spaces_no_blank_lines(buf, item.before.iter(), indent);
fmt_spaces_no_blank_lines(buf, item.before.iter(), inner_indent);
}
if item.newline {
buf.ensure_ends_with_newline();
} else if item.space {
buf.ensure_ends_with_whitespace();
}
item.node.format_with_options(buf, parens, newlines, indent);
item.node
.format_with_options(buf, parens, newlines, inner_indent);
}
}
Node::Literal(text) => {