From 0b5723a1892a68fe93b3c71e82c6ee7d3618bbcc Mon Sep 17 00:00:00 2001 From: houhaoyu Date: Sun, 9 Jan 2022 19:58:20 +0800 Subject: [PATCH 01/44] houhaoyu@huawei.com Signed-off-by: houhaoyu Change-Id: I8af359273f1df939e57e2f06fb558c8ec7e5d3eb --- compiler/src/process_component_class.ts | 80 ++++++++++++++++++- compiler/src/process_component_constructor.ts | 44 ++++++++-- compiler/src/process_component_member.ts | 9 ++- 3 files changed, 121 insertions(+), 12 deletions(-) diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index 1ac7be8..e68f682 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -16,6 +16,19 @@ import ts from 'typescript'; import { + COMPONENT_STATE_DECORATOR, + COMPONENT_PROVIDE_DECORATOR, + COMPONENT_LINK_DECORATOR, + COMPONENT_PROP_DECORATOR, + COMPONENT_STORAGE_LINK_DECORATOR, + COMPONENT_STORAGE_PROP_DECORATOR, + COMPONENT_OBJECT_LINK_DECORATOR, + COMPONENT_CONSUME_DECORATOR, + SYNCHED_PROPERTY_NESED_OBJECT, + SYNCHED_PROPERTY_SIMPLE_TWO_WAY, + SYNCHED_PROPERTY_SIMPLE_ONE_WAY, + OBSERVED_PROPERTY_OBJECT, + OBSERVED_PROPERTY_SIMPLE, COMPONENT_BUILD_FUNCTION, BASE_COMPONENT_NAME, ATTRIBUTE_ANIMATETO, @@ -59,7 +72,8 @@ import { UpdateResult, stateObjectCollection, curPropMap, - decoratorParamSet + decoratorParamSet, + isSimpleType } from './process_component_member'; import { processComponentBuild, @@ -109,6 +123,7 @@ function processMembers(members: ts.NodeArray, parentComponentN members.forEach((item: ts.ClassElement) => { let updateItem: ts.ClassElement; if (ts.isPropertyDeclaration(item)) { + addPropertyMember(item, newMembers, program); const result: UpdateResult = processMemberVariableDecorators(parentComponentName, item, ctorNode, watchMap, checkController, log, program, context, hasPreview); if (result.isItemUpdate()) { @@ -151,6 +166,65 @@ function processMembers(members: ts.NodeArray, parentComponentN return newMembers; } +function addPropertyMember(item: ts.ClassElement, newMembers: ts.ClassElement[], + program: ts.Program):void { + let propertyItem: ts.PropertyDeclaration = item as ts.PropertyDeclaration; + let decoratorName: string; + let updatePropertyItem: ts.PropertyDeclaration; + let type: ts.TypeNode = propertyItem.type; + if (!propertyItem.decorators || propertyItem.decorators.length === 0) { + updatePropertyItem = createPropertyDeclaration(propertyItem, type, true); + newMembers.push(updatePropertyItem); + } else if (propertyItem.decorators) { + for (let i = 0; i < propertyItem.decorators.length; i++) { + let newType: ts.TypeNode; + decoratorName = propertyItem.decorators[i].getText().replace(/\(.*\)$/, '').trim(); + switch (decoratorName) { + case COMPONENT_STATE_DECORATOR: + case COMPONENT_PROVIDE_DECORATOR: + newType = ts.factory.createTypeReferenceNode(isSimpleType(type, program) ? + OBSERVED_PROPERTY_SIMPLE : OBSERVED_PROPERTY_OBJECT, [type]); + break; + case COMPONENT_LINK_DECORATOR: + case COMPONENT_CONSUME_DECORATOR: + newType = ts.factory.createTypeReferenceNode(isSimpleType(type, program) ? + SYNCHED_PROPERTY_SIMPLE_TWO_WAY : SYNCHED_PROPERTY_SIMPLE_ONE_WAY, [type]); + break; + case COMPONENT_PROP_DECORATOR: + newType = ts.factory.createTypeReferenceNode(SYNCHED_PROPERTY_SIMPLE_ONE_WAY, [type]); + break; + case COMPONENT_OBJECT_LINK_DECORATOR: + newType = ts.factory.createTypeReferenceNode(SYNCHED_PROPERTY_NESED_OBJECT, [type]); + break; + case COMPONENT_STORAGE_PROP_DECORATOR: + case COMPONENT_STORAGE_LINK_DECORATOR: + newType = ts.factory.createTypeReferenceNode('ObservedPropertyAbstract', [type]); + break; + } + updatePropertyItem = createPropertyDeclaration(propertyItem, newType, false); + if (updatePropertyItem) { + newMembers.push(updatePropertyItem); + } + } + } +} + +function createPropertyDeclaration(propertyItem: ts.PropertyDeclaration, newType: ts.TypeNode | undefined, + normalVar: boolean): ts.PropertyDeclaration { + if (typeof newType === undefined) { + return undefined; + } + let prefix: string = ''; + if (!normalVar) { + prefix = '__'; + } + const privateM: ts.ModifierToken = + ts.factory.createModifier(ts.SyntaxKind.PrivateKeyword); + return ts.factory.updatePropertyDeclaration(propertyItem, undefined, + propertyItem.modifiers || [privateM], prefix + propertyItem.name.getText(), + propertyItem.questionToken, newType, undefined); +} + function processComponentMethod(node: ts.MethodDeclaration, parentComponentName: ts.Identifier, context: ts.TransformationContext, log: LogInfo[], buildCount: BuildCount): ts.MethodDeclaration { let updateItem: ts.MethodDeclaration = node; @@ -450,7 +524,9 @@ function createParamsInitBlock(express: string, statements: ts.Statement[]): ts. undefined, undefined, ts.factory.createIdentifier(express), undefined, undefined, [ts.factory.createParameterDeclaration(undefined, undefined, undefined, express === COMPONENT_CONSTRUCTOR_DELETE_PARAMS ? undefined : - ts.factory.createIdentifier(CREATE_CONSTRUCTOR_PARAMS), undefined, undefined, undefined)], + ts.factory.createIdentifier(CREATE_CONSTRUCTOR_PARAMS), undefined, + express === COMPONENT_CONSTRUCTOR_DELETE_PARAMS ? undefined : + ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), undefined)], undefined, ts.factory.createBlock(statements, true)); return methodDeclaration; } diff --git a/compiler/src/process_component_constructor.ts b/compiler/src/process_component_constructor.ts index fa619f0..9135d06 100644 --- a/compiler/src/process_component_constructor.ts +++ b/compiler/src/process_component_constructor.ts @@ -20,7 +20,8 @@ import { COMPONENT_CONSTRUCTOR_PARENT, COMPONENT_CONSTRUCTOR_PARAMS, COMPONENT_CONSTRUCTOR_UPDATE_PARAMS, - COMPONENT_WATCH_FUNCTION + COMPONENT_WATCH_FUNCTION, + BASE_COMPONENT_NAME } from './pre_define'; export function getInitConstructor(members: ts.NodeArray): ts.ConstructorDeclaration { @@ -35,7 +36,7 @@ export function getInitConstructor(members: ts.NodeArray): ts.Construct export function updateConstructor(ctorNode: ts.ConstructorDeclaration, para: ts.ParameterDeclaration[], addStatements: ts.Statement[], - isSuper: boolean = false): ts.ConstructorDeclaration { + isSuper: boolean = false, isAdd: boolean = false): ts.ConstructorDeclaration { let modifyPara: ts.ParameterDeclaration[]; if (para && para.length) { modifyPara = Array.from(ctorNode.parameters); @@ -55,9 +56,40 @@ export function updateConstructor(ctorNode: ts.ConstructorDeclaration, } } if (ctorNode) { - ctorNode = ts.factory.updateConstructorDeclaration(ctorNode, ctorNode.decorators, - ctorNode.modifiers, modifyPara || ctorNode.parameters, - ts.factory.createBlock(modifyBody || ctorNode.body.statements, true)); + const tsPara: ts.ParameterDeclaration[] | ts.NodeArray = + modifyPara || ctorNode.parameters; + const newTSPara: ts.ParameterDeclaration[] = []; + if (isAdd) { + tsPara.forEach((item) => { + let parameter: ts.ParameterDeclaration = item; + switch (item.getText()) { + case COMPONENT_CONSTRUCTOR_ID + '?': + parameter = ts.factory.updateParameterDeclaration(item, item.decorators, item.modifiers, + item.dotDotDotToken, item.name, item.questionToken, + ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), item.initializer); + break; + case COMPONENT_CONSTRUCTOR_PARENT + '?': + parameter = ts.factory.createParameterDeclaration(item.decorators, item.modifiers, + item.dotDotDotToken, item.name, item.questionToken, + ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(BASE_COMPONENT_NAME), undefined), + item.initializer); + break; + case COMPONENT_CONSTRUCTOR_PARAMS + '?': + parameter = ts.factory.updateParameterDeclaration(item, item.decorators, item.modifiers, + item.dotDotDotToken, item.name, item.questionToken, + ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), item.initializer); + break; + } + newTSPara.push(parameter); + }) + ctorNode = ts.factory.updateConstructorDeclaration(ctorNode, ctorNode.decorators, + ctorNode.modifiers, newTSPara, + ts.factory.createBlock(modifyBody || ctorNode.body.statements, true)); + } else { + ctorNode = ts.factory.updateConstructorDeclaration(ctorNode, ctorNode.decorators, + ctorNode.modifiers, modifyPara || ctorNode.parameters, + ts.factory.createBlock(modifyBody || ctorNode.body.statements, true)); + } } return ctorNode; } @@ -91,5 +123,5 @@ export function addConstructor(ctorNode: any, watchMap: Map) ts.factory.createThis(), ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_UPDATE_PARAMS)), undefined, [ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARAMS)])); return updateConstructor(updateConstructor(ctorNode, [], [callSuperStatement], true), [], - [updateWithValueParamsStatement, ...watchStatements], false); + [updateWithValueParamsStatement, ...watchStatements], false, true); } diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index 4799fe3..05909c9 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -295,7 +295,7 @@ function processStateDecorators(node: ts.PropertyDeclaration, decorator: string, updateResult.setCtor(updateConstructor(ctorNode, [], [...updateState], false)); updateResult.setVariableGet(createGetAccessor(name, CREATE_GET_METHOD)); if (!immutableDecorators.has(decorator)) { - updateResult.setVariableSet(createSetAccessor(name, CREATE_SET_METHOD)); + updateResult.setVariableSet(createSetAccessor(name, CREATE_SET_METHOD, node.type)); } if (setUpdateParamsDecorators.has(decorator)) { updateResult.setUpdateParams(createUpdateParams(name, decorator)); @@ -689,11 +689,12 @@ function createGetAccessor(item: ts.Identifier, express: string): ts.GetAccessor return getAccessorStatement; } -function createSetAccessor(item: ts.Identifier, express: string): ts.SetAccessorDeclaration { +function createSetAccessor(item: ts.Identifier, express: string, type: ts.TypeNode): + ts.SetAccessorDeclaration { const setAccessorStatement: ts.SetAccessorDeclaration = ts.factory.createSetAccessorDeclaration(undefined, undefined, item, [ts.factory.createParameterDeclaration(undefined, undefined, undefined, - ts.factory.createIdentifier(CREATE_NEWVALUE_IDENTIFIER), undefined, undefined, + ts.factory.createIdentifier(CREATE_NEWVALUE_IDENTIFIER), undefined, type, undefined)], ts.factory.createBlock([ts.factory.createExpressionStatement( ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression( createPropertyAccessExpressionWithThis(`__${item.getText()}`), @@ -710,7 +711,7 @@ function isForbiddenUseStateType(typeNode: ts.TypeNode): boolean { return false; } -function isSimpleType(typeNode: ts.TypeNode, program: ts.Program): boolean { +export function isSimpleType(typeNode: ts.TypeNode, program: ts.Program): boolean { let checker: ts.TypeChecker; if (program) { checker = program.getTypeChecker(); From 031362963a7e976da635b7bf9a757cd7e509c859 Mon Sep 17 00:00:00 2001 From: houhaoyu Date: Thu, 13 Jan 2022 10:44:18 +0800 Subject: [PATCH 02/44] houhaoyu@huawei.com Signed-off-by: houhaoyu Change-Id: Iafe0c1f5642c081667c11aaff9f34bd723856ced --- compiler/src/component_map.ts | 2 ++ compiler/src/process_component_class.ts | 22 +++++++++----- compiler/src/process_component_constructor.ts | 12 ++++---- compiler/src/process_component_member.ts | 30 ++++++++++++------- compiler/src/process_ui_syntax.ts | 12 +++++++- 5 files changed, 54 insertions(+), 24 deletions(-) diff --git a/compiler/src/component_map.ts b/compiler/src/component_map.ts index 6bd7a35..0250947 100644 --- a/compiler/src/component_map.ts +++ b/compiler/src/component_map.ts @@ -77,6 +77,8 @@ export interface ExtendParamterInterfance { export const EXTEND_ATTRIBUTE: Map> = new Map(); export const STYLES_ATTRIBUTE: Set = new Set(); +export const INTERFACE_NODE_SET: Set = new Set(); + export const JS_BIND_COMPONENTS: Set = new Set([ ...GESTURE_TYPE_NAMES, 'Gesture', 'PanGestureOption', 'CustomDialogController', 'Storage', 'Scroller', 'SwiperController', diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index e68f682..8d7b4d4 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -56,6 +56,7 @@ import { BUILDIN_STYLE_NAMES, CUSTOM_BUILDER_METHOD, INNER_STYLE_FUNCTION, + INTERFACE_NODE_SET, STYLES_ATTRIBUTE } from './component_map'; import { @@ -120,12 +121,14 @@ function processMembers(members: ts.NodeArray, parentComponentN const deleteParamsStatements: ts.PropertyDeclaration[] = []; const checkController: ControllerType = { hasController: !componentCollection.customDialogs.has(parentComponentName.getText()) }; + let interfaceNode = ts.factory.createInterfaceDeclaration(undefined, undefined, + parentComponentName.getText()+'_Params', undefined, undefined, []) members.forEach((item: ts.ClassElement) => { let updateItem: ts.ClassElement; if (ts.isPropertyDeclaration(item)) { addPropertyMember(item, newMembers, program); const result: UpdateResult = processMemberVariableDecorators(parentComponentName, item, - ctorNode, watchMap, checkController, log, program, context, hasPreview); + ctorNode, watchMap, checkController, log, program, context, hasPreview, interfaceNode); if (result.isItemUpdate()) { updateItem = result.getProperity(); } else { @@ -158,11 +161,12 @@ function processMembers(members: ts.NodeArray, parentComponentN newMembers.push(updateItem); } }); + INTERFACE_NODE_SET.add(interfaceNode); validateBuildMethodCount(buildCount, parentComponentName, log); validateHasController(parentComponentName, checkController, log); newMembers.unshift(addDeleteParamsFunc(deleteParamsStatements)); - newMembers.unshift(addUpdateParamsFunc(updateParamsStatements)); - newMembers.unshift(addConstructor(ctorNode, watchMap)); + newMembers.unshift(addUpdateParamsFunc(updateParamsStatements, parentComponentName)); + newMembers.unshift(addConstructor(ctorNode, watchMap, parentComponentName)); return newMembers; } @@ -488,8 +492,9 @@ function processAnimateTo(node: ts.CallExpression): ts.CallExpression { node.typeArguments, node.arguments); } -function addUpdateParamsFunc(statements: ts.Statement[]): ts.MethodDeclaration { - return createParamsInitBlock(COMPONENT_CONSTRUCTOR_UPDATE_PARAMS, statements); +function addUpdateParamsFunc(statements: ts.Statement[], parentComponentName: ts.Identifier): + ts.MethodDeclaration { + return createParamsInitBlock(COMPONENT_CONSTRUCTOR_UPDATE_PARAMS, statements, parentComponentName); } function addDeleteParamsFunc(statements: ts.PropertyDeclaration[]): ts.MethodDeclaration { @@ -519,15 +524,16 @@ function addDeleteParamsFunc(statements: ts.PropertyDeclaration[]): ts.MethodDec return deleteParamsMethod; } -function createParamsInitBlock(express: string, statements: ts.Statement[]): ts.MethodDeclaration { +function createParamsInitBlock(express: string, statements: ts.Statement[], + parentComponentName?: ts.Identifier): ts.MethodDeclaration { const methodDeclaration: ts.MethodDeclaration = ts.factory.createMethodDeclaration(undefined, undefined, undefined, ts.factory.createIdentifier(express), undefined, undefined, [ts.factory.createParameterDeclaration(undefined, undefined, undefined, express === COMPONENT_CONSTRUCTOR_DELETE_PARAMS ? undefined : ts.factory.createIdentifier(CREATE_CONSTRUCTOR_PARAMS), undefined, express === COMPONENT_CONSTRUCTOR_DELETE_PARAMS ? undefined : - ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), undefined)], - undefined, ts.factory.createBlock(statements, true)); + ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(parentComponentName.getText() + '_Params') + , undefined), undefined)], undefined, ts.factory.createBlock(statements, true)); return methodDeclaration; } diff --git a/compiler/src/process_component_constructor.ts b/compiler/src/process_component_constructor.ts index 9135d06..750923b 100644 --- a/compiler/src/process_component_constructor.ts +++ b/compiler/src/process_component_constructor.ts @@ -36,7 +36,8 @@ export function getInitConstructor(members: ts.NodeArray): ts.Construct export function updateConstructor(ctorNode: ts.ConstructorDeclaration, para: ts.ParameterDeclaration[], addStatements: ts.Statement[], - isSuper: boolean = false, isAdd: boolean = false): ts.ConstructorDeclaration { + isSuper: boolean = false, isAdd: boolean = false, parentComponentName?: ts.Identifier): + ts.ConstructorDeclaration { let modifyPara: ts.ParameterDeclaration[]; if (para && para.length) { modifyPara = Array.from(ctorNode.parameters); @@ -77,7 +78,8 @@ export function updateConstructor(ctorNode: ts.ConstructorDeclaration, case COMPONENT_CONSTRUCTOR_PARAMS + '?': parameter = ts.factory.updateParameterDeclaration(item, item.decorators, item.modifiers, item.dotDotDotToken, item.name, item.questionToken, - ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), item.initializer); + ts.factory.createTypeReferenceNode(ts.factory.createIdentifier + (parentComponentName.getText() + '_Params'), undefined), item.initializer); break; } newTSPara.push(parameter); @@ -94,8 +96,8 @@ export function updateConstructor(ctorNode: ts.ConstructorDeclaration, return ctorNode; } -export function addConstructor(ctorNode: any, watchMap: Map) - : ts.ConstructorDeclaration { +export function addConstructor(ctorNode: any, watchMap: Map, + parentComponentName: ts.Identifier): ts.ConstructorDeclaration { const watchStatements: ts.ExpressionStatement[] = []; watchMap.forEach((value, key) => { const watchNode: ts.ExpressionStatement = ts.factory.createExpressionStatement( @@ -123,5 +125,5 @@ export function addConstructor(ctorNode: any, watchMap: Map) ts.factory.createThis(), ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_UPDATE_PARAMS)), undefined, [ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARAMS)])); return updateConstructor(updateConstructor(ctorNode, [], [callSuperStatement], true), [], - [updateWithValueParamsStatement, ...watchStatements], false, true); + [updateWithValueParamsStatement, ...watchStatements], false, true, parentComponentName); } diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index 05909c9..1d72b7a 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -192,8 +192,8 @@ export const curPropMap: Map = new Map(); export function processMemberVariableDecorators(parentName: ts.Identifier, item: ts.PropertyDeclaration, ctorNode: ts.ConstructorDeclaration, watchMap: Map, - checkController: ControllerType, log: LogInfo[], program: ts.Program, - context: ts.TransformationContext, hasPreview: boolean): UpdateResult { + checkController: ControllerType, log: LogInfo[], program: ts.Program, context: ts.TransformationContext, + hasPreview: boolean, interfaceNode: ts.InterfaceDeclaration): UpdateResult { const updateResult: UpdateResult = new UpdateResult(); const name: ts.Identifier = item.name as ts.Identifier; if (!item.decorators || !item.decorators.length) { @@ -201,14 +201,15 @@ 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, hasPreview)])); + createVariableInitStatement(item, COMPONENT_NON_DECORATOR, log, program, context, hasPreview, + interfaceNode)])); 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, hasPreview); + log, program, context, hasPreview, interfaceNode); } return updateResult; } @@ -234,7 +235,8 @@ 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, log: LogInfo[], program: ts.Program, - context: ts.TransformationContext, hasPreview: boolean): void { + context: ts.TransformationContext, hasPreview: boolean, interfaceNode: ts.InterfaceDeclaration): + 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 +273,8 @@ 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, hasPreview); + processStateDecorators(node, decoratorName, updateResult, ctorNode, log, program, context, + hasPreview, interfaceNode); } } if (stateManagementDecoratorCount > 1) { @@ -282,12 +285,13 @@ 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, hasPreview:boolean): void { + program: ts.Program, context: ts.TransformationContext, hasPreview:boolean, + interfaceNode: ts.InterfaceDeclaration): 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, hasPreview); + createVariableInitStatement(node, decorator, log, program, context, hasPreview, interfaceNode); if (variableInitStatement) { updateState.push(variableInitStatement); } @@ -338,8 +342,8 @@ function processWatch(node: ts.PropertyDeclaration, decorator: ts.Decorator, } function createVariableInitStatement(node: ts.PropertyDeclaration, decorator: string, - log: LogInfo[], program: ts.Program, context: ts.TransformationContext, hasPreview: boolean): - ts.Statement { + log: LogInfo[], program: ts.Program, context: ts.TransformationContext, hasPreview: boolean, + interfaceNode: ts.InterfaceDeclaration): ts.Statement { const name: ts.Identifier = node.name as ts.Identifier; let type: ts.TypeNode; let updateState: ts.ExpressionStatement; @@ -376,6 +380,12 @@ function createVariableInitStatement(node: ts.PropertyDeclaration, decorator: st updateState = updateConsumeProperty(node, name); break; } + const members = interfaceNode.members; + members.push(ts.factory.createPropertySignature(undefined, name, + ts.factory.createToken(ts.SyntaxKind.QuestionToken), type)); + interfaceNode = ts.factory.updateInterfaceDeclaration(interfaceNode, undefined, + interfaceNode.modifiers, interfaceNode.name, interfaceNode.typeParameters, + interfaceNode.heritageClauses, members); return updateState; } diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index a462867..ed4d651 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -56,7 +56,8 @@ import { EXTEND_ATTRIBUTE, JS_BIND_COMPONENTS, INNER_STYLE_FUNCTION, - GLOBAL_STYLE_FUNCTION + GLOBAL_STYLE_FUNCTION, + INTERFACE_NODE_SET } from './component_map'; import { resources } from '../main'; @@ -81,6 +82,15 @@ export function processUISyntax(program: ts.Program, ut = false): Function { BUILDIN_STYLE_NAMES.delete(styleName); }) GLOBAL_STYLE_FUNCTION.clear(); + const statements: ts.NodeArray = node.statements; + INTERFACE_NODE_SET.forEach(item => { + statements.unshift(item); + }); + node = ts.factory.updateSourceFile(node, statements); + INTERFACE_NODE_SET.clear(); + const printer = ts.createPrinter({newLine: ts.NewLineKind.LineFeed}) + const result = printer.printNode(ts.EmitHint.Unspecified, node, node) + console.log(result) return node; } else { return node; From 883b6c035229658e74dfab0e51d4dbf6e3bc141a Mon Sep 17 00:00:00 2001 From: houhaoyu Date: Sat, 15 Jan 2022 14:41:02 +0800 Subject: [PATCH 03/44] houhaoyu@huawei.com Signed-off-by: houhaoyu Change-Id: I0f7d1707ef45d1067cf1daa8402d9004fae8e423 --- compiler/src/component_map.ts | 2 +- compiler/src/pre_define.ts | 3 + compiler/src/process_component_class.ts | 13 ++-- compiler/src/process_component_constructor.ts | 70 ++++++++++--------- 4 files changed, 49 insertions(+), 39 deletions(-) diff --git a/compiler/src/component_map.ts b/compiler/src/component_map.ts index 0250947..1a5ec2a 100644 --- a/compiler/src/component_map.ts +++ b/compiler/src/component_map.ts @@ -77,7 +77,7 @@ export interface ExtendParamterInterfance { export const EXTEND_ATTRIBUTE: Map> = new Map(); export const STYLES_ATTRIBUTE: Set = new Set(); -export const INTERFACE_NODE_SET: Set = new Set(); +export const INTERFACE_NODE_SET: Set = new Set(); export const JS_BIND_COMPONENTS: Set = new Set([ ...GESTURE_TYPE_NAMES, 'Gesture', diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index a0a1f74..e6f325b 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -191,3 +191,6 @@ export const $$_VALUE: string = 'value'; export const $$_CHANGE_EVENT: string = 'changeEvent'; export const $$_THIS: string = '$$this'; export const $$_NEW_VALUE: string = 'newValue'; + +export const INTERFACE_NAME_SUFFIX:string = '_Params'; +export const OBSERVED_PROPERTY_ABSTRACT:string = 'ObservedPropertyAbstract'; diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index 8d7b4d4..d5a0a0b 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -50,7 +50,9 @@ import { BUILDER_ATTR_NAME, BUILDER_ATTR_BIND, COMPONENT_STYLES_DECORATOR, - STYLES + STYLES, + INTERFACE_NAME_SUFFIX, + OBSERVED_PROPERTY_ABSTRACT } from './pre_define'; import { BUILDIN_STYLE_NAMES, @@ -122,7 +124,7 @@ function processMembers(members: ts.NodeArray, parentComponentN const checkController: ControllerType = { hasController: !componentCollection.customDialogs.has(parentComponentName.getText()) }; let interfaceNode = ts.factory.createInterfaceDeclaration(undefined, undefined, - parentComponentName.getText()+'_Params', undefined, undefined, []) + parentComponentName.getText() + INTERFACE_NAME_SUFFIX, undefined, undefined, []) members.forEach((item: ts.ClassElement) => { let updateItem: ts.ClassElement; if (ts.isPropertyDeclaration(item)) { @@ -202,7 +204,7 @@ function addPropertyMember(item: ts.ClassElement, newMembers: ts.ClassElement[], break; case COMPONENT_STORAGE_PROP_DECORATOR: case COMPONENT_STORAGE_LINK_DECORATOR: - newType = ts.factory.createTypeReferenceNode('ObservedPropertyAbstract', [type]); + newType = ts.factory.createTypeReferenceNode(OBSERVED_PROPERTY_ABSTRACT, [type]); break; } updatePropertyItem = createPropertyDeclaration(propertyItem, newType, false); @@ -532,8 +534,9 @@ function createParamsInitBlock(express: string, statements: ts.Statement[], express === COMPONENT_CONSTRUCTOR_DELETE_PARAMS ? undefined : ts.factory.createIdentifier(CREATE_CONSTRUCTOR_PARAMS), undefined, express === COMPONENT_CONSTRUCTOR_DELETE_PARAMS ? undefined : - ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(parentComponentName.getText() + '_Params') - , undefined), undefined)], undefined, ts.factory.createBlock(statements, true)); + ts.factory.createTypeReferenceNode( + ts.factory.createIdentifier(parentComponentName.getText() + INTERFACE_NAME_SUFFIX), undefined), + undefined)], undefined, ts.factory.createBlock(statements, true)); return methodDeclaration; } diff --git a/compiler/src/process_component_constructor.ts b/compiler/src/process_component_constructor.ts index 750923b..79e2472 100644 --- a/compiler/src/process_component_constructor.ts +++ b/compiler/src/process_component_constructor.ts @@ -21,7 +21,8 @@ import { COMPONENT_CONSTRUCTOR_PARAMS, COMPONENT_CONSTRUCTOR_UPDATE_PARAMS, COMPONENT_WATCH_FUNCTION, - BASE_COMPONENT_NAME + BASE_COMPONENT_NAME, + INTERFACE_NAME_SUFFIX } from './pre_define'; export function getInitConstructor(members: ts.NodeArray): ts.ConstructorDeclaration { @@ -57,45 +58,48 @@ export function updateConstructor(ctorNode: ts.ConstructorDeclaration, } } if (ctorNode) { - const tsPara: ts.ParameterDeclaration[] | ts.NodeArray = + let ctorPara: ts.ParameterDeclaration[] | ts.NodeArray = modifyPara || ctorNode.parameters; - const newTSPara: ts.ParameterDeclaration[] = []; if (isAdd) { - tsPara.forEach((item) => { - let parameter: ts.ParameterDeclaration = item; - switch (item.getText()) { - case COMPONENT_CONSTRUCTOR_ID + '?': - parameter = ts.factory.updateParameterDeclaration(item, item.decorators, item.modifiers, - item.dotDotDotToken, item.name, item.questionToken, - ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), item.initializer); - break; - case COMPONENT_CONSTRUCTOR_PARENT + '?': - parameter = ts.factory.createParameterDeclaration(item.decorators, item.modifiers, - item.dotDotDotToken, item.name, item.questionToken, - ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(BASE_COMPONENT_NAME), undefined), - item.initializer); - break; - case COMPONENT_CONSTRUCTOR_PARAMS + '?': - parameter = ts.factory.updateParameterDeclaration(item, item.decorators, item.modifiers, - item.dotDotDotToken, item.name, item.questionToken, - ts.factory.createTypeReferenceNode(ts.factory.createIdentifier - (parentComponentName.getText() + '_Params'), undefined), item.initializer); - break; - } - newTSPara.push(parameter); - }) - ctorNode = ts.factory.updateConstructorDeclaration(ctorNode, ctorNode.decorators, - ctorNode.modifiers, newTSPara, - ts.factory.createBlock(modifyBody || ctorNode.body.statements, true)); - } else { - ctorNode = ts.factory.updateConstructorDeclaration(ctorNode, ctorNode.decorators, - ctorNode.modifiers, modifyPara || ctorNode.parameters, - ts.factory.createBlock(modifyBody || ctorNode.body.statements, true)); + ctorPara = addParamsType(ctorNode, modifyPara, parentComponentName); } + ctorNode = ts.factory.updateConstructorDeclaration(ctorNode, ctorNode.decorators, + ctorNode.modifiers, ctorPara, ts.factory.createBlock(modifyBody || ctorNode.body.statements, true)); } return ctorNode; } +function addParamsType(ctorNode: ts.ConstructorDeclaration, modifyPara: ts.ParameterDeclaration[], + parentComponentName: ts.Identifier): ts.ParameterDeclaration[] { + const tsPara: ts.ParameterDeclaration[] | ts.NodeArray = + modifyPara || ctorNode.parameters; + const newTSPara: ts.ParameterDeclaration[] = []; + tsPara.forEach((item) => { + let parameter: ts.ParameterDeclaration = item; + switch (item.getText()) { + case COMPONENT_CONSTRUCTOR_ID + '?': + parameter = ts.factory.updateParameterDeclaration(item, item.decorators, item.modifiers, + item.dotDotDotToken, item.name, item.questionToken, + ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), item.initializer); + break; + case COMPONENT_CONSTRUCTOR_PARENT + '?': + parameter = ts.factory.createParameterDeclaration(item.decorators, item.modifiers, + item.dotDotDotToken, item.name, item.questionToken, + ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(BASE_COMPONENT_NAME), undefined), + item.initializer); + break; + case COMPONENT_CONSTRUCTOR_PARAMS + '?': + parameter = ts.factory.updateParameterDeclaration(item, item.decorators, item.modifiers, + item.dotDotDotToken, item.name, item.questionToken, + ts.factory.createTypeReferenceNode(ts.factory.createIdentifier + (parentComponentName.getText() + INTERFACE_NAME_SUFFIX), undefined), item.initializer); + break; + } + newTSPara.push(parameter); + }) + return newTSPara; +} + export function addConstructor(ctorNode: any, watchMap: Map, parentComponentName: ts.Identifier): ts.ConstructorDeclaration { const watchStatements: ts.ExpressionStatement[] = []; From 31fbef7e13f577cfc21538dfe79ba2b7a8751af5 Mon Sep 17 00:00:00 2001 From: lihong Date: Tue, 18 Jan 2022 22:14:34 +0800 Subject: [PATCH 04/44] lihong67@huawei.com fix application.missonManager api transform. Signed-off-by: lihong Change-Id: Ia0edc01a38732136dfb7291759155680ef8622ec --- compiler/src/validate_ui_syntax.ts | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index 7d1f305..c57d75f 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -802,13 +802,8 @@ function collectExtend(component: string, attribute: string, parameter: string): export function processSystemApi(content: string, isProcessWhiteList: boolean = false): string { let REG_SYSTEM: RegExp; - if (isProcessWhiteList) { - REG_SYSTEM = - /(import|const)\s+(.+)\s*=\s*(\_\_importDefault\()?require\(\s*['"]@(system|ohos)\.(\S+)['"]\s*\)(\))?/g; - } else { - REG_SYSTEM = - /import\s+(.+)\s+from\s+['"]@(system|ohos)\.(\S+)['"]|import\s+(.+)\s*=\s*require\(\s*['"]@(system|ohos)\.(\S+)['"]\s*\)/g; - } + REG_SYSTEM = + /import\s+(.+)\s+from\s+['"]@(system|ohos)\.(\S+)['"]|import\s+(.+)\s*=\s*require\(\s*['"]@(system|ohos)\.(\S+)['"]\s*\)/g; const REG_LIB_SO: RegExp = /import\s+(.+)\s+from\s+['"]lib(\S+)\.so['"]|import\s+(.+)\s*=\s*require\(\s*['"]lib(\S+)\.so['"]\s*\)/g; return content.replace(REG_LIB_SO, (_, item1, item2, item3, item4) => { @@ -819,13 +814,6 @@ export function processSystemApi(content: string, isProcessWhiteList: boolean = let moduleType: string = item2 || item5; let systemKey: string = item3 || item6; let systemValue: string = item1 || item4; - if (!isProcessWhiteList && validateWhiteListModule(moduleType, systemKey)) { - return item; - } else if (isProcessWhiteList) { - systemValue = item2; - moduleType = item4; - systemKey = item5; - } moduleCollection.add(`${moduleType}.${systemKey}`); if (NATIVE_MODULE.has(`${moduleType}.${systemKey}`)) { item = `var ${systemValue} = globalThis.requireNativeModule('${moduleType}.${systemKey}')`; From 908bdc84ac2acaf3c104ea259e7259b70ed17671 Mon Sep 17 00:00:00 2001 From: yangbo <1442420648@qq.com> Date: Wed, 19 Jan 2022 09:23:03 +0800 Subject: [PATCH 05/44] yangbo198@huawei.com Signed-off-by: yangbo <1442420648@qq.com> Change-Id: I430100c07adfa7ef0609839ad12dfb99b8867b9d --- compiler/webpack.config.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/webpack.config.js b/compiler/webpack.config.js index 4050b6c..c7f148a 100644 --- a/compiler/webpack.config.js +++ b/compiler/webpack.config.js @@ -152,6 +152,12 @@ function setProjectConfig(envArgs) { if (envArgs.aceManifestPath) { projectConfig.manifestFilePath = envArgs.aceManifestPath; } + if (envArgs.aceProfilePath) { + projectConfig.aceProfilePath = envArgs.aceProfilePath; + } + if (envArgs.aceModuleJsonPath) { + projectConfig.aceModuleJsonPath = envArgs.aceModuleJsonPath; + } } function setReleaseConfig(config) { From f04eb60d9674a61dd61e54dfb7d185fea1fe5444 Mon Sep 17 00:00:00 2001 From: liujinwei Date: Wed, 19 Jan 2022 14:49:44 +0800 Subject: [PATCH 06/44] add ContextMenu Signed-off-by: liujinwei Change-Id: If04050adf44e7be5bc1ce3e0466032954cd7b19d --- compiler/src/component_map.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/component_map.ts b/compiler/src/component_map.ts index 5d8bd85..550a088 100644 --- a/compiler/src/component_map.ts +++ b/compiler/src/component_map.ts @@ -84,7 +84,7 @@ export const JS_BIND_COMPONENTS: Set = new Set([ 'TabsController', 'CalendarController', 'AbilityController', 'VideoController', 'WebController', 'XComponentController', 'CanvasRenderingContext2D', 'CanvasGradient', 'ImageBitmap', 'ImageData', 'Path2D', 'RenderingContextSettings', 'OffscreenCanvasRenderingContext2D', 'DatePickerDialog', - 'TextPickerDialog', 'AlertDialog', 'ActionSheet', 'PatternLockController' + 'TextPickerDialog', 'AlertDialog', 'ContextMenu', 'ActionSheet', 'PatternLockController' ]); export const NEEDPOP_COMPONENT: Set = new Set(['Blank', 'Search']); From 4e0b2c4140a7362327790db1164d7bb4433fb0eb Mon Sep 17 00:00:00 2001 From: lizhouze Date: Wed, 19 Jan 2022 17:20:57 +0800 Subject: [PATCH 07/44] lizhouze@huawei.com Signed-off-by: lizhouze --- compiler/src/pre_process.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/pre_process.ts b/compiler/src/pre_process.ts index 8e02c3f..53ba547 100644 --- a/compiler/src/pre_process.ts +++ b/compiler/src/pre_process.ts @@ -52,7 +52,7 @@ function preProcess(source: string): string { function parseVisual(resourcePath: string, content: string, log: LogInfo[]): string { if (componentCollection.entryComponent && projectConfig.aceSuperVisualPath) { const sourceFile: ts.SourceFile = ts.createSourceFile(resourcePath, content, - ts.ScriptTarget.Latest, true, ts.ScrpitKint.TS); + ts.ScriptTarget.Latest, true, ts.ScriptKind.TS); if (sourceFile.statments) { sourceFile.statments.forEach(statment => { content = parseStatment(statment, content, log, resourcePath); From 6d8a33a5c761587f1eeb17d13797752901cd344d Mon Sep 17 00:00:00 2001 From: lihong Date: Wed, 19 Jan 2022 17:35:05 +0800 Subject: [PATCH 08/44] lihong67@huawei.com fix @Extend. Signed-off-by: lihong Change-Id: Ibb0813d4746b1a7875c4af63bcb2a7be6ebaceca --- compiler/src/compile_info.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/compile_info.ts b/compiler/src/compile_info.ts index bf509f0..90c4685 100644 --- a/compiler/src/compile_info.ts +++ b/compiler/src/compile_info.ts @@ -257,7 +257,7 @@ export class ResultStates { const componentNameReg: RegExp = /'typeof\s*(\$?[_a-zA-Z0-9]+)' is not callable/; const stateInfoReg: RegExp = /Property\s*'(\$[_a-zA-Z0-9]+)' does not exist on type/; const extendInfoReg: RegExp = - /Property\s*'([_a-zA-Z0-9]+)' does not exist on type\s*'([_a-zA-Z0-9]+)(Attribute|Interface)?'\./; + /Property\s*'([_a-zA-Z0-9]+)' does not exist on type\s*'([_a-zA-Z0-9]+)(Attribute|Interface)'\./; if (this.matchMessage(message, props.concat([...STYLES_ATTRIBUTE]), propInfoReg) || this.matchMessage(message, [...componentCollection.customComponents], componentNameReg) || this.matchMessage(message, props, stateInfoReg) || From fe5bfc713adc20d00617b46f5ef15e15e906a65f Mon Sep 17 00:00:00 2001 From: houhaoyu Date: Wed, 19 Jan 2022 17:55:44 +0800 Subject: [PATCH 09/44] fixed 6116426 from https://gitee.com/houhaoyu/developtools_ace-ets2bundle/pulls/189 houhaoyu@huawei.com Signed-off-by: houhaoyu Change-Id: I17e140c358493014c9ea14f22f173d3348e3c111 --- compiler/src/process_component_build.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 29c04bc..abfed7b 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -491,7 +491,7 @@ interface AnimationInfo { export function bindComponentAttr(node: ts.ExpressionStatement, identifierNode: ts.Identifier, newStatements: ts.Statement[], log: LogInfo[], reverse: boolean = true, - isStylesAttr: boolean = false): void { + isStylesAttr: boolean = false, isGlobalStyles: boolean = false): void { let temp: any = node.expression; const statements: ts.Statement[] = []; const lastStatement: AnimationInfo = { statement: null, kind: false }; @@ -499,13 +499,13 @@ export function bindComponentAttr(node: ts.ExpressionStatement, identifierNode: if (ts.isPropertyAccessExpression(temp.expression) && temp.expression.name && ts.isIdentifier(temp.expression.name)) { addComponentAttr(temp, temp.expression.name, lastStatement, statements, identifierNode, log, - isStylesAttr); + isStylesAttr, isGlobalStyles); temp = temp.expression.expression; } else if (ts.isIdentifier(temp.expression)) { if (!INNER_COMPONENT_NAMES.has(temp.expression.getText()) && !GESTURE_TYPE_NAMES.has(temp.expression.getText())) { addComponentAttr(temp, temp.expression, lastStatement, statements, identifierNode, log, - isStylesAttr); + isStylesAttr, isGlobalStyles); } break; } @@ -558,7 +558,7 @@ function updateArgumentFor$$(argument: any): ts.Expression { function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any, statements: ts.Statement[], identifierNode: ts.Identifier, log: LogInfo[], - isStylesAttr: boolean): void { + isStylesAttr: boolean, isGlobalStyles: boolean): void { const propName: string = node.getText(); if (propName === ATTRIBUTE_ANIMATION) { if (!lastStatement.statement) { @@ -595,8 +595,13 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any, } else if (GLOBAL_STYLE_FUNCTION.has(propName) || INNER_STYLE_FUNCTION.has(propName)) { const styleBlock: ts.Block = GLOBAL_STYLE_FUNCTION.get(propName) || INNER_STYLE_FUNCTION.get(propName); - bindComponentAttr(styleBlock.statements[0] as ts.ExpressionStatement, identifierNode, - statements, log, false, true); + if (GLOBAL_STYLE_FUNCTION.has(propName)) { + bindComponentAttr(styleBlock.statements[0] as ts.ExpressionStatement, identifierNode, + statements, log, false, true, true); + } else { + bindComponentAttr(styleBlock.statements[0] as ts.ExpressionStatement, identifierNode, + statements, log, false, true, false); + } lastStatement.kind = true; } else if (propName === BIND_POPUP && temp.arguments.length === 2 && temp.arguments[0].getText().match(/^\$\$(.|\n)+/)) { @@ -612,8 +617,10 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any, if (!COMMON_ATTRS.has(propName)) { validateStateStyleSyntax(temp, log); } - for (let i=0; i Date: Thu, 20 Jan 2022 11:26:11 +0800 Subject: [PATCH 10/44] lizhouze@huawei.com Signed-off-by: lizhouze --- compiler/src/pre_process.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/src/pre_process.ts b/compiler/src/pre_process.ts index 53ba547..318ef8e 100644 --- a/compiler/src/pre_process.ts +++ b/compiler/src/pre_process.ts @@ -53,23 +53,23 @@ function parseVisual(resourcePath: string, content: string, log: LogInfo[]): str if (componentCollection.entryComponent && projectConfig.aceSuperVisualPath) { const sourceFile: ts.SourceFile = ts.createSourceFile(resourcePath, content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS); - if (sourceFile.statments) { - sourceFile.statments.forEach(statment => { - content = parseStatment(statment, content, log, resourcePath); + if (sourceFile.statements) { + sourceFile.statements.forEach(statement => { + content = parseStatement(statement, content, log, resourcePath); }); } } return content; } -function parseStatment(statement: ts.Statement, content: string, log: LogInfo[], +function parseStatement(statement: ts.Statement, content: string, log: LogInfo[], resourcePath: string): string { if (statement.kind === ts.SyntaxKind.ClassDeclaration && statement.name && statement.name.getText() === componentCollection.entryComponent) { const visualPath: string = findVisualFile(resourcePath); if (visualPath && fs.existsSync(visualPath) && statement.members) { statement.members.forEach(member => { - if (member.kind && member === ts.SyntaxKind.MethodDeclaration) { + if (member.kind && member.kind === ts.SyntaxKind.MethodDeclaration) { content = parseMember(member, content, log, visualPath) } }); From 9cd12f20cbd852d1ad95d6ef79fa6bf7a38fe44b Mon Sep 17 00:00:00 2001 From: puyajun Date: Thu, 20 Jan 2022 14:16:49 +0800 Subject: [PATCH 11/44] puyajun@huawei.com fix builder bug and builderParam Signed-off-by: puyajun Change-Id: I38b3829020cb9d8b26e736f038fda59e3f31e513 --- compiler/src/process_component_build.ts | 56 ++++++++++------ compiler/src/process_component_class.ts | 24 +++++-- compiler/src/process_component_member.ts | 4 +- compiler/test/ut/builder/builderLambda.ts | 27 ++++---- compiler/test/ut/builder/builderParam.ts | 78 +++++++---------------- 5 files changed, 91 insertions(+), 98 deletions(-) diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index abfed7b..505000c 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -169,7 +169,7 @@ export function processComponentChild(node: ts.Block | ts.SourceFile, newStateme break; case ComponentType.customComponent: if (index + 1 < array.length && ts.isBlock(array[index + 1])) { - item = processBlockChange(item, + item = processExpressionStatementChange(item, array[index + 1] as ts.Block, log) } processCustomComponent(item, newStatements, log); @@ -195,29 +195,43 @@ export function processComponentChild(node: ts.Block | ts.SourceFile, newStateme } } -function processBlockChange(node: ts.ExpressionStatement, nextNode: ts.Block, - log: LogInfo[]): ts.block { - // @ts-ignore - const newBlock: ts.Block = processComponentBlock(nextNode, false, log); - const arrowNode: ts.ArrowFunction = ts.factory.createArrowFunction(undefined, undefined, - [], undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), newBlock); - const newPropertyAssignment:ts.PropertyAssignment = ts.factory.createPropertyAssignment( - ts.factory.createIdentifier(CHILD), arrowNode); - // @ts-ignore - let argumentsArray: ts.ObjectLiteralExpression[] = node.express.arguments; - if (arguments && arguments.length < 1) { - argumentsArray = [ts.factory.createObjectLiteralExpression([newPropertyAssignment], true)] - } else { +function processExpressionStatementChange(node: ts.ExpressionStatement, nextNode: ts.Block, + log: LogInfo[]): ts.ExpressionStatement { // @ts-ignore - argumentsArray = [ts.factory.createObjectLiteralExpression( + let name = node.expression.expression.escapedText.toString() + let childParam: string; + if (builderParamObjectCollection.get(name) && builderParamObjectCollection.get(name).size > 0) { + builderParamObjectCollection.get(name).forEach((item) => { + childParam = item + }) + // @ts-ignore + const newBlock: ts.Block = processComponentBlock(nextNode, false, log); + const arrowNode: ts.ArrowFunction = ts.factory.createArrowFunction(undefined, undefined, + [], undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), newBlock); + const newPropertyAssignment:ts.PropertyAssignment = ts.factory.createPropertyAssignment( + ts.factory.createIdentifier(childParam), arrowNode); + // @ts-ignore + let argumentsArray: ts.ObjectLiteralExpression[] = node.expression.arguments; + if (argumentsArray && argumentsArray.length < 1) { + argumentsArray = [ts.factory.createObjectLiteralExpression([newPropertyAssignment], true)] + } else { // @ts-ignore - node.express.arguments[0].properties.concat([newPropertyAssignment]), true)] - } - // @ts-ignore - node = ts.factory.updateExpressionStatement(node, ts.factory.updateCallExpression(node.expression, + argumentsArray = [ts.factory.createObjectLiteralExpression( + // @ts-ignore + node.expression.arguments[0].properties.concat([newPropertyAssignment]), true)] + } // @ts-ignore - node.expression.expression, node.expression.expression,typeArguments, argumentsArray)) - return node; + node = ts.factory.updateExpressionStatement(node, ts.factory.updateCallExpression(node.expression, + // @ts-ignore + node.expression.expression, node.expression.expression.typeArguments, argumentsArray)) + return node; + } else { + log.push({ + type: LogType.ERROR, + message: `The attribute in '${name}' should be decorated with '@BuilderParam' to receive .`, + pos: node.getStart() + }); + } } function processInnerComponent(node: ts.ExpressionStatement, index: number, arr: ts.Statement[], diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index 0e2f600..afec119 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -210,11 +210,9 @@ function processBuildMember(node: ts.MethodDeclaration, context: ts.Transformati }); } const buildNode: ts.MethodDeclaration = processComponentBuild(node, log); - return ts.visitNode(buildNode, visitBuild); + const firstParseBuildNode = ts.visitNode(buildNode, visitBuild); + return ts.visitNode(firstParseBuildNode, visitBuildSecond); function visitBuild(node: ts.Node): ts.Node { - if (isCustomComponentNode(node)) { - return node; - } if (isGeometryView(node)) { node = processGeometryView(node as ts.ExpressionStatement, log); } @@ -229,11 +227,17 @@ function processBuildMember(node: ts.MethodDeclaration, context: ts.Transformati ts.factory.createIdentifier(FOREACH_OBSERVED_OBJECT), ts.factory.createIdentifier(FOREACH_GET_RAW_OBJECT)), undefined, [node]); } + return ts.visitEachChild(node, visitBuild, context); + } + function visitBuildSecond(node: ts.Node): ts.Node { + if (isCustomComponentNode(node) || isCustomBuilderNode(node)) { + return node; + } if ((ts.isIdentifier(node) || ts.isPropertyAccessExpression(node)) && validateBuilderFunctionNode(node)) { return getParsedBuilderAttrArgument(node); } - return ts.visitEachChild(node, visitBuild, context); + return ts.visitEachChild(node, visitBuildSecond, context); } } @@ -298,11 +302,19 @@ function isCustomComponentNode(node:ts.NewExpression | ts.ExpressionStatement): node.expression.expression.expression.escapedText.toString().startsWith( CUSTOM_COMPONENT_EARLIER_CREATE_CHILD))) { return true; - }else { + } else { return false; } } +function isCustomBuilderNode(node: ts.ExpressionStatement): boolean { + return ts.isExpressionStatement(node) && node.expression && + // @ts-ignore + node.expression.expression && node.expression.expression.escapedText && + // @ts-ignore + CUSTOM_BUILDER_METHOD.has(node.expression.expression.escapedText.toString()); +} + function isGeometryView(node: ts.Node): boolean { if (ts.isExpressionStatement(node) && ts.isCallExpression(node.expression)) { const call: ts.CallExpression = node.expression; diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index 1dc9b50..dac38f4 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -419,7 +419,7 @@ function createUpdateParams(name: ts.Identifier, decorator: string): ts.Statemen builderParamObjectCollection.get(componentCollection.currentClassName) .add(name.escapedText.toString()) } - updateParamsNode = createUpdateParamsWithoutIf(name, 1); + updateParamsNode = createUpdateParamsWithoutIf(name, true); break; } return updateParamsNode; @@ -435,7 +435,7 @@ function createUpdateParamsWithIf(name: ts.Identifier): ts.IfStatement { createUpdateParamsWithoutIf(name)], true), undefined); } -function createUpdateParamsWithoutIf(name: ts.Identifier, isAdd: number = 0): ts.ExpressionStatement { +function createUpdateParamsWithoutIf(name: ts.Identifier, isAdd: boolean = false): ts.ExpressionStatement { let textName: string; if (isAdd) { textName = `__${name.getText()}`; diff --git a/compiler/test/ut/builder/builderLambda.ts b/compiler/test/ut/builder/builderLambda.ts index c197350..0bfa5ad 100644 --- a/compiler/test/ut/builder/builderLambda.ts +++ b/compiler/test/ut/builder/builderLambda.ts @@ -57,8 +57,8 @@ exports.expectResult = `class CustomContainer extends View { constructor(compilerAssignedUniqueChildId, parent, params) { super(compilerAssignedUniqueChildId, parent); - this.header = "" - this.footer = "" + this.header = ""; + this.footer = ""; this.updateWithValueParams(params); } updateWithValueParams(params) { @@ -74,17 +74,16 @@ exports.expectResult = this.__child.aboutToBeDeleted(); SubscriberManager.Get().delete(this.id()); } - get child(){ + get child() { return this.__child.get(); } set child(newValue) { - this.__child.set(newValue) + this.__child.set(newValue); } render() { Column.create(); Text.create(this.header); Text.pop(); - this.child(); Text.create(this.footer); Text.pop(); Column.pop(); @@ -94,11 +93,11 @@ function specificParam(label1, label2) { Column.create(); Text.create(label1); Text.pop(); - Text.create(label1); + Text.create(label2); Text.pop(); Column.pop(); } -class CustomContainerUser { +class CustomContainerUser extends View { constructor(compilerAssignedUniqueChildId, parent, params) { super(compilerAssignedUniqueChildId, parent); this.updateWithValueParams(params); @@ -117,12 +116,12 @@ class CustomContainerUser { child: () => { Column.create(); Text.create("content1"); - Text.width(50) + Text.width(50); Text.pop(); Text.create("content2"); Text.pop(); Column.pop(); - specificParam("content3", "content4) + specificParam("content3", "content4"); } })); } @@ -132,18 +131,18 @@ class CustomContainerUser { child: () => { Column.create(); Text.create("content1"); - Text.width(50) + Text.width(50); Text.pop(); Text.create("content2"); Text.pop(); Column.pop(); - specificParam("content3", "content4) - }} + specificParam("content3", "content4"); + } }); View.create(earlierCreatedChild_2); } - Column.pop(); + Column.pop(); } } -loadDocument(new MyComponent("1", undefined, {})); +loadDocument(new CustomContainerUser("1", undefined, {})); ` diff --git a/compiler/test/ut/builder/builderParam.ts b/compiler/test/ut/builder/builderParam.ts index 49a3916..bf41f3d 100644 --- a/compiler/test/ut/builder/builderParam.ts +++ b/compiler/test/ut/builder/builderParam.ts @@ -18,31 +18,24 @@ exports.source = ` struct CustomContainer { header: string = ""; footer: string = ""; - @BuilderParam child: () => any; + @BuilderParam child1: () => any; build() { Column() { + this.child1() Text(this.header) - this.child() Text(this.footer) } } } -@Builder function specificParam(label1: string, label2: string) { - Column() { - Text(label1) - Text(label2) - } -} - @Entry @Component struct CustomContainerUser { @Builder specificChild() { Column() { Text("My content1") - Text("My content1") + Text("My content2") } } @@ -51,13 +44,9 @@ struct CustomContainerUser { CustomContainer({ header: "Header", footer: "Footer", - child: this.specificChild - }) - CustomContainer({ - header: "Header", - footer: "Footer", - child: specificParam("content3", "content4") - }) + }){ + this.specificChild() + } } } } @@ -66,8 +55,8 @@ exports.expectResult = `class CustomContainer extends View { constructor(compilerAssignedUniqueChildId, parent, params) { super(compilerAssignedUniqueChildId, parent); - this.header = "" - this.footer = "" + this.header = ""; + this.footer = ""; this.updateWithValueParams(params); } updateWithValueParams(params) { @@ -77,37 +66,28 @@ exports.expectResult = if (params.footer !== undefined) { this.footer = params.footer; } - this.__child = params.child; + this.__child1 = params.child1; } aboutToBeDeleted() { - this.__child.aboutToBeDeleted(); + this.__child1.aboutToBeDeleted(); SubscriberManager.Get().delete(this.id()); } - get child(){ - return this.__child.get(); + get child1() { + return this.__child1.get(); } - set child(newValue) { - this.__child.set(newValue) + set child1(newValue) { + this.__child1.set(newValue); } render() { Column.create(); Text.create(this.header); Text.pop(); - this.child(); Text.create(this.footer); Text.pop(); Column.pop(); } } -function specificParam(label1, label2) { - Column.create(); - Text.create(label1); - Text.pop(); - Text.create(label1); - Text.pop(); - Column.pop(); -} -class CustomContainerUser { +class CustomContainerUser extends View { constructor(compilerAssignedUniqueChildId, parent, params) { super(compilerAssignedUniqueChildId, parent); this.updateWithValueParams(params); @@ -132,35 +112,23 @@ class CustomContainerUser { View.create(new CustomContainer("2", this, { header: "Header", footer: "Footer", - child: this.specificChild + child1: () => { + this.specificChild(); + } })); } else { earlierCreatedChild_2.updateWithValueParams({ header: "Header", footer: "Footer", - child: this.specificChild + child1: () => { + this.specificChild(); + } }); View.create(earlierCreatedChild_2); } - let earlierCreatedChild_3 = this.findChildById("3"); - if (earlierCreatedChild_3 == undefined) { - View.create(new CustomContainer("3", this, { - header: "Header", - footer: "Footer", - child: specificParam("content3", "content4") - })); - } - else { - earlierCreatedChild_3.updateWithValueParams({ - header: "Header", - footer: "Footer", - child: specificParam("content3", "content4") - }); - View.create(earlierCreatedChild_3); - } - Column.pop(); + Column.pop(); } } -loadDocument(new MyComponent("1", undefined, {})); +loadDocument(new CustomContainerUser("1", undefined, {})); ` From 7d17deac8c5db4832a6c932b4e0043e5ec595578 Mon Sep 17 00:00:00 2001 From: puyajun Date: Thu, 20 Jan 2022 14:46:56 +0800 Subject: [PATCH 12/44] puyajun@huawei.com fix bug builder and builderParam Signed-off-by: puyajun Change-Id: I55e55494d5e7c628d56cb1a17bce8c60682671ef --- compiler/src/process_component_build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 505000c..59d7756 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -228,7 +228,7 @@ function processExpressionStatementChange(node: ts.ExpressionStatement, nextNode } else { log.push({ type: LogType.ERROR, - message: `The attribute in '${name}' should be decorated with '@BuilderParam' to receive .`, + message: `'${name}' should have a property decorated with @ builderparam .`, pos: node.getStart() }); } From b766bf7e51149bc085b1b23f1b9390c2b47805d8 Mon Sep 17 00:00:00 2001 From: puyajun Date: Thu, 20 Jan 2022 18:01:46 +0800 Subject: [PATCH 13/44] fixed 8cd6dd9 from https://gitee.com/puyajun/developtools_ace-ets2bundle/pulls/214 puyajun@huawei.com MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改builderbug Signed-off-by: puyajun Change-Id: Ibd36564595e5f7a4ccf183b005b2a6ad3387c599 --- compiler/src/process_component_build.ts | 3 ++- compiler/src/process_component_member.ts | 16 +++++-------- compiler/test/ut/builder/builderLambda.ts | 28 +++++++++-------------- compiler/test/ut/builder/builderParam.ts | 27 +++++++--------------- 4 files changed, 27 insertions(+), 47 deletions(-) diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 59d7756..78d9fce 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -177,7 +177,8 @@ export function processComponentChild(node: ts.Block | ts.SourceFile, newStateme case ComponentType.forEachComponent: processForEachComponent(item, newStatements, log); break; - case ComponentType.customBuilderMethod || ComponentType.builderParamMethod: + case ComponentType.customBuilderMethod: + case ComponentType.builderParamMethod: newStatements.push(item); break; } diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index dac38f4..0052cc9 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -104,7 +104,7 @@ export const setUpdateParamsDecorators: Set = ]); export const immutableDecorators: Set = - new Set([COMPONENT_STORAGE_PROP_DECORATOR, COMPONENT_OBJECT_LINK_DECORATOR]); + new Set([COMPONENT_STORAGE_PROP_DECORATOR, COMPONENT_OBJECT_LINK_DECORATOR, COMPONENT_BUILDERPARAM_DECORATOR]); export const simpleTypes: Set = new Set([ts.SyntaxKind.StringKeyword, ts.SyntaxKind.NumberKeyword, ts.SyntaxKind.BooleanKeyword, ts.SyntaxKind.EnumDeclaration]); @@ -299,14 +299,16 @@ function processStateDecorators(node: ts.PropertyDeclaration, decorator: string, } addAddProvidedVar(node, name, decorator, updateState); updateResult.setCtor(updateConstructor(ctorNode, [], [...updateState], false)); - updateResult.setVariableGet(createGetAccessor(name, CREATE_GET_METHOD)); + if (decorator !== COMPONENT_BUILDERPARAM_DECORATOR) { + updateResult.setVariableGet(createGetAccessor(name, CREATE_GET_METHOD)); + updateResult.setDeleteParams(true); + } if (!immutableDecorators.has(decorator)) { updateResult.setVariableSet(createSetAccessor(name, CREATE_SET_METHOD)); } if (setUpdateParamsDecorators.has(decorator)) { updateResult.setUpdateParams(createUpdateParams(name, decorator)); } - updateResult.setDeleteParams(true); } function processWatch(node: ts.PropertyDeclaration, decorator: ts.Decorator, @@ -436,14 +438,8 @@ function createUpdateParamsWithIf(name: ts.Identifier): ts.IfStatement { } function createUpdateParamsWithoutIf(name: ts.Identifier, isAdd: boolean = false): ts.ExpressionStatement { - let textName: string; - if (isAdd) { - textName = `__${name.getText()}`; - } else { - textName = name.getText(); - } return ts.factory.createExpressionStatement(ts.factory.createBinaryExpression( - createPropertyAccessExpressionWithThis(textName), + createPropertyAccessExpressionWithThis(name.getText()), ts.factory.createToken(ts.SyntaxKind.EqualsToken), createPropertyAccessExpressionWithParams(name.getText()))); } diff --git a/compiler/test/ut/builder/builderLambda.ts b/compiler/test/ut/builder/builderLambda.ts index 0bfa5ad..56d695a 100644 --- a/compiler/test/ut/builder/builderLambda.ts +++ b/compiler/test/ut/builder/builderLambda.ts @@ -29,10 +29,10 @@ struct CustomContainer { } } -@Builder function specificParam(label1: string, label2: string) { +@Builder function specificParam() { Column() { - Text(label1) - Text(label2) + Text("label1") + Text("label2") } } @@ -47,7 +47,7 @@ struct CustomContainerUser { .width(50) Text("content2") } - specificParam("content3", "content4") + specificParam() } } } @@ -68,32 +68,26 @@ exports.expectResult = if (params.footer !== undefined) { this.footer = params.footer; } - this.__child = params.child; + this.child = params.child; } aboutToBeDeleted() { - this.__child.aboutToBeDeleted(); SubscriberManager.Get().delete(this.id()); } - get child() { - return this.__child.get(); - } - set child(newValue) { - this.__child.set(newValue); - } render() { Column.create(); Text.create(this.header); Text.pop(); + this.child(); Text.create(this.footer); Text.pop(); Column.pop(); } } -function specificParam(label1, label2) { +function specificParam() { Column.create(); - Text.create(label1); + Text.create("label1"); Text.pop(); - Text.create(label2); + Text.create("label2"); Text.pop(); Column.pop(); } @@ -121,7 +115,7 @@ class CustomContainerUser extends View { Text.create("content2"); Text.pop(); Column.pop(); - specificParam("content3", "content4"); + specificParam(); } })); } @@ -136,7 +130,7 @@ class CustomContainerUser extends View { Text.create("content2"); Text.pop(); Column.pop(); - specificParam("content3", "content4"); + specificParam(); } }); View.create(earlierCreatedChild_2); diff --git a/compiler/test/ut/builder/builderParam.ts b/compiler/test/ut/builder/builderParam.ts index bf41f3d..b0e117a 100644 --- a/compiler/test/ut/builder/builderParam.ts +++ b/compiler/test/ut/builder/builderParam.ts @@ -18,11 +18,11 @@ exports.source = ` struct CustomContainer { header: string = ""; footer: string = ""; - @BuilderParam child1: () => any; + @BuilderParam child: () => any; build() { Column() { - this.child1() + this.child() Text(this.header) Text(this.footer) } @@ -44,9 +44,8 @@ struct CustomContainerUser { CustomContainer({ header: "Header", footer: "Footer", - }){ - this.specificChild() - } + child: this.specificChild + }) } } } @@ -66,20 +65,14 @@ exports.expectResult = if (params.footer !== undefined) { this.footer = params.footer; } - this.__child1 = params.child1; + this.child = params.child; } aboutToBeDeleted() { - this.__child1.aboutToBeDeleted(); SubscriberManager.Get().delete(this.id()); } - get child1() { - return this.__child1.get(); - } - set child1(newValue) { - this.__child1.set(newValue); - } render() { Column.create(); + this.child(); Text.create(this.header); Text.pop(); Text.create(this.footer); @@ -112,18 +105,14 @@ class CustomContainerUser extends View { View.create(new CustomContainer("2", this, { header: "Header", footer: "Footer", - child1: () => { - this.specificChild(); - } + child: this.specificChild })); } else { earlierCreatedChild_2.updateWithValueParams({ header: "Header", footer: "Footer", - child1: () => { - this.specificChild(); - } + child: this.specificChild }); View.create(earlierCreatedChild_2); } From 333a3c1c20ee9c958b995e2f6979fe7c37e964d5 Mon Sep 17 00:00:00 2001 From: wzztoone Date: Tue, 25 Jan 2022 15:54:22 +0800 Subject: [PATCH 14/44] add multiSelect event Signed-off-by: wzztoone Change-Id: I82a3818fbb11cad5d139d79ab01887ebe185fb5c --- compiler/components/grid.json | 2 +- compiler/components/gridItem.json | 2 +- compiler/components/list.json | 3 ++- compiler/components/listItem.json | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/compiler/components/grid.json b/compiler/components/grid.json index 1a9682a..260ee96 100644 --- a/compiler/components/grid.json +++ b/compiler/components/grid.json @@ -5,6 +5,6 @@ "columnsTemplate", "rowsTemplate", "columnsGap", "rowsGap", "scrollBar", "scrollBarWidth", "scrollBarColor", "editMode", "maxCount", "minCount", "cellLength", "onItemDragStart", "onItemDragMove", "onItemDragEnter", "onItemDragMove", "onItemDrop", "layoutDirection", "direction", - "supportAnimation", "onItemDragLeave" + "supportAnimation", "onItemDragLeave", "multiSelectable" ] } \ No newline at end of file diff --git a/compiler/components/gridItem.json b/compiler/components/gridItem.json index be369c1..e245093 100644 --- a/compiler/components/gridItem.json +++ b/compiler/components/gridItem.json @@ -2,5 +2,5 @@ "name": "GridItem", "parents": ["Grid"], "single": true, - "attrs": ["rowStart", "rowEnd", "columnStart", "columnEnd", "forceRebuild"] + "attrs": ["rowStart", "rowEnd", "columnStart", "columnEnd", "forceRebuild", "selectable", "onSelect"] } \ No newline at end of file diff --git a/compiler/components/list.json b/compiler/components/list.json index acf726d..3655d8f 100644 --- a/compiler/components/list.json +++ b/compiler/components/list.json @@ -4,6 +4,7 @@ "attrs": [ "listDirection", "scrollBar", "edgeEffect", "divider", "editMode", "cachedCount", "chainAnimation", "onScroll", "onReachStart", "onReachEnd", "onScrollStop", "onItemDelete", - "onItemMove", "onItemDragStart", "onItemDragEnter", "onItemDragMove", "onItemDragLeave", "onItemDrop" + "onItemMove", "onItemDragStart", "onItemDragEnter", "onItemDragMove", "onItemDragLeave", "onItemDrop", + "multiSelectable" ] } \ No newline at end of file diff --git a/compiler/components/listItem.json b/compiler/components/listItem.json index 467c66e..7c704e6 100644 --- a/compiler/components/listItem.json +++ b/compiler/components/listItem.json @@ -2,5 +2,5 @@ "name": "ListItem", "parents": ["List"], "single": true, - "attrs": ["sticky", "editable"] + "attrs": ["sticky", "editable", "selectable", "onSelect"] } \ No newline at end of file From ebbb76f1bad771f03252d4664effa2c98cd1a979 Mon Sep 17 00:00:00 2001 From: yangbo <1442420648@qq.com> Date: Tue, 25 Jan 2022 16:06:57 +0800 Subject: [PATCH 15/44] yangbo198@huawei.com Signed-off-by: yangbo <1442420648@qq.com> Change-Id: I4656983fc5d51876c20e935400eb1c1a46d1aed1 --- compiler/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/main.js b/compiler/main.js index be5e7fd..570b6c0 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -115,7 +115,7 @@ function buildManifest(manifest, aceConfigPath) { function getPages(configJson) { const pages = [] const modulePagePath = path.resolve(projectConfig.aceProfilePath, - `${configJson.module.pages.replace(/\@profile\:/, '')}.json`); + `${configJson.module.pages.replace(/\$profile\:/, '')}.json`); if (fs.existsSync(modulePagePath)) { const pagesConfig = JSON.parse(fs.readFileSync(modulePagePath, 'utf-8')); if (pagesConfig && pagesConfig.src) { From 0d0a686033431058d4df67229719cfe1b3a639c3 Mon Sep 17 00:00:00 2001 From: yaoyuchi Date: Tue, 25 Jan 2022 16:16:55 +0800 Subject: [PATCH 16/44] add swiper animation curve attribute Signed-off-by: yaoyuchi --- compiler/components/swiper.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/components/swiper.json b/compiler/components/swiper.json index 6164d4b..e85626e 100644 --- a/compiler/components/swiper.json +++ b/compiler/components/swiper.json @@ -2,6 +2,6 @@ "name": "Swiper", "attrs": [ "index", "autoPlay", "interval", "indicator", "loop", "duration", "vertical", "itemSpace", - "cachedCount", "displayMode", "displayCount", "effectMode", "disableSwipe", "onChange" + "cachedCount", "displayMode", "displayCount", "effectMode", "disableSwipe", "curve", "onChange" ] } \ No newline at end of file From a290d45ea14d81de97f82319acddbcc8936881ea Mon Sep 17 00:00:00 2001 From: yaoyuchi Date: Wed, 26 Jan 2022 15:56:30 +0800 Subject: [PATCH 17/44] sidebar code commit Signed-off-by: yaoyuchi --- compiler/components/sideBar_container.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/components/sideBar_container.json b/compiler/components/sideBar_container.json index ec9f989..28e4e0f 100644 --- a/compiler/components/sideBar_container.json +++ b/compiler/components/sideBar_container.json @@ -1,6 +1,6 @@ { "name": "SideBarContainer", "attrs": [ - "showControlButton", "onChange" + "showControlButton", "onChange", "sideBarWidth", "maxSideBarWidth", "maxSideBarWidth" ] } \ No newline at end of file From ce2c86de39d7e07bb3790e177ffd0d8b83d58f4e Mon Sep 17 00:00:00 2001 From: puyajun Date: Sat, 22 Jan 2022 15:49:49 +0800 Subject: [PATCH 18/44] puyajun@huawei.com builder transmission parameter rule Signed-off-by: puyajun Change-Id: Ib8e3abcc0b5d8f40644230d4f49b5ee9f66ac97c --- compiler/src/compile_info.ts | 12 +-- compiler/src/pre_define.ts | 1 - compiler/src/pre_process.ts | 6 +- compiler/src/process_component_build.ts | 95 ++++++++++--------- compiler/src/process_component_class.ts | 20 ++-- compiler/src/process_component_constructor.ts | 2 +- compiler/src/process_component_member.ts | 6 +- compiler/src/process_custom_component.ts | 63 +++++++++++- compiler/src/process_ui_syntax.ts | 8 +- compiler/src/result_process.ts | 1 - compiler/src/utils.ts | 6 +- compiler/src/validate_ui_syntax.ts | 34 +++---- 12 files changed, 156 insertions(+), 98 deletions(-) diff --git a/compiler/src/compile_info.ts b/compiler/src/compile_info.ts index 90c4685..c279652 100644 --- a/compiler/src/compile_info.ts +++ b/compiler/src/compile_info.ts @@ -92,7 +92,7 @@ export class ResultStates { } ); - compilation.hooks.buildModule.tap("findModule", (module) => { + compilation.hooks.buildModule.tap('findModule', (module) => { if (/node_modules/.test(module.context)) { const modulePath: string = path.resolve(module.resourceResolveData.descriptionFileRoot, MODULE_SHARE_PATH); @@ -113,7 +113,7 @@ export class ResultStates { compilation.hooks.processAssets.tap( { name: 'GLOBAL_COMMON_MODULE_CACHE', - stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS, + stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS }, (assets) => { if (assets['commons.js']) { @@ -133,7 +133,7 @@ export class ResultStates { `globalThis["__common_module_cache__"][moduleId]: null;\n` + `if (commonCachedModule) { return commonCachedModule.exports; }\n` + source.replace('// Execute the module function', - `if (globalThis["__common_module_cache__"] && moduleId.indexOf("?name=") < 0 && ` + + `if (globalThis["__common_module_cache__"] && moduleId.indexOf("?name=") < 0 && ` + `Object.keys(globalThis["__common_module_cache__"]).indexOf(moduleId) >= 0) {\n` + ` globalThis["__common_module_cache__"][moduleId] = module;\n}`); }); @@ -157,12 +157,12 @@ export class ResultStates { compiler.hooks.compilation.tap('Collect Components And Modules', compilation => { compilation.hooks.additionalAssets.tapAsync('Collect Components And Modules', callback => { compilation.assets['./component_collection.txt'] = - new RawSource(Array.from(appComponentCollection).join(",")); + new RawSource(Array.from(appComponentCollection).join(',')); compilation.assets['./module_collection.txt'] = - new RawSource(moduleCollection.size === 0 ? 'NULL' : Array.from(moduleCollection).join(",")); + new RawSource(moduleCollection.size === 0 ? 'NULL' : Array.from(moduleCollection).join(',')); callback(); }); - }) + }); } } diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 33f4f21..8efee8a 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -182,7 +182,6 @@ export const GEOMETRY_VIEW: string = 'GeometryView'; export const MODULE_SHARE_PATH: string = 'src' + path.sep + 'ets' + path.sep + 'share'; export const BUILD_SHARE_PATH: string = '../share'; -export const CHILD: string = 'child'; export const THIS: string = 'this'; export const STYLES: string = 'Styles'; export const VISUAL_STATE: string = 'visualState'; diff --git a/compiler/src/pre_process.ts b/compiler/src/pre_process.ts index 318ef8e..bab5b8c 100644 --- a/compiler/src/pre_process.ts +++ b/compiler/src/pre_process.ts @@ -70,7 +70,7 @@ function parseStatement(statement: ts.Statement, content: string, log: LogInfo[] if (visualPath && fs.existsSync(visualPath) && statement.members) { statement.members.forEach(member => { if (member.kind && member.kind === ts.SyntaxKind.MethodDeclaration) { - content = parseMember(member, content, log, visualPath) + content = parseMember(member, content, log, visualPath); } }); } @@ -108,7 +108,7 @@ function findVisualFile(filePath: string): string { function getVisualContent(visualPath: string, log: LogInfo[], pos: number): string { const parseContent: any = genETS(fs.readFileSync(visualPath, 'utf-8')); - if (parseContent && parseContent.errorType && parseContent.errorType != '') { + if (parseContent && parseContent.errorType && parseContent.errorType !== '') { log.push({ type: LogType.ERROR, message: parseContent.message, @@ -118,4 +118,4 @@ function getVisualContent(visualPath: string, log: LogInfo[], pos: number): stri return parseContent ? parseContent.ets : null; } -module.exports = preProcess; \ No newline at end of file +module.exports = preProcess; diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 78d9fce..ea2b141 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -45,7 +45,6 @@ import { COMPONENT_TRANSITION_NAME, COMPONENT_DEBUGLINE_FUNCTION, ATTRIBUTE_STATESTYLES, - CHILD, THIS, VISUAL_STATE, VIEW_STACK_PROCESSOR, @@ -169,10 +168,11 @@ export function processComponentChild(node: ts.Block | ts.SourceFile, newStateme break; case ComponentType.customComponent: if (index + 1 < array.length && ts.isBlock(array[index + 1])) { - item = processExpressionStatementChange(item, - array[index + 1] as ts.Block, log) + if (processExpressionStatementChange(item, array[index + 1] as ts.Block, log)) { + item = processExpressionStatementChange(item, array[index + 1] as ts.Block, log); + } } - processCustomComponent(item, newStatements, log); + processCustomComponent(item as ts.ExpressionStatement, newStatements, log); break; case ComponentType.forEachComponent: processForEachComponent(item, newStatements, log); @@ -198,43 +198,48 @@ export function processComponentChild(node: ts.Block | ts.SourceFile, newStateme function processExpressionStatementChange(node: ts.ExpressionStatement, nextNode: ts.Block, log: LogInfo[]): ts.ExpressionStatement { - // @ts-ignore - let name = node.expression.expression.escapedText.toString() - let childParam: string; - if (builderParamObjectCollection.get(name) && builderParamObjectCollection.get(name).size > 0) { - builderParamObjectCollection.get(name).forEach((item) => { - childParam = item - }) - // @ts-ignore - const newBlock: ts.Block = processComponentBlock(nextNode, false, log); - const arrowNode: ts.ArrowFunction = ts.factory.createArrowFunction(undefined, undefined, - [], undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), newBlock); - const newPropertyAssignment:ts.PropertyAssignment = ts.factory.createPropertyAssignment( - ts.factory.createIdentifier(childParam), arrowNode); - // @ts-ignore - let argumentsArray: ts.ObjectLiteralExpression[] = node.expression.arguments; - if (argumentsArray && argumentsArray.length < 1) { - argumentsArray = [ts.factory.createObjectLiteralExpression([newPropertyAssignment], true)] - } else { - // @ts-ignore - argumentsArray = [ts.factory.createObjectLiteralExpression( - // @ts-ignore - node.expression.arguments[0].properties.concat([newPropertyAssignment]), true)] - } - // @ts-ignore - node = ts.factory.updateExpressionStatement(node, ts.factory.updateCallExpression(node.expression, - // @ts-ignore - node.expression.expression, node.expression.expression.typeArguments, argumentsArray)) - return node; + let name: string; + // @ts-ignore + if (node.expression.expression && ts.isIdentifier(node.expression.expression)) { + name = node.expression.expression.escapedText.toString(); + } + if (builderParamObjectCollection.get(name) && + builderParamObjectCollection.get(name).size === 1) { + return processBlockToExpression(node, nextNode, log, name); } else { log.push({ type: LogType.ERROR, - message: `'${name}' should have a property decorated with @ builderparam .`, + message: `In the trailing lambda case, '${name}' must have one and only one property decorated with ` + + `@BuilderParam, and its @BuilderParam expects no parameter.`, pos: node.getStart() }); } } +function processBlockToExpression(node: ts.ExpressionStatement, nextNode: ts.Block, + log: LogInfo[], name: string): ts.ExpressionStatement { + const childParam: string = [...builderParamObjectCollection.get(name)].slice(-1)[0]; + const newBlock: ts.Block = processComponentBlock(nextNode, false, log); + const arrowNode: ts.ArrowFunction = ts.factory.createArrowFunction(undefined, undefined, + [], undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), newBlock); + const newPropertyAssignment:ts.PropertyAssignment = ts.factory.createPropertyAssignment( + ts.factory.createIdentifier(childParam), arrowNode); + // @ts-ignore + let argumentsArray: ts.ObjectLiteralExpression[] = node.expression.arguments; + if (argumentsArray && !argumentsArray.length) { + argumentsArray = [ts.factory.createObjectLiteralExpression([newPropertyAssignment], true)]; + } else { + argumentsArray = [ts.factory.createObjectLiteralExpression( + // @ts-ignore + node.expression.arguments[0].properties.concat([newPropertyAssignment]), true)]; + } + node = ts.factory.updateExpressionStatement(node, ts.factory.updateCallExpression( + // @ts-ignore + node.expression, node.expression.expression, node.expression.expression.typeArguments, + argumentsArray)); + return node; +} + function processInnerComponent(node: ts.ExpressionStatement, index: number, arr: ts.Statement[], newStatements: ts.Statement[], log: LogInfo[], name: string): void { const res: CreateResult = createComponent(node, COMPONENT_CREATE_FUNCTION); @@ -533,7 +538,7 @@ export function bindComponentAttr(node: ts.ExpressionStatement, identifierNode: } } -function createArrowFunctionFor$$ ($$varExp: ts.Expression): ts.ArrowFunction { +function createArrowFunctionFor$$($$varExp: ts.Expression): ts.ArrowFunction { return ts.factory.createArrowFunction( undefined, undefined, [ts.factory.createParameterDeclaration( @@ -557,7 +562,7 @@ function createArrowFunctionFor$$ ($$varExp: ts.Expression): ts.ArrowFunction { function updateArgumentFor$$(argument: any): ts.Expression { if (ts.isElementAccessExpression(argument)) { return ts.factory.updateElementAccessExpression - (argument, updateArgumentFor$$(argument.expression), argument.argumentExpression); + (argument, updateArgumentFor$$(argument.expression), argument.argumentExpression); } else if (ts.isIdentifier(argument)) { props.push(argument.getText()); if (argument.getText() === $$_THIS) { @@ -567,7 +572,7 @@ function updateArgumentFor$$(argument: any): ts.Expression { } } else if (ts.isPropertyAccessExpression(argument)) { return ts.factory.updatePropertyAccessExpression - (argument, updateArgumentFor$$(argument.expression), argument.name); + (argument, updateArgumentFor$$(argument.expression), argument.name); } } @@ -633,7 +638,7 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any, validateStateStyleSyntax(temp, log); } if (isGlobalStyles) { - for (let i=0; i) ts.factory.createStringLiteral(key), ts.isStringLiteral(value) ? ts.factory.createPropertyAccessExpression(ts.factory.createThis(), - ts.factory.createIdentifier(value.text)) : value as ts.PropertyAccessExpression + ts.factory.createIdentifier(value.text)) : value as ts.PropertyAccessExpression ] )); watchStatements.push(watchNode); diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index 0052cc9..1651e16 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -419,9 +419,9 @@ function createUpdateParams(name: ts.Identifier, decorator: string): ts.Statemen builderParamObjectCollection.set(componentCollection.currentClassName, new Set([])); } builderParamObjectCollection.get(componentCollection.currentClassName) - .add(name.escapedText.toString()) + .add(name.escapedText.toString()); } - updateParamsNode = createUpdateParamsWithoutIf(name, true); + updateParamsNode = createUpdateParamsWithoutIf(name); break; } return updateParamsNode; @@ -437,7 +437,7 @@ function createUpdateParamsWithIf(name: ts.Identifier): ts.IfStatement { createUpdateParamsWithoutIf(name)], true), undefined); } -function createUpdateParamsWithoutIf(name: ts.Identifier, isAdd: boolean = false): ts.ExpressionStatement { +function createUpdateParamsWithoutIf(name: ts.Identifier): ts.ExpressionStatement { return ts.factory.createExpressionStatement(ts.factory.createBinaryExpression( createPropertyAccessExpressionWithThis(name.getText()), ts.factory.createToken(ts.SyntaxKind.EqualsToken), diff --git a/compiler/src/process_custom_component.ts b/compiler/src/process_custom_component.ts index 5ac3f84..484f906 100644 --- a/compiler/src/process_custom_component.ts +++ b/compiler/src/process_custom_component.ts @@ -52,6 +52,7 @@ import { createViewCreate, createCustomComponentNewExpression } from './process_component_member'; +import { builderParamObjectCollection } from './process_component_member'; import { LogType, LogInfo, @@ -72,10 +73,44 @@ const decoractorMap: Map>> = new Map( export function processCustomComponent(node: ts.ExpressionStatement, newStatements: ts.Statement[], log: LogInfo[]): void { if (ts.isCallExpression(node.expression)) { - addCustomComponent(node, newStatements, createCustomComponentNewExpression(node.expression), log); + let ischangeNode: boolean = false; + let customComponentNewExpression: ts.NewExpression = createCustomComponentNewExpression( + node.expression); + let argumentsArray: ts.PropertyAssignment[]; + if (isHasChild(node.expression)) { + // @ts-ignore + argumentsArray = node.expression.arguments[0].properties.slice(); + argumentsArray.forEach((item: ts.PropertyAssignment, index: number) => { + if (ts.isCallExpression(item.initializer)) { + ischangeNode = true; + const PropertyAssignmentNode: ts.PropertyAssignment = ts.factory.updatePropertyAssignment( + item, item.name, changeNodeFromCallToArrow(item.initializer)); + argumentsArray.splice(index, 1, PropertyAssignmentNode); + } + }); + if (ischangeNode) { + const newNode: ts.ExpressionStatement = ts.factory.updateExpressionStatement(node, + ts.factory.createNewExpression(node.expression.expression, node.expression.typeArguments, + [ts.factory.createObjectLiteralExpression(argumentsArray, true)])); + customComponentNewExpression = createCustomComponentNewExpression( + newNode.expression as ts.CallExpression); + } + } + addCustomComponent(node, newStatements, customComponentNewExpression, log); } } +function isHasChild(node: ts.CallExpression): boolean { + return node.arguments && node.arguments[0] && ts.isObjectLiteralExpression(node.arguments[0]) && + node.arguments[0].properties && node.arguments[0].properties.length; +} + +function changeNodeFromCallToArrow(node: ts.CallExpression): ts.ArrowFunction { + return ts.factory.createArrowFunction(undefined, undefined, [], undefined, + ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), + ts.factory.createBlock([ts.factory.createExpressionStatement(node)], true)); +} + function addCustomComponent(node: ts.ExpressionStatement, newStatements: ts.Statement[], newNode: ts.NewExpression, log: LogInfo[]): void { if (ts.isNewExpression(newNode)) { @@ -105,13 +140,16 @@ 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 && item.name.escapedText) { - // @ts-ignore + if (item.name && ts.isIdentifier(item.name)) { curChildProps.add(item.name.escapedText.toString()); } if (isThisProperty(item, propertySet)) { validateStateManagement(item, name, log); if (isNonThisProperty(item, linkSet)) { + if (item.initializer && ts.isCallExpression(item.initializer)) { + item = ts.factory.updatePropertyAssignment(item as ts.PropertyAssignment, + item.name, changeNodeFromCallToArrow(item.initializer)); + } props.push(item); } } else { @@ -119,6 +157,7 @@ function validateCustomComponentPrams(node: ts.ExpressionStatement, name: string } }); } + validateMandatoryToAssignmentViaParam(node, name, curChildProps, log); validateMandatoryToInitViaParam(node, name, curChildProps, log); } @@ -346,11 +385,27 @@ function validateNonExistentProperty(node: ts.ObjectLiteralElementLike, customComponentName: string, log: LogInfo[]): void { log.push({ type: LogType.ERROR, - message: `Property '${node.name.getText()}' does not exist on type '${customComponentName}'.`, + message: `Property '${node.name.escapedText.toString()}' does not exist on type '${customComponentName}'.`, pos: node.name.getStart() }); } +function validateMandatoryToAssignmentViaParam(node: ts.ExpressionStatement, customComponentName: string, + curChildProps: Set, log: LogInfo[]): void { + if (builderParamObjectCollection.get(customComponentName) && + builderParamObjectCollection.get(customComponentName).size) { + builderParamObjectCollection.get(customComponentName).forEach((item) => { + if (!curChildProps.has(item)) { + log.push({ + type: LogType.ERROR, + message: `The property decorated with @BuilderParam '${item}' must be assigned a value .`, + pos: node.getStart() + }); + } + }); + } +} + function validateMandatoryToInitViaParam(node: ts.ExpressionStatement, customComponentName: string, curChildProps: Set, log: LogInfo[]): void { const mandatoryToInitViaParamSet: Set = new Set([ diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index 481074b..e0d66ce 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -81,7 +81,7 @@ export function processUISyntax(program: ts.Program, ut = false): Function { node = ts.visitEachChild(node, processAllNodes, context); GLOBAL_STYLE_FUNCTION.forEach((block, styleName) => { BUILDIN_STYLE_NAMES.delete(styleName); - }) + }); GLOBAL_STYLE_FUNCTION.clear(); return node; } else { @@ -98,7 +98,7 @@ export function processUISyntax(program: ts.Program, ut = false): Function { componentCollection.currentClassName = null; INNER_STYLE_FUNCTION.forEach((block, styleName) => { BUILDIN_STYLE_NAMES.delete(styleName); - }) + }); INNER_STYLE_FUNCTION.clear(); } else if (ts.isFunctionDeclaration(node)) { if (hasDecorator(node, COMPONENT_EXTEND_DECORATOR)) { @@ -154,7 +154,7 @@ function collectComponents(node: ts.SourceFile): void { // @ts-ignore if (node.identifiers && node.identifiers.size) { // @ts-ignore - for (let key of node.identifiers.keys()) { + for (const key of node.identifiers.keys()) { if (JS_BIND_COMPONENTS.has(key)) { appComponentCollection.add(key); } @@ -186,7 +186,7 @@ function processResourceData(node: ts.CallExpression): ts.Node { return node; } -function createResourceParam(resourceValue: number, resourceType: number,argsArr: ts.Expression[]): +function createResourceParam(resourceValue: number, resourceType: number, argsArr: ts.Expression[]): ts.ObjectLiteralExpression { const resourceParams: ts.ObjectLiteralExpression = ts.factory.createObjectLiteralExpression( [ diff --git a/compiler/src/result_process.ts b/compiler/src/result_process.ts index 46ea792..fb0269a 100644 --- a/compiler/src/result_process.ts +++ b/compiler/src/result_process.ts @@ -14,7 +14,6 @@ */ import ts from 'typescript'; -import path from 'path'; import { BUILD_OFF } from './pre_define'; import { diff --git a/compiler/src/utils.ts b/compiler/src/utils.ts index fdd8cf4..c7a7700 100644 --- a/compiler/src/utils.ts +++ b/compiler/src/utils.ts @@ -159,10 +159,10 @@ export function createFunction(node: ts.Identifier, attrNode: ts.Identifier, } export function circularFile(inputPath: string, outputPath: string): void { - if ((!inputPath) || (!outputPath)) { + if (!inputPath || !outputPath) { return; } - fs.readdir(inputPath, function (err, files) { + fs.readdir(inputPath, function(err, files) { if (!files) { return; } @@ -205,4 +205,4 @@ function mkDir(path_: string): void { mkDir(parent); } fs.mkdirSync(path_); -} \ No newline at end of file +} diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index c57d75f..65e2c65 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -183,7 +183,7 @@ function checkComponentDecorator(source: string, filePath: string, } if (ts.isFunctionDeclaration(item) && item.decorators && item.decorators.length === 1 && item.decorators[0].expression && item.decorators[0].expression.getText() === STYLES) { - STYLES_ATTRIBUTE.add(item.name.getText()) + STYLES_ATTRIBUTE.add(item.name.getText()); GLOBAL_STYLE_FUNCTION.set(item.name.getText(), item.body); BUILDIN_STYLE_NAMES.add(item.name.getText()); } @@ -744,7 +744,7 @@ export function sourceReplace(source: string, sourcePath: string): ReplaceResult return { content: content, log: log - } + }; } export function preprocessExtend(content: string, sourcePath: string, log: LogInfo[]): string { @@ -772,7 +772,7 @@ export function preprocessExtend(content: string, sourcePath: string, log: LogIn syntaxCheckContent = content; } if (result.error_otherParsers) { - for(let i = 0; i < result.error_otherParsers.length; i++) { + for (let i = 0; i < result.error_otherParsers.length; i++) { log.push({ type: LogType.ERROR, message: result.error_otherParsers[i].errMessage, @@ -810,24 +810,24 @@ export function processSystemApi(content: string, isProcessWhiteList: boolean = const libSoValue: string = item1 || item3; const libSoKey: string = item2 || item4; return `var ${libSoValue} = globalThis.requireNapi("${libSoKey}", true);`; - }).replace(REG_SYSTEM, (item, item1, item2, item3, item4, item5, item6, item7) => { - let moduleType: string = item2 || item5; - let systemKey: string = item3 || item6; - let systemValue: string = item1 || item4; - moduleCollection.add(`${moduleType}.${systemKey}`); - if (NATIVE_MODULE.has(`${moduleType}.${systemKey}`)) { - item = `var ${systemValue} = globalThis.requireNativeModule('${moduleType}.${systemKey}')`; - } else if (moduleType === SYSTEM_PLUGIN) { - item = `var ${systemValue} = isSystemplugin('${systemKey}', '${SYSTEM_PLUGIN}') ? ` + + }).replace(REG_SYSTEM, (item, item1, item2, item3, item4, item5, item6, item7) => { + const moduleType: string = item2 || item5; + const systemKey: string = item3 || item6; + const systemValue: string = item1 || item4; + moduleCollection.add(`${moduleType}.${systemKey}`); + if (NATIVE_MODULE.has(`${moduleType}.${systemKey}`)) { + item = `var ${systemValue} = globalThis.requireNativeModule('${moduleType}.${systemKey}')`; + } else if (moduleType === SYSTEM_PLUGIN) { + item = `var ${systemValue} = isSystemplugin('${systemKey}', '${SYSTEM_PLUGIN}') ? ` + `globalThis.systemplugin.${systemKey} : globalThis.requireNapi('${systemKey}')`; - } else if (moduleType === OHOS_PLUGIN) { - item = `var ${systemValue} = globalThis.requireNapi('${systemKey}') || ` + + } else if (moduleType === OHOS_PLUGIN) { + item = `var ${systemValue} = globalThis.requireNapi('${systemKey}') || ` + `(isSystemplugin('${systemKey}', '${OHOS_PLUGIN}') ? ` + `globalThis.ohosplugin.${systemKey} : isSystemplugin('${systemKey}', '${SYSTEM_PLUGIN}') ` + `? globalThis.systemplugin.${systemKey} : undefined)`; - } - return item; - }); + } + return item; + }); } function validateWhiteListModule(moduleType: string, systemKey: string): boolean { From c37dc9c4ec4a77203eefe5b8205eeb92daf4b277 Mon Sep 17 00:00:00 2001 From: lixingchi1 Date: Fri, 28 Jan 2022 10:48:41 +0800 Subject: [PATCH 19/44] lixingchi1@huawei.com Signed-off-by: lixingchi1 --- compiler/components/web.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/components/web.json b/compiler/components/web.json index a2c7a48..a4fe564 100644 --- a/compiler/components/web.json +++ b/compiler/components/web.json @@ -1,5 +1,5 @@ { "name": "Web", "atomic": true, - "attrs": ["onPageFinish", "onRequestFocus", "javaScriptEnabled", "fileAccessEnabled"] + "attrs": ["onPageEnd", "onRequestSelected", "javaScriptAccess", "fileAccess"] } \ No newline at end of file From 719b22e05f00e4ee6aa33f95a9125cc938c5eb17 Mon Sep 17 00:00:00 2001 From: lihong Date: Fri, 28 Jan 2022 15:02:35 +0800 Subject: [PATCH 20/44] lihong67@huawei.com support module validate Signed-off-by: lihong Change-Id: I73c622aa3bc08da2d9223d5b54933f5abe4a344f --- compiler/src/pre_define.ts | 1 + compiler/src/validate_ui_syntax.ts | 43 ++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 8efee8a..e4780c0 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -17,6 +17,7 @@ import path from 'path'; export const NATIVE_MODULE: Set = new Set( ['system.app', 'ohos.app', 'system.router', 'system.curves', 'ohos.curves', 'system.matrix4', 'ohos.matrix4']); +export const VALIDATE_MODULE: string[] = ['application', 'util']; export const SYSTEM_PLUGIN: string = 'system'; export const OHOS_PLUGIN: string = 'ohos'; diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index 65e2c65..148178c 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -43,7 +43,8 @@ import { COMPONENT_CONSTRUCTOR_PARAMS, COMPONENT_EXTEND_DECORATOR, COMPONENT_OBSERVED_DECORATOR, - STYLES + STYLES, + VALIDATE_MODULE } from './pre_define'; import { INNER_COMPONENT_NAMES, @@ -802,18 +803,32 @@ function collectExtend(component: string, attribute: string, parameter: string): export function processSystemApi(content: string, isProcessWhiteList: boolean = false): string { let REG_SYSTEM: RegExp; - REG_SYSTEM = - /import\s+(.+)\s+from\s+['"]@(system|ohos)\.(\S+)['"]|import\s+(.+)\s*=\s*require\(\s*['"]@(system|ohos)\.(\S+)['"]\s*\)/g; + if (isProcessWhiteList) { + REG_SYSTEM = + /(import|const)\s+(.+)\s*=\s*(\_\_importDefault\()?require\(\s*['"]@(system|ohos)\.(\S+)['"]\s*\)(\))?/g; + } else { + REG_SYSTEM = + /import\s+(.+)\s+from\s+['"]@(system|ohos)\.(\S+)['"]|import\s+(.+)\s*=\s*require\(\s*['"]@(system|ohos)\.(\S+)['"]\s*\)/g; + } const REG_LIB_SO: RegExp = /import\s+(.+)\s+from\s+['"]lib(\S+)\.so['"]|import\s+(.+)\s*=\s*require\(\s*['"]lib(\S+)\.so['"]\s*\)/g; - return content.replace(REG_LIB_SO, (_, item1, item2, item3, item4) => { + const systemValueCollection: Set = new Set(); + const newContent: string = content.replace(REG_LIB_SO, (_, item1, item2, item3, item4) => { const libSoValue: string = item1 || item3; const libSoKey: string = item2 || item4; return `var ${libSoValue} = globalThis.requireNapi("${libSoKey}", true);`; }).replace(REG_SYSTEM, (item, item1, item2, item3, item4, item5, item6, item7) => { - const moduleType: string = item2 || item5; - const systemKey: string = item3 || item6; - const systemValue: string = item1 || item4; + let moduleType: string = item2 || item5; + let systemKey: string = item3 || item6; + let systemValue: string = item1 || item4; + if (!isProcessWhiteList && validateWhiteListModule(moduleType, systemKey)) { + return item; + } else if (isProcessWhiteList) { + systemValue = item2; + moduleType = item4; + systemKey = item5; + systemValueCollection.add(systemValue); + } moduleCollection.add(`${moduleType}.${systemKey}`); if (NATIVE_MODULE.has(`${moduleType}.${systemKey}`)) { item = `var ${systemValue} = globalThis.requireNativeModule('${moduleType}.${systemKey}')`; @@ -828,10 +843,22 @@ export function processSystemApi(content: string, isProcessWhiteList: boolean = } return item; }); + return processInnerModule(newContent, systemValueCollection); } +function processInnerModule(content: string, systemValueCollection: Set): string { + systemValueCollection.forEach(element => { + const target: string = element.trim() + '.default'; + while (content.includes(target)) { + content = content.replace(target, element.trim()); + } + }); + return content; +} + +const VALIDATE_MODULE_REG: RegExp = new RegExp('^(' + VALIDATE_MODULE.join('|') + ')'); function validateWhiteListModule(moduleType: string, systemKey: string): boolean { - return moduleType === 'ohos' && /^application\./g.test(systemKey); + return moduleType === 'ohos' && VALIDATE_MODULE_REG.test(systemKey); } export function resetComponentCollection() { From 305f2bc37b6fe1d1a36dcc0fcfb93d7a179e7caa Mon Sep 17 00:00:00 2001 From: puyajun Date: Sun, 30 Jan 2022 09:48:03 +0800 Subject: [PATCH 21/44] puyajun@huawei.com fix bug builderParam Signed-off-by: puyajun Change-Id: I087d4c546406030679c79e984b964530618660ec --- compiler/src/process_custom_component.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/compiler/src/process_custom_component.ts b/compiler/src/process_custom_component.ts index 484f906..e17abb5 100644 --- a/compiler/src/process_custom_component.ts +++ b/compiler/src/process_custom_component.ts @@ -81,10 +81,10 @@ export function processCustomComponent(node: ts.ExpressionStatement, newStatemen // @ts-ignore argumentsArray = node.expression.arguments[0].properties.slice(); argumentsArray.forEach((item: ts.PropertyAssignment, index: number) => { - if (ts.isCallExpression(item.initializer)) { + if (isToChange(item, node.expression as ts.CallExpression)) { ischangeNode = true; const PropertyAssignmentNode: ts.PropertyAssignment = ts.factory.updatePropertyAssignment( - item, item.name, changeNodeFromCallToArrow(item.initializer)); + item, item.name, changeNodeFromCallToArrow(item.initializer as ts.CallExpression)); argumentsArray.splice(index, 1, PropertyAssignmentNode); } }); @@ -105,6 +105,12 @@ function isHasChild(node: ts.CallExpression): boolean { node.arguments[0].properties && node.arguments[0].properties.length; } +function isToChange(item: ts.PropertyAssignment, node: ts.CallExpression): boolean { + const BuilderParamname = builderParamObjectCollection.get(node.expression.getText()); + return ts.isCallExpression(item.initializer) && BuilderParamname && + BuilderParamname.has(item.name.getText()); +} + function changeNodeFromCallToArrow(node: ts.CallExpression): ts.ArrowFunction { return ts.factory.createArrowFunction(undefined, undefined, [], undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), @@ -146,7 +152,8 @@ function validateCustomComponentPrams(node: ts.ExpressionStatement, name: string if (isThisProperty(item, propertySet)) { validateStateManagement(item, name, log); if (isNonThisProperty(item, linkSet)) { - if (item.initializer && ts.isCallExpression(item.initializer)) { + if (item.initializer && ts.isCallExpression(item.initializer) && isToChange( + item as ts.PropertyAssignment, node.expression as ts.CallExpression)) { item = ts.factory.updatePropertyAssignment(item as ts.PropertyAssignment, item.name, changeNodeFromCallToArrow(item.initializer)); } From 4425a67be69db849d2234c1c6c00cf7dd087c43c Mon Sep 17 00:00:00 2001 From: puyajun Date: Sun, 30 Jan 2022 10:04:01 +0800 Subject: [PATCH 22/44] puyajun@huawei.com fix builderParam bug Signed-off-by: puyajun Change-Id: I6d40cbc496a46523553ef76cf1a74728f69c35f9 --- compiler/test/ut/builder/builderParam.ts | 37 ++++++++++++++++-------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/compiler/test/ut/builder/builderParam.ts b/compiler/test/ut/builder/builderParam.ts index b0e117a..cdd3352 100644 --- a/compiler/test/ut/builder/builderParam.ts +++ b/compiler/test/ut/builder/builderParam.ts @@ -14,9 +14,11 @@ */ exports.source = ` + @Component struct CustomContainer { header: string = ""; + menuInfo: () => any; footer: string = ""; @BuilderParam child: () => any; @@ -32,10 +34,10 @@ struct CustomContainer { @Entry @Component struct CustomContainerUser { - @Builder specificChild() { + @Builder specificChild(label:string) { Column() { Text("My content1") - Text("My content2") + Text(label) } } @@ -44,7 +46,8 @@ struct CustomContainerUser { CustomContainer({ header: "Header", footer: "Footer", - child: this.specificChild + menuInfo: this.specificChild("menuInfo") + child: this.specificChild("child") }) } } @@ -55,6 +58,7 @@ exports.expectResult = constructor(compilerAssignedUniqueChildId, parent, params) { super(compilerAssignedUniqueChildId, parent); this.header = ""; + this.menuInfo = undefined; this.footer = ""; this.updateWithValueParams(params); } @@ -62,6 +66,9 @@ exports.expectResult = if (params.header !== undefined) { this.header = params.header; } + if (params.menuInfo !== undefined) { + this.menuInfo = params.menuInfo; + } if (params.footer !== undefined) { this.footer = params.footer; } @@ -90,31 +97,37 @@ class CustomContainerUser extends View { aboutToBeDeleted() { SubscriberManager.Get().delete(this.id()); } - specificChild() { + specificChild(label) { Column.create(); Text.create("My content1"); Text.pop(); - Text.create("My content2"); + Text.create(label); Text.pop(); Column.pop(); } render() { Column.create(); - let earlierCreatedChild_2 = this.findChildById("2"); - if (earlierCreatedChild_2 == undefined) { - View.create(new CustomContainer("2", this, { + let earlierCreatedChild_3 = this.findChildById("3"); + if (earlierCreatedChild_3 == undefined) { + View.create(new CustomContainer("3", this, { header: "Header", footer: "Footer", - child: this.specificChild + menuInfo: this.specificChild("menuInfo"), + child: () => { + this.specificChild("child"); + } })); } else { - earlierCreatedChild_2.updateWithValueParams({ + earlierCreatedChild_3.updateWithValueParams({ header: "Header", footer: "Footer", - child: this.specificChild + menuInfo: this.specificChild("menuInfo"), + child: () => { + this.specificChild("child"); + } }); - View.create(earlierCreatedChild_2); + View.create(earlierCreatedChild_3); } Column.pop(); } From b9550ee2d7d7181af5e86e286bffe3feac92dcd1 Mon Sep 17 00:00:00 2001 From: puyajun Date: Sun, 30 Jan 2022 10:09:05 +0800 Subject: [PATCH 23/44] puyajun@huawei.com fix builderParam bug Signed-off-by: puyajun Change-Id: I84fa86b1ac77ec50dd2ada2eddf4d789cb42d143 --- compiler/test/ut/builder/builderParam.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test/ut/builder/builderParam.ts b/compiler/test/ut/builder/builderParam.ts index cdd3352..d21e640 100644 --- a/compiler/test/ut/builder/builderParam.ts +++ b/compiler/test/ut/builder/builderParam.ts @@ -46,7 +46,7 @@ struct CustomContainerUser { CustomContainer({ header: "Header", footer: "Footer", - menuInfo: this.specificChild("menuInfo") + menuInfo: this.specificChild("menuInfo"), child: this.specificChild("child") }) } From 3ca8de59087b9b3c82b306c0ea7607c36194965c Mon Sep 17 00:00:00 2001 From: puyajun Date: Sun, 30 Jan 2022 10:13:04 +0800 Subject: [PATCH 24/44] puyajun@huawei.com fix builderParam bug Signed-off-by: puyajun Change-Id: Ic1de5e304086657b0f04d1bbbdf1e6fea9a18656 --- compiler/src/process_custom_component.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/compiler/src/process_custom_component.ts b/compiler/src/process_custom_component.ts index e17abb5..a17447f 100644 --- a/compiler/src/process_custom_component.ts +++ b/compiler/src/process_custom_component.ts @@ -83,9 +83,9 @@ export function processCustomComponent(node: ts.ExpressionStatement, newStatemen argumentsArray.forEach((item: ts.PropertyAssignment, index: number) => { if (isToChange(item, node.expression as ts.CallExpression)) { ischangeNode = true; - const PropertyAssignmentNode: ts.PropertyAssignment = ts.factory.updatePropertyAssignment( + const propertyAssignmentNode: ts.PropertyAssignment = ts.factory.updatePropertyAssignment( item, item.name, changeNodeFromCallToArrow(item.initializer as ts.CallExpression)); - argumentsArray.splice(index, 1, PropertyAssignmentNode); + argumentsArray.splice(index, 1, propertyAssignmentNode); } }); if (ischangeNode) { @@ -106,9 +106,9 @@ function isHasChild(node: ts.CallExpression): boolean { } function isToChange(item: ts.PropertyAssignment, node: ts.CallExpression): boolean { - const BuilderParamname = builderParamObjectCollection.get(node.expression.getText()); - return ts.isCallExpression(item.initializer) && BuilderParamname && - BuilderParamname.has(item.name.getText()); + const builderParamName: Set = builderParamObjectCollection.get(node.expression.getText()); + return item.initializer && ts.isCallExpression(item.initializer) && builderParamName && + builderParamName.has(item.name.getText()); } function changeNodeFromCallToArrow(node: ts.CallExpression): ts.ArrowFunction { @@ -152,8 +152,7 @@ function validateCustomComponentPrams(node: ts.ExpressionStatement, name: string if (isThisProperty(item, propertySet)) { validateStateManagement(item, name, log); if (isNonThisProperty(item, linkSet)) { - if (item.initializer && ts.isCallExpression(item.initializer) && isToChange( - item as ts.PropertyAssignment, node.expression as ts.CallExpression)) { + if (isToChange(item as ts.PropertyAssignment, node.expression as ts.CallExpression)) { item = ts.factory.updatePropertyAssignment(item as ts.PropertyAssignment, item.name, changeNodeFromCallToArrow(item.initializer)); } From 7c61bf782b9d9150d3a1707a6540148b9575b799 Mon Sep 17 00:00:00 2001 From: houhaoyu Date: Mon, 7 Feb 2022 16:03:29 +0800 Subject: [PATCH 25/44] houhaoyu@huawei.com Signed-off-by: houhaoyu Change-Id: I118218e51d3122888af12a44e1ff2c4fbdbf5181 --- compiler/src/process_component_class.ts | 8 ++++---- compiler/src/process_component_constructor.ts | 6 +++--- compiler/src/process_component_member.ts | 2 +- compiler/src/process_custom_component.ts | 13 +++++++------ compiler/test/ut/decorator/watchWithAnimateTo.ts | 16 ++++++---------- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index 2d9e073..ee4a482 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -126,8 +126,8 @@ function processMembers(members: ts.NodeArray, parentComponentN const deleteParamsStatements: ts.PropertyDeclaration[] = []; const checkController: ControllerType = { hasController: !componentCollection.customDialogs.has(parentComponentName.getText()) }; - let interfaceNode = ts.factory.createInterfaceDeclaration(undefined, undefined, - parentComponentName.getText() + INTERFACE_NAME_SUFFIX, undefined, undefined, []) + const interfaceNode = ts.factory.createInterfaceDeclaration(undefined, undefined, + parentComponentName.getText() + INTERFACE_NAME_SUFFIX, undefined, undefined, []); members.forEach((item: ts.ClassElement) => { let updateItem: ts.ClassElement; if (ts.isPropertyDeclaration(item)) { @@ -177,10 +177,10 @@ function processMembers(members: ts.NodeArray, parentComponentN function addPropertyMember(item: ts.ClassElement, newMembers: ts.ClassElement[], program: ts.Program):void { - let propertyItem: ts.PropertyDeclaration = item as ts.PropertyDeclaration; + const propertyItem: ts.PropertyDeclaration = item as ts.PropertyDeclaration; let decoratorName: string; let updatePropertyItem: ts.PropertyDeclaration; - let type: ts.TypeNode = propertyItem.type; + const type: ts.TypeNode = propertyItem.type; if (!propertyItem.decorators || propertyItem.decorators.length === 0) { updatePropertyItem = createPropertyDeclaration(propertyItem, type, true); newMembers.push(updatePropertyItem); diff --git a/compiler/src/process_component_constructor.ts b/compiler/src/process_component_constructor.ts index 6bc7582..36f56ba 100644 --- a/compiler/src/process_component_constructor.ts +++ b/compiler/src/process_component_constructor.ts @@ -91,12 +91,12 @@ function addParamsType(ctorNode: ts.ConstructorDeclaration, modifyPara: ts.Param case COMPONENT_CONSTRUCTOR_PARAMS + '?': parameter = ts.factory.updateParameterDeclaration(item, item.decorators, item.modifiers, item.dotDotDotToken, item.name, item.questionToken, - ts.factory.createTypeReferenceNode(ts.factory.createIdentifier - (parentComponentName.getText() + INTERFACE_NAME_SUFFIX), undefined), item.initializer); + ts.factory.createTypeReferenceNode(ts.factory.createIdentifier( + parentComponentName.getText() + INTERFACE_NAME_SUFFIX), undefined), item.initializer); break; } newTSPara.push(parameter); - }) + }); return newTSPara; } diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index 7b0123d..77ddab7 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -207,7 +207,7 @@ export function processMemberVariableDecorators(parentName: ts.Identifier, updateResult.setUpdateParams(createUpdateParams(name, COMPONENT_NON_DECORATOR)); updateResult.setCtor(updateConstructor(ctorNode, [], [ createVariableInitStatement(item, COMPONENT_NON_DECORATOR, log, program, context, hasPreview, - interfaceNode)])); + interfaceNode)])); updateResult.setControllerSet(createControllerSet(item, parentName, name, checkController)); } else if (!item.type) { validatePropertyNonType(name, log); diff --git a/compiler/src/process_custom_component.ts b/compiler/src/process_custom_component.ts index 484f906..586ea9c 100644 --- a/compiler/src/process_custom_component.ts +++ b/compiler/src/process_custom_component.ts @@ -124,7 +124,7 @@ function addCustomComponent(node: ts.ExpressionStatement, newStatements: ts.Stat function addCustomComponentStatements(node: ts.ExpressionStatement, newStatements: ts.Statement[], newNode: ts.NewExpression, name: string, props: ts.ObjectLiteralElementLike[]): void { const id: string = componentInfo.id.toString(); - newStatements.push(createFindChildById(id), createCustomComponentIfStatement(id, + newStatements.push(createFindChildById(id, name), createCustomComponentIfStatement(id, ts.factory.updateExpressionStatement(node, createViewCreate(newNode)), ts.factory.createObjectLiteralExpression(props, true), name)); } @@ -311,13 +311,14 @@ function getPropertyDecoratorKind(propertyName: string, customComponentName: str } } -function createFindChildById(id: string): ts.VariableStatement { +function createFindChildById(id: string, name: string): ts.VariableStatement { return ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList( [ts.factory.createVariableDeclaration(ts.factory.createIdentifier( - `${CUSTOM_COMPONENT_EARLIER_CREATE_CHILD}${id}`), undefined, undefined, - ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createThis(), - ts.factory.createIdentifier(`${CUSTOM_COMPONENT_FUNCTION_FIND_CHILD_BY_ID}`)), undefined, - [ts.factory.createStringLiteral(id)]))], ts.NodeFlags.Let)); + `${CUSTOM_COMPONENT_EARLIER_CREATE_CHILD}${id}`), undefined, ts.factory.createTypeReferenceNode( + ts.factory.createIdentifier(name)), ts.factory.createAsExpression(ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression(ts.factory.createThis(), ts.factory.createIdentifier( + `${CUSTOM_COMPONENT_FUNCTION_FIND_CHILD_BY_ID}`)), undefined, [ts.factory.createStringLiteral(id)]), + ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(name))))], ts.NodeFlags.Let)); } function createCustomComponentIfStatement(id: string, node: ts.ExpressionStatement, diff --git a/compiler/test/ut/decorator/watchWithAnimateTo.ts b/compiler/test/ut/decorator/watchWithAnimateTo.ts index 7744147..6b8473d 100644 --- a/compiler/test/ut/decorator/watchWithAnimateTo.ts +++ b/compiler/test/ut/decorator/watchWithAnimateTo.ts @@ -33,9 +33,7 @@ struct MyAlertDialog { } build() { Stack() { - DialogView({dialogShow: $dialogVis}).onClick(() => { - animateTo({}, () => {}) - }) + DialogView({dialogShow: $dialogVis}) } } } @@ -108,15 +106,13 @@ class MyAlertDialog extends View { } render() { Stack.create(); - let earlierCreatedChild_2 = this.findChildById("2"); - if (earlierCreatedChild_2 == undefined) { - View.create(new (DialogView({ dialogShow: this.__dialogVis }).onClick)(() => { - Context.animateTo({}, () => { }); - })); + let earlierCreatedChild_3 = this.findChildById("3"); + if (earlierCreatedChild_3 == undefined) { + View.create(new DialogView("3", this, { dialogShow: this.__dialogVis })); } else { - earlierCreatedChild_2.updateWithValueParams({}); - View.create(earlierCreatedChild_2); + earlierCreatedChild_3.updateWithValueParams({}); + View.create(earlierCreatedChild_3); } Stack.pop(); } From ccf491f1e813a16c44ddd500c32ac4bfb0be84c1 Mon Sep 17 00:00:00 2001 From: lihong Date: Tue, 8 Feb 2022 14:16:19 +0800 Subject: [PATCH 26/44] lihong67@huawei.com exclude commonjs bundle. Signed-off-by: lihong Change-Id: I0ea70cc94b247f009e6d21a3907314ab23ceb6d4 --- compiler/main.js | 1 + compiler/webpack.config.js | 48 +++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/compiler/main.js b/compiler/main.js index 570b6c0..aa25d1a 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -73,6 +73,7 @@ function loadEntryObj(projectConfig) { const jsonString = fs.readFileSync(projectConfig.manifestFilePath).toString(); manifest = JSON.parse(jsonString); } else if (projectConfig.aceModuleJsonPath && fs.existsSync(projectConfig.aceModuleJsonPath)) { + process.env.compileMode = 'moduleJson'; buildManifest(manifest, projectConfig.aceModuleJsonPath); } else { throw Error('\u001b[31m ERROR: the manifest file ' + projectConfig.manifestFilePath + diff --git a/compiler/webpack.config.js b/compiler/webpack.config.js index c7f148a..d9d0cd6 100644 --- a/compiler/webpack.config.js +++ b/compiler/webpack.config.js @@ -46,27 +46,6 @@ function initConfig(config) { poll: false, ignored: /node_modules/ }, - optimization: { - splitChunks: { - chunks(chunk) { - return !/^\.\/workers\//.test(chunk.name); - }, - minSize: 0, - cacheGroups: { - vendors: { - test: /[\\/]node_modules[\\/]/, - priority: -10, - name: "vendors", - }, - commons: { - name: 'commons', - priority: -20, - minChunks: 2, - reuseExistingChunk: true - } - } - }, - }, output: { path: path.resolve(__dirname, projectConfig.buildPath), filename: '[name].js', @@ -213,11 +192,38 @@ function setCopyPluginConfig(config) { config.plugins.push(new CopyPlugin({ patterns: copyPluginPattrens })); } +function setOptimizationConfig(config) { + if (process.env.compileMode !== 'moduleJson') { + config.optimization = { + splitChunks: { + chunks(chunk) { + return !/^\.\/workers\//.test(chunk.name); + }, + minSize: 0, + cacheGroups: { + vendors: { + test: /[\\/]node_modules[\\/]/, + priority: -10, + name: "vendors", + }, + commons: { + name: 'commons', + priority: -20, + minChunks: 2, + reuseExistingChunk: true + } + } + } + } + } +} + module.exports = (env, argv) => { const config = {}; setProjectConfig(env); loadEntryObj(projectConfig); initConfig(config); + setOptimizationConfig(config); setCopyPluginConfig(config); if (env.isPreview !== "true") { From 34746de508c2818479a85d93c9cca3cb45f8b2fb Mon Sep 17 00:00:00 2001 From: puyajun Date: Tue, 8 Feb 2022 13:09:13 +0800 Subject: [PATCH 27/44] puyajun@huawei.com Signed-off-by: puyajun Change-Id: I8b94648ddcf67eac2ceedcd188b9924ab0943c15 --- compiler/src/component_map.ts | 3 + compiler/src/process_component_build.ts | 146 ++++++++++++++++++-- compiler/src/process_component_class.ts | 89 +----------- compiler/src/validate_ui_syntax.ts | 10 +- compiler/test/ut/builder/builderBindPopu.ts | 75 ++++++++++ 5 files changed, 224 insertions(+), 99 deletions(-) create mode 100644 compiler/test/ut/builder/builderBindPopu.ts diff --git a/compiler/src/component_map.ts b/compiler/src/component_map.ts index a88790e..19083b5 100644 --- a/compiler/src/component_map.ts +++ b/compiler/src/component_map.ts @@ -91,6 +91,9 @@ export const JS_BIND_COMPONENTS: Set = new Set([ export const NEEDPOP_COMPONENT: Set = new Set(['Blank', 'Search']); +export const CUSTOM_BUILDER_PROPERTIES: Set = new Set(['bindPopup', 'bindMenu', 'bindContextMenu', 'title', + 'menus', 'toolBar', 'tabBar']); + (function initComponent() { Object.keys(COMPONENT_MAP).forEach((componentName) => { INNER_COMPONENT_NAMES.add(componentName); diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index ea2b141..c66da17 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -52,7 +52,10 @@ import { $$_VALUE, $$_CHANGE_EVENT, $$_THIS, - $$_NEW_VALUE + $$_NEW_VALUE, + BUILDER_ATTR_NAME, + BUILDER_ATTR_BIND, + CUSTOM_DIALOG_CONTROLLER_BUILDER } from './pre_define'; import { INNER_COMPONENT_NAMES, @@ -66,7 +69,8 @@ import { NEEDPOP_COMPONENT, INNER_STYLE_FUNCTION, GLOBAL_STYLE_FUNCTION, - COMMON_ATTRS + COMMON_ATTRS, + CUSTOM_BUILDER_PROPERTIES } from './component_map'; import { componentCollection } from './validate_ui_syntax'; import { processCustomComponent } from './process_custom_component'; @@ -516,6 +520,16 @@ export function bindComponentAttr(node: ts.ExpressionStatement, identifierNode: const statements: ts.Statement[] = []; const lastStatement: AnimationInfo = { statement: null, kind: false }; while (temp && ts.isCallExpression(temp) && temp.expression) { + if (temp.expression && (validatePropertyAccessExpressionWithCustomBuilder(temp.expression) || + validateIdentifierWithCustomBuilder(temp.expression))) { + let propertyName: string = ''; + if (ts.isIdentifier(temp.expression)) { + propertyName = temp.expression.escapedText.toString(); + } else if (ts.isPropertyAccessExpression(temp.expression)) { + propertyName = temp.expression.name.escapedText.toString(); + } + temp = propertyName === BIND_POPUP ? processBindPopupBuilder(temp) : processCustomBuilderProperty(temp); + } if (ts.isPropertyAccessExpression(temp.expression) && temp.expression.name && ts.isIdentifier(temp.expression.name)) { addComponentAttr(temp, temp.expression.name, lastStatement, statements, identifierNode, log, @@ -538,6 +552,122 @@ export function bindComponentAttr(node: ts.ExpressionStatement, identifierNode: } } +function processCustomBuilderProperty(node: ts.CallExpression): ts.CallExpression { + const newArguments: ts.Expression[] = []; + node.arguments.forEach((argument: ts.Expression | ts.Identifier, index: number) => { + if (index === 0 && (ts.isPropertyAccessExpression(argument) || ts.isCallExpression(argument) || + ts.isIdentifier(argument))) { + newArguments.push(parseBuilderNode(argument)); + } else { + newArguments.push(argument); + } + }); + node = ts.factory.updateCallExpression(node, node.expression, node.typeArguments, newArguments); + return node; +} + +function parseBuilderNode(node: ts.Node): ts.ObjectLiteralExpression { + if (isPropertyAccessExpressionNode(node)) { + return processPropertyBuilder(node as ts.PropertyAccessExpression); + } else if (ts.isIdentifier(node) && CUSTOM_BUILDER_METHOD.has(node.escapedText.toString())) { + return processIdentifierBuilder(node); + } else if (ts.isCallExpression(node)) { + return getParsedBuilderAttrArgumentWithParams(node); + } +} + +function isPropertyAccessExpressionNode(node: ts.Node): boolean { + return ts.isPropertyAccessExpression(node) && node.expression && + node.expression.kind === ts.SyntaxKind.ThisKeyword && node.name && ts.isIdentifier(node.name) && + CUSTOM_BUILDER_METHOD.has(node.name.escapedText.toString()); +} + +function processBindPopupBuilder(node: ts.CallExpression): ts.CallExpression { + const newArguments: ts.Expression[] = []; + node.arguments.forEach((argument: ts.ObjectLiteralExpression, index: number) => { + if (index === 1) { + // @ts-ignore + newArguments.push(processBindPopupBuilderProperty(argument)); + } else { + newArguments.push(argument); + } + }); + node = ts.factory.updateCallExpression(node, node.expression, node.typeArguments, newArguments); + return node; +} + +function processBindPopupBuilderProperty(node: ts.ObjectLiteralExpression): ts.ObjectLiteralExpression { + const newProperties: ts.PropertyAssignment[] = []; + node.properties.forEach((property: ts.PropertyAssignment, index: number) => { + if (index === 0) { + if (property.name && ts.isIdentifier(property.name) && + property.name.escapedText.toString() === CUSTOM_DIALOG_CONTROLLER_BUILDER) { + newProperties.push(ts.factory.updatePropertyAssignment(property, property.name, + parseBuilderNode(property.initializer))); + } else { + newProperties.push(property); + } + } else { + newProperties.push(property); + } + }); + return ts.factory.updateObjectLiteralExpression(node, newProperties); +} + +function processPropertyBuilder(node: ts.PropertyAccessExpression): ts.ObjectLiteralExpression { + return ts.factory.createObjectLiteralExpression([ + ts.factory.createPropertyAssignment( + ts.factory.createIdentifier(BUILDER_ATTR_NAME), + ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression( + node, + ts.factory.createIdentifier(BUILDER_ATTR_BIND) + ), + undefined, + [ts.factory.createThis()] + ) + ) + ]); +} + +function processIdentifierBuilder(node: ts.Identifier): ts.ObjectLiteralExpression { + return ts.factory.createObjectLiteralExpression([ + ts.factory.createPropertyAssignment( + ts.factory.createIdentifier(BUILDER_ATTR_NAME), + node + ) + ]); +} + +function getParsedBuilderAttrArgumentWithParams(node: ts.CallExpression): + ts.ObjectLiteralExpression { + return ts.factory.createObjectLiteralExpression([ + ts.factory.createPropertyAssignment( + ts.factory.createIdentifier(BUILDER_ATTR_NAME), + ts.factory.createArrowFunction( + undefined, + undefined, + [], + undefined, + ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), + ts.factory.createBlock( + [ts.factory.createExpressionStatement(node)], + true + ) + ) + ) + ]); +} + +function validatePropertyAccessExpressionWithCustomBuilder(node: ts.Node): boolean { + return ts.isPropertyAccessExpression(node) && node.name && + ts.isIdentifier(node.name) && CUSTOM_BUILDER_PROPERTIES.has(node.name.escapedText.toString()); +} + +function validateIdentifierWithCustomBuilder(node: ts.Node): boolean { + return ts.isIdentifier(node) && CUSTOM_BUILDER_PROPERTIES.has(node.escapedText.toString()); +} + function createArrowFunctionFor$$($$varExp: ts.Expression): ts.ArrowFunction { return ts.factory.createArrowFunction( undefined, undefined, @@ -561,8 +691,8 @@ function createArrowFunctionFor$$($$varExp: ts.Expression): ts.ArrowFunction { function updateArgumentFor$$(argument: any): ts.Expression { if (ts.isElementAccessExpression(argument)) { - return ts.factory.updateElementAccessExpression - (argument, updateArgumentFor$$(argument.expression), argument.argumentExpression); + return ts.factory.updateElementAccessExpression( + argument, updateArgumentFor$$(argument.expression), argument.argumentExpression); } else if (ts.isIdentifier(argument)) { props.push(argument.getText()); if (argument.getText() === $$_THIS) { @@ -571,8 +701,8 @@ function updateArgumentFor$$(argument: any): ts.Expression { return ts.factory.createIdentifier(argument.getText().replace(/\$\$/, '')); } } else if (ts.isPropertyAccessExpression(argument)) { - return ts.factory.updatePropertyAccessExpression - (argument, updateArgumentFor$$(argument.expression), argument.name); + return ts.factory.updatePropertyAccessExpression( + argument, updateArgumentFor$$(argument.expression), argument.name); } } @@ -706,8 +836,8 @@ function traverseStateStylesAttr(temp: any, statements: ts.Statement[], } else if (ts.isObjectLiteralExpression(item.initializer) && item.initializer.properties.length === 1 && ts.isPropertyAssignment(item.initializer.properties[0])) { - bindComponentAttr(ts.factory.createExpressionStatement - (item.initializer.properties[0].initializer), identifierNode, statements, log, false, true); + bindComponentAttr(ts.factory.createExpressionStatement( + item.initializer.properties[0].initializer), identifierNode, statements, log, false, true); } else { validateStateStyleSyntax(temp, log); } diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index ee4a482..1732d6c 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -47,8 +47,6 @@ import { COMPONENT_TRANSITION_FUNCTION, COMPONENT_CREATE_FUNCTION, GEOMETRY_VIEW, - BUILDER_ATTR_NAME, - BUILDER_ATTR_BIND, COMPONENT_STYLES_DECORATOR, STYLES, INTERFACE_NAME_SUFFIX, @@ -290,8 +288,7 @@ function processBuildMember(node: ts.MethodDeclaration, context: ts.Transformati }); } const buildNode: ts.MethodDeclaration = processComponentBuild(node, log); - const firstParseBuildNode = ts.visitNode(buildNode, visitBuild); - return ts.visitNode(firstParseBuildNode, visitBuildSecond); + return ts.visitNode(buildNode, visitBuild); function visitBuild(node: ts.Node): ts.Node { if (isGeometryView(node)) { node = processGeometryView(node as ts.ExpressionStatement, log); @@ -309,90 +306,6 @@ function processBuildMember(node: ts.MethodDeclaration, context: ts.Transformati } return ts.visitEachChild(node, visitBuild, context); } - function visitBuildSecond(node: ts.Node): ts.Node { - if (isCustomComponentNode(node) || isCustomBuilderNode(node)) { - return node; - } - if ((ts.isIdentifier(node) || ts.isPropertyAccessExpression(node)) && - validateBuilderFunctionNode(node)) { - return getParsedBuilderAttrArgument(node); - } - return ts.visitEachChild(node, visitBuildSecond, context); - } -} - -function validateBuilderFunctionNode(node: ts.PropertyAccessExpression | ts.Identifier): boolean { - if ((ts.isPropertyAccessExpression(node) && node.expression && node.name && - node.expression.kind === ts.SyntaxKind.ThisKeyword && ts.isIdentifier(node.name) && - CUSTOM_BUILDER_METHOD.has(node.name.escapedText.toString()) || - 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))) { - return true; - } else { - return false; - } -} - -function validateBuilderParam(node: ts.PropertyAccessExpression): boolean { - if (node.parent && ts.isCallExpression(node.parent) && node.parent.expression === node) { - return true; - } else { - return false; - } -} - -function getParsedBuilderAttrArgument(node: ts.PropertyAccessExpression | ts.Identifier): - ts.ObjectLiteralExpression { - let newObjectNode: ts.ObjectLiteralExpression = null; - if (ts.isPropertyAccessExpression(node)) { - newObjectNode = ts.factory.createObjectLiteralExpression([ - ts.factory.createPropertyAssignment( - ts.factory.createIdentifier(BUILDER_ATTR_NAME), - ts.factory.createCallExpression( - ts.factory.createPropertyAccessExpression( - node, - ts.factory.createIdentifier(BUILDER_ATTR_BIND) - ), - undefined, - [ts.factory.createThis()] - ) - ) - ]); - } else if (ts.isIdentifier(node)) { - newObjectNode = ts.factory.createObjectLiteralExpression([ - ts.factory.createPropertyAssignment( - ts.factory.createIdentifier(BUILDER_ATTR_NAME), - node - ) - ]); - } - 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 isCustomBuilderNode(node: ts.ExpressionStatement): boolean { - return ts.isExpressionStatement(node) && node.expression && - // @ts-ignore - node.expression.expression && node.expression.expression.escapedText && - // @ts-ignore - CUSTOM_BUILDER_METHOD.has(node.expression.expression.escapedText.toString()); } function isGeometryView(node: ts.Node): boolean { diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index 148178c..04ee994 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -41,10 +41,10 @@ import { COMPONENT_CONSTRUCTOR_ID, COMPONENT_CONSTRUCTOR_PARENT, COMPONENT_CONSTRUCTOR_PARAMS, - COMPONENT_EXTEND_DECORATOR, COMPONENT_OBSERVED_DECORATOR, STYLES, - VALIDATE_MODULE + VALIDATE_MODULE, + COMPONENT_BUILDER_DECORATOR } from './pre_define'; import { INNER_COMPONENT_NAMES, @@ -54,7 +54,8 @@ import { BUILDIN_STYLE_NAMES, EXTEND_ATTRIBUTE, GLOBAL_STYLE_FUNCTION, - STYLES_ATTRIBUTE + STYLES_ATTRIBUTE, + CUSTOM_BUILDER_METHOD } from './component_map'; import { LogType, @@ -324,6 +325,9 @@ function visitAllNode(node: ts.Node, sourceFileNode: ts.SourceFile, allComponent if (ts.isClassDeclaration(node) && node.name && ts.isIdentifier(node.name)) { collectComponentProps(node); } + if (ts.isMethodDeclaration(node) && hasDecorator(node, COMPONENT_BUILDER_DECORATOR)) { + CUSTOM_BUILDER_METHOD.add(node.name.getText()); + } node.getChildren().forEach((item: ts.Node) => visitAllNode(item, sourceFileNode, allComponentNames, log)); } diff --git a/compiler/test/ut/builder/builderBindPopu.ts b/compiler/test/ut/builder/builderBindPopu.ts new file mode 100644 index 0000000..8869428 --- /dev/null +++ b/compiler/test/ut/builder/builderBindPopu.ts @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +exports.source = ` + +@Entry +@Component +struct Banner { +@Builder textBuilder() { + Text("文本") + .fontSize(30) +} +@Builder NavigationTitle(label:string) { + Column() { + Text(label) + .width(10) + .bindMenu(this.textBuilder) + } +} + build() { + Column() { + Text("111") + .bindMenu(this.NavigationTitle("111")) + } + } +} +` +exports.expectResult = +`class Banner extends View { + constructor(compilerAssignedUniqueChildId, parent, params) { + super(compilerAssignedUniqueChildId, parent); + this.updateWithValueParams(params); + } + updateWithValueParams(params) { + } + aboutToBeDeleted() { + SubscriberManager.Get().delete(this.id()); + } + textBuilder() { + Text.create("文本"); + Text.fontSize(30); + Text.pop(); + } + NavigationTitle(label) { + Column.create(); + Text.create(label); + Text.width(10); + Text.bindMenu({ builder: this.textBuilder.bind(this) }); + Text.pop(); + Column.pop(); + } + render() { + Column.create(); + Text.create("111"); + Text.bindMenu({ builder: () => { + this.NavigationTitle("111"); + } }); + Text.pop(); + Column.pop(); + } +} +loadDocument(new Banner("1", undefined, {})); +` From 8feaab40c67f6b68da4ebbf6f66561939583cd89 Mon Sep 17 00:00:00 2001 From: houhaoyu Date: Tue, 8 Feb 2022 17:39:27 +0800 Subject: [PATCH 28/44] houhaoyu@huawei.com support 427 for Radio.checked Signed-off-by: houhaoyu Change-Id: Ieec61b12c7cd9d805f3f9fdcf137f96bba69e0d6 --- compiler/src/pre_define.ts | 2 ++ compiler/src/process_component_build.ts | 21 ++++++++++++++++----- compiler/src/process_component_class.ts | 6 +++--- compiler/test/ut/syntacticSugar/$$.ts | 8 ++++++++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index a1a29a4..cf2b3c1 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -189,6 +189,8 @@ export const VISUAL_STATE: string = 'visualState'; export const VIEW_STACK_PROCESSOR: string = 'ViewStackProcessor'; export const BIND_POPUP: string = 'bindPopup'; +export const CHECKED: string = 'checked'; +export const RADIO: string = 'Radio'; export const $$_VALUE: string = 'value'; export const $$_CHANGE_EVENT: string = 'changeEvent'; export const $$_THIS: string = '$$this'; diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index c66da17..ee016a4 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -53,6 +53,8 @@ import { $$_CHANGE_EVENT, $$_THIS, $$_NEW_VALUE, + CHECKED, + RADIO, BUILDER_ATTR_NAME, BUILDER_ATTR_BIND, CUSTOM_DIALOG_CONTROLLER_BUILDER @@ -753,12 +755,10 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any, statements, log, false, true, false); } lastStatement.kind = true; - } else if (propName === BIND_POPUP && temp.arguments.length === 2 && - temp.arguments[0].getText().match(/^\$\$(.|\n)+/)) { + } else if (!isStylesAttr && [BIND_POPUP, CHECKED].includes(propName) && + temp.arguments.length && temp.arguments[0] && temp.arguments[0].getText().match(/^\$\$(.|\n)+/)) { const argumentsArr: ts.Expression[] = []; - const varExp: ts.Expression = updateArgumentFor$$(temp.arguments[0]); - argumentsArr.push(generateObjectFor$$(varExp)); - argumentsArr.push(temp.arguments[1]); + classifyArgumentsNum(temp.arguments, argumentsArr, propName, identifierNode); statements.push(ts.factory.createExpressionStatement( createFunction(identifierNode, node, argumentsArr))); lastStatement.kind = true; @@ -779,6 +779,17 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any, } } +function classifyArgumentsNum(args: any, argumentsArr: ts.Expression[], propName: string, + identifierNode: ts.Identifier): void { + if (propName === BIND_POPUP && args.length === 2) { + const varExp: ts.Expression = updateArgumentFor$$(args[0]); + argumentsArr.push(generateObjectFor$$(varExp), args[1]); + } else if (propName === CHECKED && args.length === 1 && identifierNode.getText() === RADIO) { + const varExp: ts.Expression = updateArgumentFor$$(args[0]); + argumentsArr.push(varExp, createArrowFunctionFor$$(varExp)); + } +} + function traverseStylesAttr(node: ts.Node): ts.Node { if (ts.isStringLiteral(node)) { node = ts.factory.createStringLiteral(node.text); diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index 1732d6c..3f464cc 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -481,9 +481,9 @@ function createParamsInitBlock(express: string, statements: ts.Statement[], express === COMPONENT_CONSTRUCTOR_DELETE_PARAMS ? undefined : ts.factory.createIdentifier(CREATE_CONSTRUCTOR_PARAMS), undefined, express === COMPONENT_CONSTRUCTOR_DELETE_PARAMS ? undefined : - ts.factory.createTypeReferenceNode( - ts.factory.createIdentifier(parentComponentName.getText() + INTERFACE_NAME_SUFFIX), undefined), - undefined)], undefined, ts.factory.createBlock(statements, true)); + ts.factory.createTypeReferenceNode( + ts.factory.createIdentifier(parentComponentName.getText() + INTERFACE_NAME_SUFFIX), undefined), + undefined)], undefined, ts.factory.createBlock(statements, true)); return methodDeclaration; } diff --git a/compiler/test/ut/syntacticSugar/$$.ts b/compiler/test/ut/syntacticSugar/$$.ts index ab6d9f7..35c9732 100644 --- a/compiler/test/ut/syntacticSugar/$$.ts +++ b/compiler/test/ut/syntacticSugar/$$.ts @@ -31,6 +31,8 @@ struct HomeComponent { Text(this.value1) Text(this.value2) Text(this.value3) + Radio({value: "Radio", group: "1"}) + .checked($$this.value4) } Row() { Button() { @@ -45,6 +47,8 @@ struct HomeComponent { .fontSize(100) .bindPopup($$value6.item1, {message: "This is $$ for Obj"}) Text(this.value3) + Radio({value: "Radio", group: "1"}) + .checked($$value5[0]) } .width(20) } @@ -91,6 +95,8 @@ class HomeComponent extends View { Text.pop(); Text.create(this.value3); Text.pop(); + Radio.create({ value: "Radio", group: "1" }); + Radio.checked(this.value4, newValue => { this.value4 = newValue; }); Row.pop(); Row.create(); Row.width(20); @@ -109,6 +115,8 @@ class HomeComponent extends View { Text.pop(); Text.create(this.value3); Text.pop(); + Radio.create({ value: "Radio", group: "1" }); + Radio.checked(value5[0], newValue => { value5[0] = newValue; }); Row.pop(); Column.pop(); } From 79efbeaa02720b7541eeeb029915792b811fb388 Mon Sep 17 00:00:00 2001 From: shanshurong Date: Fri, 11 Feb 2022 11:25:02 +0800 Subject: [PATCH 29/44] add trackThickness json for slider Signed-off-by: shanshurong --- compiler/components/slider.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/components/slider.json b/compiler/components/slider.json index 6198264..caf66ef 100644 --- a/compiler/components/slider.json +++ b/compiler/components/slider.json @@ -2,7 +2,7 @@ "name": "Slider", "atomic": true, "attrs": [ - "blockColor", "trackColor", "selectedColor", "minLabel", "maxLabel", "showSteps", "showTips", + "blockColor", "trackColor", "selectedColor", "minLabel", "maxLabel", "showSteps", "showTips", "trackThickness", "onChange" ] -} \ No newline at end of file +} From 485437a3f7db2e575214a575a9615f4466400b64 Mon Sep 17 00:00:00 2001 From: puyajun Date: Fri, 11 Feb 2022 11:57:23 +0800 Subject: [PATCH 30/44] puyajun@huawei.com fix builder bug Signed-off-by: puyajun Change-Id: I12282fdcc6429ca43081c3565e8406f3cbb93d14 --- compiler/src/process_component_build.ts | 12 ++++++++++-- compiler/src/process_component_class.ts | 3 +-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index ee016a4..b5ecb19 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -557,8 +557,7 @@ export function bindComponentAttr(node: ts.ExpressionStatement, identifierNode: function processCustomBuilderProperty(node: ts.CallExpression): ts.CallExpression { const newArguments: ts.Expression[] = []; node.arguments.forEach((argument: ts.Expression | ts.Identifier, index: number) => { - if (index === 0 && (ts.isPropertyAccessExpression(argument) || ts.isCallExpression(argument) || - ts.isIdentifier(argument))) { + if (index === 0 && isBuilderChangeNode(argument)) { newArguments.push(parseBuilderNode(argument)); } else { newArguments.push(argument); @@ -568,6 +567,15 @@ function processCustomBuilderProperty(node: ts.CallExpression): ts.CallExpressio return node; } +function isBuilderChangeNode(argument: ts.Node): boolean { + return (ts.isPropertyAccessExpression(argument) && argument.name && ts.isIdentifier(argument.name) + && CUSTOM_BUILDER_METHOD.has(argument.name.getText())) || + (ts.isCallExpression(argument) && argument.expression && argument.expression.name && + ts.isIdentifier(argument.expression.name) && + CUSTOM_BUILDER_METHOD.has(argument.expression.name.getText())) || (ts.isIdentifier(argument) && + argument.escapedText && CUSTOM_BUILDER_METHOD.has(argument.escapedText.toString())); +} + function parseBuilderNode(node: ts.Node): ts.ObjectLiteralExpression { if (isPropertyAccessExpressionNode(node)) { return processPropertyBuilder(node as ts.PropertyAccessExpression); diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index 3f464cc..9d01a94 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -50,8 +50,7 @@ import { COMPONENT_STYLES_DECORATOR, STYLES, INTERFACE_NAME_SUFFIX, - OBSERVED_PROPERTY_ABSTRACT, - CUSTOM_COMPONENT_EARLIER_CREATE_CHILD + OBSERVED_PROPERTY_ABSTRACT } from './pre_define'; import { BUILDIN_STYLE_NAMES, From 3ddea7eb1662634596840e2bb0d71de462c5ccae Mon Sep 17 00:00:00 2001 From: wzztoone Date: Fri, 11 Feb 2022 16:15:46 +0800 Subject: [PATCH 31/44] add web api Signed-off-by: wzztoone Change-Id: Id8787edb8fac0bc3f9af48a39261106db632bcf0 --- compiler/components/web.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/components/web.json b/compiler/components/web.json index a4fe564..484e60b 100644 --- a/compiler/components/web.json +++ b/compiler/components/web.json @@ -1,5 +1,5 @@ { "name": "Web", "atomic": true, - "attrs": ["onPageEnd", "onRequestSelected", "javaScriptAccess", "fileAccess"] + "attrs": ["onPageEnd", "onPageBegin", "onProgressChange", "onTitleReceive", "onRequestSelected", "javaScriptAccess", "fileAccess"] } \ No newline at end of file From 98c1a2667f2cf3cdc9df1631d35885cf560d3520 Mon Sep 17 00:00:00 2001 From: liujinwei Date: Fri, 11 Feb 2022 16:27:14 +0800 Subject: [PATCH 32/44] add interface into web Signed-off-by: liujinwei Change-Id: I5619e697fe5278c12a23c5d90353cd4cc63c1f48 --- compiler/components/web.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/components/web.json b/compiler/components/web.json index a4fe564..25270ef 100644 --- a/compiler/components/web.json +++ b/compiler/components/web.json @@ -1,5 +1,8 @@ { "name": "Web", "atomic": true, - "attrs": ["onPageEnd", "onRequestSelected", "javaScriptAccess", "fileAccess"] + "attrs": [ + "onPageEnd", "onRequestSelected", "javaScriptAccess", "fileAccess", "onAlert", "onBeforeUnload", + "onConfirm", "onConsole", "onErrorReceive", "onHttpErrorReceive", "onDownloadStart" + ] } \ No newline at end of file From 393517c64c1132d06c22e2cf9a7545feaeea2013 Mon Sep 17 00:00:00 2001 From: yaoyuchi Date: Mon, 14 Feb 2022 11:29:26 +0800 Subject: [PATCH 33/44] add RichText component Signed-off-by: yaoyuchi --- compiler/components/rich_text.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 compiler/components/rich_text.json diff --git a/compiler/components/rich_text.json b/compiler/components/rich_text.json new file mode 100644 index 0000000..cf67685 --- /dev/null +++ b/compiler/components/rich_text.json @@ -0,0 +1,7 @@ +{ + "name": "RichText", + "single": true, + "attrs": [ + "onStart", "onComplete" + ] +} \ No newline at end of file From fdc5a04620bf5e84e91cf9355ea552c82551145c Mon Sep 17 00:00:00 2001 From: wzztoone Date: Mon, 14 Feb 2022 11:04:17 +0800 Subject: [PATCH 34/44] add Web Api Signed-off-by: wzztoone Change-Id: I7442d8ceaa5e7fb99f18c28c97128b44ba95993d --- compiler/components/web.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/components/web.json b/compiler/components/web.json index 18b3ac8..a5a9c8e 100644 --- a/compiler/components/web.json +++ b/compiler/components/web.json @@ -2,7 +2,8 @@ "name": "Web", "atomic": true, "attrs": [ - "onPageEnd", "onPageBegin", "onProgressChange", "onTitleReceive", "onRequestSelected", "javaScriptAccess", "fileAccess", "onAlert", "onBeforeUnload", + "onPageEnd", "onPageBegin", "onProgressChange", "onTitleReceive", "onGeolocationHide", "onGeolocationShow", + "onRequestSelected", "javaScriptAccess", "fileAccess", "onAlert", "onBeforeUnload", "onConfirm", "onConsole", "onErrorReceive", "onHttpErrorReceive", "onDownloadStart" ] } \ No newline at end of file From 762eceaced3b84fba10e0463b3281083ee3f8324 Mon Sep 17 00:00:00 2001 From: houhaoyu Date: Mon, 14 Feb 2022 19:46:40 +0800 Subject: [PATCH 35/44] houhaoyu@huawei.com fix bug of extra type Signed-off-by: houhaoyu Change-Id: Id47c045b1208512ec15dbaddf3d922c9e6ea0299 --- compiler/server/build_pipe_server.js | 2 +- compiler/webpack.config.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/server/build_pipe_server.js b/compiler/server/build_pipe_server.js index a087c32..4d3e8a6 100644 --- a/compiler/server/build_pipe_server.js +++ b/compiler/server/build_pipe_server.js @@ -57,7 +57,7 @@ function handlePluginCompileComponent(jsonData) { const newSource = ts.factory.updateSourceFile(sourceNode, previewStatements); const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed }); const result = printer.printNode(ts.EmitHint.Unspecified, newSource, newSource); - receivedMsg.data.script = result; + receivedMsg.data.script = ts.transpileModule(result, {}).outputText; if (pluginSocket.readyState === WebSocket.OPEN){ responseToPlugin(receivedMsg); } diff --git a/compiler/webpack.config.js b/compiler/webpack.config.js index d9d0cd6..e7fd2e4 100644 --- a/compiler/webpack.config.js +++ b/compiler/webpack.config.js @@ -100,7 +100,7 @@ function initConfig(config) { path.join(projectPath, '../../../../../'), './node_modules', path.join(__dirname, 'node_modules'), - path.join(__dirname, '../../api/common') + path.join(__dirname, '../../api') ] }, stats: { preset: 'none' }, From c38a297477da8706b944d2366a6e100c689e200b Mon Sep 17 00:00:00 2001 From: puyajun Date: Tue, 15 Feb 2022 10:57:39 +0800 Subject: [PATCH 36/44] puyajun@huawei.com fix button a single Signed-off-by: puyajun Change-Id: I598c817aaf58669c7f6321adb36871272e4d9cdd --- compiler/components/button.json | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/components/button.json b/compiler/components/button.json index 385a0d9..545d255 100644 --- a/compiler/components/button.json +++ b/compiler/components/button.json @@ -1,4 +1,5 @@ { "name": "Button", + "single": true, "attrs": ["type", "stateEffect", "fontColor", "fontSize", "fontWeight", "fontStyle", "fontFamily"] } \ No newline at end of file From da4281cae4a7c229be9ce96f37c363e57a3dc4cf Mon Sep 17 00:00:00 2001 From: zhangxiao Date: Tue, 15 Feb 2022 11:26:15 +0800 Subject: [PATCH 37/44] web api Change-Id: I7543d35cc53473448472fe98ae7e7a424a796cb6 Signed-off-by: zhangxiao72 --- compiler/components/web.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/components/web.json b/compiler/components/web.json index a5a9c8e..9d65595 100644 --- a/compiler/components/web.json +++ b/compiler/components/web.json @@ -3,7 +3,8 @@ "atomic": true, "attrs": [ "onPageEnd", "onPageBegin", "onProgressChange", "onTitleReceive", "onGeolocationHide", "onGeolocationShow", - "onRequestSelected", "javaScriptAccess", "fileAccess", "onAlert", "onBeforeUnload", + "onRequestSelected", "javaScriptAccess", "fileAccess", "onAlert", "onBeforeUnload", "onlineImageAccess", + "domStorageAccess", "imageAccess", "mixedMode", "zoomAccess", "geolocationAccess", "javaScriptProxy", "onConfirm", "onConsole", "onErrorReceive", "onHttpErrorReceive", "onDownloadStart" ] } \ No newline at end of file From b760397359b6775f77b94f62b321669772e9656d Mon Sep 17 00:00:00 2001 From: lixingchi1 Date: Tue, 15 Feb 2022 16:56:19 +0800 Subject: [PATCH 38/44] lixingchi1@huawei.com Signed-off-by: lixingchi1 --- compiler/components/web.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/components/web.json b/compiler/components/web.json index 9d65595..4cb5105 100644 --- a/compiler/components/web.json +++ b/compiler/components/web.json @@ -2,6 +2,8 @@ "name": "Web", "atomic": true, "attrs": [ + "password", "cacheMode", "tableData", "wideViewModeAccess", "overviewModeAccess", "textZoomAtio", "databaseAccess", + "onRefreshAccessedHistory", "onUrlLoadIntercept", "onSslErrorReceive", "onRenderExited", "onFileSelectorShow", "onPageEnd", "onPageBegin", "onProgressChange", "onTitleReceive", "onGeolocationHide", "onGeolocationShow", "onRequestSelected", "javaScriptAccess", "fileAccess", "onAlert", "onBeforeUnload", "onlineImageAccess", "domStorageAccess", "imageAccess", "mixedMode", "zoomAccess", "geolocationAccess", "javaScriptProxy", From 529d443192e98ec23d34522991e733f33a9518e9 Mon Sep 17 00:00:00 2001 From: houhaoyu Date: Tue, 15 Feb 2022 17:38:22 +0800 Subject: [PATCH 39/44] houhaoyu@huawei.com fix @Extend bug Signed-off-by: houhaoyu Change-Id: I51d54a87e8af4b506f850eab969ff6f62670ad6f --- compiler/src/process_ui_syntax.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index 61c6442..27a65a0 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -391,7 +391,7 @@ function isPropertyExist(typeChecker: ts.TypeChecker, pos: number, type: ts.Type } else { transformLog.errors.push({ type: LogType.ERROR, - message: `TS2339: Property '${propertyName}' does not exist on type '${componentName}'.`, + message: `TS2339: Property '${propertyName}' does not exist on type '${componentName}Attribute'.`, pos: pos }); } From 6a7187c98a44987c2722221a9fb26ff3911a9a41 Mon Sep 17 00:00:00 2001 From: puyajun Date: Wed, 16 Feb 2022 14:19:32 +0800 Subject: [PATCH 40/44] puyajun@huawei.com fix tab_content only have one compont Signed-off-by: puyajun Change-Id: I08fabde4148bdbb296e15b6e11817e79b85f5a00 --- compiler/components/tab_content.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/components/tab_content.json b/compiler/components/tab_content.json index e0beff0..5592200 100644 --- a/compiler/components/tab_content.json +++ b/compiler/components/tab_content.json @@ -1,5 +1,6 @@ { "name": "TabContent", "parents": ["Tabs"], - "attrs": ["tabBar"] + "attrs": ["tabBar"], + "single": true } \ No newline at end of file From 4e526a4d3e08bcff41f62e36b11f51373d509b13 Mon Sep 17 00:00:00 2001 From: houhaoyu Date: Wed, 16 Feb 2022 16:39:28 +0800 Subject: [PATCH 41/44] houhaoyu@huawei.com change logic of @Entry&@Preview Signed-off-by: houhaoyu Change-Id: Ic2c994ed6dce60d765f9d702e2442b1a015d60d1 --- compiler/src/validate_ui_syntax.ts | 9 +++++---- compiler/webpack.config.js | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index 04ee994..5dd4474 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -190,14 +190,15 @@ function checkComponentDecorator(source: string, filePath: string, BUILDIN_STYLE_NAMES.add(item.name.getText()); } }); - validateEntryAndPreviewCount(result, fileQuery, sourceFile.fileName, projectConfig.isPreview, log); + validateEntryAndPreviewCount(result, fileQuery, sourceFile.fileName, projectConfig.isPreview, + !!projectConfig.checkEntry, log); } return log.length ? log : null; } function validateEntryAndPreviewCount(result: DecoratorResult, fileQuery: string, - fileName: string, isPreview: boolean, log: LogInfo[]): void { + fileName: string, isPreview: boolean, checkEntry: boolean, log: LogInfo[]): void { if (result.previewCount > 10 && fileQuery === '?entry') { log.push({ type: LogType.ERROR, @@ -212,7 +213,7 @@ function validateEntryAndPreviewCount(result: DecoratorResult, fileQuery: string fileName: fileName }); } - if (isPreview && result.previewCount < 1 && result.entryCount !== 1 && + if (isPreview && !checkEntry && result.previewCount < 1 && result.entryCount !== 1 && fileQuery === '?entry') { log.push({ type: LogType.ERROR, @@ -220,7 +221,7 @@ function validateEntryAndPreviewCount(result: DecoratorResult, fileQuery: string + `decorator, or at least one '@Preview' decorator.`, fileName: fileName }); - } else if (!isPreview && result.entryCount !== 1 && fileQuery === '?entry') { + } else if ((!isPreview || isPreview && checkEntry) && result.entryCount !== 1 && fileQuery === '?entry') { log.push({ type: LogType.ERROR, message: `A page configured in 'config.json' must have one and only one '@Entry' ` diff --git a/compiler/webpack.config.js b/compiler/webpack.config.js index e7fd2e4..56cdbd9 100644 --- a/compiler/webpack.config.js +++ b/compiler/webpack.config.js @@ -242,6 +242,7 @@ module.exports = (env, argv) => { } } else { projectConfig.isPreview = true; + projectConfig.checkEntry = env.checkEntry; let port; process.argv.forEach((val, index) => { if(val.startsWith('port=')){ From e51959f83b1dea09bf68df7ce71d7c471ff35cd6 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Wed, 16 Feb 2022 17:17:29 +0800 Subject: [PATCH 42/44] laibo2@huawei.com Signed-off-by: laibo102 Change-Id: Iddce68f30eb594e6cae18642f5171077860a932b --- compiler/src/pre_define.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index cf2b3c1..f166b9c 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -17,7 +17,7 @@ import path from 'path'; export const NATIVE_MODULE: Set = new Set( ['system.app', 'ohos.app', 'system.router', 'system.curves', 'ohos.curves', 'system.matrix4', 'ohos.matrix4']); -export const VALIDATE_MODULE: string[] = ['application', 'util']; +export const VALIDATE_MODULE: string[] = ['application', 'util', 'screen']; export const SYSTEM_PLUGIN: string = 'system'; export const OHOS_PLUGIN: string = 'ohos'; From eb2c84359b439fe182f802895a4f1a7aee7a1191 Mon Sep 17 00:00:00 2001 From: yaoyuchi Date: Thu, 17 Feb 2022 16:43:26 +0800 Subject: [PATCH 43/44] delete textclock status property Signed-off-by: yaoyuchi --- compiler/components/text_clock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/components/text_clock.json b/compiler/components/text_clock.json index 3b23350..c139319 100644 --- a/compiler/components/text_clock.json +++ b/compiler/components/text_clock.json @@ -1,7 +1,7 @@ { "name": "TextClock", "attrs": [ - "format", "onDateChange", "status", "fontColor", + "format", "onDateChange", "fontColor", "fontSize", "fontStyle", "fontWeight", "fontFamily" ] -} \ No newline at end of file +} From e45664dc3341f1fad04f9988a2c808e24bafb5d3 Mon Sep 17 00:00:00 2001 From: houhaoyu Date: Mon, 21 Feb 2022 18:26:35 +0800 Subject: [PATCH 44/44] houhaoyu@huawei.com change position of ts attr Signed-off-by: houhaoyu Change-Id: Ia611eedf95425e665a939681aed1b726b4d5c01c --- compiler/build_declarations_file.js | 33 ++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/compiler/build_declarations_file.js b/compiler/build_declarations_file.js index 3e2e53d..41d982b 100644 --- a/compiler/build_declarations_file.js +++ b/compiler/build_declarations_file.js @@ -17,10 +17,24 @@ const ts = require('typescript') const path = require('path') const fs = require('fs') +const addTSInterfaceSet = ['ForEach', 'LazyForEach', 'TapGesture', 'LongPressGesture', 'LongPressGesture', + 'PanGesture', 'SwipeGesture', 'PinchGesture', 'RotationGesture', 'GestureGroup','PageTransitionEnter', + 'PageTransitionExit']; +const addTSAttributeSet = ['AlphabetIndexer', 'Animator', 'Badge', 'Blank', 'Button', 'Calendar', 'Canvas', + 'Checkbox', 'CheckboxGroup', 'Circle', 'Column', 'ColumnSplit', 'Counter', 'DataPanel', 'DatePicker', + 'Divider', 'Ellipse', 'Flex', 'FormComponent', 'Gauge', 'Grid', 'GridItem', 'GridContainer', 'Image', + 'ImageAnimator', 'Line', 'List', 'ListItem', 'LoadingProgress', 'Marquee', 'Navigation', 'Navigator', + 'Panel', 'Path', 'PatternLock', 'Piece', 'PluginComponent', 'Polygon', 'Polyline', 'Progress', + 'QRCode', 'Radio', 'Rating', 'Rect', 'Refresh', 'Row', 'RowSplit', 'Scroll', 'ScrollBar', 'Search', + 'Select', 'Shape', 'Sheet', 'Slider', 'Span', 'Stack', 'Stepper', 'StepperItem', 'Swiper', + 'TabContent', 'Tabs', 'Text', 'TextArea', 'TextClock', 'TextInput', 'TextPicker', 'TextTimer', + 'Toggle', 'Video', 'Web', 'XComponent', 'RichText']; + generateTargetFile(process.argv[2], process.argv[3]); function generateTargetFile(filePath, output) { const files = []; const globalTsFile = path.resolve(filePath, '../../global.d.ts'); + const middleTsFile = path.resolve(filePath, 'middle_class.d.ts'); if (fs.existsSync(globalTsFile)) { files.push(globalTsFile); } @@ -47,7 +61,7 @@ function generateTargetFile(filePath, output) { const fileName = path.resolve(output, path.basename(item)); if (item === globalTsFile) { content = license + '\n\n' + processsFile(content, fileName, true); - } else { + } else if (path.resolve(item) !== middleTsFile) { content = license + '\n\n' + processsFile(content, fileName, false); } fs.writeFile(fileName, content, err => { @@ -127,6 +141,18 @@ function processComponent(node, newStatements) { node = ts.factory.updateInterfaceDeclaration(node, node.decorators, node.modifiers, node.name, node.typeParameters, [heritageClause], node.members); } + if (addTSInterfaceSet.includes(componentName)) { + node = ts.factory.updateInterfaceDeclaration(node, node.decorators, node.modifiers, node.name, + node.typeParameters, [ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, + [ts.factory.createExpressionWithTypeArguments(ts.factory.createIdentifier('TS' + componentName + 'Interface'), + undefined)])], node.members); + } + } + if (isClass(node) && addTSAttributeSet.includes(node.name.getText().replace(/Attribute$/, ''))) { + node = ts.factory.updateClassDeclaration(node, node.decorators, node.modifiers, node.name, + node.typeParameters, [ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, + [ts.factory.createExpressionWithTypeArguments(ts.factory.createIdentifier('TS' + node.name.getText()), + undefined)])], node.members); } newStatements.push(node); } @@ -164,6 +190,11 @@ function isInterface(node) { /Interface$/.test(node.name.getText()); } +function isClass(node) { + return ts.isClassDeclaration(node) && node.name && ts.isIdentifier(node.name) && + /Attribute$/.test(node.name.getText()); +} + function isSignNode(node) { return (ts.isCallSignatureDeclaration(node) || ts.isConstructSignatureDeclaration(node)) && node.type && ts.isTypeReferenceNode(node.type) && node.type.typeName && ts.isIdentifier(node.type.typeName) &&