mirror of
https://github.com/openharmony/developtools_ace-ets2bundle.git
synced 2026-07-21 03:55:23 -04:00
!774 add checkHeritageClauses.
Merge pull request !774 from lihong/master
This commit is contained in:
@@ -96,6 +96,7 @@ export const COMPONENT_BUILD_FUNCTION: string = 'build';
|
||||
export const COMPONENT_RENDER_FUNCTION: string = 'render';
|
||||
export const COMPONENT_TRANSITION_FUNCTION: string = 'pageTransition';
|
||||
export const COMPONENT_TRANSITION_NAME: string = 'PageTransition';
|
||||
export const CUSTOM_COMPONENT: string = 'CustomComponent';
|
||||
|
||||
export const COMPONENT_BUTTON: string = 'Button';
|
||||
export const COMPONENT_FOREACH: string = 'ForEach';
|
||||
|
||||
@@ -54,7 +54,8 @@ import {
|
||||
COMPONENT_CONSTRUCTOR_LOCALSTORAGE,
|
||||
COMPONENT_SET_AND_LINK,
|
||||
COMPONENT_SET_AND_PROP,
|
||||
COMPONENT_CONSTRUCTOR_UNDEFINED
|
||||
COMPONENT_CONSTRUCTOR_UNDEFINED,
|
||||
CUSTOM_COMPONENT
|
||||
} from './pre_define';
|
||||
import {
|
||||
BUILDIN_STYLE_NAMES,
|
||||
@@ -97,7 +98,7 @@ export function processComponentClass(node: ts.StructDeclaration, context: ts.Tr
|
||||
const memberNode: ts.ClassElement[] =
|
||||
processMembers(node.members, node.name, context, log, program, checkPreview(node));
|
||||
return ts.factory.createClassDeclaration(undefined, node.modifiers, node.name,
|
||||
node.typeParameters, updateHeritageClauses(), memberNode);
|
||||
node.typeParameters, updateHeritageClauses(node, log), memberNode);
|
||||
}
|
||||
|
||||
function checkPreview(node: ts.ClassDeclaration) {
|
||||
@@ -381,7 +382,15 @@ function getGeometryReaderFunctionBlock(node: ts.ArrowFunction | ts.FunctionExpr
|
||||
return processComponentBlock(blockNode, false, log);
|
||||
}
|
||||
|
||||
function updateHeritageClauses(): ts.NodeArray<ts.HeritageClause> {
|
||||
function updateHeritageClauses(node: ts.StructDeclaration, log: LogInfo[])
|
||||
: ts.NodeArray<ts.HeritageClause> {
|
||||
if (node.heritageClauses && !checkHeritageClauses(node)) {
|
||||
log.push({
|
||||
type: LogType.ERROR,
|
||||
message: 'The struct component is not allowed to extends other class or implements other interface.',
|
||||
pos: node.heritageClauses.pos
|
||||
});
|
||||
}
|
||||
const result:ts.HeritageClause[] = [];
|
||||
const heritageClause:ts.HeritageClause = ts.factory.createHeritageClause(
|
||||
ts.SyntaxKind.ExtendsKeyword,
|
||||
@@ -391,6 +400,18 @@ function updateHeritageClauses(): ts.NodeArray<ts.HeritageClause> {
|
||||
return ts.factory.createNodeArray(result);
|
||||
}
|
||||
|
||||
function checkHeritageClauses(node: ts.StructDeclaration): boolean {
|
||||
if (node.heritageClauses.length === 1 && node.heritageClauses[0].types &&
|
||||
node.heritageClauses[0].types.length === 1) {
|
||||
const expressionNode: ts.ExpressionWithTypeArguments = node.heritageClauses[0].types[0];
|
||||
if (expressionNode.expression && ts.isIdentifier(expressionNode.expression) &&
|
||||
expressionNode.expression.escapedText.toString() === CUSTOM_COMPONENT) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isProperty(node: ts.Node): Boolean {
|
||||
if (judgmentParentType(node)) {
|
||||
if (node.parent.parent.expression && ts.isIdentifier(node.parent.parent.expression) &&
|
||||
|
||||
Reference in New Issue
Block a user