Skip to content

Commit

Permalink
Remove extra trailing newline in preprocessor.js output (emscripten-c…
Browse files Browse the repository at this point in the history
…ore#19574)

There were two different causes of extra newlines here.
  • Loading branch information
sbc100 authored Jun 9, 2023
1 parent 5625819 commit 5b9aace
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extends:
parserOptions:
ecmaVersion: 12
ignorePatterns:
- "out/"
- "site/"
- "cache/"
- "third_party/"
Expand Down
5 changes: 5 additions & 0 deletions src/parseTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ function preprocess(filename) {
const isHtml = (fileExt === 'html' || fileExt === 'htm') ? true : false;
let inStyle = false;
const lines = text.split('\n');
// text.split yields an extra empty element at the end if text itself ends with a newline.
if (!lines[lines.length - 1]) {
lines.pop();
}

let ret = '';
let emptyLine = false;

Expand Down
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
59358
59351
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_no_asserts.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
33006
33001
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_strict.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
58324
58317
9 changes: 4 additions & 5 deletions tools/preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// Parameters:
// setting file. Can specify 'settings.js' here, alternatively create a temp
// file with modified settings and supply the filename here.
// shell file This is the file that will be processed by the preprocessor
// input file This is the file that will be processed by the preprocessor

'use strict';

Expand Down Expand Up @@ -51,14 +51,13 @@ global.load = (f) => {
};

const settingsFile = arguments_[0];
const shellFile = arguments_[1];
const inputFile = arguments_[1];
const expandMacros = arguments_.includes('--expandMacros');

load(settingsFile);
load('utility.js');
load('modules.js');
load('parseTools.js');

const toHTML = expandMacros ? processMacros(preprocess(shellFile)) : preprocess(shellFile);

print(toHTML);
const output = expandMacros ? processMacros(preprocess(inputFile)) : preprocess(inputFile);
process.stdout.write(output);

0 comments on commit 5b9aace

Please sign in to comment.