Skip to content

Commit 9dfdfa6

Browse files
authored
fix(es/fixer): Fix a bug with awaited arrow fn expression (#10555)
**Description:** The minifier currently produces invalid syntax for awaited arrow expressions, for example: ```js await (() => { console.log("foo") }); ``` is minified into the following invalid syntax (missing wrapping parens): ```js await ()=>{ console.log("foo"); }; ``` https://play.swc.rs/?version=1.11.29&code=H4sIAAAAAAAAA0ssT8wsUdDQ0FSwtVOoVkjOzyvOz0nVy8lP11BKy89X0lSo1bQGAMCbrPQlAAAA&config=H4sIAAAAAAAAA1VPOw6DMAzdc4rIc4cKVR16hx7CSg0Kyk9xkBoh7k6AhJbN7%2Bdnz0JKGFnBS85lLCBgZIonLgxnl%2FBbGCBlkVXUIcGtqSNvUo%2BGaaeWQ4GEcaC0p7i7d4%2BaAOM9U0tUzmqn%2B%2FzfqbwNkZivxs2KbjB0bRS1Faz%2FTLtYf0k50HHBE36mVnYuBs3vlkxxIrGsmdxHnRcBAAA%3D
1 parent 6807643 commit 9dfdfa6

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

.changeset/big-otters-crash.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_core: patch
3+
swc_ecma_transforms_base: patch
4+
---
5+
6+
Fix minifier bug with awaited arrow fn expression
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
await (() => {
2+
console.log("non-IIFE");
3+
});
4+
5+
await (() => {
6+
console.log("IIFE");
7+
})();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
await (()=>{
2+
console.log("non-IIFE");
3+
}), await void console.log("IIFE");

crates/swc_ecma_transforms_base/src/fixer.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,11 @@ impl VisitMut for Fixer<'_> {
213213
self.ctx = old;
214214

215215
match &*expr.arg {
216-
Expr::Cond(..) | Expr::Assign(..) | Expr::Bin(..) | Expr::Yield(..) => {
217-
self.wrap(&mut expr.arg)
218-
}
216+
Expr::Cond(..)
217+
| Expr::Assign(..)
218+
| Expr::Bin(..)
219+
| Expr::Yield(..)
220+
| Expr::Arrow(..) => self.wrap(&mut expr.arg),
219221
_ => {}
220222
}
221223
}

0 commit comments

Comments
 (0)