Skip to content

Commit

Permalink
Add support for virtual keyword and abstract contracts (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
fvictorio committed Feb 19, 2020
1 parent 618a1b6 commit 9b39d17
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/nodes/ContractDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const ContractDefinition = {
concat([
group(
concat([
node.kind,
node.kind === 'abstract' ? 'abstract contract' : node.kind,
' ',
node.name,
inheritance(node, path, print),
Expand Down
8 changes: 8 additions & 0 deletions src/nodes/FunctionDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ const visibility = node => {
return '';
};

const virtual = node => {
if (node.isVirtual) {
return concat([line, 'virtual']);
}
return '';
};

const stateMutability = node => {
if (node.stateMutability && node.stateMutability !== 'default') {
return concat([line, node.stateMutability]);
Expand Down Expand Up @@ -81,6 +88,7 @@ const FunctionDefinition = {
group(
concat([
visibility(node),
virtual(node),
stateMutability(node),
modifiers(node, path, print),
returnParameters(node, path, print),
Expand Down
10 changes: 10 additions & 0 deletions tests/AllSolidityFeatures/AllSolidityFeatures.sol
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,13 @@ contract continueStatement {
while (true) { continue; }
}
}

abstract contract AbstractContract {

}

contract ContractWithVirtual
{
function foo() public virtual returns ( uint ) {
}
}
18 changes: 18 additions & 0 deletions tests/AllSolidityFeatures/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,16 @@ contract continueStatement {
while (true) { continue; }
}
}
abstract contract AbstractContract {
}
contract ContractWithVirtual
{
function foo() public virtual returns ( uint ) {
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Examples taken from the Solidity documentation online.
Expand Down Expand Up @@ -889,4 +899,12 @@ contract continueStatement {
}
}
abstract contract AbstractContract {}
contract ContractWithVirtual {
function foo() public virtual returns (uint256) {}
}
`;

0 comments on commit 9b39d17

Please sign in to comment.