Support nested rest in destructuring assignment

RESOLVED FIXED in Firefox 47

Status

()

defect
RESOLVED FIXED
5 years ago
4 years ago

People

(Reporter: Swatinem, Assigned: Swatinem)

Tracking

(Blocks 1 bug)

unspecified
mozilla47
x86_64
Windows 7
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(firefox47 fixed)

Details

Attachments

(1 attachment)

Assignee

Description

5 years ago
While it was not supported so far, with the latest draft 29, nested rest in destructuring assignment, such as `[first, ...[a[2], last]] = a;` is now possible. Lets implement it…
I almost filed a duplicate for this. Here's some more information, in case it helps

Input:

    $ js -e "[...[x, y, z]] = [1, 2, 3]; print(z);"

Expected: "3"
Actual:

    -e:1:4 SyntaxError: invalid destructuring target:
    -e:1:4 [...[x, y, z]] = [1, 2, 3]; print(z);
    -e:1:4 ....^

From ES6 12.14.5.3:

> Runtime Semantics: IteratorDestructuringAssignmentEvaluation
> 
> AssignmentRestElement[Yield] : ... DestructuringAssignmentTarget
> 
> 5. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an
>    ArrayLiteral, then
>   a. Return PutValue(lref, A).
> 6. Let nestedAssignmentPattern be the parse of the source text corresponding
>    to DestructuringAssignmentTarget using either AssignmentPattern or
>    AssignmentPattern[Yield] as the goal symbol depending upon whether this
>    AssignmentElement has the Yield parameter.
>   a. Return the result of performing DestructuringAssignmentEvaluation of nestedAssignmentPattern with A as the argument.

Source: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-runtime-semantics-iteratordestructuringassignmentevaluation

Build details:

commit 07bb578e6a93d11a3e1365e2b0d9296a755543ee
Date:   Fri Apr 17 13:52:50 2015 -0700
Assignee

Updated

4 years ago
Assignee: nobody → arpad.borsos
Status: NEW → ASSIGNED
Comment on attachment 8702007 [details]
MozReview Request: Bug 1111386 - Support nested rest in destructuring assignment; r?jorendorff

https://reviewboard.mozilla.org/r/29065/#review29033

Sorry for the belated review here. Looks good.

I'd like just a few more tests here.

- `"use strict"; [...{0: "".x}] = gen();` should exhaust the whole generator before throwing a TypeError.

- If an error is thrown on the right-hand side of a `let [...[...x]] = rhs();` in the global scope, the binding `x` is left uninitialized, and trying to read it after that is a TDZ ReferenceError. (I think this can be observed using evaluate() in a try/catch block. If not, never mind.)

::: js/src/jit-test/tests/basic/destructuring-iterator.js:63
(Diff revision 1)
> +// second rest pattern.

Great test.
Attachment #8702007 - Flags: review?(jorendorff) → review+

Comment 5

4 years ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/664f46e3d884
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla47
You need to log in before you can comment on or make changes to this bug.