babel / babylon

PSA: moved into babel/babel as @babel/parser -->

Home Page:https://github.com/babel/babel/tree/master/packages/babel-parser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Object rest spread doesn't work in non-declarations

tolmasky opened this issue · comments

As far as I know, "{ ...rest } = x" should work fine. It seems to work in node 8. However, Babylon only allows it in declarations (let/var, etc).

Input Code

https://runkit.com/tolmasky/spread-broken-babylon-current
https://runkit.com/tolmasky/spread-broken-babylon-beta

parse("{ ...rest } = x", { plugins: ["objectRestSpread"] })

Babylon/Babel Configuration

{ plugins: ["objectRestSpread"] }

Expected Behavior

Should parse.

Current Behavior

Throws.

Your Environment

software version
Babylon 6.18.0 and 7.0.0-beta.22

You need parentheses, same as you would for object destructuring without a rest, or for an object literal as a statement by itself.

Ah, indeed, I guess node REPL auto-wraps and that is why > { ...rest } = {} works.