@@ -9740,9 +9740,15 @@ var ts;
97409740 }
97419741 // First non-whitespace character on this line.
97429742 var firstNonWhitespace = 0;
9743+ var lastNonWhitespace = -1;
97439744 // These initial values are special because the first line is:
97449745 // firstNonWhitespace = 0 to indicate that we want leading whitespace,
97459746 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+ }
97469752 char = text.charCodeAt(pos);
97479753 if (char === 123 /* openBrace */) {
97489754 break;
@@ -9754,6 +9760,8 @@ var ts;
97549760 }
97559761 break;
97569762 }
9763+ if (lastNonWhitespace > 0)
9764+ lastNonWhitespace++;
97579765 // FirstNonWhitespace is 0, then we only see whitespaces so far. If we see a linebreak, we want to ignore that whitespaces.
97589766 // i.e (- : whitespace)
97599767 // <div>----
@@ -9768,7 +9776,8 @@ var ts;
97689776 }
97699777 pos++;
97709778 }
9771- tokenValue = text.substring(startPos, pos);
9779+ var endPosition = lastNonWhitespace === -1 ? pos : lastNonWhitespace;
9780+ tokenValue = text.substring(startPos, endPosition);
97729781 return firstNonWhitespace === -1 ? 12 /* JsxTextAllWhiteSpaces */ : 11 /* JsxText */;
97739782 }
97749783 // Scans a JSX identifier; these differ from normal identifiers in that
@@ -120509,7 +120518,14 @@ var ts;
120509120518 return false;
120510120519 }
120511120520 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;
120513120529 }
120514120530 function shouldRescanSlashToken(container) {
120515120531 return container.kind === 13 /* RegularExpressionLiteral */;
@@ -122024,6 +122040,11 @@ var ts;
122024122040 if (tokenInfo.token.end > node.end) {
122025122041 break;
122026122042 }
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+ }
122027122048 consumeTokenAndAdvanceScanner(tokenInfo, node, nodeDynamicIndentation, node);
122028122049 }
122029122050 if (!node.parent && formattingScanner.isOnEOF()) {
@@ -122082,7 +122103,19 @@ var ts;
122082122103 processNode(child, childContextNode, childStartLine, undecoratedChildStartLine, childIndentation.indentation, childIndentation.delta);
122083122104 if (child.kind === 11 /* JsxText */) {
122084122105 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+ }
122086122119 }
122087122120 childContextNode = node;
122088122121 if (isFirstListItem && parent.kind === 192 /* ArrayLiteralExpression */ && inheritedIndentation === -1 /* Unknown */) {
@@ -122323,7 +122356,7 @@ var ts;
122323122356 function indentationIsDifferent(indentationString, startLinePosition) {
122324122357 return indentationString !== sourceFile.text.substr(startLinePosition, indentationString.length);
122325122358 }
122326- function indentMultilineCommentOrJsxText(commentRange, indentation, firstLineIsIndented, indentFinalLine) {
122359+ function indentMultilineCommentOrJsxText(commentRange, indentation, firstLineIsIndented, indentFinalLine, jsxTextStyleIndent ) {
122327122360 if (indentFinalLine === void 0) { indentFinalLine = true; }
122328122361 // split comment in lines
122329122362 var startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line;
@@ -122349,7 +122382,7 @@ var ts;
122349122382 return;
122350122383 var startLinePos = ts.getStartPositionOfLine(startLine, sourceFile);
122351122384 var nonWhitespaceColumnInFirstPart = formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(startLinePos, parts[0].pos, sourceFile, options);
122352- if (indentation === nonWhitespaceColumnInFirstPart.column) {
122385+ if (indentation === nonWhitespaceColumnInFirstPart.column && !jsxTextStyleIndent ) {
122353122386 return;
122354122387 }
122355122388 var startIndex = 0;
@@ -122364,6 +122397,13 @@ var ts;
122364122397 var nonWhitespaceCharacterAndColumn = i === 0
122365122398 ? nonWhitespaceColumnInFirstPart
122366122399 : 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+ }
122367122407 var newIndentation = nonWhitespaceCharacterAndColumn.column + delta;
122368122408 if (newIndentation > 0) {
122369122409 var indentationString = getIndentationString(newIndentation, options);
0 commit comments