MCPcopy Index your code
hub / github.com/nodejs/node / getTypeAtSwitchClause

Function getTypeAtSwitchClause

test/fixtures/snapshot/typescript.js:70571–70596  ·  view source on GitHub ↗
(flow)

Source from the content-addressed store, hash-verified

70569 return createFlowType(narrowedType, isIncomplete(flowType));
70570 }
70571 function getTypeAtSwitchClause(flow) {
70572 var expr = flow.switchStatement.expression;
70573 var flowType = getTypeAtFlowNode(flow.antecedent);
70574 var type = getTypeFromFlowType(flowType);
70575 if (isMatchingReference(reference, expr)) {
70576 type = narrowTypeBySwitchOnDiscriminant(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd);
70577 }
70578 else if (expr.kind === 216 /* SyntaxKind.TypeOfExpression */ && isMatchingReference(reference, expr.expression)) {
70579 type = narrowBySwitchOnTypeOf(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd);
70580 }
70581 else {
70582 if (strictNullChecks) {
70583 if (optionalChainContainsReference(expr, reference)) {
70584 type = narrowTypeBySwitchOptionalChainContainment(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd, function (t) { return !(t.flags & (32768 /* TypeFlags.Undefined */ | 131072 /* TypeFlags.Never */)); });
70585 }
70586 else if (expr.kind === 216 /* SyntaxKind.TypeOfExpression */ && optionalChainContainsReference(expr.expression, reference)) {
70587 type = narrowTypeBySwitchOptionalChainContainment(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd, function (t) { return !(t.flags & 131072 /* TypeFlags.Never */ || t.flags & 128 /* TypeFlags.StringLiteral */ && t.value === "undefined"); });
70588 }
70589 }
70590 var access = getDiscriminantPropertyAccess(expr, type);
70591 if (access) {
70592 type = narrowTypeBySwitchOnDiscriminantProperty(type, access, flow.switchStatement, flow.clauseStart, flow.clauseEnd);
70593 }
70594 }
70595 return createFlowType(type, isIncomplete(flowType));
70596 }
70597 function getTypeAtFlowBranchLabel(flow) {
70598 var antecedentTypes = [];
70599 var subtypeReduction = false;

Callers 1

getTypeAtFlowNodeFunction · 0.85

Calls 11

getTypeAtFlowNodeFunction · 0.85
getTypeFromFlowTypeFunction · 0.85
isMatchingReferenceFunction · 0.85
narrowBySwitchOnTypeOfFunction · 0.85
createFlowTypeFunction · 0.85
isIncompleteFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…