Skip to content

Commit

Permalink
Prevent generating duplicate exports (#4380)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda authored Dec 25, 2024
1 parent 88452fa commit 24f20ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 12 additions & 2 deletions crates/cli-support/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down

0 comments on commit 24f20ae

Please sign in to comment.