class Opal::Nodes::BlockNode
def child_is_expr?(child)
def child_is_expr?(child) raw_expression?(child) and [:stmt, :stmt_closure].include?(@level) end
def compile
def compile return push "nil" if children.empty? children.each_with_index do |child, idx| push stmt_join unless idx == 0 if yasgn = find_inline_yield(child) push compiler.process(yasgn, @level) push ";" end push compiler.process(child, @level) push ";" if child_is_expr?(child) end end
def find_inline_yield(stmt)
-
(Sexp)-
Parameters:
-
stmt(Sexp) -- sexps to (maybe) rewrite
def find_inline_yield(stmt) found = nil case stmt.first when :js_return if found = find_inline_yield(stmt[1]) found = found[2] end when :array stmt[1..-1].each_with_index do |el, idx| if el.first == :yield found = el stmt[idx+1] = s(:js_tmp, '$yielded') end end when :call arglist = stmt[3] arglist[1..-1].each_with_index do |el, idx| if el.first == :yield found = el arglist[idx+1] = s(:js_tmp, '$yielded') end end end if found scope.add_temp '$yielded' unless scope.has_temp? '$yielded' s(:yasgn, '$yielded', found) end end
def raw_expression?(child)
def raw_expression?(child) ![:xstr, :dxstr].include?(child.type) end
def stmt_join
def stmt_join scope.class_scope? ? "\n\n#{current_indent}" : "\n#{current_indent}" end