diff --git a/modules/@angular/compiler/src/aot/static_reflector.ts b/modules/@angular/compiler/src/aot/static_reflector.ts index f07aa7e8d3..e4792d4c1e 100644 --- a/modules/@angular/compiler/src/aot/static_reflector.ts +++ b/modules/@angular/compiler/src/aot/static_reflector.ts @@ -44,12 +44,30 @@ export interface StaticReflectorHost { moduleNameToFileName(moduleName: string, containingFile: string): string; } +/** + * A cache of static symbol used by the StaticReflector to return the same symbol for the + * same symbol values. + */ +export class StaticSymbolCache { + private cache = new Map(); + + get(declarationFile: string, name: string, members?: string[]): StaticSymbol { + const memberSuffix = members ? `.${ members.join('.')}` : ''; + const key = `"${declarationFile}".${name}${memberSuffix}`; + let result = this.cache.get(key); + if (!result) { + result = new StaticSymbol(declarationFile, name, members); + this.cache.set(key, result); + } + return result; + } +} + /** * A static reflector implements enough of the Reflector API that is necessary to compile * templates statically. */ export class StaticReflector implements ReflectorReader { - private staticSymbolCache = new Map(); private declarationCache = new Map(); private annotationCache = new Map(); private propertyCache = new Map(); @@ -58,7 +76,11 @@ export class StaticReflector implements ReflectorReader { private conversionMap = new Map any>(); private opaqueToken: StaticSymbol; - constructor(private host: StaticReflectorHost) { this.initializeConversionMap(); } + constructor( + private host: StaticReflectorHost, + private staticSymbolCache: StaticSymbolCache = new StaticSymbolCache()) { + this.initializeConversionMap(); + } importUri(typeOrFunc: StaticSymbol): string { const staticSymbol = this.findDeclaration(typeOrFunc.filePath, typeOrFunc.name, ''); @@ -225,14 +247,7 @@ export class StaticReflector implements ReflectorReader { * @param name the name of the type. */ getStaticSymbol(declarationFile: string, name: string, members?: string[]): StaticSymbol { - const memberSuffix = members ? `.${ members.join('.')}` : ''; - const key = `"${declarationFile}".${name}${memberSuffix}`; - let result = this.staticSymbolCache.get(key); - if (!result) { - result = new StaticSymbol(declarationFile, name, members); - this.staticSymbolCache.set(key, result); - } - return result; + return this.staticSymbolCache.get(declarationFile, name, members); } private resolveExportedSymbol(filePath: string, symbolName: string): StaticSymbol {