Skip to content

Commit

Permalink
Fix broken parsing of new expressions when allowReserved=="never"
Browse files Browse the repository at this point in the history
  • Loading branch information
LongTengDao authored and marijnh committed Aug 7, 2019
1 parent 1555c52 commit e2b8cc0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
5 changes: 2 additions & 3 deletions acorn/src/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
27 changes: 27 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down

0 comments on commit e2b8cc0

Please sign in to comment.