Skip to content

Commit

Permalink
fix(es/compat): Visit AssignExpr right branch in FnEnvHoister (#8633)
Browse files Browse the repository at this point in the history
**Related issue:**

- Closes #8632
  • Loading branch information
magic-akari committed Feb 13, 2024
1 parent 52b6fd8 commit e5d6de0
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
19 changes: 19 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8632/input/.swcrc
Original file line number Diff line number Diff line change
@@ -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
}
22 changes: 22 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8632/input/index.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
35 changes: 35 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8632/output/index.ts
Original file line number Diff line number Diff line change
@@ -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;
})();
}
}
2 changes: 1 addition & 1 deletion crates/swc_ecma_utils/src/function/fn_env_hoister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit e5d6de0

Please sign in to comment.