Skip to content

Commit 44c8014

Browse files
fvictorioJanther
andauthored
Add support for custom errors (#502)
* Add support for custom errors * Use non-rc version of the parser * Run prettier * Remove unnecessary tests * Apply feedback from PR review * Missing feedback Co-authored-by: Klaus Hott Vidal <[email protected]>
1 parent 236aa3a commit 44c8014

14 files changed

Lines changed: 119 additions & 112 deletions

File tree

__tests__/nodes/__snapshots__/index.test.js.snap

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

__tests__/nodes/index.test.js

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

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
'!src/prettier-comments/**/*.js'
1111
],
1212
coverageDirectory: './coverage/',
13+
coveragePathIgnorePatterns: ['/node_modules/', '/scripts/'],
1314
coverageThreshold: {
1415
global: {
1516
branches: 100,

package-lock.json

Lines changed: 11 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
@@ -75,7 +75,7 @@
7575
"solc": "^0.8.3"
7676
},
7777
"dependencies": {
78-
"@solidity-parser/parser": "^0.12.2",
78+
"@solidity-parser/parser": "^0.13.0",
7979
"dir-to-object": "^2.0.0",
8080
"emoji-regex": "^9.2.2",
8181
"escape-string-regexp": "^4.0.0",

scripts/__snapshots__/makeData.test.js.snap

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

scripts/makeData.test.js

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

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 1621236946.49 */
1+
/* This file was automatically generated on 1621622090.188 */
22

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

src/nodes/CustomErrorDefinition.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const {
2+
doc: {
3+
builders: { concat }
4+
}
5+
} = require('prettier/standalone');
6+
7+
const printSeparatedList = require('./print-separated-list');
8+
9+
const parameters = (node, path, print) =>
10+
node.parameters && node.parameters.length > 0
11+
? printSeparatedList(path.map(print, 'parameters'))
12+
: '';
13+
14+
const CustomErrorDefinition = {
15+
print: ({ node, path, print }) =>
16+
concat(['error ', node.name, '(', parameters(node, path, print), ');'])
17+
};
18+
19+
module.exports = CustomErrorDefinition;

src/nodes/RevertStatement.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const {
2+
doc: {
3+
builders: { concat }
4+
}
5+
} = require('prettier/standalone');
6+
7+
const RevertStatement = {
8+
print: ({ path, print }) =>
9+
concat(['revert ', path.call(print, 'revertCall'), ';'])
10+
};
11+
12+
module.exports = RevertStatement;

0 commit comments

Comments
 (0)