Class: Opal::Rewriters::Numblocks

Inherits:
Base
  • Object
show all
Defined in:
lib/opal/rewriters/numblocks.rb

Overview

This rewriter transforms the Ruby 2.7 numblocks to regular blocks:

proc { _1 } v proc { |_1| _1 }

Constant Summary

Constants inherited from Base

Base::DUMMY_LOCATION

Instance Attribute Summary

Attributes inherited from Base

#current_node

Instance Method Summary collapse

Methods inherited from Base

#append_to_body, #begin_with_stmts, #dynamic!, #error, #on_top, #prepend_to_body, #process, s, #s, #stmts_of

Instance Method Details

#gen_args(arg_count) ⇒ Object



24
25
26
27
28
# File 'lib/opal/rewriters/numblocks.rb', line 24

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

#on_numblock(node) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/opal/rewriters/numblocks.rb', line 13

def on_numblock(node)
  left, arg_count, right = node.children

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