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 `..` when using spread operator in function arguments

See original GitHub issue

The following code:

function mergeAndConcat(...objects) {
   // stuff
}

Is throwing error Unexpected token .. on line 3, which is the function definition. I’ve got the spread option set to true in the ecmaFeatures section of my config, so I wouldn’t expect the above to cause an error.

Thanks in advance 😃

Jack

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
lo1tumacommented, Apr 20, 2015

That’s not a spread operator, it’s a rest parameter. You need to enable the restParams flag.

Somehow restParams is missing in the documentation, but it is mentioned in the documentation of espree.

0reactions
nzakascommented, Aug 6, 2015

I believe all concerns have been addressed here, so closing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is this spread operator causing a SyntaxError
Whenever I run a file containing this in Node.js or PHP I get a SyntaxError: Unexpected token, citing the spread operator [ ......
Read more >
A few neat things you can do with the vanilla JS spread syntax ...
The spread operator can be really useful for some specific situations. Passing an array of arguments into a function as individual arguments #....
Read more >
Spread arrow function spread argument Unexpected token ...
I have a problem, I've imported a new package in my project and it seems to be the first (for me) that uses...
Read more >
Spread syntax (...) - JavaScript - MDN Web Docs - Mozilla
The spread (...) syntax allows an iterable, such as an array or string, to be expanded in places where zero or more arguments...
Read more >
SyntaxError: Unexpected token - JavaScript
The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided.
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