Skip to content

Commit f862304

Browse files
committed
rightOperandPrinter is only used in a single place thus it's not needed to be exported
1 parent ef23dae commit f862304

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

src/binary-operator-printers/printers/create-binary-operation-printer.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
import { rightOperandPrinter } from './right-operand-printer.js';
1+
import { doc } from 'prettier';
2+
import { assignment } from '../assignment.js';
3+
4+
const { group, line } = doc.builders;
5+
6+
const rightOperandPrinter = (node, path, print, options) => {
7+
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
14+
const parent = path.getParentNode();
15+
return node.left.type !== 'BinaryOperation' &&
16+
(parent.type !== 'BinaryOperation' || assignment.match(parent.operator))
17+
? group(right)
18+
: right;
19+
};
220

321
export const createBinaryOperationPrinter =
422
(groupIfNecessaryBuilder, indentIfNecessaryBuilder) =>

src/binary-operator-printers/printers/right-operand-printer.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)