From c19996c2e71021f11e784c48dee759ab7f3c8b4d Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:38:55 +0000 Subject: [PATCH] refactor(transformer): add `StatementInjectorStore::insert_many_before` method (#6857) This method is not used yet, but it seems natural to provide it as a counterpart to `insert_many_after`. --- .../src/common/statement_injector.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/oxc_transformer/src/common/statement_injector.rs b/crates/oxc_transformer/src/common/statement_injector.rs index 84c93a2da7dce..52bcb988600ed 100644 --- a/crates/oxc_transformer/src/common/statement_injector.rs +++ b/crates/oxc_transformer/src/common/statement_injector.rs @@ -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(&self, target: Address, stmts: S) + where + S: IntoIterator>, + { + 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(&self, target: Address, stmts: S) where