From af14646f178c2d6c70f26d74e3a16297cd6a76b2 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Thu, 15 Dec 2016 10:50:41 -0800 Subject: [PATCH] fix(closure): avoid property renaming on globals --- lib/common/utils.ts | 2 +- lib/zone.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/common/utils.ts b/lib/common/utils.ts index 33b746f5c..1fb734eab 100644 --- a/lib/common/utils.ts +++ b/lib/common/utils.ts @@ -14,7 +14,7 @@ // Hack since TypeScript isn't compiling this for a worker. declare const WorkerGlobalScope; -export const zoneSymbol: (name: string) => string = Zone['__symbol__']; +export const zoneSymbol: (name: string) => string = (n) => `__zone_symbol__${n}`; const _global = typeof window === 'object' && window || typeof self === 'object' && self || global; export function bindArguments(args: any[], source: string): any[] { diff --git a/lib/zone.ts b/lib/zone.ts index e67f91a32..2ea28781e 100644 --- a/lib/zone.ts +++ b/lib/zone.ts @@ -6,6 +6,12 @@ * found in the LICENSE file at https://angular.io/license */ +/* + * Suppress closure compiler errors about unknown 'global' variable + * @fileoverview + * @suppress {undefinedVars} + */ + /** * Zone is a mechanism for intercepting and keeping track of asynchronous work. * @@ -540,7 +546,7 @@ type AmbientZone = Zone; type AmbientZoneDelegate = ZoneDelegate; const Zone: ZoneType = (function(global: any) { - if (global.Zone) { + if (global['Zone']) { throw new Error('Zone already loaded.'); } @@ -1214,8 +1220,8 @@ const Zone: ZoneType = (function(global: any) { ZoneAwarePromise['race'] = ZoneAwarePromise.race; ZoneAwarePromise['all'] = ZoneAwarePromise.all; - const NativePromise = global[__symbol__('Promise')] = global.Promise; - global.Promise = ZoneAwarePromise; + const NativePromise = global[__symbol__('Promise')] = global['Promise']; + global['Promise'] = ZoneAwarePromise; function patchThen(NativePromise) { const NativePromiseProtototype = NativePromise.prototype; const NativePromiseThen = NativePromiseProtototype[__symbol__('then')] = @@ -1428,5 +1434,5 @@ const Zone: ZoneType = (function(global: any) { // Cause the error to extract the stack frames. detectZone.runTask(detectZone.scheduleMacroTask('detect', detectRunFn, null, () => null, null)); - return global.Zone = Zone; + return global['Zone'] = Zone; })(typeof window === 'object' && window || typeof self === 'object' && self || global);