From 85ac3f749aa663bc8c79b4773fdc2bbfabf2cf14 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Tue, 17 Sep 2024 14:11:05 +0000 Subject: [PATCH] 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() {});`. --- crates/oxc_transformer/src/es2015/arrow_functions.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/crates/oxc_transformer/src/es2015/arrow_functions.rs b/crates/oxc_transformer/src/es2015/arrow_functions.rs index 5dc2b055a..0fa8e6901 100644 --- a/crates/oxc_transformer/src/es2015/arrow_functions.rs +++ b/crates/oxc_transformer/src/es2015/arrow_functions.rs @@ -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.