import { isCall , isVariable , isFunction , isConditional , isBinary } from 'src/lib/expressionTypeGuards' ; import { CallExpression , Expression , ConditionalExpression , FunctionExpression , VariableExpression , BinaryExpression } from 'src/types/ExpressionTypes' ; export default function replaceBinaryParentKey ( expression , key , target , replaceWith ) ; export default function replaceBinaryParentKey ( expression , key , target , replaceWith ) ; export default function replaceBinaryParentKey ( expression , key , target , replaceWith ) ; export default function replaceBinaryParentKey ( expression , key , target , replaceWith ) ; export default function replaceBinaryParentKey ( expression , key , target , replaceWith ) ; export default function replaceBinaryParentKey ( expression , key , target , replaceWith ) ; export default function replaceBinaryParentKey ( expression , key , target , replaceWith ) ; export default function replaceBinaryParentKey ( expression , key , target , replaceWith ) { if ( isVariable ( expression ) ) { return expression ; } else if ( isCall ( expression ) ) { return { ... expression , arg : replaceBinaryParentKey ( expression . arg , key , target , replaceWith ) , func : replaceBinaryParentKey ( expression . func , key , target , replaceWith ) } ; } else if ( isFunction ( expression ) ) { return { ... expression , body : replaceBinaryParentKey ( expression . body , key , target , replaceWith ) } ; } else if ( isConditional ( expression ) ) { return { ... expression , condition : replaceBinaryParentKey ( expression . condition , key , target , replaceWith ) , trueCase : replaceBinaryParentKey ( expression . trueCase , key , target , replaceWith ) , falseCase : replaceBinaryParentKey ( expression . falseCase , key , target , replaceWith ) } ; } else if ( isBinary ( expression ) ) { if ( expression === target ) { return { ... expression , [ key ] : replaceWith } ; } else { return { ... expression , first : replaceBinaryParentKey ( expression . first , key , target , replaceWith ) , second : replaceBinaryParentKey ( expression . second , key , target , replaceWith ) } ; } } else { throw new Error ( ) ; } }