Skip to content

Commit 74b5938

Browse files
committed
Work around corner case with nested destructuring arrays
Issue #1015
1 parent 2808256 commit 74b5938

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

acorn/src/expression.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ pp.parseExprSubscripts = function(refDestructuringErrors) {
270270
if (refDestructuringErrors && result.type === "MemberExpression") {
271271
if (refDestructuringErrors.parenthesizedAssign >= result.start) refDestructuringErrors.parenthesizedAssign = -1
272272
if (refDestructuringErrors.parenthesizedBind >= result.start) refDestructuringErrors.parenthesizedBind = -1
273+
if (refDestructuringErrors.trailingComma >= result.start) refDestructuringErrors.trailingComma = -1
273274
}
274275
return result
275276
}

test/tests-harmony.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16572,3 +16572,52 @@ test("const myFn = ({ set = '' }) => {};", {
1657216572
}
1657316573
]
1657416574
}, {ecmaVersion: 6})
16575+
16576+
16577+
test("[[...[], 0].x] = []", {
16578+
type: "Program",
16579+
body: [
16580+
{
16581+
type: "ExpressionStatement",
16582+
expression: {
16583+
type: "AssignmentExpression",
16584+
operator: "=",
16585+
left: {
16586+
type: "ArrayPattern",
16587+
elements: [
16588+
{
16589+
type: "MemberExpression",
16590+
object: {
16591+
type: "ArrayExpression",
16592+
elements: [
16593+
{
16594+
type: "SpreadElement",
16595+
argument: {
16596+
type: "ArrayExpression",
16597+
elements: []
16598+
}
16599+
},
16600+
{
16601+
type: "Literal",
16602+
value: 0,
16603+
raw: "0"
16604+
}
16605+
]
16606+
},
16607+
property: {
16608+
type: "Identifier",
16609+
name: "x"
16610+
},
16611+
computed: false
16612+
}
16613+
]
16614+
},
16615+
right: {
16616+
type: "ArrayExpression",
16617+
elements: []
16618+
}
16619+
}
16620+
}
16621+
],
16622+
sourceType: "script"
16623+
}, {ecmaVersion: 6})

0 commit comments

Comments
 (0)