From cd56aa9dd81cf6bdc667c978f43ac6b5b5f7b7a3 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Wed, 19 Jun 2024 12:31:02 +0000 Subject: [PATCH] refactor(transformer): simplify TS export assignment transform (#3762) Remove unnecessary jump through a `ModuleDeclaration` visitor, and visit as `TSExportAssignment` directly. --- crates/oxc_transformer/src/lib.rs | 6 +++--- crates/oxc_transformer/src/typescript/mod.rs | 6 ------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index be0d86c56d16d..0706ad5537285 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -284,11 +284,11 @@ impl<'a> Traverse<'a> for Transformer<'a> { self.x0_typescript.transform_for_statement(stmt); } - fn enter_module_declaration( + fn enter_ts_export_assignment( &mut self, - decl: &mut ModuleDeclaration<'a>, + export_assignment: &mut TSExportAssignment<'a>, _ctx: &mut TraverseCtx<'a>, ) { - self.x0_typescript.transform_module_declaration(decl); + self.x0_typescript.transform_ts_export_assignment(export_assignment); } } diff --git a/crates/oxc_transformer/src/typescript/mod.rs b/crates/oxc_transformer/src/typescript/mod.rs index 847d9fa665f01..9941ed98c91fa 100644 --- a/crates/oxc_transformer/src/typescript/mod.rs +++ b/crates/oxc_transformer/src/typescript/mod.rs @@ -189,12 +189,6 @@ impl<'a> TypeScript<'a> { } } - pub fn transform_module_declaration(&mut self, module_decl: &mut ModuleDeclaration<'a>) { - if let ModuleDeclaration::TSExportAssignment(ts_export_assignment) = &mut *module_decl { - self.transform_ts_export_assignment(ts_export_assignment); - } - } - pub fn transform_jsx_element(&mut self, elem: &mut JSXElement<'a>) { self.annotations.transform_jsx_element(elem); }