feat(codegen): add new lines to TSTypeParameterDeclaration (#5853)

This commit is contained in:
Boshen 2024-09-18 11:44:24 +00:00
parent b9c45646d1
commit 9f6696a6aa
3 changed files with 67 additions and 3 deletions

View file

@ -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'>');
}
}

View file

@ -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>;

View file

@ -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);