All files / parser/nodes typedIdentifier.js

100% Statements 5/5
50% Branches 1/2
100% Functions 3/3
100% Lines 5/5
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                                          14x     14x 14x         2x         1x    
import Node from './node';
 
/**
 * Represents an identifier and it's associated type. This node is usually used
 * for variable delcarations and such where a type is intrinsic to the parent
 * node.
 * 
 * `type` may be null and in that case the parent can specify for the type
 * inferrer to infer the type. The identifier 
 * 
 */
export default class TypedIdentifier extends Node {
    
    /**
     * Creates an identifier
     * 
     * @param {string} identifier - the identifier
     * @param {Type} type - the type of the identifier
     * @param {Object} position - a position from nearley
     */
    constructor (identifier: string, type: Type, position: Object) {
        super(position);
        
        /** @type {string} */
        this.identifier = identifier;
        this.type = type;
    }
    
    /** @override */
    get children() {
        return ['identifier', 'type'];
    }
    
    /** @override */
    toString() {
        return `${this.identifier}${this.type ? ": " + this.type : ""}`;
    }
}