Skip to content

Commit 87603af

Browse files
committed
support React stateless components
Fixes #130
1 parent d683438 commit 87603af

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# master
22

33
* Add chomp, delete_prefix, and delete_suffix support via ActiveFunctions
4+
* Support React stateless components
45

56
# 4.1.4 / 2021-05-08
67

lib/ruby2js/filter/react.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,13 @@ def on_xstr(node)
14921492
source = Ruby2JS.jsx2_rb(source)
14931493
ast = Ruby2JS.parse(source).first
14941494
ast = s(:block, s(:send, nil, :_), s(:args), ast) if ast.type == :begin
1495-
process ast
1495+
1496+
begin
1497+
react, @react = @react, @react || :react
1498+
process ast
1499+
ensure
1500+
@react = react
1501+
end
14961502
end
14971503
end
14981504

spec/react_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ def to_esm(string)
247247
must_include 'React.createElement(React.Fragment, null, ' +
248248
'React.createElement("p"), React.createElement("p"))'
249249
end
250+
251+
it "should handle stateless components" do
252+
to_js( 'Button = ->(x) { %x(<button>{x}</button>)}' ).
253+
must_equal 'var Button = function(x) {return React.createElement("button", null, x)}'
254+
end
250255
end
251256

252257
describe "render method" do

0 commit comments

Comments
 (0)