@@ -541,7 +541,7 @@ namespace ts {
541
541
let flowLoopCount = 0;
542
542
let sharedFlowCount = 0;
543
543
let flowNodeCount = -1;
544
- let flowAnalysisDisabled = false;
544
+ let flowAnalysisErrors = false;
545
545
546
546
const emptyStringType = getLiteralType("");
547
547
const zeroType = getLiteralType(0);
@@ -15950,17 +15950,14 @@ namespace ts {
15950
15950
return false;
15951
15951
}
15952
15952
15953
- function reportFlowControlError(node: Node) {
15954
- const block = <Block | ModuleBlock | SourceFile>findAncestor(node, isFunctionOrModuleBlock);
15955
- const sourceFile = getSourceFileOfNode(node);
15956
- const span = getSpanOfTokenAtPosition(sourceFile, block.statements.pos);
15957
- diagnostics.add(createFileDiagnostic(sourceFile, span.start, span.length, Diagnostics.The_containing_function_or_module_body_is_too_complex_for_control_flow_analysis));
15953
+ function getContainingBlock(node: Node) {
15954
+ return <Block | ModuleBlock | SourceFile>findAncestor(node, isFunctionOrModuleBlock);
15958
15955
}
15959
15956
15960
15957
function getFlowTypeOfReference(reference: Node, declaredType: Type, initialType = declaredType, flowContainer?: Node, couldBeUninitialized?: boolean) {
15961
15958
let key: string | undefined;
15962
15959
let flowDepth = 0;
15963
- if (flowAnalysisDisabled ) {
15960
+ if (flowAnalysisErrors && getNodeLinks(getContainingBlock(reference)).flags & NodeCheckFlags.FlowAnalysisError ) {
15964
15961
return errorType;
15965
15962
}
15966
15963
if (!reference.flowNode || !couldBeUninitialized && !(declaredType.flags & TypeFlags.Narrowable)) {
@@ -15984,9 +15981,14 @@ namespace ts {
15984
15981
// We have made 2000 recursive invocations or visited 500000 control flow nodes while analyzing
15985
15982
// the containing function or module body, the limit at which we consider the function or module
15986
15983
// body is too complex and disable further control flow analysis.
15987
- if (!flowAnalysisDisabled) {
15988
- flowAnalysisDisabled = true;
15989
- reportFlowControlError(reference);
15984
+ const block = getContainingBlock(reference);
15985
+ const nodeLinks = getNodeLinks(block);
15986
+ if (!(nodeLinks.flags & NodeCheckFlags.FlowAnalysisError)) {
15987
+ nodeLinks.flags |= NodeCheckFlags.FlowAnalysisError;
15988
+ const sourceFile = getSourceFileOfNode(block);
15989
+ const span = getSpanOfTokenAtPosition(sourceFile, block.statements.pos);
15990
+ diagnostics.add(createFileDiagnostic(sourceFile, span.start, span.length, Diagnostics.The_containing_function_or_module_body_is_too_complex_for_control_flow_analysis));
15991
+ flowAnalysisErrors = true;
15990
15992
}
15991
15993
return errorType;
15992
15994
}
@@ -26032,11 +26034,9 @@ namespace ts {
26032
26034
}
26033
26035
if (isFunctionOrModuleBlock(node)) {
26034
26036
const saveFlowNodeCount = flowNodeCount;
26035
- const saveFlowAnalysisDisabled = flowAnalysisDisabled;
26036
26037
flowNodeCount = 0;
26037
26038
forEach(node.statements, checkSourceElement);
26038
26039
flowNodeCount = saveFlowNodeCount;
26039
- flowAnalysisDisabled = saveFlowAnalysisDisabled;
26040
26040
}
26041
26041
else {
26042
26042
forEach(node.statements, checkSourceElement);
0 commit comments