Skip to content

Commit

Permalink
Fix bug in entering subscript expressions from an ambiguous obj pattern
Browse files Browse the repository at this point in the history
When the object had a shorthand defaulted property in it,
that prevented the subscript in the nested expression from
being parsed.

Closes #735
  • Loading branch information
marijnh committed Sep 26, 2018
1 parent 2b41039 commit 270dee1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 1 addition & 3 deletions acorn/dist/acorn.d.ts
Expand Up @@ -42,11 +42,9 @@ declare namespace acorn {
getToken(): Token
[Symbol.iterator](): Iterator<Token>
}
static extend(...plugins: Constructor<Parser>[]): Constructor<Parser>
static extend(...plugins: (typeof Parser)[]): typeof Parser
}

type Constructor<T> = new (...args: any[]) => T

interface Position { line: number; column: number; offset: number }

const defaultOptions: Options
Expand Down
6 changes: 4 additions & 2 deletions acorn/src/expression.js
Expand Up @@ -111,11 +111,12 @@ pp.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
else this.exprAllowed = false
}

let ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1
let ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1, oldShorthandAssign = -1
if (refDestructuringErrors) {
oldParenAssign = refDestructuringErrors.parenthesizedAssign
oldTrailingComma = refDestructuringErrors.trailingComma
refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1
oldShorthandAssign = refDestructuringErrors.shorthandAssign;
refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = refDestructuringErrors.shorthandAssign = -1
} else {
refDestructuringErrors = new DestructuringErrors
ownDestructuringErrors = true
Expand All @@ -141,6 +142,7 @@ pp.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
}
if (oldParenAssign > -1) refDestructuringErrors.parenthesizedAssign = oldParenAssign
if (oldTrailingComma > -1) refDestructuringErrors.trailingComma = oldTrailingComma
if (oldShorthandAssign > -1) refDestructuringErrors.shorthandAssign = oldShorthandAssign
return left
}

Expand Down
2 changes: 2 additions & 0 deletions test/tests-harmony.js
Expand Up @@ -16249,3 +16249,5 @@ test("a.of / 2", {}, {ecmaVersion: 6})
test("let x = 1; x = 2", {}, {ecmaVersion: 6})

test("function *f2() { () => yield / 1 }", {}, {ecmaVersion: 6})

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

0 comments on commit 270dee1

Please sign in to comment.