chore(build): migrated di to TypeScript
This commit is contained in:
+3
-2
@@ -1,6 +1,7 @@
|
||||
import {ProtoRecord} from './proto_record';
|
||||
import {BaseException} from "angular2/src/facade/lang";
|
||||
|
||||
export class ExpressionChangedAfterItHasBeenChecked extends Error {
|
||||
export class ExpressionChangedAfterItHasBeenChecked extends BaseException {
|
||||
message:string;
|
||||
|
||||
constructor(proto:ProtoRecord, change:any) {
|
||||
@@ -14,7 +15,7 @@ export class ExpressionChangedAfterItHasBeenChecked extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
export class ChangeDetectionError extends Error {
|
||||
export class ChangeDetectionError extends BaseException {
|
||||
message:string;
|
||||
originalException:any;
|
||||
location:string;
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import {Injectable} from 'angular2/src/di/annotations_impl';
|
||||
import {List, ListWrapper, SetWrapper} from "angular2/src/facade/collection";
|
||||
import {int, NumberWrapper, StringJoiner, StringWrapper} from "angular2/src/facade/lang";
|
||||
import {int, NumberWrapper, StringJoiner, StringWrapper, BaseException} from "angular2/src/facade/lang";
|
||||
|
||||
export const TOKEN_TYPE_CHARACTER = 1;
|
||||
export const TOKEN_TYPE_IDENTIFIER = 2;
|
||||
@@ -176,7 +176,7 @@ export const $RBRACE = 125;
|
||||
const $NBSP = 160;
|
||||
|
||||
|
||||
export class ScannerError extends Error {
|
||||
export class ScannerError extends BaseException {
|
||||
message:string;
|
||||
constructor(message) {
|
||||
super();
|
||||
|
||||
+2
-2
@@ -966,7 +966,7 @@ export class ElementInjector extends TreeNode {
|
||||
}
|
||||
}
|
||||
|
||||
class OutOfBoundsAccess extends Error {
|
||||
class OutOfBoundsAccess extends BaseException {
|
||||
message:string;
|
||||
constructor(index) {
|
||||
super();
|
||||
@@ -978,7 +978,7 @@ class OutOfBoundsAccess extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
class QueryError extends Error {
|
||||
class QueryError extends BaseException {
|
||||
message:string;
|
||||
// TODO(rado): pass the names of the active directives.
|
||||
constructor() {
|
||||
|
||||
@@ -10,4 +10,4 @@ export {
|
||||
Optional as OptionalAnnotation,
|
||||
Injectable as InjectableAnnotation,
|
||||
DependencyAnnotation, // abstract base class, does not need a decorator
|
||||
} from './annotations_impl';
|
||||
} from './annotations_impl';
|
||||
+22
-33
@@ -1,5 +1,10 @@
|
||||
import {CONST} from "angular2/src/facade/lang";
|
||||
|
||||
// HACK: workaround for Traceur behavior.
|
||||
// It expects all transpiled modules to contain this marker.
|
||||
// TODO: remove this when we no longer use traceur
|
||||
export var __esModule = true;
|
||||
|
||||
/**
|
||||
* A parameter annotation that specifies a dependency.
|
||||
*
|
||||
@@ -11,12 +16,10 @@ import {CONST} from "angular2/src/facade/lang";
|
||||
*
|
||||
* @exportedAs angular2/di_annotations
|
||||
*/
|
||||
|
||||
@CONST()
|
||||
export class Inject {
|
||||
token;
|
||||
@CONST()
|
||||
constructor(token) {
|
||||
this.token = token;
|
||||
}
|
||||
constructor(public token) {}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,12 +35,9 @@ export class Inject {
|
||||
*
|
||||
* @exportedAs angular2/di_annotations
|
||||
*/
|
||||
@CONST()
|
||||
export class InjectPromise {
|
||||
token;
|
||||
@CONST()
|
||||
constructor(token) {
|
||||
this.token = token;
|
||||
}
|
||||
constructor(public token) {}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,17 +53,14 @@ export class InjectPromise {
|
||||
*
|
||||
* @exportedAs angular2/di_annotations
|
||||
*/
|
||||
@CONST()
|
||||
export class InjectLazy {
|
||||
token;
|
||||
@CONST()
|
||||
constructor(token) {
|
||||
this.token = token;
|
||||
}
|
||||
constructor(public token) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* A parameter annotation that marks a dependency as optional. {@link Injector} provides `null` if the dependency is not
|
||||
* found.
|
||||
* A parameter annotation that marks a dependency as optional. {@link Injector} provides `null` if
|
||||
* the dependency is not found.
|
||||
*
|
||||
* ```
|
||||
* class AComponent {
|
||||
@@ -75,16 +72,15 @@ export class InjectLazy {
|
||||
*
|
||||
* @exportedAs angular2/di_annotations
|
||||
*/
|
||||
@CONST()
|
||||
export class Optional {
|
||||
@CONST()
|
||||
constructor() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* `DependencyAnnotation` is used by the framework to extend DI.
|
||||
*
|
||||
* Only annotations implementing `DependencyAnnotation` are added to the list of dependency properties.
|
||||
* Only annotations implementing `DependencyAnnotation` are added to the list of dependency
|
||||
* properties.
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
@@ -108,19 +104,14 @@ export class Optional {
|
||||
*
|
||||
* @exportedAs angular2/di_annotations
|
||||
*/
|
||||
@CONST()
|
||||
export class DependencyAnnotation {
|
||||
@CONST()
|
||||
constructor() {
|
||||
}
|
||||
|
||||
get token() {
|
||||
return null;
|
||||
}
|
||||
get token() { return null; }
|
||||
}
|
||||
|
||||
/**
|
||||
* A marker annotation that marks a class as available to `Injector` for creation. Used by tooling for
|
||||
* generating constructor stubs.
|
||||
* A marker annotation that marks a class as available to `Injector` for creation. Used by tooling
|
||||
* for generating constructor stubs.
|
||||
*
|
||||
* ```
|
||||
* class NeedsService {
|
||||
@@ -132,8 +123,6 @@ export class DependencyAnnotation {
|
||||
* ```
|
||||
* @exportedAs angular2/di_annotations
|
||||
*/
|
||||
@CONST()
|
||||
export class Injectable {
|
||||
@CONST()
|
||||
constructor() {
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,8 @@ import {
|
||||
InjectPromiseAnnotation,
|
||||
InjectLazyAnnotation,
|
||||
OptionalAnnotation,
|
||||
InjectableAnnotation} from './annotations';
|
||||
InjectableAnnotation
|
||||
} from './annotations';
|
||||
import {makeDecorator, makeParamDecorator} from '../util/decorators';
|
||||
|
||||
export var Inject = makeParamDecorator(InjectAnnotation);
|
||||
@@ -1,9 +1,9 @@
|
||||
import {ListWrapper, List} from 'angular2/src/facade/collection';
|
||||
import {stringify} from 'angular2/src/facade/lang';
|
||||
import {stringify, BaseException} from 'angular2/src/facade/lang';
|
||||
|
||||
function findFirstClosedCycle(keys:List):List {
|
||||
function findFirstClosedCycle(keys: List<any>): List<any> {
|
||||
var res = [];
|
||||
for(var i = 0; i < keys.length; ++i) {
|
||||
for (var i = 0; i < keys.length; ++i) {
|
||||
if (ListWrapper.contains(res, keys[i])) {
|
||||
ListWrapper.push(res, keys[i]);
|
||||
return res;
|
||||
@@ -14,7 +14,7 @@ function findFirstClosedCycle(keys:List):List {
|
||||
return res;
|
||||
}
|
||||
|
||||
function constructResolvingPath(keys:List):string {
|
||||
function constructResolvingPath(keys: List<any>): string {
|
||||
if (keys.length > 1) {
|
||||
var reversed = findFirstClosedCycle(ListWrapper.reversed(keys));
|
||||
var tokenStrs = ListWrapper.map(reversed, (k) => stringify(k.token));
|
||||
@@ -30,12 +30,13 @@ function constructResolvingPath(keys:List):string {
|
||||
*
|
||||
* @exportedAs angular2/di_errors
|
||||
*/
|
||||
export class AbstractBindingError extends Error {
|
||||
keys:List;
|
||||
constructResolvingMessage:Function;
|
||||
message;
|
||||
export class AbstractBindingError extends BaseException {
|
||||
name: string;
|
||||
message: string;
|
||||
keys: List<any>;
|
||||
constructResolvingMessage: Function;
|
||||
// TODO(tbosch): Can't do key:Key as this results in a circular dependency!
|
||||
constructor(key, constructResolvingMessage:Function) {
|
||||
constructor(key, constructResolvingMessage: Function) {
|
||||
super();
|
||||
this.keys = [key];
|
||||
this.constructResolvingMessage = constructResolvingMessage;
|
||||
@@ -43,26 +44,24 @@ export class AbstractBindingError extends Error {
|
||||
}
|
||||
|
||||
// TODO(tbosch): Can't do key:Key as this results in a circular dependency!
|
||||
addKey(key):void {
|
||||
addKey(key): void {
|
||||
ListWrapper.push(this.keys, key);
|
||||
this.message = this.constructResolvingMessage(this.keys);
|
||||
}
|
||||
|
||||
toString():string {
|
||||
return this.message;
|
||||
}
|
||||
toString(): string { return this.message; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown when trying to retrieve a dependency by `Key` from {@link Injector}, but the {@link Injector} does not have a
|
||||
* {@link Binding} for {@link Key}.
|
||||
* Thrown when trying to retrieve a dependency by `Key` from {@link Injector}, but the
|
||||
* {@link Injector} does not have a {@link Binding} for {@link Key}.
|
||||
*
|
||||
* @exportedAs angular2/di_errors
|
||||
*/
|
||||
export class NoBindingError extends AbstractBindingError {
|
||||
// TODO(tbosch): Can't do key:Key as this results in a circular dependency!
|
||||
constructor(key) {
|
||||
super(key, function (keys:List) {
|
||||
super(key, function (keys:List<any>) {
|
||||
var first = stringify(ListWrapper.first(keys).token);
|
||||
return `No provider for ${first}!${constructResolvingPath(keys)}`;
|
||||
});
|
||||
@@ -88,18 +87,17 @@ export class NoBindingError extends AbstractBindingError {
|
||||
* }).toThrowError(AsycBindingError);
|
||||
* ```
|
||||
*
|
||||
* The above example throws because `String` depends on `Number` which is async. If any binding in the dependency
|
||||
* graph is async then the graph can only be retrieved using the `asyncGet` API.
|
||||
* The above example throws because `String` depends on `Number` which is async. If any binding in
|
||||
* the dependency graph is async then the graph can only be retrieved using the `asyncGet` API.
|
||||
*
|
||||
* @exportedAs angular2/di_errors
|
||||
*/
|
||||
export class AsyncBindingError extends AbstractBindingError {
|
||||
// TODO(tbosch): Can't do key:Key as this results in a circular dependency!
|
||||
constructor(key) {
|
||||
super(key, function (keys:List) {
|
||||
super(key, function (keys:List<any>) {
|
||||
var first = stringify(ListWrapper.first(keys).token);
|
||||
return `Cannot instantiate ${first} synchronously. ` +
|
||||
`It is provided as a promise!${constructResolvingPath(keys)}`;
|
||||
return `Cannot instantiate ${first} synchronously. It is provided as a promise!${constructResolvingPath(keys)}`;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -125,7 +123,7 @@ export class AsyncBindingError extends AbstractBindingError {
|
||||
export class CyclicDependencyError extends AbstractBindingError {
|
||||
// TODO(tbosch): Can't do key:Key as this results in a circular dependency!
|
||||
constructor(key) {
|
||||
super(key, function (keys:List) {
|
||||
super(key, function (keys:List<any>) {
|
||||
return `Cannot instantiate cyclic dependency!${constructResolvingPath(keys)}`;
|
||||
});
|
||||
}
|
||||
@@ -134,8 +132,8 @@ export class CyclicDependencyError extends AbstractBindingError {
|
||||
/**
|
||||
* Thrown when a constructing type returns with an Error.
|
||||
*
|
||||
* The `InstantiationError` class contains the original error plus the dependency graph which caused this object to be
|
||||
* instantiated.
|
||||
* The `InstantiationError` class contains the original error plus the dependency graph which caused
|
||||
* this object to be instantiated.
|
||||
*
|
||||
* @exportedAs angular2/di_errors
|
||||
*/
|
||||
@@ -144,10 +142,9 @@ export class InstantiationError extends AbstractBindingError {
|
||||
causeKey;
|
||||
// TODO(tbosch): Can't do key:Key as this results in a circular dependency!
|
||||
constructor(cause, key) {
|
||||
super(key, function (keys:List) {
|
||||
super(key, function (keys:List<any>) {
|
||||
var first = stringify(ListWrapper.first(keys).token);
|
||||
return `Error during instantiation of ${first}!${constructResolvingPath(keys)}.` +
|
||||
` ORIGINAL ERROR: ${cause}`;
|
||||
return `Error during instantiation of ${first}!${constructResolvingPath(keys)}. ORIGINAL ERROR: ${cause}`;
|
||||
});
|
||||
this.cause = cause;
|
||||
this.causeKey = key;
|
||||
@@ -155,39 +152,38 @@ export class InstantiationError extends AbstractBindingError {
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown when an object other then {@link Binding} (or `Type`) is passed to {@link Injector} creation.
|
||||
* Thrown when an object other then {@link Binding} (or `Type`) is passed to {@link Injector}
|
||||
* creation.
|
||||
*
|
||||
* @exportedAs angular2/di_errors
|
||||
*/
|
||||
export class InvalidBindingError extends Error {
|
||||
message:string;
|
||||
export class InvalidBindingError extends BaseException {
|
||||
message: string;
|
||||
constructor(binding) {
|
||||
super();
|
||||
this.message = `Invalid binding - only instances of Binding and Type are allowed, got: ${binding}`;
|
||||
this.message = "Invalid binding - only instances of Binding and Type are allowed, got: " +
|
||||
binding.toString();
|
||||
}
|
||||
|
||||
toString():string {
|
||||
return this.message;
|
||||
}
|
||||
toString(): string { return this.message; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown when the class has no annotation information.
|
||||
*
|
||||
* Lack of annotation information prevents the {@link Injector} from determining which dependencies need to be injected into
|
||||
* the constructor.
|
||||
* Lack of annotation information prevents the {@link Injector} from determining which dependencies
|
||||
* need to be injected into the constructor.
|
||||
*
|
||||
* @exportedAs angular2/di_errors
|
||||
*/
|
||||
export class NoAnnotationError extends Error {
|
||||
message:string;
|
||||
export class NoAnnotationError extends BaseException {
|
||||
name: string;
|
||||
message: string;
|
||||
constructor(typeOrFunc) {
|
||||
super();
|
||||
this.message = `Cannot resolve all parameters for ${stringify(typeOrFunc)}.` +
|
||||
` Make sure they all have valid type or annotations.`;
|
||||
this.message = "Cannot resolve all parameters for " + stringify(typeOrFunc) + ". " +
|
||||
'Make sure they all have valid type or annotations.';
|
||||
}
|
||||
|
||||
toString():string {
|
||||
return this.message;
|
||||
}
|
||||
toString(): string { return this.message; }
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -16,42 +16,34 @@ import {stringify} from 'angular2/src/facade/lang';
|
||||
* @exportedAs angular2/di
|
||||
*/
|
||||
export class Key {
|
||||
token;
|
||||
id/* :int */;
|
||||
constructor(token, id/* :int */) {
|
||||
token: Object;
|
||||
id: number;
|
||||
constructor(token: Object, id: number) {
|
||||
this.token = token;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
get displayName() {
|
||||
return stringify(this.token);
|
||||
}
|
||||
get displayName() { return stringify(this.token); }
|
||||
|
||||
/**
|
||||
* Retrieves a `Key` for a token.
|
||||
*/
|
||||
static get(token):Key {
|
||||
return _globalKeyRegistry.get(token);
|
||||
}
|
||||
static get(token): Key { return _globalKeyRegistry.get(token); }
|
||||
|
||||
/**
|
||||
* @returns the number of keys registered in the system.
|
||||
*/
|
||||
static get numberOfKeys()/* :int */ {
|
||||
return _globalKeyRegistry.numberOfKeys;
|
||||
}
|
||||
static get numberOfKeys(): number { return _globalKeyRegistry.numberOfKeys; }
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
export class KeyRegistry {
|
||||
_allKeys:Map;
|
||||
constructor() {
|
||||
this._allKeys = MapWrapper.create();
|
||||
}
|
||||
_allKeys: Map<Object, Key>;
|
||||
constructor() { this._allKeys = MapWrapper.create(); }
|
||||
|
||||
get(token):Key {
|
||||
get(token: Object): Key {
|
||||
if (token instanceof Key) return token;
|
||||
|
||||
if (MapWrapper.contains(this._allKeys, token)) {
|
||||
@@ -63,9 +55,7 @@ export class KeyRegistry {
|
||||
return newKey;
|
||||
}
|
||||
|
||||
get numberOfKeys()/* :int */ {
|
||||
return MapWrapper.size(this._allKeys);
|
||||
}
|
||||
get numberOfKeys() /* :int */ { return MapWrapper.size(this._allKeys); }
|
||||
}
|
||||
|
||||
var _globalKeyRegistry = new KeyRegistry();
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @exportedAs angular2/di
|
||||
*/
|
||||
export class OpaqueToken {
|
||||
_desc:string;
|
||||
|
||||
constructor(desc:string){
|
||||
this._desc = `Token(${desc})`;
|
||||
}
|
||||
|
||||
toString():string {
|
||||
return this._desc;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @exportedAs angular2/di
|
||||
*/
|
||||
export class OpaqueToken {
|
||||
_desc: string;
|
||||
|
||||
constructor(desc: string) { this._desc = `Token(${desc})`; }
|
||||
|
||||
toString(): string { return this._desc; }
|
||||
}
|
||||
@@ -10,6 +10,8 @@ import {int, global, isPresent} from 'angular2/src/facade/lang';
|
||||
import {List} from 'angular2/src/facade/collection';
|
||||
import * as Rx from 'rx';
|
||||
|
||||
export var Promise = (<any>global).Promise;
|
||||
|
||||
export class PromiseWrapper {
|
||||
static resolve(obj): Promise<any> { return Promise.resolve(obj); }
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ class FunctionWrapper {
|
||||
class BaseException extends Error {
|
||||
final String message;
|
||||
|
||||
BaseException(this.message);
|
||||
BaseException([this.message]);
|
||||
|
||||
String toString() {
|
||||
return this.message;
|
||||
|
||||
@@ -9,6 +9,18 @@ export var __esModule = true;
|
||||
export var Type = Function;
|
||||
export type Type = typeof Function;
|
||||
|
||||
export class BaseException extends Error {
|
||||
message;
|
||||
stack;
|
||||
constructor(message?: string) {
|
||||
super(message);
|
||||
this.message = message;
|
||||
this.stack = (<any>new Error()).stack;
|
||||
}
|
||||
|
||||
toString(): string { return this.message; }
|
||||
}
|
||||
|
||||
export var Math = _global.Math;
|
||||
export var Date = _global.Date;
|
||||
|
||||
@@ -28,7 +40,9 @@ if (assertionsEnabled_) {
|
||||
}
|
||||
export {int};
|
||||
|
||||
export class CONST {}
|
||||
export function CONST() {
|
||||
return (target) => target;
|
||||
};
|
||||
export class ABSTRACT {}
|
||||
export class IMPLEMENTS {}
|
||||
|
||||
@@ -111,10 +125,10 @@ export class StringJoiner {
|
||||
toString(): string { return this.parts.join(""); }
|
||||
}
|
||||
|
||||
export class NumberParseError implements Error {
|
||||
export class NumberParseError extends BaseException {
|
||||
name: string;
|
||||
|
||||
constructor(public message: string) {}
|
||||
constructor(public message: string) { super(); }
|
||||
|
||||
toString() { return this.message; }
|
||||
}
|
||||
@@ -191,9 +205,6 @@ export class FunctionWrapper {
|
||||
static apply(fn: Function, posArgs) { return fn.apply(null, posArgs); }
|
||||
}
|
||||
|
||||
// No subclass so that we preserve error stack.
|
||||
export var BaseException = Error;
|
||||
|
||||
// JS has NaN !== NaN
|
||||
export function looseIdentical(a, b): boolean {
|
||||
return a === b || typeof a === "number" && typeof b === "number" && isNaN(a) && isNaN(b);
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
library util_decorators;
|
||||
@@ -1,12 +1,16 @@
|
||||
export var __esModule = true;
|
||||
|
||||
import {global} from 'angular2/src/facade/lang';
|
||||
|
||||
export function makeDecorator(annotationCls) {
|
||||
return function(...args) {
|
||||
return function() {
|
||||
var args = arguments;
|
||||
var Reflect = global.Reflect;
|
||||
if (!(Reflect && Reflect.getMetadata)) {
|
||||
throw 'reflect-metadata shim is required when using class decorators';
|
||||
}
|
||||
var annotationInstance = new annotationCls(...args);
|
||||
var annotationInstance = Object.create(annotationCls);
|
||||
annotationInstance.call(annotationInstance, args);
|
||||
return function(cls) {
|
||||
var annotations = Reflect.getMetadata('annotations', cls);
|
||||
annotations = annotations || [];
|
||||
@@ -18,12 +22,14 @@ export function makeDecorator(annotationCls) {
|
||||
}
|
||||
|
||||
export function makeParamDecorator(annotationCls) {
|
||||
return function(...args) {
|
||||
return function() {
|
||||
var args = arguments;
|
||||
var Reflect = global.Reflect;
|
||||
if (!(Reflect && Reflect.getMetadata)) {
|
||||
throw 'reflect-metadata shim is required when using parameter decorators';
|
||||
}
|
||||
var annotationInstance = new annotationCls(...args);
|
||||
var annotationInstance = Object.create(annotationCls);
|
||||
annotationInstance.call(annotationInstance, args);
|
||||
return function(cls, unusedKey, index) {
|
||||
var parameters = Reflect.getMetadata('parameters', cls);
|
||||
parameters = parameters || [];
|
||||
Reference in New Issue
Block a user