Sha256: 176665512dec5de8294dbe1f1b91431005b13c4620b61e2c3e642e1c6ca1261f

Contents?: true

Size: 895 Bytes

Versions: 5

Compression:

Stored size: 895 Bytes

Contents

module Ruby2JS
  class Converter

    # (array
    #   (int 1)
    #   (int 2))

    handle :array do |*items|
      splat = items.rindex { |a| a.type == :splat }
      if splat
        item = items[splat].children.first
        if items.length == 1
          parse item
        elsif splat == items.length - 1
          parse s(:send, s(:array, *items[0..-2]), :concat, item)
        elsif splat == 0
          parse s(:send, item, :concat, s(:array, *items[1..-1]))
        else
          parse s(:send, 
            s(:send, s(:array, *items[0..splat-1]), :concat, item), 
            :concat, s(:array, *items[splat+1..-1]))
        end
      else
        items.map! { |item| parse item }
        if items.map {|item| item.length+2}.reduce(&:+).to_i < 72
          "[#{ items.join(', ') }]"
        else
          "[#@nl#{ items.join(",#@ws") }#@nl]"
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ruby2js-1.1.4 lib/ruby2js/converter/array.rb
ruby2js-1.1.3 lib/ruby2js/converter/array.rb
ruby2js-1.1.2 lib/ruby2js/converter/array.rb
ruby2js-1.1.1 lib/ruby2js/converter/array.rb
ruby2js-1.1.0 lib/ruby2js/converter/array.rb