From 5c8aa522da205fc7fab156cb9d44c8acca872523 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Thu, 8 Aug 2024 14:25:06 +0800 Subject: [PATCH] fix(es/typescript): Strip declaration of exported function overloads (#9397) - Closes https://github.com/swc-project/swc/issues/9396 --- .changeset/eleven-dryers-brake.md | 6 ++++++ crates/swc_fast_ts_strip/src/lib.rs | 11 +++-------- crates/swc_fast_ts_strip/tests/fixture/issue-9396.js | 1 + .../tests/fixture/issue-9396.transform.js | 1 + crates/swc_fast_ts_strip/tests/fixture/issue-9396.ts | 1 + 5 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 .changeset/eleven-dryers-brake.md create mode 100644 crates/swc_fast_ts_strip/tests/fixture/issue-9396.js create mode 100644 crates/swc_fast_ts_strip/tests/fixture/issue-9396.transform.js create mode 100644 crates/swc_fast_ts_strip/tests/fixture/issue-9396.ts diff --git a/.changeset/eleven-dryers-brake.md b/.changeset/eleven-dryers-brake.md new file mode 100644 index 000000000000..161f6aeaf4b7 --- /dev/null +++ b/.changeset/eleven-dryers-brake.md @@ -0,0 +1,6 @@ +--- +swc_fast_ts_strip: patch +swc_core: patch +--- + +fix(es/typescript): Strip declaration of exported function overloads diff --git a/crates/swc_fast_ts_strip/src/lib.rs b/crates/swc_fast_ts_strip/src/lib.rs index 68cd118c05e5..d5bb8885cea0 100644 --- a/crates/swc_fast_ts_strip/src/lib.rs +++ b/crates/swc_fast_ts_strip/src/lib.rs @@ -655,14 +655,6 @@ impl Visit for TsStrip { n.visit_children_with(self); } - fn visit_fn_decl(&mut self, n: &FnDecl) { - if n.function.body.is_none() { - self.add_replacement(n.function.span); - return; - } - n.visit_children_with(self); - } - fn visit_import_decl(&mut self, n: &ImportDecl) { if n.type_only { self.add_replacement(n.span); @@ -955,6 +947,9 @@ impl IsTsDecl for Decl { Self::Var(ref var) => var.declare, Self::Fn(FnDecl { declare: true, .. }) | Self::Class(ClassDecl { declare: true, .. }) => true, + + Self::Fn(FnDecl { function, .. }) => function.body.is_none(), + _ => false, } } diff --git a/crates/swc_fast_ts_strip/tests/fixture/issue-9396.js b/crates/swc_fast_ts_strip/tests/fixture/issue-9396.js new file mode 100644 index 000000000000..4eea3e2ad7d8 --- /dev/null +++ b/crates/swc_fast_ts_strip/tests/fixture/issue-9396.js @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/swc_fast_ts_strip/tests/fixture/issue-9396.transform.js b/crates/swc_fast_ts_strip/tests/fixture/issue-9396.transform.js new file mode 100644 index 000000000000..2234b9cae16d --- /dev/null +++ b/crates/swc_fast_ts_strip/tests/fixture/issue-9396.transform.js @@ -0,0 +1 @@ +export { }; diff --git a/crates/swc_fast_ts_strip/tests/fixture/issue-9396.ts b/crates/swc_fast_ts_strip/tests/fixture/issue-9396.ts new file mode 100644 index 000000000000..061d64450fe4 --- /dev/null +++ b/crates/swc_fast_ts_strip/tests/fixture/issue-9396.ts @@ -0,0 +1 @@ +export function f(); \ No newline at end of file