class Opal::Rewriters::LogicalOperatorAssignment
Constants
- ASSIGNMENT_STRING_NODE
- ClassVariableHandler
Takes ‘@@lhs ||= rhs` Produces `@@lhs = defined?(@@lhs) ? (@@lhs || rhs) : rhs`
Takes ‘@@lhs &&= rhs` Produces `@@lhs = @@lhs && rhs`
- ConstantHandler
Takes ‘LHS ||= rhs` Produces `LHS = defined?(LHS) ? (LHS || rhs) : rhs`
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/logical_operator_assignment.rb, line 12 def self.new_temp @@counter ||= 0 @@counter += 1 :"$logical_op_recvr_tmp_#{@@counter}" end
reset_tmp_counter!()
click to toggle source
# File lib/opal/rewriters/logical_operator_assignment.rb, line 8 def self.reset_tmp_counter! @@counter = 0 end
Public Instance Methods
on_and_asgn(node)
click to toggle source
lhs &&= rhs
# File lib/opal/rewriters/logical_operator_assignment.rb, line 140 def on_and_asgn(node) lhs, rhs = *node result = HANDLERS .fetch(lhs.type) { error "cannot handle LHS type: #{lhs.type}" } .call(lhs, rhs, :and) process(result) end
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/logical_operator_assignment.rb, line 157 def on_defined?(node) inner, _ = *node if %i[or_asgn and_asgn].include?(inner.type) ASSIGNMENT_STRING_NODE else super(node) end end
on_or_asgn(node)
click to toggle source
lhs ||= rhs
# File lib/opal/rewriters/logical_operator_assignment.rb, line 129 def on_or_asgn(node) lhs, rhs = *node result = HANDLERS .fetch(lhs.type) { error "cannot handle LHS type: #{lhs.type}" } .call(lhs, rhs, :or) process(result) end