Skip to content

Commit

Permalink
Support yield from inside a block (fixes #379)
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Nov 15, 2013
1 parent f8d7d1d commit bbb3551
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/opal/nodes/yield.rb
Expand Up @@ -4,7 +4,10 @@ module Opal
module Nodes
class BaseYieldNode < Base
def compile_call(children, level)
scope.uses_block!
yielding_scope = find_yielding_scope

yielding_scope.uses_block!
block_name = yielding_scope.block_name || '$yield'

if yields_single_arg?(children)
push expr(children.first)
Expand All @@ -20,8 +23,16 @@ def compile_call(children, level)
end
end

def block_name
scope.block_name || '$yield'
def find_yielding_scope
working = scope
while working
if working.block_name or working.def?
break
end
working = working.parent
end

working
end

def yields_single_arg?(children)
Expand Down

0 comments on commit bbb3551

Please sign in to comment.