Skip to content

Commit 85ac3f7

Browse files
committed
refactor(transformer): arrow functions transform do not wrap function expressions in parentheses (#5824)
Wrapping a function expression in parentheses is unnecessary. Codegen already adds parentheses when printing a function expression as a statement expression. i.e. `(function() {});`.
1 parent 5901d2a commit 85ac3f7

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

crates/oxc_transformer/src/es2015/arrow_functions.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ impl<'a> Traverse<'a> for ArrowFunctions<'a> {
112112

113113
/// ```ts
114114
/// function a(){
115-
/// () => console.log(this);
115+
/// return () => console.log(this);
116116
/// }
117117
/// // to
118118
/// function a(){
119119
/// var _this = this;
120-
/// (function() { return console.log(_this); });
120+
/// return function() { return console.log(_this); };
121121
/// }
122122
/// ```
123123
/// Insert the var _this = this; statement outside the arrow function
@@ -306,10 +306,7 @@ impl<'a> ArrowFunctions<'a> {
306306
);
307307
new_function.scope_id.set(scope_id);
308308

309-
let expr = Expression::FunctionExpression(self.ctx.ast.alloc(new_function));
310-
// Avoid creating a function declaration.
311-
// `() => {};` => `(function () {});`
312-
self.ctx.ast.expression_parenthesized(SPAN, expr)
309+
Expression::FunctionExpression(self.ctx.ast.alloc(new_function))
313310
}
314311

315312
/// Insert `var _this = this;` at the top of the statements.

0 commit comments

Comments
 (0)