# Code coverage report for lib/parser/ast/base.js

## Statements: 100% (24 / 24) Branches: 100% (8 / 8) Functions: 100% (5 / 5) Lines: 100% (23 / 23) Ignored: none

All files » lib/parser/ast/ » base.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    611

    1
    8365
    8365

    1

    13409
    17728
    17728
    14328
    3432
    10896
    4584
    5044

    141

    141
    458
    139

    141

    458

    458
    317
    317

    1var protoclass = require("protoclass");

    function BaseExpression () {
      this._children = [];
      this._addChildren(Array.prototype.slice.call(arguments, 0));
    }

    protoclass(BaseExpression, {

      /**
       */

      __isExpression: true,

      /**
       */

      _addChildren: function (children) {
        for (var i = children.length; i--;) {
          var child = children[i];
          if (!child) continue;
          if (child.__isExpression) {
            this._children.push(child);
          } else if (typeof child === "object") {
            for (var k in child) {
              this._addChildren([child[k]]);
            }
          }
        }
      },

      /**
       */

      filterAllChildren: function (filter) {
        var filtered = [];

        this.traverseChildren(function (child) {
          if(filter(child)) {
            filtered.push(child);
          }
        });

        return filtered;
      },

      /**
       */

      traverseChildren: function (fn) {

        fn(this);

        for (var i = this._children.length; i--;) {
          var child = this._children[i];
          child.traverseChildren(fn);
        }
      }
    });

    module.exports = BaseExpression;