From 11a3762ab7441a5321017ee0943c64eff742e8ef Mon Sep 17 00:00:00 2001 From: Cuecuexiaoyu Date: Thu, 19 Jun 2025 17:20:35 +0800 Subject: [PATCH 1/2] add for loop node visit Signed-off-by: Cuecuexiaoyu Change-Id: I585ab13e68585ed65c509deb468a0741b797daed --- arkui-plugins/common/log-collector.ts | 6 +- arkui-plugins/common/plugin-context.ts | 1 + .../demo/mock/resource/resource-in-build.ets | 67 ++++++ .../mock/resource/resource-in-property.ets | 32 +++ .../resource/resource-in-build.test.ts | 206 ++++++++++++++++++ .../resource/resource-in-property.test.ts | 143 ++++++++++++ .../ui-plugins/checked-transformer.ts | 2 +- .../ui-plugins/struct-translators/utils.ts | 3 + koala-wrapper/native/src/generated/bridges.cc | 13 ++ .../src/arkts-api/factory/nodeFactory.ts | 30 ++- .../node-utilities/ForInStatement.ts | 37 ++++ .../node-utilities/ForOfStatement.ts | 38 ++++ .../node-utilities/ForUpdateStatement.ts | 39 ++++ koala-wrapper/src/arkts-api/visitor.ts | 45 +++- .../src/generated/Es2pandaNativeModule.ts | 10 + .../src/generated/peers/ForInStatement.ts | 59 +++-- .../src/generated/peers/ForOfStatement.ts | 71 ++++-- .../src/generated/peers/ForUpdateStatement.ts | 78 +++++-- 18 files changed, 803 insertions(+), 77 deletions(-) create mode 100644 arkui-plugins/test/demo/mock/resource/resource-in-build.ets create mode 100644 arkui-plugins/test/demo/mock/resource/resource-in-property.ets create mode 100644 arkui-plugins/test/ut/ui-plugins/resource/resource-in-build.test.ts create mode 100644 arkui-plugins/test/ut/ui-plugins/resource/resource-in-property.test.ts create mode 100644 koala-wrapper/src/arkts-api/node-utilities/ForInStatement.ts create mode 100644 koala-wrapper/src/arkts-api/node-utilities/ForOfStatement.ts create mode 100644 koala-wrapper/src/arkts-api/node-utilities/ForUpdateStatement.ts diff --git a/arkui-plugins/common/log-collector.ts b/arkui-plugins/common/log-collector.ts index 16e00bde2..5f7ede078 100644 --- a/arkui-plugins/common/log-collector.ts +++ b/arkui-plugins/common/log-collector.ts @@ -15,6 +15,7 @@ import * as arkts from '@koalaui/libarkts'; import { LogType } from './predefines'; +import { ProjectConfig } from './plugin-context'; interface LogInfo { type: LogType; @@ -55,7 +56,10 @@ export class LogCollector { this.logInfos.push(logItem); } - emitLogInfo(): void { + emitLogInfo(projectConfig: ProjectConfig | undefined): void { + if (!projectConfig || projectConfig.ignoreError) { + return; + } this.logInfos.forEach((logItem: LogInfo) => { arkts.Diagnostic.logDiagnostic(generateDiagnosticKind(logItem), arkts.getStartPosition(logItem.node)); }); diff --git a/arkui-plugins/common/plugin-context.ts b/arkui-plugins/common/plugin-context.ts index 6396f7bf8..98234f939 100644 --- a/arkui-plugins/common/plugin-context.ts +++ b/arkui-plugins/common/plugin-context.ts @@ -103,6 +103,7 @@ export interface ProjectConfig { moduleType: string; moduleRootPath: string; aceModuleJsonPath: string; + ignoreError: boolean; } export type PluginHandlerFunction = () => void; diff --git a/arkui-plugins/test/demo/mock/resource/resource-in-build.ets b/arkui-plugins/test/demo/mock/resource/resource-in-build.ets new file mode 100644 index 000000000..7205517bb --- /dev/null +++ b/arkui-plugins/test/demo/mock/resource/resource-in-build.ets @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2025 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. + */ + +import { Component, $r, $rawfile, Column, Text, Image, TextInput, Select, SelectOption, Margin, ImageAnimator, Resource } from "@kit.ArkUI" + +@Component +struct MyStateSample { + str1: string = 'app.media.ri' + str2: string = 'app.photo2.png' + raw: string = 'app.photo.png' + tt: string[] = ['0','1','3','5','8'] + + aboutToAppear() { + let arr: Array = new Array() + for (let i=0; i<5; i++) { + arr.push($r('sys.string.ohos_lab_location')) + } + for (let item of this.tt) { + arr.push($r('sys.string.ohos_lab_microphone')) + } + } + + build() { + Column() { + Text($r('app.string.ohos_lab_microphone')) + Column() { + Text($r('sys.string.ohos_id_text_font_family_regular')) + Text($r('sys.string'.concat('.ohos_id_text_font_family_regular'))) + Image($rawfile(this.raw)) + TextInput({ text: $r('sys.string.ohos_desc_manage_local_accounts') }) + Text($r(this.str1)) + Text($r(this.str2)) + Select(new Array( + { value: 'aaa', icon: $r("sys.media.ohos_ic_public_play_last") }, + { value: 'bbb', icon: $r("sys.media.ohos_ic_public_play_last") }, + { value: 'ccc', icon: $r("sys.media.ohos_ic_public_play_last") }, + { value: 'ddd', icon: $r("sys.media.ohos_ic_public_play_last") } + )) + Image($r('sys.media.ohos_ic_public_arrow_left')) + .margin({ + top: $r('sys.float.ohos_id_alpha_content_primary'), + bottom: $r('sys.float.ohos_id_alpha_content_primary_dark') + } as Margin) + ImageAnimator().images([ + { + src: $r('sys.media.ohos_ic_public_arrow_left') + }, + { + src: $r('sys.media.ohos_ic_public_arrow_left') + }, + ]) + } + } + } +} \ No newline at end of file diff --git a/arkui-plugins/test/demo/mock/resource/resource-in-property.ets b/arkui-plugins/test/demo/mock/resource/resource-in-property.ets new file mode 100644 index 000000000..3776151bd --- /dev/null +++ b/arkui-plugins/test/demo/mock/resource/resource-in-property.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +import { Component, $r, $rawfile, Column, Text, Image, Resource } from "@ohos.arkui.component" + +let i: Resource = $r('sys.symbol.ohos_trash'); + +@Component +struct ResourceComponent { + private aa: string = 'app.photo.png'; + private str: Resource = $r('sys.string.ohos_desc_accelerometer'); + private icon: Resource = $rawfile(this.aa); + build() { + Column() { + Text(this.str) + Text(i) + Image(this.icon) + } + } +} \ No newline at end of file diff --git a/arkui-plugins/test/ut/ui-plugins/resource/resource-in-build.test.ts b/arkui-plugins/test/ut/ui-plugins/resource/resource-in-build.test.ts new file mode 100644 index 000000000..7ad500f37 --- /dev/null +++ b/arkui-plugins/test/ut/ui-plugins/resource/resource-in-build.test.ts @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2025 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. + */ + +import * as path from 'path'; +import { PluginTester } from '../../../utils/plugin-tester'; +import { mockBuildConfig } from '../../../utils/artkts-config'; +import { getRootPath, MOCK_ENTRY_DIR_PATH } from '../../../utils/path-config'; +import { parseDumpSrc } from '../../../utils/parse-string'; +import { uiNoRecheck, recheck } from '../../../utils/plugins'; +import { BuildConfig, PluginTestContext } from '../../../utils/shared-types'; +import { uiTransform } from '../../../../ui-plugins'; +import { Plugins } from '../../../../common/plugin-context'; + +const BUILDER_LAMBDA_DIR_PATH: string = 'resource'; + +const buildConfig: BuildConfig = mockBuildConfig(); +buildConfig.compileFiles = [ + path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, BUILDER_LAMBDA_DIR_PATH, 'resource-in-build.ets'), +]; + +const pluginTester = new PluginTester('test resource transform in build method', buildConfig); + +const parsedTransform: Plugins = { + name: 'resource-in-build', + parsed: uiTransform().parsed, +}; + +const expectedScript: string = ` + +import { memo as memo } from "arkui.stateManagement.runtime"; + +import { _rawfile as _rawfile } from "arkui.component.resources"; + +import { ImageAnimatorAttribute as ImageAnimatorAttribute } from "arkui.component.imageAnimator"; + +import { ImageAttribute as ImageAttribute } from "arkui.component.image"; + +import { _r as _r } from "arkui.component.resources"; + +import { LayoutCallback as LayoutCallback } from "arkui.component.customComponent"; + +import { CustomComponentV2 as CustomComponentV2 } from "arkui.component.customComponent"; + +import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + +import { Component as Component, $r as $r, $rawfile as $rawfile, Column as Column, Text as Text, Image as Image, TextInput as TextInput, Select as Select, SelectOption as SelectOption, Margin as Margin, ImageAnimator as ImageAnimator, Resource as Resource } from "@kit.ArkUI"; + +function main() {} + + + +@Component() final struct MyStateSample extends CustomComponent { + public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void { + this.__backing_str1 = ((({let gensym___147578113 = initializers; + (((gensym___147578113) == (null)) ? undefined : gensym___147578113.str1)})) ?? ("app.media.ri")); + this.__backing_str2 = ((({let gensym___220149772 = initializers; + (((gensym___220149772) == (null)) ? undefined : gensym___220149772.str2)})) ?? ("app.photo2.png")); + this.__backing_raw = ((({let gensym___241810043 = initializers; + (((gensym___241810043) == (null)) ? undefined : gensym___241810043.raw)})) ?? ("app.photo.png")); + this.__backing_tt = ((({let gensym___198287964 = initializers; + (((gensym___198287964) == (null)) ? undefined : gensym___198287964.tt)})) ?? (["0", "1", "3", "5", "8"])); + } + + public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} + + private __backing_str1?: string; + + public get str1(): string { + return (this.__backing_str1 as string); + } + + public set str1(value: string) { + this.__backing_str1 = value; + } + + private __backing_str2?: string; + + public get str2(): string { + return (this.__backing_str2 as string); + } + + public set str2(value: string) { + this.__backing_str2 = value; + } + + private __backing_raw?: string; + + public get raw(): string { + return (this.__backing_raw as string); + } + + public set raw(value: string) { + this.__backing_raw = value; + } + + private __backing_tt?: Array; + + public get tt(): Array { + return (this.__backing_tt as Array); + } + + public set tt(value: Array) { + this.__backing_tt = value; + } + + public aboutToAppear() { + let arr: Array = new Array(); + for (let i = 0;((i) < (5));(i++)) { + arr.push(_r(125829791, 10003, "com.example.myapplication", "entry")); + } + for (let item of this.tt) { + arr.push(_r(125829775, 10003, "com.example.myapplication", "entry")); + } + } + + @memo() public build() { + Column(undefined, (() => { + Text(undefined, $r("app.string.ohos_lab_microphone")); + Column(undefined, (() => { + Text(undefined, _r(125829694, 10003, "com.example.myapplication", "entry")); + Text(undefined, _r(-1, -1, "com.example.myapplication", "entry", "sys.string".concat(".ohos_id_text_font_family_regular"))); + Image(undefined, _rawfile(-1, 30000, "com.example.myapplication", "entry", this.raw)); + TextInput(undefined, { + text: _r(125829826, 10003, "com.example.myapplication", "entry"), + }); + Text(undefined, _r(-1, -1, "com.example.myapplication", "entry", this.str1)); + Text(undefined, _r(-1, -1, "com.example.myapplication", "entry", this.str2)); + Select(undefined, new Array({ + value: "aaa", + icon: _r(125830397, 20000, "com.example.myapplication", "entry"), + }, { + value: "bbb", + icon: _r(125830397, 20000, "com.example.myapplication", "entry"), + }, { + value: "ccc", + icon: _r(125830397, 20000, "com.example.myapplication", "entry"), + }, { + value: "ddd", + icon: _r(125830397, 20000, "com.example.myapplication", "entry"), + })); + Image(((instance: ImageAttribute): void => { + instance.margin(({ + top: _r(125829369, 10002, "com.example.myapplication", "entry"), + bottom: _r(125829370, 10002, "com.example.myapplication", "entry"), + } as Margin)); + return; + }), _r(125830087, 20000, "com.example.myapplication", "entry")); + ImageAnimator(((instance: ImageAnimatorAttribute): void => { + instance.images([{ + src: _r(125830087, 20000, "com.example.myapplication", "entry"), + }, { + src: _r(125830087, 20000, "com.example.myapplication", "entry"), + }]); + return; + })); + })); + })); + } + + private constructor() {} + +} + +@Component() export interface __Options_MyStateSample { + set str1(str1: string | undefined) + + get str1(): string | undefined + set str2(str2: string | undefined) + + get str2(): string | undefined + set raw(raw: string | undefined) + + get raw(): string | undefined + set tt(tt: Array | undefined) + + get tt(): Array | undefined + +} +`; + +function testParsedAndCheckedTransformer(this: PluginTestContext): void { + expect(parseDumpSrc(this.scriptSnapshot ?? '')).toBe(parseDumpSrc(expectedScript)); +} + +pluginTester.run( + 'test resource transform in build method', + [parsedTransform, uiNoRecheck, recheck], + { + 'checked:ui-no-recheck': [testParsedAndCheckedTransformer], + }, + { + stopAfter: 'checked', + } +); diff --git a/arkui-plugins/test/ut/ui-plugins/resource/resource-in-property.test.ts b/arkui-plugins/test/ut/ui-plugins/resource/resource-in-property.test.ts new file mode 100644 index 000000000..77f2c7f59 --- /dev/null +++ b/arkui-plugins/test/ut/ui-plugins/resource/resource-in-property.test.ts @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2025 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. + */ + +import * as path from 'path'; +import { PluginTester } from '../../../utils/plugin-tester'; +import { mockBuildConfig } from '../../../utils/artkts-config'; +import { getRootPath, MOCK_ENTRY_DIR_PATH } from '../../../utils/path-config'; +import { parseDumpSrc } from '../../../utils/parse-string'; +import { uiNoRecheck, recheck } from '../../../utils/plugins'; +import { BuildConfig, PluginTestContext } from '../../../utils/shared-types'; +import { uiTransform } from '../../../../ui-plugins'; +import { Plugins } from '../../../../common/plugin-context'; + +const BUILDER_LAMBDA_DIR_PATH: string = 'resource'; + +const buildConfig: BuildConfig = mockBuildConfig(); +buildConfig.compileFiles = [ + path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, BUILDER_LAMBDA_DIR_PATH, 'resource-in-property.ets'), +]; + +const pluginTester = new PluginTester('test resource transform in property', buildConfig); + +const parsedTransform: Plugins = { + name: 'resource-in-property', + parsed: uiTransform().parsed +}; + +const expectedScript: string = ` + +import { memo as memo } from "arkui.stateManagement.runtime"; + +import { _rawfile as _rawfile } from "arkui.component.resources"; + +import { _r as _r } from "arkui.component.resources"; + +import { LayoutCallback as LayoutCallback } from "arkui.component.customComponent"; + +import { CustomComponentV2 as CustomComponentV2 } from "arkui.component.customComponent"; + +import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + +import { Component as Component, $r as $r, $rawfile as $rawfile, Column as Column, Text as Text, Image as Image, Resource as Resource } from "@ohos.arkui.component"; + +let i: Resource; + +function main() {} + +i = _r(125830645, 40000, "com.example.myapplication", "entry"); + +@Component() final struct ResourceComponent extends CustomComponent { + public __initializeStruct(initializers: __Options_ResourceComponent | undefined, @memo() content: (()=> void) | undefined): void { + this.__backing_aa = ((({let gensym___248008024 = initializers; + (((gensym___248008024) == (null)) ? undefined : gensym___248008024.aa)})) ?? ("app.photo.png")); + this.__backing_str = ((({let gensym___249074315 = initializers; + (((gensym___249074315) == (null)) ? undefined : gensym___249074315.str)})) ?? (_r(125829844, 10003, "com.example.myapplication", "entry"))); + this.__backing_icon = ((({let gensym___193492277 = initializers; + (((gensym___193492277) == (null)) ? undefined : gensym___193492277.icon)})) ?? (_rawfile(-1, 30000, "com.example.myapplication", "entry", this.aa))); + } + + public __updateStruct(initializers: __Options_ResourceComponent | undefined): void {} + + private __backing_aa?: string; + + public get aa(): string { + return (this.__backing_aa as string); + } + + public set aa(value: string) { + this.__backing_aa = value; + } + + private __backing_str?: Resource; + + public get str(): Resource { + return (this.__backing_str as Resource); + } + + public set str(value: Resource) { + this.__backing_str = value; + } + + private __backing_icon?: Resource; + + public get icon(): Resource { + return (this.__backing_icon as Resource); + } + + public set icon(value: Resource) { + this.__backing_icon = value; + } + + @memo() public build() { + Column(undefined, (() => { + Text(undefined, this.str); + Text(undefined, i); + Image(undefined, this.icon); + })); + } + + private constructor() {} + +} + +@Component() export interface __Options_ResourceComponent { + set aa(aa: string | undefined) + + get aa(): string | undefined + set str(str: Resource | undefined) + + get str(): Resource | undefined + set icon(icon: Resource | undefined) + + get icon(): Resource | undefined + +} +`; + +function testParsedAndCheckedTransformer(this: PluginTestContext): void { + expect(parseDumpSrc(this.scriptSnapshot ?? '')).toBe(parseDumpSrc(expectedScript)); +} + +pluginTester.run( + 'test resource transform in property', + [parsedTransform, uiNoRecheck, recheck], + { + 'checked:ui-no-recheck': [testParsedAndCheckedTransformer], + }, + { + stopAfter: 'checked', + } +); diff --git a/arkui-plugins/ui-plugins/checked-transformer.ts b/arkui-plugins/ui-plugins/checked-transformer.ts index d5c9d3942..0c7b67ce7 100644 --- a/arkui-plugins/ui-plugins/checked-transformer.ts +++ b/arkui-plugins/ui-plugins/checked-transformer.ts @@ -147,7 +147,7 @@ export class CheckedTransformer extends AbstractVisitor { return addMemoAnnotation(node); } else if (arkts.isEtsScript(node) && ImportCollector.getInstance().importInfos.length > 0) { ImportCollector.getInstance().insertCurrentImports(this.program); - LogCollector.getInstance().emitLogInfo(); + LogCollector.getInstance().emitLogInfo(this.projectConfig); } else if (arkts.isTSTypeAliasDeclaration(node)) { return structFactory.transformTSTypeAlias(node); } else if (arkts.isBlockStatement(node)) { diff --git a/arkui-plugins/ui-plugins/struct-translators/utils.ts b/arkui-plugins/ui-plugins/struct-translators/utils.ts index eba0ce6a4..c44002d9f 100644 --- a/arkui-plugins/ui-plugins/struct-translators/utils.ts +++ b/arkui-plugins/ui-plugins/struct-translators/utils.ts @@ -189,6 +189,9 @@ function readAppResource( aceBuildJson: LoaderJson, rawfile: Set ): void { + if (!projectConfig.appResource) { + projectConfig.ignoreError = true; + } if ('hspResourcesMap' in aceBuildJson && aceBuildJson.hspResourcesMap) { readHspResource(aceBuildJson, projectConfig, resourcesList); } diff --git a/koala-wrapper/native/src/generated/bridges.cc b/koala-wrapper/native/src/generated/bridges.cc index d89b383f9..73a311a4a 100644 --- a/koala-wrapper/native/src/generated/bridges.cc +++ b/koala-wrapper/native/src/generated/bridges.cc @@ -11282,6 +11282,19 @@ KNativePointer impl_CreateForUpdateStatement(KNativePointer context, KNativePoin } KOALA_INTEROP_5(CreateForUpdateStatement, KNativePointer, KNativePointer, KNativePointer, KNativePointer, KNativePointer, KNativePointer); +KNativePointer impl_UpdateForUpdateStatement(KNativePointer context, KNativePointer original, KNativePointer init, KNativePointer test, KNativePointer update, KNativePointer body) +{ + const auto _context = reinterpret_cast(context); + const auto _original = reinterpret_cast(original); + const auto _init = reinterpret_cast(init); + const auto _test = reinterpret_cast(test); + const auto _update = reinterpret_cast(update); + const auto _body = reinterpret_cast(body); + auto result = GetImpl()->UpdateForUpdateStatement(_context, _original, _init, _test, _update, _body); + return result; +} +KOALA_INTEROP_6(UpdateForUpdateStatement, KNativePointer, KNativePointer, KNativePointer, KNativePointer, KNativePointer, KNativePointer, KNativePointer); + KNativePointer impl_ForUpdateStatementInit(KNativePointer context, KNativePointer receiver) { const auto _context = reinterpret_cast(context); diff --git a/koala-wrapper/src/arkts-api/factory/nodeFactory.ts b/koala-wrapper/src/arkts-api/factory/nodeFactory.ts index f9ad24118..c780fdbf9 100644 --- a/koala-wrapper/src/arkts-api/factory/nodeFactory.ts +++ b/koala-wrapper/src/arkts-api/factory/nodeFactory.ts @@ -78,6 +78,9 @@ import { AnnotationDeclaration, TryStatement, TSClassImplements, + ForUpdateStatement, + ForInStatement, + ForOfStatement, } from '../../generated'; import { Es2pandaModifierFlags } from '../../generated/Es2pandaEnums'; import { classPropertySetOptional, hasModifierFlag } from '../utilities/public'; @@ -136,6 +139,9 @@ import { updateArrayExpression } from '../node-utilities/ArrayExpression'; import { updateAnnotationDeclaration } from '../node-utilities/AnnotationDeclaration'; import { updateTryStatement } from '../node-utilities/TryStatement'; import { updateTSClassImplements } from '../node-utilities/TSClassImplements'; +import { updateForUpdateStatement } from '../node-utilities/ForUpdateStatement'; +import { updateForInStatement } from '../node-utilities/ForInStatement'; +import { updateForOfStatement } from '../node-utilities/ForOfStatement'; export const factory = { get createIdentifier(): (...args: Parameters) => Identifier { @@ -567,12 +573,34 @@ export const factory = { get updateTryStatement(): (...args: Parameters) => TryStatement { return updateTryStatement; }, - get createTSClassImplements(): (...args: Parameters) => TSClassImplements { + get createTSClassImplements(): ( + ...args: Parameters + ) => TSClassImplements { return TSClassImplements.createTSClassImplements; }, get UpdateTSClassImplements(): (...args: Parameters) => TSClassImplements { return updateTSClassImplements; }, + get createForUpdateStatement(): ( + ...args: Parameters + ) => ForUpdateStatement { + return ForUpdateStatement.createForUpdateStatement; + }, + get updateForUpdateStatement(): (...args: Parameters) => ForUpdateStatement { + return updateForUpdateStatement; + }, + get createForInStatement(): (...args: Parameters) => ForInStatement { + return ForInStatement.createForInStatement; + }, + get updateForInStatement(): (...args: Parameters) => ForInStatement { + return updateForInStatement; + }, + get createForOfStatement(): (...args: Parameters) => ForOfStatement { + return ForOfStatement.createForOfStatement; + }, + get updateForOfStatement(): (...args: Parameters) => ForOfStatement { + return updateForOfStatement; + }, /** @deprecated */ createTypeParameter1_(name: Identifier, constraint?: TypeNode, defaultType?: TypeNode) { return TSTypeParameter.createTSTypeParameter(Identifier.create1Identifier(name.name), constraint, defaultType); diff --git a/koala-wrapper/src/arkts-api/node-utilities/ForInStatement.ts b/koala-wrapper/src/arkts-api/node-utilities/ForInStatement.ts new file mode 100644 index 000000000..5e35ce0f0 --- /dev/null +++ b/koala-wrapper/src/arkts-api/node-utilities/ForInStatement.ts @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 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. + */ + +import { ForInStatement, Statement, Expression } from '../../generated'; +import { isSameNativeObject } from '../peers/ArktsObject'; +import { AstNode } from '../peers/AstNode'; +import { attachModifiers, updateThenAttach } from '../utilities/private'; + +export function updateForInStatement( + original: ForInStatement, + left?: AstNode, + right?: Expression, + body?: Statement +): ForInStatement { + if ( + isSameNativeObject(left, original.left) && + isSameNativeObject(right, original.right) && + isSameNativeObject(body, original.body) + ) { + return original; + } + + const updateNode = updateThenAttach(ForInStatement.updateForInStatement, attachModifiers); + return updateNode(original, left, right, body); +} diff --git a/koala-wrapper/src/arkts-api/node-utilities/ForOfStatement.ts b/koala-wrapper/src/arkts-api/node-utilities/ForOfStatement.ts new file mode 100644 index 000000000..be4911dac --- /dev/null +++ b/koala-wrapper/src/arkts-api/node-utilities/ForOfStatement.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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. + */ + +import { ForOfStatement, Statement, Expression } from '../../generated'; +import { isSameNativeObject } from '../peers/ArktsObject'; +import { AstNode } from '../peers/AstNode'; +import { attachModifiers, updateThenAttach } from '../utilities/private'; + +export function updateForOfStatement( + original: ForOfStatement, + left: AstNode | undefined, + right: Expression | undefined, + body: Statement | undefined, + isAwait: boolean +): ForOfStatement { + if ( + isSameNativeObject(left, original.left) && + isSameNativeObject(right, original.right) && + isSameNativeObject(body, original.body) + ) { + return original; + } + + const updateNode = updateThenAttach(ForOfStatement.updateForOfStatement, attachModifiers); + return updateNode(original, left, right, body, isAwait); +} diff --git a/koala-wrapper/src/arkts-api/node-utilities/ForUpdateStatement.ts b/koala-wrapper/src/arkts-api/node-utilities/ForUpdateStatement.ts new file mode 100644 index 000000000..a2085b159 --- /dev/null +++ b/koala-wrapper/src/arkts-api/node-utilities/ForUpdateStatement.ts @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 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. + */ + +import { ForUpdateStatement, Statement, Expression } from '../../generated'; +import { isSameNativeObject } from '../peers/ArktsObject'; +import { AstNode } from '../peers/AstNode'; +import { attachModifiers, updateThenAttach } from '../utilities/private'; + +export function updateForUpdateStatement( + original: ForUpdateStatement, + init?: AstNode, + test?: Expression, + update?: Expression, + body?: Statement +): ForUpdateStatement { + if ( + isSameNativeObject(init, original.init) && + isSameNativeObject(test, original.test) && + isSameNativeObject(update, original.update) && + isSameNativeObject(body, original.body) + ) { + return original; + } + + const updateNode = updateThenAttach(ForUpdateStatement.updateForUpdateStatement, attachModifiers); + return updateNode(original, init, test, update, body); +} diff --git a/koala-wrapper/src/arkts-api/visitor.ts b/koala-wrapper/src/arkts-api/visitor.ts index b0a45fbda..d5f2be7d1 100644 --- a/koala-wrapper/src/arkts-api/visitor.ts +++ b/koala-wrapper/src/arkts-api/visitor.ts @@ -48,6 +48,9 @@ import { isArrayExpression, isTryStatement, isBinaryExpression, + isForInStatement, + isForUpdateStatement, + isForOfStatement, } from '../generated'; import { isEtsScript, @@ -98,6 +101,7 @@ export function visitEachChild(node: AstNode, visitor: Visitor): AstNode { script = visitDefinition(script, visitor); script = visitDefinitionBody(script, visitor); script = visitStatement(script, visitor); + script = visitForLoopStatement(script, visitor); script = visitOuterExpression(script, visitor); script = visitInnerExpression(script, visitor); script = visitTrivialExpression(script, visitor); @@ -145,10 +149,7 @@ function visitOuterExpression(node: AstNode, visitor: Visitor): AstNode { } if (isArrayExpression(node)) { updated = true; - return factory.updateArrayExpression( - node, - nodesVisitor(node.elements, visitor) - ); + return factory.updateArrayExpression(node, nodesVisitor(node.elements, visitor)); } return node; } @@ -353,6 +354,42 @@ function visitStatement(node: AstNode, visitor: Visitor): AstNode { return node; } +function visitForLoopStatement(node: AstNode, visitor: Visitor): AstNode { + if (updated) { + return node; + } + if (isForUpdateStatement(node)) { + updated = true; + return factory.updateForUpdateStatement( + node, + nodeVisitor(node.init, visitor), + nodeVisitor(node.test, visitor), + nodeVisitor(node.update, visitor), + nodeVisitor(node.body, visitor) + ); + } + if (isForInStatement(node)) { + updated = true; + return factory.updateForInStatement( + node, + nodeVisitor(node.left, visitor), + nodeVisitor(node.right, visitor), + nodeVisitor(node.body, visitor) + ); + } + if (isForOfStatement(node)) { + updated = true; + return factory.updateForOfStatement( + node, + nodeVisitor(node.left, visitor), + nodeVisitor(node.right, visitor), + nodeVisitor(node.body, visitor), + node.isAwait + ); + } + return node; +} + function visitETSModule(node: AstNode, visitor: Visitor): AstNode { if (updated) { return node; diff --git a/koala-wrapper/src/generated/Es2pandaNativeModule.ts b/koala-wrapper/src/generated/Es2pandaNativeModule.ts index 7dcfda5a9..ef089731b 100644 --- a/koala-wrapper/src/generated/Es2pandaNativeModule.ts +++ b/koala-wrapper/src/generated/Es2pandaNativeModule.ts @@ -3562,6 +3562,16 @@ export class Es2pandaNativeModule { _CreateForUpdateStatement(context: KNativePointer, init: KNativePointer, test: KNativePointer, update: KNativePointer, body: KNativePointer): KNativePointer { throw new Error("'CreateForUpdateStatement was not overloaded by native module initialization") } + _UpdateForUpdateStatement( + context: KNativePointer, + original: KNativePointer, + init: KNativePointer, + test: KNativePointer, + update: KNativePointer, + body: KNativePointer + ): KNativePointer { + throw new Error("'CreateForUpdateStatement was not overloaded by native module initialization"); + } _ForUpdateStatementInit(context: KNativePointer, receiver: KNativePointer): KNativePointer { throw new Error("'ForUpdateStatementInit was not overloaded by native module initialization") } diff --git a/koala-wrapper/src/generated/peers/ForInStatement.ts b/koala-wrapper/src/generated/peers/ForInStatement.ts index adb587a5e..52d828bc1 100644 --- a/koala-wrapper/src/generated/peers/ForInStatement.ts +++ b/koala-wrapper/src/generated/peers/ForInStatement.ts @@ -16,47 +16,62 @@ import { global, passNode, - passNodeArray, - unpackNonNullableNode, unpackNode, - unpackNodeArray, assertValidPeer, AstNode, Es2pandaAstNodeType, KNativePointer, nodeByType, - ArktsObject, - unpackString -} from "../../reexport-for-generated" +} from '../../reexport-for-generated'; -import { LoopStatement } from "./LoopStatement" -import { Expression } from "./Expression" -import { Statement } from "./Statement" +import { LoopStatement } from './LoopStatement'; +import { Expression } from './Expression'; +import { Statement } from './Statement'; export class ForInStatement extends LoopStatement { - constructor(pointer: KNativePointer) { - assertValidPeer(pointer, Es2pandaAstNodeType.AST_NODE_TYPE_FOR_IN_STATEMENT) - super(pointer) - + constructor(pointer: KNativePointer) { + assertValidPeer(pointer, Es2pandaAstNodeType.AST_NODE_TYPE_FOR_IN_STATEMENT); + super(pointer); } static createForInStatement(left?: AstNode, right?: Expression, body?: Statement): ForInStatement { - return new ForInStatement(global.generatedEs2panda._CreateForInStatement(global.context, passNode(left), passNode(right), passNode(body))) + return new ForInStatement( + global.generatedEs2panda._CreateForInStatement( + global.context, + passNode(left), + passNode(right), + passNode(body) + ) + ); } - static updateForInStatement(original?: ForInStatement, left?: AstNode, right?: Expression, body?: Statement): ForInStatement { - return new ForInStatement(global.generatedEs2panda._UpdateForInStatement(global.context, passNode(original), passNode(left), passNode(right), passNode(body))) + static updateForInStatement( + original?: ForInStatement, + left?: AstNode, + right?: Expression, + body?: Statement + ): ForInStatement { + return new ForInStatement( + global.generatedEs2panda._UpdateForInStatement( + global.context, + passNode(original), + passNode(left), + passNode(right), + passNode(body) + ) + ); } get left(): AstNode | undefined { - return unpackNode(global.generatedEs2panda._ForInStatementLeftConst(global.context, this.peer)) + return unpackNode(global.generatedEs2panda._ForInStatementLeft(global.context, this.peer)); } get right(): Expression | undefined { - return unpackNode(global.generatedEs2panda._ForInStatementRightConst(global.context, this.peer)) + return unpackNode(global.generatedEs2panda._ForInStatementRight(global.context, this.peer)); } get body(): Statement | undefined { - return unpackNode(global.generatedEs2panda._ForInStatementBodyConst(global.context, this.peer)) + return unpackNode(global.generatedEs2panda._ForInStatementBody(global.context, this.peer)); } + protected readonly brandForInStatement: undefined; } -export function isForInStatement(node: AstNode): node is ForInStatement { - return node instanceof ForInStatement +export function isForInStatement(node: object | undefined): node is ForInStatement { + return node instanceof ForInStatement; } if (!nodeByType.has(Es2pandaAstNodeType.AST_NODE_TYPE_FOR_IN_STATEMENT)) { - nodeByType.set(Es2pandaAstNodeType.AST_NODE_TYPE_FOR_IN_STATEMENT, ForInStatement) + nodeByType.set(Es2pandaAstNodeType.AST_NODE_TYPE_FOR_IN_STATEMENT, ForInStatement); } diff --git a/koala-wrapper/src/generated/peers/ForOfStatement.ts b/koala-wrapper/src/generated/peers/ForOfStatement.ts index d958eb5a2..4ff443a26 100644 --- a/koala-wrapper/src/generated/peers/ForOfStatement.ts +++ b/koala-wrapper/src/generated/peers/ForOfStatement.ts @@ -16,50 +16,73 @@ import { global, passNode, - passNodeArray, - unpackNonNullableNode, unpackNode, - unpackNodeArray, assertValidPeer, AstNode, Es2pandaAstNodeType, KNativePointer, nodeByType, - ArktsObject, - unpackString -} from "../../reexport-for-generated" +} from '../../reexport-for-generated'; -import { LoopStatement } from "./LoopStatement" -import { Expression } from "./Expression" -import { Statement } from "./Statement" +import { LoopStatement } from './LoopStatement'; +import { Expression } from './Expression'; +import { Statement } from './Statement'; export class ForOfStatement extends LoopStatement { - constructor(pointer: KNativePointer) { - assertValidPeer(pointer, Es2pandaAstNodeType.AST_NODE_TYPE_FOR_OF_STATEMENT) - super(pointer) - + constructor(pointer: KNativePointer) { + assertValidPeer(pointer, Es2pandaAstNodeType.AST_NODE_TYPE_FOR_OF_STATEMENT); + super(pointer); } - static createForOfStatement(left: AstNode | undefined, right: Expression | undefined, body: Statement | undefined, isAwait: boolean): ForOfStatement { - return new ForOfStatement(global.generatedEs2panda._CreateForOfStatement(global.context, passNode(left), passNode(right), passNode(body), isAwait)) + static createForOfStatement( + left: AstNode | undefined, + right: Expression | undefined, + body: Statement | undefined, + isAwait: boolean + ): ForOfStatement { + return new ForOfStatement( + global.generatedEs2panda._CreateForOfStatement( + global.context, + passNode(left), + passNode(right), + passNode(body), + isAwait + ) + ); } - static updateForOfStatement(original: ForOfStatement | undefined, left: AstNode | undefined, right: Expression | undefined, body: Statement | undefined, isAwait: boolean): ForOfStatement { - return new ForOfStatement(global.generatedEs2panda._UpdateForOfStatement(global.context, passNode(original), passNode(left), passNode(right), passNode(body), isAwait)) + static updateForOfStatement( + original: ForOfStatement | undefined, + left: AstNode | undefined, + right: Expression | undefined, + body: Statement | undefined, + isAwait: boolean + ): ForOfStatement { + return new ForOfStatement( + global.generatedEs2panda._UpdateForOfStatement( + global.context, + passNode(original), + passNode(left), + passNode(right), + passNode(body), + isAwait + ) + ); } get left(): AstNode | undefined { - return unpackNode(global.generatedEs2panda._ForOfStatementLeftConst(global.context, this.peer)) + return unpackNode(global.generatedEs2panda._ForOfStatementLeft(global.context, this.peer)); } get right(): Expression | undefined { - return unpackNode(global.generatedEs2panda._ForOfStatementRightConst(global.context, this.peer)) + return unpackNode(global.generatedEs2panda._ForOfStatementRight(global.context, this.peer)); } get body(): Statement | undefined { - return unpackNode(global.generatedEs2panda._ForOfStatementBodyConst(global.context, this.peer)) + return unpackNode(global.generatedEs2panda._ForOfStatementBody(global.context, this.peer)); } get isAwait(): boolean { - return global.generatedEs2panda._ForOfStatementIsAwaitConst(global.context, this.peer) + return global.generatedEs2panda._ForOfStatementIsAwaitConst(global.context, this.peer); } + protected readonly brandForOfStatement: undefined; } -export function isForOfStatement(node: AstNode): node is ForOfStatement { - return node instanceof ForOfStatement +export function isForOfStatement(node: object | undefined): node is ForOfStatement { + return node instanceof ForOfStatement; } if (!nodeByType.has(Es2pandaAstNodeType.AST_NODE_TYPE_FOR_OF_STATEMENT)) { - nodeByType.set(Es2pandaAstNodeType.AST_NODE_TYPE_FOR_OF_STATEMENT, ForOfStatement) + nodeByType.set(Es2pandaAstNodeType.AST_NODE_TYPE_FOR_OF_STATEMENT, ForOfStatement); } diff --git a/koala-wrapper/src/generated/peers/ForUpdateStatement.ts b/koala-wrapper/src/generated/peers/ForUpdateStatement.ts index cb7985248..0594d8771 100644 --- a/koala-wrapper/src/generated/peers/ForUpdateStatement.ts +++ b/koala-wrapper/src/generated/peers/ForUpdateStatement.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -16,47 +16,77 @@ import { global, passNode, - passNodeArray, - unpackNonNullableNode, unpackNode, - unpackNodeArray, assertValidPeer, AstNode, - Es2pandaAstNodeType, KNativePointer, nodeByType, - ArktsObject, - unpackString -} from "../../reexport-for-generated" + Es2pandaAstNodeType, +} from '../../reexport-for-generated'; +import { Expression } from './Expression'; +import { LoopStatement } from './LoopStatement'; +import { Statement } from './Statement'; -import { LoopStatement } from "./LoopStatement" -import { Expression } from "./Expression" -import { Statement } from "./Statement" export class ForUpdateStatement extends LoopStatement { - constructor(pointer: KNativePointer) { - assertValidPeer(pointer, Es2pandaAstNodeType.AST_NODE_TYPE_FOR_UPDATE_STATEMENT) - super(pointer) - + constructor(pointer: KNativePointer) { + assertValidPeer(pointer, Es2pandaAstNodeType.AST_NODE_TYPE_FOR_UPDATE_STATEMENT); + super(pointer); } - static createForUpdateStatement(init?: AstNode, test?: Expression, update?: Expression, body?: Statement): ForUpdateStatement { - return new ForUpdateStatement(global.generatedEs2panda._CreateForUpdateStatement(global.context, passNode(init), passNode(test), passNode(update), passNode(body))) + static createForUpdateStatement( + init?: AstNode, + test?: Expression, + update?: Expression, + body?: Statement + ): ForUpdateStatement { + return new ForUpdateStatement( + global.generatedEs2panda._CreateForUpdateStatement( + global.context, + passNode(init), + passNode(test), + passNode(update), + passNode(body) + ) + ); + } + + static updateForUpdateStatement( + original: ForUpdateStatement, + init?: AstNode, + test?: Expression, + update?: Expression, + body?: Statement + ): ForUpdateStatement { + return new ForUpdateStatement( + global.generatedEs2panda._UpdateForUpdateStatement( + global.context, + passNode(original), + passNode(init), + passNode(test), + passNode(update), + passNode(body) + ) + ); } + get init(): AstNode | undefined { - return unpackNode(global.generatedEs2panda._ForUpdateStatementInitConst(global.context, this.peer)) + return unpackNode(global.generatedEs2panda._ForUpdateStatementInit(global.context, this.peer)); } get test(): Expression | undefined { - return unpackNode(global.generatedEs2panda._ForUpdateStatementTestConst(global.context, this.peer)) + return unpackNode(global.generatedEs2panda._ForUpdateStatementTest(global.context, this.peer)); } get update(): Expression | undefined { - return unpackNode(global.generatedEs2panda._ForUpdateStatementUpdateConst(global.context, this.peer)) + return unpackNode(global.generatedEs2panda._ForUpdateStatementUpdateConst(global.context, this.peer)); } get body(): Statement | undefined { - return unpackNode(global.generatedEs2panda._ForUpdateStatementBodyConst(global.context, this.peer)) + return unpackNode(global.generatedEs2panda._ForUpdateStatementBody(global.context, this.peer)); } + protected readonly brandForUpdateStatement: undefined; } -export function isForUpdateStatement(node: AstNode): node is ForUpdateStatement { - return node instanceof ForUpdateStatement + +export function isForUpdateStatement(node: object | undefined): node is ForUpdateStatement { + return node instanceof ForUpdateStatement; } + if (!nodeByType.has(Es2pandaAstNodeType.AST_NODE_TYPE_FOR_UPDATE_STATEMENT)) { - nodeByType.set(Es2pandaAstNodeType.AST_NODE_TYPE_FOR_UPDATE_STATEMENT, ForUpdateStatement) + nodeByType.set(Es2pandaAstNodeType.AST_NODE_TYPE_FOR_UPDATE_STATEMENT, ForUpdateStatement); } -- Gitee From 4323a6d3494dbe8934373c0347e357aaf082d0f2 Mon Sep 17 00:00:00 2001 From: Jiakai Shi Date: Fri, 20 Jun 2025 11:40:24 +0800 Subject: [PATCH 2/2] support resource in ut Signed-off-by: Jiakai Shi Change-Id: If0425d0b8721548ecd8b3d5eda8303f786681eb1 --- arkui-plugins/common/log-collector.ts | 14 +- arkui-plugins/common/plugin-context.ts | 2 +- arkui-plugins/jest-test.config.js | 3 - .../decorators/resource/resource-in-build.ets | 32 ++- .../resource/resource-in-property.ets | 2 +- .../test/demo/mock/resource/ResourceTable.txt | 13 ++ .../test/demo/mock/resource/rawfile/mock.txt | 1 + .../demo/mock/resource/resource-in-build.ets | 67 ------ .../mock/resource/resource-in-property.ets | 32 --- .../resource/resource-in-build.test.ts | 75 ++++--- .../resource/resource-in-property.test.ts | 32 +-- .../resource/resource-in-build.test.ts | 206 ------------------ .../resource/resource-in-property.test.ts | 143 ------------ arkui-plugins/test/utils/artkts-config.ts | 84 +++++-- arkui-plugins/test/utils/compile.ts | 3 + arkui-plugins/test/utils/path-config.ts | 11 +- arkui-plugins/test/utils/plugin-tester.ts | 11 +- arkui-plugins/test/utils/processor-builder.ts | 13 +- .../test/utils/processors/base-processor.ts | 16 +- .../test/utils/processors/main-processor.ts | 20 +- .../test/utils/processors/task-processor.ts | 7 +- arkui-plugins/test/utils/shared-types.ts | 7 +- .../ui-plugins/checked-transformer.ts | 5 +- arkui-plugins/ui-plugins/index.ts | 8 +- .../ui-plugins/struct-translators/utils.ts | 3 - .../node-utilities/ForInStatement.ts | 2 +- .../node-utilities/ForOfStatement.ts | 2 +- .../node-utilities/ForUpdateStatement.ts | 2 +- .../src/generated/peers/ForUpdateStatement.ts | 2 +- 29 files changed, 236 insertions(+), 582 deletions(-) create mode 100644 arkui-plugins/test/demo/mock/resource/ResourceTable.txt create mode 100644 arkui-plugins/test/demo/mock/resource/rawfile/mock.txt delete mode 100644 arkui-plugins/test/demo/mock/resource/resource-in-build.ets delete mode 100644 arkui-plugins/test/demo/mock/resource/resource-in-property.ets delete mode 100644 arkui-plugins/test/ut/ui-plugins/resource/resource-in-build.test.ts delete mode 100644 arkui-plugins/test/ut/ui-plugins/resource/resource-in-property.test.ts diff --git a/arkui-plugins/common/log-collector.ts b/arkui-plugins/common/log-collector.ts index 5f7ede078..5fa9ed7af 100644 --- a/arkui-plugins/common/log-collector.ts +++ b/arkui-plugins/common/log-collector.ts @@ -15,7 +15,6 @@ import * as arkts from '@koalaui/libarkts'; import { LogType } from './predefines'; -import { ProjectConfig } from './plugin-context'; interface LogInfo { type: LogType; @@ -36,9 +35,11 @@ export function generateDiagnosticKind(logItem: LogInfo): arkts.DiagnosticKind { export class LogCollector { public logInfos: LogInfo[]; private static instance: LogCollector; + private ignoreError: boolean; private constructor() { this.logInfos = []; + this.ignoreError = false; } static getInstance(): LogCollector { @@ -50,18 +51,25 @@ export class LogCollector { reset(): void { this.logInfos = []; + this.ignoreError = false; } collectLogInfo(logItem: LogInfo): void { this.logInfos.push(logItem); } - emitLogInfo(projectConfig: ProjectConfig | undefined): void { - if (!projectConfig || projectConfig.ignoreError) { + emitLogInfo(): void { + if (this.ignoreError) { return; } this.logInfos.forEach((logItem: LogInfo) => { arkts.Diagnostic.logDiagnostic(generateDiagnosticKind(logItem), arkts.getStartPosition(logItem.node)); }); } + + shouldIgnoreError(ignoreError: boolean | undefined): void { + if (!!ignoreError) { + this.ignoreError = true; + } + } } diff --git a/arkui-plugins/common/plugin-context.ts b/arkui-plugins/common/plugin-context.ts index 98234f939..333894b19 100644 --- a/arkui-plugins/common/plugin-context.ts +++ b/arkui-plugins/common/plugin-context.ts @@ -58,7 +58,7 @@ export class PluginContext { } public setProjectConfig(projectConfig: ProjectConfig): void { - throw new Error('do not set projectConfig!'); + this.projectConfig = projectConfig; } public getProjectConfig(): ProjectConfig | undefined { diff --git a/arkui-plugins/jest-test.config.js b/arkui-plugins/jest-test.config.js index bd3fca4ea..98b801f70 100644 --- a/arkui-plugins/jest-test.config.js +++ b/arkui-plugins/jest-test.config.js @@ -55,7 +55,4 @@ module.exports = { API_PATH: apiPath, KIT_PATH: kitPath }, - testPathIgnorePatterns: [ - './test/ut/ui-plugins/decorators/resource/', - ], }; diff --git a/arkui-plugins/test/demo/mock/decorators/resource/resource-in-build.ets b/arkui-plugins/test/demo/mock/decorators/resource/resource-in-build.ets index 49331e647..f77f9a04b 100644 --- a/arkui-plugins/test/demo/mock/decorators/resource/resource-in-build.ets +++ b/arkui-plugins/test/demo/mock/decorators/resource/resource-in-build.ets @@ -13,36 +13,46 @@ * limitations under the License. */ -import { Component, $r, $rawfile, Column, Text, Image, TextInput, Select, SelectOption, Margin, ImageAnimator } from "@ohos.arkui.component" +import { Component, $r, $rawfile, Column, Text, Image, TextInput, Select, SelectOption, Margin, ImageAnimator, Resource } from "@ohos.arkui.component" @Component struct ResourceComponent { str1: string = 'app.media.ri' str2: string = 'app.photo2.png' + numbers: string[] = ['0','1','3','5','8'] + aboutToAppear() { + let arr: Array = new Array() + for (let i = 0; i < 5; i++) { + arr.push($r('app.string.app_name')) + } + for (let item of this.numbers) { + arr.push($r('app.string.app_name')) + } + } build() { Column() { Text($r('app.string.app_name')) - Image($rawfile('app.photo.png')) - TextInput({ text: $r('app.string.input_content') }) + Image($rawfile('app.mock.txt')) + TextInput({ text: $r('app.string.module_desc') }) Text($r(this.str1)) Text($r(this.str2)) Select(new Array( - { value: 'aaa', icon: $r("app.media.selection") }, - { value: 'bbb', icon: $r("app.media.selection") }, - { value: 'ccc', icon: $r("app.media.selection") }, - { value: 'ddd', icon: $r("app.media.selection") } + { value: 'aaa', icon: $r("app.media.background") }, + { value: 'bbb', icon: $r("app.media.background") }, + { value: 'ccc', icon: $r("app.media.background") }, + { value: 'ddd', icon: $r("app.media.background") } )) Image($r('app.media.app_icon')) .margin({ - top: $r('app.float.elements_margin_horizontal_m'), - bottom: $r('app.float.elements_margin_horizontal_l') + top: $r('app.float.page_text_font_size'), + bottom: $r('app.float.page_text_font_size') } as Margin) ImageAnimator().images([ { - src: $r('app.media.aaa') + src: $r('app.media.app_icon') }, { - src: $r('app.media.bbb') + src: $r('app.media.layered_image') }, ]) } diff --git a/arkui-plugins/test/demo/mock/decorators/resource/resource-in-property.ets b/arkui-plugins/test/demo/mock/decorators/resource/resource-in-property.ets index 591311c7d..fca6a78a7 100644 --- a/arkui-plugins/test/demo/mock/decorators/resource/resource-in-property.ets +++ b/arkui-plugins/test/demo/mock/decorators/resource/resource-in-property.ets @@ -20,7 +20,7 @@ let i: Resource = $r('app.string.app_name'); @Component struct ResourceComponent { private str: Resource = $r('app.string.app_name'); - private icon: Resource = $rawfile('app.photo.png'); + private icon: Resource = $rawfile('app.mock.txt'); build() { Column() { Text(this.str) diff --git a/arkui-plugins/test/demo/mock/resource/ResourceTable.txt b/arkui-plugins/test/demo/mock/resource/ResourceTable.txt new file mode 100644 index 000000000..6c0c36582 --- /dev/null +++ b/arkui-plugins/test/demo/mock/resource/ResourceTable.txt @@ -0,0 +1,13 @@ +string EntryAbility_desc 0x01000002 +string EntryAbility_label 0x01000003 +string app_name 0x01000000 +string module_desc 0x01000004 +color start_window_background 0x01000005 +float page_text_font_size 0x01000006 +media app_icon 0x01000001 +media background 0x01000007 +media foreground 0x01000008 +media layered_image 0x01000009 +media startIcon 0x0100000a +profile backup_config 0x0100000b +profile main_pages 0x0100000c \ No newline at end of file diff --git a/arkui-plugins/test/demo/mock/resource/rawfile/mock.txt b/arkui-plugins/test/demo/mock/resource/rawfile/mock.txt new file mode 100644 index 000000000..1eb866e0e --- /dev/null +++ b/arkui-plugins/test/demo/mock/resource/rawfile/mock.txt @@ -0,0 +1 @@ +mocking rawfile \ No newline at end of file diff --git a/arkui-plugins/test/demo/mock/resource/resource-in-build.ets b/arkui-plugins/test/demo/mock/resource/resource-in-build.ets deleted file mode 100644 index 7205517bb..000000000 --- a/arkui-plugins/test/demo/mock/resource/resource-in-build.ets +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2025 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. - */ - -import { Component, $r, $rawfile, Column, Text, Image, TextInput, Select, SelectOption, Margin, ImageAnimator, Resource } from "@kit.ArkUI" - -@Component -struct MyStateSample { - str1: string = 'app.media.ri' - str2: string = 'app.photo2.png' - raw: string = 'app.photo.png' - tt: string[] = ['0','1','3','5','8'] - - aboutToAppear() { - let arr: Array = new Array() - for (let i=0; i<5; i++) { - arr.push($r('sys.string.ohos_lab_location')) - } - for (let item of this.tt) { - arr.push($r('sys.string.ohos_lab_microphone')) - } - } - - build() { - Column() { - Text($r('app.string.ohos_lab_microphone')) - Column() { - Text($r('sys.string.ohos_id_text_font_family_regular')) - Text($r('sys.string'.concat('.ohos_id_text_font_family_regular'))) - Image($rawfile(this.raw)) - TextInput({ text: $r('sys.string.ohos_desc_manage_local_accounts') }) - Text($r(this.str1)) - Text($r(this.str2)) - Select(new Array( - { value: 'aaa', icon: $r("sys.media.ohos_ic_public_play_last") }, - { value: 'bbb', icon: $r("sys.media.ohos_ic_public_play_last") }, - { value: 'ccc', icon: $r("sys.media.ohos_ic_public_play_last") }, - { value: 'ddd', icon: $r("sys.media.ohos_ic_public_play_last") } - )) - Image($r('sys.media.ohos_ic_public_arrow_left')) - .margin({ - top: $r('sys.float.ohos_id_alpha_content_primary'), - bottom: $r('sys.float.ohos_id_alpha_content_primary_dark') - } as Margin) - ImageAnimator().images([ - { - src: $r('sys.media.ohos_ic_public_arrow_left') - }, - { - src: $r('sys.media.ohos_ic_public_arrow_left') - }, - ]) - } - } - } -} \ No newline at end of file diff --git a/arkui-plugins/test/demo/mock/resource/resource-in-property.ets b/arkui-plugins/test/demo/mock/resource/resource-in-property.ets deleted file mode 100644 index 3776151bd..000000000 --- a/arkui-plugins/test/demo/mock/resource/resource-in-property.ets +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2025 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. - */ - -import { Component, $r, $rawfile, Column, Text, Image, Resource } from "@ohos.arkui.component" - -let i: Resource = $r('sys.symbol.ohos_trash'); - -@Component -struct ResourceComponent { - private aa: string = 'app.photo.png'; - private str: Resource = $r('sys.string.ohos_desc_accelerometer'); - private icon: Resource = $rawfile(this.aa); - build() { - Column() { - Text(this.str) - Text(i) - Image(this.icon) - } - } -} \ No newline at end of file diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/resource/resource-in-build.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/resource/resource-in-build.test.ts index b194c8cea..ab9a379ca 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/resource/resource-in-build.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/resource/resource-in-build.test.ts @@ -38,31 +38,25 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` - import { memo as memo } from "arkui.stateManagement.runtime"; - import { _rawfile as _rawfile } from "arkui.component.resources"; - -import { _r as _r } from "arkui.component.resources"; - import { ImageAnimatorAttribute as ImageAnimatorAttribute } from "arkui.component.imageAnimator"; - import { ImageAttribute as ImageAttribute } from "arkui.component.image"; - +import { _r as _r } from "arkui.component.resources"; +import { LayoutCallback as LayoutCallback } from "arkui.component.customComponent"; +import { CustomComponentV2 as CustomComponentV2 } from "arkui.component.customComponent"; import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; - -import { Component as Component, $r as $r, $rawfile as $rawfile, Column as Column, Text as Text, Image as Image, TextInput as TextInput, Select as Select, SelectOption as SelectOption, Margin as Margin, ImageAnimator as ImageAnimator } from "@ohos.arkui.component"; - +import { Component as Component, $r as $r, $rawfile as $rawfile, Column as Column, Text as Text, Image as Image, TextInput as TextInput, Select as Select, SelectOption as SelectOption, Margin as Margin, ImageAnimator as ImageAnimator, Resource as Resource } from "@ohos.arkui.component"; function main() {} - - -@Component({freezeWhenInactive:false}) final struct ResourceComponent extends CustomComponent { +@Component() final struct ResourceComponent extends CustomComponent { public __initializeStruct(initializers: __Options_ResourceComponent | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_str1 = ((({let gensym___147578113 = initializers; (((gensym___147578113) == (null)) ? undefined : gensym___147578113.str1)})) ?? ("app.media.ri")); this.__backing_str2 = ((({let gensym___220149772 = initializers; (((gensym___220149772) == (null)) ? undefined : gensym___220149772.str2)})) ?? ("app.photo2.png")); + this.__backing_numbers = ((({let gensym___ = initializers; + (((gensym___) == (null)) ? undefined : gensym___.numbers)})) ?? (["0", "1", "3", "5", "8"])); } public __updateStruct(initializers: __Options_ResourceComponent | undefined): void {} @@ -86,41 +80,59 @@ function main() {} public set str2(value: string) { this.__backing_str2 = value; } + private __backing_numbers?: Array; + + public get numbers(): Array { + return (this.__backing_numbers as Array); + } + + public set numbers(value: Array) { + this.__backing_numbers = value; + } + public aboutToAppear() { + let arr: Array = new Array(); + for (let i = 0;((i) < (5));(i++)) { + arr.push(_r(16777216, 10003, "com.example.mock", "entry")); + } + for (let item of this.numbers) { + arr.push(_r(16777216, 10003, "com.example.mock", "entry")); + } + } - @memo() public _build(@memo() style: ((instance: ResourceComponent)=> ResourceComponent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_ResourceComponent | undefined): void { + @memo() public build() { Column(undefined, (() => { - Text(undefined, _r("", "", "app.string.app_name")); - Image(undefined, _rawfile("", "", "app.photo.png")); + Text(undefined, _r(16777216, 10003, "com.example.mock", "entry")); + Image(undefined, _rawfile(0, 30000, "com.example.mock", "entry", "app.mock.txt")); TextInput(undefined, { - text: _r("", "", "app.string.input_content"), + text: _r(16777220, 10003, "com.example.mock", "entry"), }); - Text(undefined, _r("", "", this.str1)); - Text(undefined, _r("", "", this.str2)); + Text(undefined, _r(-1, -1, "com.example.mock", "entry", this.str1)); + Text(undefined, _r(-1, -1, "com.example.mock", "entry", this.str2)); Select(undefined, new Array({ value: "aaa", - icon: _r("", "", "app.media.selection"), + icon: _r(16777223, 20000, "com.example.mock", "entry"), }, { value: "bbb", - icon: _r("", "", "app.media.selection"), + icon: _r(16777223, 20000, "com.example.mock", "entry"), }, { value: "ccc", - icon: _r("", "", "app.media.selection"), + icon: _r(16777223, 20000, "com.example.mock", "entry"), }, { value: "ddd", - icon: _r("", "", "app.media.selection"), + icon: _r(16777223, 20000, "com.example.mock", "entry"), })); Image(((instance: ImageAttribute): void => { instance.margin(({ - top: _r("", "", "app.float.elements_margin_horizontal_m"), - bottom: _r("", "", "app.float.elements_margin_horizontal_l"), + top: _r(16777222, 10002, "com.example.mock", "entry"), + bottom: _r(16777222, 10002, "com.example.mock", "entry"), } as Margin)); return; - }), _r("", "", "app.media.app_icon")); + }), _r(16777217, 20000, "com.example.mock", "entry")); ImageAnimator(((instance: ImageAnimatorAttribute): void => { instance.images([{ - src: _r("", "", "app.media.aaa"), + src: _r(16777217, 20000, "com.example.mock", "entry"), }, { - src: _r("", "", "app.media.bbb"), + src: _r(16777225, 20000, "com.example.mock", "entry"), }]); return; })); @@ -131,14 +143,13 @@ function main() {} } -@Component({freezeWhenInactive:false}) export interface __Options_ResourceComponent { +@Component() export interface __Options_ResourceComponent { set str1(str1: string | undefined) - get str1(): string | undefined set str2(str2: string | undefined) - get str2(): string | undefined - + set numbers(numbers: Array | undefined) + get numbers(): Array | undefined } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/resource/resource-in-property.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/resource/resource-in-property.test.ts index 3a3946271..6d28f0fb6 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/resource/resource-in-property.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/resource/resource-in-property.test.ts @@ -38,73 +38,57 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` - import { memo as memo } from "arkui.stateManagement.runtime"; - import { _rawfile as _rawfile } from "arkui.component.resources"; - import { _r as _r } from "arkui.component.resources"; - +import { LayoutCallback as LayoutCallback } from "arkui.component.customComponent"; +import { CustomComponentV2 as CustomComponentV2 } from "arkui.component.customComponent"; import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; - import { Component as Component, $r as $r, $rawfile as $rawfile, Column as Column, Text as Text, Image as Image, Resource as Resource } from "@ohos.arkui.component"; let i: Resource; function main() {} -i = _r("", "", "app.string.app_name"); - -@Component({freezeWhenInactive:false}) final struct ResourceComponent extends CustomComponent { +i = _r(16777216, 10003, "com.example.mock", "entry"); +@Component() final struct ResourceComponent extends CustomComponent { public __initializeStruct(initializers: __Options_ResourceComponent | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_str = ((({let gensym___42103502 = initializers; - (((gensym___42103502) == (null)) ? undefined : gensym___42103502.str)})) ?? (_r("", "", "app.string.app_name"))); + (((gensym___42103502) == (null)) ? undefined : gensym___42103502.str)})) ?? (_r(16777216, 10003, "com.example.mock", "entry"))); this.__backing_icon = ((({let gensym___38135554 = initializers; - (((gensym___38135554) == (null)) ? undefined : gensym___38135554.icon)})) ?? (_rawfile("", "", "app.photo.png"))); + (((gensym___38135554) == (null)) ? undefined : gensym___38135554.icon)})) ?? (_rawfile(0, 30000, "com.example.mock", "entry", "app.mock.txt"))); } - public __updateStruct(initializers: __Options_ResourceComponent | undefined): void {} - private __backing_str?: Resource; - public get str(): Resource { return (this.__backing_str as Resource); } - public set str(value: Resource) { this.__backing_str = value; } - private __backing_icon?: Resource; - public get icon(): Resource { return (this.__backing_icon as Resource); } - public set icon(value: Resource) { this.__backing_icon = value; } - - @memo() public _build(@memo() style: ((instance: ResourceComponent)=> ResourceComponent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_ResourceComponent | undefined): void { + @memo() public build() { Column(undefined, (() => { Text(undefined, this.str); Text(undefined, i); Image(undefined, this.icon); })); } - private constructor() {} } -@Component({freezeWhenInactive:false}) export interface __Options_ResourceComponent { +@Component() export interface __Options_ResourceComponent { set str(str: Resource | undefined) - get str(): Resource | undefined set icon(icon: Resource | undefined) - get icon(): Resource | undefined - } `; diff --git a/arkui-plugins/test/ut/ui-plugins/resource/resource-in-build.test.ts b/arkui-plugins/test/ut/ui-plugins/resource/resource-in-build.test.ts deleted file mode 100644 index 7ad500f37..000000000 --- a/arkui-plugins/test/ut/ui-plugins/resource/resource-in-build.test.ts +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (c) 2025 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. - */ - -import * as path from 'path'; -import { PluginTester } from '../../../utils/plugin-tester'; -import { mockBuildConfig } from '../../../utils/artkts-config'; -import { getRootPath, MOCK_ENTRY_DIR_PATH } from '../../../utils/path-config'; -import { parseDumpSrc } from '../../../utils/parse-string'; -import { uiNoRecheck, recheck } from '../../../utils/plugins'; -import { BuildConfig, PluginTestContext } from '../../../utils/shared-types'; -import { uiTransform } from '../../../../ui-plugins'; -import { Plugins } from '../../../../common/plugin-context'; - -const BUILDER_LAMBDA_DIR_PATH: string = 'resource'; - -const buildConfig: BuildConfig = mockBuildConfig(); -buildConfig.compileFiles = [ - path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, BUILDER_LAMBDA_DIR_PATH, 'resource-in-build.ets'), -]; - -const pluginTester = new PluginTester('test resource transform in build method', buildConfig); - -const parsedTransform: Plugins = { - name: 'resource-in-build', - parsed: uiTransform().parsed, -}; - -const expectedScript: string = ` - -import { memo as memo } from "arkui.stateManagement.runtime"; - -import { _rawfile as _rawfile } from "arkui.component.resources"; - -import { ImageAnimatorAttribute as ImageAnimatorAttribute } from "arkui.component.imageAnimator"; - -import { ImageAttribute as ImageAttribute } from "arkui.component.image"; - -import { _r as _r } from "arkui.component.resources"; - -import { LayoutCallback as LayoutCallback } from "arkui.component.customComponent"; - -import { CustomComponentV2 as CustomComponentV2 } from "arkui.component.customComponent"; - -import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; - -import { Component as Component, $r as $r, $rawfile as $rawfile, Column as Column, Text as Text, Image as Image, TextInput as TextInput, Select as Select, SelectOption as SelectOption, Margin as Margin, ImageAnimator as ImageAnimator, Resource as Resource } from "@kit.ArkUI"; - -function main() {} - - - -@Component() final struct MyStateSample extends CustomComponent { - public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_str1 = ((({let gensym___147578113 = initializers; - (((gensym___147578113) == (null)) ? undefined : gensym___147578113.str1)})) ?? ("app.media.ri")); - this.__backing_str2 = ((({let gensym___220149772 = initializers; - (((gensym___220149772) == (null)) ? undefined : gensym___220149772.str2)})) ?? ("app.photo2.png")); - this.__backing_raw = ((({let gensym___241810043 = initializers; - (((gensym___241810043) == (null)) ? undefined : gensym___241810043.raw)})) ?? ("app.photo.png")); - this.__backing_tt = ((({let gensym___198287964 = initializers; - (((gensym___198287964) == (null)) ? undefined : gensym___198287964.tt)})) ?? (["0", "1", "3", "5", "8"])); - } - - public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} - - private __backing_str1?: string; - - public get str1(): string { - return (this.__backing_str1 as string); - } - - public set str1(value: string) { - this.__backing_str1 = value; - } - - private __backing_str2?: string; - - public get str2(): string { - return (this.__backing_str2 as string); - } - - public set str2(value: string) { - this.__backing_str2 = value; - } - - private __backing_raw?: string; - - public get raw(): string { - return (this.__backing_raw as string); - } - - public set raw(value: string) { - this.__backing_raw = value; - } - - private __backing_tt?: Array; - - public get tt(): Array { - return (this.__backing_tt as Array); - } - - public set tt(value: Array) { - this.__backing_tt = value; - } - - public aboutToAppear() { - let arr: Array = new Array(); - for (let i = 0;((i) < (5));(i++)) { - arr.push(_r(125829791, 10003, "com.example.myapplication", "entry")); - } - for (let item of this.tt) { - arr.push(_r(125829775, 10003, "com.example.myapplication", "entry")); - } - } - - @memo() public build() { - Column(undefined, (() => { - Text(undefined, $r("app.string.ohos_lab_microphone")); - Column(undefined, (() => { - Text(undefined, _r(125829694, 10003, "com.example.myapplication", "entry")); - Text(undefined, _r(-1, -1, "com.example.myapplication", "entry", "sys.string".concat(".ohos_id_text_font_family_regular"))); - Image(undefined, _rawfile(-1, 30000, "com.example.myapplication", "entry", this.raw)); - TextInput(undefined, { - text: _r(125829826, 10003, "com.example.myapplication", "entry"), - }); - Text(undefined, _r(-1, -1, "com.example.myapplication", "entry", this.str1)); - Text(undefined, _r(-1, -1, "com.example.myapplication", "entry", this.str2)); - Select(undefined, new Array({ - value: "aaa", - icon: _r(125830397, 20000, "com.example.myapplication", "entry"), - }, { - value: "bbb", - icon: _r(125830397, 20000, "com.example.myapplication", "entry"), - }, { - value: "ccc", - icon: _r(125830397, 20000, "com.example.myapplication", "entry"), - }, { - value: "ddd", - icon: _r(125830397, 20000, "com.example.myapplication", "entry"), - })); - Image(((instance: ImageAttribute): void => { - instance.margin(({ - top: _r(125829369, 10002, "com.example.myapplication", "entry"), - bottom: _r(125829370, 10002, "com.example.myapplication", "entry"), - } as Margin)); - return; - }), _r(125830087, 20000, "com.example.myapplication", "entry")); - ImageAnimator(((instance: ImageAnimatorAttribute): void => { - instance.images([{ - src: _r(125830087, 20000, "com.example.myapplication", "entry"), - }, { - src: _r(125830087, 20000, "com.example.myapplication", "entry"), - }]); - return; - })); - })); - })); - } - - private constructor() {} - -} - -@Component() export interface __Options_MyStateSample { - set str1(str1: string | undefined) - - get str1(): string | undefined - set str2(str2: string | undefined) - - get str2(): string | undefined - set raw(raw: string | undefined) - - get raw(): string | undefined - set tt(tt: Array | undefined) - - get tt(): Array | undefined - -} -`; - -function testParsedAndCheckedTransformer(this: PluginTestContext): void { - expect(parseDumpSrc(this.scriptSnapshot ?? '')).toBe(parseDumpSrc(expectedScript)); -} - -pluginTester.run( - 'test resource transform in build method', - [parsedTransform, uiNoRecheck, recheck], - { - 'checked:ui-no-recheck': [testParsedAndCheckedTransformer], - }, - { - stopAfter: 'checked', - } -); diff --git a/arkui-plugins/test/ut/ui-plugins/resource/resource-in-property.test.ts b/arkui-plugins/test/ut/ui-plugins/resource/resource-in-property.test.ts deleted file mode 100644 index 77f2c7f59..000000000 --- a/arkui-plugins/test/ut/ui-plugins/resource/resource-in-property.test.ts +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2025 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. - */ - -import * as path from 'path'; -import { PluginTester } from '../../../utils/plugin-tester'; -import { mockBuildConfig } from '../../../utils/artkts-config'; -import { getRootPath, MOCK_ENTRY_DIR_PATH } from '../../../utils/path-config'; -import { parseDumpSrc } from '../../../utils/parse-string'; -import { uiNoRecheck, recheck } from '../../../utils/plugins'; -import { BuildConfig, PluginTestContext } from '../../../utils/shared-types'; -import { uiTransform } from '../../../../ui-plugins'; -import { Plugins } from '../../../../common/plugin-context'; - -const BUILDER_LAMBDA_DIR_PATH: string = 'resource'; - -const buildConfig: BuildConfig = mockBuildConfig(); -buildConfig.compileFiles = [ - path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, BUILDER_LAMBDA_DIR_PATH, 'resource-in-property.ets'), -]; - -const pluginTester = new PluginTester('test resource transform in property', buildConfig); - -const parsedTransform: Plugins = { - name: 'resource-in-property', - parsed: uiTransform().parsed -}; - -const expectedScript: string = ` - -import { memo as memo } from "arkui.stateManagement.runtime"; - -import { _rawfile as _rawfile } from "arkui.component.resources"; - -import { _r as _r } from "arkui.component.resources"; - -import { LayoutCallback as LayoutCallback } from "arkui.component.customComponent"; - -import { CustomComponentV2 as CustomComponentV2 } from "arkui.component.customComponent"; - -import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; - -import { Component as Component, $r as $r, $rawfile as $rawfile, Column as Column, Text as Text, Image as Image, Resource as Resource } from "@ohos.arkui.component"; - -let i: Resource; - -function main() {} - -i = _r(125830645, 40000, "com.example.myapplication", "entry"); - -@Component() final struct ResourceComponent extends CustomComponent { - public __initializeStruct(initializers: __Options_ResourceComponent | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_aa = ((({let gensym___248008024 = initializers; - (((gensym___248008024) == (null)) ? undefined : gensym___248008024.aa)})) ?? ("app.photo.png")); - this.__backing_str = ((({let gensym___249074315 = initializers; - (((gensym___249074315) == (null)) ? undefined : gensym___249074315.str)})) ?? (_r(125829844, 10003, "com.example.myapplication", "entry"))); - this.__backing_icon = ((({let gensym___193492277 = initializers; - (((gensym___193492277) == (null)) ? undefined : gensym___193492277.icon)})) ?? (_rawfile(-1, 30000, "com.example.myapplication", "entry", this.aa))); - } - - public __updateStruct(initializers: __Options_ResourceComponent | undefined): void {} - - private __backing_aa?: string; - - public get aa(): string { - return (this.__backing_aa as string); - } - - public set aa(value: string) { - this.__backing_aa = value; - } - - private __backing_str?: Resource; - - public get str(): Resource { - return (this.__backing_str as Resource); - } - - public set str(value: Resource) { - this.__backing_str = value; - } - - private __backing_icon?: Resource; - - public get icon(): Resource { - return (this.__backing_icon as Resource); - } - - public set icon(value: Resource) { - this.__backing_icon = value; - } - - @memo() public build() { - Column(undefined, (() => { - Text(undefined, this.str); - Text(undefined, i); - Image(undefined, this.icon); - })); - } - - private constructor() {} - -} - -@Component() export interface __Options_ResourceComponent { - set aa(aa: string | undefined) - - get aa(): string | undefined - set str(str: Resource | undefined) - - get str(): Resource | undefined - set icon(icon: Resource | undefined) - - get icon(): Resource | undefined - -} -`; - -function testParsedAndCheckedTransformer(this: PluginTestContext): void { - expect(parseDumpSrc(this.scriptSnapshot ?? '')).toBe(parseDumpSrc(expectedScript)); -} - -pluginTester.run( - 'test resource transform in property', - [parsedTransform, uiNoRecheck, recheck], - { - 'checked:ui-no-recheck': [testParsedAndCheckedTransformer], - }, - { - stopAfter: 'checked', - } -); diff --git a/arkui-plugins/test/utils/artkts-config.ts b/arkui-plugins/test/utils/artkts-config.ts index cbe7f33db..d60db9b48 100644 --- a/arkui-plugins/test/utils/artkts-config.ts +++ b/arkui-plugins/test/utils/artkts-config.ts @@ -21,13 +21,17 @@ import { changeFileExtension, ensurePathExists, getFileName, + getResourcePath, getRootPath, + MOCK_BUNDLE_NAME, MOCK_DEP_ANALYZER_PATH, MOCK_ENTRY_DIR_PATH, MOCK_ENTRY_FILE_NAME, MOCK_OUTPUT_CACHE_PATH, MOCK_OUTPUT_DIR_PATH, MOCK_OUTPUT_FILE_NAME, + MOCK_RAWFILE_DIR_PATH, + MOCK_RESOURCE_TABLE_FILE_NAME, PANDA_SDK_STDLIB_PATH, STDLIB_ESCOMPAT_PATH, STDLIB_PATH, @@ -36,6 +40,7 @@ import { import { ArkTSConfigContextCache } from './cache'; import { BuildConfig, CompileFileInfo, DependentModule } from './shared-types'; import { setUpSoPath } from './global'; +import { ProjectConfig } from '../../common/plugin-context'; export interface ArkTSConfigObject { compilerOptions: { @@ -75,6 +80,10 @@ export interface ArktsConfigBuilder { mergedAbcFile: string; // logger: Logger; // TODO isDebug: boolean; + projectConfig: ProjectConfig; + + withBuildConfig(buildConfig: BuildConfig): this; + withProjectConfig(projectConfig: ProjectConfig): this; clear(): void; } @@ -162,28 +171,60 @@ function mockBuildConfig(): BuildConfig { }; } +function mockProjectConfig(): ProjectConfig { + return { + bundleName: MOCK_BUNDLE_NAME, + moduleName: 'entry', + cachePath: path.resolve(getRootPath(), MOCK_OUTPUT_CACHE_PATH), + dependentModuleList: [], + appResource: path.resolve(getResourcePath(), MOCK_RESOURCE_TABLE_FILE_NAME), + rawFileResource: path.resolve(getResourcePath(), MOCK_RAWFILE_DIR_PATH), + buildLoaderJson: '', + hspResourcesMap: false, + compileHar: false, + byteCodeHar: false, + uiTransformOptimization: false, + resetBundleName: false, + allowEmptyBundleName: false, + moduleType: 'entry', + moduleRootPath: path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH), + aceModuleJsonPath: '', + }; +} + class MockArktsConfigBuilder implements ArktsConfigBuilder { hashId: string; - buildConfig: BuildConfig; - entryFiles: Set; - compileFiles: Map; - outputDir: string; - cacheDir: string; - pandaSdkPath: string; - apiPath: string; - kitsPath: string; - packageName: string; - sourceRoots: string[]; - moduleRootPath: string; - dependentModuleList: DependentModule[]; - moduleInfos: Map; - mergedAbcFile: string; + buildConfig!: BuildConfig; + entryFiles!: Set; + compileFiles!: Map; + outputDir!: string; + cacheDir!: string; + pandaSdkPath!: string; + apiPath!: string; + kitsPath!: string; + packageName!: string; + sourceRoots!: string[]; + moduleRootPath!: string; + dependentModuleList!: DependentModule[]; + moduleInfos!: Map; + mergedAbcFile!: string; isDebug: boolean; + projectConfig: ProjectConfig; - constructor(hashId: string, buildConfig?: BuildConfig) { + constructor(hashId: string, buildConfig?: BuildConfig, projectConfig?: ProjectConfig) { this.hashId = hashId; const _buildConfig: BuildConfig = buildConfig ?? mockBuildConfig(); + this._setBuildConfig(_buildConfig); + + const _projectConfig: ProjectConfig = projectConfig ?? mockProjectConfig(); + this.projectConfig = _projectConfig; + + this.isDebug = true; + } + + private _setBuildConfig(buildConfig: BuildConfig): void { + const _buildConfig: BuildConfig = buildConfig; this.buildConfig = _buildConfig; this.entryFiles = new Set(_buildConfig.compileFiles as string[]); this.outputDir = _buildConfig.loaderOutPath as string; @@ -195,7 +236,6 @@ class MockArktsConfigBuilder implements ArktsConfigBuilder { this.sourceRoots = _buildConfig.sourceRoots as string[]; this.moduleRootPath = path.resolve(_buildConfig.moduleRootPath as string); this.dependentModuleList = _buildConfig.dependentModuleList as DependentModule[]; - this.isDebug = true; this.compileFiles = new Map(); this.moduleInfos = new Map(); @@ -306,9 +346,19 @@ class MockArktsConfigBuilder implements ArktsConfigBuilder { }); } + withBuildConfig(buildConfig: BuildConfig): this { + this._setBuildConfig(buildConfig); + return this; + } + + withProjectConfig(projectConfig: ProjectConfig): this { + this.projectConfig = projectConfig; + return this; + } + clear(): void { ArkTSConfigContextCache.getInstance().delete(this.hashId); } } -export { mockBuildConfig, MockArktsConfigBuilder }; +export { mockBuildConfig, mockProjectConfig, MockArktsConfigBuilder }; diff --git a/arkui-plugins/test/utils/compile.ts b/arkui-plugins/test/utils/compile.ts index 46f9fe81b..9dd537855 100644 --- a/arkui-plugins/test/utils/compile.ts +++ b/arkui-plugins/test/utils/compile.ts @@ -201,6 +201,7 @@ function createContextForExternalCompilation(jobInfo: JobInfo): arkts.Context { function compileAbcWithExternal(emitter: EventEmitter, jobInfo: JobInfo, tracing: TraceOptions): void { MockPluginDriver.getInstance().initPlugins(jobInfo.plugins ?? []); + MockPluginDriver.getInstance().getPluginContext().setProjectConfig(jobInfo.projectConfig!); const context = createContextFromString(jobInfo.filePaths!); MockPluginDriver.getInstance().getPluginContext().setContextPtr(context.peer); const stopAfter = jobInfo.stopAfter!; @@ -243,6 +244,7 @@ function compileAbcWithExternal(emitter: EventEmitter, jobInfo: Jo function compileAbc(emitter: EventEmitter, jobInfo: JobInfo, tracing: TraceOptions): void { MockPluginDriver.getInstance().initPlugins(jobInfo.plugins ?? []); + MockPluginDriver.getInstance().getPluginContext().setProjectConfig(jobInfo.projectConfig!); const context = createContextForAbcCompilation(jobInfo); MockPluginDriver.getInstance().getPluginContext().setContextPtr(context.peer); const stopAfter = jobInfo.stopAfter!; @@ -282,6 +284,7 @@ function compileAbc(emitter: EventEmitter, jobInfo: JobInfo, traci function compileExternalProgram(emitter: EventEmitter, jobInfo: JobInfo, tracing: TraceOptions): void { MockPluginDriver.getInstance().initPlugins(jobInfo.plugins ?? []); + MockPluginDriver.getInstance().getPluginContext().setProjectConfig(jobInfo.projectConfig!); const context = createContextForExternalCompilation(jobInfo); MockPluginDriver.getInstance().getPluginContext().setContextPtr(context.peer); arkts.proceedToState(arkts.Es2pandaContextState.ES2PANDA_STATE_PARSED, context.peer); diff --git a/arkui-plugins/test/utils/path-config.ts b/arkui-plugins/test/utils/path-config.ts index 4712832cf..ddf26c1e1 100644 --- a/arkui-plugins/test/utils/path-config.ts +++ b/arkui-plugins/test/utils/path-config.ts @@ -16,7 +16,7 @@ import * as fs from 'fs'; import * as path from 'path'; -export const ARKTS_CONFIG_FILE_PATH: string = 'arktsconfig.json';; +export const ARKTS_CONFIG_FILE_PATH: string = 'arktsconfig.json'; export const PANDA_SDK_STDLIB_PATH: string = 'lib'; export const STDLIB_PATH: string = 'stdlib'; export const STDLIB_STD_PATH: string = 'stdlib/std'; @@ -29,6 +29,9 @@ export const MOCK_OUTPUT_FILE_NAME: string = 'entry.abc'; export const MOCK_DEP_ANALYZER_PATH: string = 'bin/dependency_analyzer'; export const MOCK_FILE_DEP_FILE_NAME: string = 'file_dependencies.json'; export const MOCK_DEP_INPUT_FILE_NAME: string = 'depInput.txt'; +export const MOCK_RESOURCE_TABLE_FILE_NAME: string = 'ResourceTable.txt'; +export const MOCK_BUNDLE_NAME: string = 'com.example.mock'; +export const MOCK_RAWFILE_DIR_PATH: string = 'rawfile'; export const ETS_SUFFIX: string = '.ets'; export const ABC_SUFFIX: string = '.abc'; export const DECL_ETS_SUFFIX: string = '.d.ets'; @@ -37,6 +40,10 @@ function getRootPath(): string { return path.resolve(__dirname, '..', '..', 'test'); } +function getResourcePath(): string { + return path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, 'resource'); +} + function changeFileExtension(file: string, targetExt: string, originExt = ''): string { const currentExt: string = originExt.length === 0 ? path.extname(file) : originExt; const fileWithoutExt: string = file.substring(0, file.lastIndexOf(currentExt)); @@ -62,4 +69,4 @@ function ensurePathExists(filePath: string): void { } } -export { getRootPath, changeFileExtension, getFileName, ensurePathExists }; +export { getRootPath, getResourcePath, changeFileExtension, getFileName, ensurePathExists }; diff --git a/arkui-plugins/test/utils/plugin-tester.ts b/arkui-plugins/test/utils/plugin-tester.ts index d10c4ebd3..1fe094237 100644 --- a/arkui-plugins/test/utils/plugin-tester.ts +++ b/arkui-plugins/test/utils/plugin-tester.ts @@ -26,7 +26,7 @@ import { } from './shared-types'; import { HashGenerator } from './hash-generator'; import { PluginTestContextCache } from './cache'; -import { Plugins, PluginState } from '../../common/plugin-context'; +import { Plugins, PluginState, ProjectConfig } from '../../common/plugin-context'; import { concatObject } from './serializable'; import { ProcessorBuilder } from './processor-builder'; import { MainProcessor } from './processors/main-processor'; @@ -48,6 +48,7 @@ type TestHooks = { export interface PluginTesterOptions { stopAfter: PluginState; buildConfig?: BuildConfig; + projectConfig?: ProjectConfig; tracing?: TraceOptions; } @@ -58,7 +59,7 @@ class PluginTester { private taskProcessor?: Processor; private resolve?: Promise; - constructor(describe: string, buildConfig?: BuildConfig) { + constructor(describe: string, buildConfig?: BuildConfig, projectConfig?: ProjectConfig) { this.describe = describe; this.hashId = HashGenerator.getInstance().dynamicSha1Id(describe, 13); this.configBuilder = new MockArktsConfigBuilder(this.hashId, buildConfig); @@ -175,6 +176,7 @@ class PluginTester { MainProcessor, this.hashId, this.configBuilder.buildConfig, + this.configBuilder.projectConfig, tracing ); return this.taskProcessor.invokeWorkers(plugins, stopAfter); @@ -188,7 +190,10 @@ class PluginTester { testHooks?: TestHooks ): void { if (!!options.buildConfig) { - this.configBuilder = new MockArktsConfigBuilder(this.hashId, options.buildConfig); + this.configBuilder = this.configBuilder.withBuildConfig(options.buildConfig); + } + if (!!options.projectConfig) { + this.configBuilder = this.configBuilder.withProjectConfig(options.projectConfig); } const that = this; diff --git a/arkui-plugins/test/utils/processor-builder.ts b/arkui-plugins/test/utils/processor-builder.ts index bb68e31e6..7be32e773 100644 --- a/arkui-plugins/test/utils/processor-builder.ts +++ b/arkui-plugins/test/utils/processor-builder.ts @@ -13,16 +13,25 @@ * limitations under the License. */ +import { ProjectConfig } from 'common/plugin-context'; import { BuildConfig, Processor, TraceOptions } from './shared-types'; class ProcessorBuilder { static build( - Processor: { new (hashId: string, buildConfig?: BuildConfig, tracing?: TraceOptions): Processor }, + Processor: { + new ( + hashId: string, + buildConfig?: BuildConfig, + projectConfig?: ProjectConfig, + tracing?: TraceOptions + ): Processor; + }, hashId: string, buildConfig?: BuildConfig, + projectConfig?: ProjectConfig, tracing?: TraceOptions ): Processor { - return new Processor(hashId, buildConfig, tracing); + return new Processor(hashId, buildConfig, projectConfig, tracing); } } diff --git a/arkui-plugins/test/utils/processors/base-processor.ts b/arkui-plugins/test/utils/processors/base-processor.ts index d60d269e0..53e79ea52 100644 --- a/arkui-plugins/test/utils/processors/base-processor.ts +++ b/arkui-plugins/test/utils/processors/base-processor.ts @@ -13,20 +13,21 @@ * limitations under the License. */ -import { Plugins, PluginState } from "common/plugin-context"; -import { mockBuildConfig } from "../artkts-config"; -import { ArkTSConfigContextCache } from "../cache"; -import { BuildConfig, CompileFileInfo, Processor, TraceOptions } from "../shared-types"; +import { Plugins, PluginState, ProjectConfig } from '../../../common/plugin-context'; +import { mockBuildConfig, mockProjectConfig } from '../artkts-config'; +import { ArkTSConfigContextCache } from '../cache'; +import { BuildConfig, CompileFileInfo, Processor, TraceOptions } from '../shared-types'; abstract class BaseProcessor implements Processor { hashId: string; buildConfig: BuildConfig; + projectConfig: ProjectConfig; tracing: TraceOptions; cacheDir: string; arktsConfigFile: string; compileFiles: Map; - constructor(hashId: string, buildConfig?: BuildConfig, tracing?: TraceOptions) { + constructor(hashId: string, buildConfig?: BuildConfig, projectConfig?: ProjectConfig, tracing?: TraceOptions) { this.hashId = hashId; this.tracing = tracing ?? { externalSourceNames: [] }; @@ -35,6 +36,9 @@ abstract class BaseProcessor implements Processor { this.cacheDir = _buildConfig.cachePath; this.arktsConfigFile = this.getArktsConfigFile(); this.compileFiles = this.getCompileFiles(); + + const _projectConfig: ProjectConfig = projectConfig ?? mockProjectConfig(); + this.projectConfig = _projectConfig; } private getArktsConfigFile(): string { @@ -62,4 +66,4 @@ abstract class BaseProcessor implements Processor { abstract clear(): void; } -export { BaseProcessor }; \ No newline at end of file +export { BaseProcessor }; diff --git a/arkui-plugins/test/utils/processors/main-processor.ts b/arkui-plugins/test/utils/processors/main-processor.ts index e033948d7..4b8f2399d 100644 --- a/arkui-plugins/test/utils/processors/main-processor.ts +++ b/arkui-plugins/test/utils/processors/main-processor.ts @@ -26,11 +26,8 @@ import { import { BaseProcessor } from './base-processor'; import { PluginTestContextCache } from '../cache'; import { concatObject, serializable } from '../serializable'; -import { Plugins, PluginState } from '../../../common/plugin-context'; -import { - createGlobalConfig, - destroyGlobalConfig, -} from '../global'; +import { Plugins, PluginState, ProjectConfig } from '../../../common/plugin-context'; +import { createGlobalConfig, destroyGlobalConfig } from '../global'; import { compileAbcWithExternal } from '../compile'; class MainProcessor extends BaseProcessor { @@ -38,8 +35,8 @@ class MainProcessor extends BaseProcessor { readonly emitter: EventEmitter = new EventEmitter(); - constructor(hashId: string, buildConfig?: BuildConfig, tracing?: TraceOptions) { - super(hashId, buildConfig, tracing); + constructor(hashId: string, buildConfig?: BuildConfig, projectConfig?: ProjectConfig, tracing?: TraceOptions) { + super(hashId, buildConfig, projectConfig, tracing); this.filePaths = this.getCompileFilePaths(); } @@ -65,19 +62,16 @@ class MainProcessor extends BaseProcessor { }); } - private assignTask( - fileInfo: CompileFileInfo, - plugins: Plugins[], - stopAfter?: PluginState - ): void { + private assignTask(fileInfo: CompileFileInfo, plugins: Plugins[], stopAfter?: PluginState): void { const jobInfo: JobInfo = { id: 'compile-abc-with-external', isCompileAbc: CompileStrategy.ABC_WTIH_EXTERNAL, compileFileInfo: fileInfo, buildConfig: serializable(this.buildConfig), + projectConfig: serializable(this.projectConfig), plugins, stopAfter, - filePaths: this.filePaths + filePaths: this.filePaths, }; compileAbcWithExternal(this.emitter, jobInfo, this.tracing); } diff --git a/arkui-plugins/test/utils/processors/task-processor.ts b/arkui-plugins/test/utils/processors/task-processor.ts index 5371d14a3..a66b89eb4 100644 --- a/arkui-plugins/test/utils/processors/task-processor.ts +++ b/arkui-plugins/test/utils/processors/task-processor.ts @@ -37,7 +37,7 @@ import { import { FileDependencyContextCache, PluginTestContextCache } from '../cache'; import { HashGenerator } from '../hash-generator'; import { createGlobalConfig, createGlobalContextPtr, destroyGlobalConfig, destroyGlobalContextPtr } from '../global'; -import { Plugins, PluginState } from '../../../common/plugin-context'; +import { Plugins, PluginState, ProjectConfig } from '../../../common/plugin-context'; import { concatObject, serializable } from '../serializable'; import { compileAbc, compileExternalProgram } from '../compile'; import { BaseProcessor } from './base-processor'; @@ -242,8 +242,8 @@ class TaskProcessor extends BaseProcessor { readonly emitter: EventEmitter = new EventEmitter(); private worker!: WorkerInfo; - constructor(hashId: string, buildConfig?: BuildConfig, tracing?: TraceOptions) { - super(hashId, buildConfig, tracing); + constructor(hashId: string, buildConfig?: BuildConfig, projectConfig?: ProjectConfig, tracing?: TraceOptions) { + super(hashId, buildConfig, projectConfig, tracing); this.entryFiles = new Set(this.buildConfig.compileFiles as string[]); this.depAnalyzerPath = this.buildConfig.depAnalyzerPath; this.depInputFile = path.resolve(this.buildConfig.cachePath, this.hashId, MOCK_DEP_INPUT_FILE_NAME); @@ -413,6 +413,7 @@ class TaskProcessor extends BaseProcessor { processingJobs.add(job.id); jobInfo.compileFileInfo = this.compileFiles.get(job.fileList[0]); jobInfo.buildConfig = serializable(this.buildConfig); + jobInfo.projectConfig = serializable(this.projectConfig); jobInfo.plugins = plugins; jobInfo.globalContextPtr = globalContextPtr; jobInfo.stopAfter = stopAfter; diff --git a/arkui-plugins/test/utils/shared-types.ts b/arkui-plugins/test/utils/shared-types.ts index 415e407be..83c365d53 100644 --- a/arkui-plugins/test/utils/shared-types.ts +++ b/arkui-plugins/test/utils/shared-types.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import type { Plugins, PluginState } from '../../common/plugin-context'; +import type { Plugins, PluginState, ProjectConfig } from '../../common/plugin-context'; export type PluginTesterId = string | `${string}:${string}`; @@ -61,9 +61,10 @@ export interface BuildConfig { sourceRoots: string[]; moduleRootPath: string; dependentModuleList: DependentModule[]; + projectConfig?: ProjectConfig; } -export type ModuleType = 'har' | string; // TODO: module type unclear +export type ModuleType = 'har' | 'feature' | 'entry' | string; // TODO: module type unclear export interface DependentModule { packageName: string; @@ -79,6 +80,7 @@ export interface JobInfo { isCompileAbc: CompileStrategy; compileFileInfo?: CompileFileInfo; buildConfig?: BuildConfig; + projectConfig?: ProjectConfig; plugins?: Plugins[]; globalContextPtr?: number; stopAfter?: PluginState; @@ -124,6 +126,7 @@ export type ProcessEvent = { export interface Processor { hashId: string; buildConfig: BuildConfig; + projectConfig?: ProjectConfig; tracing: TraceOptions; cacheDir: string; arktsConfigFile: string; diff --git a/arkui-plugins/ui-plugins/checked-transformer.ts b/arkui-plugins/ui-plugins/checked-transformer.ts index 0c7b67ce7..31ec5a48e 100644 --- a/arkui-plugins/ui-plugins/checked-transformer.ts +++ b/arkui-plugins/ui-plugins/checked-transformer.ts @@ -145,9 +145,10 @@ export class CheckedTransformer extends AbstractVisitor { return structFactory.tranformInterfaceMembers(node, this.externalSourceName); } else if (findCanAddMemoFromArrowFunction(node)) { return addMemoAnnotation(node); - } else if (arkts.isEtsScript(node) && ImportCollector.getInstance().importInfos.length > 0) { + } else if (arkts.isEtsScript(node)) { ImportCollector.getInstance().insertCurrentImports(this.program); - LogCollector.getInstance().emitLogInfo(this.projectConfig); + LogCollector.getInstance().shouldIgnoreError(this.projectConfig?.ignoreError); + LogCollector.getInstance().emitLogInfo(); } else if (arkts.isTSTypeAliasDeclaration(node)) { return structFactory.transformTSTypeAlias(node); } else if (arkts.isBlockStatement(node)) { diff --git a/arkui-plugins/ui-plugins/index.ts b/arkui-plugins/ui-plugins/index.ts index 6c780b2f6..8751ffc4f 100644 --- a/arkui-plugins/ui-plugins/index.ts +++ b/arkui-plugins/ui-plugins/index.ts @@ -16,7 +16,7 @@ import * as arkts from '@koalaui/libarkts'; import { ComponentTransformer } from './component-transformer'; import { CheckedTransformer } from './checked-transformer'; -import { Plugins, PluginContext } from '../common/plugin-context'; +import { Plugins, PluginContext, ProjectConfig } from '../common/plugin-context'; import { ProgramVisitor } from '../common/program-visitor'; import { EXTERNAL_SOURCE_PREFIX_NAMES } from '../common/predefines'; import { debugDump, debugLog, getDumpFileName } from '../common/debug'; @@ -142,7 +142,11 @@ function checkedProgramVisit(program: arkts.Program, context: PluginContext): ar debugLog('[SKIP PHASE] phase: ui-checked, moduleName: ', program.moduleName); } else { debugLog('[CANT SKIP PHASE] phase: ui-checked, moduleName: ', program.moduleName); - const checkedTransformer = new CheckedTransformer(context.getProjectConfig()); + const projectConfig: ProjectConfig | undefined = context.getProjectConfig(); + if (projectConfig && !projectConfig.appResource) { + projectConfig.ignoreError = true; + } + const checkedTransformer = new CheckedTransformer(projectConfig); const programVisitor = new ProgramVisitor({ pluginName: uiTransform.name, state: arkts.Es2pandaContextState.ES2PANDA_STATE_CHECKED, diff --git a/arkui-plugins/ui-plugins/struct-translators/utils.ts b/arkui-plugins/ui-plugins/struct-translators/utils.ts index c44002d9f..eba0ce6a4 100644 --- a/arkui-plugins/ui-plugins/struct-translators/utils.ts +++ b/arkui-plugins/ui-plugins/struct-translators/utils.ts @@ -189,9 +189,6 @@ function readAppResource( aceBuildJson: LoaderJson, rawfile: Set ): void { - if (!projectConfig.appResource) { - projectConfig.ignoreError = true; - } if ('hspResourcesMap' in aceBuildJson && aceBuildJson.hspResourcesMap) { readHspResource(aceBuildJson, projectConfig, resourcesList); } diff --git a/koala-wrapper/src/arkts-api/node-utilities/ForInStatement.ts b/koala-wrapper/src/arkts-api/node-utilities/ForInStatement.ts index 5e35ce0f0..40f78ab06 100644 --- a/koala-wrapper/src/arkts-api/node-utilities/ForInStatement.ts +++ b/koala-wrapper/src/arkts-api/node-utilities/ForInStatement.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 diff --git a/koala-wrapper/src/arkts-api/node-utilities/ForOfStatement.ts b/koala-wrapper/src/arkts-api/node-utilities/ForOfStatement.ts index be4911dac..9c8d99a1d 100644 --- a/koala-wrapper/src/arkts-api/node-utilities/ForOfStatement.ts +++ b/koala-wrapper/src/arkts-api/node-utilities/ForOfStatement.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 diff --git a/koala-wrapper/src/arkts-api/node-utilities/ForUpdateStatement.ts b/koala-wrapper/src/arkts-api/node-utilities/ForUpdateStatement.ts index a2085b159..0fa41007b 100644 --- a/koala-wrapper/src/arkts-api/node-utilities/ForUpdateStatement.ts +++ b/koala-wrapper/src/arkts-api/node-utilities/ForUpdateStatement.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 diff --git a/koala-wrapper/src/generated/peers/ForUpdateStatement.ts b/koala-wrapper/src/generated/peers/ForUpdateStatement.ts index 0594d8771..ae39482c3 100644 --- a/koala-wrapper/src/generated/peers/ForUpdateStatement.ts +++ b/koala-wrapper/src/generated/peers/ForUpdateStatement.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 -- Gitee