From b75ecb788b6c4e257e26af9252582343350b98a9 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Fri, 21 Jul 2023 18:06:08 +0800 Subject: [PATCH] chore: clean code --- crates/swc_ecma_transforms_typescript/src/collect.rs | 10 ---------- crates/swc_ecma_transforms_typescript/src/lib.rs | 1 - .../src/strip_import_export.rs | 4 ++-- .../swc_ecma_transforms_typescript/src/transform.rs | 3 +++ .../swc_ecma_transforms_typescript/src/typescript.rs | 11 ++++------- 5 files changed, 9 insertions(+), 20 deletions(-) delete mode 100644 crates/swc_ecma_transforms_typescript/src/collect.rs diff --git a/crates/swc_ecma_transforms_typescript/src/collect.rs b/crates/swc_ecma_transforms_typescript/src/collect.rs deleted file mode 100644 index fc1c284d30c17..0000000000000 --- a/crates/swc_ecma_transforms_typescript/src/collect.rs +++ /dev/null @@ -1,10 +0,0 @@ -use swc_ecma_visit::Visit; - -/// 1. Collect all import binding and values usage required by strip_import -/// -/// 2. Collect all the information required by enum -/// -/// https://github.com/microsoft/TypeScript/pull/50528 -pub(crate) struct Collect; - -impl Visit for Collect {} diff --git a/crates/swc_ecma_transforms_typescript/src/lib.rs b/crates/swc_ecma_transforms_typescript/src/lib.rs index 91eac5d43a264..ba5aa1653e21d 100644 --- a/crates/swc_ecma_transforms_typescript/src/lib.rs +++ b/crates/swc_ecma_transforms_typescript/src/lib.rs @@ -2,7 +2,6 @@ #![allow(clippy::vec_box)] pub use self::strip::*; -mod collect; mod import_export_assign; mod inline_enum; mod macros; diff --git a/crates/swc_ecma_transforms_typescript/src/strip_import_export.rs b/crates/swc_ecma_transforms_typescript/src/strip_import_export.rs index 66d6498b8d9d9..6176dc08577e9 100644 --- a/crates/swc_ecma_transforms_typescript/src/strip_import_export.rs +++ b/crates/swc_ecma_transforms_typescript/src/strip_import_export.rs @@ -218,7 +218,7 @@ impl VisitMut for StripImportExport { n.visit_with(&mut usage_info); n.visit_with(&mut declare_info); - let mut strip_ts_import_equals = StripTsImportEquals::default(); + let mut strip_ts_import_equals = StripTsImportEquals; n.retain_mut(|module_item| match module_item { ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { @@ -306,7 +306,7 @@ impl VisitMut for StripImportExport { } fn visit_mut_script(&mut self, n: &mut Script) { - let mut visitor = StripTsImportEquals::default(); + let mut visitor = StripTsImportEquals; for stmt in n.body.iter_mut() { if let Stmt::Decl(Decl::TsModule(..)) = stmt { stmt.visit_mut_with(&mut visitor); diff --git a/crates/swc_ecma_transforms_typescript/src/transform.rs b/crates/swc_ecma_transforms_typescript/src/transform.rs index bde96e94015b3..19b611e919fee 100644 --- a/crates/swc_ecma_transforms_typescript/src/transform.rs +++ b/crates/swc_ecma_transforms_typescript/src/transform.rs @@ -45,6 +45,7 @@ pub(crate) struct Transform { unresolved_mark: Mark, import_export_assign_config: TsImportExportAssignConfig, + verbatim_module_syntax: bool, namespace_id: Option, } @@ -52,10 +53,12 @@ pub(crate) struct Transform { pub fn transform( unresolved_mark: Mark, import_export_assign_config: TsImportExportAssignConfig, + verbatim_module_syntax: bool, ) -> impl Fold + VisitMut { as_folder(Transform { unresolved_mark, import_export_assign_config, + verbatim_module_syntax, ..Default::default() }) } diff --git a/crates/swc_ecma_transforms_typescript/src/typescript.rs b/crates/swc_ecma_transforms_typescript/src/typescript.rs index 1ce411b0f29da..98cd7c12b0721 100644 --- a/crates/swc_ecma_transforms_typescript/src/typescript.rs +++ b/crates/swc_ecma_transforms_typescript/src/typescript.rs @@ -1,11 +1,11 @@ use serde::{Deserialize, Serialize}; use swc_common::Mark; use swc_ecma_ast::*; -use swc_ecma_visit::{as_folder, Fold, VisitMut, VisitMutWith, VisitWith}; +use swc_ecma_visit::{as_folder, Fold, VisitMut, VisitMutWith}; use crate::{ - collect::Collect, strip_import_export::StripImportExport, strip_type::StripType, - transform::transform, TsImportExportAssignConfig, + strip_import_export::StripImportExport, strip_type::StripType, transform::transform, + TsImportExportAssignConfig, }; #[derive(Debug, Default, Serialize, Deserialize)] @@ -56,13 +56,10 @@ impl VisitMut for TypeScript { n.visit_mut_with(&mut StripType::default()); - if !self.config.verbatim_module_syntax { - n.visit_with(&mut Collect); - } - n.visit_mut_with(&mut transform( self.unresolved_mark, self.config.import_export_assign_config, + self.config.verbatim_module_syntax, )); } }