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
Handling feature detections #2273
Comments
As for 1., we could talk about this but only if we add a flag to the tree-shake section to enable tree-shaking inside try blocks again. Thinking about 2., no, this is IMO not the place to put this. Feature detection will usually happen on globals, cf. your example with So the simplest approach is the one that already works: If we make sure that I really do not like the idea of a |
Also note that with the current architecture, it is very difficult (and probably not desirable anyway) to prevent tree-shaking inside functions called from try-blocks. |
As for 1 again, as I think feature detection is always related to globals, maybe this could be a nice approach:
This is of course not perfect due to the restrictions on nested function calls but could solve many issues. |
So in short I should be possible to put nearly everything into |
Throwing further ideas out here -
Perhaps if there was a nice way to do (1), (2) could actually be entirely handled in the plugin sphere. |
The more I think about it, the more I begin to like the idea of defining globals via an option. This may not be an option for everyone but it may be very useful for people fine-tuning libraries and of course plugin developers. If we pair this idea with reworking the handling of globals and make this powerful enough, very cool things could become possible:
|
I've just found out how broken are features detection with rollup. The most basic example is this one: try { new Event('!'); }
catch (o_O) {
Event = function () {};
}
export default Event; All I want to know is if there is a global The exported result ? try {}
catch (o_O) {
Event = function () {};
} A completely useless, because empty, This happens the same with Is there any estimation on how this will be fixed/trustable? |
I actually went for the try-statement deoptimization in #2892. No feature-flag yet but some logic to limit its infectious nature. |
Some ideas:
try {}
block, or even just deopt try blocks entirely.typeof X
,Object.create === undefined
, etc)The text was updated successfully, but these errors were encountered: