All files / transform transformationContext.js

25% Statements 1/4
0% Branches 0/2
50% Functions 1/2
25% Lines 1/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                                3x                                  
/**
 * Stores and manages a global context during transformation. This stores
 * information about primitives and other global items such as linkage which
 * passes can access through the `context` property on the transformer.
 */
export default class TransformationContext {
    /**
     * Creates a brand new TransformationContext. Pass an existing one to a
     * {@link Transformer} to use it.
     */
    constructor() {
        /**
         * A map of `id, key` of a primitive binding.
         *
         * @type {Map<string, ClassStatement[]>}
         */
        this.primitives = new Map();
    }
 
    /**
     * Adds a primitive link (e.g. Integer -> class Int) to the context.
     *
     * @param {string} name - the common ID of the primitive ID.
     * @param {ClassStatement} statement - The annotation's associated class.
     */
    addPrimitive(name: string, statement: ClassStatement) {
        if (this.primitives.get(name) instanceof Array) {
            this.primitives.get(name).push(statement);
        } else {
            this.primitives.set(name, [statement]);
        }
    }
}