fix(es/compat): Visit AssignExpr right branch in FnEnvHoister (#8633)

**Related issue:**

- Closes #8632
This commit is contained in:
magic-akari 2024-02-13 13:12:41 +08:00 committed by GitHub
parent 52b6fd8808
commit e5d6de0ea9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 77 additions and 1 deletions

View File

@ -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
}

View File

@ -0,0 +1,22 @@
export class Test {
public async bad(): Promise<void> {
let foo = false;
[foo] = await Promise.all(
[
this.foo(),
]
);
}
public async good(): Promise<void> {
let [foo] = await Promise.all(
[
this.foo(),
]);
}
private async foo(): Promise<boolean> {
return true;
}
}

View File

@ -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;
})();
}
}

View File

@ -386,7 +386,7 @@ impl VisitMut for FnEnvHoister {
}) => { }) => {
let expr = match left { let expr = match left {
AssignTarget::Simple(e) => e, AssignTarget::Simple(e) => e,
AssignTarget::Pat(e) => { AssignTarget::Pat(..) => {
e.visit_mut_children_with(self); e.visit_mut_children_with(self);
return; return;
} }