-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathContractDefinition.js
More file actions
64 lines (60 loc) · 1.67 KB
/
ContractDefinition.js
File metadata and controls
64 lines (60 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { doc } from 'prettier';
import {
printComments,
printPreservingEmptyLines,
printSeparatedItem,
printSeparatedList
} from '../common/printer-helpers.js';
const { group, hardline, ifBreak, line, softline } = doc.builders;
const specifiers = (node, path, print) => {
const document = [];
if (node.baseContracts.length > 0) {
document.push([
'is',
printSeparatedList(path.map(print, 'baseContracts'), {
firstSeparator: line
})
]);
}
if (node.storageLayout) {
document.push([
'layout at',
printSeparatedItem(path.call(print, 'storageLayout'), {
firstSeparator: line,
lastSeparator: node.baseContracts.length === 0 ? line : ''
})
]);
}
if (document.length === 0) return line;
if (document.length === 1) return [' ', document];
const groupId = Symbol('ContractSpecifiers.inheritance');
return printSeparatedList(
[group(document[0], { id: groupId }), document[1]],
{
firstSeparator: line,
separator: ifBreak('', softline, { groupId })
}
);
};
const body = (node, path, options, print) => {
const comments = printComments(node, path, options);
return node.subNodes.length > 0 || comments?.length
? printSeparatedItem(
[printPreservingEmptyLines(path, 'subNodes', options, print), comments],
{ firstSeparator: hardline, grouped: false }
)
: '';
};
export const ContractDefinition = {
print: ({ node, options, path, print }) => [
group([
node.kind === 'abstract' ? 'abstract contract' : node.kind,
' ',
node.name,
specifiers(node, path, print),
'{'
]),
body(node, path, options, print),
'}'
]
};