1- import { doc } from 'prettier' ;
2- import { shouldGroupOrIndent } from '../utils/should-group-or-indent.js' ;
3- import { equality } from '../equality.js' ;
4- import { inequality } from '../inequality.js' ;
51import { rightOperandPrinter } from './right-operand-printer.js' ;
62
7- const { group, indent } = doc . builders ;
8-
9- const comparisonMatchers = [ equality , inequality ] ;
10-
11- export const createGroupIfNecessaryBuilder =
12- ( matchers ) => ( path ) => ( document ) => {
13- const parentNode = path . getParentNode ( ) ;
14- if ( shouldGroupOrIndent ( parentNode , matchers ) ) return group ( document ) ;
15- return document ;
16- } ;
17-
18- export const createIndentIfNecessaryBuilder =
19- ( matchers ) => ( path ) => ( document ) => {
20- let node = path . getNode ( ) ;
21- for ( let i = 0 ; ; i += 1 ) {
22- const parentNode = path . getParentNode ( i ) ;
23- if ( parentNode . type === 'ReturnStatement' ) return document ;
24- if ( shouldGroupOrIndent ( parentNode , matchers ) ) return indent ( document ) ;
25- if ( node === parentNode . right ) return document ;
26- node = parentNode ;
27- }
28- } ;
29-
303export const createBinaryOperationPrinter =
314 ( groupIfNecessaryBuilder , indentIfNecessaryBuilder ) =>
325 ( node , path , print , options ) => {
@@ -38,8 +11,3 @@ export const createBinaryOperationPrinter =
3811 indentIfNecessary ( rightOperandPrinter ( node , path , print , options ) )
3912 ] ) ;
4013 } ;
41-
42- export const defaultBinaryOperationPrinter = createBinaryOperationPrinter (
43- createGroupIfNecessaryBuilder ( comparisonMatchers ) ,
44- createIndentIfNecessaryBuilder ( comparisonMatchers )
45- ) ;
0 commit comments