Signed-off-by: puyajun <puyajun@huawei.com>
This commit is contained in:
puyajun
2022-01-17 23:10:03 +08:00
parent 58542cfa31
commit 1cd8704e85
3 changed files with 26 additions and 8 deletions
+22 -4
View File
@@ -37,7 +37,8 @@ import {
BUILDER_ATTR_NAME,
BUILDER_ATTR_BIND,
COMPONENT_STYLES_DECORATOR,
STYLES
STYLES,
CUSTOM_COMPONENT_EARLIER_CREATE_CHILD
} from './pre_define';
import {
BUILDIN_STYLE_NAMES,
@@ -211,6 +212,9 @@ function processBuildMember(node: ts.MethodDeclaration, context: ts.Transformati
const buildNode: ts.MethodDeclaration = processComponentBuild(node, log);
return ts.visitNode(buildNode, visitBuild);
function visitBuild(node: ts.Node): ts.Node {
if (isCustomComponentNode(node)) {
return node;
}
if (isGeometryView(node)) {
node = processGeometryView(node as ts.ExpressionStatement, log);
}
@@ -240,9 +244,7 @@ function validateBuilderFunctionNode(node: ts.PropertyAccessExpression | ts.Iden
ts.isIdentifier(node) && CUSTOM_BUILDER_METHOD.has(node.escapedText.toString())) &&
!((ts.isPropertyAccessExpression(node) && validateBuilderParam(node)) ||
(ts.isIdentifier(node) && node.parent && ts.isPropertyAccessExpression(node.parent) &&
validateBuilderParam(node.parent))) &&
// @ts-ignore
(!node.parent.arguments || (node.parent.arguments && !node.parent.arguments.length))) {
validateBuilderParam(node.parent)))) {
return true;
} else {
return false;
@@ -285,6 +287,22 @@ function getParsedBuilderAttrArgument(node: ts.PropertyAccessExpression | ts.Ide
return newObjectNode;
}
function isCustomComponentNode(node:ts.NewExpression | ts.ExpressionStatement): boolean {
if ((ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.escapedText
&& componentCollection.customComponents.has(node.expression.escapedText.toString())) ||
// @ts-ignore
(ts.isExpressionStatement(node) && node.expression && node.expression.expression &&
// @ts-ignore
node.expression.expression.expression && node.expression.expression.expression.escapedText &&
// @ts-ignore
node.expression.expression.expression.escapedText.toString().startsWith(
CUSTOM_COMPONENT_EARLIER_CREATE_CHILD))) {
return true;
}else {
return false;
}
}
function isGeometryView(node: ts.Node): boolean {
if (ts.isExpressionStatement(node) && ts.isCallExpression(node.expression)) {
const call: ts.CallExpression = node.expression;
+2 -2
View File
@@ -105,9 +105,9 @@ function validateCustomComponentPrams(node: ts.ExpressionStatement, name: string
ts.isObjectLiteralExpression(nodeArguments[0])) {
const nodeArgument: ts.ObjectLiteralExpression = nodeArguments[0] as ts.ObjectLiteralExpression;
nodeArgument.properties.forEach(item => {
if (item.name && node.name.escapedText) {
if (item.name && item.name.escapedText) {
// @ts-ignore
curChildProps.add(node.name.escapedText.toString());
curChildProps.add(item.name.escapedText.toString());
}
if (isThisProperty(item, propertySet)) {
validateStateManagement(item, name, log);
+2 -2
View File
@@ -132,14 +132,14 @@ class CustomContainerUser {
View.create(new CustomContainer("2", this, {
header: "Header",
footer: "Footer",
child: {build:this.specificChild.bind(this)}
child: this.specificChild
}));
}
else {
earlierCreatedChild_2.updateWithValueParams({
header: "Header",
footer: "Footer",
child: {build:this.specificChild.bind(this)}
child: this.specificChild
});
View.create(earlierCreatedChild_2);
}