Skip to content

Commit aa9eae5

Browse files
authored
Fix extra line in ContractSpecifiers (#1212)
* There was an extra line being printed after a StorageSpecifier when there was a InheritanceSpecifier present in the ContractSpecifiers' array * fix `antlr` parser
1 parent e1a7e70 commit aa9eae5

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/nodes/ContractDefinition.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ const specifiers = (node, path, print) => {
2222
document.push([
2323
'layout at',
2424
printSeparatedItem(path.call(print, 'storageLayout'), {
25-
firstSeparator: line
25+
firstSeparator: line,
26+
lastSeparator: node.baseContracts.length === 0 ? line : ''
2627
})
2728
]);
2829
}

src/slang-nodes/StorageLayoutSpecifier.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ export class StorageLayoutSpecifier extends SlangNode {
3131
return [
3232
'layout at',
3333
printSeparatedItem(path.call(print, 'expression'), {
34-
firstSeparator: line
34+
firstSeparator: line,
35+
// If this is the second ContractSpecifier we have to delegate printing
36+
// the line to the ContractSpecifiers node.
37+
lastSeparator: path.callParent((parentPath) => parentPath.isFirst)
38+
? line
39+
: ''
3540
})
3641
];
3742
}

tests/format/Comments/__snapshots__/format.test.js.snap

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,7 @@ contract Comments4c
275275
Interface4,
276276
Interface5,
277277
Interface6 /*why we used Interface6*/
278-
layout at
279-
/*where should this go?*/ f(123 + 456) /*why we used this layout*/
280-
278+
layout at /*where should this go?*/ f(123 + 456) /*why we used this layout*/
281279
{
282280
// solhint-disable-previous-line no-empty-blocks
283281
}

tests/format/ContractDefinitions/__snapshots__/format.test.js.snap

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ contract StorageLayoutSpecifier2 layout at
7979
)
8080
{}
8181
82-
contract StorageLayoutSpecifier3 is Contract1 layout at 123 {}
82+
contract StorageLayoutSpecifier3 is Contract1 layout at 123 {}
8383
8484
contract StorageLayoutSpecifier4
8585
is Contract1, Contract2, Contract3, Contract4, Contract5
@@ -100,7 +100,6 @@ contract StorageLayoutSpecifier6
100100
12345678901234567890 -
101101
12345678901234567890
102102
)
103-
104103
{}
105104
106105
contract StorageLayoutSpecifier7
@@ -143,7 +142,6 @@ contract StorageLayoutSpecifier9
143142
12345678901234567890 -
144143
12345678901234567890
145144
)
146-
147145
{}
148146
149147
contract InheritanceSpecifier1 is SomeOtherContract(1234, false) {}
@@ -167,7 +165,6 @@ contract InheritanceSpecifier4
167165
12345678901234567890 -
168166
12345678901234567890
169167
)
170-
171168
{}
172169
173170
contract LongInheritanceSpecifier1 is
@@ -212,7 +209,6 @@ contract LongInheritanceSpecifier4
212209
12345678901234567890 -
213210
12345678901234567890
214211
)
215-
216212
{}
217213
218214
================================================================================

0 commit comments

Comments
 (0)