From 8f6a528c40816ae2d6958f57534df8f41d37f52e Mon Sep 17 00:00:00 2001 From: magic-akari Date: Fri, 7 Apr 2023 20:11:38 +0800 Subject: [PATCH] Handle class method overloads --- .../src/strip_type.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/crates/swc_ecma_transforms_typescript/src/strip_type.rs b/crates/swc_ecma_transforms_typescript/src/strip_type.rs index 0516b2f93becb..5dd99d879bf83 100644 --- a/crates/swc_ecma_transforms_typescript/src/strip_type.rs +++ b/crates/swc_ecma_transforms_typescript/src/strip_type.rs @@ -154,6 +154,35 @@ impl VisitMut for StripType { n.visit_mut_children_with(self); } + + fn visit_mut_class_members(&mut self, n: &mut Vec) { + n.retain(|member| match member { + ClassMember::TsIndexSignature(..) => false, + ClassMember::Constructor(Constructor { body: None, .. }) => false, + + ClassMember::Method(ClassMethod { + is_abstract, + function, + .. + }) + | ClassMember::PrivateMethod(PrivateMethod { + is_abstract, + function, + .. + }) => !is_abstract && function.body.is_some(), + + ClassMember::ClassProp( + ClassProp { declare: true, .. } + | ClassProp { + is_abstract: true, .. + }, + ) => false, + + _ => true, + }); + + n.visit_mut_children_with(self); + } } impl StripType {