Skip to content

Commit 3e7e9f4

Browse files
Merge pull request #2415 from Microsoft/shorthandsOnNonExistentProperty
Fixed crash on goToDef when a shorthand property refers to an undefined entity
2 parents e2db46e + 3b453e6 commit 3e7e9f4

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-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);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////let x = {
4+
//// f/*1*/oo
5+
////}
6+
7+
goTo.marker("1");
8+
verify.not.definitionLocationExists();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////var /*varDef*/x = {
4+
//// /*varProp*/x
5+
////}
6+
////let /*letDef*/y = {
7+
//// /*letProp*/y
8+
////}
9+
10+
goTo.marker("varProp");
11+
goTo.definition();
12+
verify.caretAtMarker("varDef");
13+
14+
goTo.marker("letProp");
15+
goTo.definition();
16+
verify.caretAtMarker("letDef");

0 commit comments

Comments
 (0)