提交 4119d1e3 编写于 作者: J Justin Collins

Make Hash.new into a hash

上级 b49b665b
......@@ -75,6 +75,7 @@ class Brakeman::AliasProcessor < Brakeman::SexpProcessor
end
ARRAY_CONST = s(:const, :Array)
HASH_CONST = s(:const, :Hash)
#Process a method call.
def process_call exp
......@@ -98,10 +99,10 @@ class Brakeman::AliasProcessor < Brakeman::SexpProcessor
if node_type? target, :or and [:+, :-, :*, :/].include? method
res = process_or_simple_operation(exp)
return res if res
end
if target == ARRAY_CONST and method == :new
elsif target == ARRAY_CONST and method == :new
return Sexp.new(:array, *exp.args)
elsif target == HASH_CONST and method == :new and first_arg.nil? and !node_type?(@exp_context.last, :iter, :call_with_block)
return Sexp.new(:hash)
end
#See if it is possible to simplify some basic cases
......@@ -193,7 +194,9 @@ class Brakeman::AliasProcessor < Brakeman::SexpProcessor
end
def process_call_with_block exp
@exp_context.push exp
exp[1] = process exp.block_call
@exp_context.pop
env.scope do
exp.block_args.each do |e|
......
......@@ -133,6 +133,15 @@ class AliasProcessorTests < Test::Unit::TestCase
RUBY
end
def test_hash_new_index
assert_alias "'You say goodbye, I say :hello'", <<-RUBY
x = Hash.new
x[:hello] = "hello world"
x.merge! :goodbye => "You say goodbye, I say :hello"
x[:goodbye]
RUBY
end
def test_obvious_if
assert_alias "'Yes!'", <<-RUBY
condition = true
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册