We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent afe81b0 commit 8d645f7Copy full SHA for 8d645f7
5 files changed
src/binary-operator-printers/printers/create-binary-operation-printer.js
@@ -3,8 +3,11 @@ import { assignment } from '../assignment.js';
3
4
const { group, line } = doc.builders;
5
6
-const rightOperandPrinter = (node, path, print) => {
7
- const right = [' ', node.operator, line, path.call(print, 'right')];
+const rightOperandPrinter = (node, path, print, options) => {
+ const right =
8
+ options.experimentalOperatorPosition === 'end'
9
+ ? [' ', node.operator, line, path.call(print, 'right')]
10
+ : [line, node.operator, ' ', path.call(print, 'right')];
11
12
// If it's a single binary operation, avoid having a small right
13
// operand like - 1 on its own line
@@ -23,6 +26,6 @@ export const createBinaryOperationPrinter =
23
26
24
27
return groupIfNecessary([
25
28
path.call(print, 'left'),
- indentIfNecessary(rightOperandPrinter(node, path, print))
29
+ indentIfNecessary(rightOperandPrinter(node, path, print, options))
30
]);
31
};
src/options.ts
@@ -48,6 +48,22 @@ const options: SupportOptions = {
48
oppositeDescription:
49
'Default behavior of ternaries; keep question marks on the same line as the consequent.'
50
},
51
+ experimentalOperatorPosition: {
52
+ category: CATEGORY_JAVASCRIPT,
53
+ type: 'choice',
54
+ default: 'end',
55
+ description: 'Where to print operators when binary expressions wrap lines.',
56
+ choices: [
57
+ {
58
+ value: 'start',
59
+ description: 'Print operators at the start of new lines.'
60
+ },
61
62
+ value: 'end',
63
+ description: 'Print operators at the end of previous lines.'
64
+ }
65
+ ]
66
67
compiler: {
68
category: CATEGORY_SOLIDITY,
69
type: 'string',
src/slang-printers/create-binary-operation-printer.ts
@@ -15,13 +15,14 @@ const { group, line } = doc.builders;
15
function rightOperandPrint(
16
node: BinaryOperation,
17
path: AstPath<BinaryOperation>,
18
- print: PrintFunction
+ print: PrintFunction,
19
+ options: ParserOptions<AstNode>
20
): Doc {
- const rightOperand = [
21
- ` ${node.operator}`,
22
- line,
- path.call(print, 'rightOperand')
- ];
+ const rightOperand =
+ ? [` ${node.operator}`, line, path.call(print, 'rightOperand')]
+ : [line, `${node.operator} `, path.call(print, 'rightOperand')];
+
const shouldGroup =
@@ -54,6 +55,6 @@ export const createBinaryOperationPrinter =
return groupRules([
path.call(print, 'leftOperand'),
- indentRules(rightOperandPrint(node, path, print))
+ indentRules(rightOperandPrint(node, path, print, options))
0 commit comments