diff --git a/modules/angular2/src/compiler/runtime_metadata.ts b/modules/angular2/src/compiler/runtime_metadata.ts index de8bf28d65..0297132685 100644 --- a/modules/angular2/src/compiler/runtime_metadata.ts +++ b/modules/angular2/src/compiler/runtime_metadata.ts @@ -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(); private _anonymousTypes = new Map(); 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 = 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); diff --git a/modules/angular2/src/compiler/static_reflector.ts b/modules/angular2/src/compiler/static_reflector.ts index 9b5a73612f..413f2a4f7d 100644 --- a/modules/angular2/src/compiler/static_reflector.ts +++ b/modules/angular2/src/compiler/static_reflector.ts @@ -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(); private annotationCache = new Map(); private propertyCache = new Map(); private parameterCache = new Map(); private metadataCache = new Map(); - constructor(private host: StaticReflectorHost) { this.initializeConversionMap(); } + importUri(typeOrFunc: any): string { return (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); diff --git a/modules/angular2/src/core/reflection/reflector_reader.ts b/modules/angular2/src/core/reflection/reflector_reader.ts index 4cf7e33c86..47db280405 100644 --- a/modules/angular2/src/core/reflection/reflector_reader.ts +++ b/modules/angular2/src/core/reflection/reflector_reader.ts @@ -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[]}; -} \ No newline at end of file + abstract importUri(typeOrFunc: /*Type*/ any): string; +}