Skip to content

Commit

Permalink
refactor(transformer): add `StatementInjectorStore::insert_many_befor…
Browse files Browse the repository at this point in the history
…e` method (oxc-project#6857)

This method is not used yet, but it seems natural to provide it as a counterpart to `insert_many_after`.
  • Loading branch information
overlookmotel committed Oct 24, 2024
1 parent 7339dde commit c19996c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/oxc_transformer/src/common/statement_injector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ impl<'a> StatementInjectorStore<'a> {
adjacent_stmts.push(AdjacentStatement { stmt, direction: Direction::After });
}

/// Add multiple statements to be inserted immediately before the target statement.
#[expect(dead_code)]
pub fn insert_many_before<S>(&self, target: Address, stmts: S)
where
S: IntoIterator<Item = Statement<'a>>,
{
let mut insertions = self.insertions.borrow_mut();
let adjacent_stmts = insertions.entry(target).or_default();
adjacent_stmts.splice(
0..0,
stmts.into_iter().map(|stmt| AdjacentStatement { stmt, direction: Direction::Before }),
);
}

/// Add multiple statements to be inserted immediately after the target statement.
pub fn insert_many_after<S>(&self, target: Address, stmts: S)
where
Expand Down

0 comments on commit c19996c

Please sign in to comment.