Skip to content

Commit 1474ca2

Browse files
committed
small refactor
1 parent b7b1edd commit 1474ca2

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

src/slang-nodes/ConditionalExpression.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ function experimentalTernaries(
5050
path.call(print, 'trueExpression')
5151
]);
5252

53+
const groupId = Symbol('Slang.ConditionalExpression.trueExpression');
5354
const conditionAndTrueExpressionGroup = group(
5455
[operandDoc, trueExpressionDoc],
55-
{ id: Symbol('Slang.ConditionalExpression.trueExpression') }
56+
{ id: groupId }
5657
);
5758

5859
const falseExpression = path.call(print, 'falseExpression');
@@ -64,10 +65,9 @@ function experimentalTernaries(
6465
: ifBreak(
6566
[fillTab(options), indent(falseExpression)],
6667
[' ', falseExpression],
67-
{
68-
// We only add `fillTab` if we are sure the trueExpression is indented
69-
groupId: conditionAndTrueExpressionGroup.id
70-
}
68+
// We only add `fillTab` if we are sure the trueExpression is
69+
// indented.
70+
{ groupId }
7171
)
7272
];
7373

src/slang-printers/create-binary-operation-printer.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@ function rightOperandPrint(
2323
? [` ${node.operator}`, line, path.call(print, 'rightOperand')]
2424
: [line, `${node.operator} `, path.call(print, 'rightOperand')];
2525

26-
// If it's a single binary operation, avoid having a small right
27-
// operand like - 1 on its own line
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.
2828
const leftOperand = node.leftOperand.variant;
2929
const grandparentNode = path.grandparent as StrictAstNode;
3030
const shouldGroup =
31-
!(
32-
leftOperand.kind !== TerminalKind.Identifier &&
33-
isBinaryOperation(leftOperand)
34-
) &&
31+
(leftOperand.kind === TerminalKind.Identifier ||
32+
!isBinaryOperation(leftOperand)) &&
3533
(!isBinaryOperation(grandparentNode) ||
3634
grandparentNode.kind === NonterminalKind.AssignmentExpression);
3735

0 commit comments

Comments
 (0)