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

Spread operator not recognized in object declaration #142

Closed
wscourge opened this issue Jan 24, 2018 · 3 comments
Closed

Spread operator not recognized in object declaration #142

wscourge opened this issue Jan 24, 2018 · 3 comments

Comments

@wscourge
Copy link

Minimal example:

gulpfile.js

const gulp = require('gulp');
const concat = require('gulp-concat');
const babel = require('gulp-babel');

gulp.task('nope', () => {

  return gulp
    .src('./nope.js')
    .pipe(babel({ presets: ['env'] })
    .pipe(gulp.dest('transpiled');

});

nope.js

const y = Math.random() > 0.5;
let x = {
  q: 1,
  ... y && { a: 2 }
}

Running gulp nope produces following error:

throw er; // Unhandled 'error' event
^
SyntaxError: /directory/nope.js: Unexpected token (7:4)
    5 | let x = {
    6 |  q: 1,
 > 7 |  ... y && { a: 2 }
       |   ^
    8 | }
    9 |
    at Parser.pp$5.raise (/directory/node_modules/babylon/lib/index.js:4454:13)
    at Parser.pp.unexpected (/directory/node_modules/babylon/lib/index.js:1761:8)
    at Parser.pp$3.parseIdentifier (/directory/node_modules/babylon/lib/index.js:4332:10)
    at Parser.pp$3.parsePropertyName (/directory/node_modules/babylon/lib/index.js:4156:96)
    at Parser.pp$3.parseObj (/directory/node_modules/babylon/lib/index.js:4045:12)
    at Parser.pp$3.parseExprAtom (/directory/node_modules/babylon/lib/index.js:3719:19)
    at Parser.pp$3.parseExprSubscripts (/directory/node_modules/babylon/lib/index.js:3494:19)
    at Parser.pp$3.parseMaybeUnary (/directory/node_modules/babylon/lib/index.js:3474:19)
    at Parser.pp$3.parseExprOps (/directory/node_modules/babylon/lib/index.js:3404:19)
    at Parser.pp$3.parseMaybeConditional (/directory/node_modules/babylon/lib/index.js:3381:19)

My environment:

node -v v8.5.0
npm -v 5.5.1

package.json.dependencies

"dependencies": {
  "babel-core": "^6.26.0",
  "babel-preset-env": "^1.6.1",
  "gulp": "^3.9.1",
  "gulp-babel": "^7.0.0"
}

I created example on https://babeljs.io/repl.

@loganfsmyth
Copy link
Member

You are missing https://babeljs.io/docs/plugins/transform-object-rest-spread/. Spread in objects is not a standard feature yet.

@sasilver75
Copy link

You are missing https://babeljs.io/docs/plugins/transform-object-rest-spread/. Spread in objects is not a standard feature yet.

This makes me very sad

can you

implement it

@ilikebuttons
Copy link

This is what did it for me:

npm install --save-dev babel-plugin-transform-object-rest-spread

Then, in package.json, I added the following babel configuration:

"babel": {
    "plugins": [
      "transform-object-rest-spread"
    ]
  }

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

No branches or pull requests

4 participants