File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -3866,6 +3866,19 @@ module ts {
3866
3866
}
3867
3867
3868
3868
function instantiateAnonymousType(type: ObjectType, mapper: TypeMapper): ObjectType {
3869
+ // If this type has already been instantiated using this mapper, returned the cached result. This guards against
3870
+ // infinite instantiations of cyclic types, e.g. "var x: { a: T, b: typeof x };"
3871
+ if (mapper.mappings) {
3872
+ for (let mapping of mapper.mappings) {
3873
+ if (mapping.type === type) {
3874
+ return mapping.result;
3875
+ }
3876
+ }
3877
+ }
3878
+ else {
3879
+ mapper.mappings = [];
3880
+ }
3881
+ // Instantiate the given type using the given mapper and cache the result
3869
3882
let result = <ResolvedType>createObjectType(TypeFlags.Anonymous, type.symbol);
3870
3883
result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol);
3871
3884
result.members = createSymbolTable(result.properties);
@@ -3875,6 +3888,7 @@ module ts {
3875
3888
let numberIndexType = getIndexTypeOfType(type, IndexKind.Number);
3876
3889
if (stringIndexType) result.stringIndexType = instantiateType(stringIndexType, mapper);
3877
3890
if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper);
3891
+ mapper.mappings.push({ type, result });
3878
3892
return result;
3879
3893
}
3880
3894
Original file line number Diff line number Diff line change @@ -1586,9 +1586,15 @@ module ts {
1586
1586
Number ,
1587
1587
}
1588
1588
1589
+ export interface TypeMapping {
1590
+ type : Type ;
1591
+ result : Type ;
1592
+ }
1593
+
1589
1594
/* @internal */
1590
1595
export interface TypeMapper {
1591
1596
( t : TypeParameter ) : Type ;
1597
+ mappings ?: TypeMapping [ ] ; // Type mapping cache
1592
1598
}
1593
1599
1594
1600
/* @internal */
You can’t perform that action at this time.
0 commit comments