Skip to content

Commit 4bae429

Browse files
fix(bindgen): resource hookup for imports
1 parent 595a8e9 commit 4bae429

2 files changed

Lines changed: 16 additions & 25 deletions

File tree

crates/js-component-bindgen/src/function_bindgen.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2366,7 +2366,6 @@ impl Bindgen for FunctionBindgen<'_> {
23662366

23672367
// results.push(rsc);
23682368
// }
2369-
23702369
Instruction::HandleLower { handle, name, .. } => {
23712370
let (Handle::Own(ty) | Handle::Borrow(ty)) = handle;
23722371
let is_own = matches!(handle, Handle::Own(_));

crates/js-component-bindgen/src/transpile_bindgen.rs

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4007,35 +4007,27 @@ impl<'a> Instantiator<'a, '_> {
40074007
// Process functions imported by the iface, which will use (as arg or param)
40084008
// relevant resources
40094009
for (fn_name, iface_fn) in iface.functions.iter() {
4010-
// Find the type for the function in the import
4011-
let fn_ty_idx = match import_type_def {
4012-
// If the import is from another component instance, we need to find the function
4013-
// type within manually
4010+
match import_type_def {
40144011
TypeDef::ComponentInstance(instance_ty) => {
4015-
let component_instance = &self.types[*instance_ty];
4016-
if let Some(f) = &component_instance.exports.get(fn_name)
4017-
&& let TypeDef::ComponentFunc(type_func_idx) = f
4012+
if let Some(TypeDef::ComponentFunc(type_func_index)) =
4013+
&self.types[*instance_ty].exports.get(fn_name)
40184014
{
4019-
type_func_idx
4020-
} else {
4021-
unreachable!(
4022-
"missing imported function in imported component instance's exports"
4023-
)
4015+
self.create_resource_fn_map(
4016+
iface_fn,
4017+
*type_func_index,
4018+
&mut import_resource_map,
4019+
);
40244020
}
40254021
}
4026-
4027-
TypeDef::ComponentFunc(type_func_idx) => type_func_idx,
4028-
4029-
TypeDef::Resource(_)
4030-
| TypeDef::Component(_)
4031-
| TypeDef::Module(_)
4032-
| TypeDef::Interface(_)
4033-
| TypeDef::CoreFunc(_) => {
4034-
unreachable!("unexpected import type definition for interface")
4022+
TypeDef::ComponentFunc(type_func_idx) => {
4023+
self.create_resource_fn_map(
4024+
iface_fn,
4025+
*type_func_idx,
4026+
&mut import_resource_map,
4027+
);
40354028
}
4036-
};
4037-
4038-
self.create_resource_fn_map(iface_fn, *fn_ty_idx, &mut import_resource_map);
4029+
_ => {}
4030+
}
40394031
}
40404032
}
40414033

0 commit comments

Comments
 (0)