Merge pull request #9420 from Microsoft/formatting_loc

Do not scan nodes preceding formatted region, just skip over them
This commit is contained in:
Mohamed Hegazy
2016-07-05 14:40:48 -07:00
committed by GitHub
8 changed files with 55 additions and 22 deletions

View File

@@ -7686,7 +7686,7 @@ const _super = (function (geti, seti) {
}
firstNonWhitespace = -1;
}
else if (!isWhiteSpace(c)) {
else if (!isWhiteSpaceSingleLine(c)) {
lastNonWhitespace = i;
if (firstNonWhitespace === -1) {
firstNonWhitespace = i;

View File

@@ -31,6 +31,7 @@ namespace ts {
scanJsxToken(): SyntaxKind;
scanJSDocToken(): SyntaxKind;
scan(): SyntaxKind;
getText(): string;
// Sets the text for the scanner to scan. An optional subrange starting point and length
// can be provided to have the scanner only scan a portion of the text.
setText(text: string, start?: number, length?: number): void;
@@ -365,6 +366,11 @@ namespace ts {
const hasOwnProperty = Object.prototype.hasOwnProperty;
export function isWhiteSpace(ch: number): boolean {
return isWhiteSpaceSingleLine(ch) || isLineBreak(ch);
}
/** Does not include line breaks. For that, see isWhiteSpaceLike. */
export function isWhiteSpaceSingleLine(ch: number): boolean {
// Note: nextLine is in the Zs space, and should be considered to be a whitespace.
// It is explicitly not a line-break as it isn't in the exact set specified by EcmaScript.
return ch === CharacterCodes.space ||
@@ -505,7 +511,7 @@ namespace ts {
break;
default:
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpace(ch) || isLineBreak(ch))) {
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpace(ch))) {
pos++;
continue;
}
@@ -658,7 +664,7 @@ namespace ts {
}
break;
default:
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpace(ch) || isLineBreak(ch))) {
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpace(ch))) {
if (result && result.length && isLineBreak(ch)) {
lastOrUndefined(result).hasTrailingNewLine = true;
}
@@ -763,6 +769,7 @@ namespace ts {
scanJsxToken,
scanJSDocToken,
scan,
getText,
setText,
setScriptTarget,
setLanguageVariant,
@@ -1202,7 +1209,7 @@ namespace ts {
continue;
}
else {
while (pos < end && isWhiteSpace(text.charCodeAt(pos))) {
while (pos < end && isWhiteSpaceSingleLine(text.charCodeAt(pos))) {
pos++;
}
return token = SyntaxKind.WhitespaceTrivia;
@@ -1520,7 +1527,7 @@ namespace ts {
}
return token = getIdentifierToken();
}
else if (isWhiteSpace(ch)) {
else if (isWhiteSpaceSingleLine(ch)) {
pos++;
continue;
}
@@ -1689,7 +1696,7 @@ namespace ts {
let ch = text.charCodeAt(pos);
while (pos < end) {
ch = text.charCodeAt(pos);
if (isWhiteSpace(ch)) {
if (isWhiteSpaceSingleLine(ch)) {
pos++;
}
else {
@@ -1789,6 +1796,10 @@ namespace ts {
return speculationHelper(callback, /*isLookahead*/ false);
}
function getText(): string {
return text;
}
function setText(newText: string, start: number, length: number) {
text = newText || "";
end = length === undefined ? text.length : start + length;

View File

@@ -2605,7 +2605,7 @@ namespace ts {
function calculateIndent(text: string, pos: number, end: number) {
let currentLineIndent = 0;
for (; pos < end && isWhiteSpace(text.charCodeAt(pos)); pos++) {
for (; pos < end && isWhiteSpaceSingleLine(text.charCodeAt(pos)); pos++) {
if (text.charCodeAt(pos) === CharacterCodes.tab) {
// Tabs = TabSize = indent size and go to next tabStop
currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize());