Skip to content

Commit

Permalink
recover gradefully from empty render method
Browse files Browse the repository at this point in the history
  • Loading branch information
rubys committed Feb 26, 2015
1 parent 48809e4 commit b229965
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ruby2js/filter/react.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def on_class(node)
end

elsif mname == :render
if block.length != 1 or block.last.type == :begin
if block.length!=1 or not block.last or block.last.type==:begin
# wrap multi-line blocks with a 'div' element
block = [s(:return,
s(:block, s(:send, nil, :_div), s(:args), *block))]
Expand Down
10 changes: 10 additions & 0 deletions spec/react_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ def to_js(string)
result.must_include ', React.createElement("h1", null, "a"),'
result.must_include ', React.createElement("p", null, "b"))}})'
end

it "should insert a div if no elements are present" do
result = to_js( 'class Foo<React; def render; end; end' )
result.must_include 'return React.createElement("div")'
end

it "should insert a div if method is empty" do
result = to_js( 'class Foo<React; def render; end; end' )
result.must_include 'return React.createElement("div")'
end
end

describe "class attributes" do
Expand Down

0 comments on commit b229965

Please sign in to comment.