question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected token for spread operator.

See original GitHub issue
// app/assets/javascripts/currentUser.js
variable = {
  a: 'a',
  b: 'b'
}

export default {
  toJSON: function() {
    return {...variable};
  }
};

Currently throws an unexpected token while this is a valid syntax.

$ eslint app/assets/javascripts/currentUser.js

app/assets/javascripts/webpack/currentUser.js
  8:13  error  Unexpected token ..

✖ 1 problem (1 error, 0 warnings)

I did this on a fresh npm install eslint.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:4
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

151reactions
Salakarcommented, Dec 1, 2016

For eslint to support rest spread usage you need to enable the experimentalObjectRestSpread option under parserOptions 👍

Example:

{
  "extends": "airbnb",
  "parserOptions":{
    "ecmaFeatures": {
      "experimentalObjectRestSpread": true
    }
  }
}
26reactions
ilyavolodincommented, May 14, 2015

@hzoo is correct. We do not support object spread.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected token on spread operator in Chrome?
You are attempting Object rest/spread, which has not quite made it into the ES6 specification. So, spreading into an object isn't supported ......
Read more >
Unexpected token ... ( spread operator ) · Issue #9675 · babel ...
Bug Report Babel can't recognize spread operator (..) return resolve(user && { ...user, domain }); i tried many solutions but without result ...
Read more >
[Solved] The spread operator(...state) in react throwing error of ...
In React programming when we are using the spread operator (…state), we may encounter the error saying Unexpected token.
Read more >
Error Following React Tutorial spread operator is unexpected ...
I am following this freeCodeCamp tutorial: https://youtu.be/4UZrsTqkcW4?t=10660 and am stuck at where the link takes you.
Read more >
A few neat things you can do with the vanilla JS spread syntax ...
Uncaught SyntaxError: Unexpected token '. ... The spread operator can only be used inside of functions, arrays and objects.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found