richardscarrott / ok-computer

λ "Functions all the way down" data validation for JavaScript and TypeScript.
MIT License
79 stars 0 forks source link

Improve tree-shaking #24

Open richardscarrott opened 1 year ago

richardscarrott commented 1 year ago

Both rollup and webpack fail to efficiently tree-shake the codebase which, although very small, would be still be nice given it is side effect free.

I think it's related to curried functions being executed on import but also specifically seems to be related to newing up errors in and, or etc.

https://github.com/richardscarrott/ok-computer/pull/21

richardscarrott commented 1 year ago

https://dev.to/livechat/tree-shaking-for-javascript-library-authors-4lb0

richardscarrott commented 1 year ago

It seems introspectValidator is problematic because it does in fact have a side-effect (throws), however it's only relevant if the return value is used so prob a legit case for PURE annotation, however it's all so brittle I think it'd be better to have a test which bundles w/ rollup and asserts the output.

Also, might want to try: https://github.com/Andarist/babel-plugin-annotate-pure-calls