Description
- Version: 10.9.0
- Platform 1: Fedora 28 (Cloud Edition) x86_64
- Platform 2: Windows 10 x86_64
- Subsystem: n/a
Summary
Passing an arrow function and a destructuring assignment as two consecutive parameters of a function causes a syntax error.
Description
The following piece of code does not make much sense (and putting the initialization of [x, y]
in the 2nd parameter of map()
is definitely not a good idea), but I'd expect it to work anyway:
[[3, 4]].map(([X, Y]) => [X + x, Y + y], [x, y] = [2, 1])
In fact, this does work on both SpiderMonkey and Chakra which are returning [[5, 5]]
.
In Node (and Chrome), however, we get the following error:
SyntaxError: Invalid destructuring assignment target
Worst yet, with the following code:
[].map(_ => _, [x, y] = [2, 1])
We now get the following error:
SyntaxError: Unexpected token =>
This message is inconsistent, and that's why I suspect some kind of parsing error here.
Some more examples
This works:
foo = a => a;
foo(0, [x, y] = [2, 1]);
This also works:
foo = a => a;
foo(a => a, x = [2, 1]);
But this fails with "SyntaxError: Unexpected token =>":
foo = a => a;
foo(a => a, [x, y] = [2, 1]);