From d9826545d53c5bf6315ef5ef200fbde82f4543cf Mon Sep 17 00:00:00 2001 From: lihao Date: Thu, 29 May 2025 23:36:09 +0800 Subject: [PATCH] importPathManager Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICBJ7W Signed-off-by: lihao --- ets2panda/util/importPathManager.cpp | 29 ++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/ets2panda/util/importPathManager.cpp b/ets2panda/util/importPathManager.cpp index 7cf04669276..2aa49f27101 100644 --- a/ets2panda/util/importPathManager.cpp +++ b/ets2panda/util/importPathManager.cpp @@ -122,6 +122,7 @@ util::StringView ImportPathManager::ResolvePathAPI(StringView curModulePath, ir: ImportPathManager::ResolvedPathRes ImportPathManager::ResolvePath(std::string_view curModulePath, ir::StringLiteral *importPath) const { + isDynamic_ = program->ModuleInfo().isDeclForDynamicStaticInterop; if (importPath->Str().Empty()) { diagnosticEngine_.LogDiagnostic(diagnostic::EMPTY_IMPORT_PATH, util::DiagnosticMessageParams {}); return {*importPath}; @@ -138,8 +139,32 @@ ImportPathManager::ResolvedPathRes ImportPathManager::ResolvePath(std::string_vi auto resolvedPath = UString(currentDirectory, allocator_); resolvedPath.Append(pathDelimiter_); resolvedPath.Append(*importPath); + + if (!isDnamic_) { + const std::string& baseUrl = arktsConfig->BaseUrl(); + std::string currentStr = newResolvedPath.View().Utf8(); + + if (currentStr.rfind(baseUrl, 0) == 0) { + std::string trimmedStr = currentStr.substr(baseUrl.length()); + newResolvedPath = UString(trimmedStr, resolvedPath.allocator_); + } + + } + // NOTE(dkofanov): Suspicious shortcut: shouldn't it fallthrough into `ResolveAbsolutePath`? - return AppendExtensionOrIndexFileIfOmitted(resolvedPath.View()); + auto result = AppendExtensionOrIndexFileIfOmitted(resolvedPath.View()); + if (result.resolvedPath.empty()) { + auto absolutePath= program->AbsoluteName() + const size_t pos = absolutePath.find_last_of("/\\"); + ES2PANDA_ASSERT(pos != std::string::npos); + + auto currentDirectory = absolutePath.substr(0, pos); + auto resolvedPath = UString(currentDirectory, allocator_); + resolvedPath.Append(pathDelimiter_); + resolvedPath.Append(*importPath); + return AppendExtensionOrIndexFileIfOmitted(resolvedPath.View()); + } + return result; } return ResolveAbsolutePath(*importPath); @@ -548,4 +573,4 @@ util::StringView ImportPathManager::FormRelativePath(const util::Path &path) } } // namespace ark::es2panda::util -#undef USE_UNIX_SYSCALL +#undef USE_UNIX_SYSCALL \ No newline at end of file -- Gitee