class Opal::Nodes::BaseYieldNode
Public Instance Methods
compile_call()
click to toggle source
# File lib/opal/nodes/yield.rb, line 8 def compile_call yielding_scope = find_yielding_scope yielding_scope.uses_block! yielding_scope.block_name ||= '$yield' block_name = yielding_scope.block_name if yields_single_arg?(children) push expr(children.first) wrap "Opal.yield1(#{block_name}, ", ')' else push expr(s(:arglist, *children)) if uses_splat?(children) wrap "Opal.yieldX(#{block_name}, ", ')' else wrap "Opal.yieldX(#{block_name}, [", '])' end end end
find_yielding_scope()
click to toggle source
# File lib/opal/nodes/yield.rb, line 30 def find_yielding_scope working = scope while working if working.block_name || working.def? break end working = working.parent end working end
uses_splat?(children)
click to toggle source
# File lib/opal/nodes/yield.rb, line 46 def uses_splat?(children) children.any? { |child| child.type == :splat } end
yields_single_arg?(children)
click to toggle source
# File lib/opal/nodes/yield.rb, line 42 def yields_single_arg?(children) !uses_splat?(children) && children.size == 1 end