diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index cf0a880fc5fb79fcab21d6817f5d3425fc57fdaa..6a5607db1d194c557d239f33a46c4f583465164e 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 0000000000000000000000000000000000000000..381312e2543e19db2edc981c0322282802c70c86 --- /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 f981685eb677f2a2caa29c1ec8653eca002cc330..49b950ba548a288285ca97e07245426f01230d33 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 a3d04ea0a9bd57204ee8ad3951f79e9e8ca3d787..09c16a5f3aefd896cb8035cb0312ea9246abdb1c 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",