From 4c096f35fc267eb92f0e4647b151dbf423fa0394 Mon Sep 17 00:00:00 2001 From: weiyumeng Date: Mon, 8 Sep 2025 20:15:08 +0800 Subject: [PATCH] Fix the annotation error reports of js har Issue: https://gitee.com/openharmony/third_party_typescript/issues/ICWZIA Signed-off-by: weiyumeng Change-Id: I386e193418568c20d64c866153748f37efefc05a --- lib/tsc.js | 6 +++--- lib/tsserver.js | 6 +++--- lib/tsserverlibrary.js | 6 +++--- lib/typescript.js | 6 +++--- src/compiler/checker.ts | 12 ++++++------ 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/tsc.js b/lib/tsc.js index 39072b6786..ea0cdd4900 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -72554,14 +72554,14 @@ function createTypeChecker(host, isTypeCheckerForLinter = false) { }); } function checkAnnotation(annotation, annotationsSet) { + if (compilerOptions.isCompileJsHar && inModuleRootPath(annotation)) { + grammarErrorOnNode(annotation, Diagnostics.Annotations_are_not_supported_in_Hars_compiled_to_JavaScript_files); + } const signature = getResolvedSignature(annotation); const returnType = getReturnTypeOfSignature(signature); if (isErrorType(returnType)) { return; } - if (compilerOptions.isCompileJsHar && inModuleRootPath(annotation)) { - grammarErrorOnNode(annotation, Diagnostics.Annotations_are_not_supported_in_Hars_compiled_to_JavaScript_files); - } const annotatedDecl = annotation.parent; if (!isClassDeclaration(annotatedDecl) && !isMethodDeclaration(annotatedDecl)) { const nodeStr = getTextOfNode(annotatedDecl, false); diff --git a/lib/tsserver.js b/lib/tsserver.js index 820f270c09..7addbe066f 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -75100,14 +75100,14 @@ function createTypeChecker(host, isTypeCheckerForLinter = false) { }); } function checkAnnotation(annotation, annotationsSet) { + if (compilerOptions.isCompileJsHar && inModuleRootPath(annotation)) { + grammarErrorOnNode(annotation, Diagnostics.Annotations_are_not_supported_in_Hars_compiled_to_JavaScript_files); + } const signature = getResolvedSignature(annotation); const returnType = getReturnTypeOfSignature(signature); if (isErrorType(returnType)) { return; } - if (compilerOptions.isCompileJsHar && inModuleRootPath(annotation)) { - grammarErrorOnNode(annotation, Diagnostics.Annotations_are_not_supported_in_Hars_compiled_to_JavaScript_files); - } const annotatedDecl = annotation.parent; if (!isClassDeclaration(annotatedDecl) && !isMethodDeclaration(annotatedDecl)) { const nodeStr = getTextOfNode(annotatedDecl, false); diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 59049891dc..4f7786c15a 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -75002,14 +75002,14 @@ function createTypeChecker(host, isTypeCheckerForLinter = false) { }); } function checkAnnotation(annotation, annotationsSet) { + if (compilerOptions.isCompileJsHar && inModuleRootPath(annotation)) { + grammarErrorOnNode(annotation, Diagnostics.Annotations_are_not_supported_in_Hars_compiled_to_JavaScript_files); + } const signature = getResolvedSignature(annotation); const returnType = getReturnTypeOfSignature(signature); if (isErrorType(returnType)) { return; } - if (compilerOptions.isCompileJsHar && inModuleRootPath(annotation)) { - grammarErrorOnNode(annotation, Diagnostics.Annotations_are_not_supported_in_Hars_compiled_to_JavaScript_files); - } const annotatedDecl = annotation.parent; if (!isClassDeclaration(annotatedDecl) && !isMethodDeclaration(annotatedDecl)) { const nodeStr = getTextOfNode(annotatedDecl, false); diff --git a/lib/typescript.js b/lib/typescript.js index 808d2020f9..ad0cfa03dd 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -75160,14 +75160,14 @@ function createTypeChecker(host, isTypeCheckerForLinter = false) { }); } function checkAnnotation(annotation, annotationsSet) { + if (compilerOptions.isCompileJsHar && inModuleRootPath(annotation)) { + grammarErrorOnNode(annotation, Diagnostics.Annotations_are_not_supported_in_Hars_compiled_to_JavaScript_files); + } const signature = getResolvedSignature(annotation); const returnType = getReturnTypeOfSignature(signature); if (isErrorType(returnType)) { return; } - if (compilerOptions.isCompileJsHar && inModuleRootPath(annotation)) { - grammarErrorOnNode(annotation, Diagnostics.Annotations_are_not_supported_in_Hars_compiled_to_JavaScript_files); - } const annotatedDecl = annotation.parent; if (!isClassDeclaration(annotatedDecl) && !isMethodDeclaration(annotatedDecl)) { const nodeStr = getTextOfNode(annotatedDecl, false); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bd13f3bfd1..f6928fb440 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -39985,17 +39985,17 @@ export function createTypeChecker(host: TypeCheckerHost, isTypeCheckerForLinter: /** Check the annotation of a node */ function checkAnnotation(annotation: Annotation, annotationsSet: Set): void { + // In the har package where the compiled output is a JavaScript file, the use of annotations is prohibited. + if (compilerOptions.isCompileJsHar && inModuleRootPath(annotation)) { + grammarErrorOnNode(annotation, Diagnostics.Annotations_are_not_supported_in_Hars_compiled_to_JavaScript_files); + } + const signature = getResolvedSignature(annotation); const returnType = getReturnTypeOfSignature(signature); if (isErrorType(returnType)) { return; } - // In the har package where the compiled output is a JavaScript file, the use of annotations is prohibited. - if (compilerOptions.isCompileJsHar && inModuleRootPath(annotation)) { - grammarErrorOnNode(annotation, Diagnostics.Annotations_are_not_supported_in_Hars_compiled_to_JavaScript_files); - } - const annotatedDecl = annotation.parent; // Only classes or methods must be annotated if (!isClassDeclaration(annotatedDecl) && !isMethodDeclaration(annotatedDecl)) { @@ -44903,7 +44903,7 @@ export function createTypeChecker(host: TypeCheckerHost, isTypeCheckerForLinter: return checkClassDeclaration(node as ClassDeclaration); case SyntaxKind.StructDeclaration: return checkStructDeclaration(node as StructDeclaration); - case SyntaxKind.AnnotationDeclaration: + case SyntaxKind.AnnotationDeclaration: return checkAnnotationDeclaration(node as AnnotationDeclaration); case SyntaxKind.InterfaceDeclaration: return checkInterfaceDeclaration(node as InterfaceDeclaration); -- Gitee