Skip to content

Commit 1b79aa6

Browse files
Janthermattiaerre
authored andcommitted
true and false Expression need to be indented in case the line breaks (#209)
* trueExpression and falseExpression need to be indented in case the line breaks * only 1 indent needed
1 parent df9dc77 commit 1b79aa6

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

src/nodes/Conditional.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ const Conditional = {
99
group(
1010
concat([
1111
path.call(print, 'condition'),
12-
indent(line),
13-
'? ',
14-
path.call(print, 'trueExpression'),
15-
indent(line),
16-
': ',
17-
path.call(print, 'falseExpression')
12+
indent(
13+
concat([
14+
line,
15+
'? ',
16+
path.call(print, 'trueExpression'),
17+
line,
18+
': ',
19+
path.call(print, 'falseExpression')
20+
])
21+
)
1822
])
1923
)
2024
};

tests/Conditional/Conditional.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ pragma solidity ^0.4.24;
44
contract Conditional {
55
function foo() {
66
address contextAddress = longAddress_ == address(0) ? msg.sender : currentContextAddress_;
7+
asset == ETH
8+
? require(address(uint160(msg.sender)).send(quantity), "failed to transfer ether") // explicit casting to `address payable`
9+
: transferTokensToAccountSecurely(Token(asset), quantity, msg.sender);
10+
asset == ETH
11+
? true
12+
: transferTokensToAccountSecurely(Token(asset), quantity, msg.sender);
13+
asset == ETH
14+
? require(address(uint160(msg.sender)).send(quantity), "failed to transfer ether")
15+
: false;
716
}
817

918
// TODO: work with a break in the condition level.

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ pragma solidity ^0.4.24;
77
contract Conditional {
88
function foo() {
99
address contextAddress = longAddress_ == address(0) ? msg.sender : currentContextAddress_;
10+
asset == ETH
11+
? require(address(uint160(msg.sender)).send(quantity), "failed to transfer ether") // explicit casting to \`address payable\`
12+
: transferTokensToAccountSecurely(Token(asset), quantity, msg.sender);
13+
asset == ETH
14+
? true
15+
: transferTokensToAccountSecurely(Token(asset), quantity, msg.sender);
16+
asset == ETH
17+
? require(address(uint160(msg.sender)).send(quantity), "failed to transfer ether")
18+
: false;
1019
}
1120
1221
// TODO: work with a break in the condition level.
@@ -26,6 +35,29 @@ contract Conditional {
2635
address contextAddress = longAddress_ == address(0)
2736
? msg.sender
2837
: currentContextAddress_;
38+
asset == ETH
39+
? require(
40+
address(uint160(msg.sender)).send(quantity),
41+
"failed to transfer ether"
42+
) // explicit casting to \`address payable\`
43+
: transferTokensToAccountSecurely(
44+
Token(asset),
45+
quantity,
46+
msg.sender
47+
);
48+
asset == ETH
49+
? true
50+
: transferTokensToAccountSecurely(
51+
Token(asset),
52+
quantity,
53+
msg.sender
54+
);
55+
asset == ETH
56+
? require(
57+
address(uint160(msg.sender)).send(quantity),
58+
"failed to transfer ether"
59+
)
60+
: false;
2961
}
3062
3163
// TODO: work with a break in the condition level.

0 commit comments

Comments
 (0)