Sha256: 80ac149bbbdc9d314e9c978589df450db5f32d6cf03432673392afd4e208727d

Contents?: true

Size: 550 Bytes

Versions: 28

Compression:

Stored size: 550 Bytes

Contents

module Ruby2JS
  class Converter

    # (case
    #   (send nil :a)
    #   (when
    #      (int 1)
    #      (...))
    #   (...))

    handle :case do |expr, *whens, other|
      whens.map! do |node|
        *values, code = node.children
        cases = values.map {|value| "case #{ parse value }:#@ws"}.join
        "#{ cases }#{ parse code, :statement }#{@sep}break#@sep"
      end

      other = "#{@nl}default:#@ws#{ parse other, :statement }#@nl" if other

      "switch (#{ parse expr }) {#@nl#{whens.join(@nl)}#{other}}"
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
ruby2js-1.15.1 lib/ruby2js/converter/case.rb
ruby2js-1.15.0 lib/ruby2js/converter/case.rb
ruby2js-1.14.1 lib/ruby2js/converter/case.rb
ruby2js-1.14.0 lib/ruby2js/converter/case.rb
ruby2js-1.13.1 lib/ruby2js/converter/case.rb
ruby2js-1.13.0 lib/ruby2js/converter/case.rb
ruby2js-1.12.2 lib/ruby2js/converter/case.rb
ruby2js-1.12.1 lib/ruby2js/converter/case.rb
ruby2js-1.12.0 lib/ruby2js/converter/case.rb
ruby2js-1.11.1 lib/ruby2js/converter/case.rb
ruby2js-1.11.0 lib/ruby2js/converter/case.rb
ruby2js-1.10.0 lib/ruby2js/converter/case.rb
ruby2js-1.9.3 lib/ruby2js/converter/case.rb
ruby2js-1.9.2 lib/ruby2js/converter/case.rb
ruby2js-1.9.1 lib/ruby2js/converter/case.rb
ruby2js-1.9.0 lib/ruby2js/converter/case.rb
ruby2js-1.8.0 lib/ruby2js/converter/case.rb
ruby2js-1.7.0 lib/ruby2js/converter/case.rb
ruby2js-1.6.0 lib/ruby2js/converter/case.rb
ruby2js-1.5.0 lib/ruby2js/converter/case.rb