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

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

97.22% Statements 35/36
50% Branches 1/2
100% Functions 3/3
97.22% Lines 35/36

    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    961x
    1x

    1x

    1x

    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x

    1x

    6271x

    6271x

    6271x

    6271x

    6271x

    6271x

    6271x

    6271x

    6271x

    6271x

    6271x

    6271x

    6271x

    6265x

    6265x
    70702x

    70702x

    70702x

    70702x

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

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

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

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

    import { BlockStatementControlFlowTransformer } from '../../../node-transformers/control-flow-transformers/BlockStatementControlFlowTransformer';
    import { CatchClauseTransformer } from '../../../node-transformers/obfuscating-transformers/CatchClauseTransformer';
    import { FunctionDeclarationTransformer } from '../../../node-transformers/obfuscating-transformers/FunctionDeclarationTransformer';
    import { FunctionTransformer } from '../../../node-transformers/obfuscating-transformers/FunctionTransformer';
    import { LabeledStatementTransformer } from '../../../node-transformers/obfuscating-transformers/LabeledStatementTransformer';
    import { LiteralTransformer } from '../../../node-transformers/obfuscating-transformers/LiteralTransformer';
    import { MemberExpressionTransformer } from '../../../node-transformers/converting-transformers/MemberExpressionTransformer';
    import { MethodDefinitionTransformer } from '../../../node-transformers/converting-transformers/MethodDefinitionTransformer';
    import { ObjectExpressionTransformer } from '../../../node-transformers/obfuscating-transformers/ObjectExpressionTransformer';
    import { TemplateLiteralTransformer } from '../../../node-transformers/converting-transformers/TemplateLiteralTransformer';
    import { VariableDeclarationTransformer } from '../../../node-transformers/obfuscating-transformers/VariableDeclarationTransformer';

    export const nodeTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
        // control flow transformers
        bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
            .to(BlockStatementControlFlowTransformer)
            .whenTargetNamed(NodeTransformers.BlockStatementControlFlowTransformer);

        bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
            .to(FunctionControlFlowTransformer)
            .whenTargetNamed(NodeTransformers.FunctionControlFlowTransformer);

        // converting transformers
        bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
            .to(MemberExpressionTransformer)
            .whenTargetNamed(NodeTransformers.MemberExpressionTransformer);

        bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
            .to(MethodDefinitionTransformer)
            .whenTargetNamed(NodeTransformers.MethodDefinitionTransformer);

        bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
            .to(TemplateLiteralTransformer)
            .whenTargetNamed(NodeTransformers.TemplateLiteralTransformer);

        // obfuscation transformers
        bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
            .to(CatchClauseTransformer)
            .whenTargetNamed(NodeTransformers.CatchClauseTransformer);

        bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
            .to(FunctionDeclarationTransformer)
            .whenTargetNamed(NodeTransformers.FunctionDeclarationTransformer);

        bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
            .to(FunctionTransformer)
            .whenTargetNamed(NodeTransformers.FunctionTransformer);

        bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
            .to(LabeledStatementTransformer)
            .whenTargetNamed(NodeTransformers.LabeledStatementTransformer);

        bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
            .to(LiteralTransformer)
            .whenTargetNamed(NodeTransformers.LiteralTransformer);

        bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
            .to(ObjectExpressionTransformer)
            .whenTargetNamed(NodeTransformers.ObjectExpressionTransformer);

        bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
            .to(VariableDeclarationTransformer)
            .whenTargetNamed(NodeTransformers.VariableDeclarationTransformer);

        // node transformers factory
        bind<INodeTransformer>(ServiceIdentifiers.Factory__INodeTransformer)
            .toFactory<INodeTransformer>((context: interfaces.Context) => {
                const cache: Map <NodeTransformers, INodeTransformer> = new Map();

                return (nodeTransformerName: NodeTransformers) => {
                    Iif (cache.has(nodeTransformerName)) {
                        return <INodeTransformer>cache.get(nodeTransformerName);
                    }

                    const nodeTransformer: INodeTransformer = context.container
                        .getNamed<INodeTransformer>(
                            ServiceIdentifiers.INodeTransformer,
                            nodeTransformerName
                        );

                    cache.set(nodeTransformerName, nodeTransformer);

                    return nodeTransformer;
                };
            });
    });