22
33/* @internal */
44namespace ts . NavigationBar {
5+ /**
6+ * Matches all whitespace characters in a string. Eg:
7+ *
8+ * "app.
9+ *
10+ * onactivated"
11+ *
12+ * matches because of the newline, whereas
13+ *
14+ * "app.onactivated"
15+ *
16+ * does not match.
17+ */
18+ const whiteSpaceRegex = / \s + / g;
19+
20+ // Keep sourceFile handy so we don't have to search for it every time we need to call `getText`.
21+ let curCancellationToken : CancellationToken ;
22+ let curSourceFile : SourceFile ;
23+
24+ /**
25+ * For performance, we keep navigation bar parents on a stack rather than passing them through each recursion.
26+ * `parent` is the current parent and is *not* stored in parentsStack.
27+ * `startNode` sets a new parent and `endNode` returns to the previous parent.
28+ */
29+ let parentsStack : NavigationBarNode [ ] = [ ] ;
30+ let parent : NavigationBarNode ;
31+
32+ // NavigationBarItem requires an array, but will not mutate it, so just give it this for performance.
33+ let emptyChildItemArray : NavigationBarItem [ ] = [ ] ;
34+
535 /**
636 * Represents a navigation bar item and its children.
737 * The returned NavigationBarItem is more complicated and doesn't include 'parent', so we use these to do work before converting.
@@ -21,8 +51,7 @@ namespace ts.NavigationBar {
2151 return map ( topLevelItems ( rootNavigationBarNode ( sourceFile ) ) , convertToTopLevelItem ) ;
2252 }
2353 finally {
24- curSourceFile = undefined ;
25- curCancellationToken = undefined ;
54+ reset ( ) ;
2655 }
2756 }
2857
@@ -33,14 +62,18 @@ namespace ts.NavigationBar {
3362 return convertToTree ( rootNavigationBarNode ( sourceFile ) ) ;
3463 }
3564 finally {
36- curSourceFile = undefined ;
37- curCancellationToken = undefined ;
65+ reset ( ) ;
3866 }
3967 }
4068
41- // Keep sourceFile handy so we don't have to search for it every time we need to call `getText`.
42- let curCancellationToken : CancellationToken ;
43- let curSourceFile : SourceFile ;
69+ function reset ( ) {
70+ curSourceFile = undefined ;
71+ curCancellationToken = undefined ;
72+ parentsStack = [ ] ;
73+ parent = undefined ;
74+ emptyChildItemArray = [ ] ;
75+ }
76+
4477 function nodeText ( node : Node ) : string {
4578 return node . getText ( curSourceFile ) ;
4679 }
@@ -58,14 +91,6 @@ namespace ts.NavigationBar {
5891 }
5992 }
6093
61- /*
62- For performance, we keep navigation bar parents on a stack rather than passing them through each recursion.
63- `parent` is the current parent and is *not* stored in parentsStack.
64- `startNode` sets a new parent and `endNode` returns to the previous parent.
65- */
66- const parentsStack : NavigationBarNode [ ] = [ ] ;
67- let parent : NavigationBarNode ;
68-
6994 function rootNavigationBarNode ( sourceFile : SourceFile ) : NavigationBarNode {
7095 Debug . assert ( ! parentsStack . length ) ;
7196 const root : NavigationBarNode = { node : sourceFile , additionalNodes : undefined , parent : undefined , children : undefined , indent : 0 } ;
@@ -500,9 +525,6 @@ namespace ts.NavigationBar {
500525 }
501526 }
502527
503- // NavigationBarItem requires an array, but will not mutate it, so just give it this for performance.
504- const emptyChildItemArray : NavigationBarItem [ ] = [ ] ;
505-
506528 function convertToTree ( n : NavigationBarNode ) : NavigationTree {
507529 return {
508530 text : getItemName ( n . node ) ,
@@ -623,19 +645,4 @@ namespace ts.NavigationBar {
623645 function isFunctionOrClassExpression ( node : Node ) : boolean {
624646 return node . kind === SyntaxKind . FunctionExpression || node . kind === SyntaxKind . ArrowFunction || node . kind === SyntaxKind . ClassExpression ;
625647 }
626-
627- /**
628- * Matches all whitespace characters in a string. Eg:
629- *
630- * "app.
631- *
632- * onactivated"
633- *
634- * matches because of the newline, whereas
635- *
636- * "app.onactivated"
637- *
638- * does not match.
639- */
640- const whiteSpaceRegex = / \s + / g;
641648}
0 commit comments