eval method

  1. @override
Node eval(
  1. Contexts context
)
override

Compare (lvalue op rvalue) returning true or false (in this.evaluated)

Implementation

@override
Node eval(Contexts context) {
  //
  bool comparation(String op, Node aNode, Node bNode) {
    final a = aNode is Condition ? aNode.evaluated : false;
    final b = bNode is Condition ? bNode.evaluated : false;

    switch (op) {
      case 'and':
        return a && b;
      case 'or':
        return a || b;
      default:
        switch (Node.compareNodes(aNode, bNode)) {
          case -1:
            return op == '<' || op == '=<' || op == '<=';
          case 0:
            return op == '=' || op == '>=' || op == '=<' || op == '<=';
          case 1:
            return op == '>' || op == '>=';
          default:
            return false;
        }
    }
  }

  evaluated = comparation(op, lvalue.eval(context), rvalue.eval(context));
  evaluated = negate ? !evaluated : evaluated;
  return this; //this.evaluated was the js return

//2.3.1
//  Condition.prototype.eval = function (context) {
//      var result = (function (op, a, b) {
//          switch (op) {
//              case 'and': return a && b;
//              case 'or':  return a || b;
//              default:
//                  switch (Node.compare(a, b)) {
//                      case -1: return op === '<' || op === '=<' || op === '<=';
//                      case  0: return op === '=' || op === '>=' || op === '=<' || op === '<=';
//                      case  1: return op === '>' || op === '>=';
//                          default: return false;
//                  }
//          }
//      })(this.op, this.lvalue.eval(context), this.rvalue.eval(context));
//
//      return this.negate ? !result : result;
//  };
}