Skip to content

Fix Debug Fail Go-to-def on JS class #58204

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

Closed
wants to merge 3 commits into from
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 number Diff line number Diff 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 Down Expand Up @@ -66,6 +69,7 @@ import {
isNameOfFunctionDeclaration,
isNewExpressionTarget,
isObjectBindingPattern,
isPropertyAccessExpression,
isPropertyName,
isRightSideOfPropertyAccess,
isStaticModifier,
Expand Down Expand 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
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
Contributor Author

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 number Diff line number Diff 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 number Diff line number Diff 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");