Skip to content

Commit 86f79af

Browse files
ritikmmattiaerre
authored andcommitted
Fixed checking for the existence of parameters for a modifier (#49)
* Fixed checking for the existence of parameters for a modifier * Handle edge case where modifier doesn't have any params and does not have any parens after method name * Add test contract for adding specific cases easily
1 parent e99b35a commit 86f79af

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

src/printer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,11 @@ function genericPrint(path, options, print) {
404404
}
405405
return concat([doc, ';']);
406406
case 'ModifierDefinition':
407-
if (node.parameters && node.parameters.length > 0) {
407+
if (
408+
node.parameters &&
409+
node.parameters.parameters &&
410+
node.parameters.parameters.length > 0
411+
) {
408412
doc = path.call(print, 'parameters');
409413
} else {
410414
doc = '';

tests/Etc/Etc.sol

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pragma solidity ^0.4.24;
2+
3+
// line comment
4+
5+
/*
6+
Block comment
7+
*/
8+
9+
contract Contract {
10+
modifier modifierWithoutParams() {
11+
require(msg.sender != address(0));
12+
_;
13+
}
14+
15+
modifier modifierWithParams(address x) {
16+
require(msg.sender != x);
17+
_;
18+
}
19+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Etc.sol 1`] = `
4+
pragma solidity ^0.4.24;
5+
6+
// line comment
7+
8+
/*
9+
Block comment
10+
*/
11+
12+
contract Contract {
13+
modifier modifierWithoutParams() {
14+
require(msg.sender != address(0));
15+
_;
16+
}
17+
18+
modifier modifierWithParams(address x) {
19+
require(msg.sender != x);
20+
_;
21+
}
22+
}
23+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24+
pragma solidity ^0.4.24;
25+
26+
// line comment
27+
28+
/*
29+
Block comment
30+
*/
31+
32+
contract Contract {
33+
modifier modifierWithoutParams() {
34+
require(msg.sender != address(0));
35+
_;
36+
}
37+
38+
modifier modifierWithParams(address x) {
39+
require(msg.sender != x);
40+
_;
41+
}
42+
}
43+
44+
`;

tests/Etc/jsfmt.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
run_spec(__dirname);

0 commit comments

Comments
 (0)