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
How to override babel-types when using a custom parser? #9009
Is there a way to specify a custom version of @babel/types to be used when using a custom parser with the parserOverride option? I am working on an experimental plugin that requires custom syntax, so I forked @babel/parser and got the parsing part working, and parserOverride works well to tell Babel to use my custom version of babel-parser. I also forked babel-types and pointed my package.json to the forked version. But @babel/core is still loading the official version of @babel/types, so in my transform plugin, I can't write visitors for the new AST types I added.
If the ability to specify a custom version of babel-types isn't currently available, I think this would be an important feature to add, otherwise it definitely limits the usefulness of parserOverride. It occurred to me that I might be able to use yarn's resolutions feature as a workaround, but then anyone else who wants to try my plugin would also need this configuration in their project. I'm open to any other ideas of how to force @babel/core to use my forked version of @babel/types... Thanks!
Hey @mbrowne! 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.
If we provide a typesOverride option, any plugin could still rely on @babel/types. We don't have a way of forcing them to use the user-provided parser.
OTOH, overwriting the parser used by @babel/traverse is probably powerful enough: we can investigate it.
Thanks! In the meantime, I did go ahead and use yarn's 'resolutions' feature to force all other modules to use my fork of @babel/types and it works fine. But of course it's yarn-specific.
Just pitching in here with a slightly different usecase: I'm trying to transpile an entirely different language (Nix) to JS, reusing Babel infrastructure where possible. I have a working parser for that language, as well as code that transforms its output into an AST that's shape-compatible with ESTree.
But I can't use @babel/traverse to transform the Nix AST nodes to JS AST nodes, as it won't accept custom node types...
Activity
babel-bot commentedon Nov 9, 2018
Hey @mbrowne! 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.
nicolo-ribaudo commentedon Nov 29, 2018
If we provide a
typesOverrideoption, any plugin could still rely on@babel/types. We don't have a way of forcing them to use the user-provided parser.OTOH, overwriting the parser used by
@babel/traverseis probably powerful enough: we can investigate it.mbrowne commentedon Nov 29, 2018
Thanks! In the meantime, I did go ahead and use yarn's 'resolutions' feature to force all other modules to use my fork of @babel/types and it works fine. But of course it's yarn-specific.
joepie91 commentedon Sep 17, 2021
Just pitching in here with a slightly different usecase: I'm trying to transpile an entirely different language (Nix) to JS, reusing Babel infrastructure where possible. I have a working parser for that language, as well as code that transforms its output into an AST that's shape-compatible with ESTree.
But I can't use
@babel/traverseto transform the Nix AST nodes to JS AST nodes, as it won't accept custom node types...