Code coverage report for src/container/modules/node-transformers/NodeControlFlowTransformersModule.ts

# All files / src/container/modules/node-transformers NodeControlFlowTransformersModule.ts

53.33% Statements 8/15
0% Branches 0/2
33.33% Functions 1/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
    411x
    1x

    1x

    1x

    1x
    2628x

    2628x

    2628x

     import { ContainerModule, interfaces } from 'inversify';
    import { ServiceIdentifiers } from '../../ServiceIdentifiers';

    import { IControlFlowReplacer } from '../../../interfaces/node-transformers/IControlFlowReplacer';

    import { NodeControlFlowTransformersReplacers } from '../../../enums/container/NodeControlFlowTransformersReplacers';

    import { BinaryExpressionControlFlowReplacer } from '../../../node-transformers/node-control-flow-transformers/control-flow-replacers/BinaryExpressionControlFlowReplacer';

    export const nodeControlFlowTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
        const nodeControlFlowTransformersReplacersTag: string = 'nodeControlFlowTransformersReplacers';

        bind<IControlFlowReplacer>(ServiceIdentifiers.IControlFlowReplacer)
            .to(BinaryExpressionControlFlowReplacer)
            .whenTargetTagged(
                nodeControlFlowTransformersReplacersTag,
                NodeControlFlowTransformersReplacers.BinaryExpressionControlFlowReplacer
            );

        bind<IControlFlowReplacer>(ServiceIdentifiers['Factory<IControlFlowReplacer>'])
            .toFactory<IControlFlowReplacer>((context: interfaces.Context) => {
                const cache: Map <NodeControlFlowTransformersReplacers, IControlFlowReplacer> = new Map <NodeControlFlowTransformersReplacers, IControlFlowReplacer> ();

                return (replacer: NodeControlFlowTransformersReplacers) => {
                    if (cache.has(replacer)) {
                        return <IControlFlowReplacer>cache.get(replacer);
                    }

                    const controlFlowReplacer: IControlFlowReplacer = context.container.getTagged<IControlFlowReplacer>(
                        ServiceIdentifiers.IControlFlowReplacer,
                        nodeControlFlowTransformersReplacersTag,
                        replacer
                    );

                    cache.set(replacer, controlFlowReplacer);

                    return controlFlowReplacer;
                };
            });
    });