Skip to content

Commit

Permalink
refactor(transformer): StatementInjectorStore::insert_many_after ta…
Browse files Browse the repository at this point in the history
…ke an iterator (#6856)

Follow-on after #6654.

Taking an `IntoIterator` avoids caller needing to construct a temporary `Vec`.
  • Loading branch information
overlookmotel committed Oct 24, 2024
1 parent a47c70e commit 7339dde
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 4 additions & 1 deletion crates/oxc_transformer/src/common/statement_injector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ impl<'a> StatementInjectorStore<'a> {
}

/// Add multiple statements to be inserted immediately after the target statement.
pub fn insert_many_after(&self, target: Address, stmts: Vec<Statement<'a>>) {
pub fn insert_many_after<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.extend(
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_transformer/src/typescript/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,7 @@ impl<'a, 'ctx> Traverse<'a> for TypeScriptAnnotations<'a, 'ctx> {
stmt.address(),
self.assignments
.iter()
.map(|assignment| assignment.create_this_property_assignment(ctx))
.collect::<Vec<_>>(),
.map(|assignment| assignment.create_this_property_assignment(ctx)),
);
self.has_super_call = true;
}
Expand Down

0 comments on commit 7339dde

Please sign in to comment.