class Opal::Nodes::ResBodyNode

def compile

def compile
  push "if ("
  if rescue_exprs.empty?
    # if no expressions are given, then catch all errors
    push "true"
  else
    push "$opal.$rescue($err, ["
    rescue_exprs.each_with_index do |rexpr, idx|
      push ', ' unless idx == 0
      push expr(rexpr)
    end
    push "])"
  end
  push ") {"
  if variable = rescue_variable
    variable[2] = s(:js_tmp, '$err')
    push expr(variable), ';'
  end
  line process(rescue_body, @level)
  line "}"
end

def rescue_body

def rescue_body
  body || s(:nil)
end

def rescue_exprs

def rescue_exprs
  exprs = args.dup
  exprs.pop if rescue_variable?(exprs.last)
  exprs.children
end

def rescue_variable

def rescue_variable
  rescue_variable?(args.last) ? args.last.dup : nil
end

def rescue_variable?(variable)

def rescue_variable?(variable)
  Sexp === variable and [:lasgn, :iasgn].include?(variable.type)
end