Merge pull request #173 from rustwasm/ts-default

Emit `*.d.ts` file by default
This commit is contained in:
Alex Crichton 2018-04-27 12:40:14 -05:00 committed by GitHub
commit ba03cc3684
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -550,9 +550,8 @@ some notable options are:
`window.wasm_bindgen.foo`. Note that the name `wasm_bindgen` can be configured `window.wasm_bindgen.foo`. Note that the name `wasm_bindgen` can be configured
with the `--no-modules-global FOO` flag. with the `--no-modules-global FOO` flag.
* `--typescript` - when passed a `*.d.ts` file will be generated for the * `--no-typescript` - by default a `*.d.ts` file is generated for the generated
generated JS file. This should allow hooking into TypeScript projects to JS file, but this flag will disable generating this TypeScript file.
ensure everything still typechecks.
* `--debug` - generates a bit more JS and wasm in "debug mode" to help catch * `--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 programmer errors, but this output isn't intended to be shipped to production

View File

@ -28,7 +28,8 @@ Options:
--browser Generate output that only works in a browser --browser Generate output that only works in a browser
--no-modules Generate output that only works in a browser (without modules) --no-modules Generate output that only works in a browser (without modules)
--no-modules-global VAR Name of the global variable to initialize --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 --debug Include otherwise-extraneous debug checks in output
--no-demangle Don't demangle Rust symbol names --no-demangle Don't demangle Rust symbol names
-V --version Print the version number of wasm-bindgen -V --version Print the version number of wasm-bindgen
@ -40,6 +41,7 @@ struct Args {
flag_browser: bool, flag_browser: bool,
flag_no_modules: bool, flag_no_modules: bool,
flag_typescript: bool, flag_typescript: bool,
flag_no_typescript: bool,
flag_out_dir: Option<PathBuf>, flag_out_dir: Option<PathBuf>,
flag_debug: bool, flag_debug: bool,
flag_version: bool, flag_version: bool,
@ -74,6 +76,8 @@ fn rmain(args: &Args) -> Result<(), Error> {
None => bail!("input file expected"), None => bail!("input file expected"),
}; };
let typescript = args.flag_typescript || !args.flag_no_typescript;
let mut b = Bindgen::new(); let mut b = Bindgen::new();
b.input_path(input) b.input_path(input)
.nodejs(args.flag_nodejs) .nodejs(args.flag_nodejs)
@ -81,7 +85,7 @@ fn rmain(args: &Args) -> Result<(), Error> {
.no_modules(args.flag_no_modules) .no_modules(args.flag_no_modules)
.debug(args.flag_debug) .debug(args.flag_debug)
.demangle(!args.flag_no_demangle) .demangle(!args.flag_no_demangle)
.typescript(args.flag_typescript); .typescript(typescript);
if let Some(ref name) = args.flag_no_modules_global { if let Some(ref name) = args.flag_no_modules_global {
b.no_modules_global(name); b.no_modules_global(name);
} }