-
Notifications
You must be signed in to change notification settings - Fork 132
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
tslib is polluting window object #32
Comments
Any answer would be appreciated. |
This was to support the following scenario:
Since tslib can't know how it is going to be used, it tries to ensure it supports both module and non-module scenarios. |
If the issue is compelling enough, we could add a tslib.global.js variant (similar to what we do for tslib.es6.js), and restrict tslib.js. However; that would be a breaking change if anyone is depending on this functionality today. |
I ran into this issue while developing a library that needs to avoid adding/modifying properties on window. As a workaround, I am wrapping tslib with the following prelude/postlude:
;(function() {
var global = {};
})(); And building a wrapped copy of tslib using
This works because tslib first checks for a variable named This is brittle and could easily stop working if the structure of the tslib export code is changed, but I thought I would share it anyway in case it's useful to someone else. |
It is very strange to have |
@rbuckton any updates on this? |
Hey, so we just ran into this at Dropbox while trying to upgrade to Typescript 2.6, since that requires us to also upgrade tslib. We use alameda (an alternative requirejs implementation) and load AMD & UMD modules. So we expect to have few if not no global variables. When upgrading, we discovered that this global leakage (which we were unaware of before) now completely breaks our video previews: we use videojs 6.2.8, which appears to be a webpack or browserify bundle which internally, has a module that exports
to transform non-es6 modules into things that look like es6 modules. When loading that window module with the new tslib already loaded, videojs then wrongly decides that it's window module is actually an es6 module, and returns Moreover, we also use requirejs contexts so that we can transparently load different versions of the same module - which means, in theory, we could attempt to load two different copies of tslib on a page, so any code using the globals is not guaranteed to get the right version. Thankfully I see nothing that depends on the globals, but I would sleep better if we didn't leak them in the first place. |
#42 does not entirely fix this issue. |
This sounds good. |
Any status update on this issue? |
Any news on this? |
Similar to getsentry/sentry-javascript#2215, this causes a (somewhat minor) issue for test frameworks. In my case leak detection was enabled by default in |
Is there a reason why tslib is pushing the helper functions to the window object when module.exports is available?
-> https://github.com/Microsoft/tslib/blob/master/tslib.js#L38
The text was updated successfully, but these errors were encountered: