@@ -2365,12 +2365,12 @@ namespace ts {
23652365
23662366 function emitParenthesizedExpression ( node : ParenthesizedExpression ) {
23672367 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 ) ;
23692369 if ( leadingNewlines ) {
23702370 writeLinesAndIndent ( leadingNewlines , /*writeLinesIfNotIndenting*/ false ) ;
23712371 }
23722372 emitExpression ( node . expression ) ;
2373- const trailingNewlines = getClosingLineTerminatorCount ( node , node . expression , ListFormat . None ) ;
2373+ const trailingNewlines = preserveSourceNewlines && getClosingLineTerminatorCount ( node , [ node . expression ] , ListFormat . None ) ;
23742374 if ( trailingNewlines ) {
23752375 writeLine ( trailingNewlines ) ;
23762376 }
@@ -4282,13 +4282,13 @@ namespace ts {
42824282 }
42834283 }
42844284
4285- function getLeadingLineTerminatorCount ( parentNode : TextRange , children : NodeArray < Node > | Node , format : ListFormat ) : number {
4285+ function getLeadingLineTerminatorCount ( parentNode : TextRange , children : readonly Node [ ] , format : ListFormat ) : number {
42864286 if ( format & ListFormat . PreserveLines || preserveSourceNewlines ) {
42874287 if ( format & ListFormat . PreferNewLine ) {
42884288 return 1 ;
42894289 }
42904290
4291- const firstChild = isArray ( children ) ? children [ 0 ] : children ;
4291+ const firstChild = children [ 0 ] ;
42924292 if ( firstChild === undefined ) {
42934293 return rangeIsOnSingleLine ( parentNode , currentSourceFile ! ) ? 0 : 1 ;
42944294 }
@@ -4340,17 +4340,17 @@ namespace ts {
43404340 return format & ListFormat . MultiLine ? 1 : 0 ;
43414341 }
43424342
4343- function getClosingLineTerminatorCount ( parentNode : TextRange , children : NodeArray < Node > | Node , format : ListFormat ) : number {
4343+ function getClosingLineTerminatorCount ( parentNode : TextRange , children : readonly Node [ ] , format : ListFormat ) : number {
43444344 if ( format & ListFormat . PreserveLines || preserveSourceNewlines ) {
43454345 if ( format & ListFormat . PreferNewLine ) {
43464346 return 1 ;
43474347 }
43484348
4349- const lastChild = isArray ( children ) ? lastOrUndefined ( children ) : children ;
4349+ const lastChild = lastOrUndefined ( children ) ;
43504350 if ( lastChild === undefined ) {
43514351 return rangeIsOnSingleLine ( parentNode , currentSourceFile ! ) ? 0 : 1 ;
43524352 }
4353- else if ( ! positionIsSynthesized ( parentNode . pos ) && ! nodeIsSynthesized ( lastChild ) && lastChild . parent === parentNode ) {
4353+ if ( ! positionIsSynthesized ( parentNode . pos ) && ! nodeIsSynthesized ( lastChild ) && lastChild . parent === parentNode ) {
43544354 if ( preserveSourceNewlines ) {
43554355 return getEffectiveLines (
43564356 includeComments => getLinesBetweenPositionAndNextNonWhitespaceCharacter (
@@ -4360,7 +4360,7 @@ namespace ts {
43604360 }
43614361 return rangeEndPositionsAreOnSameLine ( parentNode , lastChild , currentSourceFile ! ) ? 0 : 1 ;
43624362 }
4363- else if ( synthesizedNodeStartsOnNewLine ( lastChild , format ) ) {
4363+ if ( synthesizedNodeStartsOnNewLine ( lastChild , format ) ) {
43644364 return 1 ;
43654365 }
43664366 }
0 commit comments