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,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
|
|
|
@@ -13,6 +14,20 @@ const multiplicationTryToHug = createHugFunction(['/', '%']);
|
|
|
13
14
|
const divisionTryToHug = createHugFunction(['*', '%']);
|
|
14
15
|
const moduloTryToHug = createHugFunction(['*', '/', '%']);
|
|
15
16
|
|
|
17
|
+
export const printMultiplicativeExpression = printBinaryOperation(
|
|
18
|
+
createKindCheckFunction([
|
|
19
|
+
NonterminalKind.AdditiveExpression,
|
|
20
|
+
NonterminalKind.ShiftExpression,
|
|
21
|
+
NonterminalKind.BitwiseAndExpression,
|
|
22
|
+
NonterminalKind.BitwiseOrExpression,
|
|
23
|
+
NonterminalKind.BitwiseXorExpression,
|
|
24
|
+
NonterminalKind.InequalityExpression,
|
|
25
|
+
NonterminalKind.EqualityExpression,
|
|
26
|
+
NonterminalKind.AndExpression,
|
|
27
|
+
NonterminalKind.OrExpression
|
|
28
|
+
])
|
|
29
|
+
);
|
|
30
|
+
|
|
16
31
|
export class MultiplicativeExpression implements SlangNode {
|
|
17
32
|
readonly kind = NonterminalKind.MultiplicativeExpression;
|
|
18
33
|
|
|
@@ -61,6 +76,6 @@ export class MultiplicativeExpression implements SlangNode {
|
|
|
61
76
|
print: PrintFunction,
|
|
62
77
|
options: ParserOptions<AstNode>
|
|
63
78
|
): Doc {
|
|
64
|
-
return
|
|
79
|
+
return printMultiplicativeExpression(this, path, print, options);
|
|
65
80
|
}
|
|
66
81
|
}
|
|
@@ -17,9 +17,9 @@ export class PositionalArguments implements SlangNode {
|
|
|
17
17
|
|
|
18
18
|
loc;
|
|
19
19
|
|
|
20
|
-
items;
|
|
20
|
+
items: Expression[];
|
|
21
21
|
|
|
22
|
-
separators;
|
|
22
|
+
separators: string[];
|
|
23
23
|
|
|
24
24
|
constructor(ast: ast.PositionalArguments, options: ParserOptions<AstNode>) {
|
|
25
25
|
let metadata = getNodeMetadata(ast, true);
|
|
@@ -46,12 +46,12 @@ export class ReceiveFunctionDefinition implements SlangNode {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
cleanModifierInvocationArguments(): void {
|
|
49
|
-
for (const attribute of this.attributes.items) {
|
|
49
|
+
for (const { variant: attribute } of this.attributes.items) {
|
|
50
50
|
if (
|
|
51
|
-
typeof attribute
|
|
52
|
-
attribute.
|
|
51
|
+
typeof attribute !== 'string' &&
|
|
52
|
+
attribute.kind === NonterminalKind.ModifierInvocation
|
|
53
53
|
) {
|
|
54
|
-
attribute.
|
|
54
|
+
attribute.cleanModifierInvocationArguments();
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -16,12 +16,11 @@ function printExpression(
|
|
|
16
16
|
print: PrintFunction,
|
|
17
17
|
options: ParserOptions<AstNode>
|
|
18
18
|
): Doc {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
NonterminalKind.ConditionalExpression))
|
|
19
|
+
const expressionVariant = node.expression?.variant;
|
|
20
|
+
if (expressionVariant) {
|
|
21
|
+
return expressionVariant.kind === NonterminalKind.TupleExpression ||
|
|
22
|
+
(options.experimentalTernaries &&
|
|
23
|
+
expressionVariant.kind === NonterminalKind.ConditionalExpression)
|
|
25
24
|
? [' ', path.call(print, 'expression')]
|
|
26
25
|
: group(indent([line, path.call(print, 'expression')]));
|
|
27
26
|
}
|
|
@@ -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
|
|
|
@@ -20,6 +21,18 @@ const tryToHugLeftOperand = createHugFunction([
|
|
|
20
21
|
]);
|
|
21
22
|
const tryToHugRightOperand = createHugFunction(['+', '-', '*', '/', '**']);
|
|
22
23
|
|
|
24
|
+
const printShiftExpression = printBinaryOperation(
|
|
25
|
+
createKindCheckFunction([
|
|
26
|
+
NonterminalKind.BitwiseAndExpression,
|
|
27
|
+
NonterminalKind.BitwiseOrExpression,
|
|
28
|
+
NonterminalKind.BitwiseXorExpression,
|
|
29
|
+
NonterminalKind.InequalityExpression,
|
|
30
|
+
NonterminalKind.EqualityExpression,
|
|
31
|
+
NonterminalKind.AndExpression,
|
|
32
|
+
NonterminalKind.OrExpression
|
|
33
|
+
])
|
|
34
|
+
);
|
|
35
|
+
|
|
23
36
|
export class ShiftExpression implements SlangNode {
|
|
24
37
|
readonly kind = NonterminalKind.ShiftExpression;
|
|
25
38
|
|
|
@@ -54,6 +67,6 @@ export class ShiftExpression implements SlangNode {
|
|
|
54
67
|
print: PrintFunction,
|
|
55
68
|
options: ParserOptions<AstNode>
|
|
56
69
|
): Doc {
|
|
57
|
-
return
|
|
70
|
+
return printShiftExpression(this, path, print, options);
|
|
58
71
|
}
|
|
59
72
|
}
|
|
@@ -52,20 +52,13 @@ export class StateVariableDefinition implements SlangNode {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
print(path: AstPath<StateVariableDefinition>, print: PrintFunction): Doc {
|
|
55
|
-
const
|
|
56
|
-
id: Symbol('Slang.StateVariableDefinition.attributes')
|
|
57
|
-
});
|
|
58
|
-
|
|
55
|
+
const groupId = Symbol('Slang.StateVariableDefinition.attributes');
|
|
59
56
|
return [
|
|
60
57
|
path.call(print, 'typeName'),
|
|
61
|
-
|
|
58
|
+
group(indent(path.call(print, 'attributes')), { id: groupId }),
|
|
62
59
|
' ',
|
|
63
60
|
path.call(print, 'name'),
|
|
64
|
-
this.value
|
|
65
|
-
? indentIfBreak(path.call(print, 'value'), {
|
|
66
|
-
groupId: attributesDoc.id!
|
|
67
|
-
})
|
|
68
|
-
: '',
|
|
61
|
+
this.value ? indentIfBreak(path.call(print, 'value'), { groupId }) : '',
|
|
69
62
|
';'
|
|
70
63
|
];
|
|
71
64
|
}
|
|
@@ -37,8 +37,7 @@ export class StateVariableDefinitionValue implements SlangNode {
|
|
|
37
37
|
path: AstPath<StateVariableDefinitionValue>,
|
|
38
38
|
print: PrintFunction
|
|
39
39
|
): Doc {
|
|
40
|
-
return
|
|
41
|
-
this.value.variant.kind === NonterminalKind.ArrayExpression
|
|
40
|
+
return this.value.variant.kind === NonterminalKind.ArrayExpression
|
|
42
41
|
? [' = ', path.call(print, 'value')]
|
|
43
42
|
: group([' =', indent([line, path.call(print, 'value')])]);
|
|
44
43
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
3
|
+
import { printSeparatedItem } from '../slang-printers/print-separated-item.js';
|
|
4
|
+
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
|
|
5
|
+
import { Expression } from './Expression.js';
|
|
6
|
+
|
|
7
|
+
import type * as ast from '@nomicfoundation/slang/ast';
|
|
8
|
+
import type { AstPath, Doc, ParserOptions } from 'prettier';
|
|
9
|
+
import type { AstNode } from './types.d.ts';
|
|
10
|
+
import type { PrintFunction, SlangNode } from '../types.d.ts';
|
|
11
|
+
|
|
12
|
+
const { line } = doc.builders;
|
|
13
|
+
|
|
14
|
+
export class StorageLayoutSpecifier implements SlangNode {
|
|
15
|
+
readonly kind = NonterminalKind.StorageLayoutSpecifier;
|
|
16
|
+
|
|
17
|
+
comments;
|
|
18
|
+
|
|
19
|
+
loc;
|
|
20
|
+
|
|
21
|
+
expression: Expression;
|
|
22
|
+
|
|
23
|
+
constructor(
|
|
24
|
+
ast: ast.StorageLayoutSpecifier,
|
|
25
|
+
options: ParserOptions<AstNode>
|
|
26
|
+
) {
|
|
27
|
+
let metadata = getNodeMetadata(ast);
|
|
28
|
+
|
|
29
|
+
this.expression = new Expression(ast.expression, options);
|
|
30
|
+
|
|
31
|
+
metadata = updateMetadata(metadata, [this.expression]);
|
|
32
|
+
|
|
33
|
+
this.comments = metadata.comments;
|
|
34
|
+
this.loc = metadata.loc;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
print(path: AstPath<StorageLayoutSpecifier>, print: PrintFunction): Doc {
|
|
38
|
+
return [
|
|
39
|
+
'layout at',
|
|
40
|
+
printSeparatedItem(path.call(print, 'expression'), {
|
|
41
|
+
firstSeparator: line
|
|
42
|
+
})
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -44,16 +44,13 @@ export class TupleDeconstructionStatement implements SlangNode {
|
|
|
44
44
|
path: AstPath<TupleDeconstructionStatement>,
|
|
45
45
|
print: PrintFunction
|
|
46
46
|
): Doc {
|
|
47
|
-
const
|
|
48
|
-
[this.varKeyword ? 'var (' : '(', path.call(print, 'elements'), ')'],
|
|
49
|
-
{ id: Symbol('Slang.VariableDeclarationStatement.variables') }
|
|
50
|
-
);
|
|
51
|
-
|
|
47
|
+
const groupId = Symbol('Slang.VariableDeclarationStatement.variables');
|
|
52
48
|
return [
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
group(
|
|
50
|
+
[this.varKeyword ? 'var (' : '(', path.call(print, 'elements'), ')'],
|
|
51
|
+
{ id: groupId }
|
|
52
|
+
),
|
|
53
|
+
indentIfBreak([' = ', path.call(print, 'expression'), ';'], { groupId })
|
|
57
54
|
];
|
|
58
55
|
}
|
|
59
56
|
}
|
|
@@ -46,9 +46,9 @@ export class UnnamedFunctionDefinition implements SlangNode {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
cleanModifierInvocationArguments(): void {
|
|
49
|
-
for (const attribute of this.attributes.items) {
|
|
50
|
-
if (typeof attribute
|
|
51
|
-
attribute.
|
|
49
|
+
for (const { variant: attribute } of this.attributes.items) {
|
|
50
|
+
if (typeof attribute !== 'string') {
|
|
51
|
+
attribute.cleanModifierInvocationArguments();
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -57,23 +57,22 @@ export class VariableDeclarationStatement implements SlangNode {
|
|
|
57
57
|
path: AstPath<VariableDeclarationStatement>,
|
|
58
58
|
print: PrintFunction
|
|
59
59
|
): Doc {
|
|
60
|
-
const
|
|
61
|
-
[
|
|
62
|
-
path.call(print, 'variableType'),
|
|
63
|
-
indent([
|
|
64
|
-
this.storageLocation
|
|
65
|
-
? [line, path.call(print, 'storageLocation')]
|
|
66
|
-
: '',
|
|
67
|
-
' ',
|
|
68
|
-
path.call(print, 'name')
|
|
69
|
-
])
|
|
70
|
-
],
|
|
71
|
-
{ id: Symbol('Slang.VariableDeclarationStatement.variables') }
|
|
72
|
-
);
|
|
73
|
-
|
|
60
|
+
const groupId = Symbol('Slang.VariableDeclarationStatement.variables');
|
|
74
61
|
return [
|
|
75
|
-
|
|
76
|
-
|
|
62
|
+
group(
|
|
63
|
+
[
|
|
64
|
+
path.call(print, 'variableType'),
|
|
65
|
+
indent([
|
|
66
|
+
this.storageLocation
|
|
67
|
+
? [line, path.call(print, 'storageLocation')]
|
|
68
|
+
: '',
|
|
69
|
+
' ',
|
|
70
|
+
path.call(print, 'name')
|
|
71
|
+
])
|
|
72
|
+
],
|
|
73
|
+
{ id: groupId }
|
|
74
|
+
),
|
|
75
|
+
indentIfBreak(path.call(print, 'value'), { groupId }),
|
|
77
76
|
';'
|
|
78
77
|
];
|
|
79
78
|
}
|
|
@@ -29,6 +29,8 @@ import type { ContinueStatement } from './ContinueStatement.ts';
|
|
|
29
29
|
import type { ContractDefinition } from './ContractDefinition.ts';
|
|
30
30
|
import type { ContractMember } from './ContractMember.ts';
|
|
31
31
|
import type { ContractMembers } from './ContractMembers.ts';
|
|
32
|
+
import type { ContractSpecifier } from './ContractSpecifier.ts';
|
|
33
|
+
import type { ContractSpecifiers } from './ContractSpecifiers.ts';
|
|
32
34
|
import type { DecimalNumberExpression } from './DecimalNumberExpression.ts';
|
|
33
35
|
import type { DoWhileStatement } from './DoWhileStatement.ts';
|
|
34
36
|
import type { ElementaryType } from './ElementaryType.ts';
|
|
@@ -139,6 +141,7 @@ import type { StateVariableAttribute } from './StateVariableAttribute.ts';
|
|
|
139
141
|
import type { StateVariableAttributes } from './StateVariableAttributes.ts';
|
|
140
142
|
import type { StateVariableDefinition } from './StateVariableDefinition.ts';
|
|
141
143
|
import type { StateVariableDefinitionValue } from './StateVariableDefinitionValue.ts';
|
|
144
|
+
import type { StorageLayoutSpecifier } from './StorageLayoutSpecifier.ts';
|
|
142
145
|
import type { StorageLocation } from './StorageLocation.ts';
|
|
143
146
|
import type { StringExpression } from './StringExpression.ts';
|
|
144
147
|
import type { StringLiteral } from './StringLiteral.ts';
|
|
@@ -257,6 +260,7 @@ export type StrictAstNode =
|
|
|
257
260
|
| ContractDefinition
|
|
258
261
|
| InheritanceSpecifier
|
|
259
262
|
| InheritanceType
|
|
263
|
+
| StorageLayoutSpecifier
|
|
260
264
|
| InterfaceDefinition
|
|
261
265
|
| LibraryDefinition
|
|
262
266
|
| StructDefinition
|
|
@@ -411,6 +415,8 @@ export type StrictAstNode =
|
|
|
411
415
|
| YulLiteral
|
|
412
416
|
| SourceUnitMembers
|
|
413
417
|
| VersionExpressionSet
|
|
418
|
+
| ContractSpecifier
|
|
419
|
+
| ContractSpecifiers
|
|
414
420
|
| ContractMembers
|
|
415
421
|
| InterfaceMembers
|
|
416
422
|
| LibraryMembers
|
|
@@ -454,7 +460,15 @@ export type StrictAstNode =
|
|
|
454
460
|
| YulPaths
|
|
455
461
|
| YulPath;
|
|
456
462
|
|
|
457
|
-
export type
|
|
463
|
+
export type NodeCollection = Extract<
|
|
464
|
+
StrictAstNode,
|
|
465
|
+
{ items: StrictAstNode[] | Identifier[] | YulIdentifier[] }
|
|
466
|
+
>;
|
|
467
|
+
|
|
468
|
+
export type Collection = Extract<
|
|
469
|
+
StrictAstNode,
|
|
470
|
+
{ items: StrictAstNode[] | Identifier[] | YulIdentifier[] | string[] }
|
|
471
|
+
>;
|
|
458
472
|
|
|
459
473
|
export type BinaryOperation = Extract<
|
|
460
474
|
StrictAstNode,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TerminalKind } from '@nomicfoundation/slang/cst';
|
|
1
|
+
import { NonterminalKind, TerminalKind } from '@nomicfoundation/slang/cst';
|
|
2
2
|
import { doc } from 'prettier';
|
|
3
3
|
import { isBinaryOperation } from '../slang-utils/is-binary-operation.js';
|
|
4
4
|
|
|
@@ -15,17 +15,23 @@ const { group, line } = doc.builders;
|
|
|
15
15
|
function rightOperandPrint(
|
|
16
16
|
node: BinaryOperation,
|
|
17
17
|
path: AstPath<BinaryOperation>,
|
|
18
|
-
print: PrintFunction
|
|
18
|
+
print: PrintFunction,
|
|
19
|
+
options: ParserOptions<AstNode>
|
|
19
20
|
): Doc {
|
|
20
|
-
const rightOperand =
|
|
21
|
+
const rightOperand =
|
|
22
|
+
options.experimentalOperatorPosition === 'end'
|
|
23
|
+
? [` ${node.operator}`, line, path.call(print, 'rightOperand')]
|
|
24
|
+
: [line, `${node.operator} `, path.call(print, 'rightOperand')];
|
|
21
25
|
|
|
22
|
-
// If
|
|
23
|
-
//
|
|
26
|
+
// If there's only a single binary expression, we want to create a group in
|
|
27
|
+
// order to avoid having a small right part like -1 be on its own line.
|
|
28
|
+
const leftOperand = node.leftOperand.variant;
|
|
29
|
+
const grandparentNode = path.grandparent as StrictAstNode;
|
|
24
30
|
const shouldGroup =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
(leftOperand.kind === TerminalKind.Identifier ||
|
|
32
|
+
!isBinaryOperation(leftOperand)) &&
|
|
33
|
+
(!isBinaryOperation(grandparentNode) ||
|
|
34
|
+
grandparentNode.kind === NonterminalKind.AssignmentExpression);
|
|
29
35
|
|
|
30
36
|
return shouldGroup ? group(rightOperand) : rightOperand;
|
|
31
37
|
}
|
|
@@ -51,7 +57,6 @@ export const createBinaryOperationPrinter =
|
|
|
51
57
|
|
|
52
58
|
return groupRules([
|
|
53
59
|
path.call(print, 'leftOperand'),
|
|
54
|
-
|
|
55
|
-
indentRules(rightOperandPrint(node, path, print))
|
|
60
|
+
indentRules(rightOperandPrint(node, path, print, options))
|
|
56
61
|
]);
|
|
57
62
|
};
|
|
@@ -2,59 +2,68 @@ import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
|
2
2
|
import { doc } from 'prettier';
|
|
3
3
|
import { createBinaryOperationPrinter } from './create-binary-operation-printer.js';
|
|
4
4
|
import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js';
|
|
5
|
+
import { isBinaryOperation } from '../slang-utils/is-binary-operation.js';
|
|
5
6
|
|
|
6
|
-
import type { AstPath, Doc } from 'prettier';
|
|
7
|
-
import type {
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
import type { AstPath, Doc, ParserOptions } from 'prettier';
|
|
8
|
+
import type {
|
|
9
|
+
AstNode,
|
|
10
|
+
BinaryOperation,
|
|
11
|
+
StrictAstNode
|
|
12
|
+
} from '../slang-nodes/types.d.ts';
|
|
13
|
+
import type { PrintFunction } from '../types.d.ts';
|
|
10
14
|
|
|
11
15
|
const { group, indent } = doc.builders;
|
|
12
16
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
NonterminalKind.MultiplicativeExpression,
|
|
16
|
-
NonterminalKind.ExponentiationExpression,
|
|
17
|
-
NonterminalKind.AssignmentExpression,
|
|
18
|
-
NonterminalKind.BitwiseAndExpression,
|
|
19
|
-
NonterminalKind.BitwiseOrExpression,
|
|
20
|
-
NonterminalKind.BitwiseXorExpression,
|
|
21
|
-
NonterminalKind.AndExpression,
|
|
22
|
-
NonterminalKind.OrExpression,
|
|
23
|
-
NonterminalKind.ShiftExpression
|
|
24
|
-
]) as (
|
|
25
|
-
node: StrictAstNode
|
|
26
|
-
) => node is Exclude<
|
|
27
|
-
BinaryOperation,
|
|
28
|
-
EqualityExpression | InequalityExpression
|
|
29
|
-
>;
|
|
30
|
-
|
|
31
|
-
const binaryGroupRulesBuilder =
|
|
17
|
+
export const binaryGroupRulesBuilder =
|
|
18
|
+
(shouldGroup: (node: BinaryOperation) => boolean) =>
|
|
32
19
|
(path: AstPath<BinaryOperation>) =>
|
|
33
20
|
(document: Doc): Doc => {
|
|
34
|
-
const grandparentNode = path.
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return group(document);
|
|
21
|
+
const grandparentNode = path.grandparent as StrictAstNode;
|
|
22
|
+
if (!isBinaryOperation(grandparentNode)) return group(document);
|
|
23
|
+
if (shouldGroup(grandparentNode)) return group(document);
|
|
24
|
+
return document;
|
|
39
25
|
};
|
|
40
26
|
|
|
41
|
-
const
|
|
27
|
+
const isStatementWithoutIndentedOperation = createKindCheckFunction([
|
|
28
|
+
NonterminalKind.ReturnStatement,
|
|
29
|
+
NonterminalKind.IfStatement,
|
|
30
|
+
NonterminalKind.WhileStatement
|
|
31
|
+
]);
|
|
32
|
+
|
|
33
|
+
export const shouldNotIndent = (
|
|
34
|
+
node: StrictAstNode,
|
|
35
|
+
path: AstPath<BinaryOperation>,
|
|
36
|
+
index: number
|
|
37
|
+
): boolean =>
|
|
38
|
+
isStatementWithoutIndentedOperation(node) ||
|
|
39
|
+
(node.kind === NonterminalKind.ExpressionStatement &&
|
|
40
|
+
(path.getNode(index + 1) as StrictAstNode).kind ===
|
|
41
|
+
NonterminalKind.ForStatementCondition);
|
|
42
|
+
|
|
43
|
+
export const binaryIndentRulesBuilder =
|
|
44
|
+
(shouldIndent: (node: BinaryOperation) => boolean) =>
|
|
42
45
|
(path: AstPath<BinaryOperation>) =>
|
|
43
46
|
(document: Doc): Doc => {
|
|
44
|
-
let node = path.
|
|
45
|
-
for (let i = 2; ; i += 2) {
|
|
47
|
+
for (let i = 2, node = path.node; ; i += 2) {
|
|
46
48
|
const grandparentNode = path.getNode(i) as StrictAstNode;
|
|
47
|
-
if (grandparentNode
|
|
48
|
-
if (!
|
|
49
|
-
|
|
50
|
-
}
|
|
49
|
+
if (shouldNotIndent(grandparentNode, path, i)) break;
|
|
50
|
+
if (!isBinaryOperation(grandparentNode)) return indent(document);
|
|
51
|
+
if (shouldIndent(grandparentNode)) return indent(document);
|
|
51
52
|
if (node === grandparentNode.rightOperand.variant) break;
|
|
52
53
|
node = grandparentNode;
|
|
53
54
|
}
|
|
54
55
|
return document;
|
|
55
56
|
};
|
|
56
57
|
|
|
57
|
-
export const printBinaryOperation =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
export const printBinaryOperation = (
|
|
59
|
+
shouldGroupAndIndent: (node: StrictAstNode) => boolean
|
|
60
|
+
): ((
|
|
61
|
+
node: BinaryOperation,
|
|
62
|
+
path: AstPath<BinaryOperation>,
|
|
63
|
+
print: PrintFunction,
|
|
64
|
+
options: ParserOptions<AstNode>
|
|
65
|
+
) => Doc) =>
|
|
66
|
+
createBinaryOperationPrinter(
|
|
67
|
+
binaryGroupRulesBuilder(shouldGroupAndIndent),
|
|
68
|
+
binaryIndentRulesBuilder(shouldGroupAndIndent)
|
|
69
|
+
);
|
|
@@ -12,7 +12,7 @@ export function printComments(path: AstPath<AstNode>): Doc[] {
|
|
|
12
12
|
const document = joinExisting(
|
|
13
13
|
line,
|
|
14
14
|
path.map((commentPath) => {
|
|
15
|
-
const comment = commentPath.
|
|
15
|
+
const comment = commentPath.node;
|
|
16
16
|
if (comment.trailing || comment.leading || comment.printed) {
|
|
17
17
|
return '';
|
|
18
18
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { NonterminalKind } from '@nomicfoundation/slang/cst';
|
|
2
2
|
import { doc } from 'prettier';
|
|
3
|
-
import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js';
|
|
4
3
|
import { isBinaryOperation } from '../slang-utils/is-binary-operation.js';
|
|
5
4
|
import { createBinaryOperationPrinter } from './create-binary-operation-printer.js';
|
|
5
|
+
import {
|
|
6
|
+
binaryGroupRulesBuilder,
|
|
7
|
+
shouldNotIndent
|
|
8
|
+
} from './print-binary-operation.js';
|
|
6
9
|
|
|
7
10
|
import type { AstPath, Doc, ParserOptions } from 'prettier';
|
|
8
11
|
import type {
|
|
@@ -11,28 +14,16 @@ import type {
|
|
|
11
14
|
StrictAstNode
|
|
12
15
|
} from '../slang-nodes/types.d.ts';
|
|
13
16
|
|
|
14
|
-
const {
|
|
17
|
+
const { indent } = doc.builders;
|
|
15
18
|
|
|
16
|
-
const
|
|
17
|
-
NonterminalKind.ReturnStatement,
|
|
18
|
-
NonterminalKind.IfStatement,
|
|
19
|
-
NonterminalKind.WhileStatement
|
|
20
|
-
]);
|
|
21
|
-
|
|
22
|
-
const logicalGroupRulesBuilder =
|
|
23
|
-
(path: AstPath<BinaryOperation>) =>
|
|
24
|
-
(document: Doc): Doc =>
|
|
25
|
-
isBinaryOperation(path.getNode(2) as StrictAstNode)
|
|
26
|
-
? document
|
|
27
|
-
: group(document);
|
|
19
|
+
const logicalGroupRulesBuilder = binaryGroupRulesBuilder(() => false);
|
|
28
20
|
|
|
29
21
|
const logicalIndentRulesBuilder =
|
|
30
22
|
(path: AstPath<BinaryOperation>, options: ParserOptions<AstNode>) =>
|
|
31
23
|
(document: Doc): Doc => {
|
|
32
|
-
let node = path.
|
|
33
|
-
for (let i = 2; ; i += 2) {
|
|
24
|
+
for (let i = 2, node = path.node; ; i += 2) {
|
|
34
25
|
const grandparentNode = path.getNode(i) as StrictAstNode;
|
|
35
|
-
if (
|
|
26
|
+
if (shouldNotIndent(grandparentNode, path, i)) break;
|
|
36
27
|
if (
|
|
37
28
|
options.experimentalTernaries &&
|
|
38
29
|
grandparentNode.kind === NonterminalKind.ConditionalExpression &&
|
|
@@ -3,22 +3,18 @@ import { doc, util } from 'prettier';
|
|
|
3
3
|
import { locEnd } from '../slang-utils/loc.js';
|
|
4
4
|
|
|
5
5
|
import type { AstPath, Doc, ParserOptions } from 'prettier';
|
|
6
|
-
import type {
|
|
7
|
-
AstNode,
|
|
8
|
-
CollectionNode,
|
|
9
|
-
StrictAstNode
|
|
10
|
-
} from '../slang-nodes/types.d.ts';
|
|
6
|
+
import type { AstNode, NodeCollection } from '../slang-nodes/types.d.ts';
|
|
11
7
|
import type { PrintFunction } from '../types.d.ts';
|
|
12
8
|
|
|
13
9
|
const { hardline } = doc.builders;
|
|
14
10
|
|
|
15
11
|
export function printPreservingEmptyLines(
|
|
16
|
-
path: AstPath<
|
|
12
|
+
path: AstPath<NodeCollection>,
|
|
17
13
|
print: PrintFunction,
|
|
18
14
|
options: ParserOptions<AstNode>
|
|
19
15
|
): Doc {
|
|
20
16
|
return path.map((childPath) => {
|
|
21
|
-
const node = childPath.
|
|
17
|
+
const node = childPath.node;
|
|
22
18
|
|
|
23
19
|
return [
|
|
24
20
|
// Only attempt to prepend an empty line if `node` is not the first item
|
|
@@ -10,13 +10,13 @@ export function createHugFunction(
|
|
|
10
10
|
): (node: Expression) => Expression {
|
|
11
11
|
const operators = new Set(huggableOperators);
|
|
12
12
|
return (node: Expression): Expression => {
|
|
13
|
+
const variant = node.variant;
|
|
13
14
|
if (
|
|
14
|
-
|
|
15
|
-
isBinaryOperation(
|
|
16
|
-
operators.has(
|
|
15
|
+
variant.kind !== TerminalKind.Identifier &&
|
|
16
|
+
isBinaryOperation(variant) &&
|
|
17
|
+
operators.has(variant.operator)
|
|
17
18
|
) {
|
|
18
|
-
const
|
|
19
|
-
|
|
19
|
+
const loc = node.loc;
|
|
20
20
|
return Object.assign(Object.create(Expression.prototype) as Expression, {
|
|
21
21
|
kind: NonterminalKind.Expression,
|
|
22
22
|
loc: { ...loc },
|