-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for SWC as a Wallaby compiler #2823
Comments
Please read: #2818 (comment) for additional context re: this issue. |
Managed to get it working using a simple Rust wrapper: https://github.com/vjpr/swc-wallaby Now on the user-you only need SWC, no Babel needed. Just need to figure out the deploy/publish. |
So how does one now use SWC with wallaby? |
@patroza - what are you using as your testing framework? |
Jest with swc |
@patroza If swc is configured and working for your with Jest CLI (ie. you can run |
Just going to leave this here as a reference for options for using SWC.
Summary of options for SWC support
Just thought I would leave a summary of SWC support options here too.
Use JS visitor API (
@swc/core/Visitor
)Apparently API is being removed. Code available here -> #2818 (comment)
Use
swc#parse
SWC has a
parse
method that returns a JSON AST.API is also being removed.They are keeping it! swc-project/swc#2123 (comment)Also, currently it is slow. swc-project/swc/issues/2175 - Speed up parse()
The AST is non-standard too. There are issues discussing compatibility here:
swc-project/swc#2123 - Babel compatible AST
swc-project/swc#1392 - ESTree compatible AST
swc-project/swc#246 - Using SWC AST for eslint
Parse with Babel, transform with SWC
Probably negates the speed benefits.
-> I am currently using this approach, haven't benchmarked yet.
Wallaby uses
acorn
to parse and visit and instrument behind-the-scenes and apply their magic. So it's questionable how much benefit you get from SWC as a transpiler for instrumented code. But if you don't instrument parts of your code, you would get a large speed-up I would expect. But Wallaby is mostly used in incremental compile mode, so we are only benefiting from cold-start.Use ESbuild for Wallaby code parsing/compilation
This might have better standard AST support than Babel.Just need a way to go from AST -> Wallaby ranges.ESBuild does not expose the AST. evanw/esbuild#201
It is very locked down regarding plugins/AST as part of its philosophy.
Just use Babel / TSC
Slower than what is theoretically possible natively, but guaranteed to work, and supported natively by Wallaby. See some benches here -> #2818 (comment) / https://wallabyjs.com/blog/optimizing-typescript.html
Wrap
@swc/core
- IMPLEMENTED! - https://github.com/vjpr/swc-wallabyswc-project/swc#2320 (comment)
There is
next-swc
, which implements a new binding wrapping@swc/core
. The Rust Cargo package systems makes it quite easy to extend SWC as necessary by just adding SWC's Rust packages as deps.The advantage of this approach is that converting the AST's to JSON is a bottleneck, so a wrapper can extract just the ranges during the parsing process causing zero overhead - the AST never needs to be read by JS code.
The text was updated successfully, but these errors were encountered: