Skip to content

Commit dc768cc

Browse files
authored
fix-FunctionTypeName (#67)
* add FunctionTypeName * moar extra spaces * bump version
1 parent 6428414 commit dc768cc

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "prettier-plugin-solidity",
3-
"version": "1.0.0-alpha.7",
3+
"version": "1.0.0-alpha.8",
44
"description": "prettier plugin for solidity",
55
"main": "src",
66
"scripts": {

src/printer.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,32 @@ function genericPrint(path, options, print) {
479479
':=',
480480
path.call(print, 'expression')
481481
]);
482+
case 'FunctionTypeName': {
483+
const returns = returnTypes => {
484+
if (returnTypes.length > 0) {
485+
return concat([
486+
'returns(',
487+
join(', ', path.map(print, 'returnTypes')),
488+
')'
489+
]);
490+
}
491+
return null;
492+
};
493+
494+
return join(
495+
' ',
496+
[
497+
concat([
498+
'function(',
499+
join(', ', path.map(print, 'parameterTypes')),
500+
')'
501+
]),
502+
returns(node.returnTypes),
503+
node.visibility === 'default' ? null : node.visibility,
504+
node.stateMutability
505+
].filter(element => element)
506+
);
507+
}
482508
default:
483509
throw new Error(`Unknown type: ${JSON.stringify(node.type)}`);
484510
}

tests/Etc/Etc.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ pragma solidity ^0.4.24;
77
*/
88

99
contract Contract {
10+
struct StructWithFunctionTypes {
11+
function (uint, uint) returns(bool)a;
12+
function(bytes32, bytes32) internal view[] b;
13+
function (bytes32, bytes32)internal[] c;
14+
}
15+
1016
modifier modifierWithoutParams() {
1117
require(msg.sender != address(0));
1218
_;

tests/Etc/__snapshots__/jsfmt.spec.js.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ pragma solidity ^0.4.24;
1010
*/
1111
1212
contract Contract {
13+
struct StructWithFunctionTypes {
14+
function (uint, uint) returns(bool)a;
15+
function(bytes32, bytes32) internal view[] b;
16+
function (bytes32, bytes32)internal[] c;
17+
}
18+
1319
modifier modifierWithoutParams() {
1420
require(msg.sender != address(0));
1521
_;
@@ -30,6 +36,12 @@ pragma solidity ^0.4.24;
3036
*/
3137
3238
contract Contract {
39+
struct StructWithFunctionTypes {
40+
function(uint, uint) returns(bool) a;
41+
function(bytes32, bytes32) internal view[] b;
42+
function(bytes32, bytes32) internal[] c;
43+
}
44+
3345
modifier modifierWithoutParams() {
3446
require(msg.sender != address(0));
3547
_;

0 commit comments

Comments
 (0)