Skip to content

Commit 8eaf58f

Browse files
committed
fix(42259): omit merging modules with different names
1 parent 8ddea6b commit 8eaf58f

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

src/services/navigationBar.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,8 @@ namespace ts.NavigationBar {
605605
case SyntaxKind.SetAccessor:
606606
return hasSyntacticModifier(a, ModifierFlags.Static) === hasSyntacticModifier(b, ModifierFlags.Static);
607607
case SyntaxKind.ModuleDeclaration:
608-
return areSameModule(<ModuleDeclaration>a, <ModuleDeclaration>b);
608+
return areSameModule(<ModuleDeclaration>a, <ModuleDeclaration>b)
609+
&& getFullyQualifiedModuleName(<ModuleDeclaration>a) === getFullyQualifiedModuleName(<ModuleDeclaration>b);
609610
default:
610611
return true;
611612
}
@@ -625,7 +626,6 @@ namespace ts.NavigationBar {
625626
// We use 1 NavNode to represent 'A.B.C', but there are multiple source nodes.
626627
// Only merge module nodes that have the same chain. Don't merge 'A.B.C' with 'A'!
627628
function areSameModule(a: ModuleDeclaration, b: ModuleDeclaration): boolean {
628-
// TODO: GH#18217
629629
return a.body!.kind === b.body!.kind && (a.body!.kind !== SyntaxKind.ModuleDeclaration || areSameModule(<ModuleDeclaration>a.body, <ModuleDeclaration>b.body));
630630
}
631631

@@ -845,6 +845,10 @@ namespace ts.NavigationBar {
845845
return getTextOfNode(moduleDeclaration.name);
846846
}
847847

848+
return getFullyQualifiedModuleName(moduleDeclaration);
849+
}
850+
851+
function getFullyQualifiedModuleName(moduleDeclaration: ModuleDeclaration): string {
848852
// Otherwise, we need to aggregate each identifier to build up the qualified name.
849853
const result = [getTextOfIdentifierOrLiteral(moduleDeclaration.name)];
850854
while (moduleDeclaration.body && moduleDeclaration.body.kind === SyntaxKind.ModuleDeclaration) {
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////namespace Test.A { }
4+
////
5+
////namespace Test.B {
6+
//// class Foo { }
7+
////}
8+
9+
verify.navigationTree({
10+
text: "<global>",
11+
kind: "script",
12+
childItems: [
13+
{
14+
text: "Test.A",
15+
kind: "module"
16+
},
17+
{
18+
text: "Test.B",
19+
kind: "module",
20+
childItems: [
21+
{
22+
text: "Foo",
23+
kind: "class"
24+
}
25+
]
26+
}
27+
]
28+
});
29+
30+
verify.navigationBar([
31+
{
32+
text: "<global>",
33+
kind: "script",
34+
childItems: [
35+
{
36+
text: "Test.A",
37+
kind: "module"
38+
},
39+
{
40+
text: "Test.B",
41+
kind: "module"
42+
}
43+
]
44+
},
45+
{
46+
text: "Test.A",
47+
kind: "module",
48+
indent: 1
49+
},
50+
{
51+
text: "Test.B",
52+
kind: "module",
53+
childItems: [
54+
{
55+
text: "Foo",
56+
kind: "class"
57+
}
58+
],
59+
indent: 1
60+
},
61+
{
62+
text: "Foo",
63+
kind: "class",
64+
indent: 2
65+
}
66+
]);

0 commit comments

Comments
 (0)