All files / vsl/scope scopeItem.js

75% Statements 3/4
100% Branches 0/0
50% Functions 1/2
75% Lines 3/4
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                                    192x             192x                     192x                                
/**
 * A generic scope item, specifying primarially the value of any identifier.
 * This specifies behavior for type matching and also getting and setting the
 * scope item, used for type checking. It should hold information and be
 * compliant for type inference if applicable.
 * 
 * @abstract
 */
export default class ScopeItem {
    /**
     * @param {string} rootId - the root identifier in a declarations
     */
    constructor(rootId: string) {
        /**
         * The string name of the scope item
         * 
         * @type {string}
         */
        this.rootId = rootId;
        
        /**
         * All items which reference this scope item
         * 
         * @type {Node[]}
         */
        this.references = []
        
        /**
         * The type of the given item. For:
         * 
         *  - ScopeItem -> ScopeTypeItem
         *  - ScopeFuncItem -> ScopeTypeItem (function)
         *  - ScopeTypeItem -> ScopeMetaClass
         * 
         * @type {ScopeItem}
         */
        this.type = null;
    }
    
    /**
     * Determines whether two `ScopeItem`s matches eachother. You can use this
     * to verify a candidate matches the prototype.
     * 
     * @param {ScopeItem} ref - The value of the other scope item. It will
     *     be of the same subclass
     * @return {bool} Indicates whether or not the `signature` is the same.
     * 
     * @abstract
     */
    equal(ref: ScopeItem): boolean {
        return ref.rootId === this.rootId; 
    }
}