From 2f4ff194b8955532f3ef6ba43e20dd938d2cb71f Mon Sep 17 00:00:00 2001 From: wuhailong Date: Mon, 11 Aug 2025 15:44:25 +0800 Subject: [PATCH] bugfix expand import hsp Issue: #ICSDAY Signed-off-by: wuhailong Change-Id: I812f9ae06c30916bf1fadaabdb3eb2a5262a1f09 --- compiler/src/import_path_expand.ts | 2 +- compiler/src/interop/src/import_path_expand.ts | 2 +- .../ark_compiler_ut/common/import_path_expand.test.ts | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/compiler/src/import_path_expand.ts b/compiler/src/import_path_expand.ts index 9d1b87661..e856e6fa3 100644 --- a/compiler/src/import_path_expand.ts +++ b/compiler/src/import_path_expand.ts @@ -43,7 +43,7 @@ export function expandAllImportPaths(checker: ts.TypeChecker, rollupObejct: Obje const visitor: ts.Visitor = (node: ts.Node): ts.VisitResult => { if (ts.isImportDeclaration(node)) { const result: ts.ImportDeclaration[] = transformImportDecl(node, checker, exclude, - rollupObejct.share.projectConfig); + Object.assign(rollupObejct.share.projectConfig, rollupObejct.share.arkProjectConfig)); return result.length > 0 ? result : node; } return node; diff --git a/compiler/src/interop/src/import_path_expand.ts b/compiler/src/interop/src/import_path_expand.ts index 9d1b87661..e856e6fa3 100644 --- a/compiler/src/interop/src/import_path_expand.ts +++ b/compiler/src/interop/src/import_path_expand.ts @@ -43,7 +43,7 @@ export function expandAllImportPaths(checker: ts.TypeChecker, rollupObejct: Obje const visitor: ts.Visitor = (node: ts.Node): ts.VisitResult => { if (ts.isImportDeclaration(node)) { const result: ts.ImportDeclaration[] = transformImportDecl(node, checker, exclude, - rollupObejct.share.projectConfig); + Object.assign(rollupObejct.share.projectConfig, rollupObejct.share.arkProjectConfig)); return result.length > 0 ? result : node; } return node; diff --git a/compiler/test/ark_compiler_ut/common/import_path_expand.test.ts b/compiler/test/ark_compiler_ut/common/import_path_expand.test.ts index 53145d3fb..1307af581 100644 --- a/compiler/test/ark_compiler_ut/common/import_path_expand.test.ts +++ b/compiler/test/ark_compiler_ut/common/import_path_expand.test.ts @@ -393,6 +393,8 @@ const rollupObejct = { expandImportPath: baseConfig, depName2DepInfo: new Map(), packageDir: 'oh_modules', + }, + arkProjectConfig: { hspNameOhmMap: {}, harNameOhmMap: {} } @@ -584,7 +586,7 @@ mocha.describe('test import_path_expand file api', () => { }); mocha.it('4-5: should preserve import when module in hspNameOhmMap', () => { - rollupObejct.share.projectConfig.hspNameOhmMap = { 'hspPkg': 'hspPkg.ohm' }; + rollupObejct.share.arkProjectConfig.hspNameOhmMap = { 'hspPkg': 'hspPkg.ohm' }; const { program, testSourceFile } = createMultiSymbolProgram(CASE_4_5_TEST, CASE_4_5_FILES, ''); const transformed = ts.transform(testSourceFile, [expandAllImportPaths(program.getTypeChecker(), rollupObejct)], program.getCompilerOptions()).transformed[0]; @@ -592,11 +594,11 @@ mocha.describe('test import_path_expand file api', () => { const result = printer.printFile(transformed); expect(result === EXPECT_4_5).to.be.true; - rollupObejct.share.projectConfig.hspNameOhmMap = {}; + rollupObejct.share.arkProjectConfig.hspNameOhmMap = {}; }); mocha.it('4-6: should preserve import when module in harNameOhmMap', () => { - rollupObejct.share.projectConfig.harNameOhmMap = { 'harPkg': 'harPkg.ohm' }; + rollupObejct.share.arkProjectConfig.harNameOhmMap = { 'harPkg': 'harPkg.ohm' }; const { program, testSourceFile } = createMultiSymbolProgram(CASE_4_6_TEST, CASE_4_6_FILES, ''); const transformed = ts.transform(testSourceFile, [expandAllImportPaths(program.getTypeChecker(), rollupObejct)], program.getCompilerOptions()).transformed[0]; @@ -604,7 +606,7 @@ mocha.describe('test import_path_expand file api', () => { const result = printer.printFile(transformed); expect(result === EXPECT_4_6).to.be.true; - rollupObejct.share.projectConfig.harNameOhmMap = {}; + rollupObejct.share.arkProjectConfig.harNameOhmMap = {}; }); mocha.it('4-7: should preserve import when module in exclude list', () => { -- Gitee