Sha256: 86bdc10d4f8a1cd518b9d595867eae59c3c77ad0471ee66ede5717cd8abc6d04

Contents?: true

Size: 805 Bytes

Versions: 6

Compression:

Stored size: 805 Bytes

Contents

module Ruby2JS
  class Converter

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

    handle :for, :for_of do |var, expression, block|
      begin
        next_token, @next_token = @next_token, :continue
        put "for (#{es2015 ? 'let' : '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 (@ast.type==:for_of ? ' of ' : ' in '); parse expression; 
        end
        puts ') {'; scope block; sput '}'
      ensure
        @next_token = next_token
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby2js-3.0.5 lib/ruby2js/converter/for.rb
ruby2js-3.0.4 lib/ruby2js/converter/for.rb
ruby2js-3.0.3 lib/ruby2js/converter/for.rb
ruby2js-3.0.2 lib/ruby2js/converter/for.rb
ruby2js-3.0.1 lib/ruby2js/converter/for.rb
ruby2js-3.0.0 lib/ruby2js/converter/for.rb