diff --git a/src/printer.js b/src/printer.js index 1577c3ec5..f4ba3d7a9 100644 --- a/src/printer.js +++ b/src/printer.js @@ -54,24 +54,29 @@ function genericPrint(path, options, print) { ]); } return concat(['import ', doc, ';']); - case 'ContractDefinition': - doc = concat([node.kind, ' ', node.name]); + case 'ContractDefinition': { + let parts = [node.kind, ' ', node.name]; + if (node.baseContracts.length > 0) { - doc = concat([ - doc, + parts = parts.concat([ ' is ', join(', ', path.map(print, 'baseContracts')) ]); } - return concat([ - doc, - ' {', - indent(line), - indent(printPreservingEmptyLines(path, 'subNodes', options, print)), - line, - '}', - line - ]); + + parts.push(' {'); + if (node.subNodes.length > 0) { + parts = parts.concat([ + indent(line), + indent(printPreservingEmptyLines(path, 'subNodes', options, print)), + line + ]); + } + parts.push('}'); + parts.push(line); + + return concat(parts); + } case 'InheritanceSpecifier': { let parts = [path.call(print, 'baseName')]; @@ -159,6 +164,11 @@ function genericPrint(path, options, print) { } return doc; case 'Block': { + // if block is empty, just return the pair of braces + if (node.statements.length === 0 && !node.comments) { + return '{}'; + } + const parts = [ '{', indent(line), diff --git a/tests/AllSolidityFeatures/__snapshots__/jsfmt.spec.js.snap b/tests/AllSolidityFeatures/__snapshots__/jsfmt.spec.js.snap index c453172d3..865bb9f94 100644 --- a/tests/AllSolidityFeatures/__snapshots__/jsfmt.spec.js.snap +++ b/tests/AllSolidityFeatures/__snapshots__/jsfmt.spec.js.snap @@ -466,9 +466,7 @@ contract Base { } contract Derived is Base(0) { - function Derived(uint i) Base(i) { - - } + function Derived(uint i) Base(i) {} } @@ -636,19 +634,13 @@ contract DualIndex { } -contract A { - -} - - -contract B { +contract A {} -} +contract B {} -contract C is A, B { -} +contract C is A, B {} contract TestPrivate { @@ -673,9 +665,7 @@ contract FromSolparse is A, B, TestPrivate, TestInternal { contract CommentedOutFunction { // FYI: This empty function, as well as the commented // out function below (bad code) is important to this test. - function() { - - } + function() {} // function something() // uint x = 10; @@ -714,9 +704,7 @@ contract NewStuff { // modifier with expression contract MyContract { - function fun() mymodifier(foo.bar()) { - - } + function fun() mymodifier(foo.bar()) {} } @@ -843,9 +831,7 @@ contract Ballot { uint[], address myAdd, string[] names - ) { - - } + ) {} function foobar() payable owner(myPrice) returns ( uint[], address myAdd,