All files / parser/nodes subscript.js

66.67% Statements 4/6
0% Branches 0/2
33.33% Functions 1/3
66.67% Lines 4/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                                    14x     14x     14x     14x                        
import Node from './node';
 
/**
 * Matches a subscript expression inside a PropertyExpression
 * 
 * @example
 * head[tail]
 */
 
export default class Subscript extends Node {
    /**
     * Creates a subscript
     * 
     * @param {Expression} head the object to subscript
     * @param {Expression} expression the provided expression
     * @param {Object} position a position from nearley
     */
    constructor (head: Expression, expression: Expression, nullable: boolean, position: Object) {
        super(position);
 
        /** @type {Expression} */
        this.head = head;
        
        /** @type {Expression} */
        this.expression = expression;
        
        /** @type {boolean} */
        this.nullable = nullable;
    }
    
    /** @override */
    get children () {
        return ['expression', 'nullable'];
    }
    
    /** @override */
    toString() {
        return `${this.nullable?'?':''}[${this.expression}]`;
    }
}