Skip to content

Commit 299745c

Browse files
authoredOct 3, 2022
Fix crash in goto-def on @override (#51016)
* Fix crash in goto-def on `@override` When the base type is not defined, getDefinitionFromOverriddenMember will have its type as errorType, which has no symbol. The error handling previously only handled the case of no baseType at all -- which I'm not sure ever actually happens. * Improve checking 1. getTypeAtLocation never returns undefined, only errorType, so check for that. 2. Return directly after missing baseTypeNode instead of continuing to return later. * Experiment with making goto-def on `override` more consistent * Unify static/instance node->symbol->type path * Make getSymbolAtLocation support class expressions and parenthesized expressions * Revert "Make getSymbolAtLocation support class expressions" This reverts commit 4c1b031. * fix semicolon lint
1 parent 7dcf11f commit 299745c

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed
 

‎src/services/goToDefinition.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,15 @@ namespace ts.GoToDefinition {
171171
if (!baseDeclaration) return;
172172

173173
const baseTypeNode = getEffectiveBaseTypeNode(baseDeclaration);
174-
const baseType = baseTypeNode ? typeChecker.getTypeAtLocation(baseTypeNode) : undefined;
175-
if (!baseType) return;
174+
if (!baseTypeNode) return;
175+
const expression = skipParentheses(baseTypeNode.expression);
176+
const base = isClassExpression(expression) ? expression.symbol : typeChecker.getSymbolAtLocation(expression);
177+
if (!base) return;
176178

177179
const name = unescapeLeadingUnderscores(getTextOfPropertyName(classElement.name));
178180
const symbol = hasStaticModifier(classElement)
179-
? typeChecker.getPropertyOfType(typeChecker.getTypeOfSymbolAtLocation(baseType.symbol, baseDeclaration), name)
180-
: typeChecker.getPropertyOfType(baseType, name);
181+
? typeChecker.getPropertyOfType(typeChecker.getTypeOfSymbol(base), name)
182+
: typeChecker.getPropertyOfType(typeChecker.getDeclaredTypeOfSymbol(base), name);
181183
if (!symbol) return;
182184

183185
return getDefinitionFromSymbol(typeChecker, symbol, node);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path="fourslash.ts" />
2+
// @Filename: goToDefinitionOverrideJsdoc.ts
3+
// @allowJs: true
4+
// @checkJs: true
5+
6+
//// export class C extends CompletelyUndefined {
7+
//// /**
8+
//// * @override/*1*/
9+
//// * @returns {{}}
10+
//// */
11+
//// static foo() {
12+
//// return {}
13+
//// }
14+
//// }
15+
16+
verify.goToDefinition(['1'], [])

0 commit comments

Comments
 (0)