mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-10 21:07:52 -05:00
Add cache of anonymous object type instantiations to TypeMapper
This commit is contained in:
@@ -4487,6 +4487,15 @@ namespace ts {
|
||||
}
|
||||
|
||||
function instantiateAnonymousType(type: ObjectType, mapper: TypeMapper): ObjectType {
|
||||
if (mapper.instantiations) {
|
||||
let cachedType = mapper.instantiations[type.id];
|
||||
if (cachedType) {
|
||||
return cachedType;
|
||||
}
|
||||
}
|
||||
else {
|
||||
mapper.instantiations = [];
|
||||
}
|
||||
// Mark the anonymous type as instantiated such that our infinite instantiation detection logic can recognize it
|
||||
let result = <ResolvedType>createObjectType(TypeFlags.Anonymous | TypeFlags.Instantiated, type.symbol);
|
||||
result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol);
|
||||
@@ -4497,6 +4506,7 @@ namespace ts {
|
||||
let numberIndexType = getIndexTypeOfType(type, IndexKind.Number);
|
||||
if (stringIndexType) result.stringIndexType = instantiateType(stringIndexType, mapper);
|
||||
if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper);
|
||||
mapper.instantiations[type.id] = result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1953,6 +1953,7 @@ namespace ts {
|
||||
/* @internal */
|
||||
export interface TypeMapper {
|
||||
(t: TypeParameter): Type;
|
||||
instantiations?: Type[]; // Cache of instantiations created using this type mapper.
|
||||
context?: InferenceContext; // The inference context this mapper was created from.
|
||||
// Only inference mappers have this set (in createInferenceMapper).
|
||||
// The identity mapper and regular instantiation mappers do not need it.
|
||||
|
||||
Reference in New Issue
Block a user