Merge pull request #29563 from Microsoft/fixSwitchControlFlow

Fix switch statement control flow logic
This commit is contained in:
Anders Hejlsberg
2019-01-24 10:36:52 -08:00
committed by GitHub
6 changed files with 445 additions and 3 deletions

View File

@@ -15780,9 +15780,6 @@ namespace ts {
function getTypeAtSwitchClause(flow: FlowSwitchClause): FlowType {
const expr = flow.switchStatement.expression;
if (containsMatchingReferenceDiscriminant(reference, expr)) {
return declaredType;
}
const flowType = getTypeAtFlowNode(flow.antecedent);
let type = getTypeFromFlowType(flowType);
if (isMatchingReference(reference, expr)) {
@@ -15797,6 +15794,9 @@ namespace ts {
else if (expr.kind === SyntaxKind.TypeOfExpression && isMatchingReference(reference, (expr as TypeOfExpression).expression)) {
type = narrowBySwitchOnTypeOf(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd);
}
else if (containsMatchingReferenceDiscriminant(reference, expr)) {
type = declaredType;
}
return createFlowType(type, isIncomplete(flowType));
}