11import { doc } from 'prettier' ;
2- import { rightOperandPrinter } from './printers/right-operand-printer.js' ;
2+ import { createBinaryOperationPrinter } from './printers/create-binary-operation-printer.js' ;
3+ import { createGroupIfNecessaryBuilder } from './printers/create-group-if-necessary-builder.js' ;
34
4- const { group, indent } = doc . builders ;
5-
6- const groupIfNecessaryBuilder = ( path ) => ( document ) =>
7- path . getParentNode ( ) . type === 'BinaryOperation' ? document : group ( document ) ;
5+ const { indent } = doc . builders ;
86
97const indentIfNecessaryBuilder = ( path , options ) => ( document ) => {
108 let node = path . getNode ( ) ;
@@ -25,15 +23,12 @@ const indentIfNecessaryBuilder = (path, options) => (document) => {
2523 }
2624} ;
2725
26+ const logicalPrinter = createBinaryOperationPrinter (
27+ createGroupIfNecessaryBuilder ( [ ] ) ,
28+ indentIfNecessaryBuilder
29+ ) ;
30+
2831export const logical = {
2932 match : ( op ) => [ '&&' , '||' ] . includes ( op ) ,
30- print : ( node , path , print , options ) => {
31- const groupIfNecessary = groupIfNecessaryBuilder ( path ) ;
32- const indentIfNecessary = indentIfNecessaryBuilder ( path , options ) ;
33-
34- return groupIfNecessary ( [
35- path . call ( print , 'left' ) ,
36- indentIfNecessary ( rightOperandPrinter ( node , path , print , options ) )
37- ] ) ;
38- }
33+ print : logicalPrinter
3934} ;
0 commit comments