@@ -65,6 +65,7 @@ namespace ts {
6565 let typeCount = 0;
6666 let symbolCount = 0;
6767 let enumCount = 0;
68+ let instantiationCount = 0;
6869 let instantiationDepth = 0;
6970 let constraintDepth = 0;
7071 let currentNode: Node | undefined;
@@ -11408,13 +11409,14 @@ namespace ts {
1140811409 if (!type || !mapper || mapper === identityMapper) {
1140911410 return type;
1141011411 }
11411- if (instantiationDepth === 50) {
11412+ if (instantiationDepth === 50 || instantiationCount >= 5000000 ) {
1141211413 // We have reached 50 recursive type instantiations and there is a very high likelyhood we're dealing
1141311414 // with a combination of infinite generic types that perpetually generate new type identities. We stop
1141411415 // the recursion here by yielding the error type.
1141511416 error(currentNode, Diagnostics.Type_instantiation_is_excessively_deep_and_possibly_infinite);
1141611417 return errorType;
1141711418 }
11419+ instantiationCount++;
1141811420 instantiationDepth++;
1141911421 const result = instantiateTypeWorker(type, mapper);
1142011422 instantiationDepth--;
@@ -24494,6 +24496,7 @@ namespace ts {
2449424496 function checkExpression(node: Expression | QualifiedName, checkMode?: CheckMode, forceTuple?: boolean): Type {
2449524497 const saveCurrentNode = currentNode;
2449624498 currentNode = node;
24499+ instantiationCount = 0;
2449724500 const uninstantiatedType = checkExpressionWorker(node, checkMode, forceTuple);
2449824501 const type = instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, checkMode);
2449924502 if (isConstEnumObjectType(type)) {
@@ -29204,6 +29207,7 @@ namespace ts {
2920429207 if (node) {
2920529208 const saveCurrentNode = currentNode;
2920629209 currentNode = node;
29210+ instantiationCount = 0;
2920729211 checkSourceElementWorker(node);
2920829212 currentNode = saveCurrentNode;
2920929213 }
@@ -29475,6 +29479,7 @@ namespace ts {
2947529479 function checkDeferredNode(node: Node) {
2947629480 const saveCurrentNode = currentNode;
2947729481 currentNode = node;
29482+ instantiationCount = 0;
2947829483 switch (node.kind) {
2947929484 case SyntaxKind.FunctionExpression:
2948029485 case SyntaxKind.ArrowFunction:
0 commit comments