Skip to content

Commit 230e835

Browse files
maxsam4mattiaerre
authored andcommitted
Fixed tuple errors (#106)
* Fixed a tupple error * Linting fixed * Updated test case * Fixed tupples * Added test case for (x, ) * Generalized null
1 parent befe85c commit 230e835

File tree

6 files changed

+76
-10
lines changed

6 files changed

+76
-10
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
{
3838
"email": "victorio.franco@gmail.com",
3939
"name": "Franco Victorio"
40+
},
41+
{
42+
"email": "hi@mudit.blog",
43+
"name": "Mudit Gupta"
4044
}
4145
],
4246
"license": "MIT",
@@ -59,7 +63,7 @@
5963
"escape-string-regexp": "^1.0.5",
6064
"extract-comments": "^1.1.0",
6165
"prettier": "^1.15.3",
62-
"solidity-parser-antlr": "^0.3.3",
66+
"solidity-parser-antlr": "^0.4.0",
6367
"string-width": "^3.0.0"
6468
}
6569
}

src/printer.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ function printPreservingEmptyLines(path, key, options, print) {
3131
function genericPrint(path, options, print) {
3232
const node = path.getValue();
3333
let doc;
34+
if (node === null) {
35+
return '';
36+
}
37+
3438
switch (node.type) {
3539
case 'SourceUnit':
3640
return concat([
@@ -307,12 +311,7 @@ function genericPrint(path, options, print) {
307311

308312
doc = join(
309313
', ',
310-
path.map(statementPath => {
311-
if (!statementPath.getValue()) {
312-
return ', ';
313-
}
314-
return print(statementPath);
315-
}, 'variables')
314+
path.map(statementPath => print(statementPath), 'variables')
316315
);
317316

318317
if (node.variables.length > 1 || startsWithVar) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,11 +771,11 @@ contract VariableDeclarationTuple {
771771
function ham() {
772772
var (x, y) = (10, 20);
773773
var (a, b) = getMyTuple();
774-
var (, , c) = (10, 20);
774+
var (, c) = (10, 20);
775775
var (d, , ) = (10, 20, 30);
776-
var (, , e, , , f, , ) = (10, 20, 30, 40, 50);
776+
var (, e, , f, ) = (10, 20, 30, 40, 50);
777777
778-
var (num1, num2, num3, , , num5) = (10, 20, 30, 40, 50);
778+
var (num1, num2, num3, , num5) = (10, 20, 30, 40, 50);
779779
}
780780
}
781781

tests/Tupples/Tupples.sol

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pragma solidity ^0.5.0;
2+
3+
contract demo {
4+
function hello() public view returns(bool,bool) {}
5+
function hello2() public view returns(bool) {}
6+
function hello3() public view returns(bool,bool,bool) {}
7+
8+
}
9+
10+
contract Tupples {
11+
function world(address payable _yo) public view {
12+
bool yo;
13+
yo = demo(_yo).hello2();
14+
(yo, ) = demo(_yo).hello();
15+
(, yo) = demo(_yo).hello();
16+
(yo, , yo) = demo(_yo).hello3();
17+
(yo, yo) = demo(_yo).hello();
18+
}
19+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Tupples.sol 1`] = `
4+
pragma solidity ^0.5.0;
5+
6+
contract demo {
7+
function hello() public view returns(bool,bool) {}
8+
function hello2() public view returns(bool) {}
9+
function hello3() public view returns(bool,bool,bool) {}
10+
11+
}
12+
13+
contract Tupples {
14+
function world(address payable _yo) public view {
15+
bool yo;
16+
yo = demo(_yo).hello2();
17+
(yo, ) = demo(_yo).hello();
18+
(, yo) = demo(_yo).hello();
19+
(yo, , yo) = demo(_yo).hello3();
20+
(yo, yo) = demo(_yo).hello();
21+
}
22+
}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23+
pragma solidity ^0.5.0;
24+
25+
contract demo {
26+
function hello() public view returns (bool, bool) {}
27+
function hello2() public view returns (bool) {}
28+
function hello3() public view returns (bool, bool, bool) {}
29+
30+
}
31+
32+
contract Tupples {
33+
function world(address payable _yo) public view {
34+
bool yo;
35+
yo = demo(_yo).hello2();
36+
(yo, ) = demo(_yo).hello();
37+
(, yo) = demo(_yo).hello();
38+
(yo, , yo) = demo(_yo).hello3();
39+
(yo, yo) = demo(_yo).hello();
40+
}
41+
}
42+
43+
`;

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