Sha256: 38e8040a69c791c40d3195700e57762d6ccbfb362a52da53fe456d73fba33d05

Contents?: true

Size: 1.42 KB

Versions: 56

Compression:

Stored size: 1.42 KB

Contents

module Ruby2JS
  class Converter

    # (op-asgn
    #   (lvasgn :a) :+
    #   (int 1))

    # NOTE: and-asgn and or_asgn handled below

    handle :op_asgn do |var, op, value|
      var = s(:ivar, var.children.first) if var.type == :ivasgn
      var = s(:lvar, var.children.first) if var.type == :lvasgn
      var = s(:cvar, var.children.first) if var.type == :cvasgn

      if [:+, :-].include?(op) and value.type==:int and value.children==[1]
        if @state == :statement
          parse var; put "#{ op }#{ op }"
        else
          put "#{ op }#{ op }"; parse var
        end
      else
        parse var; put " #{ op }= "; parse value
      end
    end

    # (or-asgn
    #   (lvasgn :a)
    #   (int 1))

    # (and-asgn
    #   (lvasgn :a)
    #   (int 1))

    handle :or_asgn, :and_asgn do |asgn, value|
      type = (@ast.type == :and_asgn ? :and : :or)

      vtype = nil
      vtype = :lvar if asgn.type == :lvasgn
      vtype = :ivar if asgn.type == :ivasgn
      vtype = :cvar if asgn.type == :cvasgn
      
      if vtype
        parse s(asgn.type, asgn.children.first, s(type, 
          s(vtype, asgn.children.first), value))
      elsif asgn.type == :send and asgn.children[1] == :[]
        parse s(:send, asgn.children.first, :[]=,
          asgn.children[2], s(type, asgn, value))
      else
        parse s(:send, asgn.children.first, "#{asgn.children[1]}=",
          s(type, asgn, value))
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
ruby2js-2.1.16 lib/ruby2js/converter/opasgn.rb
ruby2js-2.1.15 lib/ruby2js/converter/opasgn.rb
ruby2js-2.1.14 lib/ruby2js/converter/opasgn.rb
ruby2js-2.1.13 lib/ruby2js/converter/opasgn.rb
ruby2js-2.1.12 lib/ruby2js/converter/opasgn.rb
ruby2js-2.1.11 lib/ruby2js/converter/opasgn.rb
ruby2js-2.1.10 lib/ruby2js/converter/opasgn.rb
ruby2js-2.1.9 lib/ruby2js/converter/opasgn.rb
ruby2js-2.1.8 lib/ruby2js/converter/opasgn.rb
ruby2js-2.1.7 lib/ruby2js/converter/opasgn.rb
ruby2js-2.1.6 lib/ruby2js/converter/opasgn.rb
ruby2js-2.1.5 lib/ruby2js/converter/opasgn.rb
ruby2js-2.1.4 lib/ruby2js/converter/opasgn.rb
ruby2js-2.1.3 lib/ruby2js/converter/opasgn.rb
ruby2js-2.1.2 lib/ruby2js/converter/opasgn.rb
ruby2js-2.1.1 lib/ruby2js/converter/opasgn.rb
ruby2js-2.1.0 lib/ruby2js/converter/opasgn.rb
ruby2js-2.0.18 lib/ruby2js/converter/opasgn.rb
ruby2js-2.0.17 lib/ruby2js/converter/opasgn.rb
ruby2js-2.0.16 lib/ruby2js/converter/opasgn.rb