Sha256: 63c4c0efbb8046f2cb34c6bd0499834f611e30682239f82d5ef12dc7b7043fdb
Contents?: true
Size: 1010 Bytes
Versions: 14
Compression:
Stored size: 1010 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 # @param and_comma [Boolean] delete extra comma. # @param adapter [NodeMutation::Adapter] def initialize(node, *selectors, adapter:, and_comma: false) super(node, nil, adapter: adapter) @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| @adapter.child_node_range(@node, selector) } .compact.map(&:start).min @end = @selectors.map { |selector| @adapter.child_node_range(@node, selector) } .compact.map(&:end).max remove_comma if @and_comma remove_whitespace end end
Version data entries
14 entries across 14 versions & 1 rubygems