Skip to content

Commit 6427999

Browse files
committed
avoid redeclarations of ch and use const
1 parent 6f56688 commit 6427999

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/impl/scanner.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { ScanError, SyntaxKind, JSONScanner } from '../main';
1212
*/
1313
export function createScanner(text: string, ignoreTrivia: boolean = false): JSONScanner {
1414

15+
const len = text.length;
1516
let pos = 0,
16-
len = text.length,
1717
value: string = '',
1818
tokenOffset = 0,
1919
token: SyntaxKind = SyntaxKind.Unknown,
@@ -109,7 +109,7 @@ export function createScanner(text: string, ignoreTrivia: boolean = false): JSON
109109
scanError = ScanError.UnexpectedEndOfString;
110110
break;
111111
}
112-
let ch = text.charCodeAt(pos);
112+
const ch = text.charCodeAt(pos);
113113
if (ch === CharacterCodes.doubleQuote) {
114114
result += text.substring(start, pos);
115115
pos++;
@@ -122,8 +122,8 @@ export function createScanner(text: string, ignoreTrivia: boolean = false): JSON
122122
scanError = ScanError.UnexpectedEndOfString;
123123
break;
124124
}
125-
ch = text.charCodeAt(pos++);
126-
switch (ch) {
125+
const ch2 = text.charCodeAt(pos++);
126+
switch (ch2) {
127127
case CharacterCodes.doubleQuote:
128128
result += '\"';
129129
break;
@@ -149,9 +149,9 @@ export function createScanner(text: string, ignoreTrivia: boolean = false): JSON
149149
result += '\t';
150150
break;
151151
case CharacterCodes.u:
152-
let ch = scanHexDigits(4, true);
153-
if (ch >= 0) {
154-
result += String.fromCharCode(ch);
152+
const ch3 = scanHexDigits(4, true);
153+
if (ch3 >= 0) {
154+
result += String.fromCharCode(ch3);
155155
} else {
156156
scanError = ScanError.InvalidUnicode;
157157
}
@@ -246,7 +246,7 @@ export function createScanner(text: string, ignoreTrivia: boolean = false): JSON
246246

247247
// comments
248248
case CharacterCodes.slash:
249-
let start = pos - 1;
249+
const start = pos - 1;
250250
// Single-line comment
251251
if (text.charCodeAt(pos + 1) === CharacterCodes.slash) {
252252
pos += 2;
@@ -266,10 +266,10 @@ export function createScanner(text: string, ignoreTrivia: boolean = false): JSON
266266
if (text.charCodeAt(pos + 1) === CharacterCodes.asterisk) {
267267
pos += 2;
268268

269-
let safeLength = len - 1; // For lookahead.
269+
const safeLength = len - 1; // For lookahead.
270270
let commentClosed = false;
271271
while (pos < safeLength) {
272-
let ch = text.charCodeAt(pos);
272+
const ch = text.charCodeAt(pos);
273273

274274
if (ch === CharacterCodes.asterisk && text.charCodeAt(pos + 1) === CharacterCodes.slash) {
275275
pos += 2;

0 commit comments

Comments
 (0)