Skip to content

Commit fae74c7

Browse files
authored
Handle long state variable declarations (#388)
1 parent 452d72f commit fae74c7

4 files changed

Lines changed: 31 additions & 3 deletions

File tree

src/nodes/StateVariableDeclaration.js

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

7-
const initialValue = (node, path, print) =>
8-
node.initialValue ? concat([' = ', path.call(print, 'initialValue')]) : '';
7+
const initialValue = (node, path, print) => {
8+
if (!node.initialValue) {
9+
return '';
10+
}
11+
12+
if (node.initialValue.type === 'TupleExpression') {
13+
return concat([' = ', path.call(print, 'initialValue')]);
14+
}
15+
16+
return group(
17+
concat([' =', indent(concat([line, path.call(print, 'initialValue')]))])
18+
);
19+
};
920

1021
const StateVariableDeclaration = {
1122
print: ({ node, path, print }) =>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
contract Contract {
2+
bytes32 private constant DOMAIN_SEPARATOR_TYPEHASH = 0x035aff83d86937d35b32e04f0ddc6ff469290eef2f1b692d8a815c89404d4749;
3+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`StateVariableDeclarations.sol 1`] = `
4+
contract Contract {
5+
bytes32 private constant DOMAIN_SEPARATOR_TYPEHASH = 0x035aff83d86937d35b32e04f0ddc6ff469290eef2f1b692d8a815c89404d4749;
6+
}
7+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8+
contract Contract {
9+
bytes32 private constant DOMAIN_SEPARATOR_TYPEHASH =
10+
0x035aff83d86937d35b32e04f0ddc6ff469290eef2f1b692d8a815c89404d4749;
11+
}
12+
13+
`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
run_spec(__dirname);

0 commit comments

Comments
 (0)