Skip to content

Commit

Permalink
[unreal] 修复 codegen .d.ts 函数参数列表可能重名的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiruili committed Dec 5, 2023
1 parent 9d433f3 commit fb2e202
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,27 @@ bool FTypeScriptDeclarationGenerator::GenFunction(
}
OwnerBuffer << "(";
PropertyMacro* ReturnValue = nullptr;

TSet<FString> NameDeDupSet{};
auto const DeDup = [&NameDeDupSet](FString const& Name)
{
if (!NameDeDupSet.Contains(Name))
{
NameDeDupSet.Add(Name);
return Name;
}

int Cnt = 1;
FString NewName = FString::Printf(TEXT("%s_%d"), *Name, Cnt);
while (NameDeDupSet.Contains(NewName))
{
Cnt++;
NewName = FString::Printf(TEXT("%s_%d"), *Name, Cnt);
}

return NewName;
};

TArray<UObject*> RefTypes;
TArray<FString> ParamDecls;
bool First = true;
Expand Down Expand Up @@ -928,7 +949,7 @@ bool FTypeScriptDeclarationGenerator::GenFunction(
DefaultValuePtr = MetaMap->Find(MetadataCppDefaultValueKey);
}

TmpBuf << SafeParamName(Property->GetName());
TmpBuf << DeDup(SafeParamName(Property->GetName()));
if (DefaultValuePtr)
{
TmpBuf << "?";
Expand Down

0 comments on commit fb2e202

Please sign in to comment.