Sha256: 7e6da65b9259eba12d61a00970de0f58fda0c986ef00e7b2cf4893b807cf491a

Contents?: true

Size: 1.04 KB

Versions: 16

Compression:

Stored size: 1.04 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 ') {'; scope block; sput '}'
      ensure
        @next_token = next_token
        @vars = vars if es2015
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ruby2js-4.0.1 lib/ruby2js/converter/for.rb
ruby2js-4.0.0 lib/ruby2js/converter/for.rb
ruby2js-3.6.1 lib/ruby2js/converter/for.rb
ruby2js-3.6.0 lib/ruby2js/converter/for.rb
ruby2js-3.5.3 lib/ruby2js/converter/for.rb
ruby2js-3.5.2 lib/ruby2js/converter/for.rb
ruby2js-3.5.1 lib/ruby2js/converter/for.rb
ruby2js-3.5.0 lib/ruby2js/converter/for.rb
ruby2js-3.4.0 lib/ruby2js/converter/for.rb
ruby2js-3.3.6 lib/ruby2js/converter/for.rb
ruby2js-3.3.5 lib/ruby2js/converter/for.rb
ruby2js-3.3.4 lib/ruby2js/converter/for.rb
ruby2js-3.3.3 lib/ruby2js/converter/for.rb
ruby2js-3.3.2 lib/ruby2js/converter/for.rb
ruby2js-3.3.1 lib/ruby2js/converter/for.rb
ruby2js-3.3.0 lib/ruby2js/converter/for.rb