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

Can't parse spread operator #388

Closed
dmatteo opened this issue Feb 28, 2016 · 29 comments
Closed

Can't parse spread operator #388

dmatteo opened this issue Feb 28, 2016 · 29 comments

Comments

@dmatteo
Copy link
Contributor

dmatteo commented Feb 28, 2016

Hi Marijn,

I'm using acorn 3.0.2 with the plugin acorn-jsx 2.0.1, but acorn is throwing on the spread operator when used inside an object:

        var cleanField = {
          ...field, // this line throws
          config: {...field.config}
        };

Weirdly enough, this is totally fine

        var stuff = [...field];

Being part of ES6, the spread operator should be completely supported, right?
Can you spot something I'm doing wrong?

p.s. I'm not overriding options.ecmaScript, defaulting to 6

@marijnh
Copy link
Member

marijnh commented Feb 28, 2016

Spread in object literals is not part of any ECMA standard that Acorn can parse. Hence the error.

@marijnh marijnh closed this as completed Feb 28, 2016
@dmatteo
Copy link
Contributor Author

dmatteo commented Feb 28, 2016

Holy cow, I thought it was in the standard, but you're totally right.
I suppose you have no interest in supporting that in acorn then.

Would you suggest using babylon instead to get the extra ES6 features?

@dmatteo
Copy link
Contributor Author

dmatteo commented Feb 28, 2016

Yep, works great once I enable the objectRestSpread plugin.
Thanks!

@TimothyGu
Copy link
Contributor

Would you suggest using babylon instead to get the extra ES6 features?

Not sure what you are asking. Acorn supports all ES2015/ES6 features. Babylon is integrated in Babel and therefore Babel's plugins (which support nonstandard, non-ES6 plugins like babel-plugin-transform-object-rest-spread). Acorn has its own plugin system.

@dmatteo
Copy link
Contributor Author

dmatteo commented Feb 29, 2016

Poor choice of words.
By "extra ES6 features" I meant those features that are not in the ES6 standard, but are still used in the wild, like the objectRestSpread which has been made very popular by React, but it's not standardised (yet)

@RReverser
Copy link
Member

@dmatteo As an option, you can write plugin for Acorn to support that.

@dariocravero
Copy link

@RReverser @dmatteo @TimothyGu here it is https://github.com/UXtemple/acorn-object-spread :). I basically brought it in from babylon. I also pushed a PR to buble https://gitlab.com/Rich-Harris/buble/merge_requests/44 to support it, hopefully it makes it in :).

@RReverser
Copy link
Member

@dariocravero Awesome, great work!

@jdalton
Copy link
Contributor

jdalton commented Aug 11, 2017

Just a heads up, the object-rest-spread is now supported natively in Chrome 60 and Node 8.3.0 out of the box. It may be worth adding since v8 has it implemented unflagged already.

Related to standard-things/esm#14

@RReverser
Copy link
Member

RReverser commented Aug 11, 2017

@jdalton It is still stage 3 though, and Acorn accepts only stage 4 features for easier maintainance. Moreover, the latest parsing-related change in the proposal has been committed only 3 days ago: tc39/proposal-object-rest-spread@72deb7d

@jdalton
Copy link
Contributor

jdalton commented Aug 11, 2017

It is still stage 3 though, and Acorn accepts only stage 4 features

Maybe an exception to the rule is called for since implementations are shipping this unflagged.

@RReverser
Copy link
Member

Maybe an exception to the rule is called for since implementations are shipping this unflagged.

Aren't they always doing this in stage 3? (as far as I remember, it's exactly for implementation feedback)

@jdalton
Copy link
Contributor

jdalton commented Aug 11, 2017

It's my understanding that implementations for feedback are usually flagged.
Since this is unflagged though, and on by default now, it's a bit more pressing.

@boneskull
Copy link

Would love to see this fix land.

@marijnh
Copy link
Member

marijnh commented Aug 15, 2017

Again, I don't want to do extra work and complicate our backwards-compatibility story by tracking unstable proposals, and it would be great if you all could just get used to the 'use a plugin until it reaches stage 4' reality.

Drive-by comments like "Would love to see this fix land" we can also really do without.

@jdalton
Copy link
Contributor

jdalton commented Aug 15, 2017

@marijnh The reality is that support for object rest-spread is in stable versions of Chrome and Node and that the existing plugin isn't to the bar it really should be (i.e. it has 1 commit).

I understand not wanting to take on the compatibility burden, but seeing as the work put in will not likely be wasted (as it's not a question of if the feature is landing wider, but when) it would be rad if there could be an official plugin (made by Acorn core). That way folks could leverage a quality plugin and you all could get the jump on implementing the syntax while not taking on the compat burden for the primary project.

If Acorn is up for going the official plugin route, I can help.
(I have the beginnings of one kicking around somewhere)

@boneskull
Copy link

@marijnh As a maintainer it's cool to know when users really want a feature or a fix (also, there are no reactions on the mobile version of GH, so I would have used that otherwise)

@hzoo
Copy link

hzoo commented Aug 15, 2017

You can just use babylon until it's supported in acorn at Stage 4, the tools have difference use cases/times to implement.

@marijnh
Copy link
Member

marijnh commented Aug 16, 2017

@jdalton

the existing plugin isn't to the bar it really should be (i.e. it has 1 commit)

So improve it or write a better one.

@jdalton
Copy link
Contributor

jdalton commented Aug 16, 2017

So improve it or write a better one.

Seeing if Chrome team would be up for creating or updating a plugin
since they now also use Acorn in their dev tools.

@RReverser
Copy link
Member

@jdalton Small nit: looks like they used Acorn for ~2 years now https://github.com/auchenberg/chrome-devtools-app/tree/master/app/devtools/front_end/acorn, and now just widened its usage.

@jdalton
Copy link
Contributor

jdalton commented Nov 17, 2017

Updates:

Node is now using Acorn to parse top-level await in the REPL:
nodejs/node#15566

Chromium wants to pull its Acorn use in DevTools:
https://bugs.chromium.org/p/chromium/issues/detail?id=756006#c7

@askoretskiy
Copy link

Could one re-consider that? It is widely-adopted as of November 2017. Many environments support it -- Firefox, Chrome, NodeJS. Other tools as well -- babel, uglifyjs, etc.

Also, support in acorn blocks introducing this support in webpack that is somehow a show stopper. Without it you cannot pack JS code and deliver to the client.

@marijnh
Copy link
Member

marijnh commented Nov 24, 2017

a show stopper

Don't stop the show. Use https://github.com/victor-homyakov/acorn-object-rest-spread

@askoretskiy
Copy link

By the way, it is Stage 3 proposal now https://github.com/tc39/proposals/blob/master/README.md

Stage 3 means "Candidate", i.e. close to be accepted.

@adrianheine
Copy link
Member

Stage 3 is a pretty common place to be in and they are planning to get accepted in the next months. No need to rush anything.

@jdalton
Copy link
Contributor

jdalton commented Nov 24, 2017

@askoretskiy

Also, support in acorn blocks introducing this support in webpack that is somehow a show stopper. Without it you cannot pack JS code and deliver to the client.

It's not a show stopper for webpack (use the appropriate Babel plugin).

@marijnh

Use https://github.com/victor-homyakov/acorn-object-rest-spread

The one by Acorn's own, or should really soon to be own, @adrianheine is more accurate
(you may need the master branch of acorn):
https://github.com/adrianheine/acorn5-object-spread

@adrianheine

Stage 3 is a pretty common place to be in and they are planning to get accepted in the next months. No need to rush anything.

It would be nice if Acorn core could read the temperature a bit better, but I get it. Acorn is the best option in parsers at the moment, even with lack of support for common things like object-rest-spread. I make due hacking together plugins until features meet their bar. By the way, for folks just wanting parse support without concern for syntax validation, object-rest-spread is pretty straight forward.

@adrianheine
Copy link
Member

This will probably get merged pretty soon, see #658.

@marijnh
Copy link
Member

marijnh commented Jan 26, 2018

#658 was merged.

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

10 participants