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

Fix generated binding for functions returning structs.

This only affects --no-modules and --nodejs modes.

Fixes .
This commit is contained in:
Gergely Nagy 2018-05-06 18:00:14 +02:00
parent 6d167116a0
commit 02adf6defa

@ -56,9 +56,17 @@ impl<'a> Context<'a> {
let contents = deindent(contents); let contents = deindent(contents);
let contents = contents.trim(); let contents = contents.trim();
let global = if self.config.nodejs { let global = if self.config.nodejs {
format!("module.exports.{} = {};\n", name, contents) if contents.starts_with("class") {
format!("{1}\nmodule.exports.{0} = {0};\n", name, contents)
} else {
format!("module.exports.{} = {};\n", name, contents)
}
} else if self.config.no_modules { } else if self.config.no_modules {
format!("__exports.{} = {}\n", name, contents) if contents.starts_with("class") {
format!("{1}\n__exports.{0} = {0};\n", name, contents)
} else {
format!("__exports.{} = {};\n", name, contents)
}
} else { } else {
if contents.starts_with("function") { if contents.starts_with("function") {
format!("export function {}{}\n", name, &contents[8..]) format!("export function {}{}\n", name, &contents[8..])