shapesecurity / shift-parser-js

ECMAScript parser that produces a Shift format AST
http://shift-ast.org/parser.html
Apache License 2.0
251 stars 28 forks source link

Destructuring rest not supported in object assignments #457

Closed ceres-c closed 2 years ago

ceres-c commented 2 years ago

Statements such as {a, b, ...rest} = {a: 1, b: 2 c: 30, d: 40} are not supported and shift-parser throws an Unexpected token "..." Error.

If I get this right, it should be considered part of the language now, but correct me if I'm wrong and this was left out as a deliberate choice

bakkot commented 2 years ago

{a, b, ...rest} = {a: 1, b: 2, c: 30, d: 40} is not legal JavaScript (even with the missing comma added). You need to wrap it in parentheses for it to be parsed as an assignment expression, as in ({a, b, ...rest} = {a: 1, b: 2, c: 30, d: 40}). And then it will indeed be parsed (at least with the latest version of shift-parser).

ceres-c commented 2 years ago

Now I feel terribly stupid, sorry. I was experimenting with assignments to both arrays and objects and I forgot the fundamental parentheses while quickly modifying my test code. :( Node console accepting the expression without the parentheses didn't help me either

Sorry again and thanks for the great libs you people built

bakkot commented 2 years ago

No worries. The repl thing does tend to trip people up.