Closed Bug 1111386 Opened 11 years ago Closed 10 years ago

Support nested rest in destructuring assignment

Categories

(Core :: JavaScript Engine, defect)

x86_64
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla47
Tracking Status
firefox47 --- fixed

People

(Reporter: Swatinem, Assigned: Swatinem)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

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: 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+
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla47
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: