@@ -112,15 +112,21 @@ function reconstructUnaryOp(leaf: RNodeWithParent, operand: Code, configuration:
112112 }
113113}
114114
115- function reconstructBinaryOp ( n : RBinaryOp < ParentInformation > | RPipe < ParentInformation > , lhs : Code , rhs : Code ) : Code {
115+ function reconstructBinaryOp ( n : RBinaryOp < ParentInformation > | RPipe < ParentInformation > , lhs : Code , rhs : Code , config : ReconstructionConfiguration ) : Code {
116116 if ( lhs . length === 0 && rhs . length === 0 ) {
117- return [ ]
118- }
119- if ( lhs . length === 0 ) { // if we have no lhs, only return rhs
117+ if ( isSelected ( config , n ) ) {
118+ return plain ( getLexeme ( n ) )
119+ } else {
120+ return [ ]
121+ }
122+ } else if ( lhs . length === 0 ) { // if we have no lhs, only return rhs
120123 return rhs
121- }
122- if ( rhs . length === 0 ) { // if we have no rhs we have to keep everything to get the rhs
123- return plain ( getLexeme ( n ) )
124+ } else if ( rhs . length === 0 ) {
125+ if ( isSelected ( config , n ) ) {
126+ return plain ( getLexeme ( n ) )
127+ } else {
128+ return lhs
129+ }
124130 }
125131
126132 return reconstructRawBinaryOperator ( lhs , n . type === RType . Pipe ? '|>' : n . operator , rhs )
@@ -205,7 +211,7 @@ function reconstructIfThenElse(ifThenElse: RIfThenElse<ParentInformation>, condi
205211 return otherwise
206212 }
207213 } else {
208- const thenRemainder = indentBy ( then . splice ( 1 ) , 1 )
214+ const thenRemainder = indentBy ( then . slice ( 1 ) , 1 )
209215 if ( thenRemainder . length > 0 ) {
210216 if ( ! thenRemainder [ thenRemainder . length - 1 ] . line . trim ( ) . endsWith ( 'else' ) ) {
211217 thenRemainder [ thenRemainder . length - 1 ] . line += ' else '
@@ -344,10 +350,20 @@ function reconstructSpecialInfixFunctionCall(args: (Code | typeof EmptyArgument)
344350}
345351
346352function reconstructFunctionCall ( call : RFunctionCall < ParentInformation > , functionName : Code , args : ( Code | typeof EmptyArgument ) [ ] , configuration : ReconstructionConfiguration ) : Code {
353+ const selected = isSelected ( configuration , call )
354+ if ( ! selected ) {
355+ const f = args . filter ( a => a !== EmptyArgument && a . length !== 0 ) as Code [ ]
356+ if ( f . length === 0 ) {
357+ return [ ]
358+ } else if ( f . length === 1 ) {
359+ return f [ 0 ]
360+ }
361+ }
362+
347363 if ( call . infixSpecial === true ) {
348364 return reconstructSpecialInfixFunctionCall ( args , call )
349365 }
350- if ( call . flavor === 'named' && isSelected ( configuration , call ) ) {
366+ if ( call . flavor === 'named' && selected ) {
351367 return plain ( getLexeme ( call ) )
352368 }
353369 const filteredArgs = args . filter ( a => a !== undefined && a . length > 0 )
0 commit comments