From 8eaf58fd135e7187f11184bf5bf0613c8e615555 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 14 Jan 2021 15:27:28 +0200 Subject: [PATCH] fix(42259): omit merging modules with different names --- src/services/navigationBar.ts | 8 ++- ...dules.ts => navigationBarItemsModules1.ts} | 0 .../fourslash/navigationBarItemsModules2.ts | 66 +++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) rename tests/cases/fourslash/{navigationBarItemsModules.ts => navigationBarItemsModules1.ts} (100%) create mode 100644 tests/cases/fourslash/navigationBarItemsModules2.ts diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 0ace63aaced71..ed382c3853b26 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -605,7 +605,8 @@ namespace ts.NavigationBar { case SyntaxKind.SetAccessor: return hasSyntacticModifier(a, ModifierFlags.Static) === hasSyntacticModifier(b, ModifierFlags.Static); case SyntaxKind.ModuleDeclaration: - return areSameModule(a, b); + return areSameModule(a, b) + && getFullyQualifiedModuleName(a) === getFullyQualifiedModuleName(b); default: return true; } @@ -625,7 +626,6 @@ namespace ts.NavigationBar { // We use 1 NavNode to represent 'A.B.C', but there are multiple source nodes. // Only merge module nodes that have the same chain. Don't merge 'A.B.C' with 'A'! function areSameModule(a: ModuleDeclaration, b: ModuleDeclaration): boolean { - // TODO: GH#18217 return a.body!.kind === b.body!.kind && (a.body!.kind !== SyntaxKind.ModuleDeclaration || areSameModule(a.body, b.body)); } @@ -845,6 +845,10 @@ namespace ts.NavigationBar { return getTextOfNode(moduleDeclaration.name); } + return getFullyQualifiedModuleName(moduleDeclaration); + } + + function getFullyQualifiedModuleName(moduleDeclaration: ModuleDeclaration): string { // Otherwise, we need to aggregate each identifier to build up the qualified name. const result = [getTextOfIdentifierOrLiteral(moduleDeclaration.name)]; while (moduleDeclaration.body && moduleDeclaration.body.kind === SyntaxKind.ModuleDeclaration) { diff --git a/tests/cases/fourslash/navigationBarItemsModules.ts b/tests/cases/fourslash/navigationBarItemsModules1.ts similarity index 100% rename from tests/cases/fourslash/navigationBarItemsModules.ts rename to tests/cases/fourslash/navigationBarItemsModules1.ts diff --git a/tests/cases/fourslash/navigationBarItemsModules2.ts b/tests/cases/fourslash/navigationBarItemsModules2.ts new file mode 100644 index 0000000000000..0baaf089e20a2 --- /dev/null +++ b/tests/cases/fourslash/navigationBarItemsModules2.ts @@ -0,0 +1,66 @@ +/// + +////namespace Test.A { } +//// +////namespace Test.B { +//// class Foo { } +////} + +verify.navigationTree({ + text: "", + kind: "script", + childItems: [ + { + text: "Test.A", + kind: "module" + }, + { + text: "Test.B", + kind: "module", + childItems: [ + { + text: "Foo", + kind: "class" + } + ] + } + ] +}); + +verify.navigationBar([ + { + text: "", + kind: "script", + childItems: [ + { + text: "Test.A", + kind: "module" + }, + { + text: "Test.B", + kind: "module" + } + ] + }, + { + text: "Test.A", + kind: "module", + indent: 1 + }, + { + text: "Test.B", + kind: "module", + childItems: [ + { + text: "Foo", + kind: "class" + } + ], + indent: 1 + }, + { + text: "Foo", + kind: "class", + indent: 2 + } +]);