From 4c2fb42f648e93ed047bcd823e3561b66fb2dbc2 Mon Sep 17 00:00:00 2001 From: yangbo <1442420648@qq.com> Date: Sun, 13 Mar 2022 16:51:12 +0800 Subject: [PATCH 1/3] yangbo198@huawei.com Signed-off-by: yangbo <1442420648@qq.com> Change-Id: Icb7c53ca27b6b17a79d9eea3254b7eef296bd353 --- compiler/main.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/main.js b/compiler/main.js index 8b7fbca3b..96d251baf 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -90,9 +90,10 @@ function loadEntryObj(projectConfig) { if (manifest.pages) { const pages = manifest.pages; pages.forEach((element) => { - const fileName = projectConfig.projectPath + path.sep + element + '.ets'; + const sourcePath = element.replace(/^\.\/ets\//, ''); + const fileName = projectConfig.projectPath + path.sep + sourcePath + '.ets'; if (fs.existsSync(fileName)) { - projectConfig.entryObj['./' + element] = fileName + '?entry'; + projectConfig.entryObj['./' + sourcePath] = fileName + '?entry'; } else { throw Error(`\u001b[31m ERROR: page '${fileName}' does not exist. \u001b[39m`).message; } -- Gitee From a9ad1cc3cb888a598e948b2d96897ff48fedda16 Mon Sep 17 00:00:00 2001 From: yangbo <1442420648@qq.com> Date: Mon, 14 Mar 2022 07:29:43 +0800 Subject: [PATCH 2/3] yangbo198@huawei.com Signed-off-by: yangbo <1442420648@qq.com> Change-Id: I2877c7dbefa8acb6a807e08aade915cf65761f0b --- compiler/src/process_component_member.ts | 66 +------------------ compiler/src/process_ui_syntax.ts | 80 +++++++++++++++++++++++- 2 files changed, 80 insertions(+), 66 deletions(-) diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index 77ddab7d4..fa3906cf6 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -48,8 +48,6 @@ import { SET_CONTROLLER_METHOD, SET_CONTROLLER_CTR, SET_CONTROLLER_CTR_TYPE, - JS_DIALOG, - CUSTOM_DIALOG_CONTROLLER_BUILDER, BASE_COMPONENT_NAME, COMPONENT_CREATE_FUNCTION, COMPONENT_BUILDERPARAM_DECORATOR @@ -464,7 +462,7 @@ function createUpdateParamsWithSet(name: ts.Identifier): ts.ExpressionStatement function updateNormalProperty(node: ts.PropertyDeclaration, name: ts.Identifier, log: LogInfo[], context: ts.TransformationContext): ts.ExpressionStatement { const init: ts.Expression = - ts.visitNode(processCustomDialogController(node, log), visitDialogController); + ts.visitNode(node.initializer, visitDialogController); function visitDialogController(node: ts.Node): ts.Node { if (isProperty(node)) { node = createReference(node as ts.PropertyAssignment); @@ -477,59 +475,6 @@ function updateNormalProperty(node: ts.PropertyDeclaration, name: ts.Identifier, ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_UNDEFINED))); } -function processCustomDialogController(node: ts.PropertyDeclaration, - log: LogInfo[]): ts.Expression { - if (node.initializer && ts.isNewExpression(node.initializer) && - ts.isIdentifier(node.initializer.expression) && - node.initializer.expression.getText() === SET_CONTROLLER_CTR_TYPE) { - return createCustomDialogController(node, node.initializer, log); - } - return node.initializer; -} - -function createCustomDialogController(parent: ts.PropertyDeclaration, node: ts.NewExpression, - log: LogInfo[]): ts.NewExpression { - if (node.arguments && node.arguments.length === 1 && - ts.isObjectLiteralExpression(node.arguments[0]) && node.arguments[0].properties) { - const newproperties: ts.ObjectLiteralElementLike[] = node.arguments[0].properties.map((item) => { - if (isCustomDialogControllerPropertyAssignment(item, log)) { - item = processCustomDialogControllerPropertyAssignment(parent, item as ts.PropertyAssignment); - } - return item; - }); - return ts.factory.createNewExpression(node.expression, node.typeArguments, - [ts.factory.createObjectLiteralExpression(newproperties, true), ts.factory.createThis()]); - } -} - -function isCustomDialogControllerPropertyAssignment(node: ts.ObjectLiteralElementLike, - log: LogInfo[]): boolean { - if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && - node.name.getText() === CUSTOM_DIALOG_CONTROLLER_BUILDER) { - if (ts.isCallExpression(node.initializer) && ts.isIdentifier(node.initializer.expression) && - componentCollection.customDialogs.has(node.initializer.expression.getText())) { - return true; - } else { - validateCustomDialogControllerBuilderInit(node, log); - } - } -} - -function processCustomDialogControllerPropertyAssignment(parent: ts.PropertyDeclaration, - node: ts.PropertyAssignment): ts.PropertyAssignment { - if (ts.isCallExpression(node.initializer)) { - return ts.factory.updatePropertyAssignment(node, node.name, - processCustomDialogControllerBuilder(parent, node.initializer)); - } -} - -function processCustomDialogControllerBuilder(parent: ts.PropertyDeclaration, - node: ts.CallExpression): ts.ArrowFunction { - const newExp: ts.Expression = createCustomComponentNewExpression(node); - const jsDialog: ts.Identifier = ts.factory.createIdentifier(JS_DIALOG); - return createCustomComponentBuilderArrowFunction(parent, jsDialog, newExp); -} - function updateObservedProperty(item: ts.PropertyDeclaration, name: ts.Identifier, type: ts.TypeNode, program: ts.Program): ts.ExpressionStatement { return ts.factory.createExpressionStatement(ts.factory.createBinaryExpression( @@ -933,12 +878,3 @@ function validateWatchParam(type: LogType, pos: number, log: LogInfo[]): void { pos: pos }); } - -function validateCustomDialogControllerBuilderInit(node: ts.ObjectLiteralElementLike, - log: LogInfo[]): void { - log.push({ - type: LogType.ERROR, - message: 'The builder should be initialized with a @CustomDialog Component.', - pos: node.getStart() - }); -} diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index 7a4825d35..e09cef543 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -36,7 +36,11 @@ import { ATTRIBUTE_ANIMATETO, GLOBAL_CONTEXT, CHECK_COMPONENT_EXTEND_DECORATOR, - INSTANCE + INSTANCE, + SET_CONTROLLER_CTR_TYPE, + SET_CONTROLLER_METHOD, + JS_DIALOG, + CUSTOM_DIALOG_CONTROLLER_BUILDER } from './pre_define'; import { componentInfo, @@ -58,6 +62,7 @@ import { INTERFACE_NODE_SET } from './component_map'; import { resources } from '../main'; +import { createCustomComponentNewExpression, createViewCreate } from './process_component_member'; export const transformLog: FileLog = new FileLog(); export let contextGlobal: ts.TransformationContext; @@ -128,6 +133,8 @@ export function processUISyntax(program: ts.Program, ut = false): Function { node = processWorker(node as ts.NewExpression); } else if (isAnimateTo(node)) { node = processAnimateTo(node as ts.CallExpression); + } else if (isCustomDialogController(node)) { + node = createCustomDialogController(node.parent, node, transformLog.errors); } return ts.visitEachChild(node, processAllNodes, context); } @@ -140,6 +147,77 @@ export function processUISyntax(program: ts.Program, ut = false): Function { }; } +function isCustomDialogController(node: ts.PropertyDeclaration) { + return node.parent && ts.isNewExpression(node) && ts.isIdentifier(node.expression) && + node.expression.getText() === SET_CONTROLLER_CTR_TYPE; +} + +function createCustomDialogController(parent: ts.PropertyDeclaration, node: ts.NewExpression, + log: LogInfo[]): ts.NewExpression { + if (node.arguments && node.arguments.length === 1 && + ts.isObjectLiteralExpression(node.arguments[0]) && node.arguments[0].properties) { + const newproperties: ts.ObjectLiteralElementLike[] = node.arguments[0].properties.map((item) => { + if (isCustomDialogControllerPropertyAssignment(item, log)) { + item = processCustomDialogControllerPropertyAssignment(parent, item as ts.PropertyAssignment); + } + return item; + }); + return ts.factory.createNewExpression(node.expression, node.typeArguments, + [ts.factory.createObjectLiteralExpression(newproperties, true), ts.factory.createThis()]); + } +} + +function isCustomDialogControllerPropertyAssignment(node: ts.ObjectLiteralElementLike, + log: LogInfo[]): boolean { + if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && + node.name.getText() === CUSTOM_DIALOG_CONTROLLER_BUILDER) { + if (ts.isCallExpression(node.initializer) && ts.isIdentifier(node.initializer.expression) && + componentCollection.customDialogs.has(node.initializer.expression.getText())) { + return true; + } else { + validateCustomDialogControllerBuilderInit(node, log); + } + } +} + +function validateCustomDialogControllerBuilderInit(node: ts.ObjectLiteralElementLike, + log: LogInfo[]): void { + log.push({ + type: LogType.ERROR, + message: 'The builder should be initialized with a @CustomDialog Component.', + pos: node.getStart() + }); +} + +function processCustomDialogControllerPropertyAssignment(parent: ts.PropertyDeclaration, + node: ts.PropertyAssignment): ts.PropertyAssignment { + if (ts.isCallExpression(node.initializer)) { + return ts.factory.updatePropertyAssignment(node, node.name, + processCustomDialogControllerBuilder(parent, node.initializer)); + } +} + +function processCustomDialogControllerBuilder(parent: ts.PropertyDeclaration, + node: ts.CallExpression): ts.ArrowFunction { + const newExp: ts.Expression = createCustomComponentNewExpression(node); + const jsDialog: ts.Identifier = ts.factory.createIdentifier(JS_DIALOG); + return createCustomComponentBuilderArrowFunction(parent, jsDialog, newExp); +} + +function createCustomComponentBuilderArrowFunction(parent: ts.PropertyDeclaration, + jsDialog: ts.Identifier, newExp: ts.Expression): ts.ArrowFunction { + return ts.factory.createArrowFunction(undefined, undefined, [], undefined, + ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), ts.factory.createBlock([ + ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList( + [ts.factory.createVariableDeclaration(jsDialog, undefined, undefined, newExp)], + ts.NodeFlags.Let)), ts.factory.createExpressionStatement(ts.factory.createCallExpression( + ts.factory.createPropertyAccessExpression(jsDialog, + ts.factory.createIdentifier(SET_CONTROLLER_METHOD)), undefined, + [ts.factory.createPropertyAccessExpression(ts.factory.createThis(), + parent.name as ts.Identifier)])), ts.factory.createExpressionStatement( + createViewCreate(jsDialog))], true)); +} + function isResource(node: ts.Node): boolean { return ts.isCallExpression(node) && ts.isIdentifier(node.expression) && (node.expression.escapedText.toString() === RESOURCE || -- Gitee From 362c6508e4fc830056b1c68dba48c7298f88d864 Mon Sep 17 00:00:00 2001 From: yangbo <1442420648@qq.com> Date: Mon, 14 Mar 2022 08:49:13 +0800 Subject: [PATCH 3/3] yangbo198@huawei.com Signed-off-by: yangbo <1442420648@qq.com> Change-Id: I237621850afca397784506b9bf20c9ce50e8e5c6 --- compiler/src/process_component_member.ts | 66 ++++++++++++++++++- compiler/src/process_ui_syntax.ts | 80 +----------------------- 2 files changed, 66 insertions(+), 80 deletions(-) diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index fa3906cf6..77ddab7d4 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -48,6 +48,8 @@ import { SET_CONTROLLER_METHOD, SET_CONTROLLER_CTR, SET_CONTROLLER_CTR_TYPE, + JS_DIALOG, + CUSTOM_DIALOG_CONTROLLER_BUILDER, BASE_COMPONENT_NAME, COMPONENT_CREATE_FUNCTION, COMPONENT_BUILDERPARAM_DECORATOR @@ -462,7 +464,7 @@ function createUpdateParamsWithSet(name: ts.Identifier): ts.ExpressionStatement function updateNormalProperty(node: ts.PropertyDeclaration, name: ts.Identifier, log: LogInfo[], context: ts.TransformationContext): ts.ExpressionStatement { const init: ts.Expression = - ts.visitNode(node.initializer, visitDialogController); + ts.visitNode(processCustomDialogController(node, log), visitDialogController); function visitDialogController(node: ts.Node): ts.Node { if (isProperty(node)) { node = createReference(node as ts.PropertyAssignment); @@ -475,6 +477,59 @@ function updateNormalProperty(node: ts.PropertyDeclaration, name: ts.Identifier, ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_UNDEFINED))); } +function processCustomDialogController(node: ts.PropertyDeclaration, + log: LogInfo[]): ts.Expression { + if (node.initializer && ts.isNewExpression(node.initializer) && + ts.isIdentifier(node.initializer.expression) && + node.initializer.expression.getText() === SET_CONTROLLER_CTR_TYPE) { + return createCustomDialogController(node, node.initializer, log); + } + return node.initializer; +} + +function createCustomDialogController(parent: ts.PropertyDeclaration, node: ts.NewExpression, + log: LogInfo[]): ts.NewExpression { + if (node.arguments && node.arguments.length === 1 && + ts.isObjectLiteralExpression(node.arguments[0]) && node.arguments[0].properties) { + const newproperties: ts.ObjectLiteralElementLike[] = node.arguments[0].properties.map((item) => { + if (isCustomDialogControllerPropertyAssignment(item, log)) { + item = processCustomDialogControllerPropertyAssignment(parent, item as ts.PropertyAssignment); + } + return item; + }); + return ts.factory.createNewExpression(node.expression, node.typeArguments, + [ts.factory.createObjectLiteralExpression(newproperties, true), ts.factory.createThis()]); + } +} + +function isCustomDialogControllerPropertyAssignment(node: ts.ObjectLiteralElementLike, + log: LogInfo[]): boolean { + if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && + node.name.getText() === CUSTOM_DIALOG_CONTROLLER_BUILDER) { + if (ts.isCallExpression(node.initializer) && ts.isIdentifier(node.initializer.expression) && + componentCollection.customDialogs.has(node.initializer.expression.getText())) { + return true; + } else { + validateCustomDialogControllerBuilderInit(node, log); + } + } +} + +function processCustomDialogControllerPropertyAssignment(parent: ts.PropertyDeclaration, + node: ts.PropertyAssignment): ts.PropertyAssignment { + if (ts.isCallExpression(node.initializer)) { + return ts.factory.updatePropertyAssignment(node, node.name, + processCustomDialogControllerBuilder(parent, node.initializer)); + } +} + +function processCustomDialogControllerBuilder(parent: ts.PropertyDeclaration, + node: ts.CallExpression): ts.ArrowFunction { + const newExp: ts.Expression = createCustomComponentNewExpression(node); + const jsDialog: ts.Identifier = ts.factory.createIdentifier(JS_DIALOG); + return createCustomComponentBuilderArrowFunction(parent, jsDialog, newExp); +} + function updateObservedProperty(item: ts.PropertyDeclaration, name: ts.Identifier, type: ts.TypeNode, program: ts.Program): ts.ExpressionStatement { return ts.factory.createExpressionStatement(ts.factory.createBinaryExpression( @@ -878,3 +933,12 @@ function validateWatchParam(type: LogType, pos: number, log: LogInfo[]): void { pos: pos }); } + +function validateCustomDialogControllerBuilderInit(node: ts.ObjectLiteralElementLike, + log: LogInfo[]): void { + log.push({ + type: LogType.ERROR, + message: 'The builder should be initialized with a @CustomDialog Component.', + pos: node.getStart() + }); +} diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index e09cef543..7a4825d35 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -36,11 +36,7 @@ import { ATTRIBUTE_ANIMATETO, GLOBAL_CONTEXT, CHECK_COMPONENT_EXTEND_DECORATOR, - INSTANCE, - SET_CONTROLLER_CTR_TYPE, - SET_CONTROLLER_METHOD, - JS_DIALOG, - CUSTOM_DIALOG_CONTROLLER_BUILDER + INSTANCE } from './pre_define'; import { componentInfo, @@ -62,7 +58,6 @@ import { INTERFACE_NODE_SET } from './component_map'; import { resources } from '../main'; -import { createCustomComponentNewExpression, createViewCreate } from './process_component_member'; export const transformLog: FileLog = new FileLog(); export let contextGlobal: ts.TransformationContext; @@ -133,8 +128,6 @@ export function processUISyntax(program: ts.Program, ut = false): Function { node = processWorker(node as ts.NewExpression); } else if (isAnimateTo(node)) { node = processAnimateTo(node as ts.CallExpression); - } else if (isCustomDialogController(node)) { - node = createCustomDialogController(node.parent, node, transformLog.errors); } return ts.visitEachChild(node, processAllNodes, context); } @@ -147,77 +140,6 @@ export function processUISyntax(program: ts.Program, ut = false): Function { }; } -function isCustomDialogController(node: ts.PropertyDeclaration) { - return node.parent && ts.isNewExpression(node) && ts.isIdentifier(node.expression) && - node.expression.getText() === SET_CONTROLLER_CTR_TYPE; -} - -function createCustomDialogController(parent: ts.PropertyDeclaration, node: ts.NewExpression, - log: LogInfo[]): ts.NewExpression { - if (node.arguments && node.arguments.length === 1 && - ts.isObjectLiteralExpression(node.arguments[0]) && node.arguments[0].properties) { - const newproperties: ts.ObjectLiteralElementLike[] = node.arguments[0].properties.map((item) => { - if (isCustomDialogControllerPropertyAssignment(item, log)) { - item = processCustomDialogControllerPropertyAssignment(parent, item as ts.PropertyAssignment); - } - return item; - }); - return ts.factory.createNewExpression(node.expression, node.typeArguments, - [ts.factory.createObjectLiteralExpression(newproperties, true), ts.factory.createThis()]); - } -} - -function isCustomDialogControllerPropertyAssignment(node: ts.ObjectLiteralElementLike, - log: LogInfo[]): boolean { - if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && - node.name.getText() === CUSTOM_DIALOG_CONTROLLER_BUILDER) { - if (ts.isCallExpression(node.initializer) && ts.isIdentifier(node.initializer.expression) && - componentCollection.customDialogs.has(node.initializer.expression.getText())) { - return true; - } else { - validateCustomDialogControllerBuilderInit(node, log); - } - } -} - -function validateCustomDialogControllerBuilderInit(node: ts.ObjectLiteralElementLike, - log: LogInfo[]): void { - log.push({ - type: LogType.ERROR, - message: 'The builder should be initialized with a @CustomDialog Component.', - pos: node.getStart() - }); -} - -function processCustomDialogControllerPropertyAssignment(parent: ts.PropertyDeclaration, - node: ts.PropertyAssignment): ts.PropertyAssignment { - if (ts.isCallExpression(node.initializer)) { - return ts.factory.updatePropertyAssignment(node, node.name, - processCustomDialogControllerBuilder(parent, node.initializer)); - } -} - -function processCustomDialogControllerBuilder(parent: ts.PropertyDeclaration, - node: ts.CallExpression): ts.ArrowFunction { - const newExp: ts.Expression = createCustomComponentNewExpression(node); - const jsDialog: ts.Identifier = ts.factory.createIdentifier(JS_DIALOG); - return createCustomComponentBuilderArrowFunction(parent, jsDialog, newExp); -} - -function createCustomComponentBuilderArrowFunction(parent: ts.PropertyDeclaration, - jsDialog: ts.Identifier, newExp: ts.Expression): ts.ArrowFunction { - return ts.factory.createArrowFunction(undefined, undefined, [], undefined, - ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), ts.factory.createBlock([ - ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList( - [ts.factory.createVariableDeclaration(jsDialog, undefined, undefined, newExp)], - ts.NodeFlags.Let)), ts.factory.createExpressionStatement(ts.factory.createCallExpression( - ts.factory.createPropertyAccessExpression(jsDialog, - ts.factory.createIdentifier(SET_CONTROLLER_METHOD)), undefined, - [ts.factory.createPropertyAccessExpression(ts.factory.createThis(), - parent.name as ts.Identifier)])), ts.factory.createExpressionStatement( - createViewCreate(jsDialog))], true)); -} - function isResource(node: ts.Node): boolean { return ts.isCallExpression(node) && ts.isIdentifier(node.expression) && (node.expression.escapedText.toString() === RESOURCE || -- Gitee