All files / parser/nodes classStatement.js

100% Statements 8/8
50% Branches 4/8
100% Functions 3/3
100% Lines 8/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 53 54 55 56 57                                                      35x     35x   35x   35x   35x   35x         1x                   2x      
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} name - The name of the class
     * @param {Identifier[]} superclasses - 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;
        /** @type {Identifier} */
        this.name = name;
        /** @type {Identifier[]} */
        this.superclasses = superclasses;
        /** @type {Node[]} */
        this.statements = statements;
        /** @type {Annotation[]} */
        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', 'annotations'];
    }
}