Repository: swc-project/swc (rust)

Issue:
Break in a for await loop will cause a TypeError.
### Describe the bug

Break in a for await loop will cause a TypeError.

- `jsc.target`
  - `es5` ... Failed
  - `es2015` ... Failed
  - `es2016` ... Failed
  - `es2017` ... Success

### Input code

```typescript
async function* stream() {
  yield void 0;
}

async function main() {
  for await (const _ of stream()) {
    break;
  }
}

main();
```


### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false,
      "decorators": false,
      "dynamicImport": true
    },
    "transform": {
      "react": {
        "runtime": "automatic"
      }
    },
    "target": "es5",
    "preserveAllComments": true
  },
  "sourceMaps": true,
  "isModule": true
}
```


### Playground link

https://play.swc.rs/?version=1.2.186&code=H4sIAAAAAAAAA1WMMQqAMBAE%2B7xiS7Wyz2PkjAYOzR0kURHJ31UUwW4XZobSLg5%2BEZdZpUHKcaRQ1TgMsPM4D1iVB7TWFGPoRyMQy4t6jaCNOKNyKimjg%2Fqv9jBAf93JXrPctUe3J%2FZcHgqDAAAA&config=H4sIAAAAAAAAA0WOMQ7CMAxF7%2BK5K0s3xMTQQ1iui4LiOLIdRFX17qSogu3r6fl%2Fb%2FB0gnGDiuZsR%2FK1BL5hhFgrO1mqAQOEd7Rgdh5gZlLDUPM%2FWgtKortUtYAxrPHejwyLL2py9BojxTe0Ekm4L2ALFYxEsB822oO7AeyXvliN%2B0cvvuZ8UxEu4b9i12bEE9YTDZB80rllPpUPiq0WetgAAAA%3D

### Expected behavior

Nothing is output.

### Actual behavior

```
$ npx swc -q ./test.ts|node --input-type=module -
file:///tmp/tmp.F7UjrXfKFI/[eval1]:195
                    return _iteratorError.return();
                                          ^

TypeError: Cannot read properties of undefined (reading 'return')
    at _callee$ (file:///tmp/tmp.F7UjrXfKFI/[eval1]:195:43)
    at tryCatch (/tmp/tmp.F7UjrXfKFI/node_modules/regenerator-runtime/runtime.js:63:40)
    at Generator.invoke [as _invoke] (/tmp/tmp.F7UjrXfKFI/node_modules/regenerator-runtime/runtime.js:294:22)
    at Generator.next (/tmp/tmp.F7UjrXfKFI/node_modules/regenerator-runtime/runtime.js:119:21)
    at asyncGeneratorStep (file:///tmp/tmp.F7UjrXfKFI/[eval1]:98:28)
    at _next (file:///tmp/tmp.F7UjrXfKFI/[eval1]:116:17)

Node.js v18.1.0
```

### Version

1.2.186

### Additional context

I found this while using Next.js.
https://github.com/yskszk63/next-for-await-break

Pull request:
fix: `break` in for await loop
<!-- Note: CI script will automatically rebase your PR so please do not rebase unless required -->

<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. -->

**Description:**

<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->

**BREAKING CHANGE:**

<!--
If this PR introduces a breaking change, it must contain a notice for it to be included in the CHANGELOG. Add description or remove entirely if not breaking.

You may need to update `MIGRATION.md` for the breaking changes.
-->

**Related issue (if exists):**
- fix #4701 

Patch:
diff --git a/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs b/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs
index 71f22b915c..7f76bdc566 100644
--- a/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs
+++ b/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs
@@ -730,7 +730,7 @@ fn handle_await_for(stmt: &mut Stmt, is_async_generator: bool) {
                 delegate: false,
                 arg: Some(Box::new(Expr::Call(CallExpr {
                     span: DUMMY_SP,
-                    callee: iterator_error
+                    callee: iterator
                         .clone()
                         .make_member(quote_ident!("return"))
                         .as_callee(),


Test patch:
diff --git a/crates/swc/tests/fixture/issues-1xxx/1721/case1/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1721/case1/output/index.js
index e52051fafa..c2d8c0ebad 100644
--- a/crates/swc/tests/fixture/issues-1xxx/1721/case1/output/index.js
+++ b/crates/swc/tests/fixture/issues-1xxx/1721/case1/output/index.js
@@ -66,7 +66,7 @@ function _main() {
                         break;
                     }
                     _ctx.next = 21;
-                    return _iteratorError.return();
+                    return _iterator.return();
                 case 21:
                     _ctx.prev = 21;
                     if (!_didIteratorError) {
diff --git a/crates/swc/tests/fixture/issues-1xxx/1918/es2016/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1918/es2016/output/index.js
index 91a74d79c9..31e83cbc86 100644
--- a/crates/swc/tests/fixture/issues-1xxx/1918/es2016/output/index.js
+++ b/crates/swc/tests/fixture/issues-1xxx/1918/es2016/output/index.js
@@ -29,7 +29,7 @@ swcHelpers.asyncToGenerator(function*() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion && _iterator.return != null) {
-                        yield _iteratorError.return();
+                        yield _iterator.return();
                     }
                 } finally{
                     if (_didIteratorError) {
diff --git a/crates/swc/tests/fixture/issues-1xxx/1918/es5/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1918/es5/output/index.js
index 8f762a59f9..67a568004e 100644
--- a/crates/swc/tests/fixture/issues-1xxx/1918/es5/output/index.js
+++ b/crates/swc/tests/fixture/issues-1xxx/1918/es5/output/index.js
@@ -60,7 +60,7 @@ swcHelpers.asyncToGenerator(_regeneratorRuntime.default.mark(function _callee1()
                                     break;
                                 }
                                 _ctx.next = 21;
-                                return _iteratorError.return();
+                                return _iterator.return();
                             case 21:
                                 _ctx.prev = 21;
                                 if (!_didIteratorError) {
diff --git a/crates/swc/tests/tsc-references/emitter.forAwait_es2015.1.normal.js b/crates/swc/tests/tsc-references/emitter.forAwait_es2015.1.normal.js
index 9ee98d6486..4b0c5fe60c 100644
--- a/crates/swc/tests/tsc-references/emitter.forAwait_es2015.1.normal.js
+++ b/crates/swc/tests/tsc-references/emitter.forAwait_es2015.1.normal.js
@@ -21,7 +21,7 @@ function _f1() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion && _iterator.return != null) {
-                        yield _iteratorError.return();
+                        yield _iterator.return();
                     }
                 } finally{
                     if (_didIteratorError) {
@@ -53,7 +53,7 @@ function _f2() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion && _iterator.return != null) {
-                        yield _iteratorError.return();
+                        yield _iterator.return();
                     }
                 } finally{
                     if (_didIteratorError) {
@@ -85,7 +85,7 @@ function _f3() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion && _iterator.return != null) {
-                        yield _iteratorError.return();
+                        yield _iterator.return();
                     }
                 } finally{
                     if (_didIteratorError) {
@@ -117,7 +117,7 @@ function _f4() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion && _iterator.return != null) {
-                        yield _iteratorError.return();
+                        yield _iterator.return();
                     }
                 } finally{
                     if (_didIteratorError) {
@@ -151,7 +151,7 @@ function _f5() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion && _iterator.return != null) {
-                        yield _iteratorError.return();
+                        yield _iterator.return();
                     }
                 } finally{
                     if (_didIteratorError) {
@@ -185,7 +185,7 @@ function _f6() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion && _iterator.return != null) {
-                        yield _iteratorError.return();
+                        yield _iterator.return();
                     }
                 } finally{
                     if (_didIteratorError) {
@@ -219,7 +219,7 @@ function _f7() {
                 } finally{
                     try {
                         if (_iteratorAbruptCompletion && _iterator.return != null) {
-                            yield _iteratorError.return();
+                            yield _iterator.return();
                         }
                     } finally{
                         if (_didIteratorError) {
diff --git a/crates/swc/tests/tsc-references/emitter.forAwait_es5.1.normal.js b/crates/swc/tests/tsc-references/emitter.forAwait_es5.1.normal.js
index a075886167..ce76e69c91 100644
--- a/crates/swc/tests/tsc-references/emitter.forAwait_es5.1.normal.js
+++ b/crates/swc/tests/tsc-references/emitter.forAwait_es5.1.normal.js
@@ -48,7 +48,7 @@ function _f1() {
                         break;
                     }
                     _ctx.next = 22;
-                    return _iteratorError.return();
+                    return _iterator.return();
                 case 22:
                     _ctx.prev = 22;
                     if (!_didIteratorError) {
@@ -127,7 +127,7 @@ function _f2() {
                         break;
                     }
                     _ctx.next = 22;
-                    return _iteratorError.return();
+                    return _iterator.return();
                 case 22:
                     _ctx.prev = 22;
                     if (!_didIteratorError) {
@@ -206,7 +206,7 @@ function _f3() {
                         break;
                     }
                     _ctx.next = 22;
-                    return _iteratorError.return();
+                    return _iterator.return();
                 case 22:
                     _ctx.prev = 22;
                     if (!_didIteratorError) {
@@ -285,7 +285,7 @@ function _f4() {
                         break;
                     }
                     _ctx.next = 22;
-                    return _iteratorError.return();
+                    return _iterator.return();
                 case 22:
                     _ctx.prev = 22;
                     if (!_didIteratorError) {
@@ -364,7 +364,7 @@ function _f5() {
                         break;
                     }
                     _ctx.next = 24;
-                    return _iteratorError.return();
+                    return _iterator.return();
                 case 24:
                     _ctx.prev = 24;
                     if (!_didIteratorError) {
@@ -443,7 +443,7 @@ function _f6() {
                         break;
                     }
                     _ctx.next = 24;
-                    return _iteratorError.return();
+                    return _iterator.return();
                 case 24:
                     _ctx.prev = 24;
                     if (!_didIteratorError) {
@@ -524,7 +524,7 @@ function _f7() {
                         break;
                     }
                     _ctx.next = 22;
-                    return _iteratorError.return();
+                    return _iterator.return();
                 case 22:
                     _ctx.prev = 22;
                     if (!_didIteratorError) {
diff --git a/crates/swc/tests/tsc-references/generatorAssignability_es2015.1.normal.js b/crates/swc/tests/tsc-references/generatorAssignability_es2015.1.normal.js
index 728294bc59..06d1f1df6e 100644
--- a/crates/swc/tests/tsc-references/generatorAssignability_es2015.1.normal.js
+++ b/crates/swc/tests/tsc-references/generatorAssignability_es2015.1.normal.js
@@ -41,7 +41,7 @@ function _asyncfn() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion && _iterator.return != null) {
-                        yield _iteratorError.return();
+                        yield _iterator.return();
                     }
                 } finally{
                     if (_didIteratorError) {
@@ -64,7 +64,7 @@ function _asyncfn() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion1 && _iterator1.return != null) {
-                        yield _iteratorError1.return();
+                        yield _iterator1.return();
                     }
                 } finally{
                     if (_didIteratorError1) {
@@ -88,7 +88,7 @@ function _asyncfn() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion2 && _iterator2.return != null) {
-                        yield _iteratorError2.return();
+                        yield _iterator2.return();
                     }
                 } finally{
                     if (_didIteratorError2) {
@@ -111,7 +111,7 @@ function _asyncfn() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion3 && _iterator3.return != null) {
-                        yield _iteratorError3.return();
+                        yield _iterator3.return();
                     }
                 } finally{
                     if (_didIteratorError3) {
@@ -167,7 +167,7 @@ function _f3() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion && _iterator.return != null) {
-                        yield _iteratorError.return();
+                        yield _iterator.return();
                     }
                 } finally{
                     if (_didIteratorError) {
diff --git a/crates/swc/tests/tsc-references/generatorAssignability_es5.1.normal.js b/crates/swc/tests/tsc-references/generatorAssignability_es5.1.normal.js
index e6c5d77a9f..2ec946127d 100644
--- a/crates/swc/tests/tsc-references/generatorAssignability_es5.1.normal.js
+++ b/crates/swc/tests/tsc-references/generatorAssignability_es5.1.normal.js
@@ -106,7 +106,7 @@ function _asyncfn() {
                         break;
                     }
                     _ctx.next = 21;
-                    return _iteratorError5.return();
+                    return _iterator.return();
                 case 21:
                     _ctx.prev = 21;
                     if (!_didIteratorError5) {
@@ -155,7 +155,7 @@ function _asyncfn() {
                         break;
                     }
                     _ctx.next = 47;
-                    return _iteratorError2.return();
+                    return _iterator2.return();
                 case 47:
                     _ctx.prev = 47;
                     if (!_didIteratorError2) {
@@ -204,7 +204,7 @@ function _asyncfn() {
                         break;
                     }
                     _ctx.next = 73;
-                    return _iteratorError3.return();
+                    return _iterator3.return();
                 case 73:
                     _ctx.prev = 73;
                     if (!_didIteratorError3) {
@@ -253,7 +253,7 @@ function _asyncfn() {
                         break;
                     }
                     _ctx.next = 99;
-                    return _iteratorError4.return();
+                    return _iterator4.return();
                 case 99:
                     _ctx.prev = 99;
                     if (!_didIteratorError4) {
@@ -421,7 +421,7 @@ function _f3() {
                         break;
                     }
                     _ctx1.next = 23;
-                    return _iteratorError6.return();
+                    return _iterator.return();
                 case 23:
                     _ctx1.prev = 23;
                     if (!_didIteratorError6) {
diff --git a/crates/swc/tests/tsc-references/types.forAwait.es2018.1_es2015.1.normal.js b/crates/swc/tests/tsc-references/types.forAwait.es2018.1_es2015.1.normal.js
index 1dbb5ca571..c496282610 100644
--- a/crates/swc/tests/tsc-references/types.forAwait.es2018.1_es2015.1.normal.js
+++ b/crates/swc/tests/tsc-references/types.forAwait.es2018.1_es2015.1.normal.js
@@ -18,7 +18,7 @@ function _f1() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion && _iterator.return != null) {
-                        yield _iteratorError.return();
+                        yield _iterator.return();
                     }
                 } finally{
                     if (_didIteratorError) {
@@ -40,7 +40,7 @@ function _f1() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion1 && _iterator1.return != null) {
-                        yield _iteratorError1.return();
+                        yield _iterator1.return();
                     }
                 } finally{
                     if (_didIteratorError1) {
@@ -62,7 +62,7 @@ function _f1() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion2 && _iterator2.return != null) {
-                        yield _iteratorError2.return();
+                        yield _iterator2.return();
                     }
                 } finally{
                     if (_didIteratorError2) {
@@ -84,7 +84,7 @@ function _f1() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion3 && _iterator3.return != null) {
-                        yield _iteratorError3.return();
+                        yield _iterator3.return();
                     }
                 } finally{
                     if (_didIteratorError3) {
@@ -106,7 +106,7 @@ function _f1() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion4 && _iterator4.return != null) {
-                        yield _iteratorError4.return();
+                        yield _iterator4.return();
                     }
                 } finally{
                     if (_didIteratorError4) {
@@ -128,7 +128,7 @@ function _f1() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion5 && _iterator5.return != null) {
-                        yield _iteratorError5.return();
+                        yield _iterator5.return();
                     }
                 } finally{
                     if (_didIteratorError5) {
@@ -159,7 +159,7 @@ function _f2() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion && _iterator.return != null) {
-                        yield _iteratorError.return();
+                        yield _iterator.return();
                     }
                 } finally{
                     if (_didIteratorError) {
@@ -181,7 +181,7 @@ function _f2() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion6 && _iterator6.return != null) {
-                        yield _iteratorError6.return();
+                        yield _iterator6.return();
                     }
                 } finally{
                     if (_didIteratorError6) {
@@ -203,7 +203,7 @@ function _f2() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion7 && _iterator7.return != null) {
-                        yield _iteratorError7.return();
+                        yield _iterator7.return();
                     }
                 } finally{
                     if (_didIteratorError7) {
@@ -225,7 +225,7 @@ function _f2() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion8 && _iterator8.return != null) {
-                        yield _iteratorError8.return();
+                        yield _iterator8.return();
                     }
                 } finally{
                     if (_didIteratorError8) {
@@ -247,7 +247,7 @@ function _f2() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion9 && _iterator9.return != null) {
-                        yield _iteratorError9.return();
+                        yield _iterator9.return();
                     }
                 } finally{
                     if (_didIteratorError9) {
@@ -269,7 +269,7 @@ function _f2() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion10 && _iterator10.return != null) {
-                        yield _iteratorError10.return();
+                        yield _iterator10.return();
                     }
                 } finally{
                     if (_didIteratorError10) {
diff --git a/crates/swc/tests/tsc-references/types.forAwait.es2018.1_es5.1.normal.js b/crates/swc/tests/tsc-references/types.forAwait.es2018.1_es5.1.normal.js
index 265690b5d6..e2bbc35f51 100644
--- a/crates/swc/tests/tsc-references/types.forAwait.es2018.1_es5.1.normal.js
+++ b/crates/swc/tests/tsc-references/types.forAwait.es2018.1_es5.1.normal.js
@@ -45,7 +45,7 @@ function _f1() {
                         break;
                     }
                     _ctx.next = 22;
-                    return _iteratorError.return();
+                    return _iterator.return();
                 case 22:
                     _ctx.prev = 22;
                     if (!_didIteratorError) {
@@ -93,7 +93,7 @@ function _f1() {
                         break;
                     }
                     _ctx.next = 48;
-                    return _iteratorError1.return();
+                    return _iterator1.return();
                 case 48:
                     _ctx.prev = 48;
                     if (!_didIteratorError1) {
@@ -141,7 +141,7 @@ function _f1() {
                         break;
                     }
                     _ctx.next = 74;
-                    return _iteratorError2.return();
+                    return _iterator2.return();
                 case 74:
                     _ctx.prev = 74;
                     if (!_didIteratorError2) {
@@ -189,7 +189,7 @@ function _f1() {
                         break;
                     }
                     _ctx.next = 100;
-                    return _iteratorError3.return();
+                    return _iterator3.return();
                 case 100:
                     _ctx.prev = 100;
                     if (!_didIteratorError3) {
@@ -237,7 +237,7 @@ function _f1() {
                         break;
                     }
                     _ctx.next = 126;
-                    return _iteratorError4.return();
+                    return _iterator4.return();
                 case 126:
                     _ctx.prev = 126;
                     if (!_didIteratorError4) {
@@ -285,7 +285,7 @@ function _f1() {
                         break;
                     }
                     _ctx.next = 152;
-                    return _iteratorError5.return();
+                    return _iterator5.return();
                 case 152:
                     _ctx.prev = 152;
                     if (!_didIteratorError5) {
@@ -423,7 +423,7 @@ function _f2() {
                         break;
                     }
                     _ctx.next = 22;
-                    return _iteratorError.return();
+                    return _iterator.return();
                 case 22:
                     _ctx.prev = 22;
                     if (!_didIteratorError) {
@@ -471,7 +471,7 @@ function _f2() {
                         break;
                     }
                     _ctx.next = 48;
-                    return _iteratorError6.return();
+                    return _iterator6.return();
                 case 48:
                     _ctx.prev = 48;
                     if (!_didIteratorError6) {
@@ -519,7 +519,7 @@ function _f2() {
                         break;
                     }
                     _ctx.next = 74;
-                    return _iteratorError7.return();
+                    return _iterator7.return();
                 case 74:
                     _ctx.prev = 74;
                     if (!_didIteratorError7) {
@@ -567,7 +567,7 @@ function _f2() {
                         break;
                     }
                     _ctx.next = 100;
-                    return _iteratorError8.return();
+                    return _iterator8.return();
                 case 100:
                     _ctx.prev = 100;
                     if (!_didIteratorError8) {
@@ -615,7 +615,7 @@ function _f2() {
                         break;
                     }
                     _ctx.next = 126;
-                    return _iteratorError9.return();
+                    return _iterator9.return();
                 case 126:
                     _ctx.prev = 126;
                     if (!_didIteratorError9) {
@@ -663,7 +663,7 @@ function _f2() {
                         break;
                     }
                     _ctx.next = 152;
-                    return _iteratorError10.return();
+                    return _iterator10.return();
                 case 152:
                     _ctx.prev = 152;
                     if (!_didIteratorError10) {
diff --git a/crates/swc/tests/tsc-references/types.forAwait.es2018.2_es2015.1.normal.js b/crates/swc/tests/tsc-references/types.forAwait.es2018.2_es2015.1.normal.js
index dbaec51d84..c29c37cec9 100644
--- a/crates/swc/tests/tsc-references/types.forAwait.es2018.2_es2015.1.normal.js
+++ b/crates/swc/tests/tsc-references/types.forAwait.es2018.2_es2015.1.normal.js
@@ -19,7 +19,7 @@ function _f() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion && _iterator.return != null) {
-                        yield _iteratorError.return();
+                        yield _iterator.return();
                     }
                 } finally{
                     if (_didIteratorError) {
@@ -41,7 +41,7 @@ function _f() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion1 && _iterator1.return != null) {
-                        yield _iteratorError1.return();
+                        yield _iterator1.return();
                     }
                 } finally{
                     if (_didIteratorError1) {
@@ -63,7 +63,7 @@ function _f() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion2 && _iterator2.return != null) {
-                        yield _iteratorError2.return();
+                        yield _iterator2.return();
                     }
                 } finally{
                     if (_didIteratorError2) {
@@ -85,7 +85,7 @@ function _f() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion3 && _iterator3.return != null) {
-                        yield _iteratorError3.return();
+                        yield _iterator3.return();
                     }
                 } finally{
                     if (_didIteratorError3) {
diff --git a/crates/swc/tests/tsc-references/types.forAwait.es2018.2_es5.1.normal.js b/crates/swc/tests/tsc-references/types.forAwait.es2018.2_es5.1.normal.js
index 37bdc50e0c..3b8dbda6c0 100644
--- a/crates/swc/tests/tsc-references/types.forAwait.es2018.2_es5.1.normal.js
+++ b/crates/swc/tests/tsc-references/types.forAwait.es2018.2_es5.1.normal.js
@@ -46,7 +46,7 @@ function _f() {
                         break;
                     }
                     _ctx.next = 23;
-                    return _iteratorError.return();
+                    return _iterator.return();
                 case 23:
                     _ctx.prev = 23;
                     if (!_didIteratorError) {
@@ -94,7 +94,7 @@ function _f() {
                         break;
                     }
                     _ctx.next = 49;
-                    return _iteratorError1.return();
+                    return _iterator1.return();
                 case 49:
                     _ctx.prev = 49;
                     if (!_didIteratorError1) {
@@ -142,7 +142,7 @@ function _f() {
                         break;
                     }
                     _ctx.next = 75;
-                    return _iteratorError2.return();
+                    return _iterator2.return();
                 case 75:
                     _ctx.prev = 75;
                     if (!_didIteratorError2) {
@@ -190,7 +190,7 @@ function _f() {
                         break;
                     }
                     _ctx.next = 101;
-                    return _iteratorError3.return();
+                    return _iterator3.return();
                 case 101:
                     _ctx.prev = 101;
                     if (!_didIteratorError3) {
diff --git a/crates/swc/tests/tsc-references/types.forAwait.es2018.3_es2015.1.normal.js b/crates/swc/tests/tsc-references/types.forAwait.es2018.3_es2015.1.normal.js
index 3b6bd43f02..699b59a76b 100644
--- a/crates/swc/tests/tsc-references/types.forAwait.es2018.3_es2015.1.normal.js
+++ b/crates/swc/tests/tsc-references/types.forAwait.es2018.3_es2015.1.normal.js
@@ -21,7 +21,7 @@ function _f1() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion && _iterator.return != null) {
-                        yield _iteratorError.return();
+                        yield _iterator.return();
                     }
                 } finally{
                     if (_didIteratorError) {
@@ -43,7 +43,7 @@ function _f1() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion1 && _iterator1.return != null) {
-                        yield _iteratorError1.return();
+                        yield _iterator1.return();
                     }
                 } finally{
                     if (_didIteratorError1) {
@@ -74,7 +74,7 @@ function _f2() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion && _iterator.return != null) {
-                        yield _iteratorError.return();
+                        yield _iterator.return();
                     }
                 } finally{
                     if (_didIteratorError) {
@@ -96,7 +96,7 @@ function _f2() {
             } finally{
                 try {
                     if (_iteratorAbruptCompletion2 && _iterator2.return != null) {
-                        yield _iteratorError2.return();
+                        yield _iterator2.return();
                     }
                 } finally{
                     if (_didIteratorError2) {
diff --git a/crates/swc/tests/tsc-references/types.forAwait.es2018.3_es5.1.normal.js b/crates/swc/tests/tsc-references/types.forAwait.es2018.3_es5.1.normal.js
index 436525d6cc..3c680091cf 100644
--- a/crates/swc/tests/tsc-references/types.forAwait.es2018.3_es5.1.normal.js
+++ b/crates/swc/tests/tsc-references/types.forAwait.es2018.3_es5.1.normal.js
@@ -48,7 +48,7 @@ function _f1() {
                         break;
                     }
                     _ctx.next = 22;
-                    return _iteratorError.return();
+                    return _iterator.return();
                 case 22:
                     _ctx.prev = 22;
                     if (!_didIteratorError) {
@@ -96,7 +96,7 @@ function _f1() {
                         break;
                     }
                     _ctx.next = 48;
-                    return _iteratorError1.return();
+                    return _iterator1.return();
                 case 48:
                     _ctx.prev = 48;
                     if (!_didIteratorError1) {
@@ -186,7 +186,7 @@ function _f2() {
                         break;
                     }
                     _ctx.next = 22;
-                    return _iteratorError.return();
+                    return _iterator.return();
                 case 22:
                     _ctx.prev = 22;
                     if (!_didIteratorError) {
@@ -234,7 +234,7 @@ function _f2() {
                         break;
                     }
                     _ctx.next = 48;
-                    return _iteratorError2.return();
+                    return _iterator2.return();
                 case 48:
                     _ctx.prev = 48;
                     if (!_didIteratorError2) {
diff --git a/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs b/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs
index d07d6acafa..7519f996f5 100644
--- a/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs
+++ b/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs
@@ -2524,7 +2524,7 @@ test!(
                 } finally{
                     try {
                         if (_iteratorAbruptCompletion && _iterator.return != null) {
-                            yield _iteratorError.return();
+                            yield _iterator.return();
                         }
                     } finally{
                         if (_didIteratorError) {