Skip to content

Commit b66d106

Browse files
authored
Merge pull request #827 from joshtriplett/clean-up-generated-code
Clean up indentation and blanks in the generated --no-modules JavaScript
2 parents 05a0a5c + 96a70c4 commit b66d106

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

crates/cli-support/src/js/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl<'a> Context<'a> {
417417

418418
let mut js = if self.config.no_modules {
419419
format!(
420-
"
420+
"\
421421
(function() {{
422422
var wasm;
423423
const __exports = {{}};
@@ -438,8 +438,7 @@ impl<'a> Context<'a> {
438438
}});
439439
}};
440440
self.{global_name} = Object.assign(init, __exports);
441-
}})();
442-
",
441+
}})();",
443442
globals = self.globals,
444443
module = module_name,
445444
global_name = self.config.no_modules_global

crates/cli-support/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,12 @@ fn reset_indentation(s: &str) -> String {
388388
indent = indent.saturating_sub(1);
389389
}
390390
let extra = if line.starts_with(':') || line.starts_with('?') { 1 } else { 0 };
391-
for _ in 0..indent + extra {
392-
dst.push_str(" ");
391+
if !line.is_empty() {
392+
for _ in 0..indent + extra {
393+
dst.push_str(" ");
394+
}
395+
dst.push_str(line);
393396
}
394-
dst.push_str(line);
395397
dst.push_str("\n");
396398
if line.ends_with('{') {
397399
indent += 1;

0 commit comments

Comments
 (0)