prettier-plugin-solidity 1.1.4-dev → 1.3.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 +16 -1
- package/dist/standalone.cjs +1 -2
- package/dist/standalone.cjs.map +1 -1
- package/package.json +6 -6
- package/src/binary-operator-printers/logical.js +9 -3
- package/src/comments/handlers/handleContractDefinitionComments.js +3 -6
- package/src/comments/handlers/handleModifierInvocationComments.js +1 -1
- package/src/common/backward-compatibility.js +34 -0
- package/src/common/printer-helpers.js +12 -18
- package/src/common/util.js +1 -29
- package/src/loc.js +1 -1
- package/src/nodes/Conditional.js +83 -13
- package/src/nodes/ContractDefinition.js +1 -1
- package/src/nodes/CustomErrorDefinition.js +1 -1
- package/src/nodes/ElementaryTypeName.js +1 -3
- package/src/nodes/EventDefinition.js +1 -1
- package/src/nodes/ExpressionStatement.js +2 -2
- package/src/nodes/FunctionCall.js +2 -2
- package/src/nodes/FunctionDefinition.js +3 -3
- package/src/nodes/InheritanceSpecifier.js +1 -1
- package/src/nodes/InlineAssemblyStatement.js +1 -1
- package/src/nodes/ModifierDefinition.js +1 -1
- package/src/nodes/ModifierInvocation.js +1 -2
- package/src/nodes/ReturnStatement.js +5 -4
- package/src/nodes/TupleExpression.js +3 -5
- package/src/nodes/UsingForDeclaration.js +1 -1
- package/src/nodes/VariableDeclarationStatement.js +1 -1
- package/src/options.js +10 -0
- package/src/parser.js +34 -23
- package/src/prettier-comments/language-js/comments.js +1 -1
- package/dist/standalone.cjs.LICENSE.txt +0 -15
package/src/parser.js
CHANGED
|
@@ -43,7 +43,7 @@ function parse(text, _parsers, options = _parsers) {
|
|
|
43
43
|
FunctionDefinition(ctx) {
|
|
44
44
|
if (!ctx.isConstructor) {
|
|
45
45
|
ctx.modifiers.forEach((modifier) => {
|
|
46
|
-
if (modifier.arguments
|
|
46
|
+
if (modifier.arguments?.length === 0) {
|
|
47
47
|
// eslint-disable-next-line no-param-reassign
|
|
48
48
|
modifier.arguments = null;
|
|
49
49
|
}
|
|
@@ -57,9 +57,20 @@ function parse(text, _parsers, options = _parsers) {
|
|
|
57
57
|
ctx.loopExpression.omitSemicolon = true;
|
|
58
58
|
},
|
|
59
59
|
HexLiteral(ctx) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
const value = ctx.value.slice(4, -1);
|
|
61
|
+
ctx.value = options.singleQuote ? `hex'${value}'` : `hex"${value}"`;
|
|
62
|
+
},
|
|
63
|
+
Conditional(ctx) {
|
|
64
|
+
// We can remove parentheses only because we are sure that the
|
|
65
|
+
// `condition` must be a single `bool` value.
|
|
66
|
+
while (
|
|
67
|
+
ctx.condition.type === 'TupleExpression' &&
|
|
68
|
+
!ctx.condition.isArray &&
|
|
69
|
+
ctx.condition.components.length === 1 &&
|
|
70
|
+
ctx.condition.components[0].type !== 'Conditional'
|
|
71
|
+
) {
|
|
72
|
+
[ctx.condition] = ctx.condition.components;
|
|
73
|
+
}
|
|
63
74
|
},
|
|
64
75
|
BinaryOperation(ctx) {
|
|
65
76
|
switch (ctx.operator) {
|
|
@@ -78,34 +89,34 @@ function parse(text, _parsers, options = _parsers) {
|
|
|
78
89
|
ctx.left = tryHug(ctx.left, ['*', '/', '%']);
|
|
79
90
|
break;
|
|
80
91
|
case '**':
|
|
81
|
-
// If the compiler has not been given as an option using we leave
|
|
92
|
+
// If the compiler has not been given as an option using we leave
|
|
93
|
+
// a**b**c.
|
|
82
94
|
if (!compiler) break;
|
|
83
95
|
|
|
84
|
-
if (satisfies(compiler, '
|
|
85
|
-
// If the compiler is
|
|
86
|
-
//
|
|
87
|
-
ctx.
|
|
96
|
+
if (satisfies(compiler, '>=0.8.0')) {
|
|
97
|
+
// If the compiler is greater than or equal to 0.8.0 then a**b**c
|
|
98
|
+
// is formatted as a**(b**c).
|
|
99
|
+
ctx.right = tryHug(ctx.right, ['**']);
|
|
88
100
|
break;
|
|
89
101
|
}
|
|
90
102
|
if (
|
|
91
|
-
ctx.
|
|
92
|
-
ctx.
|
|
103
|
+
ctx.right.type === 'BinaryOperation' &&
|
|
104
|
+
ctx.right.operator === '**'
|
|
93
105
|
) {
|
|
94
|
-
// the parser
|
|
95
|
-
//
|
|
96
|
-
|
|
106
|
+
// the parser organizes the a**b**c as a**(b**c) so we need to
|
|
107
|
+
// restructure it.
|
|
108
|
+
const left = {
|
|
109
|
+
type: 'BinaryOperation',
|
|
110
|
+
operator: '**',
|
|
111
|
+
left: ctx.left,
|
|
112
|
+
right: ctx.right.left
|
|
113
|
+
};
|
|
114
|
+
ctx.left = {
|
|
97
115
|
type: 'TupleExpression',
|
|
98
|
-
components: [
|
|
99
|
-
{
|
|
100
|
-
type: 'BinaryOperation',
|
|
101
|
-
operator: '**',
|
|
102
|
-
left: ctx.left.right,
|
|
103
|
-
right: ctx.right
|
|
104
|
-
}
|
|
105
|
-
],
|
|
116
|
+
components: [left],
|
|
106
117
|
isArray: false
|
|
107
118
|
};
|
|
108
|
-
ctx.
|
|
119
|
+
ctx.right = ctx.right.right;
|
|
109
120
|
}
|
|
110
121
|
break;
|
|
111
122
|
case '<<':
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright 2016 The ANTLR Project. All rights reserved.
|
|
3
|
-
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/*!
|
|
7
|
-
* The buffer module from node.js, for the browser.
|
|
8
|
-
*
|
|
9
|
-
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
|
|
10
|
-
* @license MIT
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/*! https://mths.be/codepointat v0.2.0 by @mathias */
|
|
14
|
-
|
|
15
|
-
/*! https://mths.be/fromcodepoint v0.2.1 by @mathias */
|