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

feature request: support swc #555

Open
punkeel opened this issue Dec 16, 2020 · 9 comments
Open

feature request: support swc #555

punkeel opened this issue Dec 16, 2020 · 9 comments

Comments

@punkeel
Copy link
Contributor

punkeel commented Dec 16, 2020

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

@RReverser
Copy link
Collaborator

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.

@punkeel
Copy link
Contributor Author

punkeel commented Dec 16, 2020

Indeed, swc/wasm exists and is deployed to npm. It's targeting nodejs, so I've opened swc-project/swc#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 added a commit to punkeel/astexplorer that referenced this issue Dec 16, 2020
…orted

> javascript from modern standards and typescript.

Expose the swc parser in AST Explorer. This parser is built using Rust, and
the client side version relies on WebAssembly.

Known bug: any action (editing the code or changing a setting) breaks the
Autofocus feature, and requires a page reload.

Closes fkling#555.
punkeel added a commit to punkeel/astexplorer that referenced this issue Dec 16, 2020
…orted

> javascript from modern standards and typescript.

Expose the swc parser in AST Explorer. This parser is built using Rust, and
the client side version relies on WebAssembly.

Known bug: any action (editing the code or changing a setting) breaks the
Autofocus feature, and requires a page reload.

Closes fkling#555.
punkeel added a commit to punkeel/astexplorer that referenced this issue Dec 16, 2020
> swc is a super-fast compiler written in rust; producing widely-supported
> javascript from modern standards and typescript.

Expose the swc parser in AST Explorer. This parser is built using Rust, and
the client side version relies on WebAssembly.

Known bug: any action (editing the code or changing a setting) breaks the
Autofocus feature, and requires a page reload.

Closes fkling#555.
@punkeel
Copy link
Contributor Author

punkeel commented Dec 16, 2020

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

@RReverser
Copy link
Collaborator

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.

punkeel added a commit to punkeel/astexplorer that referenced this issue Dec 26, 2020
> swc is a super-fast compiler written in rust; producing widely-supported
> javascript from modern standards and typescript.

Expose the swc parser in AST Explorer. This parser is built using Rust, and
the client side version relies on WebAssembly.
Add a swc transformer, accepting a config object (see https://swc.rs/docs/configuring-swc).

Known bug: any action (editing the code or changing a setting) breaks the
Autofocus feature, and requires a page reload.

Closes fkling#555.
punkeel added a commit to punkeel/astexplorer that referenced this issue Dec 26, 2020
> swc is a super-fast compiler written in rust; producing widely-supported
> javascript from modern standards and typescript.

Expose the swc parser in AST Explorer. This parser is built using Rust, and
the client side version relies on WebAssembly.
Add a swc transformer, accepting a config object (see https://swc.rs/docs/configuring-swc).

Known bug: any action (editing the code or changing a setting) breaks the
Autofocus feature, and requires a page reload.

Closes fkling#555.
@punkeel
Copy link
Contributor Author

punkeel commented Dec 26, 2020

A first version of @swc/wasm-web was published, but another release is required to fix a bug, see swc-project/swc#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 (#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 swc-project/swc#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

@9oelM
Copy link

9oelM commented Dec 26, 2020

@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

punkeel added a commit to punkeel/astexplorer that referenced this issue Dec 30, 2020
> swc is a super-fast compiler written in rust; producing widely-supported
> javascript from modern standards and typescript.

Expose the swc parser in AST Explorer. This parser is built using Rust, and
the client side version relies on WebAssembly.
Add a swc transformer, accepting a config object (see https://swc.rs/docs/configuring-swc).

Known bug: any action (editing the code or changing a setting) breaks the
Autofocus feature, and requires a page reload.

Closes fkling#555.
@ShayRubach
Copy link

ShayRubach commented Jan 13, 2022

@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?

@0xdevalias
Copy link

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

image

@mantou132
Copy link

mantou132 commented Sep 11, 2024

Currently "Autofocus" does not work when decorators are enabled?

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

Successfully merging a pull request may close this issue.

6 participants