fix(53138): go-to-definition not working on expression of SatisfiesExpression (#53164)

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
This commit is contained in:
Zzzen 2023-04-14 06:29:18 +08:00 committed by GitHub
parent df3bec6674
commit 458c5e6c64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 3 deletions

View File

@ -221,7 +221,7 @@ export function getDefinitionAtPosition(program: Program, sourceFile: SourceFile
if (node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) {
const shorthandSymbol = typeChecker.getShorthandAssignmentValueSymbol(symbol.valueDeclaration);
const definitions = shorthandSymbol?.declarations ? shorthandSymbol.declarations.map(decl => createDefinitionInfo(decl, typeChecker, shorthandSymbol, node, /*unverified*/ false, failedAliasResolution)) : emptyArray;
return concatenate(definitions, getDefinitionFromObjectLiteralElement(typeChecker, node) || emptyArray);
return concatenate(definitions, getDefinitionFromObjectLiteralElement(typeChecker, node));
}
// If the node is the name of a BindingElement within an ObjectBindingPattern instead of just returning the
@ -245,7 +245,8 @@ export function getDefinitionAtPosition(program: Program, sourceFile: SourceFile
});
}
return concatenate(fileReferenceDefinition, getDefinitionFromObjectLiteralElement(typeChecker, node) || getDefinitionFromSymbol(typeChecker, symbol, node, failedAliasResolution));
const objectLiteralElementDefinition = getDefinitionFromObjectLiteralElement(typeChecker, node);
return concatenate(fileReferenceDefinition, objectLiteralElementDefinition.length ? objectLiteralElementDefinition : getDefinitionFromSymbol(typeChecker, symbol, node, failedAliasResolution));
}
/**
@ -278,6 +279,7 @@ function getDefinitionFromObjectLiteralElement(typeChecker: TypeChecker, node: N
getDefinitionFromSymbol(typeChecker, propertySymbol, node));
}
}
return emptyArray;
}
function getDefinitionFromOverriddenMember(typeChecker: TypeChecker, node: Node) {
@ -366,7 +368,7 @@ export function getTypeDefinitionAtPosition(typeChecker: TypeChecker, sourceFile
const typeDefinitions = fromReturnType && fromReturnType.length !== 0 ? fromReturnType : definitionFromType(typeAtLocation, typeChecker, node, failedAliasResolution);
return typeDefinitions.length ? typeDefinitions
: !(symbol.flags & SymbolFlags.Value) && symbol.flags & SymbolFlags.Type ? getDefinitionFromSymbol(typeChecker, skipAlias(symbol, typeChecker), node, failedAliasResolution)
: undefined;
: undefined;
}
function definitionFromType(type: Type, checker: TypeChecker, node: Node, failedAliasResolution: boolean | undefined): readonly DefinitionInfo[] {

View File

@ -0,0 +1,45 @@
// === goToDefinition ===
// === /tests/cases/fourslash/goToDefinitionSatisfiesExpression1.ts ===
// const STRINGS = {
// /*GOTO DEF*/<|[|{| textSpan: true |}title|]: 'A Title'|>,
// } satisfies Record<string,string>;
//
// //somewhere in app
// STRINGS.title
// === Details ===
[
{
"kind": "property",
"name": "title",
"containerName": "__object",
"isLocal": false,
"isAmbient": false,
"unverified": false,
"failedAliasResolution": false
}
]
// === goToDefinition ===
// === /tests/cases/fourslash/goToDefinitionSatisfiesExpression1.ts ===
// const STRINGS = {
// <|[|title|]: 'A Title'|>,
// } satisfies Record<string,string>;
//
// //somewhere in app
// STRINGS./*GOTO DEF*/title
// === Details ===
[
{
"kind": "property",
"name": "title",
"containerName": "__object",
"isLocal": false,
"isAmbient": false,
"unverified": false,
"failedAliasResolution": false
}
]

View File

@ -0,0 +1,10 @@
/// <reference path="./fourslash.ts"/>
////const STRINGS = {
//// [|/*definition*/title|]: 'A Title',
////} satisfies Record<string,string>;
////
//////somewhere in app
////STRINGS.[|/*usage*/title|]
verify.baselineGoToDefinition("definition", "usage")