refactor(transformer): StatementInjectorStore::insert_many_after take an iterator (#6856)

Follow-on after #6654.

Taking an `IntoIterator` avoids caller needing to construct a temporary `Vec`.
This commit is contained in:
overlookmotel 2024-10-24 12:38:54 +00:00
parent a47c70e425
commit 7339dde473
2 changed files with 5 additions and 3 deletions

View file

@ -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(

View file

@ -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;
}