From 891d353adeefbd54e56c2ff3e89a49697da0bc5b Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 14 Nov 2023 09:14:34 +0000 Subject: [PATCH] feat(prettier) Improve function printing (#1301) --- crates/oxc_prettier/src/format.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/oxc_prettier/src/format.rs b/crates/oxc_prettier/src/format.rs index 968f4aa00..998054cc3 100644 --- a/crates/oxc_prettier/src/format.rs +++ b/crates/oxc_prettier/src/format.rs @@ -387,6 +387,12 @@ impl<'a> Format<'a> for TSImportEqualsDeclaration<'a> { } } +impl<'a> Format<'a> for TSTypeParameterDeclaration<'a> { + fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> { + Doc::Line + } +} + impl<'a> Format<'a> for VariableDeclarator<'a> { fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> { Doc::Line @@ -396,7 +402,17 @@ impl<'a> Format<'a> for VariableDeclarator<'a> { impl<'a> Format<'a> for Function<'a> { fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> { let mut parts = p.vec(); - parts.push(p.str("function ")); + if self.r#async { + parts.push(string!(p, "async ")); + } + if self.generator { + parts.push(string!(p, "function* ")); + } else { + parts.push(p.str("function ")); + } + if let Some(type_params) = &self.type_parameters { + parts.push(format!(p, type_params)); + } if let Some(id) = &self.id { parts.push(p.str(id.name.as_str())); }