@@ -2365,12 +2365,12 @@ namespace ts {
2365
2365
2366
2366
function emitParenthesizedExpression ( node : ParenthesizedExpression ) {
2367
2367
const openParenPos = emitTokenWithComment ( SyntaxKind . OpenParenToken , node . pos , writePunctuation , node ) ;
2368
- const leadingNewlines = getLeadingLineTerminatorCount ( node , node . expression , ListFormat . None ) ;
2368
+ const leadingNewlines = preserveSourceNewlines && getLeadingLineTerminatorCount ( node , [ node . expression ] , ListFormat . None ) ;
2369
2369
if ( leadingNewlines ) {
2370
2370
writeLinesAndIndent ( leadingNewlines , /*writeLinesIfNotIndenting*/ false ) ;
2371
2371
}
2372
2372
emitExpression ( node . expression ) ;
2373
- const trailingNewlines = getClosingLineTerminatorCount ( node , node . expression , ListFormat . None ) ;
2373
+ const trailingNewlines = preserveSourceNewlines && getClosingLineTerminatorCount ( node , [ node . expression ] , ListFormat . None ) ;
2374
2374
if ( trailingNewlines ) {
2375
2375
writeLine ( trailingNewlines ) ;
2376
2376
}
@@ -4282,13 +4282,13 @@ namespace ts {
4282
4282
}
4283
4283
}
4284
4284
4285
- function getLeadingLineTerminatorCount ( parentNode : TextRange , children : NodeArray < Node > | Node , format : ListFormat ) : number {
4285
+ function getLeadingLineTerminatorCount ( parentNode : TextRange , children : readonly Node [ ] , format : ListFormat ) : number {
4286
4286
if ( format & ListFormat . PreserveLines || preserveSourceNewlines ) {
4287
4287
if ( format & ListFormat . PreferNewLine ) {
4288
4288
return 1 ;
4289
4289
}
4290
4290
4291
- const firstChild = isArray ( children ) ? children [ 0 ] : children ;
4291
+ const firstChild = children [ 0 ] ;
4292
4292
if ( firstChild === undefined ) {
4293
4293
return rangeIsOnSingleLine ( parentNode , currentSourceFile ! ) ? 0 : 1 ;
4294
4294
}
@@ -4340,17 +4340,17 @@ namespace ts {
4340
4340
return format & ListFormat . MultiLine ? 1 : 0 ;
4341
4341
}
4342
4342
4343
- function getClosingLineTerminatorCount ( parentNode : TextRange , children : NodeArray < Node > | Node , format : ListFormat ) : number {
4343
+ function getClosingLineTerminatorCount ( parentNode : TextRange , children : readonly Node [ ] , format : ListFormat ) : number {
4344
4344
if ( format & ListFormat . PreserveLines || preserveSourceNewlines ) {
4345
4345
if ( format & ListFormat . PreferNewLine ) {
4346
4346
return 1 ;
4347
4347
}
4348
4348
4349
- const lastChild = isArray ( children ) ? lastOrUndefined ( children ) : children ;
4349
+ const lastChild = lastOrUndefined ( children ) ;
4350
4350
if ( lastChild === undefined ) {
4351
4351
return rangeIsOnSingleLine ( parentNode , currentSourceFile ! ) ? 0 : 1 ;
4352
4352
}
4353
- else if ( ! positionIsSynthesized ( parentNode . pos ) && ! nodeIsSynthesized ( lastChild ) && lastChild . parent === parentNode ) {
4353
+ if ( ! positionIsSynthesized ( parentNode . pos ) && ! nodeIsSynthesized ( lastChild ) && lastChild . parent === parentNode ) {
4354
4354
if ( preserveSourceNewlines ) {
4355
4355
return getEffectiveLines (
4356
4356
includeComments => getLinesBetweenPositionAndNextNonWhitespaceCharacter (
@@ -4360,7 +4360,7 @@ namespace ts {
4360
4360
}
4361
4361
return rangeEndPositionsAreOnSameLine ( parentNode , lastChild , currentSourceFile ! ) ? 0 : 1 ;
4362
4362
}
4363
- else if ( synthesizedNodeStartsOnNewLine ( lastChild , format ) ) {
4363
+ if ( synthesizedNodeStartsOnNewLine ( lastChild , format ) ) {
4364
4364
return 1 ;
4365
4365
}
4366
4366
}
0 commit comments