Skip to content

Commit fc77fd6

Browse files
authored
using ... for ... supporting functions and global (prettier-solidity#683)
* using the latest parser * UsingForDeclaration with support for functions * removing unused TypeNameExpression
1 parent f577f80 commit fc77fd6

File tree

9 files changed

+139
-15
lines changed

9 files changed

+139
-15
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"solc": "^0.8.14-fixed"
8484
},
8585
"dependencies": {
86-
"@solidity-parser/parser": "^0.14.1",
86+
"@solidity-parser/parser": "^0.14.2-beta.1",
8787
"emoji-regex": "^10.1.0",
8888
"escape-string-regexp": "^4.0.0",
8989
"semver": "^7.3.7",

src/binary-operator-printers/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* This file was automatically generated on 1621622090.188 */
1+
/* This file was automatically generated on 1653243394.809 */
22

33
/* eslint-disable global-require */
44

src/nodes/TypeNameExpression.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/nodes/UsingForDeclaration.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1+
const {
2+
doc: {
3+
builders: { line, softline }
4+
}
5+
} = require('prettier');
6+
7+
const printSeparatedList = require('./print-separated-list');
8+
19
const UsingForDeclaration = {
2-
print: ({ node, path, print }) => [
10+
print: ({ node, path, print, options }) => [
311
'using ',
4-
node.libraryName,
12+
node.functions && node.functions.length
13+
? [
14+
'{',
15+
printSeparatedList(node.functions, {
16+
firstSeparator: options.bracketSpacing ? line : softline
17+
}),
18+
'}'
19+
]
20+
: node.libraryName,
521
' for ',
622
node.typeName ? path.call(print, 'typeName') : '*',
7-
';'
23+
node.isGlobal ? ' global;' : ';'
824
]
925
};
1026

src/nodes/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* This file was automatically generated on 1621622090.034 */
1+
/* This file was automatically generated on 1653243394.65 */
22

33
/* eslint-disable global-require */
44

@@ -66,7 +66,6 @@ module.exports = {
6666
TryStatement: require('./TryStatement'),
6767
TupleExpression: require('./TupleExpression'),
6868
TypeDefinition: require('./TypeDefinition'),
69-
TypeNameExpression: require('./TypeNameExpression'),
7069
UnaryOperation: require('./UnaryOperation'),
7170
UncheckedStatement: require('./UncheckedStatement'),
7271
UserDefinedTypeName: require('./UserDefinedTypeName'),
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Lib for uint;
2+
using Lib for
3+
uint global;
4+
using { f} for uint;
5+
using {f } for uint global;
6+
using { a, very, long, and, complex, Function, list, with, long, names } for
7+
uint;
8+
using { a, very,
9+
long, and, complex, Function,
10+
list, with, long, names } for uint global;
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Libraries.sol - {"bracketSpacing":true} format 1`] = `
4+
====================================options=====================================
5+
bracketSpacing: true
6+
parsers: ["solidity-parse"]
7+
printWidth: 80
8+
| printWidth
9+
=====================================input======================================
10+
using Lib for uint;
11+
using Lib for
12+
uint global;
13+
using { f} for uint;
14+
using {f } for uint global;
15+
using { a, very, long, and, complex, Function, list, with, long, names } for
16+
uint;
17+
using { a, very,
18+
long, and, complex, Function,
19+
list, with, long, names } for uint global;
20+
21+
=====================================output=====================================
22+
using Lib for uint256;
23+
using Lib for uint256 global;
24+
using { f } for uint256;
25+
using { f } for uint256 global;
26+
using {
27+
a,
28+
very,
29+
long,
30+
and,
31+
complex,
32+
Function,
33+
list,
34+
with,
35+
long,
36+
names
37+
} for uint256;
38+
using {
39+
a,
40+
very,
41+
long,
42+
and,
43+
complex,
44+
Function,
45+
list,
46+
with,
47+
long,
48+
names
49+
} for uint256 global;
50+
51+
================================================================================
52+
`;
53+
54+
exports[`Libraries.sol format 1`] = `
55+
====================================options=====================================
56+
parsers: ["solidity-parse"]
57+
printWidth: 80
58+
| printWidth
59+
=====================================input======================================
60+
using Lib for uint;
61+
using Lib for
62+
uint global;
63+
using { f} for uint;
64+
using {f } for uint global;
65+
using { a, very, long, and, complex, Function, list, with, long, names } for
66+
uint;
67+
using { a, very,
68+
long, and, complex, Function,
69+
list, with, long, names } for uint global;
70+
71+
=====================================output=====================================
72+
using Lib for uint256;
73+
using Lib for uint256 global;
74+
using {f} for uint256;
75+
using {f} for uint256 global;
76+
using {
77+
a,
78+
very,
79+
long,
80+
and,
81+
complex,
82+
Function,
83+
list,
84+
with,
85+
long,
86+
names
87+
} for uint256;
88+
using {
89+
a,
90+
very,
91+
long,
92+
and,
93+
complex,
94+
Function,
95+
list,
96+
with,
97+
long,
98+
names
99+
} for uint256 global;
100+
101+
================================================================================
102+
`;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
run_spec(__dirname, ['solidity-parse']);
2+
run_spec(__dirname, ['solidity-parse'], { bracketSpacing: true });

0 commit comments

Comments
 (0)