diff --git a/CHANGELOG.md b/CHANGELOG.md index c626bd35c14..16bd83de8e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,6 +70,9 @@ * Fixed `no_std` support for all APIs in `web-sys`. [#4378](https://github.com/rustwasm/wasm-bindgen/pull/4378) +* Prevent generating duplicate exports for closure conversions. + [#4380](https://github.com/rustwasm/wasm-bindgen/pull/4380) + -------------------------------------------------------------------------------- ## [0.2.99](https://github.com/rustwasm/wasm-bindgen/compare/0.2.98...0.2.99) diff --git a/crates/cli-support/src/js/mod.rs b/crates/cli-support/src/js/mod.rs index 118f75752cc..c7252852b49 100644 --- a/crates/cli-support/src/js/mod.rs +++ b/crates/cli-support/src/js/mod.rs @@ -4270,8 +4270,18 @@ __wbg_set_wasm(wasm);" "memory".to_owned() } walrus::ExportItem::Function(f) => match &self.module.funcs.get(f).name { - Some(s) => to_js_identifier(s), - None => default_name, + Some(s) => { + let mut name = to_js_identifier(s); + + // Account for duplicate export names. + // See https://github.com/rustwasm/wasm-bindgen/issues/4371. + if self.module.exports.get_func(&name).is_ok() { + name.push_str(&self.next_export_idx.to_string()); + } + + name + } + _ => default_name, }, _ => default_name, };