-
Notifications
You must be signed in to change notification settings - Fork 68
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
Export functions instead of static methods #22
Comments
It's definitely possible to tree-shake static methods in theory. Is the issue that tooling doesn't support that today? Which tool are you using to perform the tree-shaking? |
Is it though? The shaking of static methods would come with a lot of caveats and implicit assumptions about the code that I'm not comfortable with. Despite the name, static methods are very dynamic by the nature of JS. You can extend class in inherit static methods, use the class in mixin, assign it to variable, inject the class using DI.
Rollup and webpack. Neither supports tree-shaking of static methods. Not by default anyways, if there is a switch to toggle this feature I would gladly be corrected. |
I think this approach is necessary to make babel transform plugin to work? The Closure compiler will do the right thing -- though it will be a challenge to make it work for most of the random npm packages around. I just found it awkward to use in typescript, as the type is actually |
Only through a lot of introspection or making non-general assumptions about the code (a la Closure Compiler; though last time I used it had bugs around ES static). E.g. Generally tree shaking works only at the level of |
Also got bitten by this today! In the end I made a function returning the whole JSBI class so that at least the import of JSBI can be tree-shaken away if it's never used. But if you'd fix it so that it doesn't have side-effects that would be great. I'm using parcel v2 and terser, google closure compiler breaks my code. (Also I think google closure compiler doesn't support es2021 input and es2021 output IIRC?) |
The library is quite big and it cannot be tree shaken because all of the operators are static methods.
It would be nice to have them exported from module, so unused operators could be removed from final bundle, after all we all want faster web.
Chances are you won't be using many operators like bitwise operations.
In my case, I would like to use BigInt for operations on money and I really need only basic operations.
The text was updated successfully, but these errors were encountered: