prettier-plugin-solidity 2.0.0-beta.8 → 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 +63 -59
- 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 +9 -5
- 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 +5 -7
- 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/ContractDefinition.js +30 -10
- package/dist/nodes/ContractDefinition.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 +2 -2
- 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 +20 -10
- package/dist/slang-comments/handlers/handle-contract-definition-comments.js.map +1 -1
- package/dist/slang-comments/handlers/handle-contract-specifiers-comments.js +22 -0
- package/dist/slang-comments/handlers/handle-contract-specifiers-comments.js.map +1 -0
- 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-storage-layout-specifier-comments.js +14 -0
- package/dist/slang-comments/handlers/handle-storage-layout-specifier-comments.js.map +1 -0
- 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 +6 -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 +17 -22
- package/dist/slang-nodes/ConditionalExpression.js.map +1 -1
- package/dist/slang-nodes/ContractDefinition.js +9 -10
- package/dist/slang-nodes/ContractDefinition.js.map +1 -1
- package/dist/slang-nodes/ContractSpecifier.js +27 -0
- package/dist/slang-nodes/ContractSpecifier.js.map +1 -0
- package/dist/slang-nodes/ContractSpecifiers.js +31 -0
- package/dist/slang-nodes/ContractSpecifiers.js.map +1 -0
- 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 +7 -7
- 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 +11 -11
- 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 +6 -6
- 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 +3 -9
- package/dist/slang-nodes/StateVariableDefinition.js.map +1 -1
- package/dist/slang-nodes/StateVariableDefinitionValue.js +1 -2
- package/dist/slang-nodes/StateVariableDefinitionValue.js.map +1 -1
- package/dist/slang-nodes/StorageLayoutSpecifier.js +25 -0
- package/dist/slang-nodes/StorageLayoutSpecifier.js.map +1 -0
- package/dist/slang-nodes/TupleDeconstructionStatement.js +3 -5
- 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 +12 -12
- 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 +12 -0
- package/dist/slang-utils/sort-contract-specifiers.js.map +1 -0
- 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 +10 -18
- 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 +23 -20
- 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 +18 -6
- package/src/comments/handlers/handleModifierInvocationComments.js +7 -4
- package/src/common/printer-helpers.js +4 -15
- package/src/index.ts +6 -8
- package/src/nodes/Conditional.js +2 -2
- package/src/nodes/ContractDefinition.js +31 -11
- 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 +2 -5
- 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 +23 -15
- package/src/slang-comments/handlers/handle-contract-specifiers-comments.ts +33 -0
- 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-storage-layout-specifier-comments.ts +23 -0
- 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 +6 -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 +14 -20
- package/src/slang-nodes/ContractDefinition.ts +10 -11
- package/src/slang-nodes/ContractSpecifier.ts +48 -0
- package/src/slang-nodes/ContractSpecifiers.ts +52 -0
- 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 +7 -7
- 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 +11 -12
- 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 +5 -6
- package/src/slang-nodes/ShiftExpression.ts +14 -1
- package/src/slang-nodes/StateVariableDefinition.ts +3 -10
- package/src/slang-nodes/StateVariableDefinitionValue.ts +1 -2
- package/src/slang-nodes/StorageLayoutSpecifier.ts +45 -0
- package/src/slang-nodes/StringLiteral.ts +1 -1
- package/src/slang-nodes/TupleDeconstructionStatement.ts +6 -9
- package/src/slang-nodes/UnnamedFunctionDefinition.ts +3 -3
- package/src/slang-nodes/VariableDeclarationStatement.ts +15 -16
- package/src/slang-nodes/types.d.ts +15 -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 +22 -0
- package/src/slang-utils/sort-function-attributes.ts +2 -5
- package/src/slangPrinter.ts +12 -23
- package/src/slangSolidityParser.ts +9 -12
- package/src/types.d.ts +7 -219
- package/dist/78244c53725e2131398e.wasm +0 -0
- 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/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/dist/slang-utils/prettier-version-satisfies.js +0 -6
- package/dist/slang-utils/prettier-version-satisfies.js.map +0 -1
- package/dist/slang-utils/print-warning.js +0 -12
- package/dist/slang-utils/print-warning.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
- package/src/slang-utils/prettier-version-satisfies.ts +0 -8
- package/src/slang-utils/print-warning.ts +0 -12
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { util } from "prettier";
|
|
2
|
-
import { getNextNonSpaceNonCommentCharacter } from "../../common/backward-compatibility.js";
|
|
3
2
|
|
|
4
3
|
const {
|
|
5
4
|
addLeadingComment,
|
|
6
5
|
addTrailingComment,
|
|
7
6
|
addDanglingComment,
|
|
8
7
|
hasNewline,
|
|
9
|
-
hasNewlineInRange
|
|
8
|
+
hasNewlineInRange,
|
|
9
|
+
getNextNonSpaceNonCommentCharacter,
|
|
10
|
+
getNextNonSpaceNonCommentCharacterIndex
|
|
10
11
|
} = util
|
|
11
12
|
|
|
12
13
|
export function handleOwnLineComment(comment, text, options, ast, isLastComment) {
|
|
@@ -242,8 +243,7 @@ function handleIfStatementComments(
|
|
|
242
243
|
// it is a ).
|
|
243
244
|
const nextCharacter = getNextNonSpaceNonCommentCharacter(
|
|
244
245
|
text,
|
|
245
|
-
comment
|
|
246
|
-
options.locEnd
|
|
246
|
+
options.locEnd(comment)
|
|
247
247
|
);
|
|
248
248
|
if (nextCharacter === ")") {
|
|
249
249
|
addTrailingComment(precedingNode, comment);
|
|
@@ -311,8 +311,7 @@ function handleWhileComments(
|
|
|
311
311
|
// it is a ).
|
|
312
312
|
const nextCharacter = getNextNonSpaceNonCommentCharacter(
|
|
313
313
|
text,
|
|
314
|
-
comment
|
|
315
|
-
options.locEnd
|
|
314
|
+
options.locEnd(comment)
|
|
316
315
|
);
|
|
317
316
|
if (nextCharacter === ")") {
|
|
318
317
|
addTrailingComment(precedingNode, comment);
|
|
@@ -470,8 +469,7 @@ function handleMethodNameComments(
|
|
|
470
469
|
// comment should be attached to value instead of key
|
|
471
470
|
getNextNonSpaceNonCommentCharacter(
|
|
472
471
|
text,
|
|
473
|
-
precedingNode
|
|
474
|
-
options.locEnd
|
|
472
|
+
options.locEnd(precedingNode)
|
|
475
473
|
) !== ":"
|
|
476
474
|
) {
|
|
477
475
|
addTrailingComment(precedingNode, comment);
|
|
@@ -507,8 +505,7 @@ function handleFunctionNameComments(
|
|
|
507
505
|
if (
|
|
508
506
|
getNextNonSpaceNonCommentCharacter(
|
|
509
507
|
text,
|
|
510
|
-
comment
|
|
511
|
-
options.locEnd
|
|
508
|
+
options.locEnd(comment)
|
|
512
509
|
) !== "("
|
|
513
510
|
) {
|
|
514
511
|
return false;
|
|
@@ -536,8 +533,7 @@ function handleCommentAfterArrowParams(text, enclosingNode, comment, options) {
|
|
|
536
533
|
|
|
537
534
|
const index = getNextNonSpaceNonCommentCharacterIndex(
|
|
538
535
|
text,
|
|
539
|
-
comment
|
|
540
|
-
options
|
|
536
|
+
options.locEnd(comment)
|
|
541
537
|
);
|
|
542
538
|
if (text.substr(index, 2) === "=>") {
|
|
543
539
|
addDanglingComment(enclosingNode, comment);
|
|
@@ -551,8 +547,7 @@ function handleCommentInEmptyParens(text, enclosingNode, comment, options) {
|
|
|
551
547
|
if (
|
|
552
548
|
getNextNonSpaceNonCommentCharacter(
|
|
553
549
|
text,
|
|
554
|
-
comment
|
|
555
|
-
options.locEnd
|
|
550
|
+
options.locEnd(comment)
|
|
556
551
|
) !== ")"
|
|
557
552
|
) {
|
|
558
553
|
return false;
|
|
@@ -622,8 +617,7 @@ function handleLastFunctionArgComments(
|
|
|
622
617
|
enclosingNode.type === "ClassMethod") &&
|
|
623
618
|
getNextNonSpaceNonCommentCharacter(
|
|
624
619
|
text,
|
|
625
|
-
comment
|
|
626
|
-
options.locEnd
|
|
620
|
+
options.locEnd(comment)
|
|
627
621
|
) === ")"
|
|
628
622
|
) {
|
|
629
623
|
addTrailingComment(precedingNode, comment);
|
package/src/printer.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import * as nodes from './nodes/index.js';
|
|
2
2
|
import { printWarning } from './common/print-warning.js';
|
|
3
|
-
import {
|
|
4
|
-
hasNodeIgnoreComment,
|
|
5
|
-
prettierVersionSatisfies
|
|
6
|
-
} from './common/util.js';
|
|
3
|
+
import { hasNodeIgnoreComment } from './common/util.js';
|
|
7
4
|
import ignoreComments from './comments/ignore.js';
|
|
8
5
|
|
|
9
6
|
function once(factory) {
|
|
@@ -18,7 +15,7 @@ function once(factory) {
|
|
|
18
15
|
|
|
19
16
|
const warnDeprecation = once(() => {
|
|
20
17
|
printWarning(
|
|
21
|
-
`'
|
|
18
|
+
`The 'antlr' parser has been deprecated, please use 'slang' instead.`
|
|
22
19
|
);
|
|
23
20
|
return true;
|
|
24
21
|
});
|
|
@@ -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
|
|
|
@@ -23,10 +23,10 @@ export default function handleContractDefinitionComments({
|
|
|
23
23
|
locEnd(comment)
|
|
24
24
|
);
|
|
25
25
|
|
|
26
|
-
// Everything before the
|
|
26
|
+
// Everything before the ContractSpecifiers is pushed onto the beginning of
|
|
27
27
|
// the ContractDefinition.
|
|
28
28
|
if (
|
|
29
|
-
followingNode?.kind === NonterminalKind.
|
|
29
|
+
followingNode?.kind === NonterminalKind.ContractSpecifiers ||
|
|
30
30
|
(followingNode?.kind === NonterminalKind.ContractMembers &&
|
|
31
31
|
nextCharacter !== '{')
|
|
32
32
|
) {
|
|
@@ -36,23 +36,31 @@ 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
|
|
|
43
43
|
// The last comments before the body.
|
|
44
44
|
if (nextCharacter === '{') {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
)
|
|
55
|
-
|
|
45
|
+
if (precedingNode?.kind === NonterminalKind.ContractSpecifiers) {
|
|
46
|
+
if (precedingNode.items.length === 0) {
|
|
47
|
+
addTrailingComment(precedingNode, comment);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
const lastContractSpecifier =
|
|
51
|
+
precedingNode.items[precedingNode.items.length - 1].variant;
|
|
52
|
+
// If the last ContractSpecifier's an InheritanceSpecifier, the comment
|
|
53
|
+
// is appended to the last InheritanceType.
|
|
54
|
+
if (lastContractSpecifier.kind === NonterminalKind.InheritanceSpecifier) {
|
|
55
|
+
addCollectionLastComment(lastContractSpecifier.types, comment);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
if (
|
|
59
|
+
lastContractSpecifier.kind === NonterminalKind.StorageLayoutSpecifier
|
|
60
|
+
) {
|
|
61
|
+
addTrailingComment(lastContractSpecifier.expression, comment);
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
56
64
|
}
|
|
57
65
|
}
|
|
58
66
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
2
|
+
import { util } from 'prettier';
|
|
3
|
+
import addCollectionLastComment from './add-collection-last-comment.js';
|
|
4
|
+
|
|
5
|
+
import type { HandlerParams } from './types.d.ts';
|
|
6
|
+
|
|
7
|
+
const { addTrailingComment } = util;
|
|
8
|
+
|
|
9
|
+
export default function handleContractSpecifiersComments({
|
|
10
|
+
precedingNode,
|
|
11
|
+
enclosingNode,
|
|
12
|
+
comment
|
|
13
|
+
}: HandlerParams): boolean {
|
|
14
|
+
if (enclosingNode?.kind !== NonterminalKind.ContractSpecifiers) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (
|
|
19
|
+
precedingNode &&
|
|
20
|
+
precedingNode.kind === NonterminalKind.ContractSpecifier
|
|
21
|
+
) {
|
|
22
|
+
if (precedingNode.variant.kind === NonterminalKind.InheritanceSpecifier) {
|
|
23
|
+
addCollectionLastComment(precedingNode.variant.types, comment);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
if (precedingNode.variant.kind === NonterminalKind.StorageLayoutSpecifier) {
|
|
27
|
+
addTrailingComment(precedingNode.variant.expression, comment);
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
@@ -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,23 @@
|
|
|
1
|
+
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
2
|
+
import { util } from 'prettier';
|
|
3
|
+
|
|
4
|
+
import type { HandlerParams } from './types.d.ts';
|
|
5
|
+
|
|
6
|
+
const { addLeadingComment } = util;
|
|
7
|
+
|
|
8
|
+
export default function handleStorageLayoutSpecifierComments({
|
|
9
|
+
enclosingNode,
|
|
10
|
+
followingNode,
|
|
11
|
+
comment
|
|
12
|
+
}: HandlerParams): boolean {
|
|
13
|
+
if (enclosingNode?.kind !== NonterminalKind.StorageLayoutSpecifier) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (followingNode?.kind === NonterminalKind.Expression) {
|
|
18
|
+
addLeadingComment(followingNode, comment);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
@@ -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
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import handleBlockComments from './handle-block-comments.js';
|
|
2
2
|
import handleContractDefinitionComments from './handle-contract-definition-comments.js';
|
|
3
|
+
import handleContractSpecifiersComments from './handle-contract-specifiers-comments.js';
|
|
3
4
|
import handleElseBranchComments from './handle-else-branch-comments.js';
|
|
4
5
|
import handleIfStatementComments from './handle-if-statement-comments.js';
|
|
5
6
|
import handleInterfaceDefinitionComments from './handle-interface-definition-comments.js';
|
|
@@ -7,12 +8,15 @@ import handleLibraryDefinitionComments from './handle-library-definition-comment
|
|
|
7
8
|
import handleModifierInvocationComments from './handle-modifier-invocation-comments.js';
|
|
8
9
|
import handleParametersDeclarationComments from './handle-parameters-declaration-comments.js';
|
|
9
10
|
import handlePositionalArgumentsDeclarationComments from './handle-positional-arguments-declaration-comments.js';
|
|
11
|
+
import handleStorageLayoutSpecifierComments from './handle-storage-layout-specifier-comments.js';
|
|
12
|
+
import handleStructComments from './handle-struct-comments.js';
|
|
10
13
|
import handleWhileStatementComments from './handle-while-statement-comments.js';
|
|
11
14
|
import handleYulBlockComments from './handle-yul-block-comments.js';
|
|
12
15
|
|
|
13
16
|
export default [
|
|
14
17
|
handleBlockComments,
|
|
15
18
|
handleContractDefinitionComments,
|
|
19
|
+
handleContractSpecifiersComments,
|
|
16
20
|
handleElseBranchComments,
|
|
17
21
|
handleIfStatementComments,
|
|
18
22
|
handleInterfaceDefinitionComments,
|
|
@@ -20,6 +24,8 @@ export default [
|
|
|
20
24
|
handleModifierInvocationComments,
|
|
21
25
|
handleParametersDeclarationComments,
|
|
22
26
|
handlePositionalArgumentsDeclarationComments,
|
|
27
|
+
handleStorageLayoutSpecifierComments,
|
|
28
|
+
handleStructComments,
|
|
23
29
|
handleWhileStatementComments,
|
|
24
30
|
handleYulBlockComments
|
|
25
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
|
}
|