Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: multi-return regression #489

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading