All files / vsl/parser/nodes classStatement.js

75% Statements 6/8
20% Branches 2/10
33.33% Functions 1/3
75% Lines 6/8
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 43 44 45 46 47 48 49 50 51 52                                                    34x     34x 34x 34x 34x 34x                                    
import Node from './node';
import CodeBlock from './codeBlock';
 
/**
 * Wraps a class
 * 
 */
export default class ClassStatement extends Node {
    
    /**
     * Constructs a generic function statement
     * 
     * @param {string[]} access - The access modifiers of the node
     * @param {Identifier[]} superclass - The superclasses to inherit or implement
     * @param {Node[]} statements - The class's body.
     * @param {Annotation[]} annotations - The annotations of the class
     * @param {Object} position - a position from nearley
     */
    constructor(
        access: string[],
        name: Identifier,
        superclasses: Identifier[],
        statements: Node[],
        annotations: Annotation[],
        position: Object
    ) {
        super(position);
        
        /** @type {string} */
        this.access = access;
        this.name = name;
        this.superclasses = superclasses;
        this.statements = statements === null ? new CodeBlock([]) : statements;
        this.annotations = annotations || [];
    }
    
    /** @override */
    toString() {
        return `${this.annotations.join("\n") + (this.annotations.length?" ":"")}`+
        `${this.access.join(" ")}${this.access.length ? " " : ""}class` +
        ` ${this.name}: ${
            this.superclasses === null ?
            "Object" : this.superclasses.join(", ")
        } ${this.statements}`
    }
    
    /** @override */
    get children() {
        return ['name', 'superclasses', 'statements'];
    }
}