-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Change the emit for __extends
to support easy global override
#1622
Comments
(Copying the comment from #1601 here)
This new emit tries to find a few well-known globals (node and browser) and falls back to The only user-visible difference from the current emit that I can think of is that, if the user is on node and already has a different __extends registered on the global object, it will now be clobbered. However users should not expect names prefixed with two underscores to be available to them, so I think this is acceptable. Also, if they already have a variable named __root in scope it will be clobbered. The same reasoning applies there. TS could complain about __root being used by user code, like it complains about user-defined Alternatively, it could be done in an IIFE that only exposes __extends: var __extends = (function (root) {
return root.__extends = root.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
})(typeof global !== "undefined" && global || typeof window !== "undefined" && window || this); Then no new variable is introduced and no new diagnostic is needed from TS. I think this is not much more complicated than the current __extends. In particular, it should have no difference from the current emit in terms of performance, because the actual __extends implementation is still the same - it does not hold on to anything new from its closure. For users who are already overridding __extends with their own |
Another option seems to be generating an extends module and having it be imported by all modules that use extends |
We are considering the following change, which would only be observably different in CommonJS (details below): if (typeof __extends !== "function") __extends = function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
}; Here are some additional details on this proposal:
In general, this would not be observably different for scripts or The downside is that this change would introduce a global identifier in CommonJS (and also eventually in ES6 modules) that would not have previously been defined. Also, running a linter against the output may result in a warning or error due to introducing a global identifier. We would like to get some feedback on this approach, and are considering this change for 1.5 beta. If you are aware of any existing behavior that would be negatively impacted by this change, please let us know. |
/cc @csnover |
As recently noted, does #2901 cover everything folks wanted here? |
#2901 should address the underlying issue. |
Change the emit for
__extends
to be :Reason:
It will allow you to override
__extends
globally with a singlerequire
call to a file that contains the following:Note: all AMD / CommonJS / internal modules will work
More : #1601 (comment)
The text was updated successfully, but these errors were encountered: