Skip to content

Lexer: unify unexpected character errors #1289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/language/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,6 @@ function readToken(lexer: Lexer<*>, prev: Token): Token {
const code = charCodeAt.call(body, pos);

// SourceCharacter
if (code < 0x0020 && code !== 0x0009 && code !== 0x000a && code !== 0x000d) {
throw syntaxError(
source,
pos,
`Cannot contain the invalid character ${printCharCode(code)}.`,
);
}

switch (code) {
// !
case 33:
Expand Down Expand Up @@ -353,6 +345,10 @@ function readToken(lexer: Lexer<*>, prev: Token): Token {
* Report a message that an unexpected character was encountered.
*/
function unexpectedCharacterMessage(code) {
if (code < 0x0020 && code !== 0x0009 && code !== 0x000a && code !== 0x000d) {
return `Cannot contain the invalid character ${printCharCode(code)}.`;
}

if (code === 39) {
// '
return (
Expand All @@ -361,7 +357,7 @@ function unexpectedCharacterMessage(code) {
);
}

return 'Cannot parse the unexpected character ' + printCharCode(code) + '.';
return `Cannot parse the unexpected character ${printCharCode(code)}.`;
}

/**
Expand Down