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 9040ca1
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,13 +10,15 @@ 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,
ILLEGAL_HTML_COMMENT,
ILLEGAL_IMPORT_META_OUTSIDE_MODULE,
ILLEGAL_NEW_TARGET,
ILLEGAL_RETURN_STATEMENT,
INVALID_ESCAPED_RESERVED_WORD,
INVALID_OR_UNEXPECTED_TOKEN,
UNEXPECTED_EOS,
UNEXPECTED_EVAL_OR_ARGUMENTS,
Expand All @@ -36,6 +38,7 @@ function init() {
[ILLEGAL_IMPORT_META_OUTSIDE_MODULE]: true,
[ILLEGAL_NEW_TARGET]: true,
[ILLEGAL_RETURN_STATEMENT]: true,
[INVALID_ESCAPED_RESERVED_WORD]: true,
[INVALID_OR_UNEXPECTED_TOKEN]: true,
[UNEXPECTED_EOS]: true,
[UNEXPECTED_EVAL_OR_ARGUMENTS]: 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 9040ca1

Please sign in to comment.