Sha256: fcb923cf11cd584716cf0a83c67e87662c8a67f6cdfd2606121e343ff67ea63d

Contents?: true

Size: 1.01 KB

Versions: 8

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module RubyNext
  module Language
    module Rewriters
      class RescueWithinBlock < Base
        NAME = "rescue-within-block"
        SYNTAX_PROBE = "lambda do
          raise 'err'
        rescue
          $! # => #<RuntimeError: err>
        end.call"

        MIN_SUPPORTED_VERSION = Gem::Version.new("2.5.0")

        def on_block(block_node)
          exception_node = block_node.children.find do |node|
            node && (node.type == :rescue || node.type == :ensure)
          end

          return super(block_node) unless exception_node

          context.track! self

          insert_before(exception_node.loc.expression, "begin;")
          insert_after(exception_node.loc.expression, ";end")

          new_children = block_node.children.map do |child|
            next s(:kwbegin, exception_node) if child == exception_node

            child
          end

          process(
            block_node.updated(:block, new_children)
          )
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ruby-next-core-1.0.3 lib/ruby-next/language/rewriters/2.5/rescue_within_block.rb
ruby-next-core-1.0.2 lib/ruby-next/language/rewriters/2.5/rescue_within_block.rb
ruby-next-core-1.0.1 lib/ruby-next/language/rewriters/2.5/rescue_within_block.rb
ruby-next-core-1.0.0 lib/ruby-next/language/rewriters/2.5/rescue_within_block.rb
ruby-next-core-1.0.0.rc.1 lib/ruby-next/language/rewriters/2.5/rescue_within_block.rb
ruby-next-core-0.15.3 lib/ruby-next/language/rewriters/2.5/rescue_within_block.rb
ruby-next-core-0.15.2 lib/ruby-next/language/rewriters/2.5/rescue_within_block.rb
ruby-next-core-0.15.1 lib/ruby-next/language/rewriters/2.5/rescue_within_block.rb