Sha256: 39f2e197ad35acea92f99552ece4f8fe981be8b4e679e787eaf02f67d7c6f559
Contents?: true
Size: 1.42 KB
Versions: 18
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 }#{ op }#{ op }" else "#{ op }#{ op }#{ parse var }" end else "#{ parse var } #{ 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
18 entries across 18 versions & 1 rubygems