diff --git a/lib/tsc.js b/lib/tsc.js index 03277b2193b..689ebef5c8b 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -7106,7 +7106,11 @@ var ts; return token = 18; } var firstNonWhitespace = 0; + var lastNonWhitespace = -1; while (pos < end) { + if (!isWhiteSpaceSingleLine(char)) { + lastNonWhitespace = pos; + } char = text.charCodeAt(pos); if (char === 123) { break; @@ -7118,6 +7122,8 @@ var ts; } break; } + if (lastNonWhitespace > 0) + lastNonWhitespace++; if (isLineBreak(char) && firstNonWhitespace === 0) { firstNonWhitespace = -1; } @@ -7126,7 +7132,8 @@ var ts; } pos++; } - tokenValue = text.substring(startPos, pos); + var endPosition = lastNonWhitespace === -1 ? pos : lastNonWhitespace; + tokenValue = text.substring(startPos, endPosition); return firstNonWhitespace === -1 ? 12 : 11; } function scanJsxIdentifier() { diff --git a/lib/tsserver.js b/lib/tsserver.js index 1aca4c95e87..4a6ec3eb783 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -9740,9 +9740,15 @@ var ts; } // First non-whitespace character on this line. var firstNonWhitespace = 0; + var lastNonWhitespace = -1; // These initial values are special because the first line is: // firstNonWhitespace = 0 to indicate that we want leading whitespace, while (pos < end) { + // We want to keep track of the last non-whitespace (but including + // newlines character for hitting the end of the JSX Text region) + if (!isWhiteSpaceSingleLine(char)) { + lastNonWhitespace = pos; + } char = text.charCodeAt(pos); if (char === 123 /* openBrace */) { break; @@ -9754,6 +9760,8 @@ var ts; } break; } + if (lastNonWhitespace > 0) + lastNonWhitespace++; // FirstNonWhitespace is 0, then we only see whitespaces so far. If we see a linebreak, we want to ignore that whitespaces. // i.e (- : whitespace) //
---- @@ -9768,7 +9776,8 @@ var ts; } pos++; } - tokenValue = text.substring(startPos, pos); + var endPosition = lastNonWhitespace === -1 ? pos : lastNonWhitespace; + tokenValue = text.substring(startPos, endPosition); return firstNonWhitespace === -1 ? 12 /* JsxTextAllWhiteSpaces */ : 11 /* JsxText */; } // Scans a JSX identifier; these differ from normal identifiers in that @@ -120509,7 +120518,14 @@ var ts; return false; } function shouldRescanJsxText(node) { - return node.kind === 11 /* JsxText */; + var isJSXText = ts.isJsxText(node); + if (isJSXText) { + var containingElement = ts.findAncestor(node.parent, function (p) { return ts.isJsxElement(p); }); + if (!containingElement) + return false; // should never happen + return !ts.isParenthesizedExpression(containingElement.parent); + } + return false; } function shouldRescanSlashToken(container) { return container.kind === 13 /* RegularExpressionLiteral */; @@ -122024,6 +122040,11 @@ var ts; if (tokenInfo.token.end > node.end) { break; } + if (node.kind === 11 /* JsxText */) { + // Intentation rules for jsx text are handled by `indentMultilineCommentOrJsxText` inside `processChildNode`; just fastforward past it here + formattingScanner.advance(); + continue; + } consumeTokenAndAdvanceScanner(tokenInfo, node, nodeDynamicIndentation, node); } if (!node.parent && formattingScanner.isOnEOF()) { @@ -122082,7 +122103,19 @@ var ts; processNode(child, childContextNode, childStartLine, undecoratedChildStartLine, childIndentation.indentation, childIndentation.delta); if (child.kind === 11 /* JsxText */) { var range = { pos: child.getStart(), end: child.getEnd() }; - indentMultilineCommentOrJsxText(range, childIndentation.indentation, /*firstLineIsIndented*/ true, /*indentFinalLine*/ false); + if (range.pos !== range.end) { // don't indent zero-width jsx text + var siblings = parent.getChildren(sourceFile); + var currentIndex = ts.findIndex(siblings, function (arg) { return arg.pos === child.pos; }); + var previousNode = siblings[currentIndex - 1]; + if (previousNode) { + // The jsx text needs no indentation whatsoever if it ends on the same line the previous sibling ends on + if (sourceFile.getLineAndCharacterOfPosition(range.end).line !== sourceFile.getLineAndCharacterOfPosition(previousNode.end).line) { + // The first line is (already) "indented" if the text starts on the same line as the previous sibling element ends on + var firstLineIsIndented = sourceFile.getLineAndCharacterOfPosition(range.pos).line === sourceFile.getLineAndCharacterOfPosition(previousNode.end).line; + indentMultilineCommentOrJsxText(range, childIndentation.indentation, firstLineIsIndented, /*indentFinalLine*/ false, /*jsxStyle*/ true); + } + } + } } childContextNode = node; if (isFirstListItem && parent.kind === 192 /* ArrayLiteralExpression */ && inheritedIndentation === -1 /* Unknown */) { @@ -122323,7 +122356,7 @@ var ts; function indentationIsDifferent(indentationString, startLinePosition) { return indentationString !== sourceFile.text.substr(startLinePosition, indentationString.length); } - function indentMultilineCommentOrJsxText(commentRange, indentation, firstLineIsIndented, indentFinalLine) { + function indentMultilineCommentOrJsxText(commentRange, indentation, firstLineIsIndented, indentFinalLine, jsxTextStyleIndent) { if (indentFinalLine === void 0) { indentFinalLine = true; } // split comment in lines var startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line; @@ -122349,7 +122382,7 @@ var ts; return; var startLinePos = ts.getStartPositionOfLine(startLine, sourceFile); var nonWhitespaceColumnInFirstPart = formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(startLinePos, parts[0].pos, sourceFile, options); - if (indentation === nonWhitespaceColumnInFirstPart.column) { + if (indentation === nonWhitespaceColumnInFirstPart.column && !jsxTextStyleIndent) { return; } var startIndex = 0; @@ -122364,6 +122397,13 @@ var ts; var nonWhitespaceCharacterAndColumn = i === 0 ? nonWhitespaceColumnInFirstPart : formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(parts[i].pos, parts[i].end, sourceFile, options); + if (jsxTextStyleIndent) { + // skip adding indentation to blank lines + if (ts.isLineBreak(sourceFile.text.charCodeAt(ts.getStartPositionOfLine(startLine, sourceFile)))) + continue; + // reset delta on every line + delta = indentation - nonWhitespaceCharacterAndColumn.column; + } var newIndentation = nonWhitespaceCharacterAndColumn.column + delta; if (newIndentation > 0) { var indentationString = getIndentationString(newIndentation, options); diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 712a7209945..7871c2ca5e0 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -9890,9 +9890,15 @@ var ts; } // First non-whitespace character on this line. var firstNonWhitespace = 0; + var lastNonWhitespace = -1; // These initial values are special because the first line is: // firstNonWhitespace = 0 to indicate that we want leading whitespace, while (pos < end) { + // We want to keep track of the last non-whitespace (but including + // newlines character for hitting the end of the JSX Text region) + if (!isWhiteSpaceSingleLine(char)) { + lastNonWhitespace = pos; + } char = text.charCodeAt(pos); if (char === 123 /* openBrace */) { break; @@ -9904,6 +9910,8 @@ var ts; } break; } + if (lastNonWhitespace > 0) + lastNonWhitespace++; // FirstNonWhitespace is 0, then we only see whitespaces so far. If we see a linebreak, we want to ignore that whitespaces. // i.e (- : whitespace) //
---- @@ -9918,7 +9926,8 @@ var ts; } pos++; } - tokenValue = text.substring(startPos, pos); + var endPosition = lastNonWhitespace === -1 ? pos : lastNonWhitespace; + tokenValue = text.substring(startPos, endPosition); return firstNonWhitespace === -1 ? 12 /* JsxTextAllWhiteSpaces */ : 11 /* JsxText */; } // Scans a JSX identifier; these differ from normal identifiers in that @@ -121032,7 +121041,14 @@ var ts; return false; } function shouldRescanJsxText(node) { - return node.kind === 11 /* JsxText */; + var isJSXText = ts.isJsxText(node); + if (isJSXText) { + var containingElement = ts.findAncestor(node.parent, function (p) { return ts.isJsxElement(p); }); + if (!containingElement) + return false; // should never happen + return !ts.isParenthesizedExpression(containingElement.parent); + } + return false; } function shouldRescanSlashToken(container) { return container.kind === 13 /* RegularExpressionLiteral */; @@ -122547,6 +122563,11 @@ var ts; if (tokenInfo.token.end > node.end) { break; } + if (node.kind === 11 /* JsxText */) { + // Intentation rules for jsx text are handled by `indentMultilineCommentOrJsxText` inside `processChildNode`; just fastforward past it here + formattingScanner.advance(); + continue; + } consumeTokenAndAdvanceScanner(tokenInfo, node, nodeDynamicIndentation, node); } if (!node.parent && formattingScanner.isOnEOF()) { @@ -122605,7 +122626,19 @@ var ts; processNode(child, childContextNode, childStartLine, undecoratedChildStartLine, childIndentation.indentation, childIndentation.delta); if (child.kind === 11 /* JsxText */) { var range = { pos: child.getStart(), end: child.getEnd() }; - indentMultilineCommentOrJsxText(range, childIndentation.indentation, /*firstLineIsIndented*/ true, /*indentFinalLine*/ false); + if (range.pos !== range.end) { // don't indent zero-width jsx text + var siblings = parent.getChildren(sourceFile); + var currentIndex = ts.findIndex(siblings, function (arg) { return arg.pos === child.pos; }); + var previousNode = siblings[currentIndex - 1]; + if (previousNode) { + // The jsx text needs no indentation whatsoever if it ends on the same line the previous sibling ends on + if (sourceFile.getLineAndCharacterOfPosition(range.end).line !== sourceFile.getLineAndCharacterOfPosition(previousNode.end).line) { + // The first line is (already) "indented" if the text starts on the same line as the previous sibling element ends on + var firstLineIsIndented = sourceFile.getLineAndCharacterOfPosition(range.pos).line === sourceFile.getLineAndCharacterOfPosition(previousNode.end).line; + indentMultilineCommentOrJsxText(range, childIndentation.indentation, firstLineIsIndented, /*indentFinalLine*/ false, /*jsxStyle*/ true); + } + } + } } childContextNode = node; if (isFirstListItem && parent.kind === 192 /* ArrayLiteralExpression */ && inheritedIndentation === -1 /* Unknown */) { @@ -122846,7 +122879,7 @@ var ts; function indentationIsDifferent(indentationString, startLinePosition) { return indentationString !== sourceFile.text.substr(startLinePosition, indentationString.length); } - function indentMultilineCommentOrJsxText(commentRange, indentation, firstLineIsIndented, indentFinalLine) { + function indentMultilineCommentOrJsxText(commentRange, indentation, firstLineIsIndented, indentFinalLine, jsxTextStyleIndent) { if (indentFinalLine === void 0) { indentFinalLine = true; } // split comment in lines var startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line; @@ -122872,7 +122905,7 @@ var ts; return; var startLinePos = ts.getStartPositionOfLine(startLine, sourceFile); var nonWhitespaceColumnInFirstPart = formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(startLinePos, parts[0].pos, sourceFile, options); - if (indentation === nonWhitespaceColumnInFirstPart.column) { + if (indentation === nonWhitespaceColumnInFirstPart.column && !jsxTextStyleIndent) { return; } var startIndex = 0; @@ -122887,6 +122920,13 @@ var ts; var nonWhitespaceCharacterAndColumn = i === 0 ? nonWhitespaceColumnInFirstPart : formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(parts[i].pos, parts[i].end, sourceFile, options); + if (jsxTextStyleIndent) { + // skip adding indentation to blank lines + if (ts.isLineBreak(sourceFile.text.charCodeAt(ts.getStartPositionOfLine(startLine, sourceFile)))) + continue; + // reset delta on every line + delta = indentation - nonWhitespaceCharacterAndColumn.column; + } var newIndentation = nonWhitespaceCharacterAndColumn.column + delta; if (newIndentation > 0) { var indentationString = getIndentationString(newIndentation, options); diff --git a/lib/typescript.js b/lib/typescript.js index 28cac7dff93..60da9586fac 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -9890,9 +9890,15 @@ var ts; } // First non-whitespace character on this line. var firstNonWhitespace = 0; + var lastNonWhitespace = -1; // These initial values are special because the first line is: // firstNonWhitespace = 0 to indicate that we want leading whitespace, while (pos < end) { + // We want to keep track of the last non-whitespace (but including + // newlines character for hitting the end of the JSX Text region) + if (!isWhiteSpaceSingleLine(char)) { + lastNonWhitespace = pos; + } char = text.charCodeAt(pos); if (char === 123 /* openBrace */) { break; @@ -9904,6 +9910,8 @@ var ts; } break; } + if (lastNonWhitespace > 0) + lastNonWhitespace++; // FirstNonWhitespace is 0, then we only see whitespaces so far. If we see a linebreak, we want to ignore that whitespaces. // i.e (- : whitespace) //
---- @@ -9918,7 +9926,8 @@ var ts; } pos++; } - tokenValue = text.substring(startPos, pos); + var endPosition = lastNonWhitespace === -1 ? pos : lastNonWhitespace; + tokenValue = text.substring(startPos, endPosition); return firstNonWhitespace === -1 ? 12 /* JsxTextAllWhiteSpaces */ : 11 /* JsxText */; } // Scans a JSX identifier; these differ from normal identifiers in that @@ -121032,7 +121041,14 @@ var ts; return false; } function shouldRescanJsxText(node) { - return node.kind === 11 /* JsxText */; + var isJSXText = ts.isJsxText(node); + if (isJSXText) { + var containingElement = ts.findAncestor(node.parent, function (p) { return ts.isJsxElement(p); }); + if (!containingElement) + return false; // should never happen + return !ts.isParenthesizedExpression(containingElement.parent); + } + return false; } function shouldRescanSlashToken(container) { return container.kind === 13 /* RegularExpressionLiteral */; @@ -122547,6 +122563,11 @@ var ts; if (tokenInfo.token.end > node.end) { break; } + if (node.kind === 11 /* JsxText */) { + // Intentation rules for jsx text are handled by `indentMultilineCommentOrJsxText` inside `processChildNode`; just fastforward past it here + formattingScanner.advance(); + continue; + } consumeTokenAndAdvanceScanner(tokenInfo, node, nodeDynamicIndentation, node); } if (!node.parent && formattingScanner.isOnEOF()) { @@ -122605,7 +122626,19 @@ var ts; processNode(child, childContextNode, childStartLine, undecoratedChildStartLine, childIndentation.indentation, childIndentation.delta); if (child.kind === 11 /* JsxText */) { var range = { pos: child.getStart(), end: child.getEnd() }; - indentMultilineCommentOrJsxText(range, childIndentation.indentation, /*firstLineIsIndented*/ true, /*indentFinalLine*/ false); + if (range.pos !== range.end) { // don't indent zero-width jsx text + var siblings = parent.getChildren(sourceFile); + var currentIndex = ts.findIndex(siblings, function (arg) { return arg.pos === child.pos; }); + var previousNode = siblings[currentIndex - 1]; + if (previousNode) { + // The jsx text needs no indentation whatsoever if it ends on the same line the previous sibling ends on + if (sourceFile.getLineAndCharacterOfPosition(range.end).line !== sourceFile.getLineAndCharacterOfPosition(previousNode.end).line) { + // The first line is (already) "indented" if the text starts on the same line as the previous sibling element ends on + var firstLineIsIndented = sourceFile.getLineAndCharacterOfPosition(range.pos).line === sourceFile.getLineAndCharacterOfPosition(previousNode.end).line; + indentMultilineCommentOrJsxText(range, childIndentation.indentation, firstLineIsIndented, /*indentFinalLine*/ false, /*jsxStyle*/ true); + } + } + } } childContextNode = node; if (isFirstListItem && parent.kind === 192 /* ArrayLiteralExpression */ && inheritedIndentation === -1 /* Unknown */) { @@ -122846,7 +122879,7 @@ var ts; function indentationIsDifferent(indentationString, startLinePosition) { return indentationString !== sourceFile.text.substr(startLinePosition, indentationString.length); } - function indentMultilineCommentOrJsxText(commentRange, indentation, firstLineIsIndented, indentFinalLine) { + function indentMultilineCommentOrJsxText(commentRange, indentation, firstLineIsIndented, indentFinalLine, jsxTextStyleIndent) { if (indentFinalLine === void 0) { indentFinalLine = true; } // split comment in lines var startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line; @@ -122872,7 +122905,7 @@ var ts; return; var startLinePos = ts.getStartPositionOfLine(startLine, sourceFile); var nonWhitespaceColumnInFirstPart = formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(startLinePos, parts[0].pos, sourceFile, options); - if (indentation === nonWhitespaceColumnInFirstPart.column) { + if (indentation === nonWhitespaceColumnInFirstPart.column && !jsxTextStyleIndent) { return; } var startIndex = 0; @@ -122887,6 +122920,13 @@ var ts; var nonWhitespaceCharacterAndColumn = i === 0 ? nonWhitespaceColumnInFirstPart : formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(parts[i].pos, parts[i].end, sourceFile, options); + if (jsxTextStyleIndent) { + // skip adding indentation to blank lines + if (ts.isLineBreak(sourceFile.text.charCodeAt(ts.getStartPositionOfLine(startLine, sourceFile)))) + continue; + // reset delta on every line + delta = indentation - nonWhitespaceCharacterAndColumn.column; + } var newIndentation = nonWhitespaceCharacterAndColumn.column + delta; if (newIndentation > 0) { var indentationString = getIndentationString(newIndentation, options); diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 8a51f86cb1d..19d6dbbb6af 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -9890,9 +9890,15 @@ var ts; } // First non-whitespace character on this line. var firstNonWhitespace = 0; + var lastNonWhitespace = -1; // These initial values are special because the first line is: // firstNonWhitespace = 0 to indicate that we want leading whitespace, while (pos < end) { + // We want to keep track of the last non-whitespace (but including + // newlines character for hitting the end of the JSX Text region) + if (!isWhiteSpaceSingleLine(char)) { + lastNonWhitespace = pos; + } char = text.charCodeAt(pos); if (char === 123 /* openBrace */) { break; @@ -9904,6 +9910,8 @@ var ts; } break; } + if (lastNonWhitespace > 0) + lastNonWhitespace++; // FirstNonWhitespace is 0, then we only see whitespaces so far. If we see a linebreak, we want to ignore that whitespaces. // i.e (- : whitespace) //
---- @@ -9918,7 +9926,8 @@ var ts; } pos++; } - tokenValue = text.substring(startPos, pos); + var endPosition = lastNonWhitespace === -1 ? pos : lastNonWhitespace; + tokenValue = text.substring(startPos, endPosition); return firstNonWhitespace === -1 ? 12 /* JsxTextAllWhiteSpaces */ : 11 /* JsxText */; } // Scans a JSX identifier; these differ from normal identifiers in that @@ -121032,7 +121041,14 @@ var ts; return false; } function shouldRescanJsxText(node) { - return node.kind === 11 /* JsxText */; + var isJSXText = ts.isJsxText(node); + if (isJSXText) { + var containingElement = ts.findAncestor(node.parent, function (p) { return ts.isJsxElement(p); }); + if (!containingElement) + return false; // should never happen + return !ts.isParenthesizedExpression(containingElement.parent); + } + return false; } function shouldRescanSlashToken(container) { return container.kind === 13 /* RegularExpressionLiteral */; @@ -122547,6 +122563,11 @@ var ts; if (tokenInfo.token.end > node.end) { break; } + if (node.kind === 11 /* JsxText */) { + // Intentation rules for jsx text are handled by `indentMultilineCommentOrJsxText` inside `processChildNode`; just fastforward past it here + formattingScanner.advance(); + continue; + } consumeTokenAndAdvanceScanner(tokenInfo, node, nodeDynamicIndentation, node); } if (!node.parent && formattingScanner.isOnEOF()) { @@ -122605,7 +122626,19 @@ var ts; processNode(child, childContextNode, childStartLine, undecoratedChildStartLine, childIndentation.indentation, childIndentation.delta); if (child.kind === 11 /* JsxText */) { var range = { pos: child.getStart(), end: child.getEnd() }; - indentMultilineCommentOrJsxText(range, childIndentation.indentation, /*firstLineIsIndented*/ true, /*indentFinalLine*/ false); + if (range.pos !== range.end) { // don't indent zero-width jsx text + var siblings = parent.getChildren(sourceFile); + var currentIndex = ts.findIndex(siblings, function (arg) { return arg.pos === child.pos; }); + var previousNode = siblings[currentIndex - 1]; + if (previousNode) { + // The jsx text needs no indentation whatsoever if it ends on the same line the previous sibling ends on + if (sourceFile.getLineAndCharacterOfPosition(range.end).line !== sourceFile.getLineAndCharacterOfPosition(previousNode.end).line) { + // The first line is (already) "indented" if the text starts on the same line as the previous sibling element ends on + var firstLineIsIndented = sourceFile.getLineAndCharacterOfPosition(range.pos).line === sourceFile.getLineAndCharacterOfPosition(previousNode.end).line; + indentMultilineCommentOrJsxText(range, childIndentation.indentation, firstLineIsIndented, /*indentFinalLine*/ false, /*jsxStyle*/ true); + } + } + } } childContextNode = node; if (isFirstListItem && parent.kind === 192 /* ArrayLiteralExpression */ && inheritedIndentation === -1 /* Unknown */) { @@ -122846,7 +122879,7 @@ var ts; function indentationIsDifferent(indentationString, startLinePosition) { return indentationString !== sourceFile.text.substr(startLinePosition, indentationString.length); } - function indentMultilineCommentOrJsxText(commentRange, indentation, firstLineIsIndented, indentFinalLine) { + function indentMultilineCommentOrJsxText(commentRange, indentation, firstLineIsIndented, indentFinalLine, jsxTextStyleIndent) { if (indentFinalLine === void 0) { indentFinalLine = true; } // split comment in lines var startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line; @@ -122872,7 +122905,7 @@ var ts; return; var startLinePos = ts.getStartPositionOfLine(startLine, sourceFile); var nonWhitespaceColumnInFirstPart = formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(startLinePos, parts[0].pos, sourceFile, options); - if (indentation === nonWhitespaceColumnInFirstPart.column) { + if (indentation === nonWhitespaceColumnInFirstPart.column && !jsxTextStyleIndent) { return; } var startIndex = 0; @@ -122887,6 +122920,13 @@ var ts; var nonWhitespaceCharacterAndColumn = i === 0 ? nonWhitespaceColumnInFirstPart : formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(parts[i].pos, parts[i].end, sourceFile, options); + if (jsxTextStyleIndent) { + // skip adding indentation to blank lines + if (ts.isLineBreak(sourceFile.text.charCodeAt(ts.getStartPositionOfLine(startLine, sourceFile)))) + continue; + // reset delta on every line + delta = indentation - nonWhitespaceCharacterAndColumn.column; + } var newIndentation = nonWhitespaceCharacterAndColumn.column + delta; if (newIndentation > 0) { var indentationString = getIndentationString(newIndentation, options); diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index 5e7d12f859f..c1ae03db6f5 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -9729,9 +9729,15 @@ var ts; } // First non-whitespace character on this line. var firstNonWhitespace = 0; + var lastNonWhitespace = -1; // These initial values are special because the first line is: // firstNonWhitespace = 0 to indicate that we want leading whitespace, while (pos < end) { + // We want to keep track of the last non-whitespace (but including + // newlines character for hitting the end of the JSX Text region) + if (!isWhiteSpaceSingleLine(char)) { + lastNonWhitespace = pos; + } char = text.charCodeAt(pos); if (char === 123 /* openBrace */) { break; @@ -9743,6 +9749,8 @@ var ts; } break; } + if (lastNonWhitespace > 0) + lastNonWhitespace++; // FirstNonWhitespace is 0, then we only see whitespaces so far. If we see a linebreak, we want to ignore that whitespaces. // i.e (- : whitespace) //
---- @@ -9757,7 +9765,8 @@ var ts; } pos++; } - tokenValue = text.substring(startPos, pos); + var endPosition = lastNonWhitespace === -1 ? pos : lastNonWhitespace; + tokenValue = text.substring(startPos, endPosition); return firstNonWhitespace === -1 ? 12 /* JsxTextAllWhiteSpaces */ : 11 /* JsxText */; } // Scans a JSX identifier; these differ from normal identifiers in that