@@ -74,8 +74,8 @@ module PrinterExtensions =
7474 let subSegment =
7575 // Remove whitespace in front of new lines,
7676 // indent will be automatically applied
77- if printer.Column = 0 then subSegments. [ i - 1 ]. TrimStart()
78- else subSegments. [ i - 1 ]
77+ if printer.Column = 0 then subSegments[ i - 1 ]. TrimStart()
78+ else subSegments[ i - 1 ]
7979 if subSegment.Length > 0 then
8080 printer.Print( subSegment)
8181 if i < subSegments.Length then
@@ -87,53 +87,53 @@ module PrinterExtensions =
8787 value
8888 |> replace @" \$(\d+)\.\.\." ( fun m ->
8989 let rep = ResizeArray()
90- let i = int m.Groups. [1 ]. Value
90+ let i = int m.Groups[ 1 ]. Value
9191 for j = i to args.Length - 1 do
9292 rep.Add( " $" + string j)
9393 String.concat " , " rep)
9494
9595 |> replace @" \{\{\s*\$(\d+)\s*\?(.*?)\:(.*?)\}\}" ( fun m ->
96- let i = int m.Groups. [1 ]. Value
97- match args. [ i] with
98- | Literal( BooleanLiteral( value= value)) when value -> m.Groups. [2 ]. Value
99- | _ -> m.Groups. [3 ]. Value)
96+ let i = int m.Groups[ 1 ]. Value
97+ match args[ i] with
98+ | Literal( BooleanLiteral( value= value)) when value -> m.Groups[ 2 ]. Value
99+ | _ -> m.Groups[ 3 ]. Value)
100100
101101 |> replace @" \{\{([^\}]*\$(\d+).*?)\}\}" ( fun m ->
102- let i = int m.Groups. [2 ]. Value
102+ let i = int m.Groups[ 2 ]. Value
103103 match List.tryItem i args with
104- | Some _ -> m.Groups. [1 ]. Value
104+ | Some _ -> m.Groups[ 1 ]. Value
105105 | None -> " " )
106106
107107 // If placeholder is followed by !, emit string literals as native code: "let $0! = $1"
108108 |> replace @" \$(\d+)!" ( fun m ->
109- let i = int m.Groups. [1 ]. Value
109+ let i = int m.Groups[ 1 ]. Value
110110 match List.tryItem i args with
111111 | Some( Literal( StringLiteral value)) -> value
112112 | _ -> " " )
113113
114114 let matches = Regex.Matches( value, @" \$\d+" )
115115 if matches.Count > 0 then
116116 for i = 0 to matches.Count - 1 do
117- let m = matches. [ i]
117+ let m = matches[ i]
118118 let isSurroundedWithParens =
119119 m.Index > 0
120120 && m.Index + m.Length < value.Length
121- && value. [ m.Index - 1 ] = '('
122- && value. [ m.Index + m.Length] = ')'
121+ && value[ m.Index - 1 ] = '('
122+ && value[ m.Index + m.Length] = ')'
123123
124124 let segmentStart =
125- if i > 0 then matches. [ i-1 ]. Index + matches. [ i-1 ]. Length
125+ if i > 0 then matches[ i-1 ]. Index + matches[ i-1 ]. Length
126126 else 0
127127
128128 printSegment printer value segmentStart m.Index
129129
130- let argIndex = int m.Value. [1 ..]
130+ let argIndex = int m.Value[ 1 ..]
131131 match List.tryItem argIndex args with
132132 | Some e when isSurroundedWithParens -> printer.Print( e)
133133 | Some e -> printer.PrintWithParensIfComplex( e)
134134 | None -> ()
135135
136- let lastMatch = matches. [ matches.Count - 1 ]
136+ let lastMatch = matches[ matches.Count - 1 ]
137137 printSegment printer value ( lastMatch.Index + lastMatch.Length) value.Length
138138 else
139139 printSegment printer value 0 value.Length
@@ -496,14 +496,17 @@ module PrinterExtensions =
496496 p.PushIndentation()
497497 for s in c.Body do
498498 p.Print( s)
499- p.Print( " ;" )
500- p.PrintNewLine()
499+ p.PrintStatementSeparator()
500+
501+ let rec needsBreak statements =
502+ match List.tryLast statements with
503+ | Some( ContinueStatement _)
504+ | Some( BreakStatement _)
505+ | Some( ReturnStatement _) -> false
506+ | Some( IfStatement(_, consequent, alternate)) -> needsBreak consequent || needsBreak alternate
507+ | _ -> true
501508
502- match List.tryLast c.Body with
503- | Some( ContinueStatement _)
504- | Some( BreakStatement _)
505- | Some( ReturnStatement _) -> ()
506- | _ ->
509+ if needsBreak c.Body then
507510 p.Print( " break;" )
508511 p.PrintNewLine()
509512
@@ -552,8 +555,8 @@ module PrinterExtensions =
552555 else " '"
553556 printer.Print( quotes)
554557 for i = 0 to parts.Length - 2 do
555- printer.Print( escape parts. [ i])
556- match values. [ i] with
558+ printer.Print( escape parts[ i])
559+ match values[ i] with
557560 | IdentExpression i ->
558561 printer.Print( " $" )
559562 printer.PrintIdent( i)
@@ -579,7 +582,11 @@ module PrinterExtensions =
579582 | test, Literal( BooleanLiteral( false )), Literal( BooleanLiteral( true )) ->
580583 printer.Print( " !" )
581584 printer.PrintWithParensIfComplex( test)
582- | test, _, Literal( BooleanLiteral( false )) ->
585+ | test, Literal( BooleanLiteral( true )), alternate ->
586+ printer.PrintWithParensIfComplex( test)
587+ printer.Print( " || " )
588+ printer.PrintWithParensIfComplex( alternate)
589+ | test, consequent, Literal( BooleanLiteral( false )) ->
583590 printer.PrintWithParensIfComplex( test)
584591 printer.Print( " && " )
585592 printer.PrintWithParensIfComplex( consequent)
@@ -709,9 +716,8 @@ module PrinterExtensions =
709716 if v.IsOverride then
710717 p.Print( " @override" )
711718 p.PrintNewLine()
712- match v.Kind with
713- | Final when v.IsLate -> p.Print( " late " )
714- | _ -> ()
719+ if v.IsLate then
720+ p.Print( " late " )
715721 p.PrintVariableDeclaration( v.Ident, v.Kind, ?value= v.Value)
716722 p.Print( " ;" )
717723
@@ -722,13 +728,7 @@ module PrinterExtensions =
722728 if c.IsFactory then
723729 p.Print( " factory " )
724730 p.Print( decl.Name)
725- printer.PrintList( " (" , " , " , " )" , c.Args, function
726- | ConsThisArg name ->
727- printer.Print( " this." )
728- printer.Print( name)
729- | ConsArg i ->
730- printer.PrintIdent( i, printType= true )
731- )
731+ printer.PrintFunctionArgs( c.Args)
732732
733733 if callSuper then
734734 p.Print( " : super" )
@@ -776,12 +776,7 @@ module PrinterExtensions =
776776 printer.Print( " " )
777777 printer.PrintBlock( body, skipNewLineAtEnd=( isExpression || isModuleOrClassMember))
778778
779- member printer.PrintFunctionDeclaration ( returnType : Type , name : string , genParams : GenericParam list , args : FunctionArg list , ? body : Statement list , ? isModuleOrClassMember ) =
780- printer.PrintType( returnType)
781- printer.Print( " " )
782- printer.Print( name)
783- printer.PrintGenericParams( genParams)
784-
779+ member printer.PrintFunctionArgs ( args : FunctionArg list ) =
785780 let mutable prevArg : FunctionArg option = None
786781 printer.PrintList( " (" , " )" , args, fun pos arg ->
787782 if arg.IsNamed then
@@ -797,7 +792,10 @@ module PrinterExtensions =
797792 else
798793 ()
799794
800- printer.PrintIdent( arg.Ident, printType= true )
795+ if arg.IsConsThisArg then
796+ printer.Print( " this." + arg.Ident.Name)
797+ else
798+ printer.PrintIdent( arg.Ident, printType= true )
801799
802800 match pos with
803801 | IsSingle | IsLast ->
@@ -811,6 +809,13 @@ module PrinterExtensions =
811809
812810 prevArg <- Some arg
813811 )
812+
813+ member printer.PrintFunctionDeclaration ( returnType : Type , name : string , genParams : GenericParam list , args : FunctionArg list , ? body : Statement list , ? isModuleOrClassMember ) =
814+ printer.PrintType( returnType)
815+ printer.Print( " " )
816+ printer.Print( name)
817+ printer.PrintGenericParams( genParams)
818+ printer.PrintFunctionArgs( args)
814819 printer.PrintFunctionBody( ?body= body, ?isModuleOrClassMember= isModuleOrClassMember)
815820
816821 member printer.PrintVariableDeclaration ( ident : Ident , kind : VariableDeclarationKind , ? value : Expression ) =
@@ -871,7 +876,7 @@ let run (writer: Writer) (file: File): Async<unit> =
871876 let printer = printerImpl :> Printer
872877
873878 // If we manage to master null assertions maybe we can remove unnecessary_non_null_assertion
874- printer.Print( " // ignore_for_file: non_constant_identifier_names, camel_case_types, constant_identifier_names, unnecessary_non_null_assertion" )
879+ printer.Print( " // ignore_for_file: camel_case_types, constant_identifier_names, non_constant_identifier_names, unnecessary_non_null_assertion, unnecessary_this " )
875880 printer.PrintNewLine()
876881
877882 file.Imports
0 commit comments