Class: Opal::Nodes::AndNode

Inherits:
BinaryOp show all
Defined in:
lib/opal/nodes/logic.rb

Instance Attribute Summary

Attributes inherited from Base

#compiler, #type

Instance Method Summary collapse

Methods inherited from BinaryOp

#compile

Methods inherited from Base

#add_gvar, #add_ivar, #add_local, #add_temp, children, #children, #class_variable_owner, #class_variable_owner_nesting_level, #comments, #compile, #compile_to_fragments, #error, #expr, #expr?, #expr_or_nil, #fragment, handle, handlers, #has_rescue_else?, #helper, #in_ensure, #in_ensure?, #in_while?, #initialize, #process, #push, #recv, #recv?, #s, #scope, #stmt, #stmt?, truthy_optimize?, #unshift, #while_loop, #with_temp, #wrap

Methods included from Helpers

#conditional_send, #current_indent, #empty_line, #indent, #js_falsy, #js_truthy, #js_truthy_optimize, #line, #mid_to_jsid, #property, #valid_name?

Constructor Details

This class inherits a constructor from Opal::Nodes::Base

Instance Method Details

#compile_ifObject


177
178
179
180
181
182
183
184
185
186
# File 'lib/opal/nodes/logic.rb', line 177

def compile_if
  helper :truthy
  condition = js_truthy_optimize(lhs) || expr(lhs)

  line 'if ($truthy(', condition, ')) {'
  indent { line expr(rhs) }
  line '} else {'
  indent { line expr(lhs) }
  line '}'
end

#compile_ternaryObject


160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/opal/nodes/logic.rb', line 160

def compile_ternary
  truthy_opt = nil

  with_temp do |tmp|
    if truthy_opt = js_truthy_optimize(lhs)
      push "((#{tmp} = ", truthy_opt
      push ') ? '
      push expr(rhs)
      push ' : ', expr(lhs), ')'
    else
      helper :truthy

      push "($truthy(#{tmp} = ", expr(lhs), ') ? ', expr(rhs), " : #{tmp})"
    end
  end
end