Skip to content

@babel/eslint-parser: parserOverride only works when you use @babel/parser #12753

Closed

Description

@peteward44

Bug Report

  • I would like to work on a fix!

Current behavior
As suggested in your documentation, if you create a fork of @babel/parser and try to call that in parserOverride(), it will fail with a parsing error. Even if you make a copy of the @babel/parser folder in node_modules, call it @babel/parser2, it will fail with the same error if you try to use that instead. It is the same issue reported here in the old babel-eslint repo:

babel/babel-eslint#786

Basically because eslint/babel-eslint-parser/src/convert/convertTokens.js is using the types exported by @babel/core, (which is from @babel/parser), all type comparisons will fail, unless you are using the parser from @babel/parser, which defeats the point of parserOverride()

Environment

  Babel: 7.12.11
  System:
    OS: Windows 10 10.0.19041
  Binaries:
    Node: 10.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.16.0 - C:\Program Files\nodejs\yarn.CMD
    npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD

Possible Solution
As suggested here, #9009, a typesOverride option either for babel itself or babel-eslint-parser could solve this issue. I have already implemented this on my own fork as an option to babel-eslint-parser and it works fine, although it would make more sense to put this on a lower level and change the types exported by @babel/core. What do you think?

Additional context
Related issues:
#9009
babel/babel-eslint#786

Activity

  1. babel-bot commented on Feb 3, 2021

    @babel-bot
    Collaborator

    Hey @peteward44! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

    If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

  2. kaicataldo commented on Feb 4, 2021

    @kaicataldo
    Member

    To be clear, is this specifically an @babel/eslint-parser issue? This ultimately looks like a duplicate of #9009 to me. Personally, I'm not convinced @babel/eslint-parser should support parserOverrides() at all, since it requires first-class knowledge of node types for things like scope analysis and token types for conversion. It's hard enough to maintain as it is, and if we open the doors to a completely arbitrary AST I'm worried that it will become unmaintainable. If, on the other hand, Babel core gains built in knowledge and support, we could probably get it working by adding an API that allows to override the default scope analysis behavior.

    My recommendation would be to create a custom ESLint parser for this in the meantime (i.e. a fork of @babel/eslint-parser as well). I know that's not fun, but using parserOverrides is getting into the territory of us not being able to guarantee everything will be compatible.

  3. peteward44 commented on Feb 4, 2021

    @peteward44
    Author

    Well, it's both an @babel/eslint-parser issue as well as a core issue too, depending on how (if) you guys want to fix it. But i guess i wanted to raise awareness of how parserOverride is basically broken/useless when using in conjunction with @babel/eslint-parser. If you chose to just remove support for parserOverride when using eslint-parser that's up to you.

    Also this may effect other modules which use the token types exported by @babel/core when parserOverride is also being used.

    I already have a functioning fork which solves my issue, so i already know about how little fun that is 😃

  4. added
    outdated
    on Aug 6, 2021
  5. locked as resolved and limited conversation to collaborators on Aug 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: eslintoutdated

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions