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

Function createNormalizedTupleType

test/fixtures/snapshot/typescript.js:60992–61087  ·  view source on GitHub ↗
(target, elementTypes)

Source from the content-addressed store, hash-verified

60990 return target.objectFlags & 8 /* ObjectFlags.Tuple */ ? createNormalizedTupleType(target, typeArguments) : createTypeReference(target, typeArguments);
60991 }
60992 function createNormalizedTupleType(target, elementTypes) {
60993 var _a, _b, _c;
60994 if (!(target.combinedFlags & 14 /* ElementFlags.NonRequired */)) {
60995 // No need to normalize when we only have regular required elements
60996 return createTypeReference(target, elementTypes);
60997 }
60998 if (target.combinedFlags & 8 /* ElementFlags.Variadic */) {
60999 // Transform [A, ...(X | Y | Z)] into [A, ...X] | [A, ...Y] | [A, ...Z]
61000 var unionIndex_1 = ts.findIndex(elementTypes, function (t, i) { return !!(target.elementFlags[i] & 8 /* ElementFlags.Variadic */ && t.flags & (131072 /* TypeFlags.Never */ | 1048576 /* TypeFlags.Union */)); });
61001 if (unionIndex_1 >= 0) {
61002 return checkCrossProductUnion(ts.map(elementTypes, function (t, i) { return target.elementFlags[i] & 8 /* ElementFlags.Variadic */ ? t : unknownType; })) ?
61003 mapType(elementTypes[unionIndex_1], function (t) { return createNormalizedTupleType(target, ts.replaceElement(elementTypes, unionIndex_1, t)); }) :
61004 errorType;
61005 }
61006 }
61007 // We have optional, rest, or variadic elements that may need normalizing. Normalization ensures that all variadic
61008 // elements are generic and that the tuple type has one of the following layouts, disregarding variadic elements:
61009 // (1) Zero or more required elements, followed by zero or more optional elements, followed by zero or one rest element.
61010 // (2) Zero or more required elements, followed by a rest element, followed by zero or more required elements.
61011 // In either layout, zero or more generic variadic elements may be present at any location.
61012 var expandedTypes = [];
61013 var expandedFlags = [];
61014 var expandedDeclarations = [];
61015 var lastRequiredIndex = -1;
61016 var firstRestIndex = -1;
61017 var lastOptionalOrRestIndex = -1;
61018 var _loop_15 = function (i) {
61019 var type = elementTypes[i];
61020 var flags = target.elementFlags[i];
61021 if (flags & 8 /* ElementFlags.Variadic */) {
61022 if (type.flags & 58982400 /* TypeFlags.InstantiableNonPrimitive */ || isGenericMappedType(type)) {
61023 // Generic variadic elements stay as they are.
61024 addElement(type, 8 /* ElementFlags.Variadic */, (_a = target.labeledElementDeclarations) === null || _a === void 0 ? void 0 : _a[i]);
61025 }
61026 else if (isTupleType(type)) {
61027 var elements = getTypeArguments(type);
61028 if (elements.length + expandedTypes.length >= 10000) {
61029 error(currentNode, ts.isPartOfTypeNode(currentNode)
61030 ? ts.Diagnostics.Type_produces_a_tuple_type_that_is_too_large_to_represent
61031 : ts.Diagnostics.Expression_produces_a_tuple_type_that_is_too_large_to_represent);
61032 return { value: errorType };
61033 }
61034 // Spread variadic elements with tuple types into the resulting tuple.
61035 ts.forEach(elements, function (t, n) { var _a; return addElement(t, type.target.elementFlags[n], (_a = type.target.labeledElementDeclarations) === null || _a === void 0 ? void 0 : _a[n]); });
61036 }
61037 else {
61038 // Treat everything else as an array type and create a rest element.
61039 addElement(isArrayLikeType(type) && getIndexTypeOfType(type, numberType) || errorType, 4 /* ElementFlags.Rest */, (_b = target.labeledElementDeclarations) === null || _b === void 0 ? void 0 : _b[i]);
61040 }
61041 }
61042 else {
61043 // Copy other element kinds with no change.
61044 addElement(type, flags, (_c = target.labeledElementDeclarations) === null || _c === void 0 ? void 0 : _c[i]);
61045 }
61046 };
61047 for (var i = 0; i < elementTypes.length; i++) {
61048 var state_4 = _loop_15(i);
61049 if (typeof state_4 === "object")

Callers 1

Calls 9

createTypeReferenceFunction · 0.85
checkCrossProductUnionFunction · 0.85
mapTypeFunction · 0.85
_loop_15Function · 0.85
getUnionTypeFunction · 0.85
getIndexedAccessTypeFunction · 0.85
getTupleTargetTypeFunction · 0.85
mapMethod · 0.65
sliceMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…