Add cache of anonymous object type instantiations to TypeMapper
This commit is contained in:
parent
ca593ec1ab
commit
d615d21e6d
|
@ -4487,6 +4487,15 @@ namespace ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
function instantiateAnonymousType(type: ObjectType, mapper: TypeMapper): ObjectType {
|
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
|
// 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);
|
let result = <ResolvedType>createObjectType(TypeFlags.Anonymous | TypeFlags.Instantiated, type.symbol);
|
||||||
result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol);
|
result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol);
|
||||||
|
@ -4497,6 +4506,7 @@ namespace ts {
|
||||||
let numberIndexType = getIndexTypeOfType(type, IndexKind.Number);
|
let numberIndexType = getIndexTypeOfType(type, IndexKind.Number);
|
||||||
if (stringIndexType) result.stringIndexType = instantiateType(stringIndexType, mapper);
|
if (stringIndexType) result.stringIndexType = instantiateType(stringIndexType, mapper);
|
||||||
if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper);
|
if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper);
|
||||||
|
mapper.instantiations[type.id] = result;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1953,6 +1953,7 @@ namespace ts {
|
||||||
/* @internal */
|
/* @internal */
|
||||||
export interface TypeMapper {
|
export interface TypeMapper {
|
||||||
(t: TypeParameter): Type;
|
(t: TypeParameter): Type;
|
||||||
|
instantiations?: Type[]; // Cache of instantiations created using this type mapper.
|
||||||
context?: InferenceContext; // The inference context this mapper was created from.
|
context?: InferenceContext; // The inference context this mapper was created from.
|
||||||
// Only inference mappers have this set (in createInferenceMapper).
|
// Only inference mappers have this set (in createInferenceMapper).
|
||||||
// The identity mapper and regular instantiation mappers do not need it.
|
// The identity mapper and regular instantiation mappers do not need it.
|
||||||
|
|
Loading…
Reference in a new issue