Merge pull request #827 from joshtriplett/clean-up-generated-code

Clean up indentation and blanks in the generated --no-modules JavaScript
This commit is contained in:
Alex Crichton 2018-09-14 09:28:09 -07:00 committed by GitHub
commit b66d1064d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -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

View File

@ -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;