prettier-plugin-solidity 1.1.2 → 1.1.4-dev
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/printer-helpers.js +15 -28
- package/src/common/util.js +30 -20
- 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 +11 -14
- 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 +14 -12
- 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
package/src/common/util.js
CHANGED
|
@@ -1,18 +1,35 @@
|
|
|
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);
|
|
5
|
+
export const isPrettier2 = () => prettierVersionSatisfies('^2.3.0');
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
// The following functions will never be 100% covered in a single run
|
|
8
|
+
// since it depends on the version of Prettier being used.
|
|
9
|
+
// Mocking the behaviour will introduce a lot of maintenance in the tests.
|
|
10
|
+
/* c8 ignore start */
|
|
11
|
+
export function isNextLineEmpty(text, startIndex) {
|
|
12
|
+
return isPrettier2()
|
|
13
|
+
? util.isNextLineEmptyAfterIndex(text, startIndex)
|
|
14
|
+
: util.isNextLineEmpty(text, startIndex); // V3 deprecated `isNextLineEmptyAfterIndex`
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
|
|
18
|
+
return isPrettier2()
|
|
19
|
+
? util.getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)
|
|
20
|
+
: util.getNextNonSpaceNonCommentCharacterIndex(text, locEnd(node)); // V3 signature changed
|
|
13
21
|
}
|
|
14
22
|
|
|
15
|
-
function
|
|
23
|
+
export function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
|
|
24
|
+
return isPrettier2()
|
|
25
|
+
? text.charAt(
|
|
26
|
+
util.getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)
|
|
27
|
+
)
|
|
28
|
+
: util.getNextNonSpaceNonCommentCharacter(text, locEnd(node)); // V3 exposes this function directly
|
|
29
|
+
}
|
|
30
|
+
/* c8 ignore stop */
|
|
31
|
+
|
|
32
|
+
export function printString(rawContent, options) {
|
|
16
33
|
const double = { quote: '"', regex: /"/g };
|
|
17
34
|
const single = { quote: "'", regex: /'/g };
|
|
18
35
|
|
|
@@ -44,10 +61,10 @@ function printString(rawContent, options) {
|
|
|
44
61
|
// is enclosed with `enclosingQuote`, but it isn't. The string could contain
|
|
45
62
|
// unnecessary escapes (such as in `"\'"`). Always using `makeString` makes
|
|
46
63
|
// sure that we consistently output the minimum amount of escaped quotes.
|
|
47
|
-
return makeString(rawContent, enclosingQuote);
|
|
64
|
+
return util.makeString(rawContent, enclosingQuote);
|
|
48
65
|
}
|
|
49
66
|
|
|
50
|
-
function hasNodeIgnoreComment(node) {
|
|
67
|
+
export function hasNodeIgnoreComment(node) {
|
|
51
68
|
return (
|
|
52
69
|
node &&
|
|
53
70
|
node.comments &&
|
|
@@ -55,10 +72,3 @@ function hasNodeIgnoreComment(node) {
|
|
|
55
72
|
node.comments.some((comment) => comment.value.trim() === 'prettier-ignore')
|
|
56
73
|
);
|
|
57
74
|
}
|
|
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;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { printSeparatedList } from '../common/printer-helpers.js';
|
|
2
2
|
|
|
3
3
|
const parameters = (node, path, print) =>
|
|
4
4
|
node.parameters && node.parameters.length > 0
|
|
5
5
|
? printSeparatedList(path.map(print, 'parameters'))
|
|
6
6
|
: '';
|
|
7
7
|
|
|
8
|
-
const CustomErrorDefinition = {
|
|
8
|
+
export const CustomErrorDefinition = {
|
|
9
9
|
print: ({ node, path, print }) => [
|
|
10
10
|
'error ',
|
|
11
11
|
node.name,
|
|
@@ -14,5 +14,3 @@ const CustomErrorDefinition = {
|
|
|
14
14
|
');'
|
|
15
15
|
]
|
|
16
16
|
};
|
|
17
|
-
|
|
18
|
-
module.exports = CustomErrorDefinition;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { group, indent, line }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { printSeparatedItem } from '../common/printer-helpers.js';
|
|
6
3
|
|
|
7
|
-
const {
|
|
4
|
+
const { group, indent, line } = doc.builders;
|
|
8
5
|
|
|
9
6
|
const printBody = (node, path, print) =>
|
|
10
7
|
node.body.type === 'Block'
|
|
11
8
|
? [' ', path.call(print, 'body'), ' ']
|
|
12
9
|
: group([indent([line, path.call(print, 'body')]), line]);
|
|
13
10
|
|
|
14
|
-
const DoWhileStatement = {
|
|
11
|
+
export const DoWhileStatement = {
|
|
15
12
|
print: ({ node, path, print }) => [
|
|
16
13
|
'do',
|
|
17
14
|
printBody(node, path, print),
|
|
@@ -20,5 +17,3 @@ const DoWhileStatement = {
|
|
|
20
17
|
');'
|
|
21
18
|
]
|
|
22
19
|
};
|
|
23
|
-
|
|
24
|
-
module.exports = DoWhileStatement;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { group, hardline }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { printSeparatedList } from '../common/printer-helpers.js';
|
|
6
3
|
|
|
7
|
-
const {
|
|
4
|
+
const { group, hardline } = doc.builders;
|
|
8
5
|
|
|
9
|
-
const EnumDefinition = {
|
|
6
|
+
export const EnumDefinition = {
|
|
10
7
|
print: ({ node, path, print }) =>
|
|
11
8
|
group([
|
|
12
9
|
'enum ',
|
|
@@ -18,5 +15,3 @@ const EnumDefinition = {
|
|
|
18
15
|
'}'
|
|
19
16
|
])
|
|
20
17
|
};
|
|
21
|
-
|
|
22
|
-
module.exports = EnumDefinition;
|
package/src/nodes/EnumValue.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { printSeparatedList } from '../common/printer-helpers.js';
|
|
2
2
|
|
|
3
3
|
const parameters = (node, path, print) =>
|
|
4
4
|
node.parameters && node.parameters.length > 0
|
|
5
5
|
? printSeparatedList(path.map(print, 'parameters'))
|
|
6
6
|
: '';
|
|
7
7
|
|
|
8
|
-
const EventDefinition = {
|
|
8
|
+
export const EventDefinition = {
|
|
9
9
|
print: ({ node, path, print }) => [
|
|
10
10
|
'event ',
|
|
11
11
|
node.name,
|
|
@@ -16,5 +16,3 @@ const EventDefinition = {
|
|
|
16
16
|
';'
|
|
17
17
|
]
|
|
18
18
|
};
|
|
19
|
-
|
|
20
|
-
module.exports = EventDefinition;
|