From c209deff5df9a38e6a8646b38247eb958f3e2c63 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 13 Aug 2018 08:10:46 -0700 Subject: [PATCH] Ensure invalid escaped reserved word errors are thrown. [closes #561] --- src/acorn/parser/error-messages.js | 5 +++++ src/constant/parser-message.js | 1 + 2 files changed, 6 insertions(+) diff --git a/src/acorn/parser/error-messages.js b/src/acorn/parser/error-messages.js index 1886fbe9a..0ad6e043b 100644 --- a/src/acorn/parser/error-messages.js +++ b/src/acorn/parser/error-messages.js @@ -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, @@ -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, @@ -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, @@ -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 diff --git a/src/constant/parser-message.js b/src/constant/parser-message.js index e75162413..ecfc7371d 100644 --- a/src/constant/parser-message.js +++ b/src/constant/parser-message.js @@ -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",