Sha256: 0283a6db3680ed93e89641d2761e7266b23cb95589252591591adfa4f8bf7292

Contents?: true

Size: 1.05 KB

Versions: 19

Compression:

Stored size: 1.05 KB

Contents

module Ruby2JS
  class Converter

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

    handle :for, :for_of do |var, expression, block|
      if @jsx and @ast.type == :for_of
        parse s(:block, s(:send, expression, :map),
         s(:args, s(:arg, var.children[0])),
         s(:autoreturn, block))
        return
      end

      begin
        vars = @vars.dup
        next_token, @next_token = @next_token, :continue
        put "for (#{es2015 ? 'let' : 'var'} "; parse var
        if expression and [: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 ') {'; redoable block; sput '}'
      ensure
        @next_token = next_token
        @vars = vars if es2015
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ruby2js-5.1.1 lib/ruby2js/converter/for.rb
ruby2js-5.1.0 lib/ruby2js/converter/for.rb
ruby2js-5.0.1 lib/ruby2js/converter/for.rb
ruby2js-5.0.0 lib/ruby2js/converter/for.rb
ruby2js-4.2.2 lib/ruby2js/converter/for.rb
ruby2js-4.2.1 lib/ruby2js/converter/for.rb
ruby2js-4.2.0 lib/ruby2js/converter/for.rb
ruby2js-4.1.7 lib/ruby2js/converter/for.rb
ruby2js-4.1.6 lib/ruby2js/converter/for.rb
ruby2js-4.1.5 lib/ruby2js/converter/for.rb
ruby2js-4.1.4 lib/ruby2js/converter/for.rb
ruby2js-4.1.3 lib/ruby2js/converter/for.rb
ruby2js-4.1.2 lib/ruby2js/converter/for.rb
ruby2js-4.1.1 lib/ruby2js/converter/for.rb
ruby2js-4.1.0 lib/ruby2js/converter/for.rb
ruby2js-4.0.5 lib/ruby2js/converter/for.rb
ruby2js-4.0.4 lib/ruby2js/converter/for.rb
ruby2js-4.0.3 lib/ruby2js/converter/for.rb
ruby2js-4.0.2 lib/ruby2js/converter/for.rb