lib/mutant/mutator/node.rb in mutant-0.5.18 vs lib/mutant/mutator/node.rb in mutant-0.5.19

- old
+ new

@@ -21,12 +21,12 @@ def self.define_named_child(name, index) define_method(name) do children.at(index) end - define_method("emit_#{name}_mutations") do - mutate_child(index) + define_method("emit_#{name}_mutations") do |&block| + mutate_child(index, &block) end define_method("emit_#{name}") do |node| emit_child_update(index, node) end @@ -116,14 +116,17 @@ # # @return [undefined] # # @api private # - def mutate_child(index, mutator = Mutator) + def mutate_child(index, mutator = Mutator, &block) + block ||= lambda { |_node| true } child = children.at(index) mutator.each(child, self) do |mutation| - emit_child_update(index, mutation) + if block.call(mutation) + emit_child_update(index, mutation) + end end end # Emit delete child mutation # @@ -164,10 +167,31 @@ # def emit_type(*children) emit(new_self(*children)) end - # Emit a new AST node with NilLiteral class + # Emit singleton literals + # + # @return [undefined] + # + # @api private + # + def emit_singletons + emit_nil + emit_self + end + + # Emit a literal self + # + # @return [undefined] + # + # @api private + # + def emit_self + emit(N_SELF) + end + + # Emit a literal nil # # @return [undefined] # # @api private #