All files / parser/nodes codeBlock.js

100% Statements 6/6
100% Branches 0/0
100% Functions 4/4
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 39 40 41 42 43 44 45                                      828x     828x                   828x         14x         7x    
import Node from './node';
import Scope from '../../scope/scope';
 
/**
 * Contains a series of statements.
 * 
 * This is used by the scope generator to determine where a new scope starts. If
 * this does not fit your needs but you need a scope, subclass this and call the
 * `statements:` field with null
 */
export default class CodeBlock extends Node {
    
    /**
     * Creates a scoped series of expressions
     * 
     * @param {Node[]} statements - the statements
     * @param {Object} position - a position from nearley
     */
    constructor (statements: any[], position: Object) {
        super(position);
        
        /** @type {Expression[]} */
        this.statements = statements;
        
        /**
         * This is a hashmap describing the child scope and it's variables. It
         * contains both variable information. This is primarially to be used by
         * `ScopeTransformer`, and all information in custom transformations
         * should be accessable through an `ASTTool`
         * 
         * @type {Scope}
         */
        this.scope = new Scope();
    }
    
    /** @override */
    get children() {
        return ['statements'];
    }
    
    /** @override */
    toString() {
        return `{\n${this.statements.map(i => "    " + i.toString().split("\n").join("\n    ")).join("\n")}\n}` 
    }
}