Class: Opal::Nodes::AndNode

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

Constant Summary

Constants included from Helpers

Helpers::BASIC_IDENTIFIER_RULES, Helpers::ES3_RESERVED_WORD_EXCLUSIVE, Helpers::ES51_RESERVED_WORD, Helpers::IMMUTABLE_PROPS, Helpers::PROTO_SPECIAL_METHODS, Helpers::PROTO_SPECIAL_PROPS, Helpers::RESERVED_FUNCTION_NAMES

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, #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

#current_indent, #empty_line, #indent, #ivar, #js_falsy, #js_truthy, #js_truthy_optimize, #line, #lvar_to_js, #mid_to_jsid, #property, #valid_ivar_name?, #valid_name?, #variable

Constructor Details

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

Instance Method Details

#compile_ifObject



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'opal/lib/opal/nodes/logic.rb', line 186

def compile_if
  with_temp do |tmp|
    if truthy_opt = js_truthy_optimize(lhs)
      push "if (#{tmp} = ", truthy_opt, ") {"
    else
      push "if (#{tmp} = ", expr(lhs), ", #{tmp} !== false && #{tmp} !== nil && #{tmp} != null) {"
    end
    indent do
      line expr(rhs)
    end
    line "} else {"
    indent do
      line expr(lhs)
    end
    line "}"
  end
end

#compile_ternaryObject



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'opal/lib/opal/nodes/logic.rb', line 167

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
      push "(#{tmp} = "
      push expr(lhs)
      push ", #{tmp} !== false && #{tmp} !== nil && #{tmp} != null ?"
      push expr(rhs)
      push " : #{tmp})"
    end
  end
end