refactor(compiler): allow control of StaticSymbol lifetime (#12986)
This commit is contained in:
parent
44572f114f
commit
491d5a22a9
@ -44,12 +44,30 @@ export interface StaticReflectorHost {
|
|||||||
moduleNameToFileName(moduleName: string, containingFile: string): string;
|
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<string, StaticSymbol>();
|
||||||
|
|
||||||
|
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
|
* A static reflector implements enough of the Reflector API that is necessary to compile
|
||||||
* templates statically.
|
* templates statically.
|
||||||
*/
|
*/
|
||||||
export class StaticReflector implements ReflectorReader {
|
export class StaticReflector implements ReflectorReader {
|
||||||
private staticSymbolCache = new Map<string, StaticSymbol>();
|
|
||||||
private declarationCache = new Map<string, StaticSymbol>();
|
private declarationCache = new Map<string, StaticSymbol>();
|
||||||
private annotationCache = new Map<StaticSymbol, any[]>();
|
private annotationCache = new Map<StaticSymbol, any[]>();
|
||||||
private propertyCache = new Map<StaticSymbol, {[key: string]: any}>();
|
private propertyCache = new Map<StaticSymbol, {[key: string]: any}>();
|
||||||
@ -58,7 +76,11 @@ export class StaticReflector implements ReflectorReader {
|
|||||||
private conversionMap = new Map<StaticSymbol, (context: StaticSymbol, args: any[]) => any>();
|
private conversionMap = new Map<StaticSymbol, (context: StaticSymbol, args: any[]) => any>();
|
||||||
private opaqueToken: StaticSymbol;
|
private opaqueToken: StaticSymbol;
|
||||||
|
|
||||||
constructor(private host: StaticReflectorHost) { this.initializeConversionMap(); }
|
constructor(
|
||||||
|
private host: StaticReflectorHost,
|
||||||
|
private staticSymbolCache: StaticSymbolCache = new StaticSymbolCache()) {
|
||||||
|
this.initializeConversionMap();
|
||||||
|
}
|
||||||
|
|
||||||
importUri(typeOrFunc: StaticSymbol): string {
|
importUri(typeOrFunc: StaticSymbol): string {
|
||||||
const staticSymbol = this.findDeclaration(typeOrFunc.filePath, typeOrFunc.name, '');
|
const staticSymbol = this.findDeclaration(typeOrFunc.filePath, typeOrFunc.name, '');
|
||||||
@ -225,14 +247,7 @@ export class StaticReflector implements ReflectorReader {
|
|||||||
* @param name the name of the type.
|
* @param name the name of the type.
|
||||||
*/
|
*/
|
||||||
getStaticSymbol(declarationFile: string, name: string, members?: string[]): StaticSymbol {
|
getStaticSymbol(declarationFile: string, name: string, members?: string[]): StaticSymbol {
|
||||||
const memberSuffix = members ? `.${ members.join('.')}` : '';
|
return this.staticSymbolCache.get(declarationFile, name, members);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private resolveExportedSymbol(filePath: string, symbolName: string): StaticSymbol {
|
private resolveExportedSymbol(filePath: string, symbolName: string): StaticSymbol {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user