@@ -67,41 +67,21 @@ namespace ts.NavigateTo {
67
67
}
68
68
}
69
69
70
- function tryAddSingleDeclarationName ( declaration : Declaration , containers : string [ ] ) : boolean {
70
+ function tryAddSingleDeclarationName ( declaration : Declaration , containers : Push < string > ) : boolean {
71
71
const name = getNameOfDeclaration ( declaration ) ;
72
- if ( name && isPropertyNameLiteral ( name ) ) {
73
- containers . unshift ( getTextOfIdentifierOrLiteral ( name ) ) ;
74
- return true ;
75
- }
76
- else if ( name && name . kind === SyntaxKind . ComputedPropertyName ) {
77
- return tryAddComputedPropertyName ( name . expression , containers , /*includeLastPortion*/ true ) ;
78
- }
79
- else {
80
- // Don't know how to add this.
81
- return false ;
82
- }
72
+ return ! ! name && ( pushLiteral ( name , containers ) || name . kind === SyntaxKind . ComputedPropertyName && tryAddComputedPropertyName ( name . expression , containers ) ) ;
83
73
}
84
74
85
75
// Only added the names of computed properties if they're simple dotted expressions, like:
86
76
//
87
77
// [X.Y.Z]() { }
88
- function tryAddComputedPropertyName ( expression : Expression , containers : string [ ] , includeLastPortion : boolean ) : boolean {
89
- if ( isPropertyNameLiteral ( expression ) ) {
90
- const text = getTextOfIdentifierOrLiteral ( expression ) ;
91
- if ( includeLastPortion ) {
92
- containers . unshift ( text ) ;
93
- }
94
- return true ;
95
- }
96
- if ( isPropertyAccessExpression ( expression ) ) {
97
- if ( includeLastPortion ) {
98
- containers . unshift ( expression . name . text ) ;
99
- }
100
-
101
- return tryAddComputedPropertyName ( expression . expression , containers , /*includeLastPortion*/ true ) ;
102
- }
78
+ function tryAddComputedPropertyName ( expression : Expression , containers : Push < string > ) : boolean {
79
+ return pushLiteral ( expression , containers )
80
+ || isPropertyAccessExpression ( expression ) && ( containers . push ( expression . name . text ) , true ) && tryAddComputedPropertyName ( expression . expression , containers ) ;
81
+ }
103
82
104
- return false ;
83
+ function pushLiteral ( node : Node , containers : Push < string > ) : boolean {
84
+ return isPropertyNameLiteral ( node ) && ( containers . push ( getTextOfIdentifierOrLiteral ( node ) ) , true ) ;
105
85
}
106
86
107
87
function getContainers ( declaration : Declaration ) : ReadonlyArray < string > {
@@ -110,9 +90,11 @@ namespace ts.NavigateTo {
110
90
// First, if we started with a computed property name, then add all but the last
111
91
// portion into the container array.
112
92
const name = getNameOfDeclaration ( declaration ) ;
113
- if ( name && name . kind === SyntaxKind . ComputedPropertyName && ! tryAddComputedPropertyName ( name . expression , containers , /*includeLastPortion*/ false ) ) {
93
+ if ( name && name . kind === SyntaxKind . ComputedPropertyName && ! tryAddComputedPropertyName ( name . expression , containers ) ) {
114
94
return emptyArray ;
115
95
}
96
+ // Don't include the last portion.
97
+ containers . shift ( ) ;
116
98
117
99
// Now, walk up our containers, adding all their names to the container array.
118
100
let container = getContainerNode ( declaration ) ;
@@ -125,7 +107,7 @@ namespace ts.NavigateTo {
125
107
container = getContainerNode ( container ) ;
126
108
}
127
109
128
- return containers ;
110
+ return containers . reverse ( ) ;
129
111
}
130
112
131
113
function compareNavigateToItems ( i1 : RawNavigateToItem , i2 : RawNavigateToItem ) {
0 commit comments