Skip to content

Commit

Permalink
fix parsing errors about template literals (fixes #575)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Sep 16, 2017
1 parent 9ae70b7 commit ccfd59d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/expression.js
Expand Up @@ -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()
}
Expand Down
5 changes: 5 additions & 0 deletions test/tests-template-literal-revision.js
Expand Up @@ -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 })

0 comments on commit ccfd59d

Please sign in to comment.