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

update typescript generation to reflect that Option<T> can be undefined #1008

Merged
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
10 changes: 5 additions & 5 deletions crates/cli-support/src/js/js2rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ impl<'a, 'b> Js2Rust<'a, 'b> {

if optional {
if ty.is_wasm_native() {
self.ret_ty = "number".to_string();
self.ret_ty = "number | undefined".to_string();
self.cx.expose_global_argument_ptr()?;
self.cx.expose_uint32_memory();
match ty {
Expand Down Expand Up @@ -533,7 +533,7 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
}

if ty.is_abi_as_u32() {
self.ret_ty = "number".to_string();
self.ret_ty = "number | undefined".to_string();
self.ret_expr = "
const ret = RET;
return ret === 0xFFFFFF ? undefined : ret;
Expand All @@ -542,7 +542,7 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
}

if let Some(signed) = ty.get_64() {
self.ret_ty = "BigInt".to_string();
self.ret_ty = "BigInt | undefined".to_string();
self.cx.expose_global_argument_ptr()?;
let f = if signed {
self.cx.expose_int64_memory();
Expand All @@ -567,15 +567,15 @@ impl<'a, 'b> Js2Rust<'a, 'b> {

match *ty {
Descriptor::Boolean => {
self.ret_ty = "boolean".to_string();
self.ret_ty = "boolean | undefined".to_string();
self.ret_expr = "
const ret = RET;
return ret === 0xFFFFFF ? undefined : ret !== 0;
".to_string();
return Ok(self);
}
Descriptor::Char => {
self.ret_ty = "string".to_string();
self.ret_ty = "string | undefined".to_string();
self.cx.expose_global_argument_ptr()?;
self.cx.expose_uint32_memory();
self.prelude("const retptr = globalArgumentPtr();");
Expand Down