Class: RKelly::Visitors::FunctionVisitor

Inherits:
Visitor
  • Object
show all
Defined in:
lib/rkelly/visitors/function_visitor.rb

Constant Summary

Constants inherited from Visitor

Visitor::ALL_NODES, Visitor::ARRAY_VALUE_NODES, Visitor::BINARY_NODES, Visitor::CONDITIONAL_NODES, Visitor::FUNC_CALL_NODES, Visitor::FUNC_DECL_NODES, Visitor::NAME_VALUE_NODES, Visitor::PREFIX_POSTFIX_NODES, Visitor::SINGLE_VALUE_NODES, Visitor::TERMINAL_NODES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Visitor

#accept, #visit_BracketAccessorNode, #visit_DotAccessorNode, #visit_ForInNode, #visit_ForNode, #visit_TryNode

Constructor Details

#initialize(scope) ⇒ FunctionVisitor

Returns a new instance of FunctionVisitor.



5
6
7
8
# File 'lib/rkelly/visitors/function_visitor.rb', line 5

def initialize(scope)
  super()
  @scope_chain = scope
end

Instance Attribute Details

#scope_chainObject (readonly)

Returns the value of attribute scope_chain.



4
5
6
# File 'lib/rkelly/visitors/function_visitor.rb', line 4

def scope_chain
  @scope_chain
end

Instance Method Details

#visit_FunctionDeclNode(o) ⇒ Object



14
15
16
17
18
# File 'lib/rkelly/visitors/function_visitor.rb', line 14

def visit_FunctionDeclNode(o)
  if o.value
    scope_chain[o.value].value = RKelly::JS::Function.new(o.function_body, o.arguments)
  end
end

#visit_SourceElementsNode(o) ⇒ Object



10
11
12
# File 'lib/rkelly/visitors/function_visitor.rb', line 10

def visit_SourceElementsNode(o)
  o.value.each { |x| x.accept(self) }
end