def process_if exp
if @ignore_ifs.nil?
@ignore_ifs = @tracker && @tracker.options[:ignore_ifs]
end
condition = exp.condition = process exp.condition
if true? condition
no_branch = true
exps = [exp.then_clause, nil]
elsif false? condition
no_branch = true
exps = [nil, exp.else_clause]
else
no_branch = false
exps = [exp.then_clause, exp.else_clause]
end
if @ignore_ifs or no_branch
exps.each_with_index do |branch, i|
exp[2 + i] = process_if_branch branch
end
else
if call? condition and condition.method == :!
condition = condition.target
exps.reverse!
end
was_inside = @inside_if
@inside_if = true
branch_scopes = []
exps.each_with_index do |branch, i|
scope do
@branch_env = env.current
branch_index = 2 + i
if i == 0 and array_include_all_literals? condition
var = condition.first_arg
previous_value = env.current[var]
env.current[var] = safe_literal(var.line)
exp[branch_index] = process_if_branch branch
env.current[var] = previous_value
elsif i == 1 and array_include_all_literals? condition and early_return? branch
var = condition.first_arg
env.current[var] = safe_literal(var.line)
exp[branch_index] = process_if_branch branch
else
exp[branch_index] = process_if_branch branch
end
branch_scopes << env.current
@branch_env = nil
end
end
@inside_if = was_inside
branch_scopes.each do |s|
merge_if_branch s
end
end
exp
end