Sha256: a6e1485beec00ab4e47f137f31837b71aefea5d7e00a71872024188c7d017a56

Contents?: true

Size: 869 Bytes

Versions: 34

Compression:

Stored size: 869 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
        if items.length <= 1
          put '['; parse_all(*items, join: ', '); put ']'
        else
          compact { puts '['; parse_all(*items, join: ",#{@ws}"); sput ']' }
        end
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
ruby2js-3.0.4 lib/ruby2js/converter/array.rb
ruby2js-3.0.3 lib/ruby2js/converter/array.rb
ruby2js-3.0.2 lib/ruby2js/converter/array.rb
ruby2js-3.0.1 lib/ruby2js/converter/array.rb
ruby2js-3.0.0 lib/ruby2js/converter/array.rb
ruby2js-2.1.24 lib/ruby2js/converter/array.rb
ruby2js-2.1.23 lib/ruby2js/converter/array.rb
ruby2js-2.1.22 lib/ruby2js/converter/array.rb
ruby2js-2.1.21 lib/ruby2js/converter/array.rb
ruby2js-2.1.20 lib/ruby2js/converter/array.rb
ruby2js-2.1.19 lib/ruby2js/converter/array.rb
ruby2js-2.1.18 lib/ruby2js/converter/array.rb
ruby2js-2.1.17 lib/ruby2js/converter/array.rb
ruby2js-2.1.16 lib/ruby2js/converter/array.rb
ruby2js-2.1.15 lib/ruby2js/converter/array.rb
ruby2js-2.1.14 lib/ruby2js/converter/array.rb
ruby2js-2.1.13 lib/ruby2js/converter/array.rb
ruby2js-2.1.12 lib/ruby2js/converter/array.rb
ruby2js-2.1.11 lib/ruby2js/converter/array.rb
ruby2js-2.1.10 lib/ruby2js/converter/array.rb