Sha256: 5f399b63a84ca75393e526a2b4943c68faf57f0ab9086cc1442deed43a33eee3

Contents?: true

Size: 955 Bytes

Versions: 22

Compression:

Stored size: 955 Bytes

Contents

module Ruby2JS
  class Converter

    # (xstr
    #   (str 'a'))
    # (for
    #   (lvasgn :i)
    #   (array
    #     (int 1))
    #   (...)

    handle :for do |var, expression, block|
      begin
        next_token, @next_token = @next_token, :continue
        if expression.type == :irange
          "for (var #{parse var} = #{ parse expression.children.first }; " +
            "#{ parse var } <= #{ parse expression.children.last }; " +
            "#{ parse var }++) {#@nl#{ scope block }#@nl}"
        elsif expression.type == :erange
          "for (var #{parse var} = #{ parse expression.children.first }; " +
            "#{ parse var } < #{ parse expression.children.last }; " +
            "#{ parse var }++) {#@nl#{ scope block }#@nl}"
        else
          "for (var #{parse var} in #{ parse expression }) " +
            "{#@nl#{ scope block }#@nl}"
        end
      ensure
        @next_token = next_token
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

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