@@ -567,8 +567,10 @@ namespace ts {
567
567
// and this case is specially handled. Module augmentations should only be merged with original module definition
568
568
// and should never be merged directly with other augmentation, and the latter case would be possible if automatic merge is allowed.
569
569
if ( isJSDocTypeAlias ( node ) ) Debug . assert ( isInJSFile ( node ) ) ; // We shouldn't add symbols for JSDoc nodes if not in a JS file.
570
- if ( ( ! isAmbientModule ( node ) && ( hasExportModifier || container . flags & NodeFlags . ExportContext ) ) || isJSDocTypeAlias ( node ) ) {
571
- if ( ! container . locals || ( hasSyntacticModifier ( node , ModifierFlags . Default ) && ! getDeclarationName ( node ) ) ) {
570
+ const declarationName = getDeclarationName ( node ) ;
571
+ if ( ( ! isAmbientModule ( node ) && ( hasExportModifier || container . flags & NodeFlags . ExportContext ) )
572
+ || ( isJSDocTypeAlias ( node ) && ! nameIsExported ( container , declarationName ) ) ) {
573
+ if ( ! container . locals || ( hasSyntacticModifier ( node , ModifierFlags . Default ) && ! declarationName ) ) {
572
574
return declareSymbol ( container . symbol . exports ! , container . symbol , node , symbolFlags , symbolExcludes ) ; // No local symbol for an unnamed default!
573
575
}
574
576
const exportKind = symbolFlags & SymbolFlags . Value ? SymbolFlags . ExportValue : 0 ;
@@ -583,6 +585,17 @@ namespace ts {
583
585
}
584
586
}
585
587
588
+ function nameIsExported ( container : Node , name : __String | undefined ) : boolean {
589
+ if ( ! name ) return false ;
590
+ return arrayFrom ( container . symbol . exports ! . values ( ) ) . some ( sym =>
591
+ sym . declarations . some ( decl => {
592
+ const expSym = isExportAssignment ( decl ) ? decl . expression
593
+ : isExportSpecifier ( decl ) ? decl . propertyName
594
+ : undefined ;
595
+ return expSym && isIdentifier ( expSym ) && expSym . escapedText === name ;
596
+ } ) ) ;
597
+ }
598
+
586
599
// All container nodes are kept on a linked list in declaration order. This list is used by
587
600
// the getLocalNameOfContainer function in the type checker to validate that the local name
588
601
// used for a container is unique.
0 commit comments