diff --git a/build-tools/arkui_transformer/src/arkui_transformer.ts b/build-tools/arkui_transformer/src/arkui_transformer.ts index 1f383ce54eb89cdf52778feff61701ebc3c52c26..30802ad34b37edcbb6a3e20730fe45196b841a3e 100644 --- a/build-tools/arkui_transformer/src/arkui_transformer.ts +++ b/build-tools/arkui_transformer/src/arkui_transformer.ts @@ -53,6 +53,13 @@ function convertFiles(files: string[]): string[] { return result } +function getTransformationResult(sourceFile: ts.SourceFile, program: ts.Program, componentFile: ComponentFile): ts.TransformationResult { + if (uiconfig.isHdsComponent) { + return ts.transform(sourceFile, [interfaceTransformer(program, componentFile), exportAllTransformer()]); + } + return ts.transform(sourceFile, [interfaceTransformer(program, componentFile), exportAllTransformer(), addImportTransformer()]); +} + function printResult(source: string, file: ComponentFile) { const outPath = path.join(options.targetDir, file.outFileName) fs.mkdirSync(path.dirname(outPath), { recursive: true }); @@ -80,12 +87,7 @@ function main() { return (context: ts.TransformationContext) => { return (sourceFile: ts.SourceFile) => { const componentFile = componentFileMap.get(f)!; - let result; - if (uiconfig.isHdsComponent) { - result = ts.transform(sourceFile, [interfaceTransformer(program, componentFile), exportAllTransformer()]); - } else { - result = ts.transform(sourceFile, [interfaceTransformer(program, componentFile), exportAllTransformer(), addImportTransformer()]); - } + const result = getTransformationResult(sourceFile, program, componentFile); const transformedFile = ts.createSourceFile(f, printFile(result.transformed[0]), ts.ScriptTarget.Latest, true); const transformedSource = ts.createPrinter().printFile(transformedFile); printResult(transformedSource, componentFile);