astexplorer icon indicating copy to clipboard operation
astexplorer copied to clipboard

feature request: support swc

Open punkeel opened this issue 5 years ago • 9 comments

swc is a super-fast compiler written in rust; producing widely-supported javascript from modern standards and typescript.

swc is a serious project with 10k stars on GitHub. It is used in Deno to transpile TypeScript code into JS. I'm not 100% sure, but there may be a WebAssembly version exposing parse / codegen functions.

It would be great to add support for swc in astexplorer.

cc @kdy1

punkeel avatar Dec 16 '20 17:12 punkeel

I'm not 100% sure, but there may be a WebAssembly version exposing parse / codegen functions.

It seems to have it right in the tree you provided: https://github.com/swc-project/swc/tree/master/wasm. If you can find or publish an npm package for bindings (see my https://github.com/RReverser/astexplorer-syn for an example), it should be fairly straightforward to integrate into ASTExplorer.

RReverser avatar Dec 16 '20 18:12 RReverser

Indeed, swc/wasm exists and is deployed to npm. It's targeting nodejs, so I've opened https://github.com/swc-project/swc/issues/1277 to add a web version of it. I'll try playing a bit with AST Explorer to see if I can add support there, thanks for the syn pointer!

punkeel avatar Dec 16 '20 19:12 punkeel

I've pushed a WIP pr #556 that has the following known issues:

  1. It doesn't build, as @swc/wasm isn't meant to be used from browsers. To test it locally, I've manually built a browser-friendly version and replaced the node_modules/... files. See issue linked above in swc project.
  2. When the code (or a setting) is changed, Autofocus is broken. Would you have any ideas what could cause this?

Thinking it could be WebAssembly shenanigans, I've tried wrapping the parseSync call in JSON.parse(JSON.stringify(...)), but it didn't help.

Aside from that, it was really easy to integrate in AST Explorer, ✨ magic ✨ ! swc astexplorer

punkeel avatar Dec 16 '20 21:12 punkeel

Aside from that, it was really easy to integrate in AST Explorer, ✨ magic ✨ !

Glad you liked it :) I've set it up a long time ago, and sometimes felt bad about all the Webpack magic it's doing, but it does seem to make contributions easier.

RReverser avatar Dec 16 '20 23:12 RReverser

A first version of @swc/wasm-web was published, but another release is required to fix a bug, see https://github.com/swc-project/swc/issues/1291.

I've started working on a swc transformer, and it was just as easy as adding a parser to AST Explorer (yay!). :) image

I'll update the PR to include this transformer, and I've prepared another PR (https://github.com/fkling/astexplorer/pull/557) to replace http-server in dev with light-server, the former sending the proper Accept header for .wasm files.

For now, the transformer accepts a JSON object. I think https://github.com/swc-project/swc/issues/1275 is needed before full-fledged plugins can be written, as they'd rely on @swc/core, even if it's just for types.

cc @9oelM

punkeel avatar Dec 26 '20 22:12 punkeel

@punkeel hi!

It seems that swc does not run something like a nightly build, which is the reason I had to build web wasm of swc myself and manually include it in 9oelm.github.io/swc-wasm-demo. It'd be great if swc would support nightly build (I'm open to helping if possible, too), although I'm not sure if this is the proper repo to talk about this 😅

Also i find that we got a lot to work on the wasm side of swc like what you said

9oelM avatar Dec 26 '20 23:12 9oelM

@9oelM TLDR - Is the swc type for ASTExplorer is fully working? And if so, how do I get an access to it? Any PR open or something?

ShayRubach avatar Jan 13 '22 11:01 ShayRubach

Given that the following PR has been merged and swc seems to be supported now, should this issue be closed?

  • https://github.com/fkling/astexplorer/pull/637

image

0xdevalias avatar Jul 10 '23 01:07 0xdevalias