diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index b4c7c5a2c24..f23fa4c3493 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -612,7 +612,7 @@ namespace ts.NavigationBar { * We store 'A' as associated with a NavNode, and use getModuleName to traverse down again. */ function getInteriorModule(decl: ModuleDeclaration): ModuleDeclaration { - return decl.body!.kind === SyntaxKind.ModuleDeclaration ? getInteriorModule(decl.body) : decl; // TODO: GH#18217 + return decl.body && isModuleDeclaration(decl.body) ? getInteriorModule(decl.body) : decl; } function isComputedProperty(member: EnumMember): boolean { diff --git a/tests/cases/fourslash/navigationBarItemsModules.ts b/tests/cases/fourslash/navigationBarItemsModules.ts index fd5907e2bc7..5fe856c8979 100644 --- a/tests/cases/fourslash/navigationBarItemsModules.ts +++ b/tests/cases/fourslash/navigationBarItemsModules.ts @@ -4,6 +4,8 @@ //// ////declare module 'X2.Y2.Z2' {} //// +////declare module "foo"; +//// ////module A.B.C { //// export var x; ////} @@ -24,9 +26,6 @@ //// } ////} -//We have 8 module keywords, and 4 var keywords. -//The declarations of A.B.C.x do not get merged, so the 4 vars are independent. -//The two 'A' modules, however, do get merged, so in reality we have 7 modules. verify.navigationTree({ "text": "", "kind": "script", @@ -36,6 +35,11 @@ verify.navigationTree({ "kind": "module", "kindModifiers": "declare" }, + { + "text": "\"foo\"", + "kind": "module", + "kindModifiers": "declare" + }, { "text": "\"X.Y.Z\"", "kind": "module", @@ -104,6 +108,11 @@ verify.navigationBar([ "kind": "module", "kindModifiers": "declare" }, + { + "text": "\"foo\"", + "kind": "module", + "kindModifiers": "declare" + }, { "text": "\"X.Y.Z\"", "kind": "module", @@ -129,6 +138,12 @@ verify.navigationBar([ "kindModifiers": "declare", "indent": 1 }, + { + "text": "\"foo\"", + "kind": "module", + "kindModifiers": "declare", + "indent": 1 + }, { "text": "\"X.Y.Z\"", "kind": "module",