Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 32 additions & 22 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1967,32 +1967,42 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

function runWithoutResolvedSignatureCaching<T>(node: Node | undefined, fn: () => T): T {
const cachedResolvedSignatures = [];
const cachedTypes: (readonly [SymbolLinks, Type | undefined])[] = [];
node = findAncestor(node, isCallLikeOrFunctionLikeExpression);
if (node) {
const cachedResolvedSignatures = [];
const cachedTypes = [];
while (node) {
const nodeLinks = getNodeLinks(node);
cachedResolvedSignatures.push([nodeLinks, nodeLinks.resolvedSignature] as const);
nodeLinks.resolvedSignature = undefined;
if (isFunctionExpressionOrArrowFunction(node)) {
const symbolLinks = getSymbolLinks(getSymbolOfDeclaration(node));
const type = symbolLinks.type;
cachedTypes.push([symbolLinks, type] as const);
symbolLinks.type = undefined;
if (!node) {
return fn();
}
while (node) {
const nodeLinks = getNodeLinks(node);
cachedResolvedSignatures.push([nodeLinks, nodeLinks.resolvedSignature, nodeLinks.flags] as const);
nodeLinks.resolvedSignature = undefined;
nodeLinks.flags = NodeCheckFlags.None;
if (isFunctionExpressionOrArrowFunction(node)) {
resetCachedSymbolTypes(node);
for (const parameter of node.parameters) {
resetCachedSymbolTypes(parameter);
}
node = findAncestor(node.parent, isCallLikeOrFunctionLikeExpression);
}
const result = fn();
for (const [nodeLinks, resolvedSignature] of cachedResolvedSignatures) {
nodeLinks.resolvedSignature = resolvedSignature;
}
for (const [symbolLinks, type] of cachedTypes) {
symbolLinks.type = type;
}
return result;
node = findAncestor(node.parent, isCallLikeOrFunctionLikeExpression);
}
const result = fn();
for (const [nodeLinks, resolvedSignature, nodeCheckFlags] of cachedResolvedSignatures) {
nodeLinks.resolvedSignature = resolvedSignature;
nodeLinks.flags = nodeCheckFlags;
}
for (const [symbolLinks, type] of cachedTypes) {
symbolLinks.type = type;
}
return result;

function resetCachedSymbolTypes(declaration: Declaration) {
const symbolLinks = getSymbolLinks(getSymbolOfDeclaration(declaration));
const type = symbolLinks.type;

cachedTypes.push([symbolLinks, type] as const);
symbolLinks.type = undefined;
}
return fn();
}

function runWithInferenceBlockedFromSourceNode<T>(node: Node | undefined, fn: () => T): T {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/// <reference path="fourslash.ts" />

// @strict: true
// @target: esnext
// @lib: esnext

//// type ObjectFromEntries<T> = T extends readonly [
//// infer Key extends string | number | symbol,
//// infer Value,
//// ][]
//// ? { [key in Key]: Value }
//// : never;
////
//// type KeyValuePairs<T> = {
//// [K in keyof T]: [K, T[K]];
//// }[keyof T];
////
//// declare function mapObjectEntries<
//// const T extends object,
//// const TMapped extends [string | number | symbol, unknown],
//// >(
//// obj: T,
//// mapper: ([a, b]: KeyValuePairs<T>) => TMapped,
//// ): ObjectFromEntries<TMapped[]>;
////
//// mapObjectEntries({ a: 1, b: 2 }, ([x, y]) => ["a/*1*/", y]);

verify.completions({
marker: "1",
exact: ["a"],
});
verify.getSemanticDiagnostics([]);