Drop trailing whitespace after all newlines.

This commit is contained in:
Logan Smyth 2016-07-17 10:14:29 -07:00
parent 59fe72ee7d
commit 4dcec860bd
4 changed files with 5 additions and 7 deletions

View File

@ -58,6 +58,9 @@ export default class Buffer {
*/
queue(str: string): void {
// Drop trailing spaces when a newline is inserted.
if (str === "\n") while (this._queue.length > 0 && SPACES_RE.test(this._queue[0][0])) this._queue.shift();
const { line, column, filename } = this._sourcePosition;
this._queue.unshift([str, line, column, filename]);
}
@ -86,10 +89,6 @@ export default class Buffer {
}
}
removeTrailingSpaces(): void {
while (this._queue.length > 0 && SPACES_RE.test(this._queue[0][0])) this._queue.shift();
}
removeTrailingNewline(): void {
if (this._queue.length > 0 && this._queue[0][0] === "\n") this._queue.shift();
}

View File

@ -167,7 +167,6 @@ export default class Printer {
if (this.endsWith("{\n") || this.endsWith(":\n")) i--;
if (i <= 0) return;
this._buf.removeTrailingSpaces();
for (let j = 0; j < i; j++) {
this._newline();
}

View File

@ -6,6 +6,6 @@ function foo(l) {
function foo() {
return (
1 && 2 ||
1 && 2 ||
3);
}

View File

@ -5,7 +5,7 @@ function foo() {
}
function foo() {
return(
return (
// foobar
"bar"
);