1
0
mirror of https://github.com/fluencelabs/wasm-bindgen synced 2025-03-16 18:20:51 +00:00

Merge pull request from marienz/typescript-init

Make the argument to init optional in the Typescript declaration too
This commit is contained in:
Alex Crichton 2019-06-17 07:32:09 -05:00 committed by GitHub
commit 379cad047a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -396,7 +396,7 @@ impl<'a> Context<'a> {
Ok(imports) Ok(imports)
} }
fn ts_for_init_fn(has_memory: bool) -> String { fn ts_for_init_fn(has_memory: bool, has_module_or_path_optional: bool) -> String {
let (memory_doc, memory_param) = if has_memory { let (memory_doc, memory_param) = if has_memory {
( (
"* @param {WebAssembly.Memory} maybe_memory\n", "* @param {WebAssembly.Memory} maybe_memory\n",
@ -405,6 +405,7 @@ impl<'a> Context<'a> {
} else { } else {
("", "") ("", "")
}; };
let arg_optional = if has_module_or_path_optional { "?" } else { "" };
format!( format!(
"\n\ "\n\
/**\n\ /**\n\
@ -417,9 +418,9 @@ impl<'a> Context<'a> {
* @returns {{Promise<any>}}\n\ * @returns {{Promise<any>}}\n\
*/\n\ */\n\
export default function init \ export default function init \
(module_or_path: RequestInfo | BufferSource | WebAssembly.Module{}): Promise<any>; (module_or_path{}: RequestInfo | BufferSource | WebAssembly.Module{}): Promise<any>;
", ",
memory_doc, memory_param memory_doc, arg_optional, memory_param
) )
} }
@ -461,7 +462,7 @@ impl<'a> Context<'a> {
_ => "", _ => "",
}; };
let ts = Self::ts_for_init_fn(mem.import.is_some()); let ts = Self::ts_for_init_fn(mem.import.is_some(), !default_module_path.is_empty());
// Initialize the `imports` object for all import definitions that we're // Initialize the `imports` object for all import definitions that we're
// directed to wire up. // directed to wire up.