All files / vsl/parser/nodes annotation.js

75% Statements 3/4
50% Branches 2/4
50% Functions 1/2
75% Lines 3/4
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                                            10x     10x     10x                
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 */
    toString() {
        return `@${this.name}${this.args === null ? "" : `(${this.args.join(", ")})`}`;
    }
}