From e532161be7ad79240bd9eed9c02d6c33d3ab25e8 Mon Sep 17 00:00:00 2001 From: Yenan Date: Tue, 2 Sep 2025 16:20:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dextend=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E4=BC=A0=E8=87=AA=E5=AE=9A=E4=B9=89=E7=BB=84=E4=BB=B6=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E6=97=A0=E5=91=8A=E8=AD=A6=E6=88=96=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Yenan --- compiler/src/process_ui_syntax.ts | 16 ++++++- .../ExtendInnerComponents.ets | 43 +++++++++++++++++++ .../test/transform_ut/helpers/pathConfig.ts | 1 + compiler/test/transform_ut_error.json | 4 ++ 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 compiler/test/transform_ut/application/entry/src/main/ets/pages/utForValidate/Decorators/process_ui_syntax/ExtendInnerComponents.ets diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index cf0a880fc..6a5607db1 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -80,7 +80,8 @@ import { PAGE_FULL_PATH, LENGTH, PUV2_VIEW_BASE, - CONTEXT_STACK + CONTEXT_STACK, + CHECK_COMPONENT_EXTEND_DECORATOR } from './pre_define'; import { componentInfo, @@ -131,7 +132,8 @@ import { GLOBAL_STYLE_FUNCTION, INTERFACE_NODE_SET, ID_ATTRS, - GLOBAL_CUSTOM_BUILDER_METHOD + GLOBAL_CUSTOM_BUILDER_METHOD, + INNER_COMPONENT_NAMES } from './component_map'; import { resources, @@ -1282,6 +1284,16 @@ function parseExtendNode(node: ts.CallExpression, extendResult: ExtendResult, ch code: '10905108' }); } + if (checkArguments && CHECK_EXTEND_DECORATORS.includes(extendResult.decoratorName) && + node.arguments && node.arguments.length === 1 && ts.isIdentifier(node.arguments[0]) && + !INNER_COMPONENT_NAMES.has(node.arguments[0].getText())) { + transformLog.errors.push({ + type: LogType.WARN, + message: `'${node.arguments[0].getText()}' parameter cannot be` + + ` passed in the '@${extendResult.decoratorName}' decorator.`, + pos: node.getStart() + }); + } } if (node.arguments.length && ts.isIdentifier(node.arguments[0])) { extendResult.componentName = node.arguments[0].escapedText.toString(); diff --git a/compiler/test/transform_ut/application/entry/src/main/ets/pages/utForValidate/Decorators/process_ui_syntax/ExtendInnerComponents.ets b/compiler/test/transform_ut/application/entry/src/main/ets/pages/utForValidate/Decorators/process_ui_syntax/ExtendInnerComponents.ets new file mode 100644 index 000000000..381312e25 --- /dev/null +++ b/compiler/test/transform_ut/application/entry/src/main/ets/pages/utForValidate/Decorators/process_ui_syntax/ExtendInnerComponents.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@Extend(Text) +function fancyText(weightValue: number, color: Color) { + .fontStyle(FontStyle.Italic) + .fontWeight(weightValue) + .backgroundColor(color) +} + +@Extend(testExtend) +function extendTestExtend () { + +} + +@Component +struct testExtend { + @State stringOne: string = 'stringOne'; + + build() { + Column() { + Text(this.stringOne) + } + } +} + +@Entry +@Component +struct ExtendInnerComponentsSummerpockets { + build(){ + } +} \ No newline at end of file diff --git a/compiler/test/transform_ut/helpers/pathConfig.ts b/compiler/test/transform_ut/helpers/pathConfig.ts index f981685eb..49b950ba5 100644 --- a/compiler/test/transform_ut/helpers/pathConfig.ts +++ b/compiler/test/transform_ut/helpers/pathConfig.ts @@ -279,6 +279,7 @@ export const UT_VALIDATE_PAGES: string[] = [ 'Decorators/process_ui_syntax/EntryDecoParam', 'Decorators/process_ui_syntax/ExtendOneChild', + 'Decorators/process_ui_syntax/ExtendInnerComponents', 'Decorators/process_ui_syntax/NoSrc', 'Decorators/process_ui_syntax/NotSupportResrcParam', 'Decorators/process_ui_syntax/NotSupportResrcType', diff --git a/compiler/test/transform_ut_error.json b/compiler/test/transform_ut_error.json index a3d04ea0a..09c16a5f3 100644 --- a/compiler/test/transform_ut_error.json +++ b/compiler/test/transform_ut_error.json @@ -316,6 +316,10 @@ "type": "ERROR", "code": "10905108" }, + "ExtendInnerComponents": { + "message": "'testExtend' parameter cannot be passed in the '@Extend' decorator.", + "type": "WARN" + }, "UnknownSrc": { "message": "Unknown resource source 'hap'.", "type": "ERROR", -- Gitee