mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Record the recursion ID of each type, if available
This commit is contained in:
@@ -377,6 +377,7 @@ namespace ts {
|
||||
getMergedSymbol,
|
||||
getDiagnostics,
|
||||
getGlobalDiagnostics,
|
||||
getRecursionIdentity,
|
||||
getTypeOfSymbolAtLocation: (symbol, locationIn) => {
|
||||
const location = getParseTreeNode(locationIn);
|
||||
return location ? getTypeOfSymbolAtLocation(symbol, location) : errorType;
|
||||
|
||||
@@ -127,6 +127,8 @@ namespace ts.tracing {
|
||||
const typesPath = legend[legend.length - 1].typesPath!;
|
||||
const typesFd = fs.openSync(typesPath, "w");
|
||||
|
||||
const recursionIdentityMap = new Map<object, number>();
|
||||
|
||||
// Cleverness: no line break here so that the type ID will match the line number
|
||||
fs.writeSync(typesFd, "[");
|
||||
|
||||
@@ -178,10 +180,23 @@ namespace ts.tracing {
|
||||
};
|
||||
}
|
||||
|
||||
// We can't print out an arbitrary object, so just assign each one a unique number.
|
||||
// Don't call it an "id" so people don't treat it as a type id.
|
||||
let recursionToken: number | undefined;
|
||||
const recursionIdentity = type.checker.getRecursionIdentity(type);
|
||||
if (recursionIdentity) {
|
||||
recursionToken = recursionIdentityMap.get(recursionIdentity);
|
||||
if (!recursionToken) {
|
||||
recursionToken = recursionIdentityMap.size;
|
||||
recursionIdentityMap.set(recursionIdentity, recursionToken);
|
||||
}
|
||||
}
|
||||
|
||||
const descriptor = {
|
||||
id: type.id,
|
||||
intrinsicName: (type as any).intrinsicName,
|
||||
symbolName: symbol?.escapedName && unescapeLeadingUnderscores(symbol.escapedName),
|
||||
recursionId: recursionToken,
|
||||
unionTypes: (type.flags & TypeFlags.Union) ? (type as UnionType).types?.map(t => t.id) : undefined,
|
||||
intersectionTypes: (type.flags & TypeFlags.Intersection) ? (type as IntersectionType).types.map(t => t.id) : undefined,
|
||||
aliasTypeArguments: type.aliasTypeArguments?.map(t => t.id),
|
||||
|
||||
@@ -4073,6 +4073,7 @@ namespace ts {
|
||||
/* @internal */ getTypeCount(): number;
|
||||
/* @internal */ getInstantiationCount(): number;
|
||||
/* @internal */ getRelationCacheSizes(): { assignable: number, identity: number, subtype: number, strictSubtype: number };
|
||||
/* @internal */ getRecursionIdentity(type: Type): object | undefined;
|
||||
|
||||
/* @internal */ isArrayType(type: Type): boolean;
|
||||
/* @internal */ isTupleType(type: Type): boolean;
|
||||
|
||||
Reference in New Issue
Block a user