diff --git a/compiler/src/fast_build/ark_compiler/interop/process_arkts_evolution.ts b/compiler/src/fast_build/ark_compiler/interop/process_arkts_evolution.ts index c374bfac72a1491ecccffef3110b6bd9037f2f67..8c3238a636f82daeb3e49af553c066735b36a6fc 100644 --- a/compiler/src/fast_build/ark_compiler/interop/process_arkts_evolution.ts +++ b/compiler/src/fast_build/ark_compiler/interop/process_arkts_evolution.ts @@ -94,29 +94,6 @@ let arkTSEvoFileOHMUrlMap: Map = new Map(); let declaredClassVars: Set = new Set(); -export function addDeclFilesConfig(filePath: string, projectConfig: Object, logger: Object, - pkgPath: string, pkgName: string): void { - const { projectFilePath, pkgInfo } = getPkgInfo(filePath, projectConfig, logger, pkgPath, pkgName); - const declgenV2OutPath: string = getDeclgenV2OutPath(pkgName); - if (!declgenV2OutPath) { - return; - } - if (!pkgDeclFilesConfig[pkgName]) { - pkgDeclFilesConfig[pkgName] = { packageName: pkgName, files: {} }; - } - if (pkgDeclFilesConfig[pkgName].files[projectFilePath]) { - return; - } - const isSO: string = pkgInfo.isSO ? 'Y' : 'N'; - // The module name of the entry module of the project during the current compilation process. - const mainModuleName: string = projectConfig.mainModuleName; - const bundleName: string = projectConfig.bundleName; - const normalizedFilePath: string = `${pkgName}/${projectFilePath}`; - const declPath: string = path.join(toUnixPath(declgenV2OutPath), projectFilePath) + EXTNAME_D_ETS; - const ohmUrl: string = `${isSO}&${mainModuleName}&${bundleName}&${normalizedFilePath}&${pkgInfo.version}`; - pkgDeclFilesConfig[pkgName].files[projectFilePath] = { declPath, ohmUrl: `@normalized:${ohmUrl}` }; -} - export function getArkTSEvoDeclFilePath(resolvedFileInfo: ResolvedFileInfo): string { const { moduleRequest, resolvedFileName } = resolvedFileInfo; let arktsEvoDeclFilePath: string = moduleRequest; diff --git a/compiler/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts b/compiler/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts index 124c4ccbb70f82349c4f3fa4751c536186c7741a..4e50b4d7674e97197c9af39f5643b31f61f8ab5d 100644 --- a/compiler/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts +++ b/compiler/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts @@ -195,9 +195,6 @@ class DeclfileProductor { if (!this.pkgDeclFilesConfig[moduleInfo.packageName]) { this.pkgDeclFilesConfig[moduleInfo.packageName] = { packageName: moduleInfo.packageName, files: {} }; } - if (filePath.endsWith(EXTNAME_JS)) { - return; - } if (this.pkgDeclFilesConfig[moduleInfo.packageName].files[projectFilePath]) { return; } @@ -205,9 +202,12 @@ class DeclfileProductor { const normalizedFilePath: string = moduleInfo.isNative ? moduleInfo.moduleName : `${moduleInfo.packageName}/${projectFilePath}`; - const declPath: string = path.join(toUnixPath(declgenV2OutPath), projectFilePath) + EXTNAME_D_ETS; const isNativeFlag = moduleInfo.isNative ? 'Y' : 'N'; const ohmUrl: string = `${isNativeFlag}&${mainModuleName}&${bundleName}&${normalizedFilePath}&${moduleInfo.packageVersion}`; + let declPath: string | undefined = undefined; + if (!filePath.endsWith(EXTNAME_JS)) { + declPath = path.join(toUnixPath(declgenV2OutPath), projectFilePath) + EXTNAME_D_ETS; + } this.pkgDeclFilesConfig[moduleInfo.packageName].files[projectFilePath] = { declPath, ohmUrl: `@normalized:${ohmUrl}` }; } diff --git a/compiler/src/fast_build/ark_compiler/interop/type.ts b/compiler/src/fast_build/ark_compiler/interop/type.ts index 3a3dc2a11c4c1e7e197241e5f46c4bcaa55c8624..1f73c7b32f167953a1277f38f00bbc02706387cd 100644 --- a/compiler/src/fast_build/ark_compiler/interop/type.ts +++ b/compiler/src/fast_build/ark_compiler/interop/type.ts @@ -86,7 +86,7 @@ export interface DeclFilesConfig { } interface DeclFileConfig { - declPath: string; + declPath: string | undefined; ohmUrl: string; isNative?: boolean } diff --git a/compiler/src/fast_build/ark_compiler/module/module_mode.ts b/compiler/src/fast_build/ark_compiler/module/module_mode.ts index a86646caa7b0f8add8c6bbe10913360fe2fc14e9..72e6eb153af68e0327d3f31a07378631a57dcefe 100644 --- a/compiler/src/fast_build/ark_compiler/module/module_mode.ts +++ b/compiler/src/fast_build/ark_compiler/module/module_mode.ts @@ -125,7 +125,6 @@ import { } from '../../../performance'; import { BytecodeObfuscator } from '../bytecode_obfuscator'; import { - addDeclFilesConfig, ArkTSEvolutionModule, getDeclgenBridgeCodePath, pkgDeclFilesConfig, diff --git a/compiler/src/interop/src/fast_build/ark_compiler/interop/process_arkts_evolution.ts b/compiler/src/interop/src/fast_build/ark_compiler/interop/process_arkts_evolution.ts index c374bfac72a1491ecccffef3110b6bd9037f2f67..8c3238a636f82daeb3e49af553c066735b36a6fc 100644 --- a/compiler/src/interop/src/fast_build/ark_compiler/interop/process_arkts_evolution.ts +++ b/compiler/src/interop/src/fast_build/ark_compiler/interop/process_arkts_evolution.ts @@ -94,29 +94,6 @@ let arkTSEvoFileOHMUrlMap: Map = new Map(); let declaredClassVars: Set = new Set(); -export function addDeclFilesConfig(filePath: string, projectConfig: Object, logger: Object, - pkgPath: string, pkgName: string): void { - const { projectFilePath, pkgInfo } = getPkgInfo(filePath, projectConfig, logger, pkgPath, pkgName); - const declgenV2OutPath: string = getDeclgenV2OutPath(pkgName); - if (!declgenV2OutPath) { - return; - } - if (!pkgDeclFilesConfig[pkgName]) { - pkgDeclFilesConfig[pkgName] = { packageName: pkgName, files: {} }; - } - if (pkgDeclFilesConfig[pkgName].files[projectFilePath]) { - return; - } - const isSO: string = pkgInfo.isSO ? 'Y' : 'N'; - // The module name of the entry module of the project during the current compilation process. - const mainModuleName: string = projectConfig.mainModuleName; - const bundleName: string = projectConfig.bundleName; - const normalizedFilePath: string = `${pkgName}/${projectFilePath}`; - const declPath: string = path.join(toUnixPath(declgenV2OutPath), projectFilePath) + EXTNAME_D_ETS; - const ohmUrl: string = `${isSO}&${mainModuleName}&${bundleName}&${normalizedFilePath}&${pkgInfo.version}`; - pkgDeclFilesConfig[pkgName].files[projectFilePath] = { declPath, ohmUrl: `@normalized:${ohmUrl}` }; -} - export function getArkTSEvoDeclFilePath(resolvedFileInfo: ResolvedFileInfo): string { const { moduleRequest, resolvedFileName } = resolvedFileInfo; let arktsEvoDeclFilePath: string = moduleRequest; diff --git a/compiler/src/interop/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts b/compiler/src/interop/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts index 124c4ccbb70f82349c4f3fa4751c536186c7741a..7decd4b683ef16cad5002f7b1dd3283807814fc4 100644 --- a/compiler/src/interop/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts +++ b/compiler/src/interop/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts @@ -58,7 +58,7 @@ export function run(param: Params): boolean { return true; } -class DeclfileProductor { +export class DeclfileProductor { private static declFileProductor: DeclfileProductor; static compilerOptions: ts.CompilerOptions; @@ -187,7 +187,6 @@ class DeclfileProductor { addDeclFilesConfig(filePath: string, mainModuleName: string, bundleName: string, moduleInfo: ArkTSEvolutionModule): void { const projectFilePath = getRelativePath(filePath, moduleInfo.modulePath); - const declgenV2OutPath: string = this.getDeclgenV2OutPath(moduleInfo.packageName); if (!declgenV2OutPath) { return; @@ -195,9 +194,6 @@ class DeclfileProductor { if (!this.pkgDeclFilesConfig[moduleInfo.packageName]) { this.pkgDeclFilesConfig[moduleInfo.packageName] = { packageName: moduleInfo.packageName, files: {} }; } - if (filePath.endsWith(EXTNAME_JS)) { - return; - } if (this.pkgDeclFilesConfig[moduleInfo.packageName].files[projectFilePath]) { return; } @@ -205,9 +201,12 @@ class DeclfileProductor { const normalizedFilePath: string = moduleInfo.isNative ? moduleInfo.moduleName : `${moduleInfo.packageName}/${projectFilePath}`; - const declPath: string = path.join(toUnixPath(declgenV2OutPath), projectFilePath) + EXTNAME_D_ETS; const isNativeFlag = moduleInfo.isNative ? 'Y' : 'N'; const ohmUrl: string = `${isNativeFlag}&${mainModuleName}&${bundleName}&${normalizedFilePath}&${moduleInfo.packageVersion}`; + let declPath: string | undefined = undefined; + if (!filePath.endsWith(EXTNAME_JS)) { + declPath = path.join(toUnixPath(declgenV2OutPath), projectFilePath) + EXTNAME_D_ETS; + } this.pkgDeclFilesConfig[moduleInfo.packageName].files[projectFilePath] = { declPath, ohmUrl: `@normalized:${ohmUrl}` }; } diff --git a/compiler/src/interop/src/fast_build/ark_compiler/interop/type.ts b/compiler/src/interop/src/fast_build/ark_compiler/interop/type.ts index c4eae6d787d01e7849e84bc34bb2f28f084fa346..d9853a7a5578be649dd59ac01689685d38beab9b 100644 --- a/compiler/src/interop/src/fast_build/ark_compiler/interop/type.ts +++ b/compiler/src/interop/src/fast_build/ark_compiler/interop/type.ts @@ -86,7 +86,7 @@ export interface DeclFilesConfig { } interface DeclFileConfig { - declPath: string; + declPath: string | undefined; ohmUrl: string; isNative?: boolean } diff --git a/compiler/src/interop/src/fast_build/ark_compiler/module/module_mode.ts b/compiler/src/interop/src/fast_build/ark_compiler/module/module_mode.ts index cbaa0f995699b2bf19ad0d58acd80b8cfee13004..9f17b6a15e4f47f52e2b4d337b4e9523a4825ea5 100644 --- a/compiler/src/interop/src/fast_build/ark_compiler/module/module_mode.ts +++ b/compiler/src/interop/src/fast_build/ark_compiler/module/module_mode.ts @@ -125,7 +125,6 @@ import { } from '../../../performance'; import { BytecodeObfuscator } from '../bytecode_obfuscator'; import { - addDeclFilesConfig, ArkTSEvolutionModule, getDeclgenBridgeCodePath, pkgDeclFilesConfig, diff --git a/compiler/test/ark_compiler_ut/common/process_arkts_evolution.test.ts b/compiler/test/ark_compiler_ut/common/process_arkts_evolution.test.ts index 3da5547c0ce15dfc66c7fb740aec5c95d4550ed1..421126f0eaa8b73a5c4cfbea59cb638d67a0fbea 100644 --- a/compiler/test/ark_compiler_ut/common/process_arkts_evolution.test.ts +++ b/compiler/test/ark_compiler_ut/common/process_arkts_evolution.test.ts @@ -20,7 +20,6 @@ import ts from 'typescript'; import path from 'path'; import proxyquire from 'proxyquire'; import { - addDeclFilesConfig, arkTSEvolutionModuleMap, arkTSModuleMap, cleanUpProcessArkTSEvolutionObj, @@ -541,47 +540,15 @@ mocha.describe('process arkts evolution tests', function () { throwArkTsCompilerErrorStub.restore(); }); - mocha.it('2-1: test generate declFilesInfo in mixed compilation', function () { - pkgDeclFilesConfig['har'] = { - packageName: 'har', - files: {} - }; - const filePath = '/har/Index.ets' - const projectConfig = { - mainModuleName: 'entry', - bundleName: BUNDLE_NAME_DEFAULT, - pkgContextInfo: { - 'har': { - packageName: 'har', - version: '1.0.0', - isSO: false - } - } - } - arkTSModuleMap.set('har', { - language: '1.1', - pkgName: 'har', - declgenV2OutPath: HAR_DECLGENV2OUTPATH - }) - addDeclFilesConfig(filePath, projectConfig, undefined, '/har', 'har'); - const expectDeclPath: string = `${HAR_DECLGENV2OUTPATH}/Index.d.ets`; - const expectOhmUrl: string = `@normalized:N&entry&${BUNDLE_NAME_DEFAULT}&har/Index&1.0.0`; - expect(pkgDeclFilesConfig['har'].files.length !== 0).to.be.true; - expect(pkgDeclFilesConfig['har'].files['Index'].length !== 0).to.be.true; - expect(pkgDeclFilesConfig['har'].files['Index'].declPath === expectDeclPath).to.be.true; - expect(pkgDeclFilesConfig['har'].files['Index'].ohmUrl === expectOhmUrl).to.be.true; - arkTSModuleMap.clear(); - }); - - mocha.describe('3: process arkts evolution tests: interop transform', function () { - mocha.it('3-1-1: test mixCompile is false', function () { + mocha.describe('2: process arkts evolution tests: interop transform', function () { + mocha.it('2-1-1: test mixCompile is false', function () { const sourceFile: ts.SourceFile = ts.createSourceFile('a.ts', 'let x = 1;', ts.ScriptTarget.ESNext); const program: ts.Program = ts.createProgram({ rootNames: ['a.ts'], options: {}, host: ts.createCompilerHost({}) }); const result: ts.SourceFile = interopTransform(program, testFileName, false)()(sourceFile); expect(result === sourceFile).to.be.true; }); - mocha.it('3-1-2: test error message of ArkTS evoluion class does not has a no-argument constructor', function () { + mocha.it('2-1-2: test error message of ArkTS evoluion class does not has a no-argument constructor', function () { const { program, testSourceFile } = createDualSourceProgram(CLASS_NO_HAS_NO_ARG_CONSTRUCTOR_CODE); const errInfo: LogData = LogDataFactory.newInstance( ErrorCode.ETS2BUNDLE_EXTERNAL_CLASS_HAS_NO_CONSTRUCTOR_WITHOUT_ARGS, @@ -601,7 +568,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-3: test import ArkTS evoluion Record in object literal', function () { + mocha.it('2-1-3: test import ArkTS evoluion Record in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(IMPORT_ARKTS_EVO_RECORD_CODE); const originalChecker = program.getTypeChecker(); const mockedTypeChecker = Object.create(originalChecker); @@ -614,7 +581,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-4-1: test import ArkTS evoluion class (variable init) in object literal', function () { + mocha.it('2-1-4-1: test import ArkTS evoluion class (variable init) in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(IMPORT_ARKTS_EVO_CLASS_CODE_1); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -622,7 +589,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-4-2: test import ArkTS evoluion class (object assignment) in object literal', function () { + mocha.it('2-1-4-2: test import ArkTS evoluion class (object assignment) in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(IMPORT_ARKTS_EVO_CLASS_CODE_2); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -630,7 +597,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-4-3: test import ArkTS evoluion class (type assertions) in object literal', function () { + mocha.it('2-1-4-3: test import ArkTS evoluion class (type assertions) in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(IMPORT_ARKTS_EVO_CLASS_CODE_3); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -638,7 +605,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-4-4: test import ArkTS evoluion class (property init) in object literal', function () { + mocha.it('2-1-4-4: test import ArkTS evoluion class (property init) in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(IMPORT_ARKTS_EVO_CLASS_CODE_4); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -646,7 +613,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-4-5: test import ArkTS evoluion class (contr function call) in object literal', function () { + mocha.it('2-1-4-5: test import ArkTS evoluion class (contr function call) in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(IMPORT_ARKTS_EVO_CLASS_CODE_5); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -654,7 +621,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-4-6: test import ArkTS evoluion class (multi-layer object assignment) in object literal', function () { + mocha.it('2-1-4-6: test import ArkTS evoluion class (multi-layer object assignment) in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(IMPORT_ARKTS_EVO_CLASS_CODE_6); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -662,7 +629,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-4-7: test import ArkTS evoluion class (parameter initp) in object literal', function () { + mocha.it('2-1-4-7: test import ArkTS evoluion class (parameter initp) in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(IMPORT_ARKTS_EVO_CLASS_CODE_7); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -670,7 +637,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-4-8: test import ArkTS evoluion class (function call) in object literal', function () { + mocha.it('2-1-4-8: test import ArkTS evoluion class (function call) in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(IMPORT_ARKTS_EVO_CLASS_CODE_8); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -678,7 +645,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-4-9: test import ArkTS evoluion class (arrow function return value) in object literal', function () { + mocha.it('2-1-4-9: test import ArkTS evoluion class (arrow function return value) in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(IMPORT_ARKTS_EVO_CLASS_CODE_9); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -686,7 +653,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-4-10: test import ArkTS evoluion class (function return value) in object literal', function () { + mocha.it('2-1-4-10: test import ArkTS evoluion class (function return value) in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(IMPORT_ARKTS_EVO_CLASS_CODE_10); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -694,7 +661,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-5-1: test import ArkTS evoluion interface (variable init) in object literal', function () { + mocha.it('2-1-5-1: test import ArkTS evoluion interface (variable init) in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(IMPORT_ARKTS_EVO_INTERFACE_CODE_1); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -702,7 +669,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-5-2: test import ArkTS evoluion interface (type assertions) in object literal', function () { + mocha.it('2-1-5-2: test import ArkTS evoluion interface (type assertions) in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(IMPORT_ARKTS_EVO_INTERFACE_CODE_2); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -710,7 +677,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-5-3: test import ArkTS evoluion interface (property init) in object literal', function () { + mocha.it('2-1-5-3: test import ArkTS evoluion interface (property init) in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(IMPORT_ARKTS_EVO_INTERFACE_CODE_3); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -718,7 +685,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-5-4: test import ArkTS evoluion interface (contr function call) in object literal', function () { + mocha.it('2-1-5-4: test import ArkTS evoluion interface (contr function call) in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(IMPORT_ARKTS_EVO_INTERFACE_CODE_4); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -726,7 +693,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-5-5: test import ArkTS evoluion interface (parameter initp) in object literal', function () { + mocha.it('2-1-5-5: test import ArkTS evoluion interface (parameter initp) in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(IMPORT_ARKTS_EVO_INTERFACE_CODE_5); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -734,7 +701,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-5-6: test import ArkTS evoluion interface (function call) in object literal', function () { + mocha.it('2-1-5-6: test import ArkTS evoluion interface (function call) in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(IMPORT_ARKTS_EVO_INTERFACE_CODE_6); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -742,7 +709,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-5-7: test import ArkTS evoluion interface (arrow function return value) in object literal', function () { + mocha.it('2-1-5-7: test import ArkTS evoluion interface (arrow function return value) in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(IMPORT_ARKTS_EVO_INTERFACE_CODE_7); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -750,7 +717,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-5-8: test import ArkTS evoluion interface (function return value) in object literal', function () { + mocha.it('2-1-5-8: test import ArkTS evoluion interface (function return value) in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(IMPORT_ARKTS_EVO_INTERFACE_CODE_8); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -758,7 +725,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-6: test import ArkTS evoluion function in object literal', function () { + mocha.it('2-1-6: test import ArkTS evoluion function in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(IMPORT_ARKTS_EVO_FUNCTION_CODE); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -766,7 +733,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-7: test union type (no ambiguity) in object literal', function () { + mocha.it('2-1-7: test union type (no ambiguity) in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(UNION_NO_AMBIGUITY_CODE); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -774,7 +741,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-8: test union type (ambiguity) in object literal', function () { + mocha.it('2-1-8: test union type (ambiguity) in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(UNION_AMBIGUITY_CODE); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -793,7 +760,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-1-9: test parenthesized type in object literal', function () { + mocha.it('2-1-9: test parenthesized type in object literal', function () { const { program, testSourceFile } = createDualSourceProgram(PARENTHESIZED_CODE); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); @@ -801,7 +768,7 @@ mocha.describe('process arkts evolution tests', function () { cleanUpProcessArkTSEvolutionObj(); }); - mocha.it('3-2-1: test class extends arkTS evolution class or implement arkTS evolution interface', function () { + mocha.it('2-2-1: test class extends arkTS evolution class or implement arkTS evolution interface', function () { const { program, testSourceFile } = createDualSourceProgram(CLASS_IMPLEMENTS_ARKTS_EVO_CLASS_OR_INTERFACE_CODE); const result = ts.transform(testSourceFile, [interopTransform(program, testFileName, true)]).transformed[0]; const resultCode = ts.createPrinter().printFile(result); diff --git a/compiler/test/ark_compiler_ut/interop/process_arkts_evolution.test.ts b/compiler/test/ark_compiler_ut/interop/process_arkts_evolution.test.ts index 6119d6bd35800320841a97d4e14d14a13dccafa9..4f54e251bd0c89f171dfdb93e5356a81e20eb880 100644 --- a/compiler/test/ark_compiler_ut/interop/process_arkts_evolution.test.ts +++ b/compiler/test/ark_compiler_ut/interop/process_arkts_evolution.test.ts @@ -19,7 +19,6 @@ import sinon from 'sinon'; import { collectArkTSEvolutionModuleInfo, - addDeclFilesConfig, pkgDeclFilesConfig, arkTSModuleMap } from '../../../lib/fast_build/ark_compiler/interop/process_arkts_evolution'; @@ -82,36 +81,4 @@ mocha.describe('process arkts evolution tests', function () { expect(throwArkTsCompilerErrorStub.getCall(0).args[1] === errMsg).to.be.true; throwArkTsCompilerErrorStub.restore(); }); - - mocha.it('2-1: test generate declFilesInfo in mixed compilation', function () { - pkgDeclFilesConfig['har'] = { - packageName: 'har', - files: {} - }; - const filePath = '/har/Index.ets' - const projectConfig = { - mainModuleName: 'entry', - bundleName: BUNDLE_NAME_DEFAULT, - pkgContextInfo: { - 'har': { - packageName: 'har', - version: '1.0.0', - isSO: false - } - } - } - arkTSModuleMap.set('har', { - language: '1.1', - pkgName: 'har', - declgenV2OutPath: HAR_DECLGENV2OUTPATH - }) - addDeclFilesConfig(filePath, projectConfig, undefined, '/har', 'har'); - const expectDeclPath: string = `${HAR_DECLGENV2OUTPATH}/Index.d.ets`; - const expectOhmUrl: string = `@normalized:N&entry&${BUNDLE_NAME_DEFAULT}&har/Index&1.0.0`; - expect(pkgDeclFilesConfig['har'].files.length !== 0).to.be.true; - expect(pkgDeclFilesConfig['har'].files['Index'].length !== 0).to.be.true; - expect(pkgDeclFilesConfig['har'].files['Index'].declPath === expectDeclPath).to.be.true; - expect(pkgDeclFilesConfig['har'].files['Index'].ohmUrl === expectOhmUrl).to.be.true; - arkTSModuleMap.clear(); - }); }); \ No newline at end of file diff --git a/compiler/test/ark_compiler_ut/interop/run_declgen_standalone.test.ts b/compiler/test/ark_compiler_ut/interop/run_declgen_standalone.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..3763a381ccb7367eb988df39d45f571938eb66f4 --- /dev/null +++ b/compiler/test/ark_compiler_ut/interop/run_declgen_standalone.test.ts @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use rollupObject 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 { expect } from 'chai'; +import sinon from 'sinon'; +import fs from 'fs'; +import path from 'path'; +import { + FileManager, + collectSDKInfo, + isBridgeCode, + getBrdigeCodeRootPath, + isMixCompile, + initConfigForInterop, + destroyInterop +} from '../../../lib/fast_build/ark_compiler/interop/interop_manager'; +import { + ArkTSEvolutionModule, + ProjectConfig, + Params, + DeclFilesConfig +} from '../../../lib/fast_build/ark_compiler/interop/type'; +import { DeclfileProductor } from '../../../lib/fast_build/ark_compiler/interop/run_declgen_standalone'; +import { ARKTS_1_1, ARKTS_1_2, ARKTS_testPkg } from '../../../lib/fast_build/ark_compiler/interop/pre_define'; +import { mkdirsSync } from '../../../lib/fast_build/ark_compiler/utils'; + +describe('DeclfileProductor.writeDeclFileInfo', () => { + const projectConfig1: ProjectConfig = { + language: '1.0.0', + cachePath: '/cache/path', + bundleName: 'testBundle', + mainModuleName: 'entry', + projectRootPath: '/project/root', + }; + + const params: Params = { + dependentModuleMap: new Map(), + projectConfig: projectConfig1, + tasks: [], + }; + + before(() => { + DeclfileProductor.init(params); + const dependentModuleMap: Map = new Map(); + dependentModuleMap.set('testPkg', { + language: ARKTS_testPkg, + packageName: 'testPkg', + moduleName: 'testPkg', + modulePath: '/testPkg', + declgenV1OutPath: '/declgenV1', + declgenV2OutPath: '/declgenV2', + declgenBridgeCodePath: '/declgenBridgeCode', + declFilesPath: '/decl-fileInfo.json', + dynamicFiles: ['/testPkg/fileV1.ets'], + staticFiles: ['/testPkg/fileV2.ets'], + cachePath: '/testPkg/build/cache', + byteCodeHarInfo: {} + }); + FileManager.cleanFileManagerObject(); + FileManager.initForTest( + dependentModuleMap + ); + }); + + + it('1-1: test addDeclFilesConfig', () => { + let productor = DeclfileProductor.getInstance(); + productor.projectConfig = projectConfig1; + productor.pkgDeclFilesConfig = {}; + const filePath: string = '/project/src/Index.ets'; + const mainModuleName: string = 'Index'; + const bundleName: string = 'testBundle'; + const moduleInfo: ArkTSEvolutionModule = { + language: '1.0.0', + packageName: 'testPkg', + moduleName: 'testPkg', + modulePath: '/project/src', + packageVersion: '1.0.0', + declFilesPath: '/output', + dynamicFiles: ['/project/src/Index.ets'], + staticFiles: [], + cachePath: '/cache/path', + }; + productor.addDeclFilesConfig(filePath, mainModuleName, bundleName, moduleInfo); + const url = productor.pkgDeclFilesConfig['testPkg'].files['Index'].ohmUrl; + const declPath = productor.pkgDeclFilesConfig['testPkg'].files['Index'].declPath; + expect(declPath).equal('/declgenV2/Index.d.ets'); + expect(url).equal('@normalized:N&Index&testBundle&testPkg/Index&1.0.0'); + }); + + it('1-2: test addJSDeclFilesConfig', () => { + let productor = DeclfileProductor.getInstance(); + productor.projectConfig = projectConfig1; + productor.pkgDeclFilesConfig = {}; + const filePath: string = '/project/src/Index.js'; + const mainModuleName: string = 'Index'; + const bundleName: string = 'testBundle'; + const moduleInfo: ArkTSEvolutionModule = { + language: '1.0.0', + packageName: 'testPkg', + moduleName: 'testPkg', + modulePath: '/project/src', + packageVersion: '1.0.0', + declFilesPath: '/output', + dynamicFiles: ['/project/src/Index.js'], + staticFiles: [], + cachePath: '/cache/path', + }; + productor.addDeclFilesConfig(filePath, mainModuleName, bundleName, moduleInfo); + const url = productor.pkgDeclFilesConfig['testPkg'].files['Index'].ohmUrl; + const declPath = productor.pkgDeclFilesConfig['testPkg'].files['Index'].declPath; + expect(declPath).equal(undefined); + expect(url).equal('@normalized:N&Index&testBundle&testPkg/Index&1.0.0'); + }); + +});