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



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'opal/lib/opal/rewriters/forward_args.rb', line 38

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

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

#on_block_pass(node) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'opal/lib/opal/rewriters/forward_args.rb', line 26

def on_block_pass(node)
  if !node.children.first
    process(
      node.updated(nil,
        [s(:lvar, '$fwd_block')]
      )
    )
  else
    super
  end
end

#on_blockarg(node) ⇒ Object



70
71
72
73
74
75
76
# File 'opal/lib/opal/rewriters/forward_args.rb', line 70

def on_blockarg(node)
  if !node.children.first
    node.updated(nil, ['$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_forwarded_kwrestarg(_node) ⇒ Object



20
21
22
23
24
# File 'opal/lib/opal/rewriters/forward_args.rb', line 20

def on_forwarded_kwrestarg(_node)
  process(
    s(:kwsplat, s(:lvar, '$fwd_kwrest'))
  )
end

#on_forwarded_restarg(_node) ⇒ Object



14
15
16
17
18
# File 'opal/lib/opal/rewriters/forward_args.rb', line 14

def on_forwarded_restarg(_node)
  process(
    s(:splat, s(:lvar, '$fwd_rest'))
  )
end

#on_kwrestarg(node) ⇒ Object



62
63
64
65
66
67
68
# File 'opal/lib/opal/rewriters/forward_args.rb', line 62

def on_kwrestarg(node)
  if !node.children.first
    node.updated(nil, ['$fwd_kwrest'])
  else
    super
  end
end

#on_restarg(node) ⇒ Object



54
55
56
57
58
59
60
# File 'opal/lib/opal/rewriters/forward_args.rb', line 54

def on_restarg(node)
  if !node.children.first
    node.updated(nil, ['$fwd_rest'])
  else
    super
  end
end

#on_send(node) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'opal/lib/opal/rewriters/forward_args.rb', line 78

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]

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