All files / parser/nodes annotation.js

60% Statements 3/5
50% Branches 2/4
33.33% Functions 1/3
60% Lines 3/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 39 40 41 42                                            20x     20x     20x                          
import Node from './node';
 
/**
 * Matches a decorator/annotation, an array of these is kept inside a class or
 * whatever node it is applied too.
 * 
 * @example
 * @foo(bar)
 *
 * @example
 * foo(bar)
 */
 
export default class Annotation extends Node {
    /**
     * Creates an annotation
     * 
     * @param {string} name - name of the annotation
     * @param {?Node[]} args - The arguments (if exist) of it.
     * @param {Object} position - A position from nearley
     */
    constructor(name: string, args: Node[], position: Object) {
        super(position);
 
        /** @type {string} */
        this.name = name;
 
        /** @type {?Node[]} */
        this.args = args || null;
    }
 
    /** @override */
    get children() {
        return null;
    }
    
    /** @override */
    toString() {
        return `@${this.name}${this.args === null ? "" : `(${this.args.join(", ")})`}`;
    }
}