Merge pull request #1053 from alexcrichton/dts-wasm

Generate a `*.d.ts` file for wasm files
This commit is contained in:
Alex Crichton
2018-11-27 16:55:25 -06:00
committed by GitHub
2 changed files with 76 additions and 73 deletions

View File

@ -217,7 +217,7 @@ impl Bindgen {
.with_context(|_| format!("failed to write `{}`", js_path.display()))?;
if self.typescript {
let ts_path = out_dir.join(stem).with_extension("d.ts");
let ts_path = js_path.with_extension("d.ts");
fs::write(&ts_path, ts)
.with_context(|_| format!("failed to write `{}`", ts_path.display()))?;
}
@ -231,9 +231,17 @@ impl Bindgen {
.with_context(|_| format!("failed to write `{}`", js_path.display()))?;
}
if self.typescript {
let ts_path = wasm_path.with_extension("d.ts");
let ts = wasm2es6js::typescript(&module);
fs::write(&ts_path, ts)
.with_context(|_| format!("failed to write `{}`", ts_path.display()))?;
}
let wasm_bytes = parity_wasm::serialize(module)?;
fs::write(&wasm_path, wasm_bytes)
.with_context(|_| format!("failed to write `{}`", wasm_path.display()))?;
Ok(())
}