Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')];

Expand Down Expand Up @@ -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),
Expand Down
28 changes: 7 additions & 21 deletions tests/AllSolidityFeatures/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,7 @@ contract Base {
}

contract Derived is Base(0) {
function Derived(uint i) Base(i) {

}
function Derived(uint i) Base(i) {}
}


Expand Down Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -714,9 +704,7 @@ contract NewStuff {

// modifier with expression
contract MyContract {
function fun() mymodifier(foo.bar()) {

}
function fun() mymodifier(foo.bar()) {}
}


Expand Down Expand Up @@ -843,9 +831,7 @@ contract Ballot {
uint[],
address myAdd,
string[] names
) {

}
) {}
function foobar() payable owner(myPrice) returns (
uint[],
address myAdd,
Expand Down