Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Object spread is not working #1632

Closed
mohsen1 opened this issue Jun 27, 2018 · 10 comments
Closed

🐛 Object spread is not working #1632

mohsen1 opened this issue Jun 27, 2018 · 10 comments
Labels

Comments

@mohsen1
Copy link
Contributor

mohsen1 commented Jun 27, 2018

🐛 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
fkling/astexplorer#330

💻 Code Sample

Repo to reproduce

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

@mohsen1
Copy link
Contributor Author

mohsen1 commented Jun 27, 2018

Interesting:

Removing Google Analytics inline script will resolve the hanging issue

mohsen1/parcel-spread-bug#1

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

@mohsen1
Copy link
Contributor Author

mohsen1 commented Jun 28, 2018

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 |

@tripodsan
Copy link
Contributor

note, it works with --target node

@buronnie
Copy link

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.

@mohsen1
Copy link
Contributor Author

mohsen1 commented Jun 29, 2018

That seems to work:

mohsen1/parcel-spread-bug#2

I wonder why this works in node target though?

@DeMoorJasper
Copy link
Member

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

@danielo515
Copy link

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

@DeMoorJasper
Copy link
Member

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

@danielo515
Copy link

Awesome!
Thanks for making parcel even better

@taylorjdawson
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants