From 1c52fb1b2fd69215a9fd1c27c4108b23de8661eb Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Thu, 13 Sep 2018 22:10:59 -0700 Subject: [PATCH 1/2] Remove leading and trailing blanks from the --no-modules output The output using modules already uses string formatting that carefully avoids emitting leading and trailing blanks; adjust the --no-modules output to match. --- crates/cli-support/src/js/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/cli-support/src/js/mod.rs b/crates/cli-support/src/js/mod.rs index 29c3be86..e1a9175d 100644 --- a/crates/cli-support/src/js/mod.rs +++ b/crates/cli-support/src/js/mod.rs @@ -417,7 +417,7 @@ impl<'a> Context<'a> { let mut js = if self.config.no_modules { format!( - " + "\ (function() {{ var wasm; const __exports = {{}}; @@ -438,8 +438,7 @@ impl<'a> Context<'a> { }}); }}; self.{global_name} = Object.assign(init, __exports); - }})(); - ", + }})();", globals = self.globals, module = module_name, global_name = self.config.no_modules_global From 96a70c41bea3ebf32eeaae1a73d6952e3bdbca4b Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Thu, 13 Sep 2018 22:13:07 -0700 Subject: [PATCH 2/2] reset_indentation: Don't emit indentation on blank lines This resulted in trailing whitespace in the generated file. In addition to wasting space in a file that gets served over the wire, this also gets highlighted as a problem when reviewing the generated file in an editor that highlights trailing whitespace. --- crates/cli-support/src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/cli-support/src/lib.rs b/crates/cli-support/src/lib.rs index 6af4ac1a..75b3291c 100644 --- a/crates/cli-support/src/lib.rs +++ b/crates/cli-support/src/lib.rs @@ -388,10 +388,12 @@ fn reset_indentation(s: &str) -> String { indent = indent.saturating_sub(1); } let extra = if line.starts_with(':') || line.starts_with('?') { 1 } else { 0 }; - for _ in 0..indent + extra { - dst.push_str(" "); + if !line.is_empty() { + for _ in 0..indent + extra { + dst.push_str(" "); + } + dst.push_str(line); } - dst.push_str(line); dst.push_str("\n"); if line.ends_with('{') { indent += 1;