Skip to content

Commit bf3d27c

Browse files
IvanGoncharovleebyron
authored andcommitted
Lexer: unify unexpected character errors (#1289)
1 parent 0d7a353 commit bf3d27c

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/language/lexer.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,6 @@ function readToken(lexer: Lexer<*>, prev: Token): Token {
207207
const code = charCodeAt.call(body, pos);
208208

209209
// SourceCharacter
210-
if (code < 0x0020 && code !== 0x0009 && code !== 0x000a && code !== 0x000d) {
211-
throw syntaxError(
212-
source,
213-
pos,
214-
`Cannot contain the invalid character ${printCharCode(code)}.`,
215-
);
216-
}
217-
218210
switch (code) {
219211
// !
220212
case 33:
@@ -353,6 +345,10 @@ function readToken(lexer: Lexer<*>, prev: Token): Token {
353345
* Report a message that an unexpected character was encountered.
354346
*/
355347
function unexpectedCharacterMessage(code) {
348+
if (code < 0x0020 && code !== 0x0009 && code !== 0x000a && code !== 0x000d) {
349+
return `Cannot contain the invalid character ${printCharCode(code)}.`;
350+
}
351+
356352
if (code === 39) {
357353
// '
358354
return (
@@ -361,7 +357,7 @@ function unexpectedCharacterMessage(code) {
361357
);
362358
}
363359
364-
return 'Cannot parse the unexpected character ' + printCharCode(code) + '.';
360+
return `Cannot parse the unexpected character ${printCharCode(code)}.`;
365361
}
366362
367363
/**

0 commit comments

Comments
 (0)