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() {});`.
This commit is contained in:
overlookmotel 2024-09-17 14:11:05 +00:00
parent 5901d2a0f1
commit 85ac3f749a

View file

@ -112,12 +112,12 @@ impl<'a> Traverse<'a> for ArrowFunctions<'a> {
/// ```ts
/// function a(){
/// () => console.log(this);
/// return () => console.log(this);
/// }
/// // to
/// function a(){
/// var _this = this;
/// (function() { return console.log(_this); });
/// return function() { return console.log(_this); };
/// }
/// ```
/// Insert the var _this = this; statement outside the arrow function
@ -306,10 +306,7 @@ impl<'a> ArrowFunctions<'a> {
);
new_function.scope_id.set(scope_id);
let expr = Expression::FunctionExpression(self.ctx.ast.alloc(new_function));
// Avoid creating a function declaration.
// `() => {};` => `(function () {});`
self.ctx.ast.expression_parenthesized(SPAN, expr)
Expression::FunctionExpression(self.ctx.ast.alloc(new_function))
}
/// Insert `var _this = this;` at the top of the statements.