prettier-plugin-solidity 1.1.3 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -9
- package/dist/standalone.cjs +3 -0
- package/dist/standalone.cjs.map +1 -0
- package/package.json +42 -33
- package/src/binary-operator-printers/arithmetic.js +12 -14
- package/src/binary-operator-printers/assignment.js +4 -6
- package/src/binary-operator-printers/bit.js +2 -2
- package/src/binary-operator-printers/comparison.js +11 -13
- package/src/binary-operator-printers/exponentiation.js +4 -6
- package/src/binary-operator-printers/index.js +7 -13
- package/src/binary-operator-printers/logical.js +12 -14
- package/src/binary-operator-printers/shift.js +2 -2
- package/src/clean.js +1 -1
- package/src/comments/handler.js +7 -15
- package/src/comments/handlers/handleContractDefinitionComments.js +9 -11
- package/src/comments/handlers/handleModifierInvocationComments.js +9 -11
- package/src/comments/handlers/index.js +5 -3
- package/src/comments/ignore.js +1 -1
- package/src/comments/index.js +2 -4
- package/src/comments/printer.js +5 -10
- package/src/common/backward-compatibility.js +46 -0
- package/src/common/printer-helpers.js +63 -41
- package/src/common/util.js +6 -22
- package/src/index.js +14 -12
- package/src/loc.js +1 -1
- package/src/nodes/ArrayTypeName.js +1 -3
- package/src/nodes/AssemblyAssignment.js +4 -8
- package/src/nodes/AssemblyBlock.js +6 -11
- package/src/nodes/AssemblyCall.js +2 -4
- package/src/nodes/AssemblyCase.js +1 -3
- package/src/nodes/AssemblyFor.js +4 -8
- package/src/nodes/AssemblyFunctionDefinition.js +6 -11
- package/src/nodes/AssemblyIf.js +1 -3
- package/src/nodes/AssemblyLocalDefinition.js +4 -9
- package/src/nodes/AssemblyMemberAccess.js +1 -3
- package/src/nodes/AssemblyStackAssignment.js +1 -3
- package/src/nodes/AssemblySwitch.js +4 -8
- package/src/nodes/BinaryOperation.js +2 -5
- package/src/nodes/Block.js +6 -11
- package/src/nodes/BooleanLiteral.js +1 -3
- package/src/nodes/Break.js +1 -3
- package/src/nodes/BreakStatement.js +1 -3
- package/src/nodes/CatchClause.js +2 -4
- package/src/nodes/Conditional.js +4 -8
- package/src/nodes/Continue.js +1 -3
- package/src/nodes/ContinueStatement.js +1 -3
- package/src/nodes/ContractDefinition.js +11 -17
- package/src/nodes/CustomErrorDefinition.js +2 -4
- package/src/nodes/DecimalNumber.js +1 -3
- package/src/nodes/DoWhileStatement.js +4 -9
- package/src/nodes/ElementaryTypeName.js +1 -3
- package/src/nodes/EmitStatement.js +1 -3
- package/src/nodes/EnumDefinition.js +4 -9
- package/src/nodes/EnumValue.js +1 -3
- package/src/nodes/EventDefinition.js +2 -4
- package/src/nodes/ExpressionStatement.js +4 -9
- package/src/nodes/FileLevelConstant.js +1 -3
- package/src/nodes/ForStatement.js +4 -9
- package/src/nodes/FunctionCall.js +4 -9
- package/src/nodes/FunctionDefinition.js +11 -18
- package/src/nodes/FunctionTypeName.js +4 -9
- package/src/nodes/HexLiteral.js +4 -9
- package/src/nodes/HexNumber.js +1 -3
- package/src/nodes/Identifier.js +1 -3
- package/src/nodes/IfStatement.js +6 -11
- package/src/nodes/ImportDirective.js +12 -17
- package/src/nodes/IndexAccess.js +4 -8
- package/src/nodes/IndexRangeAccess.js +1 -3
- package/src/nodes/InheritanceSpecifier.js +2 -4
- package/src/nodes/InlineAssemblyStatement.js +3 -4
- package/src/nodes/LabelDefinition.js +4 -8
- package/src/nodes/Mapping.js +17 -18
- package/src/nodes/MemberAccess.js +6 -10
- package/src/nodes/ModifierDefinition.js +4 -9
- package/src/nodes/ModifierInvocation.js +3 -5
- package/src/nodes/NameValueExpression.js +1 -3
- package/src/nodes/NameValueList.js +4 -9
- package/src/nodes/NewExpression.js +1 -3
- package/src/nodes/NumberLiteral.js +1 -3
- package/src/nodes/PragmaDirective.js +1 -3
- package/src/nodes/ReturnStatement.js +4 -8
- package/src/nodes/RevertStatement.js +1 -3
- package/src/nodes/SourceUnit.js +4 -9
- package/src/nodes/StateVariableDeclaration.js +4 -8
- package/src/nodes/StringLiteral.js +5 -9
- package/src/nodes/StructDefinition.js +13 -22
- package/src/nodes/ThrowStatement.js +1 -3
- package/src/nodes/TryStatement.js +6 -11
- package/src/nodes/TupleExpression.js +4 -9
- package/src/nodes/TypeDefinition.js +1 -3
- package/src/nodes/UnaryOperation.js +1 -3
- package/src/nodes/UncheckedStatement.js +4 -8
- package/src/nodes/UserDefinedTypeName.js +1 -3
- package/src/nodes/UsingForDeclaration.js +28 -44
- package/src/nodes/VariableDeclaration.js +4 -9
- package/src/nodes/VariableDeclarationStatement.js +6 -11
- package/src/nodes/WhileStatement.js +4 -9
- package/src/nodes/index.js +72 -78
- package/src/options.js +1 -1
- package/src/parser.js +5 -12
- package/src/prettier-comments/language-js/comments.js +13 -23
- package/src/printer.js +6 -6
- package/dist/standalone.js +0 -3
- package/dist/standalone.js.map +0 -1
- package/src/prettier-comments/index.js +0 -3
- /package/dist/{standalone.js.LICENSE.txt → standalone.cjs.LICENSE.txt} +0 -0
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import {
|
|
3
|
+
isFirst,
|
|
4
|
+
isLast,
|
|
5
|
+
isNextLineEmpty,
|
|
6
|
+
isPrettier2,
|
|
7
|
+
next,
|
|
8
|
+
previous
|
|
9
|
+
} from './backward-compatibility.js';
|
|
8
10
|
|
|
9
|
-
const
|
|
11
|
+
const { group, indent, join, line, softline, hardline } = doc.builders;
|
|
12
|
+
|
|
13
|
+
export const printComments = (node, path, options, filter = () => true) => {
|
|
10
14
|
if (!node.comments) return '';
|
|
11
|
-
const
|
|
15
|
+
const document = join(
|
|
12
16
|
line,
|
|
13
17
|
path
|
|
14
18
|
.map((commentPath) => {
|
|
@@ -29,13 +33,29 @@ const printComments = (node, path, options, filter = () => true) => {
|
|
|
29
33
|
// since it depends on the version of Prettier being used.
|
|
30
34
|
// Mocking the behaviour will introduce a lot of maintenance in the tests.
|
|
31
35
|
/* c8 ignore start */
|
|
32
|
-
return
|
|
33
|
-
?
|
|
34
|
-
:
|
|
36
|
+
return isPrettier2
|
|
37
|
+
? document.parts // Prettier V2
|
|
38
|
+
: document; // Prettier V3
|
|
35
39
|
/* c8 ignore stop */
|
|
36
40
|
};
|
|
37
41
|
|
|
38
|
-
|
|
42
|
+
const shouldHaveEmptyLine = (node, checkForLeading) =>
|
|
43
|
+
Boolean(
|
|
44
|
+
// if node is not FunctionDefinition, it should have an empty line
|
|
45
|
+
node.type !== 'FunctionDefinition' ||
|
|
46
|
+
// if FunctionDefinition is not abstract, it should have an empty line
|
|
47
|
+
node.body ||
|
|
48
|
+
// if FunctionDefinition has the comment we are looking for (trailing or
|
|
49
|
+
// leading), it should have an empty line
|
|
50
|
+
node.comments?.some((comment) => checkForLeading && comment.leading)
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const separatingLine = (firstNode, secondNode) =>
|
|
54
|
+
shouldHaveEmptyLine(firstNode, false) || shouldHaveEmptyLine(secondNode, true)
|
|
55
|
+
? hardline
|
|
56
|
+
: '';
|
|
57
|
+
|
|
58
|
+
export function printPreservingEmptyLines(path, key, options, print) {
|
|
39
59
|
const parts = [];
|
|
40
60
|
path.each((childPath, index) => {
|
|
41
61
|
const node = childPath.getValue();
|
|
@@ -51,38 +71,47 @@ function printPreservingEmptyLines(path, key, options, print) {
|
|
|
51
71
|
parts.push(hardline);
|
|
52
72
|
}
|
|
53
73
|
|
|
54
|
-
if
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
74
|
+
// Only attempt to prepend an empty line if `node` is not the first item
|
|
75
|
+
// and an empty line hasn't already been appended after the previous `node`
|
|
76
|
+
if (
|
|
77
|
+
!isFirst(childPath, key, index) &&
|
|
78
|
+
parts[parts.length - 2] !== hardline
|
|
79
|
+
) {
|
|
80
|
+
if (nodeType === 'FunctionDefinition') {
|
|
81
|
+
// Prepend FunctionDefinition with an empty line if there should be a
|
|
82
|
+
// separation with the previous `node`
|
|
83
|
+
parts.push(separatingLine(previous(childPath, key, index), node));
|
|
84
|
+
} else if (nodeType === 'ContractDefinition') {
|
|
85
|
+
// Prepend ContractDefinition with an empty line
|
|
59
86
|
parts.push(hardline);
|
|
60
87
|
}
|
|
61
88
|
}
|
|
62
89
|
|
|
63
90
|
parts.push(print(childPath));
|
|
64
91
|
|
|
65
|
-
if
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
92
|
+
// Only attempt to append an empty line if `node` is not the last item
|
|
93
|
+
if (!isLast(childPath, key, index)) {
|
|
94
|
+
if (isNextLineEmpty(options.originalText, options.locEnd(node) + 1)) {
|
|
95
|
+
// Append an empty line if the original text already had an one after
|
|
96
|
+
// the current `node`
|
|
97
|
+
parts.push(hardline);
|
|
98
|
+
} else if (nodeType === 'FunctionDefinition') {
|
|
99
|
+
// Append FunctionDefinition with an empty line if there should be a
|
|
100
|
+
// separation with the next `node`
|
|
101
|
+
parts.push(separatingLine(node, next(childPath, key, index)));
|
|
102
|
+
} else if (nodeType === 'ContractDefinition') {
|
|
103
|
+
// Append ContractDefinition with an empty line
|
|
104
|
+
parts.push(hardline);
|
|
105
|
+
}
|
|
73
106
|
}
|
|
74
107
|
}, key);
|
|
75
108
|
|
|
76
|
-
if (parts.length > 1 && parts[parts.length - 1] === hardline) {
|
|
77
|
-
parts.pop();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
109
|
return parts;
|
|
81
110
|
}
|
|
82
111
|
|
|
83
112
|
// This function will add an indentation to the `item` and separate it from the
|
|
84
113
|
// rest of the `doc` in most cases by a `softline`.
|
|
85
|
-
const printSeparatedItem = (
|
|
114
|
+
export const printSeparatedItem = (
|
|
86
115
|
item,
|
|
87
116
|
{
|
|
88
117
|
firstSeparator = softline,
|
|
@@ -90,15 +119,15 @@ const printSeparatedItem = (
|
|
|
90
119
|
grouped = true
|
|
91
120
|
} = {}
|
|
92
121
|
) => {
|
|
93
|
-
const
|
|
94
|
-
return grouped ? group(
|
|
122
|
+
const document = [indent([firstSeparator, item]), lastSeparator];
|
|
123
|
+
return grouped ? group(document) : document;
|
|
95
124
|
};
|
|
96
125
|
|
|
97
126
|
// This function will add an indentation to the `list` and separate it from the
|
|
98
127
|
// rest of the `doc` in most cases by a `softline`.
|
|
99
128
|
// the list itself will be printed with a separator that in most cases is a
|
|
100
129
|
// comma (,) and a `line`
|
|
101
|
-
const printSeparatedList = (
|
|
130
|
+
export const printSeparatedList = (
|
|
102
131
|
list,
|
|
103
132
|
{ firstSeparator, separator = [',', line], lastSeparator, grouped } = {}
|
|
104
133
|
) =>
|
|
@@ -107,10 +136,3 @@ const printSeparatedList = (
|
|
|
107
136
|
lastSeparator,
|
|
108
137
|
grouped
|
|
109
138
|
});
|
|
110
|
-
|
|
111
|
-
module.exports = {
|
|
112
|
-
printComments,
|
|
113
|
-
printPreservingEmptyLines,
|
|
114
|
-
printSeparatedList,
|
|
115
|
-
printSeparatedItem
|
|
116
|
-
};
|
package/src/common/util.js
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
version
|
|
4
|
-
} = require('prettier');
|
|
5
|
-
const satisfies = require('semver/functions/satisfies');
|
|
1
|
+
import { util, version } from 'prettier';
|
|
2
|
+
import satisfies from 'semver/functions/satisfies.js';
|
|
6
3
|
|
|
7
|
-
const prettierVersionSatisfies = (range) => satisfies(version, range);
|
|
4
|
+
export const prettierVersionSatisfies = (range) => satisfies(version, range);
|
|
8
5
|
|
|
9
|
-
function
|
|
10
|
-
return text.charAt(
|
|
11
|
-
getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function printString(rawContent, options) {
|
|
6
|
+
export function printString(rawContent, options) {
|
|
16
7
|
const double = { quote: '"', regex: /"/g };
|
|
17
8
|
const single = { quote: "'", regex: /'/g };
|
|
18
9
|
|
|
@@ -44,10 +35,10 @@ function printString(rawContent, options) {
|
|
|
44
35
|
// is enclosed with `enclosingQuote`, but it isn't. The string could contain
|
|
45
36
|
// unnecessary escapes (such as in `"\'"`). Always using `makeString` makes
|
|
46
37
|
// sure that we consistently output the minimum amount of escaped quotes.
|
|
47
|
-
return makeString(rawContent, enclosingQuote);
|
|
38
|
+
return util.makeString(rawContent, enclosingQuote);
|
|
48
39
|
}
|
|
49
40
|
|
|
50
|
-
function hasNodeIgnoreComment(node) {
|
|
41
|
+
export function hasNodeIgnoreComment(node) {
|
|
51
42
|
return (
|
|
52
43
|
node &&
|
|
53
44
|
node.comments &&
|
|
@@ -55,10 +46,3 @@ function hasNodeIgnoreComment(node) {
|
|
|
55
46
|
node.comments.some((comment) => comment.value.trim() === 'prettier-ignore')
|
|
56
47
|
);
|
|
57
48
|
}
|
|
58
|
-
|
|
59
|
-
module.exports = {
|
|
60
|
-
getNextNonSpaceNonCommentCharacter,
|
|
61
|
-
printString,
|
|
62
|
-
prettierVersionSatisfies,
|
|
63
|
-
hasNodeIgnoreComment
|
|
64
|
-
};
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import * as comments from './comments/index.js';
|
|
2
|
+
import massageAstNode from './clean.js';
|
|
3
|
+
import loc from './loc.js';
|
|
4
|
+
import options from './options.js';
|
|
5
|
+
import parse from './parser.js';
|
|
6
|
+
import print from './printer.js';
|
|
7
7
|
|
|
8
8
|
// https://prettier.io/docs/en/plugins.html#languages
|
|
9
9
|
// https://github.com/ikatyang/linguist-languages/blob/master/data/Solidity.json
|
|
@@ -35,14 +35,14 @@ const printers = {
|
|
|
35
35
|
'solidity-ast': {
|
|
36
36
|
canAttachComment,
|
|
37
37
|
handleComments: {
|
|
38
|
-
ownLine:
|
|
39
|
-
endOfLine:
|
|
40
|
-
remaining:
|
|
38
|
+
ownLine: comments.solidityHandleOwnLineComment,
|
|
39
|
+
endOfLine: comments.solidityHandleEndOfLineComment,
|
|
40
|
+
remaining: comments.solidityHandleRemainingComment
|
|
41
41
|
},
|
|
42
|
-
isBlockComment:
|
|
42
|
+
isBlockComment: comments.isBlockComment,
|
|
43
43
|
massageAstNode,
|
|
44
44
|
print,
|
|
45
|
-
printComment
|
|
45
|
+
printComment: comments.printComment
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
48
|
|
|
@@ -52,10 +52,12 @@ const defaultOptions = {
|
|
|
52
52
|
tabWidth: 4
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
const plugin = {
|
|
56
56
|
languages,
|
|
57
57
|
parsers,
|
|
58
58
|
printers,
|
|
59
59
|
options,
|
|
60
60
|
defaultOptions
|
|
61
61
|
};
|
|
62
|
+
|
|
63
|
+
export default plugin;
|
package/src/loc.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
doc: {
|
|
3
|
-
builders: { join }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
6
2
|
|
|
7
|
-
const
|
|
3
|
+
const { join } = doc.builders;
|
|
4
|
+
|
|
5
|
+
export const AssemblyAssignment = {
|
|
8
6
|
print: ({ path, print }) => [
|
|
9
7
|
join(', ', path.map(print, 'names')),
|
|
10
8
|
' := ',
|
|
11
9
|
path.call(print, 'expression')
|
|
12
10
|
]
|
|
13
11
|
};
|
|
14
|
-
|
|
15
|
-
module.exports = AssemblyAssignment;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { hardline }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
6
|
-
|
|
7
|
-
const {
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import {
|
|
8
3
|
printComments,
|
|
9
4
|
printPreservingEmptyLines,
|
|
10
5
|
printSeparatedItem
|
|
11
|
-
}
|
|
6
|
+
} from '../common/printer-helpers.js';
|
|
7
|
+
|
|
8
|
+
const { hardline } = doc.builders;
|
|
12
9
|
|
|
13
|
-
const AssemblyBlock = {
|
|
10
|
+
export const AssemblyBlock = {
|
|
14
11
|
print: ({ node, options, path, print }) => [
|
|
15
12
|
'{',
|
|
16
13
|
printSeparatedItem(
|
|
@@ -23,5 +20,3 @@ const AssemblyBlock = {
|
|
|
23
20
|
'}'
|
|
24
21
|
]
|
|
25
22
|
};
|
|
26
|
-
|
|
27
|
-
module.exports = AssemblyBlock;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { printSeparatedList } from '../common/printer-helpers.js';
|
|
2
2
|
|
|
3
|
-
const AssemblyCall = {
|
|
3
|
+
export const AssemblyCall = {
|
|
4
4
|
print: ({ node, path, print, options }) =>
|
|
5
5
|
node.arguments.length === 0 &&
|
|
6
6
|
options.originalText.charAt(options.locEnd(node)) !== ')'
|
|
@@ -12,5 +12,3 @@ const AssemblyCall = {
|
|
|
12
12
|
')'
|
|
13
13
|
]
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
module.exports = AssemblyCall;
|
package/src/nodes/AssemblyFor.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
doc: {
|
|
3
|
-
builders: { join }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
6
2
|
|
|
7
|
-
const
|
|
3
|
+
const { join } = doc.builders;
|
|
4
|
+
|
|
5
|
+
export const AssemblyFor = {
|
|
8
6
|
print: ({ path, print }) =>
|
|
9
7
|
join(' ', [
|
|
10
8
|
'for',
|
|
@@ -14,5 +12,3 @@ const AssemblyFor = {
|
|
|
14
12
|
path.call(print, 'body')
|
|
15
13
|
])
|
|
16
14
|
};
|
|
17
|
-
|
|
18
|
-
module.exports = AssemblyFor;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { line }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
6
|
-
|
|
7
|
-
const {
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import {
|
|
8
3
|
printSeparatedItem,
|
|
9
4
|
printSeparatedList
|
|
10
|
-
}
|
|
5
|
+
} from '../common/printer-helpers.js';
|
|
6
|
+
|
|
7
|
+
const { line } = doc.builders;
|
|
11
8
|
|
|
12
|
-
const AssemblyFunctionDefinition = {
|
|
9
|
+
export const AssemblyFunctionDefinition = {
|
|
13
10
|
print: ({ node, path, print }) => [
|
|
14
11
|
'function ',
|
|
15
12
|
node.name,
|
|
@@ -31,5 +28,3 @@ const AssemblyFunctionDefinition = {
|
|
|
31
28
|
path.call(print, 'body')
|
|
32
29
|
]
|
|
33
30
|
};
|
|
34
|
-
|
|
35
|
-
module.exports = AssemblyFunctionDefinition;
|
package/src/nodes/AssemblyIf.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { line }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { printSeparatedList } from '../common/printer-helpers.js';
|
|
6
3
|
|
|
7
|
-
const {
|
|
4
|
+
const { line } = doc.builders;
|
|
8
5
|
|
|
9
|
-
const AssemblyLocalDefinition = {
|
|
6
|
+
export const AssemblyLocalDefinition = {
|
|
10
7
|
print: ({ node, path, print }) => {
|
|
11
8
|
const parts = [
|
|
12
9
|
'let',
|
|
@@ -21,5 +18,3 @@ const AssemblyLocalDefinition = {
|
|
|
21
18
|
return parts;
|
|
22
19
|
}
|
|
23
20
|
};
|
|
24
|
-
|
|
25
|
-
module.exports = AssemblyLocalDefinition;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
doc: {
|
|
3
|
-
builders: { hardline, join }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
6
2
|
|
|
7
|
-
const
|
|
3
|
+
const { hardline, join } = doc.builders;
|
|
4
|
+
|
|
5
|
+
export const AssemblySwitch = {
|
|
8
6
|
print: ({ path, print }) => [
|
|
9
7
|
'switch ',
|
|
10
8
|
path.call(print, 'expression'),
|
|
@@ -12,5 +10,3 @@ const AssemblySwitch = {
|
|
|
12
10
|
join(hardline, path.map(print, 'cases'))
|
|
13
11
|
]
|
|
14
12
|
};
|
|
15
|
-
|
|
16
|
-
module.exports = AssemblySwitch;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
const printers = require('../binary-operator-printers');
|
|
1
|
+
import * as printers from '../binary-operator-printers/index.js';
|
|
3
2
|
|
|
4
|
-
const BinaryOperation = {
|
|
3
|
+
export const BinaryOperation = {
|
|
5
4
|
print: ({ node, path, print, options }) => {
|
|
6
5
|
const binaryOperationPrinter = Object.values(printers).find((printer) =>
|
|
7
6
|
printer.match(node.operator)
|
|
@@ -16,5 +15,3 @@ const BinaryOperation = {
|
|
|
16
15
|
return binaryOperationPrinter.print(node, path, print, options);
|
|
17
16
|
}
|
|
18
17
|
};
|
|
19
|
-
|
|
20
|
-
module.exports = BinaryOperation;
|
package/src/nodes/Block.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { hardline, indent }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
6
|
-
|
|
7
|
-
const {
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import {
|
|
8
3
|
printComments,
|
|
9
4
|
printPreservingEmptyLines
|
|
10
|
-
}
|
|
5
|
+
} from '../common/printer-helpers.js';
|
|
6
|
+
|
|
7
|
+
const { hardline, indent } = doc.builders;
|
|
11
8
|
|
|
12
|
-
const Block = {
|
|
9
|
+
export const Block = {
|
|
13
10
|
print: ({ node, options, path, print }) =>
|
|
14
11
|
// if block is empty, just return the pair of braces
|
|
15
12
|
node.statements.length === 0 && !node.comments
|
|
@@ -25,5 +22,3 @@ const Block = {
|
|
|
25
22
|
'}'
|
|
26
23
|
]
|
|
27
24
|
};
|
|
28
|
-
|
|
29
|
-
module.exports = Block;
|
package/src/nodes/Break.js
CHANGED
package/src/nodes/CatchClause.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { printSeparatedList } from '../common/printer-helpers.js';
|
|
2
2
|
|
|
3
3
|
const parameters = (node, path, print) =>
|
|
4
4
|
node.parameters
|
|
@@ -10,12 +10,10 @@ const parameters = (node, path, print) =>
|
|
|
10
10
|
]
|
|
11
11
|
: '';
|
|
12
12
|
|
|
13
|
-
const CatchClause = {
|
|
13
|
+
export const CatchClause = {
|
|
14
14
|
print: ({ node, path, print }) => [
|
|
15
15
|
'catch ',
|
|
16
16
|
parameters(node, path, print),
|
|
17
17
|
path.call(print, 'body')
|
|
18
18
|
]
|
|
19
19
|
};
|
|
20
|
-
|
|
21
|
-
module.exports = CatchClause;
|
package/src/nodes/Conditional.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
doc: {
|
|
3
|
-
builders: { group, indent, line }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
6
2
|
|
|
7
|
-
const
|
|
3
|
+
const { group, indent, line } = doc.builders;
|
|
4
|
+
|
|
5
|
+
export const Conditional = {
|
|
8
6
|
print: ({ path, print }) =>
|
|
9
7
|
group([
|
|
10
8
|
path.call(print, 'condition'),
|
|
@@ -18,5 +16,3 @@ const Conditional = {
|
|
|
18
16
|
])
|
|
19
17
|
])
|
|
20
18
|
};
|
|
21
|
-
|
|
22
|
-
module.exports = Conditional;
|
package/src/nodes/Continue.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { group, line, hardline }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
6
|
-
|
|
7
|
-
const {
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import {
|
|
8
3
|
printComments,
|
|
9
4
|
printPreservingEmptyLines,
|
|
10
5
|
printSeparatedItem,
|
|
11
6
|
printSeparatedList
|
|
12
|
-
}
|
|
7
|
+
} from '../common/printer-helpers.js';
|
|
8
|
+
|
|
9
|
+
const { group, line, hardline } = doc.builders;
|
|
13
10
|
|
|
14
11
|
const inheritance = (node, path, print) =>
|
|
15
12
|
node.baseContracts.length > 0
|
|
@@ -21,18 +18,17 @@ const inheritance = (node, path, print) =>
|
|
|
21
18
|
]
|
|
22
19
|
: line;
|
|
23
20
|
|
|
24
|
-
const body = (node, path, options, print) =>
|
|
25
|
-
|
|
21
|
+
const body = (node, path, options, print) => {
|
|
22
|
+
const comments = printComments(node, path, options);
|
|
23
|
+
return node.subNodes.length > 0 || (comments && comments.length)
|
|
26
24
|
? printSeparatedItem(
|
|
27
|
-
[
|
|
28
|
-
printPreservingEmptyLines(path, 'subNodes', options, print),
|
|
29
|
-
printComments(node, path, options)
|
|
30
|
-
],
|
|
25
|
+
[printPreservingEmptyLines(path, 'subNodes', options, print), comments],
|
|
31
26
|
{ firstSeparator: hardline, grouped: false }
|
|
32
27
|
)
|
|
33
28
|
: '';
|
|
29
|
+
};
|
|
34
30
|
|
|
35
|
-
const ContractDefinition = {
|
|
31
|
+
export const ContractDefinition = {
|
|
36
32
|
print: ({ node, options, path, print }) => [
|
|
37
33
|
group([
|
|
38
34
|
node.kind === 'abstract' ? 'abstract contract' : node.kind,
|
|
@@ -45,5 +41,3 @@ const ContractDefinition = {
|
|
|
45
41
|
'}'
|
|
46
42
|
]
|
|
47
43
|
};
|
|
48
|
-
|
|
49
|
-
module.exports = ContractDefinition;
|