From 0f77c28453837b6e7d3ab600986680e9e40285c7 Mon Sep 17 00:00:00 2001 From: liuchunlin Date: Fri, 12 Sep 2025 11:25:59 +0800 Subject: [PATCH] fix the annotation error information of getter or setter for 6.0 Release MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue:https://gitee.com/openharmony/third_party_typescript/issues/ICXOGE Signed-off-by: liuchunlin Change-Id: I65a8679682ff0041299d24804e8135e8c30e2332 --- lib/tsc.js | 12 ++++++++++-- lib/tsserver.js | 12 ++++++++++-- lib/tsserverlibrary.js | 12 ++++++++++-- lib/typescript.js | 12 ++++++++++-- lib/typingsInstaller.js | 3 ++- src/compiler/checker.ts | 9 ++++++++- src/compiler/diagnosticMessages.json | 4 ++++ .../reference/annotationApplicationError8.errors.txt | 12 ++++++------ 8 files changed, 60 insertions(+), 16 deletions(-) diff --git a/lib/tsc.js b/lib/tsc.js index 274f67b5d0..3a503bc216 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 3ae3145064..9b7a103671 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 96d913c93d..e737875f2e 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 68ffd2ed23..fd5a2fbfe7 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 96c76b3fce..1afe00fe1a 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 9fb13fac53..8f38b9e679 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 b45f742ca4..01aba1cd5c 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 bba93f327f..0fdf1ddf9b 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 -- Gitee