From 8c3a9543362afae5768edd62085175911600e080 Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Fri, 6 Dec 2024 15:52:05 +0000 Subject: [PATCH] fix(codegen): missing parens for `in` in `for in` loop init (#7705) Well, this looks like an accidental change before, `Context::empty().and_forbid_in(false)` does nothing at all. --- crates/oxc_codegen/src/gen.rs | 2 +- crates/oxc_codegen/tests/integration/unit.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index 095b5fcf8..644f0b446 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -291,7 +291,7 @@ impl Gen for ForInStatement<'_> { p.print_str("for"); p.print_soft_space(); p.print_ascii_byte(b'('); - self.left.print(p, Context::empty().and_forbid_in(false)); + self.left.print(p, Context::FORBID_IN); p.print_soft_space(); p.print_space_before_identifier(); p.print_str("in"); diff --git a/crates/oxc_codegen/tests/integration/unit.rs b/crates/oxc_codegen/tests/integration/unit.rs index 152ba20c4..115611cf0 100644 --- a/crates/oxc_codegen/tests/integration/unit.rs +++ b/crates/oxc_codegen/tests/integration/unit.rs @@ -64,10 +64,10 @@ fn for_stmt() { "for (x = (y in z) || y || (y in z) || y || (y in z);;);", "for (x = (y in z) || y || (y in z) || y || (y in z);;);\n", ); - // test( - // "for (var a = 1 || (2 in {}) in { x: 1 }) count++;", - // "for (var a = 1 || (2 in {}) in {x: 1}) count++;\n", - // ); + test( + "for (var a = 1 || (2 in {}) in { x: 1 }) count++;", + "for (var a = 1 || (2 in {}) in { x: 1 }) count++;\n", + ); } #[test]