Drop trailing whitespace after all newlines.
This commit is contained in:
parent
59fe72ee7d
commit
4dcec860bd
@ -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();
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
@ -6,6 +6,6 @@ function foo(l) {
|
||||
|
||||
function foo() {
|
||||
return (
|
||||
1 && 2 ||
|
||||
1 && 2 ||
|
||||
3);
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ function foo() {
|
||||
}
|
||||
|
||||
function foo() {
|
||||
return(
|
||||
return (
|
||||
// foobar
|
||||
"bar"
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user