class Opal::Nodes::IfNode
def could_become_switch_branch?(body)
def could_become_switch_branch?(body) if !body return true elsif body.type != :if if valid_switch_body?(body) body.meta[:switch_default] = true return true end return false end test, true_body, false_body = *body test_match = SWITCH_BRANCH_TEST_MATCH.match(test) || SWITCH_BRANCH_TEST_MATCH_CONTINUED.match(test) unless test_match if valid_switch_body?(body, true) body.meta[:switch_default] = true return true end end switch_test, switch_variable, additional_rules = *test_match switch_additional_rules = handle_additional_switch_rules(additional_rules) return false unless switch_additional_rules # It's ok for them to be empty, but false denotes a mismatch return false unless switch_variable == @switch_variable return false unless valid_switch_body?(true_body) return false unless could_become_switch_branch?(false_body) body.meta.merge!(switch_child: true, switch_test: switch_test, switch_variable: @switch_variable, switch_additional_rules: switch_additional_rules ) true end