diff --git a/crates/cli-support/src/js/js2rust.rs b/crates/cli-support/src/js/js2rust.rs index 847b56ab..91b4b4f2 100644 --- a/crates/cli-support/src/js/js2rust.rs +++ b/crates/cli-support/src/js/js2rust.rs @@ -750,12 +750,16 @@ impl<'a, 'b> Js2Rust<'a, 'b> { .map(|s| format!("{}: {}", s.0, s.1)) .collect::>() .join(", "); - let mut ts = format!("{} {}({})", prefix, self.js_name, ts_args); + let mut ts = if prefix.is_empty() { + format!("{}({})", self.js_name, ts_args) + } else { + format!("{} {}({})", prefix, self.js_name, ts_args) + }; if self.constructor.is_none() { ts.push_str(": "); ts.push_str(&self.ret_ty); } - ts.push_str(";\n"); + ts.push(';'); (js, ts, self.js_doc_comments()) } } diff --git a/crates/cli-support/src/js/mod.rs b/crates/cli-support/src/js/mod.rs index 97a062f4..0ff36301 100644 --- a/crates/cli-support/src/js/mod.rs +++ b/crates/cli-support/src/js/mod.rs @@ -845,7 +845,7 @@ impl<'a> Context<'a> { ", name, )); - ts_dst.push_str("free(): void;\n"); + ts_dst.push_str(" free(): void;"); dst.push_str(&class.contents); ts_dst.push_str(&class.typescript); dst.push_str("}\n"); @@ -2399,6 +2399,8 @@ impl<'a, 'b> SubContext<'a, 'b> { .contents .push_str(&format_doc_comments(&export.comments, Some(js_doc))); + class.typescript.push_str(" "); // Indentation + if export.is_constructor { if class.has_constructor { bail!("found duplicate constructor `{}`", export.function.name); @@ -2571,12 +2573,12 @@ impl<'a, 'b> SubContext<'a, 'b> { .typescript .push_str(&format!("export enum {} {{", enum_.name)); - variants.clear(); for variant in enum_.variants.iter() { - variants.push_str(&format!("{},", variant.name)); + self.cx + .typescript + .push_str(&format!("\n {},", variant.name)); } - self.cx.typescript.push_str(&variants); - self.cx.typescript.push_str("}\n"); + self.cx.typescript.push_str("\n}\n"); } fn generate_struct(&mut self, struct_: &decode::Struct) -> Result<(), Error> { @@ -2596,7 +2598,7 @@ impl<'a, 'b> SubContext<'a, 'b> { .argument(&descriptor)? .ret(&Descriptor::Unit)?; ts_dst.push_str(&format!( - "{}{}: {};\n", + "\n {}{}: {};", if field.readonly { "readonly " } else { "" }, field.name, &cx.js_arguments[0].1