Skip to content

Commit

Permalink
fix(codegen): fix in in sequence expr in for loops (#6428)
Browse files Browse the repository at this point in the history
not sure if this is right, but it doesn't break any existing tests so hopefully?
  • Loading branch information
camc314 committed Oct 13, 2024
1 parent 096e590 commit 6896efc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1948,9 +1948,9 @@ impl<'a> Gen for AssignmentTargetRest<'a> {
}

impl<'a> GenExpr for SequenceExpression<'a> {
fn gen_expr(&self, p: &mut Codegen, precedence: Precedence, _ctx: Context) {
fn gen_expr(&self, p: &mut Codegen, precedence: Precedence, ctx: Context) {
p.wrap(precedence >= self.precedence(), |p| {
p.print_expressions(&self.expressions, Precedence::Lowest, Context::empty());
p.print_expressions(&self.expressions, Precedence::Lowest, ctx);
});
}
}
Expand Down
9 changes: 9 additions & 0 deletions crates/oxc_codegen/tests/integration/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,12 @@ fn vite_special_comments() {
"import(\n\t/* @vite-ignore */\n\tmodule1Url\n).then((module1) => {\n\tself.postMessage(module.default + module1.msg1 + import.meta.env.BASE_URL);\n});\n",
);
}

// followup from https://github.com/oxc-project/oxc/pull/6422
#[test]
fn in_expr_in_sequence_in_for_loop_init() {
test(
"for (l = ('foo' in bar), i; i < 10; i += 1) {}",
"for (l = (\"foo\" in bar), i; i < 10; i += 1) {}\n",
);
}

0 comments on commit 6896efc

Please sign in to comment.