From 02adf6defa17f881f29207bc70a9a10e22774c20 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sun, 6 May 2018 18:00:14 +0200 Subject: [PATCH] Fix generated binding for functions returning structs. This only affects --no-modules and --nodejs modes. Fixes #190. --- crates/cli-support/src/js/mod.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/cli-support/src/js/mod.rs b/crates/cli-support/src/js/mod.rs index 3bfe9b8c..3009a503 100644 --- a/crates/cli-support/src/js/mod.rs +++ b/crates/cli-support/src/js/mod.rs @@ -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..])