From 08f834fce6287fb4b2ad029c2ee3104e307e1a24 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Tue, 14 Mar 2023 21:08:19 +0800 Subject: [PATCH 1/2] fix(es/codegen): emit `type_params` for TsConstructSignatureDecl --- crates/swc_ecma_codegen/src/typescript.rs | 6 +++++- crates/swc_ecma_codegen/tests/fixture/issues/7079/input.ts | 3 +++ crates/swc_ecma_codegen/tests/fixture/issues/7079/output.ts | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 crates/swc_ecma_codegen/tests/fixture/issues/7079/input.ts create mode 100644 crates/swc_ecma_codegen/tests/fixture/issues/7079/output.ts diff --git a/crates/swc_ecma_codegen/src/typescript.rs b/crates/swc_ecma_codegen/src/typescript.rs index 2c73cb79ddf6..c60b133f650b 100644 --- a/crates/swc_ecma_codegen/src/typescript.rs +++ b/crates/swc_ecma_codegen/src/typescript.rs @@ -100,6 +100,10 @@ where self.emit_leading_comments_of_span(n.span(), false)?; keyword!("new"); + if let Some(type_params) = &n.type_params { + space!(); + emit!(type_params); + } punct!("("); self.emit_list(n.span, Some(&n.params), ListFormat::Parameters)?; @@ -122,8 +126,8 @@ where } keyword!("new"); - space!(); if let Some(type_params) = &n.type_params { + space!(); emit!(type_params); } diff --git a/crates/swc_ecma_codegen/tests/fixture/issues/7079/input.ts b/crates/swc_ecma_codegen/tests/fixture/issues/7079/input.ts new file mode 100644 index 000000000000..f7309f09fd2e --- /dev/null +++ b/crates/swc_ecma_codegen/tests/fixture/issues/7079/input.ts @@ -0,0 +1,3 @@ +interface Foo { + new (value: T): Obj; +} diff --git a/crates/swc_ecma_codegen/tests/fixture/issues/7079/output.ts b/crates/swc_ecma_codegen/tests/fixture/issues/7079/output.ts new file mode 100644 index 000000000000..02e85c6cbc9a --- /dev/null +++ b/crates/swc_ecma_codegen/tests/fixture/issues/7079/output.ts @@ -0,0 +1,3 @@ +interface Foo { + new (value: T): Obj; +} From 81bb27127b4b0aa259e9be1676d2eaff4e278c34 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Fri, 17 Mar 2023 00:23:57 +0800 Subject: [PATCH 2/2] chore: update test cases --- .../swc_ecma_transforms_base/tests/ts-resolver/stc/1/output.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_transforms_base/tests/ts-resolver/stc/1/output.ts b/crates/swc_ecma_transforms_base/tests/ts-resolver/stc/1/output.ts index 106c79d40a59..20b97579d4ac 100644 --- a/crates/swc_ecma_transforms_base/tests/ts-resolver/stc/1/output.ts +++ b/crates/swc_ecma_transforms_base/tests/ts-resolver/stc/1/output.ts @@ -4,7 +4,7 @@ interface Mixin1__1 { class AbstractBase__1 { abstractBaseMethod(): void; } -function Mixin2__1 any>(baseClass__2: TBase__2) { +function Mixin2__1 any>(baseClass__2: TBase__2) { class MixinClass__2 extends baseClass__2 implements Mixin1__1 { mixinMethod(): void {} static staticMixinMethod(): void {}