Skip to content

Commit 3bfe91c

Browse files
author
Andy
authored
navigationBar: Fix bug for shorthand ambient module (microsoft#25992)
1 parent af3f737 commit 3bfe91c

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/services/navigationBar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ namespace ts.NavigationBar {
612612
* We store 'A' as associated with a NavNode, and use getModuleName to traverse down again.
613613
*/
614614
function getInteriorModule(decl: ModuleDeclaration): ModuleDeclaration {
615-
return decl.body!.kind === SyntaxKind.ModuleDeclaration ? getInteriorModule(<ModuleDeclaration>decl.body) : decl; // TODO: GH#18217
615+
return decl.body && isModuleDeclaration(decl.body) ? getInteriorModule(decl.body) : decl;
616616
}
617617

618618
function isComputedProperty(member: EnumMember): boolean {

tests/cases/fourslash/navigationBarItemsModules.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
////
55
////declare module 'X2.Y2.Z2' {}
66
////
7+
////declare module "foo";
8+
////
79
////module A.B.C {
810
//// export var x;
911
////}
@@ -24,9 +26,6 @@
2426
//// }
2527
////}
2628

27-
//We have 8 module keywords, and 4 var keywords.
28-
//The declarations of A.B.C.x do not get merged, so the 4 vars are independent.
29-
//The two 'A' modules, however, do get merged, so in reality we have 7 modules.
3029
verify.navigationTree({
3130
"text": "<global>",
3231
"kind": "script",
@@ -36,6 +35,11 @@ verify.navigationTree({
3635
"kind": "module",
3736
"kindModifiers": "declare"
3837
},
38+
{
39+
"text": "\"foo\"",
40+
"kind": "module",
41+
"kindModifiers": "declare"
42+
},
3943
{
4044
"text": "\"X.Y.Z\"",
4145
"kind": "module",
@@ -104,6 +108,11 @@ verify.navigationBar([
104108
"kind": "module",
105109
"kindModifiers": "declare"
106110
},
111+
{
112+
"text": "\"foo\"",
113+
"kind": "module",
114+
"kindModifiers": "declare"
115+
},
107116
{
108117
"text": "\"X.Y.Z\"",
109118
"kind": "module",
@@ -129,6 +138,12 @@ verify.navigationBar([
129138
"kindModifiers": "declare",
130139
"indent": 1
131140
},
141+
{
142+
"text": "\"foo\"",
143+
"kind": "module",
144+
"kindModifiers": "declare",
145+
"indent": 1
146+
},
132147
{
133148
"text": "\"X.Y.Z\"",
134149
"kind": "module",

0 commit comments

Comments
 (0)