cli-support: cargo fmt

This commit is contained in:
Nick Fitzgerald 2019-09-10 11:20:19 -07:00
parent 5f90951441
commit 908fc614c0
3 changed files with 34 additions and 20 deletions

View File

@ -465,12 +465,10 @@ impl<'a> Context<'a> {
}; };
let default_module_path = match self.config.mode { let default_module_path = match self.config.mode {
OutputMode::Web => { OutputMode::Web => "\
"\
if (typeof module === 'undefined') { if (typeof module === 'undefined') {
module = import.meta.url.replace(/\\.js$/, '_bg.wasm'); module = import.meta.url.replace(/\\.js$/, '_bg.wasm');
}" }",
}
_ => "", _ => "",
}; };
@ -872,21 +870,30 @@ impl<'a> Context<'a> {
match self.config.encode_into { match self.config.encode_into {
EncodeInto::Always if !shared => { EncodeInto::Always if !shared => {
self.global(&format!(" self.global(&format!(
"
const encodeString = {}; const encodeString = {};
", encode_into)); ",
encode_into
));
} }
EncodeInto::Test if !shared => { EncodeInto::Test if !shared => {
self.global(&format!(" self.global(&format!(
"
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
? {} ? {}
: {}); : {});
", encode_into, encode)); ",
encode_into, encode
));
} }
_ => { _ => {
self.global(&format!(" self.global(&format!(
"
const encodeString = {}; const encodeString = {};
", encode)); ",
encode
));
} }
} }
@ -1080,7 +1087,6 @@ impl<'a> Context<'a> {
fields: Vec::new(), fields: Vec::new(),
})?; })?;
self.global(&format!("let cached{} = new {}{};", s, name, args)); self.global(&format!("let cached{} = new {}{};", s, name, args));
} else if !self.config.mode.always_run_in_browser() { } else if !self.config.mode.always_run_in_browser() {
self.global(&format!( self.global(&format!(
" "
@ -1090,7 +1096,6 @@ impl<'a> Context<'a> {
s s
)); ));
self.global(&format!("let cached{0} = new l{0}{1};", s, args)); self.global(&format!("let cached{0} = new l{0}{1};", s, args));
} else { } else {
self.global(&format!("let cached{0} = new {0}{1};", s, args)); self.global(&format!("let cached{0} = new {0}{1};", s, args));
} }

View File

@ -337,7 +337,12 @@ impl Bindgen {
// the webidl bindings proposal) as well as an auxiliary section for all // the webidl bindings proposal) as well as an auxiliary section for all
// sorts of miscellaneous information and features #[wasm_bindgen] // sorts of miscellaneous information and features #[wasm_bindgen]
// supports that aren't covered by WebIDL bindings. // supports that aren't covered by WebIDL bindings.
webidl::process(&mut module, self.anyref, self.wasm_interface_types, self.emit_start)?; webidl::process(
&mut module,
self.anyref,
self.wasm_interface_types,
self.emit_start,
)?;
// Now that we've got type information from the webidl processing pass, // Now that we've got type information from the webidl processing pass,
// touch up the output of rustc to insert anyref shims where necessary. // touch up the output of rustc to insert anyref shims where necessary.
@ -563,16 +568,14 @@ impl Output {
} else { } else {
format!("{}_bg", self.stem) format!("{}_bg", self.stem)
}; };
let wasm_path = out_dir let wasm_path = out_dir.join(wasm_name).with_extension("wasm");
.join(wasm_name)
.with_extension("wasm");
fs::create_dir_all(out_dir)?; fs::create_dir_all(out_dir)?;
let wasm_bytes = self.module.emit_wasm(); let wasm_bytes = self.module.emit_wasm();
fs::write(&wasm_path, wasm_bytes) fs::write(&wasm_path, wasm_bytes)
.with_context(|_| format!("failed to write `{}`", wasm_path.display()))?; .with_context(|_| format!("failed to write `{}`", wasm_path.display()))?;
if self.wasm_interface_types { if self.wasm_interface_types {
return Ok(()) return Ok(());
} }
// Write out all local JS snippets to the final destination now that // Write out all local JS snippets to the final destination now that

View File

@ -453,7 +453,7 @@ fn extract_incoming(
exprs.push(e.clone()); exprs.push(e.clone());
continue; continue;
} }
NonstandardIncoming::Int64 { .. } => "64-bit integer", NonstandardIncoming::Int64 { .. } => "64-bit integer",
NonstandardIncoming::AllocCopyInt64 { .. } => "64-bit integer array", NonstandardIncoming::AllocCopyInt64 { .. } => "64-bit integer array",
NonstandardIncoming::AllocCopyAnyrefArray { .. } => "array of JsValue", NonstandardIncoming::AllocCopyAnyrefArray { .. } => "array of JsValue",
NonstandardIncoming::MutableSlice { .. } => "mutable slice", NonstandardIncoming::MutableSlice { .. } => "mutable slice",
@ -472,7 +472,10 @@ fn extract_incoming(
NonstandardIncoming::Char { .. } => "character", NonstandardIncoming::Char { .. } => "character",
NonstandardIncoming::BorrowedAnyref { .. } => "borrowed anyref", NonstandardIncoming::BorrowedAnyref { .. } => "borrowed anyref",
}; };
bail!("cannot represent {} with a standard bindings expression", desc); bail!(
"cannot represent {} with a standard bindings expression",
desc
);
} }
Ok(exprs) Ok(exprs)
} }
@ -525,7 +528,10 @@ fn extract_outgoing(
NonstandardOutgoing::OptionRustType { .. } => "optional rust type", NonstandardOutgoing::OptionRustType { .. } => "optional rust type",
NonstandardOutgoing::StackClosure { .. } => "closures", NonstandardOutgoing::StackClosure { .. } => "closures",
}; };
bail!("cannot represent {} with a standard bindings expression", desc); bail!(
"cannot represent {} with a standard bindings expression",
desc
);
} }
Ok(exprs) Ok(exprs)
} }