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
15 changes: 13 additions & 2 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3032,17 +3032,28 @@ impl Gen for TSTupleType<'_> {
}
}

fn parenthesize_check_type_of_conditional_type(ty: &TSType<'_>) -> bool {
matches!(
ty,
TSType::TSFunctionType(_) | TSType::TSConstructorType(_) | TSType::TSConditionalType(_)
)
}

impl Gen for TSUnionType<'_> {
fn r#gen(&self, p: &mut Codegen, ctx: Context) {
let Some((first, rest)) = self.types.split_first() else {
return;
};
first.print(p, ctx);
p.wrap(parenthesize_check_type_of_conditional_type(first), |p| {
first.print(p, ctx);
});
for item in rest {
p.print_soft_space();
p.print_str("|");
p.print_soft_space();
item.print(p, ctx);
p.wrap(parenthesize_check_type_of_conditional_type(item), |p| {
item.print(p, ctx);
});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class Foo {
constructor(
public one?: () => void,
protected two?: () => void,
private three?: () => void,
) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/union-type.ts
---
```
==================== .D.TS ====================

export declare class Foo {
one?: (() => void) | undefined;
protected two?: (() => void) | undefined;
private three?;
constructor(one?: (() => void) | undefined, two?: (() => void) | undefined, three?: (() => void) | undefined);
}
4 changes: 2 additions & 2 deletions tasks/coverage/snapshots/transpile.snap
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ export class ClsWithRequiredInitializedParameter {
//// [fnDecl.d.ts] ////
type T = number[];
export declare function fnDeclBasic1(p: number[] | string[] | [T] | undefined, rParam: string): void;
export declare function fnDeclBasic2(p: (n: T) => T | undefined, rParam: string): void;
export declare function fnDeclBasic3(p: new () => any | undefined, rParam: string): void;
export declare function fnDeclBasic2(p: ((n: T) => T) | undefined, rParam: string): void;
export declare function fnDeclBasic3(p: (new () => any) | undefined, rParam: string): void;
export declare function fnDeclBasic4(p: [T] | undefined, rParam: string): void;
export declare function fnDeclBasic5(p: {
a: T;
Expand Down
Loading