ruby2js 2.0.14 → 2.0.15
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.
- checksums.yaml +4 -4
- data/lib/ruby2js/converter/args.rb +1 -1
- data/lib/ruby2js/converter/array.rb +2 -2
- data/lib/ruby2js/converter/begin.rb +1 -1
- data/lib/ruby2js/converter/class.rb +10 -9
- data/lib/ruby2js/converter/cvar.rb +1 -0
- data/lib/ruby2js/converter/ivar.rb +3 -3
- data/lib/ruby2js/converter/return.rb +2 -2
- data/lib/ruby2js/converter/send.rb +6 -8
- data/lib/ruby2js/converter/vasgn.rb +1 -1
- data/lib/ruby2js/converter/xstr.rb +1 -1
- data/lib/ruby2js/converter.rb +9 -3
- data/lib/ruby2js/filter/angularrb.rb +6 -5
- data/lib/ruby2js/filter/functions.rb +2 -2
- data/lib/ruby2js/filter/jquery.rb +24 -19
- data/lib/ruby2js/filter/minitest-jasmine.rb +14 -9
- data/lib/ruby2js/filter/react.rb +38 -30
- data/lib/ruby2js/filter/require.rb +6 -1
- data/lib/ruby2js/serializer.rb +5 -3
- data/lib/ruby2js/version.rb +1 -1
- data/lib/ruby2js.rb +2 -4
- data/ruby2js.gemspec +3 -3
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 656fbf21438b096f37a606de1a6d3bf19a55bb5b
         | 
| 4 | 
            +
              data.tar.gz: 1251eeab90080384e8d97257184129a77859a69e
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: ddfbded6bfafa9e257f1ab8dc3a309f12381e2a0edf7e76cca328d7d0ebf279f3a02775cac1c22ad5762094efa30cc3a49be03620e8aa8cf79ffccfe4ae54d6e
         | 
| 7 | 
            +
              data.tar.gz: 45116a4d10458125e78b3589ca25e51c5e1b115ffe6202b649d70fbd59bac5a6bf06cee8b155f7a41c8d05d6c3f85d4174ec360ede27ecaae9c2658664458bde
         | 
| @@ -22,9 +22,9 @@ module Ruby2JS | |
| 22 22 | 
             
                    end
         | 
| 23 23 | 
             
                  else
         | 
| 24 24 | 
             
                    if items.length <= 1
         | 
| 25 | 
            -
                      put '['; parse_all | 
| 25 | 
            +
                      put '['; parse_all(*items, join: ', '); put ']'
         | 
| 26 26 | 
             
                    else
         | 
| 27 | 
            -
                      compact { puts '['; parse_all | 
| 27 | 
            +
                      compact { puts '['; parse_all(*items, join: ",#{@ws}"); sput ']' }
         | 
| 28 28 | 
             
                    end
         | 
| 29 29 | 
             
                  end
         | 
| 30 30 | 
             
                end
         | 
| @@ -75,8 +75,8 @@ module Ruby2JS | |
| 75 75 |  | 
| 76 76 | 
             
                    elsif m.type == :send and m.children.first == nil
         | 
| 77 77 | 
             
                      if m.children[1] == :attr_accessor
         | 
| 78 | 
            -
                        m.children[2..-1].map do | | 
| 79 | 
            -
                          var =  | 
| 78 | 
            +
                        m.children[2..-1].map do |child_sym|
         | 
| 79 | 
            +
                          var = child_sym.children.first
         | 
| 80 80 | 
             
                          s(:prop, s(:attr, name, :prototype), var =>
         | 
| 81 81 | 
             
                              {enumerable: s(:true), configurable: s(:true),
         | 
| 82 82 | 
             
                              get: s(:block, s(:send, nil, :proc), s(:args), 
         | 
| @@ -85,8 +85,8 @@ module Ruby2JS | |
| 85 85 | 
             
                                s(:ivasgn, :"@#{var}", s(:lvar, var)))})
         | 
| 86 86 | 
             
                        end
         | 
| 87 87 | 
             
                      elsif m.children[1] == :attr_reader
         | 
| 88 | 
            -
                        m.children[2..-1].map do | | 
| 89 | 
            -
                          var =  | 
| 88 | 
            +
                        m.children[2..-1].map do |child_sym|
         | 
| 89 | 
            +
                          var = child_sym.children.first
         | 
| 90 90 | 
             
                          s(:prop, s(:attr, name, :prototype), var =>
         | 
| 91 91 | 
             
                              {get: s(:block, s(:send, nil, :proc), s(:args), 
         | 
| 92 92 | 
             
                                s(:return, s(:ivar, :"@#{var}"))),
         | 
| @@ -94,8 +94,8 @@ module Ruby2JS | |
| 94 94 | 
             
                              configurable: s(:true)})
         | 
| 95 95 | 
             
                        end
         | 
| 96 96 | 
             
                      elsif m.children[1] == :attr_writer
         | 
| 97 | 
            -
                        m.children[2..-1].map do | | 
| 98 | 
            -
                          var =  | 
| 97 | 
            +
                        m.children[2..-1].map do |child_sym|
         | 
| 98 | 
            +
                          var = child_sym.children.first
         | 
| 99 99 | 
             
                          s(:prop, s(:attr, name, :prototype), var =>
         | 
| 100 100 | 
             
                              {set: s(:block, s(:send, nil, :proc), s(:args, s(:arg, var)), 
         | 
| 101 101 | 
             
                                s(:ivasgn, :"@#{var}", s(:lvar, var))),
         | 
| @@ -244,9 +244,10 @@ module Ruby2JS | |
| 244 244 | 
             
                          *descriptor.map { |key, value| s(:pair, s(:sym, key), value) }))
         | 
| 245 245 | 
             
                      else
         | 
| 246 246 | 
             
                        parse s(:send, s(:const, nil, :Object), :defineProperties,
         | 
| 247 | 
            -
                          obj, s(:hash, *props.map {| | 
| 248 | 
            -
                            s(:pair, s(:sym,  | 
| 249 | 
            -
                            s(: | 
| 247 | 
            +
                          obj, s(:hash, *props.map {|hprop, hdescriptor|
         | 
| 248 | 
            +
                            s(:pair, s(:sym, hprop), 
         | 
| 249 | 
            +
                            s(:hash, *hdescriptor.map {|key, value| 
         | 
| 250 | 
            +
                              s(:pair, s(:sym, key), value) }))}))
         | 
| 250 251 | 
             
                      end
         | 
| 251 252 | 
             
                    elsif @ast.type == :method
         | 
| 252 253 | 
             
                      parse s(:send, *args)
         | 
| @@ -14,10 +14,10 @@ module Ruby2JS | |
| 14 14 | 
             
                handle :hostvalue do |value|
         | 
| 15 15 | 
             
                  case value
         | 
| 16 16 | 
             
                  when Hash
         | 
| 17 | 
            -
                    parse s(:hash, *value.map {|key,  | 
| 18 | 
            -
                      s(:hostvalue,  | 
| 17 | 
            +
                    parse s(:hash, *value.map {|key, hvalue| s(:pair, s(:hostvalue, key), 
         | 
| 18 | 
            +
                      s(:hostvalue, hvalue))})
         | 
| 19 19 | 
             
                  when Array
         | 
| 20 | 
            -
                    parse s(:array, *value.map {| | 
| 20 | 
            +
                    parse s(:array, *value.map {|hvalue| s(:hostvalue, hvalue)})
         | 
| 21 21 | 
             
                  when String
         | 
| 22 22 | 
             
                    parse s(:str, value)
         | 
| 23 23 | 
             
                  when Integer
         | 
| @@ -44,8 +44,8 @@ module Ruby2JS | |
| 44 44 |  | 
| 45 45 | 
             
                      node = node.children[2] ? s(:autoreturn, node.children[2]) : nil
         | 
| 46 46 |  | 
| 47 | 
            -
                      conditions.each do |condition,  | 
| 48 | 
            -
                        node = s(:if, condition,  | 
| 47 | 
            +
                      conditions.each do |condition, cstatements| 
         | 
| 48 | 
            +
                        node = s(:if, condition, cstatements, node)
         | 
| 49 49 | 
             
                      end
         | 
| 50 50 | 
             
                    end
         | 
| 51 51 | 
             
                    block.push node
         | 
| @@ -16,8 +16,6 @@ module Ruby2JS | |
| 16 16 | 
             
                handle :send, :sendw, :attr, :call do |receiver, method, *args|
         | 
| 17 17 | 
             
                  ast = @ast
         | 
| 18 18 |  | 
| 19 | 
            -
                  width = ((ast.type == :sendw && !@nl.empty?) ? 0 : @width)
         | 
| 20 | 
            -
             | 
| 21 19 | 
             
                  # strip '!' and '?' decorations
         | 
| 22 20 | 
             
                  method = method.to_s[0..-2] if method =~ /\w[!?]$/
         | 
| 23 21 |  | 
| @@ -38,7 +36,7 @@ module Ruby2JS | |
| 38 36 | 
             
                    t2,m2,*args2 = receiver.children.first.children
         | 
| 39 37 | 
             
                    if not t2 and [:lambda, :proc].include? m2 and args2.length == 0
         | 
| 40 38 | 
             
                      (@state == :statement ? group(receiver) : parse(receiver))
         | 
| 41 | 
            -
                      put '('; parse_all | 
| 39 | 
            +
                      put '('; parse_all(*args, join: ', '); put ')'
         | 
| 42 40 | 
             
                      return
         | 
| 43 41 | 
             
                    end
         | 
| 44 42 | 
             
                  end
         | 
| @@ -68,10 +66,10 @@ module Ruby2JS | |
| 68 66 | 
             
                    parse s(:not, receiver)
         | 
| 69 67 |  | 
| 70 68 | 
             
                  elsif method == :[]
         | 
| 71 | 
            -
                    parse receiver; put '['; parse_all | 
| 69 | 
            +
                    parse receiver; put '['; parse_all(*args, join: ', '); put ']'
         | 
| 72 70 |  | 
| 73 71 | 
             
                  elsif method == :[]=
         | 
| 74 | 
            -
                    parse receiver; put '['; parse_all | 
| 72 | 
            +
                    parse receiver; put '['; parse_all(*args[0..-2], join: ', '); put '] = '
         | 
| 75 73 | 
             
                    parse args[-1]
         | 
| 76 74 |  | 
| 77 75 | 
             
                  elsif [:-@, :+@, :~, '~'].include? method
         | 
| @@ -133,7 +131,7 @@ module Ruby2JS | |
| 133 131 |  | 
| 134 132 | 
             
                      put "new "; parse receiver
         | 
| 135 133 | 
             
                      if ast.is_method?
         | 
| 136 | 
            -
                        put '('; parse_all | 
| 134 | 
            +
                        put '('; parse_all(*args, join: ', '); put ')'
         | 
| 137 135 | 
             
                      end
         | 
| 138 136 | 
             
                    elsif args.length == 1 and args.first.type == :send
         | 
| 139 137 | 
             
                      # accommodation for JavaScript like new syntax w/argument list
         | 
| @@ -179,9 +177,9 @@ module Ruby2JS | |
| 179 177 | 
             
                      put "#{ '.' if receiver && method}#{ method }"
         | 
| 180 178 |  | 
| 181 179 | 
             
                      if args.length <= 1
         | 
| 182 | 
            -
                        put "("; parse_all | 
| 180 | 
            +
                        put "("; parse_all(*args, join: ', '); put ')'
         | 
| 183 181 | 
             
                      else
         | 
| 184 | 
            -
                        compact { puts "("; parse_all | 
| 182 | 
            +
                        compact { puts "("; parse_all(*args, join: ",#@ws"); sput ')' }
         | 
| 185 183 | 
             
                      end
         | 
| 186 184 | 
             
                    end
         | 
| 187 185 | 
             
                  end
         | 
    
        data/lib/ruby2js/converter.rb
    CHANGED
    
    | @@ -37,10 +37,15 @@ module Ruby2JS | |
| 37 37 | 
             
                  @@handlers.each do |name|
         | 
| 38 38 | 
             
                    @handlers[name] = method("on_#{name}")
         | 
| 39 39 | 
             
                  end
         | 
| 40 | 
            -
                end
         | 
| 41 40 |  | 
| 42 | 
            -
             | 
| 43 | 
            -
                  @ | 
| 41 | 
            +
                  @state = nil
         | 
| 42 | 
            +
                  @block_this = nil
         | 
| 43 | 
            +
                  @block_depth = nil
         | 
| 44 | 
            +
                  @prop = nil
         | 
| 45 | 
            +
                  @instance_method = nil
         | 
| 46 | 
            +
                  @prototype = nil
         | 
| 47 | 
            +
                  @class_parent = nil
         | 
| 48 | 
            +
                  @class_name = nil
         | 
| 44 49 | 
             
                end
         | 
| 45 50 |  | 
| 46 51 | 
             
                def width=(width)
         | 
| @@ -117,6 +122,7 @@ module Ruby2JS | |
| 117 122 | 
             
                  handler.call(*ast.children)
         | 
| 118 123 | 
             
                ensure
         | 
| 119 124 | 
             
                  @ast = oldast
         | 
| 125 | 
            +
                  @state = oldstate
         | 
| 120 126 | 
             
                end
         | 
| 121 127 |  | 
| 122 128 | 
             
                def parse_all(*args)
         | 
| @@ -39,6 +39,7 @@ module Ruby2JS | |
| 39 39 | 
             
                    @ngAppUses = []
         | 
| 40 40 | 
             
                    @ngClassUses = []
         | 
| 41 41 | 
             
                    @ngClassOmit = []
         | 
| 42 | 
            +
                    @ngScope = nil
         | 
| 42 43 | 
             
                    super
         | 
| 43 44 | 
             
                  end
         | 
| 44 45 |  | 
| @@ -74,7 +75,7 @@ module Ruby2JS | |
| 74 75 |  | 
| 75 76 | 
             
                    # convert use calls into dependencies
         | 
| 76 77 | 
             
                    depends = @ngAppUses.map {|sym| s(:sym, sym)} + extract_uses(block)
         | 
| 77 | 
            -
                    depends = depends.map {| | 
| 78 | 
            +
                    depends = depends.map {|dnode| dnode.children.first.to_s}.uniq.sort.
         | 
| 78 79 | 
             
                      map {|sym| s(:str, sym)}
         | 
| 79 80 |  | 
| 80 81 | 
             
                    ngApp, @ngApp, @ngChildren = @ngApp, nil, nil
         | 
| @@ -129,7 +130,7 @@ module Ruby2JS | |
| 129 130 |  | 
| 130 131 | 
             
                      @ngClassUses -= @ngClassOmit + [name.children.last]
         | 
| 131 132 | 
             
                      args = @ngClassUses.map {|sym| s(:arg, sym)} + uses
         | 
| 132 | 
            -
                      args = args.map {| | 
| 133 | 
            +
                      args = args.map {|anode| anode.children.first.to_sym}.uniq.sort.
         | 
| 133 134 | 
             
                        map {|sym| s(:arg, sym)}
         | 
| 134 135 | 
             
                      @ngClassUses, @ngClassOmit = [], []
         | 
| 135 136 |  | 
| @@ -249,7 +250,7 @@ module Ruby2JS | |
| 249 250 | 
             
                    @ngClassUses -= @ngClassOmit
         | 
| 250 251 | 
             
                    args = node.children[1].children
         | 
| 251 252 | 
             
                    args += @ngClassUses.map {|sym| s(:arg, sym)} + extract_uses(block)
         | 
| 252 | 
            -
                    args = args.map {| | 
| 253 | 
            +
                    args = args.map {|anode| anode.children.first.to_sym}.uniq.sort.
         | 
| 253 254 | 
             
                      map {|sym| s(:arg, sym)}
         | 
| 254 255 |  | 
| 255 256 | 
             
                    node.updated :block, [target, s(:args, *args), s(:begin, *block)]
         | 
| @@ -322,7 +323,7 @@ module Ruby2JS | |
| 322 323 | 
             
                    @ngClassUses.delete call.children[2].children[0]
         | 
| 323 324 | 
             
                    args = process_all(node.children[1].children)
         | 
| 324 325 | 
             
                    args += @ngClassUses.map {|sym| s(:arg, sym)} + extract_uses(block)
         | 
| 325 | 
            -
                    args = args.map {| | 
| 326 | 
            +
                    args = args.map {|anode| anode.children.first.to_sym}.uniq.sort.
         | 
| 326 327 | 
             
                      map {|sym| s(:arg, sym)}
         | 
| 327 328 |  | 
| 328 329 | 
             
                    # construct a function
         | 
| @@ -578,7 +579,7 @@ module Ruby2JS | |
| 578 579 | 
             
                  def extract_uses(block)
         | 
| 579 580 | 
             
                    # find the block
         | 
| 580 581 | 
             
                    while block.length == 1 and block.first and block.first.type == :begin
         | 
| 581 | 
            -
                      block.push | 
| 582 | 
            +
                      block.push(*block.shift.children)
         | 
| 582 583 | 
             
                    end
         | 
| 583 584 |  | 
| 584 585 | 
             
                    # find use class method calls
         | 
| @@ -174,8 +174,6 @@ module Ruby2JS | |
| 174 174 |  | 
| 175 175 |  | 
| 176 176 | 
             
                    elsif method == :[]
         | 
| 177 | 
            -
                      index = args.first
         | 
| 178 | 
            -
             | 
| 179 177 | 
             
                      # resolve negative literal indexes
         | 
| 180 178 | 
             
                      i = proc do |index|
         | 
| 181 179 | 
             
                        if index.type == :int and index.children.first < 0
         | 
| @@ -186,6 +184,8 @@ module Ruby2JS | |
| 186 184 | 
             
                        end
         | 
| 187 185 | 
             
                      end
         | 
| 188 186 |  | 
| 187 | 
            +
                      index = args.first
         | 
| 188 | 
            +
             | 
| 189 189 | 
             
                      if not index
         | 
| 190 190 | 
             
                        super
         | 
| 191 191 |  | 
| @@ -65,6 +65,11 @@ module Ruby2JS | |
| 65 65 | 
             
                module JQuery
         | 
| 66 66 | 
             
                  include SEXP
         | 
| 67 67 |  | 
| 68 | 
            +
                  def initialize(*args)
         | 
| 69 | 
            +
                    @react = nil
         | 
| 70 | 
            +
                    super
         | 
| 71 | 
            +
                  end
         | 
| 72 | 
            +
             | 
| 68 73 | 
             
                  # map $$ to $
         | 
| 69 74 | 
             
                  def on_gvar(node)
         | 
| 70 75 | 
             
                    if node.children[0] == :$$
         | 
| @@ -109,32 +114,32 @@ module Ruby2JS | |
| 109 114 | 
             
                      domprops = %w(checked disabled readonly readOnly required)
         | 
| 110 115 |  | 
| 111 116 | 
             
                      stopProps = false
         | 
| 112 | 
            -
                      rewrite_tilda = proc do | | 
| 117 | 
            +
                      rewrite_tilda = proc do |tnode|
         | 
| 113 118 | 
             
                        # Example conversion:
         | 
| 114 119 | 
             
                        #   before:
         | 
| 115 120 | 
             
                        #    (send (send (send (send nil :a) :b) :c) :~)
         | 
| 116 121 | 
             
                        #   after:
         | 
| 117 122 | 
             
                        #    (send (send (send nil "$" (send nil :a)) :b) :c)
         | 
| 118 | 
            -
                        if  | 
| 119 | 
            -
                          stopProps = true if  | 
| 120 | 
            -
                          if  | 
| 123 | 
            +
                        if tnode.type == :send and tnode.children[0]
         | 
| 124 | 
            +
                          stopProps = true if tnode.children[1] == :[]
         | 
| 125 | 
            +
                          if tnode.children[1] == :~ and tnode.children[0].children[1] == :~
         | 
| 121 126 | 
             
                            # consecutive tildes
         | 
| 122 | 
            -
                            if  | 
| 123 | 
            -
                              result =  | 
| 127 | 
            +
                            if tnode.children[0].children[0].children[1] == :~
         | 
| 128 | 
            +
                              result = tnode.children[0].children[0].children[0]
         | 
| 124 129 | 
             
                            else
         | 
| 125 | 
            -
                              result = s(:attr,  | 
| 130 | 
            +
                              result = s(:attr, tnode.children[0].children[0], :~)
         | 
| 126 131 | 
             
                            end
         | 
| 127 132 | 
             
                            s(:attr, s(:attr, process(result), :~), :~)
         | 
| 128 133 | 
             
                          else
         | 
| 129 134 | 
             
                            # possible getter/setter
         | 
| 130 | 
            -
                            method =  | 
| 135 | 
            +
                            method = tnode.children[1]
         | 
| 131 136 | 
             
                            method = method.to_s.chomp('=') if method =~ /=$/
         | 
| 132 137 | 
             
                            method = :each! if method == :each
         | 
| 133 | 
            -
                            rewrite = [rewrite_tilda[ | 
| 134 | 
            -
                              method, * | 
| 135 | 
            -
                            if stopProps or props.include?  | 
| 136 | 
            -
                              rewrite[1] =  | 
| 137 | 
            -
                               | 
| 138 | 
            +
                            rewrite = [rewrite_tilda[tnode.children[0]], 
         | 
| 139 | 
            +
                              method, *tnode.children[2..-1]]
         | 
| 140 | 
            +
                            if stopProps or props.include? tnode.children[1]
         | 
| 141 | 
            +
                              rewrite[1] = tnode.children[1]
         | 
| 142 | 
            +
                              tnode.updated nil, rewrite
         | 
| 138 143 | 
             
                            elsif domprops.include? method.to_s
         | 
| 139 144 | 
             
                              method = :readOnly if method.to_s == 'readonly'
         | 
| 140 145 | 
             
                              s(:send, rewrite[0], :prop, s(:sym, method), *rewrite[2..-1]) 
         | 
| @@ -142,16 +147,16 @@ module Ruby2JS | |
| 142 147 | 
             
                              s(:send, *rewrite)
         | 
| 143 148 | 
             
                            end
         | 
| 144 149 | 
             
                          end
         | 
| 145 | 
            -
                        elsif  | 
| 150 | 
            +
                        elsif tnode.type == :block
         | 
| 146 151 | 
             
                          # method call with a block parameter
         | 
| 147 | 
            -
                           | 
| 148 | 
            -
                            * | 
| 149 | 
            -
                        elsif  | 
| 152 | 
            +
                          tnode.updated nil, [rewrite_tilda[tnode.children[0]],
         | 
| 153 | 
            +
                            *tnode.children[1..-1]]
         | 
| 154 | 
            +
                        elsif tnode.type == :array
         | 
| 150 155 | 
             
                          # innermost expression is an array
         | 
| 151 | 
            -
                          s(:send, nil, '$', * | 
| 156 | 
            +
                          s(:send, nil, '$', *tnode)
         | 
| 152 157 | 
             
                        else
         | 
| 153 158 | 
             
                          # innermost expression is a scalar
         | 
| 154 | 
            -
                          s(:send, nil, '$',  | 
| 159 | 
            +
                          s(:send, nil, '$', tnode)
         | 
| 155 160 | 
             
                        end
         | 
| 156 161 | 
             
                      end
         | 
| 157 162 |  | 
| @@ -5,6 +5,11 @@ module Ruby2JS | |
| 5 5 | 
             
                module MiniTestJasmine
         | 
| 6 6 | 
             
                  include SEXP
         | 
| 7 7 |  | 
| 8 | 
            +
                  def initialize(*args)
         | 
| 9 | 
            +
                    @jasmine_describe = nil
         | 
| 10 | 
            +
                    super
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
             | 
| 8 13 | 
             
                  RELOPS = [:<, :<=, :==, :>=, :>].
         | 
| 9 14 | 
             
                    map {|sym| Parser::AST::Node.new :sym, [sym]}
         | 
| 10 15 |  | 
| @@ -17,17 +22,17 @@ module Ruby2JS | |
| 17 22 | 
             
                      body = body.first.children
         | 
| 18 23 | 
             
                    end
         | 
| 19 24 |  | 
| 20 | 
            -
                    body = body.map do | | 
| 21 | 
            -
                      if  | 
| 25 | 
            +
                    body = body.map do |bnode|
         | 
| 26 | 
            +
                      if bnode.type == :def and bnode.children.first =~ /^test_/
         | 
| 22 27 | 
             
                        s(:block, s(:send, nil, :it, s(:str, 
         | 
| 23 | 
            -
                           | 
| 24 | 
            -
                          s(:args),  | 
| 25 | 
            -
                      elsif  | 
| 26 | 
            -
                        s(:block, s(:send, nil, :before), s(:args),  | 
| 27 | 
            -
                      elsif  | 
| 28 | 
            -
                        s(:block, s(:send, nil, :after), s(:args),  | 
| 28 | 
            +
                          bnode.children.first.to_s.sub(/^test_/, '').gsub('_', ' '))),
         | 
| 29 | 
            +
                          s(:args), bnode.children.last)
         | 
| 30 | 
            +
                      elsif bnode.type == :def and bnode.children.first == :setup
         | 
| 31 | 
            +
                        s(:block, s(:send, nil, :before), s(:args), bnode.children.last)
         | 
| 32 | 
            +
                      elsif bnode.type == :def and bnode.children.first == :teardown
         | 
| 33 | 
            +
                        s(:block, s(:send, nil, :after), s(:args), bnode.children.last)
         | 
| 29 34 | 
             
                      else
         | 
| 30 | 
            -
                         | 
| 35 | 
            +
                        bnode
         | 
| 31 36 | 
             
                      end
         | 
| 32 37 | 
             
                    end
         | 
| 33 38 |  | 
    
        data/lib/ruby2js/filter/react.rb
    CHANGED
    
    | @@ -63,6 +63,14 @@ module Ruby2JS | |
| 63 63 | 
             
                  ReactAttrMap = Hash[ReactAttrs.map {|name| [name.downcase, name]}]
         | 
| 64 64 | 
             
                  ReactAttrMap['for'] = 'htmlFor'
         | 
| 65 65 |  | 
| 66 | 
            +
                  def initialize(*args)
         | 
| 67 | 
            +
                    @react = nil
         | 
| 68 | 
            +
                    @reactApply = nil
         | 
| 69 | 
            +
                    @reactBlock = nil
         | 
| 70 | 
            +
                    @reactClass = nil
         | 
| 71 | 
            +
                    super
         | 
| 72 | 
            +
                  end
         | 
| 73 | 
            +
             | 
| 66 74 | 
             
                  def options=(options)
         | 
| 67 75 | 
             
                    super
         | 
| 68 76 | 
             
                    @react = true if options[:react]
         | 
| @@ -105,7 +113,7 @@ module Ruby2JS | |
| 105 113 | 
             
                      # collect static properties/functions
         | 
| 106 114 | 
             
                      statics = []
         | 
| 107 115 | 
             
                      body.select {|child| child.type == :defs}.each do |child|
         | 
| 108 | 
            -
                         | 
| 116 | 
            +
                        _parent, mname, args, *block = child.children
         | 
| 109 117 | 
             
                        if child.is_method?
         | 
| 110 118 | 
             
                          statics << s(:pair, s(:sym, mname), process(child.updated(:block,
         | 
| 111 119 | 
             
                            [s(:send, nil, :proc), args, s(:autoreturn, *block)])))
         | 
| @@ -181,8 +189,8 @@ module Ruby2JS | |
| 181 189 | 
             
                          end
         | 
| 182 190 |  | 
| 183 191 | 
             
                          # build a hash for state
         | 
| 184 | 
            -
                          state = s(:hash, *assigns.map {| | 
| 185 | 
            -
                             | 
| 192 | 
            +
                          state = s(:hash, *assigns.map {|anode| s(:pair, s(:str,
         | 
| 193 | 
            +
                            anode.children.first.to_s[1..-1]), anode.children.last)})
         | 
| 186 194 |  | 
| 187 195 | 
             
                          # modify block to build and/or return state
         | 
| 188 196 | 
             
                          if block.empty?
         | 
| @@ -567,53 +575,53 @@ module Ruby2JS | |
| 567 575 | 
             
                        end
         | 
| 568 576 | 
             
                      end
         | 
| 569 577 |  | 
| 570 | 
            -
                      rewrite_tilda = proc do | | 
| 578 | 
            +
                      rewrite_tilda = proc do |tnode|
         | 
| 571 579 | 
             
                        # Example conversion:
         | 
| 572 580 | 
             
                        #   before:
         | 
| 573 581 | 
             
                        #    (send (send nil :a) :text) :~)
         | 
| 574 582 | 
             
                        #   after:
         | 
| 575 583 | 
             
                        #    (send (gvar :$a))), :text)
         | 
| 576 | 
            -
                        if  | 
| 577 | 
            -
                          if  | 
| 584 | 
            +
                        if tnode.type == :send and tnode.children[0]
         | 
| 585 | 
            +
                          if tnode.children[1] == :~ and tnode.children[0].children[1] == :~
         | 
| 578 586 | 
             
                            # consecutive tildes
         | 
| 579 | 
            -
                            if  | 
| 580 | 
            -
                              result =  | 
| 587 | 
            +
                            if tnode.children[0].children[0].children[1] == :~
         | 
| 588 | 
            +
                              result = tnode.children[0].children[0].children[0]
         | 
| 581 589 | 
             
                            else
         | 
| 582 | 
            -
                              result = s(:attr,  | 
| 590 | 
            +
                              result = s(:attr, tnode.children[0].children[0], '~')
         | 
| 583 591 | 
             
                            end
         | 
| 584 592 | 
             
                            s(:attr, s(:attr, process(result), '~'), '~')
         | 
| 585 593 | 
             
                          else
         | 
| 586 594 | 
             
                            # possible getter/setter
         | 
| 587 | 
            -
                            method =  | 
| 595 | 
            +
                            method = tnode.children[1]
         | 
| 588 596 | 
             
                            method = method.to_s.chomp('=') if method =~ /=$/
         | 
| 589 | 
            -
                            rewrite = [rewrite_tilda[ | 
| 590 | 
            -
                              method, * | 
| 591 | 
            -
                            rewrite[1] =  | 
| 592 | 
            -
                             | 
| 597 | 
            +
                            rewrite = [rewrite_tilda[tnode.children[0]],
         | 
| 598 | 
            +
                              method, *tnode.children[2..-1]]
         | 
| 599 | 
            +
                            rewrite[1] = tnode.children[1]
         | 
| 600 | 
            +
                            tnode.updated nil, rewrite
         | 
| 593 601 | 
             
                          end
         | 
| 594 | 
            -
                        elsif  | 
| 602 | 
            +
                        elsif tnode.children.first == nil and Symbol === tnode.children[1]
         | 
| 595 603 | 
             
                          # innermost expression is a scalar
         | 
| 596 | 
            -
                          s(:gvar, "$#{ | 
| 597 | 
            -
                        elsif  | 
| 598 | 
            -
                          s(:gvar, "$#{ | 
| 599 | 
            -
                        elsif  | 
| 600 | 
            -
                          if  | 
| 604 | 
            +
                          s(:gvar, "$#{tnode.children[1]}")
         | 
| 605 | 
            +
                        elsif tnode.type == :lvar
         | 
| 606 | 
            +
                          s(:gvar, "$#{tnode.children[0]}")
         | 
| 607 | 
            +
                        elsif tnode.type == :str
         | 
| 608 | 
            +
                          if tnode.children.first =~ /^#[-\w]+$/
         | 
| 601 609 | 
             
                            s(:send, s(:attr, nil, :document), :getElementById,
         | 
| 602 | 
            -
                              s(:str,  | 
| 603 | 
            -
                          elsif  | 
| 610 | 
            +
                              s(:str, tnode.children.first[1..-1].gsub('_', '-')))
         | 
| 611 | 
            +
                          elsif tnode.children.first =~ /^(\.[-\w]+)+$/
         | 
| 604 612 | 
             
                            s(:send, s(:send, s(:attr, nil, :document),
         | 
| 605 613 | 
             
                              :getElementsByClassName, s(:str,
         | 
| 606 | 
            -
                               | 
| 614 | 
            +
                              tnode.children.first[1..-1].gsub('.', ' ').gsub('_', '-'))),
         | 
| 607 615 | 
             
                              :[], s(:int, 0))
         | 
| 608 | 
            -
                          elsif  | 
| 616 | 
            +
                          elsif tnode.children.first =~ /^[-\w]+$/
         | 
| 609 617 | 
             
                            s(:send, s(:send, s(:attr, nil, :document),
         | 
| 610 618 | 
             
                              :getElementsByTagName, s(:str,
         | 
| 611 | 
            -
                               | 
| 619 | 
            +
                              tnode.children.first.gsub('_', '-'))), :[], s(:int, 0))
         | 
| 612 620 | 
             
                          else
         | 
| 613 | 
            -
                            s(:send, s(:attr, nil, :document), :querySelector,  | 
| 621 | 
            +
                            s(:send, s(:attr, nil, :document), :querySelector, tnode)
         | 
| 614 622 | 
             
                          end
         | 
| 615 623 | 
             
                        else
         | 
| 616 | 
            -
                          s(:send, s(:attr, nil, :document), :querySelector,  | 
| 624 | 
            +
                          s(:send, s(:attr, nil, :document), :querySelector, tnode)
         | 
| 617 625 | 
             
                        end
         | 
| 618 626 | 
             
                      end
         | 
| 619 627 |  | 
| @@ -644,7 +652,7 @@ module Ruby2JS | |
| 644 652 | 
             
                          end
         | 
| 645 653 |  | 
| 646 654 | 
             
                          # if a hash argument is already passed, merge in id value
         | 
| 647 | 
            -
                          hash = children.find_index {| | 
| 655 | 
            +
                          hash = children.find_index {|cnode| cnode.type == :hash}
         | 
| 648 656 | 
             
                          if hash
         | 
| 649 657 | 
             
                            children[hash] = s(:hash, pair, *children[hash].children)
         | 
| 650 658 | 
             
                          else
         | 
| @@ -882,14 +890,14 @@ module Ruby2JS | |
| 882 890 | 
             
                      node.children[1].type == :block
         | 
| 883 891 | 
             
                    return if node.type == :defs
         | 
| 884 892 |  | 
| 885 | 
            -
                    child = node.children.first
         | 
| 886 | 
            -
             | 
| 887 893 | 
             
                    base = @reactIvars[:asgn].dup if [:if, :case].include? node.type
         | 
| 888 894 |  | 
| 889 895 | 
             
                    node.children.each do |child|
         | 
| 890 896 | 
             
                      react_walk(child) if Parser::AST::Node === child
         | 
| 891 897 | 
             
                    end
         | 
| 892 898 |  | 
| 899 | 
            +
                    child = node.children.first
         | 
| 900 | 
            +
             | 
| 893 901 | 
             
                    case node.type
         | 
| 894 902 | 
             
                    when :if, :case
         | 
| 895 903 | 
             
                      @reactIvars[:cond] += @reactIvars[:asgn] - base
         | 
| @@ -5,12 +5,17 @@ module Ruby2JS | |
| 5 5 | 
             
                module Require
         | 
| 6 6 | 
             
                  include SEXP
         | 
| 7 7 |  | 
| 8 | 
            -
                  @@valid_path = /\A[-\ | 
| 8 | 
            +
                  @@valid_path = /\A[-\w.]+\Z/
         | 
| 9 9 |  | 
| 10 10 | 
             
                  def self.valid_path=(valid_path)
         | 
| 11 11 | 
             
                    @@valid_path = valid_path
         | 
| 12 12 | 
             
                  end
         | 
| 13 13 |  | 
| 14 | 
            +
                  def initialize(*args)
         | 
| 15 | 
            +
                    @require_expr = nil
         | 
| 16 | 
            +
                    super
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
             | 
| 14 19 | 
             
                  def on_send(node)
         | 
| 15 20 | 
             
                    if
         | 
| 16 21 | 
             
                      not @require_expr and # only statements
         | 
    
        data/lib/ruby2js/serializer.rb
    CHANGED
    
    | @@ -52,6 +52,8 @@ module Ruby2JS | |
| 52 52 | 
             
                  @lines = [Line.new]
         | 
| 53 53 | 
             
                  @line = @lines.last
         | 
| 54 54 | 
             
                  @timestamps = {}
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                  @ast = nil
         | 
| 55 57 | 
             
                end
         | 
| 56 58 |  | 
| 57 59 | 
             
                def timestamp(file)
         | 
| @@ -222,7 +224,7 @@ module Ruby2JS | |
| 222 224 | 
             
                  # survey what we have to work with, keeping track of a possible
         | 
| 223 225 | 
             
                  # split of the last argument or value
         | 
| 224 226 | 
             
                  work = []
         | 
| 225 | 
            -
                   | 
| 227 | 
            +
                  len = 0
         | 
| 226 228 | 
             
                  trail = split = nil
         | 
| 227 229 | 
             
                  slice = @lines[mark.first..-1]
         | 
| 228 230 | 
             
                  reindent(slice)
         | 
| @@ -250,7 +252,7 @@ module Ruby2JS | |
| 250 252 | 
             
                    if slice[split[2]].indent < slice[split[2]+1].indent
         | 
| 251 253 | 
             
                      # collapse all but the last argument (typically a hash or function)
         | 
| 252 254 | 
             
                      close = slice.pop
         | 
| 253 | 
            -
                      slice[-1].push | 
| 255 | 
            +
                      slice[-1].push(*close)
         | 
| 254 256 | 
             
                      @lines[mark.first] = Line.new(*work[0..split[1]-1])
         | 
| 255 257 | 
             
                      @lines[mark.first+1..-1] = slice[split[2]+1..-1]
         | 
| 256 258 | 
             
                      @line = @lines.last
         | 
| @@ -260,7 +262,7 @@ module Ruby2JS | |
| 260 262 |  | 
| 261 263 | 
             
                # return the output as a string
         | 
| 262 264 | 
             
                def to_s
         | 
| 263 | 
            -
                  return @str if @str
         | 
| 265 | 
            +
                  return @str if (@str ||= nil)
         | 
| 264 266 | 
             
                  respace
         | 
| 265 267 | 
             
                  @lines.map(&:to_s).join(@nl)
         | 
| 266 268 | 
             
                end
         | 
    
        data/lib/ruby2js/version.rb
    CHANGED
    
    
    
        data/lib/ruby2js.rb
    CHANGED
    
    | @@ -24,6 +24,7 @@ module Ruby2JS | |
| 24 24 |  | 
| 25 25 | 
             
                  def initialize(comments)
         | 
| 26 26 | 
             
                    @comments = comments
         | 
| 27 | 
            +
                    @ast = nil
         | 
| 27 28 | 
             
                  end
         | 
| 28 29 |  | 
| 29 30 | 
             
                  def options=(options)
         | 
| @@ -130,10 +131,7 @@ module Ruby2JS | |
| 130 131 | 
             
              end
         | 
| 131 132 |  | 
| 132 133 | 
             
              def self.parse(source, file=nil)
         | 
| 133 | 
            -
                 | 
| 134 | 
            -
                buffer = Parser::Source::Buffer.new(file || '__SOURCE__')
         | 
| 135 | 
            -
                buffer.raw_source = source.encode('utf-8')
         | 
| 136 | 
            -
                Parser::CurrentRuby.new.parse_with_comments(buffer)
         | 
| 134 | 
            +
                Parser::CurrentRuby.parse_with_comments(source.encode('utf-8'))
         | 
| 137 135 | 
             
              rescue Parser::SyntaxError => e
         | 
| 138 136 | 
             
                split = source[0..e.diagnostic.location.begin_pos].split("\n")
         | 
| 139 137 | 
             
                line, col = split.length, split.last.length
         | 
    
        data/ruby2js.gemspec
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            -
            # stub: ruby2js 2.0. | 
| 2 | 
            +
            # stub: ruby2js 2.0.15 ruby lib
         | 
| 3 3 |  | 
| 4 4 | 
             
            Gem::Specification.new do |s|
         | 
| 5 5 | 
             
              s.name = "ruby2js"
         | 
| 6 | 
            -
              s.version = "2.0. | 
| 6 | 
            +
              s.version = "2.0.15"
         | 
| 7 7 |  | 
| 8 8 | 
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 9 9 | 
             
              s.require_paths = ["lib"]
         | 
| 10 10 | 
             
              s.authors = ["Sam Ruby"]
         | 
| 11 | 
            -
              s.date = "2016- | 
| 11 | 
            +
              s.date = "2016-07-30"
         | 
| 12 12 | 
             
              s.description = "    The base package maps Ruby syntax to JavaScript semantics.\n    Filters may be provided to add Ruby-specific or framework specific\n    behavior.\n"
         | 
| 13 13 | 
             
              s.email = "rubys@intertwingly.net"
         | 
| 14 14 | 
             
              s.files = ["README.md", "lib/ruby2js", "lib/ruby2js.rb", "lib/ruby2js/cgi.rb", "lib/ruby2js/converter", "lib/ruby2js/converter.rb", "lib/ruby2js/converter/arg.rb", "lib/ruby2js/converter/args.rb", "lib/ruby2js/converter/array.rb", "lib/ruby2js/converter/begin.rb", "lib/ruby2js/converter/block.rb", "lib/ruby2js/converter/blockpass.rb", "lib/ruby2js/converter/boolean.rb", "lib/ruby2js/converter/break.rb", "lib/ruby2js/converter/case.rb", "lib/ruby2js/converter/casgn.rb", "lib/ruby2js/converter/class.rb", "lib/ruby2js/converter/const.rb", "lib/ruby2js/converter/cvar.rb", "lib/ruby2js/converter/cvasgn.rb", "lib/ruby2js/converter/def.rb", "lib/ruby2js/converter/defined.rb", "lib/ruby2js/converter/defs.rb", "lib/ruby2js/converter/dstr.rb", "lib/ruby2js/converter/for.rb", "lib/ruby2js/converter/hash.rb", "lib/ruby2js/converter/if.rb", "lib/ruby2js/converter/in.rb", "lib/ruby2js/converter/ivar.rb", "lib/ruby2js/converter/ivasgn.rb", "lib/ruby2js/converter/kwbegin.rb", "lib/ruby2js/converter/literal.rb", "lib/ruby2js/converter/logical.rb", "lib/ruby2js/converter/masgn.rb", "lib/ruby2js/converter/module.rb", "lib/ruby2js/converter/next.rb", "lib/ruby2js/converter/nil.rb", "lib/ruby2js/converter/nthref.rb", "lib/ruby2js/converter/opasgn.rb", "lib/ruby2js/converter/prototype.rb", "lib/ruby2js/converter/regexp.rb", "lib/ruby2js/converter/return.rb", "lib/ruby2js/converter/self.rb", "lib/ruby2js/converter/send.rb", "lib/ruby2js/converter/super.rb", "lib/ruby2js/converter/sym.rb", "lib/ruby2js/converter/undef.rb", "lib/ruby2js/converter/until.rb", "lib/ruby2js/converter/untilpost.rb", "lib/ruby2js/converter/var.rb", "lib/ruby2js/converter/vasgn.rb", "lib/ruby2js/converter/while.rb", "lib/ruby2js/converter/whilepost.rb", "lib/ruby2js/converter/xstr.rb", "lib/ruby2js/execjs.rb", "lib/ruby2js/filter", "lib/ruby2js/filter/angular-resource.rb", "lib/ruby2js/filter/angular-route.rb", "lib/ruby2js/filter/angularrb.rb", "lib/ruby2js/filter/camelCase.rb", "lib/ruby2js/filter/functions.rb", "lib/ruby2js/filter/jquery.rb", "lib/ruby2js/filter/minitest-jasmine.rb", "lib/ruby2js/filter/react.rb", "lib/ruby2js/filter/require.rb", "lib/ruby2js/filter/return.rb", "lib/ruby2js/filter/rubyjs.rb", "lib/ruby2js/filter/strict.rb", "lib/ruby2js/filter/underscore.rb", "lib/ruby2js/rails.rb", "lib/ruby2js/serializer.rb", "lib/ruby2js/sinatra.rb", "lib/ruby2js/version.rb", "ruby2js.gemspec"]
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: ruby2js
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 2.0. | 
| 4 | 
            +
              version: 2.0.15
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Sam Ruby
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2016- | 
| 11 | 
            +
            date: 2016-07-30 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: parser
         |