Sha256: 8f1c88b5d365492f943327082a6e6ba968716513451926b921033142c394ec06

Contents?: true

Size: 514 Bytes

Versions: 2

Compression:

Stored size: 514 Bytes

Contents

module Ruby2JS
  class Converter

    # (hash
    #   (pair
    #     (sym :name)
    #     (str "value")))

    handle :hash do |*pairs|
      pairs.map! do |node|
        left, right = node.children
        key = parse left
        key = $1 if key =~ /\A"([a-zA-Z_$][a-zA-Z_$0-9]*)"\Z/
        "#{key}: #{parse right}"
      end

      if pairs.map {|item| item.length+2}.reduce(&:+).to_i < 72
        "{#{ pairs.join(', ') }}"
      else
        "{#@nl#{ pairs.join(",#@ws") }#@nl}"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby2js-1.1.1 lib/ruby2js/converter/hash.rb
ruby2js-1.1.0 lib/ruby2js/converter/hash.rb