Skip to content

Commit 5f81ba1

Browse files
committed
Use CharactersCodes and isLineBreak in conditions
1 parent f5e73ab commit 5f81ba1

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/compiler/commandLineParser.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -426,18 +426,19 @@ namespace ts {
426426
let processingSingleLineComment = false;
427427
let processingMultiLineComment = false;
428428
for (let i = 0; i < jsonText.length; i++) {
429+
let currentCharCode = jsonText.charCodeAt(i);
429430
let currentChar = jsonText.charAt(i);
430-
let nextChar = (i + 1 < jsonText.length) ? jsonText.charAt(i + 1) : undefined;
431+
let nextCharCode = (i + 1 < jsonText.length) ? jsonText.charCodeAt(i + 1) : undefined;
431432
if (processingString) {
432-
if (currentChar === "\\"
433-
&& nextChar !== undefined) {
433+
if (currentCharCode === CharacterCodes.backslash
434+
&& nextCharCode !== undefined) {
434435
// Found an escaped character
435436
// consume the \ and the escaped char
436437
result += currentChar;
437-
result += nextChar;
438+
result += jsonText.charAt(i + 1);
438439
i += 1;
439440
}
440-
else if (currentChar === "\"") {
441+
else if (currentCharCode === CharacterCodes.doubleQuote) {
441442
// End of string
442443
result += currentChar;
443444
processingString = false;
@@ -448,7 +449,7 @@ namespace ts {
448449
}
449450
}
450451
else if (processingSingleLineComment) {
451-
if (currentChar === "\n") {
452+
if (isLineBreak(currentCharCode)) {
452453
// End of single line comment
453454
processingSingleLineComment = false;
454455
// Keep the line breaks to keep line numbers aligned
@@ -460,13 +461,13 @@ namespace ts {
460461
}
461462
}
462463
else if (processingMultiLineComment) {
463-
if (currentChar === "*" && nextChar === "/") {
464-
// End of comment
464+
if (currentCharCode === CharacterCodes.asterisk && nextCharCode === CharacterCodes.slash) {
465+
// End of comment */
465466
result += " ";
466467
i += 1;
467468
processingMultiLineComment = false;
468469
}
469-
else if (currentChar === "\n") {
470+
else if (isLineBreak(currentCharCode)) {
470471
// Keep the line breaks to Keep line aligned
471472
result += currentChar;
472473
}
@@ -475,23 +476,23 @@ namespace ts {
475476
result += " ";
476477
}
477478
}
478-
else if (currentChar === "\"") {
479+
else if (currentCharCode === CharacterCodes.doubleQuote) {
479480
// String start
480481
result += currentChar;
481482
processingString = true;
482483
}
483-
else if (currentChar === "#") {
484+
else if (currentCharCode === CharacterCodes.hash) {
484485
// Start of # comment
485486
result += " ";
486487
processingSingleLineComment = true;
487488
}
488-
else if (currentChar === "/" && nextChar === "/") {
489+
else if (currentCharCode === CharacterCodes.slash && nextCharCode === CharacterCodes.slash) {
489490
// Start of // comment
490491
result += " ";
491492
i += 1;
492493
processingSingleLineComment = true;
493494
}
494-
else if (currentChar === "/" && nextChar === "*") {
495+
else if (currentCharCode === CharacterCodes.slash && nextCharCode === CharacterCodes.asterisk) {
495496
// Start of /**/ comment
496497
result += " ";
497498
i += 1;

0 commit comments

Comments
 (0)