diff --git a/ets2panda/util/importPathManager.cpp b/ets2panda/util/importPathManager.cpp index 24d8d592b6c29cf0725b44713b83306444ad7474..457906c1fc36ba0eb00065f7dd28d4185514dd42 100644 --- a/ets2panda/util/importPathManager.cpp +++ b/ets2panda/util/importPathManager.cpp @@ -460,6 +460,22 @@ util::StringView ImportPathManager::FormModuleNameSolelyByAbsolutePath(const uti return util::UString(name, allocator_).View(); } +template +static std::string TryFormDynamicModuleName(const DynamicPaths &dynPaths, const ModuleNameFormer &tryFormModuleName) +{ + for (auto const &[unitName, did] : dynPaths) { + if (did.Path().empty()) { + // NOTE(dkofanov): related to #23698. Current assumption: if 'declPath' is absent, it is a pure-dynamic + // source, and, as soon it won't be parsed, no module should be created. + continue; + } + if (auto res = tryFormModuleName(unitName, did.Path()); res) { + return res.value(); + } + } + return ""; +} + util::StringView ImportPathManager::FormModuleName(const util::Path &path, const lexer::SourcePosition &srcPos) { srcPos_ = srcPos; @@ -508,6 +524,9 @@ util::StringView ImportPathManager::FormModuleName(const util::Path &path) return util::UString(res.value(), allocator_).View(); } } + if (auto dmn = TryFormDynamicModuleName(arktsConfig_->Dependencies(), tryFormModuleName); !dmn.empty()) { + return util::UString(dmn, allocator_).View(); + } // NOTE (hurton): as a last step, try resolving using the BaseUrl again without a path delimiter at the end if (auto res = tryFormModuleName(arktsConfig_->Package(), arktsConfig_->BaseUrl()); res) { return util::UString(res.value(), allocator_).View(); @@ -564,4 +583,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