From 210dbd3ff2a9a91d3b4f37039262cfc835ea4981 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Fri, 17 Nov 2023 13:59:29 +0800 Subject: [PATCH] feat(prettier): support format arrow function as expression (#1364) --- crates/oxc_prettier/src/format/arrow_function.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/oxc_prettier/src/format/arrow_function.rs b/crates/oxc_prettier/src/format/arrow_function.rs index d74bef1d0..e3c966b7b 100644 --- a/crates/oxc_prettier/src/format/arrow_function.rs +++ b/crates/oxc_prettier/src/format/arrow_function.rs @@ -10,7 +10,17 @@ pub(super) fn print_arrow_function<'a>( let mut parts = p.vec(); parts.push(ss!("() => ")); - parts.push(expr.body.format(p)); + if expr.expression { + let stmt = &expr.body.statements[0]; + match stmt { + // ExpressionStatement will add a semicolon and Hardline, But we don't need it + // So we only need to format the expression of the ExpressionStatement + Statement::ExpressionStatement(expr_stmt) => parts.push(expr_stmt.expression.format(p)), + _ => parts.push(stmt.format(p)), + } + } else { + parts.push(expr.body.format(p)); + } Doc::Array(parts) }