eslint / js

Monorepo for the JS language tools.
BSD 2-Clause "Simplified" License
2.29k stars 196 forks source link

espree improvements as an acorn plugin extension [RFC] #593

Closed martypdx closed 10 months ago

martypdx commented 10 months ago

I'm building an eslint custom parser extension and wanted to leverage the espree parser as an acorn extension to take advantage of the esprima compatible translation that already exist for tokens and comments (and template differences).

Running into some issues with the structure of espree:

Extension function not exposed

The acorn factory extension method is not currently exposed as an package export. Would be great to be able to import espreeAcornPlugin as a composable acorn plugin.

Changed option key for locations and ranges

Minor issue in that the keys for locations and ranges options differs (unnecessarily?) from acorn options. New options are fine but would be good to allow locations and ranges as input options.

Token and Context Types

This is a broader acorn plugin ecosystem issue, but the token types in espree are hard coded for only core acorn and acorn-jsx. I followed the acorn-jsx example and added a custom namespace as well, but that approach doesn't really work in a composable plugin system. Not sure what the answer is. Have some hacks in mind, will update with more info when I try them.

EDIT: Not sure what the answer is for this. I ended up injecting new tokens into the base Parser. Opened this issue on acorn.

nzakas commented 10 months ago

We don’t expose Acorn related functionality because using Acorn id an implementation that could potentially change in the future. We’ve discussed this before.

https://github.com/eslint/espree/issues/542#issuecomment-1094469829