fix(codegen): do not print parenthesis for in expression in ArrowFunctionExpression (#7360)

Please check out [esbuild](https://esbuild.github.io/try/#dAAwLjI0LjAAACgpID0+ICIiIGluIHt9)
This commit is contained in:
Dunqing 2024-11-19 14:29:18 +00:00
parent 514878d927
commit c587dd3cd6
2 changed files with 8 additions and 1 deletions

View file

@ -1623,7 +1623,7 @@ impl<'a> GenExpr for ArrowFunctionExpression<'a> {
if self.expression {
if let Some(Statement::ExpressionStatement(stmt)) = &self.body.statements.first() {
p.start_of_arrow_expr = p.code_len();
stmt.expression.print_expr(p, Precedence::Comma, ctx.and_forbid_in(true));
stmt.expression.print_expr(p, Precedence::Comma, ctx);
}
} else {
self.body.print(p, ctx);

View file

@ -294,3 +294,10 @@ fn in_expr_in_sequence_in_for_loop_init() {
"for ((\"hidden\" in a) && (m = a.hidden), r = 0; s > r; r++) {}\n",
);
}
#[test]
fn in_expr_in_arrow_function_expression() {
test("() => ('foo' in bar)", "() => \"foo\" in bar;\n");
test("() => 'foo' in bar", "() => \"foo\" in bar;\n");
test("() => { ('foo' in bar) }", "() => {\n\t\"foo\" in bar;\n};\n");
}