Class: StyleScript::ExistenceNode

Inherits:
Node
  • Object
show all
Defined in:
lib/style_script/nodes.rb

Overview

Check an expression for existence (meaning not null or undefined).

Constant Summary

Constants inherited from Node

Node::TAB

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#children, children, #compile, #compile_closure, #contains?, #idt, statement, #statement?, statement_only, #statement_only?, top_sensitive, #top_sensitive?, #unwrap, #write

Constructor Details

#initialize(expression) ⇒ ExistenceNode

Returns a new instance of ExistenceNode.



959
960
961
# File 'lib/style_script/nodes.rb', line 959

def initialize(expression)
  @expression = expression
end

Class Method Details

.compile_test(o, variable) ⇒ Object



953
954
955
956
957
# File 'lib/style_script/nodes.rb', line 953

def self.compile_test(o, variable)
  first, second = variable, variable
  first, second = *variable.compile_reference(o) if variable.is_a?(CallNode)
  "(typeof #{first.compile(o)} !== \"undefined\" && #{second.compile(o)} !== null)"
end

Instance Method Details

#compile_node(o) ⇒ Object



963
964
965
# File 'lib/style_script/nodes.rb', line 963

def compile_node(o)
  write(ExistenceNode.compile_test(o, @expression))
end