Sha256: 1477b1845a33ed54510cdd956112c00c0997570a9b4c5aa375db1ae6c59f39a4

Contents?: true

Size: 784 Bytes

Versions: 4

Compression:

Stored size: 784 Bytes

Contents

module DeepCover
  class Node::EmptyBody < Node
    def initialize(base_node, parent: raise, index: 0, position: ChildCanBeEmpty.last_empty_position)
      @position = position
      super(base_node, parent: parent, index: index, base_children: [])
    end

    def type
      :EmptyBody
    end

    def loc_hash
      return {} if @position == true
      {expression: @position}
    end

    def is_statement
      false
    end

    # When parent rewrites us, the %{node} must always be at the beginning because our location can
    # also be rewritten by out parent, and we want the rewrite to be after it.
    def rewriting_rules
      rules = super
      rules.map do |expression, rule|
        [expression, "%{node};#{rule.sub('%{node}', 'nil;')}"]
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
deep-cover-0.1.14 lib/deep_cover/node/empty_body.rb
deep-cover-0.1.13 lib/deep_cover/node/empty_body.rb
deep-cover-0.1.12 lib/deep_cover/node/empty_body.rb
deep-cover-0.1.11 lib/deep_cover/node/empty_body.rb