From c77386ecd88532ea16c39c99da49f0c176d8f400 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Mon, 25 Jul 2022 07:49:46 +0000 Subject: [PATCH 01/33] !1 Update inner_struct_state transform * Update: inner_struct_state transform (cherry picked from commit 7d02cf5e0fac5783deee367d293c7654906bd924) Signed-off-by: laibo102 --- compiler/main.js | 1 + compiler/src/pre_define.ts | 16 ++ compiler/src/process_component_class.ts | 169 +++++++++++++++++- compiler/src/process_component_constructor.ts | 65 +++++-- compiler/src/process_component_member.ts | 107 ++++++++++- compiler/test/test.js | 6 +- .../@link/@link.ts | 125 +++++++++++++ .../@prop/@prop.ts | 127 +++++++++++++ .../@state/@state.ts | 73 ++++++++ 9 files changed, 662 insertions(+), 27 deletions(-) create mode 100644 compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts create mode 100644 compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts create mode 100644 compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts diff --git a/compiler/main.js b/compiler/main.js index d9de016..cd83906 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -443,3 +443,4 @@ exports.loadModuleInfo = loadModuleInfo; exports.systemModules = systemModules; exports.checkAppResourcePath = checkAppResourcePath; exports.addSDKBuildDependencies = addSDKBuildDependencies; +exports.compatibleSdkVersion = '8'; \ No newline at end of file diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 6dd695a..46da357 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -275,3 +275,19 @@ export const ES2ABC: string = 'es2abc'; export const GENERATE_ID = 'generateId'; export const _GENERATE_ID = '__generate__Id'; + +export const COMPONENT_CONSTRUCTOR_INITIAL_PARAMS: string = 'setInitiallyProvidedValue'; +export const COMPONENT_RERENDER_FUNCTION: string = 'rerender'; +export const SETONEWAYSYNCPROPERTIESUNCHANGED: string = 'setOneWaySyncPropertiesUnchanged'; +export const SETTWOWAYSYNCPROPERTIESUNCHANGED: string = 'setTwoWaySyncPropertiesUnchanged'; +export const COMPONENT_CONSTRUCTOR_SET_STATE_UNCHANGED: string = 'setStateSourcePropertiesUnchanged'; +export const COMPONENT_CONSTRUCTOR_PURGE_VARIABLE_DEP: string = 'purgeVariableDependenciesOnElmtId'; +export const MARKDEPENDENTELEMENTSDIRTY: string = 'markDependentElementsDirty'; +export const ABOUT_TO_BE_DELETE_FUNCTION_ID__: string = 'id__'; +export const RMELMTID: string = 'rmElmtId'; +export const PURGEDEPENDENCYONELMTID: string = 'purgeDependencyOnElmtId'; +export const SETPROPERTYUNCHANGED: string = 'SetPropertyUnchanged'; +export const ABOUTTOBEDELETEDINTERNAL: string = 'aboutToBeDeletedInternal'; +export const UPDATEDIRTYELEMENTS: string ='updateDirtyElements'; +export const BASICDECORATORS: Set = new Set([COMPONENT_STATE_DECORATOR, COMPONENT_PROP_DECORATOR, + COMPONENT_LINK_DECORATOR]); diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index 6cf0021..d9291a8 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -33,10 +33,14 @@ import { BASE_COMPONENT_NAME, CREATE_CONSTRUCTOR_PARAMS, COMPONENT_CONSTRUCTOR_UPDATE_PARAMS, + COMPONENT_CONSTRUCTOR_INITIAL_PARAMS, + COMPONENT_CONSTRUCTOR_SET_STATE_UNCHANGED, + COMPONENT_CONSTRUCTOR_PURGE_VARIABLE_DEP, COMPONENT_CONSTRUCTOR_DELETE_PARAMS, COMPONENT_DECORATOR_PREVIEW, CREATE_CONSTRUCTOR_SUBSCRIBER_MANAGER, ABOUT_TO_BE_DELETE_FUNCTION_ID, + ABOUT_TO_BE_DELETE_FUNCTION_ID__, CREATE_CONSTRUCTOR_GET_FUNCTION, CREATE_CONSTRUCTOR_DELETE_FUNCTION, FOREACH_OBSERVED_OBJECT, @@ -58,7 +62,13 @@ import { CUSTOM_COMPONENT, COMPONENT_CONSTRUCTOR_PARENT, COMPONENT_IF_UNDEFINED, - INNER_COMPONENT_MEMBER_DECORATORS + INNER_COMPONENT_MEMBER_DECORATORS, + COMPONENT_RERENDER_FUNCTION, + SETONEWAYSYNCPROPERTIESUNCHANGED, + SETTWOWAYSYNCPROPERTIESUNCHANGED, + RMELMTID, + ABOUTTOBEDELETEDINTERNAL, + UPDATEDIRTYELEMENTS } from './pre_define'; import { BUILDIN_STYLE_NAMES, @@ -72,7 +82,8 @@ import { componentCollection, linkCollection, localStorageLinkCollection, - localStoragePropCollection + localStoragePropCollection, + propCollection } from './validate_ui_syntax'; import { addConstructor, @@ -96,6 +107,7 @@ import { LogInfo, hasDecorator } from './utils'; +import { compatibleSdkVersion } from '../main'; export function processComponentClass(node: ts.StructDeclaration, context: ts.TransformationContext, log: LogInfo[], program: ts.Program): ts.ClassDeclaration { @@ -130,6 +142,11 @@ function processMembers(members: ts.NodeArray, parentComponentN const newMembers: ts.ClassElement[] = []; const watchMap: Map = new Map(); const updateParamsStatements: ts.Statement[] = []; + const setStateUnchangedStatements: ts.Statement[] = []; + const setOneWayUnchangedStatements: ts.Statement[] = []; + const setTwoWayUnchangedStatements: ts.Statement[] = []; + const purgeVariableDepStatements: ts.Statement[] = []; + const rerenderStatements: ts.Statement[] = []; const deleteParamsStatements: ts.PropertyDeclaration[] = []; const checkController: ControllerType = { hasController: !componentCollection.customDialogs.has(parentComponentName.getText()) }; @@ -169,6 +186,8 @@ function processMembers(members: ts.NodeArray, parentComponentN newMembers.push(result.getControllerSet()); } } + processPropertyUnchanged(result, setStateUnchangedStatements, setOneWayUnchangedStatements, + setTwoWayUnchangedStatements, purgeVariableDepStatements, rerenderStatements); } if (ts.isMethodDeclaration(item) && item.name) { updateItem = @@ -182,7 +201,8 @@ function processMembers(members: ts.NodeArray, parentComponentN validateBuildMethodCount(buildCount, parentComponentName, log); validateHasController(parentComponentName, checkController, log); newMembers.unshift(addDeleteParamsFunc(deleteParamsStatements)); - newMembers.unshift(addUpdateParamsFunc(updateParamsStatements, parentComponentName)); + addIntoNewMembers(newMembers, parentComponentName, updateParamsStatements, setStateUnchangedStatements, + setOneWayUnchangedStatements, setTwoWayUnchangedStatements, purgeVariableDepStatements, rerenderStatements); newMembers.unshift(addConstructor(ctorNode, watchMap, parentComponentName)); return newMembers; } @@ -202,6 +222,58 @@ function validateDecorators(item: ts.ClassElement, log: LogInfo[]): void { } } +function processPropertyUnchanged( + result: UpdateResult, + setStateUnchangedStatements: ts.Statement[], + setOneWayUnchangedStatements: ts.Statement[], + setTwoWayUnchangedStatements: ts.Statement[], + purgeVariableDepStatements: ts.Statement[], + rerenderStatements: ts.Statement[] +): void { + if (compatibleSdkVersion === '9') { + if(result.getPropertyUnchanged()) { + const propertyUnchanged: ts.Statement = result.getPropertyUnchanged(); + if (result.getDecoratorName() === COMPONENT_STATE_DECORATOR) { + setStateUnchangedStatements.push(propertyUnchanged); + } else if (result.getDecoratorName() === COMPONENT_PROP_DECORATOR) { + setOneWayUnchangedStatements.push(propertyUnchanged); + } else if(result.getDecoratorName() === COMPONENT_LINK_DECORATOR) { + setTwoWayUnchangedStatements.push(propertyUnchanged); + } + } + if(result.getPurgeVariableDepStatement()) { + purgeVariableDepStatements.push(result.getPurgeVariableDepStatement()); + } + if(result.getRerenderStatement()) { + rerenderStatements.push(result.getRerenderStatement()); + } + } +} + +function addIntoNewMembers( + newMembers: ts.ClassElement[], + parentComponentName: ts.Identifier, + updateParamsStatements: ts.Statement[], + setStateUnchangedStatements: ts.Statement[], + setOneWayUnchangedStatements: ts.Statement[], + setTwoWayUnchangedStatements: ts.Statement[], + purgeVariableDepStatements: ts.Statement[], + rerenderStatements: ts.Statement[] +): void { + if (compatibleSdkVersion === '9') { + newMembers.unshift( + addInitialParamsFunc(updateParamsStatements, parentComponentName), + createStateUnchangedFunc(setStateUnchangedStatements), + createOneWaySyncUnchangedFunc(setOneWayUnchangedStatements), + createTwoWaySyncUnchangedFunc(setTwoWayUnchangedStatements), + addPurgeVariableDepFunc(purgeVariableDepStatements) + ); + newMembers.push(addRerenderFunc(rerenderStatements)); + } else { + newMembers.unshift(addUpdateParamsFunc(updateParamsStatements, parentComponentName)); + } +} + function addPropertyMember(item: ts.ClassElement, newMembers: ts.ClassElement[], program: ts.Program, parentComponentName: string, log: LogInfo[]): void { const propertyItem: ts.PropertyDeclaration = item as ts.PropertyDeclaration; @@ -475,6 +547,7 @@ function judgmentParentType(node: ts.Node): boolean { export function createReference(node: ts.PropertyAssignment, log: LogInfo[]): ts.PropertyAssignment { const linkParentComponent: string[] = getParentNode(node, linkCollection).slice(1); + const propParentComponent: string[] = getParentNode(node, propCollection).slice(1); const propertyName: ts.Identifier = node.name as ts.Identifier; let initText: string; const LINK_REG: RegExp = /^\$/g; @@ -492,6 +565,9 @@ export function createReference(node: ts.PropertyAssignment, log: LogInfo[]): ts pos: initExpression.getStart() }); } + } else if (compatibleSdkVersion === '9' && isMatchInitExpression(initExpression) && + propParentComponent.includes(propertyName.escapedText.toString())) { + initText = initExpression.name.escapedText.toString(); } if (initText) { node = addDoubleUnderline(node, propertyName, initText); @@ -539,15 +615,49 @@ function addUpdateParamsFunc(statements: ts.Statement[], parentComponentName: ts return createParamsInitBlock(COMPONENT_CONSTRUCTOR_UPDATE_PARAMS, statements, parentComponentName); } +function addInitialParamsFunc(statements: ts.Statement[], parentComponentName: ts.Identifier): ts.MethodDeclaration { + return createParamsInitBlock(COMPONENT_CONSTRUCTOR_INITIAL_PARAMS, statements, parentComponentName); +} + +function createStateUnchangedFunc(statements: ts.Statement[]): ts.MethodDeclaration { + return ts.factory.createMethodDeclaration(undefined, undefined, undefined, + ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_SET_STATE_UNCHANGED), undefined, undefined, [], undefined, + ts.factory.createBlock(statements, true)); +} + +// @Prop +function createOneWaySyncUnchangedFunc(statements: ts.Statement[]): ts.MethodDeclaration { + return ts.factory.createMethodDeclaration(undefined, undefined, undefined, + ts.factory.createIdentifier(SETONEWAYSYNCPROPERTIESUNCHANGED), undefined, undefined, [], + undefined, ts.factory.createBlock(statements, true)); +} + +// @Link +function createTwoWaySyncUnchangedFunc(statements: ts.Statement[]): ts.MethodDeclaration { + return ts.factory.createMethodDeclaration( + undefined, undefined, undefined, ts.factory.createIdentifier(SETTWOWAYSYNCPROPERTIESUNCHANGED), + undefined, undefined, [], undefined, ts.factory.createBlock(statements, true)); +} + +function addPurgeVariableDepFunc(statements: ts.Statement[]): ts.MethodDeclaration { + return ts.factory.createMethodDeclaration( + undefined, undefined, undefined, + ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PURGE_VARIABLE_DEP), + undefined, undefined, [ts.factory.createParameterDeclaration(undefined, undefined, undefined, + ts.factory.createIdentifier(RMELMTID), undefined, undefined, undefined)], undefined, + ts.factory.createBlock(statements, true)); +} + function addDeleteParamsFunc(statements: ts.PropertyDeclaration[]): ts.MethodDeclaration { const deleteStatements: ts.ExpressionStatement[] = []; statements.forEach((statement: ts.PropertyDeclaration) => { const name: ts.Identifier = statement.name as ts.Identifier; - const paramsStatement: ts.ExpressionStatement = ts.factory.createExpressionStatement( - ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression( - ts.factory.createPropertyAccessExpression(ts.factory.createThis(), - ts.factory.createIdentifier(`__${name.escapedText.toString()}`)), - ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_DELETE_PARAMS)), undefined, [])); + let paramsStatement: ts.ExpressionStatement; + if (compatibleSdkVersion === '9' && !statement.decorators) { + paramsStatement = createParamsStatement(name); + } else { + paramsStatement = createParamsWithUnderlineStatement(name); + } deleteStatements.push(paramsStatement); }); const defaultStatement: ts.ExpressionStatement = @@ -558,14 +668,55 @@ function addDeleteParamsFunc(statements: ts.PropertyDeclaration[]): ts.MethodDec ts.factory.createIdentifier(CREATE_CONSTRUCTOR_GET_FUNCTION)), undefined, []), ts.factory.createIdentifier(CREATE_CONSTRUCTOR_DELETE_FUNCTION)), undefined, [ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression( - ts.factory.createThis(), ts.factory.createIdentifier(ABOUT_TO_BE_DELETE_FUNCTION_ID)), + ts.factory.createThis(), ts.factory.createIdentifier( + compatibleSdkVersion === '8' ? + ABOUT_TO_BE_DELETE_FUNCTION_ID : ABOUT_TO_BE_DELETE_FUNCTION_ID__)), undefined, [])])); deleteStatements.push(defaultStatement); + if (compatibleSdkVersion === '9') { + const aboutToBeDeletedInternalStatement: ts.ExpressionStatement = createDeletedInternalStatement(); + deleteStatements.push(aboutToBeDeletedInternalStatement); + } const deleteParamsMethod: ts.MethodDeclaration = createParamsInitBlock(COMPONENT_CONSTRUCTOR_DELETE_PARAMS, deleteStatements); return deleteParamsMethod; } +function createParamsStatement(name: ts.Identifier): ts.ExpressionStatement { + return ts.factory.createExpressionStatement(ts.factory.createBinaryExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createThis(), + ts.factory.createIdentifier(`${name.escapedText.toString()}`) + ), + ts.factory.createToken(ts.SyntaxKind.EqualsToken), + ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_UNDEFINED) + )); +} + +function createParamsWithUnderlineStatement(name: ts.Identifier): ts.ExpressionStatement { + return ts.factory.createExpressionStatement( + ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression( + ts.factory.createPropertyAccessExpression(ts.factory.createThis(), + ts.factory.createIdentifier(`__${name.escapedText.toString()}`)), + ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_DELETE_PARAMS)), undefined, [])); +} + +function createDeletedInternalStatement(): ts.ExpressionStatement { + return ts.factory.createExpressionStatement(ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression(ts.factory.createThis(), + ts.factory.createIdentifier(ABOUTTOBEDELETEDINTERNAL)), undefined, [])); +} + +function addRerenderFunc(statements: ts.Statement[]): ts.MethodDeclaration { + let updateDirtyElementStatement: ts.Statement = ts.factory.createExpressionStatement( + ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression( + ts.factory.createThis(), ts.factory.createIdentifier(UPDATEDIRTYELEMENTS)), undefined, [])); + statements.push(updateDirtyElementStatement); + return ts.factory.createMethodDeclaration(undefined, undefined, undefined, + ts.factory.createIdentifier(COMPONENT_RERENDER_FUNCTION), undefined, undefined, [], undefined, + ts.factory.createBlock(statements, true)); +} + function createParamsInitBlock(express: string, statements: ts.Statement[], parentComponentName?: ts.Identifier): ts.MethodDeclaration { const methodDeclaration: ts.MethodDeclaration = ts.factory.createMethodDeclaration(undefined, diff --git a/compiler/src/process_component_constructor.ts b/compiler/src/process_component_constructor.ts index 5b04845..53ffde2 100644 --- a/compiler/src/process_component_constructor.ts +++ b/compiler/src/process_component_constructor.ts @@ -20,6 +20,7 @@ import { COMPONENT_CONSTRUCTOR_PARENT, COMPONENT_CONSTRUCTOR_PARAMS, COMPONENT_CONSTRUCTOR_UPDATE_PARAMS, + COMPONENT_CONSTRUCTOR_INITIAL_PARAMS, COMPONENT_WATCH_FUNCTION, BASE_COMPONENT_NAME, INTERFACE_NAME_SUFFIX, @@ -31,6 +32,8 @@ import { localStoragePropCollection } from './validate_ui_syntax'; +import { compatibleSdkVersion } from '../main'; + export function getInitConstructor(members: ts.NodeArray, parentComponentName: ts.Identifier ): ts.ConstructorDeclaration { let ctorNode: any = members.find(item => { @@ -83,9 +86,16 @@ function initConstructorParams(node: ts.ConstructorDeclaration, parentComponentN } const localStorageNum: number = localStorageLinkCollection.get(parentComponentName.getText()).size + localStoragePropCollection.get(parentComponentName.getText()).size; - const paramNames: Set = new Set([COMPONENT_CONSTRUCTOR_ID, COMPONENT_CONSTRUCTOR_PARENT, - COMPONENT_CONSTRUCTOR_PARAMS, localStorageNum ? COMPONENT_CONSTRUCTOR_LOCALSTORAGE : - COMPONENT_CONSTRUCTOR_PARAMS]); + const paramNames: Set = compatibleSdkVersion === "8" ? new Set([ + COMPONENT_CONSTRUCTOR_ID, + COMPONENT_CONSTRUCTOR_PARENT, + COMPONENT_CONSTRUCTOR_PARAMS, + localStorageNum ? COMPONENT_CONSTRUCTOR_LOCALSTORAGE : COMPONENT_CONSTRUCTOR_PARAMS + ]) : new Set([ + COMPONENT_CONSTRUCTOR_PARENT, + COMPONENT_CONSTRUCTOR_PARAMS, + localStorageNum ? COMPONENT_CONSTRUCTOR_LOCALSTORAGE : COMPONENT_CONSTRUCTOR_PARAMS + ]); const newParameters: ts.ParameterDeclaration[] = Array.from(node.parameters); if (newParameters.length !== 0) { // @ts-ignore @@ -154,19 +164,42 @@ export function addConstructor(ctorNode: any, watchMap: Map, )); watchStatements.push(watchNode); }); - const callSuperStatement: ts.Statement = ts.factory.createExpressionStatement( - ts.factory.createCallExpression(ts.factory.createSuper(), undefined, - localStorageNum ? - [ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_ID), - ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT), - ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_LOCALSTORAGE)] : - [ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_ID), - ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT)] - )); - const updateWithValueParamsStatement: ts.Statement = ts.factory.createExpressionStatement( - ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression( - ts.factory.createThis(), ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_UPDATE_PARAMS)), - undefined, [ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARAMS)])); + const callSuperStatement: ts.Statement = createCallSuperStatement(localStorageNum); + const updateWithValueParamsStatement: ts.Statement = createUPdWithValStatement(); return updateConstructor(updateConstructor(ctorNode, [], [callSuperStatement], true), [], [...watchStatements, updateWithValueParamsStatement], false, true, parentComponentName); } + +function createCallSuperStatement(localStorageNum: number): ts.Statement{ + if (compatibleSdkVersion === '8') { + return ts.factory.createExpressionStatement(ts.factory.createCallExpression( + ts.factory.createSuper(), undefined, + localStorageNum ? [ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_ID), + ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT), + ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_LOCALSTORAGE)] : + [ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_ID), + ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT)])); + } else { + return (ts.factory.createExpressionStatement( + ts.factory.createCallExpression(ts.factory.createSuper(), undefined, + localStorageNum ? [ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT), + ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_LOCALSTORAGE)] : + [ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT)]))); + } +} + +// create updateWithValueParamsStatement +function createUPdWithValStatement(): ts.Statement { + return ts.factory.createExpressionStatement( + ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createThis(), + ts.factory.createIdentifier( + compatibleSdkVersion === '8' ? COMPONENT_CONSTRUCTOR_UPDATE_PARAMS : COMPONENT_CONSTRUCTOR_INITIAL_PARAMS + ) + ), + undefined, + [ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARAMS)] + ) + ); +} \ No newline at end of file diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index e1461c5..8ee76b0 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -55,7 +55,12 @@ import { COMPONENT_LOCAL_STORAGE_PROP_DECORATOR, COMPONENT_CONSTRUCTOR_PARENT, EXTNAME_ETS, - _GENERATE_ID + _GENERATE_ID, + MARKDEPENDENTELEMENTSDIRTY, + RMELMTID, + PURGEDEPENDENCYONELMTID, + SETPROPERTYUNCHANGED, + BASICDECORATORS } from './pre_define'; import { forbiddenUseStateType, @@ -81,6 +86,8 @@ import { import { transformLog } from './process_ui_syntax'; import { globalProgram, projectConfig } from '../main'; +import { compatibleSdkVersion } from '../main'; + export type ControllerType = { hasController: boolean } @@ -129,6 +136,10 @@ export class UpdateResult { private updateParams: ts.Statement; private deleteParams: boolean = false; private controllerSet: ts.MethodDeclaration; + private propertyUnchanged: ts.Statement; + private purgeVariableDepStatement: ts.Statement; + private rerenderStatement: ts.Statement; + private decoratorName: string; public setProperity(updateItem: ts.PropertyDeclaration) { this.itemUpdate = true; @@ -164,6 +175,22 @@ export class UpdateResult { this.deleteParams = deleteParams; } + public setPropertyUnchanged(propertyUnchanged: ts.Statement) { + this.propertyUnchanged = propertyUnchanged; + } + + public setPurgeVariableDepStatement(purgeVariableDepStatement: ts.Statement) { + this.purgeVariableDepStatement = purgeVariableDepStatement; + } + + public setRerenderStatement(rerenderStatement: ts.Statement) { + this.rerenderStatement = rerenderStatement; + } + + public setDecoratorName(decoratorName: string) { + this.decoratorName = decoratorName; + } + public isItemUpdate(): boolean { return this.itemUpdate; } @@ -184,6 +211,18 @@ export class UpdateResult { return this.updateParams; } + public getPropertyUnchanged(): ts.Statement { + return this.propertyUnchanged; + } + + public getPurgeVariableDepStatement(): ts.Statement { + return this.purgeVariableDepStatement; + } + + public getRerenderStatement(): ts.Statement { + return this.rerenderStatement; + } + public getVariableGet(): ts.GetAccessorDeclaration { return this.variableGet; } @@ -192,6 +231,10 @@ export class UpdateResult { return this.variableSet; } + public getDecoratorName(): string { + return this.decoratorName; + } + public isDeleteParams(): boolean { return this.deleteParams; } @@ -213,6 +256,9 @@ export function processMemberVariableDecorators(parentName: ts.Identifier, createVariableInitStatement(item, COMPONENT_NON_DECORATOR, log, program, context, hasPreview, interfaceNode)])); updateResult.setControllerSet(createControllerSet(item, parentName, name, checkController)); + if (compatibleSdkVersion === '9') { + updateResult.setDeleteParams(true); + } } else if (!item.type) { validatePropertyNonType(name, log); return updateResult; @@ -317,6 +363,61 @@ function processStateDecorators(node: ts.PropertyDeclaration, decorator: string, if (setUpdateParamsDecorators.has(decorator)) { updateResult.setUpdateParams(createUpdateParams(name, decorator)); } + if (compatibleSdkVersion === '9' && BASICDECORATORS.has(decorator)) { + const variableWithUnderLink: string = '__' + name.escapedText.toString(); + updateResult.setPropertyUnchanged(createPropertyUnchangedStatement(variableWithUnderLink)); + updateResult.setDecoratorName(decorator); + updateResult.setPurgeVariableDepStatement(createPurgeVariableDepStatement(variableWithUnderLink)); + updateResult.setRerenderStatement(createRerenderStatement(variableWithUnderLink)); + } +} + +function createPropertyUnchangedStatement(variableWithUnderLink: string): ts.Statement { + return ts.factory.createExpressionStatement( + ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createThis(), + ts.factory.createIdentifier(variableWithUnderLink) + ), + ts.factory.createIdentifier(SETPROPERTYUNCHANGED) + ), + undefined, + [] + ) + ); +} + +function createPurgeVariableDepStatement(variableWithUnderLink: string): ts.Statement { + return ts.factory.createExpressionStatement( + ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createThis(), + ts.factory.createIdentifier(variableWithUnderLink) + ), + ts.factory.createIdentifier(PURGEDEPENDENCYONELMTID) + ), + undefined, + [ts.factory.createIdentifier(RMELMTID)] + ) + ); +} + +function createRerenderStatement(variableWithUnderLink: string): ts.Statement { + return ts.factory.createExpressionStatement( + ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createThis(), + ts.factory.createIdentifier(variableWithUnderLink) + ), + ts.factory.createIdentifier(MARKDEPENDENTELEMENTSDIRTY) + ), + undefined, + [ts.factory.createThis()] + ) + ); } function processWatch(node: ts.PropertyDeclaration, decorator: ts.Decorator, @@ -422,6 +523,10 @@ function createUpdateParams(name: ts.Identifier, decorator: string): ts.Statemen updateParamsNode = createUpdateParamsWithIf(name); break; case COMPONENT_PROP_DECORATOR: + if (compatibleSdkVersion === '8') { + updateParamsNode = createUpdateParamsWithoutIf(name); + } + break; case COMPONENT_BUILDERPARAM_DECORATOR: updateParamsNode = createUpdateParamsWithoutIf(name); break; diff --git a/compiler/test/test.js b/compiler/test/test.js index 0595536..4bb9b6f 100644 --- a/compiler/test/test.js +++ b/compiler/test/test.js @@ -35,6 +35,9 @@ const { NATIVE_MODULE, SYSTEM_PLUGIN } = require('../lib/pre_define'); +const { + compatibleSdkVersion +} = require('../main'); function expectActual(name, filePath) { const content = require(filePath); @@ -59,7 +62,8 @@ function expectActual(name, filePath) { } mocha.describe('compiler', () => { - const utPath = path.resolve(__dirname, './ut'); + const utPath = compatibleSdkVersion === '8' ? + path.resolve(__dirname, './ut') : path.resolve(__dirname, './utForPartialUpdate'); const utFiles = []; readFile(utPath, utFiles); utFiles.forEach((item) => { diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts new file mode 100644 index 0000000..524dd45 --- /dev/null +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2022 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 = ` +@Component +struct LinkComponent { + @Link counter: string + build() { + Text(this.counter) + } +} + +@Entry +@Component +struct ParentComponent { + @State value: string = 'first init content'; + build() { + Column() { + LinkComponent({counter: this.$value}) + } + } +} +` +exports.expectResult = +`class LinkComponent extends View { + constructor(parent, params) { + super(parent); + this.__counter = new SynchedPropertySimpleTwoWay(params.counter, this, "counter"); + this.setInitiallyProvidedValue(params); + } + setInitiallyProvidedValue(params) { + } + setStateSourcePropertiesUnchanged() { + } + setOneWaySyncPropertiesUnchanged() { + } + setTwoWaySyncPropertiesUnchanged() { + this.__counter.SetPropertyUnchanged(); + } + purgeVariableDependenciesOnElmtId(rmElmtId) { + this.__counter.purgeDependencyOnElmtId(rmElmtId); + } + aboutToBeDeleted() { + this.__counter.aboutToBeDeleted(); + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal(); + } + get counter() { + return this.__counter.get(); + } + set counter(newValue) { + this.__counter.set(newValue); + } + render() { + Text.create(this.counter); + Text.pop(); + } + rerender() { + this.__counter.markDependentElementsDirty(this); + this.updateDirtyElements(); + } +} +class ParentComponent extends View { + constructor(parent, params) { + super(parent); + this.__value = new ObservedPropertySimple('first init content', this, "value"); + this.setInitiallyProvidedValue(params); + } + setInitiallyProvidedValue(params) { + if (params.value !== undefined) { + this.value = params.value; + } + } + setStateSourcePropertiesUnchanged() { + this.__value.SetPropertyUnchanged(); + } + setOneWaySyncPropertiesUnchanged() { + } + setTwoWaySyncPropertiesUnchanged() { + } + purgeVariableDependenciesOnElmtId(rmElmtId) { + this.__value.purgeDependencyOnElmtId(rmElmtId); + } + aboutToBeDeleted() { + this.__value.aboutToBeDeleted(); + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal(); + } + get value() { + return this.__value.get(); + } + set value(newValue) { + this.__value.set(newValue); + } + render() { + Column.create(); + let earlierCreatedChild_2 = this.findChildById("2"); + if (earlierCreatedChild_2 == undefined) { + View.create(new LinkComponent("2", this, { counter: this.__value })); + } + else { + earlierCreatedChild_2.updateWithValueParams({}); + View.create(earlierCreatedChild_2); + } + Column.pop(); + } + rerender() { + this.__value.markDependentElementsDirty(this); + this.updateDirtyElements(); + } +} +loadDocument(new ParentComponent("1", undefined, {})); +` \ No newline at end of file diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts new file mode 100644 index 0000000..a4992f8 --- /dev/null +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2022 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 = ` +@Component +struct PropComponent { + @Prop counter: string + build() { + Text(this.counter) + } +} + +@Entry +@Component +struct ParentComponent { + @State value: string = 'first init content'; + build() { + Column() { + PropComponent({counter: this.value}) + } + } +} +` +exports.expectResult = +`class PropComponent extends View { + constructor(parent, params) { + super(parent); + this.__counter = new SynchedPropertySimpleOneWay(params.counter, this, "counter"); + this.setInitiallyProvidedValue(params); + } + setInitiallyProvidedValue(params) { + } + setStateSourcePropertiesUnchanged() { + } + setOneWaySyncPropertiesUnchanged() { + this.__counter.SetPropertyUnchanged(); + } + setTwoWaySyncPropertiesUnchanged() { + } + purgeVariableDependenciesOnElmtId(rmElmtId) { + this.__counter.purgeDependencyOnElmtId(rmElmtId); + } + aboutToBeDeleted() { + this.__counter.aboutToBeDeleted(); + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal(); + } + get counter() { + return this.__counter.get(); + } + set counter(newValue) { + this.__counter.set(newValue); + } + render() { + Text.create(this.counter); + Text.pop(); + } + rerender() { + this.__counter.markDependentElementsDirty(this); + this.updateDirtyElements(); + } +} +class ParentComponent extends View { + constructor(parent, params) { + super(parent); + this.__value = new ObservedPropertySimple('first init content', this, "value"); + this.setInitiallyProvidedValue(params); + } + setInitiallyProvidedValue(params) { + if (params.value !== undefined) { + this.value = params.value; + } + } + setStateSourcePropertiesUnchanged() { + this.__value.SetPropertyUnchanged(); + } + setOneWaySyncPropertiesUnchanged() { + } + setTwoWaySyncPropertiesUnchanged() { + } + purgeVariableDependenciesOnElmtId(rmElmtId) { + this.__value.purgeDependencyOnElmtId(rmElmtId); + } + aboutToBeDeleted() { + this.__value.aboutToBeDeleted(); + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal(); + } + get value() { + return this.__value.get(); + } + set value(newValue) { + this.__value.set(newValue); + } + render() { + Column.create(); + let earlierCreatedChild_2 = this.findChildById("2"); + if (earlierCreatedChild_2 == undefined) { + View.create(new PropComponent("2", this, { counter: this.__value })); + } + else { + earlierCreatedChild_2.updateWithValueParams({ + counter: this.__value + }); + View.create(earlierCreatedChild_2); + } + Column.pop(); + } + rerender() { + this.__value.markDependentElementsDirty(this); + this.updateDirtyElements(); + } +} +loadDocument(new ParentComponent("1", undefined, {})); +` \ No newline at end of file diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts new file mode 100644 index 0000000..960af8a --- /dev/null +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2022 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 StatePage { + @State counter: number = 0; + build() { + Column() { + Text("counter:" + this.counter) + } + } +} +` +exports.expectResult = +`class StatePage extends View { + constructor(parent, params) { + super(parent); + this.__counter = new ObservedPropertySimple(0, this, "counter"); + this.setInitiallyProvidedValue(params); + } + setInitiallyProvidedValue(params) { + if (params.counter !== undefined) { + this.counter = params.counter; + } + } + setStateSourcePropertiesUnchanged() { + this.__counter.SetPropertyUnchanged(); + } + setOneWaySyncPropertiesUnchanged() { + } + setTwoWaySyncPropertiesUnchanged() { + } + purgeVariableDependenciesOnElmtId(rmElmtId) { + this.__counter.purgeDependencyOnElmtId(rmElmtId); + } + aboutToBeDeleted() { + this.__counter.aboutToBeDeleted(); + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal(); + } + get counter() { + return this.__counter.get(); + } + set counter(newValue) { + this.__counter.set(newValue); + } + render() { + Column.create(); + Text.create("counter:" + this.counter); + Text.pop(); + Column.pop(); + } + rerender() { + this.__counter.markDependentElementsDirty(this); + this.updateDirtyElements(); + } +} +loadDocument(new StatePage("1", undefined, {})); +` From ee439be97320e53041a64ec96c569ca363490a3f Mon Sep 17 00:00:00 2001 From: laibo102 Date: Mon, 25 Jul 2022 19:44:40 +0800 Subject: [PATCH 02/33] Update: normal inner_component transform Signed-off-by: laibo102 Change-Id: I6a1c8d7b67d2c7dee6426a611f89ee83e46d50a4 (cherry picked from commit ef272bc2e34a479a3acfcc06253070e8ccf310a8) Signed-off-by: laibo102 --- compiler/src/pre_define.ts | 6 ++ compiler/src/process_component_build.ts | 89 +++++++++++++++++-- .../@link/@link.ts | 18 +++- .../@prop/@prop.ts | 18 +++- .../@state/@state.ts | 18 +++- 5 files changed, 138 insertions(+), 11 deletions(-) diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 46da357..60c6935 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -291,3 +291,9 @@ export const ABOUTTOBEDELETEDINTERNAL: string = 'aboutToBeDeletedInternal'; export const UPDATEDIRTYELEMENTS: string ='updateDirtyElements'; export const BASICDECORATORS: Set = new Set([COMPONENT_STATE_DECORATOR, COMPONENT_PROP_DECORATOR, COMPONENT_LINK_DECORATOR]); +export const ISINITIALRENDER: string = 'isInitialRender'; +export const ELMTID: string = 'elmtId'; +export const STARTGETACCESSRECORDINGFOR: string = 'StartGetAccessRecordingFor'; +export const STOPGETACCESSRECORDING: string = 'StopGetAccessRecording'; +export const VIEWSTACKPROCESSOR: string = 'ViewStackProcessor'; +export const OBSERVECOMPONENTCREATION: string = 'observeComponentCreation'; diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index eea4651..3fcca1a 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -61,7 +61,13 @@ import { $$, PROPERTIES_ADD_DOUBLE_DOLLAR, ATTRIBUTE_ID, - RESOURCE + RESOURCE, + ISINITIALRENDER, + ELMTID, + VIEWSTACKPROCESSOR, + STOPGETACCESSRECORDING, + STARTGETACCESSRECORDINGFOR, + OBSERVECOMPONENTCREATION } from './pre_define'; import { INNER_COMPONENT_NAMES, @@ -92,7 +98,7 @@ import { componentInfo, createFunction } from './utils'; -import { projectConfig } from '../main'; +import { compatibleSdkVersion, projectConfig } from '../main'; import { transformLog, contextGlobal } from './process_ui_syntax'; import { props } from './compile_info'; import { CUSTOM_COMPONENT } from '../lib/pre_define'; @@ -374,8 +380,9 @@ function parseEtsComponentExpression(node: ts.ExpressionStatement): EtsComponent return { etsComponentNode: etsComponentNode, hasAttr: hasAttr }; } -function processInnerComponent(node: ts.ExpressionStatement, newStatements: ts.Statement[], +function processInnerComponent(node: ts.ExpressionStatement, innerCompStatements: ts.Statement[], log: LogInfo[], parent: string = undefined): void { + const newStatements: ts.Statement[] = []; const res: CreateResult = createComponent(node, COMPONENT_CREATE_FUNCTION); newStatements.push(res.newNode); const nameResult: NameResult = { name: null }; @@ -424,16 +431,88 @@ function processInnerComponent(node: ts.ExpressionStatement, newStatements: ts.S if (etsComponentResult.hasAttr) { bindComponentAttr(node, res.identifierNode, newStatements, log); } - processComponentChild(etsComponentResult.etsComponentNode.body, newStatements, log, + processInnerCompStatements(innerCompStatements, newStatements, node); + processComponentChild(etsComponentResult.etsComponentNode.body, innerCompStatements, log, {isAcceleratePreview: false, line: 0, column: 0, fileName: ''}, false, parent); } else { bindComponentAttr(node, res.identifierNode, newStatements, log); + processInnerCompStatements(innerCompStatements, newStatements, node); } if (res.isContainerComponent || res.needPop) { - newStatements.push(createComponent(node, COMPONENT_POP_FUNCTION).newNode); + innerCompStatements.push(createComponent(node, COMPONENT_POP_FUNCTION).newNode); } } +function processInnerCompStatements( + innerCompStatements: ts.Statement[], + newStatements: ts.Statement[], + node: ts.Statement +): void { + if (compatibleSdkVersion === '8') { + innerCompStatements.push(...newStatements); + } else { + innerCompStatements.push(createComponentCreationStatement(node, newStatements)); + } +} + +function createComponentCreationStatement(node: ts.Statement, innerStatements: ts.Statement[]): ts.Statement { + return ts.factory.createExpressionStatement( + ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createThis(), + ts.factory.createIdentifier(OBSERVECOMPONENTCREATION) + ), undefined, + [ts.factory.createArrowFunction(undefined, undefined, + [ + ts.factory.createParameterDeclaration(undefined, undefined, undefined, + ts.factory.createIdentifier(ELMTID), undefined, undefined, undefined), + ts.factory.createParameterDeclaration(undefined, undefined, undefined, + ts.factory.createIdentifier(ISINITIALRENDER), undefined, undefined, undefined) + ], undefined, + ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), + ts.factory.createBlock( + [ + createViewStackProcessorStatement(STARTGETACCESSRECORDINGFOR, ELMTID), + ...innerStatements, + createInitRenderStatement(node), + createViewStackProcessorStatement(STOPGETACCESSRECORDING) + ], + true + ) + )] + ) + ); +} + +function createViewStackProcessorStatement(propertyAccessName: string, elmtId?: string): ts.Statement { + return ts.factory.createExpressionStatement( + ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createIdentifier(VIEWSTACKPROCESSOR), + ts.factory.createIdentifier(propertyAccessName) + ), + undefined, + elmtId ? [ts.factory.createIdentifier(ELMTID)] : [] + ) + ); +} + +function createInitRenderStatement(node: ts.Statement): ts.Statement { + return ts.factory.createIfStatement( + ts.factory.createPrefixUnaryExpression( + ts.SyntaxKind.ExclamationToken, + ts.factory.createIdentifier(ISINITIALRENDER) + ), + ts.factory.createBlock( + [ + ts.isExpressionStatement(node) ? + createComponent(node, COMPONENT_POP_FUNCTION).newNode : createIfPop() + ], + true + ) + ); +} + function getRealNodePos(node: ts.Node): number { // @ts-ignore if (node.pos === -1 && node.expression) { diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts index 524dd45..2f94dd3 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts @@ -64,7 +64,14 @@ exports.expectResult = this.__counter.set(newValue); } render() { - Text.create(this.counter); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create(this.counter); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); Text.pop(); } rerender() { @@ -105,7 +112,14 @@ class ParentComponent extends View { this.__value.set(newValue); } render() { - Column.create(); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Column.create(); + if (!isInitialRender) { + Column.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); let earlierCreatedChild_2 = this.findChildById("2"); if (earlierCreatedChild_2 == undefined) { View.create(new LinkComponent("2", this, { counter: this.__value })); diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts index a4992f8..59d572b 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts @@ -64,7 +64,14 @@ exports.expectResult = this.__counter.set(newValue); } render() { - Text.create(this.counter); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create(this.counter); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); Text.pop(); } rerender() { @@ -105,7 +112,14 @@ class ParentComponent extends View { this.__value.set(newValue); } render() { - Column.create(); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Column.create(); + if (!isInitialRender) { + Column.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); let earlierCreatedChild_2 = this.findChildById("2"); if (earlierCreatedChild_2 == undefined) { View.create(new PropComponent("2", this, { counter: this.__value })); diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts index 960af8a..a1a2fde 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts @@ -59,8 +59,22 @@ exports.expectResult = this.__counter.set(newValue); } render() { - Column.create(); - Text.create("counter:" + this.counter); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Column.create(); + if (!isInitialRender) { + Column.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create("counter:" + this.counter); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); Text.pop(); Column.pop(); } From 7326eb5ff8d271d26c0a04866e387eb5e1628f07 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Tue, 26 Jul 2022 14:29:10 +0800 Subject: [PATCH 03/33] Update: IF component transform Signed-off-by: laibo102 Change-Id: I91ea9c54bad081288e7cc418e0711e93f325d0a1 (cherry picked from commit 738c3ec799e187f6e2cf516613ffc389c9b5b353) Signed-off-by: laibo102 --- compiler/src/process_component_build.ts | 6 +- .../render_component/if/if.ts | 174 ++++++++++++++++++ 2 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 3fcca1a..f00dbfd 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -606,7 +606,11 @@ function processIfStatement(node: ts.IfStatement, newStatements: ts.Statement[], const ifCreate: ts.ExpressionStatement = createIfCreate(); const newIfNode: ts.IfStatement = processInnerIfStatement(node, 0, log, isInnerBuilder); const ifPop: ts.ExpressionStatement = createIfPop(); - newStatements.push(ifCreate, newIfNode, ifPop); + if (compatibleSdkVersion === '8') { + newStatements.push(ifCreate, newIfNode, ifPop); + } else { + newStatements.push(createComponentCreationStatement(node, [ifCreate,newIfNode]),ifPop); + } } function processInnerIfStatement(node: ts.IfStatement, id: number, log: LogInfo[], diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts new file mode 100644 index 0000000..124b4ee --- /dev/null +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2022 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 IFView { + @State toggle1: boolean = false; + @State toggle2: boolean = false; + @State toggle3: boolean = false; + + build() { + Column() { + if (this.toggle1) { + Text('toggle1') + } else if(this.toggle2) { + Text('toggle2') + } else if (this.toggle3) { + Text('toggle3') + } else { + Text('toggle no thing') + } + } + } +} +` +exports.expectResult = +`class IFView extends View { + constructor(parent, params) { + super(parent); + this.__toggle1 = new ObservedPropertySimple(false, this, "toggle1"); + this.__toggle2 = new ObservedPropertySimple(false, this, "toggle2"); + this.__toggle3 = new ObservedPropertySimple(false, this, "toggle3"); + this.setInitiallyProvidedValue(params); + } + setInitiallyProvidedValue(params) { + if (params.toggle1 !== undefined) { + this.toggle1 = params.toggle1; + } + if (params.toggle2 !== undefined) { + this.toggle2 = params.toggle2; + } + if (params.toggle3 !== undefined) { + this.toggle3 = params.toggle3; + } + } + setStateSourcePropertiesUnchanged() { + this.__toggle1.SetPropertyUnchanged(); + this.__toggle2.SetPropertyUnchanged(); + this.__toggle3.SetPropertyUnchanged(); + } + setOneWaySyncPropertiesUnchanged() { + } + setTwoWaySyncPropertiesUnchanged() { + } + purgeVariableDependenciesOnElmtId(rmElmtId) { + this.__toggle1.purgeDependencyOnElmtId(rmElmtId); + this.__toggle2.purgeDependencyOnElmtId(rmElmtId); + this.__toggle3.purgeDependencyOnElmtId(rmElmtId); + } + aboutToBeDeleted() { + this.__toggle1.aboutToBeDeleted(); + this.__toggle2.aboutToBeDeleted(); + this.__toggle3.aboutToBeDeleted(); + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal(); + } + get toggle1() { + return this.__toggle1.get(); + } + set toggle1(newValue) { + this.__toggle1.set(newValue); + } + get toggle2() { + return this.__toggle2.get(); + } + set toggle2(newValue) { + this.__toggle2.set(newValue); + } + get toggle3() { + return this.__toggle3.get(); + } + set toggle3(newValue) { + this.__toggle3.set(newValue); + } + render() { + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Column.create(); + if (!isInitialRender) { + Column.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + If.create(); + if (this.toggle1) { + If.branchId(0); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create('toggle1'); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + Text.pop(); + } + else if (this.toggle2) { + If.branchId(1); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create('toggle2'); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + Text.pop(); + } + else if (this.toggle3) { + If.branchId(2); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create('toggle3'); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + Text.pop(); + } + else { + If.branchId(3); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create('toggle no thing'); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + Text.pop(); + } + if (!isInitialRender) { + If.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + If.pop(); + Column.pop(); + } + rerender() { + this.__toggle1.markDependentElementsDirty(this); + this.__toggle2.markDependentElementsDirty(this); + this.__toggle3.markDependentElementsDirty(this); + this.updateDirtyElements(); + } +} +loadDocument(new IFView("1", undefined, {})); +` \ No newline at end of file From 66190c65bd45cb4c433c1182531908b2e22f490e Mon Sep 17 00:00:00 2001 From: laibo102 Date: Tue, 26 Jul 2022 20:10:51 +0800 Subject: [PATCH 04/33] Update: ListItem&GridItem component transform Signed-off-by: laibo102 Change-Id: Iad746d51764fce0c358af4488c58346aefcffd70 (cherry picked from commit d421499a76e34b8146698e729825c64a9889439c) Signed-off-by: laibo102 --- compiler/src/pre_define.ts | 8 +- compiler/src/process_component_build.ts | 321 ++++++++++++++++-- .../render_component/item/GridItem.ts | 113 ++++++ .../render_component/item/ListItem.ts | 113 ++++++ 4 files changed, 526 insertions(+), 29 deletions(-) create mode 100644 compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts create mode 100644 compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 60c6935..0cbbb9f 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -288,7 +288,7 @@ export const RMELMTID: string = 'rmElmtId'; export const PURGEDEPENDENCYONELMTID: string = 'purgeDependencyOnElmtId'; export const SETPROPERTYUNCHANGED: string = 'SetPropertyUnchanged'; export const ABOUTTOBEDELETEDINTERNAL: string = 'aboutToBeDeletedInternal'; -export const UPDATEDIRTYELEMENTS: string ='updateDirtyElements'; +export const UPDATEDIRTYELEMENTS: string = 'updateDirtyElements'; export const BASICDECORATORS: Set = new Set([COMPONENT_STATE_DECORATOR, COMPONENT_PROP_DECORATOR, COMPONENT_LINK_DECORATOR]); export const ISINITIALRENDER: string = 'isInitialRender'; @@ -297,3 +297,9 @@ export const STARTGETACCESSRECORDINGFOR: string = 'StartGetAccessRecordingFor'; export const STOPGETACCESSRECORDING: string = 'StopGetAccessRecording'; export const VIEWSTACKPROCESSOR: string = 'ViewStackProcessor'; export const OBSERVECOMPONENTCREATION: string = 'observeComponentCreation'; +export const ISLAZYCREATE: string = 'isLazyCreate'; +export const DEEPRENDERFUNCTION: string = 'deepRenderFunction'; +export const ITEMCREATION: string = 'itemCreation'; +export const OBSERVEDSHALLOWRENDER: string = 'observedShallowRender'; +export const OBSERVEDDEEPRENDER:string = 'observedDeepRender'; +export const ItemComponents: string[] = ['ListItem', 'GridItem']; diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index f00dbfd..8c16d38 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -67,7 +67,13 @@ import { VIEWSTACKPROCESSOR, STOPGETACCESSRECORDING, STARTGETACCESSRECORDINGFOR, - OBSERVECOMPONENTCREATION + OBSERVECOMPONENTCREATION, + ISLAZYCREATE, + DEEPRENDERFUNCTION, + ITEMCREATION, + OBSERVEDSHALLOWRENDER, + OBSERVEDDEEPRENDER, + ItemComponents } from './pre_define'; import { INNER_COMPONENT_NAMES, @@ -387,32 +393,19 @@ function processInnerComponent(node: ts.ExpressionStatement, innerCompStatements newStatements.push(res.newNode); const nameResult: NameResult = { name: null }; validateEtsComponentNode(node.expression as ts.EtsComponentExpression, nameResult); - if (projectConfig.isPreview && nameResult.name && !NO_DEBUG_LINE_COMPONENT.has(nameResult.name)) { - let posOfNode: ts.LineAndCharacter; - let curFileName: string; - let line: number = 1; - let col: number = 1; - if (newsupplement.isAcceleratePreview) { - posOfNode = sourceNode.getLineAndCharacterOfPosition(getRealNodePos(node)); - curFileName = newsupplement.fileName; - if (posOfNode.line === 0) { - col = newsupplement.column - 15; - } - line = newsupplement.line; - } else { - posOfNode = transformLog.sourceFile.getLineAndCharacterOfPosition(getRealNodePos(node)); - curFileName = transformLog.sourceFile.fileName.replace(/\.ts$/, ''); - } - const projectPath: string = projectConfig.projectPath; - const debugInfo: string = - `${path.relative(projectPath, curFileName).replace(/\\+/g, '/')}` + - `(${posOfNode.line + line}:${posOfNode.character + col})`; - const debugNode: ts.ExpressionStatement = ts.factory.createExpressionStatement( - createFunction(ts.factory.createIdentifier(nameResult.name), - ts.factory.createIdentifier(COMPONENT_DEBUGLINE_FUNCTION), - ts.factory.createNodeArray([ts.factory.createStringLiteral(debugInfo)]))); - newStatements.push(debugNode); + if (compatibleSdkVersion === '9' && ItemComponents.includes(nameResult.name)) { + processItemComponent(node, nameResult, innerCompStatements, log); + } else { + processNormalComponent(node, nameResult, innerCompStatements, log); } +} + +function processNormalComponent(node: ts.ExpressionStatement, nameResult: NameResult, + innerCompStatements: ts.Statement[], log: LogInfo[]): void { + const newStatements: ts.Statement[] = []; + const res: CreateResult = createComponent(node, COMPONENT_CREATE_FUNCTION); + newStatements.push(res.newNode); + processDebug(node, nameResult, newStatements); const etsComponentResult: EtsComponentResult = parseEtsComponentExpression(node); if (PROPERTIES_ADD_DOUBLE_DOLLAR.has(res.identifierNode.getText()) && etsComponentResult.etsComponentNode.arguments && etsComponentResult.etsComponentNode.arguments.length) { @@ -443,6 +436,34 @@ function processInnerComponent(node: ts.ExpressionStatement, innerCompStatements } } +function processDebug(node: ts.Statement, nameResult: NameResult, newStatements: ts.Statement[]): void { + if (projectConfig.isPreview && nameResult.name && !NO_DEBUG_LINE_COMPONENT.has(nameResult.name)) { + let posOfNode: ts.LineAndCharacter; + let curFileName: string; + let line: number = 1; + let col: number = 1; + if (newsupplement.isAcceleratePreview) { + posOfNode = sourceNode.getLineAndCharacterOfPosition(getRealNodePos(node)); + curFileName = newsupplement.fileName; + if (posOfNode.line === 0) { + col = newsupplement.column - 15; + } + line = newsupplement.line; + } else { + posOfNode = transformLog.sourceFile.getLineAndCharacterOfPosition(getRealNodePos(node)); + curFileName = transformLog.sourceFile.fileName.replace(/\.ts$/, ''); + } + const projectPath: string = projectConfig.projectPath; + const debugInfo: string = `${path.relative(projectPath, curFileName).replace(/\\+/g, '/')}` + + `(${posOfNode.line + line}:${posOfNode.character + col})`; + const debugNode: ts.ExpressionStatement = ts.factory.createExpressionStatement( + createFunction(ts.factory.createIdentifier(nameResult.name), + ts.factory.createIdentifier(COMPONENT_DEBUGLINE_FUNCTION), + ts.factory.createNodeArray([ts.factory.createStringLiteral(debugInfo)]))); + newStatements.push(debugNode); + } +} + function processInnerCompStatements( innerCompStatements: ts.Statement[], newStatements: ts.Statement[], @@ -505,7 +526,7 @@ function createInitRenderStatement(node: ts.Statement): ts.Statement { ), ts.factory.createBlock( [ - ts.isExpressionStatement(node) ? + ts.isExpressionStatement(node) ? createComponent(node, COMPONENT_POP_FUNCTION).newNode : createIfPop() ], true @@ -513,6 +534,250 @@ function createInitRenderStatement(node: ts.Statement): ts.Statement { ); } +function processItemComponent(node: ts.ExpressionStatement, nameResult: NameResult, innerCompStatements: ts.Statement[], + log: LogInfo[]): void { + const itemRenderInnerStatements: ts.Statement[] = []; + const deepItemRenderInnerStatements: ts.Statement[] = []; + const res: CreateResult = createComponent(node, COMPONENT_CREATE_FUNCTION); + const itemCreateStatement: ts.Statement = createItemCreate(nameResult); + itemRenderInnerStatements.push(itemCreateStatement); + processDebug(node, nameResult, innerCompStatements); + const etsComponentResult: EtsComponentResult = parseEtsComponentExpression(node); + if (etsComponentResult.etsComponentNode.body && ts.isBlock(etsComponentResult.etsComponentNode.body)) { + if (etsComponentResult.hasAttr) { + bindComponentAttr(node, res.identifierNode, itemRenderInnerStatements, log); + } + processComponentChild(etsComponentResult.etsComponentNode.body, deepItemRenderInnerStatements, log); + } else { + bindComponentAttr(node, res.identifierNode, itemRenderInnerStatements, log); + } + innerCompStatements.push(createItemBlock(node, itemRenderInnerStatements, deepItemRenderInnerStatements)); +} + +function createItemCreate(nameResult: NameResult): ts.Statement { + return ts.factory.createExpressionStatement(ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(nameResult.name), + ts.factory.createIdentifier(COMPONENT_CREATE_FUNCTION)), undefined, + [ts.factory.createIdentifier(DEEPRENDERFUNCTION), ts.factory.createIdentifier(ISLAZYCREATE)])); +} + +function createItemBlock( + node: ts.ExpressionStatement, + itemRenderInnerStatements: ts.Statement[], + deepItemRenderInnerStatements: ts.Statement[] +): ts.Block { + const etsComponent: ts.EtsComponentExpression = getEtsComponentExpression(node); + let isLazyCreate: ts.BooleanLiteral = ts.factory.createTrue(); + if (etsComponent && etsComponent.arguments[0]) { + if (etsComponent.arguments[0] as ts.StringLiteral.text === 'false') { + isLazyCreate = ts.factory.createFalse(); + } + } + return ts.factory.createBlock( + [ + ts.factory.createVariableStatement( + undefined, + ts.factory.createVariableDeclarationList( + [ts.factory.createVariableDeclaration(ts.factory.createIdentifier(ISLAZYCREATE), + undefined, undefined, isLazyCreate)], + ts.NodeFlags.Const + ) + ), + createItemCreation(node, itemRenderInnerStatements), + createObservedShallowRender(node, itemRenderInnerStatements), + createObservedDeepRender(node, deepItemRenderInnerStatements), + createDeepRenderFunction(node, deepItemRenderInnerStatements), + ts.factory.createIfStatement( + ts.factory.createIdentifier(ISLAZYCREATE), + ts.factory.createBlock( + [ts.factory.createExpressionStatement(ts.factory.createCallExpression( + ts.factory.createIdentifier(OBSERVEDSHALLOWRENDER), undefined, []))], true), + ts.factory.createBlock( + [ts.factory.createExpressionStatement(ts.factory.createCallExpression( + ts.factory.createIdentifier(OBSERVEDDEEPRENDER), undefined, []))], true) + ) + ], + true + ); +} + +function createItemCreation( + node: ts.ExpressionStatement, + itemRenderInnerStatements: ts.Statement[] +): ts.VariableStatement { + return ts.factory.createVariableStatement( + undefined, + ts.factory.createVariableDeclarationList( + [ts.factory.createVariableDeclaration( + ts.factory.createIdentifier(ITEMCREATION), undefined, undefined, + ts.factory.createArrowFunction(undefined, undefined, + [ + ts.factory.createParameterDeclaration(undefined, undefined, undefined, + ts.factory.createIdentifier(ELMTID), undefined, undefined, undefined), + ts.factory.createParameterDeclaration(undefined, undefined, undefined, + ts.factory.createIdentifier(ISINITIALRENDER), undefined, undefined, undefined) + ], undefined, + ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), + ts.factory.createBlock( + [ + createViewStackProcessorStatement(STARTGETACCESSRECORDINGFOR, ELMTID), + ...itemRenderInnerStatements, + ts.factory.createIfStatement( + ts.factory.createPrefixUnaryExpression( + ts.SyntaxKind.ExclamationToken, + ts.factory.createIdentifier(ISINITIALRENDER) + ), + ts.factory.createBlock( + [createComponent(node, COMPONENT_POP_FUNCTION).newNode], + true + ) + ), + createViewStackProcessorStatement(STOPGETACCESSRECORDING) + ], + true + ) + ) + )], + ts.NodeFlags.Const + ) + ); +} + +function createDeepRenderFunction( + node: ts.ExpressionStatement, + deepItemRenderInnerStatements: ts.Statement[] +): ts.VariableStatement { + return ts.factory.createVariableStatement( + undefined, + ts.factory.createVariableDeclarationList( + [ts.factory.createVariableDeclaration( + ts.factory.createIdentifier(DEEPRENDERFUNCTION), undefined, undefined, + ts.factory.createArrowFunction(undefined, undefined, + [ + ts.factory.createParameterDeclaration(undefined, undefined, undefined, + ts.factory.createIdentifier(ELMTID), undefined, undefined, undefined), + ts.factory.createParameterDeclaration(undefined, undefined, undefined, + ts.factory.createIdentifier(ISINITIALRENDER), undefined, undefined, undefined) + ], undefined, + ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), + ts.factory.createBlock( + [ + ts.factory.createExpressionStatement(ts.factory.createCallExpression( + ts.factory.createIdentifier(ITEMCREATION), undefined, + [ + ts.factory.createIdentifier(ELMTID), + ts.factory.createIdentifier(ISINITIALRENDER) + ] + )), + ts.factory.createExpressionStatement(ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createThis(), + ts.factory.createIdentifier('updateFuncByElmtId') + ), + ts.factory.createIdentifier('set') + ), undefined, + [ts.factory.createIdentifier(ELMTID), ts.factory.createIdentifier(ITEMCREATION)] + )), + ...deepItemRenderInnerStatements, + createComponent(node, COMPONENT_POP_FUNCTION).newNode + ], + true + ) + ) + )], + ts.NodeFlags.Const + ) + ); +} + +function createObservedShallowRender( + node: ts.ExpressionStatement, + itemRenderInnerStatements: ts.Statement[] +): ts.VariableStatement { + return ts.factory.createVariableStatement(undefined, + ts.factory.createVariableDeclarationList( + [ts.factory.createVariableDeclaration( + ts.factory.createIdentifier(OBSERVEDSHALLOWRENDER), undefined, undefined, + ts.factory.createArrowFunction(undefined, undefined, [], undefined, + ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), + ts.factory.createBlock( + [ + ts.factory.createExpressionStatement(ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createThis(), + ts.factory.createIdentifier(OBSERVECOMPONENTCREATION) + ), undefined, + [ts.factory.createArrowFunction(undefined, undefined, + [ + ts.factory.createParameterDeclaration(undefined, undefined, undefined, + ts.factory.createIdentifier(ELMTID), undefined, undefined, undefined), + ts.factory.createParameterDeclaration(undefined, undefined, undefined, + ts.factory.createIdentifier(ISINITIALRENDER), undefined, undefined, undefined) + ], undefined, + ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), + ts.factory.createBlock( + [createViewStackProcessorStatement(STARTGETACCESSRECORDINGFOR, ELMTID), + itemRenderInnerStatements[0], + ts.factory.createIfStatement( + ts.factory.createPrefixUnaryExpression(ts.SyntaxKind.ExclamationToken, + ts.factory.createIdentifier(ISINITIALRENDER)), + ts.factory.createBlock( + [createComponent(node, COMPONENT_POP_FUNCTION).newNode], true)), + createViewStackProcessorStatement(STOPGETACCESSRECORDING)], true + ) + )] + )), + createComponent(node, COMPONENT_POP_FUNCTION).newNode + ], + true + ) + ) + )], + ts.NodeFlags.Const + ) + ); +} + +function createObservedDeepRender( + node: ts.ExpressionStatement, + deepItemRenderInnerStatements: ts.Statement[] +): ts.VariableStatement { + return ts.factory.createVariableStatement( + undefined, + ts.factory.createVariableDeclarationList( + [ts.factory.createVariableDeclaration( + ts.factory.createIdentifier(OBSERVEDDEEPRENDER), + undefined, + undefined, + ts.factory.createArrowFunction( + undefined, + undefined, + [], + undefined, + ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), + ts.factory.createBlock( + [ + ts.factory.createExpressionStatement(ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createThis(), + ts.factory.createIdentifier(OBSERVECOMPONENTCREATION) + ), + undefined, + [ts.factory.createIdentifier(ITEMCREATION)] + )), + ...deepItemRenderInnerStatements, + createComponent(node, COMPONENT_POP_FUNCTION).newNode + ], + true + ) + ) + )], + ts.NodeFlags.Const + ) + ); +} + function getRealNodePos(node: ts.Node): number { // @ts-ignore if (node.pos === -1 && node.expression) { @@ -609,7 +874,7 @@ function processIfStatement(node: ts.IfStatement, newStatements: ts.Statement[], if (compatibleSdkVersion === '8') { newStatements.push(ifCreate, newIfNode, ifPop); } else { - newStatements.push(createComponentCreationStatement(node, [ifCreate,newIfNode]),ifPop); + newStatements.push(createComponentCreationStatement(node, [ifCreate, newIfNode]), ifPop); } } diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts new file mode 100644 index 0000000..30b25f1 --- /dev/null +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2022 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 ParentView { + build() { + GridItem('true') { + Text('xx').width(100) + }.width(200).height(100) + } +} +` +exports.expectResult = +`class ParentView extends View { + constructor(parent, params) { + super(parent); + this.setInitiallyProvidedValue(params); + } + setInitiallyProvidedValue(params) { + } + setStateSourcePropertiesUnchanged() { + } + setOneWaySyncPropertiesUnchanged() { + } + setTwoWaySyncPropertiesUnchanged() { + } + purgeVariableDependenciesOnElmtId(rmElmtId) { + } + aboutToBeDeleted() { + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal(); + } + render() { + { + const isLazyCreate = true; + const itemCreation = (elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + GridItem.create(deepRenderFunction, isLazyCreate); + GridItem.width(200); + GridItem.height(100); + if (!isInitialRender) { + GridItem.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }; + const observedShallowRender = () => { + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + GridItem.create(deepRenderFunction, isLazyCreate); + if (!isInitialRender) { + GridItem.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + GridItem.pop(); + }; + const observedDeepRender = () => { + this.observeComponentCreation(itemCreation); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create('xx'); + Text.width(100); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + Text.pop(); + GridItem.pop(); + }; + const deepRenderFunction = (elmtId, isInitialRender) => { + itemCreation(elmtId, isInitialRender); + this.updateFuncByElmtId.set(elmtId, itemCreation); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create('xx'); + Text.width(100); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + Text.pop(); + GridItem.pop(); + }; + if (isLazyCreate) { + observedShallowRender(); + } + else { + observedDeepRender(); + } + } + } + rerender() { + this.updateDirtyElements(); + } +} +loadDocument(new ParentView("1", undefined, {})); +` \ No newline at end of file diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts new file mode 100644 index 0000000..62638a5 --- /dev/null +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2022 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 ParentView { + build() { + ListItem('true') { + Text('xx').width(100) + }.width(200).height(100) + } +} +` +exports.expectResult = +`class ParentView extends View { + constructor(parent, params) { + super(parent); + this.setInitiallyProvidedValue(params); + } + setInitiallyProvidedValue(params) { + } + setStateSourcePropertiesUnchanged() { + } + setOneWaySyncPropertiesUnchanged() { + } + setTwoWaySyncPropertiesUnchanged() { + } + purgeVariableDependenciesOnElmtId(rmElmtId) { + } + aboutToBeDeleted() { + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal(); + } + render() { + { + const isLazyCreate = true; + const itemCreation = (elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + ListItem.create(deepRenderFunction, isLazyCreate); + ListItem.width(200); + ListItem.height(100); + if (!isInitialRender) { + ListItem.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }; + const observedShallowRender = () => { + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + ListItem.create(deepRenderFunction, isLazyCreate); + if (!isInitialRender) { + ListItem.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + ListItem.pop(); + }; + const observedDeepRender = () => { + this.observeComponentCreation(itemCreation); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create('xx'); + Text.width(100); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + Text.pop(); + ListItem.pop(); + }; + const deepRenderFunction = (elmtId, isInitialRender) => { + itemCreation(elmtId, isInitialRender); + this.updateFuncByElmtId.set(elmtId, itemCreation); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create('xx'); + Text.width(100); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + Text.pop(); + ListItem.pop(); + }; + if (isLazyCreate) { + observedShallowRender(); + } + else { + observedDeepRender(); + } + } + } + rerender() { + this.updateDirtyElements(); + } +} +loadDocument(new ParentView("1", undefined, {})); +` \ No newline at end of file From 40ce2c3d50ac429d8656d9d6b0b8d3cd3d88b756 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Thu, 28 Jul 2022 10:30:33 +0800 Subject: [PATCH 05/33] Update: Foreach & LazyForeach component Signed-off-by: laibo102 Change-Id: Iaa2e39cde53a28dfa6528eb4f3e542d6e1981264 (cherry picked from commit 30960824aff42fcecf3b3e36806137637b86e9c1) Signed-off-by: laibo102 --- compiler/src/pre_define.ts | 6 + compiler/src/process_component_build.ts | 201 ++++++++++++- .../render_component/foreach/foreach.ts | 106 +++++++ .../lazyforeach/lazyforeach.ts | 276 ++++++++++++++++++ 4 files changed, 576 insertions(+), 13 deletions(-) create mode 100644 compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts create mode 100644 compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 0cbbb9f..ced40f0 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -303,3 +303,9 @@ export const ITEMCREATION: string = 'itemCreation'; export const OBSERVEDSHALLOWRENDER: string = 'observedShallowRender'; export const OBSERVEDDEEPRENDER:string = 'observedDeepRender'; export const ItemComponents: string[] = ['ListItem', 'GridItem']; +export const FOREACHITEMGENFUNCTION: string = 'forEachItemGenFunction'; +export const __LAZYFOREACHITEMGENFUNCTION: string = '__lazyForEachItemGenFunction'; +export const _ITEM: string = '_item'; +export const FOREACHITEMIDFUNC: string = 'forEachItemIdFunc'; +export const __LAZYFOREACHITEMIDFUNC: string = '__lazyForEachItemIdFunc'; +export const FOREACHUPDATEFUNCTION: string = 'forEachUpdateFunction'; diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 8c16d38..26fb1af 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -73,7 +73,13 @@ import { ITEMCREATION, OBSERVEDSHALLOWRENDER, OBSERVEDDEEPRENDER, - ItemComponents + ItemComponents, + FOREACHITEMGENFUNCTION, + __LAZYFOREACHITEMGENFUNCTION, + _ITEM, + FOREACHITEMIDFUNC, + __LAZYFOREACHITEMIDFUNC, + FOREACHUPDATEFUNCTION } from './pre_define'; import { INNER_COMPONENT_NAMES, @@ -131,7 +137,7 @@ export function processComponentBlock(node: ts.Block, isLazy: boolean, log: LogI const newStatements: ts.Statement[] = []; processComponentChild(node, newStatements, log, {isAcceleratePreview: false, line: 0, column: 0, fileName: ''}, isInnerBuilder, parent); - if (isLazy) { + if (isLazy && compatibleSdkVersion === '8') { newStatements.unshift(createRenderingInProgress(true)); } if (isTransition) { @@ -142,7 +148,7 @@ export function processComponentBlock(node: ts.Block, isLazy: boolean, log: LogI createFunction(ts.factory.createIdentifier(COMPONENT_TRANSITION_NAME), ts.factory.createIdentifier(COMPONENT_POP_FUNCTION), null))); } - if (isLazy) { + if (isLazy && compatibleSdkVersion === '8') { newStatements.push(createRenderingInProgress(false)); } return ts.factory.updateBlock(node, newStatements); @@ -266,7 +272,13 @@ export function processComponentChild(node: ts.Block | ts.SourceFile, newStateme break; case ComponentType.forEachComponent: parent = undefined; - processForEachComponent(item, newStatements, log, isInnerBuilder); + if (compatibleSdkVersion === '8') { + processForEachComponent(item, newStatements, log, isInnerBuilder); + } else { + processForEachComponentNew(item, newStatements, log); + } + lastName = name; + lastExpression = item; break; case ComponentType.customBuilderMethod: parent = undefined; @@ -807,7 +819,8 @@ function processForEachComponent(node: ts.ExpressionStatement, newStatements: ts ts.factory.createIdentifier(FOREACH_GET_RAW_OBJECT)), undefined, [argumentsArray[0]]); } argumentsArray.splice(0, 1, arrayObserveredObject); - const newArrowNode: ts.ArrowFunction = processForEachBlock(node.expression, log, isInnerBuilder); + const newArrowNode: ts.ArrowFunction = + processForEachBlock(node.expression, log, isInnerBuilder) as ts.ArrowFunction; if (newArrowNode) { argumentsArray.splice(1, 1, newArrowNode); } @@ -817,6 +830,160 @@ function processForEachComponent(node: ts.ExpressionStatement, newStatements: ts newStatements.push(node, popNode); } +function processForEachComponentNew(node: ts.ExpressionStatement, newStatements: ts.Statement[], + log: LogInfo[]): void { + const newForEachStatements: ts.Statement[] = []; + const popNode: ts.ExpressionStatement = ts.factory.createExpressionStatement(createFunction( + (node.expression as ts.CallExpression ).expression as ts.Identifier, + ts.factory.createIdentifier(COMPONENT_POP_FUNCTION), null)); + if (ts.isCallExpression(node.expression)) { + const argumentsArray: ts.Expression[] = Array.from(node.expression.arguments); + const propertyNode: ts.ExpressionStatement = ts.factory.createExpressionStatement( + ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression( + node.expression.expression as ts.Identifier, + ts.factory.createIdentifier(COMPONENT_CREATE_FUNCTION)), undefined, [])); + const newArrowNode: ts.NodeArray = + processForEachBlock(node.expression, log) as ts.NodeArray; + const itemGenFunctionStatement: ts.VariableStatement = createItemGenFunctionStatement(node.expression, + argumentsArray, newArrowNode); + const itemIdFuncStatement: ts.VariableStatement = createItemIdFuncStatement(node.expression, argumentsArray); + const updateFunctionStatement: ts.ExpressionStatement = createUpdateFunctionStatement(argumentsArray); + const lazyForEachStatement: ts.ExpressionStatement = createLazyForEachStatement(argumentsArray); + if (node.expression.expression.getText() === COMPONENT_FOREACH) { + if (argumentsArray[2]) { + newForEachStatements.push(propertyNode, itemGenFunctionStatement, itemIdFuncStatement, updateFunctionStatement); + } else { + newForEachStatements.push(propertyNode, itemGenFunctionStatement, updateFunctionStatement); + } + newStatements.push(createComponentCreationStatement(node, newForEachStatements), popNode); + } else { + if (argumentsArray[2]) { + newStatements.push(itemGenFunctionStatement, itemIdFuncStatement, lazyForEachStatement, popNode); + } else { + newStatements.push(itemGenFunctionStatement, lazyForEachStatement, popNode); + } + } + } +} + +function createItemGenFunctionStatement( + node: ts.CallExpression, + argumentsArray: ts.Expression[], + newArrowNode: ts.NodeArray +): ts.VariableStatement { + if (argumentsArray[1] && ts.isArrowFunction(argumentsArray[1])) { + return ts.factory.createVariableStatement( + undefined, + ts.factory.createVariableDeclarationList( + [ts.factory.createVariableDeclaration( + ts.factory.createIdentifier(node.expression.getText() === COMPONENT_FOREACH ? + FOREACHITEMGENFUNCTION : __LAZYFOREACHITEMGENFUNCTION), + undefined, undefined, + ts.factory.createArrowFunction( + undefined, undefined, + [ts.factory.createParameterDeclaration( + undefined, undefined, undefined, ts.factory.createIdentifier(_ITEM))], + undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), + ts.factory.createBlock( + [ts.factory.createVariableStatement( + undefined, + ts.factory.createVariableDeclarationList( + [ts.factory.createVariableDeclaration( + ts.factory.createIdentifier( + argumentsArray[1].parameters[0] && argumentsArray[1].parameters[0].name.getText()), + undefined, + undefined, + ts.factory.createIdentifier(_ITEM) + )], + ts.NodeFlags.Const + ) + ), + ...newArrowNode + ], + true + ) + ) + ) + ], + ts.NodeFlags.Const + ) + ); + } +} + +function createItemIdFuncStatement( + node: ts.CallExpression, + argumentsArray: ts.Expression[] +): ts.VariableStatement { + if (argumentsArray[2] && ts.isArrowFunction(argumentsArray[2])) { + return ts.factory.createVariableStatement( + undefined, + ts.factory.createVariableDeclarationList( + [ts.factory.createVariableDeclaration( + ts.factory.createIdentifier(node.expression.getText() === COMPONENT_FOREACH ? + FOREACHITEMIDFUNC : __LAZYFOREACHITEMIDFUNC), undefined, undefined, + ts.factory.createArrowFunction( + undefined, undefined, + [ts.factory.createParameterDeclaration(undefined, undefined, undefined, + ts.factory.createIdentifier( + argumentsArray[2].parameters[0] ? argumentsArray[2].parameters[0].name.escapedText : '' + ) + )], undefined, + ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), + ts.factory.createIdentifier(argumentsArray[2].body ? argumentsArray[2].body.getText() : '') + ) + )], + ts.NodeFlags.Const + ) + ); + } + +} + +function createUpdateFunctionStatement(argumentsArray: ts.Expression[]): ts.ExpressionStatement { + return ts.factory.createExpressionStatement( + ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createThis(), + ts.factory.createIdentifier(FOREACHUPDATEFUNCTION) + ), + undefined, + addForEachIdFuncParameter(argumentsArray) + ) + ); +} + +function addForEachIdFuncParameter(argumentsArray: ts.Expression[]): ts.Identifier[] { + const addForEachIdFuncParameterArr: ts.Identifier[] = []; + addForEachIdFuncParameterArr.push( + ts.factory.createIdentifier(ELMTID), + ts.factory.createIdentifier(argumentsArray[0] && argumentsArray[0].getText()) + ); + if (argumentsArray[2]) { + addForEachIdFuncParameterArr.push(ts.factory.createIdentifier(FOREACHITEMIDFUNC)); + } + addForEachIdFuncParameterArr.push(ts.factory.createIdentifier(FOREACHITEMGENFUNCTION)); + return addForEachIdFuncParameterArr; +} + +function createLazyForEachStatement(argumentsArray: ts.Expression[]): ts.ExpressionStatement { + return ts.factory.createExpressionStatement( + ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createIdentifier(COMPONENT_LAZYFOREACH), + ts.factory.createIdentifier(COMPONENT_CREATE_FUNCTION) + ), + undefined, + [ts.factory.createStringLiteral(componentInfo.id.toString()), + ts.factory.createThis(), + argumentsArray[0], + ts.factory.createIdentifier(__LAZYFOREACHITEMGENFUNCTION), + ts.factory.createIdentifier(__LAZYFOREACHITEMIDFUNC) + ] + ) + ); +} + function addForEachId(node: ts.ExpressionStatement): ts.ExpressionStatement { const forEachComponent: ts.CallExpression = node.expression as ts.CallExpression; return ts.factory.updateExpressionStatement(node, ts.factory.updateCallExpression( @@ -826,7 +993,7 @@ function addForEachId(node: ts.ExpressionStatement): ts.ExpressionStatement { } function processForEachBlock(node: ts.CallExpression, log: LogInfo[], - isInnerBuilder: boolean = false): ts.ArrowFunction { + isInnerBuilder: boolean = false): ts.NodeArray | ts.ArrowFunction { if (node.arguments.length > 1 && ts.isArrowFunction(node.arguments[1])) { const isLazy: boolean = node.expression.getText() === COMPONENT_LAZYFOREACH; const arrowNode: ts.ArrowFunction = node.arguments[1] as ts.ArrowFunction; @@ -842,14 +1009,22 @@ function processForEachBlock(node: ts.CallExpression, log: LogInfo[], const blockNode: ts.Block = ts.factory.createBlock([statement], true); // @ts-ignore statement.parent = blockNode; - return ts.factory.updateArrowFunction( - arrowNode, arrowNode.modifiers, arrowNode.typeParameters, arrowNode.parameters, - arrowNode.type, arrowNode.equalsGreaterThanToken, processComponentBlock(blockNode, isLazy, log)); + if (compatibleSdkVersion === '8') { + return ts.factory.updateArrowFunction( + arrowNode, arrowNode.modifiers, arrowNode.typeParameters, arrowNode.parameters, + arrowNode.type, arrowNode.equalsGreaterThanToken, processComponentBlock(blockNode, isLazy, log)); + } else { + return processComponentBlock(blockNode, isLazy, log).statements; + } } else { - return ts.factory.updateArrowFunction( - arrowNode, arrowNode.modifiers, arrowNode.typeParameters, arrowNode.parameters, - arrowNode.type, arrowNode.equalsGreaterThanToken, - processComponentBlock(body, isLazy, log, false, isInnerBuilder)); + if (compatibleSdkVersion === '8') { + return ts.factory.updateArrowFunction( + arrowNode, arrowNode.modifiers, arrowNode.typeParameters, arrowNode.parameters, + arrowNode.type, arrowNode.equalsGreaterThanToken, + processComponentBlock(body, isLazy, log, false, isInnerBuilder)); + } else { + return processComponentBlock(body, isLazy, log).statements; + } } } return null; diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts new file mode 100644 index 0000000..0f4f85b --- /dev/null +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2022 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 ParentView { + @State arr: string[] = ['1', '2', '3']; + build() { + List() { + ForEach(this.arr, + item => { + Text(item) + }, + item => item.toString() + ) + } + } +} +` +exports.expectResult = +`class ParentView extends View { + constructor(parent, params) { + super(parent); + this.__arr = new ObservedPropertyObject(['1', '2', '3'], this, "arr"); + this.setInitiallyProvidedValue(params); + } + setInitiallyProvidedValue(params) { + if (params.arr !== undefined) { + this.arr = params.arr; + } + } + setStateSourcePropertiesUnchanged() { + this.__arr.SetPropertyUnchanged(); + } + setOneWaySyncPropertiesUnchanged() { + } + setTwoWaySyncPropertiesUnchanged() { + } + purgeVariableDependenciesOnElmtId(rmElmtId) { + this.__arr.purgeDependencyOnElmtId(rmElmtId); + } + aboutToBeDeleted() { + this.__arr.aboutToBeDeleted(); + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal(); + } + get arr() { + return this.__arr.get(); + } + set arr(newValue) { + this.__arr.set(newValue); + } + render() { + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + List.create(); + if (!isInitialRender) { + List.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + ForEach.create(); + const forEachItemGenFunction = _item => { + const item = _item; + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create(item); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + Text.pop(); + }; + const forEachItemIdFunc = item => item.toString(); + this.forEachUpdateFunction(elmtId, this.arr, forEachItemIdFunc, forEachItemGenFunction); + if (!isInitialRender) { + ForEach.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + ForEach.pop(); + List.pop(); + } + rerender() { + this.__arr.markDependentElementsDirty(this); + this.updateDirtyElements(); + } +} +loadDocument(new ParentView("1", undefined, {})); +` \ No newline at end of file diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts new file mode 100644 index 0000000..1ff6422 --- /dev/null +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts @@ -0,0 +1,276 @@ +/* + * Copyright (c) 2022 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 = ` +class BasicDataSource implements IDataSource { + private listeners: DataChangeListener[] = [] + + public totalCount(): number { + return 0 + } + public getData(index: number): any { + return undefined + } + + registerDataChangeListener(listener: DataChangeListener): void { + if (this.listeners.indexOf(listener) < 0) { + console.info('add listener') + this.listeners.push(listener) + } + } + unregisterDataChangeListener(listener: DataChangeListener): void { + const pos = this.listeners.indexOf(listener); + if (pos >= 0) { + console.info('remove listener') + this.listeners.splice(pos, 1) + } + } + + notifyDataReload(): void { + this.listeners.forEach(listener => { + listener.onDataReloaded() + }) + } + notifyDataAdd(index: number): void { + this.listeners.forEach(listener => { + listener.onDataAdd(index) + }) + } + notifyDataChange(index: number): void { + this.listeners.forEach(listener => { + listener.onDataChange(index) + }) + } + notifyDataDelete(index: number): void { + this.listeners.forEach(listener => { + listener.onDataDelete(index) + }) + } + notifyDataMove(from: number, to: number): void { + this.listeners.forEach(listener => { + listener.onDataMove(from, to) + }) + } +} + +class MyDataSource extends BasicDataSource { + private dataArray: string[] = ['/path/image0', '/path/image1', '/path/image2', '/path/image3'] + + public totalCount(): number { + return this.dataArray.length + } + public getData(index: number): any { + return this.dataArray[index] + } + + public addData(index: number, data: string): void { + this.dataArray.splice(index, 0, data) + this.notifyDataAdd(index) + } + public pushData(data: string): void { + this.dataArray.push(data) + this.notifyDataAdd(this.dataArray.length - 1) + } +} + +@Entry +@Component +struct Test { +private data: MyDataSource = new MyDataSource() +build() { + Grid() { + LazyForEach (this.data, + (row) => { + GridItem() { + Text(row) + } + }, + row => row) + } +} +} +` +exports.expectResult = +`class BasicDataSource { + constructor() { + this.listeners = []; + } + totalCount() { + return 0; + } + getData(index) { + return undefined; + } + registerDataChangeListener(listener) { + if (this.listeners.indexOf(listener) < 0) { + console.info('add listener'); + this.listeners.push(listener); + } + } + unregisterDataChangeListener(listener) { + const pos = this.listeners.indexOf(listener); + if (pos >= 0) { + console.info('remove listener'); + this.listeners.splice(pos, 1); + } + } + notifyDataReload() { + this.listeners.forEach(listener => { + listener.onDataReloaded(); + }); + } + notifyDataAdd(index) { + this.listeners.forEach(listener => { + listener.onDataAdd(index); + }); + } + notifyDataChange(index) { + this.listeners.forEach(listener => { + listener.onDataChange(index); + }); + } + notifyDataDelete(index) { + this.listeners.forEach(listener => { + listener.onDataDelete(index); + }); + } + notifyDataMove(from, to) { + this.listeners.forEach(listener => { + listener.onDataMove(from, to); + }); + } +} +class MyDataSource extends BasicDataSource { + constructor() { + super(...arguments); + this.dataArray = ['/path/image0', '/path/image1', '/path/image2', '/path/image3']; + } + totalCount() { + return this.dataArray.length; + } + getData(index) { + return this.dataArray[index]; + } + addData(index, data) { + this.dataArray.splice(index, 0, data); + this.notifyDataAdd(index); + } + pushData(data) { + this.dataArray.push(data); + this.notifyDataAdd(this.dataArray.length - 1); + } +} +class Test extends View { + constructor(parent, params) { + super(parent); + this.data = new MyDataSource(); + this.setInitiallyProvidedValue(params); + } + setInitiallyProvidedValue(params) { + if (params.data !== undefined) { + this.data = params.data; + } + } + setStateSourcePropertiesUnchanged() { + } + setOneWaySyncPropertiesUnchanged() { + } + setTwoWaySyncPropertiesUnchanged() { + } + purgeVariableDependenciesOnElmtId(rmElmtId) { + } + aboutToBeDeleted() { + this.data = undefined; + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal(); + } + render() { + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Grid.create(); + if (!isInitialRender) { + Grid.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + const __lazyForEachItemGenFunction = _item => { + const row = _item; + { + const isLazyCreate = true; + const itemCreation = (elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + GridItem.create(deepRenderFunction, isLazyCreate); + if (!isInitialRender) { + GridItem.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }; + const observedShallowRender = () => { + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + GridItem.create(deepRenderFunction, isLazyCreate); + if (!isInitialRender) { + GridItem.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + GridItem.pop(); + }; + const observedDeepRender = () => { + this.observeComponentCreation(itemCreation); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create(row); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + Text.pop(); + GridItem.pop(); + }; + const deepRenderFunction = (elmtId, isInitialRender) => { + itemCreation(elmtId, isInitialRender); + this.updateFuncByElmtId.set(elmtId, itemCreation); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create(row); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + Text.pop(); + GridItem.pop(); + }; + if (isLazyCreate) { + observedShallowRender(); + } + else { + observedDeepRender(); + } + } + }; + const __lazyForEachItemIdFunc = row => row; + LazyForEach.create("1", this, this.data, __lazyForEachItemGenFunction, __lazyForEachItemIdFunc); + LazyForEach.pop(); + Grid.pop(); + } + rerender() { + this.updateDirtyElements(); + } +} +loadDocument(new Test("1", undefined, {})); +` \ No newline at end of file From 54848e4e1dd4cff50cabd9935cfeb3f5211e1681 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Thu, 28 Jul 2022 15:22:57 +0800 Subject: [PATCH 06/33] Update: @objectLink transform Signed-off-by: laibo102 Change-Id: I8063b73eb5e72d57094c4448abeb023d40508c73 (cherry picked from commit 426b803c8eeb6d9d7e93196eeccb4d10ce238ad1) Signed-off-by: laibo102 --- compiler/src/pre_define.ts | 3 +- compiler/src/process_component_class.ts | 5 +- .../@objectLink/@objectLink.ts | 203 ++++++++++++++++++ 3 files changed, 208 insertions(+), 3 deletions(-) create mode 100644 compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index ced40f0..67c6908 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -290,7 +290,8 @@ export const SETPROPERTYUNCHANGED: string = 'SetPropertyUnchanged'; export const ABOUTTOBEDELETEDINTERNAL: string = 'aboutToBeDeletedInternal'; export const UPDATEDIRTYELEMENTS: string = 'updateDirtyElements'; export const BASICDECORATORS: Set = new Set([COMPONENT_STATE_DECORATOR, COMPONENT_PROP_DECORATOR, - COMPONENT_LINK_DECORATOR]); + COMPONENT_LINK_DECORATOR, COMPONENT_OBJECT_LINK_DECORATOR]); +export const LINKS_DECORATORS: Set = new Set([COMPONENT_LINK_DECORATOR, COMPONENT_OBJECT_LINK_DECORATOR]) export const ISINITIALRENDER: string = 'isInitialRender'; export const ELMTID: string = 'elmtId'; export const STARTGETACCESSRECORDINGFOR: string = 'StartGetAccessRecordingFor'; diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index d9291a8..820098e 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -68,7 +68,8 @@ import { SETTWOWAYSYNCPROPERTIESUNCHANGED, RMELMTID, ABOUTTOBEDELETEDINTERNAL, - UPDATEDIRTYELEMENTS + UPDATEDIRTYELEMENTS, + LINKS_DECORATORS } from './pre_define'; import { BUILDIN_STYLE_NAMES, @@ -237,7 +238,7 @@ function processPropertyUnchanged( setStateUnchangedStatements.push(propertyUnchanged); } else if (result.getDecoratorName() === COMPONENT_PROP_DECORATOR) { setOneWayUnchangedStatements.push(propertyUnchanged); - } else if(result.getDecoratorName() === COMPONENT_LINK_DECORATOR) { + } else if(LINKS_DECORATORS.has(result.getDecoratorName())) { setTwoWayUnchangedStatements.push(propertyUnchanged); } } diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts new file mode 100644 index 0000000..6ac62e1 --- /dev/null +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2022 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 = ` +var nextID: number = 0; +@Observed +class Model { + text : string = ''; + color: string = '#00ff00'; + constructor(t: string, c: string) { + this.text = t; + this.color = c; + } +} + +@Component +struct CustomText { + @ObjectLink model: Model; + build() { + Row() { + Text(this.model.text) + } + } +} + +@Entry +@Component +struct Parent { + nextId: number = 1; + @State models : Model[] = [ new Model('0', '#ffffff'), new Model('1', '#fff456') ]; + build() { + Column() { + ForEach (this.models, (item) => { + CustomText({model: item}) + }, + (item) => item.text + ) + } + } +} +` +exports.expectResult = +`var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var nextID = 0; +let Model = class Model { + constructor(t, c) { + this.text = ''; + this.color = '#00ff00'; + this.text = t; + this.color = c; + } +}; +Model = __decorate([ + Observed +], Model); +class CustomText extends View { + constructor(parent, params) { + super(parent); + this.__model = new SynchedPropertyNesedObject(params.model, this, "model"); + this.setInitiallyProvidedValue(params); + } + setInitiallyProvidedValue(params) { + this.__model.set(params.model); + } + setStateSourcePropertiesUnchanged() { + } + setOneWaySyncPropertiesUnchanged() { + } + setTwoWaySyncPropertiesUnchanged() { + this.__model.SetPropertyUnchanged(); + } + purgeVariableDependenciesOnElmtId(rmElmtId) { + this.__model.purgeDependencyOnElmtId(rmElmtId); + } + aboutToBeDeleted() { + this.__model.aboutToBeDeleted(); + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal(); + } + get model() { + return this.__model.get(); + } + render() { + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Row.create(); + if (!isInitialRender) { + Row.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create(this.model.text); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + Text.pop(); + Row.pop(); + } + rerender() { + this.__model.markDependentElementsDirty(this); + this.updateDirtyElements(); + } +} +class Parent extends View { + constructor(parent, params) { + super(parent); + this.nextId = 1; + this.__models = new ObservedPropertyObject([new Model('0', '#ffffff'), new Model('1', '#fff456')], this, "models"); + this.setInitiallyProvidedValue(params); + } + setInitiallyProvidedValue(params) { + if (params.nextId !== undefined) { + this.nextId = params.nextId; + } + if (params.models !== undefined) { + this.models = params.models; + } + } + setStateSourcePropertiesUnchanged() { + this.__models.SetPropertyUnchanged(); + } + setOneWaySyncPropertiesUnchanged() { + } + setTwoWaySyncPropertiesUnchanged() { + } + purgeVariableDependenciesOnElmtId(rmElmtId) { + this.__models.purgeDependencyOnElmtId(rmElmtId); + } + aboutToBeDeleted() { + this.nextId = undefined; + this.__models.aboutToBeDeleted(); + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal(); + } + get models() { + return this.__models.get(); + } + set models(newValue) { + this.__models.set(newValue); + } + render() { + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Column.create(); + if (!isInitialRender) { + Column.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + ForEach.create(); + const forEachItemGenFunction = _item => { + const item = _item; + let earlierCreatedChild_2 = this.findChildById("2"); + if (earlierCreatedChild_2 == undefined) { + View.create(new CustomText("2", this, { model: item })); + } + else { + earlierCreatedChild_2.updateWithValueParams({ + model: item + }); + View.create(earlierCreatedChild_2); + } + }; + const forEachItemIdFunc = item => item.text; + this.forEachUpdateFunction(elmtId, this.models, forEachItemIdFunc, forEachItemGenFunction); + if (!isInitialRender) { + ForEach.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + ForEach.pop(); + Column.pop(); + } + rerender() { + this.__models.markDependentElementsDirty(this); + this.updateDirtyElements(); + } +} +loadDocument(new Parent("1", undefined, {})); +` \ No newline at end of file From 14c579f362298aab0c6ce60c8c48cc72a4b38755 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Thu, 28 Jul 2022 17:05:01 +0800 Subject: [PATCH 07/33] Update: Custom Component transform Signed-off-by: laibo102 Change-Id: Ic389f1e2fb9015c2a48c01eb13377caf7e61e947 (cherry picked from commit 5381df22daac379f6c3c388a79873a89bd6158a5) Signed-off-by: laibo102 --- compiler/src/pre_define.ts | 4 +- compiler/src/process_component_member.ts | 28 +-- compiler/src/process_custom_component.ts | 71 ++++++- .../custom_component/custom_component.ts | 182 ++++++++++++++++++ .../@link/@link.ts | 12 +- .../@objectLink/@objectLink.ts | 14 +- .../@prop/@prop.ts | 14 +- 7 files changed, 281 insertions(+), 44 deletions(-) create mode 100644 compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 67c6908..2cf10b4 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -291,7 +291,7 @@ export const ABOUTTOBEDELETEDINTERNAL: string = 'aboutToBeDeletedInternal'; export const UPDATEDIRTYELEMENTS: string = 'updateDirtyElements'; export const BASICDECORATORS: Set = new Set([COMPONENT_STATE_DECORATOR, COMPONENT_PROP_DECORATOR, COMPONENT_LINK_DECORATOR, COMPONENT_OBJECT_LINK_DECORATOR]); -export const LINKS_DECORATORS: Set = new Set([COMPONENT_LINK_DECORATOR, COMPONENT_OBJECT_LINK_DECORATOR]) +export const LINKS_DECORATORS: Set = new Set([COMPONENT_LINK_DECORATOR, COMPONENT_OBJECT_LINK_DECORATOR]); export const ISINITIALRENDER: string = 'isInitialRender'; export const ELMTID: string = 'elmtId'; export const STARTGETACCESSRECORDINGFOR: string = 'StartGetAccessRecordingFor'; @@ -310,3 +310,5 @@ export const _ITEM: string = '_item'; export const FOREACHITEMIDFUNC: string = 'forEachItemIdFunc'; export const __LAZYFOREACHITEMIDFUNC: string = '__lazyForEachItemIdFunc'; export const FOREACHUPDATEFUNCTION: string = 'forEachUpdateFunction'; +export const ALLOCATENEWELMETIDFORNEXTCOMPONENT: string = 'AllocateNewElmetIdForNextComponent'; +export const STATE_OBJECTLINK_DECORATORS: string[] = [COMPONENT_STATE_DECORATOR, COMPONENT_OBJECT_LINK_DECORATOR]; diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index 8ee76b0..3c457d4 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -367,7 +367,7 @@ function processStateDecorators(node: ts.PropertyDeclaration, decorator: string, const variableWithUnderLink: string = '__' + name.escapedText.toString(); updateResult.setPropertyUnchanged(createPropertyUnchangedStatement(variableWithUnderLink)); updateResult.setDecoratorName(decorator); - updateResult.setPurgeVariableDepStatement(createPurgeVariableDepStatement(variableWithUnderLink)); + updateResult.setPurgeVariableDepStatement(createPurgeVariableDepStatement(variableWithUnderLink)); updateResult.setRerenderStatement(createRerenderStatement(variableWithUnderLink)); } } @@ -700,17 +700,21 @@ function addCustomComponentId(node: ts.NewExpression, componentName: string, if (!argumentsArray) { argumentsArray = [ts.factory.createObjectLiteralExpression([], true)]; } - ++componentInfo.id; - argumentsArray.unshift(isInnerBuilder ? ts.factory.createBinaryExpression( - ts.factory.createStringLiteral(path.basename(transformLog.sourceFile.fileName, EXTNAME_ETS) + '_'), - ts.factory.createToken(ts.SyntaxKind.PlusToken), ts.factory.createIdentifier(_GENERATE_ID)) : - ts.factory.createStringLiteral(componentInfo.id.toString()), - isInnerBuilder ? ts.factory.createConditionalExpression( - ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT), - ts.factory.createToken(ts.SyntaxKind.QuestionToken), - ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT), - ts.factory.createToken(ts.SyntaxKind.ColonToken), ts.factory.createThis() - ) : ts.factory.createThis()); + if (compatibleSdkVersion === '8') { + ++componentInfo.id; + argumentsArray.unshift(isInnerBuilder ? ts.factory.createBinaryExpression( + ts.factory.createStringLiteral(path.basename(transformLog.sourceFile.fileName, EXTNAME_ETS) + '_'), + ts.factory.createToken(ts.SyntaxKind.PlusToken), ts.factory.createIdentifier(_GENERATE_ID)) : + ts.factory.createStringLiteral(componentInfo.id.toString()), + isInnerBuilder ? ts.factory.createConditionalExpression( + ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT), + ts.factory.createToken(ts.SyntaxKind.QuestionToken), + ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT), + ts.factory.createToken(ts.SyntaxKind.ColonToken), ts.factory.createThis() + ) : ts.factory.createThis()); + } else { + argumentsArray.unshift(ts.factory.createThis()); + } node = ts.factory.updateNewExpression(node, node.expression, node.typeArguments, argumentsArray); } else if (argumentsArray) { diff --git a/compiler/src/process_custom_component.ts b/compiler/src/process_custom_component.ts index 6c69be9..815b9c4 100644 --- a/compiler/src/process_custom_component.ts +++ b/compiler/src/process_custom_component.ts @@ -34,7 +34,13 @@ import { CUSTOM_COMPONENT_MARK_STATIC_FUNCTION, COMPONENT_COMMON, COMPONENT_CONSTRUCTOR_PARENT, - GENERATE_ID + GENERATE_ID, + ELMTID, + VIEWSTACKPROCESSOR, + STARTGETACCESSRECORDINGFOR, + STOPGETACCESSRECORDING, + ALLOCATENEWELMETIDFORNEXTCOMPONENT, + STATE_OBJECTLINK_DECORATORS } from './pre_define'; import { propertyCollection, @@ -64,6 +70,7 @@ import { createFunction } from './utils'; import { bindComponentAttr } from './process_component_build'; +import { compatibleSdkVersion } from '../main'; const localArray: string[] = [...observedPropertyDecorators, COMPONENT_NON_DECORATOR, COMPONENT_PROP_DECORATOR, COMPONENT_OBJECT_LINK_DECORATOR]; @@ -155,10 +162,60 @@ function addCustomComponent(node: ts.ExpressionStatement, newStatements: ts.Stat function addCustomComponentStatements(node: ts.ExpressionStatement, newStatements: ts.Statement[], newNode: ts.NewExpression, name: string, props: ts.ObjectLiteralElementLike[], isInnerBuilder: boolean = false): void { - const id: string = componentInfo.id.toString(); - newStatements.push(createFindChildById(id, name, isInnerBuilder), createCustomComponentIfStatement(id, - ts.factory.updateExpressionStatement(node, createViewCreate(newNode)), - ts.factory.createObjectLiteralExpression(props, true), name)); + if (compatibleSdkVersion === '8') { + const id: string = componentInfo.id.toString(); + newStatements.push(createFindChildById(id, name, isInnerBuilder), createCustomComponentIfStatement(id, + ts.factory.updateExpressionStatement(node, createViewCreate(newNode)), + ts.factory.createObjectLiteralExpression(props, true), name)); + } else { + newStatements.push(createCustomComponent(newNode)); + } +} + +function createCustomComponent(newNode: ts.NewExpression): ts.Block { + return ts.factory.createBlock( + [ + ts.factory.createVariableStatement(undefined, + ts.factory.createVariableDeclarationList( + [ts.factory.createVariableDeclaration( + ts.factory.createIdentifier(ELMTID), undefined, undefined, + ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createIdentifier(VIEWSTACKPROCESSOR), + ts.factory.createIdentifier(ALLOCATENEWELMETIDFORNEXTCOMPONENT) + ), undefined, []))], + ts.NodeFlags.Const + ) + ), + ts.factory.createExpressionStatement( + ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createIdentifier(VIEWSTACKPROCESSOR), + ts.factory.createIdentifier(STARTGETACCESSRECORDINGFOR) + ), undefined, + [ts.factory.createIdentifier(ELMTID)] + ) + ), + ts.factory.createExpressionStatement( + ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createIdentifier(BASE_COMPONENT_NAME), + ts.factory.createIdentifier(COMPONENT_CREATE_FUNCTION) + ), undefined, + [newNode] + ) + ), + ts.factory.createExpressionStatement( + ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression( + ts.factory.createIdentifier(VIEWSTACKPROCESSOR), + ts.factory.createIdentifier(STOPGETACCESSRECORDING) + ), undefined, [] + ) + ) + ], + true + ); } function validateCustomComponentPrams(node: ts.CallExpression, name: string, @@ -344,7 +401,9 @@ function isCorrectInitFormParent(parent: string, child: string): boolean { } break; case COMPONENT_OBJECT_LINK_DECORATOR: - if (parent === COMPONENT_STATE_DECORATOR) { + if (compatibleSdkVersion === '8' && parent === COMPONENT_STATE_DECORATOR) { + return true; + } else if (compatibleSdkVersion === '9' && STATE_OBJECTLINK_DECORATORS.includes(parent)) { return true; } break; diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts b/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts new file mode 100644 index 0000000..319d4f7 --- /dev/null +++ b/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2022 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 = ` +@Component +@Entry +struct MyComponent { + build() { + Column() { + Banner() + Banner() + .width(100) + Banner() + .width(100) + .height(200) + Banner({value: "Hello"}) + Banner({value: "Hello"}) + .width(100) + Banner({value: "Hello"}) + .width(100) + .height(200) + } + } +} + +@Component +struct Banner { + value: string = "Hello" + build() { + Column() { + Text(this.value) + } + } +}` + +exports.expectResult = +`class MyComponent extends View { + constructor(parent, params) { + super(parent); + this.setInitiallyProvidedValue(params); + } + setInitiallyProvidedValue(params) { + } + setStateSourcePropertiesUnchanged() { + } + setOneWaySyncPropertiesUnchanged() { + } + setTwoWaySyncPropertiesUnchanged() { + } + purgeVariableDependenciesOnElmtId(rmElmtId) { + } + aboutToBeDeleted() { + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal(); + } + render() { + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Column.create(); + if (!isInitialRender) { + Column.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + { + const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + View.create(new Banner(this, {})); + ViewStackProcessor.StopGetAccessRecording(); + } + __Common__.create(); + __Common__.width(100); + { + const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + View.create(new Banner(this, {})); + ViewStackProcessor.StopGetAccessRecording(); + } + __Common__.pop(); + __Common__.create(); + __Common__.width(100); + __Common__.height(200); + { + const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + View.create(new Banner(this, {})); + ViewStackProcessor.StopGetAccessRecording(); + } + __Common__.pop(); + { + const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + View.create(new Banner(this, { value: "Hello" })); + ViewStackProcessor.StopGetAccessRecording(); + } + __Common__.create(); + __Common__.width(100); + { + const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + View.create(new Banner(this, { value: "Hello" })); + ViewStackProcessor.StopGetAccessRecording(); + } + __Common__.pop(); + __Common__.create(); + __Common__.width(100); + __Common__.height(200); + { + const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + View.create(new Banner(this, { value: "Hello" })); + ViewStackProcessor.StopGetAccessRecording(); + } + __Common__.pop(); + Column.pop(); + } + rerender() { + this.updateDirtyElements(); + } +} +class Banner extends View { + constructor(parent, params) { + super(parent); + this.value = "Hello"; + this.setInitiallyProvidedValue(params); + } + setInitiallyProvidedValue(params) { + if (params.value !== undefined) { + this.value = params.value; + } + } + setStateSourcePropertiesUnchanged() { + } + setOneWaySyncPropertiesUnchanged() { + } + setTwoWaySyncPropertiesUnchanged() { + } + purgeVariableDependenciesOnElmtId(rmElmtId) { + } + aboutToBeDeleted() { + this.value = undefined; + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal(); + } + render() { + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Column.create(); + if (!isInitialRender) { + Column.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create(this.value); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + Text.pop(); + Column.pop(); + } + rerender() { + this.updateDirtyElements(); + } +} +loadDocument(new MyComponent("1", undefined, {})); +` \ No newline at end of file diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts index 2f94dd3..0ae1ad8 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts @@ -120,13 +120,11 @@ class ParentComponent extends View { } ViewStackProcessor.StopGetAccessRecording(); }); - let earlierCreatedChild_2 = this.findChildById("2"); - if (earlierCreatedChild_2 == undefined) { - View.create(new LinkComponent("2", this, { counter: this.__value })); - } - else { - earlierCreatedChild_2.updateWithValueParams({}); - View.create(earlierCreatedChild_2); + { + const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + View.create(new LinkComponent(this, { counter: this.__value })); + ViewStackProcessor.StopGetAccessRecording(); } Column.pop(); } diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts index 6ac62e1..8a4ab18 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts @@ -173,15 +173,11 @@ class Parent extends View { ForEach.create(); const forEachItemGenFunction = _item => { const item = _item; - let earlierCreatedChild_2 = this.findChildById("2"); - if (earlierCreatedChild_2 == undefined) { - View.create(new CustomText("2", this, { model: item })); - } - else { - earlierCreatedChild_2.updateWithValueParams({ - model: item - }); - View.create(earlierCreatedChild_2); + { + const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + View.create(new CustomText(this, { model: item })); + ViewStackProcessor.StopGetAccessRecording(); } }; const forEachItemIdFunc = item => item.text; diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts index 59d572b..077778a 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts @@ -120,15 +120,11 @@ class ParentComponent extends View { } ViewStackProcessor.StopGetAccessRecording(); }); - let earlierCreatedChild_2 = this.findChildById("2"); - if (earlierCreatedChild_2 == undefined) { - View.create(new PropComponent("2", this, { counter: this.__value })); - } - else { - earlierCreatedChild_2.updateWithValueParams({ - counter: this.__value - }); - View.create(earlierCreatedChild_2); + { + const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + View.create(new PropComponent(this, { counter: this.__value })); + ViewStackProcessor.StopGetAccessRecording(); } Column.pop(); } From 6ddba48e6065b1761987fff3f3493642184e620f Mon Sep 17 00:00:00 2001 From: laibo102 Date: Thu, 28 Jul 2022 20:14:56 +0800 Subject: [PATCH 08/33] Update: Init transform Signed-off-by: laibo102 Change-Id: Ia3f4c1681c0d51473c8fe1092c59c5a6fae3c403 (cherry picked from commit b5f494f18a57006aa52060e138f096c86be66b8a) Signed-off-by: laibo102 --- compiler/src/pre_define.ts | 1 + compiler/src/process_component_build.ts | 15 ++- compiler/src/process_ui_syntax.ts | 94 ++++++++++++++++--- .../custom_component/custom_component.ts | 8 +- .../render_component/foreach/foreach.ts | 6 +- .../render_component/if/if.ts | 6 +- .../render_component/item/GridItem.ts | 6 +- .../render_component/item/ListItem.ts | 6 +- .../lazyforeach/lazyforeach.ts | 6 +- .../@link/@link.ts | 8 +- .../@objectLink/@objectLink.ts | 8 +- .../@prop/@prop.ts | 8 +- .../@state/@state.ts | 6 +- 13 files changed, 137 insertions(+), 41 deletions(-) diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 2cf10b4..556e37a 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -312,3 +312,4 @@ export const __LAZYFOREACHITEMIDFUNC: string = '__lazyForEachItemIdFunc'; export const FOREACHUPDATEFUNCTION: string = 'forEachUpdateFunction'; export const ALLOCATENEWELMETIDFORNEXTCOMPONENT: string = 'AllocateNewElmetIdForNextComponent'; export const STATE_OBJECTLINK_DECORATORS: string[] = [COMPONENT_STATE_DECORATOR, COMPONENT_OBJECT_LINK_DECORATOR]; +export const COMPONENT_INITIAl_RENDER_FUNCTION: string = 'initialRender'; diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 26fb1af..fd57975 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -79,7 +79,8 @@ import { _ITEM, FOREACHITEMIDFUNC, __LAZYFOREACHITEMIDFUNC, - FOREACHUPDATEFUNCTION + FOREACHUPDATEFUNCTION, + COMPONENT_INITIAl_RENDER_FUNCTION } from './pre_define'; import { INNER_COMPONENT_NAMES, @@ -118,7 +119,12 @@ import { CUSTOM_COMPONENT } from '../lib/pre_define'; export function processComponentBuild(node: ts.MethodDeclaration, log: LogInfo[]): ts.MethodDeclaration { let newNode: ts.MethodDeclaration; - const renderNode: ts.Identifier = ts.factory.createIdentifier(COMPONENT_RENDER_FUNCTION); + let renderNode: ts.Identifier; + if (compatibleSdkVersion === '8') { + renderNode = ts.factory.createIdentifier(COMPONENT_RENDER_FUNCTION); + } else { + renderNode = ts.factory.createIdentifier(COMPONENT_INITIAl_RENDER_FUNCTION); + } if (node.body && node.body.statements && node.body.statements.length && validateRootNode(node, log)) { newNode = ts.factory.updateMethodDeclaration(node, node.decorators, node.modifiers, @@ -834,7 +840,7 @@ function processForEachComponentNew(node: ts.ExpressionStatement, newStatements: log: LogInfo[]): void { const newForEachStatements: ts.Statement[] = []; const popNode: ts.ExpressionStatement = ts.factory.createExpressionStatement(createFunction( - (node.expression as ts.CallExpression ).expression as ts.Identifier, + (node.expression as ts.CallExpression).expression as ts.Identifier, ts.factory.createIdentifier(COMPONENT_POP_FUNCTION), null)); if (ts.isCallExpression(node.expression)) { const argumentsArray: ts.Expression[] = Array.from(node.expression.arguments); @@ -842,7 +848,7 @@ function processForEachComponentNew(node: ts.ExpressionStatement, newStatements: ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression( node.expression.expression as ts.Identifier, ts.factory.createIdentifier(COMPONENT_CREATE_FUNCTION)), undefined, [])); - const newArrowNode: ts.NodeArray = + const newArrowNode: ts.NodeArray = processForEachBlock(node.expression, log) as ts.NodeArray; const itemGenFunctionStatement: ts.VariableStatement = createItemGenFunctionStatement(node.expression, argumentsArray, newArrowNode); @@ -937,7 +943,6 @@ function createItemIdFuncStatement( ) ); } - } function createUpdateFunctionStatement(argumentsArray: ts.Expression[]): ts.ExpressionStatement { diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index 233f4cf..2012447 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -54,7 +54,11 @@ import { COMPONENT_COMMON, EXTNAME_ETS, GENERATE_ID, - _GENERATE_ID + _GENERATE_ID, + VIEWSTACKPROCESSOR, + STARTGETACCESSRECORDINGFOR, + ALLOCATENEWELMETIDFORNEXTCOMPONENT, + STOPGETACCESSRECORDING } from './pre_define'; import { componentInfo, @@ -84,7 +88,8 @@ import { } from './validate_ui_syntax'; import { resources, - projectConfig + projectConfig, + compatibleSdkVersion } from '../main'; import { createCustomComponentNewExpression, createViewCreate } from './process_component_member'; @@ -581,9 +586,15 @@ export function isExtendFunction(node: ts.FunctionDeclaration): string { function createEntryNode(node: ts.SourceFile, context: ts.TransformationContext): ts.SourceFile { if (componentCollection.previewComponent.size === 0 || !projectConfig.isPreview) { if (componentCollection.entryComponent) { - const entryNode: ts.ExpressionStatement = - createEntryFunction(componentCollection.entryComponent, context); - return context.factory.updateSourceFile(node, [...node.statements, entryNode]); + if (compatibleSdkVersion === '8') { + const entryNode: ts.ExpressionStatement = + createEntryFunction(componentCollection.entryComponent, context) as ts.ExpressionStatement; + return context.factory.updateSourceFile(node, [...node.statements, entryNode]); + } else { + const entryNodes: ts.ExpressionStatement[] = + createEntryFunction(componentCollection.entryComponent, context) as ts.ExpressionStatement[]; + return context.factory.updateSourceFile(node, [...node.statements, ...entryNodes]); + } } else { return node; } @@ -595,7 +606,7 @@ function createEntryNode(node: ts.SourceFile, context: ts.TransformationContext) } function createEntryFunction(name: string, context: ts.TransformationContext) - : ts.ExpressionStatement { + : ts.ExpressionStatement | ts.ExpressionStatement[] { let localStorageName: string; const localStorageNum: number = localStorageLinkCollection.get(name).size + localStoragePropCollection.get(name).size; @@ -619,12 +630,71 @@ function createEntryFunction(name: string, context: ts.TransformationContext) if (localStorageName) { newArray.push(context.factory.createIdentifier(localStorageName)); } - const newExpressionStatement: ts.ExpressionStatement = - context.factory.createExpressionStatement(context.factory.createCallExpression( - context.factory.createIdentifier(PAGE_ENTRY_FUNCTION_NAME), undefined, - [context.factory.createNewExpression(context.factory.createIdentifier(name), - undefined, newArray)])); - return newExpressionStatement; + if (compatibleSdkVersion === '8') { + const newExpressionStatement: ts.ExpressionStatement = + context.factory.createExpressionStatement(context.factory.createCallExpression( + context.factory.createIdentifier(PAGE_ENTRY_FUNCTION_NAME), undefined, + [context.factory.createNewExpression(context.factory.createIdentifier(name), + undefined, newArray)])); + return newExpressionStatement; + } else { + return [ + createStartGetAccessRecording(context), + createLoadDocument(context, name), + createStopGetAccessRecording(context) + ]; + } +} + +function createStartGetAccessRecording(context: ts.TransformationContext): ts.ExpressionStatement { + return context.factory.createExpressionStatement( + context.factory.createCallExpression( + context.factory.createPropertyAccessExpression( + context.factory.createIdentifier(VIEWSTACKPROCESSOR), + context.factory.createIdentifier(STARTGETACCESSRECORDINGFOR) + ), + undefined, + [context.factory.createCallExpression( + context.factory.createPropertyAccessExpression( + context.factory.createIdentifier(VIEWSTACKPROCESSOR), + context.factory.createIdentifier(ALLOCATENEWELMETIDFORNEXTCOMPONENT) + ), + undefined, + [] + )] + ) + ); +} + +function createLoadDocument(context: ts.TransformationContext, name: string): ts.ExpressionStatement { + return context.factory.createExpressionStatement( + context.factory.createCallExpression( + context.factory.createIdentifier(PAGE_ENTRY_FUNCTION_NAME), + undefined, + [context.factory.createNewExpression( + context.factory.createIdentifier(name), + undefined, + [context.factory.createIdentifier('undefined'), + context.factory.createObjectLiteralExpression( + [], + false + )] + )] + ) + ); +} + +function createStopGetAccessRecording(context: ts.TransformationContext): ts.ExpressionStatement { + return context.factory.createExpressionStatement( + context.factory.createCallExpression( + context.factory.createPropertyAccessExpression( + context.factory.createIdentifier(VIEWSTACKPROCESSOR), + context.factory.createIdentifier(STOPGETACCESSRECORDING) + ), + undefined, + [] + ) + ); } function createPreviewComponentFunction(name: string, context: ts.TransformationContext) diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts b/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts index 319d4f7..a5a4f6f 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts @@ -65,7 +65,7 @@ exports.expectResult = SubscriberManager.Get().delete(this.id__()); this.aboutToBeDeletedInternal(); } - render() { + initialRender() { this.observeComponentCreation((elmtId, isInitialRender) => { ViewStackProcessor.StartGetAccessRecordingFor(elmtId); Column.create(); @@ -154,7 +154,7 @@ class Banner extends View { SubscriberManager.Get().delete(this.id__()); this.aboutToBeDeletedInternal(); } - render() { + initialRender() { this.observeComponentCreation((elmtId, isInitialRender) => { ViewStackProcessor.StartGetAccessRecordingFor(elmtId); Column.create(); @@ -178,5 +178,7 @@ class Banner extends View { this.updateDirtyElements(); } } -loadDocument(new MyComponent("1", undefined, {})); +ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); +loadDocument(new MyComponent(undefined, {})); +ViewStackProcessor.StopGetAccessRecording(); ` \ No newline at end of file diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts index 0f4f85b..d5c6d6e 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts @@ -63,7 +63,7 @@ exports.expectResult = set arr(newValue) { this.__arr.set(newValue); } - render() { + initialRender() { this.observeComponentCreation((elmtId, isInitialRender) => { ViewStackProcessor.StartGetAccessRecordingFor(elmtId); List.create(); @@ -102,5 +102,7 @@ exports.expectResult = this.updateDirtyElements(); } } -loadDocument(new ParentView("1", undefined, {})); +ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); +loadDocument(new ParentView(undefined, {})); +ViewStackProcessor.StopGetAccessRecording(); ` \ No newline at end of file diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts index 124b4ee..4a33c5c 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts @@ -95,7 +95,7 @@ exports.expectResult = set toggle3(newValue) { this.__toggle3.set(newValue); } - render() { + initialRender() { this.observeComponentCreation((elmtId, isInitialRender) => { ViewStackProcessor.StartGetAccessRecordingFor(elmtId); Column.create(); @@ -170,5 +170,7 @@ exports.expectResult = this.updateDirtyElements(); } } -loadDocument(new IFView("1", undefined, {})); +ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); +loadDocument(new IFView(undefined, {})); +ViewStackProcessor.StopGetAccessRecording(); ` \ No newline at end of file diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts index 30b25f1..8f7aedc 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts @@ -44,7 +44,7 @@ exports.expectResult = SubscriberManager.Get().delete(this.id__()); this.aboutToBeDeletedInternal(); } - render() { + initialRender() { { const isLazyCreate = true; const itemCreation = (elmtId, isInitialRender) => { @@ -109,5 +109,7 @@ exports.expectResult = this.updateDirtyElements(); } } -loadDocument(new ParentView("1", undefined, {})); +ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); +loadDocument(new ParentView(undefined, {})); +ViewStackProcessor.StopGetAccessRecording(); ` \ No newline at end of file diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts index 62638a5..4e334ea 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts @@ -44,7 +44,7 @@ exports.expectResult = SubscriberManager.Get().delete(this.id__()); this.aboutToBeDeletedInternal(); } - render() { + initialRender() { { const isLazyCreate = true; const itemCreation = (elmtId, isInitialRender) => { @@ -109,5 +109,7 @@ exports.expectResult = this.updateDirtyElements(); } } -loadDocument(new ParentView("1", undefined, {})); +ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); +loadDocument(new ParentView(undefined, {})); +ViewStackProcessor.StopGetAccessRecording(); ` \ No newline at end of file diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts index 1ff6422..40b64e6 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts @@ -196,7 +196,7 @@ class Test extends View { SubscriberManager.Get().delete(this.id__()); this.aboutToBeDeletedInternal(); } - render() { + initialRender() { this.observeComponentCreation((elmtId, isInitialRender) => { ViewStackProcessor.StartGetAccessRecordingFor(elmtId); Grid.create(); @@ -272,5 +272,7 @@ class Test extends View { this.updateDirtyElements(); } } -loadDocument(new Test("1", undefined, {})); +ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); +loadDocument(new Test(undefined, {})); +ViewStackProcessor.StopGetAccessRecording(); ` \ No newline at end of file diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts index 0ae1ad8..ad22cd4 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts @@ -63,7 +63,7 @@ exports.expectResult = set counter(newValue) { this.__counter.set(newValue); } - render() { + initialRender() { this.observeComponentCreation((elmtId, isInitialRender) => { ViewStackProcessor.StartGetAccessRecordingFor(elmtId); Text.create(this.counter); @@ -111,7 +111,7 @@ class ParentComponent extends View { set value(newValue) { this.__value.set(newValue); } - render() { + initialRender() { this.observeComponentCreation((elmtId, isInitialRender) => { ViewStackProcessor.StartGetAccessRecordingFor(elmtId); Column.create(); @@ -133,5 +133,7 @@ class ParentComponent extends View { this.updateDirtyElements(); } } -loadDocument(new ParentComponent("1", undefined, {})); +ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); +loadDocument(new ParentComponent(undefined, {})); +ViewStackProcessor.StopGetAccessRecording(); ` \ No newline at end of file diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts index 8a4ab18..e89e261 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts @@ -97,7 +97,7 @@ class CustomText extends View { get model() { return this.__model.get(); } - render() { + initialRender() { this.observeComponentCreation((elmtId, isInitialRender) => { ViewStackProcessor.StartGetAccessRecordingFor(elmtId); Row.create(); @@ -159,7 +159,7 @@ class Parent extends View { set models(newValue) { this.__models.set(newValue); } - render() { + initialRender() { this.observeComponentCreation((elmtId, isInitialRender) => { ViewStackProcessor.StartGetAccessRecordingFor(elmtId); Column.create(); @@ -195,5 +195,7 @@ class Parent extends View { this.updateDirtyElements(); } } -loadDocument(new Parent("1", undefined, {})); +ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); +loadDocument(new Parent(undefined, {})); +ViewStackProcessor.StopGetAccessRecording(); ` \ No newline at end of file diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts index 077778a..df78558 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts @@ -63,7 +63,7 @@ exports.expectResult = set counter(newValue) { this.__counter.set(newValue); } - render() { + initialRender() { this.observeComponentCreation((elmtId, isInitialRender) => { ViewStackProcessor.StartGetAccessRecordingFor(elmtId); Text.create(this.counter); @@ -111,7 +111,7 @@ class ParentComponent extends View { set value(newValue) { this.__value.set(newValue); } - render() { + initialRender() { this.observeComponentCreation((elmtId, isInitialRender) => { ViewStackProcessor.StartGetAccessRecordingFor(elmtId); Column.create(); @@ -133,5 +133,7 @@ class ParentComponent extends View { this.updateDirtyElements(); } } -loadDocument(new ParentComponent("1", undefined, {})); +ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); +loadDocument(new ParentComponent(undefined, {})); +ViewStackProcessor.StopGetAccessRecording(); ` \ No newline at end of file diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts index a1a2fde..d282fa2 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts @@ -58,7 +58,7 @@ exports.expectResult = set counter(newValue) { this.__counter.set(newValue); } - render() { + initialRender() { this.observeComponentCreation((elmtId, isInitialRender) => { ViewStackProcessor.StartGetAccessRecordingFor(elmtId); Column.create(); @@ -83,5 +83,7 @@ exports.expectResult = this.updateDirtyElements(); } } -loadDocument(new StatePage("1", undefined, {})); +ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); +loadDocument(new StatePage(undefined, {})); +ViewStackProcessor.StopGetAccessRecording(); ` From e38ae5b0abbea0b4c9485f0e7aebf3c88b658620 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Fri, 29 Jul 2022 15:10:42 +0800 Subject: [PATCH 09/33] Bugfix: remove conflict codes Signed-off-by: laibo102 Change-Id: Idc78a71e77d2deb5e2f955830a27d6e490415774 (cherry picked from commit f9f2761a54d7f0a1e44f28268031b7176a765bbb) Signed-off-by: laibo102 --- compiler/src/process_component_build.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index fd57975..7024cdd 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -283,8 +283,6 @@ export function processComponentChild(node: ts.Block | ts.SourceFile, newStateme } else { processForEachComponentNew(item, newStatements, log); } - lastName = name; - lastExpression = item; break; case ComponentType.customBuilderMethod: parent = undefined; From b6bd8b6213c46985c18a34d175412670ebe9cbd2 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Tue, 2 Aug 2022 15:58:11 +0800 Subject: [PATCH 10/33] Update: test script Signed-off-by: laibo102 Change-Id: I096ba2171913f3c44f12a9ee7bd9246692b407da --- compiler/main.js | 27 +++++++++++-------- compiler/package.json | 2 ++ compiler/src/process_component_build.ts | 20 +++++++------- compiler/src/process_component_class.ts | 14 +++++----- compiler/src/process_component_constructor.ts | 9 ++++--- compiler/src/process_component_member.ts | 10 +++---- compiler/src/process_custom_component.ts | 8 +++--- compiler/src/process_ui_syntax.ts | 6 ++--- compiler/test/test.js | 9 ++++--- 9 files changed, 58 insertions(+), 47 deletions(-) diff --git a/compiler/main.js b/compiler/main.js index cd83906..74f2f52 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -400,19 +400,20 @@ function checkAppResourcePath(appResourcePath, config) { } function saveAppResourcePath(appResourcePath, appResourcePathSavePath) { - let isSave = false; - if (fs.existsSync(appResourcePathSavePath)) { - const saveContent = fs.readFileSync(appResourcePathSavePath); - if (appResourcePath !== saveContent) { + if (!projectConfig.xtsMode) { + let isSave = false; + if (fs.existsSync(appResourcePathSavePath)) { + const saveContent = fs.readFileSync(appResourcePathSavePath); + if (appResourcePath !== saveContent) { + isSave = true; + } + } else { isSave = true; } - } else { - isSave = true; + if (isSave) { + fs.writeFileSync(appResourcePathSavePath, appResourcePath); + } } - if (isSave) { - fs.writeFileSync(appResourcePathSavePath, appResourcePath); - } -} function addSDKBuildDependencies(config) { if (projectConfig.localPropertiesPath && @@ -430,6 +431,10 @@ const globalProgram = { watchProgram: null }; +const sdkVersion = { + compatibleSdkVersion: '8' +}; + exports.globalProgram = globalProgram; exports.projectConfig = projectConfig; exports.loadEntryObj = loadEntryObj; @@ -443,4 +448,4 @@ exports.loadModuleInfo = loadModuleInfo; exports.systemModules = systemModules; exports.checkAppResourcePath = checkAppResourcePath; exports.addSDKBuildDependencies = addSDKBuildDependencies; -exports.compatibleSdkVersion = '8'; \ No newline at end of file +exports.sdkVersion = sdkVersion; \ No newline at end of file diff --git a/compiler/package.json b/compiler/package.json index 6bdb1e6..1a04d56 100644 --- a/compiler/package.json +++ b/compiler/package.json @@ -14,6 +14,8 @@ "create": "node ./lib/create.js --env projectName", "compile": "webpack --config webpack.config.js --env buildMode=debug projectName", "test": "npm run build && mocha -r mocha-context/register test/test.js", + "testPU": "npm run build && mocha -r mocha-context/register test/test.js --partialUpdate", + "testAll": "npm run build && mocha -r mocha-context/register test/test.js && mocha -r mocha-context/register test/test.js --partialUpdate", "generateDeclarations": "node ./build_declarations_file.js ../../../interface/sdk-js/api/@internal/component/ets ./declarations ./lib", "generateSyntaxParser": "node build_parser.js ./syntax_parser/dist", "postinstall": "node npm-install.js" diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 7024cdd..ce00358 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -111,7 +111,7 @@ import { componentInfo, createFunction } from './utils'; -import { compatibleSdkVersion, projectConfig } from '../main'; +import { sdkVersion, projectConfig } from '../main'; import { transformLog, contextGlobal } from './process_ui_syntax'; import { props } from './compile_info'; import { CUSTOM_COMPONENT } from '../lib/pre_define'; @@ -120,7 +120,7 @@ export function processComponentBuild(node: ts.MethodDeclaration, log: LogInfo[]): ts.MethodDeclaration { let newNode: ts.MethodDeclaration; let renderNode: ts.Identifier; - if (compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === '8') { renderNode = ts.factory.createIdentifier(COMPONENT_RENDER_FUNCTION); } else { renderNode = ts.factory.createIdentifier(COMPONENT_INITIAl_RENDER_FUNCTION); @@ -143,7 +143,7 @@ export function processComponentBlock(node: ts.Block, isLazy: boolean, log: LogI const newStatements: ts.Statement[] = []; processComponentChild(node, newStatements, log, {isAcceleratePreview: false, line: 0, column: 0, fileName: ''}, isInnerBuilder, parent); - if (isLazy && compatibleSdkVersion === '8') { + if (isLazy && sdkVersion.compatibleSdkVersion === '8') { newStatements.unshift(createRenderingInProgress(true)); } if (isTransition) { @@ -154,7 +154,7 @@ export function processComponentBlock(node: ts.Block, isLazy: boolean, log: LogI createFunction(ts.factory.createIdentifier(COMPONENT_TRANSITION_NAME), ts.factory.createIdentifier(COMPONENT_POP_FUNCTION), null))); } - if (isLazy && compatibleSdkVersion === '8') { + if (isLazy && sdkVersion.compatibleSdkVersion === '8') { newStatements.push(createRenderingInProgress(false)); } return ts.factory.updateBlock(node, newStatements); @@ -278,7 +278,7 @@ export function processComponentChild(node: ts.Block | ts.SourceFile, newStateme break; case ComponentType.forEachComponent: parent = undefined; - if (compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === '8') { processForEachComponent(item, newStatements, log, isInnerBuilder); } else { processForEachComponentNew(item, newStatements, log); @@ -409,7 +409,7 @@ function processInnerComponent(node: ts.ExpressionStatement, innerCompStatements newStatements.push(res.newNode); const nameResult: NameResult = { name: null }; validateEtsComponentNode(node.expression as ts.EtsComponentExpression, nameResult); - if (compatibleSdkVersion === '9' && ItemComponents.includes(nameResult.name)) { + if (sdkVersion.compatibleSdkVersion === '9' && ItemComponents.includes(nameResult.name)) { processItemComponent(node, nameResult, innerCompStatements, log); } else { processNormalComponent(node, nameResult, innerCompStatements, log); @@ -485,7 +485,7 @@ function processInnerCompStatements( newStatements: ts.Statement[], node: ts.Statement ): void { - if (compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === '8') { innerCompStatements.push(...newStatements); } else { innerCompStatements.push(createComponentCreationStatement(node, newStatements)); @@ -1012,7 +1012,7 @@ function processForEachBlock(node: ts.CallExpression, log: LogInfo[], const blockNode: ts.Block = ts.factory.createBlock([statement], true); // @ts-ignore statement.parent = blockNode; - if (compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === '8') { return ts.factory.updateArrowFunction( arrowNode, arrowNode.modifiers, arrowNode.typeParameters, arrowNode.parameters, arrowNode.type, arrowNode.equalsGreaterThanToken, processComponentBlock(blockNode, isLazy, log)); @@ -1020,7 +1020,7 @@ function processForEachBlock(node: ts.CallExpression, log: LogInfo[], return processComponentBlock(blockNode, isLazy, log).statements; } } else { - if (compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === '8') { return ts.factory.updateArrowFunction( arrowNode, arrowNode.modifiers, arrowNode.typeParameters, arrowNode.parameters, arrowNode.type, arrowNode.equalsGreaterThanToken, @@ -1049,7 +1049,7 @@ function processIfStatement(node: ts.IfStatement, newStatements: ts.Statement[], const ifCreate: ts.ExpressionStatement = createIfCreate(); const newIfNode: ts.IfStatement = processInnerIfStatement(node, 0, log, isInnerBuilder); const ifPop: ts.ExpressionStatement = createIfPop(); - if (compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === '8') { newStatements.push(ifCreate, newIfNode, ifPop); } else { newStatements.push(createComponentCreationStatement(node, [ifCreate, newIfNode]), ifPop); diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index 820098e..a746b47 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -108,7 +108,7 @@ import { LogInfo, hasDecorator } from './utils'; -import { compatibleSdkVersion } from '../main'; +import { sdkVersion } from '../main'; export function processComponentClass(node: ts.StructDeclaration, context: ts.TransformationContext, log: LogInfo[], program: ts.Program): ts.ClassDeclaration { @@ -231,7 +231,7 @@ function processPropertyUnchanged( purgeVariableDepStatements: ts.Statement[], rerenderStatements: ts.Statement[] ): void { - if (compatibleSdkVersion === '9') { + if (sdkVersion.compatibleSdkVersion === '9') { if(result.getPropertyUnchanged()) { const propertyUnchanged: ts.Statement = result.getPropertyUnchanged(); if (result.getDecoratorName() === COMPONENT_STATE_DECORATOR) { @@ -261,7 +261,7 @@ function addIntoNewMembers( purgeVariableDepStatements: ts.Statement[], rerenderStatements: ts.Statement[] ): void { - if (compatibleSdkVersion === '9') { + if (sdkVersion.compatibleSdkVersion === '9') { newMembers.unshift( addInitialParamsFunc(updateParamsStatements, parentComponentName), createStateUnchangedFunc(setStateUnchangedStatements), @@ -566,7 +566,7 @@ export function createReference(node: ts.PropertyAssignment, log: LogInfo[]): ts pos: initExpression.getStart() }); } - } else if (compatibleSdkVersion === '9' && isMatchInitExpression(initExpression) && + } else if (sdkVersion.compatibleSdkVersion === '9' && isMatchInitExpression(initExpression) && propParentComponent.includes(propertyName.escapedText.toString())) { initText = initExpression.name.escapedText.toString(); } @@ -654,7 +654,7 @@ function addDeleteParamsFunc(statements: ts.PropertyDeclaration[]): ts.MethodDec statements.forEach((statement: ts.PropertyDeclaration) => { const name: ts.Identifier = statement.name as ts.Identifier; let paramsStatement: ts.ExpressionStatement; - if (compatibleSdkVersion === '9' && !statement.decorators) { + if (sdkVersion.compatibleSdkVersion === '9' && !statement.decorators) { paramsStatement = createParamsStatement(name); } else { paramsStatement = createParamsWithUnderlineStatement(name); @@ -670,11 +670,11 @@ function addDeleteParamsFunc(statements: ts.PropertyDeclaration[]): ts.MethodDec ts.factory.createIdentifier(CREATE_CONSTRUCTOR_DELETE_FUNCTION)), undefined, [ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression( ts.factory.createThis(), ts.factory.createIdentifier( - compatibleSdkVersion === '8' ? + sdkVersion.compatibleSdkVersion === '8' ? ABOUT_TO_BE_DELETE_FUNCTION_ID : ABOUT_TO_BE_DELETE_FUNCTION_ID__)), undefined, [])])); deleteStatements.push(defaultStatement); - if (compatibleSdkVersion === '9') { + if (sdkVersion.compatibleSdkVersion === '9') { const aboutToBeDeletedInternalStatement: ts.ExpressionStatement = createDeletedInternalStatement(); deleteStatements.push(aboutToBeDeletedInternalStatement); } diff --git a/compiler/src/process_component_constructor.ts b/compiler/src/process_component_constructor.ts index 53ffde2..ec46c70 100644 --- a/compiler/src/process_component_constructor.ts +++ b/compiler/src/process_component_constructor.ts @@ -32,7 +32,7 @@ import { localStoragePropCollection } from './validate_ui_syntax'; -import { compatibleSdkVersion } from '../main'; +import { sdkVersion } from '../main'; export function getInitConstructor(members: ts.NodeArray, parentComponentName: ts.Identifier ): ts.ConstructorDeclaration { @@ -86,7 +86,7 @@ function initConstructorParams(node: ts.ConstructorDeclaration, parentComponentN } const localStorageNum: number = localStorageLinkCollection.get(parentComponentName.getText()).size + localStoragePropCollection.get(parentComponentName.getText()).size; - const paramNames: Set = compatibleSdkVersion === "8" ? new Set([ + const paramNames: Set = sdkVersion.compatibleSdkVersion === "8" ? new Set([ COMPONENT_CONSTRUCTOR_ID, COMPONENT_CONSTRUCTOR_PARENT, COMPONENT_CONSTRUCTOR_PARAMS, @@ -171,7 +171,7 @@ export function addConstructor(ctorNode: any, watchMap: Map, } function createCallSuperStatement(localStorageNum: number): ts.Statement{ - if (compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === '8') { return ts.factory.createExpressionStatement(ts.factory.createCallExpression( ts.factory.createSuper(), undefined, localStorageNum ? [ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_ID), @@ -195,7 +195,8 @@ function createUPdWithValStatement(): ts.Statement { ts.factory.createPropertyAccessExpression( ts.factory.createThis(), ts.factory.createIdentifier( - compatibleSdkVersion === '8' ? COMPONENT_CONSTRUCTOR_UPDATE_PARAMS : COMPONENT_CONSTRUCTOR_INITIAL_PARAMS + sdkVersion.compatibleSdkVersion === '8' ? + COMPONENT_CONSTRUCTOR_UPDATE_PARAMS : COMPONENT_CONSTRUCTOR_INITIAL_PARAMS ) ), undefined, diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index 3c457d4..03afeda 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -86,7 +86,7 @@ import { import { transformLog } from './process_ui_syntax'; import { globalProgram, projectConfig } from '../main'; -import { compatibleSdkVersion } from '../main'; +import { sdkVersion } from '../main'; export type ControllerType = { hasController: boolean @@ -256,7 +256,7 @@ export function processMemberVariableDecorators(parentName: ts.Identifier, createVariableInitStatement(item, COMPONENT_NON_DECORATOR, log, program, context, hasPreview, interfaceNode)])); updateResult.setControllerSet(createControllerSet(item, parentName, name, checkController)); - if (compatibleSdkVersion === '9') { + if (sdkVersion.compatibleSdkVersion === '9') { updateResult.setDeleteParams(true); } } else if (!item.type) { @@ -363,7 +363,7 @@ function processStateDecorators(node: ts.PropertyDeclaration, decorator: string, if (setUpdateParamsDecorators.has(decorator)) { updateResult.setUpdateParams(createUpdateParams(name, decorator)); } - if (compatibleSdkVersion === '9' && BASICDECORATORS.has(decorator)) { + if (sdkVersion.compatibleSdkVersion === '9' && BASICDECORATORS.has(decorator)) { const variableWithUnderLink: string = '__' + name.escapedText.toString(); updateResult.setPropertyUnchanged(createPropertyUnchangedStatement(variableWithUnderLink)); updateResult.setDecoratorName(decorator); @@ -523,7 +523,7 @@ function createUpdateParams(name: ts.Identifier, decorator: string): ts.Statemen updateParamsNode = createUpdateParamsWithIf(name); break; case COMPONENT_PROP_DECORATOR: - if (compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === '8') { updateParamsNode = createUpdateParamsWithoutIf(name); } break; @@ -700,7 +700,7 @@ function addCustomComponentId(node: ts.NewExpression, componentName: string, if (!argumentsArray) { argumentsArray = [ts.factory.createObjectLiteralExpression([], true)]; } - if (compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === '8') { ++componentInfo.id; argumentsArray.unshift(isInnerBuilder ? ts.factory.createBinaryExpression( ts.factory.createStringLiteral(path.basename(transformLog.sourceFile.fileName, EXTNAME_ETS) + '_'), diff --git a/compiler/src/process_custom_component.ts b/compiler/src/process_custom_component.ts index 815b9c4..3a73e0e 100644 --- a/compiler/src/process_custom_component.ts +++ b/compiler/src/process_custom_component.ts @@ -70,7 +70,7 @@ import { createFunction } from './utils'; import { bindComponentAttr } from './process_component_build'; -import { compatibleSdkVersion } from '../main'; +import { sdkVersion } from '../main'; const localArray: string[] = [...observedPropertyDecorators, COMPONENT_NON_DECORATOR, COMPONENT_PROP_DECORATOR, COMPONENT_OBJECT_LINK_DECORATOR]; @@ -162,7 +162,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[], isInnerBuilder: boolean = false): void { - if (compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === '8') { const id: string = componentInfo.id.toString(); newStatements.push(createFindChildById(id, name, isInnerBuilder), createCustomComponentIfStatement(id, ts.factory.updateExpressionStatement(node, createViewCreate(newNode)), @@ -401,9 +401,9 @@ function isCorrectInitFormParent(parent: string, child: string): boolean { } break; case COMPONENT_OBJECT_LINK_DECORATOR: - if (compatibleSdkVersion === '8' && parent === COMPONENT_STATE_DECORATOR) { + if (sdkVersion.compatibleSdkVersion === '8' && parent === COMPONENT_STATE_DECORATOR) { return true; - } else if (compatibleSdkVersion === '9' && STATE_OBJECTLINK_DECORATORS.includes(parent)) { + } else if (sdkVersion.compatibleSdkVersion === '9' && STATE_OBJECTLINK_DECORATORS.includes(parent)) { return true; } break; diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index 2012447..f5dd044 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -89,7 +89,7 @@ import { import { resources, projectConfig, - compatibleSdkVersion + sdkVersion } from '../main'; import { createCustomComponentNewExpression, createViewCreate } from './process_component_member'; @@ -586,7 +586,7 @@ export function isExtendFunction(node: ts.FunctionDeclaration): string { function createEntryNode(node: ts.SourceFile, context: ts.TransformationContext): ts.SourceFile { if (componentCollection.previewComponent.size === 0 || !projectConfig.isPreview) { if (componentCollection.entryComponent) { - if (compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === '8') { const entryNode: ts.ExpressionStatement = createEntryFunction(componentCollection.entryComponent, context) as ts.ExpressionStatement; return context.factory.updateSourceFile(node, [...node.statements, entryNode]); @@ -630,7 +630,7 @@ function createEntryFunction(name: string, context: ts.TransformationContext) if (localStorageName) { newArray.push(context.factory.createIdentifier(localStorageName)); } - if (compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === '8') { const newExpressionStatement: ts.ExpressionStatement = context.factory.createExpressionStatement(context.factory.createCallExpression( context.factory.createIdentifier(PAGE_ENTRY_FUNCTION_NAME), undefined, diff --git a/compiler/test/test.js b/compiler/test/test.js index 4bb9b6f..b226cae 100644 --- a/compiler/test/test.js +++ b/compiler/test/test.js @@ -36,7 +36,7 @@ const { SYSTEM_PLUGIN } = require('../lib/pre_define'); const { - compatibleSdkVersion + sdkVersion } = require('../main'); function expectActual(name, filePath) { @@ -62,8 +62,11 @@ function expectActual(name, filePath) { } mocha.describe('compiler', () => { - const utPath = compatibleSdkVersion === '8' ? - path.resolve(__dirname, './ut') : path.resolve(__dirname, './utForPartialUpdate'); + let utPath = path.resolve(__dirname, './ut'); + if (process.argv.includes('--partialUpdate')) { + sdkVersion.compatibleSdkVersion = '9'; + utPath = path.resolve(__dirname, './utForPartialUpdate'); + } const utFiles = []; readFile(utPath, utFiles); utFiles.forEach((item) => { From 5c805a66e96c731689f213985d9ed04bf8576cf8 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Tue, 2 Aug 2022 16:45:03 +0800 Subject: [PATCH 11/33] Add: read compatibleSdkVersion from aceBuildJson Signed-off-by: laibo102 Change-Id: I883164f517a1a90cd9171c8b3620b53be7b1d81d --- compiler/main.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/main.js b/compiler/main.js index 74f2f52..2d94ee6 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -380,6 +380,9 @@ function loadModuleInfo(projectConfig, envArgs) { projectConfig.nodeModulesPath = buildJsonInfo.nodeModulesPath; } projectConfig.pandaMode = buildJsonInfo.pandaMode; + if (buildJsonInfo.compatibleSdkVersion) { + sdkVersion.compatibleSdkVersion = buildJsonInfo.compatibleSdkVersion.toString(); + } } } From 7f63ad8ad66ea6b01f82ee1ceea6782150403117 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Wed, 3 Aug 2022 16:58:49 +0800 Subject: [PATCH 12/33] Update: compatibleSdkVersion to be number type Signed-off-by: laibo102 Change-Id: I7533730fffd5fc498e52e64373200b1c2f94d412 --- compiler/main.js | 4 ++-- compiler/src/process_component_build.ts | 18 +++++++++--------- compiler/src/process_component_class.ts | 12 ++++++------ compiler/src/process_component_constructor.ts | 6 +++--- compiler/src/process_component_member.ts | 8 ++++---- compiler/src/process_custom_component.ts | 6 +++--- compiler/src/process_ui_syntax.ts | 4 ++-- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/compiler/main.js b/compiler/main.js index 2d94ee6..0b2461b 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -381,7 +381,7 @@ function loadModuleInfo(projectConfig, envArgs) { } projectConfig.pandaMode = buildJsonInfo.pandaMode; if (buildJsonInfo.compatibleSdkVersion) { - sdkVersion.compatibleSdkVersion = buildJsonInfo.compatibleSdkVersion.toString(); + sdkVersion.compatibleSdkVersion = buildJsonInfo.compatibleSdkVersion; } } } @@ -435,7 +435,7 @@ const globalProgram = { }; const sdkVersion = { - compatibleSdkVersion: '8' + compatibleSdkVersion: 8 }; exports.globalProgram = globalProgram; diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index ce00358..91889e1 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -120,7 +120,7 @@ export function processComponentBuild(node: ts.MethodDeclaration, log: LogInfo[]): ts.MethodDeclaration { let newNode: ts.MethodDeclaration; let renderNode: ts.Identifier; - if (sdkVersion.compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === 8) { renderNode = ts.factory.createIdentifier(COMPONENT_RENDER_FUNCTION); } else { renderNode = ts.factory.createIdentifier(COMPONENT_INITIAl_RENDER_FUNCTION); @@ -143,7 +143,7 @@ export function processComponentBlock(node: ts.Block, isLazy: boolean, log: LogI const newStatements: ts.Statement[] = []; processComponentChild(node, newStatements, log, {isAcceleratePreview: false, line: 0, column: 0, fileName: ''}, isInnerBuilder, parent); - if (isLazy && sdkVersion.compatibleSdkVersion === '8') { + if (isLazy && sdkVersion.compatibleSdkVersion === 8) { newStatements.unshift(createRenderingInProgress(true)); } if (isTransition) { @@ -154,7 +154,7 @@ export function processComponentBlock(node: ts.Block, isLazy: boolean, log: LogI createFunction(ts.factory.createIdentifier(COMPONENT_TRANSITION_NAME), ts.factory.createIdentifier(COMPONENT_POP_FUNCTION), null))); } - if (isLazy && sdkVersion.compatibleSdkVersion === '8') { + if (isLazy && sdkVersion.compatibleSdkVersion === 8) { newStatements.push(createRenderingInProgress(false)); } return ts.factory.updateBlock(node, newStatements); @@ -278,7 +278,7 @@ export function processComponentChild(node: ts.Block | ts.SourceFile, newStateme break; case ComponentType.forEachComponent: parent = undefined; - if (sdkVersion.compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === 8) { processForEachComponent(item, newStatements, log, isInnerBuilder); } else { processForEachComponentNew(item, newStatements, log); @@ -409,7 +409,7 @@ function processInnerComponent(node: ts.ExpressionStatement, innerCompStatements newStatements.push(res.newNode); const nameResult: NameResult = { name: null }; validateEtsComponentNode(node.expression as ts.EtsComponentExpression, nameResult); - if (sdkVersion.compatibleSdkVersion === '9' && ItemComponents.includes(nameResult.name)) { + if (sdkVersion.compatibleSdkVersion === 9 && ItemComponents.includes(nameResult.name)) { processItemComponent(node, nameResult, innerCompStatements, log); } else { processNormalComponent(node, nameResult, innerCompStatements, log); @@ -485,7 +485,7 @@ function processInnerCompStatements( newStatements: ts.Statement[], node: ts.Statement ): void { - if (sdkVersion.compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === 8) { innerCompStatements.push(...newStatements); } else { innerCompStatements.push(createComponentCreationStatement(node, newStatements)); @@ -1012,7 +1012,7 @@ function processForEachBlock(node: ts.CallExpression, log: LogInfo[], const blockNode: ts.Block = ts.factory.createBlock([statement], true); // @ts-ignore statement.parent = blockNode; - if (sdkVersion.compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === 8) { return ts.factory.updateArrowFunction( arrowNode, arrowNode.modifiers, arrowNode.typeParameters, arrowNode.parameters, arrowNode.type, arrowNode.equalsGreaterThanToken, processComponentBlock(blockNode, isLazy, log)); @@ -1020,7 +1020,7 @@ function processForEachBlock(node: ts.CallExpression, log: LogInfo[], return processComponentBlock(blockNode, isLazy, log).statements; } } else { - if (sdkVersion.compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === 8) { return ts.factory.updateArrowFunction( arrowNode, arrowNode.modifiers, arrowNode.typeParameters, arrowNode.parameters, arrowNode.type, arrowNode.equalsGreaterThanToken, @@ -1049,7 +1049,7 @@ function processIfStatement(node: ts.IfStatement, newStatements: ts.Statement[], const ifCreate: ts.ExpressionStatement = createIfCreate(); const newIfNode: ts.IfStatement = processInnerIfStatement(node, 0, log, isInnerBuilder); const ifPop: ts.ExpressionStatement = createIfPop(); - if (sdkVersion.compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === 8) { newStatements.push(ifCreate, newIfNode, ifPop); } else { newStatements.push(createComponentCreationStatement(node, [ifCreate, newIfNode]), ifPop); diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index a746b47..b772e64 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -231,7 +231,7 @@ function processPropertyUnchanged( purgeVariableDepStatements: ts.Statement[], rerenderStatements: ts.Statement[] ): void { - if (sdkVersion.compatibleSdkVersion === '9') { + if (sdkVersion.compatibleSdkVersion === 9) { if(result.getPropertyUnchanged()) { const propertyUnchanged: ts.Statement = result.getPropertyUnchanged(); if (result.getDecoratorName() === COMPONENT_STATE_DECORATOR) { @@ -261,7 +261,7 @@ function addIntoNewMembers( purgeVariableDepStatements: ts.Statement[], rerenderStatements: ts.Statement[] ): void { - if (sdkVersion.compatibleSdkVersion === '9') { + if (sdkVersion.compatibleSdkVersion === 9) { newMembers.unshift( addInitialParamsFunc(updateParamsStatements, parentComponentName), createStateUnchangedFunc(setStateUnchangedStatements), @@ -566,7 +566,7 @@ export function createReference(node: ts.PropertyAssignment, log: LogInfo[]): ts pos: initExpression.getStart() }); } - } else if (sdkVersion.compatibleSdkVersion === '9' && isMatchInitExpression(initExpression) && + } else if (sdkVersion.compatibleSdkVersion === 9 && isMatchInitExpression(initExpression) && propParentComponent.includes(propertyName.escapedText.toString())) { initText = initExpression.name.escapedText.toString(); } @@ -654,7 +654,7 @@ function addDeleteParamsFunc(statements: ts.PropertyDeclaration[]): ts.MethodDec statements.forEach((statement: ts.PropertyDeclaration) => { const name: ts.Identifier = statement.name as ts.Identifier; let paramsStatement: ts.ExpressionStatement; - if (sdkVersion.compatibleSdkVersion === '9' && !statement.decorators) { + if (sdkVersion.compatibleSdkVersion === 9 && !statement.decorators) { paramsStatement = createParamsStatement(name); } else { paramsStatement = createParamsWithUnderlineStatement(name); @@ -670,11 +670,11 @@ function addDeleteParamsFunc(statements: ts.PropertyDeclaration[]): ts.MethodDec ts.factory.createIdentifier(CREATE_CONSTRUCTOR_DELETE_FUNCTION)), undefined, [ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression( ts.factory.createThis(), ts.factory.createIdentifier( - sdkVersion.compatibleSdkVersion === '8' ? + sdkVersion.compatibleSdkVersion === 8 ? ABOUT_TO_BE_DELETE_FUNCTION_ID : ABOUT_TO_BE_DELETE_FUNCTION_ID__)), undefined, [])])); deleteStatements.push(defaultStatement); - if (sdkVersion.compatibleSdkVersion === '9') { + if (sdkVersion.compatibleSdkVersion === 9) { const aboutToBeDeletedInternalStatement: ts.ExpressionStatement = createDeletedInternalStatement(); deleteStatements.push(aboutToBeDeletedInternalStatement); } diff --git a/compiler/src/process_component_constructor.ts b/compiler/src/process_component_constructor.ts index ec46c70..ffa51a5 100644 --- a/compiler/src/process_component_constructor.ts +++ b/compiler/src/process_component_constructor.ts @@ -86,7 +86,7 @@ function initConstructorParams(node: ts.ConstructorDeclaration, parentComponentN } const localStorageNum: number = localStorageLinkCollection.get(parentComponentName.getText()).size + localStoragePropCollection.get(parentComponentName.getText()).size; - const paramNames: Set = sdkVersion.compatibleSdkVersion === "8" ? new Set([ + const paramNames: Set = sdkVersion.compatibleSdkVersion === 8 ? new Set([ COMPONENT_CONSTRUCTOR_ID, COMPONENT_CONSTRUCTOR_PARENT, COMPONENT_CONSTRUCTOR_PARAMS, @@ -171,7 +171,7 @@ export function addConstructor(ctorNode: any, watchMap: Map, } function createCallSuperStatement(localStorageNum: number): ts.Statement{ - if (sdkVersion.compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === 8) { return ts.factory.createExpressionStatement(ts.factory.createCallExpression( ts.factory.createSuper(), undefined, localStorageNum ? [ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_ID), @@ -195,7 +195,7 @@ function createUPdWithValStatement(): ts.Statement { ts.factory.createPropertyAccessExpression( ts.factory.createThis(), ts.factory.createIdentifier( - sdkVersion.compatibleSdkVersion === '8' ? + sdkVersion.compatibleSdkVersion === 8 ? COMPONENT_CONSTRUCTOR_UPDATE_PARAMS : COMPONENT_CONSTRUCTOR_INITIAL_PARAMS ) ), diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index 03afeda..2c0cfe8 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -256,7 +256,7 @@ export function processMemberVariableDecorators(parentName: ts.Identifier, createVariableInitStatement(item, COMPONENT_NON_DECORATOR, log, program, context, hasPreview, interfaceNode)])); updateResult.setControllerSet(createControllerSet(item, parentName, name, checkController)); - if (sdkVersion.compatibleSdkVersion === '9') { + if (sdkVersion.compatibleSdkVersion === 9) { updateResult.setDeleteParams(true); } } else if (!item.type) { @@ -363,7 +363,7 @@ function processStateDecorators(node: ts.PropertyDeclaration, decorator: string, if (setUpdateParamsDecorators.has(decorator)) { updateResult.setUpdateParams(createUpdateParams(name, decorator)); } - if (sdkVersion.compatibleSdkVersion === '9' && BASICDECORATORS.has(decorator)) { + if (sdkVersion.compatibleSdkVersion === 9 && BASICDECORATORS.has(decorator)) { const variableWithUnderLink: string = '__' + name.escapedText.toString(); updateResult.setPropertyUnchanged(createPropertyUnchangedStatement(variableWithUnderLink)); updateResult.setDecoratorName(decorator); @@ -523,7 +523,7 @@ function createUpdateParams(name: ts.Identifier, decorator: string): ts.Statemen updateParamsNode = createUpdateParamsWithIf(name); break; case COMPONENT_PROP_DECORATOR: - if (sdkVersion.compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === 8) { updateParamsNode = createUpdateParamsWithoutIf(name); } break; @@ -700,7 +700,7 @@ function addCustomComponentId(node: ts.NewExpression, componentName: string, if (!argumentsArray) { argumentsArray = [ts.factory.createObjectLiteralExpression([], true)]; } - if (sdkVersion.compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === 8) { ++componentInfo.id; argumentsArray.unshift(isInnerBuilder ? ts.factory.createBinaryExpression( ts.factory.createStringLiteral(path.basename(transformLog.sourceFile.fileName, EXTNAME_ETS) + '_'), diff --git a/compiler/src/process_custom_component.ts b/compiler/src/process_custom_component.ts index 3a73e0e..7be29b6 100644 --- a/compiler/src/process_custom_component.ts +++ b/compiler/src/process_custom_component.ts @@ -162,7 +162,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[], isInnerBuilder: boolean = false): void { - if (sdkVersion.compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === 8) { const id: string = componentInfo.id.toString(); newStatements.push(createFindChildById(id, name, isInnerBuilder), createCustomComponentIfStatement(id, ts.factory.updateExpressionStatement(node, createViewCreate(newNode)), @@ -401,9 +401,9 @@ function isCorrectInitFormParent(parent: string, child: string): boolean { } break; case COMPONENT_OBJECT_LINK_DECORATOR: - if (sdkVersion.compatibleSdkVersion === '8' && parent === COMPONENT_STATE_DECORATOR) { + if (sdkVersion.compatibleSdkVersion === 8 && parent === COMPONENT_STATE_DECORATOR) { return true; - } else if (sdkVersion.compatibleSdkVersion === '9' && STATE_OBJECTLINK_DECORATORS.includes(parent)) { + } else if (sdkVersion.compatibleSdkVersion === 9 && STATE_OBJECTLINK_DECORATORS.includes(parent)) { return true; } break; diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index f5dd044..d0eb38e 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -586,7 +586,7 @@ export function isExtendFunction(node: ts.FunctionDeclaration): string { function createEntryNode(node: ts.SourceFile, context: ts.TransformationContext): ts.SourceFile { if (componentCollection.previewComponent.size === 0 || !projectConfig.isPreview) { if (componentCollection.entryComponent) { - if (sdkVersion.compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === 8) { const entryNode: ts.ExpressionStatement = createEntryFunction(componentCollection.entryComponent, context) as ts.ExpressionStatement; return context.factory.updateSourceFile(node, [...node.statements, entryNode]); @@ -630,7 +630,7 @@ function createEntryFunction(name: string, context: ts.TransformationContext) if (localStorageName) { newArray.push(context.factory.createIdentifier(localStorageName)); } - if (sdkVersion.compatibleSdkVersion === '8') { + if (sdkVersion.compatibleSdkVersion === 8) { const newExpressionStatement: ts.ExpressionStatement = context.factory.createExpressionStatement(context.factory.createCallExpression( context.factory.createIdentifier(PAGE_ENTRY_FUNCTION_NAME), undefined, From 72743d8c6158a024cccbdc6f499c3c85318db1b2 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Wed, 3 Aug 2022 17:01:25 +0800 Subject: [PATCH 13/33] Update: test script Signed-off-by: laibo102 Change-Id: I1a59fb83848bd67b7277bdef4a9e3cf7753616c7 --- compiler/package.json | 4 +--- compiler/test/test.js | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/compiler/package.json b/compiler/package.json index 1a04d56..8f99725 100644 --- a/compiler/package.json +++ b/compiler/package.json @@ -13,9 +13,7 @@ "build": "npm run generateSyntaxParser && npm run generateDeclarations && ./node_modules/.bin/babel ./src --out-dir lib --extensions .ts && node uglify-source.js lib", "create": "node ./lib/create.js --env projectName", "compile": "webpack --config webpack.config.js --env buildMode=debug projectName", - "test": "npm run build && mocha -r mocha-context/register test/test.js", - "testPU": "npm run build && mocha -r mocha-context/register test/test.js --partialUpdate", - "testAll": "npm run build && mocha -r mocha-context/register test/test.js && mocha -r mocha-context/register test/test.js --partialUpdate", + "test": "npm run build && mocha -r mocha-context/register test/test.js && mocha -r mocha-context/register test/test.js --partialUpdate", "generateDeclarations": "node ./build_declarations_file.js ../../../interface/sdk-js/api/@internal/component/ets ./declarations ./lib", "generateSyntaxParser": "node build_parser.js ./syntax_parser/dist", "postinstall": "node npm-install.js" diff --git a/compiler/test/test.js b/compiler/test/test.js index b226cae..b010fa4 100644 --- a/compiler/test/test.js +++ b/compiler/test/test.js @@ -64,7 +64,7 @@ function expectActual(name, filePath) { mocha.describe('compiler', () => { let utPath = path.resolve(__dirname, './ut'); if (process.argv.includes('--partialUpdate')) { - sdkVersion.compatibleSdkVersion = '9'; + sdkVersion.compatibleSdkVersion = 9; utPath = path.resolve(__dirname, './utForPartialUpdate'); } const utFiles = []; From fa62aca6f7e0e98e43ed5776e29ebbacc74f8fdd Mon Sep 17 00:00:00 2001 From: laibo102 Date: Tue, 9 Aug 2022 20:22:17 +0800 Subject: [PATCH 14/33] Update: The default compatibleSdkVersion Signed-off-by: laibo102 Change-Id: I0b2ce64e74e231a35afe162d2af37d4c1c99d935 --- compiler/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/main.js b/compiler/main.js index 0b2461b..daaddd1 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -435,7 +435,7 @@ const globalProgram = { }; const sdkVersion = { - compatibleSdkVersion: 8 + compatibleSdkVersion: 9 }; exports.globalProgram = globalProgram; From f4f4a8f920ec74b9f87c1679a89f4e2876c90db5 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Wed, 10 Aug 2022 15:12:11 +0800 Subject: [PATCH 15/33] Bugfix: fixed conflict Signed-off-by: laibo102 Change-Id: I6f33ee77840a1b02743cccb283e24e2bfd93a647 --- compiler/src/process_component_class.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index b772e64..332c475 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -186,9 +186,9 @@ function processMembers(members: ts.NodeArray, parentComponentN if (result.getControllerSet()) { newMembers.push(result.getControllerSet()); } + processPropertyUnchanged(result, setStateUnchangedStatements, setOneWayUnchangedStatements, + setTwoWayUnchangedStatements, purgeVariableDepStatements, rerenderStatements); } - processPropertyUnchanged(result, setStateUnchangedStatements, setOneWayUnchangedStatements, - setTwoWayUnchangedStatements, purgeVariableDepStatements, rerenderStatements); } if (ts.isMethodDeclaration(item) && item.name) { updateItem = From 577a45e7104866b9b6719004b5b6d21376b995b0 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Thu, 11 Aug 2022 19:40:15 +0800 Subject: [PATCH 16/33] Update: GridItem transform and its UT Signed-off-by: laibo102 Change-Id: I9c036706b2465af4383854a5286a0d19251dbc6e --- compiler/src/pre_define.ts | 3 + compiler/src/process_component_build.ts | 56 +++++++++++++------ .../render_component/item/GridItem.ts | 19 +++++-- .../lazyforeach/lazyforeach.ts | 2 +- 4 files changed, 58 insertions(+), 22 deletions(-) diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 556e37a..ae2d3c6 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -313,3 +313,6 @@ export const FOREACHUPDATEFUNCTION: string = 'forEachUpdateFunction'; export const ALLOCATENEWELMETIDFORNEXTCOMPONENT: string = 'AllocateNewElmetIdForNextComponent'; export const STATE_OBJECTLINK_DECORATORS: string[] = [COMPONENT_STATE_DECORATOR, COMPONENT_OBJECT_LINK_DECORATOR]; export const COMPONENT_INITIAl_RENDER_FUNCTION: string = 'initialRender'; +export const GRID_COMPONENT: string = 'Grid'; +export const GRIDITEM_COMPONENT: string = 'GridItem'; +export const WILLUSEPROXY: string = 'willUseProxy'; diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 91889e1..2d7ded8 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -80,7 +80,10 @@ import { FOREACHITEMIDFUNC, __LAZYFOREACHITEMIDFUNC, FOREACHUPDATEFUNCTION, - COMPONENT_INITIAl_RENDER_FUNCTION + COMPONENT_INITIAl_RENDER_FUNCTION, + GRIDITEM_COMPONENT, + GRID_COMPONENT, + WILLUSEPROXY } from './pre_define'; import { INNER_COMPONENT_NAMES, @@ -582,23 +585,9 @@ function createItemBlock( itemRenderInnerStatements: ts.Statement[], deepItemRenderInnerStatements: ts.Statement[] ): ts.Block { - const etsComponent: ts.EtsComponentExpression = getEtsComponentExpression(node); - let isLazyCreate: ts.BooleanLiteral = ts.factory.createTrue(); - if (etsComponent && etsComponent.arguments[0]) { - if (etsComponent.arguments[0] as ts.StringLiteral.text === 'false') { - isLazyCreate = ts.factory.createFalse(); - } - } return ts.factory.createBlock( [ - ts.factory.createVariableStatement( - undefined, - ts.factory.createVariableDeclarationList( - [ts.factory.createVariableDeclaration(ts.factory.createIdentifier(ISLAZYCREATE), - undefined, undefined, isLazyCreate)], - ts.NodeFlags.Const - ) - ), + createIsLazyCreate(node), createItemCreation(node, itemRenderInnerStatements), createObservedShallowRender(node, itemRenderInnerStatements), createObservedDeepRender(node, deepItemRenderInnerStatements), @@ -617,6 +606,39 @@ function createItemBlock( ); } +function createIsLazyCreate(node: ts.ExpressionStatement): ts.VariableStatement { + const etsComponent: ts.EtsComponentExpression = getEtsComponentExpression(node); + if (etsComponent) { + if ((etsComponent.expression as ts.Identifier).escapedText.toString() === GRIDITEM_COMPONENT) { + if (etsComponent.arguments[0] && (etsComponent.arguments[0] as ts.StringLiteral).text === 'false') { + return ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList( + [ts.factory.createVariableDeclaration(ts.factory.createIdentifier(ISLAZYCREATE), + undefined, undefined, ts.factory.createFalse())], ts.NodeFlags.Const)); + } else { + return ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList( + [ts.factory.createVariableDeclaration(ts.factory.createIdentifier(ISLAZYCREATE), undefined, undefined, + ts.factory.createBinaryExpression( + ts.factory.createTrue(), ts.factory.createToken(ts.SyntaxKind.AmpersandAmpersandToken), + ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression( + ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression( + ts.factory.createIdentifier(GRID_COMPONENT), ts.factory.createIdentifier(WILLUSEPROXY) + ), undefined, []), ts.factory.createToken(ts.SyntaxKind.EqualsEqualsEqualsToken), + ts.factory.createTrue()))))], ts.NodeFlags.Const)); + } + } else { + if (etsComponent.arguments[0] && (etsComponent.arguments[0] as ts.StringLiteral).text === 'false') { + return ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList( + [ts.factory.createVariableDeclaration(ts.factory.createIdentifier(ISLAZYCREATE), + undefined, undefined, ts.factory.createFalse())], ts.NodeFlags.Const)); + } else { + return ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList( + [ts.factory.createVariableDeclaration(ts.factory.createIdentifier(ISLAZYCREATE), + undefined, undefined, ts.factory.createTrue())], ts.NodeFlags.Const)); + } + } + } +} + function createItemCreation( node: ts.ExpressionStatement, itemRenderInnerStatements: ts.Statement[] @@ -823,7 +845,7 @@ function processForEachComponent(node: ts.ExpressionStatement, newStatements: ts ts.factory.createIdentifier(FOREACH_GET_RAW_OBJECT)), undefined, [argumentsArray[0]]); } argumentsArray.splice(0, 1, arrayObserveredObject); - const newArrowNode: ts.ArrowFunction = + const newArrowNode: ts.ArrowFunction = processForEachBlock(node.expression, log, isInnerBuilder) as ts.ArrowFunction; if (newArrowNode) { argumentsArray.splice(1, 1, newArrowNode); diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts index 8f7aedc..4ad66e0 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts @@ -18,9 +18,11 @@ exports.source = ` @Component struct ParentView { build() { - GridItem('true') { - Text('xx').width(100) - }.width(200).height(100) + Grid() { + GridItem('true') { + Text('xx').width(100) + }.width(200).height(100) + } } } ` @@ -45,8 +47,16 @@ exports.expectResult = this.aboutToBeDeletedInternal(); } initialRender() { + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Grid.create(); + if (!isInitialRender) { + Grid.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); { - const isLazyCreate = true; + const isLazyCreate = true && (Grid.willUseProxy() === true); const itemCreation = (elmtId, isInitialRender) => { ViewStackProcessor.StartGetAccessRecordingFor(elmtId); GridItem.create(deepRenderFunction, isLazyCreate); @@ -104,6 +114,7 @@ exports.expectResult = observedDeepRender(); } } + Grid.pop(); } rerender() { this.updateDirtyElements(); diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts index 40b64e6..6ad1094 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts @@ -208,7 +208,7 @@ class Test extends View { const __lazyForEachItemGenFunction = _item => { const row = _item; { - const isLazyCreate = true; + const isLazyCreate = true && (Grid.willUseProxy() === true); const itemCreation = (elmtId, isInitialRender) => { ViewStackProcessor.StartGetAccessRecordingFor(elmtId); GridItem.create(deepRenderFunction, isLazyCreate); From 197ce1c3c1d93d383e53f269d6835d8cab04085e Mon Sep 17 00:00:00 2001 From: laibo102 Date: Mon, 15 Aug 2022 16:12:56 +0800 Subject: [PATCH 17/33] Update: TabContent transform Signed-off-by: laibo102 Change-Id: Ib4dff7668fe1ef6d6b07e1bfa98aab42f401c4d3 --- compiler/src/pre_define.ts | 1 + compiler/src/process_component_build.ts | 35 +++- .../render_component/tab/tab.ts | 185 ++++++++++++++++++ 3 files changed, 220 insertions(+), 1 deletion(-) create mode 100644 compiler/test/utForPartialUpdate/inner_component_transform/render_component/tab/tab.ts diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index ae2d3c6..005cd4e 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -316,3 +316,4 @@ export const COMPONENT_INITIAl_RENDER_FUNCTION: string = 'initialRender'; export const GRID_COMPONENT: string = 'Grid'; export const GRIDITEM_COMPONENT: string = 'GridItem'; export const WILLUSEPROXY: string = 'willUseProxy'; +export const TABCONTENT_COMPONENT: string = 'TabContent'; diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 2d7ded8..f0896b4 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -83,7 +83,8 @@ import { COMPONENT_INITIAl_RENDER_FUNCTION, GRIDITEM_COMPONENT, GRID_COMPONENT, - WILLUSEPROXY + WILLUSEPROXY, + TABCONTENT_COMPONENT } from './pre_define'; import { INNER_COMPONENT_NAMES, @@ -414,6 +415,8 @@ function processInnerComponent(node: ts.ExpressionStatement, innerCompStatements validateEtsComponentNode(node.expression as ts.EtsComponentExpression, nameResult); if (sdkVersion.compatibleSdkVersion === 9 && ItemComponents.includes(nameResult.name)) { processItemComponent(node, nameResult, innerCompStatements, log); + } else if (sdkVersion.compatibleSdkVersion === 9 && TABCONTENT_COMPONENT.includes(nameResult.name)) { + processTabContent(node, innerCompStatements, log); } else { processNormalComponent(node, nameResult, innerCompStatements, log); } @@ -816,6 +819,36 @@ function createObservedDeepRender( ); } +function processTabContent(node: ts.ExpressionStatement, innerCompStatements: ts.Statement[], log: LogInfo[]): void { + const TabContentComp: ts.EtsComponentExpression = getEtsComponentExpression(node); + const TabContentBody: ts.Block = TabContentComp.body; + let tabContentCreation: ts.Statement; + const tabContentPop: ts.Statement = ts.factory.createExpressionStatement(ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(TABCONTENT_COMPONENT), + ts.factory.createIdentifier(COMPONENT_POP_FUNCTION)), undefined, [])); + const tabAttrs: ts.Statement[] = []; + if (TabContentBody) { + const TabContentBodyChild = TabContentBody.statements[0] as ts.ExpressionStatement; + const newTabContentChildren: ts.Statement[] = []; + processInnerComponent(TabContentBodyChild, newTabContentChildren, log); + tabContentCreation = ts.factory.createExpressionStatement( + ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression( + ts.factory.createIdentifier(TABCONTENT_COMPONENT), ts.factory.createIdentifier(COMPONENT_CREATE_FUNCTION)), + undefined, [ts.factory.createArrowFunction(undefined, undefined, [], undefined, + ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), + ts.factory.createBlock([...newTabContentChildren], true))])); + bindComponentAttr(node, ts.factory.createIdentifier(TABCONTENT_COMPONENT), tabAttrs, log); + processInnerCompStatements(innerCompStatements, [tabContentCreation, ...tabAttrs], node); + } else { + tabContentCreation = ts.factory.createExpressionStatement(ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(TABCONTENT_COMPONENT), + ts.factory.createIdentifier(COMPONENT_CREATE_FUNCTION)), undefined, [])); + bindComponentAttr(node, ts.factory.createIdentifier(TABCONTENT_COMPONENT), tabAttrs, log); + processInnerCompStatements(innerCompStatements, [tabContentCreation, ...tabAttrs], node); + } + innerCompStatements.push(tabContentPop); +} + function getRealNodePos(node: ts.Node): number { // @ts-ignore if (node.pos === -1 && node.expression) { diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/tab/tab.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/tab/tab.ts new file mode 100644 index 0000000..1ba43d6 --- /dev/null +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/tab/tab.ts @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2022 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 TabSimple { + private controller: TabsController = new TabsController(); + build() { + Column() { + Tabs({ barPosition: BarPosition.Start, index: 1, controller: this.controller}) { + TabContent() { + Flex() { + Column() { + Text('text1') + .height(100) + .width(200) + Text('xxx') + .height(100) + .width(200) + } + .height(100) + .width(200) + } + .height(100) + .width(200) + } + .tabBar("TabBar") + .height(100) + .width(200) + TabContent() { + Text('text2') + } + .tabBar("TabBar 2") + .height(100) + .width(200) + } + } + } +} +` +exports.expectResult = +`class TabSimple extends View { + constructor(parent, params) { + super(parent); + this.controller = new TabsController(); + this.setInitiallyProvidedValue(params); + } + setInitiallyProvidedValue(params) { + if (params.controller !== undefined) { + this.controller = params.controller; + } + } + setStateSourcePropertiesUnchanged() { + } + setOneWaySyncPropertiesUnchanged() { + } + setTwoWaySyncPropertiesUnchanged() { + } + purgeVariableDependenciesOnElmtId(rmElmtId) { + } + aboutToBeDeleted() { + this.controller = undefined; + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal(); + } + initialRender() { + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Column.create(); + if (!isInitialRender) { + Column.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Tabs.create({ barPosition: BarPosition.Start, index: 1, controller: this.controller }); + if (!isInitialRender) { + Tabs.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + TabContent.create(() => { + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Flex.create(); + Flex.height(100); + Flex.width(200); + if (!isInitialRender) { + Flex.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Column.create(); + Column.height(100); + Column.width(200); + if (!isInitialRender) { + Column.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create('text1'); + Text.height(100); + Text.width(200); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + Text.pop(); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create('xxx'); + Text.height(100); + Text.width(200); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + Text.pop(); + Column.pop(); + Flex.pop(); + }); + TabContent.tabBar("TabBar"); + TabContent.height(100); + TabContent.width(200); + if (!isInitialRender) { + TabContent.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + TabContent.pop(); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + TabContent.create(() => { + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create('text2'); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + Text.pop(); + }); + TabContent.tabBar("TabBar 2"); + TabContent.height(100); + TabContent.width(200); + if (!isInitialRender) { + TabContent.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + TabContent.pop(); + Tabs.pop(); + Column.pop(); + } + rerender() { + this.updateDirtyElements(); + } +} +ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); +loadDocument(new TabSimple(undefined, {})); +ViewStackProcessor.StopGetAccessRecording(); +` \ No newline at end of file From 12d0747c552b4edc8b3a948321549542ca855e7a Mon Sep 17 00:00:00 2001 From: laibo102 Date: Mon, 15 Aug 2022 16:57:45 +0800 Subject: [PATCH 18/33] Update: delete SetXYZUnchange methods and update UT Signed-off-by: laibo102 Change-Id: I5d8105266d84182fc8c565da05b1a6a7ad0b286a --- compiler/src/pre_define.ts | 3 -- compiler/src/process_component_class.ts | 52 ++----------------- compiler/src/process_component_member.ts | 26 ---------- .../custom_component/custom_component.ts | 12 ----- .../render_component/foreach/foreach.ts | 7 --- .../render_component/if/if.ts | 9 ---- .../render_component/item/GridItem.ts | 6 --- .../render_component/item/ListItem.ts | 6 --- .../lazyforeach/lazyforeach.ts | 6 --- .../render_component/tab/tab.ts | 6 --- .../@link/@link.ts | 14 ----- .../@objectLink/@objectLink.ts | 14 ----- .../@prop/@prop.ts | 14 ----- .../@state/@state.ts | 7 --- 14 files changed, 3 insertions(+), 179 deletions(-) diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 005cd4e..81eb06d 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -278,9 +278,6 @@ export const _GENERATE_ID = '__generate__Id'; export const COMPONENT_CONSTRUCTOR_INITIAL_PARAMS: string = 'setInitiallyProvidedValue'; export const COMPONENT_RERENDER_FUNCTION: string = 'rerender'; -export const SETONEWAYSYNCPROPERTIESUNCHANGED: string = 'setOneWaySyncPropertiesUnchanged'; -export const SETTWOWAYSYNCPROPERTIESUNCHANGED: string = 'setTwoWaySyncPropertiesUnchanged'; -export const COMPONENT_CONSTRUCTOR_SET_STATE_UNCHANGED: string = 'setStateSourcePropertiesUnchanged'; export const COMPONENT_CONSTRUCTOR_PURGE_VARIABLE_DEP: string = 'purgeVariableDependenciesOnElmtId'; export const MARKDEPENDENTELEMENTSDIRTY: string = 'markDependentElementsDirty'; export const ABOUT_TO_BE_DELETE_FUNCTION_ID__: string = 'id__'; diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index 332c475..fd6c048 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -34,7 +34,6 @@ import { CREATE_CONSTRUCTOR_PARAMS, COMPONENT_CONSTRUCTOR_UPDATE_PARAMS, COMPONENT_CONSTRUCTOR_INITIAL_PARAMS, - COMPONENT_CONSTRUCTOR_SET_STATE_UNCHANGED, COMPONENT_CONSTRUCTOR_PURGE_VARIABLE_DEP, COMPONENT_CONSTRUCTOR_DELETE_PARAMS, COMPONENT_DECORATOR_PREVIEW, @@ -64,8 +63,6 @@ import { COMPONENT_IF_UNDEFINED, INNER_COMPONENT_MEMBER_DECORATORS, COMPONENT_RERENDER_FUNCTION, - SETONEWAYSYNCPROPERTIESUNCHANGED, - SETTWOWAYSYNCPROPERTIESUNCHANGED, RMELMTID, ABOUTTOBEDELETEDINTERNAL, UPDATEDIRTYELEMENTS, @@ -143,9 +140,6 @@ function processMembers(members: ts.NodeArray, parentComponentN const newMembers: ts.ClassElement[] = []; const watchMap: Map = new Map(); const updateParamsStatements: ts.Statement[] = []; - const setStateUnchangedStatements: ts.Statement[] = []; - const setOneWayUnchangedStatements: ts.Statement[] = []; - const setTwoWayUnchangedStatements: ts.Statement[] = []; const purgeVariableDepStatements: ts.Statement[] = []; const rerenderStatements: ts.Statement[] = []; const deleteParamsStatements: ts.PropertyDeclaration[] = []; @@ -186,8 +180,7 @@ function processMembers(members: ts.NodeArray, parentComponentN if (result.getControllerSet()) { newMembers.push(result.getControllerSet()); } - processPropertyUnchanged(result, setStateUnchangedStatements, setOneWayUnchangedStatements, - setTwoWayUnchangedStatements, purgeVariableDepStatements, rerenderStatements); + processPropertyUnchanged(result, purgeVariableDepStatements, rerenderStatements); } } if (ts.isMethodDeclaration(item) && item.name) { @@ -202,8 +195,8 @@ function processMembers(members: ts.NodeArray, parentComponentN validateBuildMethodCount(buildCount, parentComponentName, log); validateHasController(parentComponentName, checkController, log); newMembers.unshift(addDeleteParamsFunc(deleteParamsStatements)); - addIntoNewMembers(newMembers, parentComponentName, updateParamsStatements, setStateUnchangedStatements, - setOneWayUnchangedStatements, setTwoWayUnchangedStatements, purgeVariableDepStatements, rerenderStatements); + addIntoNewMembers(newMembers, parentComponentName, updateParamsStatements, + purgeVariableDepStatements, rerenderStatements); newMembers.unshift(addConstructor(ctorNode, watchMap, parentComponentName)); return newMembers; } @@ -225,23 +218,10 @@ function validateDecorators(item: ts.ClassElement, log: LogInfo[]): void { function processPropertyUnchanged( result: UpdateResult, - setStateUnchangedStatements: ts.Statement[], - setOneWayUnchangedStatements: ts.Statement[], - setTwoWayUnchangedStatements: ts.Statement[], purgeVariableDepStatements: ts.Statement[], rerenderStatements: ts.Statement[] ): void { if (sdkVersion.compatibleSdkVersion === 9) { - if(result.getPropertyUnchanged()) { - const propertyUnchanged: ts.Statement = result.getPropertyUnchanged(); - if (result.getDecoratorName() === COMPONENT_STATE_DECORATOR) { - setStateUnchangedStatements.push(propertyUnchanged); - } else if (result.getDecoratorName() === COMPONENT_PROP_DECORATOR) { - setOneWayUnchangedStatements.push(propertyUnchanged); - } else if(LINKS_DECORATORS.has(result.getDecoratorName())) { - setTwoWayUnchangedStatements.push(propertyUnchanged); - } - } if(result.getPurgeVariableDepStatement()) { purgeVariableDepStatements.push(result.getPurgeVariableDepStatement()); } @@ -255,18 +235,12 @@ function addIntoNewMembers( newMembers: ts.ClassElement[], parentComponentName: ts.Identifier, updateParamsStatements: ts.Statement[], - setStateUnchangedStatements: ts.Statement[], - setOneWayUnchangedStatements: ts.Statement[], - setTwoWayUnchangedStatements: ts.Statement[], purgeVariableDepStatements: ts.Statement[], rerenderStatements: ts.Statement[] ): void { if (sdkVersion.compatibleSdkVersion === 9) { newMembers.unshift( addInitialParamsFunc(updateParamsStatements, parentComponentName), - createStateUnchangedFunc(setStateUnchangedStatements), - createOneWaySyncUnchangedFunc(setOneWayUnchangedStatements), - createTwoWaySyncUnchangedFunc(setTwoWayUnchangedStatements), addPurgeVariableDepFunc(purgeVariableDepStatements) ); newMembers.push(addRerenderFunc(rerenderStatements)); @@ -620,26 +594,6 @@ function addInitialParamsFunc(statements: ts.Statement[], parentComponentName: t return createParamsInitBlock(COMPONENT_CONSTRUCTOR_INITIAL_PARAMS, statements, parentComponentName); } -function createStateUnchangedFunc(statements: ts.Statement[]): ts.MethodDeclaration { - return ts.factory.createMethodDeclaration(undefined, undefined, undefined, - ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_SET_STATE_UNCHANGED), undefined, undefined, [], undefined, - ts.factory.createBlock(statements, true)); -} - -// @Prop -function createOneWaySyncUnchangedFunc(statements: ts.Statement[]): ts.MethodDeclaration { - return ts.factory.createMethodDeclaration(undefined, undefined, undefined, - ts.factory.createIdentifier(SETONEWAYSYNCPROPERTIESUNCHANGED), undefined, undefined, [], - undefined, ts.factory.createBlock(statements, true)); -} - -// @Link -function createTwoWaySyncUnchangedFunc(statements: ts.Statement[]): ts.MethodDeclaration { - return ts.factory.createMethodDeclaration( - undefined, undefined, undefined, ts.factory.createIdentifier(SETTWOWAYSYNCPROPERTIESUNCHANGED), - undefined, undefined, [], undefined, ts.factory.createBlock(statements, true)); -} - function addPurgeVariableDepFunc(statements: ts.Statement[]): ts.MethodDeclaration { return ts.factory.createMethodDeclaration( undefined, undefined, undefined, diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index 2c0cfe8..2b429dd 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -136,7 +136,6 @@ export class UpdateResult { private updateParams: ts.Statement; private deleteParams: boolean = false; private controllerSet: ts.MethodDeclaration; - private propertyUnchanged: ts.Statement; private purgeVariableDepStatement: ts.Statement; private rerenderStatement: ts.Statement; private decoratorName: string; @@ -175,10 +174,6 @@ export class UpdateResult { this.deleteParams = deleteParams; } - public setPropertyUnchanged(propertyUnchanged: ts.Statement) { - this.propertyUnchanged = propertyUnchanged; - } - public setPurgeVariableDepStatement(purgeVariableDepStatement: ts.Statement) { this.purgeVariableDepStatement = purgeVariableDepStatement; } @@ -211,10 +206,6 @@ export class UpdateResult { return this.updateParams; } - public getPropertyUnchanged(): ts.Statement { - return this.propertyUnchanged; - } - public getPurgeVariableDepStatement(): ts.Statement { return this.purgeVariableDepStatement; } @@ -365,29 +356,12 @@ function processStateDecorators(node: ts.PropertyDeclaration, decorator: string, } if (sdkVersion.compatibleSdkVersion === 9 && BASICDECORATORS.has(decorator)) { const variableWithUnderLink: string = '__' + name.escapedText.toString(); - updateResult.setPropertyUnchanged(createPropertyUnchangedStatement(variableWithUnderLink)); updateResult.setDecoratorName(decorator); updateResult.setPurgeVariableDepStatement(createPurgeVariableDepStatement(variableWithUnderLink)); updateResult.setRerenderStatement(createRerenderStatement(variableWithUnderLink)); } } -function createPropertyUnchangedStatement(variableWithUnderLink: string): ts.Statement { - return ts.factory.createExpressionStatement( - ts.factory.createCallExpression( - ts.factory.createPropertyAccessExpression( - ts.factory.createPropertyAccessExpression( - ts.factory.createThis(), - ts.factory.createIdentifier(variableWithUnderLink) - ), - ts.factory.createIdentifier(SETPROPERTYUNCHANGED) - ), - undefined, - [] - ) - ); -} - function createPurgeVariableDepStatement(variableWithUnderLink: string): ts.Statement { return ts.factory.createExpressionStatement( ts.factory.createCallExpression( diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts b/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts index a5a4f6f..d054ce3 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts @@ -53,12 +53,6 @@ exports.expectResult = } setInitiallyProvidedValue(params) { } - setStateSourcePropertiesUnchanged() { - } - setOneWaySyncPropertiesUnchanged() { - } - setTwoWaySyncPropertiesUnchanged() { - } purgeVariableDependenciesOnElmtId(rmElmtId) { } aboutToBeDeleted() { @@ -141,12 +135,6 @@ class Banner extends View { this.value = params.value; } } - setStateSourcePropertiesUnchanged() { - } - setOneWaySyncPropertiesUnchanged() { - } - setTwoWaySyncPropertiesUnchanged() { - } purgeVariableDependenciesOnElmtId(rmElmtId) { } aboutToBeDeleted() { diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts index d5c6d6e..3ae74ae 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts @@ -42,13 +42,6 @@ exports.expectResult = this.arr = params.arr; } } - setStateSourcePropertiesUnchanged() { - this.__arr.SetPropertyUnchanged(); - } - setOneWaySyncPropertiesUnchanged() { - } - setTwoWaySyncPropertiesUnchanged() { - } purgeVariableDependenciesOnElmtId(rmElmtId) { this.__arr.purgeDependencyOnElmtId(rmElmtId); } diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts index 4a33c5c..806010b 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts @@ -56,15 +56,6 @@ exports.expectResult = this.toggle3 = params.toggle3; } } - setStateSourcePropertiesUnchanged() { - this.__toggle1.SetPropertyUnchanged(); - this.__toggle2.SetPropertyUnchanged(); - this.__toggle3.SetPropertyUnchanged(); - } - setOneWaySyncPropertiesUnchanged() { - } - setTwoWaySyncPropertiesUnchanged() { - } purgeVariableDependenciesOnElmtId(rmElmtId) { this.__toggle1.purgeDependencyOnElmtId(rmElmtId); this.__toggle2.purgeDependencyOnElmtId(rmElmtId); diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts index 4ad66e0..399594e 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts @@ -34,12 +34,6 @@ exports.expectResult = } setInitiallyProvidedValue(params) { } - setStateSourcePropertiesUnchanged() { - } - setOneWaySyncPropertiesUnchanged() { - } - setTwoWaySyncPropertiesUnchanged() { - } purgeVariableDependenciesOnElmtId(rmElmtId) { } aboutToBeDeleted() { diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts index 4e334ea..d815324 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts @@ -32,12 +32,6 @@ exports.expectResult = } setInitiallyProvidedValue(params) { } - setStateSourcePropertiesUnchanged() { - } - setOneWaySyncPropertiesUnchanged() { - } - setTwoWaySyncPropertiesUnchanged() { - } purgeVariableDependenciesOnElmtId(rmElmtId) { } aboutToBeDeleted() { diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts index 6ad1094..2e4960d 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts @@ -183,12 +183,6 @@ class Test extends View { this.data = params.data; } } - setStateSourcePropertiesUnchanged() { - } - setOneWaySyncPropertiesUnchanged() { - } - setTwoWaySyncPropertiesUnchanged() { - } purgeVariableDependenciesOnElmtId(rmElmtId) { } aboutToBeDeleted() { diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/tab/tab.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/tab/tab.ts index 1ba43d6..f530986 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/tab/tab.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/tab/tab.ts @@ -63,12 +63,6 @@ exports.expectResult = this.controller = params.controller; } } - setStateSourcePropertiesUnchanged() { - } - setOneWaySyncPropertiesUnchanged() { - } - setTwoWaySyncPropertiesUnchanged() { - } purgeVariableDependenciesOnElmtId(rmElmtId) { } aboutToBeDeleted() { diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts index ad22cd4..e7dedf2 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts @@ -42,13 +42,6 @@ exports.expectResult = } setInitiallyProvidedValue(params) { } - setStateSourcePropertiesUnchanged() { - } - setOneWaySyncPropertiesUnchanged() { - } - setTwoWaySyncPropertiesUnchanged() { - this.__counter.SetPropertyUnchanged(); - } purgeVariableDependenciesOnElmtId(rmElmtId) { this.__counter.purgeDependencyOnElmtId(rmElmtId); } @@ -90,13 +83,6 @@ class ParentComponent extends View { this.value = params.value; } } - setStateSourcePropertiesUnchanged() { - this.__value.SetPropertyUnchanged(); - } - setOneWaySyncPropertiesUnchanged() { - } - setTwoWaySyncPropertiesUnchanged() { - } purgeVariableDependenciesOnElmtId(rmElmtId) { this.__value.purgeDependencyOnElmtId(rmElmtId); } diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts index e89e261..7144bfa 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts @@ -79,13 +79,6 @@ class CustomText extends View { setInitiallyProvidedValue(params) { this.__model.set(params.model); } - setStateSourcePropertiesUnchanged() { - } - setOneWaySyncPropertiesUnchanged() { - } - setTwoWaySyncPropertiesUnchanged() { - this.__model.SetPropertyUnchanged(); - } purgeVariableDependenciesOnElmtId(rmElmtId) { this.__model.purgeDependencyOnElmtId(rmElmtId); } @@ -137,13 +130,6 @@ class Parent extends View { this.models = params.models; } } - setStateSourcePropertiesUnchanged() { - this.__models.SetPropertyUnchanged(); - } - setOneWaySyncPropertiesUnchanged() { - } - setTwoWaySyncPropertiesUnchanged() { - } purgeVariableDependenciesOnElmtId(rmElmtId) { this.__models.purgeDependencyOnElmtId(rmElmtId); } diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts index df78558..27d59a3 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts @@ -42,13 +42,6 @@ exports.expectResult = } setInitiallyProvidedValue(params) { } - setStateSourcePropertiesUnchanged() { - } - setOneWaySyncPropertiesUnchanged() { - this.__counter.SetPropertyUnchanged(); - } - setTwoWaySyncPropertiesUnchanged() { - } purgeVariableDependenciesOnElmtId(rmElmtId) { this.__counter.purgeDependencyOnElmtId(rmElmtId); } @@ -90,13 +83,6 @@ class ParentComponent extends View { this.value = params.value; } } - setStateSourcePropertiesUnchanged() { - this.__value.SetPropertyUnchanged(); - } - setOneWaySyncPropertiesUnchanged() { - } - setTwoWaySyncPropertiesUnchanged() { - } purgeVariableDependenciesOnElmtId(rmElmtId) { this.__value.purgeDependencyOnElmtId(rmElmtId); } diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts index d282fa2..52ba157 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts @@ -37,13 +37,6 @@ exports.expectResult = this.counter = params.counter; } } - setStateSourcePropertiesUnchanged() { - this.__counter.SetPropertyUnchanged(); - } - setOneWaySyncPropertiesUnchanged() { - } - setTwoWaySyncPropertiesUnchanged() { - } purgeVariableDependenciesOnElmtId(rmElmtId) { this.__counter.purgeDependencyOnElmtId(rmElmtId); } From bbedae985bd615918dc6091c1b5bacaf0ab8dd94 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Fri, 19 Aug 2022 14:31:42 +0800 Subject: [PATCH 19/33] Bugfix: fixed the tabContent's children transform Signed-off-by: laibo102 Change-Id: Ic7f6b388426a73f2b71f1453c2cece878909af12 --- compiler/src/process_component_build.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index f0896b4..53caa03 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -827,10 +827,9 @@ function processTabContent(node: ts.ExpressionStatement, innerCompStatements: ts ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(TABCONTENT_COMPONENT), ts.factory.createIdentifier(COMPONENT_POP_FUNCTION)), undefined, [])); const tabAttrs: ts.Statement[] = []; - if (TabContentBody) { - const TabContentBodyChild = TabContentBody.statements[0] as ts.ExpressionStatement; + if (TabContentBody && TabContentBody.statements.length) { const newTabContentChildren: ts.Statement[] = []; - processInnerComponent(TabContentBodyChild, newTabContentChildren, log); + processComponentChild(TabContentBody, newTabContentChildren, log); tabContentCreation = ts.factory.createExpressionStatement( ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression( ts.factory.createIdentifier(TABCONTENT_COMPONENT), ts.factory.createIdentifier(COMPONENT_CREATE_FUNCTION)), From b1c825da376b0717b868859609842e2c7eb6185d Mon Sep 17 00:00:00 2001 From: laibo102 Date: Tue, 23 Aug 2022 09:34:33 +0800 Subject: [PATCH 20/33] Bugfix: fixed some conflicts Signed-off-by: laibo102 Change-Id: Ifec1751b4f5886847b7d8cae0b6c0478d9fec602 --- compiler/src/process_component_build.ts | 4 ++-- compiler/src/process_ui_syntax.ts | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 53caa03..9be9423 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -418,12 +418,12 @@ function processInnerComponent(node: ts.ExpressionStatement, innerCompStatements } else if (sdkVersion.compatibleSdkVersion === 9 && TABCONTENT_COMPONENT.includes(nameResult.name)) { processTabContent(node, innerCompStatements, log); } else { - processNormalComponent(node, nameResult, innerCompStatements, log); + processNormalComponent(node, nameResult, innerCompStatements, log, parent); } } function processNormalComponent(node: ts.ExpressionStatement, nameResult: NameResult, - innerCompStatements: ts.Statement[], log: LogInfo[]): void { + innerCompStatements: ts.Statement[], log: LogInfo[], parent: string = undefined): void { const newStatements: ts.Statement[] = []; const res: CreateResult = createComponent(node, COMPONENT_CREATE_FUNCTION); newStatements.push(res.newNode); diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index d0eb38e..011ef02 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -120,7 +120,9 @@ export function processUISyntax(program: ts.Program, ut = false): Function { }); GLOBAL_STYLE_FUNCTION.clear(); const statements: ts.Statement[] = Array.from(node.statements); - generateId(statements, node); + if (sdkVersion.compatibleSdkVersion === 8) { + generateId(statements, node); + } INTERFACE_NODE_SET.forEach(item => { statements.unshift(item); }); From 337d881c9df662aa225c5407688d5913a5654bef Mon Sep 17 00:00:00 2001 From: laibo102 Date: Tue, 23 Aug 2022 11:02:03 +0800 Subject: [PATCH 21/33] Update:update base class name 'View' to 'ViewPU' Signed-off-by: laibo102 Change-Id: I3769dd5384aedca09f7361b8c79748274923a1f5 --- compiler/src/pre_define.ts | 1 + compiler/src/process_component_class.ts | 21 ++++++++++++++----- compiler/src/process_component_member.ts | 7 ++++++- compiler/src/process_custom_component.ts | 5 +++-- .../custom_component/custom_component.ts | 16 +++++++------- .../render_component/foreach/foreach.ts | 2 +- .../render_component/if/if.ts | 2 +- .../render_component/item/GridItem.ts | 2 +- .../render_component/item/ListItem.ts | 2 +- .../lazyforeach/lazyforeach.ts | 2 +- .../render_component/tab/tab.ts | 2 +- .../@link/@link.ts | 6 +++--- .../@objectLink/@objectLink.ts | 6 +++--- .../@prop/@prop.ts | 6 +++--- .../@state/@state.ts | 2 +- 15 files changed, 50 insertions(+), 32 deletions(-) diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 81eb06d..20a82ce 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -314,3 +314,4 @@ export const GRID_COMPONENT: string = 'Grid'; export const GRIDITEM_COMPONENT: string = 'GridItem'; export const WILLUSEPROXY: string = 'willUseProxy'; export const TABCONTENT_COMPONENT: string = 'TabContent'; +export const BASE_COMPONENT_NAME_PU: string = 'ViewPU'; diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index fd6c048..19c6b4b 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -66,7 +66,8 @@ import { RMELMTID, ABOUTTOBEDELETEDINTERNAL, UPDATEDIRTYELEMENTS, - LINKS_DECORATORS + LINKS_DECORATORS, + BASE_COMPONENT_NAME_PU } from './pre_define'; import { BUILDIN_STYLE_NAMES, @@ -477,10 +478,7 @@ function updateHeritageClauses(node: ts.StructDeclaration, log: LogInfo[]) }); } const result:ts.HeritageClause[] = []; - const heritageClause:ts.HeritageClause = ts.factory.createHeritageClause( - ts.SyntaxKind.ExtendsKeyword, - [ts.factory.createExpressionWithTypeArguments( - ts.factory.createIdentifier(BASE_COMPONENT_NAME), [])]); + const heritageClause:ts.HeritageClause = createHeritageClause(); result.push(heritageClause); return ts.factory.createNodeArray(result); } @@ -707,3 +705,16 @@ function validateHasController(componentName: ts.Identifier, checkController: Co }); } } + +function createHeritageClause(): ts.HeritageClause { + if (sdkVersion.compatibleSdkVersion === 9) { + return ts.factory.createHeritageClause( + ts.SyntaxKind.ExtendsKeyword, + [ts.factory.createExpressionWithTypeArguments(ts.factory.createIdentifier(BASE_COMPONENT_NAME_PU), [])] + ); + } + return ts.factory.createHeritageClause( + ts.SyntaxKind.ExtendsKeyword, + [ts.factory.createExpressionWithTypeArguments(ts.factory.createIdentifier(BASE_COMPONENT_NAME), [])] + ); +} diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index 2b429dd..6341a39 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -60,7 +60,8 @@ import { RMELMTID, PURGEDEPENDENCYONELMTID, SETPROPERTYUNCHANGED, - BASICDECORATORS + BASICDECORATORS, + BASE_COMPONENT_NAME_PU } from './pre_define'; import { forbiddenUseStateType, @@ -649,6 +650,10 @@ function createCustomComponentBuilderArrowFunction(parent: ts.PropertyDeclaratio } export function createViewCreate(node: ts.NewExpression | ts.Identifier): ts.CallExpression { + if (sdkVersion.compatibleSdkVersion === 9) { + return createFunction(ts.factory.createIdentifier(BASE_COMPONENT_NAME_PU), + ts.factory.createIdentifier(COMPONENT_CREATE_FUNCTION), ts.factory.createNodeArray([node])); + } return createFunction(ts.factory.createIdentifier(BASE_COMPONENT_NAME), ts.factory.createIdentifier(COMPONENT_CREATE_FUNCTION), ts.factory.createNodeArray([node])); } diff --git a/compiler/src/process_custom_component.ts b/compiler/src/process_custom_component.ts index 7be29b6..a7d9645 100644 --- a/compiler/src/process_custom_component.ts +++ b/compiler/src/process_custom_component.ts @@ -40,7 +40,8 @@ import { STARTGETACCESSRECORDINGFOR, STOPGETACCESSRECORDING, ALLOCATENEWELMETIDFORNEXTCOMPONENT, - STATE_OBJECTLINK_DECORATORS + STATE_OBJECTLINK_DECORATORS, + BASE_COMPONENT_NAME_PU } from './pre_define'; import { propertyCollection, @@ -199,7 +200,7 @@ function createCustomComponent(newNode: ts.NewExpression): ts.Block { ts.factory.createExpressionStatement( ts.factory.createCallExpression( ts.factory.createPropertyAccessExpression( - ts.factory.createIdentifier(BASE_COMPONENT_NAME), + ts.factory.createIdentifier(BASE_COMPONENT_NAME_PU), ts.factory.createIdentifier(COMPONENT_CREATE_FUNCTION) ), undefined, [newNode] diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts b/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts index d054ce3..71cb2a1 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts @@ -46,7 +46,7 @@ struct Banner { }` exports.expectResult = -`class MyComponent extends View { +`class MyComponent extends ViewPU { constructor(parent, params) { super(parent); this.setInitiallyProvidedValue(params); @@ -71,7 +71,7 @@ exports.expectResult = { const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); ViewStackProcessor.StartGetAccessRecordingFor(elmtId); - View.create(new Banner(this, {})); + ViewPU.create(new Banner(this, {})); ViewStackProcessor.StopGetAccessRecording(); } __Common__.create(); @@ -79,7 +79,7 @@ exports.expectResult = { const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); ViewStackProcessor.StartGetAccessRecordingFor(elmtId); - View.create(new Banner(this, {})); + ViewPU.create(new Banner(this, {})); ViewStackProcessor.StopGetAccessRecording(); } __Common__.pop(); @@ -89,14 +89,14 @@ exports.expectResult = { const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); ViewStackProcessor.StartGetAccessRecordingFor(elmtId); - View.create(new Banner(this, {})); + ViewPU.create(new Banner(this, {})); ViewStackProcessor.StopGetAccessRecording(); } __Common__.pop(); { const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); ViewStackProcessor.StartGetAccessRecordingFor(elmtId); - View.create(new Banner(this, { value: "Hello" })); + ViewPU.create(new Banner(this, { value: "Hello" })); ViewStackProcessor.StopGetAccessRecording(); } __Common__.create(); @@ -104,7 +104,7 @@ exports.expectResult = { const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); ViewStackProcessor.StartGetAccessRecordingFor(elmtId); - View.create(new Banner(this, { value: "Hello" })); + ViewPU.create(new Banner(this, { value: "Hello" })); ViewStackProcessor.StopGetAccessRecording(); } __Common__.pop(); @@ -114,7 +114,7 @@ exports.expectResult = { const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); ViewStackProcessor.StartGetAccessRecordingFor(elmtId); - View.create(new Banner(this, { value: "Hello" })); + ViewPU.create(new Banner(this, { value: "Hello" })); ViewStackProcessor.StopGetAccessRecording(); } __Common__.pop(); @@ -124,7 +124,7 @@ exports.expectResult = this.updateDirtyElements(); } } -class Banner extends View { +class Banner extends ViewPU { constructor(parent, params) { super(parent); this.value = "Hello"; diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts index 3ae74ae..77c2288 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts @@ -31,7 +31,7 @@ struct ParentView { } ` exports.expectResult = -`class ParentView extends View { +`class ParentView extends ViewPU { constructor(parent, params) { super(parent); this.__arr = new ObservedPropertyObject(['1', '2', '3'], this, "arr"); diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts index 806010b..d6aee2d 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts @@ -37,7 +37,7 @@ struct IFView { } ` exports.expectResult = -`class IFView extends View { +`class IFView extends ViewPU { constructor(parent, params) { super(parent); this.__toggle1 = new ObservedPropertySimple(false, this, "toggle1"); diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts index 399594e..1b721ed 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts @@ -27,7 +27,7 @@ struct ParentView { } ` exports.expectResult = -`class ParentView extends View { +`class ParentView extends ViewPU { constructor(parent, params) { super(parent); this.setInitiallyProvidedValue(params); diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts index d815324..7f06ac2 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts @@ -25,7 +25,7 @@ struct ParentView { } ` exports.expectResult = -`class ParentView extends View { +`class ParentView extends ViewPU { constructor(parent, params) { super(parent); this.setInitiallyProvidedValue(params); diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts index 2e4960d..8a8d517 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts @@ -172,7 +172,7 @@ class MyDataSource extends BasicDataSource { this.notifyDataAdd(this.dataArray.length - 1); } } -class Test extends View { +class Test extends ViewPU { constructor(parent, params) { super(parent); this.data = new MyDataSource(); diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/tab/tab.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/tab/tab.ts index f530986..2305279 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/tab/tab.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/tab/tab.ts @@ -52,7 +52,7 @@ struct TabSimple { } ` exports.expectResult = -`class TabSimple extends View { +`class TabSimple extends ViewPU { constructor(parent, params) { super(parent); this.controller = new TabsController(); diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts index e7dedf2..53bb1ff 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts @@ -34,7 +34,7 @@ struct ParentComponent { } ` exports.expectResult = -`class LinkComponent extends View { +`class LinkComponent extends ViewPU { constructor(parent, params) { super(parent); this.__counter = new SynchedPropertySimpleTwoWay(params.counter, this, "counter"); @@ -72,7 +72,7 @@ exports.expectResult = this.updateDirtyElements(); } } -class ParentComponent extends View { +class ParentComponent extends ViewPU { constructor(parent, params) { super(parent); this.__value = new ObservedPropertySimple('first init content', this, "value"); @@ -109,7 +109,7 @@ class ParentComponent extends View { { const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); ViewStackProcessor.StartGetAccessRecordingFor(elmtId); - View.create(new LinkComponent(this, { counter: this.__value })); + ViewPU.create(new LinkComponent(this, { counter: this.__value })); ViewStackProcessor.StopGetAccessRecording(); } Column.pop(); diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts index 7144bfa..d62ab55 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts @@ -70,7 +70,7 @@ let Model = class Model { Model = __decorate([ Observed ], Model); -class CustomText extends View { +class CustomText extends ViewPU { constructor(parent, params) { super(parent); this.__model = new SynchedPropertyNesedObject(params.model, this, "model"); @@ -115,7 +115,7 @@ class CustomText extends View { this.updateDirtyElements(); } } -class Parent extends View { +class Parent extends ViewPU { constructor(parent, params) { super(parent); this.nextId = 1; @@ -162,7 +162,7 @@ class Parent extends View { { const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); ViewStackProcessor.StartGetAccessRecordingFor(elmtId); - View.create(new CustomText(this, { model: item })); + ViewPU.create(new CustomText(this, { model: item })); ViewStackProcessor.StopGetAccessRecording(); } }; diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts index 27d59a3..cba0f20 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts @@ -34,7 +34,7 @@ struct ParentComponent { } ` exports.expectResult = -`class PropComponent extends View { +`class PropComponent extends ViewPU { constructor(parent, params) { super(parent); this.__counter = new SynchedPropertySimpleOneWay(params.counter, this, "counter"); @@ -72,7 +72,7 @@ exports.expectResult = this.updateDirtyElements(); } } -class ParentComponent extends View { +class ParentComponent extends ViewPU { constructor(parent, params) { super(parent); this.__value = new ObservedPropertySimple('first init content', this, "value"); @@ -109,7 +109,7 @@ class ParentComponent extends View { { const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent(); ViewStackProcessor.StartGetAccessRecordingFor(elmtId); - View.create(new PropComponent(this, { counter: this.__value })); + ViewPU.create(new PropComponent(this, { counter: this.__value })); ViewStackProcessor.StopGetAccessRecording(); } Column.pop(); diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts index 52ba157..edd82f8 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts @@ -26,7 +26,7 @@ struct StatePage { } ` exports.expectResult = -`class StatePage extends View { +`class StatePage extends ViewPU { constructor(parent, params) { super(parent); this.__counter = new ObservedPropertySimple(0, this, "counter"); From 94a6ff0154114a938d0ab445c78fffd888ebceb2 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Tue, 23 Aug 2022 19:49:22 +0800 Subject: [PATCH 22/33] Update: update lazyForEach component and relevant UT Signed-off-by: laibo102 Change-Id: I906c49c5379004ff3ad7671c3655b320b213dd6b --- compiler/src/pre_define.ts | 1 + compiler/src/process_component_build.ts | 58 ++++++++++++++++--- .../render_component/item/ListItem.ts | 17 +++++- .../lazyforeach/lazyforeach.ts | 2 +- 4 files changed, 66 insertions(+), 12 deletions(-) diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 20a82ce..2ef96f6 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -315,3 +315,4 @@ export const GRIDITEM_COMPONENT: string = 'GridItem'; export const WILLUSEPROXY: string = 'willUseProxy'; export const TABCONTENT_COMPONENT: string = 'TabContent'; export const BASE_COMPONENT_NAME_PU: string = 'ViewPU'; +export const GLOBAL_THIS: string = 'globalThis'; diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 9be9423..421f601 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -84,7 +84,8 @@ import { GRIDITEM_COMPONENT, GRID_COMPONENT, WILLUSEPROXY, - TABCONTENT_COMPONENT + TABCONTENT_COMPONENT, + GLOBAL_THIS } from './pre_define'; import { INNER_COMPONENT_NAMES, @@ -614,9 +615,22 @@ function createIsLazyCreate(node: ts.ExpressionStatement): ts.VariableStatement if (etsComponent) { if ((etsComponent.expression as ts.Identifier).escapedText.toString() === GRIDITEM_COMPONENT) { if (etsComponent.arguments[0] && (etsComponent.arguments[0] as ts.StringLiteral).text === 'false') { + return createIsLazyWithValue(false); + } else if (isLazyForEachChild(node)) { return ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList( - [ts.factory.createVariableDeclaration(ts.factory.createIdentifier(ISLAZYCREATE), - undefined, undefined, ts.factory.createFalse())], ts.NodeFlags.Const)); + [ts.factory.createVariableDeclaration(ts.factory.createIdentifier(ISLAZYCREATE), undefined, undefined, + ts.factory.createBinaryExpression(ts.factory.createBinaryExpression( + ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression( + ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(GLOBAL_THIS), + ts.factory.createIdentifier(__LAZYFOREACHITEMGENFUNCTION)), ts.factory.createToken( + ts.SyntaxKind.ExclamationEqualsEqualsToken), ts.factory.createIdentifier(COMPONENT_IF_UNDEFINED))), + ts.factory.createToken(ts.SyntaxKind.AmpersandAmpersandToken), ts.factory.createTrue()), + ts.factory.createToken(ts.SyntaxKind.AmpersandAmpersandToken), + ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression( + ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression( + ts.factory.createIdentifier(GRID_COMPONENT), ts.factory.createIdentifier(WILLUSEPROXY)), + undefined, []), ts.factory.createToken(ts.SyntaxKind.EqualsEqualsEqualsToken), + ts.factory.createTrue()))))],ts.NodeFlags.Const)); } else { return ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList( [ts.factory.createVariableDeclaration(ts.factory.createIdentifier(ISLAZYCREATE), undefined, undefined, @@ -630,13 +644,18 @@ function createIsLazyCreate(node: ts.ExpressionStatement): ts.VariableStatement } } else { if (etsComponent.arguments[0] && (etsComponent.arguments[0] as ts.StringLiteral).text === 'false') { + return createIsLazyWithValue(false); + } else if (isLazyForEachChild(node)) { return ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList( - [ts.factory.createVariableDeclaration(ts.factory.createIdentifier(ISLAZYCREATE), - undefined, undefined, ts.factory.createFalse())], ts.NodeFlags.Const)); + [ts.factory.createVariableDeclaration(ts.factory.createIdentifier(ISLAZYCREATE), undefined, undefined, + ts.factory.createBinaryExpression(ts.factory.createParenthesizedExpression( + ts.factory.createBinaryExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier( + GLOBAL_THIS), ts.factory.createIdentifier(__LAZYFOREACHITEMGENFUNCTION)), ts.factory.createToken( + ts.SyntaxKind.ExclamationEqualsEqualsToken), ts.factory.createIdentifier(COMPONENT_IF_UNDEFINED))), + ts.factory.createToken(ts.SyntaxKind.AmpersandAmpersandToken), ts.factory.createTrue()))], + ts.NodeFlags.Const)); } else { - return ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList( - [ts.factory.createVariableDeclaration(ts.factory.createIdentifier(ISLAZYCREATE), - undefined, undefined, ts.factory.createTrue())], ts.NodeFlags.Const)); + return createIsLazyWithValue(true); } } } @@ -1984,3 +2003,26 @@ function checkButtonParamHasLabel(node: ts.EtsComponentExpression, log: LogInfo[ } } } + +function isLazyForEachChild(node: ts.ExpressionStatement): boolean { + let temp: any = node.parent; + while(!ts.isEtsComponentExpression(temp) && !ts.isCallExpression(temp)) { + temp = temp.parent; + } + if (temp && temp.expression && (temp.expression as ts.Identifier).escapedText.toString() === COMPONENT_LAZYFOREACH) { + return true; + } + return false; +} + +function createIsLazyWithValue(value: boolean): ts.VariableStatement { + if (value) { + return ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList( + [ts.factory.createVariableDeclaration(ts.factory.createIdentifier(ISLAZYCREATE), + undefined, undefined, ts.factory.createTrue())], ts.NodeFlags.Const)); + } else { + return ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList( + [ts.factory.createVariableDeclaration(ts.factory.createIdentifier(ISLAZYCREATE), + undefined, undefined, ts.factory.createFalse())], ts.NodeFlags.Const)); + } +} diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts index 7f06ac2..bff95ef 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts @@ -18,9 +18,11 @@ exports.source = ` @Component struct ParentView { build() { - ListItem('true') { - Text('xx').width(100) - }.width(200).height(100) + List() { + ListItem('true') { + Text('xx').width(100) + }.width(200).height(100) + } } } ` @@ -39,6 +41,14 @@ exports.expectResult = this.aboutToBeDeletedInternal(); } initialRender() { + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + List.create(); + if (!isInitialRender) { + List.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); { const isLazyCreate = true; const itemCreation = (elmtId, isInitialRender) => { @@ -98,6 +108,7 @@ exports.expectResult = observedDeepRender(); } } + List.pop(); } rerender() { this.updateDirtyElements(); diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts index 8a8d517..ded6f6b 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts @@ -202,7 +202,7 @@ class Test extends ViewPU { const __lazyForEachItemGenFunction = _item => { const row = _item; { - const isLazyCreate = true && (Grid.willUseProxy() === true); + const isLazyCreate = (globalThis.__lazyForEachItemGenFunction !== undefined) && true && (Grid.willUseProxy() === true); const itemCreation = (elmtId, isInitialRender) => { ViewStackProcessor.StartGetAccessRecordingFor(elmtId); GridItem.create(deepRenderFunction, isLazyCreate); From d3b23cb888949e3af2ee69d799454086d52abdb2 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Wed, 24 Aug 2022 11:12:07 +0800 Subject: [PATCH 23/33] Update: update the order of parameters for forEach and relevant UT Signed-off-by: laibo102 Change-Id: Iaa01ec5ca7b8f63e0c68d2a1a4a144a36cd2192c --- compiler/src/process_component_build.ts | 2 +- .../render_component/foreach/foreach.ts | 2 +- .../inner_struct_state_management/@objectLink/@objectLink.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 421f601..4e2a765 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -1035,10 +1035,10 @@ function addForEachIdFuncParameter(argumentsArray: ts.Expression[]): ts.Identifi ts.factory.createIdentifier(ELMTID), ts.factory.createIdentifier(argumentsArray[0] && argumentsArray[0].getText()) ); + addForEachIdFuncParameterArr.push(ts.factory.createIdentifier(FOREACHITEMGENFUNCTION)); if (argumentsArray[2]) { addForEachIdFuncParameterArr.push(ts.factory.createIdentifier(FOREACHITEMIDFUNC)); } - addForEachIdFuncParameterArr.push(ts.factory.createIdentifier(FOREACHITEMGENFUNCTION)); return addForEachIdFuncParameterArr; } diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts index 77c2288..b40e21e 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts @@ -81,7 +81,7 @@ exports.expectResult = Text.pop(); }; const forEachItemIdFunc = item => item.toString(); - this.forEachUpdateFunction(elmtId, this.arr, forEachItemIdFunc, forEachItemGenFunction); + this.forEachUpdateFunction(elmtId, this.arr, forEachItemGenFunction, forEachItemIdFunc); if (!isInitialRender) { ForEach.pop(); } diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts index d62ab55..f687eb8 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts @@ -167,7 +167,7 @@ class Parent extends ViewPU { } }; const forEachItemIdFunc = item => item.text; - this.forEachUpdateFunction(elmtId, this.models, forEachItemIdFunc, forEachItemGenFunction); + this.forEachUpdateFunction(elmtId, this.models, forEachItemGenFunction, forEachItemIdFunc); if (!isInitialRender) { ForEach.pop(); } From 263f7e65e153cba027b0a2fdf67ecfc36d2f29aa Mon Sep 17 00:00:00 2001 From: laibo102 Date: Thu, 25 Aug 2022 20:50:12 +0800 Subject: [PATCH 24/33] Update: updated state variable type and relevant UT Signed-off-by: laibo102 Change-Id: If5265f227e58fddf72c6f8e93082386cef229568 --- compiler/src/pre_define.ts | 8 + compiler/src/process_component_class.ts | 150 ++++++++++++++---- compiler/src/process_component_constructor.ts | 6 +- compiler/src/process_component_member.ts | 61 ++++++- .../render_component/foreach/foreach.ts | 2 +- .../render_component/if/if.ts | 6 +- .../@link/@link.ts | 4 +- .../@objectLink/@objectLink.ts | 4 +- .../@prop/@prop.ts | 4 +- .../@state/@state.ts | 2 +- 10 files changed, 196 insertions(+), 51 deletions(-) diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 2ef96f6..c8bfbf9 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -316,3 +316,11 @@ export const WILLUSEPROXY: string = 'willUseProxy'; export const TABCONTENT_COMPONENT: string = 'TabContent'; export const BASE_COMPONENT_NAME_PU: string = 'ViewPU'; export const GLOBAL_THIS: string = 'globalThis'; +export const OBSERVED_PROPERTY_SIMPLE_PU: string = 'ObservedPropertySimplePU'; +export const OBSERVED_PROPERTY_OBJECT_PU: string = 'ObservedPropertyObjectPU'; +export const SYNCHED_PROPERTY_SIMPLE_ONE_WAY_PU: string = 'SynchedPropertySimpleOneWayPU'; +export const SYNCHED_PROPERTY_SIMPLE_TWO_WAY_PU: string = 'SynchedPropertySimpleTwoWayPU'; +export const SYNCHED_PROPERTY_OBJECT_TWO_WAY_PU: string = 'SynchedPropertyObjectTwoWayPU'; +export const SYNCHED_PROPERTY_NESED_OBJECT_PU: string = 'SynchedPropertyNesedObjectPU'; +export const OBSERVED_PROPERTY_ABSTRACT_PU:string = 'ObservedPropertyAbstractPU'; + diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index 19c6b4b..359bc04 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -67,7 +67,13 @@ import { ABOUTTOBEDELETEDINTERNAL, UPDATEDIRTYELEMENTS, LINKS_DECORATORS, - BASE_COMPONENT_NAME_PU + BASE_COMPONENT_NAME_PU, + OBSERVED_PROPERTY_SIMPLE_PU, + OBSERVED_PROPERTY_OBJECT_PU, + SYNCHED_PROPERTY_SIMPLE_TWO_WAY_PU, + SYNCHED_PROPERTY_SIMPLE_ONE_WAY_PU, + SYNCHED_PROPERTY_NESED_OBJECT_PU, + OBSERVED_PROPERTY_ABSTRACT_PU } from './pre_define'; import { BUILDIN_STYLE_NAMES, @@ -264,38 +270,16 @@ function addPropertyMember(item: ts.ClassElement, newMembers: ts.ClassElement[], let newType: ts.TypeNode; decoratorName = propertyItem.decorators[i].getText().replace(/\(.*\)$/, '').trim(); let isLocalStorage: boolean = false; - switch (decoratorName) { - case COMPONENT_STATE_DECORATOR: - case COMPONENT_PROVIDE_DECORATOR: - newType = ts.factory.createTypeReferenceNode(isSimpleType(type, program, log) ? - OBSERVED_PROPERTY_SIMPLE : OBSERVED_PROPERTY_OBJECT, [type || - ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)]); - break; - case COMPONENT_LINK_DECORATOR: - case COMPONENT_CONSUME_DECORATOR: - newType = ts.factory.createTypeReferenceNode(isSimpleType(type, program, log) ? - SYNCHED_PROPERTY_SIMPLE_TWO_WAY : SYNCHED_PROPERTY_SIMPLE_ONE_WAY, [type || - ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)]); - break; - case COMPONENT_PROP_DECORATOR: - newType = ts.factory.createTypeReferenceNode(SYNCHED_PROPERTY_SIMPLE_ONE_WAY, [type || - ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)]); - break; - case COMPONENT_OBJECT_LINK_DECORATOR: - newType = ts.factory.createTypeReferenceNode(SYNCHED_PROPERTY_NESED_OBJECT, [type || - ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)]); - break; - case COMPONENT_STORAGE_PROP_DECORATOR: - case COMPONENT_STORAGE_LINK_DECORATOR: - newType = ts.factory.createTypeReferenceNode(OBSERVED_PROPERTY_ABSTRACT, [type || - ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)]); - break; - case COMPONENT_LOCAL_STORAGE_LINK_DECORATOR: - case COMPONENT_LOCAL_STORAGE_PROP_DECORATOR: - newType = ts.factory.createTypeReferenceNode(OBSERVED_PROPERTY_ABSTRACT, [type || - ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)]); - isLocalStorage = true; - break; + if (sdkVersion.compatibleSdkVersion === 8) { + newType = createTypeReference(decoratorName, type, log, program); + } else { + newType = createTypeReferencePU(decoratorName, type, log, program); + } + if ( + decoratorName === COMPONENT_LOCAL_STORAGE_LINK_DECORATOR || + decoratorName === COMPONENT_LOCAL_STORAGE_PROP_DECORATOR + ) { + isLocalStorage = true; } updatePropertyItem = createPropertyDeclaration(propertyItem, newType, false, isLocalStorage, parentComponentName); @@ -718,3 +702,103 @@ function createHeritageClause(): ts.HeritageClause { [ts.factory.createExpressionWithTypeArguments(ts.factory.createIdentifier(BASE_COMPONENT_NAME), [])] ); } + +function createTypeReference(decoratorName: string, type: ts.TypeNode, log: LogInfo[], + program: ts.Program): ts.TypeNode { + let newType: ts.TypeNode; + switch (decoratorName) { + case COMPONENT_STATE_DECORATOR: + case COMPONENT_PROVIDE_DECORATOR: + newType = ts.factory.createTypeReferenceNode( + isSimpleType(type, program, log) + ? OBSERVED_PROPERTY_SIMPLE + : OBSERVED_PROPERTY_OBJECT, + [type || ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)] + ); + break; + case COMPONENT_LINK_DECORATOR: + case COMPONENT_CONSUME_DECORATOR: + newType = ts.factory.createTypeReferenceNode( + isSimpleType(type, program, log) + ? SYNCHED_PROPERTY_SIMPLE_TWO_WAY + : SYNCHED_PROPERTY_SIMPLE_ONE_WAY, + [type || ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)] + ); + break; + case COMPONENT_PROP_DECORATOR: + newType = ts.factory.createTypeReferenceNode( + SYNCHED_PROPERTY_SIMPLE_ONE_WAY, + [type || ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)] + ); + break; + case COMPONENT_OBJECT_LINK_DECORATOR: + newType = ts.factory.createTypeReferenceNode( + SYNCHED_PROPERTY_NESED_OBJECT, + [type || ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)] + ); + break; + case COMPONENT_STORAGE_PROP_DECORATOR: + case COMPONENT_STORAGE_LINK_DECORATOR: + newType = ts.factory.createTypeReferenceNode(OBSERVED_PROPERTY_ABSTRACT, [ + type || ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), + ]); + break; + case COMPONENT_LOCAL_STORAGE_LINK_DECORATOR: + case COMPONENT_LOCAL_STORAGE_PROP_DECORATOR: + newType = ts.factory.createTypeReferenceNode(OBSERVED_PROPERTY_ABSTRACT, [ + type || ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), + ]); + break; + } + return newType; +} + +function createTypeReferencePU(decoratorName: string, type: ts.TypeNode, log: LogInfo[], + program: ts.Program): ts.TypeNode { + let newType: ts.TypeNode; + switch (decoratorName) { + case COMPONENT_STATE_DECORATOR: + case COMPONENT_PROVIDE_DECORATOR: + newType = ts.factory.createTypeReferenceNode( + isSimpleType(type, program, log) + ? OBSERVED_PROPERTY_SIMPLE_PU + : OBSERVED_PROPERTY_OBJECT_PU, + [type || ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)] + ); + break; + case COMPONENT_LINK_DECORATOR: + newType = ts.factory.createTypeReferenceNode( + isSimpleType(type, program, log) + ? SYNCHED_PROPERTY_SIMPLE_TWO_WAY_PU + : SYNCHED_PROPERTY_SIMPLE_ONE_WAY_PU, + [type || ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)] + ); + break; + case COMPONENT_PROP_DECORATOR: + newType = ts.factory.createTypeReferenceNode( + SYNCHED_PROPERTY_SIMPLE_ONE_WAY_PU, + [type || ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)] + ); + break; + case COMPONENT_OBJECT_LINK_DECORATOR: + newType = ts.factory.createTypeReferenceNode( + SYNCHED_PROPERTY_NESED_OBJECT_PU, + [type || ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)] + ); + break; + case COMPONENT_CONSUME_DECORATOR: + case COMPONENT_STORAGE_PROP_DECORATOR: + case COMPONENT_STORAGE_LINK_DECORATOR: + newType = ts.factory.createTypeReferenceNode(OBSERVED_PROPERTY_ABSTRACT_PU, [ + type || ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), + ]); + break; + case COMPONENT_LOCAL_STORAGE_LINK_DECORATOR: + case COMPONENT_LOCAL_STORAGE_PROP_DECORATOR: + newType = ts.factory.createTypeReferenceNode(OBSERVED_PROPERTY_ABSTRACT_PU, [ + type || ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), + ]); + break; + } + return newType; +} diff --git a/compiler/src/process_component_constructor.ts b/compiler/src/process_component_constructor.ts index ffa51a5..11c1d2f 100644 --- a/compiler/src/process_component_constructor.ts +++ b/compiler/src/process_component_constructor.ts @@ -24,7 +24,8 @@ import { COMPONENT_WATCH_FUNCTION, BASE_COMPONENT_NAME, INTERFACE_NAME_SUFFIX, - COMPONENT_CONSTRUCTOR_LOCALSTORAGE + COMPONENT_CONSTRUCTOR_LOCALSTORAGE, + BASE_COMPONENT_NAME_PU } from './pre_define'; import { @@ -127,7 +128,8 @@ function addParamsType(ctorNode: ts.ConstructorDeclaration, modifyPara: ts.Param 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), + ts.factory.createTypeReferenceNode(ts.factory.createIdentifier( + sdkVersion.compatibleSdkVersion === 8 ? BASE_COMPONENT_NAME : BASE_COMPONENT_NAME_PU), undefined), item.initializer); break; case COMPONENT_CONSTRUCTOR_PARAMS: diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index 6341a39..1a72ed8 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -61,7 +61,13 @@ import { PURGEDEPENDENCYONELMTID, SETPROPERTYUNCHANGED, BASICDECORATORS, - BASE_COMPONENT_NAME_PU + BASE_COMPONENT_NAME_PU, + OBSERVED_PROPERTY_SIMPLE_PU, + OBSERVED_PROPERTY_OBJECT_PU, + SYNCHED_PROPERTY_SIMPLE_TWO_WAY_PU, + SYNCHED_PROPERTY_OBJECT_TWO_WAY_PU, + SYNCHED_PROPERTY_SIMPLE_ONE_WAY_PU, + SYNCHED_PROPERTY_NESED_OBJECT_PU } from './pre_define'; import { forbiddenUseStateType, @@ -444,15 +450,19 @@ function createVariableInitStatement(node: ts.PropertyDeclaration, decorator: st break; case COMPONENT_STATE_DECORATOR: case COMPONENT_PROVIDE_DECORATOR: - updateState = updateObservedProperty(node, name, type, program); + updateState = sdkVersion.compatibleSdkVersion === 8 ? + updateObservedProperty(node, name, type, program) : updateObservedPropertyPU(node, name, type, program); break; case COMPONENT_LINK_DECORATOR: wrongDecoratorInPreview(node, COMPONENT_LINK_DECORATOR, hasPreview, log); - updateState = updateSynchedPropertyTwoWay(name, type, program); + updateState = sdkVersion.compatibleSdkVersion === 8 ? + updateSynchedPropertyTwoWay(name, type, program) : updateSynchedPropertyTwoWayPU(name, type, program); break; case COMPONENT_PROP_DECORATOR: wrongDecoratorInPreview(node, COMPONENT_PROP_DECORATOR, hasPreview, log); - updateState = updateSynchedPropertyOneWay(name, type, decorator, log, program); + updateState = sdkVersion.compatibleSdkVersion === 8 + ? updateSynchedPropertyOneWay(name, type, decorator, log, program) + : updateSynchedPropertyOneWayPU(name, type, decorator, log, program); break; case COMPONENT_STORAGE_PROP_DECORATOR: case COMPONENT_STORAGE_LINK_DECORATOR: @@ -461,7 +471,9 @@ function createVariableInitStatement(node: ts.PropertyDeclaration, decorator: st updateState = updateStoragePropAndLinkProperty(node, name, setFuncName, log); break; case COMPONENT_OBJECT_LINK_DECORATOR: - updateState = updateSynchedPropertyNesedObject(name, type, decorator, log); + updateState = sdkVersion.compatibleSdkVersion === 8 + ? updateSynchedPropertyNesedObject(name, type, decorator, log) + : updateSynchedPropertyNesedObjectPU(name, type, decorator, log); break; case COMPONENT_CONSUME_DECORATOR: wrongDecoratorInPreview(node, COMPONENT_CONSUME_DECORATOR, hasPreview, log); @@ -988,3 +1000,42 @@ function validateVariableType(typeNode: ts.TypeNode, log: LogInfo[]): void { }); } +function updateObservedPropertyPU(item: ts.PropertyDeclaration, name: ts.Identifier, + type: ts.TypeNode, program: ts.Program): ts.ExpressionStatement { + return ts.factory.createExpressionStatement(ts.factory.createBinaryExpression( + createPropertyAccessExpressionWithThis(`__${name.getText()}`), + ts.factory.createToken(ts.SyntaxKind.EqualsToken), ts.factory.createNewExpression( + ts.factory.createIdentifier(isSimpleType(type, program) ? OBSERVED_PROPERTY_SIMPLE_PU : + OBSERVED_PROPERTY_OBJECT_PU), undefined, [item.initializer, ts.factory.createThis(), + ts.factory.createStringLiteral(name.escapedText.toString())]))); +} + +function updateSynchedPropertyTwoWayPU(nameIdentifier: ts.Identifier, type: ts.TypeNode, + program: ts.Program): ts.ExpressionStatement { + const name: string = nameIdentifier.escapedText.toString(); + const functionName: string = isSimpleType(type, program) ? + SYNCHED_PROPERTY_SIMPLE_TWO_WAY_PU : SYNCHED_PROPERTY_OBJECT_TWO_WAY_PU; + return createInitExpressionStatementForDecorator(name, functionName, + createPropertyAccessExpressionWithParams(name)); +} + +function updateSynchedPropertyOneWayPU(nameIdentifier: ts.Identifier, type: ts.TypeNode, + decoractor: string, log: LogInfo[], program: ts.Program): ts.ExpressionStatement { + const name: string = nameIdentifier.escapedText.toString(); + if (isSimpleType(type, program)) { + return createInitExpressionStatementForDecorator(name, SYNCHED_PROPERTY_SIMPLE_ONE_WAY_PU, + createPropertyAccessExpressionWithParams(name)); + } else { + validateNonSimpleType(nameIdentifier, decoractor, log); + } +} + +function updateSynchedPropertyNesedObjectPU(nameIdentifier: ts.Identifier, + type: ts.TypeNode, decoractor: string, log: LogInfo[]): ts.ExpressionStatement { + if (isObservedClassType(type)) { + return createInitExpressionStatementForDecorator(nameIdentifier.getText(), SYNCHED_PROPERTY_NESED_OBJECT_PU, + createPropertyAccessExpressionWithParams(nameIdentifier.getText())); + } else { + validateNonObservedClassType(nameIdentifier, decoractor, log); + } +} diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts index b40e21e..64a7326 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts @@ -34,7 +34,7 @@ exports.expectResult = `class ParentView extends ViewPU { constructor(parent, params) { super(parent); - this.__arr = new ObservedPropertyObject(['1', '2', '3'], this, "arr"); + this.__arr = new ObservedPropertyObjectPU(['1', '2', '3'], this, "arr"); this.setInitiallyProvidedValue(params); } setInitiallyProvidedValue(params) { diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts index d6aee2d..7492357 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts @@ -40,9 +40,9 @@ exports.expectResult = `class IFView extends ViewPU { constructor(parent, params) { super(parent); - this.__toggle1 = new ObservedPropertySimple(false, this, "toggle1"); - this.__toggle2 = new ObservedPropertySimple(false, this, "toggle2"); - this.__toggle3 = new ObservedPropertySimple(false, this, "toggle3"); + this.__toggle1 = new ObservedPropertySimplePU(false, this, "toggle1"); + this.__toggle2 = new ObservedPropertySimplePU(false, this, "toggle2"); + this.__toggle3 = new ObservedPropertySimplePU(false, this, "toggle3"); this.setInitiallyProvidedValue(params); } setInitiallyProvidedValue(params) { diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts index 53bb1ff..87a2198 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts @@ -37,7 +37,7 @@ exports.expectResult = `class LinkComponent extends ViewPU { constructor(parent, params) { super(parent); - this.__counter = new SynchedPropertySimpleTwoWay(params.counter, this, "counter"); + this.__counter = new SynchedPropertySimpleTwoWayPU(params.counter, this, "counter"); this.setInitiallyProvidedValue(params); } setInitiallyProvidedValue(params) { @@ -75,7 +75,7 @@ exports.expectResult = class ParentComponent extends ViewPU { constructor(parent, params) { super(parent); - this.__value = new ObservedPropertySimple('first init content', this, "value"); + this.__value = new ObservedPropertySimplePU('first init content', this, "value"); this.setInitiallyProvidedValue(params); } setInitiallyProvidedValue(params) { diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts index f687eb8..4daa5bc 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts @@ -73,7 +73,7 @@ Model = __decorate([ class CustomText extends ViewPU { constructor(parent, params) { super(parent); - this.__model = new SynchedPropertyNesedObject(params.model, this, "model"); + this.__model = new SynchedPropertyNesedObjectPU(params.model, this, "model"); this.setInitiallyProvidedValue(params); } setInitiallyProvidedValue(params) { @@ -119,7 +119,7 @@ class Parent extends ViewPU { constructor(parent, params) { super(parent); this.nextId = 1; - this.__models = new ObservedPropertyObject([new Model('0', '#ffffff'), new Model('1', '#fff456')], this, "models"); + this.__models = new ObservedPropertyObjectPU([new Model('0', '#ffffff'), new Model('1', '#fff456')], this, "models"); this.setInitiallyProvidedValue(params); } setInitiallyProvidedValue(params) { diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts index cba0f20..b93267c 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts @@ -37,7 +37,7 @@ exports.expectResult = `class PropComponent extends ViewPU { constructor(parent, params) { super(parent); - this.__counter = new SynchedPropertySimpleOneWay(params.counter, this, "counter"); + this.__counter = new SynchedPropertySimpleOneWayPU(params.counter, this, "counter"); this.setInitiallyProvidedValue(params); } setInitiallyProvidedValue(params) { @@ -75,7 +75,7 @@ exports.expectResult = class ParentComponent extends ViewPU { constructor(parent, params) { super(parent); - this.__value = new ObservedPropertySimple('first init content', this, "value"); + this.__value = new ObservedPropertySimplePU('first init content', this, "value"); this.setInitiallyProvidedValue(params); } setInitiallyProvidedValue(params) { diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts index edd82f8..c3ec7b0 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts @@ -29,7 +29,7 @@ exports.expectResult = `class StatePage extends ViewPU { constructor(parent, params) { super(parent); - this.__counter = new ObservedPropertySimple(0, this, "counter"); + this.__counter = new ObservedPropertySimplePU(0, this, "counter"); this.setInitiallyProvidedValue(params); } setInitiallyProvidedValue(params) { From ab0b3fd1381000064b25a1140509d8bad4b37c63 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Fri, 26 Aug 2022 16:55:39 +0800 Subject: [PATCH 25/33] Bugfix: fix double lazyForEach Signed-off-by: laibo102 Change-Id: If1bed824ac157231da0e6cf31d355d9aa6960c66 --- compiler/src/process_component_build.ts | 5 +- .../lazyforeach/lazyforeach.ts | 110 +++++++++--------- 2 files changed, 59 insertions(+), 56 deletions(-) diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 4e2a765..5e4ffe6 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -935,9 +935,10 @@ function processForEachComponentNew(node: ts.ExpressionStatement, newStatements: newStatements.push(createComponentCreationStatement(node, newForEachStatements), popNode); } else { if (argumentsArray[2]) { - newStatements.push(itemGenFunctionStatement, itemIdFuncStatement, lazyForEachStatement, popNode); + newStatements.push(ts.factory.createBlock([itemGenFunctionStatement, itemIdFuncStatement, lazyForEachStatement, + popNode], true)); } else { - newStatements.push(itemGenFunctionStatement, lazyForEachStatement, popNode); + newStatements.push(ts.factory.createBlock([itemGenFunctionStatement, lazyForEachStatement, popNode], true)); } } } diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts index ded6f6b..fe7f387 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts @@ -199,67 +199,69 @@ class Test extends ViewPU { } ViewStackProcessor.StopGetAccessRecording(); }); - const __lazyForEachItemGenFunction = _item => { - const row = _item; - { - const isLazyCreate = (globalThis.__lazyForEachItemGenFunction !== undefined) && true && (Grid.willUseProxy() === true); - const itemCreation = (elmtId, isInitialRender) => { - ViewStackProcessor.StartGetAccessRecordingFor(elmtId); - GridItem.create(deepRenderFunction, isLazyCreate); - if (!isInitialRender) { - GridItem.pop(); - } - ViewStackProcessor.StopGetAccessRecording(); - }; - const observedShallowRender = () => { - this.observeComponentCreation((elmtId, isInitialRender) => { + { + const __lazyForEachItemGenFunction = _item => { + const row = _item; + { + const isLazyCreate = (globalThis.__lazyForEachItemGenFunction !== undefined) && true && (Grid.willUseProxy() === true); + const itemCreation = (elmtId, isInitialRender) => { ViewStackProcessor.StartGetAccessRecordingFor(elmtId); GridItem.create(deepRenderFunction, isLazyCreate); if (!isInitialRender) { GridItem.pop(); } ViewStackProcessor.StopGetAccessRecording(); - }); - GridItem.pop(); - }; - const observedDeepRender = () => { - this.observeComponentCreation(itemCreation); - this.observeComponentCreation((elmtId, isInitialRender) => { - ViewStackProcessor.StartGetAccessRecordingFor(elmtId); - Text.create(row); - if (!isInitialRender) { - Text.pop(); - } - ViewStackProcessor.StopGetAccessRecording(); - }); - Text.pop(); - GridItem.pop(); - }; - const deepRenderFunction = (elmtId, isInitialRender) => { - itemCreation(elmtId, isInitialRender); - this.updateFuncByElmtId.set(elmtId, itemCreation); - this.observeComponentCreation((elmtId, isInitialRender) => { - ViewStackProcessor.StartGetAccessRecordingFor(elmtId); - Text.create(row); - if (!isInitialRender) { - Text.pop(); - } - ViewStackProcessor.StopGetAccessRecording(); - }); - Text.pop(); - GridItem.pop(); - }; - if (isLazyCreate) { - observedShallowRender(); + }; + const observedShallowRender = () => { + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + GridItem.create(deepRenderFunction, isLazyCreate); + if (!isInitialRender) { + GridItem.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + GridItem.pop(); + }; + const observedDeepRender = () => { + this.observeComponentCreation(itemCreation); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create(row); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + Text.pop(); + GridItem.pop(); + }; + const deepRenderFunction = (elmtId, isInitialRender) => { + itemCreation(elmtId, isInitialRender); + this.updateFuncByElmtId.set(elmtId, itemCreation); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create(row); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + Text.pop(); + GridItem.pop(); + }; + if (isLazyCreate) { + observedShallowRender(); + } + else { + observedDeepRender(); + } } - else { - observedDeepRender(); - } - } - }; - const __lazyForEachItemIdFunc = row => row; - LazyForEach.create("1", this, this.data, __lazyForEachItemGenFunction, __lazyForEachItemIdFunc); - LazyForEach.pop(); + }; + const __lazyForEachItemIdFunc = row => row; + LazyForEach.create("1", this, this.data, __lazyForEachItemGenFunction, __lazyForEachItemIdFunc); + LazyForEach.pop(); + } Grid.pop(); } rerender() { From cc4b0f63c7b099497a3926c549ea8315ae896230 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Mon, 29 Aug 2022 15:34:32 +0800 Subject: [PATCH 26/33] Update: constructor init with __localStorage Signed-off-by: laibo102 Change-Id: I848c3523a706903c95d6819cc70da731c533be05 --- compiler/src/pre_define.ts | 3 ++- compiler/src/process_component_constructor.ts | 16 +++++++++++----- .../custom_component/custom_component.ts | 8 ++++---- .../render_component/foreach/foreach.ts | 4 ++-- .../render_component/if/if.ts | 4 ++-- .../render_component/item/GridItem.ts | 4 ++-- .../render_component/item/ListItem.ts | 4 ++-- .../render_component/lazyforeach/lazyforeach.ts | 4 ++-- .../render_component/tab/tab.ts | 4 ++-- .../inner_struct_state_management/@link/@link.ts | 8 ++++---- .../@objectLink/@objectLink.ts | 8 ++++---- .../inner_struct_state_management/@prop/@prop.ts | 8 ++++---- .../@state/@state.ts | 4 ++-- 13 files changed, 43 insertions(+), 36 deletions(-) diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index c8bfbf9..e7aa6ee 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -323,4 +323,5 @@ export const SYNCHED_PROPERTY_SIMPLE_TWO_WAY_PU: string = 'SynchedPropertySimple export const SYNCHED_PROPERTY_OBJECT_TWO_WAY_PU: string = 'SynchedPropertyObjectTwoWayPU'; export const SYNCHED_PROPERTY_NESED_OBJECT_PU: string = 'SynchedPropertyNesedObjectPU'; export const OBSERVED_PROPERTY_ABSTRACT_PU:string = 'ObservedPropertyAbstractPU'; - +export const COMPONENT_CONSTRUCTOR_LOCALSTORAGE_PU: string = '__localStorage'; +export const COMPONENT_CONSTRUCTOR_LOCALSTORAGE_TYPE_PU: string = 'LocalStorage'; diff --git a/compiler/src/process_component_constructor.ts b/compiler/src/process_component_constructor.ts index 11c1d2f..da552aa 100644 --- a/compiler/src/process_component_constructor.ts +++ b/compiler/src/process_component_constructor.ts @@ -25,7 +25,9 @@ import { BASE_COMPONENT_NAME, INTERFACE_NAME_SUFFIX, COMPONENT_CONSTRUCTOR_LOCALSTORAGE, - BASE_COMPONENT_NAME_PU + BASE_COMPONENT_NAME_PU, + COMPONENT_CONSTRUCTOR_LOCALSTORAGE_PU, + COMPONENT_CONSTRUCTOR_LOCALSTORAGE_TYPE_PU } from './pre_define'; import { @@ -95,7 +97,7 @@ function initConstructorParams(node: ts.ConstructorDeclaration, parentComponentN ]) : new Set([ COMPONENT_CONSTRUCTOR_PARENT, COMPONENT_CONSTRUCTOR_PARAMS, - localStorageNum ? COMPONENT_CONSTRUCTOR_LOCALSTORAGE : COMPONENT_CONSTRUCTOR_PARAMS + COMPONENT_CONSTRUCTOR_LOCALSTORAGE_PU ]); const newParameters: ts.ParameterDeclaration[] = Array.from(node.parameters); if (newParameters.length !== 0) { @@ -138,6 +140,11 @@ function addParamsType(ctorNode: ts.ConstructorDeclaration, modifyPara: ts.Param ts.factory.createTypeReferenceNode(ts.factory.createIdentifier( parentComponentName.getText() + INTERFACE_NAME_SUFFIX), undefined), item.initializer); break; + case COMPONENT_CONSTRUCTOR_LOCALSTORAGE_PU: + parameter = ts.factory.createParameterDeclaration(item.decorators, item.modifiers, item.dotDotDotToken, + item.name, ts.factory.createToken(ts.SyntaxKind.QuestionToken), ts.factory.createTypeReferenceNode( + ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_LOCALSTORAGE_TYPE_PU), undefined), item.initializer); + break; } newTSPara.push(parameter); }); @@ -184,9 +191,8 @@ function createCallSuperStatement(localStorageNum: number): ts.Statement{ } else { return (ts.factory.createExpressionStatement( ts.factory.createCallExpression(ts.factory.createSuper(), undefined, - localStorageNum ? [ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT), - ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_LOCALSTORAGE)] : - [ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT)]))); + [ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARENT), + ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_LOCALSTORAGE_PU)]))); } } diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts b/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts index 71cb2a1..5b2bd68 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts @@ -47,8 +47,8 @@ struct Banner { exports.expectResult = `class MyComponent extends ViewPU { - constructor(parent, params) { - super(parent); + constructor(parent, params, __localStorage) { + super(parent, __localStorage); this.setInitiallyProvidedValue(params); } setInitiallyProvidedValue(params) { @@ -125,8 +125,8 @@ exports.expectResult = } } class Banner extends ViewPU { - constructor(parent, params) { - super(parent); + constructor(parent, params, __localStorage) { + super(parent, __localStorage); this.value = "Hello"; this.setInitiallyProvidedValue(params); } diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts index 64a7326..14722aa 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts @@ -32,8 +32,8 @@ struct ParentView { ` exports.expectResult = `class ParentView extends ViewPU { - constructor(parent, params) { - super(parent); + constructor(parent, params, __localStorage) { + super(parent, __localStorage); this.__arr = new ObservedPropertyObjectPU(['1', '2', '3'], this, "arr"); this.setInitiallyProvidedValue(params); } diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts index 7492357..5d011f9 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts @@ -38,8 +38,8 @@ struct IFView { ` exports.expectResult = `class IFView extends ViewPU { - constructor(parent, params) { - super(parent); + constructor(parent, params, __localStorage) { + super(parent, __localStorage); this.__toggle1 = new ObservedPropertySimplePU(false, this, "toggle1"); this.__toggle2 = new ObservedPropertySimplePU(false, this, "toggle2"); this.__toggle3 = new ObservedPropertySimplePU(false, this, "toggle3"); diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts index 1b721ed..8a7dfac 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts @@ -28,8 +28,8 @@ struct ParentView { ` exports.expectResult = `class ParentView extends ViewPU { - constructor(parent, params) { - super(parent); + constructor(parent, params, __localStorage) { + super(parent, __localStorage); this.setInitiallyProvidedValue(params); } setInitiallyProvidedValue(params) { diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts index bff95ef..0c572a2 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts @@ -28,8 +28,8 @@ struct ParentView { ` exports.expectResult = `class ParentView extends ViewPU { - constructor(parent, params) { - super(parent); + constructor(parent, params, __localStorage) { + super(parent, __localStorage); this.setInitiallyProvidedValue(params); } setInitiallyProvidedValue(params) { diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts index fe7f387..22bf64f 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts @@ -173,8 +173,8 @@ class MyDataSource extends BasicDataSource { } } class Test extends ViewPU { - constructor(parent, params) { - super(parent); + constructor(parent, params, __localStorage) { + super(parent, __localStorage); this.data = new MyDataSource(); this.setInitiallyProvidedValue(params); } diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/tab/tab.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/tab/tab.ts index 2305279..e0a0599 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/tab/tab.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/tab/tab.ts @@ -53,8 +53,8 @@ struct TabSimple { ` exports.expectResult = `class TabSimple extends ViewPU { - constructor(parent, params) { - super(parent); + constructor(parent, params, __localStorage) { + super(parent, __localStorage); this.controller = new TabsController(); this.setInitiallyProvidedValue(params); } diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts index 87a2198..ef54527 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts @@ -35,8 +35,8 @@ struct ParentComponent { ` exports.expectResult = `class LinkComponent extends ViewPU { - constructor(parent, params) { - super(parent); + constructor(parent, params, __localStorage) { + super(parent, __localStorage); this.__counter = new SynchedPropertySimpleTwoWayPU(params.counter, this, "counter"); this.setInitiallyProvidedValue(params); } @@ -73,8 +73,8 @@ exports.expectResult = } } class ParentComponent extends ViewPU { - constructor(parent, params) { - super(parent); + constructor(parent, params, __localStorage) { + super(parent, __localStorage); this.__value = new ObservedPropertySimplePU('first init content', this, "value"); this.setInitiallyProvidedValue(params); } diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts index 4daa5bc..3105ead 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts @@ -71,8 +71,8 @@ Model = __decorate([ Observed ], Model); class CustomText extends ViewPU { - constructor(parent, params) { - super(parent); + constructor(parent, params, __localStorage) { + super(parent, __localStorage); this.__model = new SynchedPropertyNesedObjectPU(params.model, this, "model"); this.setInitiallyProvidedValue(params); } @@ -116,8 +116,8 @@ class CustomText extends ViewPU { } } class Parent extends ViewPU { - constructor(parent, params) { - super(parent); + constructor(parent, params, __localStorage) { + super(parent, __localStorage); this.nextId = 1; this.__models = new ObservedPropertyObjectPU([new Model('0', '#ffffff'), new Model('1', '#fff456')], this, "models"); this.setInitiallyProvidedValue(params); diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts index b93267c..88ffb83 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts @@ -35,8 +35,8 @@ struct ParentComponent { ` exports.expectResult = `class PropComponent extends ViewPU { - constructor(parent, params) { - super(parent); + constructor(parent, params, __localStorage) { + super(parent, __localStorage); this.__counter = new SynchedPropertySimpleOneWayPU(params.counter, this, "counter"); this.setInitiallyProvidedValue(params); } @@ -73,8 +73,8 @@ exports.expectResult = } } class ParentComponent extends ViewPU { - constructor(parent, params) { - super(parent); + constructor(parent, params, __localStorage) { + super(parent, __localStorage); this.__value = new ObservedPropertySimplePU('first init content', this, "value"); this.setInitiallyProvidedValue(params); } diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts index c3ec7b0..75cfd8e 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts @@ -27,8 +27,8 @@ struct StatePage { ` exports.expectResult = `class StatePage extends ViewPU { - constructor(parent, params) { - super(parent); + constructor(parent, params, __localStorage) { + super(parent, __localStorage); this.__counter = new ObservedPropertySimplePU(0, this, "counter"); this.setInitiallyProvidedValue(params); } From 7e1c6f8a1e6ce896d1d0cb8188f1ceebe56ba0cf Mon Sep 17 00:00:00 2001 From: laibo102 Date: Mon, 29 Aug 2022 16:41:35 +0800 Subject: [PATCH 27/33] Bugfix: fix conflict Signed-off-by: laibo102 Change-Id: I09e7ceb5137b1962ee3497e91af9fee064c7b224 --- compiler/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/main.js b/compiler/main.js index daaddd1..21f1ff1 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -417,6 +417,7 @@ function saveAppResourcePath(appResourcePath, appResourcePathSavePath) { fs.writeFileSync(appResourcePathSavePath, appResourcePath); } } +} function addSDKBuildDependencies(config) { if (projectConfig.localPropertiesPath && From a2a2d6681f7354db7748149ef6dc6c6f8d6727eb Mon Sep 17 00:00:00 2001 From: laibo102 Date: Fri, 2 Sep 2022 14:47:40 +0800 Subject: [PATCH 28/33] Bugfix: fixed conflict Signed-off-by: laibo102 Change-Id: Iad018bae7e24c7432ea7dd71ab8871417fe9b6ca --- compiler/main.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/compiler/main.js b/compiler/main.js index 21f1ff1..d09b36a 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -403,19 +403,17 @@ function checkAppResourcePath(appResourcePath, config) { } function saveAppResourcePath(appResourcePath, appResourcePathSavePath) { - if (!projectConfig.xtsMode) { - let isSave = false; - if (fs.existsSync(appResourcePathSavePath)) { - const saveContent = fs.readFileSync(appResourcePathSavePath); - if (appResourcePath !== saveContent) { - isSave = true; - } - } else { + let isSave = false; + if (fs.existsSync(appResourcePathSavePath)) { + const saveContent = fs.readFileSync(appResourcePathSavePath); + if (appResourcePath !== saveContent) { isSave = true; } - if (isSave) { - fs.writeFileSync(appResourcePathSavePath, appResourcePath); - } + } else { + isSave = true; + } + if (isSave) { + fs.writeFileSync(appResourcePathSavePath, appResourcePath); } } From 3fda83cf92f0b99efbc20adf5b90922795464ddc Mon Sep 17 00:00:00 2001 From: laibo102 Date: Fri, 2 Sep 2022 14:50:00 +0800 Subject: [PATCH 29/33] Update: updated UT Signed-off-by: laibo102 Change-Id: I31967521ae07d04b5b80ddb7826eaec8f0b010e9 --- .../custom_component/custom_component.ts | 3 ++- .../render_component/foreach/foreach.ts | 3 ++- .../inner_component_transform/render_component/if/if.ts | 3 ++- .../render_component/item/GridItem.ts | 3 ++- .../render_component/item/ListItem.ts | 3 ++- .../render_component/lazyforeach/lazyforeach.ts | 3 ++- .../inner_component_transform/render_component/tab/tab.ts | 3 ++- .../inner_struct_state_management/@link/@link.ts | 3 ++- .../inner_struct_state_management/@objectLink/@objectLink.ts | 3 ++- .../inner_struct_state_management/@prop/@prop.ts | 3 ++- .../inner_struct_state_management/@state/@state.ts | 3 ++- 11 files changed, 22 insertions(+), 11 deletions(-) diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts b/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts index 5b2bd68..598d2a4 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/custom_component/custom_component.ts @@ -46,7 +46,8 @@ struct Banner { }` exports.expectResult = -`class MyComponent extends ViewPU { +`"use strict"; +class MyComponent extends ViewPU { constructor(parent, params, __localStorage) { super(parent, __localStorage); this.setInitiallyProvidedValue(params); diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts index 14722aa..09e3232 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/foreach/foreach.ts @@ -31,7 +31,8 @@ struct ParentView { } ` exports.expectResult = -`class ParentView extends ViewPU { +`"use strict"; +class ParentView extends ViewPU { constructor(parent, params, __localStorage) { super(parent, __localStorage); this.__arr = new ObservedPropertyObjectPU(['1', '2', '3'], this, "arr"); diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts index 5d011f9..6a79a06 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/if/if.ts @@ -37,7 +37,8 @@ struct IFView { } ` exports.expectResult = -`class IFView extends ViewPU { +`"use strict"; +class IFView extends ViewPU { constructor(parent, params, __localStorage) { super(parent, __localStorage); this.__toggle1 = new ObservedPropertySimplePU(false, this, "toggle1"); diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts index 8a7dfac..2988c7f 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/GridItem.ts @@ -27,7 +27,8 @@ struct ParentView { } ` exports.expectResult = -`class ParentView extends ViewPU { +`"use strict"; +class ParentView extends ViewPU { constructor(parent, params, __localStorage) { super(parent, __localStorage); this.setInitiallyProvidedValue(params); diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts index 0c572a2..ae8cbcd 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/item/ListItem.ts @@ -27,7 +27,8 @@ struct ParentView { } ` exports.expectResult = -`class ParentView extends ViewPU { +`"use strict"; +class ParentView extends ViewPU { constructor(parent, params, __localStorage) { super(parent, __localStorage); this.setInitiallyProvidedValue(params); diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts index 22bf64f..102dd68 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/lazyforeach/lazyforeach.ts @@ -103,7 +103,8 @@ build() { } ` exports.expectResult = -`class BasicDataSource { +`"use strict"; +class BasicDataSource { constructor() { this.listeners = []; } diff --git a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/tab/tab.ts b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/tab/tab.ts index e0a0599..f531e56 100644 --- a/compiler/test/utForPartialUpdate/inner_component_transform/render_component/tab/tab.ts +++ b/compiler/test/utForPartialUpdate/inner_component_transform/render_component/tab/tab.ts @@ -52,7 +52,8 @@ struct TabSimple { } ` exports.expectResult = -`class TabSimple extends ViewPU { +`"use strict"; +class TabSimple extends ViewPU { constructor(parent, params, __localStorage) { super(parent, __localStorage); this.controller = new TabsController(); diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts index ef54527..aaef837 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@link/@link.ts @@ -34,7 +34,8 @@ struct ParentComponent { } ` exports.expectResult = -`class LinkComponent extends ViewPU { +`"use strict"; +class LinkComponent extends ViewPU { constructor(parent, params, __localStorage) { super(parent, __localStorage); this.__counter = new SynchedPropertySimpleTwoWayPU(params.counter, this, "counter"); diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts index 3105ead..1b92a88 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@objectLink/@objectLink.ts @@ -52,7 +52,8 @@ struct Parent { } ` exports.expectResult = -`var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { +`"use strict"; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts index 88ffb83..a74de3a 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@prop/@prop.ts @@ -34,7 +34,8 @@ struct ParentComponent { } ` exports.expectResult = -`class PropComponent extends ViewPU { +`"use strict"; +class PropComponent extends ViewPU { constructor(parent, params, __localStorage) { super(parent, __localStorage); this.__counter = new SynchedPropertySimpleOneWayPU(params.counter, this, "counter"); diff --git a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts index 75cfd8e..c895d07 100644 --- a/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts +++ b/compiler/test/utForPartialUpdate/ui_state_management/inner_struct_state_management/@state/@state.ts @@ -26,7 +26,8 @@ struct StatePage { } ` exports.expectResult = -`class StatePage extends ViewPU { +`"use strict"; +class StatePage extends ViewPU { constructor(parent, params, __localStorage) { super(parent, __localStorage); this.__counter = new ObservedPropertySimplePU(0, this, "counter"); From e9b23defef15dacbf1baaa6b512db702ff415bce Mon Sep 17 00:00:00 2001 From: laibo102 Date: Fri, 2 Sep 2022 16:43:20 +0800 Subject: [PATCH 30/33] Update: delete useless notes Signed-off-by: laibo102 Change-Id: I706f86f3acd56f2b6403ea38da2b99712b90c66f --- compiler/src/process_component_constructor.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/src/process_component_constructor.ts b/compiler/src/process_component_constructor.ts index da552aa..48b8626 100644 --- a/compiler/src/process_component_constructor.ts +++ b/compiler/src/process_component_constructor.ts @@ -196,7 +196,6 @@ function createCallSuperStatement(localStorageNum: number): ts.Statement{ } } -// create updateWithValueParamsStatement function createUPdWithValStatement(): ts.Statement { return ts.factory.createExpressionStatement( ts.factory.createCallExpression( From 0a2f3feebcbabe67164a2ab9b193903302e4416e Mon Sep 17 00:00:00 2001 From: laibo102 Date: Fri, 2 Sep 2022 17:14:52 +0800 Subject: [PATCH 31/33] Update: updated adaptation rules Signed-off-by: laibo102 Change-Id: I08ae1c53ef77172351f2c1ed30457ccaa289fdff --- compiler/main.js | 11 +++++----- compiler/src/pre_define.ts | 1 + compiler/src/process_component_build.ts | 22 +++++++++---------- compiler/src/process_component_class.ts | 18 +++++++-------- compiler/src/process_component_constructor.ts | 10 ++++----- compiler/src/process_component_member.ts | 20 ++++++++--------- compiler/src/process_custom_component.ts | 8 +++---- compiler/src/process_ui_syntax.ts | 8 +++---- compiler/test/test.js | 4 ++-- 9 files changed, 52 insertions(+), 50 deletions(-) diff --git a/compiler/main.js b/compiler/main.js index d09b36a..e6021bc 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -24,6 +24,7 @@ const { configure, getLogger } = require('log4js'); +const { PARTIALUPDATESDKVERSIONS } = require('./lib/pre_define'); configure({ appenders: { 'ETS': {type: 'stderr', layout: {type: 'messagePassThrough'}}}, @@ -380,8 +381,8 @@ function loadModuleInfo(projectConfig, envArgs) { projectConfig.nodeModulesPath = buildJsonInfo.nodeModulesPath; } projectConfig.pandaMode = buildJsonInfo.pandaMode; - if (buildJsonInfo.compatibleSdkVersion) { - sdkVersion.compatibleSdkVersion = buildJsonInfo.compatibleSdkVersion; + if (PARTIALUPDATESDKVERSIONS.has(buildJsonInfo.compatibleSdkVersion)) { + partialUpdateConfig.partialUpdateMode = true; } } } @@ -433,8 +434,8 @@ const globalProgram = { watchProgram: null }; -const sdkVersion = { - compatibleSdkVersion: 9 +const partialUpdateConfig = { + partialUpdateMode: true }; exports.globalProgram = globalProgram; @@ -450,4 +451,4 @@ exports.loadModuleInfo = loadModuleInfo; exports.systemModules = systemModules; exports.checkAppResourcePath = checkAppResourcePath; exports.addSDKBuildDependencies = addSDKBuildDependencies; -exports.sdkVersion = sdkVersion; \ No newline at end of file +exports.partialUpdateConfig = partialUpdateConfig; \ No newline at end of file diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index e7aa6ee..8994d64 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -325,3 +325,4 @@ export const SYNCHED_PROPERTY_NESED_OBJECT_PU: string = 'SynchedPropertyNesedObj export const OBSERVED_PROPERTY_ABSTRACT_PU:string = 'ObservedPropertyAbstractPU'; export const COMPONENT_CONSTRUCTOR_LOCALSTORAGE_PU: string = '__localStorage'; export const COMPONENT_CONSTRUCTOR_LOCALSTORAGE_TYPE_PU: string = 'LocalStorage'; +export const PARTIALUPDATESDKVERSIONS: Set = new Set([9]); diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 5e4ffe6..2a3ae95 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -116,7 +116,7 @@ import { componentInfo, createFunction } from './utils'; -import { sdkVersion, projectConfig } from '../main'; +import { partialUpdateConfig, projectConfig } from '../main'; import { transformLog, contextGlobal } from './process_ui_syntax'; import { props } from './compile_info'; import { CUSTOM_COMPONENT } from '../lib/pre_define'; @@ -125,7 +125,7 @@ export function processComponentBuild(node: ts.MethodDeclaration, log: LogInfo[]): ts.MethodDeclaration { let newNode: ts.MethodDeclaration; let renderNode: ts.Identifier; - if (sdkVersion.compatibleSdkVersion === 8) { + if (!partialUpdateConfig.partialUpdateMode) { renderNode = ts.factory.createIdentifier(COMPONENT_RENDER_FUNCTION); } else { renderNode = ts.factory.createIdentifier(COMPONENT_INITIAl_RENDER_FUNCTION); @@ -148,7 +148,7 @@ export function processComponentBlock(node: ts.Block, isLazy: boolean, log: LogI const newStatements: ts.Statement[] = []; processComponentChild(node, newStatements, log, {isAcceleratePreview: false, line: 0, column: 0, fileName: ''}, isInnerBuilder, parent); - if (isLazy && sdkVersion.compatibleSdkVersion === 8) { + if (isLazy && !partialUpdateConfig.partialUpdateMode) { newStatements.unshift(createRenderingInProgress(true)); } if (isTransition) { @@ -159,7 +159,7 @@ export function processComponentBlock(node: ts.Block, isLazy: boolean, log: LogI createFunction(ts.factory.createIdentifier(COMPONENT_TRANSITION_NAME), ts.factory.createIdentifier(COMPONENT_POP_FUNCTION), null))); } - if (isLazy && sdkVersion.compatibleSdkVersion === 8) { + if (isLazy && !partialUpdateConfig.partialUpdateMode) { newStatements.push(createRenderingInProgress(false)); } return ts.factory.updateBlock(node, newStatements); @@ -283,7 +283,7 @@ export function processComponentChild(node: ts.Block | ts.SourceFile, newStateme break; case ComponentType.forEachComponent: parent = undefined; - if (sdkVersion.compatibleSdkVersion === 8) { + if (!partialUpdateConfig.partialUpdateMode) { processForEachComponent(item, newStatements, log, isInnerBuilder); } else { processForEachComponentNew(item, newStatements, log); @@ -414,9 +414,9 @@ function processInnerComponent(node: ts.ExpressionStatement, innerCompStatements newStatements.push(res.newNode); const nameResult: NameResult = { name: null }; validateEtsComponentNode(node.expression as ts.EtsComponentExpression, nameResult); - if (sdkVersion.compatibleSdkVersion === 9 && ItemComponents.includes(nameResult.name)) { + if (partialUpdateConfig.partialUpdateMode && ItemComponents.includes(nameResult.name)) { processItemComponent(node, nameResult, innerCompStatements, log); - } else if (sdkVersion.compatibleSdkVersion === 9 && TABCONTENT_COMPONENT.includes(nameResult.name)) { + } else if (partialUpdateConfig.partialUpdateMode && TABCONTENT_COMPONENT.includes(nameResult.name)) { processTabContent(node, innerCompStatements, log); } else { processNormalComponent(node, nameResult, innerCompStatements, log, parent); @@ -492,7 +492,7 @@ function processInnerCompStatements( newStatements: ts.Statement[], node: ts.Statement ): void { - if (sdkVersion.compatibleSdkVersion === 8) { + if (!partialUpdateConfig.partialUpdateMode) { innerCompStatements.push(...newStatements); } else { innerCompStatements.push(createComponentCreationStatement(node, newStatements)); @@ -1086,7 +1086,7 @@ function processForEachBlock(node: ts.CallExpression, log: LogInfo[], const blockNode: ts.Block = ts.factory.createBlock([statement], true); // @ts-ignore statement.parent = blockNode; - if (sdkVersion.compatibleSdkVersion === 8) { + if (!partialUpdateConfig.partialUpdateMode) { return ts.factory.updateArrowFunction( arrowNode, arrowNode.modifiers, arrowNode.typeParameters, arrowNode.parameters, arrowNode.type, arrowNode.equalsGreaterThanToken, processComponentBlock(blockNode, isLazy, log)); @@ -1094,7 +1094,7 @@ function processForEachBlock(node: ts.CallExpression, log: LogInfo[], return processComponentBlock(blockNode, isLazy, log).statements; } } else { - if (sdkVersion.compatibleSdkVersion === 8) { + if (!partialUpdateConfig.partialUpdateMode) { return ts.factory.updateArrowFunction( arrowNode, arrowNode.modifiers, arrowNode.typeParameters, arrowNode.parameters, arrowNode.type, arrowNode.equalsGreaterThanToken, @@ -1123,7 +1123,7 @@ function processIfStatement(node: ts.IfStatement, newStatements: ts.Statement[], const ifCreate: ts.ExpressionStatement = createIfCreate(); const newIfNode: ts.IfStatement = processInnerIfStatement(node, 0, log, isInnerBuilder); const ifPop: ts.ExpressionStatement = createIfPop(); - if (sdkVersion.compatibleSdkVersion === 8) { + if (!partialUpdateConfig.partialUpdateMode) { newStatements.push(ifCreate, newIfNode, ifPop); } else { newStatements.push(createComponentCreationStatement(node, [ifCreate, newIfNode]), ifPop); diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index 359bc04..eef49ba 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -112,7 +112,7 @@ import { LogInfo, hasDecorator } from './utils'; -import { sdkVersion } from '../main'; +import { partialUpdateConfig } from '../main'; export function processComponentClass(node: ts.StructDeclaration, context: ts.TransformationContext, log: LogInfo[], program: ts.Program): ts.ClassDeclaration { @@ -228,7 +228,7 @@ function processPropertyUnchanged( purgeVariableDepStatements: ts.Statement[], rerenderStatements: ts.Statement[] ): void { - if (sdkVersion.compatibleSdkVersion === 9) { + if (partialUpdateConfig.partialUpdateMode) { if(result.getPurgeVariableDepStatement()) { purgeVariableDepStatements.push(result.getPurgeVariableDepStatement()); } @@ -245,7 +245,7 @@ function addIntoNewMembers( purgeVariableDepStatements: ts.Statement[], rerenderStatements: ts.Statement[] ): void { - if (sdkVersion.compatibleSdkVersion === 9) { + if (partialUpdateConfig.partialUpdateMode) { newMembers.unshift( addInitialParamsFunc(updateParamsStatements, parentComponentName), addPurgeVariableDepFunc(purgeVariableDepStatements) @@ -270,7 +270,7 @@ function addPropertyMember(item: ts.ClassElement, newMembers: ts.ClassElement[], let newType: ts.TypeNode; decoratorName = propertyItem.decorators[i].getText().replace(/\(.*\)$/, '').trim(); let isLocalStorage: boolean = false; - if (sdkVersion.compatibleSdkVersion === 8) { + if (!partialUpdateConfig.partialUpdateMode) { newType = createTypeReference(decoratorName, type, log, program); } else { newType = createTypeReferencePU(decoratorName, type, log, program); @@ -522,7 +522,7 @@ export function createReference(node: ts.PropertyAssignment, log: LogInfo[]): ts pos: initExpression.getStart() }); } - } else if (sdkVersion.compatibleSdkVersion === 9 && isMatchInitExpression(initExpression) && + } else if (partialUpdateConfig.partialUpdateMode && isMatchInitExpression(initExpression) && propParentComponent.includes(propertyName.escapedText.toString())) { initText = initExpression.name.escapedText.toString(); } @@ -590,7 +590,7 @@ function addDeleteParamsFunc(statements: ts.PropertyDeclaration[]): ts.MethodDec statements.forEach((statement: ts.PropertyDeclaration) => { const name: ts.Identifier = statement.name as ts.Identifier; let paramsStatement: ts.ExpressionStatement; - if (sdkVersion.compatibleSdkVersion === 9 && !statement.decorators) { + if (partialUpdateConfig.partialUpdateMode && !statement.decorators) { paramsStatement = createParamsStatement(name); } else { paramsStatement = createParamsWithUnderlineStatement(name); @@ -606,11 +606,11 @@ function addDeleteParamsFunc(statements: ts.PropertyDeclaration[]): ts.MethodDec ts.factory.createIdentifier(CREATE_CONSTRUCTOR_DELETE_FUNCTION)), undefined, [ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression( ts.factory.createThis(), ts.factory.createIdentifier( - sdkVersion.compatibleSdkVersion === 8 ? + !partialUpdateConfig.partialUpdateMode ? ABOUT_TO_BE_DELETE_FUNCTION_ID : ABOUT_TO_BE_DELETE_FUNCTION_ID__)), undefined, [])])); deleteStatements.push(defaultStatement); - if (sdkVersion.compatibleSdkVersion === 9) { + if (partialUpdateConfig.partialUpdateMode) { const aboutToBeDeletedInternalStatement: ts.ExpressionStatement = createDeletedInternalStatement(); deleteStatements.push(aboutToBeDeletedInternalStatement); } @@ -691,7 +691,7 @@ function validateHasController(componentName: ts.Identifier, checkController: Co } function createHeritageClause(): ts.HeritageClause { - if (sdkVersion.compatibleSdkVersion === 9) { + if (partialUpdateConfig.partialUpdateMode) { return ts.factory.createHeritageClause( ts.SyntaxKind.ExtendsKeyword, [ts.factory.createExpressionWithTypeArguments(ts.factory.createIdentifier(BASE_COMPONENT_NAME_PU), [])] diff --git a/compiler/src/process_component_constructor.ts b/compiler/src/process_component_constructor.ts index 48b8626..27bcb78 100644 --- a/compiler/src/process_component_constructor.ts +++ b/compiler/src/process_component_constructor.ts @@ -35,7 +35,7 @@ import { localStoragePropCollection } from './validate_ui_syntax'; -import { sdkVersion } from '../main'; +import { partialUpdateConfig } from '../main'; export function getInitConstructor(members: ts.NodeArray, parentComponentName: ts.Identifier ): ts.ConstructorDeclaration { @@ -89,7 +89,7 @@ function initConstructorParams(node: ts.ConstructorDeclaration, parentComponentN } const localStorageNum: number = localStorageLinkCollection.get(parentComponentName.getText()).size + localStoragePropCollection.get(parentComponentName.getText()).size; - const paramNames: Set = sdkVersion.compatibleSdkVersion === 8 ? new Set([ + const paramNames: Set = !partialUpdateConfig.partialUpdateMode ? new Set([ COMPONENT_CONSTRUCTOR_ID, COMPONENT_CONSTRUCTOR_PARENT, COMPONENT_CONSTRUCTOR_PARAMS, @@ -131,7 +131,7 @@ function addParamsType(ctorNode: ts.ConstructorDeclaration, modifyPara: ts.Param parameter = ts.factory.createParameterDeclaration(item.decorators, item.modifiers, item.dotDotDotToken, item.name, item.questionToken, ts.factory.createTypeReferenceNode(ts.factory.createIdentifier( - sdkVersion.compatibleSdkVersion === 8 ? BASE_COMPONENT_NAME : BASE_COMPONENT_NAME_PU), undefined), + !partialUpdateConfig.partialUpdateMode ? BASE_COMPONENT_NAME : BASE_COMPONENT_NAME_PU), undefined), item.initializer); break; case COMPONENT_CONSTRUCTOR_PARAMS: @@ -180,7 +180,7 @@ export function addConstructor(ctorNode: any, watchMap: Map, } function createCallSuperStatement(localStorageNum: number): ts.Statement{ - if (sdkVersion.compatibleSdkVersion === 8) { + if (!partialUpdateConfig.partialUpdateMode) { return ts.factory.createExpressionStatement(ts.factory.createCallExpression( ts.factory.createSuper(), undefined, localStorageNum ? [ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_ID), @@ -202,7 +202,7 @@ function createUPdWithValStatement(): ts.Statement { ts.factory.createPropertyAccessExpression( ts.factory.createThis(), ts.factory.createIdentifier( - sdkVersion.compatibleSdkVersion === 8 ? + !partialUpdateConfig.partialUpdateMode ? COMPONENT_CONSTRUCTOR_UPDATE_PARAMS : COMPONENT_CONSTRUCTOR_INITIAL_PARAMS ) ), diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index 1a72ed8..7923364 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -93,7 +93,7 @@ import { import { transformLog } from './process_ui_syntax'; import { globalProgram, projectConfig } from '../main'; -import { sdkVersion } from '../main'; +import { partialUpdateConfig } from '../main'; export type ControllerType = { hasController: boolean @@ -254,7 +254,7 @@ export function processMemberVariableDecorators(parentName: ts.Identifier, createVariableInitStatement(item, COMPONENT_NON_DECORATOR, log, program, context, hasPreview, interfaceNode)])); updateResult.setControllerSet(createControllerSet(item, parentName, name, checkController)); - if (sdkVersion.compatibleSdkVersion === 9) { + if (partialUpdateConfig.partialUpdateMode) { updateResult.setDeleteParams(true); } } else if (!item.type) { @@ -361,7 +361,7 @@ function processStateDecorators(node: ts.PropertyDeclaration, decorator: string, if (setUpdateParamsDecorators.has(decorator)) { updateResult.setUpdateParams(createUpdateParams(name, decorator)); } - if (sdkVersion.compatibleSdkVersion === 9 && BASICDECORATORS.has(decorator)) { + if (partialUpdateConfig.partialUpdateMode && BASICDECORATORS.has(decorator)) { const variableWithUnderLink: string = '__' + name.escapedText.toString(); updateResult.setDecoratorName(decorator); updateResult.setPurgeVariableDepStatement(createPurgeVariableDepStatement(variableWithUnderLink)); @@ -450,17 +450,17 @@ function createVariableInitStatement(node: ts.PropertyDeclaration, decorator: st break; case COMPONENT_STATE_DECORATOR: case COMPONENT_PROVIDE_DECORATOR: - updateState = sdkVersion.compatibleSdkVersion === 8 ? + updateState = !partialUpdateConfig.partialUpdateMode ? updateObservedProperty(node, name, type, program) : updateObservedPropertyPU(node, name, type, program); break; case COMPONENT_LINK_DECORATOR: wrongDecoratorInPreview(node, COMPONENT_LINK_DECORATOR, hasPreview, log); - updateState = sdkVersion.compatibleSdkVersion === 8 ? + updateState = !partialUpdateConfig.partialUpdateMode ? updateSynchedPropertyTwoWay(name, type, program) : updateSynchedPropertyTwoWayPU(name, type, program); break; case COMPONENT_PROP_DECORATOR: wrongDecoratorInPreview(node, COMPONENT_PROP_DECORATOR, hasPreview, log); - updateState = sdkVersion.compatibleSdkVersion === 8 + updateState = !partialUpdateConfig.partialUpdateMode ? updateSynchedPropertyOneWay(name, type, decorator, log, program) : updateSynchedPropertyOneWayPU(name, type, decorator, log, program); break; @@ -471,7 +471,7 @@ function createVariableInitStatement(node: ts.PropertyDeclaration, decorator: st updateState = updateStoragePropAndLinkProperty(node, name, setFuncName, log); break; case COMPONENT_OBJECT_LINK_DECORATOR: - updateState = sdkVersion.compatibleSdkVersion === 8 + updateState = !partialUpdateConfig.partialUpdateMode ? updateSynchedPropertyNesedObject(name, type, decorator, log) : updateSynchedPropertyNesedObjectPU(name, type, decorator, log); break; @@ -510,7 +510,7 @@ function createUpdateParams(name: ts.Identifier, decorator: string): ts.Statemen updateParamsNode = createUpdateParamsWithIf(name); break; case COMPONENT_PROP_DECORATOR: - if (sdkVersion.compatibleSdkVersion === 8) { + if (!partialUpdateConfig.partialUpdateMode) { updateParamsNode = createUpdateParamsWithoutIf(name); } break; @@ -662,7 +662,7 @@ function createCustomComponentBuilderArrowFunction(parent: ts.PropertyDeclaratio } export function createViewCreate(node: ts.NewExpression | ts.Identifier): ts.CallExpression { - if (sdkVersion.compatibleSdkVersion === 9) { + if (partialUpdateConfig.partialUpdateMode) { return createFunction(ts.factory.createIdentifier(BASE_COMPONENT_NAME_PU), ts.factory.createIdentifier(COMPONENT_CREATE_FUNCTION), ts.factory.createNodeArray([node])); } @@ -691,7 +691,7 @@ function addCustomComponentId(node: ts.NewExpression, componentName: string, if (!argumentsArray) { argumentsArray = [ts.factory.createObjectLiteralExpression([], true)]; } - if (sdkVersion.compatibleSdkVersion === 8) { + if (!partialUpdateConfig.partialUpdateMode) { ++componentInfo.id; argumentsArray.unshift(isInnerBuilder ? ts.factory.createBinaryExpression( ts.factory.createStringLiteral(path.basename(transformLog.sourceFile.fileName, EXTNAME_ETS) + '_'), diff --git a/compiler/src/process_custom_component.ts b/compiler/src/process_custom_component.ts index a7d9645..6aff256 100644 --- a/compiler/src/process_custom_component.ts +++ b/compiler/src/process_custom_component.ts @@ -71,7 +71,7 @@ import { createFunction } from './utils'; import { bindComponentAttr } from './process_component_build'; -import { sdkVersion } from '../main'; +import { partialUpdateConfig } from '../main'; const localArray: string[] = [...observedPropertyDecorators, COMPONENT_NON_DECORATOR, COMPONENT_PROP_DECORATOR, COMPONENT_OBJECT_LINK_DECORATOR]; @@ -163,7 +163,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[], isInnerBuilder: boolean = false): void { - if (sdkVersion.compatibleSdkVersion === 8) { + if (!partialUpdateConfig.partialUpdateMode) { const id: string = componentInfo.id.toString(); newStatements.push(createFindChildById(id, name, isInnerBuilder), createCustomComponentIfStatement(id, ts.factory.updateExpressionStatement(node, createViewCreate(newNode)), @@ -402,9 +402,9 @@ function isCorrectInitFormParent(parent: string, child: string): boolean { } break; case COMPONENT_OBJECT_LINK_DECORATOR: - if (sdkVersion.compatibleSdkVersion === 8 && parent === COMPONENT_STATE_DECORATOR) { + if (!partialUpdateConfig.partialUpdateMode && parent === COMPONENT_STATE_DECORATOR) { return true; - } else if (sdkVersion.compatibleSdkVersion === 9 && STATE_OBJECTLINK_DECORATORS.includes(parent)) { + } else if (partialUpdateConfig.partialUpdateMode && STATE_OBJECTLINK_DECORATORS.includes(parent)) { return true; } break; diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index 011ef02..7c170d3 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -89,7 +89,7 @@ import { import { resources, projectConfig, - sdkVersion + partialUpdateConfig } from '../main'; import { createCustomComponentNewExpression, createViewCreate } from './process_component_member'; @@ -120,7 +120,7 @@ export function processUISyntax(program: ts.Program, ut = false): Function { }); GLOBAL_STYLE_FUNCTION.clear(); const statements: ts.Statement[] = Array.from(node.statements); - if (sdkVersion.compatibleSdkVersion === 8) { + if (!partialUpdateConfig.partialUpdateMode) { generateId(statements, node); } INTERFACE_NODE_SET.forEach(item => { @@ -588,7 +588,7 @@ export function isExtendFunction(node: ts.FunctionDeclaration): string { function createEntryNode(node: ts.SourceFile, context: ts.TransformationContext): ts.SourceFile { if (componentCollection.previewComponent.size === 0 || !projectConfig.isPreview) { if (componentCollection.entryComponent) { - if (sdkVersion.compatibleSdkVersion === 8) { + if (!partialUpdateConfig.partialUpdateMode) { const entryNode: ts.ExpressionStatement = createEntryFunction(componentCollection.entryComponent, context) as ts.ExpressionStatement; return context.factory.updateSourceFile(node, [...node.statements, entryNode]); @@ -632,7 +632,7 @@ function createEntryFunction(name: string, context: ts.TransformationContext) if (localStorageName) { newArray.push(context.factory.createIdentifier(localStorageName)); } - if (sdkVersion.compatibleSdkVersion === 8) { + if (!partialUpdateConfig.partialUpdateMode) { const newExpressionStatement: ts.ExpressionStatement = context.factory.createExpressionStatement(context.factory.createCallExpression( context.factory.createIdentifier(PAGE_ENTRY_FUNCTION_NAME), undefined, diff --git a/compiler/test/test.js b/compiler/test/test.js index b010fa4..1e986e5 100644 --- a/compiler/test/test.js +++ b/compiler/test/test.js @@ -36,7 +36,7 @@ const { SYSTEM_PLUGIN } = require('../lib/pre_define'); const { - sdkVersion + partialUpdateConfig } = require('../main'); function expectActual(name, filePath) { @@ -64,7 +64,7 @@ function expectActual(name, filePath) { mocha.describe('compiler', () => { let utPath = path.resolve(__dirname, './ut'); if (process.argv.includes('--partialUpdate')) { - sdkVersion.compatibleSdkVersion = 9; + partialUpdateConfig.partialUpdateMode = true; utPath = path.resolve(__dirname, './utForPartialUpdate'); } const utFiles = []; From 57285b038733f542a2ab21bf8ec25c8ddc97965a Mon Sep 17 00:00:00 2001 From: laibo102 Date: Mon, 5 Sep 2022 12:23:19 +0800 Subject: [PATCH 32/33] Bugfix: fixed listItem component transform Signed-off-by: laibo102 Change-Id: Ie055b3c53bd82836cdc40793116c19298579fa3d --- 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 2a3ae95..d6901d6 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -2007,7 +2007,7 @@ function checkButtonParamHasLabel(node: ts.EtsComponentExpression, log: LogInfo[ function isLazyForEachChild(node: ts.ExpressionStatement): boolean { let temp: any = node.parent; - while(!ts.isEtsComponentExpression(temp) && !ts.isCallExpression(temp)) { + while(temp && !ts.isEtsComponentExpression(temp) && !ts.isCallExpression(temp)) { temp = temp.parent; } if (temp && temp.expression && (temp.expression as ts.Identifier).escapedText.toString() === COMPONENT_LAZYFOREACH) { From 8b685d20d48342525772bb6dcc879a8697be84d4 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Mon, 5 Sep 2022 15:34:18 +0800 Subject: [PATCH 33/33] Update: updated default config close partial update Signed-off-by: laibo102 Change-Id: I055cb53a02a68854b0949bff0b41f24ef077b199 --- compiler/main.js | 5 ++--- compiler/src/pre_define.ts | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/compiler/main.js b/compiler/main.js index e6021bc..c6aab9d 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -24,7 +24,6 @@ const { configure, getLogger } = require('log4js'); -const { PARTIALUPDATESDKVERSIONS } = require('./lib/pre_define'); configure({ appenders: { 'ETS': {type: 'stderr', layout: {type: 'messagePassThrough'}}}, @@ -381,7 +380,7 @@ function loadModuleInfo(projectConfig, envArgs) { projectConfig.nodeModulesPath = buildJsonInfo.nodeModulesPath; } projectConfig.pandaMode = buildJsonInfo.pandaMode; - if (PARTIALUPDATESDKVERSIONS.has(buildJsonInfo.compatibleSdkVersion)) { + if (buildJsonInfo.compatibleSdkVersion >= 9) { partialUpdateConfig.partialUpdateMode = true; } } @@ -435,7 +434,7 @@ const globalProgram = { }; const partialUpdateConfig = { - partialUpdateMode: true + partialUpdateMode: false }; exports.globalProgram = globalProgram; diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 8994d64..e7aa6ee 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -325,4 +325,3 @@ export const SYNCHED_PROPERTY_NESED_OBJECT_PU: string = 'SynchedPropertyNesedObj export const OBSERVED_PROPERTY_ABSTRACT_PU:string = 'ObservedPropertyAbstractPU'; export const COMPONENT_CONSTRUCTOR_LOCALSTORAGE_PU: string = '__localStorage'; export const COMPONENT_CONSTRUCTOR_LOCALSTORAGE_TYPE_PU: string = 'LocalStorage'; -export const PARTIALUPDATESDKVERSIONS: Set = new Set([9]);