Skip to content

Commit 7e4ba3e

Browse files
Franco Victoriomattiaerre
authored andcommitted
Preserve constant keyword in variable declarations (#48)
* Preserve constant keyword in variable declarations * Fix formatting issues * Use wrap VariableDeclaration case in a block * remove no-case-declarations from eslint rules * Update snapshot
1 parent 6fb5e7f commit 7e4ba3e

File tree

4 files changed

+162
-3
lines changed

4 files changed

+162
-3
lines changed

src/printer.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,21 +273,28 @@ function genericPrint(path, options, print) {
273273
hardline,
274274
'}'
275275
]);
276-
case 'VariableDeclaration':
276+
case 'VariableDeclaration': {
277277
if (!node.typeName) {
278278
return node.name;
279279
}
280280
doc = path.call(print, 'typeName');
281281
if (node.isIndexed) {
282282
doc = join(' ', [doc, 'indexed']);
283283
}
284+
const constantKeyword = node.isDeclaredConst ? 'constant' : '';
284285
if (node.visibility === 'default') {
285-
return join(' ', [doc, node.name]);
286+
return join(
287+
' ',
288+
[doc, constantKeyword, node.name].filter(element => element)
289+
);
286290
}
287291
return join(
288292
' ',
289-
[doc, node.visibility, node.name].filter(element => element)
293+
[doc, node.visibility, constantKeyword, node.name].filter(
294+
element => element
295+
)
290296
);
297+
}
291298
case 'ArrayTypeName':
292299
return concat([
293300
path.call(print, 'baseTypeName'),
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
pragma solidity ^0.4.18;
2+
3+
import "../crowdsale/CappedCrowdsale.sol";
4+
import "../crowdsale/RefundableCrowdsale.sol";
5+
import "../token/MintableToken.sol";
6+
7+
/**
8+
* @title SampleCrowdsaleToken
9+
* @dev Very simple ERC20 Token that can be minted.
10+
* It is meant to be used in a crowdsale contract.
11+
*/
12+
contract SampleCrowdsaleToken is MintableToken {
13+
14+
string public constant name = "Sample Crowdsale Token";
15+
string public constant symbol = "SCT";
16+
uint8 public constant decimals = 18;
17+
18+
}
19+
20+
/**
21+
* @title SampleCrowdsale
22+
* @dev This is an example of a fully fledged crowdsale.
23+
* The way to add new features to a base crowdsale is by multiple inheritance.
24+
* In this example we are providing following extensions:
25+
* CappedCrowdsale - sets a max boundary for raised funds
26+
* RefundableCrowdsale - set a min goal to be reached and returns funds if it's not met
27+
*
28+
* After adding multiple features it's good practice to run integration tests
29+
* to ensure that subcontracts works together as intended.
30+
*/
31+
contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale {
32+
33+
function SampleCrowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, uint256 _goal, uint256 _cap, address _wallet) public
34+
CappedCrowdsale(_cap)
35+
FinalizableCrowdsale()
36+
RefundableCrowdsale(_goal)
37+
Crowdsale(_startTime, _endTime, _rate, _wallet)
38+
{
39+
//As goal needs to be met for a successful crowdsale
40+
//the value needs to less or equal than a cap which is limit for accepted funds
41+
require(_goal <= _cap);
42+
}
43+
44+
function createTokenContract() internal returns (MintableToken) {
45+
return new SampleCrowdsaleToken();
46+
}
47+
48+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`SampleCrowdsale.sol 1`] = `
4+
pragma solidity ^0.4.18;
5+
6+
import "../crowdsale/CappedCrowdsale.sol";
7+
import "../crowdsale/RefundableCrowdsale.sol";
8+
import "../token/MintableToken.sol";
9+
10+
/**
11+
* @title SampleCrowdsaleToken
12+
* @dev Very simple ERC20 Token that can be minted.
13+
* It is meant to be used in a crowdsale contract.
14+
*/
15+
contract SampleCrowdsaleToken is MintableToken {
16+
17+
string public constant name = "Sample Crowdsale Token";
18+
string public constant symbol = "SCT";
19+
uint8 public constant decimals = 18;
20+
21+
}
22+
23+
/**
24+
* @title SampleCrowdsale
25+
* @dev This is an example of a fully fledged crowdsale.
26+
* The way to add new features to a base crowdsale is by multiple inheritance.
27+
* In this example we are providing following extensions:
28+
* CappedCrowdsale - sets a max boundary for raised funds
29+
* RefundableCrowdsale - set a min goal to be reached and returns funds if it's not met
30+
*
31+
* After adding multiple features it's good practice to run integration tests
32+
* to ensure that subcontracts works together as intended.
33+
*/
34+
contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale {
35+
36+
function SampleCrowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, uint256 _goal, uint256 _cap, address _wallet) public
37+
CappedCrowdsale(_cap)
38+
FinalizableCrowdsale()
39+
RefundableCrowdsale(_goal)
40+
Crowdsale(_startTime, _endTime, _rate, _wallet)
41+
{
42+
//As goal needs to be met for a successful crowdsale
43+
//the value needs to less or equal than a cap which is limit for accepted funds
44+
require(_goal <= _cap);
45+
}
46+
47+
function createTokenContract() internal returns (MintableToken) {
48+
return new SampleCrowdsaleToken();
49+
}
50+
51+
}
52+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53+
pragma solidity ^0.4.18;
54+
55+
import "../crowdsale/CappedCrowdsale.sol";
56+
import "../crowdsale/RefundableCrowdsale.sol";
57+
import "../token/MintableToken.sol";
58+
59+
/**
60+
* @title SampleCrowdsaleToken
61+
* @dev Very simple ERC20 Token that can be minted.
62+
* It is meant to be used in a crowdsale contract.
63+
*/
64+
contract SampleCrowdsaleToken is MintableToken {
65+
string public constant name = "Sample Crowdsale Token";
66+
string public constant symbol = "SCT";
67+
uint8 public constant decimals = 18;
68+
69+
}
70+
71+
72+
/**
73+
* @title SampleCrowdsale
74+
* @dev This is an example of a fully fledged crowdsale.
75+
* The way to add new features to a base crowdsale is by multiple inheritance.
76+
* In this example we are providing following extensions:
77+
* CappedCrowdsale - sets a max boundary for raised funds
78+
* RefundableCrowdsale - set a min goal to be reached and returns funds if it's not met
79+
*
80+
* After adding multiple features it's good practice to run integration tests
81+
* to ensure that subcontracts works together as intended.
82+
*/
83+
contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale {
84+
function SampleCrowdsale(
85+
uint256 _startTime,
86+
uint256 _endTime,
87+
uint256 _rate,
88+
uint256 _goal,
89+
uint256 _cap,
90+
address _wallet
91+
) public CappedCrowdsale(_cap) FinalizableCrowdsale RefundableCrowdsale(_goal) Crowdsale(_startTime, _endTime, _rate, _wallet) {
92+
//As goal needs to be met for a successful crowdsale
93+
//the value needs to less or equal than a cap which is limit for accepted funds
94+
require(_goal <= _cap);
95+
}
96+
97+
function createTokenContract() internal returns(MintableToken) {
98+
return new SampleCrowdsaleToken();
99+
}
100+
101+
}
102+
103+
`;
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)