Skip to content

Commit 667a512

Browse files
authored
Coverage (#237)
* try/catch had a bug and all the coverage is taking care of all cases * UsingForDeclaration now has 100% coverage * Labels have coverage now * small refactor for UsingForDeclaration * removing TupleExpression hack * last details for coverage
1 parent 9bcb096 commit 667a512

12 files changed

Lines changed: 205 additions & 37 deletions

File tree

src/nodes/CatchClause.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,22 @@ const {
66

77
const printList = require('./print-list');
88

9+
const parameters = (node, path, print) =>
10+
node.parameters
11+
? concat([
12+
node.isReasonStringType ? 'Error' : '',
13+
'(',
14+
printList(path.map(print, 'parameters')),
15+
') '
16+
])
17+
: '';
18+
919
const CatchClause = {
1020
print: ({ node, path, print }) => {
1121
return group(
1222
concat([
1323
'catch ',
14-
node.isReasonStringType ? 'Error' : '',
15-
'(',
16-
printList(path.map(print, 'parameters')),
17-
') ',
24+
parameters(node, path, print),
1825
path.call(print, 'body')
1926
])
2027
);

src/nodes/LabelDefinition.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
const {
22
doc: {
3-
builders: { concat, line }
3+
builders: { concat, dedent, line }
44
}
55
} = require('prettier/standalone');
66

77
const LabelDefinition = {
8-
print: ({ node }) => concat([node.name, ':', line])
8+
print: ({ node }) => concat([dedent(line), node.name, ':'])
99
};
1010

1111
module.exports = LabelDefinition;

src/nodes/StateVariableDeclaration.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@ const {
44
}
55
} = require('prettier/standalone');
66

7+
const initialValue = (node, path, print) =>
8+
node.initialValue ? concat([' = ', path.call(print, 'initialValue')]) : '';
9+
710
const StateVariableDeclaration = {
8-
print: ({ node, path, print }) => {
9-
let doc = concat(
10-
path.map(statementPath => {
11-
if (!statementPath.getValue()) {
12-
return ', ';
13-
}
14-
return print(statementPath);
15-
}, 'variables')
16-
);
17-
if (node.initialValue) {
18-
doc = concat([doc, ' = ', path.call(print, 'initialValue')]);
19-
}
20-
return concat([doc, ';']);
21-
}
11+
print: ({ node, path, print }) =>
12+
concat([
13+
...path.map(print, 'variables'),
14+
initialValue(node, path, print),
15+
';'
16+
])
2217
};
2318

2419
module.exports = StateVariableDeclaration;

src/nodes/TupleExpression.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ const contents = (node, path, print) =>
1111
node.components.length === 1 &&
1212
node.components[0].type === 'BinaryOperation'
1313
? path.map(print, 'components')
14-
: [printList(path.map(print, node.components ? 'components' : 'elements'))];
14+
: [printList(path.map(print, 'components'))];
1515

1616
const TupleExpression = {
17-
// @TODO: remove hack once solidity-parser-antlr is fixed
1817
print: ({ node, path, print }) =>
1918
group(
2019
concat([

src/nodes/UsingForDeclaration.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@ const {
55
} = require('prettier/standalone');
66

77
const UsingForDeclaration = {
8-
print: ({ node, path, print }) => {
9-
if (node.typeName) {
10-
return concat([
11-
'using ',
12-
node.libraryName,
13-
' for ',
14-
path.call(print, 'typeName'),
15-
';'
16-
]);
17-
}
18-
return concat(['using ', node.libraryName, ' for *;']);
19-
}
8+
print: ({ node, path, print }) =>
9+
concat([
10+
'using ',
11+
node.libraryName,
12+
' for ',
13+
node.typeName ? path.call(print, 'typeName') : '*',
14+
';'
15+
])
2016
};
2117

2218
module.exports = UsingForDeclaration;

src/parser.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ function parse(text, parsers, options) {
2121
if (ctx.initExpression) {
2222
ctx.initExpression.omitSemicolon = true;
2323
}
24-
if (ctx.loopExpression) {
25-
ctx.loopExpression.omitSemicolon = true;
26-
}
24+
ctx.loopExpression.omitSemicolon = true;
2725
},
2826
HexLiteral(ctx) {
2927
ctx.value = options.singleQuote

tests/AllSolidityFeatures/AllSolidityFeatures.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ library UsingExampleLibrary {
259259
}
260260

261261
contract UsingExampleContract {
262+
using UsingExampleLibrary for *;
262263
using UsingExampleLibrary for uint[];
263264
}
264265

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ library UsingExampleLibrary {
262262
}
263263
264264
contract UsingExampleContract {
265+
using UsingExampleLibrary for *;
265266
using UsingExampleLibrary for uint[];
266267
}
267268
@@ -723,6 +724,7 @@ library UsingExampleLibrary {
723724
724725
725726
contract UsingExampleContract {
727+
using UsingExampleLibrary for *;
726728
using UsingExampleLibrary for uint256[];
727729
}
728730

tests/Assembly/Assembly.sol

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,36 @@ for { let i := 0 } lt(i, x) { i := add(i, 1) } { y := mul(2, y) }
100100
}
101101
}
102102
}
103+
104+
function assemblyLabels() {
105+
assembly {
106+
let n := calldataload(4)
107+
let a := 1
108+
let b := a
109+
loop:
110+
jumpi(loopend, eq(n, 0))
111+
a add swap1
112+
n := sub(n, 1)
113+
jump(loop)
114+
loopend:
115+
mstore(0, a)
116+
return(0, 0x20)
117+
}
118+
119+
assembly{
120+
let x := 8
121+
jump(two)
122+
one:
123+
// Here the stack height is 2 (because we pushed x and 7),
124+
// but the assembler thinks it is 1 because it reads
125+
// from top to bottom.
126+
// Accessing the stack variable x here will lead to errors.
127+
x := 9
128+
jump(three)
129+
two:
130+
7 // push something onto the stack
131+
jump(one)
132+
three:
133+
}
134+
}
103135
}

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,38 @@ for { let i := 0 } lt(i, x) { i := add(i, 1) } { y := mul(2, y) }
103103
}
104104
}
105105
}
106+
107+
function assemblyLabels() {
108+
assembly {
109+
let n := calldataload(4)
110+
let a := 1
111+
let b := a
112+
loop:
113+
jumpi(loopend, eq(n, 0))
114+
a add swap1
115+
n := sub(n, 1)
116+
jump(loop)
117+
loopend:
118+
mstore(0, a)
119+
return(0, 0x20)
120+
}
121+
122+
assembly{
123+
let x := 8
124+
jump(two)
125+
one:
126+
// Here the stack height is 2 (because we pushed x and 7),
127+
// but the assembler thinks it is 1 because it reads
128+
// from top to bottom.
129+
// Accessing the stack variable x here will lead to errors.
130+
x := 9
131+
jump(three)
132+
two:
133+
7 // push something onto the stack
134+
jump(one)
135+
three:
136+
}
137+
}
106138
}
107139
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
108140
contract Assembly {
@@ -236,6 +268,45 @@ contract Assembly {
236268
}
237269
}
238270
}
271+
272+
function assemblyLabels() {
273+
assembly {
274+
let n := calldataload(4)
275+
let a := 1
276+
let b := a
277+
278+
loop:
279+
jumpi(loopend, eq(n, 0))
280+
a
281+
add
282+
swap1
283+
n := sub(n, 1)
284+
jump(loop)
285+
286+
loopend:
287+
mstore(0, a)
288+
return(0, 0x20)
289+
}
290+
291+
assembly {
292+
let x := 8
293+
jump(two)
294+
295+
one:
296+
// Here the stack height is 2 (because we pushed x and 7),
297+
// but the assembler thinks it is 1 because it reads
298+
// from top to bottom.
299+
// Accessing the stack variable x here will lead to errors.
300+
x := 9
301+
jump(three)
302+
303+
two:
304+
7 // push something onto the stack
305+
jump(one)
306+
307+
three:
308+
}
309+
}
239310
}
240311
241312
`;

0 commit comments

Comments
 (0)