@@ -987,6 +987,7 @@ import {
987
987
tokenToString,
988
988
tracing,
989
989
TracingNode,
990
+ TrackedSymbol,
990
991
TransientSymbol,
991
992
TransientSymbolLinks,
992
993
tryAddToSet,
@@ -6256,7 +6257,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
6256
6257
visitedTypes: undefined,
6257
6258
symbolDepth: undefined,
6258
6259
inferTypeParameters: undefined,
6259
- approximateLength: 0
6260
+ approximateLength: 0,
6261
+ trackedSymbols: undefined!,
6260
6262
};
6261
6263
context.tracker = new SymbolTrackerImpl(context, tracker, moduleResolverHost);
6262
6264
const resultingNode = cb(context);
@@ -6709,6 +6711,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
6709
6711
}
6710
6712
const cachedResult = links?.serializedTypes?.get(key);
6711
6713
if (cachedResult) {
6714
+ // TODO:: check if we instead store late painted statements associated with this?
6715
+ cachedResult.trackedSymbols?.forEach(
6716
+ ([symbol, enclosingDeclaration, meaning]) =>
6717
+ context.tracker.trackSymbol(symbol, enclosingDeclaration, meaning)
6718
+ );
6712
6719
if (cachedResult.truncating) {
6713
6720
context.truncating = true;
6714
6721
}
@@ -6729,7 +6736,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
6729
6736
const result = transform(type);
6730
6737
const addedLength = context.approximateLength - startLength;
6731
6738
if (!context.reportedDiagnostic && !context.encounteredError) {
6732
- links?.serializedTypes?.set(key, { node: result, truncating: context.truncating, addedLength });
6739
+ links?.serializedTypes?.set(key, { node: result, truncating: context.truncating, addedLength, trackedSymbols: context.trackedSymbols });
6733
6740
}
6734
6741
context.visitedTypes.delete(typeId);
6735
6742
if (id) {
@@ -8477,6 +8484,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
8477
8484
if (context.reportedDiagnostic) {
8478
8485
oldcontext.reportedDiagnostic = context.reportedDiagnostic; // hoist diagnostic result into outer context
8479
8486
}
8487
+ if (context.trackedSymbols) {
8488
+ if (!oldContext.trackedSymbols) oldContext.trackedSymbols = context.trackedSymbols;
8489
+ else oldContext.trackedSymbols.push(...context.trackedSymbols);
8490
+ }
8480
8491
context = oldContext;
8481
8492
}
8482
8493
}
@@ -48352,6 +48363,7 @@ interface NodeBuilderContext {
48352
48363
// State
48353
48364
encounteredError: boolean;
48354
48365
reportedDiagnostic: boolean;
48366
+ trackedSymbols: TrackedSymbol[] | undefined;
48355
48367
visitedTypes: Set<number> | undefined;
48356
48368
symbolDepth: Map<string, number> | undefined;
48357
48369
inferTypeParameters: TypeParameter[] | undefined;
@@ -48386,6 +48398,7 @@ class SymbolTrackerImpl implements SymbolTracker {
48386
48398
}
48387
48399
48388
48400
trackSymbol(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags): boolean {
48401
+ (this.context.trackedSymbols ??= []).push([symbol, enclosingDeclaration, meaning]);
48389
48402
if (this.inner?.trackSymbol && !this.disableTrackSymbol) {
48390
48403
if (this.inner.trackSymbol(symbol, enclosingDeclaration, meaning)) {
48391
48404
this.onDiagnosticReported();
0 commit comments