From 78500af546ea3c92f016c729e173c66fccbe46ed Mon Sep 17 00:00:00 2001 From: CPunisher <1343316114@qq.com> Date: Fri, 25 Oct 2024 11:53:48 +0800 Subject: [PATCH] fix(typescript): Check whether the method is abstract when checking `is_overload` (#9678) **Related issue:** - Closes https://github.com/swc-project/swc/issues/9656 --- .changeset/fair-maps-move.md | 6 ++++++ crates/swc_typescript/src/fast_dts/mod.rs | 2 +- crates/swc_typescript/tests/fast_dts_deno.rs | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 .changeset/fair-maps-move.md diff --git a/.changeset/fair-maps-move.md b/.changeset/fair-maps-move.md new file mode 100644 index 000000000000..317919d90c76 --- /dev/null +++ b/.changeset/fair-maps-move.md @@ -0,0 +1,6 @@ +--- +swc_core: patch +swc_typescript: patch +--- + +fix(typescript): Check whether the method is abstract when checking `is_overload` diff --git a/crates/swc_typescript/src/fast_dts/mod.rs b/crates/swc_typescript/src/fast_dts/mod.rs index 3403619bd3d2..3e61548518f2 100644 --- a/crates/swc_typescript/src/fast_dts/mod.rs +++ b/crates/swc_typescript/src/fast_dts/mod.rs @@ -758,7 +758,7 @@ impl FastDts { } } ClassMember::Method(method) => { - let is_overload = method.function.body.is_none(); + let is_overload = method.function.body.is_none() && !method.is_abstract; if !prev_is_overload || is_overload { prev_is_overload = is_overload; true diff --git a/crates/swc_typescript/tests/fast_dts_deno.rs b/crates/swc_typescript/tests/fast_dts_deno.rs index a35dfd279eb1..76eb1ca40093 100644 --- a/crates/swc_typescript/tests/fast_dts_deno.rs +++ b/crates/swc_typescript/tests/fast_dts_deno.rs @@ -218,6 +218,26 @@ fn dts_class_decl_prop_infer_test() { ); } +#[test] +fn dts_class_abstract_method_test() { + transform_dts_test( + r#"export abstract class Manager { + protected abstract A(): void; + protected B(): void { + console.log("B"); + } + protected C(): void { + console.log("B"); + } +}"#, + r#"export declare abstract class Manager { + protected abstract A(): void; + protected B(): void; + protected C(): void; +}"#, + ); +} + #[test] fn dts_var_decl_test() { transform_dts_test(