All files / parser/nodes binaryExpression.js

83.33% Statements 5/6
100% Branches 0/0
66.67% Functions 2/3
83.33% Lines 5/6
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                                        55x     55x   55x   55x                   9x    
import Node from './node';
 
/**
 * Matches a binary expression
 * 
 * See Also: `UnaryExpression`
 * 
 * This matches any generic binary expression.
 */
export default class BinaryExpression extends Node {
    
    /**
     * Creates a wrapper ExpressionStatement
     * 
     * @param {Expression} lhs left-hand side of the expression
     * @param {Expression} rhs right-hand side of the expression
     * @param {string} operator the operator for the expression
     * @param {Object} position a position from nearley
     */
    constructor (lhs: Expression, rhs: Expression, operator: string, position: Object) {
        super(position);
        
        /** @type {Expression} */
        this.lhs = lhs;
        /** @type {Expression} */
        this.rhs = rhs;
        /** @type {string} */
        this.op = operator;
    }
    
    /** @override */
    get children() {
        return ['lhs', 'rhs'];
    }
    
    /** @override */
    toString() {
        return `(${this.lhs} ${this.op} ${this.rhs})`
    }
}