POC: Limited AST for preTransforms in TypeScript #121
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Okay!
DO NOT MERGE.
With regards to my comment here, I've created this POC.
It took a bit longer time than I expected, since I wasn't very familiar with Rust or how to write SWC plugins before this.
A few things to note:
playground/next
.packages/swc-plugin/src/transform.ts#L43
) could be specified in the swc/babel plugin as defaults.It's very rough, and messy at the moment. But due to the time difference from Sweden to Japan, I wanted to get it out there before you go to sleep.
The idea is that library authors might want to extend the functionality of the engine. This would allow for that.
I imagine an api like this:
Then my
__preCreateTheme
would create a serialisation that matches what needs to be done.Again, super early draft of my idea. I haven't had much time to work on it in code. But I think it's pretty flushed out conceptually.
Please take a look @taishinaritomi :)
Edit:
I also think that with this concept, we could remove the
preTransform
-plugins from babel and swc and adapt the new one I've written, to do all the work for us. Maybe. Just a thought!