Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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'>');
}
}

Expand Down
30 changes: 30 additions & 0 deletions crates/oxc_codegen/tests/integration/snapshots/ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,33 @@ export @x declare abstract class C {}
div<T>``
----------
div<T>``;

########## 30
export type Component<Props = any> = Foo;
----------
export type Component<Props = any> = Foo;

########## 31

export type Component<
Props = any,
RawBindings = any,
D = any,
C extends ComputedOptions = ComputedOptions,
M extends MethodOptions = MethodOptions,
E extends EmitsOptions | Record<string, any[]> = {},
S extends Record<string, any> = any,
> =
| ConcreteComponent<Props, RawBindings, D, C, M, E, S>
| ComponentPublicInstanceConstructor<Props>

----------
export type Component<
Props = any,
RawBindings = any,
D = any,
C extends ComputedOptions = ComputedOptions,
M extends MethodOptions = MethodOptions,
E extends EmitsOptions | Record<string, any[]> = {},
S extends Record<string, any> = any
> = ConcreteComponent<Props, RawBindings, D, C, M, E, S> | ComponentPublicInstanceConstructor<Props>;
14 changes: 14 additions & 0 deletions crates/oxc_codegen/tests/integration/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ fn ts() {
"d = x satisfies y;",
"export @x declare abstract class C {}",
"div<T>``",
"export type Component<Props = any> = Foo;",
"
export type Component<
Props = any,
RawBindings = any,
D = any,
C extends ComputedOptions = ComputedOptions,
M extends MethodOptions = MethodOptions,
E extends EmitsOptions | Record<string, any[]> = {},
S extends Record<string, any> = any,
> =
| ConcreteComponent<Props, RawBindings, D, C, M, E, S>
| ComponentPublicInstanceConstructor<Props>
"
];

snapshot("ts", &cases);
Expand Down