You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@babel/eslint-parser: parserOverride only works when you use @babel/parser #12753
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:
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()
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?
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."
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.
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 😃
Activity
babel-bot commentedon Feb 3, 2021
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."
kaicataldo commentedon Feb 4, 2021
To be clear, is this specifically an
@babel/eslint-parserissue? This ultimately looks like a duplicate of #9009 to me. Personally, I'm not convinced@babel/eslint-parsershould supportparserOverrides()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-parseras well). I know that's not fun, but usingparserOverridesis getting into the territory of us not being able to guarantee everything will be compatible.peteward44 commentedon Feb 4, 2021
Well, it's both an
@babel/eslint-parserissue 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 howparserOverrideis basically broken/useless when using in conjunction with@babel/eslint-parser. If you chose to just remove support forparserOverridewhen using eslint-parser that's up to you.Also this may effect other modules which use the token types exported by
@babel/corewhenparserOverrideis also being used.I already have a functioning fork which solves my issue, so i already know about how little fun that is 😃