Skip to content

Commit

Permalink
refactor(transformer): make branch more predictable in arrow function…
Browse files Browse the repository at this point in the history
… transform
  • Loading branch information
overlookmotel committed Sep 17, 2024
1 parent 14297fd commit 33f255c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crates/oxc_transformer/src/es2015/arrow_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ impl<'a> ArrowFunctions<'a> {
Self {
ctx,
_options: options,
// Initial entry for `Program` scope
// Initial entries for `Program` scope
this_var_stack: vec![None],
inside_arrow_function_stack: vec![],
inside_arrow_function_stack: vec![false],
}
}
}

impl<'a> Traverse<'a> for ArrowFunctions<'a> {
/// Insert `var _this = this;` for the global scope.
fn exit_program(&mut self, program: &mut Program<'a>, _ctx: &mut TraverseCtx<'a>) {
debug_assert!(self.inside_arrow_function_stack.is_empty());
debug_assert!(self.inside_arrow_function_stack.len() == 1);

assert!(self.this_var_stack.len() == 1);
let this_var = self.this_var_stack.pop().unwrap();
Expand Down Expand Up @@ -238,7 +238,7 @@ impl<'a> Traverse<'a> for ArrowFunctions<'a> {

impl<'a> ArrowFunctions<'a> {
fn is_inside_arrow_function(&self) -> bool {
self.inside_arrow_function_stack.last().copied().unwrap_or(false)
*self.inside_arrow_function_stack.last().unwrap()
}

fn get_this_name(&mut self, ctx: &mut TraverseCtx<'a>) -> BoundIdentifier<'a> {
Expand Down

0 comments on commit 33f255c

Please sign in to comment.