# Class: Traverser

Defined in: | node_modules/grunt-codo/node_modules/codo/lib/traverser.coffee

## Overview

The class takes CS nodes tree and recursively injects additional meta-data into it:

1. For each possible node it tries every registered entity and pushes an instance of it into tree if it suites. 2. For every suitable node it finds the suitable comment block respecting things like `this.` and `module.exports =` and links it to the tree as well.

Since the transformation is happening upside down, nested entities can interact with initialized parents (for instance a class can find parent class; method can find the class/mixin/file it belongs to).

## Class Method Summary

- . (void) read(file, environment)
- . (void) linkAncestors(node) Attach each parent to its children, so we are able to traverse the ancestor parse tree.
- . (void) convertComments(content, closure = false) Convert the comments to block comments, so they appear in the nodes.
- . (String) whitespace(n) Whitespace helper function

## Instance Method Summary

- # (void) prepare(node, file, Entity)
- # (Array<String>) leftTrimBlock(text) Detect whitespace on the left and removes the minimum whitespace ammount.
- # (void) inspect()

## Class Method Details

. (void) read(file, environment)

. (void) linkAncestors(node)

Attach each parent to its children, so we are able to traverse the ancestor parse tree. Since the parent attribute is already used in the class node, the parent is stored as `ancestor`.

### Parameters:

- nodes ( `Base` ) — the CoffeeScript nodes

. (void) convertComments(content, closure = false)

Convert the comments to block comments, so they appear in the nodes.

The methods replaces starting # symbols with invisible unicode whitespace to keep empty lines formatted.

### Parameters:

- content ( `String` ) — the CoffeeScript file content

. (String) whitespace(n)

Whitespace helper function

### Parameters:

- n ( `Number` ) — the number of spaces

### Returns:

- ( `String` ) — the space string

## Constructor Details

# (void) constructor(path, content, environment)

## Instance Method Details

# (void) prepare(node, file, Entity)

# (Array<String>) leftTrimBlock(text)

Detect whitespace on the left and removes the minimum whitespace ammount.

The method additionally drops invisible UTF whitespace introduced by `convertComments`

This will keep indention for examples intact.

### Examples:

#### left trim all lines

    leftTrimBlock(['', '  Escape at maximum speed.', '', '  @param (see #move)', '  '])
    => ['', 'Escape at maximum speed.', '', '@param (see #move)', '']

### Parameters:

- lines ( `Array<String>` ) — the comment lines

### Returns:

- ( `Array<String>` ) — lines left trimmed lines

# (void) inspect()

Quickly fuzzy find classes, mixins, methods, file:

- T Open fuzzy finder dialog

Control the navigation frame:

- L Toggle list view
- C Show class list
- I Show mixin list
- F Show file list
- M Show method list
- E Show extras list

You can focus and blur the search input:

- S Focus search input
- Esc Blur search input