Sha256: 12d696dbeec60184d8668dc4f190070aadfd384f9a88914b3cccfa90e0b8b6f0

Contents?: true

Size: 861 Bytes

Versions: 10

Compression:

Stored size: 861 Bytes

Contents

module Ruby2JS
  class Converter

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

    handle :for, :for_of do |var, expression, block|
      begin
        vars = @vars.dup
        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
        @vars = vars if es2015
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ruby2js-3.1.0 lib/ruby2js/converter/for.rb
ruby2js-3.0.15 lib/ruby2js/converter/for.rb
ruby2js-3.0.14 lib/ruby2js/converter/for.rb
ruby2js-3.0.13 lib/ruby2js/converter/for.rb
ruby2js-3.0.12 lib/ruby2js/converter/for.rb
ruby2js-3.0.11 lib/ruby2js/converter/for.rb
ruby2js-3.0.10 lib/ruby2js/converter/for.rb
ruby2js-3.0.9 lib/ruby2js/converter/for.rb
ruby2js-3.0.8 lib/ruby2js/converter/for.rb
ruby2js-3.0.7 lib/ruby2js/converter/for.rb