mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Tracing: dump more information about types (#42962)
* Tracing: dump more info about substitution types * Tracing: dump more info about reverse-mapped types * Tracing: dump more info about destructuring types * Tracing: dump more info about evolving-array types * Tracing: dump more info about tuple types * Tracing: dump more info about type references * Fix lint errors * Tracing: extract getLocation helper
This commit is contained in:
parent
c44b3ba223
commit
41b5abf342
@ -162,11 +162,22 @@ namespace ts { // eslint-disable-line one-namespace-per-file
|
||||
performance.measure("Tracing", "beginTracing", "endTracing");
|
||||
}
|
||||
|
||||
function indexFromOne(lc: LineAndCharacter): LineAndCharacter {
|
||||
return {
|
||||
line: lc.line + 1,
|
||||
character: lc.character + 1,
|
||||
};
|
||||
function getLocation(node: Node | undefined) {
|
||||
const file = getSourceFileOfNode(node);
|
||||
return !file
|
||||
? undefined
|
||||
: {
|
||||
path: file.path,
|
||||
start: indexFromOne(getLineAndCharacterOfPosition(file, node!.pos)),
|
||||
end: indexFromOne(getLineAndCharacterOfPosition(file, node!.end)),
|
||||
};
|
||||
|
||||
function indexFromOne(lc: LineAndCharacter): LineAndCharacter {
|
||||
return {
|
||||
line: lc.line + 1,
|
||||
character: lc.character + 1,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function dumpTypes(types: readonly Type[]) {
|
||||
@ -185,8 +196,6 @@ namespace ts { // eslint-disable-line one-namespace-per-file
|
||||
const type = types[i];
|
||||
const objectFlags = (type as any).objectFlags;
|
||||
const symbol = type.aliasSymbol ?? type.symbol;
|
||||
const firstDeclaration = symbol?.declarations?.[0];
|
||||
const firstFile = firstDeclaration && getSourceFileOfNode(firstDeclaration);
|
||||
|
||||
// It's slow to compute the display text, so skip it unless it's really valuable (or cheap)
|
||||
let display: string | undefined;
|
||||
@ -214,6 +223,7 @@ namespace ts { // eslint-disable-line one-namespace-per-file
|
||||
referenceProperties = {
|
||||
instantiatedType: referenceType.target?.id,
|
||||
typeArguments: referenceType.resolvedTypeArguments?.map(t => t.id),
|
||||
referenceLocation: getLocation(referenceType.node),
|
||||
};
|
||||
}
|
||||
|
||||
@ -228,6 +238,34 @@ namespace ts { // eslint-disable-line one-namespace-per-file
|
||||
};
|
||||
}
|
||||
|
||||
let substitutionProperties: object = {};
|
||||
if (type.flags & TypeFlags.Substitution) {
|
||||
const substitutionType = type as SubstitutionType;
|
||||
substitutionProperties = {
|
||||
substitutionBaseType: substitutionType.baseType?.id,
|
||||
substituteType: substitutionType.substitute?.id,
|
||||
};
|
||||
}
|
||||
|
||||
let reverseMappedProperties: object = {};
|
||||
if (objectFlags & ObjectFlags.ReverseMapped) {
|
||||
const reverseMappedType = type as ReverseMappedType;
|
||||
reverseMappedProperties = {
|
||||
reverseMappedSourceType: reverseMappedType.source?.id,
|
||||
reverseMappedMappedType: reverseMappedType.mappedType?.id,
|
||||
reverseMappedConstraintType: reverseMappedType.constraintType?.id,
|
||||
};
|
||||
}
|
||||
|
||||
let evolvingArrayProperties: object = {};
|
||||
if (objectFlags & ObjectFlags.EvolvingArray) {
|
||||
const evolvingArrayType = type as EvolvingArrayType;
|
||||
evolvingArrayProperties = {
|
||||
evolvingArrayElementType: evolvingArrayType.elementType.id,
|
||||
evolvingArrayFinalType: evolvingArrayType.finalArrayType?.id,
|
||||
};
|
||||
}
|
||||
|
||||
// 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;
|
||||
@ -245,6 +283,7 @@ namespace ts { // eslint-disable-line one-namespace-per-file
|
||||
intrinsicName: (type as any).intrinsicName,
|
||||
symbolName: symbol?.escapedName && unescapeLeadingUnderscores(symbol.escapedName),
|
||||
recursionId: recursionToken,
|
||||
isTuple: objectFlags & ObjectFlags.Tuple ? true : undefined,
|
||||
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),
|
||||
@ -252,11 +291,11 @@ namespace ts { // eslint-disable-line one-namespace-per-file
|
||||
...indexedAccessProperties,
|
||||
...referenceProperties,
|
||||
...conditionalProperties,
|
||||
firstDeclaration: firstDeclaration && {
|
||||
path: firstFile.path,
|
||||
start: indexFromOne(getLineAndCharacterOfPosition(firstFile, firstDeclaration.pos)),
|
||||
end: indexFromOne(getLineAndCharacterOfPosition(getSourceFileOfNode(firstDeclaration), firstDeclaration.end)),
|
||||
},
|
||||
...substitutionProperties,
|
||||
...reverseMappedProperties,
|
||||
...evolvingArrayProperties,
|
||||
destructuringPattern: getLocation(type.pattern),
|
||||
firstDeclaration: getLocation(symbol?.declarations?.[0]),
|
||||
flags: Debug.formatTypeFlags(type.flags).split("|"),
|
||||
display,
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user