diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index c0c2347bb0a..098d908ea6e 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -104,6 +104,7 @@ module ts { An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode: { code: 1117, category: DiagnosticCategory.Error, key: "An object literal cannot have multiple properties with the same name in strict mode." }, An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name: { code: 1118, category: DiagnosticCategory.Error, key: "An object literal cannot have multiple get/set accessors with the same name." }, An_object_literal_cannot_have_property_and_accessor_with_the_same_name: { code: 1119, category: DiagnosticCategory.Error, key: "An object literal cannot have property and accessor with the same name." }, + An_export_assignment_cannot_have_modifiers: { code: 1120, category: DiagnosticCategory.Error, key: "An export assignment cannot have modifiers." }, Duplicate_identifier_0: { code: 2000, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 2068, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, Multiple_constructor_implementations_are_not_allowed: { code: 2070, category: DiagnosticCategory.Error, key: "Multiple constructor implementations are not allowed." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 51260ccd6ef..24fcdfa51e4 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -408,6 +408,10 @@ "category": "Error", "code": 1119 }, + "An export assignment cannot have modifiers.": { + "category": "Error", + "code": 1120 + }, "Duplicate identifier '{0}'.": { "category": "Error", "code": 2000 diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index ee0fcccb239..305e1724174 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3348,9 +3348,15 @@ module ts { var flags = parseAndCheckModifiers(modifierContext); if (token === SyntaxKind.ExportKeyword) { + var modifiersEnd = scanner.getStartPos(); nextToken(); if (parseOptional(SyntaxKind.EqualsToken)) { - return parseExportAssignmentTail(pos); + var exportAssignmentTail = parseExportAssignmentTail(pos); + if (flags !== 0 && errorCountBeforeModifiers === file.syntacticErrors.length) { + var modifiersStart = skipTrivia(sourceText, pos); + grammarErrorAtPos(modifiersStart, modifiersEnd - modifiersStart, Diagnostics.An_export_assignment_cannot_have_modifiers); + } + return exportAssignmentTail; } } diff --git a/tests/baselines/reference/exportAssignmentWithDeclareAndExportModifiers.errors.txt b/tests/baselines/reference/exportAssignmentWithDeclareAndExportModifiers.errors.txt new file mode 100644 index 00000000000..2dd71ce0d07 --- /dev/null +++ b/tests/baselines/reference/exportAssignmentWithDeclareAndExportModifiers.errors.txt @@ -0,0 +1,7 @@ +==== tests/cases/compiler/exportAssignmentWithDeclareAndExportModifiers.ts (2 errors) ==== + var x; + export declare export = x; + ~~~~~~~~~~~~~~ +!!! An export assignment cannot have modifiers. + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! Cannot compile external modules unless the '--module' flag is provided. \ No newline at end of file diff --git a/tests/baselines/reference/exportAssignmentWithDeclareModifier.errors.txt b/tests/baselines/reference/exportAssignmentWithDeclareModifier.errors.txt new file mode 100644 index 00000000000..27b202ce0c8 --- /dev/null +++ b/tests/baselines/reference/exportAssignmentWithDeclareModifier.errors.txt @@ -0,0 +1,7 @@ +==== tests/cases/compiler/exportAssignmentWithDeclareModifier.ts (2 errors) ==== + var x; + declare export = x; + ~~~~~~~ +!!! An export assignment cannot have modifiers. + ~~~~~~~~~~~~~~~~~~~ +!!! Cannot compile external modules unless the '--module' flag is provided. \ No newline at end of file diff --git a/tests/baselines/reference/exportAssignmentWithExportModifier.errors.txt b/tests/baselines/reference/exportAssignmentWithExportModifier.errors.txt new file mode 100644 index 00000000000..dc3d6cb4cc5 --- /dev/null +++ b/tests/baselines/reference/exportAssignmentWithExportModifier.errors.txt @@ -0,0 +1,7 @@ +==== tests/cases/compiler/exportAssignmentWithExportModifier.ts (2 errors) ==== + var x; + export export = x; + ~~~~~~ +!!! An export assignment cannot have modifiers. + ~~~~~~~~~~~~~~~~~~ +!!! Cannot compile external modules unless the '--module' flag is provided. \ No newline at end of file diff --git a/tests/cases/compiler/exportAssignmentWithDeclareAndExportModifiers.ts b/tests/cases/compiler/exportAssignmentWithDeclareAndExportModifiers.ts new file mode 100644 index 00000000000..02e40fd3645 --- /dev/null +++ b/tests/cases/compiler/exportAssignmentWithDeclareAndExportModifiers.ts @@ -0,0 +1,2 @@ +var x; +export declare export = x; \ No newline at end of file diff --git a/tests/cases/compiler/exportAssignmentWithDeclareModifier.ts b/tests/cases/compiler/exportAssignmentWithDeclareModifier.ts new file mode 100644 index 00000000000..e38f7fa8d38 --- /dev/null +++ b/tests/cases/compiler/exportAssignmentWithDeclareModifier.ts @@ -0,0 +1,2 @@ +var x; +declare export = x; \ No newline at end of file diff --git a/tests/cases/compiler/exportAssignmentWithExportModifier.ts b/tests/cases/compiler/exportAssignmentWithExportModifier.ts new file mode 100644 index 00000000000..c6b543caeec --- /dev/null +++ b/tests/cases/compiler/exportAssignmentWithExportModifier.ts @@ -0,0 +1,2 @@ +var x; +export export = x; \ No newline at end of file