Sha256: 9fef85b0ca141d9c522b4981138e63cce737164a7dcd069cbcdfb6e0116efefa

Contents?: true

Size: 985 Bytes

Versions: 3

Compression:

Stored size: 985 Bytes

Contents

module Ruby2JS
  class Converter

    # (block
    #   (send nil :x)
    #   (args
    #     (arg :a))
    #   (lvar :a))

    handle :block do |call, args, block|

      if
        @state == :statement and args.children.length == 1 and
        call.children.first and call.children.first.type == :begin and
        [:irange, :erange].include? call.children.first.children.first.type
      then
        var = args.children.first
        expression = call.children.first.children.first
        comp = (expression.type == :irange ? '<=' : '<')
        put "for (var "; parse var; put " = "; parse expression.children.first
        put "; "; parse var; put " #{comp} "; parse expression.children.last
        put "; "; parse var; put " += "; parse call.children[2]; puts ") {"
        scope block
        sput "}"
      else
        block ||= s(:begin)
        function = @ast.updated(:def, [nil, args, block])
        parse s(:send, *call.children, function)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby2js-2.0.2 lib/ruby2js/converter/block.rb
ruby2js-2.0.1 lib/ruby2js/converter/block.rb
ruby2js-2.0.0 lib/ruby2js/converter/block.rb