From f183f1ab387331f3957faf9a581c26ab54aa775a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 2 May 2016 09:21:54 -0700 Subject: [PATCH] Quicker bail out for type analysis in nested loops --- src/compiler/checker.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c434721d714..b3174766347 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7664,17 +7664,18 @@ namespace ts { const type = flow.kind === FlowKind.LoopLabel ? getTypeAtFlowNodeCached(antecedent) : getTypeAtFlowNode(antecedent); - if (type) { - // If the type at a particular antecedent path is the declared type and the - // reference is known to always be assigned (i.e. when declared and initial types - // are the same), there is no reason to process more antecedents since the only - // possible outcome is subtypes that will be removed in the final union type anyway. - if (type === declaredType && declaredType === initialType) { - return type; - } - if (!contains(antecedentTypes, type)) { - antecedentTypes.push(type); - } + if (!type) { + break; + } + // If the type at a particular antecedent path is the declared type and the + // reference is known to always be assigned (i.e. when declared and initial types + // are the same), there is no reason to process more antecedents since the only + // possible outcome is subtypes that will be removed in the final union type anyway. + if (type === declaredType && declaredType === initialType) { + return type; + } + if (!contains(antecedentTypes, type)) { + antecedentTypes.push(type); } } return antecedentTypes.length === 0 ? undefined :