From 465d9e36dd0e454ee5a897b92f7e9ef6c85e2049 Mon Sep 17 00:00:00 2001 From: houhaoyu Date: Tue, 8 Feb 2022 17:39:27 +0800 Subject: [PATCH] houhaoyu@huawei.com support 427 for Radio.checked Signed-off-by: houhaoyu Change-Id: Ieec61b12c7cd9d805f3f9fdcf137f96bba69e0d6 --- compiler/src/pre_define.ts | 2 ++ compiler/src/process_component_build.ts | 21 ++++++++++++++++----- compiler/src/process_component_class.ts | 6 +++--- compiler/test/ut/syntacticSugar/$$.ts | 8 ++++++++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index a1a29a46f..cf2b3c16f 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -189,6 +189,8 @@ export const VISUAL_STATE: string = 'visualState'; export const VIEW_STACK_PROCESSOR: string = 'ViewStackProcessor'; export const BIND_POPUP: string = 'bindPopup'; +export const CHECKED: string = 'checked'; +export const RADIO: string = 'Radio'; export const $$_VALUE: string = 'value'; export const $$_CHANGE_EVENT: string = 'changeEvent'; export const $$_THIS: string = '$$this'; diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index c66da1729..ee016a404 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -53,6 +53,8 @@ import { $$_CHANGE_EVENT, $$_THIS, $$_NEW_VALUE, + CHECKED, + RADIO, BUILDER_ATTR_NAME, BUILDER_ATTR_BIND, CUSTOM_DIALOG_CONTROLLER_BUILDER @@ -753,12 +755,10 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any, statements, log, false, true, false); } lastStatement.kind = true; - } else if (propName === BIND_POPUP && temp.arguments.length === 2 && - temp.arguments[0].getText().match(/^\$\$(.|\n)+/)) { + } else if (!isStylesAttr && [BIND_POPUP, CHECKED].includes(propName) && + temp.arguments.length && temp.arguments[0] && temp.arguments[0].getText().match(/^\$\$(.|\n)+/)) { const argumentsArr: ts.Expression[] = []; - const varExp: ts.Expression = updateArgumentFor$$(temp.arguments[0]); - argumentsArr.push(generateObjectFor$$(varExp)); - argumentsArr.push(temp.arguments[1]); + classifyArgumentsNum(temp.arguments, argumentsArr, propName, identifierNode); statements.push(ts.factory.createExpressionStatement( createFunction(identifierNode, node, argumentsArr))); lastStatement.kind = true; @@ -779,6 +779,17 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any, } } +function classifyArgumentsNum(args: any, argumentsArr: ts.Expression[], propName: string, + identifierNode: ts.Identifier): void { + if (propName === BIND_POPUP && args.length === 2) { + const varExp: ts.Expression = updateArgumentFor$$(args[0]); + argumentsArr.push(generateObjectFor$$(varExp), args[1]); + } else if (propName === CHECKED && args.length === 1 && identifierNode.getText() === RADIO) { + const varExp: ts.Expression = updateArgumentFor$$(args[0]); + argumentsArr.push(varExp, createArrowFunctionFor$$(varExp)); + } +} + function traverseStylesAttr(node: ts.Node): ts.Node { if (ts.isStringLiteral(node)) { node = ts.factory.createStringLiteral(node.text); diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index 1732d6c3a..3f464cca4 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -481,9 +481,9 @@ function createParamsInitBlock(express: string, statements: ts.Statement[], express === COMPONENT_CONSTRUCTOR_DELETE_PARAMS ? undefined : ts.factory.createIdentifier(CREATE_CONSTRUCTOR_PARAMS), undefined, express === COMPONENT_CONSTRUCTOR_DELETE_PARAMS ? undefined : - ts.factory.createTypeReferenceNode( - ts.factory.createIdentifier(parentComponentName.getText() + INTERFACE_NAME_SUFFIX), undefined), - undefined)], undefined, ts.factory.createBlock(statements, true)); + ts.factory.createTypeReferenceNode( + ts.factory.createIdentifier(parentComponentName.getText() + INTERFACE_NAME_SUFFIX), undefined), + undefined)], undefined, ts.factory.createBlock(statements, true)); return methodDeclaration; } diff --git a/compiler/test/ut/syntacticSugar/$$.ts b/compiler/test/ut/syntacticSugar/$$.ts index ab6d9f761..35c9732d5 100644 --- a/compiler/test/ut/syntacticSugar/$$.ts +++ b/compiler/test/ut/syntacticSugar/$$.ts @@ -31,6 +31,8 @@ struct HomeComponent { Text(this.value1) Text(this.value2) Text(this.value3) + Radio({value: "Radio", group: "1"}) + .checked($$this.value4) } Row() { Button() { @@ -45,6 +47,8 @@ struct HomeComponent { .fontSize(100) .bindPopup($$value6.item1, {message: "This is $$ for Obj"}) Text(this.value3) + Radio({value: "Radio", group: "1"}) + .checked($$value5[0]) } .width(20) } @@ -91,6 +95,8 @@ class HomeComponent extends View { Text.pop(); Text.create(this.value3); Text.pop(); + Radio.create({ value: "Radio", group: "1" }); + Radio.checked(this.value4, newValue => { this.value4 = newValue; }); Row.pop(); Row.create(); Row.width(20); @@ -109,6 +115,8 @@ class HomeComponent extends View { Text.pop(); Text.create(this.value3); Text.pop(); + Radio.create({ value: "Radio", group: "1" }); + Radio.checked(value5[0], newValue => { value5[0] = newValue; }); Row.pop(); Column.pop(); } -- Gitee