From 4a2f4c4509b2714db987f996e91ccb33c5fdfea0 Mon Sep 17 00:00:00 2001 From: wuhailong Date: Mon, 4 Aug 2025 21:58:25 +0800 Subject: [PATCH] bugfix autoLazyImport Issue: #ICR2M3 Signed-off-by: wuhailong Change-Id: I0e73a895cf865ade1f87ff13cf0cec36a61bc492 --- compiler/src/interop/src/process_lazy_import.ts | 3 +++ compiler/src/process_lazy_import.ts | 3 +++ .../test/ark_compiler_ut/common/process_lazy_import.test.ts | 2 ++ 3 files changed, 8 insertions(+) diff --git a/compiler/src/interop/src/process_lazy_import.ts b/compiler/src/interop/src/process_lazy_import.ts index a7004df8a..dc1d33d55 100644 --- a/compiler/src/interop/src/process_lazy_import.ts +++ b/compiler/src/interop/src/process_lazy_import.ts @@ -84,6 +84,9 @@ function updateImportDecl(node: ts.ImportDeclaration, resolver: Object): ts.Impo // case1: import { x } from '...' --> import lazy { x } from '...' // case2: import y, { x } from '...' --> import lazy y, { x } from '...' if (namedBindings && ts.isNamedImports(namedBindings)) { + if (namedBindings.elements.some(e => e.isTypeOnly)) { + return node; + } // The resolver is used to determine whether type symbols need to be processed. // Only TS/ETS files have type symbols. if (resolver) { diff --git a/compiler/src/process_lazy_import.ts b/compiler/src/process_lazy_import.ts index a7004df8a..dc1d33d55 100644 --- a/compiler/src/process_lazy_import.ts +++ b/compiler/src/process_lazy_import.ts @@ -84,6 +84,9 @@ function updateImportDecl(node: ts.ImportDeclaration, resolver: Object): ts.Impo // case1: import { x } from '...' --> import lazy { x } from '...' // case2: import y, { x } from '...' --> import lazy y, { x } from '...' if (namedBindings && ts.isNamedImports(namedBindings)) { + if (namedBindings.elements.some(e => e.isTypeOnly)) { + return node; + } // The resolver is used to determine whether type symbols need to be processed. // Only TS/ETS files have type symbols. if (resolver) { diff --git a/compiler/test/ark_compiler_ut/common/process_lazy_import.test.ts b/compiler/test/ark_compiler_ut/common/process_lazy_import.test.ts index 2fc025d0b..f5f017e30 100644 --- a/compiler/test/ark_compiler_ut/common/process_lazy_import.test.ts +++ b/compiler/test/ark_compiler_ut/common/process_lazy_import.test.ts @@ -47,6 +47,7 @@ const TRANSFORM_LAZY_IMPORT_CODE: string = import test4, { test5 } from "./test4"; import test6, * as ns6 from "./test6"; import type dt from "./test7"; + import { type test8 } from "./test8"; let a: testType = test + t + test2 + testType + ns3.b + test4 + test5 + test6 + ns6.b + dt; let localAbility = new Ability(); let localFeatureAbility = new k(); @@ -67,6 +68,7 @@ const TRANSFORM_LAZY_IMPORT_CODE_EXPECT: string = 'import lazy test4, { test5 } from "./test4";\n' + 'import test6, * as ns6 from "./test6";\n' + 'import type dt from "./test7";\n' + +'import { type test8 } from "./test8";\n' + 'let a: testType = test + t + test2 + testType + ns3.b + test4 + test5 + test6 + ns6.b + dt;\n' + 'let localAbility = new Ability();\n' + 'let localFeatureAbility = new k();\n' + -- Gitee