@@ -26,8 +26,12 @@ module ts.NavigateTo {
2626 // It was a match! If the pattern has dots in it, then also see if hte
2727 // declaration container matches as well.
2828 if ( patternMatcher . patternContainsDots ) {
29- var containerName = getContainerName ( getContainerNode ( declaration ) ) ;
30- matches = patternMatcher . getMatches ( name , containerName ) ;
29+ var containers = getContainers ( declaration ) ;
30+ if ( ! containers ) {
31+ return undefined ;
32+ }
33+
34+ matches = patternMatcher . getMatches ( containers , name ) ;
3135
3236 if ( ! matches ) {
3337 continue ;
@@ -36,7 +40,7 @@ module ts.NavigateTo {
3640
3741 var fileName = sourceFile . fileName ;
3842 var matchKind = bestMatchKind ( matches ) ;
39- rawItems . push ( { name, fileName, matchKind, isCaseSensitive : isCaseSensitive ( matches ) , declaration } ) ;
43+ rawItems . push ( { name, fileName, matchKind, isCaseSensitive : allMatchesAreCaseSensitive ( matches ) , declaration } ) ;
4044 }
4145 }
4246 } ) ;
@@ -50,7 +54,7 @@ module ts.NavigateTo {
5054
5155 return items ;
5256
53- function isCaseSensitive ( matches : PatternMatch [ ] ) : boolean {
57+ function allMatchesAreCaseSensitive ( matches : PatternMatch [ ] ) : boolean {
5458 Debug . assert ( matches . length > 0 ) ;
5559
5660 // This is a case sensitive match, only if all the submatches were case sensitive.
@@ -64,26 +68,99 @@ module ts.NavigateTo {
6468 }
6569
6670 function getDeclarationName ( declaration : Declaration ) : string {
67- if ( declaration . name . kind === SyntaxKind . Identifier ||
68- declaration . name . kind === SyntaxKind . StringLiteral ||
69- declaration . name . kind === SyntaxKind . NumericLiteral ) {
71+ var result = getTextOfIdentifierOrLiteral ( declaration . name ) ;
72+ if ( result !== undefined ) {
73+ return result ;
74+ }
75+
76+ if ( declaration . name . kind === SyntaxKind . ComputedPropertyName ) {
77+ var expr = ( < ComputedPropertyName > declaration . name ) . expression ;
78+ if ( expr . kind === SyntaxKind . PropertyAccessExpression ) {
79+ return ( < PropertyAccessExpression > expr ) . name . text ;
80+ }
81+
82+ return getTextOfIdentifierOrLiteral ( expr ) ;
83+ }
84+
85+ return undefined ;
86+ }
87+
88+ function getTextOfIdentifierOrLiteral ( node : Node ) {
89+ if ( node . kind === SyntaxKind . Identifier ||
90+ node . kind === SyntaxKind . StringLiteral ||
91+ node . kind === SyntaxKind . NumericLiteral ) {
7092
71- return ( < Identifier > declaration . name ) . text ;
93+ return ( < Identifier | LiteralExpression > node ) . text ;
7294 }
7395
7496 return undefined ;
7597 }
7698
77- function getContainerName ( declaration : Declaration ) : string {
78- var name = getDeclarationName ( declaration ) ;
79- if ( name === undefined ) {
80- return undefined ;
99+ function tryAddSingleDeclarationName ( declaration : Declaration , containers : string [ ] ) {
100+ if ( declaration && declaration . name ) {
101+ var text = getTextOfIdentifierOrLiteral ( declaration . name ) ;
102+ if ( text !== undefined ) {
103+ containers . unshift ( text ) ;
104+ }
105+ else if ( declaration . name . kind === SyntaxKind . ComputedPropertyName ) {
106+ return tryAddComputedPropertyName ( ( < ComputedPropertyName > declaration . name ) . expression , containers , /*includeLastPortion:*/ true ) ;
107+ }
108+ else {
109+ // Don't know how to add this.
110+ return false
111+ }
112+ }
113+
114+ return true ;
115+ }
116+
117+ // Only added the names of computed properties if they're simple dotted expressions, like:
118+ //
119+ // [X.Y.Z]() { }
120+ function tryAddComputedPropertyName ( expression : Expression , containers : string [ ] , includeLastPortion : boolean ) : boolean {
121+ var text = getTextOfIdentifierOrLiteral ( expression ) ;
122+ if ( text !== undefined ) {
123+ if ( includeLastPortion ) {
124+ containers . unshift ( text ) ;
125+ }
126+ return true ;
127+ }
128+
129+ if ( expression . kind === SyntaxKind . PropertyAccessExpression ) {
130+ var propertyAccess = < PropertyAccessExpression > expression ;
131+ if ( includeLastPortion ) {
132+ containers . unshift ( propertyAccess . name . text ) ;
133+ }
134+
135+ return tryAddComputedPropertyName ( propertyAccess . expression , containers , /*includeLastPortion:*/ true ) ;
136+ }
137+
138+ return false ;
139+ }
140+
141+ function getContainers ( declaration : Declaration ) {
142+ var containers : string [ ] = [ ] ;
143+
144+ // First, if we started with a computed property name, then add all but the last
145+ // portion into the container array.
146+ if ( declaration . name . kind === SyntaxKind . ComputedPropertyName ) {
147+ if ( ! tryAddComputedPropertyName ( ( < ComputedPropertyName > declaration . name ) . expression , containers , /*includeLastPortion:*/ false ) ) {
148+ return undefined ;
149+ }
150+ }
151+
152+ // Now, walk up our containers, adding all their names to the container array.
153+ declaration = getContainerNode ( declaration ) ;
154+
155+ while ( declaration ) {
156+ if ( ! tryAddSingleDeclarationName ( declaration , containers ) ) {
157+ return undefined ;
158+ }
159+
160+ declaration = getContainerNode ( declaration ) ;
81161 }
82162
83- var container = getContainerNode ( declaration ) ;
84- return container && container . name
85- ? getContainerName ( container ) + "." + name
86- : name ;
163+ return containers ;
87164 }
88165
89166 function bestMatchKind ( matches : PatternMatch [ ] ) {
0 commit comments