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

Unexpected token ... - is the spread operator supported? #2899

Closed
bryanrideshark opened this issue Jun 21, 2017 · 1 comment
Closed

Unexpected token ... - is the spread operator supported? #2899

bryanrideshark opened this issue Jun 21, 2017 · 1 comment

Comments

@bryanrideshark
Copy link

I am running Node 8.1.0, developing in TypeScript and setting the output to "EsNext".

Now, I can downgrade my TypeScript output to Es2015, and this problem goes away - but I'd really like to use the spread operator.

This is the offending code:


const someObject = {
    ...someOtherObject
};

Mocha chokes on the spread operator.

Will this ever be a supported feature? What can I do to get mocha to run my program?

@ScottFreeCode
Copy link
Contributor

It's not really in Mocha's control one way or the other, as the only thing Mocha does about it is require the transpiler (and that only if you use --require <transpiler> or --compilers <extension>:<transpiler>); it's Node that chokes on next-gen features that the transpiler isn't configured to backport (or on anything buggy in the transpiler's implementation). Mocha isn't a JavaScript engine, platform or environment, it's just a library. You can always verify this by running the same transpiler and settings against your project's code and running some of it that uses the spread operator without Mocha.

Most likely you'd need to review the difference between ES2015 and ESNext TypeScript modes, and Node 8's support (if any) for this specific usage of the spread operator, to make sure this isn't just expected behavior -- and if it should work, check the output to see if it's transpiled correctly (to determine whether the issue is on the TypeScript side or the Node side) and open an issue with the respective project.

(Off the top of my head, my guess is that ES2015 vs. ESNext is the output version of JavaScript, meaning that ES2015 backports everything to work in environments that are only up to ES2015 features and ESNext assumes an up-to-date JS environment and does not backport anything; and based on Node 8 being able to use other versions of the spread operator but not object property assignment I suppose the latter may be defined in a newer version of the JS standard. But all that should be verified in documentation.)

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

2 participants