Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Ensure invalid escaped reserved word errors are thrown. [closes #561]
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Aug 13, 2018
1 parent 399e503 commit c209def
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/acorn/parser/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function init() {

const PARSER_IMPORT_EXPORT_INVALID_LEVEL = "'import' and 'export' may only appear at the top level"
const PARSER_IMPORT_EXPORT_OUTSIDE_MODULE = "'import' and 'export' may appear only with 'sourceType: module'"
const PARSER_INVALID_ESCAPED_RESERVED_WORD = "Escape sequence in keyword "

const {
ILLEGAL_AWAIT_IN_NON_ASYNC_FUNCTION,
Expand All @@ -18,6 +19,7 @@ function init() {
ILLEGAL_NEW_TARGET,
ILLEGAL_RETURN_STATEMENT,
INVALID_OR_UNEXPECTED_TOKEN,
INVALID_ESCAPED_RESERVED_WORD,
UNEXPECTED_EOS,
UNEXPECTED_EVAL_OR_ARGUMENTS,
UNEXPECTED_IDENTIFIER,
Expand All @@ -37,6 +39,7 @@ function init() {
[ILLEGAL_NEW_TARGET]: true,
[ILLEGAL_RETURN_STATEMENT]: true,
[INVALID_OR_UNEXPECTED_TOKEN]: true,
[INVALID_ESCAPED_RESERVED_WORD]: true,
[UNEXPECTED_EOS]: true,
[UNEXPECTED_EVAL_OR_ARGUMENTS]: true,
[UNEXPECTED_IDENTIFIER]: true,
Expand Down Expand Up @@ -127,6 +130,8 @@ function init() {
message = UNEXPECTED_TOKEN + " " + this.type.label
} else if (message.startsWith(PARSER_DUPLICATE_EXPORT)) {
message = message.replace(PARSER_DUPLICATE_EXPORT, ENGINE_DUPLICATE_EXPORT)
} else if (message.startsWith(PARSER_INVALID_ESCAPED_RESERVED_WORD)) {
message = INVALID_ESCAPED_RESERVED_WORD
} else if (! Reflect.has(messages, message) &&
! message.startsWith(UNEXPECTED_TOKEN)) {
return
Expand Down
1 change: 1 addition & 0 deletions src/constant/parser-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const PARSER_MESSAGE = {
ILLEGAL_IMPORT_META_OUTSIDE_MODULE: "Cannot use 'import.meta' outside a module",
ILLEGAL_NEW_TARGET: "new.target expression is not allowed here",
ILLEGAL_RETURN_STATEMENT: "Illegal return statement",
INVALID_ESCAPED_RESERVED_WORD: "Keyword must not contain escaped characters",
INVALID_OR_UNEXPECTED_TOKEN: "Invalid or unexpected token",
UNEXPECTED_EOS: "Unexpected end of input",
UNEXPECTED_EVAL_OR_ARGUMENTS: "Unexpected eval or arguments in strict mode",
Expand Down

0 comments on commit c209def

Please sign in to comment.