11import { NonterminalKind } from '@nomicfoundation/slang/cst' ;
22import { doc } from 'prettier' ;
33import { isBinaryOperation } from '../slang-utils/is-binary-operation.js' ;
4- import { TerminalNode } from '../slang-nodes/TerminalNode.js' ;
54
65import type { AstPath , Doc , ParserOptions } from 'prettier' ;
76import type {
@@ -15,7 +14,7 @@ const { group, line } = doc.builders;
1514
1615function rightOperandPrint (
1716 { operator, leftOperand } : BinaryOperation ,
18- path : AstPath < BinaryOperation > ,
17+ path : AstPath < StrictAstNode > ,
1918 print : PrintFunction ,
2019 options : ParserOptions < AstNode >
2120) : Doc {
@@ -27,9 +26,9 @@ function rightOperandPrint(
2726
2827 // If there's only a single binary expression, we want to create a group in
2928 // order to avoid having a small right part like -1 be on its own line.
30- const parent = path . parent as StrictAstNode ;
29+ const parent = path . parent ! ;
3130 const shouldGroup =
32- ( leftOperand instanceof TerminalNode || ! isBinaryOperation ( leftOperand ) ) &&
31+ ! isBinaryOperation ( leftOperand ) &&
3332 ( ! isBinaryOperation ( parent ) ||
3433 parent . kind === NonterminalKind . AssignmentExpression ) ;
3534
@@ -38,17 +37,15 @@ function rightOperandPrint(
3837
3938export const createBinaryOperationPrinter =
4039 (
41- groupRulesBuilder : (
42- path : AstPath < BinaryOperation >
43- ) => ( document : Doc ) => Doc ,
40+ groupRulesBuilder : ( path : AstPath < StrictAstNode > ) => ( document : Doc ) => Doc ,
4441 indentRulesBuilder : (
4542 node : BinaryOperation ,
4643 path : AstPath < StrictAstNode >
4744 ) => ( document : Doc ) => Doc
4845 ) =>
4946 (
5047 node : BinaryOperation ,
51- path : AstPath < BinaryOperation > ,
48+ path : AstPath < StrictAstNode > ,
5249 print : PrintFunction ,
5350 options : ParserOptions < AstNode >
5451 ) : Doc => {
0 commit comments