mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-13 16:34:39 -06:00
Improve names of whitespace functions
This commit is contained in:
parent
fee06acf84
commit
2c40fea9f1
@ -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;
|
||||
|
||||
@ -365,12 +365,12 @@ namespace ts {
|
||||
|
||||
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
|
||||
export function isWhiteSpaceLike(ch: number): boolean {
|
||||
return isWhiteSpace(ch) || isLineBreak(ch);
|
||||
export function isWhiteSpace(ch: number): boolean {
|
||||
return isWhiteSpaceSingleLine(ch) || isLineBreak(ch);
|
||||
}
|
||||
|
||||
/** Does not include line breaks. For that, see isWhiteSpaceLike. */
|
||||
export function isWhiteSpace(ch: number): boolean {
|
||||
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 ||
|
||||
@ -511,7 +511,7 @@ namespace ts {
|
||||
break;
|
||||
|
||||
default:
|
||||
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpaceLike(ch))) {
|
||||
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpace(ch))) {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
@ -664,7 +664,7 @@ namespace ts {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpaceLike(ch))) {
|
||||
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpace(ch))) {
|
||||
if (result && result.length && isLineBreak(ch)) {
|
||||
lastOrUndefined(result).hasTrailingNewLine = true;
|
||||
}
|
||||
@ -1209,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;
|
||||
@ -1527,7 +1527,7 @@ namespace ts {
|
||||
}
|
||||
return token = getIdentifierToken();
|
||||
}
|
||||
else if (isWhiteSpace(ch)) {
|
||||
else if (isWhiteSpaceSingleLine(ch)) {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
@ -1696,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 {
|
||||
|
||||
@ -2607,7 +2607,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());
|
||||
|
||||
@ -78,7 +78,7 @@ namespace ts.formatting {
|
||||
// 1. the end of the previous line
|
||||
// 2. the last non-whitespace character in the current line
|
||||
let endOfFormatSpan = getEndLinePosition(line, sourceFile);
|
||||
while (isWhiteSpace(sourceFile.text.charCodeAt(endOfFormatSpan))) {
|
||||
while (isWhiteSpaceSingleLine(sourceFile.text.charCodeAt(endOfFormatSpan))) {
|
||||
endOfFormatSpan--;
|
||||
}
|
||||
// if the character at the end of the span is a line break, we shouldn't include it, because it indicates we don't want to
|
||||
@ -966,7 +966,7 @@ namespace ts.formatting {
|
||||
|
||||
const whitespaceStart = getTrailingWhitespaceStartPosition(lineStartPosition, lineEndPosition);
|
||||
if (whitespaceStart !== -1) {
|
||||
Debug.assert(whitespaceStart === lineStartPosition || !isWhiteSpace(sourceFile.text.charCodeAt(whitespaceStart - 1)));
|
||||
Debug.assert(whitespaceStart === lineStartPosition || !isWhiteSpaceSingleLine(sourceFile.text.charCodeAt(whitespaceStart - 1)));
|
||||
recordDelete(whitespaceStart, lineEndPosition + 1 - whitespaceStart);
|
||||
}
|
||||
}
|
||||
@ -978,7 +978,7 @@ namespace ts.formatting {
|
||||
*/
|
||||
function getTrailingWhitespaceStartPosition(start: number, end: number) {
|
||||
let pos = end;
|
||||
while (pos >= start && isWhiteSpace(sourceFile.text.charCodeAt(pos))) {
|
||||
while (pos >= start && isWhiteSpaceSingleLine(sourceFile.text.charCodeAt(pos))) {
|
||||
pos--;
|
||||
}
|
||||
if (pos !== end) {
|
||||
|
||||
@ -42,7 +42,7 @@ namespace ts.formatting {
|
||||
let current = position;
|
||||
while (current > 0) {
|
||||
const char = sourceFile.text.charCodeAt(current);
|
||||
if (!isWhiteSpaceLike(char)) {
|
||||
if (!isWhiteSpace(char)) {
|
||||
break;
|
||||
}
|
||||
current--;
|
||||
@ -406,7 +406,7 @@ namespace ts.formatting {
|
||||
let column = 0;
|
||||
for (let pos = startPos; pos < endPos; pos++) {
|
||||
const ch = sourceFile.text.charCodeAt(pos);
|
||||
if (!isWhiteSpace(ch)) {
|
||||
if (!isWhiteSpaceSingleLine(ch)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@ -474,7 +474,7 @@ namespace ts {
|
||||
|
||||
for (; pos < end; pos++) {
|
||||
const ch = sourceFile.text.charCodeAt(pos);
|
||||
if (!isWhiteSpace(ch)) {
|
||||
if (!isWhiteSpaceSingleLine(ch)) {
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
@ -493,7 +493,7 @@ namespace ts {
|
||||
function isName(pos: number, end: number, sourceFile: SourceFile, name: string) {
|
||||
return pos + name.length < end &&
|
||||
sourceFile.text.substr(pos, name.length) === name &&
|
||||
isWhiteSpaceLike(sourceFile.text.charCodeAt(pos + name.length));
|
||||
isWhiteSpace(sourceFile.text.charCodeAt(pos + name.length));
|
||||
}
|
||||
|
||||
function isParamTag(pos: number, end: number, sourceFile: SourceFile) {
|
||||
@ -688,7 +688,7 @@ namespace ts {
|
||||
return paramDocComments;
|
||||
|
||||
function consumeWhiteSpaces(pos: number) {
|
||||
while (pos < end && isWhiteSpace(sourceFile.text.charCodeAt(pos))) {
|
||||
while (pos < end && isWhiteSpaceSingleLine(sourceFile.text.charCodeAt(pos))) {
|
||||
pos++;
|
||||
}
|
||||
|
||||
@ -5725,7 +5725,7 @@ namespace ts {
|
||||
|
||||
// Avoid recalculating getStart() by iterating backwards.
|
||||
for (let j = ifKeyword.getStart() - 1; j >= elseKeyword.end; j--) {
|
||||
if (!isWhiteSpace(sourceFile.text.charCodeAt(j))) {
|
||||
if (!isWhiteSpaceSingleLine(sourceFile.text.charCodeAt(j))) {
|
||||
shouldCombindElseAndIf = false;
|
||||
break;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user