@@ -335,7 +335,7 @@ namespace ts {
335
335
let flowLoopStart = 0;
336
336
let flowLoopCount = 0;
337
337
let sharedFlowCount = 0;
338
- let flowNodeCount = 0 ;
338
+ let flowAnalysisDisabled = false ;
339
339
340
340
const emptyStringType = getLiteralType("");
341
341
const zeroType = getLiteralType(0);
@@ -11470,7 +11470,7 @@ namespace ts {
11470
11470
function getFlowTypeOfReference(reference: Node, declaredType: Type, initialType = declaredType, flowContainer?: Node, couldBeUninitialized?: boolean) {
11471
11471
let key: string;
11472
11472
let flowDepth = 0;
11473
- if (flowNodeCount < 0 ) {
11473
+ if (flowAnalysisDisabled ) {
11474
11474
return unknownType;
11475
11475
}
11476
11476
if (!reference.flowNode || !couldBeUninitialized && !(declaredType.flags & TypeFlags.Narrowable)) {
@@ -11490,17 +11490,15 @@ namespace ts {
11490
11490
return resultType;
11491
11491
11492
11492
function getTypeAtFlowNode(flow: FlowNode): FlowType {
11493
+ if (flowDepth === 2500) {
11494
+ // We have made 2500 recursive invocations. To avoid overflowing the call stack we report an error
11495
+ // and disable further control flow analysis in the containing function or module body.
11496
+ flowAnalysisDisabled = true;
11497
+ reportFlowControlError(reference);
11498
+ return unknownType;
11499
+ }
11493
11500
flowDepth++;
11494
11501
while (true) {
11495
- flowNodeCount++;
11496
- if (flowDepth >= 2500 || flowNodeCount >= 100000000) {
11497
- // We have made over 2500 recursive invocations or visited over 100M flow nodes. Rather than
11498
- // overflowing the call stack or spending an excessive amount of time, we report an error
11499
- // and disable further control flow analysis in the containing function or module body.
11500
- flowNodeCount = -1;
11501
- reportFlowControlError(reference);
11502
- return unknownType;
11503
- }
11504
11502
const flags = flow.flags;
11505
11503
if (flags & FlowFlags.Shared) {
11506
11504
// We cache results of flow type resolution for shared nodes that were previously visited in
@@ -19963,10 +19961,9 @@ namespace ts {
19963
19961
checkGrammarStatementInAmbientContext(node);
19964
19962
}
19965
19963
if (isFunctionOrModuleBlock(node)) {
19966
- const saveFlowNodeCount = flowNodeCount;
19967
- flowNodeCount = 0;
19964
+ const saveFlowAnalysisDisabled = flowAnalysisDisabled;
19968
19965
forEach(node.statements, checkSourceElement);
19969
- flowNodeCount = saveFlowNodeCount ;
19966
+ flowAnalysisDisabled = saveFlowAnalysisDisabled ;
19970
19967
}
19971
19968
else {
19972
19969
forEach(node.statements, checkSourceElement);
@@ -22560,7 +22557,7 @@ namespace ts {
22560
22557
22561
22558
deferredNodes = [];
22562
22559
deferredUnusedIdentifierNodes = produceDiagnostics && noUnusedIdentifiers ? [] : undefined;
22563
- flowNodeCount = 0 ;
22560
+ flowAnalysisDisabled = false ;
22564
22561
22565
22562
forEach(node.statements, checkSourceElement);
22566
22563
0 commit comments