@@ -14,25 +14,27 @@ namespace ts.NavigationBar {
14
14
indent : number ; // # of parents
15
15
}
16
16
17
- export function getNavigationBarItems ( sourceFile : SourceFile , cancellationToken : ThrottledCancellationToken ) : NavigationBarItem [ ] {
17
+ export function getNavigationBarItems ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : NavigationBarItem [ ] {
18
18
curCancellationToken = cancellationToken ;
19
19
curSourceFile = sourceFile ;
20
20
try {
21
21
return map ( topLevelItems ( rootNavigationBarNode ( sourceFile ) ) , convertToTopLevelItem ) ;
22
22
}
23
23
finally {
24
24
curSourceFile = undefined ;
25
+ curCancellationToken = undefined ;
25
26
}
26
27
}
27
28
28
- export function getNavigationTree ( sourceFile : SourceFile , cancellationToken : ThrottledCancellationToken ) : NavigationTree {
29
+ export function getNavigationTree ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : NavigationTree {
29
30
curCancellationToken = cancellationToken ;
30
31
curSourceFile = sourceFile ;
31
32
try {
32
33
return convertToTree ( rootNavigationBarNode ( sourceFile ) ) ;
33
34
}
34
35
finally {
35
36
curSourceFile = undefined ;
37
+ curCancellationToken = undefined ;
36
38
}
37
39
}
38
40
@@ -112,144 +114,140 @@ namespace ts.NavigationBar {
112
114
parent = parentsStack . pop ( ) ;
113
115
}
114
116
115
- function addNodeWithRecursiveChild ( node : Node , child : Node , addChildrenRecursively : ( node : Node ) => void ) : void {
117
+ function addNodeWithRecursiveChild ( node : Node , child : Node ) : void {
116
118
startNode ( node ) ;
117
119
addChildrenRecursively ( child ) ;
118
120
endNode ( ) ;
119
121
}
120
122
121
123
/** Look for navigation bar items in node's subtree, adding them to the current `parent`. */
122
124
function addChildrenRecursively ( node : Node ) : void {
123
- function addChildrenRecursively ( node : Node ) : void {
124
- curCancellationToken . throwIfCancellationRequested ( ) ;
125
+ curCancellationToken . throwIfCancellationRequested ( ) ;
125
126
126
- if ( ! node || isToken ( node ) ) {
127
- return ;
128
- }
127
+ if ( ! node || isToken ( node ) ) {
128
+ return ;
129
+ }
129
130
130
- switch ( node . kind ) {
131
- case SyntaxKind . Constructor :
132
- // Get parameter properties, and treat them as being on the *same* level as the constructor, not under it.
133
- const ctr = < ConstructorDeclaration > node ;
134
- addNodeWithRecursiveChild ( ctr , ctr . body , addChildrenRecursively ) ;
135
-
136
- // Parameter properties are children of the class, not the constructor.
137
- for ( const param of ctr . parameters ) {
138
- if ( isParameterPropertyDeclaration ( param ) ) {
139
- addLeafNode ( param ) ;
140
- }
131
+ switch ( node . kind ) {
132
+ case SyntaxKind . Constructor :
133
+ // Get parameter properties, and treat them as being on the *same* level as the constructor, not under it.
134
+ const ctr = < ConstructorDeclaration > node ;
135
+ addNodeWithRecursiveChild ( ctr , ctr . body ) ;
136
+
137
+ // Parameter properties are children of the class, not the constructor.
138
+ for ( const param of ctr . parameters ) {
139
+ if ( isParameterPropertyDeclaration ( param ) ) {
140
+ addLeafNode ( param ) ;
141
141
}
142
- break ;
142
+ }
143
+ break ;
144
+
145
+ case SyntaxKind . MethodDeclaration :
146
+ case SyntaxKind . GetAccessor :
147
+ case SyntaxKind . SetAccessor :
148
+ case SyntaxKind . MethodSignature :
149
+ if ( ! hasDynamicName ( ( < ClassElement | TypeElement > node ) ) ) {
150
+ addNodeWithRecursiveChild ( node , ( < FunctionLikeDeclaration > node ) . body ) ;
151
+ }
152
+ break ;
143
153
144
- case SyntaxKind . MethodDeclaration :
145
- case SyntaxKind . GetAccessor :
146
- case SyntaxKind . SetAccessor :
147
- case SyntaxKind . MethodSignature :
148
- if ( ! hasDynamicName ( ( < ClassElement | TypeElement > node ) ) ) {
149
- addNodeWithRecursiveChild ( node , ( < FunctionLikeDeclaration > node ) . body , addChildrenRecursively ) ;
150
- }
151
- break ;
154
+ case SyntaxKind . PropertyDeclaration :
155
+ case SyntaxKind . PropertySignature :
156
+ if ( ! hasDynamicName ( ( < ClassElement | TypeElement > node ) ) ) {
157
+ addLeafNode ( node ) ;
158
+ }
159
+ break ;
160
+
161
+ case SyntaxKind . ImportClause :
162
+ const importClause = < ImportClause > node ;
163
+ // Handle default import case e.g.:
164
+ // import d from "mod";
165
+ if ( importClause . name ) {
166
+ addLeafNode ( importClause ) ;
167
+ }
152
168
153
- case SyntaxKind . PropertyDeclaration :
154
- case SyntaxKind . PropertySignature :
155
- if ( ! hasDynamicName ( ( < ClassElement | TypeElement > node ) ) ) {
156
- addLeafNode ( node ) ;
169
+ // Handle named bindings in imports e.g.:
170
+ // import * as NS from "mod";
171
+ // import {a, b as B} from "mod";
172
+ const { namedBindings} = importClause ;
173
+ if ( namedBindings ) {
174
+ if ( namedBindings . kind === SyntaxKind . NamespaceImport ) {
175
+ addLeafNode ( < NamespaceImport > namedBindings ) ;
157
176
}
158
- break ;
159
-
160
- case SyntaxKind . ImportClause :
161
- const importClause = < ImportClause > node ;
162
- // Handle default import case e.g.:
163
- // import d from "mod";
164
- if ( importClause . name ) {
165
- addLeafNode ( importClause ) ;
166
- }
167
-
168
- // Handle named bindings in imports e.g.:
169
- // import * as NS from "mod";
170
- // import {a, b as B} from "mod";
171
- const { namedBindings} = importClause ;
172
- if ( namedBindings ) {
173
- if ( namedBindings . kind === SyntaxKind . NamespaceImport ) {
174
- addLeafNode ( < NamespaceImport > namedBindings ) ;
175
- }
176
- else {
177
- for ( const element of ( < NamedImports > namedBindings ) . elements ) {
178
- addLeafNode ( element ) ;
179
- }
177
+ else {
178
+ for ( const element of ( < NamedImports > namedBindings ) . elements ) {
179
+ addLeafNode ( element ) ;
180
180
}
181
181
}
182
- break ;
182
+ }
183
+ break ;
184
+
185
+ case SyntaxKind . BindingElement :
186
+ case SyntaxKind . VariableDeclaration :
187
+ const decl = < VariableDeclaration > node ;
188
+ const name = decl . name ;
189
+ if ( isBindingPattern ( name ) ) {
190
+ addChildrenRecursively ( name ) ;
191
+ }
192
+ else if ( decl . initializer && isFunctionOrClassExpression ( decl . initializer ) ) {
193
+ // For `const x = function() {}`, just use the function node, not the const.
194
+ addChildrenRecursively ( decl . initializer ) ;
195
+ }
196
+ else {
197
+ addNodeWithRecursiveChild ( decl , decl . initializer ) ;
198
+ }
199
+ break ;
183
200
184
- case SyntaxKind . BindingElement :
185
- case SyntaxKind . VariableDeclaration :
186
- const decl = < VariableDeclaration > node ;
187
- const name = decl . name ;
188
- if ( isBindingPattern ( name ) ) {
189
- addChildrenRecursively ( name ) ;
190
- }
191
- else if ( decl . initializer && isFunctionOrClassExpression ( decl . initializer ) ) {
192
- // For `const x = function() {}`, just use the function node, not the const.
193
- addChildrenRecursively ( decl . initializer ) ;
194
- }
195
- else {
196
- addNodeWithRecursiveChild ( decl , decl . initializer , addChildrenRecursively ) ;
201
+ case SyntaxKind . ArrowFunction :
202
+ case SyntaxKind . FunctionDeclaration :
203
+ case SyntaxKind . FunctionExpression :
204
+ addNodeWithRecursiveChild ( node , ( < FunctionLikeDeclaration > node ) . body ) ;
205
+ break ;
206
+
207
+ case SyntaxKind . EnumDeclaration :
208
+ startNode ( node ) ;
209
+ for ( const member of ( < EnumDeclaration > node ) . members ) {
210
+ if ( ! isComputedProperty ( member ) ) {
211
+ addLeafNode ( member ) ;
197
212
}
198
- break ;
199
-
200
- case SyntaxKind . ArrowFunction :
201
- case SyntaxKind . FunctionDeclaration :
202
- case SyntaxKind . FunctionExpression :
203
- addNodeWithRecursiveChild ( node , ( < FunctionLikeDeclaration > node ) . body , addChildrenRecursively ) ;
204
- break ;
213
+ }
214
+ endNode ( ) ;
215
+ break ;
205
216
206
- case SyntaxKind . EnumDeclaration :
207
- startNode ( node ) ;
208
- for ( const member of ( < EnumDeclaration > node ) . members ) {
209
- if ( ! isComputedProperty ( member ) ) {
210
- addLeafNode ( member ) ;
211
- }
212
- }
213
- endNode ( ) ;
214
- break ;
217
+ case SyntaxKind . ClassDeclaration :
218
+ case SyntaxKind . ClassExpression :
219
+ case SyntaxKind . InterfaceDeclaration :
220
+ startNode ( node ) ;
221
+ for ( const member of ( < InterfaceDeclaration > node ) . members ) {
222
+ addChildrenRecursively ( member ) ;
223
+ }
224
+ endNode ( ) ;
225
+ break ;
215
226
216
- case SyntaxKind . ClassDeclaration :
217
- case SyntaxKind . ClassExpression :
218
- case SyntaxKind . InterfaceDeclaration :
219
- startNode ( node ) ;
220
- for ( const member of ( < InterfaceDeclaration > node ) . members ) {
221
- addChildrenRecursively ( member ) ;
222
- }
223
- endNode ( ) ;
224
- break ;
227
+ case SyntaxKind . ModuleDeclaration :
228
+ addNodeWithRecursiveChild ( node , getInteriorModule ( < ModuleDeclaration > node ) . body ) ;
229
+ break ;
225
230
226
- case SyntaxKind . ModuleDeclaration :
227
- addNodeWithRecursiveChild ( node , getInteriorModule ( < ModuleDeclaration > node ) . body , addChildrenRecursively ) ;
228
- break ;
229
-
230
- case SyntaxKind . ExportSpecifier :
231
- case SyntaxKind . ImportEqualsDeclaration :
232
- case SyntaxKind . IndexSignature :
233
- case SyntaxKind . CallSignature :
234
- case SyntaxKind . ConstructSignature :
235
- case SyntaxKind . TypeAliasDeclaration :
236
- addLeafNode ( node ) ;
237
- break ;
231
+ case SyntaxKind . ExportSpecifier :
232
+ case SyntaxKind . ImportEqualsDeclaration :
233
+ case SyntaxKind . IndexSignature :
234
+ case SyntaxKind . CallSignature :
235
+ case SyntaxKind . ConstructSignature :
236
+ case SyntaxKind . TypeAliasDeclaration :
237
+ addLeafNode ( node ) ;
238
+ break ;
238
239
239
- default :
240
- forEach ( node . jsDoc , jsDoc => {
241
- forEach ( jsDoc . tags , tag => {
242
- if ( tag . kind === SyntaxKind . JSDocTypedefTag ) {
243
- addLeafNode ( tag ) ;
244
- }
245
- } ) ;
240
+ default :
241
+ forEach ( node . jsDoc , jsDoc => {
242
+ forEach ( jsDoc . tags , tag => {
243
+ if ( tag . kind === SyntaxKind . JSDocTypedefTag ) {
244
+ addLeafNode ( tag ) ;
245
+ }
246
246
} ) ;
247
+ } ) ;
247
248
248
- forEachChild ( node , addChildrenRecursively ) ;
249
- }
249
+ forEachChild ( node , addChildrenRecursively ) ;
250
250
}
251
-
252
- addChildrenRecursively ( node ) ;
253
251
}
254
252
255
253
/** Merge declarations of the same kind. */
0 commit comments