Closed heygrady closed 2 years ago
Hi @heygrady!
That sounds cool. I don't have the bandwidth to work on it myself, but if you want to do it then you're welcome to! 👍
What language are SWC plugins written in? Rust?
Indeed, they are written in Rust. So macros would have to be themselves written in Rust. This may be possible, but it won't share any code or architecture with babel-plugin-macros
and would require maintainers with a completely different skill set. I'm going to close this issue as it will never be actionable here. Best of luck to those looking for this functionality.
Some update on the SWC front here: https://github.com/swc-project/swc/issues/3167
TL;DR: they are integrating WASM plugin support in SWC. This means you can write your plugins in any language that can be compiled to WASM, for example Typescript with https://www.assemblyscript.org
Would this make it easier to have a macros plugin for SWC ?
That might make it possible! May I suggest that you make a repo or chat or something for people who are interested in using or building that functionality to talk and collaborate, and you should link to it here.
The plugin support in SWC is still an experimental work in progress. If it lives up to expectations and goes into a release, then I will see what I can do!
But I suspect that it will need to be a separate project from this one, as SWC uses a different AST than babel, so macros will probably need to be rewritten entirely
I agree that it would be a separate project that would not be intercompatible with this one. Hence the suggestion to make a new space for interested contributors.
Maybe this is a noob question, but wouldn't this PR have made this possible?
@matthewmatician I mean you could always do a two-step process. Parse with babel, transpile macros, send the program to SWC, then have SWC do the rest of the transpilation.
The only question is: how you would send the program to SWC? Obviously you could print it from babel and parse in SWC. But perhaps there's a more efficient way? I can't say I understand the PR you linked well enough to know quite what its API would be. If it can do a copy in a way that's faster than a parse and print, then perhaps the perf numbers would still be favorable at the end of the day.
I realise this isn't directly related, however I am working on stailwc, a swc-native version of twin.macro which serves as both
https://swc-project.github.io/docs/usage-plugin
Proposal: create an
swc-plugin-macros
that is similar tobabel-plugin-macros
SWC is increasing in popularity. It is aiming to be a drop-in replacement for babel with some significant speed improvements. It already has a webpack loader.
There is some early interest in how it might integrate with create-react-app (https://github.com/facebook/create-react-app/issues/8060). Looking at which babel plugins create-react-app uses it seems like most of those things are supported by swc (with only a few exceptions).
SWC appears to be missing support for:
babel-plugin-macros
(important for some of my projects)babel-plugin-transform-react-remove-prop-types
(less important in TypeScript projects)babel-plugin-transform-flow-strip-types
(generally SWC has no Flow support 🤷🏻♂️)Generally everything else babel does for me is handled by swc preset-env (or isn't particularly vital to my projects).