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
6 changes: 5 additions & 1 deletion src/services/goToDefinition.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@ import {
AssignmentOperatorToken,
CallLikeExpression,
canHaveSymbol,
ClassLikeDeclaration,
concatenate,
createTextSpan,
createTextSpanFromBounds,
Expand All@@ -15,6 +16,7 @@ import {
DefinitionInfoAndBoundSpan,
emptyArray,
every,
Expression,
FileReference,
filter,
find,
Expand All@@ -33,6 +35,7 @@ import {
getNameOfDeclaration,
getObjectFlags,
getPropertySymbolsFromContextualType,
getRightMostAssignedExpression,
getTargetLabel,
getTextOfPropertyName,
getTouchingPropertyName,
Expand DownExpand Up@@ -66,6 +69,7 @@ import {
isNameOfFunctionDeclaration,
isNewExpressionTarget,
isObjectBindingPattern,
isPropertyAccessExpression,
isPropertyName,
isRightSideOfPropertyAccess,
isStaticModifier,
Expand DownExpand Up@@ -589,7 +593,7 @@ function getDefinitionFromSymbol(typeChecker: TypeChecker, symbol: Symbol, node:
// Applicable only if we are in a new expression, or we are on a constructor declaration
// and in either case the symbol has a construct signature definition, i.e. class
if (symbol.flags & SymbolFlags.Class && !(symbol.flags & (SymbolFlags.Function | SymbolFlags.Variable)) && (isNewExpressionTarget(node) || node.kind === SyntaxKind.ConstructorKeyword)) {
const cls = find(filteredDeclarations, isClassLike) || Debug.fail("Expected declaration to have at least one class-like declaration");
const cls = find(filteredDeclarations, isClassLike) || getRightMostAssignedExpression(find(filteredDeclarations, isPropertyAccessExpression)?.parent as Expression) as ClassLikeDeclaration || Debug.fail("Expected declaration to have at least one class-like declaration");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that this change "competes" with #57628

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing. I'll close this as I think yours makes more sense.

return getSignatureDefinition(cls.members, /*selectConstructors*/ true);
}
}
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
// === goToDefinition ===
// === /tests/cases/fourslash/index.js ===
// const A = {};
// <|A.[|B|]|> = class Foo { }
// new A./*GOTO DEF*/B();
// A.B.prototype.C = null;

// === Details ===
[
{
"kind": "property",
"name": "B",
"containerName": "A",
"isLocal": true,
"isAmbient": false,
"unverified": false,
"failedAliasResolution": false
}
]
12 changes: 12 additions & 0 deletions tests/cases/fourslash/goToDefinitionExpandoObjectAccess.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
/// <reference path="fourslash.ts" />

// @allowJs: true
// @checkJs: true
// @noEmit: true
// @filename: index.js
////const A = {};
////A./*Destination*/B = class Foo { }
////new A./*1*/B();
////A.B.prototype.C = null;

verify.baselineGoToDefinition("1");