diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 64746d75417..cac2d60d500 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6261,7 +6261,7 @@ module ts { ((node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName) && isInRightSideOfImportOrExportAssignment(node)); if (!ok) { - error(node, Diagnostics.const_enums_can_only_be_used_in_property_access_Slashindex_access_expressions_and_as_right_hand_side_in_import_declarations_Slashexport_assignments); + error(node, Diagnostics.const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment); } } return type; @@ -7771,10 +7771,10 @@ module ts { } else if (enumIsConst) { if (isNaN(autoValue)) { - error(initializer, Diagnostics.const_enum_member_initializer_was_evaluated_to_NaN); + error(initializer, Diagnostics.const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN); } else if (!isFinite(autoValue)) { - error(initializer, Diagnostics.const_enum_member_initializer_was_evaluated_to_a_non_finite_number); + error(initializer, Diagnostics.const_enum_member_initializer_was_evaluated_to_a_non_finite_value); } } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 47520cb0317..fed7c991b2e 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -121,7 +121,8 @@ module ts { }, { name: "preserveConstEnums", - type: "boolean" + type: "boolean", + description: Diagnostics.Do_not_erase_const_enum_declarations_in_generated_code } ]; diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index a868133044f..9138baeda41 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -354,10 +354,10 @@ module ts { Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using private name '{1}'." }, Enum_declarations_must_all_be_const_or_non_const: { code: 4082, category: DiagnosticCategory.Error, key: "Enum declarations must all be const or non-const." }, In_const_enum_declarations_member_initializer_must_be_constant_expression: { code: 4083, category: DiagnosticCategory.Error, key: "In 'const' enum declarations member initializer must be constant expression.", isEarly: true }, - const_enums_can_only_be_used_in_property_access_Slashindex_access_expressions_and_as_right_hand_side_in_import_declarations_Slashexport_assignments: { code: 4084, category: DiagnosticCategory.Error, key: "'const' enums can only be used in property access/index access expressions and as right hand side in import declarations/export assignments." }, + const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment: { code: 4084, category: DiagnosticCategory.Error, key: "'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment." }, Index_expression_arguments_in_const_enums_must_be_of_type_string: { code: 4085, category: DiagnosticCategory.Error, key: "Index expression arguments in 'const' enums must be of type 'string'." }, - const_enum_member_initializer_was_evaluated_to_a_non_finite_number: { code: 4086, category: DiagnosticCategory.Error, key: "'const' enum member initializer was evaluated to a non-finite number." }, - const_enum_member_initializer_was_evaluated_to_NaN: { code: 4087, category: DiagnosticCategory.Error, key: "'const' enum member initializer was evaluated to NaN." }, + const_enum_member_initializer_was_evaluated_to_a_non_finite_value: { code: 4086, category: DiagnosticCategory.Error, key: "'const' enum member initializer was evaluated to a non-finite value." }, + const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN: { code: 4087, category: DiagnosticCategory.Error, key: "'const' enum member initializer was evaluated to disallowed value 'NaN'." }, The_current_host_does_not_support_the_0_option: { code: 5001, category: DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." }, Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: DiagnosticCategory.Error, key: "Cannot find the common subdirectory path for the input files." }, Cannot_read_file_0_Colon_1: { code: 5012, category: DiagnosticCategory.Error, key: "Cannot read file '{0}': {1}" }, @@ -372,6 +372,7 @@ module ts { Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations: { code: 6004, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate TypeScript files instead of source locations." }, Watch_input_files: { code: 6005, category: DiagnosticCategory.Message, key: "Watch input files." }, Redirect_output_structure_to_the_directory: { code: 6006, category: DiagnosticCategory.Message, key: "Redirect output structure to the directory." }, + Do_not_erase_const_enum_declarations_in_generated_code: { code: 6007, category: DiagnosticCategory.Message, key: "Do not erase const enum declarations in generated code." }, Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs' or 'amd'" }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index eafde362f96..b6c9df1cf36 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1418,7 +1418,7 @@ "code": 4083, "isEarly": true }, - "'const' enums can only be used in property access/index access expressions and as right hand side in import declarations/export assignments.": { + "'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment.": { "category": "Error", "code": 4084 }, @@ -1426,11 +1426,11 @@ "category": "Error", "code": 4085 }, - "'const' enum member initializer was evaluated to a non-finite number.": { + "'const' enum member initializer was evaluated to a non-finite value.": { "category": "Error", "code": 4086 }, - "'const' enum member initializer was evaluated to NaN.": { + "'const' enum member initializer was evaluated to disallowed value 'NaN'.": { "category": "Error", "code": 4087 }, @@ -1490,6 +1490,10 @@ "category": "Message", "code": 6006 }, + "Do not erase const enum declarations in generated code.": { + "category": "Message", + "code": 6007 + }, "Do not emit comments to output.": { "category": "Message", "code": 6009 diff --git a/tests/baselines/reference/constEnumErrors.errors.txt b/tests/baselines/reference/constEnumErrors.errors.txt index 78115a22dc4..541f814af98 100644 --- a/tests/baselines/reference/constEnumErrors.errors.txt +++ b/tests/baselines/reference/constEnumErrors.errors.txt @@ -5,12 +5,12 @@ tests/cases/compiler/constEnumErrors.ts(14,9): error TS4083: In 'const' enum dec tests/cases/compiler/constEnumErrors.ts(15,10): error TS4083: In 'const' enum declarations member initializer must be constant expression. tests/cases/compiler/constEnumErrors.ts(22,13): error TS4085: Index expression arguments in 'const' enums must be of type 'string'. tests/cases/compiler/constEnumErrors.ts(24,13): error TS4085: Index expression arguments in 'const' enums must be of type 'string'. -tests/cases/compiler/constEnumErrors.ts(26,9): error TS4084: 'const' enums can only be used in property access/index access expressions and as right hand side in import declarations/export assignments. -tests/cases/compiler/constEnumErrors.ts(27,10): error TS4084: 'const' enums can only be used in property access/index access expressions and as right hand side in import declarations/export assignments. -tests/cases/compiler/constEnumErrors.ts(32,5): error TS4084: 'const' enums can only be used in property access/index access expressions and as right hand side in import declarations/export assignments. -tests/cases/compiler/constEnumErrors.ts(40,9): error TS4086: 'const' enum member initializer was evaluated to a non-finite number. -tests/cases/compiler/constEnumErrors.ts(41,9): error TS4086: 'const' enum member initializer was evaluated to a non-finite number. -tests/cases/compiler/constEnumErrors.ts(42,9): error TS4087: 'const' enum member initializer was evaluated to NaN. +tests/cases/compiler/constEnumErrors.ts(26,9): error TS4084: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment. +tests/cases/compiler/constEnumErrors.ts(27,10): error TS4084: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment. +tests/cases/compiler/constEnumErrors.ts(32,5): error TS4084: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment. +tests/cases/compiler/constEnumErrors.ts(40,9): error TS4086: 'const' enum member initializer was evaluated to a non-finite value. +tests/cases/compiler/constEnumErrors.ts(41,9): error TS4086: 'const' enum member initializer was evaluated to a non-finite value. +tests/cases/compiler/constEnumErrors.ts(42,9): error TS4087: 'const' enum member initializer was evaluated to disallowed value 'NaN'. ==== tests/cases/compiler/constEnumErrors.ts (13 errors) ==== @@ -55,17 +55,17 @@ tests/cases/compiler/constEnumErrors.ts(42,9): error TS4087: 'const' enum member var x = E2; ~~ -!!! error TS4084: 'const' enums can only be used in property access/index access expressions and as right hand side in import declarations/export assignments. +!!! error TS4084: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment. var y = [E2]; ~~ -!!! error TS4084: 'const' enums can only be used in property access/index access expressions and as right hand side in import declarations/export assignments. +!!! error TS4084: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment. function foo(t: any): void { } foo(E2); ~~ -!!! error TS4084: 'const' enums can only be used in property access/index access expressions and as right hand side in import declarations/export assignments. +!!! error TS4084: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment. const enum NaNOrInfinity { A = 9007199254740992, @@ -75,11 +75,11 @@ tests/cases/compiler/constEnumErrors.ts(42,9): error TS4087: 'const' enum member E = D * D, F = E * E, // overflow ~~~~~ -!!! error TS4086: 'const' enum member initializer was evaluated to a non-finite number. +!!! error TS4086: 'const' enum member initializer was evaluated to a non-finite value. G = 1 / 0, // overflow ~~~~~ -!!! error TS4086: 'const' enum member initializer was evaluated to a non-finite number. +!!! error TS4086: 'const' enum member initializer was evaluated to a non-finite value. H = 0 / 0 // NaN ~~~~~ -!!! error TS4087: 'const' enum member initializer was evaluated to NaN. +!!! error TS4087: 'const' enum member initializer was evaluated to disallowed value 'NaN'. } \ No newline at end of file