diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 3bce13820d7..048beb21e09 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1961,23 +1961,22 @@ namespace FourSlash { public verifyNavigationBarCount(expected: number) { const items = this.languageService.getNavigationBarItems(this.activeFile.fileName); - const actual = this.getNavigationBarItemsCount(items); + const actual = this.getNavigationBarItemsCount(items[0]); if (expected !== actual) { this.raiseError(`verifyNavigationBarCount failed - found: ${actual} navigation items, expected: ${expected}.`); } } - private getNavigationBarItemsCount(items: ts.NavigationBarItem[]) { - let result = 0; - if (items) { - for (let i = 0, n = items.length; i < n; i++) { - result++; - result += this.getNavigationBarItemsCount(items[i].childItems); - } + private getNavigationBarItemsCount(root: ts.NavigationBarItem) { + ts.Debug.assert(root.kind === ts.ScriptElementKind.moduleElement); + function recur(item: ts.NavigationBarItem) { + let count = 1; + for (const child of item.childItems) + count += recur(child); + return count; } - - return result; + return recur(root); } public verifyNavigationBarContains(name: string, kind: string, fileName?: string, parentName?: string, isAdditionalSpan?: boolean, markerPosition?: number) { diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index bcf0726ffd5..f6f7b741a56 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -9,16 +9,10 @@ namespace ts.NavigationBar { return getJsNavigationBarItems(sourceFile, compilerOptions); } - // If the source file has any child items, then it included in the tree - // and takes lexical ownership of all other top-level items. - let hasGlobalNode = false; - return getItemsWorker(getTopLevelNodes(sourceFile), createTopLevelItem); function getIndent(node: Node): number { - // If we have a global node in the tree, - // then it adds an extra layer of depth to all subnodes. - let indent = hasGlobalNode ? 1 : 0; + let indent = 1; // Global node is the only one with indent 0. let current = node.parent; while (current) { @@ -508,11 +502,6 @@ namespace ts.NavigationBar { function createSourceFileItem(node: SourceFile): ts.NavigationBarItem { const childItems = getItemsWorker(getChildNodes(node.statements), createChildItem); - if (childItems === undefined || childItems.length === 0) { - return undefined; - } - - hasGlobalNode = true; const rootName = isExternalModule(node) ? "\"" + escapeString(getBaseFileName(removeFileExtension(normalizePath(node.fileName)))) + "\"" : "";