Merge pull request #3104 from amasad/semi
Fix up semicolon omission in compact mode
This commit is contained in:
commit
8457885599
@ -101,7 +101,9 @@ export default class Buffer {
|
||||
|
||||
rightBrace() {
|
||||
this.newline(true);
|
||||
//if (this.format.compact) this._removeLast(";");
|
||||
if (this.format.compact && !this._lastPrintedIsEmptyStatement) {
|
||||
this._removeLast(";");
|
||||
}
|
||||
this.push("}");
|
||||
}
|
||||
|
||||
|
||||
@ -130,6 +130,7 @@ export let YieldExpression = buildYieldAwait("yield");
|
||||
export let AwaitExpression = buildYieldAwait("await");
|
||||
|
||||
export function EmptyStatement() {
|
||||
this._lastPrintedIsEmptyStatement = true;
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
|
||||
@ -13,6 +13,8 @@ export default class Printer extends Buffer {
|
||||
print(node, parent, opts = {}) {
|
||||
if (!node) return;
|
||||
|
||||
this._lastPrintedIsEmptyStatement = false;
|
||||
|
||||
if (parent && parent._compact) {
|
||||
node._compact = true;
|
||||
}
|
||||
@ -144,12 +146,11 @@ export default class Printer extends Buffer {
|
||||
|
||||
printBlock(parent) {
|
||||
let node = parent.body;
|
||||
if (t.isEmptyStatement(node)) {
|
||||
this.semicolon();
|
||||
} else {
|
||||
this.push(" ");
|
||||
this.print(node, parent);
|
||||
if (!t.isEmptyStatement(node)) {
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.print(node, parent);
|
||||
}
|
||||
|
||||
generateComment(comment) {
|
||||
|
||||
@ -1,6 +1,12 @@
|
||||
function foo() {
|
||||
var x = 1;
|
||||
y();
|
||||
if (bar) {
|
||||
baz();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
function bar() {
|
||||
for(;;);
|
||||
}
|
||||
|
||||
@ -1 +1 @@
|
||||
function foo(){if(bar){baz();}return;}
|
||||
function foo(){var x=1;y();if(bar){baz()}return}function bar(){for(;;);}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
function foo(l){
|
||||
return (
|
||||
|
||||
l);}
|
||||
l)}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user