class Crispr::Mutations::Ternary

Mutates ternary expressions like ‘cond ? a : b`

def mutations_for(node)

Returns:
  • (Array) - mutated nodes

Parameters:
  • node (Parser::AST::Node) -- the AST node to inspect
def mutations_for(node)
  return [] unless node.is_a?(Parser::AST::Node)
  return [] unless node.type == :if
  return [] unless node.loc.respond_to?(:question) && node.loc.question
  cond, if_branch, else_branch = node.children
  [
    if_branch,
    else_branch,
    cond,
    Parser::AST::Node.new(:if, [cond, else_branch, if_branch]) # swap branches
  ].compact
end