diff --git a/lib/tsc.js b/lib/tsc.js index 274f67b5d0a3eba1c4472c8068e86dafcd8bb8d8..3a503bc2163c762d749bc2d335edec61473c811e 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -9029,7 +9029,8 @@ var Diagnostics = { In_annotation_declaration_any_symbols_between_and_interface_are_forbidden: diag(28037, 1 /* Error */, "In_annotation_declaration_any_symbols_between_and_interface_are_forbidden_28037", "In annotation declaration any symbols between '@' and 'interface' are forbidden."), Enable_support_of_ETS_annotations: diag(28038, 3 /* Message */, "Enable_support_of_ETS_annotations_28038", "Enable support of ETS annotations"), Annotation_can_only_be_exported_in_declaration_statement: diag(28039, 1 /* Error */, "Annotation_can_only_be_exported_in_declaration_statement_28039", "Annotation can only be exported in declaration statement."), - Function_may_throw_exceptions_Special_handling_is_required: diag(28040, 0 /* Warning */, "Function_may_throw_exceptions_Special_handling_is_required_28040", "Function may throw exceptions. Special handling is required.") + Function_may_throw_exceptions_Special_handling_is_required: diag(28040, 0 /* Warning */, "Function_may_throw_exceptions_Special_handling_is_required_28040", "Function may throw exceptions. Special handling is required."), + Annotation_cannot_be_applied_for_getter_or_setter_got_Colon_0: diag(28042, 1 /* Error */, "Annotation_cannot_be_applied_for_getter_or_setter_got_Colon_0_28042", "Annotation cannot be applied for getter or setter, got: '{0}'.") }; // src/compiler/memorydotting/memoryDotting.ts @@ -72559,7 +72560,14 @@ function createTypeChecker(host, isTypeCheckerForLinter = false) { const annotatedDecl = annotation.parent; if (!isClassDeclaration(annotatedDecl) && !isMethodDeclaration(annotatedDecl)) { const nodeStr = getTextOfNode(annotatedDecl, false); - error(annotation, Diagnostics.Annotation_have_to_be_applied_for_classes_or_methods_only_got_Colon_0, nodeStr); + switch (annotatedDecl.kind) { + case 177 /* GetAccessor */: + case 178 /* SetAccessor */: + error(annotation, Diagnostics.Annotation_cannot_be_applied_for_getter_or_setter_got_Colon_0, nodeStr); + break; + default: + error(annotation, Diagnostics.Annotation_have_to_be_applied_for_classes_or_methods_only_got_Colon_0, nodeStr); + } return; } if (hasSyntacticModifier(annotatedDecl, 256 /* Abstract */)) { diff --git a/lib/tsserver.js b/lib/tsserver.js index 3ae314506424b43dfdfcde4e56cb9ac2a43c3c4f..9b7a103671d5a79abfee9e49d51c6a22a15abc69 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -11733,7 +11733,8 @@ var Diagnostics = { In_annotation_declaration_any_symbols_between_and_interface_are_forbidden: diag(28037, 1 /* Error */, "In_annotation_declaration_any_symbols_between_and_interface_are_forbidden_28037", "In annotation declaration any symbols between '@' and 'interface' are forbidden."), Enable_support_of_ETS_annotations: diag(28038, 3 /* Message */, "Enable_support_of_ETS_annotations_28038", "Enable support of ETS annotations"), Annotation_can_only_be_exported_in_declaration_statement: diag(28039, 1 /* Error */, "Annotation_can_only_be_exported_in_declaration_statement_28039", "Annotation can only be exported in declaration statement."), - Function_may_throw_exceptions_Special_handling_is_required: diag(28040, 0 /* Warning */, "Function_may_throw_exceptions_Special_handling_is_required_28040", "Function may throw exceptions. Special handling is required.") + Function_may_throw_exceptions_Special_handling_is_required: diag(28040, 0 /* Warning */, "Function_may_throw_exceptions_Special_handling_is_required_28040", "Function may throw exceptions. Special handling is required."), + Annotation_cannot_be_applied_for_getter_or_setter_got_Colon_0: diag(28042, 1 /* Error */, "Annotation_cannot_be_applied_for_getter_or_setter_got_Colon_0_28042", "Annotation cannot be applied for getter or setter, got: '{0}'.") }; // src/compiler/memorydotting/memoryDotting.ts @@ -75105,7 +75106,14 @@ function createTypeChecker(host, isTypeCheckerForLinter = false) { const annotatedDecl = annotation.parent; if (!isClassDeclaration(annotatedDecl) && !isMethodDeclaration(annotatedDecl)) { const nodeStr = getTextOfNode(annotatedDecl, false); - error(annotation, Diagnostics.Annotation_have_to_be_applied_for_classes_or_methods_only_got_Colon_0, nodeStr); + switch (annotatedDecl.kind) { + case 177 /* GetAccessor */: + case 178 /* SetAccessor */: + error(annotation, Diagnostics.Annotation_cannot_be_applied_for_getter_or_setter_got_Colon_0, nodeStr); + break; + default: + error(annotation, Diagnostics.Annotation_have_to_be_applied_for_classes_or_methods_only_got_Colon_0, nodeStr); + } return; } if (hasSyntacticModifier(annotatedDecl, 256 /* Abstract */)) { diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 96d913c93da2b298d642cad282528a03b0556305..e737875f2e7e23cbb511540c77cdc92e9f648ed9 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -11635,7 +11635,8 @@ var Diagnostics = { In_annotation_declaration_any_symbols_between_and_interface_are_forbidden: diag(28037, 1 /* Error */, "In_annotation_declaration_any_symbols_between_and_interface_are_forbidden_28037", "In annotation declaration any symbols between '@' and 'interface' are forbidden."), Enable_support_of_ETS_annotations: diag(28038, 3 /* Message */, "Enable_support_of_ETS_annotations_28038", "Enable support of ETS annotations"), Annotation_can_only_be_exported_in_declaration_statement: diag(28039, 1 /* Error */, "Annotation_can_only_be_exported_in_declaration_statement_28039", "Annotation can only be exported in declaration statement."), - Function_may_throw_exceptions_Special_handling_is_required: diag(28040, 0 /* Warning */, "Function_may_throw_exceptions_Special_handling_is_required_28040", "Function may throw exceptions. Special handling is required.") + Function_may_throw_exceptions_Special_handling_is_required: diag(28040, 0 /* Warning */, "Function_may_throw_exceptions_Special_handling_is_required_28040", "Function may throw exceptions. Special handling is required."), + Annotation_cannot_be_applied_for_getter_or_setter_got_Colon_0: diag(28042, 1 /* Error */, "Annotation_cannot_be_applied_for_getter_or_setter_got_Colon_0_28042", "Annotation cannot be applied for getter or setter, got: '{0}'.") }; // src/compiler/memorydotting/memoryDotting.ts @@ -75007,7 +75008,14 @@ function createTypeChecker(host, isTypeCheckerForLinter = false) { const annotatedDecl = annotation.parent; if (!isClassDeclaration(annotatedDecl) && !isMethodDeclaration(annotatedDecl)) { const nodeStr = getTextOfNode(annotatedDecl, false); - error(annotation, Diagnostics.Annotation_have_to_be_applied_for_classes_or_methods_only_got_Colon_0, nodeStr); + switch (annotatedDecl.kind) { + case 177 /* GetAccessor */: + case 178 /* SetAccessor */: + error(annotation, Diagnostics.Annotation_cannot_be_applied_for_getter_or_setter_got_Colon_0, nodeStr); + break; + default: + error(annotation, Diagnostics.Annotation_have_to_be_applied_for_classes_or_methods_only_got_Colon_0, nodeStr); + } return; } if (hasSyntacticModifier(annotatedDecl, 256 /* Abstract */)) { diff --git a/lib/typescript.js b/lib/typescript.js index 68ffd2ed237d3d71643a7615d4f420a518c345de..fd5a2fbfe7370ffdda3baf6e8c8467d5ef8fdbbd 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -11635,7 +11635,8 @@ var Diagnostics = { In_annotation_declaration_any_symbols_between_and_interface_are_forbidden: diag(28037, 1 /* Error */, "In_annotation_declaration_any_symbols_between_and_interface_are_forbidden_28037", "In annotation declaration any symbols between '@' and 'interface' are forbidden."), Enable_support_of_ETS_annotations: diag(28038, 3 /* Message */, "Enable_support_of_ETS_annotations_28038", "Enable support of ETS annotations"), Annotation_can_only_be_exported_in_declaration_statement: diag(28039, 1 /* Error */, "Annotation_can_only_be_exported_in_declaration_statement_28039", "Annotation can only be exported in declaration statement."), - Function_may_throw_exceptions_Special_handling_is_required: diag(28040, 0 /* Warning */, "Function_may_throw_exceptions_Special_handling_is_required_28040", "Function may throw exceptions. Special handling is required.") + Function_may_throw_exceptions_Special_handling_is_required: diag(28040, 0 /* Warning */, "Function_may_throw_exceptions_Special_handling_is_required_28040", "Function may throw exceptions. Special handling is required."), + Annotation_cannot_be_applied_for_getter_or_setter_got_Colon_0: diag(28042, 1 /* Error */, "Annotation_cannot_be_applied_for_getter_or_setter_got_Colon_0_28042", "Annotation cannot be applied for getter or setter, got: '{0}'.") }; // src/compiler/memorydotting/memoryDotting.ts @@ -75165,7 +75166,14 @@ function createTypeChecker(host, isTypeCheckerForLinter = false) { const annotatedDecl = annotation.parent; if (!isClassDeclaration(annotatedDecl) && !isMethodDeclaration(annotatedDecl)) { const nodeStr = getTextOfNode(annotatedDecl, false); - error(annotation, Diagnostics.Annotation_have_to_be_applied_for_classes_or_methods_only_got_Colon_0, nodeStr); + switch (annotatedDecl.kind) { + case 177 /* GetAccessor */: + case 178 /* SetAccessor */: + error(annotation, Diagnostics.Annotation_cannot_be_applied_for_getter_or_setter_got_Colon_0, nodeStr); + break; + default: + error(annotation, Diagnostics.Annotation_have_to_be_applied_for_classes_or_methods_only_got_Colon_0, nodeStr); + } return; } if (hasSyntacticModifier(annotatedDecl, 256 /* Abstract */)) { diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index 96c76b3fce0e3dc46dfb5f429e97fab224dd3446..1afe00fe1a3cd9897c1ece705c483c8a8a2e115b 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -7272,7 +7272,8 @@ var Diagnostics = { In_annotation_declaration_any_symbols_between_and_interface_are_forbidden: diag(28037, 1 /* Error */, "In_annotation_declaration_any_symbols_between_and_interface_are_forbidden_28037", "In annotation declaration any symbols between '@' and 'interface' are forbidden."), Enable_support_of_ETS_annotations: diag(28038, 3 /* Message */, "Enable_support_of_ETS_annotations_28038", "Enable support of ETS annotations"), Annotation_can_only_be_exported_in_declaration_statement: diag(28039, 1 /* Error */, "Annotation_can_only_be_exported_in_declaration_statement_28039", "Annotation can only be exported in declaration statement."), - Function_may_throw_exceptions_Special_handling_is_required: diag(28040, 0 /* Warning */, "Function_may_throw_exceptions_Special_handling_is_required_28040", "Function may throw exceptions. Special handling is required.") + Function_may_throw_exceptions_Special_handling_is_required: diag(28040, 0 /* Warning */, "Function_may_throw_exceptions_Special_handling_is_required_28040", "Function may throw exceptions. Special handling is required."), + Annotation_cannot_be_applied_for_getter_or_setter_got_Colon_0: diag(28042, 1 /* Error */, "Annotation_cannot_be_applied_for_getter_or_setter_got_Colon_0_28042", "Annotation cannot be applied for getter or setter, got: '{0}'.") }; // src/compiler/memorydotting/memoryDotting.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9fb13fac536ddad61a1ca38c2eaf5e784b54d3b0..8f38b9e679bb23dddd48062693fb1d2a0ed1ccc3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -39992,7 +39992,14 @@ export function createTypeChecker(host: TypeCheckerHost, isTypeCheckerForLinter: // Only classes or methods must be annotated if (!isClassDeclaration(annotatedDecl) && !isMethodDeclaration(annotatedDecl)) { const nodeStr = getTextOfNode(annotatedDecl, /*includeTrivia*/ false); - error(annotation, Diagnostics.Annotation_have_to_be_applied_for_classes_or_methods_only_got_Colon_0, nodeStr); + switch (annotatedDecl.kind) { + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + error(annotation, Diagnostics.Annotation_cannot_be_applied_for_getter_or_setter_got_Colon_0, nodeStr); + break; + default: + error(annotation, Diagnostics.Annotation_have_to_be_applied_for_classes_or_methods_only_got_Colon_0, nodeStr); + } return; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b45f742ca44ee53005fbbfeb41441e1cfc918375..01aba1cd5c6903c5fce182b9d79f661aa15d936a 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -7837,5 +7837,9 @@ "Function may throw exceptions. Special handling is required.": { "category": "Warning", "code": 28040 + }, + "Annotation cannot be applied for getter or setter, got: '{0}'.": { + "category": "Error", + "code": 28042 } } diff --git a/tests/baselines/reference/annotationApplicationError8.errors.txt b/tests/baselines/reference/annotationApplicationError8.errors.txt index bba93f327f6b793660e70f0f2a8d01c4f9d7d60e..0fdf1ddf9b9d217ec4f66b2a6329fdbd04b6bf02 100644 --- a/tests/baselines/reference/annotationApplicationError8.errors.txt +++ b/tests/baselines/reference/annotationApplicationError8.errors.txt @@ -1,9 +1,9 @@ tests/cases/conformance/annotations/annotationApplicationError8.ets(8,5): error TS28022: Annotation have to be applied for classes or methods only, got: '@Anno public a: number'. tests/cases/conformance/annotations/annotationApplicationError8.ets(11,16): error TS28022: Annotation have to be applied for classes or methods only, got: '@Anno a: number'. -tests/cases/conformance/annotations/annotationApplicationError8.ets(13,5): error TS28022: Annotation have to be applied for classes or methods only, got: '@Anno +tests/cases/conformance/annotations/annotationApplicationError8.ets(13,5): error TS28042: Annotation cannot be applied for getter or setter, got: '@Anno get prop(): number { return 0}'. -tests/cases/conformance/annotations/annotationApplicationError8.ets(16,5): error TS28022: Annotation have to be applied for classes or methods only, got: '@Anno +tests/cases/conformance/annotations/annotationApplicationError8.ets(16,5): error TS28042: Annotation cannot be applied for getter or setter, got: '@Anno set prop(a: number) {}'. @@ -27,14 +27,14 @@ tests/cases/conformance/annotations/annotationApplicationError8.ets(16,5): error @Anno ~~~~~ -!!! error TS28022: Annotation have to be applied for classes or methods only, got: '@Anno -!!! error TS28022: get prop(): number { return 0}'. +!!! error TS28042: Annotation cannot be applied for getter or setter, got: '@Anno +!!! error TS28042: get prop(): number { return 0}'. get prop(): number { return 0} @Anno ~~~~~ -!!! error TS28022: Annotation have to be applied for classes or methods only, got: '@Anno -!!! error TS28022: set prop(a: number) {}'. +!!! error TS28042: Annotation cannot be applied for getter or setter, got: '@Anno +!!! error TS28042: set prop(a: number) {}'. set prop(a: number) {} } \ No newline at end of file