feat(prettier): support format arrow function as expression (#1364)

This commit is contained in:
Dunqing 2023-11-17 13:59:29 +08:00 committed by GitHub
parent 5af76b4bcd
commit 210dbd3ff2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)
}