From d331b706c30ec3c79477c9a00e8c88389231026a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Sj=C3=B6=C3=B6h?= Date: Sun, 4 Nov 2018 10:26:20 +0100 Subject: [PATCH] update typescript generation to reflect that Option can be undefined --- crates/cli-support/src/js/js2rust.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/cli-support/src/js/js2rust.rs b/crates/cli-support/src/js/js2rust.rs index fe29defec88..d90fb5e3a9c 100644 --- a/crates/cli-support/src/js/js2rust.rs +++ b/crates/cli-support/src/js/js2rust.rs @@ -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 { @@ -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; @@ -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(); @@ -567,7 +567,7 @@ 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; @@ -575,7 +575,7 @@ impl<'a, 'b> Js2Rust<'a, 'b> { 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();");