Sha256: a7dbca7eb549bb27322b25d129db719eca829dc8edc5e479613e4f124ced95f7
Contents?: true
Size: 964 Bytes
Versions: 21
Compression:
Stored size: 964 Bytes
Contents
# frozen_string_literal: true # DeleteAction deletes child nodes. class NodeMutation::DeleteAction < NodeMutation::Action # Initialize a DeleteAction. # # @param node [Node] # @param selectors [Array<Symbol, String>] used to select child nodes # @option and_comma [Boolean] delete extra comma. def initialize(node, *selectors, and_comma: false) super(node, nil) @selectors = selectors @and_comma = and_comma @type = :delete end # The rewritten code, always empty string. def new_code '' end private # Calculate the begin and end positions. def calculate_position @start = @selectors.map { |selector| NodeMutation.adapter.child_node_range(@node, selector) } .compact.map(&:start).min @end = @selectors.map { |selector| NodeMutation.adapter.child_node_range(@node, selector) } .compact.map(&:end).max remove_comma if @and_comma remove_whitespace end end
Version data entries
21 entries across 21 versions & 1 rubygems
Version | Path |
---|---|
node_mutation-1.15.3 | lib/node_mutation/action/delete_action.rb |