Microbundle: Object spread seems to be failing

Created on 13 Feb 2018  路  10Comments  路  Source: developit/microbundle

Looks like buble supports it, as long as you pass an option for objectAssign: 'Object.assign' but in practice it doesn't seem to be working.

My code:

import { h } from 'preact'

export default ({ title, ...rest }) => (
  <div {...rest} className={`${rest.className}`} />
)

Output:

SyntaxError: Unexpected token (3:25) /some/path/page.js (nodent)
export default ({ title, ...rest }) => (
-------------------------^
bug upstream

Most helpful comment

The medium-term fix would be to allow using Babel with Microbundle, triggered by the existence of a .babelrc.

All 10 comments

The problem is in Rollup as i remember.

Try out

const opts = { input: 1, a: 2, bbbb: 3 };

const { input, ...rest } = opts;

console.log(rest);

and

rollup -i foo.js -o bar.js -f es

It still fails.

Rollup idealogy is to "add acorn plugin" for such things.

I just ran into this. One quick workaround is to transpile with babel's transform-object-rest-spread first, then run microbundle on the intermediary output, e.g. in crosslink.

Update Rollup to 0.56, it now support ecmaVersion: 9. But yea, there still need to have sup prebundling compilation for most recent javascript. _Or_ to add acorn-stage3 to rollup here.

is there a workarround in the mean time, or can we simply not use object spread with microbundle until it gets fixed upstream?

@MobiusHorizons you can pre-transform it through babel for now, e.g. https://github.com/tlvince/react-router-crosslink/blob/1ce2b6aad7f001e1dbea36ba76877ec8bbcda94e/package.json#L10-L11

And if someone want to contribute, there are few things that may be done to help.

  1. Implement ESPree (not the ESTree one) plugin into babylon - https://github.com/babel/babel/issues/7369
  2. PR needed small changes to Rollup to use babylon with the ESPree plugin by default, because it needs the ESPree AST - https://github.com/rollup/rollup/issues/1690

The medium-term fix would be to allow using Babel with Microbundle, triggered by the existence of a .babelrc.

@developit I've had a WIP here. Should we revive this PR until we switch to babel entirely?

Just tried it out with 0.9.0 and I can't reproduce this issue anymore with the code from the first post 馃帀

Was this page helpful?
0 / 5 - 0 ratings

Related issues

skipjack picture skipjack  路  11Comments

developit picture developit  路  14Comments

JoviDeCroock picture JoviDeCroock  路  17Comments

artemtam picture artemtam  路  19Comments

Conaclos picture Conaclos  路  11Comments