condition.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var tslib_1 = require("tslib");
  4. var node_1 = tslib_1.__importDefault(require("./node"));
  5. var Condition = function (op, l, r, i, negate) {
  6. this.op = op.trim();
  7. this.lvalue = l;
  8. this.rvalue = r;
  9. this._index = i;
  10. this.negate = negate;
  11. };
  12. Condition.prototype = Object.assign(new node_1.default(), {
  13. type: 'Condition',
  14. accept: function (visitor) {
  15. this.lvalue = visitor.visit(this.lvalue);
  16. this.rvalue = visitor.visit(this.rvalue);
  17. },
  18. eval: function (context) {
  19. var result = (function (op, a, b) {
  20. switch (op) {
  21. case 'and': return a && b;
  22. case 'or': return a || b;
  23. default:
  24. switch (node_1.default.compare(a, b)) {
  25. case -1:
  26. return op === '<' || op === '=<' || op === '<=';
  27. case 0:
  28. return op === '=' || op === '>=' || op === '=<' || op === '<=';
  29. case 1:
  30. return op === '>' || op === '>=';
  31. default:
  32. return false;
  33. }
  34. }
  35. })(this.op, this.lvalue.eval(context), this.rvalue.eval(context));
  36. return this.negate ? !result : result;
  37. }
  38. });
  39. exports.default = Condition;
  40. //# sourceMappingURL=condition.js.map