fix(variable): ensure unique variable names in var-list (#22038)

This commit is contained in:
Minamiyama
2025-07-08 15:41:27 +08:00
committed by GitHub
parent f62b59a805
commit f925869f61

View File

@@ -75,8 +75,16 @@ const VarList: FC<Props> = ({
if (isSupportConstantValue) if (isSupportConstantValue)
draft[index].variable_type = VarKindType.variable draft[index].variable_type = VarKindType.variable
if (!draft[index].variable) if (!draft[index].variable) {
draft[index].variable = value[value.length - 1] const variables = draft.map(v => v.variable)
let newVarName = value[value.length - 1]
let count = 1
while (variables.includes(newVarName)) {
newVarName = `${value[value.length - 1]}_${count}`
count++
}
draft[index].variable = newVarName
}
} }
else { else {
draft[index].variable_type = VarKindType.constant draft[index].variable_type = VarKindType.constant