@@ -337,21 +337,24 @@ namespace ts {
337
337
? Diagnostics . Cannot_redeclare_block_scoped_variable_0
338
338
: Diagnostics . Duplicate_identifier_0 ;
339
339
340
- // If the current node has NodeFlags.Default (e.g. if the node is class declaration or function declaration)
341
- // and there is already another default export (i.e. symbol.declarations is not empty), we need to report such error
340
+ // If the current node is a default export of some sort, then check if
341
+ // there are any other default exports that we need to error on.
342
+ // We'll know whether we have other default exports depending on if `symbol` already has a declaration list set.
342
343
if ( isDefaultExport && symbol . declarations ) {
343
344
message = Diagnostics . A_module_cannot_have_multiple_default_exports ;
344
345
}
345
-
346
- forEach ( symbol . declarations , declaration => {
347
- // Error on multiple export default in the following case:
348
- // 1. multiple export default of class declaration or function declaration by checking NodeFlags.Default
349
- // 2. multiple export default of export assignment. This one doesn't have NodeFlags.Default on (as export default doesn't considered as modifiers)
350
- if ( ( declaration . flags & NodeFlags . Default ) ||
351
- ( declaration . kind === SyntaxKind . ExportAssignment && ! ( < ExportAssignment > node ) . isExportEquals ) ) {
352
- message = Diagnostics . A_module_cannot_have_multiple_default_exports ;
353
- }
354
- } ) ;
346
+ else {
347
+ // This is to properly report an error in the case "export default { }" is after export default of class declaration or function declaration.
348
+ forEach ( symbol . declarations , declaration => {
349
+ // Error on multiple export default in the following case:
350
+ // 1. multiple export default of class declaration or function declaration by checking NodeFlags.Default
351
+ // 2. multiple export default of export assignment. This one doesn't have NodeFlags.Default on (as export default doesn't considered as modifiers)
352
+ if ( ( declaration . flags & NodeFlags . Default ) ||
353
+ ( declaration . kind === SyntaxKind . ExportAssignment && ! ( < ExportAssignment > node ) . isExportEquals ) ) {
354
+ message = Diagnostics . A_module_cannot_have_multiple_default_exports ;
355
+ }
356
+ } ) ;
357
+ }
355
358
356
359
forEach ( symbol . declarations , declaration => {
357
360
file . bindDiagnostics . push ( createDiagnosticForNode ( declaration . name || declaration , message , getDisplayName ( declaration ) ) ) ;
0 commit comments