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

[WIP] Add swc JavaScript parser #556

Closed
wants to merge 1 commit into from

Conversation

punkeel
Copy link
Contributor

@punkeel punkeel commented 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 #555.

@punkeel punkeel force-pushed the punkeel/555-add-swc-parser branch 2 times, most recently from bd4fcf6 to a07820a Compare December 26, 2020 21:58
@punkeel punkeel marked this pull request as draft December 26, 2020 22:05
@gengjiawen
Copy link
Contributor

Looks like npm moudle missing files.

ERROR in ./node_modules/@swc/wasm-web/wasm.js
Module not found: Error: Can't resolve './wasm_bg.js' in '/workspace/astexplorer/website/node_modules/@swc/wasm-web'
 @ ./node_modules/@swc/wasm-web/wasm.js 2:0-29 2:0-29
 @ ./src/parsers/js/transformers/swc/index.js
 @ ./src/parsers sync ^\.\/(?!utils|transpilers)[^/]+\/(transformers\/([^/]+)\/)?(codeExample\.txt|[^/]+?\.js)$
 @ ./src/parsers/index.js
 @ ./src/storage/gist.js
 @ ./src/app.js

image

@punkeel
Copy link
Contributor Author

punkeel commented Dec 29, 2020

Yup, a new @swc/wasm-web release is required to fix it 😕

> 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 punkeel force-pushed the punkeel/555-add-swc-parser branch from a07820a to 86b48eb Compare December 30, 2020 20:43
@punkeel punkeel marked this pull request as ready for review December 30, 2020 20:43
@punkeel punkeel marked this pull request as draft December 30, 2020 20:49
@punkeel
Copy link
Contributor Author

punkeel commented Dec 30, 2020

Still not ok ;(

@gengjiawen
Copy link
Contributor

Still not ok ;(

The publish npm is still broken, you can delete files in package.json and remove .gitignore in pkg folder.
My fork works (https://www.npmjs.com/package/@gengjiawen/swc).

image

@fkling
Copy link
Owner

fkling commented Jan 4, 2021

What's the current state of this? Can I do anything to help? Or do you just want me to take a look at the parser wrapper?

@gengjiawen
Copy link
Contributor

What's the current state of this? Can I do anything to help? Or do you just want me to take a look at the parser wrapper?

I think next release will swc will fix the build issue since the fix pr merged. Not sure the focus issue still exists ? @punkeel

@punkeel
Copy link
Contributor Author

punkeel commented Jan 4, 2021

Hey there,

This PR is still blocked by @swc/wasm-web not containing the required files, hopefully this will be fixed with the next release. Once it's ready, I'll just update the package.json+yarn.lock files. I don't plan on changing the code in this PR in the foreseeable future, so reviews are welcome!

The focus issue still exists, the bug is reproducible across reloads/builds, just introduce Syntax Errors in the snippet, and the focus stops working until the page is reloaded. I haven't been able to pinpoint a reason for it.

@jdb8
Copy link

jdb8 commented Aug 11, 2021

@punkeel hey, curious if @swc/wasm-web has now exposed what you need for this PR? I tried cloning it locally and bumping the package, but it seems like under webpack 4 (which astexplorer uses, at least in this branch), the way that the wasm lib is being imported doesn't work (they're using import.meta.url plus the URL() constructor which I think may have been added in webpack 5).

I can dig in more and google for workarounds but wondering if you were still interested in getting this merged - I think it'd be really useful as I and likely many others are starting to explore swc :)

Additionally - IMO something that would be really cool after this lands would be to support swc plugins in the transform section of ast explorer, so then it'd be feasible to prototype a full swc js plugin in-browser. UPDATE (2021-08-21): looks like the js plugin architecture is going to be deprecated, so this part probably doesn't make sense now (unless adding support for writing rust in-browser too!).

@punkeel
Copy link
Contributor Author

punkeel commented Jul 22, 2022

Merged as part of f6a399b

@punkeel punkeel closed this Jul 22, 2022
@punkeel punkeel deleted the punkeel/555-add-swc-parser branch July 22, 2022 21:15
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 this pull request may close these issues.

feature request: support swc
4 participants