Parcel: 馃悰 Object spread is not working

Created on 28 Jun 2018  路  10Comments  路  Source: parcel-bundler/parcel

馃悰 Object spread (...obj) is failing to work with basic setup

馃 Expected Behavior

No error

馃槸 Current Behavior

Parcel build hangs with this syntax error

```
yarn run v1.7.0
$ parcel build index.html
馃毃 Desktop/parcel-spread-bug/src/components/SplitPane.js:74:8: Unexpected token (74:8)
72 | // top
73 | styleA = {

74 | ...baseStyleVertical,
| ^
75 | top: 0,
76 | height: dividerPos + '%',
77 | paddingBottom: 3,
````

馃敠 Context

Faced this bug here
https://github.com/fkling/astexplorer/pull/330

馃捇 Code Sample

Repo to reproduce

https://github.com/mohsen1/parcel-spread-bug

Bug

Most helpful comment

Parcel out of box includes babel-preset-env and babel-preset-react. The object rest spread transform is not part of either. So you need to install babel-plugin-transform-object-rest-spread and define it in your .babelrc file.

All 10 comments

Interesting:

Removing Google Analytics inline script will resolve the hanging issue

https://github.com/mohsen1/parcel-spread-bug/pull/1

edit
this was a red herring. I'm still not sure why it does not hang

I reduced this bug to simply:

index.html

<!DOCTYPE html>
<html lang="en">

<head>
</head>

<body>
    <script src="./index.js"></script>
</body>

</html>

index.js

var a = {
  foo: 1
};

var b = {
  ...a,
  bar: 2
};

parcel build index.html prints:

$ parcel build index.html
馃毃  /parcel-spread-bug/index.js:6:2: Unexpected token (6:2)
  4 |
  5 | var b = {
> 6 |   ...a,
    |   ^
  7 |   bar: 2
  8 | };
  9 |

note, it works with --target node

Parcel out of box includes babel-preset-env and babel-preset-react. The object rest spread transform is not part of either. So you need to install babel-plugin-transform-object-rest-spread and define it in your .babelrc file.

That seems to work:

https://github.com/mohsen1/parcel-spread-bug/pull/2

I wonder why this works in node target though?

Owkeey, so this is not a bug, closing this.

This may not be a bug, but it is so usual that I expected it to be included by default.

@danielo515 It will be in the next release see #1835

Awesome!
Thanks for making parcel even better

So this doesn't work with external dependencies.

This even works in third-party node_modules: if a configuration file is published as part of the package, the transform is automatically turned on for that module only.
Parcel Docs

Is there a way to transpile third-party node_modules that don't have the configuration file?

Was this page helpful?
0 / 5 - 0 ratings