Skip to content

Commit 14f33d5

Browse files
Fix for crash in navbar with double ambient modules (#47395)
* Add failing test. * Guard against undefined module bodies in navbar/navtree.
1 parent ed014db commit 14f33d5

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/services/navigationBar.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,10 @@ namespace ts.NavigationBar {
650650
// We use 1 NavNode to represent 'A.B.C', but there are multiple source nodes.
651651
// Only merge module nodes that have the same chain. Don't merge 'A.B.C' with 'A'!
652652
function areSameModule(a: ModuleDeclaration, b: ModuleDeclaration): boolean {
653-
return a.body!.kind === b.body!.kind && (a.body!.kind !== SyntaxKind.ModuleDeclaration || areSameModule(a.body as ModuleDeclaration, b.body as ModuleDeclaration));
653+
if (!a.body || !b.body) {
654+
return a.body === b.body;
655+
}
656+
return a.body.kind === b.body.kind && (a.body.kind !== SyntaxKind.ModuleDeclaration || areSameModule(a.body as ModuleDeclaration, b.body as ModuleDeclaration));
654657
}
655658

656659
/** Merge source into target. Source should be thrown away after this is called. */
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// <reference path="./fourslash.ts" />
2+
3+
//// declare module "foo";
4+
//// declare module "foo";
5+
6+
verify.navigationBar([
7+
{
8+
"text": "<global>",
9+
"kind": "script",
10+
"childItems": [
11+
{
12+
"text": "\"foo\"",
13+
"kind": "module",
14+
"kindModifiers": "declare"
15+
}
16+
]
17+
},
18+
{
19+
"text": "\"foo\"",
20+
"kind": "module",
21+
"kindModifiers": "declare",
22+
"indent": 1
23+
}
24+
]);

0 commit comments

Comments
 (0)