diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3536152ee35..e09df418b2a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10682,10 +10682,18 @@ namespace ts { // to denote disjoint declarationSpaces (without making new enum type). let exportedDeclarationSpaces = SymbolFlags.None; let nonExportedDeclarationSpaces = SymbolFlags.None; + let defaultExportedDeclarationFlags = SymbolFlags.None; for (let d of symbol.declarations) { let declarationSpaces = getDeclarationSpaces(d); - if (getEffectiveDeclarationFlags(d, NodeFlags.Export)) { - exportedDeclarationSpaces |= declarationSpaces; + let effectiveDeclarationFlags = getEffectiveDeclarationFlags(d, NodeFlags.Export | NodeFlags.Default); + + if (effectiveDeclarationFlags & NodeFlags.Export) { + if (effectiveDeclarationFlags & NodeFlags.Default) { + defaultExportedDeclarationFlags |= declarationSpaces; + } + else { + exportedDeclarationSpaces |= declarationSpaces; + } } else { nonExportedDeclarationSpaces |= declarationSpaces; @@ -10693,11 +10701,16 @@ namespace ts { } let commonDeclarationSpace = exportedDeclarationSpaces & nonExportedDeclarationSpaces; + let commonDeclarationSpaceForDefault = defaultExportedDeclarationFlags & (exportedDeclarationSpaces | nonExportedDeclarationSpaces); - if (commonDeclarationSpace) { + if (commonDeclarationSpace || commonDeclarationSpaceForDefault) { // declaration spaces for exported and non-exported declarations intersect for (let d of symbol.declarations) { - if (getDeclarationSpaces(d) & commonDeclarationSpace) { + let declarationSpaces = getDeclarationSpaces(d); + if (declarationSpaces & commonDeclarationSpaceForDefault) { + error(d.name, Diagnostics.Merged_declaration_0_cannot_include_a_default_export_declaration, declarationNameToString(d.name)); + } + else if (declarationSpaces & commonDeclarationSpace) { error(d.name, Diagnostics.Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local, declarationNameToString(d.name)); } } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index c17a49484b8..c1afb8c9706 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -424,6 +424,7 @@ namespace ts { JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property: { code: 2607, category: DiagnosticCategory.Error, key: "JSX element class does not support attributes because it does not have a '{0}' property" }, The_global_type_JSX_0_may_not_have_more_than_one_property: { code: 2608, category: DiagnosticCategory.Error, key: "The global type 'JSX.{0}' may not have more than one property" }, Cannot_emit_namespaced_JSX_elements_in_React: { code: 2650, category: DiagnosticCategory.Error, key: "Cannot emit namespaced JSX elements in React" }, + Merged_declaration_0_cannot_include_a_default_export_declaration: { code: 2651, category: DiagnosticCategory.Error, key: "Merged declaration '{0}' cannot include a default export declaration." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index d01084c1bc8..fa792639556 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1685,6 +1685,10 @@ "category": "Error", "code": 2650 }, + "Merged declaration '{0}' cannot include a default export declaration.": { + "category": "Error", + "code": 2651 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000