Skip to content

Commit

Permalink
fix: multi-return regression (#489)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Aug 20, 2024
1 parent 3b390c7 commit b772089
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions crates/js-component-bindgen/src/function_bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1157,24 +1157,27 @@ impl Bindgen for FunctionBindgen<'_> {
}
return;
}
assert!(*amt == 1, "Unexpected multiple return");
let ret_assign = if self.post_return.is_some() {
"const retVal ="
} else {
"return"
};
if self.err == ErrHandling::ThrowResultErr {
let component_err = self.intrinsic(Intrinsic::ComponentError);
let op = &operands[0];
uwriteln!(
self.src,
"if ({op}.tag === 'err') {{
throw new {component_err}({op}.val);
}}
{ret_assign} {op}.val;"
);
if *amt == 1 {
if self.err == ErrHandling::ThrowResultErr {
let component_err = self.intrinsic(Intrinsic::ComponentError);
let op = &operands[0];
uwriteln!(
self.src,
"if (typeof {op} === 'object' && {op}.tag === 'err') {{
throw new {component_err}({op}.val);
}}
{ret_assign} {op}.val;"
);
} else {
uwriteln!(self.src, "{ret_assign} {};", operands[0]);
}
} else {
uwriteln!(self.src, "{ret_assign} {};", operands[0]);
uwriteln!(self.src, "{ret_assign} [{}];", operands.join(", "));
}
if let Some(f) = &self.post_return {
uwriteln!(
Expand Down

0 comments on commit b772089

Please sign in to comment.