Class: Opal::Nodes::WhenNode
Constant Summary
Constants included from Helpers
Helpers::BASIC_IDENTIFIER_RULES , Helpers::ES3_RESERVED_WORD_EXCLUSIVE , Helpers::ES51_RESERVED_WORD , Helpers::IMMUTABLE_PROPS , Helpers::PROTO_SPECIAL_METHODS , Helpers::PROTO_SPECIAL_PROPS
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#add_gvar , #add_ivar , #add_local , #add_temp , children , #children , #compile_to_fragments , #error , #expr , #expr? , #expr_or_nil , #fragment , handle , handlers , #helper , #in_while? , #initialize , #process , #push , #recv , #recv? , #s , #scope , #stmt , #stmt? , truthy_optimize? , #unshift , #while_loop , #with_temp , #wrap
Methods included from Helpers
#current_indent , #empty_line , #indent , #ivar , #js_falsy , #js_truthy , #js_truthy_optimize , #line , #lvar_to_js , #mid_to_jsid , #property , #valid_ivar_name? , #valid_name? , #variable
Constructor Details
This class inherits a constructor from Opal::Nodes::Base
Instance Method Details
#body_code ⇒ Object
91 92 93
# File 'opal/lib/opal/nodes/case.rb', line 91 def body_code body || s(:nil) end
#case_stmt ⇒ Object
87 88 89
# File 'opal/lib/opal/nodes/case.rb', line 87 def case_stmt compiler.case_stmt end
#compile ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
# File 'opal/lib/opal/nodes/case.rb', line 60 def compile push "if (" when_checks.each_with_index do |check, idx| push ' || ' unless idx == 0 if check.type == :splat push "(function($splt) { for (var i = 0; i < $splt.length; i++) {" push "if ($splt[i]['$===']($case)) { return true; }" push "} return false; })(", expr(check[1]), ")" else if case_stmt[:cond] call = s(:call, check, :===, s(:arglist, s(:js_tmp, '$case'))) push expr(call) else push js_truthy(check) end end end push ") {", process(body_code, @level), "}" end
#when_checks ⇒ Object
83 84 85
# File 'opal/lib/opal/nodes/case.rb', line 83 def when_checks whens.children end