2016-02-18 10:53:21 -08:00
|
|
|
import {StringMapWrapper, ListWrapper} from 'angular2/src/facade/collection';
|
2016-04-12 09:40:37 -07:00
|
|
|
import {
|
|
|
|
isArray,
|
|
|
|
isPresent,
|
2016-02-18 10:53:21 -08:00
|
|
|
isBlank,
|
2016-04-12 09:40:37 -07:00
|
|
|
isPrimitive,
|
2016-02-18 10:53:21 -08:00
|
|
|
isStringMap,
|
|
|
|
FunctionWrapper
|
2016-04-12 09:40:37 -07:00
|
|
|
} from 'angular2/src/facade/lang';
|
|
|
|
import {
|
|
|
|
AttributeMetadata,
|
|
|
|
DirectiveMetadata,
|
|
|
|
ComponentMetadata,
|
|
|
|
ContentChildrenMetadata,
|
|
|
|
ContentChildMetadata,
|
|
|
|
InputMetadata,
|
|
|
|
HostBindingMetadata,
|
|
|
|
HostListenerMetadata,
|
|
|
|
OutputMetadata,
|
|
|
|
PipeMetadata,
|
|
|
|
ViewChildMetadata,
|
|
|
|
ViewChildrenMetadata,
|
|
|
|
ViewQueryMetadata,
|
|
|
|
QueryMetadata,
|
|
|
|
} from 'angular2/src/core/metadata';
|
2016-02-18 10:53:21 -08:00
|
|
|
import {ReflectorReader} from 'angular2/src/core/reflection/reflector_reader';
|
2016-02-18 10:53:21 -08:00
|
|
|
import {reflector} from 'angular2/src/core/reflection/reflection';
|
|
|
|
import {Provider} from 'angular2/src/core/di/provider';
|
|
|
|
import {
|
|
|
|
HostMetadata,
|
|
|
|
OptionalMetadata,
|
|
|
|
InjectableMetadata,
|
|
|
|
SelfMetadata,
|
|
|
|
SkipSelfMetadata,
|
2016-04-29 14:34:01 -07:00
|
|
|
InjectMetadata,
|
2016-02-18 10:53:21 -08:00
|
|
|
} from "angular2/src/core/di/metadata";
|
2016-04-28 21:54:02 -07:00
|
|
|
|
2016-03-24 10:03:10 -07:00
|
|
|
/**
|
|
|
|
* The host of the static resolver is expected to be able to provide module metadata in the form of
|
|
|
|
* ModuleMetadata. Angular 2 CLI will produce this metadata for a module whenever a .d.ts files is
|
|
|
|
* produced and the module has exported variables or classes with decorators. Module metadata can
|
|
|
|
* also be produced directly from TypeScript sources by using MetadataCollector in tools/metadata.
|
|
|
|
*/
|
|
|
|
export interface StaticReflectorHost {
|
|
|
|
/**
|
2016-04-25 21:29:06 -07:00
|
|
|
* Return a ModuleMetadata for the given module.
|
2016-03-24 10:03:10 -07:00
|
|
|
*
|
2016-04-25 21:29:06 -07:00
|
|
|
* @param moduleId is a string identifier for a module as an absolute path.
|
2016-03-24 10:03:10 -07:00
|
|
|
* @returns the metadata for the given module.
|
|
|
|
*/
|
2016-02-18 10:53:21 -08:00
|
|
|
getMetadataFor(modulePath: string): {[key: string]: any};
|
2016-04-25 21:29:06 -07:00
|
|
|
|
|
|
|
/**
|
2016-04-28 21:54:02 -07:00
|
|
|
* Resolve a symbol from an import statement form, to the file where it is declared.
|
|
|
|
* @param module the location imported from
|
2016-04-25 21:29:06 -07:00
|
|
|
* @param containingFile for relative imports, the path of the file containing the import
|
|
|
|
*/
|
2016-04-28 21:54:02 -07:00
|
|
|
findDeclaration(modulePath: string, symbolName: string, containingFile?: string): StaticSymbol;
|
2016-02-18 10:53:21 -08:00
|
|
|
|
2016-04-28 21:54:02 -07:00
|
|
|
getStaticSymbol(moduleId: string, declarationFile: string, name: string): StaticSymbol;
|
2016-03-24 10:03:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A token representing the a reference to a static type.
|
|
|
|
*
|
|
|
|
* This token is unique for a moduleId and name and can be used as a hash table key.
|
|
|
|
*/
|
2016-04-29 16:27:21 -07:00
|
|
|
export class StaticSymbol {
|
2016-04-28 21:54:02 -07:00
|
|
|
constructor(public moduleId: string, public filePath: string, public name: string) {}
|
2016-03-24 10:03:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A static reflector implements enough of the Reflector API that is necessary to compile
|
|
|
|
* templates statically.
|
|
|
|
*/
|
2016-02-18 10:53:21 -08:00
|
|
|
export class StaticReflector implements ReflectorReader {
|
2016-04-28 21:54:02 -07:00
|
|
|
private annotationCache = new Map<StaticSymbol, any[]>();
|
|
|
|
private propertyCache = new Map<StaticSymbol, {[key: string]: any}>();
|
|
|
|
private parameterCache = new Map<StaticSymbol, any[]>();
|
2016-03-24 10:03:10 -07:00
|
|
|
private metadataCache = new Map<string, {[key: string]: any}>();
|
2016-04-29 16:27:21 -07:00
|
|
|
private conversionMap = new Map<StaticSymbol, (context: StaticSymbol, args: any[]) => any>();
|
2016-02-18 10:53:21 -08:00
|
|
|
|
2016-03-24 10:03:10 -07:00
|
|
|
constructor(private host: StaticReflectorHost) { this.initializeConversionMap(); }
|
|
|
|
|
2016-04-28 21:54:02 -07:00
|
|
|
importUri(typeOrFunc: any): string { return (<StaticSymbol>typeOrFunc).filePath; }
|
2016-02-18 10:53:21 -08:00
|
|
|
|
2016-04-28 21:54:02 -07:00
|
|
|
public annotations(type: StaticSymbol): any[] {
|
2016-03-24 10:03:10 -07:00
|
|
|
let annotations = this.annotationCache.get(type);
|
|
|
|
if (!isPresent(annotations)) {
|
|
|
|
let classMetadata = this.getTypeMetadata(type);
|
|
|
|
if (isPresent(classMetadata['decorators'])) {
|
2016-04-29 14:34:01 -07:00
|
|
|
annotations = this.simplify(type, classMetadata['decorators']);
|
2016-04-08 15:39:21 -07:00
|
|
|
} else {
|
|
|
|
annotations = [];
|
2016-03-24 10:03:10 -07:00
|
|
|
}
|
2016-02-18 10:53:21 -08:00
|
|
|
this.annotationCache.set(type, annotations.filter(ann => isPresent(ann)));
|
2016-03-24 10:03:10 -07:00
|
|
|
}
|
|
|
|
return annotations;
|
|
|
|
}
|
|
|
|
|
2016-04-28 21:54:02 -07:00
|
|
|
public propMetadata(type: StaticSymbol): {[key: string]: any} {
|
2016-03-24 10:03:10 -07:00
|
|
|
let propMetadata = this.propertyCache.get(type);
|
|
|
|
if (!isPresent(propMetadata)) {
|
|
|
|
let classMetadata = this.getTypeMetadata(type);
|
2016-02-18 10:53:21 -08:00
|
|
|
let members = isPresent(classMetadata) ? classMetadata['members'] : {};
|
|
|
|
propMetadata = mapStringMap(members, (propData, propName) => {
|
|
|
|
let prop = (<any[]>propData).find(a => a['__symbolic'] == 'property');
|
|
|
|
if (isPresent(prop) && isPresent(prop['decorators'])) {
|
2016-04-29 14:34:01 -07:00
|
|
|
return this.simplify(type, prop['decorators']);
|
2016-02-18 10:53:21 -08:00
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
});
|
2016-03-24 10:03:10 -07:00
|
|
|
this.propertyCache.set(type, propMetadata);
|
|
|
|
}
|
|
|
|
return propMetadata;
|
|
|
|
}
|
|
|
|
|
2016-04-28 21:54:02 -07:00
|
|
|
public parameters(type: StaticSymbol): any[] {
|
2016-04-29 14:34:01 -07:00
|
|
|
try {
|
|
|
|
let parameters = this.parameterCache.get(type);
|
2016-04-08 15:39:21 -07:00
|
|
|
if (!isPresent(parameters)) {
|
2016-04-29 14:34:01 -07:00
|
|
|
let classMetadata = this.getTypeMetadata(type);
|
|
|
|
let members = isPresent(classMetadata) ? classMetadata['members'] : null;
|
|
|
|
let ctorData = isPresent(members) ? members['__ctor__'] : null;
|
|
|
|
if (isPresent(ctorData)) {
|
|
|
|
let ctor = (<any[]>ctorData).find(a => a['__symbolic'] == 'constructor');
|
|
|
|
let parameterTypes = <any[]>this.simplify(type, ctor['parameters']);
|
|
|
|
let parameterDecorators = <any[]>this.simplify(type, ctor['parameterDecorators']);
|
|
|
|
|
|
|
|
parameters = [];
|
|
|
|
ListWrapper.forEachWithIndex(parameterTypes, (paramType, index) => {
|
2016-04-30 12:27:37 -07:00
|
|
|
let nestedResult: any[] = [];
|
2016-04-29 14:34:01 -07:00
|
|
|
if (isPresent(paramType)) {
|
|
|
|
nestedResult.push(paramType);
|
|
|
|
}
|
|
|
|
let decorators = isPresent(parameterDecorators) ? parameterDecorators[index] : null;
|
|
|
|
if (isPresent(decorators)) {
|
|
|
|
ListWrapper.addAll(nestedResult, decorators);
|
|
|
|
}
|
|
|
|
parameters.push(nestedResult);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (!isPresent(parameters)) {
|
|
|
|
parameters = [];
|
|
|
|
}
|
|
|
|
this.parameterCache.set(type, parameters);
|
2016-04-08 15:39:21 -07:00
|
|
|
}
|
2016-04-29 14:34:01 -07:00
|
|
|
return parameters;
|
|
|
|
} catch (e) {
|
2016-04-29 16:27:21 -07:00
|
|
|
console.log(`Failed on type ${type} with error ${e}`);
|
2016-04-29 14:34:01 -07:00
|
|
|
throw e;
|
2016-03-24 10:03:10 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 14:34:01 -07:00
|
|
|
private registerDecoratorOrConstructor(type: StaticSymbol, ctor: any): void {
|
2016-04-29 16:27:21 -07:00
|
|
|
this.conversionMap.set(type, (context: StaticSymbol, args: any[]) => {
|
2016-04-30 12:27:37 -07:00
|
|
|
let argValues: any[] = [];
|
2016-02-18 10:53:21 -08:00
|
|
|
ListWrapper.forEachWithIndex(args, (arg, index) => {
|
2016-04-30 12:27:37 -07:00
|
|
|
let argValue: any;
|
2016-02-18 10:53:21 -08:00
|
|
|
if (isStringMap(arg) && isBlank(arg['__symbolic'])) {
|
2016-04-29 16:27:21 -07:00
|
|
|
argValue = mapStringMap(arg, (value, key) => this.simplify(context, value));
|
2016-02-18 10:53:21 -08:00
|
|
|
} else {
|
2016-04-29 16:27:21 -07:00
|
|
|
argValue = this.simplify(context, arg);
|
2016-02-18 10:53:21 -08:00
|
|
|
}
|
|
|
|
argValues.push(argValue);
|
2016-03-24 10:03:10 -07:00
|
|
|
});
|
2016-02-18 10:53:21 -08:00
|
|
|
return FunctionWrapper.apply(reflector.factory(ctor), argValues);
|
2016-03-24 10:03:10 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-02-18 10:53:21 -08:00
|
|
|
private initializeConversionMap(): void {
|
2016-04-28 21:54:02 -07:00
|
|
|
let coreDecorators = 'angular2/src/core/metadata';
|
|
|
|
let diDecorators = 'angular2/src/core/di/decorators';
|
|
|
|
let diMetadata = 'angular2/src/core/di/metadata';
|
|
|
|
let provider = 'angular2/src/core/di/provider';
|
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(provider, 'Provider'), Provider);
|
2016-03-24 10:03:10 -07:00
|
|
|
|
2016-04-28 21:54:02 -07:00
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(diDecorators, 'Host'),
|
|
|
|
HostMetadata);
|
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(diDecorators, 'Injectable'),
|
2016-02-18 10:53:21 -08:00
|
|
|
InjectableMetadata);
|
2016-04-28 21:54:02 -07:00
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(diDecorators, 'Self'),
|
|
|
|
SelfMetadata);
|
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(diDecorators, 'SkipSelf'),
|
2016-02-18 10:53:21 -08:00
|
|
|
SkipSelfMetadata);
|
2016-04-28 21:54:02 -07:00
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(diDecorators, 'Inject'),
|
|
|
|
InjectMetadata);
|
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(diDecorators, 'Optional'),
|
2016-02-18 10:53:21 -08:00
|
|
|
OptionalMetadata);
|
2016-04-28 21:54:02 -07:00
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(coreDecorators, 'Attribute'),
|
2016-02-18 10:53:21 -08:00
|
|
|
AttributeMetadata);
|
2016-04-28 21:54:02 -07:00
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(coreDecorators, 'Query'),
|
|
|
|
QueryMetadata);
|
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(coreDecorators, 'ViewQuery'),
|
2016-02-18 10:53:21 -08:00
|
|
|
ViewQueryMetadata);
|
2016-04-28 21:54:02 -07:00
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(coreDecorators, 'ContentChild'),
|
2016-02-18 10:53:21 -08:00
|
|
|
ContentChildMetadata);
|
2016-04-28 21:54:02 -07:00
|
|
|
this.registerDecoratorOrConstructor(
|
|
|
|
this.host.findDeclaration(coreDecorators, 'ContentChildren'), ContentChildrenMetadata);
|
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(coreDecorators, 'ViewChild'),
|
2016-02-18 10:53:21 -08:00
|
|
|
ViewChildMetadata);
|
2016-04-28 21:54:02 -07:00
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(coreDecorators, 'ViewChildren'),
|
2016-02-18 10:53:21 -08:00
|
|
|
ViewChildrenMetadata);
|
2016-04-28 21:54:02 -07:00
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(coreDecorators, 'Input'),
|
|
|
|
InputMetadata);
|
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(coreDecorators, 'Output'),
|
2016-02-18 10:53:21 -08:00
|
|
|
OutputMetadata);
|
2016-04-28 21:54:02 -07:00
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(coreDecorators, 'Pipe'),
|
|
|
|
PipeMetadata);
|
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(coreDecorators, 'HostBinding'),
|
2016-02-18 10:53:21 -08:00
|
|
|
HostBindingMetadata);
|
2016-04-28 21:54:02 -07:00
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(coreDecorators, 'HostListener'),
|
2016-02-18 10:53:21 -08:00
|
|
|
HostListenerMetadata);
|
2016-04-28 21:54:02 -07:00
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(coreDecorators, 'Directive'),
|
2016-04-29 14:34:01 -07:00
|
|
|
DirectiveMetadata);
|
2016-04-28 21:54:02 -07:00
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(coreDecorators, 'Component'),
|
2016-04-29 14:34:01 -07:00
|
|
|
ComponentMetadata);
|
2016-03-24 10:03:10 -07:00
|
|
|
|
2016-02-18 10:53:21 -08:00
|
|
|
// Note: Some metadata classes can be used directly with Provider.deps.
|
2016-04-28 21:54:02 -07:00
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(diMetadata, 'HostMetadata'),
|
2016-02-18 10:53:21 -08:00
|
|
|
HostMetadata);
|
2016-04-28 21:54:02 -07:00
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(diMetadata, 'SelfMetadata'),
|
2016-02-18 10:53:21 -08:00
|
|
|
SelfMetadata);
|
2016-04-28 21:54:02 -07:00
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(diMetadata, 'SkipSelfMetadata'),
|
2016-02-18 10:53:21 -08:00
|
|
|
SkipSelfMetadata);
|
2016-04-28 21:54:02 -07:00
|
|
|
this.registerDecoratorOrConstructor(this.host.findDeclaration(diMetadata, 'OptionalMetadata'),
|
2016-02-18 10:53:21 -08:00
|
|
|
OptionalMetadata);
|
2016-03-24 10:03:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @internal */
|
2016-04-29 16:27:21 -07:00
|
|
|
public simplify(context: StaticSymbol, value: any): any {
|
2016-03-24 10:03:10 -07:00
|
|
|
let _this = this;
|
|
|
|
|
|
|
|
function simplify(expression: any): any {
|
|
|
|
if (isPrimitive(expression)) {
|
|
|
|
return expression;
|
|
|
|
}
|
|
|
|
if (isArray(expression)) {
|
2016-04-30 12:27:37 -07:00
|
|
|
let result: any[] = [];
|
2016-04-12 09:40:37 -07:00
|
|
|
for (let item of(<any>expression)) {
|
2016-03-24 10:03:10 -07:00
|
|
|
result.push(simplify(item));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (isPresent(expression)) {
|
|
|
|
if (isPresent(expression['__symbolic'])) {
|
2016-04-30 12:27:37 -07:00
|
|
|
let staticSymbol: StaticSymbol;
|
2016-03-24 10:03:10 -07:00
|
|
|
switch (expression['__symbolic']) {
|
2016-04-12 09:40:37 -07:00
|
|
|
case "binop":
|
2016-03-24 10:03:10 -07:00
|
|
|
let left = simplify(expression['left']);
|
|
|
|
let right = simplify(expression['right']);
|
|
|
|
switch (expression['operator']) {
|
|
|
|
case '&&':
|
|
|
|
return left && right;
|
|
|
|
case '||':
|
|
|
|
return left || right;
|
|
|
|
case '|':
|
|
|
|
return left | right;
|
|
|
|
case '^':
|
|
|
|
return left ^ right;
|
|
|
|
case '&':
|
|
|
|
return left & right;
|
|
|
|
case '==':
|
|
|
|
return left == right;
|
|
|
|
case '!=':
|
|
|
|
return left != right;
|
|
|
|
case '===':
|
|
|
|
return left === right;
|
|
|
|
case '!==':
|
|
|
|
return left !== right;
|
|
|
|
case '<':
|
|
|
|
return left < right;
|
|
|
|
case '>':
|
|
|
|
return left > right;
|
|
|
|
case '<=':
|
|
|
|
return left <= right;
|
|
|
|
case '>=':
|
|
|
|
return left >= right;
|
|
|
|
case '<<':
|
|
|
|
return left << right;
|
|
|
|
case '>>':
|
|
|
|
return left >> right;
|
|
|
|
case '+':
|
|
|
|
return left + right;
|
|
|
|
case '-':
|
|
|
|
return left - right;
|
|
|
|
case '*':
|
|
|
|
return left * right;
|
|
|
|
case '/':
|
|
|
|
return left / right;
|
|
|
|
case '%':
|
|
|
|
return left % right;
|
|
|
|
}
|
|
|
|
return null;
|
2016-04-12 09:40:37 -07:00
|
|
|
case "pre":
|
2016-03-24 10:03:10 -07:00
|
|
|
let operand = simplify(expression['operand']);
|
|
|
|
switch (expression['operator']) {
|
|
|
|
case '+':
|
|
|
|
return operand;
|
|
|
|
case '-':
|
|
|
|
return -operand;
|
|
|
|
case '!':
|
|
|
|
return !operand;
|
|
|
|
case '~':
|
|
|
|
return ~operand;
|
|
|
|
}
|
|
|
|
return null;
|
2016-04-12 09:40:37 -07:00
|
|
|
case "index":
|
2016-03-24 10:03:10 -07:00
|
|
|
let indexTarget = simplify(expression['expression']);
|
|
|
|
let index = simplify(expression['index']);
|
|
|
|
if (isPresent(indexTarget) && isPrimitive(index)) return indexTarget[index];
|
|
|
|
return null;
|
2016-04-12 09:40:37 -07:00
|
|
|
case "select":
|
2016-03-24 10:03:10 -07:00
|
|
|
let selectTarget = simplify(expression['expression']);
|
|
|
|
let member = simplify(expression['member']);
|
|
|
|
if (isPresent(selectTarget) && isPrimitive(member)) return selectTarget[member];
|
|
|
|
return null;
|
2016-04-12 09:40:37 -07:00
|
|
|
case "reference":
|
2016-02-18 10:53:21 -08:00
|
|
|
if (isPresent(expression['module'])) {
|
2016-04-28 21:54:02 -07:00
|
|
|
staticSymbol = _this.host.findDeclaration(expression['module'], expression['name'],
|
2016-04-29 16:27:21 -07:00
|
|
|
context.filePath);
|
2016-04-28 21:54:02 -07:00
|
|
|
} else {
|
2016-04-29 16:27:21 -07:00
|
|
|
staticSymbol = _this.host.getStaticSymbol(context.moduleId, context.filePath,
|
|
|
|
expression['name']);
|
2016-02-18 10:53:21 -08:00
|
|
|
}
|
2016-04-29 14:34:01 -07:00
|
|
|
let result = staticSymbol;
|
|
|
|
let moduleMetadata = _this.getModuleMetadata(staticSymbol.filePath);
|
2016-04-29 16:27:21 -07:00
|
|
|
let declarationValue =
|
|
|
|
isPresent(moduleMetadata) ? moduleMetadata['metadata'][staticSymbol.name] : null;
|
2016-04-29 14:34:01 -07:00
|
|
|
if (isPresent(declarationValue)) {
|
2016-02-18 10:53:21 -08:00
|
|
|
if (isClassMetadata(declarationValue)) {
|
2016-04-28 21:54:02 -07:00
|
|
|
result = staticSymbol;
|
2016-02-18 10:53:21 -08:00
|
|
|
} else {
|
2016-04-29 16:27:21 -07:00
|
|
|
result = _this.simplify(staticSymbol, declarationValue);
|
2016-02-18 10:53:21 -08:00
|
|
|
}
|
2016-03-24 10:03:10 -07:00
|
|
|
}
|
2016-02-18 10:53:21 -08:00
|
|
|
return result;
|
2016-04-29 16:27:21 -07:00
|
|
|
case "class":
|
|
|
|
return context;
|
2016-02-18 10:53:21 -08:00
|
|
|
case "new":
|
2016-04-12 09:40:37 -07:00
|
|
|
case "call":
|
2016-02-18 10:53:21 -08:00
|
|
|
let target = expression['expression'];
|
2016-04-29 16:27:21 -07:00
|
|
|
staticSymbol =
|
|
|
|
_this.host.findDeclaration(target['module'], target['name'], context.filePath);
|
2016-04-28 21:54:02 -07:00
|
|
|
let converter = _this.conversionMap.get(staticSymbol);
|
2016-04-29 14:34:01 -07:00
|
|
|
if (isPresent(converter)) {
|
|
|
|
let args = expression['arguments'];
|
|
|
|
if (isBlank(args)) {
|
|
|
|
args = [];
|
|
|
|
}
|
2016-04-29 16:27:21 -07:00
|
|
|
return converter(context, args);
|
2016-04-29 14:34:01 -07:00
|
|
|
} else {
|
2016-04-29 16:27:21 -07:00
|
|
|
return context;
|
2016-02-18 10:53:21 -08:00
|
|
|
}
|
2016-03-24 10:03:10 -07:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2016-02-18 10:53:21 -08:00
|
|
|
return mapStringMap(expression, (value, name) => simplify(value));
|
2016-03-24 10:03:10 -07:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return simplify(value);
|
|
|
|
}
|
|
|
|
|
2016-04-25 21:29:06 -07:00
|
|
|
/**
|
|
|
|
* @param module an absolute path to a module file.
|
|
|
|
*/
|
2016-02-18 10:53:21 -08:00
|
|
|
public getModuleMetadata(module: string): {[key: string]: any} {
|
2016-03-24 10:03:10 -07:00
|
|
|
let moduleMetadata = this.metadataCache.get(module);
|
|
|
|
if (!isPresent(moduleMetadata)) {
|
|
|
|
moduleMetadata = this.host.getMetadataFor(module);
|
|
|
|
if (!isPresent(moduleMetadata)) {
|
2016-04-12 09:40:37 -07:00
|
|
|
moduleMetadata = {__symbolic: "module", module: module, metadata: {}};
|
2016-03-24 10:03:10 -07:00
|
|
|
}
|
|
|
|
this.metadataCache.set(module, moduleMetadata);
|
|
|
|
}
|
|
|
|
return moduleMetadata;
|
|
|
|
}
|
|
|
|
|
2016-04-28 21:54:02 -07:00
|
|
|
private getTypeMetadata(type: StaticSymbol): {[key: string]: any} {
|
|
|
|
let moduleMetadata = this.getModuleMetadata(type.filePath);
|
2016-03-24 10:03:10 -07:00
|
|
|
let result = moduleMetadata['metadata'][type.name];
|
|
|
|
if (!isPresent(result)) {
|
2016-04-12 09:40:37 -07:00
|
|
|
result = {__symbolic: "class"};
|
2016-03-24 10:03:10 -07:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function isClassMetadata(expression: any): boolean {
|
|
|
|
return !isPrimitive(expression) && !isArray(expression) && expression['__symbolic'] == 'class';
|
|
|
|
}
|
2016-02-18 10:53:21 -08:00
|
|
|
|
|
|
|
function mapStringMap(input: {[key: string]: any},
|
|
|
|
transform: (value: any, key: string) => any): {[key: string]: any} {
|
|
|
|
if (isBlank(input)) return {};
|
2016-04-30 12:27:37 -07:00
|
|
|
var result: {[key: string]: any} = {};
|
2016-02-18 10:53:21 -08:00
|
|
|
StringMapWrapper.keys(input).forEach((key) => { result[key] = transform(input[key], key); });
|
|
|
|
return result;
|
|
|
|
}
|