Skip to content

Commit

Permalink
Make the argument to init optional in the Typescript declaration too
Browse files Browse the repository at this point in the history
Commit 8ace828 made the argument to the
generated init() function optional (when the target is "web"), but it is still
marked as required in the generated .d.ts file.

Fix the generated declaration to match the function definition again.
  • Loading branch information
marienz committed Jun 16, 2019
1 parent 9cac16f commit 1b91457
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions crates/cli-support/src/js/mod.rs
Expand Up @@ -396,7 +396,7 @@ impl<'a> Context<'a> {
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 {
(
"* @param {WebAssembly.Memory} maybe_memory\n",
Expand All @@ -405,6 +405,7 @@ impl<'a> Context<'a> {
} else {
("", "")
};
let arg_optional = if has_module_or_path_optional { "?" } else { "" };
format!(
"\n\
/**\n\
Expand All @@ -417,9 +418,9 @@ impl<'a> Context<'a> {
* @returns {{Promise<any>}}\n\
*/\n\
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
)
}

Expand Down Expand Up @@ -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
// directed to wire up.
Expand Down

0 comments on commit 1b91457

Please sign in to comment.