@@ -7,7 +7,9 @@ import { AllPrettierOptions } from "src/options";
77export const programMap : CstToDocMap < Program > = {
88 program : ( print , node , path , options ) =>
99 print ( "statements" ) . map ( ( doc , i ) =>
10- printStatement ( doc , i , node . statements , options ) ,
10+ i === node . statements . length - 1
11+ ? printFinalStatement ( doc , i , node . statements , options )
12+ : printStatement ( doc , i , node . statements , options ) ,
1113 ) ,
1214} ;
1315
@@ -31,3 +33,23 @@ const printStatement = (
3133 return [ ";" , hardline , doc ] ;
3234 }
3335} ;
36+
37+ const printFinalStatement = (
38+ doc : Doc ,
39+ i : number ,
40+ statements : Node [ ] ,
41+ options : AllPrettierOptions < Program > ,
42+ ) : Doc => {
43+ const stmtDoc = printStatement ( doc , i , statements , options ) ;
44+ if ( statements [ i ] . type === "empty" ) {
45+ // When the final statement is an empty statement,
46+ // this means we have inserted a semicolon and newline before it.
47+ // So nothing else is needed.
48+ return stmtDoc ;
49+ } else {
50+ // If the last statement is not empty,
51+ // this means sqlFinalSemicolon option is false,
52+ // so we need to add an empty line after it.
53+ return [ stmtDoc , hardline ] ;
54+ }
55+ } ;
0 commit comments