@@ -355,11 +355,24 @@ namespace ts {
355355 ? Diagnostics . Cannot_redeclare_block_scoped_variable_0
356356 : Diagnostics . Duplicate_identifier_0 ;
357357
358- forEach ( symbol . declarations , declaration => {
359- if ( hasModifier ( declaration , ModifierFlags . Default ) ) {
358+ if ( symbol . declarations && symbol . declarations . length ) {
359+ // If the current node is a default export of some sort, then check if
360+ // there are any other default exports that we need to error on.
361+ // We'll know whether we have other default exports depending on if `symbol` already has a declaration list set.
362+ if ( isDefaultExport ) {
360363 message = Diagnostics . A_module_cannot_have_multiple_default_exports ;
361364 }
362- } ) ;
365+ else {
366+ // This is to properly report an error in the case "export default { }" is after export default of class declaration or function declaration.
367+ // Error on multiple export default in the following case:
368+ // 1. multiple export default of class declaration or function declaration by checking NodeFlags.Default
369+ // 2. multiple export default of export assignment. This one doesn't have NodeFlags.Default on (as export default doesn't considered as modifiers)
370+ if ( symbol . declarations && symbol . declarations . length &&
371+ ( isDefaultExport || ( node . kind === SyntaxKind . ExportAssignment && ! ( < ExportAssignment > node ) . isExportEquals ) ) ) {
372+ message = Diagnostics . A_module_cannot_have_multiple_default_exports ;
373+ }
374+ }
375+ }
363376
364377 forEach ( symbol . declarations , declaration => {
365378 file . bindDiagnostics . push ( createDiagnosticForNode ( declaration . name || declaration , message , getDisplayName ( declaration ) ) ) ;
@@ -1114,7 +1127,7 @@ namespace ts {
11141127 }
11151128 else {
11161129 forEachChild ( node , bind ) ;
1117- if ( node . operator === SyntaxKind . PlusEqualsToken || node . operator === SyntaxKind . MinusMinusToken ) {
1130+ if ( node . operator === SyntaxKind . PlusPlusToken || node . operator === SyntaxKind . MinusMinusToken ) {
11181131 bindAssignmentTargetFlow ( node . operand ) ;
11191132 }
11201133 }
@@ -1363,7 +1376,7 @@ namespace ts {
13631376 function hasExportDeclarations ( node : ModuleDeclaration | SourceFile ) : boolean {
13641377 const body = node . kind === SyntaxKind . SourceFile ? node : ( < ModuleDeclaration > node ) . body ;
13651378 if ( body && ( body . kind === SyntaxKind . SourceFile || body . kind === SyntaxKind . ModuleBlock ) ) {
1366- for ( const stat of ( < Block > body ) . statements ) {
1379+ for ( const stat of ( < BlockLike > body ) . statements ) {
13671380 if ( stat . kind === SyntaxKind . ExportDeclaration || stat . kind === SyntaxKind . ExportAssignment ) {
13681381 return true ;
13691382 }
@@ -1948,12 +1961,15 @@ namespace ts {
19481961 bindAnonymousDeclaration ( node , SymbolFlags . Alias , getDeclarationName ( node ) ) ;
19491962 }
19501963 else {
1964+ // An export default clause with an expression exports a value
1965+ // We want to exclude both class and function here, this is necessary to issue an error when there are both
1966+ // default export-assignment and default export function and class declaration.
19511967 const flags = node . kind === SyntaxKind . ExportAssignment && exportAssignmentIsAlias ( < ExportAssignment > node )
19521968 // An export default clause with an EntityNameExpression exports all meanings of that identifier
19531969 ? SymbolFlags . Alias
19541970 // An export default clause with any other expression exports a value
19551971 : SymbolFlags . Property ;
1956- declareSymbol ( container . symbol . exports , container . symbol , node , flags , SymbolFlags . PropertyExcludes | SymbolFlags . AliasExcludes ) ;
1972+ declareSymbol ( container . symbol . exports , container . symbol , node , flags , SymbolFlags . Property | SymbolFlags . AliasExcludes | SymbolFlags . Class | SymbolFlags . Function ) ;
19571973 }
19581974 }
19591975
@@ -2436,8 +2452,7 @@ namespace ts {
24362452 }
24372453
24382454 // If the parameter's name is 'this', then it is TypeScript syntax.
2439- if ( subtreeFlags & TransformFlags . ContainsDecorators
2440- || ( name && isIdentifier ( name ) && name . originalKeywordKind === SyntaxKind . ThisKeyword ) ) {
2455+ if ( subtreeFlags & TransformFlags . ContainsDecorators || isThisIdentifier ( name ) ) {
24412456 transformFlags |= TransformFlags . AssertTypeScript ;
24422457 }
24432458
0 commit comments