@@ -2297,7 +2297,7 @@ namespace ts {
2297
2297
emitTokenWithComment ( token . kind , node . expression . end , writePunctuation , node ) ;
2298
2298
writeLinesAndIndent ( linesAfterDot , /*writeSpaceIfNotIndenting*/ false ) ;
2299
2299
emit ( node . name ) ;
2300
- decreaseIndentIf ( linesBeforeDot , linesAfterDot ) ;
2300
+ decreaseIndentIf ( linesBeforeDot > 0 , linesAfterDot > 0 ) ;
2301
2301
}
2302
2302
2303
2303
// 1..toString is a valid property access, emit a dot after the literal
@@ -2475,7 +2475,7 @@ namespace ts {
2475
2475
case EmitBinaryExpressionState . FinishEmit : {
2476
2476
const linesBeforeOperator = getLinesBetweenNodes ( node , node . left , node . operatorToken ) ;
2477
2477
const linesAfterOperator = getLinesBetweenNodes ( node , node . operatorToken , node . right ) ;
2478
- decreaseIndentIf ( linesBeforeOperator , linesAfterOperator ) ;
2478
+ decreaseIndentIf ( linesBeforeOperator > 0 , linesAfterOperator > 0 ) ;
2479
2479
stackIndex -- ;
2480
2480
break ;
2481
2481
}
@@ -2529,13 +2529,13 @@ namespace ts {
2529
2529
emit ( node . questionToken ) ;
2530
2530
writeLinesAndIndent ( linesAfterQuestion , /*writeSpaceIfNotIndenting*/ true ) ;
2531
2531
emitExpression ( node . whenTrue ) ;
2532
- decreaseIndentIf ( linesBeforeQuestion , linesAfterQuestion ) ;
2532
+ decreaseIndentIf ( linesBeforeQuestion > 0 , linesAfterQuestion > 0 ) ;
2533
2533
2534
2534
writeLinesAndIndent ( linesBeforeColon , /*writeSpaceIfNotIndenting*/ true ) ;
2535
2535
emit ( node . colonToken ) ;
2536
2536
writeLinesAndIndent ( linesAfterColon , /*writeSpaceIfNotIndenting*/ true ) ;
2537
2537
emitExpression ( node . whenFalse ) ;
2538
- decreaseIndentIf ( linesBeforeColon , linesAfterColon ) ;
2538
+ decreaseIndentIf ( linesBeforeColon > 0 , linesAfterColon > 0 ) ;
2539
2539
}
2540
2540
2541
2541
function emitTemplateExpression ( node : TemplateExpression ) {
@@ -4010,7 +4010,7 @@ namespace ts {
4010
4010
let shouldEmitInterveningComments = mayEmitInterveningComments ;
4011
4011
const leadingLineTerminatorCount = getLeadingLineTerminatorCount ( parentNode , children ! , format ) ; // TODO: GH#18217
4012
4012
if ( leadingLineTerminatorCount ) {
4013
- writeLine ( leadingLineTerminatorCount ) ;
4013
+ writeBlankLines ( leadingLineTerminatorCount ) ;
4014
4014
shouldEmitInterveningComments = false ;
4015
4015
}
4016
4016
else if ( format & ListFormat . SpaceBetweenBraces ) {
@@ -4058,7 +4058,7 @@ namespace ts {
4058
4058
shouldDecreaseIndentAfterEmit = true ;
4059
4059
}
4060
4060
4061
- writeLine ( separatingLineTerminatorCount ) ;
4061
+ writeBlankLines ( separatingLineTerminatorCount ) ;
4062
4062
shouldEmitInterveningComments = false ;
4063
4063
}
4064
4064
else if ( previousSibling && format & ListFormat . SpaceBetweenSiblings ) {
@@ -4115,7 +4115,7 @@ namespace ts {
4115
4115
// Write the closing line terminator or closing whitespace.
4116
4116
const closingLineTerminatorCount = getClosingLineTerminatorCount ( parentNode , children ! , format ) ;
4117
4117
if ( closingLineTerminatorCount ) {
4118
- writeLine ( closingLineTerminatorCount ) ;
4118
+ writeBlankLines ( closingLineTerminatorCount ) ;
4119
4119
}
4120
4120
else if ( format & ListFormat . SpaceBetweenBraces ) {
4121
4121
writeSpace ( ) ;
@@ -4185,10 +4185,8 @@ namespace ts {
4185
4185
writer . writeProperty ( s ) ;
4186
4186
}
4187
4187
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 ( ) ;
4192
4190
}
4193
4191
4194
4192
function increaseIndent ( ) {
@@ -4244,10 +4242,21 @@ namespace ts {
4244
4242
}
4245
4243
}
4246
4244
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
+
4247
4256
function writeLinesAndIndent ( lineCount : number , writeSpaceIfNotIndenting : boolean ) {
4248
4257
if ( lineCount ) {
4249
4258
increaseIndent ( ) ;
4250
- writeLine ( lineCount ) ;
4259
+ writeBlankLines ( lineCount ) ;
4251
4260
}
4252
4261
else if ( writeSpaceIfNotIndenting ) {
4253
4262
writeSpace ( ) ;
@@ -4258,7 +4267,7 @@ namespace ts {
4258
4267
// previous indent values to be considered at a time. This also allows caller to just
4259
4268
// call this once, passing in all their appropriate indent values, instead of needing
4260
4269
// to call this helper function multiple times.
4261
- function decreaseIndentIf ( value1 : boolean | number , value2 : boolean | number ) {
4270
+ function decreaseIndentIf ( value1 : boolean , value2 : boolean ) {
4262
4271
if ( value1 ) {
4263
4272
decreaseIndent ( ) ;
4264
4273
}
0 commit comments