parcel-bundler/parcel

Fail to transform files when using spread / object destructing

Closed this issue ยท 5 comments

๐ŸŽ› 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

Object destructuring is currently a stage 3 feature, so you'll need what @garrydzeng mentioned, or the stage-3 babel preset.

These babel suggestions should fix your issue, if it didn't feel free to reopen this issue

thanks works

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)