MCPcopy Create free account
hub / github.com/aurelia/binding / evaluate

Method evaluate

src/ast.js:436–489  ·  view source on GitHub ↗
(scope, lookupFunctions)

Source from the content-addressed store, hash-verified

434 }
435
436 evaluate(scope, lookupFunctions) {
437 let left = this.left.evaluate(scope, lookupFunctions);
438
439 switch (this.operation) {
440 case '&&': return left && this.right.evaluate(scope, lookupFunctions);
441 case '||': return left || this.right.evaluate(scope, lookupFunctions);
442 // no default
443 }
444
445 let right = this.right.evaluate(scope, lookupFunctions);
446
447 switch (this.operation) {
448 case '==' : return left == right; // eslint-disable-line eqeqeq
449 case '===': return left === right;
450 case '!=' : return left != right; // eslint-disable-line eqeqeq
451 case '!==': return left !== right;
452 case 'instanceof': return typeof right === 'function' && left instanceof right;
453 case 'in': return typeof right === 'object' && right !== null && left in right;
454 // no default
455 }
456
457 // Null check for the operations.
458 if (left === null || right === null || left === undefined || right === undefined) {
459 switch (this.operation) {
460 case '+':
461 if (left !== null && left !== undefined) return left;
462 if (right !== null && right !== undefined) return right;
463 return 0;
464 case '-':
465 if (left !== null && left !== undefined) return left;
466 if (right !== null && right !== undefined) return 0 - right;
467 return 0;
468 // no default
469 }
470
471 return null;
472 }
473
474 switch (this.operation) {
475 case '+' : return autoConvertAdd(left, right);
476 case '-' : return left - right;
477 case '*' : return left * right;
478 case '/' : return left / right;
479 case '%' : return left % right;
480 case '<' : return left < right;
481 case '>' : return left > right;
482 case '<=' : return left <= right;
483 case '>=' : return left >= right;
484 case '^' : return left ^ right;
485 // no default
486 }
487
488 throw new Error(`Internal error [${this.operation}] not handled`);
489 }
490
491 accept(visitor) {
492 return visitor.visitBinary(this);

Callers

nothing calls this directly

Calls 2

autoConvertAddFunction · 0.70
evaluateMethod · 0.45

Tested by

no test coverage detected