Skip to content

Commit

Permalink
fix(codegen): do not print parenthesis for in expression in ArrowFunc…
Browse files Browse the repository at this point in the history
…tionExpression
  • Loading branch information
Dunqing committed Nov 19, 2024
1 parent 514878d commit 25e18f1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions crates/oxc_codegen/tests/integration/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

0 comments on commit 25e18f1

Please sign in to comment.