From 2d4f3e9708cdaa8c663d90ff3068db5281f371db Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 14 May 2024 15:46:34 +0200 Subject: [PATCH] chore: remove unused, always empty fields from TsPropertySignature TsPropertySignature can not have params, type params, or an initializer. --- crates/swc_ecma_ast/src/typescript.rs | 5 ----- crates/swc_ecma_codegen/src/typescript.rs | 9 --------- crates/swc_ecma_parser/src/parser/typescript.rs | 3 --- crates/swc_ecma_transforms_base/src/resolver/mod.rs | 3 --- crates/swc_ecma_visit/src/lib.rs | 3 --- crates/swc_estree_ast/src/typescript.rs | 2 -- crates/swc_estree_compat/src/babelify/typescript.rs | 1 - 7 files changed, 26 deletions(-) diff --git a/crates/swc_ecma_ast/src/typescript.rs b/crates/swc_ecma_ast/src/typescript.rs index d86dad68d79df..e9df5168746a7 100644 --- a/crates/swc_ecma_ast/src/typescript.rs +++ b/crates/swc_ecma_ast/src/typescript.rs @@ -185,13 +185,8 @@ pub struct TsPropertySignature { pub key: Box, pub computed: bool, pub optional: bool, - #[cfg_attr(feature = "serde-impl", serde(default))] - pub init: Option>, - pub params: Vec, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))] pub type_ann: Option>, - #[cfg_attr(feature = "serde-impl", serde(default))] - pub type_params: Option>, } #[ast_node("TsGetterSignature")] diff --git a/crates/swc_ecma_codegen/src/typescript.rs b/crates/swc_ecma_codegen/src/typescript.rs index 88c8abdf45763..8516420215ea3 100644 --- a/crates/swc_ecma_codegen/src/typescript.rs +++ b/crates/swc_ecma_codegen/src/typescript.rs @@ -741,8 +741,6 @@ where punct!("?"); } - emit!(n.type_params); - // punct!("("); // self.emit_list(n.span, Some(&n.params), ListFormat::Parameters)?; // punct!(")"); @@ -752,13 +750,6 @@ where formatting_space!(); emit!(type_ann); } - - if let Some(init) = &n.init { - formatting_space!(); - punct!("="); - formatting_space!(); - emit!(init); - } } #[emitter] diff --git a/crates/swc_ecma_parser/src/parser/typescript.rs b/crates/swc_ecma_parser/src/parser/typescript.rs index dc960d7c38bed..246ee016ee3e4 100644 --- a/crates/swc_ecma_parser/src/parser/typescript.rs +++ b/crates/swc_ecma_parser/src/parser/typescript.rs @@ -1449,9 +1449,6 @@ impl Parser { readonly, key, optional, - init: None, - type_params: None, - params: vec![], type_ann, })) } diff --git a/crates/swc_ecma_transforms_base/src/resolver/mod.rs b/crates/swc_ecma_transforms_base/src/resolver/mod.rs index f2e4e438e72c0..9a8f766ee3cc3 100644 --- a/crates/swc_ecma_transforms_base/src/resolver/mod.rs +++ b/crates/swc_ecma_transforms_base/src/resolver/mod.rs @@ -1401,9 +1401,6 @@ impl<'a> VisitMut for Resolver<'a> { self.with_child(ScopeKind::Fn, |child| { child.in_type = true; - n.type_params.visit_mut_with(child); - n.init.visit_mut_with(child); - n.params.visit_mut_with(child); n.type_ann.visit_mut_with(child); }); } diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index 8287239570dfb..ba26449892002 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -1531,10 +1531,7 @@ define!({ pub key: Box, pub computed: bool, pub optional: bool, - pub init: Option>, - pub params: Vec, pub type_ann: Option>, - pub type_params: Option>, } pub struct TsGetterSignature { diff --git a/crates/swc_estree_ast/src/typescript.rs b/crates/swc_estree_ast/src/typescript.rs index 3be4a8a1b1f51..d57facfb4d8c9 100644 --- a/crates/swc_estree_ast/src/typescript.rs +++ b/crates/swc_estree_ast/src/typescript.rs @@ -289,8 +289,6 @@ pub struct TSPropertySignature { #[serde(default)] pub type_annotation: Option>, #[serde(default)] - pub initializer: Option>, - #[serde(default)] pub computed: Option, #[serde(default)] pub optional: Option, diff --git a/crates/swc_estree_compat/src/babelify/typescript.rs b/crates/swc_estree_compat/src/babelify/typescript.rs index 5d91715521a4e..ed4c2d7697965 100644 --- a/crates/swc_estree_compat/src/babelify/typescript.rs +++ b/crates/swc_estree_compat/src/babelify/typescript.rs @@ -261,7 +261,6 @@ impl Babelify for TsPropertySignature { type_annotation: self .type_ann .map(|ann| Box::alloc().init(ann.babelify(ctx))), - initializer: self.init.map(|i| Box::alloc().init(i.babelify(ctx).into())), computed: Some(self.computed), optional: Some(self.optional), readonly: Some(self.readonly),