Merge pull request #3104 from amasad/semi

Fix up semicolon omission in compact mode
This commit is contained in:
Sebastian McKenzie 2015-11-25 13:55:09 +11:00
commit 8457885599
6 changed files with 18 additions and 8 deletions

View File

@ -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("}");
}

View File

@ -130,6 +130,7 @@ export let YieldExpression = buildYieldAwait("yield");
export let AwaitExpression = buildYieldAwait("await");
export function EmptyStatement() {
this._lastPrintedIsEmptyStatement = true;
this.semicolon();
}

View File

@ -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) {

View File

@ -1,6 +1,12 @@
function foo() {
var x = 1;
y();
if (bar) {
baz();
}
return;
}
function bar() {
for(;;);
}

View File

@ -1 +1 @@
function foo(){if(bar){baz();}return;}
function foo(){var x=1;y();if(bar){baz()}return}function bar(){for(;;);}

View File

@ -1,4 +1,4 @@
function foo(l){
return (
l);}
l)}