Skip to content

Commit 0026225

Browse files
Update LKG.
1 parent eaf97e0 commit 0026225

File tree

6 files changed

+198
-22
lines changed

6 files changed

+198
-22
lines changed

lib/tsc.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7106,7 +7106,11 @@ var ts;
71067106
return token = 18;
71077107
}
71087108
var firstNonWhitespace = 0;
7109+
var lastNonWhitespace = -1;
71097110
while (pos < end) {
7111+
if (!isWhiteSpaceSingleLine(char)) {
7112+
lastNonWhitespace = pos;
7113+
}
71107114
char = text.charCodeAt(pos);
71117115
if (char === 123) {
71127116
break;
@@ -7118,6 +7122,8 @@ var ts;
71187122
}
71197123
break;
71207124
}
7125+
if (lastNonWhitespace > 0)
7126+
lastNonWhitespace++;
71217127
if (isLineBreak(char) && firstNonWhitespace === 0) {
71227128
firstNonWhitespace = -1;
71237129
}
@@ -7126,7 +7132,8 @@ var ts;
71267132
}
71277133
pos++;
71287134
}
7129-
tokenValue = text.substring(startPos, pos);
7135+
var endPosition = lastNonWhitespace === -1 ? pos : lastNonWhitespace;
7136+
tokenValue = text.substring(startPos, endPosition);
71307137
return firstNonWhitespace === -1 ? 12 : 11;
71317138
}
71327139
function scanJsxIdentifier() {

lib/tsserver.js

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

lib/tsserverlibrary.js

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9890,9 +9890,15 @@ var ts;
98909890
}
98919891
// First non-whitespace character on this line.
98929892
var firstNonWhitespace = 0;
9893+
var lastNonWhitespace = -1;
98939894
// These initial values are special because the first line is:
98949895
// firstNonWhitespace = 0 to indicate that we want leading whitespace,
98959896
while (pos < end) {
9897+
// We want to keep track of the last non-whitespace (but including
9898+
// newlines character for hitting the end of the JSX Text region)
9899+
if (!isWhiteSpaceSingleLine(char)) {
9900+
lastNonWhitespace = pos;
9901+
}
98969902
char = text.charCodeAt(pos);
98979903
if (char === 123 /* openBrace */) {
98989904
break;
@@ -9904,6 +9910,8 @@ var ts;
99049910
}
99059911
break;
99069912
}
9913+
if (lastNonWhitespace > 0)
9914+
lastNonWhitespace++;
99079915
// FirstNonWhitespace is 0, then we only see whitespaces so far. If we see a linebreak, we want to ignore that whitespaces.
99089916
// i.e (- : whitespace)
99099917
// <div>----
@@ -9918,7 +9926,8 @@ var ts;
99189926
}
99199927
pos++;
99209928
}
9921-
tokenValue = text.substring(startPos, pos);
9929+
var endPosition = lastNonWhitespace === -1 ? pos : lastNonWhitespace;
9930+
tokenValue = text.substring(startPos, endPosition);
99229931
return firstNonWhitespace === -1 ? 12 /* JsxTextAllWhiteSpaces */ : 11 /* JsxText */;
99239932
}
99249933
// Scans a JSX identifier; these differ from normal identifiers in that
@@ -121032,7 +121041,14 @@ var ts;
121032121041
return false;
121033121042
}
121034121043
function shouldRescanJsxText(node) {
121035-
return node.kind === 11 /* JsxText */;
121044+
var isJSXText = ts.isJsxText(node);
121045+
if (isJSXText) {
121046+
var containingElement = ts.findAncestor(node.parent, function (p) { return ts.isJsxElement(p); });
121047+
if (!containingElement)
121048+
return false; // should never happen
121049+
return !ts.isParenthesizedExpression(containingElement.parent);
121050+
}
121051+
return false;
121036121052
}
121037121053
function shouldRescanSlashToken(container) {
121038121054
return container.kind === 13 /* RegularExpressionLiteral */;
@@ -122547,6 +122563,11 @@ var ts;
122547122563
if (tokenInfo.token.end > node.end) {
122548122564
break;
122549122565
}
122566+
if (node.kind === 11 /* JsxText */) {
122567+
// Intentation rules for jsx text are handled by `indentMultilineCommentOrJsxText` inside `processChildNode`; just fastforward past it here
122568+
formattingScanner.advance();
122569+
continue;
122570+
}
122550122571
consumeTokenAndAdvanceScanner(tokenInfo, node, nodeDynamicIndentation, node);
122551122572
}
122552122573
if (!node.parent && formattingScanner.isOnEOF()) {
@@ -122605,7 +122626,19 @@ var ts;
122605122626
processNode(child, childContextNode, childStartLine, undecoratedChildStartLine, childIndentation.indentation, childIndentation.delta);
122606122627
if (child.kind === 11 /* JsxText */) {
122607122628
var range = { pos: child.getStart(), end: child.getEnd() };
122608-
indentMultilineCommentOrJsxText(range, childIndentation.indentation, /*firstLineIsIndented*/ true, /*indentFinalLine*/ false);
122629+
if (range.pos !== range.end) { // don't indent zero-width jsx text
122630+
var siblings = parent.getChildren(sourceFile);
122631+
var currentIndex = ts.findIndex(siblings, function (arg) { return arg.pos === child.pos; });
122632+
var previousNode = siblings[currentIndex - 1];
122633+
if (previousNode) {
122634+
// The jsx text needs no indentation whatsoever if it ends on the same line the previous sibling ends on
122635+
if (sourceFile.getLineAndCharacterOfPosition(range.end).line !== sourceFile.getLineAndCharacterOfPosition(previousNode.end).line) {
122636+
// The first line is (already) "indented" if the text starts on the same line as the previous sibling element ends on
122637+
var firstLineIsIndented = sourceFile.getLineAndCharacterOfPosition(range.pos).line === sourceFile.getLineAndCharacterOfPosition(previousNode.end).line;
122638+
indentMultilineCommentOrJsxText(range, childIndentation.indentation, firstLineIsIndented, /*indentFinalLine*/ false, /*jsxStyle*/ true);
122639+
}
122640+
}
122641+
}
122609122642
}
122610122643
childContextNode = node;
122611122644
if (isFirstListItem && parent.kind === 192 /* ArrayLiteralExpression */ && inheritedIndentation === -1 /* Unknown */) {
@@ -122846,7 +122879,7 @@ var ts;
122846122879
function indentationIsDifferent(indentationString, startLinePosition) {
122847122880
return indentationString !== sourceFile.text.substr(startLinePosition, indentationString.length);
122848122881
}
122849-
function indentMultilineCommentOrJsxText(commentRange, indentation, firstLineIsIndented, indentFinalLine) {
122882+
function indentMultilineCommentOrJsxText(commentRange, indentation, firstLineIsIndented, indentFinalLine, jsxTextStyleIndent) {
122850122883
if (indentFinalLine === void 0) { indentFinalLine = true; }
122851122884
// split comment in lines
122852122885
var startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line;
@@ -122872,7 +122905,7 @@ var ts;
122872122905
return;
122873122906
var startLinePos = ts.getStartPositionOfLine(startLine, sourceFile);
122874122907
var nonWhitespaceColumnInFirstPart = formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(startLinePos, parts[0].pos, sourceFile, options);
122875-
if (indentation === nonWhitespaceColumnInFirstPart.column) {
122908+
if (indentation === nonWhitespaceColumnInFirstPart.column && !jsxTextStyleIndent) {
122876122909
return;
122877122910
}
122878122911
var startIndex = 0;
@@ -122887,6 +122920,13 @@ var ts;
122887122920
var nonWhitespaceCharacterAndColumn = i === 0
122888122921
? nonWhitespaceColumnInFirstPart
122889122922
: formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(parts[i].pos, parts[i].end, sourceFile, options);
122923+
if (jsxTextStyleIndent) {
122924+
// skip adding indentation to blank lines
122925+
if (ts.isLineBreak(sourceFile.text.charCodeAt(ts.getStartPositionOfLine(startLine, sourceFile))))
122926+
continue;
122927+
// reset delta on every line
122928+
delta = indentation - nonWhitespaceCharacterAndColumn.column;
122929+
}
122890122930
var newIndentation = nonWhitespaceCharacterAndColumn.column + delta;
122891122931
if (newIndentation > 0) {
122892122932
var indentationString = getIndentationString(newIndentation, options);

0 commit comments

Comments
 (0)