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

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

100% Statements 18/18
100% Branches 2/2
100% Functions 3/3
100% Lines 18/18

    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
    451x
    1x

    1x

    1x
    1x
    1x

    1x
    2463x

    2463x

    2463x

    2463x

    838x

    838x
    5531x
    4270x

    1261x

    1261x

    1261x

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

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

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

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

    export const nodeControlFlowTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
        bind<IControlFlowReplacer>(ServiceIdentifiers.IControlFlowReplacer)
            .to(BinaryExpressionControlFlowReplacer)
            .whenTargetNamed(NodeControlFlowReplacers.BinaryExpressionControlFlowReplacer);

        bind<IControlFlowReplacer>(ServiceIdentifiers.IControlFlowReplacer)
            .to(CallExpressionControlFlowReplacer)
            .whenTargetNamed(NodeControlFlowReplacers.CallExpressionControlFlowReplacer);

        bind<IControlFlowReplacer>(ServiceIdentifiers.IControlFlowReplacer)
            .to(LogicalExpressionControlFlowReplacer)
            .whenTargetNamed(NodeControlFlowReplacers.LogicalExpressionControlFlowReplacer);

        bind<IControlFlowReplacer>(ServiceIdentifiers.Factory__IControlFlowReplacer)
            .toFactory<IControlFlowReplacer>((context: interfaces.Context) => {
                const cache: Map <NodeControlFlowReplacers, IControlFlowReplacer> = new Map();

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

                    const controlFlowReplacer: IControlFlowReplacer = context.container.getNamed<IControlFlowReplacer>(
                        ServiceIdentifiers.IControlFlowReplacer,
                        replacerName
                    );

                    cache.set(replacerName, controlFlowReplacer);

                    return controlFlowReplacer;
                };
            });
    });