Skip to content

Commit 5b9aace

Browse files
authored
Remove extra trailing newline in preprocessor.js output (#19574)
There were two different causes of extra newlines here.
1 parent 5625819 commit 5b9aace

File tree

6 files changed

+13
-8
lines changed

6 files changed

+13
-8
lines changed

.eslintrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extends:
77
parserOptions:
88
ecmaVersion: 12
99
ignorePatterns:
10+
- "out/"
1011
- "site/"
1112
- "cache/"
1213
- "third_party/"

src/parseTools.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ function preprocess(filename) {
6161
const isHtml = (fileExt === 'html' || fileExt === 'htm') ? true : false;
6262
let inStyle = false;
6363
const lines = text.split('\n');
64+
// text.split yields an extra empty element at the end if text itself ends with a newline.
65+
if (!lines[lines.length - 1]) {
66+
lines.pop();
67+
}
68+
6469
let ret = '';
6570
let emptyLine = false;
6671

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
59358
1+
59351
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
33006
1+
33001
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
58324
1+
58317

tools/preprocessor.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// Parameters:
1111
// setting file. Can specify 'settings.js' here, alternatively create a temp
1212
// file with modified settings and supply the filename here.
13-
// shell file This is the file that will be processed by the preprocessor
13+
// input file This is the file that will be processed by the preprocessor
1414

1515
'use strict';
1616

@@ -51,14 +51,13 @@ global.load = (f) => {
5151
};
5252

5353
const settingsFile = arguments_[0];
54-
const shellFile = arguments_[1];
54+
const inputFile = arguments_[1];
5555
const expandMacros = arguments_.includes('--expandMacros');
5656

5757
load(settingsFile);
5858
load('utility.js');
5959
load('modules.js');
6060
load('parseTools.js');
6161

62-
const toHTML = expandMacros ? processMacros(preprocess(shellFile)) : preprocess(shellFile);
63-
64-
print(toHTML);
62+
const output = expandMacros ? processMacros(preprocess(inputFile)) : preprocess(inputFile);
63+
process.stdout.write(output);

0 commit comments

Comments
 (0)