Help wanted: swc-project (javascript transpiler)

babel.js, which is used in almost all web project these days, is a new-javascript to old-javascript compiler. But it’s quite slow. I want to replace babel with swc (speedy web compiler). You might know scss, It’s widely used because it’s much faster than alternatives.

I’ve implemented some basic features like parser and code generator.

Now I’m working on transformers (new-to-old compiler and optimizer), but it require lots of work and I want to know if someone wants to participate.

For demonstrating purpose, transpiler works like this

1 Like

How are you planning to do modules and plugins? In mdbook we enabled plugins by shelling out to an executable, piping input to it as JSON, then reading back the result, but that’s probably not going to work for something performance critical and frequently called like an AST transformer.

In my FFI guide I have a chapter about dynamic loading and plugins, where you can load a DLL at runtime, invoke a known “register” function, then use the trait object it gives you as a plugin.

May I suggest using Web Assembly as something like a “scripting language” for plugins. That way plugins can be loaded and unloaded dynamically, can be used cross-platform, and run in an isolated environment, so you can safely download and run untrusted plugins, which would be another advantage over the software you’re aiming to replace. The obstacle is just that there doesn’t currently seem to be a high performance Web Assembly host available to embed in Rust. I hope there will be one soon, and that this will be a new standard for loading plugins.

1 Like

Just as libsass, I want to make node binding which has plugin api.
It would be slower than normal passes but I don;t think it would be performance bottleneck.

I like the idea of using web assembly for plugins! It’d solve the problem of cross-compilation and would be considerably safer than dynamically loading DLLs. I know parity have a wasm VM which they use for their blockchain client, so that may be a possibility.

You also have an advantage in that WASM is amenable to type-checking and inspecting the signature of a function, which helps reduce the amount of unsafe code necessary.

This wouldn’t be too difficult, but it might be a bit annoying to implement. If you want JavaScript to be able to manipulate a program’s AST then either AST and any types it references would need to be run through something like wasm-bindgen or you could create a more simplified AST “facade” which JavaScript binds to and manipulates.

That just means writing more glue code to act as an adapter between languages, where some of it would need to be unsafe because there’s no guarantee JavaScript will adhere to rustc's rules around safety and mutability.

I don’t think web developer like writing plugin in wasm… I prefer js based plugin system as we target javascript developers.

wasm-bindgen allow us to export rust code to javascript code, right?
I’m not sure about wasm vs neon.