eslint/js

Expose acorn plugin from espree module

Opened this issue · 6 comments

The espree parser is defined as a plugin for the Acorn parser. This plugin used to be accessible via espree/lib/espree.js, but this is now an internal module and cannot be imported directly.

Could this value be exported from the package? Something like export const acornPlugin = espree;

The fact that Espree is currently implemented as an Acorn plugin doesn't mean it always will be, so it doesn't make sense to export the Acorn plugin from the espree package.

However, I've been thinking it might be helpful to look at creating a different package that is more of general "ESLint Acorn plugin" that formats Acorn results in the way ESLint wants them. Espree could then use that, with any additional modifications necessary to get the full Espree experience. That would require a bit of thought, though, as it wouldn't make sense just to take the entire current Espree Acorn plugin and expose that.

@eslint/eslint-team what do you think about this idea?

I'd be perfectly happy if there was another package that exposed an "ESLint Acorn plugin", rather than exposing it from this package.

For context: I have a use case at work where we build a custom Acorn parser with specific behaviors, then we re-use that parser for ESLint. Right now we depend on espree@7 (which doesn't have exports defined on the package.json) so we can just directly import espree/lib/espree. We include the espree plugin with our own plugins and that produces a parser that works with ESLint. I ran into this exports issue when I went to update espree as it was introduced with espree@8.

@molisani thanks, that's very helpful context, and I think is a vote in favor of exposing the "ESLint Acorn plugin" separately to allow for people to build custom parsers with Acorn that can be used with ESLint.

Ping @eslint/eslint-tsc

However, I've been thinking it might be helpful to look at creating a different package that is more of general "ESLint Acorn plugin" that formats Acorn results in the way ESLint wants them. Espree could then use that, with any additional modifications necessary to get the full Espree experience. That would require a bit of thought, though, as it wouldn't make sense just to take the entire current Espree Acorn plugin and expose that.

I like the idea of an Acorn plugin, but to be honest I don't understand what is specific to Espree that is not also specific to ESLint, or was specific to ESLint at some point in time. So I'm not sure what the general "ESLint Acorn plugin" should expose if not the entire current Espree Acorn plugin, as the OP suggested. I'd be happy to comment on a more detailed proposal.

So I'm not sure what the general "ESLint Acorn plugin" should expose if not the entire current Espree Acorn plugin, as the OP suggested.

I'd need to look more closely, but basically it would be Espree without JSX support or impliedStrict (no ecmaFeatures) and would only export the plugin and not a parse() function.