Fix generated binding for functions returning structs.

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

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

View File

@ -56,9 +56,17 @@ impl<'a> Context<'a> {
let contents = deindent(contents);
let contents = contents.trim();
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 {
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 {
if contents.starts_with("function") {
format!("export function {}{}\n", name, &contents[8..])