@@ -133,7 +133,7 @@ namespace ts.NavigationBar {
133
133
/** Call after calling `startNode` and adding children to it. */
134
134
function endNode ( ) : void {
135
135
if ( parent . children ) {
136
- mergeChildren ( parent . children ) ;
136
+ mergeChildren ( parent . children , parent ) ;
137
137
sortChildren ( parent . children ) ;
138
138
}
139
139
parent = parentsStack . pop ( ) ! ;
@@ -304,7 +304,7 @@ namespace ts.NavigationBar {
304
304
}
305
305
306
306
/** Merge declarations of the same kind. */
307
- function mergeChildren ( children : NavigationBarNode [ ] ) : void {
307
+ function mergeChildren ( children : NavigationBarNode [ ] , node : NavigationBarNode ) : void {
308
308
const nameToItems = createMap < NavigationBarNode | NavigationBarNode [ ] > ( ) ;
309
309
filterMutate ( children , child => {
310
310
const declName = getNameOfDeclaration ( < Declaration > child . node ) ;
@@ -322,7 +322,7 @@ namespace ts.NavigationBar {
322
322
323
323
if ( itemsWithSameName instanceof Array ) {
324
324
for ( const itemWithSameName of itemsWithSameName ) {
325
- if ( tryMerge ( itemWithSameName , child ) ) {
325
+ if ( tryMerge ( itemWithSameName , child , node ) ) {
326
326
return false ;
327
327
}
328
328
}
@@ -331,7 +331,7 @@ namespace ts.NavigationBar {
331
331
}
332
332
else {
333
333
const itemWithSameName = itemsWithSameName ;
334
- if ( tryMerge ( itemWithSameName , child ) ) {
334
+ if ( tryMerge ( itemWithSameName , child , node ) ) {
335
335
return false ;
336
336
}
337
337
nameToItems . set ( name , [ itemWithSameName , child ] ) ;
@@ -340,17 +340,17 @@ namespace ts.NavigationBar {
340
340
} ) ;
341
341
}
342
342
343
- function tryMerge ( a : NavigationBarNode , b : NavigationBarNode ) : boolean {
344
- if ( shouldReallyMerge ( a . node , b . node ) ) {
343
+ function tryMerge ( a : NavigationBarNode , b : NavigationBarNode , parent : NavigationBarNode ) : boolean {
344
+ if ( shouldReallyMerge ( a . node , b . node , parent ) ) {
345
345
merge ( a , b ) ;
346
346
return true ;
347
347
}
348
348
return false ;
349
349
}
350
350
351
351
/** a and b have the same name, but they may not be mergeable. */
352
- function shouldReallyMerge ( a : Node , b : Node ) : boolean {
353
- if ( a . kind !== b . kind ) {
352
+ function shouldReallyMerge ( a : Node , b : Node , parent : NavigationBarNode ) : boolean {
353
+ if ( a . kind !== b . kind || a . parent !== b . parent && ! ( isOwnChild ( a , parent ) && isOwnChild ( b , parent ) ) ) {
354
354
return false ;
355
355
}
356
356
switch ( a . kind ) {
@@ -366,6 +366,13 @@ namespace ts.NavigationBar {
366
366
}
367
367
}
368
368
369
+ // We want to merge own children like `I` in in `module A { interface I {} } module A { interface I {} }`
370
+ // We don't want to merge unrelated children like `m` in `const o = { a: { m() {} }, b: { m() {} } };`
371
+ function isOwnChild ( n : Node , parent : NavigationBarNode ) : boolean {
372
+ const par = isModuleBlock ( n . parent ) ? n . parent . parent : n . parent ;
373
+ return par === parent . node || contains ( parent . additionalNodes , par ) ;
374
+ }
375
+
369
376
// We use 1 NavNode to represent 'A.B.C', but there are multiple source nodes.
370
377
// Only merge module nodes that have the same chain. Don't merge 'A.B.C' with 'A'!
371
378
function areSameModule ( a : ModuleDeclaration , b : ModuleDeclaration ) : boolean {
@@ -383,7 +390,7 @@ namespace ts.NavigationBar {
383
390
384
391
target . children = concatenate ( target . children , source . children ) ;
385
392
if ( target . children ) {
386
- mergeChildren ( target . children ) ;
393
+ mergeChildren ( target . children , target ) ;
387
394
sortChildren ( target . children ) ;
388
395
}
389
396
}
0 commit comments