From 89bd10f9745f49640646707f212c399ba28a334e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 27 Apr 2018 07:14:46 -0700 Subject: [PATCH] Emit `*.d.ts` file by default --- README.md | 5 ++--- crates/cli/src/bin/wasm-bindgen.rs | 8 ++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f568e819..479353a8 100644 --- a/README.md +++ b/README.md @@ -550,9 +550,8 @@ some notable options are: `window.wasm_bindgen.foo`. Note that the name `wasm_bindgen` can be configured with the `--no-modules-global FOO` flag. -* `--typescript` - when passed a `*.d.ts` file will be generated for the - generated JS file. This should allow hooking into TypeScript projects to - ensure everything still typechecks. +* `--no-typescript` - by default a `*.d.ts` file is generated for the generated + JS file, but this flag will disable generating this TypeScript file. * `--debug` - generates a bit more JS and wasm in "debug mode" to help catch programmer errors, but this output isn't intended to be shipped to production diff --git a/crates/cli/src/bin/wasm-bindgen.rs b/crates/cli/src/bin/wasm-bindgen.rs index 02974770..e8d6de13 100644 --- a/crates/cli/src/bin/wasm-bindgen.rs +++ b/crates/cli/src/bin/wasm-bindgen.rs @@ -28,7 +28,8 @@ Options: --browser Generate output that only works in a browser --no-modules Generate output that only works in a browser (without modules) --no-modules-global VAR Name of the global variable to initialize - --typescript Output a TypeScript definition file + --typescript Output a TypeScript definition file (on by default) + --no-typescript Don't emit a *.d.ts file --debug Include otherwise-extraneous debug checks in output --no-demangle Don't demangle Rust symbol names -V --version Print the version number of wasm-bindgen @@ -40,6 +41,7 @@ struct Args { flag_browser: bool, flag_no_modules: bool, flag_typescript: bool, + flag_no_typescript: bool, flag_out_dir: Option, flag_debug: bool, flag_version: bool, @@ -74,6 +76,8 @@ fn rmain(args: &Args) -> Result<(), Error> { None => bail!("input file expected"), }; + let typescript = args.flag_typescript || !args.flag_no_typescript; + let mut b = Bindgen::new(); b.input_path(input) .nodejs(args.flag_nodejs) @@ -81,7 +85,7 @@ fn rmain(args: &Args) -> Result<(), Error> { .no_modules(args.flag_no_modules) .debug(args.flag_debug) .demangle(!args.flag_no_demangle) - .typescript(args.flag_typescript); + .typescript(typescript); if let Some(ref name) = args.flag_no_modules_global { b.no_modules_global(name); }