From 755448220529f82e82b56624e5a431c256c172ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 5 Oct 2022 00:17:50 +0900 Subject: [PATCH] fix(es/compat): Fix handling of op-assignment in `generator` (#6036) --- crates/swc/tests/exec/issues-5xxx/5994/exec.mjs | 10 ++++++++++ .../swc_ecma_transforms_compat/src/es2015/generator.rs | 9 ++++----- 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 crates/swc/tests/exec/issues-5xxx/5994/exec.mjs diff --git a/crates/swc/tests/exec/issues-5xxx/5994/exec.mjs b/crates/swc/tests/exec/issues-5xxx/5994/exec.mjs new file mode 100644 index 00000000000..3bfe0bbea5d --- /dev/null +++ b/crates/swc/tests/exec/issues-5xxx/5994/exec.mjs @@ -0,0 +1,10 @@ + + +async function b() { return "bar"; } + +let x; +let a; + +a = async () => { x = ""; x += await b(); return x; } + +console.log(await a()); \ No newline at end of file diff --git a/crates/swc_ecma_transforms_compat/src/es2015/generator.rs b/crates/swc_ecma_transforms_compat/src/es2015/generator.rs index 1af792d9c74..e69932d760c 100644 --- a/crates/swc_ecma_transforms_compat/src/es2015/generator.rs +++ b/crates/swc_ecma_transforms_compat/src/es2015/generator.rs @@ -617,15 +617,14 @@ impl VisitMut for Generator { if node.op != op!("=") { let left_of_right = self.cache_expression(node.left.take().expect_expr()); - let op = node.op.to_update().unwrap(); node.right.visit_mut_with(self); - node.right = Box::new(Expr::Bin(BinExpr { + *e = Expr::Assign(AssignExpr { span: node.right.span(), - op, - left: Box::new(Expr::Ident(left_of_right)), + op: node.op, + left: left_of_right.into(), right: node.right.take(), - })); + }); } else { node.right.visit_mut_with(self); }