@@ -649,6 +649,11 @@ namespace ts.formatting {
649
649
if ( tokenInfo . token . end > node . end ) {
650
650
break ;
651
651
}
652
+ if ( node . kind === SyntaxKind . JsxText ) {
653
+ // Intentation rules for jsx text are handled by `indentMultilineCommentOrJsxText` inside `processChildNode`; just fastforward past it here
654
+ formattingScanner . advance ( ) ;
655
+ continue ;
656
+ }
652
657
consumeTokenAndAdvanceScanner ( tokenInfo , node , nodeDynamicIndentation , node ) ;
653
658
}
654
659
@@ -736,10 +741,21 @@ namespace ts.formatting {
736
741
const childIndentation = computeIndentation ( child , childStartLine , childIndentationAmount , node , parentDynamicIndentation , effectiveParentStartLine ) ;
737
742
738
743
processNode ( child , childContextNode , childStartLine , undecoratedChildStartLine , childIndentation . indentation , childIndentation . delta ) ;
739
-
740
744
if ( child . kind === SyntaxKind . JsxText ) {
741
745
const range : TextRange = { pos : child . getStart ( ) , end : child . getEnd ( ) } ;
742
- indentMultilineCommentOrJsxText ( range , childIndentation . indentation , /*firstLineIsIndented*/ true , /*indentFinalLine*/ false ) ;
746
+ if ( range . pos !== range . end ) { // don't indent zero-width jsx text
747
+ const siblings = parent . getChildren ( sourceFile ) ;
748
+ const currentIndex = findIndex ( siblings , arg => arg . pos === child . pos ) ;
749
+ const previousNode = siblings [ currentIndex - 1 ] ;
750
+ if ( previousNode ) {
751
+ // The jsx text needs no indentation whatsoever if it ends on the same line the previous sibling ends on
752
+ if ( sourceFile . getLineAndCharacterOfPosition ( range . end ) . line !== sourceFile . getLineAndCharacterOfPosition ( previousNode . end ) . line ) {
753
+ // The first line is (already) "indented" if the text starts on the same line as the previous sibling element ends on
754
+ const firstLineIsIndented = sourceFile . getLineAndCharacterOfPosition ( range . pos ) . line === sourceFile . getLineAndCharacterOfPosition ( previousNode . end ) . line ;
755
+ indentMultilineCommentOrJsxText ( range , childIndentation . indentation , firstLineIsIndented , /*indentFinalLine*/ false , /*jsxStyle*/ true ) ;
756
+ }
757
+ }
758
+ }
743
759
}
744
760
745
761
childContextNode = node ;
@@ -1039,7 +1055,7 @@ namespace ts.formatting {
1039
1055
return indentationString !== sourceFile . text . substr ( startLinePosition , indentationString . length ) ;
1040
1056
}
1041
1057
1042
- function indentMultilineCommentOrJsxText ( commentRange : TextRange , indentation : number , firstLineIsIndented : boolean , indentFinalLine = true ) {
1058
+ function indentMultilineCommentOrJsxText ( commentRange : TextRange , indentation : number , firstLineIsIndented : boolean , indentFinalLine = true , jsxTextStyleIndent ?: boolean ) {
1043
1059
// split comment in lines
1044
1060
let startLine = sourceFile . getLineAndCharacterOfPosition ( commentRange . pos ) . line ;
1045
1061
const endLine = sourceFile . getLineAndCharacterOfPosition ( commentRange . end ) . line ;
@@ -1070,7 +1086,7 @@ namespace ts.formatting {
1070
1086
const nonWhitespaceColumnInFirstPart =
1071
1087
SmartIndenter . findFirstNonWhitespaceCharacterAndColumn ( startLinePos , parts [ 0 ] . pos , sourceFile , options ) ;
1072
1088
1073
- if ( indentation === nonWhitespaceColumnInFirstPart . column ) {
1089
+ if ( indentation === nonWhitespaceColumnInFirstPart . column && ! jsxTextStyleIndent ) {
1074
1090
return ;
1075
1091
}
1076
1092
@@ -1081,14 +1097,19 @@ namespace ts.formatting {
1081
1097
}
1082
1098
1083
1099
// shift all parts on the delta size
1084
- const delta = indentation - nonWhitespaceColumnInFirstPart . column ;
1100
+ let delta = indentation - nonWhitespaceColumnInFirstPart . column ;
1085
1101
for ( let i = startIndex ; i < parts . length ; i ++ , startLine ++ ) {
1086
1102
const startLinePos = getStartPositionOfLine ( startLine , sourceFile ) ;
1087
1103
const nonWhitespaceCharacterAndColumn =
1088
1104
i === 0
1089
1105
? nonWhitespaceColumnInFirstPart
1090
1106
: SmartIndenter . findFirstNonWhitespaceCharacterAndColumn ( parts [ i ] . pos , parts [ i ] . end , sourceFile , options ) ;
1091
-
1107
+ if ( jsxTextStyleIndent ) {
1108
+ // skip adding indentation to blank lines
1109
+ if ( isLineBreak ( sourceFile . text . charCodeAt ( getStartPositionOfLine ( startLine , sourceFile ) ) ) ) continue ;
1110
+ // reset delta on every line
1111
+ delta = indentation - nonWhitespaceCharacterAndColumn . column ;
1112
+ }
1092
1113
const newIndentation = nonWhitespaceCharacterAndColumn . column + delta ;
1093
1114
if ( newIndentation > 0 ) {
1094
1115
const indentationString = getIndentationString ( newIndentation , options ) ;
0 commit comments