@@ -337,8 +337,18 @@ 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
342
+ if ( isDefaultExport && symbol . declarations ) {
343
+ message = Diagnostics . A_module_cannot_have_multiple_default_exports ;
344
+ }
345
+
340
346
forEach ( symbol . declarations , declaration => {
341
- if ( declaration . flags & NodeFlags . Default ) {
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 ) ) {
342
352
message = Diagnostics . A_module_cannot_have_multiple_default_exports ;
343
353
}
344
354
} ) ;
@@ -1898,7 +1908,9 @@ namespace ts {
1898
1908
}
1899
1909
else {
1900
1910
// An export default clause with an expression exports a value
1901
- declareSymbol ( container . symbol . exports , container . symbol , node , SymbolFlags . Property , SymbolFlags . PropertyExcludes | SymbolFlags . AliasExcludes ) ;
1911
+ // We want to exclude both class and function here, this is necessary to issue an error when there are both
1912
+ // default export-assignment and default export function and class declaration.
1913
+ declareSymbol ( container . symbol . exports , container . symbol , node , SymbolFlags . Property , SymbolFlags . Class | SymbolFlags . Function | SymbolFlags . Property ) ;
1902
1914
}
1903
1915
}
1904
1916
0 commit comments