Skip to content

Commit

Permalink
Update LKG.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielRosenwasser committed Feb 5, 2020
1 parent eaf97e0 commit 0026225
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 22 deletions.
9 changes: 8 additions & 1 deletion lib/tsc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -7118,6 +7122,8 @@ var ts;
}
break;
}
if (lastNonWhitespace > 0)
lastNonWhitespace++;
if (isLineBreak(char) && firstNonWhitespace === 0) {
firstNonWhitespace = -1;
}
Expand All @@ -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() {
Expand Down
50 changes: 45 additions & 5 deletions lib/tsserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
// <div>----
Expand All @@ -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
Expand Down Expand Up @@ -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 */;
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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 */) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
50 changes: 45 additions & 5 deletions lib/tsserverlibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
// <div>----
Expand All @@ -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
Expand Down Expand Up @@ -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 */;
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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 */) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
Loading

0 comments on commit 0026225

Please sign in to comment.