Let's discuss TypeScript support.
See original GitHub issueI am well aware that this is Babel world project and it was meant like that from the start. However, I would like to initiate the discussion here what it would take to have macros available in TypeScript world. Macros are such a great concept it would be almost a crime to leave it like this.
Problem
I am mostly coming from the situation I am trying to solve now. The LinguiJS is going to be using macros to transform i18n elements. While in a Webpack world it’s possible to run ts-loader
and babel-loader
in tandem, it already introduces challenges, eg. keep JSX untransformed so Babel can have enough information and do JSX transformation on its own later along with Macros.
Also, other toolings needs to solve the same. Be it extraction process of Lingui itself or Jest testing or any other bundler I suppose. None can use Webpack loaders and have its own way around. This is no good for a whole ecosystem in my opinion.
I am sure this situation is not unique and with rising adoption of TypeScript there will surely be more projects popping out trying to solve the same. I feel it would be rather unhealthy to keep ecosystem separated like this. Not only for library authors, but for users as well.
Solutions?
TypeScript has it’s own “plugin” system or rather it’s called custom transforms. There is some AST apparently, but I do have trouble finding a real documentation for that. Honestly, I’ve never been fiddling with AST in Babel, so I am probably the least capable person to deliver any valid information in here.
Would it be viable to basically have a Typescript transform that can understand babel macros out of the box? Most likely that due to AST difference the authors of macros would need to account for both variants, but on the user end it would mean complete transparency as you could use either language without hassle.
Goal
To prepare a TypeScript plugin/transform that would work in a similar fashion to babel-plugin-macros allowing user code driven transformation instead of relying on bunch of hard-to-configure plugins. Ultimately, if we can achieve some level of compatibility between these projects and bridge the gap, it make life easier for everyone.
Current stage
None 😃 We are seeking some smart people who have insight into TypeScript transforms and AST. We need to create a prototype that mimics the behavior of babel-plugin-macros
at some basic level to verify the core idea.
Why not to use Babel-Typescript support?
One might argue that since there is TypeScript support in Babel now, it’s a clear path and no need to bother with this. I would agree in case that support would be building on a real TypeScript compiler. Since it’s completely separate implementation, it might introduce unexpected errors and incompatibilities. VSCode checking can tell A and then Babel will transform it into B. Current lack of some features is an example of that and more might come.
Personally, I think it’s a wrong path, but that’s not the point of this discussion. Perhaps I am mistaken on this and I would love to be proven otherwise.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:36
- Comments:116 (29 by maintainers)
Top GitHub Comments
@FredyC https://github.com/xiaoxiangmoe/typescript-macros/
Babel-plugin-macros use mutable API, this does not seem to be compatible with TypeScript transformer, so I chose to use immutable API.
Checkout https://github.com/LeDDGroup/typescript-transform-macros