Skip to content
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

fix(closure): don't throw at top-level scope #2546

Merged
merged 1 commit into from Apr 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/util/root.ts
Expand Up @@ -12,12 +12,18 @@ declare module NodeJS {
* self: browser in WebWorker
* global: Node.js/other
*/
export const root: any = (
typeof window == 'object' && window.window === window && window
|| typeof self == 'object' && self.self === self && self
|| typeof global == 'object' && global.global === global && global
);

if (!root) {
throw new Error('RxJS could not find any global context (window, self, global)');
export let root: any;
if (typeof window == 'object' && window.window === window) {
root = window;
} else if (typeof self == 'object' && self.self === self) {
root = self;
} else if (typeof global == 'object' && global.global === global) {
root = global;
} else {
// Workaround Closure Compiler restriction: The body of a goog.module cannot use throw.
// This is needed when used with angular/tsickle which inserts a goog.module statement.
// Wrap in IIFE
(function () {
throw new Error('RxJS could not find any global context (window, self, global)');
})();
}