Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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