update component declare file.

Signed-off-by: lihong <lihong67@huawei.com>
Change-Id: Ibd8299f12af9efc97203978d4a0f7422631b4b22
This commit is contained in:
lihong
2022-01-13 15:58:08 +08:00
parent d3ffe73ac8
commit 3fc4fa793b
+38 -28
View File
@@ -105,32 +105,7 @@ function processsFile(content, fileName, isGlobal) {
});
} else {
sourceFile.statements.forEach((node) => {
let extendNode = null;
if (isInterface(node)) {
const componentName = node.name.getText().replace(/Interface$/, '');
let isComponentName = false;
if (node.members) {
for (let i = 0; i < node.members.length; i++) {
const callSignNode = node.members[i];
if (isSignNode(callSignNode)) {
const callSignName = callSignNode.type.name.getText().repleace(/Attribute$/, '');
if (componentName === callSignName) {
extendNode = callSignNode.type.typeName;
isComponentName = true;
break;
}
}
}
}
if (isComponentName) {
const heritageClause = ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword,
[ts.factory.createExpressionWithTypeArguments(extendNode, undefined)]);
extendNode = null;
node = ts.factory.updateInterfaceDeclaration(node, node.decorators, node.modifiers,
node.name, node.typeParameters, [heritageClause], node.members);
}
}
newStatements.push(node);
processComponent(node, newStatements);
});
}
}
@@ -140,6 +115,41 @@ function processsFile(content, fileName, isGlobal) {
return result;
}
function processComponent(node, newStatements) {
let extendNode = null;
if (isInterface(node)) {
const componentName = node.name.getText().replace(/Interface$/, '');
const result = validateComponentMembers(node, componentName);
if (result.isComponentName) {
const heritageClause = ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword,
[ts.factory.createExpressionWithTypeArguments(result.extendNode, undefined)]);
extendNode = null;
node = ts.factory.updateInterfaceDeclaration(node, node.decorators, node.modifiers,
node.name, node.typeParameters, [heritageClause], node.members);
}
}
newStatements.push(node);
}
function validateComponentMembers(node, componentName) {
let extendNode = null;
let isComponentName = false;
if (node.members) {
for (let i = 0; i < node.members.length; i++) {
const callSignNode = node.members[i];
if (isSignNode(callSignNode)) {
const callSignName = callSignNode.type.typeName.getText().replace(/Attribute$/, '');
if (componentName === callSignName) {
extendNode = callSignNode.type.typeName;
isComponentName = true;
break;
}
}
}
}
return { isComponentName, extendNode }
}
function isVariable(node) {
if (ts.isVariableStatement(node) && node.declarationList && node.declarationList.declarations &&
node.declarationList.declarations.length && ts.isVariableDeclaration(node.declarationList.declarations[0]) &&
@@ -156,8 +166,8 @@ function isInterface(node) {
function isSignNode(node) {
return (ts.isCallSignatureDeclaration(node) || ts.isConstructSignatureDeclaration(node)) &&
node.type && ts.isTypeReferenceNode(node.type) && node.type.name && ts.isIdentifier(node.type.name) &&
/Attribute$/.test(node.type.name.getText());
node.type && ts.isTypeReferenceNode(node.type) && node.type.typeName && ts.isIdentifier(node.type.typeName) &&
/Attribute$/.test(node.type.typeName.getText());
}
generateComponentConfig(process.argv[4]);