ruby2js 2.0.5 → 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- # traverse through potential "css proxy" style method calls
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
@@ -2,7 +2,7 @@ module Ruby2JS
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 2
4
4
  MINOR = 0
5
- TINY = 5
5
+ TINY = 6
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/ruby2js.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "ruby2js"
5
- s.version = "2.0.5"
5
+ s.version = "2.0.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sam Ruby"]
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ruby2js
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.0.5
5
+ version: 2.0.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sam Ruby