Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

chore: Fix type definitions #298

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/browser/browser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../zone';
import { TaskData, Zone, Task } from '../zone';
import {eventTargetPatch} from './event-target';
import {propertyPatch} from './define-property';
import {registerElementPatch} from './register-element';
Expand Down Expand Up @@ -96,4 +96,3 @@ function patchTimer(
}
});
}

3 changes: 2 additions & 1 deletion lib/browser/property-descriptor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Zone } from '../zone';
import * as webSocketPatch from './websocket';
import {zoneSymbol, patchOnProperties, patchClass, isBrowser, isNode} from './utils';

Expand All @@ -7,7 +8,7 @@ export function propertyDescriptorPatch(_global) {
if (isNode){
return;
}

var supportsWebSocket = typeof WebSocket !== 'undefined';
if (canPatchViaPropertyDescriptor()) {
// for browsers that we can patch the descriptor: Chrome & Firefox
Expand Down
1 change: 1 addition & 0 deletions lib/browser/register-element.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Zone } from '../zone';
import {_redefineProperty} from './define-property';
import {isBrowser} from './utils';

Expand Down
2 changes: 1 addition & 1 deletion lib/browser/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Zone, TaskData, Task } from '../zone';
/**
* Suppress closure compiler errors about unknown 'process' variable
* @fileoverview
Expand Down Expand Up @@ -317,4 +318,3 @@ export function patchMethod(target: any, name: string,
}
return delegate;
}

3 changes: 1 addition & 2 deletions lib/jasmine/jasmine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
import { Zone, ZoneSpec, Task, ZoneDelegate, MicroTask } from '../../lib/zone';
// Patch jasmine's it and fit functions so that the `done` wrapCallback always resets the zone
// to the jasmine zone, which should be the root zone. (angular/zone.js#91)
if (!Zone) {
Expand Down Expand Up @@ -30,4 +30,3 @@ const _global = typeof window == 'undefined' ? global : window;
QueueRunner.prototype = SuperQueueRunner.prototype;
return QueueRunner;
})((<any>jasmine).QueueRunner);

2 changes: 2 additions & 0 deletions lib/zone-spec/async-test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Zone, ZoneSpec, Task, ZoneDelegate, HasTaskState } from '../zone';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can not add this code here. If we do then Zones will be included in the async-test.js bundle as well as zone.js bundle.

Zone's is meant as a polyfil, and so it should be ambiently available.


(function() {
class AsyncTestZoneSpec implements ZoneSpec {
_finishCallback: Function;
Expand Down
1 change: 1 addition & 0 deletions lib/zone-spec/long-stack-trace.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Zone, ZoneDelegate, Task, ZoneSpec } from '../zone';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

'use strict';
(function() {
const NEWLINE = '\n';
Expand Down
2 changes: 2 additions & 0 deletions lib/zone-spec/sync-test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Zone, ZoneSpec, Task, ZoneDelegate, MicroTask } from '../zone';

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

(function() {
class SyncTestZoneSpec implements ZoneSpec {
runZone = Zone.current;
Expand Down
2 changes: 2 additions & 0 deletions lib/zone-spec/wtf.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Zone, ZoneSpec, Task, ZoneDelegate } from '../zone';

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

(function(global) {
interface Wtf { trace: WtfTrace; }
interface WtfScope {};
Expand Down
24 changes: 12 additions & 12 deletions lib/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
* zones are children of the root zone.
*
*/
interface Zone {
export interface Zone {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will prevent the Zone from being imported ambiently. Sorry we can't do it that way.

/**
*
* @returns {Zone} The parent Zone.
Expand Down Expand Up @@ -212,7 +212,7 @@ interface Zone {
cancelTask(task: Task): any;
}

interface ZoneType {
export interface ZoneType {
/**
* @returns {Zone} Returns the current [Zone]. Returns the current zone. The only way to change
* the current zone is by invoking a run() method, which will update the current zone for the
Expand All @@ -230,7 +230,7 @@ interface ZoneType {
*
* Only the `name` property is required (all other are optional).
*/
interface ZoneSpec {
export interface ZoneSpec {
/**
* The name of the zone. Usefull when debugging Zones.
*/
Expand Down Expand Up @@ -359,7 +359,7 @@ interface ZoneSpec {
* Note: The ZoneDelegate treats ZoneSpec as class. This allows the ZoneSpec to use its `this` to
* store internal state.
*/
interface ZoneDelegate {
export interface ZoneDelegate {
zone: Zone;
fork(targetZone: Zone, zoneSpec: ZoneSpec): Zone;
intercept(targetZone: Zone, callback: Function, source: string): Function;
Expand All @@ -371,7 +371,7 @@ interface ZoneDelegate {
hasTask(targetZone: Zone, isEmpty: HasTaskState): void;
}

type HasTaskState = {
export type HasTaskState = {
microTask: boolean,
macroTask: boolean,
eventTask: boolean,
Expand All @@ -381,11 +381,11 @@ type HasTaskState = {
/**
* Task type: `microTask`, `macroTask`, `eventTask`.
*/
type TaskType = string; /* TS v1.8 => "microTask" | "macroTask" | "eventTask" */;
export type TaskType = string; /* TS v1.8 => "microTask" | "macroTask" | "eventTask" */;

/**
*/
interface TaskData {
export interface TaskData {
/**
* A periodic [MacroTask] is such which get automatically rescheduled after it is executed.
*/
Expand Down Expand Up @@ -414,7 +414,7 @@ interface TaskData {
* queue. This happens when the event fires.
*
*/
interface Task {
export interface Task {
/**
* Task type: `microTask`, `macroTask`, `eventTask`.
*/
Expand Down Expand Up @@ -464,15 +464,15 @@ interface Task {
zone: Zone;
}

interface MicroTask extends Task {
export interface MicroTask extends Task {
/* TS v1.8 => type: 'microTask'; */
}

interface MacroTask extends Task {
export interface MacroTask extends Task {
/* TS v1.8 => type: 'macroTask'; */
}

interface EventTask extends Task {
export interface EventTask extends Task {
/* TS v1.8 => type: 'eventTask'; */
}

Expand All @@ -481,7 +481,7 @@ type AmbientZone = Zone;
/** @internal */
type AmbientZoneDelegate = ZoneDelegate;

var Zone: ZoneType = (function(global) {
export var Zone: ZoneType = (function(global) {
class Zone implements AmbientZone {
static __symbol__: (name: string) => string = __symbol__;

Expand Down
1 change: 1 addition & 0 deletions test/async-test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import '../lib/zone-spec/async-test';
import { Zone, ZoneSpec, Task, ZoneDelegate, HasTaskState } from '../lib/zone';

describe('AsyncTestZoneSpec', function() {
var log;
Expand Down
5 changes: 3 additions & 2 deletions test/browser/FileReader.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {ifEnvSupports} from '../util';
import { Zone } from '../../lib/zone';

describe('FileReader', ifEnvSupports('FileReader', function () {
var fileReader;
var blob;
var data = 'Hello, World!';
var testZone = Zone.current.fork({ name: 'TestZone' });

// Android 4.3's native browser doesn't implement add/RemoveEventListener for FileReader
// Android 4.3's native browser doesn't implement add/RemoveEventListener for FileReader
function supportsEventTargetFns () {
return FileReader.prototype.addEventListener && FileReader.prototype.removeEventListener;
}
Expand Down Expand Up @@ -92,4 +93,4 @@ describe('FileReader', ifEnvSupports('FileReader', function () {

fileReader.readAsText(blob);
});
}));
}));
1 change: 1 addition & 0 deletions test/browser/HTMLImports.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ifEnvSupports} from '../util';
import { Zone } from '../../lib/zone';

function supportsImports() {
return 'import' in document.createElement('link');
Expand Down
1 change: 1 addition & 0 deletions test/browser/MutationObserver.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Zone } from '../../lib/zone';
import {ifEnvSupports} from '../util';

describe('MutationObserver', ifEnvSupports('MutationObserver', function () {
Expand Down
3 changes: 2 additions & 1 deletion test/browser/Promise.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ifEnvSupports} from '../util';
import { Zone, ZoneSpec, Task, ZoneDelegate, MicroTask } from '../../lib/zone';

class MicroTaskQueueZoneSpec implements ZoneSpec {
name: string = 'MicroTaskQueue';
Expand Down Expand Up @@ -138,7 +139,7 @@ describe('Promise', ifEnvSupports('Promise', function () {
});
});


expect(reject()).toBe(undefined);
});

Expand Down
3 changes: 2 additions & 1 deletion test/browser/WebSocket.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ifEnvSupports} from '../util';
import { Zone } from '../../lib/zone';

var TIMEOUT = 5000;

Expand Down Expand Up @@ -119,4 +120,4 @@ if (!window['soucelabs']) {
}, 100);
}, TIMEOUT);
}));
}
}
2 changes: 1 addition & 1 deletion test/browser/XMLHttpRequest.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ifEnvSupports} from '../util';
import { Zone } from '../../lib/zone';

describe('XMLHttpRequest', function () {
var testZone = Zone.current.fork({name: 'test'});
Expand Down Expand Up @@ -65,4 +66,3 @@ describe('XMLHttpRequest', function () {
expect(XMLHttpRequest.DONE).toEqual(4);
});
});

9 changes: 5 additions & 4 deletions test/browser/element.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ifEnvSupports} from '../util';
import { Zone } from '../../lib/zone';

describe('element', function () {

Expand Down Expand Up @@ -106,7 +107,7 @@ describe('element', function () {
it('should have no effect while calling addEventListener without listener', function () {
var onAddEventListenerSpy = jasmine.createSpy('addEventListener')
var eventListenerZone = Zone.current.fork({
name: 'eventListenerZone',
name: 'eventListenerZone',
onScheduleTask: onAddEventListenerSpy
});
expect(function() {
Expand All @@ -120,8 +121,8 @@ describe('element', function () {

it('should have no effect while calling removeEventListener without listener', function () {
var onAddEventListenerSpy = jasmine.createSpy('removeEventListener');
var eventListenerZone = Zone.current.fork({
name: 'eventListenerZone',
var eventListenerZone = Zone.current.fork({
name: 'eventListenerZone',
onScheduleTask: onAddEventListenerSpy
});
expect(function() {
Expand Down Expand Up @@ -277,7 +278,7 @@ describe('element', function () {
afterEach(function () {
document.body.removeChild(checkbox);
});

it('should be possible to prevent default behavior by returning false', function() {
checkbox.onclick = function() {
return false;
Expand Down
1 change: 1 addition & 0 deletions test/browser/geolocation.spec.manual.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ifEnvSupports} from '../util';
import { Zone } from '../../lib/zone';

function supportsGeolocation() {
return 'geolocation' in navigator;
Expand Down
1 change: 1 addition & 0 deletions test/browser/registerElement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import {ifEnvSupports} from '../util';
import { Zone } from '../../lib/zone';

function registerElement() {
return ('registerElement' in document);
Expand Down
1 change: 1 addition & 0 deletions test/browser/requestAnimationFrame.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ifEnvSupports} from '../util';
import { Zone, } from '../../lib/zone';

describe('requestAnimationFrame', function () {
var functions = [
Expand Down
1 change: 1 addition & 0 deletions test/browser/setInterval.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
import {zoneSymbol} from "../../lib/browser/utils";
import { Zone, MacroTask } from '../../lib/zone';

describe('setInterval', function () {

Expand Down
1 change: 1 addition & 0 deletions test/browser/setTimeout.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {zoneSymbol} from '../../lib/browser/utils';
import { Zone, MacroTask } from '../../lib/zone';

describe('setTimeout', function () {
it('should intercept setTimeout', function (done) {
Expand Down
2 changes: 2 additions & 0 deletions test/long-stack-trace-zone.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Zone, ZoneDelegate } from '../lib/zone';

describe('longStackTraceZone', function () {
var log;

Expand Down
2 changes: 2 additions & 0 deletions test/microtasks.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Zone, ZoneDelegate, Task } from '../lib/zone';

describe('Microtasks', function () {
if (!global.Promise) return;

Expand Down
1 change: 1 addition & 0 deletions test/sync-test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import '../lib/zone-spec/sync-test';
import { Zone } from '../lib/zone';

describe('SyncTestZoneSpec', () => {
var SyncTestZoneSpec = Zone['SyncTestZoneSpec'];
Expand Down
2 changes: 1 addition & 1 deletion test/ws-webworker-context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
importScripts('/base/test/zone_worker_entry_point.ts');
import { Zone } from '../lib/zone';

Zone.current.fork({name: 'webworker'}).run(() => {
var websocket = new WebSocket('ws://localhost:8001');
Expand All @@ -13,4 +14,3 @@ Zone.current.fork({name: 'webworker'}).run(() => {
websocket.send('text');
});
});

3 changes: 2 additions & 1 deletion test/zone.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import './test-env-setup';
import {zoneSymbol} from '../lib/browser/utils';
import { Zone, Task, ZoneDelegate, HasTaskState } from '../lib/zone';

describe('Zone', function () {
var rootZone = Zone.current;
Expand Down Expand Up @@ -97,7 +98,7 @@ describe('Zone', function () {
zone.run(function() {
button.addEventListener('click', eventListenerSpy);
});

button.dispatchEvent(clickEvent);

expect(hookSpy).toHaveBeenCalled();
Expand Down