Fail to transform files when using spread / object destructing
Closed this issue ยท 5 comments
idanwe commented
๐ Configuration (.babelrc, package.json, cli command)
// .babelrc
{
"presets": ["env", "react"]
}
// package.json
{
"name": "parcel-spread",
"version": "1.0.0",
"main": "index.js",
"repository": {},
"license": "MIT",
"scripts": {
"start": "parcel index.html"
},
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0"
},
"devDependencies": {
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"parcel-bundler": "^1.2.0"
}
}
// index.js
import React from 'react';
import { render } from 'react-dom';
import App from './App';
render(<App name="World" date={new Date()} />, document.getElementById('app'));
// App.js
import React, { Component } from 'react';
export default ({ name, ...rest }) => {
return (
<div>
<h1>Hello {name} ๐ฆ ๐</h1>
<Child {...rest} />
</div>
);
};
๐ค Expected Behavior
I'm expecting that due to use of babel preset "env" it will transform files with spread and object destructuring.
๐ฏ Current Behavior
๐จ parcel-spread/App.js:5:24: Unexpected token (5:24)
3 | import Child from './Child';
4 |
> 5 | export default ({ name, ...rest }) => {
| ^
6 | return (
7 | <div>
8 |
๐ Your Environment
Software | Version(s) |
---|---|
Parcel | v1.2.0 |
Node | v8.5.0 |
Yarn | v0.19.1 |
Operating System | macOS 10.12.6 |
garrydzeng commented
try to use babel-plugin-transform-object-rest-spread ?
itsMapleLeaf commented
Object destructuring is currently a stage 3 feature, so you'll need what @garrydzeng mentioned, or the stage-3 babel preset.
DeMoorJasper commented
These babel suggestions should fix your issue, if it didn't feel free to reopen this issue
idanwe commented
thanks works
Nantris commented
I'm using stage-0
and importing redux-throttle
and getting an error that seems to be related to the spread operator.
C:\projects\myapp\node_modules\redux-throttle\src\index.js:52:17: Unexpected token (52:17)
[0] 50 | } else if (typeof shouldThrottle === 'object') {
[0] 51 | wait = shouldThrottle.wait || defaultWait
[0] > 52 | options = {...defaultThrottleOption, ...shouldThrottle}
[0] | ^
[0] 53 | }
[0] 54 |
[0] 55 | throttled[action.type] = throttle(next, wait, options)