diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index 2c625d460a31d..0588e78290c4d 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -2790,9 +2790,29 @@ impl<'a> Gen for TSClassImplements<'a> { impl<'a> Gen for TSTypeParameterDeclaration<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { - p.print_str("<"); - p.print_list(&self.params, ctx); - p.print_str(">"); + let is_multi_line = self.params.len() >= 2; + p.print_char(b'<'); + if is_multi_line { + p.indent(); + } + for (index, item) in self.params.iter().enumerate() { + if index != 0 { + p.print_comma(); + } + if is_multi_line { + p.print_soft_newline(); + p.print_indent(); + } else if index != 0 { + p.print_soft_space(); + } + item.print(p, ctx); + } + if is_multi_line { + p.print_soft_newline(); + p.dedent(); + p.print_indent(); + } + p.print_char(b'>'); } } diff --git a/crates/oxc_codegen/tests/integration/snapshots/ts.snap b/crates/oxc_codegen/tests/integration/snapshots/ts.snap index b443a8333b53a..c5bb3fddcaae7 100644 --- a/crates/oxc_codegen/tests/integration/snapshots/ts.snap +++ b/crates/oxc_codegen/tests/integration/snapshots/ts.snap @@ -180,3 +180,33 @@ export @x declare abstract class C {} div`` ---------- div``; + +########## 30 +export type Component = Foo; +---------- +export type Component = Foo; + +########## 31 + +export type Component< + Props = any, + RawBindings = any, + D = any, + C extends ComputedOptions = ComputedOptions, + M extends MethodOptions = MethodOptions, + E extends EmitsOptions | Record = {}, + S extends Record = any, +> = + | ConcreteComponent + | ComponentPublicInstanceConstructor + +---------- +export type Component< + Props = any, + RawBindings = any, + D = any, + C extends ComputedOptions = ComputedOptions, + M extends MethodOptions = MethodOptions, + E extends EmitsOptions | Record = {}, + S extends Record = any +> = ConcreteComponent | ComponentPublicInstanceConstructor; diff --git a/crates/oxc_codegen/tests/integration/ts.rs b/crates/oxc_codegen/tests/integration/ts.rs index 148575424bdaf..1ee5d448b786f 100644 --- a/crates/oxc_codegen/tests/integration/ts.rs +++ b/crates/oxc_codegen/tests/integration/ts.rs @@ -37,6 +37,20 @@ fn ts() { "d = x satisfies y;", "export @x declare abstract class C {}", "div``", + "export type Component = Foo;", + " +export type Component< + Props = any, + RawBindings = any, + D = any, + C extends ComputedOptions = ComputedOptions, + M extends MethodOptions = MethodOptions, + E extends EmitsOptions | Record = {}, + S extends Record = any, +> = + | ConcreteComponent + | ComponentPublicInstanceConstructor +" ]; snapshot("ts", &cases);