Skip to content

Commit

Permalink
cli-support: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
fitzgen committed Sep 11, 2019
1 parent 5f90951 commit 908fc61
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
29 changes: 17 additions & 12 deletions crates/cli-support/src/js/mod.rs
Expand Up @@ -465,12 +465,10 @@ impl<'a> Context<'a> {
};

let default_module_path = match self.config.mode {
OutputMode::Web => {
"\
OutputMode::Web => "\
if (typeof module === 'undefined') {
module = import.meta.url.replace(/\\.js$/, '_bg.wasm');
}"
}
}",
_ => "",
};

Expand Down Expand Up @@ -872,21 +870,30 @@ impl<'a> Context<'a> {

match self.config.encode_into {
EncodeInto::Always if !shared => {
self.global(&format!("
self.global(&format!(
"
const encodeString = {};
", encode_into));
",
encode_into
));
}
EncodeInto::Test if !shared => {
self.global(&format!("
self.global(&format!(
"
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
? {}
: {});
", encode_into, encode));
",
encode_into, encode
));
}
_ => {
self.global(&format!("
self.global(&format!(
"
const encodeString = {};
", encode));
",
encode
));
}
}

Expand Down Expand Up @@ -1080,7 +1087,6 @@ impl<'a> Context<'a> {
fields: Vec::new(),
})?;
self.global(&format!("let cached{} = new {}{};", s, name, args));

} else if !self.config.mode.always_run_in_browser() {
self.global(&format!(
"
Expand All @@ -1090,7 +1096,6 @@ impl<'a> Context<'a> {
s
));
self.global(&format!("let cached{0} = new l{0}{1};", s, args));

} else {
self.global(&format!("let cached{0} = new {0}{1};", s, args));
}
Expand Down
13 changes: 8 additions & 5 deletions crates/cli-support/src/lib.rs
Expand Up @@ -337,7 +337,12 @@ impl Bindgen {
// the webidl bindings proposal) as well as an auxiliary section for all
// sorts of miscellaneous information and features #[wasm_bindgen]
// 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,
// touch up the output of rustc to insert anyref shims where necessary.
Expand Down Expand Up @@ -563,16 +568,14 @@ impl Output {
} else {
format!("{}_bg", self.stem)
};
let wasm_path = out_dir
.join(wasm_name)
.with_extension("wasm");
let wasm_path = out_dir.join(wasm_name).with_extension("wasm");
fs::create_dir_all(out_dir)?;
let wasm_bytes = self.module.emit_wasm();
fs::write(&wasm_path, wasm_bytes)
.with_context(|_| format!("failed to write `{}`", wasm_path.display()))?;

if self.wasm_interface_types {
return Ok(())
return Ok(());
}

// Write out all local JS snippets to the final destination now that
Expand Down
12 changes: 9 additions & 3 deletions crates/cli-support/src/webidl/standard.rs
Expand Up @@ -453,7 +453,7 @@ fn extract_incoming(
exprs.push(e.clone());
continue;
}
NonstandardIncoming::Int64 { .. } => "64-bit integer",
NonstandardIncoming::Int64 { .. } => "64-bit integer",
NonstandardIncoming::AllocCopyInt64 { .. } => "64-bit integer array",
NonstandardIncoming::AllocCopyAnyrefArray { .. } => "array of JsValue",
NonstandardIncoming::MutableSlice { .. } => "mutable slice",
Expand All @@ -472,7 +472,10 @@ fn extract_incoming(
NonstandardIncoming::Char { .. } => "character",
NonstandardIncoming::BorrowedAnyref { .. } => "borrowed anyref",
};
bail!("cannot represent {} with a standard bindings expression", desc);
bail!(
"cannot represent {} with a standard bindings expression",
desc
);
}
Ok(exprs)
}
Expand Down Expand Up @@ -525,7 +528,10 @@ fn extract_outgoing(
NonstandardOutgoing::OptionRustType { .. } => "optional rust type",
NonstandardOutgoing::StackClosure { .. } => "closures",
};
bail!("cannot represent {} with a standard bindings expression", desc);
bail!(
"cannot represent {} with a standard bindings expression",
desc
);
}
Ok(exprs)
}
Expand Down

0 comments on commit 908fc61

Please sign in to comment.