Sha256: f75a33f2be591d99b79b1c5c748746c84240a7c921b0d183b71d1467067fbca2

Contents?: true

Size: 585 Bytes

Versions: 33

Compression:

Stored size: 585 Bytes

Contents

# frozen_string_literal: true

require 'opal/rewriters/base'

module Opal
  module Rewriters
    # This rewriter transforms the Ruby 2.7 numblocks to regular blocks:
    #
    # proc { _1 }
    #      v
    # proc { |_1| _1 }
    class Numblocks < Base
      def on_numblock(node)
        left, arg_count, right = node.children

        s(
          :block,
          left,
          s(:args, *gen_args(arg_count)),
          right
        )
      end

      def gen_args(arg_count)
        (1..arg_count).map do |i|
          s(:arg, :"_#{i}")
        end
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
opal-1.8.3.rc1 lib/opal/rewriters/numblocks.rb
opal-1.8.2 lib/opal/rewriters/numblocks.rb
opal-1.8.1 lib/opal/rewriters/numblocks.rb
opal-1.8.0 lib/opal/rewriters/numblocks.rb
opal-1.8.0.beta1 lib/opal/rewriters/numblocks.rb
opal-1.7.4 lib/opal/rewriters/numblocks.rb
opal-1.8.0.alpha1 lib/opal/rewriters/numblocks.rb
opal-1.7.3 lib/opal/rewriters/numblocks.rb
opal-1.7.2 lib/opal/rewriters/numblocks.rb
opal-1.7.1 lib/opal/rewriters/numblocks.rb
opal-1.7.0 lib/opal/rewriters/numblocks.rb
opal-1.7.0.rc1 lib/opal/rewriters/numblocks.rb
opal-1.6.1 lib/opal/rewriters/numblocks.rb
opal-1.6.0 lib/opal/rewriters/numblocks.rb
opal-1.6.0.rc1 lib/opal/rewriters/numblocks.rb
opal-1.6.0.alpha1 lib/opal/rewriters/numblocks.rb
opal-1.5.1 lib/opal/rewriters/numblocks.rb
opal-1.5.0 lib/opal/rewriters/numblocks.rb
opal-1.5.0.rc1 lib/opal/rewriters/numblocks.rb
opal-1.4.1 lib/opal/rewriters/numblocks.rb