@@ -2297,7 +2297,7 @@ namespace ts {
22972297 emitTokenWithComment ( token . kind , node . expression . end , writePunctuation , node ) ;
22982298 writeLinesAndIndent ( linesAfterDot , /*writeSpaceIfNotIndenting*/ false ) ;
22992299 emit ( node . name ) ;
2300- decreaseIndentIf ( linesBeforeDot , linesAfterDot ) ;
2300+ decreaseIndentIf ( linesBeforeDot > 0 , linesAfterDot > 0 ) ;
23012301 }
23022302
23032303 // 1..toString is a valid property access, emit a dot after the literal
@@ -2475,7 +2475,7 @@ namespace ts {
24752475 case EmitBinaryExpressionState . FinishEmit : {
24762476 const linesBeforeOperator = getLinesBetweenNodes ( node , node . left , node . operatorToken ) ;
24772477 const linesAfterOperator = getLinesBetweenNodes ( node , node . operatorToken , node . right ) ;
2478- decreaseIndentIf ( linesBeforeOperator , linesAfterOperator ) ;
2478+ decreaseIndentIf ( linesBeforeOperator > 0 , linesAfterOperator > 0 ) ;
24792479 stackIndex -- ;
24802480 break ;
24812481 }
@@ -2529,13 +2529,13 @@ namespace ts {
25292529 emit ( node . questionToken ) ;
25302530 writeLinesAndIndent ( linesAfterQuestion , /*writeSpaceIfNotIndenting*/ true ) ;
25312531 emitExpression ( node . whenTrue ) ;
2532- decreaseIndentIf ( linesBeforeQuestion , linesAfterQuestion ) ;
2532+ decreaseIndentIf ( linesBeforeQuestion > 0 , linesAfterQuestion > 0 ) ;
25332533
25342534 writeLinesAndIndent ( linesBeforeColon , /*writeSpaceIfNotIndenting*/ true ) ;
25352535 emit ( node . colonToken ) ;
25362536 writeLinesAndIndent ( linesAfterColon , /*writeSpaceIfNotIndenting*/ true ) ;
25372537 emitExpression ( node . whenFalse ) ;
2538- decreaseIndentIf ( linesBeforeColon , linesAfterColon ) ;
2538+ decreaseIndentIf ( linesBeforeColon > 0 , linesAfterColon > 0 ) ;
25392539 }
25402540
25412541 function emitTemplateExpression ( node : TemplateExpression ) {
@@ -4010,7 +4010,7 @@ namespace ts {
40104010 let shouldEmitInterveningComments = mayEmitInterveningComments ;
40114011 const leadingLineTerminatorCount = getLeadingLineTerminatorCount ( parentNode , children ! , format ) ; // TODO: GH#18217
40124012 if ( leadingLineTerminatorCount ) {
4013- writeLine ( leadingLineTerminatorCount ) ;
4013+ writeBlankLines ( leadingLineTerminatorCount ) ;
40144014 shouldEmitInterveningComments = false ;
40154015 }
40164016 else if ( format & ListFormat . SpaceBetweenBraces ) {
@@ -4058,7 +4058,7 @@ namespace ts {
40584058 shouldDecreaseIndentAfterEmit = true ;
40594059 }
40604060
4061- writeLine ( separatingLineTerminatorCount ) ;
4061+ writeBlankLines ( separatingLineTerminatorCount ) ;
40624062 shouldEmitInterveningComments = false ;
40634063 }
40644064 else if ( previousSibling && format & ListFormat . SpaceBetweenSiblings ) {
@@ -4115,7 +4115,7 @@ namespace ts {
41154115 // Write the closing line terminator or closing whitespace.
41164116 const closingLineTerminatorCount = getClosingLineTerminatorCount ( parentNode , children ! , format ) ;
41174117 if ( closingLineTerminatorCount ) {
4118- writeLine ( closingLineTerminatorCount ) ;
4118+ writeBlankLines ( closingLineTerminatorCount ) ;
41194119 }
41204120 else if ( format & ListFormat . SpaceBetweenBraces ) {
41214121 writeSpace ( ) ;
@@ -4185,10 +4185,8 @@ namespace ts {
41854185 writer . writeProperty ( s ) ;
41864186 }
41874187
4188- function writeLine ( count = 1 ) {
4189- for ( let i = 0 ; i < count ; i ++ ) {
4190- writer . writeLine ( i > 0 ) ;
4191- }
4188+ function writeLine ( ) {
4189+ writer . writeLine ( ) ;
41924190 }
41934191
41944192 function increaseIndent ( ) {
@@ -4244,10 +4242,21 @@ namespace ts {
42444242 }
42454243 }
42464244
4245+ function writeBlankLines ( lineCount : number ) {
4246+ for ( let i = 0 ; i < lineCount ; i ++ ) {
4247+ if ( i === 0 ) {
4248+ writer . writeLine ( ) ;
4249+ }
4250+ else {
4251+ writer . forceWriteLine ( ) ;
4252+ }
4253+ }
4254+ }
4255+
42474256 function writeLinesAndIndent ( lineCount : number , writeSpaceIfNotIndenting : boolean ) {
42484257 if ( lineCount ) {
42494258 increaseIndent ( ) ;
4250- writeLine ( lineCount ) ;
4259+ writeBlankLines ( lineCount ) ;
42514260 }
42524261 else if ( writeSpaceIfNotIndenting ) {
42534262 writeSpace ( ) ;
@@ -4258,7 +4267,7 @@ namespace ts {
42584267 // previous indent values to be considered at a time. This also allows caller to just
42594268 // call this once, passing in all their appropriate indent values, instead of needing
42604269 // to call this helper function multiple times.
4261- function decreaseIndentIf ( value1 : boolean | number , value2 : boolean | number ) {
4270+ function decreaseIndentIf ( value1 : boolean , value2 : boolean ) {
42624271 if ( value1 ) {
42634272 decreaseIndent ( ) ;
42644273 }
0 commit comments