Skip to content

Commit e5d6de0

Browse files
authoredFeb 13, 2024··
fix(es/compat): Visit AssignExpr right branch in FnEnvHoister (#8633)
**Related issue:** - Closes #8632
1 parent 52b6fd8 commit e5d6de0

File tree

4 files changed

+77
-1
lines changed

4 files changed

+77
-1
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"jsc": {
3+
"parser": {
4+
"syntax": "typescript",
5+
"tsx": false
6+
},
7+
"target": "es2015",
8+
"loose": false,
9+
"minify": {
10+
"compress": false,
11+
"mangle": false
12+
}
13+
},
14+
"module": {
15+
"type": "commonjs"
16+
},
17+
"minify": false,
18+
"isModule": true
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export class Test {
2+
public async bad(): Promise<void> {
3+
let foo = false;
4+
5+
[foo] = await Promise.all(
6+
[
7+
this.foo(),
8+
]
9+
);
10+
}
11+
12+
public async good(): Promise<void> {
13+
let [foo] = await Promise.all(
14+
[
15+
this.foo(),
16+
]);
17+
}
18+
19+
private async foo(): Promise<boolean> {
20+
return true;
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", {
3+
value: true
4+
});
5+
Object.defineProperty(exports, "Test", {
6+
enumerable: true,
7+
get: function() {
8+
return Test;
9+
}
10+
});
11+
const _async_to_generator = require("@swc/helpers/_/_async_to_generator");
12+
class Test {
13+
bad() {
14+
var _this = this;
15+
return _async_to_generator._(function*() {
16+
let foo = false;
17+
[foo] = yield Promise.all([
18+
_this.foo()
19+
]);
20+
})();
21+
}
22+
good() {
23+
var _this = this;
24+
return _async_to_generator._(function*() {
25+
let [foo] = yield Promise.all([
26+
_this.foo()
27+
]);
28+
})();
29+
}
30+
foo() {
31+
return _async_to_generator._(function*() {
32+
return true;
33+
})();
34+
}
35+
}

‎crates/swc_ecma_utils/src/function/fn_env_hoister.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ impl VisitMut for FnEnvHoister {
386386
}) => {
387387
let expr = match left {
388388
AssignTarget::Simple(e) => e,
389-
AssignTarget::Pat(e) => {
389+
AssignTarget::Pat(..) => {
390390
e.visit_mut_children_with(self);
391391
return;
392392
}

0 commit comments

Comments
 (0)
Please sign in to comment.