Skip to content

Commit a18aac2

Browse files
committed
Remove deduplication logic now that subtype reduction was optimized
1 parent d282c70 commit a18aac2

File tree

1 file changed

+1
-44
lines changed

1 file changed

+1
-44
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25215,9 +25215,8 @@ namespace ts {
2521525215
if (forceTuple || inConstContext || contextualType && forEachType(contextualType, isTupleLikeType)) {
2521625216
return createArrayLiteralType(createTupleType(elementTypes, elementFlags, /*readonly*/ inConstContext));
2521725217
}
25218-
const deduplicatedTypes = deduplicateObjectOrArrayLiteralTypes(sameMap(elementTypes, (t, i) => elementFlags[i] & ElementFlags.Variadic ? getIndexedAccessTypeOrUndefined(t, numberType) || anyType : t));
2521925218
return createArrayLiteralType(createArrayType(elementTypes.length ?
25220-
getUnionType(deduplicatedTypes, UnionReduction.Subtype) :
25219+
getUnionType(sameMap(elementTypes, (t, i) => elementFlags[i] & ElementFlags.Variadic ? getIndexedAccessTypeOrUndefined(t, numberType) || anyType : t), UnionReduction.Subtype) :
2522125220
strictNullChecks ? implicitNeverType : undefinedWideningType, inConstContext));
2522225221
}
2522325222

@@ -25233,48 +25232,6 @@ namespace ts {
2523325232
return literalType;
2523425233
}
2523525234

25236-
/**
25237-
* Replaces all references to structurally equivalent object and array literal types in the given list
25238-
* with references to a single one of those types. The process is applied recursively to properties of
25239-
* object literals and elements of array literals.
25240-
*/
25241-
function deduplicateObjectOrArrayLiteralTypes(types: Type[]) {
25242-
if (!some(types, isObjectOrArrayLiteralType)) {
25243-
return types;
25244-
}
25245-
const typeMap = new Map<string, Type>();
25246-
return sameMap(types, getInternedType);
25247-
25248-
function getInternedType(type: Type): Type {
25249-
if (type.flags & TypeFlags.Union) {
25250-
const newTypes = sameMap((<UnionType>type).types, getInternedType);
25251-
return newTypes !== (<UnionType>type).types ? getUnionType(newTypes) : type;
25252-
}
25253-
const key = getLiteralTypeKey(type);
25254-
return key ? typeMap.get(key) || (typeMap.set(key, type), type) : type;
25255-
}
25256-
25257-
function getLiteralTypeKey(type: Type): string | undefined {
25258-
const objectFlags = getObjectFlags(type);
25259-
if (objectFlags & ObjectFlags.ObjectLiteral) {
25260-
const props = getPropertiesOfObjectType(type);
25261-
const propTypes = map(props, p => getInternedType(getTypeOfSymbol(p)));
25262-
const nameLengths = map(props, p => p.flags & SymbolFlags.Optional ? -(<string>p.escapedName).length : (<string>p.escapedName).length);
25263-
const nameStrings = map(props, p => <string>p.escapedName);
25264-
return `${getTypeListId(propTypes)}|${nameLengths.join(",")}|${nameStrings.join("")}`;
25265-
}
25266-
if (objectFlags & ObjectFlags.ArrayLiteral) {
25267-
if (isArrayType(type)) {
25268-
return `${isReadonlyArrayType(type) ? "R" : "A"}${getTypeId(getInternedType(getTypeArguments(type)[0]))}`;
25269-
}
25270-
if (isTupleType(type)) {
25271-
return `T${getTypeId(type.target)}|${getTypeListId(sameMap(getTypeArguments(type), getInternedType))}`;
25272-
}
25273-
}
25274-
return undefined;
25275-
}
25276-
}
25277-
2527825235
function isNumericName(name: DeclarationName): boolean {
2527925236
switch (name.kind) {
2528025237
case SyntaxKind.ComputedPropertyName:

0 commit comments

Comments
 (0)