@@ -306,7 +306,7 @@ namespace ts {
306306 }
307307
308308 function getDisplayName ( node : Declaration ) : string {
309- return isNamedDeclaration ( node ) ? declarationNameToString ( node . name ) : unescapeLeadingUnderscores ( getDeclarationName ( node ) ! ) ; // TODO: GH#18217
309+ return isNamedDeclaration ( node ) ? declarationNameToString ( node . name ) : unescapeLeadingUnderscores ( Debug . assertDefined ( getDeclarationName ( node ) ) ) ;
310310 }
311311
312312 /**
@@ -383,9 +383,11 @@ namespace ts {
383383 let message = symbol . flags & SymbolFlags . BlockScopedVariable
384384 ? Diagnostics . Cannot_redeclare_block_scoped_variable_0
385385 : Diagnostics . Duplicate_identifier_0 ;
386+ let messageNeedsName = true ;
386387
387388 if ( symbol . flags & SymbolFlags . Enum || includes & SymbolFlags . Enum ) {
388389 message = Diagnostics . Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations ;
390+ messageNeedsName = false ;
389391 }
390392
391393 if ( symbol . declarations && symbol . declarations . length ) {
@@ -394,6 +396,7 @@ namespace ts {
394396 // We'll know whether we have other default exports depending on if `symbol` already has a declaration list set.
395397 if ( isDefaultExport ) {
396398 message = Diagnostics . A_module_cannot_have_multiple_default_exports ;
399+ messageNeedsName = false ;
397400 }
398401 else {
399402 // This is to properly report an error in the case "export default { }" is after export default of class declaration or function declaration.
@@ -403,14 +406,16 @@ namespace ts {
403406 if ( symbol . declarations && symbol . declarations . length &&
404407 ( node . kind === SyntaxKind . ExportAssignment && ! ( < ExportAssignment > node ) . isExportEquals ) ) {
405408 message = Diagnostics . A_module_cannot_have_multiple_default_exports ;
409+ messageNeedsName = false ;
406410 }
407411 }
408412 }
409413
410- forEach ( symbol . declarations , declaration => {
411- file . bindDiagnostics . push ( createDiagnosticForNode ( getNameOfDeclaration ( declaration ) || declaration , message , getDisplayName ( declaration ) ) ) ;
412- } ) ;
413- file . bindDiagnostics . push ( createDiagnosticForNode ( getNameOfDeclaration ( node ) || node , message , getDisplayName ( node ) ) ) ;
414+ const addError = ( decl : Declaration ) : void => {
415+ file . bindDiagnostics . push ( createDiagnosticForNode ( getNameOfDeclaration ( decl ) || decl , message , messageNeedsName ? getDisplayName ( decl ) : undefined ) ) ;
416+ } ;
417+ forEach ( symbol . declarations , addError ) ;
418+ addError ( node ) ;
414419
415420 symbol = createSymbol ( SymbolFlags . None , name ) ;
416421 }
0 commit comments