Skip to content

Commit

Permalink
feat(transformer/var-declaration): add insert_var_with_init method
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Dec 5, 2024
1 parent f437658 commit 1541969
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/oxc_transformer/src/common/var_declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ impl<'a> VarDeclarationsStore<'a> {
self.insert_var_binding_pattern(pattern, init, ctx);
}

/// Add a `var` declaration with the given init expression to be inserted at top of
/// current enclosing statement block, given a `BoundIdentifier`.
#[expect(unused)]
#[inline]
pub fn insert_var_with_init(
&self,
binding: &BoundIdentifier<'a>,
init: Expression<'a>,
ctx: &TraverseCtx<'a>,
) {
let pattern = binding.create_binding_pattern(ctx);
self.insert_var_binding_pattern(pattern, Some(init), ctx);
}

/// Create a new [`BoundIdentifier`], add a var declaration to be inserted at the top of
/// the current enclosing statement block, and then return the [`BoundIdentifier`].
#[inline]
Expand Down

0 comments on commit 1541969

Please sign in to comment.