All files / transform/passes DescribeClassDeclaration.js

50% Statements 8/16
25% Branches 1/4
66.67% Functions 2/3
53.33% Lines 8/15
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                        19x       1x 1x     1x 1x 1x         1x                               1x              
import Transformation from '../transformation';
import t from '../../parser/nodes';
 
import ScopeTypeItem from '../../scope/items/scopeTypeItem';
 
/**
 * A pre-processing entry for a class declaration. This goes top-down and
 * "registers" or adds the class to a global table of all items for at least
 * that scope.
 */
export default class DescribeClassDeclaration extends Transformation {
    constructor() {
        super(t.ClassStatement, "Describe::ClassDeclaration");
    }
    
    modify(node: Node, tool: ASTTool) {
        let scope = node.parentScope.scope;
        let rootId = node.name.identifier.rootId;
        
        // Okay do a lookup for these
        let parentRefs = node.superclasses;
        let parents = [];
        let options = {
            isInterface: false
        };
        
        // Transform 
        Iif (parentRefs !== null) {
            parentRefs.forEach((_, i) => {
                // Transform the children (i.e. resolve paths)
                tool.queueThenDeep(parentRefs[i], parentRefs, i, null);
                
                let candidateId = parentRefs[i].identifier.rootId;
                
                // Lookup
                let candidateResult = scope.get(new ScopeTypeItem(candidateId));
                if (candidateResult === null) parents.push(candidateId);
                else parents.push(candidateResult);
            });
            
            options.superclasses = parents;
        }
        
        scope.set(new ScopeTypeItem(
            rootId,
            node.statements.scope,
            options
        ));
    }
}