Skip to content

Commit 440057b

Browse files
svechinskymattiaerre
authored andcommitted
Fix prettier removing payable from address payable (#77)
* Fix prettier removing payable from address payable * Styling * Add tests for address payable syntax
1 parent 002a4da commit 440057b

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

src/printer.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,12 @@ function genericPrint(path, options, print) {
135135
doc = path.call(print, 'typeName');
136136
doc = join(
137137
' ',
138-
[doc, node.storageLocation, node.name].filter(element => element)
138+
[
139+
doc,
140+
node.storageLocation,
141+
node.typeName.stateMutability,
142+
node.name
143+
].filter(element => element)
139144
);
140145
return doc;
141146
case 'ModifierInvocation':
@@ -286,13 +291,19 @@ function genericPrint(path, options, print) {
286291
if (node.visibility === 'default') {
287292
return join(
288293
' ',
289-
[doc, constantKeyword, node.name].filter(element => element)
294+
[
295+
doc,
296+
node.typeName.stateMutability,
297+
constantKeyword,
298+
node.name
299+
].filter(element => element)
290300
);
291301
}
292302
return join(
293303
' ',
294304
[
295305
doc,
306+
node.typeName.stateMutability,
296307
node.visibility,
297308
constantKeyword,
298309
node.storageLocation,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pragma solidity ^0.5.2;
2+
3+
contract AddressPayable {
4+
function sendSomeEth(address payable to) public payable {
5+
address payable target = to;
6+
target.transfer(msg.value);
7+
}
8+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`AddressPayable.sol 1`] = `
4+
pragma solidity ^0.5.2;
5+
6+
contract AddressPayable {
7+
function sendSomeEth(address payable to) public payable {
8+
address payable target = to;
9+
target.transfer(msg.value);
10+
}
11+
}
12+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13+
pragma solidity ^0.5.2;
14+
15+
contract AddressPayable {
16+
function sendSomeEth(address payable to) public payable {
17+
address payable target = to;
18+
target.transfer(msg.value);
19+
}
20+
}
21+
22+
`;

tests/AddressPayable/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)