-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
Use Esprima 2.x. #4
Conversation
@thlorenz ping |
As indicated, I'm weary of merging this in. As far as I recall people were using this branch and things broke horribly (particularly in browserify) so they switched to facebook's fork. Have those problems been fixed by now? |
Thanks for the response! I'm not sure about the issues from browserify (do you have the link handy?). I can't recall how browserify switched to Esprima 2. It probably attempted to use the so-called harmony branch, which was considered experimental and associated with esprima-fb, or worse, a few others unmaintained forks (e.g. esprima-six). Despite the name, esprima-fb is not a part of official Esprima as it served as a playground for Facebook to add support for ES6 and JSX while the ES2015 specification was not finalized yet (and yes, I wished many times in the past that Facebook didn't call it esprima-fb). Esprima 2.0 is the beginning of official ES6 support where ES6 features were added bit-by-bit, culminating in the latest 2.7 which has all the syntax features per the latest ES2015 specification. The development happens in Esprima upstream master systematically and carefully, not in some experimental branch. Official releases were made throughout the 2.x series. Other JS tools which need to support ES6 have switched to use it (Istanbul, JSCS, js2coffee, jsfmt, etc). Another way to think about it: Esprima 1.x is an ES5 parser, Esprima 2.x is an ES6 parser. /cc @mikesherov As for performance, (since a long time ago) Esprima is not much slower nor much faster than anybody else (see e.g. this speed comparison). If we want to compare latest esprima-fb vs Esprima 2.7.0, the numbers follow:
Esprima 2.x also aligns its syntax tree closer to the de-facto AST format, ESTree. This is the same AST followed by other parsers. Since esprima-fb is not maintained anymore, its AST is slightly outdated. Also, Esprima 2.x tries very hard to follow the ES2015 specification faithfully. Take a look at the way it correctly handles e.g. yield, identifier names, SMP, let, etc (with tons and tons of new unit tests). Those, along with many other spec-compliant fixes, were definitely not part of esprima-fb. In the context of redeyed (as well as e.g. cardinal), I think it's quite important to handle thoses cases well. I'm not aware of the config.js file, I'll take a look. Meanwhile, I'm happy to answer more questions. |
I can say that JSCS has been using 2.x for a while and are quite happy with the results. As far as what there is to be gained, rejoining the active mainline development now prepares this codebase for the eventual ES2016 changes that esprima will support but esprima-fb will not, since it's dead. As far as concerns of regressions go, the concern would be people using redeyed to highlight jsx. Otherwise, I think the unit suite that exists covers it pretty well, but of course, that's your call. Thanks for considering this PR. |
tl;dr not seeing a huge benefit, but willing to merge if you feel strongly about it and ensure that cardinal keeps working. Correct me if I'm wrong, but if I read your comment correctly @ariya we'd just prepare for gains here, but wouldn't see any right away.
OK, but nothing will be practically gained until the config file is updated since otherwise those extra tokens will be ignored. So with all this considered I'm leaning towards upgrading only when those additions become practical enough to allow adding extra tokens to the config file that then are handled by redeyed. However if you feel very strongly about this I'm open to merge this anyways especially considering that only 3 packages depend on redeyed currently (the main one being cardinal). So not too much could break here. |
I've added some future and strict mode reserved words to |
The benefit of using Esprima 2.7 instead of esprima-fb is that redeyed will correctly understand the input (JavaScript program or module) according to the specification. Perhaps it was not obvious from my previous comment, I'll try to clarify it. The fact that esprima-fb is outdated (it stopped tracking the specification long time ago) means that it is not as specification-compliant as Esprima 2.7. Among others, it means that some valid ES2015 program and module will be incorrectly rejected by esprima-fb (and thus also redeyed as well as cardinal). Few cases off the top of my head (each line is an example): function f() { new.target() }
x = 09.5
([[{ x= y }]]) => z;
for (var x = y in z) f(x);
function *x() { (z = yield) => {} }
import {x, y,} from "z"; Whenever I use cardinal and it mistakenly handles the input, it makes me sad (hence why I'm motivated to propose this fix). If you decide to merge this, I certainly hope it is because you are convinced of the said benefit, not merely because I (or someone else for that matter) feel strongly about it. |
Another good example of real-world highlighting problem: https://github.com/facebook/esprima/issues/117. |
Made you collab @ariya. |
Thanks for your vote of confidence, @thlorenz! I'll merge it soon. |
Thanks, published as |
Upgraded and updated cardinal themes so the change should've rippled through there :) |
Excellent. Thank you @thlorenz! 👍 |
Facebook's fork is deprecated. Let's just the mainline Esprima 2.x since it already supports major ES6 features.