detective icon indicating copy to clipboard operation
detective copied to clipboard

Replace `acorn` parser for `babylon`?

Open zdychacek opened this issue 8 years ago • 5 comments

Hi,

I came across a problem when node-detective cannot operate on ES2015+ source code.

This is not a problem solely related to this package. The same problem applies to node-syntax-error package which is used in browserify pipeline.

I can see a clear problem in the fact, that some packages used by browserify internally depend on acorn parser.

This parser dependency is limiting e.g. for using browserify in conjuction with babelify in such situations when you don't want to transpile all the source code down to ES5.

For instance, let's say you don't want to transpile those syntax features, which are already natively supported by browsers, e.g. object spread operator in current Chrome. And now comes the problem with browserify syntax check and module dependecies parsing via module-deps -> node-detective dependency, all caused by code containing syntax features not parseable using acorn parser. It this case with ... operator.

Don't you think it would make sense to replace the parser and be more aligned with babel ecosystem?

Cheers,

Ondrej

PS: The same issue is being solved in these issues in Webpack project:

https://github.com/webpack/webpack/pull/4308 https://github.com/webpack/webpack/issues/2872

zdychacek avatar Jul 13 '17 19:07 zdychacek

Implemented in my fork: https://github.com/zdychacek/node-detective

I can create PR.

zdychacek avatar Jul 14 '17 15:07 zdychacek

node-detective has ES2017 support enabled already. On the specific point of object spread it is a ES2018 feature and only landed in Node 8.3.

Perhaps it would be simpler to just bump Acorn’s options to ecmaVersion to 9?

casr avatar Nov 11 '17 10:11 casr

@casr But what about non-standard features (stage < 4) which are already supported through Babel transformations?

Optional chaining operator and do expressions, to name a few.

zdychacek avatar Dec 06 '17 08:12 zdychacek

I don't think browserify should support nonstandard features. You would not be able to use them anyway after bundling without first applying babel to the result, so you might as well use babelify first.

goto-bus-stop avatar Feb 13 '18 14:02 goto-bus-stop

Note that most (all?) browserify packages now use acorn-node which has support for the latest features, and will match Node syntax with parser plugins if necessary.

goto-bus-stop avatar Feb 13 '18 15:02 goto-bus-stop