rescript-compiler
rescript-compiler copied to clipboard
Throw as instance of JS `new Error()`
Throws an instance of JavaScript's new Error() and adds the extension payload for cause option
Breaking Changes
causehas a good support on browsers. See caniuse.com- Supported only in Node >= 16.9.0 MDN Browser Compatibility
Adapted from https://github.com/melange-re/melange/pull/1036
Thanks @anmonteiro
Should it be somehow marked as a ReScript exception?
Ah, I see there's a discussion exactly about this in the Melange PR https://github.com/melange-re/melange/pull/1036#issuecomment-1917749133
Related issue: https://github.com/rescript-lang/rescript-compiler/issues/4898
Ready for review. I don't know if it should go to v12 or v11
Since cause is only supported above Node 16.9 we can emit RescriptError and use instanceof
Can't we just drop support for nodejs 16 and only support node > 18? They dropped support for node 16 last August already.
Can't we just drop support for nodejs 16 and only support node > 18? They dropped support for node 16 last August already.
related: #6429
Sorry, missed this. Looks like a good change! @cristianoc any thoughts?
Would be useful to have an assessment of the consequences of this change, as well as a description. I guess this changes the internal representation of exceptions raised from ReScript. First things that come to mind is if this affects the ability of recognising what exceptions are from ReScript, and e.g. pattern match on them. Are there any observable changes after this in user code, any breaks, etc?
@aspeddro and anyone else interested - some more research needed here, let us know if you're interested in tackling it.
@aspeddro Could you rebase?
Rebase done!! Are we going to merge this?
I need to update the changelog
LGTM and could be merged after after updating the CHANGELOG. Agreed @zth?
We can investigate whether to port https://github.com/melange-re/melange/pull/1043 separately later on.
CHANGELOG updated https://github.com/rescript-lang/rescript-compiler/pull/6611/commits/15ea2538ffd8491aef2eec8e2527af5e9a6219b2
Good to go from my end.
Was wondering why CI wouldn't run, but then noticed the [skip ci] on the CHANGELOG commit. 😄
Will merge now as CI was successful on the previous commit.
With large scale codebases (especially web clients) this is a bit of an issue. Error usage is a major cause of bundle bloat, and major libraries such as React and Apollo additionally use a system called "invariant" to reduce bundle size bloating by errors.
- https://www.npmjs.com/package/invariant
- https://www.npmjs.com/package/ts-invariant
As we own the toolchain, there remains the potential to create a much better & performant result.