# 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
    61
    621

    1
    8527
    8527

    1

    13628
    18038
    18038
    14592
    3490
    11102
    4746
    5101

    149

    149
    465
    142

    149

    465

    465
    316
    316

    1
     var 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;