Skip to content

Commit 1a3a564

Browse files
JLHwungmarijnh
authored andcommitted
Do not reset shorthandAssign when parsing maybeAssign
1 parent 15a87cd commit 1a3a564

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

acorn/src/expression.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,11 @@ pp.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
113113
else this.exprAllowed = false
114114
}
115115

116-
let ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1, oldShorthandAssign = -1
116+
let ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1
117117
if (refDestructuringErrors) {
118118
oldParenAssign = refDestructuringErrors.parenthesizedAssign
119119
oldTrailingComma = refDestructuringErrors.trailingComma
120-
oldShorthandAssign = refDestructuringErrors.shorthandAssign
121-
refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = refDestructuringErrors.shorthandAssign = -1
120+
refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1
122121
} else {
123122
refDestructuringErrors = new DestructuringErrors
124123
ownDestructuringErrors = true
@@ -133,8 +132,11 @@ pp.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
133132
let node = this.startNodeAt(startPos, startLoc)
134133
node.operator = this.value
135134
node.left = this.type === tt.eq ? this.toAssignable(left, false, refDestructuringErrors) : left
136-
if (!ownDestructuringErrors) DestructuringErrors.call(refDestructuringErrors)
137-
refDestructuringErrors.shorthandAssign = -1 // reset because shorthand default was used correctly
135+
if (!ownDestructuringErrors) {
136+
refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = refDestructuringErrors.doubleProto = -1
137+
}
138+
if (refDestructuringErrors.shorthandAssign >= node.left.start)
139+
refDestructuringErrors.shorthandAssign = -1 // reset because shorthand default was used correctly
138140
this.checkLVal(left)
139141
this.next()
140142
node.right = this.parseMaybeAssign(noIn)
@@ -144,7 +146,6 @@ pp.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
144146
}
145147
if (oldParenAssign > -1) refDestructuringErrors.parenthesizedAssign = oldParenAssign
146148
if (oldTrailingComma > -1) refDestructuringErrors.trailingComma = oldTrailingComma
147-
if (oldShorthandAssign > -1) refDestructuringErrors.shorthandAssign = oldShorthandAssign
148149
return left
149150
}
150151

@@ -249,8 +250,8 @@ pp.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
249250
pp.parseExprSubscripts = function(refDestructuringErrors) {
250251
let startPos = this.start, startLoc = this.startLoc
251252
let expr = this.parseExprAtom(refDestructuringErrors)
252-
let skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")"
253-
if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) return expr
253+
if (expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")")
254+
return expr
254255
let result = this.parseSubscripts(expr, startPos, startLoc)
255256
if (refDestructuringErrors && result.type === "MemberExpression") {
256257
if (refDestructuringErrors.parenthesizedAssign >= result.start) refDestructuringErrors.parenthesizedAssign = -1

test/tests-harmony.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16513,4 +16513,6 @@ test("function *f2() { () => yield / 1 }", {}, {ecmaVersion: 6})
1651316513

1651416514
test("({ a = 42, b: c.d } = e)", {}, {ecmaVersion: 6})
1651516515

16516+
testFail("({ a = 42, b: c = d })", "Shorthand property assignments are valid only in destructuring patterns (1:5)", {ecmaVersion: 6})
16517+
1651616518
test("({ __proto__: x, __proto__: y, __proto__: z }) => {}", {}, {ecmaVersion: 6})

0 commit comments

Comments
 (0)