Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 13, 2023
Merged
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
8 changes: 5 additions & 3 deletions src/services/goToDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
}

/**
Expand Down Expand Up @@ -278,6 +279,7 @@ function getDefinitionFromObjectLiteralElement(typeChecker: TypeChecker, node: N
getDefinitionFromSymbol(typeChecker, propertySymbol, node));
}
}
return emptyArray;
}

function getDefinitionFromOverriddenMember(typeChecker: TypeChecker, node: Node) {
Expand Down Expand Up @@ -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[] {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
]
10 changes: 10 additions & 0 deletions tests/cases/fourslash/goToDefinitionSatisfiesExpression1.ts
Original file line number Diff line number Diff line change
@@ -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")