You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tree-shaking algorithm seems to be too aggressive; it drops some useful code breaking runtime feature detection. The dropped code is part of a module of core-js (v2.6.7) installed as dependencies of @babel/polyfill (v.7.4.4).
Rollup Version: 1.12.3
Operating System (or Browser): macOS Sierra 10.13.6
The reason the code is removed is that Rollup always assumes that the code is running in a current generation environment when deciding if the call to a global function/contstructor has side-effects (such as throwing an error). This of course is a big problem for feature detection and finding solutions for this is definitely on my to-do list.
Even though there are already issues for this topic, I really like your reproduction as it shows nicely the code that is generated by core-js and we can readily use it to write tests.
Even though I stated otherwise in #2273, I think now that deoptimizing try-catch statements with regard to tree-shaking might actually be a good compromise way forward if we manage to track situations as in your example.
Alternative approaches are:
provide a user option to list or determine via a function files which should not be tree-shaken
open up the API to define side-effects for globals (more useful in marking stuff as side-effects-free IMO)
a special (comment) syntax to retain code (would rely on adoption by library authors, though. We might consider working with core-js if we want this).
Tree-shaking algorithm seems to be too aggressive; it drops some useful code breaking runtime feature detection. The dropped code is part of a module of core-js (v2.6.7) installed as dependencies of @babel/polyfill (v.7.4.4).
How Do We Reproduce?
Clone this repository https://github.com/straccia17/rollup-treeshake-bug, execute yarn, then yarn run build.
Expected Behavior
Expected behavior is shown by dist/bundle-fixed.js files
Actual Behavior
Actual behavior is shown by dist/bundle.js files
Workaround
Set
treeshake: false
in rollup.config.jsThe text was updated successfully, but these errors were encountered: