Compare commits
2 commits
main
...
dump-varia
Author | SHA1 | Date | |
---|---|---|---|
416323d967 | |||
18b0fc0040 |
|
@ -621,6 +621,7 @@ namespace ts {
|
|||
return tryFindAmbientModule(moduleName, /*withAugmentations*/ false);
|
||||
},
|
||||
getApparentType,
|
||||
dumpVariances,
|
||||
getUnionType,
|
||||
isTypeAssignableTo,
|
||||
createAnonymousType,
|
||||
|
@ -3999,7 +4000,7 @@ namespace ts {
|
|||
typeCount++;
|
||||
result.id = typeCount;
|
||||
if (produceDiagnostics) { // Only record types from one checker
|
||||
tracing?.recordType(result);
|
||||
tracingEnabled.recordType(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -20209,6 +20210,24 @@ namespace ts {
|
|||
return variances;
|
||||
}
|
||||
|
||||
|
||||
function getVariancesUltra(type: GenericType, refid: number): { variances: string[], how: 'static' | 'check' | 'dump', refid: number, targetid: number } {
|
||||
// Arrays and tuples are known to be covariant, no need to spend time computing this.
|
||||
if (type === globalArrayType || type === globalReadonlyArrayType || type.objectFlags & ObjectFlags.Tuple) {
|
||||
return { variances: arrayVariances.map(translateEnum), how: 'static', targetid: type.id, refid };
|
||||
}
|
||||
return {
|
||||
how: type.variances ? 'check' : 'dump',
|
||||
variances: getVariancesWorker(type.typeParameters, type, getMarkerTypeReference).map(translateEnum),
|
||||
targetid: type.id,
|
||||
refid,
|
||||
}
|
||||
}
|
||||
|
||||
function translateEnum(flag: VarianceFlags): string {
|
||||
return flag.toString() // laters! (once I find out the distribution)
|
||||
}
|
||||
|
||||
function getVariances(type: GenericType): VarianceFlags[] {
|
||||
// Arrays and tuples are known to be covariant, no need to spend time computing this.
|
||||
if (type === globalArrayType || type === globalReadonlyArrayType || type.objectFlags & ObjectFlags.Tuple) {
|
||||
|
@ -40303,6 +40322,14 @@ namespace ts {
|
|||
return diagnostics.getDiagnostics();
|
||||
}
|
||||
|
||||
function dumpVariances() {
|
||||
tracingEnabled.iterTypes(t => {
|
||||
if (getObjectFlags(t) & ObjectFlags.Reference) {
|
||||
console.log(JSON.stringify(getVariancesUltra((t as TypeReference).target, t.id)))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function getGlobalDiagnostics(): Diagnostic[] {
|
||||
throwIfNonDiagnosticsProducing();
|
||||
return diagnostics.getGlobalDiagnostics();
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace ts { // eslint-disable-line one-namespace-per-file
|
|||
// enable the above using startTracing()
|
||||
|
||||
// `tracingEnabled` should never be used directly, only through the above
|
||||
namespace tracingEnabled { // eslint-disable-line one-namespace-per-file
|
||||
export namespace tracingEnabled { // eslint-disable-line one-namespace-per-file
|
||||
type Mode = "project" | "build" | "server";
|
||||
|
||||
let fs: typeof import("fs");
|
||||
|
@ -103,6 +103,12 @@ namespace ts { // eslint-disable-line one-namespace-per-file
|
|||
}
|
||||
}
|
||||
|
||||
export function iterTypes(action: (t: Type) => void): void {
|
||||
for (const t of typeCatalog) {
|
||||
action(t)
|
||||
}
|
||||
}
|
||||
|
||||
export const enum Phase {
|
||||
Parse = "parse",
|
||||
Program = "program",
|
||||
|
|
|
@ -4152,6 +4152,7 @@ namespace ts {
|
|||
}
|
||||
|
||||
export interface TypeChecker {
|
||||
dumpVariances(): void;
|
||||
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
|
||||
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
|
||||
getPropertiesOfType(type: Type): Symbol[];
|
||||
|
|
|
@ -327,6 +327,7 @@ namespace ts {
|
|||
|
||||
if (allDiagnostics.length === configFileParsingDiagnosticsLength) {
|
||||
addRange(allDiagnostics, program.getSemanticDiagnostics(/*sourceFile*/ undefined, cancellationToken));
|
||||
(program as Program).getTypeChecker().dumpVariances();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue