prettier-plugin-solidity 2.0.0 → 2.1.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/LICENSE +1 -1
- package/README.md +2 -2
- package/dist/3620299963220ca08ee1.wasm +0 -0
- package/dist/binary-operator-printers/addition.js +11 -0
- package/dist/binary-operator-printers/addition.js.map +1 -0
- package/dist/binary-operator-printers/bit.js +5 -2
- package/dist/binary-operator-printers/bit.js.map +1 -1
- package/dist/binary-operator-printers/equality.js +7 -0
- package/dist/binary-operator-printers/equality.js.map +1 -0
- package/dist/binary-operator-printers/exponentiation.js +20 -12
- package/dist/binary-operator-printers/exponentiation.js.map +1 -1
- package/dist/binary-operator-printers/index.js +4 -2
- package/dist/binary-operator-printers/index.js.map +1 -1
- package/dist/binary-operator-printers/inequality.js +8 -0
- package/dist/binary-operator-printers/inequality.js.map +1 -0
- package/dist/binary-operator-printers/logical.js +9 -24
- package/dist/binary-operator-printers/logical.js.map +1 -1
- package/dist/binary-operator-printers/multiplication.js +19 -0
- package/dist/binary-operator-printers/multiplication.js.map +1 -0
- package/dist/binary-operator-printers/printers/binary-operation-printer.js +5 -0
- package/dist/binary-operator-printers/printers/binary-operation-printer.js.map +1 -0
- package/dist/binary-operator-printers/printers/create-binary-operation-printer.js +24 -0
- package/dist/binary-operator-printers/printers/create-binary-operation-printer.js.map +1 -0
- package/dist/binary-operator-printers/printers/create-group-if-necessary-builder.js +10 -0
- package/dist/binary-operator-printers/printers/create-group-if-necessary-builder.js.map +1 -0
- package/dist/binary-operator-printers/printers/create-indent-if-necessary-builder.js +22 -0
- package/dist/binary-operator-printers/printers/create-indent-if-necessary-builder.js.map +1 -0
- package/dist/binary-operator-printers/shift.js +6 -2
- package/dist/binary-operator-printers/shift.js.map +1 -1
- package/dist/binary-operator-printers/utils/should-group-or-indent.js +3 -0
- package/dist/binary-operator-printers/utils/should-group-or-indent.js.map +1 -0
- package/dist/comments/handlers/handleContractDefinitionComments.js +2 -3
- package/dist/comments/handlers/handleContractDefinitionComments.js.map +1 -1
- package/dist/comments/handlers/handleModifierInvocationComments.js +2 -3
- package/dist/comments/handlers/handleModifierInvocationComments.js.map +1 -1
- package/dist/common/printer-helpers.js +4 -11
- package/dist/common/printer-helpers.js.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/nodes/Conditional.js +2 -2
- package/dist/nodes/Conditional.js.map +1 -1
- package/dist/nodes/ExpressionStatement.js +1 -1
- package/dist/nodes/ExpressionStatement.js.map +1 -1
- package/dist/nodes/FunctionDefinition.js +3 -3
- package/dist/nodes/FunctionDefinition.js.map +1 -1
- package/dist/nodes/ImportDirective.js +3 -1
- package/dist/nodes/ImportDirective.js.map +1 -1
- package/dist/options.js +16 -0
- package/dist/options.js.map +1 -1
- package/dist/parser.js +4 -0
- package/dist/parser.js.map +1 -1
- package/dist/prettier-comments/language-js/comments.js +8 -9
- package/dist/prettier-comments/language-js/comments.js.map +1 -1
- package/dist/printer.js +1 -1
- package/dist/printer.js.map +1 -1
- package/dist/slang-comments/handlers/{add-collection-node-first-comment.js → add-collection-first-comment.js} +2 -2
- package/dist/slang-comments/handlers/add-collection-first-comment.js.map +1 -0
- package/dist/slang-comments/handlers/{add-collection-node-last-comment.js → add-collection-last-comment.js} +2 -2
- package/dist/slang-comments/handlers/add-collection-last-comment.js.map +1 -0
- package/dist/slang-comments/handlers/handle-block-comments.js +4 -4
- package/dist/slang-comments/handlers/handle-block-comments.js.map +1 -1
- package/dist/slang-comments/handlers/handle-contract-definition-comments.js +3 -3
- package/dist/slang-comments/handlers/handle-contract-definition-comments.js.map +1 -1
- package/dist/slang-comments/handlers/handle-contract-specifiers-comments.js +2 -2
- package/dist/slang-comments/handlers/handle-contract-specifiers-comments.js.map +1 -1
- package/dist/slang-comments/handlers/handle-else-branch-comments.js +2 -2
- package/dist/slang-comments/handlers/handle-else-branch-comments.js.map +1 -1
- package/dist/slang-comments/handlers/handle-if-statement-comments.js +3 -3
- package/dist/slang-comments/handlers/handle-if-statement-comments.js.map +1 -1
- package/dist/slang-comments/handlers/handle-interface-definition-comments.js +4 -4
- package/dist/slang-comments/handlers/handle-interface-definition-comments.js.map +1 -1
- package/dist/slang-comments/handlers/handle-library-definition-comments.js +4 -4
- package/dist/slang-comments/handlers/handle-library-definition-comments.js.map +1 -1
- package/dist/slang-comments/handlers/handle-modifier-invocation-comments.js +2 -2
- package/dist/slang-comments/handlers/handle-modifier-invocation-comments.js.map +1 -1
- package/dist/slang-comments/handlers/handle-parameters-declaration-comments.js +4 -4
- package/dist/slang-comments/handlers/handle-parameters-declaration-comments.js.map +1 -1
- package/dist/slang-comments/handlers/handle-positional-arguments-declaration-comments.js +4 -4
- package/dist/slang-comments/handlers/handle-positional-arguments-declaration-comments.js.map +1 -1
- package/dist/slang-comments/handlers/handle-struct-comments.js +22 -0
- package/dist/slang-comments/handlers/handle-struct-comments.js.map +1 -0
- package/dist/slang-comments/handlers/handle-while-statement-comments.js +2 -2
- package/dist/slang-comments/handlers/handle-while-statement-comments.js.map +1 -1
- package/dist/slang-comments/handlers/index.js +2 -0
- package/dist/slang-comments/handlers/index.js.map +1 -1
- package/dist/slang-comments/printer.js +1 -2
- package/dist/slang-comments/printer.js.map +1 -1
- package/dist/slang-nodes/AdditiveExpression.js +12 -1
- package/dist/slang-nodes/AdditiveExpression.js.map +1 -1
- package/dist/slang-nodes/BitwiseAndExpression.js +8 -1
- package/dist/slang-nodes/BitwiseAndExpression.js.map +1 -1
- package/dist/slang-nodes/BitwiseOrExpression.js +8 -1
- package/dist/slang-nodes/BitwiseOrExpression.js.map +1 -1
- package/dist/slang-nodes/BitwiseXorExpression.js +8 -1
- package/dist/slang-nodes/BitwiseXorExpression.js.map +1 -1
- package/dist/slang-nodes/ConditionalExpression.js +11 -10
- package/dist/slang-nodes/ConditionalExpression.js.map +1 -1
- package/dist/slang-nodes/ContractDefinition.js +4 -4
- package/dist/slang-nodes/ContractDefinition.js.map +1 -1
- package/dist/slang-nodes/EqualityExpression.js +10 -2
- package/dist/slang-nodes/EqualityExpression.js.map +1 -1
- package/dist/slang-nodes/ExponentiationExpression.js +16 -2
- package/dist/slang-nodes/ExponentiationExpression.js.map +1 -1
- package/dist/slang-nodes/FallbackFunctionDefinition.js +4 -4
- package/dist/slang-nodes/FallbackFunctionDefinition.js.map +1 -1
- package/dist/slang-nodes/FunctionCallExpression.js +6 -5
- package/dist/slang-nodes/FunctionCallExpression.js.map +1 -1
- package/dist/slang-nodes/FunctionDefinition.js +4 -4
- package/dist/slang-nodes/FunctionDefinition.js.map +1 -1
- package/dist/slang-nodes/IfStatement.js +5 -4
- package/dist/slang-nodes/IfStatement.js.map +1 -1
- package/dist/slang-nodes/ImportDeconstructionSymbols.js +1 -1
- package/dist/slang-nodes/ImportDeconstructionSymbols.js.map +1 -1
- package/dist/slang-nodes/IndexAccessExpression.js +10 -9
- package/dist/slang-nodes/IndexAccessExpression.js.map +1 -1
- package/dist/slang-nodes/InequalityExpression.js +8 -2
- package/dist/slang-nodes/InequalityExpression.js.map +1 -1
- package/dist/slang-nodes/MemberAccessExpression.js +11 -13
- package/dist/slang-nodes/MemberAccessExpression.js.map +1 -1
- package/dist/slang-nodes/MultiplicativeExpression.js +13 -1
- package/dist/slang-nodes/MultiplicativeExpression.js.map +1 -1
- package/dist/slang-nodes/ReceiveFunctionDefinition.js +4 -4
- package/dist/slang-nodes/ReceiveFunctionDefinition.js.map +1 -1
- package/dist/slang-nodes/ReturnStatement.js +5 -3
- package/dist/slang-nodes/ReturnStatement.js.map +1 -1
- package/dist/slang-nodes/ShiftExpression.js +11 -1
- package/dist/slang-nodes/ShiftExpression.js.map +1 -1
- package/dist/slang-nodes/StateVariableDefinition.js +1 -4
- package/dist/slang-nodes/StateVariableDefinition.js.map +1 -1
- package/dist/slang-nodes/TupleDeconstructionStatement.js +1 -2
- package/dist/slang-nodes/TupleDeconstructionStatement.js.map +1 -1
- package/dist/slang-nodes/UnnamedFunctionDefinition.js +3 -3
- package/dist/slang-nodes/UnnamedFunctionDefinition.js.map +1 -1
- package/dist/slang-nodes/VariableDeclarationStatement.js +10 -11
- package/dist/slang-nodes/VariableDeclarationStatement.js.map +1 -1
- package/dist/slang-printers/create-binary-operation-printer.js +14 -9
- package/dist/slang-printers/create-binary-operation-printer.js.map +1 -1
- package/dist/slang-printers/print-binary-operation.js +24 -25
- package/dist/slang-printers/print-binary-operation.js.map +1 -1
- package/dist/slang-printers/print-comments.js +1 -1
- package/dist/slang-printers/print-comments.js.map +1 -1
- package/dist/slang-printers/print-logical-operation.js +5 -13
- package/dist/slang-printers/print-logical-operation.js.map +1 -1
- package/dist/slang-printers/print-preserving-empty-lines.js +1 -1
- package/dist/slang-printers/print-preserving-empty-lines.js.map +1 -1
- package/dist/slang-utils/create-hug-function.js +5 -4
- package/dist/slang-utils/create-hug-function.js.map +1 -1
- package/dist/slang-utils/create-parser.js +31 -86
- package/dist/slang-utils/create-parser.js.map +1 -1
- package/dist/slang-utils/metadata.js +31 -35
- package/dist/slang-utils/metadata.js.map +1 -1
- package/dist/slang-utils/sort-contract-specifiers.js +5 -7
- package/dist/slang-utils/sort-contract-specifiers.js.map +1 -1
- package/dist/slang-utils/sort-function-attributes.js +1 -3
- package/dist/slang-utils/sort-function-attributes.js.map +1 -1
- package/dist/slangPrinter.js +9 -16
- package/dist/slangPrinter.js.map +1 -1
- package/dist/slangSolidityParser.js +6 -9
- package/dist/slangSolidityParser.js.map +1 -1
- package/dist/standalone.js +1 -1
- package/dist/standalone.js.map +1 -1
- package/package.json +19 -19
- package/src/binary-operator-printers/addition.js +11 -0
- package/src/binary-operator-printers/bit.js +5 -2
- package/src/binary-operator-printers/equality.js +7 -0
- package/src/binary-operator-printers/exponentiation.js +22 -13
- package/src/binary-operator-printers/index.js +4 -2
- package/src/binary-operator-printers/inequality.js +8 -0
- package/src/binary-operator-printers/logical.js +12 -26
- package/src/binary-operator-printers/multiplication.js +19 -0
- package/src/binary-operator-printers/printers/binary-operation-printer.js +9 -0
- package/src/binary-operator-printers/printers/create-binary-operation-printer.js +31 -0
- package/src/binary-operator-printers/printers/create-group-if-necessary-builder.js +12 -0
- package/src/binary-operator-printers/printers/create-indent-if-necessary-builder.js +23 -0
- package/src/binary-operator-printers/shift.js +6 -2
- package/src/binary-operator-printers/utils/should-group-or-indent.js +3 -0
- package/src/comments/handlers/handleContractDefinitionComments.js +7 -4
- package/src/comments/handlers/handleModifierInvocationComments.js +7 -4
- package/src/common/printer-helpers.js +4 -15
- package/src/index.ts +2 -4
- package/src/nodes/Conditional.js +2 -2
- package/src/nodes/ExpressionStatement.js +1 -1
- package/src/nodes/FunctionDefinition.js +3 -4
- package/src/nodes/ImportDirective.js +5 -1
- package/src/options.ts +16 -0
- package/src/parser.js +4 -0
- package/src/prettier-comments/language-js/comments.js +10 -16
- package/src/printer.js +1 -4
- package/src/slang-comments/handlers/{add-collection-node-first-comment.ts → add-collection-first-comment.ts} +3 -3
- package/src/slang-comments/handlers/{add-collection-node-last-comment.ts → add-collection-last-comment.ts} +3 -3
- package/src/slang-comments/handlers/handle-block-comments.ts +4 -4
- package/src/slang-comments/handlers/handle-contract-definition-comments.ts +3 -3
- package/src/slang-comments/handlers/handle-contract-specifiers-comments.ts +2 -2
- package/src/slang-comments/handlers/handle-else-branch-comments.ts +2 -2
- package/src/slang-comments/handlers/handle-if-statement-comments.ts +3 -6
- package/src/slang-comments/handlers/handle-interface-definition-comments.ts +4 -4
- package/src/slang-comments/handlers/handle-library-definition-comments.ts +4 -4
- package/src/slang-comments/handlers/handle-modifier-invocation-comments.ts +2 -2
- package/src/slang-comments/handlers/handle-parameters-declaration-comments.ts +4 -4
- package/src/slang-comments/handlers/handle-positional-arguments-declaration-comments.ts +4 -4
- package/src/slang-comments/handlers/handle-struct-comments.ts +39 -0
- package/src/slang-comments/handlers/handle-while-statement-comments.ts +2 -2
- package/src/slang-comments/handlers/index.ts +2 -0
- package/src/slang-comments/printer.ts +1 -3
- package/src/slang-nodes/AdditiveExpression.ts +15 -1
- package/src/slang-nodes/BitwiseAndExpression.ts +11 -1
- package/src/slang-nodes/BitwiseOrExpression.ts +14 -4
- package/src/slang-nodes/BitwiseXorExpression.ts +11 -1
- package/src/slang-nodes/ConditionalExpression.ts +10 -10
- package/src/slang-nodes/ContractDefinition.ts +4 -4
- package/src/slang-nodes/ContractSpecifier.ts +2 -2
- package/src/slang-nodes/ContractSpecifiers.ts +2 -2
- package/src/slang-nodes/EqualityExpression.ts +15 -2
- package/src/slang-nodes/ExponentiationExpression.ts +17 -4
- package/src/slang-nodes/FallbackFunctionDefinition.ts +4 -4
- package/src/slang-nodes/FunctionCallExpression.ts +6 -5
- package/src/slang-nodes/FunctionDefinition.ts +4 -4
- package/src/slang-nodes/IfStatement.ts +5 -4
- package/src/slang-nodes/ImportDeconstructionSymbols.ts +1 -1
- package/src/slang-nodes/IndexAccessExpression.ts +10 -10
- package/src/slang-nodes/InequalityExpression.ts +11 -2
- package/src/slang-nodes/MemberAccessExpression.ts +13 -17
- package/src/slang-nodes/MultiplicativeExpression.ts +16 -1
- package/src/slang-nodes/PositionalArguments.ts +2 -2
- package/src/slang-nodes/ReceiveFunctionDefinition.ts +4 -4
- package/src/slang-nodes/ReturnStatement.ts +4 -3
- package/src/slang-nodes/ShiftExpression.ts +14 -1
- package/src/slang-nodes/StateVariableDefinition.ts +1 -5
- package/src/slang-nodes/StorageLayoutSpecifier.ts +2 -2
- package/src/slang-nodes/StringLiteral.ts +1 -1
- package/src/slang-nodes/TupleDeconstructionStatement.ts +4 -6
- package/src/slang-nodes/UnnamedFunctionDefinition.ts +3 -3
- package/src/slang-nodes/VariableDeclarationStatement.ts +13 -15
- package/src/slang-nodes/types.d.ts +9 -1
- package/src/slang-printers/create-binary-operation-printer.ts +16 -11
- package/src/slang-printers/print-binary-operation.ts +48 -39
- package/src/slang-printers/print-comments.ts +1 -1
- package/src/slang-printers/print-logical-operation.ts +8 -17
- package/src/slang-printers/print-preserving-empty-lines.ts +3 -7
- package/src/slang-utils/create-hug-function.ts +5 -5
- package/src/slang-utils/create-parser.ts +56 -119
- package/src/slang-utils/metadata.ts +33 -37
- package/src/slang-utils/sort-contract-specifiers.ts +6 -9
- package/src/slang-utils/sort-function-attributes.ts +2 -5
- package/src/slangPrinter.ts +11 -21
- package/src/slangSolidityParser.ts +9 -12
- package/dist/binary-operator-printers/arithmetic.js +0 -44
- package/dist/binary-operator-printers/arithmetic.js.map +0 -1
- package/dist/binary-operator-printers/comparison.js +0 -38
- package/dist/binary-operator-printers/comparison.js.map +0 -1
- package/dist/common/backward-compatibility.js +0 -27
- package/dist/common/backward-compatibility.js.map +0 -1
- package/dist/ea6945b7193921081ced.wasm +0 -0
- package/dist/slang-comments/handlers/add-collection-node-first-comment.js.map +0 -1
- package/dist/slang-comments/handlers/add-collection-node-last-comment.js.map +0 -1
- package/dist/slang-printers/print-comparison-operation.js +0 -35
- package/dist/slang-printers/print-comparison-operation.js.map +0 -1
- package/src/binary-operator-printers/arithmetic.js +0 -51
- package/src/binary-operator-printers/comparison.js +0 -36
- package/src/common/backward-compatibility.js +0 -34
- package/src/slang-printers/print-comparison-operation.ts +0 -45
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { util } from 'prettier';
|
|
2
2
|
|
|
3
|
-
import type { Comment,
|
|
3
|
+
import type { Comment, Collection } from '../../slang-nodes/types.d.ts';
|
|
4
4
|
|
|
5
5
|
const { addDanglingComment, addLeadingComment } = util;
|
|
6
6
|
|
|
7
|
-
export default function
|
|
8
|
-
node:
|
|
7
|
+
export default function addCollectionFirstComment(
|
|
8
|
+
node: Collection,
|
|
9
9
|
comment: Comment
|
|
10
10
|
): void {
|
|
11
11
|
if (node.items.length === 0) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { util } from 'prettier';
|
|
2
2
|
|
|
3
|
-
import type { Comment,
|
|
3
|
+
import type { Comment, Collection } from '../../slang-nodes/types.d.ts';
|
|
4
4
|
|
|
5
5
|
const { addDanglingComment, addTrailingComment } = util;
|
|
6
6
|
|
|
7
|
-
export default function
|
|
8
|
-
node:
|
|
7
|
+
export default function addCollectionLastComment(
|
|
8
|
+
node: Collection,
|
|
9
9
|
comment: Comment
|
|
10
10
|
): void {
|
|
11
11
|
if (node.items.length === 0) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import addCollectionFirstComment from './add-collection-first-comment.js';
|
|
3
|
+
import addCollectionLastComment from './add-collection-last-comment.js';
|
|
4
4
|
|
|
5
5
|
import type { HandlerParams } from './types.d.ts';
|
|
6
6
|
|
|
@@ -15,12 +15,12 @@ export default function handleBlockComments({
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
if (precedingNode?.kind === NonterminalKind.Statements) {
|
|
18
|
-
|
|
18
|
+
addCollectionLastComment(precedingNode, comment);
|
|
19
19
|
return true;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
if (followingNode?.kind === NonterminalKind.Statements) {
|
|
23
|
-
|
|
23
|
+
addCollectionFirstComment(followingNode, comment);
|
|
24
24
|
return true;
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
2
2
|
import { util } from 'prettier';
|
|
3
3
|
import { locEnd } from '../../slang-utils/loc.js';
|
|
4
|
-
import
|
|
4
|
+
import addCollectionLastComment from './add-collection-last-comment.js';
|
|
5
5
|
|
|
6
6
|
import type { HandlerParams } from './types.d.ts';
|
|
7
7
|
|
|
@@ -36,7 +36,7 @@ export default function handleContractDefinitionComments({
|
|
|
36
36
|
|
|
37
37
|
// The comment is at the end of the body of the ContractDefinition.
|
|
38
38
|
if (precedingNode?.kind === NonterminalKind.ContractMembers) {
|
|
39
|
-
|
|
39
|
+
addCollectionLastComment(precedingNode, comment);
|
|
40
40
|
return true;
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -52,7 +52,7 @@ export default function handleContractDefinitionComments({
|
|
|
52
52
|
// If the last ContractSpecifier's an InheritanceSpecifier, the comment
|
|
53
53
|
// is appended to the last InheritanceType.
|
|
54
54
|
if (lastContractSpecifier.kind === NonterminalKind.InheritanceSpecifier) {
|
|
55
|
-
|
|
55
|
+
addCollectionLastComment(lastContractSpecifier.types, comment);
|
|
56
56
|
return true;
|
|
57
57
|
}
|
|
58
58
|
if (
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
2
2
|
import { util } from 'prettier';
|
|
3
|
-
import
|
|
3
|
+
import addCollectionLastComment from './add-collection-last-comment.js';
|
|
4
4
|
|
|
5
5
|
import type { HandlerParams } from './types.d.ts';
|
|
6
6
|
|
|
@@ -20,7 +20,7 @@ export default function handleContractSpecifiersComments({
|
|
|
20
20
|
precedingNode.kind === NonterminalKind.ContractSpecifier
|
|
21
21
|
) {
|
|
22
22
|
if (precedingNode.variant.kind === NonterminalKind.InheritanceSpecifier) {
|
|
23
|
-
|
|
23
|
+
addCollectionLastComment(precedingNode.variant.types, comment);
|
|
24
24
|
return true;
|
|
25
25
|
}
|
|
26
26
|
if (precedingNode.variant.kind === NonterminalKind.StorageLayoutSpecifier) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
2
2
|
import { util } from 'prettier';
|
|
3
|
-
import
|
|
3
|
+
import addCollectionFirstComment from './add-collection-first-comment.js';
|
|
4
4
|
|
|
5
5
|
import type { HandlerParams } from './types.d.ts';
|
|
6
6
|
|
|
@@ -20,7 +20,7 @@ export default function handleElseBranchComments({
|
|
|
20
20
|
followingNode.variant.kind === NonterminalKind.IfStatement
|
|
21
21
|
) {
|
|
22
22
|
if (followingNode.variant.body.variant.kind === NonterminalKind.Block) {
|
|
23
|
-
|
|
23
|
+
addCollectionFirstComment(
|
|
24
24
|
followingNode.variant.body.variant.statements,
|
|
25
25
|
comment
|
|
26
26
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
2
2
|
import { util } from 'prettier';
|
|
3
3
|
import { locEnd } from '../../slang-utils/loc.js';
|
|
4
|
-
import
|
|
4
|
+
import addCollectionFirstComment from './add-collection-first-comment.js';
|
|
5
5
|
|
|
6
6
|
import type { HandlerParams } from './types.d.ts';
|
|
7
7
|
|
|
@@ -45,10 +45,7 @@ export default function handleIfStatementComments({
|
|
|
45
45
|
|
|
46
46
|
if (followingNode.kind === NonterminalKind.IfStatement) {
|
|
47
47
|
if (followingNode.body.variant.kind === NonterminalKind.Block) {
|
|
48
|
-
|
|
49
|
-
followingNode.body.variant.statements,
|
|
50
|
-
comment
|
|
51
|
-
);
|
|
48
|
+
addCollectionFirstComment(followingNode.body.variant.statements, comment);
|
|
52
49
|
} else {
|
|
53
50
|
addLeadingComment(followingNode.body.variant, comment);
|
|
54
51
|
}
|
|
@@ -60,7 +57,7 @@ export default function handleIfStatementComments({
|
|
|
60
57
|
// if (a) /* comment */ true
|
|
61
58
|
if (enclosingNode.body === followingNode) {
|
|
62
59
|
if (followingNode.variant.kind === NonterminalKind.Block) {
|
|
63
|
-
|
|
60
|
+
addCollectionFirstComment(followingNode.variant.statements, comment);
|
|
64
61
|
} else {
|
|
65
62
|
addLeadingComment(followingNode, comment);
|
|
66
63
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
2
2
|
import { util } from 'prettier';
|
|
3
3
|
import { locEnd } from '../../slang-utils/loc.js';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
4
|
+
import addCollectionFirstComment from './add-collection-first-comment.js';
|
|
5
|
+
import addCollectionLastComment from './add-collection-last-comment.js';
|
|
6
6
|
|
|
7
7
|
import type { HandlerParams } from './types.d.ts';
|
|
8
8
|
|
|
@@ -24,7 +24,7 @@ export default function handleInterfaceDefinitionComments({
|
|
|
24
24
|
|
|
25
25
|
// The comment is at the end of the body of the InterfaceDefinition.
|
|
26
26
|
if (precedingNode?.kind === NonterminalKind.InterfaceMembers) {
|
|
27
|
-
|
|
27
|
+
addCollectionLastComment(precedingNode, comment);
|
|
28
28
|
return true;
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -33,7 +33,7 @@ export default function handleInterfaceDefinitionComments({
|
|
|
33
33
|
nextCharacter === '{' &&
|
|
34
34
|
followingNode?.kind === NonterminalKind.InterfaceMembers
|
|
35
35
|
) {
|
|
36
|
-
|
|
36
|
+
addCollectionFirstComment(followingNode, comment);
|
|
37
37
|
return true;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
2
2
|
import { util } from 'prettier';
|
|
3
3
|
import { locEnd } from '../../slang-utils/loc.js';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
4
|
+
import addCollectionFirstComment from './add-collection-first-comment.js';
|
|
5
|
+
import addCollectionLastComment from './add-collection-last-comment.js';
|
|
6
6
|
|
|
7
7
|
import type { HandlerParams } from './types.d.ts';
|
|
8
8
|
|
|
@@ -24,7 +24,7 @@ export default function handleLibraryDefinitionComments({
|
|
|
24
24
|
|
|
25
25
|
// The comment is at the end of the body of the ContractDefinition.
|
|
26
26
|
if (precedingNode?.kind === NonterminalKind.LibraryMembers) {
|
|
27
|
-
|
|
27
|
+
addCollectionLastComment(precedingNode, comment);
|
|
28
28
|
return true;
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -33,7 +33,7 @@ export default function handleLibraryDefinitionComments({
|
|
|
33
33
|
nextCharacter === '{' &&
|
|
34
34
|
followingNode?.kind === NonterminalKind.LibraryMembers
|
|
35
35
|
) {
|
|
36
|
-
|
|
36
|
+
addCollectionFirstComment(followingNode, comment);
|
|
37
37
|
return true;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
2
2
|
import { util } from 'prettier';
|
|
3
3
|
import { locEnd } from '../../slang-utils/loc.js';
|
|
4
|
-
import
|
|
4
|
+
import addCollectionFirstComment from './add-collection-first-comment.js';
|
|
5
5
|
|
|
6
6
|
import type { HandlerParams } from './types.d.ts';
|
|
7
7
|
|
|
@@ -34,7 +34,7 @@ export default function handleModifierInvocationComments({
|
|
|
34
34
|
if (followingNode.variant.arguments.items.length === 0) {
|
|
35
35
|
addTrailingComment(enclosingNode, comment);
|
|
36
36
|
} else {
|
|
37
|
-
|
|
37
|
+
addCollectionFirstComment(followingNode.variant.arguments, comment);
|
|
38
38
|
}
|
|
39
39
|
return true;
|
|
40
40
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import addCollectionFirstComment from './add-collection-first-comment.js';
|
|
3
|
+
import addCollectionLastComment from './add-collection-last-comment.js';
|
|
4
4
|
|
|
5
5
|
import type { HandlerParams } from './types.d.ts';
|
|
6
6
|
|
|
@@ -15,12 +15,12 @@ export default function handleBlockComments({
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
if (precedingNode?.kind === NonterminalKind.Parameters) {
|
|
18
|
-
|
|
18
|
+
addCollectionLastComment(precedingNode, comment);
|
|
19
19
|
return true;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
if (followingNode?.kind === NonterminalKind.Parameters) {
|
|
23
|
-
|
|
23
|
+
addCollectionFirstComment(followingNode, comment);
|
|
24
24
|
return true;
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import addCollectionFirstComment from './add-collection-first-comment.js';
|
|
3
|
+
import addCollectionLastComment from './add-collection-last-comment.js';
|
|
4
4
|
|
|
5
5
|
import type { HandlerParams } from './types.d.ts';
|
|
6
6
|
|
|
@@ -15,12 +15,12 @@ export default function handlePositionalArgumentsDeclarationComments({
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
if (precedingNode?.kind === NonterminalKind.PositionalArguments) {
|
|
18
|
-
|
|
18
|
+
addCollectionLastComment(precedingNode, comment);
|
|
19
19
|
return true;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
if (followingNode?.kind === NonterminalKind.PositionalArguments) {
|
|
23
|
-
|
|
23
|
+
addCollectionFirstComment(followingNode, comment);
|
|
24
24
|
return true;
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
2
|
+
import { util } from 'prettier';
|
|
3
|
+
import { locEnd } from '../../slang-utils/loc.js';
|
|
4
|
+
import addCollectionFirstComment from './add-collection-first-comment.js';
|
|
5
|
+
import addCollectionLastComment from './add-collection-last-comment.js';
|
|
6
|
+
|
|
7
|
+
import type { HandlerParams } from './types.d.ts';
|
|
8
|
+
|
|
9
|
+
export default function handleStructComments({
|
|
10
|
+
text,
|
|
11
|
+
precedingNode,
|
|
12
|
+
enclosingNode,
|
|
13
|
+
followingNode,
|
|
14
|
+
comment
|
|
15
|
+
}: HandlerParams): boolean {
|
|
16
|
+
if (enclosingNode?.kind !== NonterminalKind.StructDefinition) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const nextCharacter = util.getNextNonSpaceNonCommentCharacter(
|
|
21
|
+
text,
|
|
22
|
+
locEnd(comment)
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
if (
|
|
26
|
+
precedingNode?.kind === NonterminalKind.StructMembers &&
|
|
27
|
+
nextCharacter === '}'
|
|
28
|
+
) {
|
|
29
|
+
addCollectionLastComment(precedingNode, comment);
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (followingNode?.kind === NonterminalKind.StructMembers) {
|
|
34
|
+
addCollectionFirstComment(followingNode, comment);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
2
2
|
import { util } from 'prettier';
|
|
3
3
|
import { locEnd } from '../../slang-utils/loc.js';
|
|
4
|
-
import
|
|
4
|
+
import addCollectionFirstComment from './add-collection-first-comment.js';
|
|
5
5
|
|
|
6
6
|
import type { HandlerParams } from './types.d.ts';
|
|
7
7
|
|
|
@@ -37,7 +37,7 @@ export default function handleWhileStatementComments({
|
|
|
37
37
|
|
|
38
38
|
if (enclosingNode.body === followingNode) {
|
|
39
39
|
if (followingNode.variant.kind === NonterminalKind.Block) {
|
|
40
|
-
|
|
40
|
+
addCollectionFirstComment(followingNode.variant.statements, comment);
|
|
41
41
|
} else {
|
|
42
42
|
addLeadingComment(followingNode, comment);
|
|
43
43
|
}
|
|
@@ -9,6 +9,7 @@ import handleModifierInvocationComments from './handle-modifier-invocation-comme
|
|
|
9
9
|
import handleParametersDeclarationComments from './handle-parameters-declaration-comments.js';
|
|
10
10
|
import handlePositionalArgumentsDeclarationComments from './handle-positional-arguments-declaration-comments.js';
|
|
11
11
|
import handleStorageLayoutSpecifierComments from './handle-storage-layout-specifier-comments.js';
|
|
12
|
+
import handleStructComments from './handle-struct-comments.js';
|
|
12
13
|
import handleWhileStatementComments from './handle-while-statement-comments.js';
|
|
13
14
|
import handleYulBlockComments from './handle-yul-block-comments.js';
|
|
14
15
|
|
|
@@ -24,6 +25,7 @@ export default [
|
|
|
24
25
|
handleParametersDeclarationComments,
|
|
25
26
|
handlePositionalArgumentsDeclarationComments,
|
|
26
27
|
handleStorageLayoutSpecifierComments,
|
|
28
|
+
handleStructComments,
|
|
27
29
|
handleWhileStatementComments,
|
|
28
30
|
handleYulBlockComments
|
|
29
31
|
];
|
|
@@ -3,9 +3,7 @@ import { isComment } from '../slang-utils/is-comment.js';
|
|
|
3
3
|
import type { AstPath, Doc } from 'prettier';
|
|
4
4
|
import type { AstNode } from '../slang-nodes/types.d.ts';
|
|
5
5
|
|
|
6
|
-
export function printComment(
|
|
7
|
-
const comment = commentPath.getNode()!;
|
|
8
|
-
|
|
6
|
+
export function printComment({ node: comment }: AstPath<AstNode>): Doc {
|
|
9
7
|
if (isComment(comment)) {
|
|
10
8
|
return comment.print();
|
|
11
9
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
2
2
|
import { printBinaryOperation } from '../slang-printers/print-binary-operation.js';
|
|
3
3
|
import { createHugFunction } from '../slang-utils/create-hug-function.js';
|
|
4
|
+
import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js';
|
|
4
5
|
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
|
|
5
6
|
import { Expression } from './Expression.js';
|
|
6
7
|
|
|
@@ -11,6 +12,19 @@ import type { PrintFunction, SlangNode } from '../types.d.ts';
|
|
|
11
12
|
|
|
12
13
|
const tryToHug = createHugFunction(['%']);
|
|
13
14
|
|
|
15
|
+
const printAdditiveExpression = printBinaryOperation(
|
|
16
|
+
createKindCheckFunction([
|
|
17
|
+
NonterminalKind.ShiftExpression,
|
|
18
|
+
NonterminalKind.BitwiseAndExpression,
|
|
19
|
+
NonterminalKind.BitwiseOrExpression,
|
|
20
|
+
NonterminalKind.BitwiseXorExpression,
|
|
21
|
+
NonterminalKind.InequalityExpression,
|
|
22
|
+
NonterminalKind.EqualityExpression,
|
|
23
|
+
NonterminalKind.AndExpression,
|
|
24
|
+
NonterminalKind.OrExpression
|
|
25
|
+
])
|
|
26
|
+
);
|
|
27
|
+
|
|
14
28
|
export class AdditiveExpression implements SlangNode {
|
|
15
29
|
readonly kind = NonterminalKind.AdditiveExpression;
|
|
16
30
|
|
|
@@ -45,6 +59,6 @@ export class AdditiveExpression implements SlangNode {
|
|
|
45
59
|
print: PrintFunction,
|
|
46
60
|
options: ParserOptions<AstNode>
|
|
47
61
|
): Doc {
|
|
48
|
-
return
|
|
62
|
+
return printAdditiveExpression(this, path, print, options);
|
|
49
63
|
}
|
|
50
64
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
2
2
|
import { printBinaryOperation } from '../slang-printers/print-binary-operation.js';
|
|
3
3
|
import { createHugFunction } from '../slang-utils/create-hug-function.js';
|
|
4
|
+
import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js';
|
|
4
5
|
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
|
|
5
6
|
import { Expression } from './Expression.js';
|
|
6
7
|
|
|
@@ -11,6 +12,15 @@ import type { PrintFunction, SlangNode } from '../types.d.ts';
|
|
|
11
12
|
|
|
12
13
|
const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>']);
|
|
13
14
|
|
|
15
|
+
const printBitwiseAndExpression = printBinaryOperation(
|
|
16
|
+
createKindCheckFunction([
|
|
17
|
+
NonterminalKind.InequalityExpression,
|
|
18
|
+
NonterminalKind.EqualityExpression,
|
|
19
|
+
NonterminalKind.AndExpression,
|
|
20
|
+
NonterminalKind.OrExpression
|
|
21
|
+
])
|
|
22
|
+
);
|
|
23
|
+
|
|
14
24
|
export class BitwiseAndExpression implements SlangNode {
|
|
15
25
|
readonly kind = NonterminalKind.BitwiseAndExpression;
|
|
16
26
|
|
|
@@ -45,6 +55,6 @@ export class BitwiseAndExpression implements SlangNode {
|
|
|
45
55
|
print: PrintFunction,
|
|
46
56
|
options: ParserOptions<AstNode>
|
|
47
57
|
): Doc {
|
|
48
|
-
return
|
|
58
|
+
return printBitwiseAndExpression(this, path, print, options);
|
|
49
59
|
}
|
|
50
60
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
2
2
|
import { printBinaryOperation } from '../slang-printers/print-binary-operation.js';
|
|
3
3
|
import { createHugFunction } from '../slang-utils/create-hug-function.js';
|
|
4
|
+
import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js';
|
|
4
5
|
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
|
|
5
6
|
import { Expression } from './Expression.js';
|
|
6
7
|
|
|
@@ -21,6 +22,15 @@ const tryToHug = createHugFunction([
|
|
|
21
22
|
'^'
|
|
22
23
|
]);
|
|
23
24
|
|
|
25
|
+
const printBitwiseOrExpression = printBinaryOperation(
|
|
26
|
+
createKindCheckFunction([
|
|
27
|
+
NonterminalKind.InequalityExpression,
|
|
28
|
+
NonterminalKind.EqualityExpression,
|
|
29
|
+
NonterminalKind.AndExpression,
|
|
30
|
+
NonterminalKind.OrExpression
|
|
31
|
+
])
|
|
32
|
+
);
|
|
33
|
+
|
|
24
34
|
export class BitwiseOrExpression implements SlangNode {
|
|
25
35
|
readonly kind = NonterminalKind.BitwiseOrExpression;
|
|
26
36
|
|
|
@@ -28,11 +38,11 @@ export class BitwiseOrExpression implements SlangNode {
|
|
|
28
38
|
|
|
29
39
|
loc;
|
|
30
40
|
|
|
31
|
-
leftOperand;
|
|
41
|
+
leftOperand: Expression;
|
|
32
42
|
|
|
33
|
-
operator;
|
|
43
|
+
operator: string;
|
|
34
44
|
|
|
35
|
-
rightOperand;
|
|
45
|
+
rightOperand: Expression;
|
|
36
46
|
|
|
37
47
|
constructor(ast: ast.BitwiseOrExpression, options: ParserOptions<AstNode>) {
|
|
38
48
|
let metadata = getNodeMetadata(ast);
|
|
@@ -55,6 +65,6 @@ export class BitwiseOrExpression implements SlangNode {
|
|
|
55
65
|
print: PrintFunction,
|
|
56
66
|
options: ParserOptions<AstNode>
|
|
57
67
|
): Doc {
|
|
58
|
-
return
|
|
68
|
+
return printBitwiseOrExpression(this, path, print, options);
|
|
59
69
|
}
|
|
60
70
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
2
2
|
import { printBinaryOperation } from '../slang-printers/print-binary-operation.js';
|
|
3
3
|
import { createHugFunction } from '../slang-utils/create-hug-function.js';
|
|
4
|
+
import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js';
|
|
4
5
|
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
|
|
5
6
|
import { Expression } from './Expression.js';
|
|
6
7
|
|
|
@@ -11,6 +12,15 @@ import type { PrintFunction, SlangNode } from '../types.d.ts';
|
|
|
11
12
|
|
|
12
13
|
const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>', '&']);
|
|
13
14
|
|
|
15
|
+
const printBitwiseXorExpression = printBinaryOperation(
|
|
16
|
+
createKindCheckFunction([
|
|
17
|
+
NonterminalKind.InequalityExpression,
|
|
18
|
+
NonterminalKind.EqualityExpression,
|
|
19
|
+
NonterminalKind.AndExpression,
|
|
20
|
+
NonterminalKind.OrExpression
|
|
21
|
+
])
|
|
22
|
+
);
|
|
23
|
+
|
|
14
24
|
export class BitwiseXorExpression implements SlangNode {
|
|
15
25
|
readonly kind = NonterminalKind.BitwiseXorExpression;
|
|
16
26
|
|
|
@@ -45,6 +55,6 @@ export class BitwiseXorExpression implements SlangNode {
|
|
|
45
55
|
print: PrintFunction,
|
|
46
56
|
options: ParserOptions<AstNode>
|
|
47
57
|
): Doc {
|
|
48
|
-
return
|
|
58
|
+
return printBitwiseXorExpression(this, path, print, options);
|
|
49
59
|
}
|
|
50
60
|
}
|
|
@@ -11,11 +11,11 @@ import type { PrintFunction, SlangNode } from '../types.d.ts';
|
|
|
11
11
|
|
|
12
12
|
const { group, hardline, ifBreak, indent, line, softline } = doc.builders;
|
|
13
13
|
|
|
14
|
-
function fillTab(
|
|
15
|
-
if (
|
|
14
|
+
function fillTab({ useTabs, tabWidth }: ParserOptions<AstNode>): Doc {
|
|
15
|
+
if (useTabs) return '\t';
|
|
16
16
|
// For the odd case of `tabWidth` of 1 or 0 we initiate `fillTab` as a single
|
|
17
17
|
// space.
|
|
18
|
-
return
|
|
18
|
+
return tabWidth > 2 ? ' '.repeat(tabWidth - 1) : ' ';
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
function experimentalTernaries(
|
|
@@ -24,7 +24,7 @@ function experimentalTernaries(
|
|
|
24
24
|
print: PrintFunction,
|
|
25
25
|
options: ParserOptions<AstNode>
|
|
26
26
|
): Doc {
|
|
27
|
-
const grandparent = path.
|
|
27
|
+
const grandparent = path.grandparent as StrictAstNode;
|
|
28
28
|
const isNested = grandparent.kind === NonterminalKind.ConditionalExpression;
|
|
29
29
|
const isNestedAsTrueExpression =
|
|
30
30
|
isNested && grandparent.trueExpression.variant === node;
|
|
@@ -50,9 +50,10 @@ function experimentalTernaries(
|
|
|
50
50
|
path.call(print, 'trueExpression')
|
|
51
51
|
]);
|
|
52
52
|
|
|
53
|
+
const groupId = Symbol('Slang.ConditionalExpression.trueExpression');
|
|
53
54
|
const conditionAndTrueExpressionGroup = group(
|
|
54
55
|
[operandDoc, trueExpressionDoc],
|
|
55
|
-
{ id:
|
|
56
|
+
{ id: groupId }
|
|
56
57
|
);
|
|
57
58
|
|
|
58
59
|
const falseExpression = path.call(print, 'falseExpression');
|
|
@@ -64,10 +65,9 @@ function experimentalTernaries(
|
|
|
64
65
|
: ifBreak(
|
|
65
66
|
[fillTab(options), indent(falseExpression)],
|
|
66
67
|
[' ', falseExpression],
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
68
|
+
// We only add `fillTab` if we are sure the trueExpression is
|
|
69
|
+
// indented.
|
|
70
|
+
{ groupId }
|
|
71
71
|
)
|
|
72
72
|
];
|
|
73
73
|
|
|
@@ -87,7 +87,7 @@ function traditionalTernaries(
|
|
|
87
87
|
indent([
|
|
88
88
|
// Nested trueExpression and falseExpression are always printed in a new
|
|
89
89
|
// line
|
|
90
|
-
(path.
|
|
90
|
+
(path.grandparent as StrictAstNode).kind ===
|
|
91
91
|
NonterminalKind.ConditionalExpression
|
|
92
92
|
? hardline
|
|
93
93
|
: line,
|
|
@@ -49,12 +49,12 @@ export class ContractDefinition implements SlangNode {
|
|
|
49
49
|
// the same name as the contract.
|
|
50
50
|
const compiler = coerce(options.compiler);
|
|
51
51
|
if (compiler && !satisfies(compiler, '>=0.5.0')) {
|
|
52
|
-
for (const member of this.members.items) {
|
|
52
|
+
for (const { variant: member } of this.members.items) {
|
|
53
53
|
if (
|
|
54
|
-
member.
|
|
55
|
-
member.
|
|
54
|
+
member.kind === NonterminalKind.FunctionDefinition &&
|
|
55
|
+
member.name.variant.value !== this.name.value
|
|
56
56
|
) {
|
|
57
|
-
member.
|
|
57
|
+
member.cleanModifierInvocationArguments();
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -5,8 +5,8 @@ import { StorageLayoutSpecifier } from './StorageLayoutSpecifier.js';
|
|
|
5
5
|
|
|
6
6
|
import type * as ast from '@nomicfoundation/slang/ast';
|
|
7
7
|
import type { AstPath, Doc, ParserOptions } from 'prettier';
|
|
8
|
-
import type { AstNode } from './types.
|
|
9
|
-
import type { PrintFunction, SlangNode } from '../types.
|
|
8
|
+
import type { AstNode } from './types.d.ts';
|
|
9
|
+
import type { PrintFunction, SlangNode } from '../types.d.ts';
|
|
10
10
|
|
|
11
11
|
export class ContractSpecifier implements SlangNode {
|
|
12
12
|
readonly kind = NonterminalKind.ContractSpecifier;
|
|
@@ -7,8 +7,8 @@ import { ContractSpecifier } from './ContractSpecifier.js';
|
|
|
7
7
|
|
|
8
8
|
import type * as ast from '@nomicfoundation/slang/ast';
|
|
9
9
|
import type { AstPath, Doc, ParserOptions } from 'prettier';
|
|
10
|
-
import type { AstNode } from './types.
|
|
11
|
-
import type { PrintFunction, SlangNode } from '../types.
|
|
10
|
+
import type { AstNode } from './types.d.ts';
|
|
11
|
+
import type { PrintFunction, SlangNode } from '../types.d.ts';
|
|
12
12
|
|
|
13
13
|
const { group, ifBreak, line, softline } = doc.builders;
|
|
14
14
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
2
|
-
import {
|
|
2
|
+
import { createHugFunction } from '../slang-utils/create-hug-function.js';
|
|
3
|
+
import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js';
|
|
4
|
+
import { printBinaryOperation } from '../slang-printers/print-binary-operation.js';
|
|
3
5
|
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
|
|
4
6
|
import { Expression } from './Expression.js';
|
|
5
7
|
|
|
@@ -8,6 +10,15 @@ import type { AstPath, Doc, ParserOptions } from 'prettier';
|
|
|
8
10
|
import type { AstNode } from './types.d.ts';
|
|
9
11
|
import type { PrintFunction, SlangNode } from '../types.d.ts';
|
|
10
12
|
|
|
13
|
+
const tryToHug = createHugFunction(['==', '!=']);
|
|
14
|
+
|
|
15
|
+
const printEqualityExpression = printBinaryOperation(
|
|
16
|
+
createKindCheckFunction([
|
|
17
|
+
NonterminalKind.AndExpression,
|
|
18
|
+
NonterminalKind.OrExpression
|
|
19
|
+
])
|
|
20
|
+
);
|
|
21
|
+
|
|
11
22
|
export class EqualityExpression implements SlangNode {
|
|
12
23
|
readonly kind = NonterminalKind.EqualityExpression;
|
|
13
24
|
|
|
@@ -32,6 +43,8 @@ export class EqualityExpression implements SlangNode {
|
|
|
32
43
|
|
|
33
44
|
this.comments = metadata.comments;
|
|
34
45
|
this.loc = metadata.loc;
|
|
46
|
+
|
|
47
|
+
this.leftOperand = tryToHug(this.leftOperand);
|
|
35
48
|
}
|
|
36
49
|
|
|
37
50
|
print(
|
|
@@ -39,6 +52,6 @@ export class EqualityExpression implements SlangNode {
|
|
|
39
52
|
print: PrintFunction,
|
|
40
53
|
options: ParserOptions<AstNode>
|
|
41
54
|
): Doc {
|
|
42
|
-
return
|
|
55
|
+
return printEqualityExpression(this, path, print, options);
|
|
43
56
|
}
|
|
44
57
|
}
|