diff --git a/es2panda/parser/module/sourceTextModuleRecord.cpp b/es2panda/parser/module/sourceTextModuleRecord.cpp index a6b213ed4a6bfe714aefb19d142f467c7e6de022..a5c1f4ad633d7f0ba7f771ab50fa26cef8dd1448 100644 --- a/es2panda/parser/module/sourceTextModuleRecord.cpp +++ b/es2panda/parser/module/sourceTextModuleRecord.cpp @@ -169,6 +169,18 @@ namespace panda::es2panda::parser { for (auto it = localExportEntries_.begin(); it != localExportEntries_.end(); it = localExportEntries_.upper_bound(it->first)) { + // local module variable's index is suffixed to the exportEntry's localName as format liking + // `[identifier]#index` to resolve resolvingBindings's index correctly in runtime. + std::pair localNames = + localExportEntries_.equal_range(it->first); + util::StringView updatedLocalName = + util::UString(std::string(it->first) + '#' + std::to_string(index), allocator_).View(); + for (auto localNameIter = localNames.first; localNameIter != localNames.second; ++localNameIter) { + auto *entry = localNameIter->second; + entry->localName_ = updatedLocalName; + } + CheckAndAssignIndex(moduleScope, it->first, &index); } diff --git a/ts2panda/src/ecmaModule.ts b/ts2panda/src/ecmaModule.ts index d69254de3850114bc903de52c3c177b9bba4d653..1be9e67a6aa4092a4efad4106a7ea6d7ff2c8f73 100644 --- a/ts2panda/src/ecmaModule.ts +++ b/ts2panda/src/ecmaModule.ts @@ -244,6 +244,12 @@ export function assignIndexToModuleVariable(moduleScope: Scope) { let index: number = 0; // @ts-ignore moduleScope.module().getLocalExportEntries().forEach((entries: Array, localName: string) => { + // local module variable's index is suffixed to the exportEntry's localName as format liking + // `[identifier]#index` to resolve resolvingBindings's index correctly in runtime. + let updatedLocalName: string = localName + '#' + index; + entries.forEach(entry => { + entry.localName = updatedLocalName; + }); (moduleScope.findLocal(localName)!).assignIndex(index++); }); index = 0;