agsamantha/node_modules/jintr/dist/nodes/LogicalExpression.js
2024-10-02 15:15:21 -05:00

22 lines
884 B
JavaScript

import BaseJSNode from './BaseJSNode.js';
export default class LogicalExpression extends BaseJSNode {
run() {
const operator = this.node.operator;
switch (operator) {
case '&&': {
const left_side = this.visitor.visitNode(this.node.left);
if (left_side === true)
return this.visitor.visitNode(this.node.right);
return left_side;
}
case '||': {
const left_side = this.visitor.visitNode(this.node.left);
return left_side || this.visitor.visitNode(this.node.right);
}
case '??': {
const left_side = this.visitor.visitNode(this.node.left);
return left_side !== null && left_side !== void 0 ? left_side : this.visitor.visitNode(this.node.right);
}
}
}
}