Skip to content
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

Closed
vjpr opened this issue Oct 1, 2021 · 6 comments
Closed

Support for SWC as a Wallaby compiler #2823

vjpr opened this issue Oct 1, 2021 · 6 comments

Comments

@vjpr
Copy link

vjpr commented Oct 1, 2021

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-wallaby

kdy1: I think a new node binding built on top of swc will be the best.

swc-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.

@vjpr vjpr closed this as completed Oct 1, 2021
@smcenlly
Copy link
Member

smcenlly commented Oct 1, 2021

Please read: #2818 (comment) for additional context re: this issue.

@smcenlly smcenlly changed the title SWC support Support for SWC as a Wallaby compiler Oct 1, 2021
@vjpr
Copy link
Author

vjpr commented Oct 2, 2021

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.

@patroza
Copy link

patroza commented Jan 30, 2022

So how does one now use SWC with wallaby?

@smcenlly
Copy link
Member

@patroza - what are you using as your testing framework?

@patroza
Copy link

patroza commented Jan 31, 2022

@patroza - what are you using as your testing framework?

Jest with swc

@ArtemGovorov
Copy link
Member

@patroza If swc is configured and working for your with Jest CLI (ie. you can run npx jest from your repo's root and it works), then there's no special Wallaby config is required, you may simply start Wallaby on the project and ti should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants