Skip to content

Commit

Permalink
refactor(transformer): arrow functions transform do not wrap function…
Browse files Browse the repository at this point in the history
… expressions in parentheses
  • Loading branch information
overlookmotel committed Sep 17, 2024
1 parent 5901d2a commit 9cde4c7
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions crates/oxc_transformer/src/es2015/arrow_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 9cde4c7

Please sign in to comment.