es-module-lexer icon indicating copy to clipboard operation
es-module-lexer copied to clipboard

Raw C usage (or in Go via Cgo)

Open b3nten opened this issue 2 years ago • 6 comments

Hi,

I don't have experience with wasm (or C for that matter) but I'm wondering how difficult this would be to get working in C (and eventually Go)? Would it be a few small changes, or is it entirely designed for wasm as a target and would require significant work?

End goal would be to parse JS strings with this in a Go cli.

Cheers

b3nten avatar Feb 20 '23 07:02 b3nten

It should be possible to get this project building for native C quite easily yes. That said, since it wasn't designed for this, it likely would have vulnerabilities outside of being used in a Wasm sandbox.

There is also a Rust build at https://github.com/jspm/rust-lexer which may be easier to run in Go.

Another alternative might even be to use the component build at https://github.com/guybedford/es-module-lexer/pull/143 which builds a WebAssembly component which could be used in Go while retaining strong security. These Wasm directions are very experimental though so it would only be if you're interested in exploring that.

guybedford avatar Feb 21 '23 00:02 guybedford

Hi, thanks for the response

The Rust build looks promising, although I can't find it (perhaps it's a private repo?). I thought about using WASM but that looks like it would be fairly complex to run. I'm willing to explore different routes - it's not a high priority, I have the functionality via EsBuild but this would be preferable. What's the experimental part with Wasm?

b3nten avatar Feb 21 '23 00:02 b3nten

Ah, ok I've given you access to the Rust lexer. Note it's behind this main branch by quite a bit now, although in theory the upstreaming shouldn't be too tricky. Open to collaboration on that repo. Also happy to share more about Wasm workflows too.

guybedford avatar Feb 23 '23 19:02 guybedford

I'd be really interested in the Rust lexer as well (or other documentation on how to use the wasm module in rust). I was trying to get the lexer to run in Rust, but I was having a hard time using both wasmtime and cc, and can't seem to get things up and running.

thepassle avatar Nov 27 '23 12:11 thepassle

Also found this today: https://github.com/devongovett/es-module-lexer/blob/main/src/lib.rs for anybody else who's reading along

thepassle avatar Nov 27 '23 19:11 thepassle

The Rust version worked on previously in collaboration with @vovacodes is at https://github.com/jspm/rust-lexer. It hasn't been updated in over two years to the current es-module-lexer commits though.

guybedford avatar Nov 29 '23 06:11 guybedford