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

Function getGenericTypeReferenceRelationKey

test/fixtures/snapshot/typescript.js:67073–67108  ·  view source on GitHub ↗
(source, target, postFix, ignoreConstraints)

Source from the content-addressed store, hash-verified

67071 return isNonDeferredTypeReference(type) && ts.some(getTypeArguments(type), function (t) { return !!(t.flags & 262144 /* TypeFlags.TypeParameter */) || isTypeReferenceWithGenericArguments(t); });
67072 }
67073 function getGenericTypeReferenceRelationKey(source, target, postFix, ignoreConstraints) {
67074 var typeParameters = [];
67075 var constraintMarker = "";
67076 var sourceId = getTypeReferenceId(source, 0);
67077 var targetId = getTypeReferenceId(target, 0);
67078 return "".concat(constraintMarker).concat(sourceId, ",").concat(targetId).concat(postFix);
67079 // getTypeReferenceId(A<T, number, U>) returns "111=0-12=1"
67080 // where A.id=111 and number.id=12
67081 function getTypeReferenceId(type, depth) {
67082 if (depth === void 0) { depth = 0; }
67083 var result = "" + type.target.id;
67084 for (var _i = 0, _a = getTypeArguments(type); _i < _a.length; _i++) {
67085 var t = _a[_i];
67086 if (t.flags & 262144 /* TypeFlags.TypeParameter */) {
67087 if (ignoreConstraints || isUnconstrainedTypeParameter(t)) {
67088 var index = typeParameters.indexOf(t);
67089 if (index < 0) {
67090 index = typeParameters.length;
67091 typeParameters.push(t);
67092 }
67093 result += "=" + index;
67094 continue;
67095 }
67096 // We mark type references that reference constrained type parameters such that we know to obtain
67097 // and look for a "broadest equivalent key" in the cache.
67098 constraintMarker = "*";
67099 }
67100 else if (depth < 4 && isTypeReferenceWithGenericArguments(t)) {
67101 result += "<" + getTypeReferenceId(t, depth + 1) + ">";
67102 continue;
67103 }
67104 result += "-" + t.id;
67105 }
67106 return result;
67107 }
67108 }
67109 /**
67110 * To improve caching, the relation key for two generic types uses the target's id plus ids of the type parameters.
67111 * For other cases, the types ids are used.

Callers 1

getRelationKeyFunction · 0.85

Calls 2

getTypeReferenceIdFunction · 0.85
concatMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…