Supporting ES7/Babel
hzoo opened this issue ยท 29 comments
My plan is to make babel
a possible parser to use in the esprima
option.
I could do a repo for this so you can do "esprima": "babel-jscs"
or something like that.
Nothing would need to be changed in jscs
itself.
babel-jscs
would modify the acorn parser to output into an esprima format and patch estraverse
(just modifying babel-eslint
somewhat).
I got it working on an es7 code snippet (the issues linked) and a small project but running it with more rules leads to some errors that still need to be fixed.
Created - https://github.com/jscs-dev/babel-jscs
Almost ready to do an initial version - can someone give thoughts on the change in #1369?
Just ran all the rules/
tests (the other ones failed but shouldn't matter) and the only failing ones left are for validate-quote-marks
. Seems to lose quote information.
@moroshko, @olanod, @ben-ng - If you want to try it out, I created https://github.com/hzoo/babel-jscs for testing (no npm package yet).
Will wait for the next release and then move to https://github.com/jscs-dev/babel-jscs - (or should I just do that now?).
You'll need to update package.json
and your .jscsrc
to "esprima": "./node_modules/babel-jscs"
{
"node-jscs": "jscs-dev/node-jscs#master",
"babel-jscs": "hzoo/babel-jscs#master"
}
Does it work with our tests? We can intergrate this in our CI-runs, if it pass, i think we could do the npm package and push to jscs-dev org repo
I still have to figure out how to run the tests (git submodule?) not sure yet. I ran it manually before and got a few issues regarding cli, and quotes (babel infers the quotes will always output the same one).
It seems babel-jscs has support for jsx?
Yeah it will parse anything babel supports itself since it will be an option for esprima - "esprima": "babel-jscs"
(es6, es7, jsx, flow) - mostly through acorn-to-esprima
transformation and some other stuff
So is there anything preventing us from dropping esprima-harmony-jscs
dep and using babel-jscs
for esnext
option?
For me it would be that it hasn't been tested as much yet and not all the tests pass (at the moment) but that shouldn't be too hard to fix.
Well, we described this esnext
option as experimental, although, i fear about esprimaOptions
param.
Otherwise jsx and more extensive es6 supports does it for me.
@mikesherov, @zxqfox, @mrjoelkemp, @mdevils thoughts?
@markelog ๐ for jsx as a plugin for esprima ast. And I'm not sure we need this when we'll support esprima 2.x. Since there I'm not against using it for another library. But it's a revolution, and need to hear @mikesherov about it.
@hzoo thank you!! ๐ I was trying to set up jscs on a project that uses babel (es6) + flow, and couldn't find any parser that could accommodate both. your package made everything magically work. hope you keep developing it ๐
Just added this feature to 2.0 roadmap, i hope you don't mind
As for me, there is a strange situation around esprima
right now.
esprima
supportsES6
, but it does not supportES5
withoutES6
(it does not support enabling/disabling features). It also does not supportJSX
and doesn't have plugin interface to write aJSX
plugin.esprima-fb
is not planned to be supported.estraverse
supports bothES5
andES6
. And it can be configured to supportJSX
.escodegen
only supportsES5
(noES6
andJSX
support).escope
supports bothES5
andES6
, but does not supportJSX
.
I hope someone can share his picture on acorn/babel
.
Nice list
esprima supports ES6
Not fully, plugin interface will come right after full support of the ES6.
but it does not support ES5 without ES6
ES6 is back-compat, so i don't see an issue there.
Acorn supports es6 and written on es6-dialect also has plugin for jsx, you forgot the espree btw :-).
Answer for babel
is kinda obvious :-), but it also has support for ES7 features, like if someone mention possible extension on TC-meeting. But not proposed but only mentioned! It probably be added into the babel for the community response, which scary cool and dangerous at the same time.
In any case, i put all my money on babel-jscs
here.
What would I need to do for the pr?
Basically, pr that proposes to use babel-jscs
instead of esprima-fb
@hzoo where should I file issues? here:
https://github.com/hzoo/babel-jscs
I tried your branch seems buggy on the validatequotemarks. Its changing my single quotes to double quotes when I use -f
@deezahyn Um yeah just file it at https://github.com/hzoo/babel-jscs there until I move it to https://github.com/jscs-dev/babel-jscs. I guess we can just do it whenever.
However for that particular issue about quote marks I documented in the readme already. Not sure what we can do about it @sebmck?
Rules related to quotes won't work: validateQuoteMarks (Babel infers and transforms quotes to be consistent so you'll need to find another way to enforce this or turn off the parser and run it.)
Babel infers and transforms quotes to be consistent so you'll need to find another way to enforce this or turn off the parser and run it.
This is completely unrelated to the parser and is done in the code generator (which babel-jscs
and babel-eslint
don't use) so this isn't the cause of the issue.
@sebmck Ah ok. I didn't do enough research then xd.
@deezahyn Yeah you can make an issue for it in the repo or I'l do it later (added in hzoo/babel-jscs/issues/1)
@markelog Ok shouldn't be too hard to just replace the parser for esnext.
Seems like it's just
this._esprima = options.esprima || (options.esnext ? babelJscs : defaultEsprima);
Yeah :-)
Why not publish an beta version(npm publish . --tag beta
), so that we can install with a beta tag.
Install from github, sometimes will be too slow.
Sounds like a good idea (would be good so people can test and find any big issues). I think we're going to release "soon" though ๐
@hzoo That great. Waiting for you beta release.
I'm trying to enable es7 decorator rules in jscs. Will this help me out?
Now you just need to use esnext: true