fix: make sure that Zone does not show up in angular2.d.ts

Closes #7655
This commit is contained in:
Misko Hevery 2016-03-17 20:58:25 -07:00 committed by Miško Hevery
parent 048bd280dd
commit d4e9b55fb6
3 changed files with 51 additions and 49 deletions

View File

@ -988,7 +988,7 @@ gulp.task('test.typings',
['!pre.test.typings.layoutNodeModule', '!pre.test.typings.copyTypingsSpec'], function() { ['!pre.test.typings.layoutNodeModule', '!pre.test.typings.copyTypingsSpec'], function() {
var tsc = require('gulp-typescript'); 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({ .pipe(tsc({
target: 'ES6', target: 'ES6',
module: 'commonjs', module: 'commonjs',

View File

@ -8,13 +8,12 @@ export class NgZoneError {
} }
export class NgZoneImpl implements ZoneSpec { export class NgZoneImpl {
static isInAngularZone(): boolean { return Zone.current.get('isAngularZone') === true; } static isInAngularZone(): boolean { return Zone.current.get('isAngularZone') === true; }
public name: string = 'angular'; /** @internal */
public properties: {[k: string]: string} = <any>{'isAngularZone': true};
private outer: Zone; private outer: Zone;
/** @internal */
private inner: Zone; private inner: Zone;
private onEnter: () => void; private onEnter: () => void;
@ -37,7 +36,7 @@ export class NgZoneImpl implements ZoneSpec {
this.setMacrotask = setMacrotask; this.setMacrotask = setMacrotask;
this.onError = onError; this.onError = onError;
if (global.Zone) { if (Zone) {
this.outer = this.inner = Zone.current; this.outer = this.inner = Zone.current;
if (Zone['wtfZoneSpec']) { if (Zone['wtfZoneSpec']) {
this.inner = this.inner.fork(Zone['wtfZoneSpec']); this.inner = this.inner.fork(Zone['wtfZoneSpec']);
@ -45,34 +44,32 @@ export class NgZoneImpl implements ZoneSpec {
if (trace) { if (trace) {
this.inner = this.inner.fork(Zone['longStackTraceZoneSpec']); this.inner = this.inner.fork(Zone['longStackTraceZoneSpec']);
} }
this.inner = this.inner.fork(this); this.inner = this.inner.fork({
} else { name: 'angular',
throw new Error('Angular2 needs to be run with Zone.js polyfill.'); properties:<any>{'isAngularZone': true},
} onInvokeTask: (delegate: ZoneDelegate, current: Zone, target: Zone, task: Task,
} applyThis: any, applyArgs: any): any => {
onInvokeTask(delegate: ZoneDelegate, current: Zone, target: Zone, task: Task, applyThis: any,
applyArgs: any): any {
try { try {
this.onEnter(); this.onEnter();
return delegate.invokeTask(target, task, applyThis, applyArgs); return delegate.invokeTask(target, task, applyThis, applyArgs);
} finally { } finally {
this.onLeave(); this.onLeave();
} }
}; },
onInvoke(delegate: ZoneDelegate, current: Zone, target: Zone, callback: Function, applyThis: any, onInvoke: (delegate: ZoneDelegate, current: Zone, target: Zone, callback: Function,
applyArgs: any[], source: string): any { applyThis: any, applyArgs: any[], source: string): any => {
try { try {
this.onEnter(); this.onEnter();
return delegate.invoke(target, callback, applyThis, applyArgs, source); return delegate.invoke(target, callback, applyThis, applyArgs, source);
} finally { } finally {
this.onLeave(); this.onLeave();
} }
} },
onHasTask(delegate: ZoneDelegate, current: Zone, target: Zone, hasTaskState: HasTaskState) { onHasTask:
(delegate: ZoneDelegate, current: Zone, target: Zone, hasTaskState: HasTaskState) => {
delegate.hasTask(target, hasTaskState); delegate.hasTask(target, hasTaskState);
if (current == target) { if (current == target) {
// We are only interested in hasTask events which originate from our zone // We are only interested in hasTask events which originate from our zone
@ -83,13 +80,19 @@ export class NgZoneImpl implements ZoneSpec {
this.setMacrotask(hasTaskState.macroTask); this.setMacrotask(hasTaskState.macroTask);
} }
} }
} },
onHandleError(delegate: ZoneDelegate, current: Zone, target: Zone, error: any): boolean { onHandleError: (delegate: ZoneDelegate, current: Zone, target: Zone, error: any):
boolean => {
delegate.handleError(target, error); delegate.handleError(target, error);
this.onError(new NgZoneError(error, error.stack)); this.onError(new NgZoneError(error, error.stack));
return false; return false;
} }
});
} else {
throw new Error('Angular2 needs to be run with Zone.js polyfill.');
}
}
runInner(fn: () => any): any { return this.inner.runGuarded(fn); }; runInner(fn: () => any): any { return this.inner.runGuarded(fn); };
runOuter(fn: () => any): any { return this.outer.run(fn); }; runOuter(fn: () => any): any { return this.outer.run(fn); };

View File

@ -9,7 +9,6 @@ export interface BrowserNodeGlobal {
Math: any; // typeof Math; Math: any; // typeof Math;
assert(condition: any): void; assert(condition: any): void;
Reflect: any; Reflect: any;
Zone: typeof Zone;
getAngularTestability: Function; getAngularTestability: Function;
getAllAngularTestabilities: Function; getAllAngularTestabilities: Function;
getAllAngularRootElements: Function; getAllAngularRootElements: Function;