Sha256: cb4f7c7fa51aee4531547251accf3e7be9349455797cea8543f43e7f9ed3e359

Contents?: true

Size: 742 Bytes

Versions: 43

Compression:

Stored size: 742 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
        put "for (var "; parse var
        if [:irange, :erange].include? expression.type
          put ' = '; parse expression.children.first; put '; '; parse var
          (expression.type == :erange ? put(' < ') : put(' <= '))
          parse expression.children.last; put '; '; parse var; put '++'
        else
          put ' in '; parse expression; 
        end
        puts ') {'; scope block; sput '}'
      ensure
        @next_token = next_token
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
ruby2js-2.1.24 lib/ruby2js/converter/for.rb
ruby2js-2.1.23 lib/ruby2js/converter/for.rb
ruby2js-2.1.22 lib/ruby2js/converter/for.rb
ruby2js-2.1.21 lib/ruby2js/converter/for.rb
ruby2js-2.1.20 lib/ruby2js/converter/for.rb
ruby2js-2.1.19 lib/ruby2js/converter/for.rb
ruby2js-2.1.18 lib/ruby2js/converter/for.rb
ruby2js-2.1.17 lib/ruby2js/converter/for.rb
ruby2js-2.1.16 lib/ruby2js/converter/for.rb
ruby2js-2.1.15 lib/ruby2js/converter/for.rb
ruby2js-2.1.14 lib/ruby2js/converter/for.rb
ruby2js-2.1.13 lib/ruby2js/converter/for.rb
ruby2js-2.1.12 lib/ruby2js/converter/for.rb
ruby2js-2.1.11 lib/ruby2js/converter/for.rb
ruby2js-2.1.10 lib/ruby2js/converter/for.rb
ruby2js-2.1.9 lib/ruby2js/converter/for.rb
ruby2js-2.1.8 lib/ruby2js/converter/for.rb
ruby2js-2.1.7 lib/ruby2js/converter/for.rb
ruby2js-2.1.6 lib/ruby2js/converter/for.rb
ruby2js-2.1.5 lib/ruby2js/converter/for.rb