From cca7440d4bc6f11710ec5a4862b5409b9daff855 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Mon, 19 Aug 2024 21:09:14 +0000 Subject: [PATCH] refactor(ast): replace `AstBuilder::move_statement_vec` with `move_vec` (#4988) Replace `AstBuilder::move_statement_vec` with a general `move_vec` method which handles any kind of `Vec`. --- crates/oxc_ast/src/ast_builder_impl.rs | 10 +++++----- crates/oxc_transformer/src/typescript/namespace.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/oxc_ast/src/ast_builder_impl.rs b/crates/oxc_ast/src/ast_builder_impl.rs index 3dc648715e040..f4a7d5c79e230 100644 --- a/crates/oxc_ast/src/ast_builder_impl.rs +++ b/crates/oxc_ast/src/ast_builder_impl.rs @@ -82,11 +82,6 @@ impl<'a> AstBuilder<'a> { mem::replace(stmt, Statement::EmptyStatement(self.alloc(empty_stmt))) } - #[inline] - pub fn move_statement_vec(self, stmts: &mut Vec<'a, Statement<'a>>) -> Vec<'a, Statement<'a>> { - mem::replace(stmts, self.vec()) - } - #[inline] pub fn move_assignment_target(self, target: &mut AssignmentTarget<'a>) -> AssignmentTarget<'a> { let dummy = self.simple_assignment_target_identifier_reference(Span::default(), ""); @@ -105,6 +100,11 @@ impl<'a> AstBuilder<'a> { mem::replace(decl, empty_decl) } + #[inline] + pub fn move_vec(self, vec: &mut Vec<'a, T>) -> Vec<'a, T> { + mem::replace(vec, self.vec()) + } + /* ---------- Constructors ---------- */ /// `void 0` diff --git a/crates/oxc_transformer/src/typescript/namespace.rs b/crates/oxc_transformer/src/typescript/namespace.rs index ebe739443a0e5..f791d1469a526 100644 --- a/crates/oxc_transformer/src/typescript/namespace.rs +++ b/crates/oxc_transformer/src/typescript/namespace.rs @@ -37,7 +37,7 @@ impl<'a> TypeScript<'a> { // every time a namespace declaration is encountered. let mut new_stmts = self.ctx.ast.vec(); - for stmt in self.ctx.ast.move_statement_vec(&mut program.body) { + for stmt in self.ctx.ast.move_vec(&mut program.body) { match stmt { Statement::TSModuleDeclaration(decl) => { if !decl.declare {