From 1487288050d924c9f7aafd4c344624e555a15494 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 30 Jan 2018 07:45:36 -0800 Subject: [PATCH] Expose typescript option in wasm2es6js --- crates/wasm-bindgen-cli/src/bin/wasm2es6js.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/wasm-bindgen-cli/src/bin/wasm2es6js.rs b/crates/wasm-bindgen-cli/src/bin/wasm2es6js.rs index 7f67714e..7f56660c 100644 --- a/crates/wasm-bindgen-cli/src/bin/wasm2es6js.rs +++ b/crates/wasm-bindgen-cli/src/bin/wasm2es6js.rs @@ -4,13 +4,11 @@ extern crate docopt; extern crate parity_wasm; extern crate wasm_bindgen_cli_support; -use std::collections::HashSet; use std::fs::File; use std::io::{Write, Read}; use std::path::PathBuf; use docopt::Docopt; -use parity_wasm::elements::*; const USAGE: &'static str = " Converts a wasm file to an ES6 JS module @@ -22,12 +20,14 @@ Usage: Options: -h --help Show this screen. -o --output FILE File to place output in + --output-ts FILE File to place a typescript definition of the module to --base64 Inline the wasm module using base64 encoding "; #[derive(Debug, Deserialize)] struct Args { flag_output: Option, + flag_output_ts: Option, flag_base64: bool, arg_input: PathBuf, } @@ -49,6 +49,12 @@ fn main() { .base64(args.flag_base64) .generate(&wasm) .expect("failed to parse wasm"); + + if let Some(ref p) = args.flag_output_ts { + File::create(p).expect("failed to create output") + .write_all(object.typescript().as_bytes()).expect("failed to write output"); + } + let js = object.js(); match args.flag_output {