@@ -30,21 +30,25 @@ export const indentIfNecessaryBuilder = (path) => (document) => {
3030 }
3131} ;
3232
33+ export const rightOperand = ( node , path , print , options ) =>
34+ options . experimentalOperatorPosition === 'end'
35+ ? [ ' ' , node . operator , line , path . call ( print , 'right' ) ]
36+ : [ line , node . operator , ' ' , path . call ( print , 'right' ) ] ;
37+
3338export const arithmetic = {
3439 match : ( op ) => [ '+' , '-' , '*' , '/' , '%' ] . includes ( op ) ,
35- print : ( node , path , print ) => {
40+ print : ( node , path , print , options ) => {
3641 const groupIfNecessary = groupIfNecessaryBuilder ( path ) ;
3742 const indentIfNecessary = indentIfNecessaryBuilder ( path ) ;
3843
39- const right = [ node . operator , line , path . call ( print , 'right' ) ] ;
44+ const right = rightOperand ( node , path , print , options ) ;
4045 // If it's a single binary operation, avoid having a small right
4146 // operand like - 1 on its own line
4247 const shouldGroup =
4348 node . left . type !== 'BinaryOperation' &&
4449 path . getParentNode ( ) . type !== 'BinaryOperation' ;
4550 return groupIfNecessary ( [
4651 path . call ( print , 'left' ) ,
47- ' ' ,
4852 indentIfNecessary ( shouldGroup ? group ( right ) : right )
4953 ] ) ;
5054 }
0 commit comments