From ccfd59d044fa004f852cc4105d09782e0192e078 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Sat, 16 Sep 2017 20:13:10 +0900 Subject: [PATCH] fix parsing errors about template literals (fixes #575) --- src/expression.js | 7 +++++++ test/tests-template-literal-revision.js | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/src/expression.js b/src/expression.js index 635642c86..9a7d01a21 100644 --- a/src/expression.js +++ b/src/expression.js @@ -814,6 +814,13 @@ pp.parseIdent = function(liberal, isBinding) { node.name = this.value } else if (this.type.keyword) { node.name = this.type.keyword + + // To fix https://github.com/ternjs/acorn/issues/575 + // `class` and `function` keywords push new context into this.context. + // But there is no chance to pop the context if the keyword is consumed as an identifier such as a property name. + if (node.name === "class" || node.name === "function") { + this.context.pop() + } } else { this.unexpected() } diff --git a/test/tests-template-literal-revision.js b/test/tests-template-literal-revision.js index 3b4de1c2b..ce275c294 100644 --- a/test/tests-template-literal-revision.js +++ b/test/tests-template-literal-revision.js @@ -549,3 +549,8 @@ test("foo`\\unicode\\\\`", { ], sourceType: "script" }, {ecmaVersion: 9}) + +test("`${ {class: 1} }`", {}, { ecmaVersion: 9 }) +test("`${ {delete: 1} }`", {}, { ecmaVersion: 9 }) +test("`${ {enum: 1} }`", {}, { ecmaVersion: 9 }) +test("`${ {function: 1} }`", {}, { ecmaVersion: 9 })