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

Function getUnionSignatures

test/fixtures/snapshot/typescript.js:58100–58158  ·  view source on GitHub ↗
(signatureLists)

Source from the content-addressed store, hash-verified

58098 // parameters and may differ in return types. When signatures differ in return types, the resulting return
58099 // type is the union of the constituent return types.
58100 function getUnionSignatures(signatureLists) {
58101 var result;
58102 var indexWithLengthOverOne;
58103 for (var i = 0; i < signatureLists.length; i++) {
58104 if (signatureLists[i].length === 0)
58105 return ts.emptyArray;
58106 if (signatureLists[i].length > 1) {
58107 indexWithLengthOverOne = indexWithLengthOverOne === undefined ? i : -1; // -1 is a signal there are multiple overload sets
58108 }
58109 for (var _i = 0, _a = signatureLists[i]; _i < _a.length; _i++) {
58110 var signature = _a[_i];
58111 // Only process signatures with parameter lists that aren't already in the result list
58112 if (!result || !findMatchingSignature(result, signature, /*partialMatch*/ false, /*ignoreThisTypes*/ false, /*ignoreReturnTypes*/ true)) {
58113 var unionSignatures = findMatchingSignatures(signatureLists, signature, i);
58114 if (unionSignatures) {
58115 var s = signature;
58116 // Union the result types when more than one signature matches
58117 if (unionSignatures.length > 1) {
58118 var thisParameter = signature.thisParameter;
58119 var firstThisParameterOfUnionSignatures = ts.forEach(unionSignatures, function (sig) { return sig.thisParameter; });
58120 if (firstThisParameterOfUnionSignatures) {
58121 var thisType = getIntersectionType(ts.mapDefined(unionSignatures, function (sig) { return sig.thisParameter && getTypeOfSymbol(sig.thisParameter); }));
58122 thisParameter = createSymbolWithType(firstThisParameterOfUnionSignatures, thisType);
58123 }
58124 s = createUnionSignature(signature, unionSignatures);
58125 s.thisParameter = thisParameter;
58126 }
58127 (result || (result = [])).push(s);
58128 }
58129 }
58130 }
58131 }
58132 if (!ts.length(result) && indexWithLengthOverOne !== -1) {
58133 // No sufficiently similar signature existed to subsume all the other signatures in the union - time to see if we can make a single
58134 // signature that handles all over them. We only do this when there are overloads in only one constituent.
58135 // (Overloads are conditional in nature and having overloads in multiple constituents would necessitate making a power set of
58136 // signatures from the type, whose ordering would be non-obvious)
58137 var masterList = signatureLists[indexWithLengthOverOne !== undefined ? indexWithLengthOverOne : 0];
58138 var results = masterList.slice();
58139 var _loop_10 = function (signatures) {
58140 if (signatures !== masterList) {
58141 var signature_1 = signatures[0];
58142 ts.Debug.assert(!!signature_1, "getUnionSignatures bails early on empty signature lists and should not have empty lists on second pass");
58143 results = !!signature_1.typeParameters && ts.some(results, function (s) { return !!s.typeParameters && !compareTypeParametersIdentical(signature_1.typeParameters, s.typeParameters); }) ? undefined : ts.map(results, function (sig) { return combineSignaturesOfUnionMembers(sig, signature_1); });
58144 if (!results) {
58145 return "break";
58146 }
58147 }
58148 };
58149 for (var _b = 0, signatureLists_1 = signatureLists; _b < signatureLists_1.length; _b++) {
58150 var signatures = signatureLists_1[_b];
58151 var state_3 = _loop_10(signatures);
58152 if (state_3 === "break")
58153 break;
58154 }
58155 result = results;
58156 }
58157 return result || ts.emptyArray;

Callers 2

resolveUnionTypeMembersFunction · 0.85

Calls 11

findMatchingSignatureFunction · 0.85
findMatchingSignaturesFunction · 0.85
getIntersectionTypeFunction · 0.85
getTypeOfSymbolFunction · 0.85
createSymbolWithTypeFunction · 0.85
createUnionSignatureFunction · 0.85
_loop_10Function · 0.85
forEachMethod · 0.65
sliceMethod · 0.65
pushMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected