Open thecotne opened 4 years ago
It sounds great, but I (a little bit) don't understand what you mean when say "macros on AST". Can you show some examples or links, where I can read about it? Or, the greatest thing which you can do, it's PR with the feature ^_^
i will try to implement it myself but before that i can explain it better
so let's start from basics
how does babel work?
there is parser that produces AST from code (string basically) there are plugins that produces AST from AST (transforming some js features to others like classes to functions with prototype etc.) and there is code generator that produces code (string) from AST
what i want to do is to allow hegel to have any number of plugins executed on AST before hegel itself starts to consume it (AST) so for example if we want to support do expressions we can just add @babel/plugin-proposal-do-expressions
and do expressions will become function call or conditional (ternary) operator and do expressions will be auto magically supported just like that
and other use case for having babel plugins will be to support macros with babel-plugin-macros and hegel will be only js type checker with support for type safe macros
Oh, sorry, but Hegel's goal is only analysis. Hegel isn't a compiler and currently, we don't want to convert it into a compiler because there will be a lot of problems which we can't solve with good level quality (optimization, result bundle code, etc.) Maybe in a bright future when we solve all our analysis problems we will try to make a good compilation. But not now. Sorry 😞
compilation and bundling still will be out of scope but we can just support analysis of AST after it has been transformed by few plugins (this even can be configured by user)
most of plugins does not make sense and analysis after them will be harder but some of them do make sense for example @babel/plugin-proposal-do-expressions
and babel-plugin-macros
but having those plugins in hegel does not mean we need to produce code (compilation) it's still babels job to transform code into something that browser/node will understand.
i am still going to implement this and maybe seeing it in action would be better explanation
Okay, will check your implementation ^_^
the idea is to first execute macros on AST and then type check that AST so that whatever macros produce can be trusted...
also we can support some js features through transformations so that codebase does not need to separately type check every new syntax sugar that TC39 approves