Skip to content

Commit 14016a7

Browse files
TypeScript BotDanielRosenwasser
TypeScript Bot
andauthored
Cherry-pick PR #47395 into release-4.5 (#47421)
Component commits: f230a5a Add failing test. 3ba8469 Guard against undefined module bodies in navbar/navtree. Co-authored-by: Daniel Rosenwasser <[email protected]>
1 parent 0854a93 commit 14016a7

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Diff for: src/services/navigationBar.ts

+4-1
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. */
+24
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)