Class: Opal::Rewriters::ForwardArgs

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

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

#on_args(node) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'opal/lib/opal/rewriters/forward_args.rb', line 14

def on_args(node)
  if node.children.last && node.children.last.type == :forward_arg
    prev_children = node.children[0..-2]

    node.updated(nil,
      [
        *prev_children,
        s(:restarg, '$fwd_rest'),
        s(:blockarg, '$fwd_block')
      ]
    )
  else
    super
  end
end

#on_forward_args(_node) ⇒ Object



8
9
10
11
12
# File 'opal/lib/opal/rewriters/forward_args.rb', line 8

def on_forward_args(_node)
  process(
    s(:args, s(:forward_arg, :"$"))
  )
end

#on_send(node) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'opal/lib/opal/rewriters/forward_args.rb', line 30

def on_send(node)
  if node.children.last &&
     node.children.last.class != Symbol &&
     node.children.last.type == :forwarded_args

    prev_children = node.children[0..-2]

    node.updated(nil,
      [
        *prev_children,
        s(:splat,
          s(:lvar, '$fwd_rest')
        ),
        s(:block_pass,
          s(:lvar, '$fwd_block')
        )
      ]
    )
  else
    super
  end
end