Copy a second package to TypeScript.

This commit is contained in:
Alex Eagle 2015-04-24 13:17:36 -07:00
parent b5e350b18c
commit 623edcd2d8
7 changed files with 176 additions and 4 deletions

View File

@ -530,7 +530,7 @@ gulp.task('build/pure-packages.dart', function() {
// `modules_dart`, so they have to walk up and into `dist`. // `modules_dart`, so they have to walk up and into `dist`.
// //
// Example: // Example:
// //
// dependency_overrides: // dependency_overrides:
// angular2: // angular2:
// path: ../../dist/dart/angular2 // path: ../../dist/dart/angular2
@ -538,7 +538,7 @@ gulp.task('build/pure-packages.dart', function() {
// When we copy a pure package into `dist` the relative path // When we copy a pure package into `dist` the relative path
// must be updated. The code below replaces paths accordingly. // must be updated. The code below replaces paths accordingly.
// So the example above is turned into: // So the example above is turned into:
// //
// dependency_overrides: // dependency_overrides:
// angular2: // angular2:
// path: ../angular2 // path: ../angular2

View File

@ -7,6 +7,8 @@ export {_global as global};
export var __esModule = true; export var __esModule = true;
export var Type = Function; export var Type = Function;
export type Type = typeof Function;
export var Math = _global.Math; export var Math = _global.Math;
export var Date = _global.Date; export var Date = _global.Date;

View File

@ -0,0 +1,12 @@
import {Type, isPresent} from 'angular2/src/facade/lang';
import {List, ListWrapper} from 'angular2/src/facade/collection';
import {Reflector} from './reflector';
export {Reflector} from './reflector';
import {ReflectionCapabilities} from './reflection_capabilities';
// 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;
export var reflector = new Reflector(new ReflectionCapabilities());

View File

@ -0,0 +1,66 @@
import {Type, isPresent} from 'angular2/src/facade/lang';
import {List, ListWrapper} from 'angular2/src/facade/collection';
import {GetterFn, SetterFn, MethodFn} from './types';
// 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;
export class ReflectionCapabilities {
factory(type: Type): Function {
switch (type.length) {
case 0:
return function() { return new type(); };
case 1:
return function(a1) { return new type(a1); };
case 2:
return function(a1, a2) { return new type(a1, a2); };
case 3:
return function(a1, a2, a3) { return new type(a1, a2, a3); };
case 4:
return function(a1, a2, a3, a4) { return new type(a1, a2, a3, a4); };
case 5:
return function(a1, a2, a3, a4, a5) { return new type(a1, a2, a3, a4, a5); };
case 6:
return function(a1, a2, a3, a4, a5, a6) { return new type(a1, a2, a3, a4, a5, a6); };
case 7:
return function(a1, a2, a3, a4, a5, a6, a7) {
return new type(a1, a2, a3, a4, a5, a6, a7);
};
case 8:
return function(a1, a2, a3, a4, a5, a6, a7, a8) {
return new type(a1, a2, a3, a4, a5, a6, a7, a8);
};
case 9:
return function(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
return new type(a1, a2, a3, a4, a5, a6, a7, a8, a9);
};
case 10:
return function(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
return new type(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
};
};
throw new Error("Factory cannot take more than 10 arguments");
}
parameters(typeOfFunc): List<List<any>> {
return isPresent(typeOfFunc.parameters) ? typeOfFunc.parameters :
ListWrapper.createFixedSize(typeOfFunc.length);
}
annotations(typeOfFunc): List<any> {
return isPresent(typeOfFunc.annotations) ? typeOfFunc.annotations : [];
}
getter(name: string): GetterFn { return new Function('o', 'return o.' + name + ';'); }
setter(name: string): SetterFn { return new Function('o', 'v', 'return o.' + name + ' = v;'); }
method(name: string): MethodFn {
let functionBody = `if (!o.${name}) throw new Error('"${name}" is undefined');
return o.${name}.apply(o, args);`;
return new Function('o', 'args', functionBody);
}
}

View File

@ -0,0 +1,85 @@
import {Type, isPresent, stringify, BaseException} from 'angular2/src/facade/lang';
import {List, ListWrapper, Map, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
import {SetterFn, GetterFn, MethodFn} from './types';
export {SetterFn, GetterFn, MethodFn} from './types';
// 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;
export class Reflector {
_typeInfo: Map<any, any>;
_getters: Map<any, any>;
_setters: Map<any, any>;
_methods: Map<any, any>;
reflectionCapabilities: any;
constructor(reflectionCapabilities) {
this._typeInfo = MapWrapper.create();
this._getters = MapWrapper.create();
this._setters = MapWrapper.create();
this._methods = MapWrapper.create();
this.reflectionCapabilities = reflectionCapabilities;
}
registerType(type, typeInfo) { MapWrapper.set(this._typeInfo, type, typeInfo); }
registerGetters(getters) { _mergeMaps(this._getters, getters); }
registerSetters(setters) { _mergeMaps(this._setters, setters); }
registerMethods(methods) { _mergeMaps(this._methods, methods); }
factory(type: Type): Function {
if (MapWrapper.contains(this._typeInfo, type)) {
return MapWrapper.get(this._typeInfo, type)["factory"];
} else {
return this.reflectionCapabilities.factory(type);
}
}
parameters(typeOfFunc): List<any> {
if (MapWrapper.contains(this._typeInfo, typeOfFunc)) {
return MapWrapper.get(this._typeInfo, typeOfFunc)["parameters"];
} else {
return this.reflectionCapabilities.parameters(typeOfFunc);
}
}
annotations(typeOfFunc): List<any> {
if (MapWrapper.contains(this._typeInfo, typeOfFunc)) {
return MapWrapper.get(this._typeInfo, typeOfFunc)["annotations"];
} else {
return this.reflectionCapabilities.annotations(typeOfFunc);
}
}
getter(name: string): GetterFn {
if (MapWrapper.contains(this._getters, name)) {
return MapWrapper.get(this._getters, name);
} else {
return this.reflectionCapabilities.getter(name);
}
}
setter(name: string): SetterFn {
if (MapWrapper.contains(this._setters, name)) {
return MapWrapper.get(this._setters, name);
} else {
return this.reflectionCapabilities.setter(name);
}
}
method(name: string): MethodFn {
if (MapWrapper.contains(this._methods, name)) {
return MapWrapper.get(this._methods, name);
} else {
return this.reflectionCapabilities.method(name);
}
}
}
function _mergeMaps(target: Map<any, any>, config) {
StringMapWrapper.forEach(config, (v, k) => MapWrapper.set(target, k, v));
}

View File

@ -0,0 +1,8 @@
// 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;
export {Function as SetterFn};
export {Function as GetterFn};
export {Function as MethodFn};

View File

@ -54,14 +54,13 @@ export class BroccoliBuilder {
printSlowTrees(hash.graph); printSlowTrees(hash.graph);
}) })
.catch(err => { .catch(err => {
console.log(err.toString());
// Should show file and line/col if present // Should show file and line/col if present
if (err.file) { if (err.file) {
console.error('File: ' + err.file); console.error('File: ' + err.file);
} }
if (err.stack) { if (err.stack) {
console.error(err.stack); console.error(err.stack);
} else {
console.error(err);
} }
throw err; throw err;
}); });