File tree Expand file tree Collapse file tree 4 files changed +35
-4
lines changed
oxc_isolated_declarations/tests Expand file tree Collapse file tree 4 files changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -3032,17 +3032,28 @@ impl Gen for TSTupleType<'_> {
30323032 }
30333033}
30343034
3035+ fn parenthesize_check_type_of_conditional_type ( ty : & TSType < ' _ > ) -> bool {
3036+ matches ! (
3037+ ty,
3038+ TSType :: TSFunctionType ( _) | TSType :: TSConstructorType ( _) | TSType :: TSConditionalType ( _)
3039+ )
3040+ }
3041+
30353042impl Gen for TSUnionType < ' _ > {
30363043 fn r#gen ( & self , p : & mut Codegen , ctx : Context ) {
30373044 let Some ( ( first, rest) ) = self . types . split_first ( ) else {
30383045 return ;
30393046 } ;
3040- first. print ( p, ctx) ;
3047+ p. wrap ( parenthesize_check_type_of_conditional_type ( first) , |p| {
3048+ first. print ( p, ctx) ;
3049+ } ) ;
30413050 for item in rest {
30423051 p. print_soft_space ( ) ;
30433052 p. print_str ( "|" ) ;
30443053 p. print_soft_space ( ) ;
3045- item. print ( p, ctx) ;
3054+ p. wrap ( parenthesize_check_type_of_conditional_type ( item) , |p| {
3055+ item. print ( p, ctx) ;
3056+ } ) ;
30463057 }
30473058 }
30483059}
Original file line number Diff line number Diff line change 1+ export class Foo {
2+ constructor (
3+ public one ?: ( ) => void ,
4+ protected two ?: ( ) => void ,
5+ private three ?: ( ) => void ,
6+ ) { }
7+ }
Original file line number Diff line number Diff line change 1+ -- -
2+ source : crates / oxc_isolated_declarations / tests / mod .rs
3+ input_file : crates / oxc_isolated_declarations / tests / fixtures / union - type .ts
4+ -- -
5+ ` ` `
6+ ==================== .D.TS ====================
7+
8+ export declare class Foo {
9+ one ?: (() => void ) | undefined ;
10+ protected two ?: (() => void ) | undefined ;
11+ private three ? ;
12+ constructor (one ?: (() => void ) | undefined , two ?: (() => void ) | undefined , three ?: (() => void ) | undefined );
13+ }
Original file line number Diff line number Diff line change @@ -395,8 +395,8 @@ export class ClsWithRequiredInitializedParameter {
395395// // [fnDecl.d.ts] ////
396396type T = number [];
397397export declare function fnDeclBasic1(p : number [] | string [] | [T ] | undefined , rParam : string ): void ;
398- export declare function fnDeclBasic2(p : (n : T ) => T | undefined , rParam : string ): void ;
399- export declare function fnDeclBasic3(p : new () => any | undefined , rParam : string ): void ;
398+ export declare function fnDeclBasic2(p : (( n : T ) => T ) | undefined , rParam : string ): void ;
399+ export declare function fnDeclBasic3(p : ( new () => any ) | undefined , rParam : string ): void ;
400400export declare function fnDeclBasic4(p : [T ] | undefined , rParam : string ): void ;
401401export declare function fnDeclBasic5(p : {
402402 a: T ;
You can’t perform that action at this time.
0 commit comments