Sha256: 205a50010d3f178563b71836ca9180d3c3437d10e5693c43bf9e6f22da2c02b7

Contents?: true

Size: 866 Bytes

Versions: 1

Compression:

Stored size: 866 Bytes

Contents

# frozen_string_literal: true

module Synvert::Core
  # DeleteAction deletes child nodes.
  class Rewriter::DeleteAction < Rewriter::Action
    # Initialize a DeleteAction.
    #
    # @param instance [Synvert::Core::Rewriter::Instance]
    # @param selectors [Array<Symbol, String>] used to select child nodes
    def initialize(instance, *selectors)
      super(instance, nil)
      @selectors = selectors
    end

    # The rewritten code, always empty string.
    def rewritten_code
      ''
    end

    private

    # Calculate the begin and end positions.
    def calculate_position
      @begin_pos = @selectors.map { |selector| @node.child_node_range(selector) }.compact.map(&:begin_pos).min
      @end_pos = @selectors.map { |selector| @node.child_node_range(selector) }.compact.map(&:end_pos).max
      squeeze_spaces
      remove_comma
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
synvert-core-0.64.0 lib/synvert/core/rewriter/action/delete_action.rb