Code coverage report for src/node-transformers/control-flow-transformers/control-flow-replacers/ExpressionWithOperatorControlFlowReplacer.ts

# All files / src/node-transformers/control-flow-transformers/control-flow-replacers ExpressionWithOperatorControlFlowReplacer.ts

94.12% Statements 16/17
75% Branches 3/4
100% Functions 1/1
92.86% Lines 13/14

    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
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    721x
    1x

    1x
    1x
    1x

    1x

    4030x

    4030x

    6631x

    6631x

    6631x

    6631x

    6631x

     import { injectable, inject } from 'inversify';
    import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';

    import * as ESTree from 'estree';

    import { TCustomNodeFactory } from '../../../types/container/TCustomNodeFactory';
    import { TStatement } from '../../../types/node/TStatement';

    import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
    import { IOptions } from '../../../interfaces/options/IOptions';

    import { AbstractControlFlowReplacer } from './AbstractControlFlowReplacer';
    import { CustomNodes } from '../../../enums/container/CustomNodes';
    import { Node } from '../../../node/Node';

    @injectable()
    export abstract class ExpressionWithOperatorControlFlowReplacer extends AbstractControlFlowReplacer {
        /**
         * @type {TCustomNodeFactory}
         */
        protected readonly customNodeFactory: TCustomNodeFactory;

        /**
         * @type {IOptions}
         */
        protected readonly options: IOptions;

        /**
         * @type {Map<string, Map<string, string[]>>}
         */
        protected readonly replacerDataByControlFlowStorageId: Map <string, Map<string, string[]>> = new Map();

        /**
         * @param customNodeFactory
         * @param options
         */
        constructor (
            @inject(ServiceIdentifiers.Factory__ICustomNode) customNodeFactory: TCustomNodeFactory,
            @inject(ServiceIdentifiers.IOptions) options: IOptions
        ) {
            super(customNodeFactory, options);
        }

        /**
         * @param controlFlowStorageId
         * @param storageKey
         * @param leftExpression
         * @param rightExpression
         * @returns {ESTree.Node}
         */
        protected getControlFlowStorageCallNode (
            controlFlowStorageId: string,
            storageKey: string,
            leftExpression: ESTree.Expression,
            rightExpression: ESTree.Expression
        ): ESTree.Node {
            const controlFlowStorageCallCustomNode: ICustomNode = this.customNodeFactory(
                CustomNodes.ExpressionWithOperatorControlFlowStorageCallNode
            );

            controlFlowStorageCallCustomNode.initialize(controlFlowStorageId, storageKey, leftExpression, rightExpression);

            const statementNode: TStatement = controlFlowStorageCallCustomNode.getNode()[0];

            Iif (!statementNode || !Node.isExpressionStatementNode(statementNode)) {
                throw new Error(`\`controlFlowStorageCallCustomNode.getNode()[0]\` should returns array with \`ExpressionStatement\` node`);
            }

            return statementNode.expression;
        }
    }