提交 4d603423 编写于 作者: J Justin

Merge pull request #150 from presidentbeef/more_method_missing_sexp

Fix uses of `method_missing` for Sexp
......@@ -35,12 +35,26 @@ class Sexp
self[0] = type
end
#Don't use this, please.
#:nodoc:
def resbody delete = false
#RubyParser relies on method_missing for this, but since we don't want to use
#method_missing, here's a real method.
#RubyParser and Ruby2Ruby rely on method_missing for this, but since we
#don't want to use method_missing, here's a real method.
find_node :resbody, delete
end
#Don't use this, please.
#:nodoc:
def lasgn delete = false
find_node :lasgn, delete
end
#Don't use this, please.
#:nodoc:
def iasgn delete = false
find_node :iasgn, delete
end
alias :node_type :sexp_type
alias :values :sexp_body # TODO: retire
......@@ -304,13 +318,16 @@ class Sexp
# s(:block, s(:lvar, :y), s(:call, nil, :z, s(:arglist))))
# ^-------------------- block --------------------------^
def block
expect :iter, :call_with_block, :scope
expect :iter, :call_with_block, :scope, :resbody
case self.node_type
when :iter, :call_with_block
self[3]
when :scope
self[1]
when :resbody
#This is for Ruby2Ruby ONLY
find_node :block
end
end
......
......@@ -243,4 +243,30 @@ class SexpTests < Test::Unit::TestCase
assert_equal s(:arglist, s(:lit, 1)), exp.arglist
assert_equal s(s(:lit, 1)), exp.args
end
def test_resbody_block
#Ruby2Ruby has calls like this which need to be supported
#for Brakeman::OutputProcessor
exp = parse "begin; rescue; end"
assert_nil exp.resbody.block
end
def test_lasgn
#Ruby2Ruby has calls like this which need to be supported
#for Brakeman::OutputProcessor
exp = parse "blah; x = 1"
assert_equal s(:lasgn, :x, s(:lit, 1)), exp.lasgn(true)
assert_equal nil, exp.lasgn #Was deleted
end
def test_iasgn
#Ruby2Ruby has calls like this which need to be supported
#for Brakeman::OutputProcessor
exp = parse "blah; @x = 1"
assert_equal s(:iasgn, :@x, s(:lit, 1)), exp.iasgn(true)
assert_equal nil, exp.iasgn #Was deleted
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册