Skip to content

Commit

Permalink
fix(transformer): arrow function transform: prevent stack getting out…
Browse files Browse the repository at this point in the history
… of sync
  • Loading branch information
overlookmotel committed Sep 21, 2024
1 parent d360337 commit 6d36544
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions crates/oxc_transformer/src/es2015/arrow_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,8 @@ impl<'a> Traverse<'a> for ArrowFunctions<'a> {
}
}

fn enter_function(&mut self, func: &mut Function<'a>, _ctx: &mut TraverseCtx<'a>) {
if func.body.is_some() {
self.this_var_stack.push(None);
}
fn enter_function(&mut self, _func: &mut Function<'a>, _ctx: &mut TraverseCtx<'a>) {
self.this_var_stack.push(None);
}

/// ```ts
Expand All @@ -140,12 +138,10 @@ impl<'a> Traverse<'a> for ArrowFunctions<'a> {
/// ```
/// Insert the var _this = this; statement outside the arrow function
fn exit_function(&mut self, func: &mut Function<'a>, _ctx: &mut TraverseCtx<'a>) {
let Some(body) = func.body.as_mut() else {
return;
};

let this_var = self.this_var_stack.pop().unwrap();
if let Some(this_var) = this_var {
let Some(body) = &mut func.body else { unreachable!() };

self.insert_this_var_statement_at_the_top_of_statements(
&mut body.statements,
&this_var,
Expand Down

0 comments on commit 6d36544

Please sign in to comment.