@@ -2365,16 +2365,10 @@ namespace ts {
2365
2365
2366
2366
function emitParenthesizedExpression ( node : ParenthesizedExpression ) {
2367
2367
const openParenPos = emitTokenWithComment ( SyntaxKind . OpenParenToken , node . pos , writePunctuation , node ) ;
2368
- const leadingNewlines = preserveSourceNewlines && getLeadingLineTerminatorCount ( node , [ node . expression ] , ListFormat . None ) ;
2369
- if ( leadingNewlines ) {
2370
- writeLinesAndIndent ( leadingNewlines , /*writeLinesIfNotIndenting*/ false ) ;
2371
- }
2368
+ const indented = writeLineSeparatorsAndIndentBefore ( node . expression , node ) ;
2372
2369
emitExpression ( node . expression ) ;
2373
- const trailingNewlines = preserveSourceNewlines && getClosingLineTerminatorCount ( node , [ node . expression ] , ListFormat . None ) ;
2374
- if ( trailingNewlines ) {
2375
- writeLine ( trailingNewlines ) ;
2376
- }
2377
- decreaseIndentIf ( leadingNewlines ) ;
2370
+ writeLineSeparatorsAfter ( node . expression , node ) ;
2371
+ decreaseIndentIf ( indented ) ;
2378
2372
emitTokenWithComment ( SyntaxKind . CloseParenToken , node . expression ? node . expression . end : openParenPos , writePunctuation , node ) ;
2379
2373
}
2380
2374
@@ -3292,12 +3286,15 @@ namespace ts {
3292
3286
writePunctuation ( "<" ) ;
3293
3287
3294
3288
if ( isJsxOpeningElement ( node ) ) {
3289
+ const indented = writeLineSeparatorsAndIndentBefore ( node . tagName , node ) ;
3295
3290
emitJsxTagName ( node . tagName ) ;
3296
3291
emitTypeArguments ( node , node . typeArguments ) ;
3297
3292
if ( node . attributes . properties && node . attributes . properties . length > 0 ) {
3298
3293
writeSpace ( ) ;
3299
3294
}
3300
3295
emit ( node . attributes ) ;
3296
+ writeLineSeparatorsAfter ( node . attributes , node ) ;
3297
+ decreaseIndentIf ( indented ) ;
3301
3298
}
3302
3299
3303
3300
writePunctuation ( ">" ) ;
@@ -4399,6 +4396,21 @@ namespace ts {
4399
4396
return lines ;
4400
4397
}
4401
4398
4399
+ function writeLineSeparatorsAndIndentBefore ( node : Node , parent : Node ) : boolean {
4400
+ const leadingNewlines = preserveSourceNewlines && getLeadingLineTerminatorCount ( parent , [ node ] , ListFormat . None ) ;
4401
+ if ( leadingNewlines ) {
4402
+ writeLinesAndIndent ( leadingNewlines , /*writeLinesIfNotIndenting*/ false ) ;
4403
+ }
4404
+ return ! ! leadingNewlines ;
4405
+ }
4406
+
4407
+ function writeLineSeparatorsAfter ( node : Node , parent : Node ) {
4408
+ const trailingNewlines = preserveSourceNewlines && getClosingLineTerminatorCount ( parent , [ node ] , ListFormat . None ) ;
4409
+ if ( trailingNewlines ) {
4410
+ writeLine ( trailingNewlines ) ;
4411
+ }
4412
+ }
4413
+
4402
4414
function synthesizedNodeStartsOnNewLine ( node : Node , format : ListFormat ) {
4403
4415
if ( nodeIsSynthesized ( node ) ) {
4404
4416
const startsOnNewLine = getStartsOnNewLine ( node ) ;
0 commit comments