diff --git a/lib/ruby_parser/bm_sexp.rb b/lib/ruby_parser/bm_sexp.rb index bba287f6a5882ae5f9319129b151a8786ffbc2d7..3cd793ab8bc46d46cfbd446f5a72071f5da372c9 100644 --- a/lib/ruby_parser/bm_sexp.rb +++ b/lib/ruby_parser/bm_sexp.rb @@ -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 diff --git a/test/tests/test_sexp.rb b/test/tests/test_sexp.rb index 2de7b9a530fbac93855fe887d97634686c0e3e2b..b4bdf68d51e558dcb2a40d915bd5563a4ae9e919 100644 --- a/test/tests/test_sexp.rb +++ b/test/tests/test_sexp.rb @@ -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