/* @flow */

import type Token from '../Token';
import type Node from '../Node';
import type Element from '../Element';
import type ElementAssert from '../ElementAssert';
import Statement from '../Statement';
import Traverse from '../../Traverse';

export default class Program extends Statement {
    constructor(childNodes: Array<any>) {
        super('Program', childNodes);

        this._isProgram = true;
        this._searchIndex = new Traverse();
        this._searchIndex.addElements(childNodes);
    }

    _searchIndex: Traverse;
    _body: Array<any>;
    _isProgram: boolean;

    _acceptChildren(children: ElementAssert) {
        if (children.isToken('Hashbang')) {
            children.passToken('Hashbang');
        }

        children.skipNonCode();

        let body = [];
        while (children.isStatement()) {
            body.push(children.passStatement());
            children.skipNonCode();
        }

        children.passToken('EOF');
        children.assertEnd();

        this._body = body;
    }

    /**
     * Returns node list with specified type from the tree.
     *
     * @param {String} type
     * @returns {Node[]}
     */
    selectNodesByType(type: string): Array<Node> {
        return this._searchIndex.selectNodesByType(type);
    }

    /**
     * Returns tokens list with specified type from the tree.
     *
     * @param {String} type
     * @returns {Token[]}
     */
    selectTokensByType(type: string): Array<Token> {
        return this._searchIndex.selectTokensByType(type);
    }

    _addElementsToSearchIndex(elements: Array<Element>) {
        this._searchIndex.addElements(elements);
    }

    _removeElementsFromSearchIndex(elements: Array<Element>) {
        this._searchIndex.removeElements(elements);
    }

    get body(): Array<any> {
        return this._body.concat();
    }
}

@@ -418,27 +418,24 @@
   this._
-searchIndex
+traverse
  = new T
@@ -455,35 +455,32 @@
       this._
-searchIndex
+traverse
 .addElements
@@ -505,27 +505,24 @@
 %7D%0A%0A    _
-searchIndex
+traverse
 : Traver
@@ -1217,35 +1217,32 @@
 eturn this._
-searchIndex
+traverse
 .selectNodes
@@ -1475,27 +1475,24 @@
 n this._
-searchIndex
+traverse
 .selectT
@@ -1589,27 +1589,24 @@
   this._
-searchIndex
+traverse
 .addElem
@@ -1709,19 +1709,16 @@
 is._
-searchIndex
+traverse
 .rem

Rename internal property