import { isFunction , isVariable , isCall , isConditional , isBinary } from 'src/lib/expressionTypeGuards' ; import { activeFuncArg } from 'scripts/lib/steps/stepToShowFuncUnbound' ; import { CallExpression , ExecutableCallRegular , ExecutableStepCallRegular , Expression , FunctionExpression , StepConditional , ConditionalExpression , NonExecutableStepCall , StepChild , StepFunction , StepVariable , BinaryExpression , StepBinary , VariableExpression } from 'src/types/ExpressionTypes' ; import { ConflictingNamesToUnusedNames } from 'scripts/lib/getConflictsToUnused' ; export function toNeedsAlphaConvert ( e , conflicts , funcSide ) ; export function toNeedsAlphaConvert ( e , conflicts , funcSide ) ; export function toNeedsAlphaConvert ( e , conflicts , funcSide ) ; export function toNeedsAlphaConvert ( e , conflicts , funcSide ) ; export function toNeedsAlphaConvert ( e , conflicts , funcSide ) ; export function toNeedsAlphaConvert ( e , conflicts , funcSide ) ; export function toNeedsAlphaConvert ( e , conflicts , funcSide ) ; export function toNeedsAlphaConvert ( e , conflicts , funcSide ) { if ( isVariable ( e ) ) { if ( funcSide && e . bound ) { return { ... e , highlightType : 'active' , topLeftBadgeType : 'none' , bottomRightBadgeType : 'funcBound' } ; } else if ( funcSide && ! e . bound ) { if ( conflicts [ e . name ] ) { return { ... e , highlightType : 'highlighted' , topLeftBadgeType : 'conflict' , bottomRightBadgeType : 'funcUnbound' } ; } else { return { ... e , highlightType : 'active' , topLeftBadgeType : 'none' , bottomRightBadgeType : 'funcUnbound' } ; } } else { if ( conflicts [ e . name ] ) { return { ... e , highlightType : 'highlighted' , topLeftBadgeType : 'conflict' , bottomRightBadgeType : 'callArg' } ; } else { return { ... e , highlightType : 'active' , topLeftBadgeType : 'none' , bottomRightBadgeType : 'callArg' } ; } } } else if ( isFunction ( e ) ) { return { ... e , arg : toNeedsAlphaConvert ( e . arg , conflicts , funcSide ) , body : toNeedsAlphaConvert ( e . body , conflicts , funcSide ) } ; } else if ( isCall ( e ) ) { return { ... e , state : 'default' , arg : toNeedsAlphaConvert ( e . arg , conflicts , funcSide ) , func : toNeedsAlphaConvert ( e . func , conflicts , funcSide ) } ; } else if ( isConditional ( e ) ) { return { ... e , state : 'default' , condition : toNeedsAlphaConvert ( e . condition , conflicts , funcSide ) , trueCase : toNeedsAlphaConvert ( e . trueCase , conflicts , funcSide ) , falseCase : toNeedsAlphaConvert ( e . falseCase , conflicts , funcSide ) } ; } else if ( isBinary ( e ) ) { return { ... e , state : 'default' , first : toNeedsAlphaConvert ( e . first , conflicts , funcSide ) , second : toNeedsAlphaConvert ( e . second , conflicts , funcSide ) } ; } else { throw new Error ( ) ; } } const stepToNeedsAlphaConvert = ( x , conflicts ) : ExecutableStepCallRegular < 'needsAlphaConvert' > => ( { ... x , state : 'needsAlphaConvert' , arg : toNeedsAlphaConvert ( x . arg , conflicts , false ) , func : { ... x . func , arg : activeFuncArg ( x . func . arg ) , body : toNeedsAlphaConvert ( x . func . body , conflicts , true ) } } ) ; export default stepToNeedsAlphaConvert ;