From e2b8cc087386eccc2ad6fd4a02b4257833557cb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E8=85=BE=E9=81=93?= Date: Thu, 8 Aug 2019 01:11:42 +0800 Subject: [PATCH] Fix broken parsing of new expressions when allowReserved=="never" --- acorn/src/expression.js | 5 ++--- test/tests.js | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/acorn/src/expression.js b/acorn/src/expression.js index 7a4aed93b..b338141e8 100644 --- a/acorn/src/expression.js +++ b/acorn/src/expression.js @@ -272,7 +272,7 @@ pp.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow) if (computed || this.eat(tt.dot)) { let node = this.startNodeAt(startPos, startLoc) node.object = base - node.property = computed ? this.parseExpression() : this.parseIdent(true) + node.property = computed ? this.parseExpression() : this.parseIdent(this.options.allowReserved !== "never") node.computed = !!computed if (computed) this.expect(tt.bracketR) base = this.finishNode(node, "MemberExpression") @@ -734,7 +734,7 @@ pp.parsePropertyName = function(prop) { prop.computed = false } } - return prop.key = this.type === tt.num || this.type === tt.string ? this.parseExprAtom() : this.parseIdent(true) + return prop.key = this.type === tt.num || this.type === tt.string ? this.parseExprAtom() : this.parseIdent(this.options.allowReserved !== "never") } // Initialize empty function node. @@ -902,7 +902,6 @@ pp.checkUnreserved = function({start, end, name}) { pp.parseIdent = function(liberal, isBinding) { let node = this.startNode() - if (liberal && this.options.allowReserved === "never") liberal = false if (this.type === tt.name) { node.name = this.value } else if (this.type.keyword) { diff --git a/test/tests.js b/test/tests.js index ca07b3a71..eeaaf0d7f 100644 --- a/test/tests.js +++ b/test/tests.js @@ -7,6 +7,33 @@ if (typeof exports != "undefined") { var acorn = require("../acorn"); } +test("new Object", { + type: "Program", + start: 0, + end: 10, + body: [ + { + type: "ExpressionStatement", + start: 0, + end: 10, + expression: { + type: "NewExpression", + start: 0, + end: 10, + callee: { + type: "Identifier", + start: 4, + end: 10, + name: "Object" + }, + arguments: [] + } + } + ] +}, { + allowReserved: "never" +}); + test("this\n", { type: "Program", body: [