ruby2js 2.0.5 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/ruby2js/filter/react.rb +37 -1
- data/lib/ruby2js/version.rb +1 -1
- data/ruby2js.gemspec +1 -1
- metadata +1 -1
data/lib/ruby2js/filter/react.rb
CHANGED
@@ -437,6 +437,7 @@ module Ruby2JS
|
|
437
437
|
# React.createElement(*proc {
|
438
438
|
# var $_ = ['tag', hash]
|
439
439
|
# $_.push(React.createElement(...))
|
440
|
+
# return $_
|
440
441
|
# }())
|
441
442
|
#
|
442
443
|
# Base Ruby2JS processing will convert the 'splat' to 'apply'
|
@@ -645,8 +646,43 @@ module Ruby2JS
|
|
645
646
|
|
646
647
|
return super unless @react
|
647
648
|
|
648
|
-
#
|
649
|
+
# block calls to createElement
|
650
|
+
#
|
651
|
+
# collect block and apply. Intermediate representation
|
652
|
+
# will look something like the following:
|
653
|
+
#
|
654
|
+
# React.createElement(*proc {
|
655
|
+
# var $_ = ['tag', hash]
|
656
|
+
# $_.push(React.createElement(...))
|
657
|
+
# return $_
|
658
|
+
# }())
|
659
|
+
#
|
660
|
+
# Base Ruby2JS processing will convert the 'splat' to 'apply'
|
649
661
|
child = node.children.first
|
662
|
+
if
|
663
|
+
child.children[1] == :createElement and
|
664
|
+
child.children[0] == s(:const, nil, :React)
|
665
|
+
then
|
666
|
+
begin
|
667
|
+
reactApply, @reactApply = @reactApply, true
|
668
|
+
params = [s(:splat, s(:send, s(:block, s(:send, nil, :proc),
|
669
|
+
s(:args, s(:shadowarg, :$_)), s(:begin,
|
670
|
+
s(:lvasgn, :$_, s(:array, *child.children[2..-1])),
|
671
|
+
process(node.children[2]),
|
672
|
+
s(:return, s(:lvar, :$_)))), :[]))]
|
673
|
+
ensure
|
674
|
+
@reactApply = reactApply
|
675
|
+
end
|
676
|
+
|
677
|
+
if reactApply
|
678
|
+
return child.updated(:send, [s(:gvar, :$_), :push,
|
679
|
+
s(:send, *child.children[0..1], *params)])
|
680
|
+
else
|
681
|
+
return child.updated(:send, [*child.children[0..1], *params])
|
682
|
+
end
|
683
|
+
end
|
684
|
+
|
685
|
+
# traverse through potential "css proxy" style method calls
|
650
686
|
test = child.children.first
|
651
687
|
while test and test.type == :send and not test.is_method?
|
652
688
|
child, test = test, test.children.first
|
data/lib/ruby2js/version.rb
CHANGED
data/ruby2js.gemspec
CHANGED