Skip to content

Commit e2b8cc0

Browse files
LongTengDaomarijnh
authored andcommitted
Fix broken parsing of new expressions when allowReserved=="never"
1 parent 1555c52 commit e2b8cc0

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

acorn/src/expression.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ pp.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow)
272272
if (computed || this.eat(tt.dot)) {
273273
let node = this.startNodeAt(startPos, startLoc)
274274
node.object = base
275-
node.property = computed ? this.parseExpression() : this.parseIdent(true)
275+
node.property = computed ? this.parseExpression() : this.parseIdent(this.options.allowReserved !== "never")
276276
node.computed = !!computed
277277
if (computed) this.expect(tt.bracketR)
278278
base = this.finishNode(node, "MemberExpression")
@@ -734,7 +734,7 @@ pp.parsePropertyName = function(prop) {
734734
prop.computed = false
735735
}
736736
}
737-
return prop.key = this.type === tt.num || this.type === tt.string ? this.parseExprAtom() : this.parseIdent(true)
737+
return prop.key = this.type === tt.num || this.type === tt.string ? this.parseExprAtom() : this.parseIdent(this.options.allowReserved !== "never")
738738
}
739739

740740
// Initialize empty function node.
@@ -902,7 +902,6 @@ pp.checkUnreserved = function({start, end, name}) {
902902

903903
pp.parseIdent = function(liberal, isBinding) {
904904
let node = this.startNode()
905-
if (liberal && this.options.allowReserved === "never") liberal = false
906905
if (this.type === tt.name) {
907906
node.name = this.value
908907
} else if (this.type.keyword) {

test/tests.js

+27
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,33 @@ if (typeof exports != "undefined") {
77
var acorn = require("../acorn");
88
}
99

10+
test("new Object", {
11+
type: "Program",
12+
start: 0,
13+
end: 10,
14+
body: [
15+
{
16+
type: "ExpressionStatement",
17+
start: 0,
18+
end: 10,
19+
expression: {
20+
type: "NewExpression",
21+
start: 0,
22+
end: 10,
23+
callee: {
24+
type: "Identifier",
25+
start: 4,
26+
end: 10,
27+
name: "Object"
28+
},
29+
arguments: []
30+
}
31+
}
32+
]
33+
}, {
34+
allowReserved: "never"
35+
});
36+
1037
test("this\n", {
1138
type: "Program",
1239
body: [

0 commit comments

Comments
 (0)