Skip to content

Commit 2c40fea

Browse files
author
Andy Hanson
committed
Improve names of whitespace functions
1 parent fee06ac commit 2c40fea

6 files changed

Lines changed: 19 additions & 19 deletions

File tree

src/compiler/emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7686,7 +7686,7 @@ const _super = (function (geti, seti) {
76867686
}
76877687
firstNonWhitespace = -1;
76887688
}
7689-
else if (!isWhiteSpace(c)) {
7689+
else if (!isWhiteSpaceSingleLine(c)) {
76907690
lastNonWhitespace = i;
76917691
if (firstNonWhitespace === -1) {
76927692
firstNonWhitespace = i;

src/compiler/scanner.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,12 @@ namespace ts {
365365

366366
const hasOwnProperty = Object.prototype.hasOwnProperty;
367367

368-
export function isWhiteSpaceLike(ch: number): boolean {
369-
return isWhiteSpace(ch) || isLineBreak(ch);
368+
export function isWhiteSpace(ch: number): boolean {
369+
return isWhiteSpaceSingleLine(ch) || isLineBreak(ch);
370370
}
371371

372372
/** Does not include line breaks. For that, see isWhiteSpaceLike. */
373-
export function isWhiteSpace(ch: number): boolean {
373+
export function isWhiteSpaceSingleLine(ch: number): boolean {
374374
// Note: nextLine is in the Zs space, and should be considered to be a whitespace.
375375
// It is explicitly not a line-break as it isn't in the exact set specified by EcmaScript.
376376
return ch === CharacterCodes.space ||
@@ -511,7 +511,7 @@ namespace ts {
511511
break;
512512

513513
default:
514-
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpaceLike(ch))) {
514+
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpace(ch))) {
515515
pos++;
516516
continue;
517517
}
@@ -664,7 +664,7 @@ namespace ts {
664664
}
665665
break;
666666
default:
667-
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpaceLike(ch))) {
667+
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpace(ch))) {
668668
if (result && result.length && isLineBreak(ch)) {
669669
lastOrUndefined(result).hasTrailingNewLine = true;
670670
}
@@ -1209,7 +1209,7 @@ namespace ts {
12091209
continue;
12101210
}
12111211
else {
1212-
while (pos < end && isWhiteSpace(text.charCodeAt(pos))) {
1212+
while (pos < end && isWhiteSpaceSingleLine(text.charCodeAt(pos))) {
12131213
pos++;
12141214
}
12151215
return token = SyntaxKind.WhitespaceTrivia;
@@ -1527,7 +1527,7 @@ namespace ts {
15271527
}
15281528
return token = getIdentifierToken();
15291529
}
1530-
else if (isWhiteSpace(ch)) {
1530+
else if (isWhiteSpaceSingleLine(ch)) {
15311531
pos++;
15321532
continue;
15331533
}
@@ -1696,7 +1696,7 @@ namespace ts {
16961696
let ch = text.charCodeAt(pos);
16971697
while (pos < end) {
16981698
ch = text.charCodeAt(pos);
1699-
if (isWhiteSpace(ch)) {
1699+
if (isWhiteSpaceSingleLine(ch)) {
17001700
pos++;
17011701
}
17021702
else {

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2607,7 +2607,7 @@ namespace ts {
26072607

26082608
function calculateIndent(text: string, pos: number, end: number) {
26092609
let currentLineIndent = 0;
2610-
for (; pos < end && isWhiteSpace(text.charCodeAt(pos)); pos++) {
2610+
for (; pos < end && isWhiteSpaceSingleLine(text.charCodeAt(pos)); pos++) {
26112611
if (text.charCodeAt(pos) === CharacterCodes.tab) {
26122612
// Tabs = TabSize = indent size and go to next tabStop
26132613
currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize());

src/services/formatting/formatting.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ namespace ts.formatting {
7878
// 1. the end of the previous line
7979
// 2. the last non-whitespace character in the current line
8080
let endOfFormatSpan = getEndLinePosition(line, sourceFile);
81-
while (isWhiteSpace(sourceFile.text.charCodeAt(endOfFormatSpan))) {
81+
while (isWhiteSpaceSingleLine(sourceFile.text.charCodeAt(endOfFormatSpan))) {
8282
endOfFormatSpan--;
8383
}
8484
// 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 {
966966

967967
const whitespaceStart = getTrailingWhitespaceStartPosition(lineStartPosition, lineEndPosition);
968968
if (whitespaceStart !== -1) {
969-
Debug.assert(whitespaceStart === lineStartPosition || !isWhiteSpace(sourceFile.text.charCodeAt(whitespaceStart - 1)));
969+
Debug.assert(whitespaceStart === lineStartPosition || !isWhiteSpaceSingleLine(sourceFile.text.charCodeAt(whitespaceStart - 1)));
970970
recordDelete(whitespaceStart, lineEndPosition + 1 - whitespaceStart);
971971
}
972972
}
@@ -978,7 +978,7 @@ namespace ts.formatting {
978978
*/
979979
function getTrailingWhitespaceStartPosition(start: number, end: number) {
980980
let pos = end;
981-
while (pos >= start && isWhiteSpace(sourceFile.text.charCodeAt(pos))) {
981+
while (pos >= start && isWhiteSpaceSingleLine(sourceFile.text.charCodeAt(pos))) {
982982
pos--;
983983
}
984984
if (pos !== end) {

src/services/formatting/smartIndenter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace ts.formatting {
4242
let current = position;
4343
while (current > 0) {
4444
const char = sourceFile.text.charCodeAt(current);
45-
if (!isWhiteSpaceLike(char)) {
45+
if (!isWhiteSpace(char)) {
4646
break;
4747
}
4848
current--;
@@ -406,7 +406,7 @@ namespace ts.formatting {
406406
let column = 0;
407407
for (let pos = startPos; pos < endPos; pos++) {
408408
const ch = sourceFile.text.charCodeAt(pos);
409-
if (!isWhiteSpace(ch)) {
409+
if (!isWhiteSpaceSingleLine(ch)) {
410410
break;
411411
}
412412

src/services/services.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ namespace ts {
474474

475475
for (; pos < end; pos++) {
476476
const ch = sourceFile.text.charCodeAt(pos);
477-
if (!isWhiteSpace(ch)) {
477+
if (!isWhiteSpaceSingleLine(ch)) {
478478
return pos;
479479
}
480480
}
@@ -493,7 +493,7 @@ namespace ts {
493493
function isName(pos: number, end: number, sourceFile: SourceFile, name: string) {
494494
return pos + name.length < end &&
495495
sourceFile.text.substr(pos, name.length) === name &&
496-
isWhiteSpaceLike(sourceFile.text.charCodeAt(pos + name.length));
496+
isWhiteSpace(sourceFile.text.charCodeAt(pos + name.length));
497497
}
498498

499499
function isParamTag(pos: number, end: number, sourceFile: SourceFile) {
@@ -688,7 +688,7 @@ namespace ts {
688688
return paramDocComments;
689689

690690
function consumeWhiteSpaces(pos: number) {
691-
while (pos < end && isWhiteSpace(sourceFile.text.charCodeAt(pos))) {
691+
while (pos < end && isWhiteSpaceSingleLine(sourceFile.text.charCodeAt(pos))) {
692692
pos++;
693693
}
694694

@@ -5725,7 +5725,7 @@ namespace ts {
57255725

57265726
// Avoid recalculating getStart() by iterating backwards.
57275727
for (let j = ifKeyword.getStart() - 1; j >= elseKeyword.end; j--) {
5728-
if (!isWhiteSpace(sourceFile.text.charCodeAt(j))) {
5728+
if (!isWhiteSpaceSingleLine(sourceFile.text.charCodeAt(j))) {
57295729
shouldCombindElseAndIf = false;
57305730
break;
57315731
}

0 commit comments

Comments
 (0)