@@ -9740,9 +9740,15 @@ var ts;
9740
9740
}
9741
9741
// First non-whitespace character on this line.
9742
9742
var firstNonWhitespace = 0;
9743
+ var lastNonWhitespace = -1;
9743
9744
// These initial values are special because the first line is:
9744
9745
// firstNonWhitespace = 0 to indicate that we want leading whitespace,
9745
9746
while (pos < end) {
9747
+ // We want to keep track of the last non-whitespace (but including
9748
+ // newlines character for hitting the end of the JSX Text region)
9749
+ if (!isWhiteSpaceSingleLine(char)) {
9750
+ lastNonWhitespace = pos;
9751
+ }
9746
9752
char = text.charCodeAt(pos);
9747
9753
if (char === 123 /* openBrace */) {
9748
9754
break;
@@ -9754,6 +9760,8 @@ var ts;
9754
9760
}
9755
9761
break;
9756
9762
}
9763
+ if (lastNonWhitespace > 0)
9764
+ lastNonWhitespace++;
9757
9765
// FirstNonWhitespace is 0, then we only see whitespaces so far. If we see a linebreak, we want to ignore that whitespaces.
9758
9766
// i.e (- : whitespace)
9759
9767
// <div>----
@@ -9768,7 +9776,8 @@ var ts;
9768
9776
}
9769
9777
pos++;
9770
9778
}
9771
- tokenValue = text.substring(startPos, pos);
9779
+ var endPosition = lastNonWhitespace === -1 ? pos : lastNonWhitespace;
9780
+ tokenValue = text.substring(startPos, endPosition);
9772
9781
return firstNonWhitespace === -1 ? 12 /* JsxTextAllWhiteSpaces */ : 11 /* JsxText */;
9773
9782
}
9774
9783
// Scans a JSX identifier; these differ from normal identifiers in that
@@ -120509,7 +120518,14 @@ var ts;
120509
120518
return false;
120510
120519
}
120511
120520
function shouldRescanJsxText(node) {
120512
- return node.kind === 11 /* JsxText */;
120521
+ var isJSXText = ts.isJsxText(node);
120522
+ if (isJSXText) {
120523
+ var containingElement = ts.findAncestor(node.parent, function (p) { return ts.isJsxElement(p); });
120524
+ if (!containingElement)
120525
+ return false; // should never happen
120526
+ return !ts.isParenthesizedExpression(containingElement.parent);
120527
+ }
120528
+ return false;
120513
120529
}
120514
120530
function shouldRescanSlashToken(container) {
120515
120531
return container.kind === 13 /* RegularExpressionLiteral */;
@@ -122024,6 +122040,11 @@ var ts;
122024
122040
if (tokenInfo.token.end > node.end) {
122025
122041
break;
122026
122042
}
122043
+ if (node.kind === 11 /* JsxText */) {
122044
+ // Intentation rules for jsx text are handled by `indentMultilineCommentOrJsxText` inside `processChildNode`; just fastforward past it here
122045
+ formattingScanner.advance();
122046
+ continue;
122047
+ }
122027
122048
consumeTokenAndAdvanceScanner(tokenInfo, node, nodeDynamicIndentation, node);
122028
122049
}
122029
122050
if (!node.parent && formattingScanner.isOnEOF()) {
@@ -122082,7 +122103,19 @@ var ts;
122082
122103
processNode(child, childContextNode, childStartLine, undecoratedChildStartLine, childIndentation.indentation, childIndentation.delta);
122083
122104
if (child.kind === 11 /* JsxText */) {
122084
122105
var range = { pos: child.getStart(), end: child.getEnd() };
122085
- indentMultilineCommentOrJsxText(range, childIndentation.indentation, /*firstLineIsIndented*/ true, /*indentFinalLine*/ false);
122106
+ if (range.pos !== range.end) { // don't indent zero-width jsx text
122107
+ var siblings = parent.getChildren(sourceFile);
122108
+ var currentIndex = ts.findIndex(siblings, function (arg) { return arg.pos === child.pos; });
122109
+ var previousNode = siblings[currentIndex - 1];
122110
+ if (previousNode) {
122111
+ // The jsx text needs no indentation whatsoever if it ends on the same line the previous sibling ends on
122112
+ if (sourceFile.getLineAndCharacterOfPosition(range.end).line !== sourceFile.getLineAndCharacterOfPosition(previousNode.end).line) {
122113
+ // The first line is (already) "indented" if the text starts on the same line as the previous sibling element ends on
122114
+ var firstLineIsIndented = sourceFile.getLineAndCharacterOfPosition(range.pos).line === sourceFile.getLineAndCharacterOfPosition(previousNode.end).line;
122115
+ indentMultilineCommentOrJsxText(range, childIndentation.indentation, firstLineIsIndented, /*indentFinalLine*/ false, /*jsxStyle*/ true);
122116
+ }
122117
+ }
122118
+ }
122086
122119
}
122087
122120
childContextNode = node;
122088
122121
if (isFirstListItem && parent.kind === 192 /* ArrayLiteralExpression */ && inheritedIndentation === -1 /* Unknown */) {
@@ -122323,7 +122356,7 @@ var ts;
122323
122356
function indentationIsDifferent(indentationString, startLinePosition) {
122324
122357
return indentationString !== sourceFile.text.substr(startLinePosition, indentationString.length);
122325
122358
}
122326
- function indentMultilineCommentOrJsxText(commentRange, indentation, firstLineIsIndented, indentFinalLine) {
122359
+ function indentMultilineCommentOrJsxText(commentRange, indentation, firstLineIsIndented, indentFinalLine, jsxTextStyleIndent ) {
122327
122360
if (indentFinalLine === void 0) { indentFinalLine = true; }
122328
122361
// split comment in lines
122329
122362
var startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line;
@@ -122349,7 +122382,7 @@ var ts;
122349
122382
return;
122350
122383
var startLinePos = ts.getStartPositionOfLine(startLine, sourceFile);
122351
122384
var nonWhitespaceColumnInFirstPart = formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(startLinePos, parts[0].pos, sourceFile, options);
122352
- if (indentation === nonWhitespaceColumnInFirstPart.column) {
122385
+ if (indentation === nonWhitespaceColumnInFirstPart.column && !jsxTextStyleIndent ) {
122353
122386
return;
122354
122387
}
122355
122388
var startIndex = 0;
@@ -122364,6 +122397,13 @@ var ts;
122364
122397
var nonWhitespaceCharacterAndColumn = i === 0
122365
122398
? nonWhitespaceColumnInFirstPart
122366
122399
: formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(parts[i].pos, parts[i].end, sourceFile, options);
122400
+ if (jsxTextStyleIndent) {
122401
+ // skip adding indentation to blank lines
122402
+ if (ts.isLineBreak(sourceFile.text.charCodeAt(ts.getStartPositionOfLine(startLine, sourceFile))))
122403
+ continue;
122404
+ // reset delta on every line
122405
+ delta = indentation - nonWhitespaceCharacterAndColumn.column;
122406
+ }
122367
122407
var newIndentation = nonWhitespaceCharacterAndColumn.column + delta;
122368
122408
if (newIndentation > 0) {
122369
122409
var indentationString = getIndentationString(newIndentation, options);
0 commit comments