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