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

Function mapToTypeNodes

test/fixtures/snapshot/typescript.js:53166–53231  ·  view source on GitHub ↗
(types, context, isBareList)

Source from the content-addressed store, hash-verified

53164 }
53165 }
53166 function mapToTypeNodes(types, context, isBareList) {
53167 if (ts.some(types)) {
53168 if (checkTruncationLength(context)) {
53169 if (!isBareList) {
53170 return [ts.factory.createTypeReferenceNode("...", /*typeArguments*/ undefined)];
53171 }
53172 else if (types.length > 2) {
53173 return [
53174 typeToTypeNodeHelper(types[0], context),
53175 ts.factory.createTypeReferenceNode("... ".concat(types.length - 2, " more ..."), /*typeArguments*/ undefined),
53176 typeToTypeNodeHelper(types[types.length - 1], context)
53177 ];
53178 }
53179 }
53180 var mayHaveNameCollisions = !(context.flags & 64 /* NodeBuilderFlags.UseFullyQualifiedType */);
53181 /** Map from type reference identifier text to [type, index in `result` where the type node is] */
53182 var seenNames = mayHaveNameCollisions ? ts.createUnderscoreEscapedMultiMap() : undefined;
53183 var result_5 = [];
53184 var i = 0;
53185 for (var _i = 0, types_2 = types; _i < types_2.length; _i++) {
53186 var type = types_2[_i];
53187 i++;
53188 if (checkTruncationLength(context) && (i + 2 < types.length - 1)) {
53189 result_5.push(ts.factory.createTypeReferenceNode("... ".concat(types.length - i, " more ..."), /*typeArguments*/ undefined));
53190 var typeNode_1 = typeToTypeNodeHelper(types[types.length - 1], context);
53191 if (typeNode_1) {
53192 result_5.push(typeNode_1);
53193 }
53194 break;
53195 }
53196 context.approximateLength += 2; // Account for whitespace + separator
53197 var typeNode = typeToTypeNodeHelper(type, context);
53198 if (typeNode) {
53199 result_5.push(typeNode);
53200 if (seenNames && ts.isIdentifierTypeReference(typeNode)) {
53201 seenNames.add(typeNode.typeName.escapedText, [type, result_5.length - 1]);
53202 }
53203 }
53204 }
53205 if (seenNames) {
53206 // To avoid printing types like `[Foo, Foo]` or `Bar & Bar` where
53207 // occurrences of the same name actually come from different
53208 // namespaces, go through the single-identifier type reference nodes
53209 // we just generated, and see if any names were generated more than
53210 // once while referring to different types. If so, regenerate the
53211 // type node for each entry by that name with the
53212 // `UseFullyQualifiedType` flag enabled.
53213 var saveContextFlags = context.flags;
53214 context.flags |= 64 /* NodeBuilderFlags.UseFullyQualifiedType */;
53215 seenNames.forEach(function (types) {
53216 if (!ts.arrayIsHomogeneous(types, function (_a, _b) {
53217 var a = _a[0];
53218 var b = _b[0];
53219 return typesAreSameReference(a, b);
53220 })) {
53221 for (var _i = 0, types_3 = types; _i < types_3.length; _i++) {
53222 var _a = types_3[_i], type = _a[0], resultIndex = _a[1];
53223 result_5[resultIndex] = typeToTypeNodeHelper(type, context);

Callers 3

typeToTypeNodeHelperFunction · 0.85
typeReferenceToTypeNodeFunction · 0.85
lookupTypeParameterNodesFunction · 0.85

Calls 8

checkTruncationLengthFunction · 0.85
typeToTypeNodeHelperFunction · 0.85
typesAreSameReferenceFunction · 0.85
someMethod · 0.80
concatMethod · 0.80
addMethod · 0.65
forEachMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…