embroider-build / content-tag

A rust program that uses a fork of SWC to parse and transform Javascript containing the content-tag proposal
MIT License
8 stars 7 forks source link

Pass a better message back to JS #10

Closed mansona closed 1 year ago

mansona commented 1 year ago

fixes #1

ef4 commented 1 year ago

Thanks.

Can we please try to match the output of the pure rust examples? For example, run cargo run ./sample/has_error.js and you'll see that it produces a codeframe pointing at the syntax error:

Screenshot 2023-07-08 at 3 56 55 PM

swc is already tracking squrcemap-like details that enable it to produce this output. If we can just capture those and attach them to the exception, we'd be able to match the pretty output even from JS.

mansona commented 1 year ago

So it turns out this was surprisingly difficult 🙈 I don't know if it's just a result of the API that SWC has for its errors but I had to do some Rust jujitsu that was a bit outside of my confort zone to get this to work 🙃

I "stole" the implementation of the "error to string" functionality from https://github.com/swc-project/swc/blob/e4f9f734ad1f92c6f05e8cb4c2d799679cca9f79/crates/swc_error_reporters/tests/fixture.rs so I hope it's ok.

Also worth noting that I wasn't able to match the CLI version output exactly no matter what I did 🤔 I tried different handlers with different GraphicalThemes but nothing seemed to work. I settled for one that was as close as I could get 👍