Bugfix: fiexd button with label parameter cannot have any child

Signed-off-by: laibo102 <laibo2@huawei.com>
Change-Id: Iae9c68672c09080d7098274e45876242a40610c3
(cherry picked from commit 024621f25f)
Signed-off-by: laibo102 <laibo2@huawei.com>
This commit is contained in:
laibo102
2022-09-02 15:04:25 +08:00
parent f7b0ff46c8
commit 27d89eb290
+20 -1
View File
@@ -59,7 +59,8 @@ import {
BIND_DRAG_SET,
BIND_POPUP_SET,
$$,
PROPERTIES_ADD_DOUBLE_DOLLAR
PROPERTIES_ADD_DOUBLE_DOLLAR,
RESOURCE
} from './pre_define';
import {
INNER_COMPONENT_NAMES,
@@ -366,6 +367,7 @@ function processInnerComponent(node: ts.ExpressionStatement, newStatements: ts.S
}
if (etsComponentResult.etsComponentNode.body && ts.isBlock(etsComponentResult.etsComponentNode.body)) {
if (res.isButton) {
checkButtonParamHasLabel(etsComponentResult.etsComponentNode, log);
if (projectConfig.isPreview) {
newStatements.splice(-2, 1, createComponent(node, COMPONENT_CREATE_CHILD_FUNCTION).newNode);
} else {
@@ -1262,3 +1264,20 @@ export function validateStateStyleSyntax(temp: any, log: LogInfo[]): void {
pos: temp.getStart()
});
}
function checkButtonParamHasLabel(node: ts.EtsComponentExpression, log: LogInfo[]): void {
if (node.arguments && node.arguments.length !== 0) {
for (let i = 0; i < node.arguments.length; i++) {
let argument: ts.Expression = node.arguments[i];
if (ts.isStringLiteral(argument) || (ts.isCallExpression(argument) && ts.isIdentifier(argument.expression) &&
(argument.expression.escapedText.toString() === RESOURCE))) {
log.push({
type: LogType.ERROR,
message: "The Button component with a label parameter can not have any child.",
pos: node.getStart(),
});
return;
}
}
}
}