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

Function compareSignaturesIdentical

test/fixtures/snapshot/typescript.js:67299–67357  ·  view source on GitHub ↗

* See signatureRelatedTo, compareSignaturesIdentical

(source, target, partialMatch, ignoreThisTypes, ignoreReturnTypes, compareTypes)

Source from the content-addressed store, hash-verified

67297 * See signatureRelatedTo, compareSignaturesIdentical
67298 */
67299 function compareSignaturesIdentical(source, target, partialMatch, ignoreThisTypes, ignoreReturnTypes, compareTypes) {
67300 // TODO (drosen): De-duplicate code between related functions.
67301 if (source === target) {
67302 return -1 /* Ternary.True */;
67303 }
67304 if (!(isMatchingSignature(source, target, partialMatch))) {
67305 return 0 /* Ternary.False */;
67306 }
67307 // Check that the two signatures have the same number of type parameters.
67308 if (ts.length(source.typeParameters) !== ts.length(target.typeParameters)) {
67309 return 0 /* Ternary.False */;
67310 }
67311 // Check that type parameter constraints and defaults match. If they do, instantiate the source
67312 // signature with the type parameters of the target signature and continue the comparison.
67313 if (target.typeParameters) {
67314 var mapper = createTypeMapper(source.typeParameters, target.typeParameters);
67315 for (var i = 0; i < target.typeParameters.length; i++) {
67316 var s = source.typeParameters[i];
67317 var t = target.typeParameters[i];
67318 if (!(s === t || compareTypes(instantiateType(getConstraintFromTypeParameter(s), mapper) || unknownType, getConstraintFromTypeParameter(t) || unknownType) &&
67319 compareTypes(instantiateType(getDefaultFromTypeParameter(s), mapper) || unknownType, getDefaultFromTypeParameter(t) || unknownType))) {
67320 return 0 /* Ternary.False */;
67321 }
67322 }
67323 source = instantiateSignature(source, mapper, /*eraseTypeParameters*/ true);
67324 }
67325 var result = -1 /* Ternary.True */;
67326 if (!ignoreThisTypes) {
67327 var sourceThisType = getThisTypeOfSignature(source);
67328 if (sourceThisType) {
67329 var targetThisType = getThisTypeOfSignature(target);
67330 if (targetThisType) {
67331 var related = compareTypes(sourceThisType, targetThisType);
67332 if (!related) {
67333 return 0 /* Ternary.False */;
67334 }
67335 result &= related;
67336 }
67337 }
67338 }
67339 var targetLen = getParameterCount(target);
67340 for (var i = 0; i < targetLen; i++) {
67341 var s = getTypeAtPosition(source, i);
67342 var t = getTypeAtPosition(target, i);
67343 var related = compareTypes(t, s);
67344 if (!related) {
67345 return 0 /* Ternary.False */;
67346 }
67347 result &= related;
67348 }
67349 if (!ignoreReturnTypes) {
67350 var sourceTypePredicate = getTypePredicateOfSignature(source);
67351 var targetTypePredicate = getTypePredicateOfSignature(target);
67352 result &= sourceTypePredicate || targetTypePredicate ?
67353 compareTypePredicatesIdentical(sourceTypePredicate, targetTypePredicate, compareTypes) :
67354 compareTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target));
67355 }
67356 return result;

Callers 5

serializeSignaturesFunction · 0.85
findMatchingSignatureFunction · 0.85
_loop_13Function · 0.85
signaturesIdenticalToFunction · 0.85
getContextualSignatureFunction · 0.85

Calls 13

isMatchingSignatureFunction · 0.85
createTypeMapperFunction · 0.85
instantiateTypeFunction · 0.85
instantiateSignatureFunction · 0.85
getThisTypeOfSignatureFunction · 0.85
getParameterCountFunction · 0.85
getTypeAtPositionFunction · 0.85
getReturnTypeOfSignatureFunction · 0.85

Tested by

no test coverage detected