Flattens the NavNode tree to a list of items to appear in the primary navbar menu.
(root)
| 141386 | } |
| 141387 | /** Flattens the NavNode tree to a list of items to appear in the primary navbar menu. */ |
| 141388 | function primaryNavBarMenuItems(root) { |
| 141389 | // The primary (middle) navbar menu displays the general code navigation hierarchy, similar to the navtree. |
| 141390 | // The secondary (right) navbar menu displays the child items of whichever primary item is selected. |
| 141391 | // Some less interesting items without their own child navigation items (e.g. a local variable declaration) only show up in the secondary menu. |
| 141392 | var primaryNavBarMenuItems = []; |
| 141393 | function recur(item) { |
| 141394 | if (shouldAppearInPrimaryNavBarMenu(item)) { |
| 141395 | primaryNavBarMenuItems.push(item); |
| 141396 | if (item.children) { |
| 141397 | for (var _i = 0, _a = item.children; _i < _a.length; _i++) { |
| 141398 | var child = _a[_i]; |
| 141399 | recur(child); |
| 141400 | } |
| 141401 | } |
| 141402 | } |
| 141403 | } |
| 141404 | recur(root); |
| 141405 | return primaryNavBarMenuItems; |
| 141406 | /** Determines if a node should appear in the primary navbar menu. */ |
| 141407 | function shouldAppearInPrimaryNavBarMenu(item) { |
| 141408 | // Items with children should always appear in the primary navbar menu. |
| 141409 | if (item.children) { |
| 141410 | return true; |
| 141411 | } |
| 141412 | // Some nodes are otherwise important enough to always include in the primary navigation menu. |
| 141413 | switch (navigationBarNodeKind(item)) { |
| 141414 | case 257 /* SyntaxKind.ClassDeclaration */: |
| 141415 | case 226 /* SyntaxKind.ClassExpression */: |
| 141416 | case 260 /* SyntaxKind.EnumDeclaration */: |
| 141417 | case 258 /* SyntaxKind.InterfaceDeclaration */: |
| 141418 | case 261 /* SyntaxKind.ModuleDeclaration */: |
| 141419 | case 305 /* SyntaxKind.SourceFile */: |
| 141420 | case 259 /* SyntaxKind.TypeAliasDeclaration */: |
| 141421 | case 345 /* SyntaxKind.JSDocTypedefTag */: |
| 141422 | case 338 /* SyntaxKind.JSDocCallbackTag */: |
| 141423 | return true; |
| 141424 | case 214 /* SyntaxKind.ArrowFunction */: |
| 141425 | case 256 /* SyntaxKind.FunctionDeclaration */: |
| 141426 | case 213 /* SyntaxKind.FunctionExpression */: |
| 141427 | return isTopLevelFunctionDeclaration(item); |
| 141428 | default: |
| 141429 | return false; |
| 141430 | } |
| 141431 | function isTopLevelFunctionDeclaration(item) { |
| 141432 | if (!item.node.body) { |
| 141433 | return false; |
| 141434 | } |
| 141435 | switch (navigationBarNodeKind(item.parent)) { |
| 141436 | case 262 /* SyntaxKind.ModuleBlock */: |
| 141437 | case 305 /* SyntaxKind.SourceFile */: |
| 141438 | case 169 /* SyntaxKind.MethodDeclaration */: |
| 141439 | case 171 /* SyntaxKind.Constructor */: |
| 141440 | return true; |
| 141441 | default: |
| 141442 | return false; |
| 141443 | } |
| 141444 | } |
| 141445 | } |
no test coverage detected
searching dependent graphs…