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() { rightBrace() {
this.newline(true); this.newline(true);
//if (this.format.compact) this._removeLast(";"); if (this.format.compact && !this._lastPrintedIsEmptyStatement) {
this._removeLast(";");
}
this.push("}"); this.push("}");
} }

View File

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

View File

@ -13,6 +13,8 @@ export default class Printer extends Buffer {
print(node, parent, opts = {}) { print(node, parent, opts = {}) {
if (!node) return; if (!node) return;
this._lastPrintedIsEmptyStatement = false;
if (parent && parent._compact) { if (parent && parent._compact) {
node._compact = true; node._compact = true;
} }
@ -144,12 +146,11 @@ export default class Printer extends Buffer {
printBlock(parent) { printBlock(parent) {
let node = parent.body; let node = parent.body;
if (t.isEmptyStatement(node)) { if (!t.isEmptyStatement(node)) {
this.semicolon(); this.space();
} else {
this.push(" ");
this.print(node, parent);
} }
this.print(node, parent);
} }
generateComment(comment) { generateComment(comment) {

View File

@ -1,6 +1,12 @@
function foo() { function foo() {
var x = 1;
y();
if (bar) { if (bar) {
baz(); baz();
} }
return; 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){ function foo(l){
return ( return (
l);} l)}