Skip to content

Commit

Permalink
fix: anon interface typescript generation (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Jun 22, 2023
1 parent 0e22af9 commit dd8822c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions crates/js-component-bindgen/src/ts_bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,27 @@ pub fn ts_bindgen(
for (name, export) in world.exports.iter() {
match export {
WorldItem::Function(f) => {
let WorldKey::Name(export_name) = name else { unreachable!() };
let export_name = match name {
WorldKey::Name(export_name) => export_name,
WorldKey::Interface(_) => unreachable!(),
};
seen_names.insert(export_name.to_string());
funcs.push((export_name.to_lower_camel_case(), f));
}
WorldItem::Interface(id) => {
let WorldKey::Interface(interface) = name else { unreachable!() };
let export_name = resolve.id_of(*interface).unwrap();
let iface_id: String;
let (export_name, iface_name): (&str, &str) = match name {
WorldKey::Name(export_name) => (export_name, export_name),
WorldKey::Interface(interface) => {
iface_id = resolve.id_of(*interface).unwrap();
let (_, _, iface) = parse_world_key(&iface_id).unwrap();
(iface_id.as_ref(), iface)
}
};
seen_names.insert(export_name.to_string());
let (_, _, iface) = parse_world_key(&export_name).unwrap();
let local_name =
bindgen.export_interface(resolve, &export_name, *id, files, opts.instantiation);
export_aliases.push((iface.to_lower_camel_case(), local_name));
export_aliases.push((iface_name.to_lower_camel_case(), local_name));
}
WorldItem::Type(_) => unimplemented!("type exports"),
}
Expand Down

0 comments on commit dd8822c

Please sign in to comment.