From 6ffbd78947f45527ed98c8c7bbdf921037181098 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Mon, 19 Aug 2024 21:09:12 +0000 Subject: [PATCH] fix(transformer): remove an `AstBuilder::copy` call from TS namespace transform (#4987) Replace an unsafe `AstBuilder::copy` call with `AstBuilder::move_expression` in TS namespace transform. --- crates/oxc_transformer/src/typescript/namespace.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/oxc_transformer/src/typescript/namespace.rs b/crates/oxc_transformer/src/typescript/namespace.rs index bb60be96b..ebe739443 100644 --- a/crates/oxc_transformer/src/typescript/namespace.rs +++ b/crates/oxc_transformer/src/typescript/namespace.rs @@ -460,7 +460,7 @@ impl<'a> TypeScript<'a> { let Some(property_name) = declarator.id.get_identifier() else { return; }; - if let Some(init) = &declarator.init { + if let Some(init) = &mut declarator.init { declarator.init = Some( self.ctx.ast.expression_assignment( SPAN, @@ -476,8 +476,7 @@ impl<'a> TypeScript<'a> { ), ) .into(), - // SAFETY: `ast.copy` is unsound! We need to fix. - unsafe { self.ctx.ast.copy(init) }, + self.ctx.ast.move_expression(init), ), ); }