From af557a6370949599d415e1352098a27b5314f578 Mon Sep 17 00:00:00 2001 From: houhaoyu Date: Thu, 21 Sep 2023 18:48:00 +0800 Subject: [PATCH] houhaoyu@huawei.com fix styles bug Signed-off-by: houhaoyu --- src/compiler/checker.ts | 27 +++++++++++++++++++-------- src/compiler/ohApi.ts | 2 +- src/compiler/parser.ts | 6 +++++- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5b07e6403c..e52a37cbfb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -33883,14 +33883,14 @@ namespace ts { const stylesNames = getEtsStylesDecoratorComponentNames(func.illegalDecorators, compilerOptions); if (stylesNames.length > 0) { - const returnTypeReferenceName = compilerOptions.ets?.styles.component.type; - if (returnType?.symbol?.escapedName === returnTypeReferenceName) { - return; - } - else { - error(getEffectiveReturnTypeNode(func), Diagnostics.Should_not_add_return_type_to_the_function_that_is_annotated_by_Styles); - return; - } + return judgeReturnTypeOfStyles(); + } + } + + if (isMethodDeclaration(func) && func.modifiers && func.modifiers.length && returnType) { + const stylesNames = getEtsStylesDecoratorComponentNames(func.modifiers as NodeArray, compilerOptions); + if (stylesNames.length > 0) { + return judgeReturnTypeOfStyles(); } } @@ -33929,6 +33929,17 @@ namespace ts { } error(errorNode, Diagnostics.Not_all_code_paths_return_a_value); } + + function judgeReturnTypeOfStyles(): void { + const returnTypeReferenceName = compilerOptions.ets?.styles.component.type; + if (returnType?.symbol?.escapedName === returnTypeReferenceName) { + return; + } + else { + error(getEffectiveReturnTypeNode(func), Diagnostics.Should_not_add_return_type_to_the_function_that_is_annotated_by_Styles); + return; + } + } } } diff --git a/src/compiler/ohApi.ts b/src/compiler/ohApi.ts index de4851f9bc..41e686c0cd 100644 --- a/src/compiler/ohApi.ts +++ b/src/compiler/ohApi.ts @@ -354,7 +354,7 @@ namespace ts { const stylesComponents: __String[] = []; const stylesDecorator = compilerOptions.ets?.styles?.decorator ?? "Styles"; decorators?.forEach(decorator => { - if (decorator.expression.kind === SyntaxKind.Identifier) { + if (decorator.kind === SyntaxKind.Decorator && decorator.expression.kind === SyntaxKind.Identifier) { const identifier = decorator.expression; if (identifier.kind === SyntaxKind.Identifier && identifier.escapedText === stylesDecorator) { stylesComponents.push(identifier.escapedText); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 7e77de257b..c16200020d 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -6183,7 +6183,11 @@ namespace ts { rootNodeName.slice(0, -8) : undefined; const attributeName = name ? `${name}Attribute` : undefined; if (attributeName) { - typeArguments = parseEtsTypeArguments(pos, `${rootNodeName}Attribute`); + if (inEtsStateStylesContext()) { + typeArguments = parseEtsTypeArguments(pos, `${name}Attribute`); + } else { + typeArguments = parseEtsTypeArguments(pos, `${rootNodeName}Attribute`); + } } } } -- Gitee