All files / transform/passes RegisterClassDeclaration.js

0% Statements 0/11
0% Branches 0/4
0% Functions 0/2
0% Lines 0/11
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 58                                                                                                                   
import Transformation from '../transformation';
import TransformError from '../transformError';
import TokenType from '../../parser/vsltokentype';
import t from '../../parser/nodes';
 
import ScopeTypeItem from '../../scope/items/scopeTypeItem';
 
/**
 * Registers a class declaration. Does NOT register any of the child functions
 * or such.
 * 
 * This may call other registrars declared further down the line without this
 * being completed in terms of generation
 */
export default class TypeDeductAssignment extends Transformation {
    constructor() {
        super(t.ClassStatement, "Register::ClassDeclaration");
    }
    
    modify(node: Node, tool: ASTTool) {
        // The root class name (primary associate in scope)
        let rootId, generic = null;
        
        if (node.name instanceof t.GenericDeclaration) {
            rootId = name.type.identifier.rootId;
            // generic = 
        } else {
            rootId = node.name.identifier.rootId;
        }
        
        // The subscope
        let statements = node.statements;
        
        // ScopeTypeItems ths can be cast too
        let castables = []; 
        
        
        let type = new ScopeTypeItem(
            /*rootId:*/ rootId,
            /*subscope:*/ node.statements,
            {
                castables: castables,
                isInterface: false
            }
        );
        
        // Register the type in the parent scope
        let res = this.parentScope.scope.set(type);
        if (res === false) {
            throw new TransformError(
                "Redeclaration of class. This class has already been declared" +
                " somewhere else, give this a unique name or remove one of " +
                "the conflicting classes.",
                node
            );
        }
    }
}