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
Make accessing unknown globals a side-effect #3068
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3068 +/- ##
==========================================
+ Coverage 89.06% 89.21% +0.14%
==========================================
Files 165 165
Lines 5715 5719 +4
Branches 1738 1737 -1
==========================================
+ Hits 5090 5102 +12
+ Misses 383 380 -3
+ Partials 242 237 -5
Continue to review full report at Codecov.
|
a84ba59
to
f5441a9
Compare
f5441a9
to
4ed5632
Compare
c505f11
to
322c3e5
Compare
|
Figured out what I meant, and opened #3115. |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Resolves #3045
Description
This will make accessing unknown global variables a side-effect so that unchecked variable accesses are not removed by tree-shaking. To avoid too many false positives, the global handling was revised to use a common table for existing globals as well as pure global functions. The plan is to extend this in the future to add return types to global functions as well as handle global functions that have no side-effect except calling their arguments. In the end, I hope to merge this at some point with the existing logic for builtin prototypes.
The known globals have been mostly taken from the
builtin
section of https://github.com/sindresorhus/globals. Additionally, this also adds the global object to global detection as eitherglobalThis
,window
,global
orself
. I know that in any real environment, onlyglobalThis
is kind of a standard, but maybe this is a good compromise for the start.It also adds an new
treeshake.unknownGlobalSideEffects
option to deactivate this.