@@ -2360,7 +2360,16 @@ namespace ts {
2360
2360
2361
2361
function emitParenthesizedExpression ( node : ParenthesizedExpression ) {
2362
2362
const openParenPos = emitTokenWithComment ( SyntaxKind . OpenParenToken , node . pos , writePunctuation , node ) ;
2363
+ const leadingNewlines = getLeadingLineTerminatorCount ( node , node . expression , ListFormat . None ) ;
2364
+ if ( leadingNewlines ) {
2365
+ writeLinesAndIndent ( leadingNewlines , /*writeLinesIfNotIndenting*/ false ) ;
2366
+ }
2363
2367
emitExpression ( node . expression ) ;
2368
+ const trailingNewlines = getClosingLineTerminatorCount ( node , node . expression , ListFormat . None ) ;
2369
+ if ( trailingNewlines ) {
2370
+ writeLine ( trailingNewlines ) ;
2371
+ }
2372
+ decreaseIndentIf ( leadingNewlines ) ;
2364
2373
emitTokenWithComment ( SyntaxKind . CloseParenToken , node . expression ? node . expression . end : openParenPos , writePunctuation , node ) ;
2365
2374
}
2366
2375
@@ -4259,7 +4268,7 @@ namespace ts {
4259
4268
// previous indent values to be considered at a time. This also allows caller to just
4260
4269
// call this once, passing in all their appropriate indent values, instead of needing
4261
4270
// to call this helper function multiple times.
4262
- function decreaseIndentIf ( value1 : boolean | number , value2 : boolean | number ) {
4271
+ function decreaseIndentIf ( value1 : boolean | number | undefined , value2 ? : boolean | number ) {
4263
4272
if ( value1 ) {
4264
4273
decreaseIndent ( ) ;
4265
4274
}
@@ -4268,17 +4277,21 @@ namespace ts {
4268
4277
}
4269
4278
}
4270
4279
4271
- function getLeadingLineTerminatorCount ( parentNode : TextRange , children : NodeArray < Node > , format : ListFormat ) : number {
4280
+ function getLeadingLineTerminatorCount ( parentNode : TextRange , children : NodeArray < Node > | Node , format : ListFormat ) : number {
4272
4281
if ( format & ListFormat . PreserveLines || preserveSourceNewlines ) {
4273
4282
if ( format & ListFormat . PreferNewLine ) {
4274
4283
return 1 ;
4275
4284
}
4276
4285
4277
- const firstChild = children [ 0 ] ;
4286
+ const firstChild = isArray ( children ) ? children [ 0 ] : children ;
4278
4287
if ( firstChild === undefined ) {
4279
4288
return rangeIsOnSingleLine ( parentNode , currentSourceFile ! ) ? 0 : 1 ;
4280
4289
}
4281
- else if ( ! positionIsSynthesized ( parentNode . pos ) && ! nodeIsSynthesized ( firstChild ) && firstChild . parent === parentNode ) {
4290
+ if ( firstChild . kind === SyntaxKind . JsxText ) {
4291
+ // JsxText will be written with its leading whitespace, so don't add more manually.
4292
+ return 0 ;
4293
+ }
4294
+ if ( ! positionIsSynthesized ( parentNode . pos ) && ! nodeIsSynthesized ( firstChild ) && firstChild . parent === parentNode ) {
4282
4295
if ( preserveSourceNewlines ) {
4283
4296
return getEffectiveLines (
4284
4297
includeComments => getLinesBetweenPositionAndPrecedingNonWhitespaceCharacter (
@@ -4288,7 +4301,7 @@ namespace ts {
4288
4301
}
4289
4302
return rangeStartPositionsAreOnSameLine ( parentNode , firstChild , currentSourceFile ! ) ? 0 : 1 ;
4290
4303
}
4291
- else if ( synthesizedNodeStartsOnNewLine ( firstChild , format ) ) {
4304
+ if ( synthesizedNodeStartsOnNewLine ( firstChild , format ) ) {
4292
4305
return 1 ;
4293
4306
}
4294
4307
}
@@ -4300,6 +4313,10 @@ namespace ts {
4300
4313
if ( previousNode === undefined || nextNode === undefined ) {
4301
4314
return 0 ;
4302
4315
}
4316
+ if ( nextNode . kind === SyntaxKind . JsxText ) {
4317
+ // JsxText will be written with its leading whitespace, so don't add more manually.
4318
+ return 0 ;
4319
+ }
4303
4320
else if ( ! nodeIsSynthesized ( previousNode ) && ! nodeIsSynthesized ( nextNode ) && previousNode . parent === nextNode . parent ) {
4304
4321
return getEffectiveLines (
4305
4322
includeComments => getLinesBetweenRangeEndAndRangeStart (
@@ -4318,13 +4335,13 @@ namespace ts {
4318
4335
return format & ListFormat . MultiLine ? 1 : 0 ;
4319
4336
}
4320
4337
4321
- function getClosingLineTerminatorCount ( parentNode : TextRange , children : NodeArray < Node > , format : ListFormat ) : number {
4338
+ function getClosingLineTerminatorCount ( parentNode : TextRange , children : NodeArray < Node > | Node , format : ListFormat ) : number {
4322
4339
if ( format & ListFormat . PreserveLines || preserveSourceNewlines ) {
4323
4340
if ( format & ListFormat . PreferNewLine ) {
4324
4341
return 1 ;
4325
4342
}
4326
4343
4327
- const lastChild = lastOrUndefined ( children ) ;
4344
+ const lastChild = isArray ( children ) ? lastOrUndefined ( children ) : children ;
4328
4345
if ( lastChild === undefined ) {
4329
4346
return rangeIsOnSingleLine ( parentNode , currentSourceFile ! ) ? 0 : 1 ;
4330
4347
}
0 commit comments