From 5ff300ed2ff7d5e2bdf9e2a054881cacff4f59e2 Mon Sep 17 00:00:00 2001 From: Bojiang Date: Tue, 1 Apr 2025 20:46:35 +0800 Subject: [PATCH 1/2] jiangbo91@huawei.com fix $r $rawfile `` Signed-off-by: Bojiang Change-Id: I3dac930d0e4b71a513a007e3b209f4ca3a26d2aa --- compiler/src/process_ui_syntax.ts | 2 +- .../resource/resourceTest.js.sample | 58 +++++++++++++++++++ .../resource/resourceTest.ets | 25 ++++++++ .../test/transform_ut/helpers/pathConfig.ts | 2 + 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 compiler/test/transform_ut/application/entry/build/default/cache/default/default@CompileArkTS/esmodule/debug/entry/src/main/ets/pages/utForPartialUpdate/resource/resourceTest.js.sample create mode 100644 compiler/test/transform_ut/application/entry/src/main/ets/pages/utForPartialUpdate/resource/resourceTest.ets diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index 97b281894..0055b2629 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -726,7 +726,7 @@ export function isAnimateToOrImmediately(node: ts.Node): boolean { export function processResourceData(node: ts.CallExpression, filePath: string, previewLog: {isAcceleratePreview: boolean, log: LogInfo[]} = {isAcceleratePreview: false, log: []}): ts.Node { - if (ts.isStringLiteral(node.arguments[0])) { + if (ts.isStringLiteral(node.arguments[0]) || ts.isNoSubstitutionTemplateLiteral(node.arguments[0])) { const resourceData: string[] = (node.arguments[0] as ts.StringLiteral).text.trim().split('.'); const isResourceModule: boolean = resourceData.length && /^\[.*\]$/g.test(resourceData[0]); if (node.expression.getText() === RESOURCE_RAWFILE) { diff --git a/compiler/test/transform_ut/application/entry/build/default/cache/default/default@CompileArkTS/esmodule/debug/entry/src/main/ets/pages/utForPartialUpdate/resource/resourceTest.js.sample b/compiler/test/transform_ut/application/entry/build/default/cache/default/default@CompileArkTS/esmodule/debug/entry/src/main/ets/pages/utForPartialUpdate/resource/resourceTest.js.sample new file mode 100644 index 000000000..f3d898bf4 --- /dev/null +++ b/compiler/test/transform_ut/application/entry/build/default/cache/default/default@CompileArkTS/esmodule/debug/entry/src/main/ets/pages/utForPartialUpdate/resource/resourceTest.js.sample @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022-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. + */ +"use strict"; +if (!("finalizeConstruction" in ViewPU.prototype)) { + Reflect.set(ViewPU.prototype, "finalizeConstruction", () => { }); +} +class Index extends ViewPU { + constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { + super(parent, __localStorage, elmtId, extraInfo); + if (typeof paramsLambda === "function") { + this.paramsGenerator_ = paramsLambda; + } + this.setInitiallyProvidedValue(params); + this.finalizeConstruction(); + } + setInitiallyProvidedValue(params) { + } + updateStateVars(params) { + } + purgeVariableDependenciesOnElmtId(rmElmtId) { + } + aboutToBeDeleted() { + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal(); + } + initialRender() { + this.observeComponentCreation2((elmtId, isInitialRender) => { + Row.create(); + }, Row); + this.observeComponentCreation2((elmtId, isInitialRender) => { + Image.create({ "id": 0, "type": 30000, params: ['foreground.png'], "bundleName": "com.example.application", "moduleName": "application" }); + }, Image); + this.observeComponentCreation2((elmtId, isInitialRender) => { + Image.create({ "id": 0, "type": 30000, params: [`foreground.png`], "bundleName": "com.example.application", "moduleName": "application" }); + }, Image); + Row.pop(); + } + rerender() { + this.updateDirtyElements(); + } + static getEntryName() { + return "Index"; + } +} +registerNamedRoute(() => new Index(undefined, {}), "", { bundleName: "com.example.application", moduleName: "application", pagePath: "pages/utForPartialUpdate/resource/resourceTest", pageFullPath: "application/entry/src/main/ets/pages/utForPartialUpdate/resource/resourceTest", integratedHsp: "false", moduleType: "followWithHap" }); +//# sourceMappingURL=resourceTest.js.map \ No newline at end of file diff --git a/compiler/test/transform_ut/application/entry/src/main/ets/pages/utForPartialUpdate/resource/resourceTest.ets b/compiler/test/transform_ut/application/entry/src/main/ets/pages/utForPartialUpdate/resource/resourceTest.ets new file mode 100644 index 000000000..57402fbdb --- /dev/null +++ b/compiler/test/transform_ut/application/entry/src/main/ets/pages/utForPartialUpdate/resource/resourceTest.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2022-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. + */ +// Reusable test +@Entry +@Component +struct Index { + build() { + Row() { + Image($rawfile('foreground.png')) + Image($rawfile(`foreground.png`)) + } + } +} \ No newline at end of file diff --git a/compiler/test/transform_ut/helpers/pathConfig.ts b/compiler/test/transform_ut/helpers/pathConfig.ts index b12b5d80f..a057a126d 100644 --- a/compiler/test/transform_ut/helpers/pathConfig.ts +++ b/compiler/test/transform_ut/helpers/pathConfig.ts @@ -208,6 +208,8 @@ export const UT_PARTIAL_UPFATE_PAGES: string[] = [ 'v2_component_decorator/reusableV2/reusableV2_initialRender', 'v2_component_decorator/reusableV2/reusableV2_members', 'v2_component_decorator/reusableV2/reusableV2_component_nesting', + + 'resource/resourceTest', ]; export const UT_VALIDATE_PAGES_PREVIEW: string[] = []; -- Gitee From 4bf724fee31eadda720f29991031af82cfb40202 Mon Sep 17 00:00:00 2001 From: Bojiang Date: Wed, 18 Jun 2025 11:12:49 +0800 Subject: [PATCH 2/2] jiangbo91@huawei.com MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `` check 等级修改 Signed-off-by: Bojiang Change-Id: Ibdebd0c8bd2a15c950bc55e8f646265220208da7 --- compiler/src/process_ui_syntax.ts | 43 +++++++++++++++++-------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index 0055b2629..35ef8dc52 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -726,18 +726,22 @@ export function isAnimateToOrImmediately(node: ts.Node): boolean { export function processResourceData(node: ts.CallExpression, filePath: string, previewLog: {isAcceleratePreview: boolean, log: LogInfo[]} = {isAcceleratePreview: false, log: []}): ts.Node { - if (ts.isStringLiteral(node.arguments[0]) || ts.isNoSubstitutionTemplateLiteral(node.arguments[0])) { + let isTemplateString: boolean = false; + if (ts.isNoSubstitutionTemplateLiteral(node.arguments[0])) { + isTemplateString = true; + } + if (ts.isStringLiteral(node.arguments[0]) || isTemplateString) { const resourceData: string[] = (node.arguments[0] as ts.StringLiteral).text.trim().split('.'); const isResourceModule: boolean = resourceData.length && /^\[.*\]$/g.test(resourceData[0]); if (node.expression.getText() === RESOURCE_RAWFILE) { - isResourcefile(node, previewLog, isResourceModule); + isResourcefile(node, previewLog, isResourceModule, isTemplateString); if (resourceData && resourceData[0] && isResourceModule) { return createResourceParam(-1, RESOURCE_TYPE.rawfile, [node.arguments[0]], resourceData[0], true); } else { return createResourceParam(0, RESOURCE_TYPE.rawfile, [node.arguments[0]], '', false); } } else { - return getResourceDataNode(node, previewLog, resourceData, isResourceModule, filePath); + return getResourceDataNode(node, previewLog, resourceData, isResourceModule, filePath, isTemplateString); } } else if (node.expression.getText() === RESOURCE && node.arguments && node.arguments.length) { resourcePreviewMessage(previewLog); @@ -759,14 +763,14 @@ function resourcePreviewMessage(previewLog: {isAcceleratePreview: boolean, log: } } -function getResourceDataNode(node: ts.CallExpression, - previewLog: {isAcceleratePreview: boolean, log: LogInfo[]}, resourceData: string[], isResourceModule: boolean, filePath: string): ts.Node { +function getResourceDataNode(node: ts.CallExpression, previewLog: {isAcceleratePreview: boolean, log: LogInfo[]}, + resourceData: string[], isResourceModule: boolean, filePath: string, isTemplateString: boolean): ts.Node { let resourceValue: number; - if (preCheckResourceData(resourceData, resources, node.arguments[0].getStart(), previewLog, isResourceModule, filePath)) { + if (preCheckResourceData(resourceData, resources, node.arguments[0].getStart(), previewLog, isResourceModule, filePath, isTemplateString)) { let resourceType: number = RESOURCE_TYPE[resourceData[1]]; if (resourceType === undefined && !previewLog.isAcceleratePreview) { transformLog.errors.push({ - type: LogType.ERROR, + type: isTemplateString ? LogType.WARN : LogType.ERROR, message: `The resource type '${resourceData[1]}' is not supported.`, pos: node.getStart(), code: '10906334' @@ -786,11 +790,12 @@ function getResourceDataNode(node: ts.CallExpression, return node; } -function isResourcefile(node: ts.CallExpression, previewLog: {isAcceleratePreview: boolean, log: LogInfo[]}, isResourceModule: boolean): void { +function isResourcefile(node: ts.CallExpression, previewLog: {isAcceleratePreview: boolean, log: LogInfo[]}, isResourceModule: boolean, + isTemplateString: boolean): void { if (!isResourceModule && process.env.rawFileResource && !storedFileInfo.resourcesArr.has(node.arguments[0].text) && !previewLog.isAcceleratePreview && process.env.compileMode === 'moduleJson') { transformLog.errors.push({ - type: LogType.ERROR, + type: isTemplateString ? LogType.WARN : LogType.ERROR, message: `No such '${node.arguments[0].text}' resource in current module.`, pos: node.getStart(), code: '10904333' @@ -896,19 +901,19 @@ function createResourceParam(resourceValue: number, resourceType: number, argsAr } function preCheckResourceData(resourceData: string[], resources: object, pos: number, - previewLog: {isAcceleratePreview: boolean, log: LogInfo[]}, isResourceModule: boolean, filePath: string): boolean { + previewLog: {isAcceleratePreview: boolean, log: LogInfo[]}, isResourceModule: boolean, filePath: string, isTemplateString: boolean): boolean { if (previewLog.isAcceleratePreview) { - return validateResourceData(resourceData, resources, pos, previewLog.log, true, isResourceModule, filePath); + return validateResourceData(resourceData, resources, pos, previewLog.log, true, isResourceModule, filePath, isTemplateString); } else { - return validateResourceData(resourceData, resources, pos, transformLog.errors, false, isResourceModule, filePath); + return validateResourceData(resourceData, resources, pos, transformLog.errors, false, isResourceModule, filePath, isTemplateString); } } function validateResourceData(resourceData: string[], resources: object, pos: number, log: LogInfo[], isAcceleratePreview: boolean, - isResourceModule: boolean, filePath: string): boolean { + isResourceModule: boolean, filePath: string, isTemplateString: boolean): boolean { if (resourceData.length !== 3) { log.push({ - type: LogType.ERROR, + type: isTemplateString ? LogType.WARN : LogType.ERROR, message: `Invalid resource file parameter. Enter a value in the format of 'xxx.yyy.zzz'.`, pos, code: '10905332' @@ -920,20 +925,20 @@ function validateResourceData(resourceData: string[], resources: object, pos: nu if (isResourceModule) { if (/^\[.*\]$/.test(resourceData[0]) && projectConfig.hspResourcesMap) { const resourceDataFirst: string = resourceData[0].replace(/^\[/, '').replace(/\]$/, '').trim(); - return resourceCheck(resourceData, resources, pos, log, true, resourceDataFirst, false); + return resourceCheck(resourceData, resources, pos, log, true, resourceDataFirst, false, isTemplateString); } else { - return resourceCheck(resourceData, resources, pos, log, false, resourceData[0], true); + return resourceCheck(resourceData, resources, pos, log, false, resourceData[0], true, isTemplateString); } } else { - return resourceCheck(resourceData, resources, pos, log, false, resourceData[0], false); + return resourceCheck(resourceData, resources, pos, log, false, resourceData[0], false, isTemplateString); } } return false; } function resourceCheck(resourceData: string[], resources: object, pos: number, log: LogInfo[], isHspResourceModule: boolean, - resourceDataFirst: string, faOrNoHspResourcesMap: boolean): boolean { - const logType: LogType = isHspResourceModule ? LogType.WARN : LogType.ERROR; + resourceDataFirst: string, faOrNoHspResourcesMap: boolean, isTemplateString: boolean): boolean { + const logType: LogType = isHspResourceModule || isTemplateString ? LogType.WARN : LogType.ERROR; if (!faOrNoHspResourcesMap && !resources[resourceDataFirst]) { log.push({ type: logType, -- Gitee