Skip to content

Commit

Permalink
Generate opt args in def before outputting vars to avoid missed yields
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Oct 23, 2013
1 parent 49aaf1c commit b069185
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/opal/nodes/def.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,20 @@ def compile

line "#{splat} = $slice.call(arguments, #{argc});" if splat

scope_name = scope.identity

if scope.uses_block?
add_temp "$iter = #{scope_name}._p"
add_temp "#{yielder} = $iter || nil"
end

opt[1..-1].each do |o|
next if o[2][2] == :undefined
line "if (#{variable(o[1])} == null) {"
line ' ', expr(o)
line "}"
end if opt

# must do this after opt args incase opt arg uses yield
scope_name = scope.identity

if scope.uses_block?
add_temp "$iter = #{scope_name}._p"
add_temp "#{yielder} = $iter || nil"

line "#{scope_name}._p = null;"
end

Expand Down

0 comments on commit b069185

Please sign in to comment.