Skip to content

Commit

Permalink
fix(transformer): arrow func transform maintain scope ID
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Jun 11, 2024
1 parent 6143b5f commit c1601d8
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions crates/oxc_transformer/src/es2015/arrow_functions.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::cell::Cell;

use oxc_allocator::Vec;
use oxc_ast::ast::*;
use oxc_span::{Atom, SPAN};
Expand Down Expand Up @@ -154,21 +156,22 @@ impl<'a> ArrowFunctions<'a> {
}
}

let new_function = self.ctx.ast.function(
FunctionType::FunctionExpression,
arrow_function_expr.span,
None,
false,
arrow_function_expr.r#async,
None,
self.ctx.ast.copy(&arrow_function_expr.params),
Some(body),
self.ctx.ast.copy(&arrow_function_expr.type_parameters),
self.ctx.ast.copy(&arrow_function_expr.return_type),
Modifiers::empty(),
);

Expression::FunctionExpression(new_function)
let new_function = Function {
r#type: FunctionType::FunctionExpression,
span: arrow_function_expr.span,
id: None,
generator: false,
r#async: arrow_function_expr.r#async,
this_param: None,
params: self.ctx.ast.copy(&arrow_function_expr.params),
body: Some(body),
type_parameters: self.ctx.ast.copy(&arrow_function_expr.type_parameters),
return_type: self.ctx.ast.copy(&arrow_function_expr.return_type),
modifiers: Modifiers::empty(),
scope_id: Cell::new(arrow_function_expr.scope_id.get()),
};

Expression::FunctionExpression(self.ctx.ast.alloc(new_function))
}

pub fn transform_expression(&mut self, expr: &mut Expression<'a>) {
Expand Down

0 comments on commit c1601d8

Please sign in to comment.