Skip to content

Commit acd0fdf

Browse files
Fixed issue where goToDef on a shorthand property of an undefined entity would crash.
1 parent 773530c commit acd0fdf

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/services/services.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3492,7 +3492,6 @@ module ts {
34923492
}
34933493
}
34943494

3495-
let result: DefinitionInfo[] = [];
34963495

34973496
// Because name in short-hand property assignment has two different meanings: property name and property value,
34983497
// using go-to-definition at such position should go to the variable declaration of the property value rather than
@@ -3501,16 +3500,19 @@ module ts {
35013500
// assignment. This case and others are handled by the following code.
35023501
if (node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) {
35033502
let shorthandSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(symbol.valueDeclaration);
3503+
if (!shorthandSymbol) {
3504+
return [];
3505+
}
3506+
35043507
let shorthandDeclarations = shorthandSymbol.getDeclarations();
35053508
let shorthandSymbolKind = getSymbolKind(shorthandSymbol, typeInfoResolver, node);
35063509
let shorthandSymbolName = typeInfoResolver.symbolToString(shorthandSymbol);
35073510
let shorthandContainerName = typeInfoResolver.symbolToString(symbol.parent, node);
3508-
forEach(shorthandDeclarations, declaration => {
3509-
result.push(getDefinitionInfo(declaration, shorthandSymbolKind, shorthandSymbolName, shorthandContainerName));
3510-
});
3511-
return result
3511+
return map(shorthandDeclarations,
3512+
declaration => getDefinitionInfo(declaration, shorthandSymbolKind, shorthandSymbolName, shorthandContainerName));
35123513
}
35133514

3515+
let result: DefinitionInfo[] = [];
35143516
let declarations = symbol.getDeclarations();
35153517
let symbolName = typeInfoResolver.symbolToString(symbol); // Do not get scoped name, just the name of the symbol
35163518
let symbolKind = getSymbolKind(symbol, typeInfoResolver, node);

0 commit comments

Comments
 (0)