parent
6103aa0a46
commit
3e114227f8
|
@ -39,6 +39,7 @@ import {
|
|||
SkipSelfMetadata
|
||||
} from 'angular2/src/core/di/metadata';
|
||||
import {AttributeMetadata} from 'angular2/src/core/metadata/di';
|
||||
import {ReflectorReader} from 'angular2/src/core/reflection/reflector_reader';
|
||||
|
||||
@Injectable()
|
||||
export class RuntimeMetadataResolver {
|
||||
|
@ -46,11 +47,19 @@ export class RuntimeMetadataResolver {
|
|||
private _pipeCache = new Map<Type, cpl.CompilePipeMetadata>();
|
||||
private _anonymousTypes = new Map<Object, number>();
|
||||
private _anonymousTypeIndex = 0;
|
||||
private _reflector: ReflectorReader;
|
||||
|
||||
constructor(private _directiveResolver: DirectiveResolver, private _pipeResolver: PipeResolver,
|
||||
private _viewResolver: ViewResolver,
|
||||
@Optional() @Inject(PLATFORM_DIRECTIVES) private _platformDirectives: Type[],
|
||||
@Optional() @Inject(PLATFORM_PIPES) private _platformPipes: Type[]) {}
|
||||
@Optional() @Inject(PLATFORM_PIPES) private _platformPipes: Type[],
|
||||
_reflector?: ReflectorReader) {
|
||||
if (isPresent(_reflector)) {
|
||||
this._reflector = _reflector;
|
||||
} else {
|
||||
this._reflector = reflector;
|
||||
}
|
||||
}
|
||||
|
||||
private sanitizeTokenName(token: any): string {
|
||||
let identifier = stringify(token);
|
||||
|
@ -78,7 +87,7 @@ export class RuntimeMetadataResolver {
|
|||
if (dirMeta instanceof md.ComponentMetadata) {
|
||||
assertArrayOfStrings('styles', dirMeta.styles);
|
||||
var cmpMeta = <md.ComponentMetadata>dirMeta;
|
||||
moduleUrl = calcModuleUrl(directiveType, cmpMeta);
|
||||
moduleUrl = calcModuleUrl(this._reflector, directiveType, cmpMeta);
|
||||
var viewMeta = this._viewResolver.resolve(directiveType);
|
||||
assertArrayOfStrings('styles', viewMeta.styles);
|
||||
templateMeta = new cpl.CompileTemplateMetadata({
|
||||
|
@ -148,7 +157,7 @@ export class RuntimeMetadataResolver {
|
|||
var meta = this._pipeCache.get(pipeType);
|
||||
if (isBlank(meta)) {
|
||||
var pipeMeta = this._pipeResolver.resolve(pipeType);
|
||||
var moduleUrl = reflector.importUri(pipeType);
|
||||
var moduleUrl = this._reflector.importUri(pipeType);
|
||||
meta = new cpl.CompilePipeMetadata({
|
||||
type: this.getTypeMetadata(pipeType, moduleUrl),
|
||||
name: pipeMeta.name,
|
||||
|
@ -341,7 +350,8 @@ function isValidType(value: Type): boolean {
|
|||
return isPresent(value) && (value instanceof Type);
|
||||
}
|
||||
|
||||
function calcModuleUrl(type: Type, cmpMetadata: md.ComponentMetadata): string {
|
||||
function calcModuleUrl(reflector: ReflectorReader, type: Type,
|
||||
cmpMetadata: md.ComponentMetadata): string {
|
||||
var moduleId = cmpMetadata.moduleId;
|
||||
if (isPresent(moduleId)) {
|
||||
var scheme = getUrlScheme(moduleId);
|
||||
|
|
|
@ -25,6 +25,7 @@ import {
|
|||
ViewQueryMetadata,
|
||||
QueryMetadata,
|
||||
} from 'angular2/src/core/metadata';
|
||||
import {ReflectorReader} from 'angular2/src/core/reflection/reflector_reader';
|
||||
|
||||
/**
|
||||
* The host of the static resolver is expected to be able to provide module metadata in the form of
|
||||
|
@ -56,15 +57,16 @@ export class StaticType {
|
|||
* A static reflector implements enough of the Reflector API that is necessary to compile
|
||||
* templates statically.
|
||||
*/
|
||||
export class StaticReflector {
|
||||
export class StaticReflector implements ReflectorReader {
|
||||
private typeCache = new Map<string, StaticType>();
|
||||
private annotationCache = new Map<StaticType, any[]>();
|
||||
private propertyCache = new Map<StaticType, {[key: string]: any}>();
|
||||
private parameterCache = new Map<StaticType, any[]>();
|
||||
private metadataCache = new Map<string, {[key: string]: any}>();
|
||||
|
||||
constructor(private host: StaticReflectorHost) { this.initializeConversionMap(); }
|
||||
|
||||
importUri(typeOrFunc: any): string { return (<StaticType>typeOrFunc).moduleId; }
|
||||
|
||||
/**
|
||||
* getStatictype produces a Type whose metadata is known but whose implementation is not loaded.
|
||||
* All types passed to the StaticResolver should be pseudo-types returned by this method.
|
||||
|
@ -438,7 +440,7 @@ export class StaticReflector {
|
|||
return simplify(value);
|
||||
}
|
||||
|
||||
private getModuleMetadata(module: string): {[key: string]: any} {
|
||||
public getModuleMetadata(module: string): {[key: string]: any} {
|
||||
let moduleMetadata = this.metadataCache.get(module);
|
||||
if (!isPresent(moduleMetadata)) {
|
||||
moduleMetadata = this.host.getMetadataFor(module);
|
||||
|
|
|
@ -6,4 +6,5 @@ export abstract class ReflectorReader {
|
|||
abstract parameters(typeOrFunc: /*Type*/ any): any[][];
|
||||
abstract annotations(typeOrFunc: /*Type*/ any): any[];
|
||||
abstract propMetadata(typeOrFunc: /*Type*/ any): {[key: string]: any[]};
|
||||
abstract importUri(typeOrFunc: /*Type*/ any): string;
|
||||
}
|
Loading…
Reference in New Issue