Merge pull request #1221 from rhysd/format-dts-file

Format .d.ts file
This commit is contained in:
Alex Crichton 2019-02-01 09:24:49 -06:00 committed by GitHub
commit 2e80313aa3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View File

@ -750,12 +750,16 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
.map(|s| format!("{}: {}", s.0, s.1))
.collect::<Vec<_>>()
.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())
}
}

View File

@ -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