Class: JsDuck::Js::Associator

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

Overview

Associates comments with syntax nodes.

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Associator

Returns a new instance of Associator.



9
10
11
12
13
14
15
# File 'lib/jsduck/js/associator.rb', line 9

def initialize(input)
  @input = input

  # Initialize line number counting
  @start_index = 0
  @start_linenr = 1
end

Instance Method Details

#associate(ast) ⇒ Object

Analyzes the comments and AST nodes and returns array of hashes like this:

{
    :comment => "The contents of the comment",
    :code => {...AST data structure for code following the comment...},
    :linenr => 12,  // Beginning with 1
    :type => :doc_comment, // or :plain_comment
}


27
28
29
30
31
32
# File 'lib/jsduck/js/associator.rb', line 27

def associate(ast)
  @ast = ast

  @ast["comments"] = merge_comments(@ast["comments"])
  locate_comments
end