Skip to content

Commit 0af6913

Browse files
authored
Adding support for storage layout (#1117)
* update dependencies * support storage layout * comments for storage layout
1 parent a29c8fa commit 0af6913

File tree

11 files changed

+434
-111
lines changed

11 files changed

+434
-111
lines changed

package-lock.json

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

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,27 +90,27 @@
9090
"@babel/code-frame": "^7.26.2",
9191
"c8": "^10.1.3",
9292
"cross-env": "^7.0.3",
93-
"eslint": "^8.47.0",
93+
"eslint": "^8.57.1",
9494
"eslint-config-airbnb-base": "^15.0.0",
95-
"eslint-config-prettier": "^10.0.1",
95+
"eslint-config-prettier": "^10.1.2",
9696
"eslint-plugin-import": "^2.31.0",
9797
"esm-utils": "^4.3.0",
98-
"esmock": "^2.6.9",
98+
"esmock": "^2.7.0",
9999
"jest": "^29.7.0",
100-
"jest-light-runner": "^0.7.0",
101-
"jest-snapshot-serializer-ansi": "^2.1.0",
100+
"jest-light-runner": "^0.7.8",
101+
"jest-snapshot-serializer-ansi": "^2.2.1",
102102
"jest-snapshot-serializer-raw": "^2.0.0",
103103
"jest-watch-typeahead": "^2.2.2",
104104
"lines-and-columns": "^2.0.4",
105-
"prettier": "^3.3.3",
105+
"prettier": "^3.5.3",
106106
"proxyquire": "^2.1.3",
107-
"solc": "^0.8.28",
108-
"webpack": "^5.97.1",
107+
"solc": "^0.8.29",
108+
"webpack": "^5.99.6",
109109
"webpack-cli": "^6.0.1"
110110
},
111111
"dependencies": {
112-
"@solidity-parser/parser": "^0.19.0",
113-
"semver": "^7.6.3"
112+
"@solidity-parser/parser": "^0.20.1",
113+
"semver": "^7.7.1"
114114
},
115115
"peerDependencies": {
116116
"prettier": ">=2.3.0"

src/comments/handlers/handleContractDefinitionComments.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,19 @@ function handleContractDefinitionComments({
2727
);
2828

2929
// The comment is behind the start of the Block `{}` or behind a base contract
30-
if (followingNode?.type === 'InheritanceSpecifier' || nextCharacter === '{') {
30+
if (
31+
(followingNode &&
32+
(followingNode.type === 'InheritanceSpecifier' ||
33+
followingNode === enclosingNode.storageLayout)) ||
34+
nextCharacter === '{'
35+
) {
3136
// In this scenario the comment belongs to a base contract.
3237
// contract A is B, /* comment for B */ C /* comment for C */ {}
33-
if (precedingNode?.type === 'InheritanceSpecifier') {
38+
if (
39+
precedingNode &&
40+
(precedingNode.type === 'InheritanceSpecifier' ||
41+
precedingNode === enclosingNode.storageLayout)
42+
) {
3443
addTrailingComment(precedingNode, comment);
3544
return true;
3645
}

src/nodes/ContractDefinition.js

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,37 @@ import {
66
printSeparatedList
77
} from '../common/printer-helpers.js';
88

9-
const { group, line, hardline } = doc.builders;
9+
const { group, hardline, ifBreak, line, softline } = doc.builders;
1010

11-
const inheritance = (node, path, print) =>
12-
node.baseContracts.length > 0
13-
? [
14-
' is',
15-
printSeparatedList(path.map(print, 'baseContracts'), {
16-
firstSeparator: line
17-
})
18-
]
19-
: line;
11+
const specifiers = (node, path, print) => {
12+
const document = [];
13+
if (node.baseContracts.length > 0) {
14+
document.push([
15+
'is',
16+
printSeparatedList(path.map(print, 'baseContracts'), {
17+
firstSeparator: line
18+
})
19+
]);
20+
}
21+
if (node.storageLayout) {
22+
document.push([
23+
'layout at',
24+
printSeparatedItem(path.call(print, 'storageLayout'), {
25+
firstSeparator: line
26+
})
27+
]);
28+
}
29+
if (document.length === 0) return line;
30+
if (document.length === 1) return [' ', document];
31+
const groupId = Symbol('ContractSpecifiers.inheritance');
32+
return printSeparatedList(
33+
[group(document[0], { id: groupId }), document[1]],
34+
{
35+
firstSeparator: line,
36+
separator: ifBreak('', softline, { groupId })
37+
}
38+
);
39+
};
2040

2141
const body = (node, path, options, print) => {
2242
const comments = printComments(node, path, options);
@@ -34,7 +54,7 @@ export const ContractDefinition = {
3454
node.kind === 'abstract' ? 'abstract contract' : node.kind,
3555
' ',
3656
node.name,
37-
inheritance(node, path, print),
57+
specifiers(node, path, print),
3858
'{'
3959
]),
4060
body(node, path, options, print),

tests/format/Comments/Comments.sol

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ contract Comments4 is Interface1, Interface2, Interface3, Interface4, Interface5
3838
// solhint-disable-previous-line no-empty-blocks
3939
}
4040

41+
contract Comments4a is Interface1, Interface2, Interface3, Interface4, Interface5, Interface6 /*why we used Interface6*/ layout /*where should this go?*/at 123/*why we used this layout*/ {
42+
// solhint-disable-previous-line no-empty-blocks
43+
}
44+
45+
contract Comments4b is Interface1, Interface2, Interface3, Interface4, Interface5, Interface6 /*why we used Interface6*/ layout /*where should this go?*/at 123 + 456/*why we used this layout*/ {
46+
// solhint-disable-previous-line no-empty-blocks
47+
}
48+
49+
contract Comments4c is Interface1, Interface2, Interface3, Interface4, Interface5, Interface6 /*why we used Interface6*/ layout /*where should this go?*/at f(123 + 456)/*why we used this layout*/ {
50+
// solhint-disable-previous-line no-empty-blocks
51+
}
52+
4153
contract Comments5 /*nice name*/ {
4254
// solhint-disable-previous-line no-empty-blocks
4355
}

0 commit comments

Comments
 (0)