From 1ea3b9728dacab5b9b9875bd1edc54e0af68c3b6 Mon Sep 17 00:00:00 2001 From: CPunisher <1343316114@qq.com> Date: Mon, 28 Oct 2024 23:41:43 -0700 Subject: [PATCH 1/3] fix --- crates/swc/tests/exec/issues-9xxx/9110/.swcrc | 10 ++++++ .../swc/tests/exec/issues-9xxx/9110/1/exec.js | 36 +++++++++++++++++++ .../swc_ecma_compat_es2015/src/generator.rs | 3 +- 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 crates/swc/tests/exec/issues-9xxx/9110/.swcrc create mode 100644 crates/swc/tests/exec/issues-9xxx/9110/1/exec.js diff --git a/crates/swc/tests/exec/issues-9xxx/9110/.swcrc b/crates/swc/tests/exec/issues-9xxx/9110/.swcrc new file mode 100644 index 000000000000..2ac251cd12a7 --- /dev/null +++ b/crates/swc/tests/exec/issues-9xxx/9110/.swcrc @@ -0,0 +1,10 @@ +{ + "jsc": { + "parser": { + "syntax": "ecmascript" + }, + "externalHelpers": false, + "target": "es5" + }, + "isModule": true +} \ No newline at end of file diff --git a/crates/swc/tests/exec/issues-9xxx/9110/1/exec.js b/crates/swc/tests/exec/issues-9xxx/9110/1/exec.js new file mode 100644 index 000000000000..acd67fe91504 --- /dev/null +++ b/crates/swc/tests/exec/issues-9xxx/9110/1/exec.js @@ -0,0 +1,36 @@ +function* test() { + while (!False()) { + // execute this line + while (!False()) { + // execute this line + break; + } + // execute this line + if (False()) { + // NOT execute this line + break; + } + + // execute this line + yield "correct"; + return; + } + + // NOT execute this line + yield "wrong"; + return; +} + +function False() { + return false; +} + +const t = test(); +expect(t.next()).toEqual({ + value: "correct", + done: false, +}); +expect(t.next()).toEqual({ + value: undefined, + done: true, +}); diff --git a/crates/swc_ecma_compat_es2015/src/generator.rs b/crates/swc_ecma_compat_es2015/src/generator.rs index 346e0c660f91..d3580655910f 100644 --- a/crates/swc_ecma_compat_es2015/src/generator.rs +++ b/crates/swc_ecma_compat_es2015/src/generator.rs @@ -1659,7 +1659,7 @@ impl Generator { self.emit_break(loop_label, None); self.end_loop_block(); } else { - node.visit_mut_children_with(self); + node.visit_mut_with(self); self.emit_stmt(node.into()); } @@ -2860,6 +2860,7 @@ impl Generator { /// Builds the statements for the generator function body. fn build_stmts(&mut self) -> Vec { if let Some(ops) = self.operations.clone() { + dbg!(&ops); for (op_index, _) in ops.iter().enumerate() { self.write_operation(op_index); } From 02533f439902a5a7e3711a63b7da234cf79adb94 Mon Sep 17 00:00:00 2001 From: CPunisher <1343316114@qq.com> Date: Mon, 28 Oct 2024 23:57:22 -0700 Subject: [PATCH 2/3] remove dbg --- crates/swc_ecma_compat_es2015/src/generator.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/swc_ecma_compat_es2015/src/generator.rs b/crates/swc_ecma_compat_es2015/src/generator.rs index d3580655910f..cf51237e8ff7 100644 --- a/crates/swc_ecma_compat_es2015/src/generator.rs +++ b/crates/swc_ecma_compat_es2015/src/generator.rs @@ -2860,7 +2860,6 @@ impl Generator { /// Builds the statements for the generator function body. fn build_stmts(&mut self) -> Vec { if let Some(ops) = self.operations.clone() { - dbg!(&ops); for (op_index, _) in ops.iter().enumerate() { self.write_operation(op_index); } From 0876eb422e4aea70ceed4577ef9f2f2cb9e0a3f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Tue, 29 Oct 2024 22:20:40 +0900 Subject: [PATCH 3/3] Create quick-actors-do.md --- .changeset/quick-actors-do.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/quick-actors-do.md diff --git a/.changeset/quick-actors-do.md b/.changeset/quick-actors-do.md new file mode 100644 index 000000000000..47c0e9d17108 --- /dev/null +++ b/.changeset/quick-actors-do.md @@ -0,0 +1,6 @@ +--- +swc_core: patch +swc_ecma_compat_es2015: patch +--- + +fix(es/generator): Fix code generation for `break` in nested while