Skip to content

Commit

Permalink
fix(codegen): missing parenthesis for PrivateInExpression (#4865)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Aug 13, 2024
1 parent 1808529 commit 3da33d3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
14 changes: 8 additions & 6 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ impl<'a, const MINIFY: bool> GenExpr<MINIFY> for Expression<'a> {
Self::UpdateExpression(expr) => expr.gen_expr(p, precedence, ctx),
Self::UnaryExpression(expr) => expr.gen_expr(p, precedence, ctx),
Self::BinaryExpression(expr) => expr.gen_expr(p, precedence, ctx),
Self::PrivateInExpression(expr) => expr.gen(p, ctx),
Self::PrivateInExpression(expr) => expr.gen_expr(p, precedence, ctx),
Self::LogicalExpression(expr) => expr.gen_expr(p, precedence, ctx),
Self::ConditionalExpression(expr) => expr.gen_expr(p, precedence, ctx),
Self::AssignmentExpression(expr) => expr.gen_expr(p, precedence, ctx),
Expand Down Expand Up @@ -1778,11 +1778,13 @@ impl<const MINIFY: bool> Gen<MINIFY> for BinaryOperator {
}
}

impl<'a, const MINIFY: bool> Gen<MINIFY> for PrivateInExpression<'a> {
fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) {
self.left.gen(p, ctx);
p.print_str(" in ");
self.right.gen_expr(p, Precedence::Shift, Context::empty());
impl<'a, const MINIFY: bool> GenExpr<MINIFY> for PrivateInExpression<'a> {
fn gen_expr(&self, p: &mut Codegen<{ MINIFY }>, precedence: Precedence, ctx: Context) {
p.wrap(precedence >= Precedence::Compare, |p| {
self.left.gen(p, ctx);
p.print_str(" in ");
self.right.gen_expr(p, Precedence::Equals, Context::empty());
});
}
}

Expand Down
8 changes: 7 additions & 1 deletion crates/oxc_codegen/tests/integration/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ fn module_decl() {
}

#[test]
fn new_expr() {
fn expr() {
test("new (foo()).bar();", "new (foo()).bar();\n");
test(
"class Foo { #test
bar() { if (!(#test in Foo)) { } }
}",
"class Foo {\n\t#test;\n\tbar() {\n\t\tif (!(#test in Foo)) {}\n\t}\n}\n",
);
}

#[test]
Expand Down

0 comments on commit 3da33d3

Please sign in to comment.