diff --git a/lib/browser/browser.ts b/lib/browser/browser.ts index bba9994d7..9b72338bd 100644 --- a/lib/browser/browser.ts +++ b/lib/browser/browser.ts @@ -154,7 +154,7 @@ Zone.__load_patch('XHR', (global: any, Zone: ZoneType) => { if (!storedTask) { target[XHR_TASK] = task; } - sendNative.apply(target, data.args); + sendNative!.apply(target, data.args); (XMLHttpRequest as any)[XHR_SCHEDULED] = true; return task; } @@ -166,31 +166,25 @@ Zone.__load_patch('XHR', (global: any, Zone: ZoneType) => { // Note - ideally, we would call data.target.removeEventListener here, but it's too late // to prevent it from firing. So instead, we store info for the event listener. data.aborted = true; - return abortNative.apply(data.target, data.args); + return abortNative!.apply(data.target, data.args); } - const openNative: Function = + const openNative = patchMethod(XMLHttpRequestPrototype, 'open', () => function(self: any, args: any[]) { self[XHR_SYNC] = args[2] == false; self[XHR_URL] = args[1]; - return openNative.apply(self, args); + return openNative!.apply(self, args); }); const XMLHTTPREQUEST_SOURCE = 'XMLHttpRequest.send'; - const sendNative: Function = + const sendNative = patchMethod(XMLHttpRequestPrototype, 'send', () => function(self: any, args: any[]) { if (self[XHR_SYNC]) { // if the XHR is sync there is no task to schedule, just execute the code. - return sendNative.apply(self, args); + return sendNative!.apply(self, args); } else { - const options: XHROptions = { - target: self, - url: self[XHR_URL], - isPeriodic: false, - delay: null, - args: args, - aborted: false - }; + const options: XHROptions = + {target: self, url: self[XHR_URL], isPeriodic: false, args: args, aborted: false}; return scheduleMacroTaskWithCurrentZone( XMLHTTPREQUEST_SOURCE, placeholderCallback, options, scheduleTask, clearTask); } diff --git a/lib/browser/define-property.ts b/lib/browser/define-property.ts index 00193832e..daffc6d12 100644 --- a/lib/browser/define-property.ts +++ b/lib/browser/define-property.ts @@ -48,7 +48,7 @@ export function propertyPatch() { Object.getOwnPropertyDescriptor = function(obj, prop) { const desc = _getOwnPropertyDescriptor(obj, prop); - if (isUnconfigurable(obj, prop)) { + if (desc && isUnconfigurable(obj, prop)) { desc.configurable = false; } return desc; @@ -97,7 +97,7 @@ function _tryDefineProperty(obj: any, prop: string, desc: any, originalConfigura try { return _defineProperty(obj, prop, desc); } catch (error) { - let descJson: string = null; + let descJson: string|null = null; try { descJson = JSON.stringify(desc); } catch (error) { diff --git a/lib/browser/property-descriptor.ts b/lib/browser/property-descriptor.ts index 221962802..b302eaad5 100644 --- a/lib/browser/property-descriptor.ts +++ b/lib/browser/property-descriptor.ts @@ -384,7 +384,7 @@ function canPatchViaPropertyDescriptor() { const detectFunc = () => {}; req.onreadystatechange = detectFunc; const result = (req as any)[SYMBOL_FAKE_ONREADYSTATECHANGE] === detectFunc; - req.onreadystatechange = null; + req.onreadystatechange = null as any; return result; } } diff --git a/lib/common/error-rewrite.ts b/lib/common/error-rewrite.ts index dcd5b3970..dc9a48918 100644 --- a/lib/common/error-rewrite.ts +++ b/lib/common/error-rewrite.ts @@ -63,7 +63,7 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => { // Process the stack trace and rewrite the frames. if ((ZoneAwareError as any)[stackRewrite] && originalStack) { let frames: string[] = originalStack.split('\n'); - let zoneFrame = api.currentZoneFrame(); + let zoneFrame: _ZoneFrame|null = api.currentZoneFrame(); let i = 0; // Find the first frame while (!(frames[i] === zoneAwareFrame1 || frames[i] === zoneAwareFrame2) && @@ -295,20 +295,20 @@ Zone.__load_patch('Error', (global: any, Zone: ZoneType, api: _ZonePrivate) => { () => { throw new (ZoneAwareError as any)(ZoneAwareError, NativeError); }, - null, + undefined, (t: Task) => { (t as any)._transitionTo = fakeTransitionTo; t.invoke(); }); }, - null, + undefined, (t) => { (t as any)._transitionTo = fakeTransitionTo; t.invoke(); }, () => {}); }, - null, + undefined, (t) => { (t as any)._transitionTo = fakeTransitionTo; t.invoke(); diff --git a/lib/common/events.ts b/lib/common/events.ts index ecc80122f..e3078529d 100644 --- a/lib/common/events.ts +++ b/lib/common/events.ts @@ -398,7 +398,7 @@ export function patchEventTarget( taskData.eventName = eventName; taskData.isExisting = isExisting; - const data = useGlobalCallback ? OPTIMIZED_ZONE_EVENT_TASK_DATA : null; + const data = useGlobalCallback ? OPTIMIZED_ZONE_EVENT_TASK_DATA : undefined; // keep taskData into data to allow onScheduleEventTask to access the task information if (data) { diff --git a/lib/common/promise.ts b/lib/common/promise.ts index 876d964bb..35eccc1f1 100644 --- a/lib/common/promise.ts +++ b/lib/common/promise.ts @@ -46,7 +46,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr api.microtaskDrainDone = () => { while (_uncaughtPromiseErrors.length) { while (_uncaughtPromiseErrors.length) { - const uncaughtPromiseError: UncaughtPromiseError = _uncaughtPromiseErrors.shift(); + const uncaughtPromiseError: UncaughtPromiseError = _uncaughtPromiseErrors.shift()!; try { uncaughtPromiseError.zone.runGuarded(() => { throw uncaughtPromiseError; @@ -164,7 +164,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr (promise as any)[symbolValue] = value; if ((promise as any)[symbolFinally] === symbolFinally) { - // the promise is generated by Promise.prototype.finally + // the promise is generated by Promise.prototype.finally if (state === RESOLVED) { // the state is resolved, should ignore the value // and use parent promise value @@ -202,7 +202,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr error.rejection = value; error.promise = promise; error.zone = Zone.current; - error.task = Zone.currentTask; + error.task = Zone.currentTask!; _uncaughtPromiseErrors.push(error); api.scheduleMicroTask(); // to make sure that it is running } @@ -239,7 +239,8 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr function scheduleResolveOrReject( promise: ZoneAwarePromise, zone: AmbientZone, chainPromise: ZoneAwarePromise, - onFulfilled?: (value: R) => U1, onRejected?: (error: any) => U2): void { + onFulfilled?: ((value: R) => U1) | null | undefined, + onRejected?: ((error: any) => U2) | null | undefined): void { clearRejectedNoCatch(promise); const promiseState = (promise as any)[symbolState]; const delegate = promiseState ? @@ -248,14 +249,19 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr zone.scheduleMicroTask(source, () => { try { const parentPromiseValue = (promise as any)[symbolValue]; - const isFinallyPromise = chainPromise && symbolFinally === (chainPromise as any)[symbolFinally]; + const isFinallyPromise = + chainPromise && symbolFinally === (chainPromise as any)[symbolFinally]; if (isFinallyPromise) { // if the promise is generated from finally call, keep parent promise's state and value (chainPromise as any)[symbolParentPromiseValue] = parentPromiseValue; (chainPromise as any)[symbolParentPromiseState] = promiseState; } // should not pass value to finally callback - const value = zone.run(delegate, undefined, isFinallyPromise && delegate !== forwardRejection && delegate !== forwardResolution ? [] : [parentPromiseValue]); + const value = zone.run( + delegate, undefined, + isFinallyPromise && delegate !== forwardRejection && delegate !== forwardResolution ? + [] : + [parentPromiseValue]); resolvePromise(chainPromise, true, value); } catch (error) { // if error occurs, should always return this error @@ -272,11 +278,11 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr } static resolve(value: R): Promise { - return resolvePromise(>new this(null), RESOLVED, value); + return resolvePromise(>new this(null as any), RESOLVED, value); } static reject(error: U): Promise { - return resolvePromise(>new this(null), REJECTED, error); + return resolvePromise(>new this(null as any), REJECTED, error); } static race(values: PromiseLike[]): Promise { @@ -323,10 +329,10 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr resolve(resolvedValues); } })(count), - reject); + reject!); count++; } - if (!count) resolve(resolvedValues); + if (!count) resolve!(resolvedValues); return promise; } @@ -351,7 +357,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr onRejected?: ((reason: any) => TResult2 | PromiseLike)|undefined| null): Promise { const chainPromise: Promise = - new (this.constructor as typeof ZoneAwarePromise)(null); + new (this.constructor as typeof ZoneAwarePromise)(null as any); const zone = Zone.current; if ((this as any)[symbolState] == UNRESOLVED) { ((this as any)[symbolValue]).push(zone, chainPromise, onFulfilled, onRejected); @@ -368,7 +374,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr finally(onFinally?: () => U | PromiseLike): Promise { const chainPromise: Promise = - new (this.constructor as typeof ZoneAwarePromise)(null); + new (this.constructor as typeof ZoneAwarePromise)(null as any); (chainPromise as any)[symbolFinally] = symbolFinally; const zone = Zone.current; if ((this as any)[symbolState] == UNRESOLVED) { diff --git a/lib/common/timers.ts b/lib/common/timers.ts index bdec80baf..ccf53aaba 100644 --- a/lib/common/timers.ts +++ b/lib/common/timers.ts @@ -15,13 +15,13 @@ import {patchMethod, scheduleMacroTaskWithCurrentZone, zoneSymbol} from './utils const taskSymbol = zoneSymbol('zoneTask'); interface TimerOptions extends TaskData { - handleId: number; + handleId?: number; args: any[]; } export function patchTimer(window: any, setName: string, cancelName: string, nameSuffix: string) { - let setNative: Function = null; - let clearNative: Function = null; + let setNative: Function|null = null; + let clearNative: Function|null = null; setName += nameSuffix; cancelName += nameSuffix; @@ -50,21 +50,21 @@ export function patchTimer(window: any, setName: string, cancelName: string, nam } } data.args[0] = timer; - data.handleId = setNative.apply(window, data.args); + data.handleId = setNative!.apply(window, data.args); return task; } function clearTask(task: Task) { - return clearNative((task.data).handleId); + return clearNative!((task.data).handleId); } setNative = patchMethod(window, setName, (delegate: Function) => function(self: any, args: any[]) { if (typeof args[0] === 'function') { const options: TimerOptions = { - handleId: null, isPeriodic: nameSuffix === 'Interval', - delay: (nameSuffix === 'Timeout' || nameSuffix === 'Interval') ? args[1] || 0 : null, + delay: (nameSuffix === 'Timeout' || nameSuffix === 'Interval') ? args[1] || 0 : + undefined, args: args }; const task = @@ -118,7 +118,7 @@ export function patchTimer(window: any, setName: string, cancelName: string, nam } if (task && typeof task.type === 'string') { if (task.state !== 'notScheduled' && - (task.cancelFn && task.data.isPeriodic || task.runCount === 0)) { + (task.cancelFn && task.data!.isPeriodic || task.runCount === 0)) { if (typeof id === 'number') { delete tasksByHandleId[id]; } else if (id) { diff --git a/lib/common/utils.ts b/lib/common/utils.ts index 958bd863d..2f5b40f39 100644 --- a/lib/common/utils.ts +++ b/lib/common/utils.ts @@ -43,8 +43,8 @@ export function wrapWithCurrentZone(callback: T, source: str } export function scheduleMacroTaskWithCurrentZone( - source: string, callback: Function, data: TaskData, customSchedule: (task: Task) => void, - customCancel: (task: Task) => void): MacroTask { + source: string, callback: Function, data?: TaskData, customSchedule?: (task: Task) => void, + customCancel?: (task: Task) => void): MacroTask { return Zone.current.scheduleMacroTask(source, callback, data, customSchedule, customCancel); } @@ -229,7 +229,7 @@ export function patchProperty(obj: any, prop: string, prototype?: any) { // so we should use original native get to retrieve the handler let value = originalDescGet && originalDescGet.call(this); if (value) { - desc.set.call(this, value); + desc!.set!.call(this, value); if (typeof target[REMOVE_ATTRIBUTE] === 'function') { target.removeAttribute(prop); } @@ -242,7 +242,7 @@ export function patchProperty(obj: any, prop: string, prototype?: any) { ObjectDefineProperty(obj, prop, desc); } -export function patchOnProperties(obj: any, properties: string[], prototype?: any) { +export function patchOnProperties(obj: any, properties: string[]|null, prototype?: any) { if (properties) { for (let i = 0; i < properties.length; i++) { patchProperty(obj, 'on' + properties[i], prototype); @@ -337,7 +337,7 @@ export function patchClass(className: string) { export function patchMethod( target: any, name: string, patchFn: (delegate: Function, delegateName: string, name: string) => (self: any, args: any[]) => - any): Function { + any): Function|null { let proto = target; while (proto && !proto.hasOwnProperty(name)) { proto = ObjectGetPrototypeOf(proto); @@ -348,14 +348,14 @@ export function patchMethod( } const delegateName = zoneSymbol(name); - let delegate: Function; + let delegate: Function|null = null; if (proto && !(delegate = proto[delegateName])) { delegate = proto[delegateName] = proto[name]; // check whether proto[name] is writable // some property is readonly in safari, such as HtmlCanvasElement.prototype.toBlob const desc = proto && ObjectGetOwnPropertyDescriptor(proto, name); if (isPropertyWritable(desc)) { - const patchDelegate = patchFn(delegate, delegateName, name); + const patchDelegate = patchFn(delegate!, delegateName, name); proto[name] = function() { return patchDelegate(this, arguments as any); }; @@ -375,22 +375,21 @@ export interface MacroTaskMeta extends TaskData { // TODO: @JiaLiPassion, support cancel task later if necessary export function patchMacroTask( obj: any, funcName: string, metaCreator: (self: any, args: any[]) => MacroTaskMeta) { - let setNative: Function = null; + let setNative: Function|null = null; function scheduleTask(task: Task) { const data = task.data; data.args[data.cbIdx] = function() { task.invoke.apply(this, arguments); }; - setNative.apply(data.target, data.args); + setNative!.apply(data.target, data.args); return task; } setNative = patchMethod(obj, funcName, (delegate: Function) => function(self: any, args: any[]) { const meta = metaCreator(self, args); if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') { - return scheduleMacroTaskWithCurrentZone( - meta.name, args[meta.cbIdx], meta, scheduleTask, null); + return scheduleMacroTaskWithCurrentZone(meta.name, args[meta.cbIdx], meta, scheduleTask); } else { // cause an error by calling it directly. return delegate.apply(self, args); @@ -407,14 +406,14 @@ export interface MicroTaskMeta extends TaskData { export function patchMicroTask( obj: any, funcName: string, metaCreator: (self: any, args: any[]) => MicroTaskMeta) { - let setNative: Function = null; + let setNative: Function|null = null; function scheduleTask(task: Task) { const data = task.data; data.args[data.cbIdx] = function() { task.invoke.apply(this, arguments); }; - setNative.apply(data.target, data.args); + setNative!.apply(data.target, data.args); return task; } diff --git a/lib/extra/cordova.ts b/lib/extra/cordova.ts index 0365248ec..c37938889 100644 --- a/lib/extra/cordova.ts +++ b/lib/extra/cordova.ts @@ -10,7 +10,7 @@ Zone.__load_patch('cordova', (global: any, Zone: ZoneType, api: _ZonePrivate) => const SUCCESS_SOURCE = 'cordova.exec.success'; const ERROR_SOURCE = 'cordova.exec.error'; const FUNCTION = 'function'; - const nativeExec: Function = + const nativeExec: Function|null = api.patchMethod(global.cordova, 'exec', () => function(self: any, args: any[]) { if (args.length > 0 && typeof args[0] === FUNCTION) { args[0] = Zone.current.wrap(args[0], SUCCESS_SOURCE); @@ -18,7 +18,7 @@ Zone.__load_patch('cordova', (global: any, Zone: ZoneType, api: _ZonePrivate) => if (args.length > 1 && typeof args[1] === FUNCTION) { args[1] = Zone.current.wrap(args[1], ERROR_SOURCE); } - return nativeExec.apply(self, args); + return nativeExec!.apply(self, args); }); } }); diff --git a/lib/extra/electron.ts b/lib/extra/electron.ts index eee5b552b..73693eaab 100644 --- a/lib/extra/electron.ts +++ b/lib/extra/electron.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ Zone.__load_patch('electron', (global: any, Zone: ZoneType, api: _ZonePrivate) => { - function patchArguments(target: any, name: string, source: string): Function { + function patchArguments(target: any, name: string, source: string): Function|null { return api.patchMethod(target, name, (delegate: Function) => (self: any, args: any[]) => { return delegate && delegate.apply(self, api.bindArguments(args, source)); }); diff --git a/lib/jasmine/jasmine.ts b/lib/jasmine/jasmine.ts index 5d279ab36..bbf68bc2c 100644 --- a/lib/jasmine/jasmine.ts +++ b/lib/jasmine/jasmine.ts @@ -234,7 +234,7 @@ _super.call(this, attrs); } ZoneQueueRunner.prototype.execute = function() { - let zone: Zone = Zone.current; + let zone: Zone|null = Zone.current; let isChildOfAmbientZone = false; while (zone) { if (zone === ambientZone) { diff --git a/lib/mocha/mocha.ts b/lib/mocha/mocha.ts index f36f76a4a..2b99a66c1 100644 --- a/lib/mocha/mocha.ts +++ b/lib/mocha/mocha.ts @@ -34,7 +34,7 @@ const rootZone = Zone.current; const syncZone = rootZone.fork(new SyncTestZoneSpec('Mocha.describe')); - let testZone: Zone = null; + let testZone: Zone|null = null; const suiteZone = rootZone.fork(new ProxyZoneSpec()); const mochaOriginal = { @@ -55,7 +55,7 @@ // Note we have to make a function with correct number of arguments, // otherwise mocha will // think that all functions are sync or async. - args[i] = (arg.length === 0) ? syncTest(arg) : asyncTest(arg); + args[i] = (arg.length === 0) ? syncTest(arg) : asyncTest!(arg); // Mocha uses toString to view the test body in the result list, make sure we return the // correct function body args[i].toString = function() { @@ -80,13 +80,13 @@ function wrapTestInZone(args: IArguments): any[] { const asyncTest = function(fn: Function) { return function(done: Function) { - return testZone.run(fn, this, [done]); + return testZone!.run(fn, this, [done]); }; }; const syncTest: any = function(fn: Function) { return function() { - return testZone.run(fn, this); + return testZone!.run(fn, this); }; }; diff --git a/lib/testing/async-testing.ts b/lib/testing/async-testing.ts index 1e3c3ab4a..c629ab6ca 100644 --- a/lib/testing/async-testing.ts +++ b/lib/testing/async-testing.ts @@ -70,7 +70,7 @@ Zone.__load_patch('asynctest', (global: any, Zone: ZoneType, api: _ZonePrivate) // If we do it in ProxyZone then we will get to infinite recursion. const proxyZone = Zone.current.getZoneWith('ProxyZoneSpec'); const previousDelegate = proxyZoneSpec.getDelegate(); - proxyZone.parent.run(() => { + proxyZone!.parent!.run(() => { const testZoneSpec: ZoneSpec = new AsyncTestZoneSpec( () => { // Need to restore the original zone. diff --git a/lib/zone-spec/async-test.ts b/lib/zone-spec/async-test.ts index 328585123..86ed4b190 100644 --- a/lib/zone-spec/async-test.ts +++ b/lib/zone-spec/async-test.ts @@ -108,7 +108,7 @@ class AsyncTestZoneSpec implements ZoneSpec { // was scheduled/invoked/canceled. onInvoke( parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, delegate: Function, - applyThis: any, applyArgs: any[], source: string): any { + applyThis: any, applyArgs?: any[], source?: string): any { let previousTaskCounts: any = null; try { this._isSync = true; diff --git a/lib/zone-spec/fake-async-test.ts b/lib/zone-spec/fake-async-test.ts index 278cc1f52..bdf7187c9 100644 --- a/lib/zone-spec/fake-async-test.ts +++ b/lib/zone-spec/fake-async-test.ts @@ -19,7 +19,7 @@ interface MicroTaskScheduledFunction { func: Function; - args: any[]; + args?: any[]; target: any; } @@ -137,7 +137,7 @@ break; } else { // Time to run scheduled function. Remove it from the head of queue. - let current = this._schedulerQueue.shift(); + let current = this._schedulerQueue.shift()!; lastCurrentTime = this._currentTime; this._currentTime = current.endTime; if (doTick) { @@ -192,7 +192,7 @@ break; } - const current = this._schedulerQueue.shift(); + const current = this._schedulerQueue.shift()!; lastCurrentTime = this._currentTime; this._currentTime = current.endTime; if (doTick) { @@ -218,7 +218,7 @@ private _scheduler: Scheduler = new Scheduler(); private _microtasks: MicroTaskScheduledFunction[] = []; - private _lastError: Error = null; + private _lastError: Error|null = null; private _uncaughtPromiseErrors: {rejection: any}[] = (Promise as any)[(Zone as any).__symbol__('uncaughtPromiseErrors')]; @@ -306,7 +306,7 @@ private _setInterval(fn: Function, interval: number, args: any[]): number { let id = this._scheduler.nextId; - let completers = {onSuccess: null as Function, onError: this._dequeuePeriodicTimer(id)}; + let completers = {onSuccess: null as any, onError: this._dequeuePeriodicTimer(id)}; let cb = this._fnAndFlush(fn, completers); // Use the callback created above to requeue on success. @@ -400,7 +400,7 @@ } }; while (this._microtasks.length > 0) { - let microtask = this._microtasks.shift(); + let microtask = this._microtasks.shift()!; microtask.func.apply(microtask.target, microtask.args); } flushErrors(); @@ -429,7 +429,7 @@ // should pass additional arguments to callback if have any // currently we know process.nextTick will have such additional // arguments - let additionalArgs: any[]; + let additionalArgs: any[]|undefined; if (args) { let callbackIndex = (task.data as any).cbIdx; if (typeof args.length === 'number' && args.length > callbackIndex + 1) { @@ -445,17 +445,17 @@ case 'macroTask': switch (task.source) { case 'setTimeout': - task.data['handleId'] = this._setTimeout( - task.invoke, task.data['delay'], + task.data!['handleId'] = this._setTimeout( + task.invoke, task.data!['delay']!, Array.prototype.slice.call((task.data as any)['args'], 2)); break; case 'setImmediate': - task.data['handleId'] = this._setTimeout( + task.data!['handleId'] = this._setTimeout( task.invoke, 0, Array.prototype.slice.call((task.data as any)['args'], 1)); break; case 'setInterval': - task.data['handleId'] = this._setInterval( - task.invoke, task.data['delay'], + task.data!['handleId'] = this._setInterval( + task.invoke, task.data!['delay']!, Array.prototype.slice.call((task.data as any)['args'], 2)); break; case 'XMLHttpRequest.send': @@ -467,7 +467,7 @@ case 'mozRequestAnimationFrame': // Simulate a requestAnimationFrame by using a setTimeout with 16 ms. // (60 frames per second) - task.data['handleId'] = this._setTimeout( + task.data!['handleId'] = this._setTimeout( task.invoke, 16, (task.data as any)['args'], this.trackPendingRequestAnimationFrame); break; @@ -482,11 +482,11 @@ macroTaskOption.callbackArgs ? macroTaskOption.callbackArgs : args; if (!!macroTaskOption.isPeriodic) { // periodic macroTask, use setInterval to simulate - task.data['handleId'] = this._setInterval(task.invoke, delay, callbackArgs); - task.data.isPeriodic = true; + task.data!['handleId'] = this._setInterval(task.invoke, delay, callbackArgs); + task.data!.isPeriodic = true; } else { // not periodic, use setTimeout to simulate - task.data['handleId'] = this._setTimeout(task.invoke, delay, callbackArgs); + task.data!['handleId'] = this._setTimeout(task.invoke, delay, callbackArgs); } break; } @@ -506,15 +506,15 @@ case 'requestAnimationFrame': case 'webkitRequestAnimationFrame': case 'mozRequestAnimationFrame': - return this._clearTimeout(task.data['handleId']); + return this._clearTimeout(task.data!['handleId']); case 'setInterval': - return this._clearInterval(task.data['handleId']); + return this._clearInterval(task.data!['handleId']); default: // user can define which macroTask they want to support by passing // macroTaskOptions const macroTaskOption = this.findMacroTaskOption(task); if (macroTaskOption) { - const handleId = task.data['handleId']; + const handleId: number = task.data!['handleId']; return macroTaskOption.isPeriodic ? this._clearInterval(handleId) : this._clearTimeout(handleId); } @@ -524,7 +524,7 @@ onInvoke( delegate: ZoneDelegate, current: Zone, target: Zone, callback: Function, applyThis: any, - applyArgs: any[], source: string): any { + applyArgs?: any[], source?: string): any { try { FakeAsyncTestZoneSpec.patchDate(); return delegate.invoke(target, callback, applyThis, applyArgs, source); diff --git a/lib/zone-spec/long-stack-trace.ts b/lib/zone-spec/long-stack-trace.ts index df42499e5..7ffa807d6 100644 --- a/lib/zone-spec/long-stack-trace.ts +++ b/lib/zone-spec/long-stack-trace.ts @@ -57,7 +57,7 @@ function addErrorStack(lines: string[], error: Error): void { } } -function renderLongStackTrace(frames: LongStackTrace[], stack: string): string { +function renderLongStackTrace(frames: LongStackTrace[], stack?: string): string { const longTrace: string[] = [stack ? stack.trim() : '']; if (frames) { @@ -83,16 +83,17 @@ function renderLongStackTrace(frames: LongStackTrace[], stack: string): string { longStackTraceLimit: 10, // Max number of task to keep the stack trace for. // add a getLongStackTrace method in spec to // handle handled reject promise error. - getLongStackTrace: function(error: Error): string { - if (!error) { - return undefined; - } - const trace = (error as any)[(Zone as any).__symbol__('currentTaskTrace')]; - if (!trace) { - return error.stack; - } - return renderLongStackTrace(trace, error.stack); - }, + getLongStackTrace: function(error: Error): string | + undefined { + if (!error) { + return undefined; + } + const trace = (error as any)[(Zone as any).__symbol__('currentTaskTrace')]; + if (!trace) { + return error.stack; + } + return renderLongStackTrace(trace, error.stack); + }, onScheduleTask: function( parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task): any { diff --git a/lib/zone-spec/proxy.ts b/lib/zone-spec/proxy.ts index abe03d6dd..16fbf213c 100644 --- a/lib/zone-spec/proxy.ts +++ b/lib/zone-spec/proxy.ts @@ -8,12 +8,12 @@ class ProxyZoneSpec implements ZoneSpec { name: string = 'ProxyZone'; - private _delegateSpec: ZoneSpec; + private _delegateSpec: ZoneSpec|null = null; properties: {[k: string]: any} = {'ProxyZoneSpec': this}; - propertyKeys: string[] = null; + propertyKeys: string[]|null = null; - lastTaskState: HasTaskState = null; + lastTaskState: HasTaskState|null = null; isNeedToTriggerHasTask = false; private tasks: Task[] = []; @@ -33,18 +33,18 @@ class ProxyZoneSpec implements ZoneSpec { return ProxyZoneSpec.get(); } - constructor(private defaultSpecDelegate: ZoneSpec = null) { + constructor(private defaultSpecDelegate: ZoneSpec|null = null) { this.setDelegate(defaultSpecDelegate); } - setDelegate(delegateSpec: ZoneSpec) { + setDelegate(delegateSpec: ZoneSpec|null) { const isNewDelegate = this._delegateSpec !== delegateSpec; this._delegateSpec = delegateSpec; this.propertyKeys && this.propertyKeys.forEach((key) => delete this.properties[key]); this.propertyKeys = null; if (delegateSpec && delegateSpec.properties) { this.propertyKeys = Object.keys(delegateSpec.properties); - this.propertyKeys.forEach((k) => this.properties[k] = delegateSpec.properties[k]); + this.propertyKeys.forEach((k) => this.properties[k] = delegateSpec.properties![k]); } // if set a new delegateSpec, shoulde check whether need to // trigger hasTask or not @@ -129,7 +129,7 @@ class ProxyZoneSpec implements ZoneSpec { onInvoke( parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, delegate: Function, - applyThis: any, applyArgs: any[], source: string): any { + applyThis: any, applyArgs?: any[], source?: string): any { this.tryTriggerHasTask(parentZoneDelegate, currentZone, targetZone); if (this._delegateSpec && this._delegateSpec.onInvoke) { return this._delegateSpec.onInvoke( diff --git a/lib/zone-spec/wtf.ts b/lib/zone-spec/wtf.ts index d56fc10a4..4a6c6694c 100644 --- a/lib/zone-spec/wtf.ts +++ b/lib/zone-spec/wtf.ts @@ -31,8 +31,8 @@ type WtfEventFn = (...args: any[]) => any; // Detect and setup WTF. - let wtfTrace: WtfTrace = null; - let wtfEvents: WtfEvents = null; + let wtfTrace: WtfTrace|null = null; + let wtfEvents: WtfEvents|null = null; const wtfEnabled: boolean = (function(): boolean { const wtf: Wtf = global['wtf']; if (wtf) { @@ -49,7 +49,7 @@ name: string = 'WTF'; static forkInstance = - wtfEnabled && wtfEvents.createInstance('Zone:fork(ascii zone, ascii newZone)'); + wtfEnabled ? wtfEvents!.createInstance('Zone:fork(ascii zone, ascii newZone)') : null; static scheduleInstance: {[key: string]: WtfEventFn} = {}; static cancelInstance: {[key: string]: WtfEventFn} = {}; static invokeScope: {[key: string]: WtfEventFn} = {}; @@ -59,19 +59,20 @@ parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, zoneSpec: ZoneSpec): Zone { const retValue = parentZoneDelegate.fork(targetZone, zoneSpec); - WtfZoneSpec.forkInstance(zonePathName(targetZone), retValue.name); + WtfZoneSpec.forkInstance!(zonePathName(targetZone), retValue.name); return retValue; } onInvoke( parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, delegate: Function, - applyThis: any, applyArgs: any[], source: string): any { - let scope = WtfZoneSpec.invokeScope[source]; + applyThis: any, applyArgs?: any[], source?: string): any { + const src = source || 'unknown'; + let scope = WtfZoneSpec.invokeScope[src]; if (!scope) { - scope = WtfZoneSpec.invokeScope[source] = - wtfEvents.createScope(`Zone:invoke:${source}(ascii zone)`); + scope = WtfZoneSpec.invokeScope[src] = + wtfEvents!.createScope(`Zone:invoke:${source}(ascii zone)`); } - return wtfTrace.leaveScope( + return wtfTrace!.leaveScope( scope(zonePathName(targetZone)), parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source)); } @@ -89,7 +90,7 @@ let instance = WtfZoneSpec.scheduleInstance[key]; if (!instance) { instance = WtfZoneSpec.scheduleInstance[key] = - wtfEvents.createInstance(`Zone:schedule:${key}(ascii zone, any data)`); + wtfEvents!.createInstance(`Zone:schedule:${key}(ascii zone, any data)`); } const retValue = parentZoneDelegate.scheduleTask(targetZone, task); instance(zonePathName(targetZone), shallowObj(task.data, 2)); @@ -99,14 +100,14 @@ onInvokeTask( parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task, - applyThis: any, applyArgs: any[]): any { + applyThis?: any, applyArgs?: any[]): any { const source = task.source; let scope = WtfZoneSpec.invokeTaskScope[source]; if (!scope) { scope = WtfZoneSpec.invokeTaskScope[source] = - wtfEvents.createScope(`Zone:invokeTask:${source}(ascii zone)`); + wtfEvents!.createScope(`Zone:invokeTask:${source}(ascii zone)`); } - return wtfTrace.leaveScope( + return wtfTrace!.leaveScope( scope(zonePathName(targetZone)), parentZoneDelegate.invokeTask(targetZone, task, applyThis, applyArgs)); } @@ -117,7 +118,7 @@ let instance = WtfZoneSpec.cancelInstance[key]; if (!instance) { instance = WtfZoneSpec.cancelInstance[key] = - wtfEvents.createInstance(`Zone:cancel:${key}(ascii zone, any options)`); + wtfEvents!.createInstance(`Zone:cancel:${key}(ascii zone, any options)`); } const retValue = parentZoneDelegate.cancelTask(targetZone, task); instance(zonePathName(targetZone), shallowObj(task.data, 2)); @@ -125,8 +126,8 @@ } } - function shallowObj(obj: {[k: string]: any}, depth: number): any { - if (!depth) return null; + function shallowObj(obj: {[k: string]: any}|undefined, depth: number): any { + if (!obj || !depth) return null; const out: {[k: string]: any} = {}; for (const key in obj) { if (obj.hasOwnProperty(key)) { @@ -148,10 +149,10 @@ function zonePathName(zone: Zone) { let name: string = zone.name; - zone = zone.parent; - while (zone != null) { - name = zone.name + '::' + name; - zone = zone.parent; + let localZone = zone.parent; + while (localZone != null) { + name = localZone.name + '::' + name; + localZone = localZone.parent; } return name; } diff --git a/lib/zone.ts b/lib/zone.ts index 9cbd04fdc..c8dc24f4b 100644 --- a/lib/zone.ts +++ b/lib/zone.ts @@ -138,7 +138,7 @@ interface Zone { * * @returns {Zone} The parent Zone. */ - parent: Zone; + parent: Zone|null; /** * @returns {string} The Zone name (useful for debugging) */ @@ -162,7 +162,7 @@ interface Zone { * @param key The key to use for identification of the returned zone. * @returns {Zone} The Zone which defines the `key`, `null` if not found. */ - getZoneWith(key: string): Zone; + getZoneWith(key: string): Zone|null; /** * Used to create a child zone. * @@ -243,8 +243,8 @@ interface Zone { * @param customCancel */ scheduleMacroTask( - source: string, callback: Function, data: TaskData, customSchedule: (task: Task) => void, - customCancel: (task: Task) => void): MacroTask; + source: string, callback: Function, data?: TaskData, customSchedule?: (task: Task) => void, + customCancel?: (task: Task) => void): MacroTask; /** * Schedule an EventTask. @@ -256,8 +256,8 @@ interface Zone { * @param customCancel */ scheduleEventTask( - source: string, callback: Function, data: TaskData, customSchedule: (task: Task) => void, - customCancel: (task: Task) => void): EventTask; + source: string, callback: Function, data?: TaskData, customSchedule?: (task: Task) => void, + customCancel?: (task: Task) => void): EventTask; /** * Schedule an existing Task. @@ -290,7 +290,7 @@ interface ZoneType { /** * @returns {Task} The task associated with the current execution. */ - currentTask: Task; + currentTask: Task|null; /** * Verify that Zone has been correctly patched. Specifically that Promise is zone aware. @@ -321,18 +321,18 @@ interface _ZonePrivate { microtaskDrainDone: () => void; showUncaughtError: () => boolean; patchEventTarget: (global: any, apis: any[], options?: any) => boolean[]; - patchOnProperties: (obj: any, properties: string[]) => void; + patchOnProperties: (obj: any, properties: string[]|null) => void; setNativePromise: (nativePromise: any) => void; patchMethod: (target: any, name: string, patchFn: (delegate: Function, delegateName: string, name: string) => - (self: any, args: any[]) => any) => Function; + (self: any, args: any[]) => any) => Function | null; bindArguments: (args: any[], source: string) => any[]; } /** @internal */ interface _ZoneFrame { - parent: _ZoneFrame; + parent: _ZoneFrame|null; zone: Zone; } @@ -399,7 +399,7 @@ interface ZoneSpec { */ onInvoke?: (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, delegate: Function, - applyThis: any, applyArgs: any[], source: string) => any; + applyThis: any, applyArgs?: any[], source?: string) => any; /** * Allows interception of the error handling. @@ -426,7 +426,7 @@ interface ZoneSpec { onInvokeTask?: (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task, - applyThis: any, applyArgs: any) => any; + applyThis: any, applyArgs?: any[]) => any; /** * Allows interception of task cancellation. @@ -488,11 +488,11 @@ interface ZoneDelegate { zone: Zone; fork(targetZone: Zone, zoneSpec: ZoneSpec): Zone; intercept(targetZone: Zone, callback: Function, source: string): Function; - invoke(targetZone: Zone, callback: Function, applyThis: any, applyArgs: any[], source: string): + invoke(targetZone: Zone, callback: Function, applyThis?: any, applyArgs?: any[], source?: string): any; handleError(targetZone: Zone, error: any): boolean; scheduleTask(targetZone: Zone, task: Task): Task; - invokeTask(targetZone: Zone, task: Task, applyThis: any, applyArgs: any): any; + invokeTask(targetZone: Zone, task: Task, applyThis?: any, applyArgs?: any[]): any; cancelTask(targetZone: Zone, task: Task): any; hasTask(targetZone: Zone, isEmpty: HasTaskState): void; } @@ -579,14 +579,14 @@ interface Task { /** * Task specific options associated with the current task. This is passed to the `scheduleFn`. */ - data: TaskData; + data?: TaskData; /** * Represents the default work which needs to be done to schedule the Task by the VM. * * A zone may choose to intercept this function and perform its own scheduling. */ - scheduleFn: (task: Task) => void; + scheduleFn?: (task: Task) => void; /** * Represents the default work which needs to be done to un-schedule the Task from the VM. Not all @@ -594,7 +594,7 @@ interface Task { * * A zone may chose to intercept this function and perform its own un-scheduling. */ - cancelFn: (task: Task) => void; + cancelFn?: (task: Task) => void; /** * @type {Zone} The zone which will be used to invoke the `callback`. The Zone is captured @@ -633,8 +633,6 @@ type AmbientZone = Zone; type AmbientZoneDelegate = ZoneDelegate; const Zone: ZoneType = (function(global: any) { - const FUNCTION = 'function'; - const performance: {mark(name: string): void; measure(name: string, label: string): void;} = global['performance']; function mark(name: string) { @@ -674,7 +672,7 @@ const Zone: ZoneType = (function(global: any) { return _currentZoneFrame.zone; } - static get currentTask(): Task { + static get currentTask(): Task|null { return _currentTask; } @@ -689,7 +687,7 @@ const Zone: ZoneType = (function(global: any) { } } - public get parent(): AmbientZone { + public get parent(): AmbientZone|null { return this._parent; } @@ -698,12 +696,12 @@ const Zone: ZoneType = (function(global: any) { } - private _parent: Zone; + private _parent: Zone|null; private _name: string; - private _properties: {[key: string]: any} = null; + private _properties: {[key: string]: any}; private _zoneDelegate: ZoneDelegate; - constructor(parent: Zone, zoneSpec: ZoneSpec) { + constructor(parent: Zone|null, zoneSpec: ZoneSpec|null) { this._parent = parent; this._name = zoneSpec ? zoneSpec.name || 'unnamed' : ''; this._properties = zoneSpec && zoneSpec.properties || {}; @@ -716,8 +714,8 @@ const Zone: ZoneType = (function(global: any) { if (zone) return zone._properties[key]; } - public getZoneWith(key: string): AmbientZone { - let current: Zone = this; + public getZoneWith(key: string): AmbientZone|null { + let current: Zone|null = this; while (current) { if (current._properties.hasOwnProperty(key)) { return current; @@ -733,32 +731,31 @@ const Zone: ZoneType = (function(global: any) { } public wrap(callback: T, source: string): T { - if (typeof callback !== FUNCTION) { + if (typeof callback !== 'function') { throw new Error('Expecting function got: ' + callback); } const _callback = this._zoneDelegate.intercept(this, callback, source); const zone: Zone = this; return function() { - return zone.runGuarded(_callback, this, arguments, source); + return zone.runGuarded(_callback, (this as any), arguments, source); } as any as T; } public run(callback: Function, applyThis?: any, applyArgs?: any[], source?: string): any; public run( - callback: (...args: any[]) => T, applyThis: any = undefined, applyArgs: any[] = null, - source: string = null): T { + callback: (...args: any[]) => T, applyThis?: any, applyArgs?: any[], source?: string): T { _currentZoneFrame = {parent: _currentZoneFrame, zone: this}; try { return this._zoneDelegate.invoke(this, callback, applyThis, applyArgs, source); } finally { - _currentZoneFrame = _currentZoneFrame.parent; + _currentZoneFrame = _currentZoneFrame.parent!; } } public runGuarded(callback: Function, applyThis?: any, applyArgs?: any[], source?: string): any; public runGuarded( - callback: (...args: any[]) => T, applyThis: any = null, applyArgs: any[] = null, - source: string = null) { + callback: (...args: any[]) => T, applyThis: any = null, applyArgs?: any[], + source?: string) { _currentZoneFrame = {parent: _currentZoneFrame, zone: this}; try { try { @@ -769,7 +766,7 @@ const Zone: ZoneType = (function(global: any) { } } } finally { - _currentZoneFrame = _currentZoneFrame.parent; + _currentZoneFrame = _currentZoneFrame.parent!; } } @@ -784,10 +781,7 @@ const Zone: ZoneType = (function(global: any) { // will run in notScheduled(canceled) state, we should not try to // run such kind of task but just return - // we have to define an variable here, if not - // typescript compiler will complain below - const isNotScheduled = task.state === notScheduled; - if (isNotScheduled && task.type === eventTask) { + if (task.state === notScheduled && task.type === eventTask) { return; } @@ -799,7 +793,7 @@ const Zone: ZoneType = (function(global: any) { _currentZoneFrame = {parent: _currentZoneFrame, zone: this}; try { if (task.type == macroTask && task.data && !task.data.isPeriodic) { - task.cancelFn = null; + task.cancelFn = undefined; } try { return this._zoneDelegate.invokeTask(this, task, applyThis, applyArgs); @@ -821,7 +815,7 @@ const Zone: ZoneType = (function(global: any) { (task as ZoneTask)._transitionTo(notScheduled, running, notScheduled); } } - _currentZoneFrame = _currentZoneFrame.parent; + _currentZoneFrame = _currentZoneFrame.parent!; _currentTask = previousTask; } } @@ -867,19 +861,19 @@ const Zone: ZoneType = (function(global: any) { source: string, callback: Function, data?: TaskData, customSchedule?: (task: Task) => void): MicroTask { return this.scheduleTask( - new ZoneTask(microTask, source, callback, data, customSchedule, null)); + new ZoneTask(microTask, source, callback, data, customSchedule, undefined)); } scheduleMacroTask( - source: string, callback: Function, data: TaskData, customSchedule: (task: Task) => void, - customCancel: (task: Task) => void): MacroTask { + source: string, callback: Function, data?: TaskData, customSchedule?: (task: Task) => void, + customCancel?: (task: Task) => void): MacroTask { return this.scheduleTask( new ZoneTask(macroTask, source, callback, data, customSchedule, customCancel)); } scheduleEventTask( - source: string, callback: Function, data: TaskData, customSchedule: (task: Task) => void, - customCancel: (task: Task) => void): EventTask { + source: string, callback: Function, data?: TaskData, customSchedule?: (task: Task) => void, + customCancel?: (task: Task) => void): EventTask { return this.scheduleTask( new ZoneTask(eventTask, source, callback, data, customSchedule, customCancel)); } @@ -905,7 +899,7 @@ const Zone: ZoneType = (function(global: any) { } private _updateTaskCount(task: ZoneTask, count: number) { - const zoneDelegates = task._zoneDelegates; + const zoneDelegates = task._zoneDelegates!; if (count == -1) { task._zoneDelegates = null; } @@ -917,14 +911,15 @@ const Zone: ZoneType = (function(global: any) { const DELEGATE_ZS: ZoneSpec = { name: '', - onHasTask: (delegate: ZoneDelegate, _: Zone, target: Zone, hasTaskState: HasTaskState): void => - delegate.hasTask(target, hasTaskState), - onScheduleTask: (delegate: ZoneDelegate, _: Zone, target: Zone, task: Task): Task => - delegate.scheduleTask(target, task), - onInvokeTask: (delegate: ZoneDelegate, _: Zone, target: Zone, task: Task, applyThis: any, - applyArgs: any): any => delegate.invokeTask(target, task, applyThis, applyArgs), - onCancelTask: (delegate: ZoneDelegate, _: Zone, target: Zone, task: Task): any => - delegate.cancelTask(target, task) + onHasTask: (delegate: AmbientZoneDelegate, _: AmbientZone, target: AmbientZone, + hasTaskState: HasTaskState): void => delegate.hasTask(target, hasTaskState), + onScheduleTask: (delegate: AmbientZoneDelegate, _: AmbientZone, target: AmbientZone, + task: Task): Task => delegate.scheduleTask(target, task), + onInvokeTask: (delegate: AmbientZoneDelegate, _: AmbientZone, target: AmbientZone, task: Task, + applyThis: any, applyArgs: any): any => + delegate.invokeTask(target, task, applyThis, applyArgs), + onCancelTask: (delegate: AmbientZoneDelegate, _: AmbientZone, target: AmbientZone, task: Task): + any => delegate.cancelTask(target, task) }; class ZoneDelegate implements AmbientZoneDelegate { @@ -934,88 +929,88 @@ const Zone: ZoneType = (function(global: any) { macroTask: number, eventTask: number} = {'microTask': 0, 'macroTask': 0, 'eventTask': 0}; - private _parentDelegate: ZoneDelegate; + private _parentDelegate: ZoneDelegate|null; - private _forkDlgt: ZoneDelegate; - private _forkZS: ZoneSpec; - private _forkCurrZone: Zone; + private _forkDlgt: ZoneDelegate|null; + private _forkZS: ZoneSpec|null; + private _forkCurrZone: Zone|null; - private _interceptDlgt: ZoneDelegate; - private _interceptZS: ZoneSpec; - private _interceptCurrZone: Zone; + private _interceptDlgt: ZoneDelegate|null; + private _interceptZS: ZoneSpec|null; + private _interceptCurrZone: Zone|null; - private _invokeDlgt: ZoneDelegate; - private _invokeZS: ZoneSpec; - private _invokeCurrZone: Zone; + private _invokeDlgt: ZoneDelegate|null; + private _invokeZS: ZoneSpec|null; + private _invokeCurrZone: Zone|null; - private _handleErrorDlgt: ZoneDelegate; - private _handleErrorZS: ZoneSpec; - private _handleErrorCurrZone: Zone; + private _handleErrorDlgt: ZoneDelegate|null; + private _handleErrorZS: ZoneSpec|null; + private _handleErrorCurrZone: Zone|null; - private _scheduleTaskDlgt: ZoneDelegate; - private _scheduleTaskZS: ZoneSpec; - private _scheduleTaskCurrZone: Zone; + private _scheduleTaskDlgt: ZoneDelegate|null; + private _scheduleTaskZS: ZoneSpec|null; + private _scheduleTaskCurrZone: Zone|null; - private _invokeTaskDlgt: ZoneDelegate; - private _invokeTaskZS: ZoneSpec; - private _invokeTaskCurrZone: Zone; + private _invokeTaskDlgt: ZoneDelegate|null; + private _invokeTaskZS: ZoneSpec|null; + private _invokeTaskCurrZone: Zone|null; - private _cancelTaskDlgt: ZoneDelegate; - private _cancelTaskZS: ZoneSpec; - private _cancelTaskCurrZone: Zone; + private _cancelTaskDlgt: ZoneDelegate|null; + private _cancelTaskZS: ZoneSpec|null; + private _cancelTaskCurrZone: Zone|null; - private _hasTaskDlgt: ZoneDelegate; - private _hasTaskDlgtOwner: ZoneDelegate; - private _hasTaskZS: ZoneSpec; - private _hasTaskCurrZone: Zone; + private _hasTaskDlgt: ZoneDelegate|null; + private _hasTaskDlgtOwner: ZoneDelegate|null; + private _hasTaskZS: ZoneSpec|null; + private _hasTaskCurrZone: Zone|null; - constructor(zone: Zone, parentDelegate: ZoneDelegate, zoneSpec: ZoneSpec) { + constructor(zone: Zone, parentDelegate: ZoneDelegate|null, zoneSpec: ZoneSpec|null) { this.zone = zone; this._parentDelegate = parentDelegate; - this._forkZS = zoneSpec && (zoneSpec && zoneSpec.onFork ? zoneSpec : parentDelegate._forkZS); - this._forkDlgt = zoneSpec && (zoneSpec.onFork ? parentDelegate : parentDelegate._forkDlgt); - this._forkCurrZone = zoneSpec && (zoneSpec.onFork ? this.zone : parentDelegate.zone); + this._forkZS = zoneSpec && (zoneSpec && zoneSpec.onFork ? zoneSpec : parentDelegate!._forkZS); + this._forkDlgt = zoneSpec && (zoneSpec.onFork ? parentDelegate : parentDelegate!._forkDlgt); + this._forkCurrZone = zoneSpec && (zoneSpec.onFork ? this.zone : parentDelegate!.zone); this._interceptZS = - zoneSpec && (zoneSpec.onIntercept ? zoneSpec : parentDelegate._interceptZS); + zoneSpec && (zoneSpec.onIntercept ? zoneSpec : parentDelegate!._interceptZS); this._interceptDlgt = - zoneSpec && (zoneSpec.onIntercept ? parentDelegate : parentDelegate._interceptDlgt); + zoneSpec && (zoneSpec.onIntercept ? parentDelegate : parentDelegate!._interceptDlgt); this._interceptCurrZone = - zoneSpec && (zoneSpec.onIntercept ? this.zone : parentDelegate.zone); + zoneSpec && (zoneSpec.onIntercept ? this.zone : parentDelegate!.zone); - this._invokeZS = zoneSpec && (zoneSpec.onInvoke ? zoneSpec : parentDelegate._invokeZS); + this._invokeZS = zoneSpec && (zoneSpec.onInvoke ? zoneSpec : parentDelegate!._invokeZS); this._invokeDlgt = - zoneSpec && (zoneSpec.onInvoke ? parentDelegate : parentDelegate._invokeDlgt); - this._invokeCurrZone = zoneSpec && (zoneSpec.onInvoke ? this.zone : parentDelegate.zone); + zoneSpec && (zoneSpec.onInvoke ? parentDelegate! : parentDelegate!._invokeDlgt); + this._invokeCurrZone = zoneSpec && (zoneSpec.onInvoke ? this.zone : parentDelegate!.zone); this._handleErrorZS = - zoneSpec && (zoneSpec.onHandleError ? zoneSpec : parentDelegate._handleErrorZS); + zoneSpec && (zoneSpec.onHandleError ? zoneSpec : parentDelegate!._handleErrorZS); this._handleErrorDlgt = - zoneSpec && (zoneSpec.onHandleError ? parentDelegate : parentDelegate._handleErrorDlgt); + zoneSpec && (zoneSpec.onHandleError ? parentDelegate! : parentDelegate!._handleErrorDlgt); this._handleErrorCurrZone = - zoneSpec && (zoneSpec.onHandleError ? this.zone : parentDelegate.zone); + zoneSpec && (zoneSpec.onHandleError ? this.zone : parentDelegate!.zone); this._scheduleTaskZS = - zoneSpec && (zoneSpec.onScheduleTask ? zoneSpec : parentDelegate._scheduleTaskZS); - this._scheduleTaskDlgt = - zoneSpec && (zoneSpec.onScheduleTask ? parentDelegate : parentDelegate._scheduleTaskDlgt); + zoneSpec && (zoneSpec.onScheduleTask ? zoneSpec : parentDelegate!._scheduleTaskZS); + this._scheduleTaskDlgt = zoneSpec && + (zoneSpec.onScheduleTask ? parentDelegate! : parentDelegate!._scheduleTaskDlgt); this._scheduleTaskCurrZone = - zoneSpec && (zoneSpec.onScheduleTask ? this.zone : parentDelegate.zone); + zoneSpec && (zoneSpec.onScheduleTask ? this.zone : parentDelegate!.zone); this._invokeTaskZS = - zoneSpec && (zoneSpec.onInvokeTask ? zoneSpec : parentDelegate._invokeTaskZS); + zoneSpec && (zoneSpec.onInvokeTask ? zoneSpec : parentDelegate!._invokeTaskZS); this._invokeTaskDlgt = - zoneSpec && (zoneSpec.onInvokeTask ? parentDelegate : parentDelegate._invokeTaskDlgt); + zoneSpec && (zoneSpec.onInvokeTask ? parentDelegate! : parentDelegate!._invokeTaskDlgt); this._invokeTaskCurrZone = - zoneSpec && (zoneSpec.onInvokeTask ? this.zone : parentDelegate.zone); + zoneSpec && (zoneSpec.onInvokeTask ? this.zone : parentDelegate!.zone); this._cancelTaskZS = - zoneSpec && (zoneSpec.onCancelTask ? zoneSpec : parentDelegate._cancelTaskZS); + zoneSpec && (zoneSpec.onCancelTask ? zoneSpec : parentDelegate!._cancelTaskZS); this._cancelTaskDlgt = - zoneSpec && (zoneSpec.onCancelTask ? parentDelegate : parentDelegate._cancelTaskDlgt); + zoneSpec && (zoneSpec.onCancelTask ? parentDelegate! : parentDelegate!._cancelTaskDlgt); this._cancelTaskCurrZone = - zoneSpec && (zoneSpec.onCancelTask ? this.zone : parentDelegate.zone); + zoneSpec && (zoneSpec.onCancelTask ? this.zone : parentDelegate!.zone); this._hasTaskZS = null; this._hasTaskDlgt = null; @@ -1031,49 +1026,50 @@ const Zone: ZoneType = (function(global: any) { this._hasTaskDlgt = parentDelegate; this._hasTaskDlgtOwner = this; this._hasTaskCurrZone = zone; - if (!zoneSpec.onScheduleTask) { + if (!zoneSpec!.onScheduleTask) { this._scheduleTaskZS = DELEGATE_ZS; - this._scheduleTaskDlgt = parentDelegate; + this._scheduleTaskDlgt = parentDelegate!; this._scheduleTaskCurrZone = this.zone; } - if (!zoneSpec.onInvokeTask) { + if (!zoneSpec!.onInvokeTask) { this._invokeTaskZS = DELEGATE_ZS; - this._invokeTaskDlgt = parentDelegate; + this._invokeTaskDlgt = parentDelegate!; this._invokeTaskCurrZone = this.zone; } - if (!zoneSpec.onCancelTask) { + if (!zoneSpec!.onCancelTask) { this._cancelTaskZS = DELEGATE_ZS; - this._cancelTaskDlgt = parentDelegate; + this._cancelTaskDlgt = parentDelegate!; this._cancelTaskCurrZone = this.zone; } } } fork(targetZone: Zone, zoneSpec: ZoneSpec): AmbientZone { - return this._forkZS ? this._forkZS.onFork(this._forkDlgt, this.zone, targetZone, zoneSpec) : + return this._forkZS ? this._forkZS.onFork!(this._forkDlgt!, this.zone, targetZone, zoneSpec) : new Zone(targetZone, zoneSpec); } intercept(targetZone: Zone, callback: Function, source: string): Function { return this._interceptZS ? - this._interceptZS.onIntercept( - this._interceptDlgt, this._interceptCurrZone, targetZone, callback, source) : + this._interceptZS.onIntercept!( + this._interceptDlgt!, this._interceptCurrZone!, targetZone, callback, source) : callback; } - invoke(targetZone: Zone, callback: Function, applyThis: any, applyArgs: any[], source: string): - any { + invoke( + targetZone: Zone, callback: Function, applyThis: any, applyArgs?: any[], + source?: string): any { return this._invokeZS ? - this._invokeZS.onInvoke( - this._invokeDlgt, this._invokeCurrZone, targetZone, callback, applyThis, applyArgs, + this._invokeZS.onInvoke!( + this._invokeDlgt!, this._invokeCurrZone!, targetZone, callback, applyThis, applyArgs, source) : callback.apply(applyThis, applyArgs); } handleError(targetZone: Zone, error: any): boolean { return this._handleErrorZS ? - this._handleErrorZS.onHandleError( - this._handleErrorDlgt, this._handleErrorCurrZone, targetZone, error) : + this._handleErrorZS.onHandleError!( + this._handleErrorDlgt!, this._handleErrorCurrZone!, targetZone, error) : true; } @@ -1081,10 +1077,11 @@ const Zone: ZoneType = (function(global: any) { let returnTask: ZoneTask = task as ZoneTask; if (this._scheduleTaskZS) { if (this._hasTaskZS) { - returnTask._zoneDelegates.push(this._hasTaskDlgtOwner); + returnTask._zoneDelegates!.push(this._hasTaskDlgtOwner!); } - returnTask = this._scheduleTaskZS.onScheduleTask( - this._scheduleTaskDlgt, this._scheduleTaskCurrZone, targetZone, task) as ZoneTask; + returnTask = this._scheduleTaskZS.onScheduleTask!( + this._scheduleTaskDlgt!, this._scheduleTaskCurrZone!, targetZone, + task) as ZoneTask; if (!returnTask) returnTask = task as ZoneTask; } else { if (task.scheduleFn) { @@ -1098,10 +1095,10 @@ const Zone: ZoneType = (function(global: any) { return returnTask; } - invokeTask(targetZone: Zone, task: Task, applyThis: any, applyArgs: any): any { + invokeTask(targetZone: Zone, task: Task, applyThis: any, applyArgs?: any[]): any { return this._invokeTaskZS ? - this._invokeTaskZS.onInvokeTask( - this._invokeTaskDlgt, this._invokeTaskCurrZone, targetZone, task, applyThis, + this._invokeTaskZS.onInvokeTask!( + this._invokeTaskDlgt!, this._invokeTaskCurrZone!, targetZone, task, applyThis, applyArgs) : task.callback.apply(applyThis, applyArgs); } @@ -1109,8 +1106,8 @@ const Zone: ZoneType = (function(global: any) { cancelTask(targetZone: Zone, task: Task): any { let value: any; if (this._cancelTaskZS) { - value = this._cancelTaskZS.onCancelTask( - this._cancelTaskDlgt, this._cancelTaskCurrZone, targetZone, task); + value = this._cancelTaskZS.onCancelTask!( + this._cancelTaskDlgt!, this._cancelTaskCurrZone!, targetZone, task); } else { if (!task.cancelFn) { throw Error('Task is not cancelable'); @@ -1124,9 +1121,9 @@ const Zone: ZoneType = (function(global: any) { // hasTask should not throw error so other ZoneDelegate // can still trigger hasTask callback try { - return this._hasTaskZS && - this._hasTaskZS.onHasTask( - this._hasTaskDlgt, this._hasTaskCurrZone, targetZone, isEmpty); + this._hasTaskZS && + this._hasTaskZS.onHasTask!( + this._hasTaskDlgt!, this._hasTaskCurrZone!, targetZone, isEmpty); } catch (err) { this.handleError(targetZone, err); } @@ -1156,17 +1153,17 @@ const Zone: ZoneType = (function(global: any) { public source: string; public invoke: Function; public callback: Function; - public data: TaskData; - public scheduleFn: (task: Task) => void; - public cancelFn: (task: Task) => void; - _zone: Zone = null; + public data: TaskData|undefined; + public scheduleFn: ((task: Task) => void)|undefined; + public cancelFn: ((task: Task) => void)|undefined; + _zone: Zone|null = null; public runCount: number = 0; - _zoneDelegates: ZoneDelegate[] = null; + _zoneDelegates: ZoneDelegate[]|null = null; _state: TaskState = 'notScheduled'; constructor( - type: T, source: string, callback: Function, options: TaskData, - scheduleFn: (task: Task) => void, cancelFn: (task: Task) => void) { + type: T, source: string, callback: Function, options: TaskData|undefined, + scheduleFn: ((task: Task) => void)|undefined, cancelFn: ((task: Task) => void)|undefined) { this.type = type; this.source = source; this.data = options; @@ -1201,7 +1198,7 @@ const Zone: ZoneType = (function(global: any) { } get zone(): Zone { - return this._zone; + return this._zone!; } get state(): TaskState { @@ -1325,18 +1322,18 @@ const Zone: ZoneType = (function(global: any) { patchEventTarget: () => [], patchOnProperties: noop, patchMethod: () => noop, - bindArguments: () => null, + bindArguments: () => (null as any), setNativePromise: (NativePromise: any) => { // sometimes NativePromise.resolve static function // is not ready yet, (such as core-js/es6.promise) // so we need to check here. - if (NativePromise && typeof NativePromise.resolve === FUNCTION) { + if (NativePromise && typeof NativePromise.resolve === 'function') { nativeMicroTaskQueuePromise = NativePromise.resolve(0); } }, }; let _currentZoneFrame: _ZoneFrame = {parent: null, zone: new Zone(null, null)}; - let _currentTask: Task = null; + let _currentTask: Task|null = null; let _numberOfNestedTaskFrames = 0; function noop() {} diff --git a/test/browser/HTMLImports.spec.ts b/test/browser/HTMLImports.spec.ts index 8fc399936..8d22557dc 100644 --- a/test/browser/HTMLImports.spec.ts +++ b/test/browser/HTMLImports.spec.ts @@ -30,7 +30,7 @@ describe('HTML Imports', ifEnvSupports(supportsImports, function() { }); }); - document.head.appendChild(link); + document.head.appendChild(link!); }); function supportsOnEvents() { @@ -56,7 +56,7 @@ describe('HTML Imports', ifEnvSupports(supportsImports, function() { }; }); - document.head.appendChild(link); + document.head.appendChild(link!); }); it('should work with onload', function(done) { @@ -73,7 +73,7 @@ describe('HTML Imports', ifEnvSupports(supportsImports, function() { }; }); - document.head.appendChild(link); + document.head.appendChild(link!); }); }); diff --git a/test/browser/MutationObserver.spec.ts b/test/browser/MutationObserver.spec.ts index 15b2da37a..e7bf3056b 100644 --- a/test/browser/MutationObserver.spec.ts +++ b/test/browser/MutationObserver.spec.ts @@ -48,7 +48,7 @@ describe('MutationObserver', ifEnvSupports('MutationObserver', function() { ob = new MutationObserver(function() {}); }); - ob.disconnect(); + ob!.disconnect(); expect(flag).toBe(false); }); })); @@ -70,6 +70,6 @@ describe('WebKitMutationObserver', ifEnvSupports('WebKitMutationObserver', funct ob.observe(elt, {childList: true}); }); - elt.innerHTML = '

hey

'; + elt!.innerHTML = '

hey

'; }); })); diff --git a/test/browser/WebSocket.spec.ts b/test/browser/WebSocket.spec.ts index 1ee4b39d8..82c51c321 100644 --- a/test/browser/WebSocket.spec.ts +++ b/test/browser/WebSocket.spec.ts @@ -121,7 +121,7 @@ if (!window['saucelabs']) { log += 'a'; }; - socket.onmessage = null; + socket.onmessage = null as any; socket.send('hi'); diff --git a/test/browser/XMLHttpRequest.spec.ts b/test/browser/XMLHttpRequest.spec.ts index e6f9a705a..49121396a 100644 --- a/test/browser/XMLHttpRequest.spec.ts +++ b/test/browser/XMLHttpRequest.spec.ts @@ -41,7 +41,7 @@ describe('XMLHttpRequest', function() { req.send(); const lastScheduled = wtfMock.log[wtfMock.log.length - 1]; expect(lastScheduled).toMatch('# Zone:schedule:macroTask:XMLHttpRequest.send'); - }, null, null, 'unit-test'); + }, null, undefined, 'unit-test'); }); it('should not trigger Zone callback of internal onreadystatechange', function(done) { @@ -77,14 +77,14 @@ describe('XMLHttpRequest', function() { req = new XMLHttpRequest(); req.onreadystatechange = function() { // Make sure that the wrapCallback will only be called once - req.onreadystatechange = null; + req.onreadystatechange = null as any; expect(Zone.current).toBe(testZone); done(); }; req.open('get', '/', true); }); - req.send(); + req!.send(); }); it('should return null when access ontimeout first time without error', function() { @@ -105,14 +105,14 @@ describe('XMLHttpRequest', function() { req = new XMLHttpRequest(); req.onprogress = function() { // Make sure that the wrapCallback will only be called once - req.onprogress = null; + req.onprogress = null as any; expect(Zone.current).toBe(testZone); done(); }; req.open('get', '/', true); }); - req.send(); + req!.send(); }); it('should allow canceling of an XMLHttpRequest', function(done) { @@ -222,7 +222,7 @@ describe('XMLHttpRequest', function() { req.open('get', '/', true); req.send(); req.onload = function() { - req.onload = null; + req.onload = null as any; req.open('get', '/', true); req.onload = function() { done(); diff --git a/test/browser/browser.spec.ts b/test/browser/browser.spec.ts index 9b013d70c..58899a4a9 100644 --- a/test/browser/browser.spec.ts +++ b/test/browser/browser.spec.ts @@ -47,8 +47,8 @@ try { supportsPassive = true; } }); - window.addEventListener('test', null, opts); - window.removeEventListener('test', null, opts); + window.addEventListener('test', null as any, opts); + window.removeEventListener('test', null as any, opts); } catch (e) { } @@ -89,7 +89,8 @@ describe('Zone', function() { const myZone = Zone.current.fork({ name: 'spy', onInvoke: (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, - callback: Function, applyThis: any, applyArgs: any[], source: string): any => { + callback: Function, applyThis?: any, applyArgs?: any[], + source?: string): any => { if (source) { spies[source].apply(null, applyArgs); } else { @@ -336,11 +337,11 @@ describe('Zone', function() { span.onmousedown = listener1; }); - expect(handler1).toBe(handler2); + expect(handler1!).toBe(handler2!); - handler1.apply(undefined, [{type: 'click', target: span}]); + handler1!.apply(undefined, [{type: 'click', target: span}]); - handler2.apply(undefined, [{type: 'mousedown', target: span}]); + handler2!.apply(undefined, [{type: 'mousedown', target: span}]); expect(hookSpy).toHaveBeenCalled(); expect(logs).toEqual(['listener1', 'listener2']); @@ -1070,7 +1071,7 @@ describe('Zone', function() { }); let listeners = (button as any).eventListeners('click'); expect(listeners.length).toBe(1); - eventTask.zone.cancelTask(eventTask); + eventTask!.zone.cancelTask(eventTask!); listeners = (button as any).eventListeners('click'); button.dispatchEvent(clickEvent); @@ -1098,7 +1099,7 @@ describe('Zone', function() { }); let listeners = (button as any).eventListeners('click'); expect(listeners.length).toBe(1); - eventTask.zone.cancelTask(eventTask); + eventTask!.zone.cancelTask(eventTask!); listeners = (button as any).eventListeners('click'); button.dispatchEvent(clickEvent); @@ -1133,7 +1134,7 @@ describe('Zone', function() { button.dispatchEvent(clickEvent); expect(logs.length).toBe(2); expect(logs).toEqual(['click1', 'click2']); - eventTask.zone.cancelTask(eventTask); + eventTask!.zone.cancelTask(eventTask!); logs = []; listeners = (button as any).eventListeners('click'); @@ -1170,7 +1171,7 @@ describe('Zone', function() { button.dispatchEvent(clickEvent); expect(logs.length).toBe(2); expect(logs).toEqual(['click1', 'click2']); - eventTask.zone.cancelTask(eventTask); + eventTask!.zone.cancelTask(eventTask!); logs = []; listeners = (button as any).eventListeners('click'); @@ -1207,7 +1208,7 @@ describe('Zone', function() { button.dispatchEvent(clickEvent); expect(logs.length).toBe(2); expect(logs).toEqual(['click1', 'click2']); - eventTask.zone.cancelTask(eventTask); + eventTask!.zone.cancelTask(eventTask!); logs = []; listeners = (button as any).eventListeners('click'); @@ -2436,7 +2437,7 @@ describe('Zone', function() { ifEnvSupportsWithDone(supportCanvasTest, (done: Function) => { const canvas = document.createElement('canvas'); const d = canvas.width; - const ctx = canvas.getContext('2d'); + const ctx = canvas.getContext('2d')!; ctx.beginPath(); ctx.moveTo(d / 2, 0); ctx.lineTo(d, d); @@ -2462,7 +2463,7 @@ describe('Zone', function() { expect(scheduleSpy).toHaveBeenCalled(); const reader = new FileReader(); - reader.readAsDataURL(blob); + reader.readAsDataURL(blob!); reader.onloadend = function() { const base64data = reader.result; expect(base64data).toEqual(canvasData); @@ -2472,61 +2473,59 @@ describe('Zone', function() { }); })); - describe('ResizeObserver', ifEnvSupports('ResizeObserver', () => { - it('ResizeObserver callback should be in zone', (done) => { - const ResizeObserver = (window as any)['ResizeObserver']; - const div = document.createElement('div'); - const zone = Zone.current.fork({ - name: 'observer' - }); - const observer = new ResizeObserver((entries: any, ob: any) => { - expect(Zone.current.name).toEqual(zone.name); - - expect(entries.length).toBe(1); - expect(entries[0].target).toBe(div); - done(); - }); - - zone.run(() => { - observer.observe(div); - }); + describe( + 'ResizeObserver', ifEnvSupports('ResizeObserver', () => { + it('ResizeObserver callback should be in zone', (done) => { + const ResizeObserver = (window as any)['ResizeObserver']; + const div = document.createElement('div'); + const zone = Zone.current.fork({name: 'observer'}); + const observer = new ResizeObserver((entries: any, ob: any) => { + expect(Zone.current.name).toEqual(zone.name); - document.body.appendChild(div); - }); + expect(entries.length).toBe(1); + expect(entries[0].target).toBe(div); + done(); + }); - it('ResizeObserver callback should be able to in different zones which when they were observed', (done) => { - const ResizeObserver = (window as any)['ResizeObserver']; - const div1 = document.createElement('div'); - const div2 = document.createElement('div'); - const zone = Zone.current.fork({ - name: 'observer' - }); - let count = 0; - const observer = new ResizeObserver((entries: any, ob: any) => { - entries.forEach((entry: any) => { - if (entry.target === div1) { - expect(Zone.current.name).toEqual(zone.name); - } else { - expect(Zone.current.name).toEqual(''); - } + zone.run(() => { + observer.observe(div); }); - count ++; - if (count === 2) { - done(); - } - }); - zone.run(() => { - observer.observe(div1); - }); - Zone.root.run(() => { - observer.observe(div2); + document.body.appendChild(div); }); - document.body.appendChild(div1); - document.body.appendChild(div2); - }); - })); + it('ResizeObserver callback should be able to in different zones which when they were observed', + (done) => { + const ResizeObserver = (window as any)['ResizeObserver']; + const div1 = document.createElement('div'); + const div2 = document.createElement('div'); + const zone = Zone.current.fork({name: 'observer'}); + let count = 0; + const observer = new ResizeObserver((entries: any, ob: any) => { + entries.forEach((entry: any) => { + if (entry.target === div1) { + expect(Zone.current.name).toEqual(zone.name); + } else { + expect(Zone.current.name).toEqual(''); + } + }); + count++; + if (count === 2) { + done(); + } + }); + + zone.run(() => { + observer.observe(div1); + }); + Zone.root.run(() => { + observer.observe(div2); + }); + + document.body.appendChild(div1); + document.body.appendChild(div2); + }); + })); xdescribe('getUserMedia', () => { it('navigator.mediaDevices.getUserMedia should in zone', diff --git a/test/browser/element.spec.ts b/test/browser/element.spec.ts index 4b7e50d1b..ad9a34adc 100644 --- a/test/browser/element.spec.ts +++ b/test/browser/element.spec.ts @@ -161,8 +161,8 @@ describe('element', function() { Zone.current.fork({name: 'eventListenerZone', onScheduleTask: onAddEventListenerSpy}); expect(function() { eventListenerZone.run(function() { - button.addEventListener('click', null); - button.addEventListener('click', undefined); + button.addEventListener('click', null as any); + button.addEventListener('click', undefined as any); }); }).not.toThrowError(); expect(onAddEventListenerSpy).not.toHaveBeenCalledWith(); @@ -174,8 +174,8 @@ describe('element', function() { Zone.current.fork({name: 'eventListenerZone', onScheduleTask: onAddEventListenerSpy}); expect(function() { eventListenerZone.run(function() { - button.removeEventListener('click', null); - button.removeEventListener('click', undefined); + button.removeEventListener('click', null as any); + button.removeEventListener('click', undefined as any); }); }).not.toThrowError(); expect(onAddEventListenerSpy).not.toHaveBeenCalledWith(); @@ -294,7 +294,7 @@ describe('element', function() { button.onclick = function() { log += 'a'; }; - button.onclick = null; + button.onclick = null as any; button.click(); expect(log).toEqual(''); diff --git a/test/closure/zone.closure.ts b/test/closure/zone.closure.ts index b065efde1..facfc4719 100644 --- a/test/closure/zone.closure.ts +++ b/test/closure/zone.closure.ts @@ -18,13 +18,13 @@ const testClosureFunction = () => { }, onIntercept: (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, - delegate: Function, source?: string) => { + delegate: Function, source: string) => { return parentZoneDelegate.intercept(targetZone, delegate, source); }, onInvoke: function( parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, delegate: Function, - applyThis: any, applyArgs: any[], source: string) { + applyThis?: any, applyArgs?: any[], source?: string) { return parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source); }, @@ -40,7 +40,7 @@ const testClosureFunction = () => { onInvokeTask: function( parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task, - applyThis: any, applyArgs: any[]) { + applyThis?: any, applyArgs?: any[]) { return parentZoneDelegate.invokeTask(targetZone, task, applyThis, applyArgs); }, @@ -59,13 +59,13 @@ const testClosureFunction = () => { testZone.runGuarded(() => { testZone.run(() => { const properties = testZoneSpec.properties; - properties['key'] = 'value'; + properties!['key'] = 'value'; const keyZone = Zone.current.getZoneWith('key'); logs.push('current' + Zone.current.name); - logs.push('parent' + Zone.current.parent.name); - logs.push('getZoneWith' + keyZone.name); - logs.push('get' + keyZone.get('key')); + logs.push('parent' + Zone.current.parent!.name); + logs.push('getZoneWith' + keyZone!.name); + logs.push('get' + keyZone!.get('key')); logs.push('root' + Zone.root.name); Object.keys((Zone as any).prototype).forEach(key => { logs.push(key); @@ -74,7 +74,7 @@ const testClosureFunction = () => { logs.push(key); }); - const task = Zone.current.scheduleMicroTask('testTask', () => {}, null, () => {}); + const task = Zone.current.scheduleMicroTask('testTask', () => {}, undefined, () => {}); Object.keys(task).forEach(key => { logs.push(key); }); diff --git a/test/common/Error.spec.ts b/test/common/Error.spec.ts index 1f4727b8d..9a9812439 100644 --- a/test/common/Error.spec.ts +++ b/test/common/Error.spec.ts @@ -175,8 +175,8 @@ describe('ZoneAwareError', () => { // there event without throw const error = new Error('test'); const errorWithoutNew = Error('test'); - expect(error.stack.split('\n').length > 0).toBeTruthy(); - expect(errorWithoutNew.stack.split('\n').length > 0).toBeTruthy(); + expect(error.stack!.split('\n').length > 0).toBeTruthy(); + expect(errorWithoutNew.stack!.split('\n').length > 0).toBeTruthy(); }); it('should show zone names in stack frames and remove extra frames', () => { @@ -214,14 +214,14 @@ describe('ZoneAwareError', () => { expect(outside.stack).toEqual(outside.zoneAwareStack); expect(outsideWithoutNew.stack).toEqual(outsideWithoutNew.zoneAwareStack); - expect(inside.stack).toEqual(inside.zoneAwareStack); - expect(insideWithoutNew.stack).toEqual(insideWithoutNew.zoneAwareStack); - expect(typeof inside.originalStack).toEqual('string'); - expect(typeof insideWithoutNew.originalStack).toEqual('string'); - const outsideFrames = outside.stack.split(/\n/); - const insideFrames = inside.stack.split(/\n/); - const outsideWithoutNewFrames = outsideWithoutNew.stack.split(/\n/); - const insideWithoutNewFrames = insideWithoutNew.stack.split(/\n/); + expect(inside!.stack).toEqual(inside!.zoneAwareStack); + expect(insideWithoutNew!.stack).toEqual(insideWithoutNew!.zoneAwareStack); + expect(typeof inside!.originalStack).toEqual('string'); + expect(typeof insideWithoutNew!.originalStack).toEqual('string'); + const outsideFrames = outside.stack!.split(/\n/); + const insideFrames = inside!.stack!.split(/\n/); + const outsideWithoutNewFrames = outsideWithoutNew!.stack!.split(/\n/); + const insideWithoutNewFrames = insideWithoutNew!.stack!.split(/\n/); // throw away first line if it contains the error if (/Outside/.test(outsideFrames[0])) { @@ -271,7 +271,7 @@ describe('ZoneAwareError', () => { ]; function assertStackDoesNotContainZoneFrames(err: Error) { - const frames = err.stack.split('\n'); + const frames = err.stack!.split('\n'); for (let i = 0; i < frames.length; i++) { expect(zoneAwareFrames.filter(f => frames[i].indexOf(f) !== -1)).toEqual([]); } @@ -279,7 +279,7 @@ describe('ZoneAwareError', () => { const errorZoneSpec = { name: 'errorZone', - done: <() => void>null, + done: <(() => void)|null>null, onHandleError: (parentDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, error: Error) => { assertStackDoesNotContainZoneFrames(error); @@ -340,7 +340,7 @@ describe('ZoneAwareError', () => { assertStackDoesNotContainZoneFramesTest(() => { const task = Zone.current.scheduleEventTask('errorEvent', () => { throw new Error('test error'); - }, null, () => null, null); + }, undefined, () => null, undefined); task.invoke(); })); @@ -348,7 +348,7 @@ describe('ZoneAwareError', () => { assertStackDoesNotContainZoneFramesTest(() => { const task = Zone.current.scheduleEventTask('errorEvent', () => { throw Error('test error'); - }, null, () => null, null); + }, undefined, () => null, undefined); task.invoke(); })); @@ -357,7 +357,7 @@ describe('ZoneAwareError', () => { const task = Zone.current.fork((Zone as any)['longStackTraceZoneSpec']) .scheduleEventTask('errorEvent', () => { throw new Error('test error'); - }, null, () => null, null); + }, undefined, () => null, undefined); task.invoke(); })); @@ -366,7 +366,7 @@ describe('ZoneAwareError', () => { const task = Zone.current.fork((Zone as any)['longStackTraceZoneSpec']) .scheduleEventTask('errorEvent', () => { throw Error('test error'); - }, null, () => null, null); + }, undefined, () => null, undefined); task.invoke(); })); @@ -388,7 +388,7 @@ describe('ZoneAwareError', () => { }) .scheduleEventTask('errorEvent', () => { throw new Error('test error'); - }, null, () => null, null); + }, undefined, () => null, undefined); task.invoke(); })); @@ -398,9 +398,9 @@ describe('ZoneAwareError', () => { const NativeError = _global['__zone_symbol__Error']; const desc = Object.getOwnPropertyDescriptor(NativeError.prototype, 'stack'); if (desc) { - const originalSet: (value: any) => void = desc.set; + const originalSet: ((value: any) => void)|undefined = desc.set; // make stack readonly - desc.set = null; + desc.set = null as any; try { const error = new Error('test error'); diff --git a/test/common/Promise.spec.ts b/test/common/Promise.spec.ts index d6a803b72..90f69be6a 100644 --- a/test/common/Promise.spec.ts +++ b/test/common/Promise.spec.ts @@ -19,13 +19,12 @@ class MicroTaskQueueZoneSpec implements ZoneSpec { flush() { while (this.queue.length) { const task = this.queue.shift(); - task.invoke(); + task!.invoke(); } } - onScheduleTask(delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: MicroTask): - any { - this.queue.push(task); + onScheduleTask(delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task): any { + this.queue.push(task as MicroTask); } } @@ -34,8 +33,8 @@ function flushMicrotasks() { } class TestRejection { - prop1: string; - prop2: string; + prop1?: string; + prop2?: string; } describe( @@ -52,7 +51,7 @@ describe( pZone = Zone.current.fork({ name: 'promise-zone', onScheduleTask: (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, - task: MicroTask): any => { + task: Task): any => { log.push('scheduleTask'); parentZoneDelegate.scheduleTask(targetZone, task); } @@ -185,7 +184,7 @@ describe( describe('Promise API', function() { it('should work with .then', function(done) { - let resolve: Function = null; + let resolve: Function|null = null; testZone.run(function() { new Promise(function(resolveFn) { @@ -196,11 +195,11 @@ describe( }); }); - resolve(); + resolve!(); }); it('should work with .catch', function(done) { - let reject: () => void = null; + let reject: (() => void)|null = null; testZone.run(function() { new Promise(function(resolveFn, rejectFn) { @@ -212,11 +211,11 @@ describe( }); - expect(reject()).toBe(undefined); + expect(reject!()).toBe(undefined); }); it('should work with .finally with resolved promise', function(done) { - let resolve: Function = null; + let resolve: Function|null = null; testZone.run(function() { new Promise(function(resolveFn) { @@ -228,11 +227,11 @@ describe( }); }); - resolve('value'); + resolve!('value'); }); it('should work with .finally with rejected promise', function(done) { - let reject: Function = null; + let reject: Function|null = null; testZone.run(function() { new Promise(function(_, rejectFn) { @@ -244,7 +243,7 @@ describe( }); }); - reject('error'); + reject!('error'); }); it('should work with Promise.resolve', () => { @@ -344,10 +343,10 @@ describe( }); it('should notify Zone.onHandleError if no one catches promise', (done) => { - let promiseError: Error = null; - let zone: Zone = null; - let task: Task = null; - let error: Error = null; + let promiseError: Error|null = null; + let zone: Zone|null = null; + let task: Task|null = null; + let error: Error|null = null; queueZone .fork({ name: 'promise-error', @@ -370,11 +369,12 @@ describe( Promise.reject(error); expect(promiseError).toBe(null); }); - setTimeout((): void => null); + setTimeout((): any => null); setTimeout(() => { - expect(promiseError.message) + expect(promiseError!.message) .toBe( - 'Uncaught (in promise): ' + error + (error.stack ? '\n' + error.stack : '')); + 'Uncaught (in promise): ' + error + + (error!.stack ? '\n' + error!.stack : '')); expect((promiseError as any)['rejection']).toBe(error); expect((promiseError as any)['zone']).toBe(zone); expect((promiseError as any)['task']).toBe(task); @@ -383,9 +383,9 @@ describe( }); it('should print readable information when throw a not error object', (done) => { - let promiseError: Error = null; - let zone: Zone = null; - let task: Task = null; + let promiseError: Error|null = null; + let zone: Zone|null = null; + let task: Task|null = null; let rejectObj: TestRejection; queueZone .fork({ @@ -406,9 +406,9 @@ describe( Promise.reject(rejectObj); expect(promiseError).toBe(null); }); - setTimeout((): void => null); + setTimeout((): any => null); setTimeout(() => { - expect(promiseError.message) + expect(promiseError!.message) .toMatch(/Uncaught \(in promise\):.*: {"prop1":"value1","prop2":"value2"}/); done(); }); @@ -540,7 +540,7 @@ describe( expect(result).toBe('foo'); done && done(); }); - } + } it('should resolve if the Promise subclass resolves', jasmine ? function(done) { testPromiseSubClass(done); diff --git a/test/common/microtasks.spec.ts b/test/common/microtasks.spec.ts index 87f512012..332b27b06 100644 --- a/test/common/microtasks.spec.ts +++ b/test/common/microtasks.spec.ts @@ -16,9 +16,9 @@ describe('Microtasks', function() { it('should execute microtasks enqueued in the root zone', function(done) { const log: number[] = []; - Zone.current.scheduleMicroTask('test', () => log.push(1), null, scheduleFn); - Zone.current.scheduleMicroTask('test', () => log.push(2), null, scheduleFn); - Zone.current.scheduleMicroTask('test', () => log.push(3), null, scheduleFn); + Zone.current.scheduleMicroTask('test', () => log.push(1), undefined, scheduleFn); + Zone.current.scheduleMicroTask('test', () => log.push(2), undefined, scheduleFn); + Zone.current.scheduleMicroTask('test', () => log.push(3), undefined, scheduleFn); setTimeout(function() { expect(log).toEqual([1, 2, 3]); @@ -29,11 +29,11 @@ describe('Microtasks', function() { it('should correctly scheduleMacroTask microtasks vs macrotasks', function(done) { const log = ['+root']; - Zone.current.scheduleMicroTask('test', () => log.push('root.mit'), null, scheduleFn); + Zone.current.scheduleMicroTask('test', () => log.push('root.mit'), undefined, scheduleFn); setTimeout(function() { log.push('+mat1'); - Zone.current.scheduleMicroTask('test', () => log.push('mat1.mit'), null, scheduleFn); + Zone.current.scheduleMicroTask('test', () => log.push('mat1.mit'), undefined, scheduleFn); log.push('-mat1'); }, 10); diff --git a/test/common/setInterval.spec.ts b/test/common/setInterval.spec.ts index 42aaac7b0..fc41c306f 100644 --- a/test/common/setInterval.spec.ts +++ b/test/common/setInterval.spec.ts @@ -57,7 +57,7 @@ describe('setInterval', function() { expect(wtfMock.log[1]).toEqual('> Zone:invoke:unit-test("::ProxyZone::WTF::TestZone")'); expect(wtfMock.log[2]) .toContain('# Zone:schedule:macroTask:setInterval("::ProxyZone::WTF::TestZone"'); - }, null, null, 'unit-test'); + }, null, undefined, 'unit-test'); }); it('should not cancel the task after invoke the setInterval callback', (done) => { diff --git a/test/common/setTimeout.spec.ts b/test/common/setTimeout.spec.ts index c71ab4d5f..0b868836d 100644 --- a/test/common/setTimeout.spec.ts +++ b/test/common/setTimeout.spec.ts @@ -39,7 +39,7 @@ describe('setTimeout', function() { expect(wtfMock.log[1]).toEqual('> Zone:invoke:unit-test("::ProxyZone::WTF::TestZone")'); expect(wtfMock.log[2]) .toContain('# Zone:schedule:macroTask:setTimeout("::ProxyZone::WTF::TestZone"'); - }, null, null, 'unit-test'); + }, null, undefined, 'unit-test'); }); it('should allow canceling of fns registered with setTimeout', function(done) { @@ -116,7 +116,7 @@ describe('setTimeout', function() { }); it('should pass invalid values through', function() { - clearTimeout(null); + clearTimeout(null as any); clearTimeout({}); }); diff --git a/test/common/task.spec.ts b/test/common/task.spec.ts index da1286244..6cac1f41c 100644 --- a/test/common/task.spec.ts +++ b/test/common/task.spec.ts @@ -9,7 +9,7 @@ const noop = function() {}; let log: {zone: string, taskZone: undefined | string, toState: TaskState, fromState: TaskState}[] = []; -const detectTask = Zone.current.scheduleMacroTask('detectTask', noop, null, noop, noop); +const detectTask = Zone.current.scheduleMacroTask('detectTask', noop, undefined, noop, noop); const originalTransitionTo = detectTask.constructor.prototype._transitionTo; // patch _transitionTo of ZoneTask to add log for test const logTransitionTo: Function = function( @@ -40,7 +40,7 @@ describe('task lifecycle', () => { it('task should transit from notScheduled to scheduling then to scheduled state when scheduleTask', testFnWithLoggedTransitionTo(() => { Zone.current.fork({name: 'testEventTaskZone'}).run(() => { - Zone.current.scheduleEventTask('testEventTask', noop, null, noop, noop); + Zone.current.scheduleEventTask('testEventTask', noop, undefined, noop, noop); }); expect(log.map(item => { return {toState: item.toState, fromState: item.fromState}; @@ -62,7 +62,7 @@ describe('task lifecycle', () => { }) .run(() => { try { - Zone.current.scheduleEventTask('testEventTask', noop, null, noop, noop); + Zone.current.scheduleEventTask('testEventTask', noop, undefined, noop, noop); } catch (err) { } }); @@ -78,7 +78,8 @@ describe('task lifecycle', () => { it('task should transit from scheduled to running when task is invoked then from running to scheduled after invoke', testFnWithLoggedTransitionTo(() => { Zone.current.fork({name: 'testEventTaskZone'}).run(() => { - const task = Zone.current.scheduleEventTask('testEventTask', noop, null, noop, noop); + const task = + Zone.current.scheduleEventTask('testEventTask', noop, undefined, noop, noop); task.invoke(); }); expect(log.map(item => { @@ -95,7 +96,8 @@ describe('task lifecycle', () => { it('task should transit from scheduled to canceling then from canceling to notScheduled when task is canceled before running', testFnWithLoggedTransitionTo(() => { Zone.current.fork({name: 'testEventTaskZone'}).run(() => { - const task = Zone.current.scheduleEventTask('testEventTask', noop, null, noop, noop); + const task = + Zone.current.scheduleEventTask('testEventTask', noop, undefined, noop, noop); Zone.current.cancelTask(task); }); expect(log.map(item => { @@ -114,7 +116,7 @@ describe('task lifecycle', () => { Zone.current.fork({name: 'testEventTaskZone'}).run(() => { const task = Zone.current.scheduleEventTask('testEventTask', () => { Zone.current.cancelTask(task); - }, null, noop, noop); + }, undefined, noop, noop); task.invoke(); }); expect(log.map(item => { @@ -134,7 +136,7 @@ describe('task lifecycle', () => { Zone.current.fork({name: 'testEventTaskZone'}).run(() => { const task = Zone.current.scheduleEventTask('testEventTask', () => { throw Error('invoke error'); - }, null, noop, noop); + }, undefined, noop, noop); try { task.invoke(); } catch (err) { @@ -154,9 +156,10 @@ describe('task lifecycle', () => { it('task should transit from canceling to unknown when zoneSpec.onCancelTask throw error before task running', testFnWithLoggedTransitionTo(() => { Zone.current.fork({name: 'testEventTaskZone'}).run(() => { - const task = Zone.current.scheduleEventTask('testEventTask', noop, null, noop, () => { - throw Error('cancel task'); - }); + const task = + Zone.current.scheduleEventTask('testEventTask', noop, undefined, noop, () => { + throw Error('cancel task'); + }); try { Zone.current.cancelTask(task); } catch (err) { @@ -176,9 +179,10 @@ describe('task lifecycle', () => { it('task should transit from canceling to unknown when zoneSpec.onCancelTask throw error in running state', testFnWithLoggedTransitionTo(() => { Zone.current.fork({name: 'testEventTaskZone'}).run(() => { - const task = Zone.current.scheduleEventTask('testEventTask', noop, null, noop, () => { - throw Error('cancel task'); - }); + const task = + Zone.current.scheduleEventTask('testEventTask', noop, undefined, noop, () => { + throw Error('cancel task'); + }); try { Zone.current.cancelTask(task); } catch (err) { @@ -206,7 +210,7 @@ describe('task lifecycle', () => { }) .run(() => { try { - Zone.current.scheduleEventTask('testEventTask', noop, null, noop, noop); + Zone.current.scheduleEventTask('testEventTask', noop, undefined, noop, noop); } catch (err) { } }); @@ -233,7 +237,8 @@ describe('task lifecycle', () => { }) .run(() => { try { - task = Zone.current.scheduleEventTask('testEventTask', noop, null, noop, noop); + task = + Zone.current.scheduleEventTask('testEventTask', noop, undefined, noop, noop); Zone.current.cancelTask(task); } catch (err) { } @@ -258,7 +263,7 @@ describe('task lifecycle', () => { it('task should transit from notScheduled to scheduling then to scheduled state when scheduleTask', testFnWithLoggedTransitionTo(() => { Zone.current.fork({name: 'testMacroTaskZone'}).run(() => { - Zone.current.scheduleMacroTask('testMacroTask', noop, null, noop, noop); + Zone.current.scheduleMacroTask('testMacroTask', noop, undefined, noop, noop); }); expect(log.map(item => { return {toState: item.toState, fromState: item.fromState}; @@ -280,7 +285,7 @@ describe('task lifecycle', () => { }) .run(() => { try { - Zone.current.scheduleMacroTask('testMacroTask', noop, null, noop, noop); + Zone.current.scheduleMacroTask('testMacroTask', noop, undefined, noop, noop); } catch (err) { } }); @@ -296,7 +301,8 @@ describe('task lifecycle', () => { it('task should transit from scheduled to running when task is invoked then from running to noScheduled after invoke', testFnWithLoggedTransitionTo(() => { Zone.current.fork({name: 'testMacroTaskZone'}).run(() => { - const task = Zone.current.scheduleMacroTask('testMacroTask', noop, null, noop, noop); + const task = + Zone.current.scheduleMacroTask('testMacroTask', noop, undefined, noop, noop); task.invoke(); }); expect(log.map(item => { @@ -313,7 +319,8 @@ describe('task lifecycle', () => { it('task should transit from scheduled to canceling then from canceling to notScheduled when task is canceled before running', testFnWithLoggedTransitionTo(() => { Zone.current.fork({name: 'testMacroTaskZone'}).run(() => { - const task = Zone.current.scheduleMacroTask('testMacrotask', noop, null, noop, noop); + const task = + Zone.current.scheduleMacroTask('testMacrotask', noop, undefined, noop, noop); Zone.current.cancelTask(task); }); expect(log.map(item => { @@ -332,7 +339,7 @@ describe('task lifecycle', () => { Zone.current.fork({name: 'testMacroTaskZone'}).run(() => { const task = Zone.current.scheduleMacroTask('testMacroTask', () => { Zone.current.cancelTask(task); - }, null, noop, noop); + }, undefined, noop, noop); task.invoke(); }); expect(log.map(item => { @@ -352,7 +359,7 @@ describe('task lifecycle', () => { Zone.current.fork({name: 'testMacroTaskZone'}).run(() => { const task = Zone.current.scheduleMacroTask('testMacroTask', () => { throw Error('invoke error'); - }, null, noop, noop); + }, undefined, noop, noop); try { task.invoke(); } catch (err) { @@ -372,9 +379,10 @@ describe('task lifecycle', () => { it('task should transit from canceling to unknown when zoneSpec.onCancelTask throw error before task running', testFnWithLoggedTransitionTo(() => { Zone.current.fork({name: 'testMacroTaskZone'}).run(() => { - const task = Zone.current.scheduleMacroTask('testMacroTask', noop, null, noop, () => { - throw Error('cancel task'); - }); + const task = + Zone.current.scheduleMacroTask('testMacroTask', noop, undefined, noop, () => { + throw Error('cancel task'); + }); try { Zone.current.cancelTask(task); } catch (err) { @@ -394,9 +402,10 @@ describe('task lifecycle', () => { it('task should transit from canceling to unknown when zoneSpec.onCancelTask throw error in running state', testFnWithLoggedTransitionTo(() => { Zone.current.fork({name: 'testMacroTaskZone'}).run(() => { - const task = Zone.current.scheduleMacroTask('testMacroTask', noop, null, noop, () => { - throw Error('cancel task'); - }); + const task = + Zone.current.scheduleMacroTask('testMacroTask', noop, undefined, noop, () => { + throw Error('cancel task'); + }); try { Zone.current.cancelTask(task); } catch (err) { @@ -424,7 +433,7 @@ describe('task lifecycle', () => { }) .run(() => { try { - Zone.current.scheduleMacroTask('testMacroTask', noop, null, noop, noop); + Zone.current.scheduleMacroTask('testMacroTask', noop, undefined, noop, noop); } catch (err) { } }); @@ -451,7 +460,8 @@ describe('task lifecycle', () => { }) .run(() => { try { - task = Zone.current.scheduleMacroTask('testMacroTask', noop, null, noop, noop); + task = + Zone.current.scheduleMacroTask('testMacroTask', noop, undefined, noop, noop); task.invoke(); } catch (err) { } @@ -481,7 +491,8 @@ describe('task lifecycle', () => { }) .run(() => { try { - task = Zone.current.scheduleMacroTask('testMacroTask', noop, null, noop, noop); + task = + Zone.current.scheduleMacroTask('testMacroTask', noop, undefined, noop, noop); Zone.current.cancelTask(task); } catch (err) { } @@ -499,7 +510,7 @@ describe('task lifecycle', () => { }); describe('periodical macroTask lifecycle', () => { - let task: Task; + let task: Task|null; beforeEach(() => { log = []; task = null; @@ -589,7 +600,7 @@ describe('task lifecycle', () => { testFnWithLoggedTransitionTo(() => { Zone.current.fork({name: 'testPeriodicalTaskZone'}).run(() => { task = Zone.current.scheduleMacroTask('testPeriodicalTask', () => { - Zone.current.cancelTask(task); + Zone.current.cancelTask(task!); }, {isPeriodic: true}, noop, noop); task.invoke(); }); @@ -737,7 +748,7 @@ describe('task lifecycle', () => { it('task should transit from notScheduled to scheduling then to scheduled state when scheduleTask', testFnWithLoggedTransitionTo(() => { Zone.current.fork({name: 'testMicroTaskZone'}).run(() => { - Zone.current.scheduleMicroTask('testMicroTask', noop, null, noop); + Zone.current.scheduleMicroTask('testMicroTask', noop, undefined, noop); }); expect(log.map(item => { return {toState: item.toState, fromState: item.fromState}; @@ -759,7 +770,7 @@ describe('task lifecycle', () => { }) .run(() => { try { - Zone.current.scheduleMicroTask('testMicroTask', noop, null, noop); + Zone.current.scheduleMicroTask('testMicroTask', noop, undefined, noop); } catch (err) { } }); @@ -775,7 +786,7 @@ describe('task lifecycle', () => { it('task should transit from scheduled to running when task is invoked then from running to noScheduled after invoke', testFnWithLoggedTransitionTo(() => { Zone.current.fork({name: 'testMicroTaskZone'}).run(() => { - const task = Zone.current.scheduleMicroTask('testMicroTask', noop, null, noop); + const task = Zone.current.scheduleMicroTask('testMicroTask', noop, undefined, noop); task.invoke(); }); expect(log.map(item => { @@ -791,7 +802,7 @@ describe('task lifecycle', () => { it('should throw error when try to cancel a microTask', testFnWithLoggedTransitionTo(() => { Zone.current.fork({name: 'testMicroTaskZone'}).run(() => { - const task = Zone.current.scheduleMicroTask('testMicroTask', () => {}, null, noop); + const task = Zone.current.scheduleMicroTask('testMicroTask', () => {}, undefined, noop); expect(() => { Zone.current.cancelTask(task); }).toThrowError('Task is not cancelable'); @@ -803,7 +814,7 @@ describe('task lifecycle', () => { Zone.current.fork({name: 'testMicroTaskZone'}).run(() => { const task = Zone.current.scheduleMicroTask('testMicroTask', () => { throw Error('invoke error'); - }, null, noop); + }, undefined, noop); try { task.invoke(); } catch (err) { @@ -831,7 +842,7 @@ describe('task lifecycle', () => { }) .run(() => { try { - Zone.current.scheduleMicroTask('testMicroTask', noop, null, noop); + Zone.current.scheduleMicroTask('testMicroTask', noop, undefined, noop); } catch (err) { } }); @@ -858,7 +869,7 @@ describe('task lifecycle', () => { }) .run(() => { try { - task = Zone.current.scheduleMicroTask('testMicroTask', noop, null, noop); + task = Zone.current.scheduleMicroTask('testMicroTask', noop, undefined, noop); task.invoke(); } catch (err) { } @@ -878,7 +889,8 @@ describe('task lifecycle', () => { testFnWithLoggedTransitionTo(() => { let task: Task; Zone.current.fork({name: 'testCancelZone'}).run(() => { - const task = Zone.current.scheduleEventTask('testEventTask', noop, null, noop, noop); + const task = + Zone.current.scheduleEventTask('testEventTask', noop, undefined, noop, noop); Zone.current.cancelTask(task); task.invoke(); }); @@ -955,8 +967,8 @@ describe('task lifecycle', () => { it('should be able to reschedule zone when in scheduling state, after that, task will completely go to new zone, has nothing to do with original one', testFnWithLoggedTransitionTo(() => { zone.run(() => { - const t = - Zone.current.scheduleMacroTask('testRescheduleZoneTask', noop, null, noop, noop); + const t = Zone.current.scheduleMacroTask( + 'testRescheduleZoneTask', noop, undefined, noop, noop); t.invoke(); }); @@ -978,8 +990,8 @@ describe('task lifecycle', () => { it('should not be able to reschedule task in notScheduled / running / canceling state', testFnWithLoggedTransitionTo(() => { Zone.current.fork({name: 'rescheduleNotScheduled'}).run(() => { - const t = - Zone.current.scheduleMacroTask('testRescheduleZoneTask', noop, null, noop, noop); + const t = Zone.current.scheduleMacroTask( + 'testRescheduleZoneTask', noop, undefined, noop, noop); Zone.current.cancelTask(t); expect(() => { t.cancelScheduleRequest(); @@ -1002,8 +1014,8 @@ describe('task lifecycle', () => { } }) .run(() => { - const t = - Zone.current.scheduleMacroTask('testRescheduleZoneTask', noop, null, noop, noop); + const t = Zone.current.scheduleMacroTask( + 'testRescheduleZoneTask', noop, undefined, noop, noop); t.invoke(); }); @@ -1020,8 +1032,8 @@ describe('task lifecycle', () => { } }) .run(() => { - const t = - Zone.current.scheduleMacroTask('testRescheduleZoneTask', noop, null, noop, noop); + const t = Zone.current.scheduleMacroTask( + 'testRescheduleZoneTask', noop, undefined, noop, noop); Zone.current.cancelTask(t); }); })); @@ -1051,7 +1063,7 @@ describe('task lifecycle', () => { const rescheduleZone = originalZone.fork({name: 'rescheduleZone'}); expect(() => { originalZone.run(() => { - Zone.current.scheduleMacroTask('testRescheduleZoneTask', noop, null, noop, noop); + Zone.current.scheduleMacroTask('testRescheduleZoneTask', noop, undefined, noop, noop); }); }) .toThrowError( diff --git a/test/common/util.spec.ts b/test/common/util.spec.ts index b6b122d10..605a21248 100644 --- a/test/common/util.spec.ts +++ b/test/common/util.spec.ts @@ -33,14 +33,14 @@ describe('utils', function() { return function(self, args) { return delegate.apply(self, ['patch', args[0]]); }; - })).toBe(delegateMethod); + })).toBe(delegateMethod!); expect(instance.method('a0')).toEqual('OK'); expect(args).toEqual(['patch', 'a0']); expect(self).toBe(instance); - expect(delegateMethod).toBe(method); - expect(delegateSymbol).toEqual(zoneSymbol('method')); - expect((Type.prototype as any)[delegateSymbol]).toBe(method); + expect(delegateMethod!).toBe(method); + expect(delegateSymbol!).toEqual(zoneSymbol('method')); + expect((Type.prototype as any)[delegateSymbol!]).toBe(method); }); it('should not double patch', () => { @@ -75,8 +75,8 @@ describe('utils', function() { } patchProperty(TestType.prototype, 'nonConfigurableProperty'); const desc = Object.getOwnPropertyDescriptor(TestType.prototype, 'nonConfigurableProperty'); - expect(desc.writable).toBeTruthy(); - expect(!desc.get).toBeTruthy(); + expect(desc!.writable).toBeTruthy(); + expect(!desc!.get).toBeTruthy(); }); }); diff --git a/test/common/zone.spec.ts b/test/common/zone.spec.ts index f969df913..3b9b79bd1 100644 --- a/test/common/zone.spec.ts +++ b/test/common/zone.spec.ts @@ -101,7 +101,7 @@ describe('Zone', function() { Zone.current.fork({name: 'testZone'}).run(function() { Zone.root.fork({name: 'newTestZone'}).run(() => { expect(Zone.current.name).toEqual('newTestZone'); - expect(Zone.current.parent.name).toEqual(''); + expect(Zone.current.parent!.name).toEqual(''); }); }); }); @@ -143,7 +143,7 @@ describe('Zone', function() { it('task can only run in the zone of creation', () => { const task = - zone.fork({name: 'createZone'}).scheduleMacroTask('test', noop, null, noop, noop); + zone.fork({name: 'createZone'}).scheduleMacroTask('test', noop, undefined, noop, noop); expect(() => { Zone.current.fork({name: 'anotherZone'}).runTask(task); }) @@ -154,7 +154,7 @@ describe('Zone', function() { it('task can only cancel in the zone of creation', () => { const task = - zone.fork({name: 'createZone'}).scheduleMacroTask('test', noop, null, noop, noop); + zone.fork({name: 'createZone'}).scheduleMacroTask('test', noop, undefined, noop, noop); expect(() => { Zone.current.fork({name: 'anotherZone'}).cancelTask(task); }) @@ -164,7 +164,8 @@ describe('Zone', function() { }); it('should prevent double cancellation', () => { - const task = zone.scheduleMacroTask('test', () => log.push('macroTask'), null, noop, noop); + const task = + zone.scheduleMacroTask('test', () => log.push('macroTask'), undefined, noop, noop); zone.cancelTask(task); try { zone.cancelTask(task); @@ -198,8 +199,10 @@ describe('Zone', function() { zone.run(() => { const z = Zone.current; z.runTask(z.scheduleMicroTask('test', () => log.push('microTask'))); - z.cancelTask(z.scheduleMacroTask('test', () => log.push('macroTask'), null, noop, noop)); - z.cancelTask(z.scheduleEventTask('test', () => log.push('eventTask'), null, noop, noop)); + z.cancelTask( + z.scheduleMacroTask('test', () => log.push('macroTask'), undefined, noop, noop)); + z.cancelTask( + z.scheduleEventTask('test', () => log.push('eventTask'), undefined, noop, noop)); }); expect(log).toEqual([ {microTask: true, macroTask: false, eventTask: false, change: 'microTask', zone: 'parent'}, @@ -316,7 +319,7 @@ describe('Zone', function() { const task = zone.scheduleEventTask('testEventTask', () => { zone.cancelTask(task); - }, null, () => {}, () => {}); + }, undefined, () => {}, () => {}); task.invoke(); expect(task.state).toBe('notScheduled'); @@ -361,7 +364,7 @@ describe('Zone', function() { it('should not drain the microtask queue too early', () => { const z = Zone.current; - const event = z.scheduleEventTask('test', () => log.push('eventTask'), null, noop, noop); + const event = z.scheduleEventTask('test', () => log.push('eventTask'), undefined, noop, noop); z.scheduleMicroTask('test', () => log.push('microTask')); @@ -369,16 +372,16 @@ describe('Zone', function() { event.invoke(); // At this point, we should not have invoked the microtask. expect(log).toEqual(['eventTask']); - }, null, noop, noop); + }, undefined, noop, noop); macro.invoke(); }); it('should convert task to json without cyclic error', () => { const z = Zone.current; - const event = z.scheduleEventTask('test', () => {}, null, noop, noop); + const event = z.scheduleEventTask('test', () => {}, undefined, noop, noop); const micro = z.scheduleMicroTask('test', () => {}); - const macro = z.scheduleMacroTask('test', () => {}, null, noop, noop); + const macro = z.scheduleMacroTask('test', () => {}, undefined, noop, noop); expect(function() { JSON.stringify(event); }).not.toThrow(); @@ -405,7 +408,7 @@ describe('Zone', function() { } }); - const microTask = hasTaskZone.scheduleMicroTask('test', () => {}, null, () => {}); + const microTask = hasTaskZone.scheduleMicroTask('test', () => {}, undefined, () => {}); expect(spy).toHaveBeenCalledWith('onHasTask Error'); }); }); diff --git a/test/jasmine-patch.spec.ts b/test/jasmine-patch.spec.ts index c7fc9be7d..71ecf240f 100644 --- a/test/jasmine-patch.spec.ts +++ b/test/jasmine-patch.spec.ts @@ -22,11 +22,11 @@ ifEnvSupports(supportJasmineSpec, () => { describe('jasmine', () => { let throwOnAsync = false; - let beforeEachZone: Zone = null; - let itZone: Zone = null; + let beforeEachZone: Zone|null = null; + let itZone: Zone|null = null; const syncZone = Zone.current; try { - Zone.current.scheduleMicroTask('dontallow', () => null as void); + Zone.current.scheduleMicroTask('dontallow', (): any => null); } catch (e) { throwOnAsync = true; } @@ -44,7 +44,7 @@ ifEnvSupports(supportJasmineSpec, () => { afterEach(() => { let zone = Zone.current; expect(zone.name).toEqual('ProxyZone'); - expect(beforeEachZone.name).toEqual(zone.name); + expect(beforeEachZone!.name).toEqual(zone.name); expect(itZone).toBe(zone); }); }); diff --git a/test/mocha-patch.spec.ts b/test/mocha-patch.spec.ts index 54c47bcd0..1a583ab8d 100644 --- a/test/mocha-patch.spec.ts +++ b/test/mocha-patch.spec.ts @@ -25,17 +25,17 @@ ifEnvSupports('Mocha', function() { describe('Mocha BDD-style', () => { let throwOnAsync = false; - let beforeEachZone: Zone = null; - let itZone: Zone = null; + let beforeEachZone: Zone|null = null; + let itZone: Zone|null = null; const syncZone = Zone.current; - let beforeZone: Zone = null; + let beforeZone: Zone|null = null; before(() => { beforeZone = Zone.current; }); try { - Zone.current.scheduleMicroTask('dontallow', () => null as void); + Zone.current.scheduleMicroTask('dontallow', (): any => null); } catch (e) { throwOnAsync = true; } @@ -62,9 +62,9 @@ ifEnvSupports('Mocha', function() { }); suite('Mocha TDD-style', () => { - let testZone: Zone = null; - let beforeEachZone: Zone = null; - let suiteSetupZone: Zone = null; + let testZone: Zone|null = null; + let beforeEachZone: Zone|null = null; + let suiteSetupZone: Zone|null = null; suiteSetup(() => { suiteSetupZone = Zone.current; diff --git a/test/rxjs/rxjs.Observable.notification.spec.ts b/test/rxjs/rxjs.Observable.notification.spec.ts index 6bc561005..c87ffb5fd 100644 --- a/test/rxjs/rxjs.Observable.notification.spec.ts +++ b/test/rxjs/rxjs.Observable.notification.spec.ts @@ -30,7 +30,7 @@ describe('Observable.notification', ifEnvSupports(supportNotification, () => { const notifA = new Rx.Notification('N', 'A'); const notifB = new Rx.Notification('N', 'B'); const notifE = new Rx.Notification('E', void 0, error); - const materialized = Rx.Observable.of(notifA, notifB, notifE); + const materialized = Rx.Observable.of(notifA, notifB, notifE as any); return materialized.dematerialize(); }); diff --git a/test/rxjs/rxjs.bindCallback.spec.ts b/test/rxjs/rxjs.bindCallback.spec.ts index fb52dea78..ca0cb708e 100644 --- a/test/rxjs/rxjs.bindCallback.spec.ts +++ b/test/rxjs/rxjs.bindCallback.spec.ts @@ -70,7 +70,7 @@ describe('Observable.bindCallback', () => { expect(Zone.current.name).toEqual(constructorZone.name); callback(arg0); }; - boundFunc = Rx.Observable.bindCallback(func, null, Rx.Scheduler.asap); + boundFunc = Rx.Observable.bindCallback(func, undefined, Rx.Scheduler.asap); observable = boundFunc('test'); }); diff --git a/test/rxjs/rxjs.bindNodeCallback.spec.ts b/test/rxjs/rxjs.bindNodeCallback.spec.ts index 90c8002f8..5bcc0b023 100644 --- a/test/rxjs/rxjs.bindNodeCallback.spec.ts +++ b/test/rxjs/rxjs.bindNodeCallback.spec.ts @@ -70,7 +70,7 @@ describe('Observable.bindNodeCallback', () => { expect(Zone.current.name).toEqual(constructorZone.name); callback(null, arg); }; - boundFunc = Rx.Observable.bindCallback(func, null, Rx.Scheduler.asap); + boundFunc = Rx.Observable.bindCallback(func, undefined, Rx.Scheduler.asap); observable = boundFunc('test'); }); diff --git a/test/test-util.ts b/test/test-util.ts index 77907f522..5a58cf8bd 100644 --- a/test/test-util.ts +++ b/test/test-util.ts @@ -42,7 +42,7 @@ function _ifEnvSupports(test: any, block: Function, withDone = false) { } } -function _runTest(test: any, block: Function, done: Function) { +function _runTest(test: any, block: Function, done?: Function) { const message = (test.message || test.name || test); if (typeof test === 'string' ? !!global[test] : test()) { if (done) { diff --git a/test/zone-spec/long-stack-trace-zone.spec.ts b/test/zone-spec/long-stack-trace-zone.spec.ts index 4515c2965..779fba53e 100644 --- a/test/zone-spec/long-stack-trace-zone.spec.ts +++ b/test/zone-spec/long-stack-trace-zone.spec.ts @@ -54,7 +54,7 @@ describe( setTimeout(function() { setTimeout(function() { setTimeout(function() { - expectElapsed(log[0].stack, 3); + expectElapsed(log[0].stack!, 3); done(); }, 0); throw new Error('Hello'); @@ -72,7 +72,7 @@ describe( document.body.appendChild(button); button.addEventListener('click', function() { - expectElapsed(log[0].stack, 1); + expectElapsed(log[0].stack!, 1); }); button.dispatchEvent(clickEvent); @@ -116,7 +116,7 @@ describe( fail('should not get here'); }); setTimeout(function() { - expectElapsed(log[0].stack, 5); + expectElapsed(log[0].stack!, 5); done(); }, 0); }, 0); @@ -155,7 +155,7 @@ describe( setTimeout(function() { setTimeout(function() { if (log[0].stack) { - expectElapsed(log[0].stack, 1); + expectElapsed(log[0].stack!, 1); } Error.stackTraceLimit = originalStackTraceLimit; done(); diff --git a/test/zone-spec/proxy.spec.ts b/test/zone-spec/proxy.spec.ts index 950353fef..2285855fb 100644 --- a/test/zone-spec/proxy.spec.ts +++ b/test/zone-spec/proxy.spec.ts @@ -136,7 +136,7 @@ describe('ProxySpec', () => { }); it('should Task', () => { - const fn = () => null as void; + const fn = (): any => null; const task = proxyZone.scheduleMacroTask('test', fn, {}, () => null, () => null); expect(task.source).toEqual('test'); proxyZone.cancelTask(task); diff --git a/test/zone-spec/task-tracking.spec.ts b/test/zone-spec/task-tracking.spec.ts index 1c7115d2a..9c824bfe7 100644 --- a/test/zone-spec/task-tracking.spec.ts +++ b/test/zone-spec/task-tracking.spec.ts @@ -12,7 +12,7 @@ declare const global: any; describe('TaskTrackingZone', function() { let _TaskTrackingZoneSpec: typeof TaskTrackingZoneSpec = (Zone as any)['TaskTrackingZoneSpec']; - let taskTrackingZoneSpec: TaskTrackingZoneSpec = null; + let taskTrackingZoneSpec: TaskTrackingZoneSpec|null = null; let taskTrackingZone: Zone; beforeEach(() => { @@ -23,19 +23,19 @@ describe('TaskTrackingZone', function() { it('should track tasks', (done: Function) => { taskTrackingZone.run(() => { taskTrackingZone.scheduleMicroTask('test1', () => {}); - expect(taskTrackingZoneSpec.microTasks.length).toBe(1); - expect(taskTrackingZoneSpec.microTasks[0].source).toBe('test1'); + expect(taskTrackingZoneSpec!.microTasks.length).toBe(1); + expect(taskTrackingZoneSpec!.microTasks[0].source).toBe('test1'); setTimeout(() => {}); - expect(taskTrackingZoneSpec.macroTasks.length).toBe(1); - expect(taskTrackingZoneSpec.macroTasks[0].source).toBe('setTimeout'); - taskTrackingZone.cancelTask(taskTrackingZoneSpec.macroTasks[0]); - expect(taskTrackingZoneSpec.macroTasks.length).toBe(0); + expect(taskTrackingZoneSpec!.macroTasks.length).toBe(1); + expect(taskTrackingZoneSpec!.macroTasks[0].source).toBe('setTimeout'); + taskTrackingZone.cancelTask(taskTrackingZoneSpec!.macroTasks[0]); + expect(taskTrackingZoneSpec!.macroTasks.length).toBe(0); setTimeout(() => { // assert on execution it is null - expect(taskTrackingZoneSpec.macroTasks.length).toBe(0); - expect(taskTrackingZoneSpec.microTasks.length).toBe(0); + expect(taskTrackingZoneSpec!.macroTasks.length).toBe(0); + expect(taskTrackingZoneSpec!.microTasks.length).toBe(0); // If a browser does not have XMLHttpRequest, then end test here. if (typeof global['XMLHttpRequest'] == 'undefined') return done(); @@ -45,22 +45,22 @@ describe('TaskTrackingZone', function() { if (xhr.readyState == 4) { // clear current event tasks using setTimeout setTimeout(() => { - expect(taskTrackingZoneSpec.macroTasks.length).toBe(0); - expect(taskTrackingZoneSpec.microTasks.length).toBe(0); + expect(taskTrackingZoneSpec!.macroTasks.length).toBe(0); + expect(taskTrackingZoneSpec!.microTasks.length).toBe(0); if (supportPatchXHROnProperty()) { - expect(taskTrackingZoneSpec.eventTasks.length).not.toBe(0); + expect(taskTrackingZoneSpec!.eventTasks.length).not.toBe(0); } - taskTrackingZoneSpec.clearEvents(); - expect(taskTrackingZoneSpec.eventTasks.length).toBe(0); + taskTrackingZoneSpec!.clearEvents(); + expect(taskTrackingZoneSpec!.eventTasks.length).toBe(0); done(); }); } }; xhr.send(); - expect(taskTrackingZoneSpec.macroTasks.length).toBe(1); - expect(taskTrackingZoneSpec.macroTasks[0].source).toBe('XMLHttpRequest.send'); + expect(taskTrackingZoneSpec!.macroTasks.length).toBe(1); + expect(taskTrackingZoneSpec!.macroTasks[0].source).toBe('XMLHttpRequest.send'); if (supportPatchXHROnProperty()) { - expect(taskTrackingZoneSpec.eventTasks[0].source) + expect(taskTrackingZoneSpec!.eventTasks[0].source) .toMatch(/\.addEventListener:readystatechange/); } }); @@ -72,7 +72,7 @@ describe('TaskTrackingZone', function() { setTimeout(() => { done(); }); - expect((taskTrackingZoneSpec.macroTasks[0] as any)['creationLocation']).toBeTruthy(); + expect((taskTrackingZoneSpec!.macroTasks[0] as any)['creationLocation']).toBeTruthy(); }); }); }); diff --git a/tsconfig-esm-node.json b/tsconfig-esm-node.json index 8aecae97e..8a79dc143 100644 --- a/tsconfig-esm-node.json +++ b/tsconfig-esm-node.json @@ -14,7 +14,12 @@ "sourceMap": true, "downlevelIteration": true, "moduleResolution": "node", - "lib": ["es5", "dom", "es2015.promise"] + "strict": true, + "lib": [ + "es5", + "dom", + "es2015.promise" + ] }, "exclude": [ "node_modules", @@ -23,4 +28,4 @@ "dist", "lib/closure" ] -} +} \ No newline at end of file diff --git a/tsconfig-esm.json b/tsconfig-esm.json index 5dbdd52d2..ab2416b2d 100644 --- a/tsconfig-esm.json +++ b/tsconfig-esm.json @@ -14,7 +14,12 @@ "stripInternal": true, "sourceMap": true, "moduleResolution": "node", - "lib": ["es5", "dom", "es2015.promise"] + "strict": true, + "lib": [ + "es5", + "dom", + "es2015.promise" + ] }, "exclude": [ "node_modules", @@ -23,4 +28,4 @@ "dist", "lib/closure" ] -} +} \ No newline at end of file diff --git a/tsconfig-node.json b/tsconfig-node.json index 4e5512c20..eca611773 100644 --- a/tsconfig-node.json +++ b/tsconfig-node.json @@ -12,7 +12,12 @@ "downlevelIteration": true, "noEmitOnError": false, "stripInternal": false, - "lib": ["es5", "dom", "es2015.promise"] + "strict": true, + "lib": [ + "es5", + "dom", + "es2015.promise" + ] }, "exclude": [ "node_modules", @@ -21,4 +26,4 @@ "dist", "lib/closure" ] -} +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 7303adf3a..ec1d893a9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,9 +11,12 @@ "declaration": false, "noEmitOnError": false, "stripInternal": false, - // TODO: turn this on. - "strict": false, - "lib": ["es5", "dom", "es2015.promise"] + "strict": true, + "lib": [ + "es5", + "dom", + "es2015.promise" + ] }, "exclude": [ "node_modules",