From d4e9b55fb69d87f948d02905d34fc78221adb11a Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 17 Mar 2016 20:58:25 -0700 Subject: [PATCH] fix: make sure that Zone does not show up in angular2.d.ts Closes #7655 --- gulpfile.js | 2 +- .../angular2/src/core/zone/ng_zone_impl.ts | 95 ++++++++++--------- modules/angular2/src/facade/lang.ts | 3 +- 3 files changed, 51 insertions(+), 49 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index bf9a0f280a..38eb2513a3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -988,7 +988,7 @@ gulp.task('test.typings', ['!pre.test.typings.layoutNodeModule', '!pre.test.typings.copyTypingsSpec'], function() { var tsc = require('gulp-typescript'); - return gulp.src([tmpdir + '/*.ts', 'node_modules/zone.js/dist/zone.js.d.ts']) + return gulp.src([tmpdir + '/*.ts']) .pipe(tsc({ target: 'ES6', module: 'commonjs', diff --git a/modules/angular2/src/core/zone/ng_zone_impl.ts b/modules/angular2/src/core/zone/ng_zone_impl.ts index 8445eb9adf..96ef145837 100644 --- a/modules/angular2/src/core/zone/ng_zone_impl.ts +++ b/modules/angular2/src/core/zone/ng_zone_impl.ts @@ -8,13 +8,12 @@ export class NgZoneError { } -export class NgZoneImpl implements ZoneSpec { +export class NgZoneImpl { static isInAngularZone(): boolean { return Zone.current.get('isAngularZone') === true; } - public name: string = 'angular'; - public properties: {[k: string]: string} = {'isAngularZone': true}; - + /** @internal */ private outer: Zone; + /** @internal */ private inner: Zone; private onEnter: () => void; @@ -37,7 +36,7 @@ export class NgZoneImpl implements ZoneSpec { this.setMacrotask = setMacrotask; this.onError = onError; - if (global.Zone) { + if (Zone) { this.outer = this.inner = Zone.current; if (Zone['wtfZoneSpec']) { this.inner = this.inner.fork(Zone['wtfZoneSpec']); @@ -45,52 +44,56 @@ export class NgZoneImpl implements ZoneSpec { if (trace) { this.inner = this.inner.fork(Zone['longStackTraceZoneSpec']); } - this.inner = this.inner.fork(this); + this.inner = this.inner.fork({ + name: 'angular', + properties:{'isAngularZone': true}, + onInvokeTask: (delegate: ZoneDelegate, current: Zone, target: Zone, task: Task, + applyThis: any, applyArgs: any): any => { + try { + this.onEnter(); + return delegate.invokeTask(target, task, applyThis, applyArgs); + } finally { + this.onLeave(); + } + }, + + + onInvoke: (delegate: ZoneDelegate, current: Zone, target: Zone, callback: Function, + applyThis: any, applyArgs: any[], source: string): any => { + try { + this.onEnter(); + return delegate.invoke(target, callback, applyThis, applyArgs, source); + } finally { + this.onLeave(); + } + }, + + onHasTask: + (delegate: ZoneDelegate, current: Zone, target: Zone, hasTaskState: HasTaskState) => { + delegate.hasTask(target, hasTaskState); + if (current == target) { + // We are only interested in hasTask events which originate from our zone + // (A child hasTask event is not interesting to us) + if (hasTaskState.change == 'microTask') { + this.setMicrotask(hasTaskState.microTask); + } else if (hasTaskState.change == 'macroTask') { + this.setMacrotask(hasTaskState.macroTask); + } + } + }, + + onHandleError: (delegate: ZoneDelegate, current: Zone, target: Zone, error: any): + boolean => { + delegate.handleError(target, error); + this.onError(new NgZoneError(error, error.stack)); + return false; + } + }); } else { throw new Error('Angular2 needs to be run with Zone.js polyfill.'); } } - onInvokeTask(delegate: ZoneDelegate, current: Zone, target: Zone, task: Task, applyThis: any, - applyArgs: any): any { - try { - this.onEnter(); - return delegate.invokeTask(target, task, applyThis, applyArgs); - } finally { - this.onLeave(); - } - }; - - - onInvoke(delegate: ZoneDelegate, current: Zone, target: Zone, callback: Function, applyThis: any, - applyArgs: any[], source: string): any { - try { - this.onEnter(); - return delegate.invoke(target, callback, applyThis, applyArgs, source); - } finally { - this.onLeave(); - } - } - - onHasTask(delegate: ZoneDelegate, current: Zone, target: Zone, hasTaskState: HasTaskState) { - delegate.hasTask(target, hasTaskState); - if (current == target) { - // We are only interested in hasTask events which originate from our zone - // (A child hasTask event is not interesting to us) - if (hasTaskState.change == 'microTask') { - this.setMicrotask(hasTaskState.microTask); - } else if (hasTaskState.change == 'macroTask') { - this.setMacrotask(hasTaskState.macroTask); - } - } - } - - onHandleError(delegate: ZoneDelegate, current: Zone, target: Zone, error: any): boolean { - delegate.handleError(target, error); - this.onError(new NgZoneError(error, error.stack)); - return false; - } - runInner(fn: () => any): any { return this.inner.runGuarded(fn); }; runOuter(fn: () => any): any { return this.outer.run(fn); }; } diff --git a/modules/angular2/src/facade/lang.ts b/modules/angular2/src/facade/lang.ts index 27d90ffed0..edfb50dc5b 100644 --- a/modules/angular2/src/facade/lang.ts +++ b/modules/angular2/src/facade/lang.ts @@ -9,7 +9,6 @@ export interface BrowserNodeGlobal { Math: any; // typeof Math; assert(condition: any): void; Reflect: any; - Zone: typeof Zone; getAngularTestability: Function; getAllAngularTestabilities: Function; getAllAngularRootElements: Function; @@ -477,4 +476,4 @@ export function bitWiseAnd(values: number[]): number { export function escape(s: string): string { return _global.encodeURI(s); -} \ No newline at end of file +}