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
In order to add new syntax, you need to modify the parser (we don't allow plugins on purpose but I kinda want to re-think that but in a way that doesn't ruin the ecosystem, which is I suppose why the parser is "bundled" now).
Currently you can pass overrides for the parser/generator if you want fork the parser or use recast/prettier to do codemods.
Even in a PR to babel (ex: tc39/proposal-private-fields-in-in
, babel/babel#11372) you have to change a lot of different files (a good thing as it's independent), but maybe it's possible to keep it in one place? I know this wouldn't work if you are modifying different nodes, but just thinking out loud here.
So it would be interesting if we supported adding your own "types", "printer nodes" in the plugin itself?
exportfunctioncustomPlugin(){return{parser: {// @babel/parserparserOverrideFunction(){// parse a?.b }},
visitor,// same as usualgenerator: {// @babel/generatorOptionalChaining(){// print a?.b }},types: {// for @babel/typesOptionalChaining: {builder: ["operator","left","right"],visitor: ["left","right"],aliases: ["Binary","Expression"]}}};}
The text was updated successfully, but these errors were encountered:
I think any change that makes it easier to add new syntax locally would likely make it easier to add in a published package, thus "ruining the ecosystem" :-/
It's already pretty simple but we don't document it well. I would like more people to understand ASTs/compilers/etc so it comes with the territory I guess. My ideal is allowing people to write the whole thing in the repl/whatever we call it. Doesn't mean you can publish but you can share a link for people to test it out and get feedback. Just thinking how to balance it
Just another idea I had for making it easier to create new syntax (not necessarily for production or standardization but to test out ideas).
Currently, the only thing you can do now in transform plugin itself is modify existing AST/syntax.
In order to add new syntax, you need to modify the parser (we don't allow plugins on purpose but I kinda want to re-think that but in a way that doesn't ruin the ecosystem, which is I suppose why the parser is "bundled" now).
Even in a PR to babel (ex: tc39/proposal-private-fields-in-in
, babel/babel#11372) you have to change a lot of different files (a good thing as it's independent), but maybe it's possible to keep it in one place? I know this wouldn't work if you are modifying different nodes, but just thinking out loud here.
So it would be interesting if we supported adding your own "types", "printer nodes" in the plugin itself?
The text was updated successfully, but these errors were encountered: