@@ -51,7 +51,8 @@ namespace ts.GoToDefinition {
51
51
// assignment. This case and others are handled by the following code.
52
52
if ( node . parent . kind === SyntaxKind . ShorthandPropertyAssignment ) {
53
53
const shorthandSymbol = typeChecker . getShorthandAssignmentValueSymbol ( symbol . valueDeclaration ) ;
54
- return shorthandSymbol ? shorthandSymbol . declarations . map ( decl => createDefinitionInfo ( decl , typeChecker , shorthandSymbol , node ) ) : [ ] ;
54
+ const definitions = shorthandSymbol ? shorthandSymbol . declarations . map ( decl => createDefinitionInfo ( decl , typeChecker , shorthandSymbol , node ) ) : emptyArray ;
55
+ return concatenate ( definitions , getDefinitionFromObjectLiteralElement ( typeChecker , node ) || emptyArray ) ;
55
56
}
56
57
57
58
// If the node is the name of a BindingElement within an ObjectBindingPattern instead of just returning the
@@ -75,25 +76,7 @@ namespace ts.GoToDefinition {
75
76
} ) ;
76
77
}
77
78
78
- // If the current location we want to find its definition is in an object literal, try to get the contextual type for the
79
- // object literal, lookup the property symbol in the contextual type, and use this for goto-definition.
80
- // For example
81
- // interface Props{
82
- // /*first*/prop1: number
83
- // prop2: boolean
84
- // }
85
- // function Foo(arg: Props) {}
86
- // Foo( { pr/*1*/op1: 10, prop2: true })
87
- const element = getContainingObjectLiteralElement ( node ) ;
88
- if ( element ) {
89
- const contextualType = element && typeChecker . getContextualType ( element . parent ) ;
90
- if ( contextualType ) {
91
- return flatMap ( getPropertySymbolsFromContextualType ( element , typeChecker , contextualType , /*unionSymbolOk*/ false ) , propertySymbol =>
92
- getDefinitionFromSymbol ( typeChecker , propertySymbol , node ) ) ;
93
- }
94
- }
95
-
96
- return getDefinitionFromSymbol ( typeChecker , symbol , node ) ;
79
+ return getDefinitionFromObjectLiteralElement ( typeChecker , node ) || getDefinitionFromSymbol ( typeChecker , symbol , node ) ;
97
80
}
98
81
99
82
/**
@@ -108,6 +91,26 @@ namespace ts.GoToDefinition {
108
91
|| ( ! isCallLikeExpression ( calledDeclaration . parent ) && s === calledDeclaration . parent . symbol ) ;
109
92
}
110
93
94
+ // If the current location we want to find its definition is in an object literal, try to get the contextual type for the
95
+ // object literal, lookup the property symbol in the contextual type, and use this for goto-definition.
96
+ // For example
97
+ // interface Props{
98
+ // /*first*/prop1: number
99
+ // prop2: boolean
100
+ // }
101
+ // function Foo(arg: Props) {}
102
+ // Foo( { pr/*1*/op1: 10, prop2: true })
103
+ function getDefinitionFromObjectLiteralElement ( typeChecker : TypeChecker , node : Node ) {
104
+ const element = getContainingObjectLiteralElement ( node ) ;
105
+ if ( element ) {
106
+ const contextualType = element && typeChecker . getContextualType ( element . parent ) ;
107
+ if ( contextualType ) {
108
+ return flatMap ( getPropertySymbolsFromContextualType ( element , typeChecker , contextualType , /*unionSymbolOk*/ false ) , propertySymbol =>
109
+ getDefinitionFromSymbol ( typeChecker , propertySymbol , node ) ) ;
110
+ }
111
+ }
112
+ }
113
+
111
114
export function getReferenceAtPosition ( sourceFile : SourceFile , position : number , program : Program ) : { reference : FileReference , file : SourceFile } | undefined {
112
115
const referencePath = findReferenceInPosition ( sourceFile . referencedFiles , position ) ;
113
116
if ( referencePath ) {
0 commit comments