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

Function getFactsFromTypeofSwitch

test/fixtures/snapshot/typescript.js:77974–78009  ·  view source on GitHub ↗

* Collect the TypeFacts learned from a typeof switch with * total clauses `witnesses`, and the active clause ranging * from `start` to `end`. Parameter `hasDefault` denotes * whether the active clause contains a default clause.

(start, end, witnesses, hasDefault)

Source from the content-addressed store, hash-verified

77972 * whether the active clause contains a default clause.
77973 */
77974 function getFactsFromTypeofSwitch(start, end, witnesses, hasDefault) {
77975 var facts = 0 /* TypeFacts.None */;
77976 // When in the default we only collect inequality facts
77977 // because default is 'in theory' a set of infinite
77978 // equalities.
77979 if (hasDefault) {
77980 // Value is not equal to any types after the active clause.
77981 for (var i = end; i < witnesses.length; i++) {
77982 facts |= typeofNEFacts.get(witnesses[i]) || 32768 /* TypeFacts.TypeofNEHostObject */;
77983 }
77984 // Remove inequalities for types that appear in the
77985 // active clause because they appear before other
77986 // types collected so far.
77987 for (var i = start; i < end; i++) {
77988 facts &= ~(typeofNEFacts.get(witnesses[i]) || 0);
77989 }
77990 // Add inequalities for types before the active clause unconditionally.
77991 for (var i = 0; i < start; i++) {
77992 facts |= typeofNEFacts.get(witnesses[i]) || 32768 /* TypeFacts.TypeofNEHostObject */;
77993 }
77994 }
77995 // When in an active clause without default the set of
77996 // equalities is finite.
77997 else {
77998 // Add equalities for all types in the active clause.
77999 for (var i = start; i < end; i++) {
78000 facts |= typeofEQFacts.get(witnesses[i]) || 128 /* TypeFacts.TypeofEQHostObject */;
78001 }
78002 // Remove equalities for types that appear before the
78003 // active clause.
78004 for (var i = 0; i < start; i++) {
78005 facts &= ~(typeofEQFacts.get(witnesses[i]) || 0);
78006 }
78007 }
78008 return facts;
78009 }
78010 function isExhaustiveSwitchStatement(node) {
78011 var links = getNodeLinks(node);
78012 return links.isExhaustive !== undefined ? links.isExhaustive : (links.isExhaustive = computeExhaustiveSwitchStatement(node));

Callers 2

narrowBySwitchOnTypeOfFunction · 0.85

Calls 1

getMethod · 0.65

Tested by

no test coverage detected