From e684a3c24717c799bcf9f702380ace6d63dc333b Mon Sep 17 00:00:00 2001 From: Tyler K Date: Tue, 29 Oct 2024 12:33:42 -0700 Subject: [PATCH] Adding code for detecting collisions in parameter names --- tool/src/demo_gen/terminus.rs | 16 +++++++++++++++- tool/templates/demo_gen/terminus.js.jinja | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tool/src/demo_gen/terminus.rs b/tool/src/demo_gen/terminus.rs index 5227f3eb5..1d809f5fd 100644 --- a/tool/src/demo_gen/terminus.rs +++ b/tool/src/demo_gen/terminus.rs @@ -1,4 +1,4 @@ -use std::collections::BTreeSet; +use std::collections::{BTreeSet, HashMap}; use diplomat_core::hir::{ self, DemoInfo, Method, OpaqueDef, StructDef, StructPath, TyPosition, Type, TypeContext, @@ -172,6 +172,20 @@ impl<'ctx, 'tcx> RenderTerminusContext<'ctx, 'tcx> { self.relative_import_path.clone(), ); + let mut param_collision_dict : HashMap = HashMap::new(); + + for out_param in &mut self.terminus_info.out_params { + if param_collision_dict.contains_key(&out_param.param_name) { + let num = param_collision_dict.get(&out_param.param_name).unwrap(); + + out_param.param_name = format!("{}_{}", out_param.param_name, num); + + param_collision_dict.insert(out_param.param_name.clone(), num + 1); + } else { + param_collision_dict.insert(out_param.param_name.clone(), 1); + } + } + self.terminus_info.imports.insert(format); } diff --git a/tool/templates/demo_gen/terminus.js.jinja b/tool/templates/demo_gen/terminus.js.jinja index 174a1b5e5..f9b00cdf0 100644 --- a/tool/templates/demo_gen/terminus.js.jinja +++ b/tool/templates/demo_gen/terminus.js.jinja @@ -1,7 +1,7 @@ export function {{function_name}}( - {%- if typescript %}{%- for param in out_params -%} + {%- for param in out_params -%} {{param.param_name}}{% if typescript %}: {{param.type_name}}{% endif %}{% if !loop.last %}, {% endif %} - {%- endfor -%}{% endif -%} + {%- endfor -%} ){% if typescript %};{% else %} { var terminusArgs = arguments; return {{node_call_stack|indent(4)}};