mirror of
https://github.com/openharmony/developtools_ace-ets2bundle.git
synced 2026-07-21 12:05:24 -04:00
optimize preview warning Signed-off-by: houhaoyu <houhaoyu@huawei.com> Change-Id: I73f21561c06b621aee5b78ea192d7d50d82997f7
This commit is contained in:
@@ -23,6 +23,7 @@ import {
|
||||
CREATE_CONSTRUCTOR_PARAMS,
|
||||
COMPONENT_CONSTRUCTOR_UPDATE_PARAMS,
|
||||
COMPONENT_CONSTRUCTOR_DELETE_PARAMS,
|
||||
COMPONENT_DECORATOR_PREVIEW,
|
||||
CREATE_CONSTRUCTOR_SUBSCRIBER_MANAGER,
|
||||
ABOUT_TO_BE_DELETE_FUNCTION_ID,
|
||||
CREATE_CONSTRUCTOR_GET_FUNCTION,
|
||||
@@ -74,17 +75,29 @@ export function processComponentClass(node: ts.ClassDeclaration, context: ts.Tra
|
||||
log: LogInfo[], program: ts.Program): ts.ClassDeclaration {
|
||||
validateInheritClass(node, log);
|
||||
const memberNode: ts.ClassElement[] =
|
||||
processMembers(node.members, node.name, context, log, program);
|
||||
processMembers(node.members, node.name, context, log, program, checkPreview(node));
|
||||
return ts.factory.updateClassDeclaration(node, undefined, node.modifiers, node.name,
|
||||
node.typeParameters, updateHeritageClauses(node), memberNode);
|
||||
}
|
||||
|
||||
function checkPreview(node: ts.ClassDeclaration) {
|
||||
let hasPreview: boolean = false;
|
||||
for (let i = 0; i < node.decorators.length; i++) {
|
||||
const name: string = node.decorators[i].getText().replace(/\((.|\n)*\)/, '').trim();
|
||||
if (name === COMPONENT_DECORATOR_PREVIEW) {
|
||||
hasPreview = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return hasPreview;
|
||||
}
|
||||
|
||||
type BuildCount = {
|
||||
count: number;
|
||||
}
|
||||
|
||||
function processMembers(members: ts.NodeArray<ts.ClassElement>, parentComponentName: ts.Identifier,
|
||||
context: ts.TransformationContext, log: LogInfo[], program: ts.Program): ts.ClassElement[] {
|
||||
context: ts.TransformationContext, log: LogInfo[], program: ts.Program, hasPreview: boolean): ts.ClassElement[] {
|
||||
const buildCount: BuildCount = { count: 0 };
|
||||
let ctorNode: any = getInitConstructor(members);
|
||||
const newMembers: ts.ClassElement[] = [];
|
||||
@@ -97,7 +110,7 @@ function processMembers(members: ts.NodeArray<ts.ClassElement>, parentComponentN
|
||||
let updateItem: ts.ClassElement;
|
||||
if (ts.isPropertyDeclaration(item)) {
|
||||
const result: UpdateResult = processMemberVariableDecorators(parentComponentName, item,
|
||||
ctorNode, watchMap, checkController, log, program, context);
|
||||
ctorNode, watchMap, checkController, log, program, context, hasPreview);
|
||||
if (result.isItemUpdate()) {
|
||||
updateItem = result.getProperity();
|
||||
} else {
|
||||
@@ -298,7 +311,7 @@ function getGeometryReaderFunctionBlock(node: ts.ArrowFunction | ts.FunctionExpr
|
||||
log: LogInfo[]): ts.Block {
|
||||
let blockNode: ts.Block;
|
||||
if (ts.isBlock(node.body)) {
|
||||
blockNode = node.body;
|
||||
blockNode = node.body;
|
||||
} else if (ts.isArrowFunction(node) && ts.isCallExpression(node.body)) {
|
||||
blockNode = ts.factory.createBlock([ts.factory.createExpressionStatement(node.body)]);
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ export const curPropMap: Map<string, string> = new Map();
|
||||
export function processMemberVariableDecorators(parentName: ts.Identifier,
|
||||
item: ts.PropertyDeclaration, ctorNode: ts.ConstructorDeclaration, watchMap: Map<string, ts.Node>,
|
||||
checkController: ControllerType, log: LogInfo[], program: ts.Program,
|
||||
context: ts.TransformationContext): UpdateResult {
|
||||
context: ts.TransformationContext, hasPreview: boolean): UpdateResult {
|
||||
const updateResult: UpdateResult = new UpdateResult();
|
||||
const name: ts.Identifier = item.name as ts.Identifier;
|
||||
if (!item.decorators || !item.decorators.length) {
|
||||
@@ -201,14 +201,14 @@ export function processMemberVariableDecorators(parentName: ts.Identifier,
|
||||
updateResult.setProperity(undefined);
|
||||
updateResult.setUpdateParams(createUpdateParams(name, COMPONENT_NON_DECORATOR));
|
||||
updateResult.setCtor(updateConstructor(ctorNode, [], [
|
||||
createVariableInitStatement(item, COMPONENT_NON_DECORATOR, log, program, context)]));
|
||||
createVariableInitStatement(item, COMPONENT_NON_DECORATOR, log, program, context, hasPreview)]));
|
||||
updateResult.setControllerSet(createControllerSet(item, parentName, name, checkController));
|
||||
} else if (!item.type) {
|
||||
validatePropertyNonType(name, log);
|
||||
return updateResult;
|
||||
} else {
|
||||
processPropertyNodeDecorator(parentName, item, updateResult, ctorNode, name, watchMap,
|
||||
log, program, context);
|
||||
log, program, context, hasPreview);
|
||||
}
|
||||
return updateResult;
|
||||
}
|
||||
@@ -234,7 +234,7 @@ function createControllerSet(node: ts.PropertyDeclaration, componentName: ts.Ide
|
||||
function processPropertyNodeDecorator(parentName: ts.Identifier, node: ts.PropertyDeclaration,
|
||||
updateResult: UpdateResult, ctorNode: ts.ConstructorDeclaration, name: ts.Identifier,
|
||||
watchMap: Map<string, ts.Node>, log: LogInfo[], program: ts.Program,
|
||||
context: ts.TransformationContext): void {
|
||||
context: ts.TransformationContext, hasPreview: boolean): void {
|
||||
let stateManagementDecoratorCount: number = 0;
|
||||
for (let i = 0; i < node.decorators.length; i++) {
|
||||
const decoratorName: string = node.decorators[i].getText().replace(/\(.*\)$/, '').trim();
|
||||
@@ -271,7 +271,7 @@ function processPropertyNodeDecorator(parentName: ts.Identifier, node: ts.Proper
|
||||
processWatch(node, node.decorators[i], watchMap, log);
|
||||
} else if (INNER_COMPONENT_MEMBER_DECORATORS.has(decoratorName)) {
|
||||
stateManagementDecoratorCount += 1;
|
||||
processStateDecorators(node, decoratorName, updateResult, ctorNode, log, program, context);
|
||||
processStateDecorators(node, decoratorName, updateResult, ctorNode, log, program, context, hasPreview);
|
||||
}
|
||||
}
|
||||
if (stateManagementDecoratorCount > 1) {
|
||||
@@ -282,12 +282,12 @@ function processPropertyNodeDecorator(parentName: ts.Identifier, node: ts.Proper
|
||||
|
||||
function processStateDecorators(node: ts.PropertyDeclaration, decorator: string,
|
||||
updateResult: UpdateResult, ctorNode: ts.ConstructorDeclaration, log: LogInfo[],
|
||||
program: ts.Program, context: ts.TransformationContext): void {
|
||||
program: ts.Program, context: ts.TransformationContext, hasPreview:boolean): void {
|
||||
const name: ts.Identifier = node.name as ts.Identifier;
|
||||
updateResult.setProperity(undefined);
|
||||
const updateState: ts.Statement[] = [];
|
||||
const variableInitStatement: ts.Statement =
|
||||
createVariableInitStatement(node, decorator, log, program, context);
|
||||
createVariableInitStatement(node, decorator, log, program, context, hasPreview);
|
||||
if (variableInitStatement) {
|
||||
updateState.push(variableInitStatement);
|
||||
}
|
||||
@@ -338,7 +338,8 @@ function processWatch(node: ts.PropertyDeclaration, decorator: ts.Decorator,
|
||||
}
|
||||
|
||||
function createVariableInitStatement(node: ts.PropertyDeclaration, decorator: string,
|
||||
log: LogInfo[], program: ts.Program, context: ts.TransformationContext): ts.Statement {
|
||||
log: LogInfo[], program: ts.Program, context: ts.TransformationContext, hasPreview: boolean):
|
||||
ts.Statement {
|
||||
const name: ts.Identifier = node.name as ts.Identifier;
|
||||
let type: ts.TypeNode;
|
||||
let updateState: ts.ExpressionStatement;
|
||||
@@ -354,9 +355,11 @@ function createVariableInitStatement(node: ts.PropertyDeclaration, decorator: st
|
||||
updateState = updateObservedProperty(node, name, type, program);
|
||||
break;
|
||||
case COMPONENT_LINK_DECORATOR:
|
||||
wrongDecoratorInPreview(node, COMPONENT_LINK_DECORATOR, hasPreview, log);
|
||||
updateState = updateSynchedPropertyTwoWay(name, type, program);
|
||||
break;
|
||||
case COMPONENT_PROP_DECORATOR:
|
||||
wrongDecoratorInPreview(node, COMPONENT_PROP_DECORATOR, hasPreview, log);
|
||||
updateState = updateSynchedPropertyOneWay(name, type, decorator, log, program);
|
||||
break;
|
||||
case COMPONENT_STORAGE_PROP_DECORATOR:
|
||||
@@ -369,12 +372,25 @@ function createVariableInitStatement(node: ts.PropertyDeclaration, decorator: st
|
||||
updateState = updateSynchedPropertyNesedObject(name, type, decorator, log);
|
||||
break;
|
||||
case COMPONENT_CONSUME_DECORATOR:
|
||||
wrongDecoratorInPreview(node, COMPONENT_CONSUME_DECORATOR, hasPreview, log);
|
||||
updateState = updateConsumeProperty(node, name);
|
||||
break;
|
||||
}
|
||||
return updateState;
|
||||
}
|
||||
|
||||
function wrongDecoratorInPreview(node: ts.PropertyDeclaration, decorator: string,
|
||||
hasPreview: boolean, log: LogInfo[]) {
|
||||
if (hasPreview) {
|
||||
log.push({
|
||||
type: LogType.WARN,
|
||||
message: `The variable with ${decorator} in component with @Preview may ` +
|
||||
`cause error in component preview mode`,
|
||||
pos: node.getStart()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function createUpdateParams(name: ts.Identifier, decorator: string): ts.Statement {
|
||||
let updateParamsNode: ts.Statement;
|
||||
switch (decorator) {
|
||||
|
||||
Reference in New Issue
Block a user