Class: JsDuck::Js::NodeArray

Inherits:
Object
  • Object
show all
Defined in:
lib/jsduck/js/node_array.rb

Overview

Wraps around array of AST nodes.

Instance Method Summary collapse

Constructor Details

#initialize(nodes) ⇒ NodeArray

Initialized with array of AST Hashes from Esprima.



9
10
11
# File 'lib/jsduck/js/node_array.rb', line 9

def initialize(nodes)
  @nodes = nodes || []
end

Instance Method Details

#[](i) ⇒ Object

Returns a child AST node as AstNode class.



14
15
16
# File 'lib/jsduck/js/node_array.rb', line 14

def [](i)
  Js::Node.create(@nodes[i])
end

#eachObject

Iterates over all the AstNodes in array.



24
25
26
# File 'lib/jsduck/js/node_array.rb', line 24

def each
  @nodes.each {|p| yield(Js::Node.create(p)) }
end

#lengthObject

The length of array



19
20
21
# File 'lib/jsduck/js/node_array.rb', line 19

def length
  @nodes.length
end

#mapObject

Maps over all the AstNodes in array.



29
30
31
# File 'lib/jsduck/js/node_array.rb', line 29

def map
  @nodes.map {|p| yield(Js::Node.create(p)) }
end