From e5d6de0ea9fbab0e36791f59b58d6d2c76809ea5 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Tue, 13 Feb 2024 13:12:41 +0800 Subject: [PATCH] fix(es/compat): Visit AssignExpr right branch in FnEnvHoister (#8633) **Related issue:** - Closes #8632 --- .../fixture/issues-8xxx/8632/input/.swcrc | 19 ++++++++++ .../fixture/issues-8xxx/8632/input/index.ts | 22 ++++++++++++ .../fixture/issues-8xxx/8632/output/index.ts | 35 +++++++++++++++++++ .../src/function/fn_env_hoister.rs | 2 +- 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 crates/swc/tests/fixture/issues-8xxx/8632/input/.swcrc create mode 100644 crates/swc/tests/fixture/issues-8xxx/8632/input/index.ts create mode 100644 crates/swc/tests/fixture/issues-8xxx/8632/output/index.ts diff --git a/crates/swc/tests/fixture/issues-8xxx/8632/input/.swcrc b/crates/swc/tests/fixture/issues-8xxx/8632/input/.swcrc new file mode 100644 index 00000000000..ec753bb2de7 --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8632/input/.swcrc @@ -0,0 +1,19 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript", + "tsx": false + }, + "target": "es2015", + "loose": false, + "minify": { + "compress": false, + "mangle": false + } + }, + "module": { + "type": "commonjs" + }, + "minify": false, + "isModule": true +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-8xxx/8632/input/index.ts b/crates/swc/tests/fixture/issues-8xxx/8632/input/index.ts new file mode 100644 index 00000000000..f2046c87694 --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8632/input/index.ts @@ -0,0 +1,22 @@ +export class Test { + public async bad(): Promise { + let foo = false; + + [foo] = await Promise.all( + [ + this.foo(), + ] + ); + } + + public async good(): Promise { + let [foo] = await Promise.all( + [ + this.foo(), + ]); + } + + private async foo(): Promise { + return true; + } +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-8xxx/8632/output/index.ts b/crates/swc/tests/fixture/issues-8xxx/8632/output/index.ts new file mode 100644 index 00000000000..ba5926a8caa --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8632/output/index.ts @@ -0,0 +1,35 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "Test", { + enumerable: true, + get: function() { + return Test; + } +}); +const _async_to_generator = require("@swc/helpers/_/_async_to_generator"); +class Test { + bad() { + var _this = this; + return _async_to_generator._(function*() { + let foo = false; + [foo] = yield Promise.all([ + _this.foo() + ]); + })(); + } + good() { + var _this = this; + return _async_to_generator._(function*() { + let [foo] = yield Promise.all([ + _this.foo() + ]); + })(); + } + foo() { + return _async_to_generator._(function*() { + return true; + })(); + } +} diff --git a/crates/swc_ecma_utils/src/function/fn_env_hoister.rs b/crates/swc_ecma_utils/src/function/fn_env_hoister.rs index 57755e9c8ca..11d9126cf86 100644 --- a/crates/swc_ecma_utils/src/function/fn_env_hoister.rs +++ b/crates/swc_ecma_utils/src/function/fn_env_hoister.rs @@ -386,7 +386,7 @@ impl VisitMut for FnEnvHoister { }) => { let expr = match left { AssignTarget::Simple(e) => e, - AssignTarget::Pat(e) => { + AssignTarget::Pat(..) => { e.visit_mut_children_with(self); return; }