class Opal::Rewriters::BinaryOperatorAssignment

Constants

ASSIGNMENT_STRING_NODE
ClassVariableHandler

Takes ‘@@lhs += rhs` Produces `@@lhs = @@lhs + rhs`

ConstantHandler

Takes ‘LHS += rhs` Produces `LHS = LHS + rhs`

GET_SET
GlobalVariableHandler

Takes ‘$lhs += rhs` Produces `$lhs = $lhs + rhs`

HANDLERS
InstanceVariableHandler

Takes ‘@lhs += rhs` Produces `@lhs = @lhs + rhs`

LocalVariableHandler

Takes ‘lhs += rhs` Produces `lhs = lhs + rhs`

Public Class Methods

new_temp() click to toggle source
# File lib/opal/rewriters/binary_operator_assignment.rb, line 12
def self.new_temp
  @@counter ||= 0
  @@counter += 1
  :"$binary_op_recvr_tmp_#{@@counter}"
end
reset_tmp_counter!() click to toggle source
# File lib/opal/rewriters/binary_operator_assignment.rb, line 8
def self.reset_tmp_counter!
  @@counter = 0
end

Public Instance Methods

on_defined?(node) click to toggle source

Rewrites any or_asgn and and_asgn node like

`defined?(a ||= 1)`

and

`defined?(a &&= 1)`

to a static “assignment” string node

Calls superclass method
# File lib/opal/rewriters/binary_operator_assignment.rb, line 131
def on_defined?(node)
  inner, _ = *node
  if inner.type == :op_asgn
    ASSIGNMENT_STRING_NODE
  else
    super(node)
  end
end
on_op_asgn(node) click to toggle source

lhs += rhs

# File lib/opal/rewriters/binary_operator_assignment.rb, line 114
def on_op_asgn(node)
  lhs, op, rhs = *node

  result = HANDLERS
           .fetch(lhs.type) { error "cannot handle LHS type: #{lhs.type}" }
           .call(node, lhs, op, rhs)

  process(result)
end