Class: Evilution::Mutator::Operator::IndexToDig

Inherits:
Base
  • Object
show all
Defined in:
lib/evilution/mutator/operator/index_to_dig.rb

Instance Attribute Summary

Attributes inherited from Base

#mutations

Instance Method Summary collapse

Methods inherited from Base

#call, clear_parse_cache!, operator_name, parsed_tree_for

Constructor Details

#initialize(**options) ⇒ IndexToDig

Returns a new instance of IndexToDig.



6
7
8
9
# File 'lib/evilution/mutator/operator/index_to_dig.rb', line 6

def initialize(**options)
  super
  @consumed = Set.new
end

Instance Method Details

#visit_call_node(node) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/evilution/mutator/operator/index_to_dig.rb', line 11

def visit_call_node(node)
  if chain_head?(node)
    root, args = collect_chain(node)
    root_source = byteslice_source(root.location.start_offset, root.location.length)
    arg_sources = args.map { |a| byteslice_source(a.location.start_offset, a.location.length) }

    add_mutation(
      offset: node.location.start_offset,
      length: node.location.length,
      replacement: "#{root_source}.dig(#{arg_sources.join(", ")})",
      node: node
    )
  end

  super
end