Code coverage report for src/container/modules/stack-trace-analyzer/StackTraceAnalyzerModule.ts

# All files / src/container/modules/stack-trace-analyzer StackTraceAnalyzerModule.ts

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

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

    1x
    1x
    1x
    1x
    1x

    1x
    2628x

    2628x

    2628x

    2628x

    2628x

    2628x

    2624x

    2624x
    47364x
    41199x

    6165x

    6165x

    6165x

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

    import { ICalleeDataExtractor } from '../../../interfaces/stack-trace-analyzer/ICalleeDataExtractor';
    import { IStackTraceAnalyzer } from '../../../interfaces/stack-trace-analyzer/IStackTraceAnalyzer';

    import { FunctionDeclarationCalleeDataExtractor } from '../../../stack-trace-analyzer/callee-data-extractors/FunctionDeclarationCalleeDataExtractor';
    import { FunctionExpressionCalleeDataExtractor } from '../../../stack-trace-analyzer/callee-data-extractors/FunctionExpressionCalleeDataExtractor';
    import { ObjectExpressionCalleeDataExtractor } from '../../../stack-trace-analyzer/callee-data-extractors/ObjectExpressionCalleeDataExtractor';
    import { StackTraceAnalyzer } from '../../../stack-trace-analyzer/StackTraceAnalyzer';
    import { CalleeDataExtractors } from '../../../enums/container/CalleeDataExtractors';

    export const stackTraceAnalyzerModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
        const calleeDataExtractorsTag: string = 'calleeDataExtractors';

        // stack trace analyzer
        bind<IStackTraceAnalyzer>(ServiceIdentifiers.IStackTraceAnalyzer)
            .to(StackTraceAnalyzer)
            .inSingletonScope();

        // callee data extractors
        bind<ICalleeDataExtractor>(ServiceIdentifiers.ICalleeDataExtractor)
            .to(FunctionDeclarationCalleeDataExtractor)
            .whenTargetTagged(calleeDataExtractorsTag, CalleeDataExtractors.FunctionDeclarationCalleeDataExtractor);

        bind<ICalleeDataExtractor>(ServiceIdentifiers.ICalleeDataExtractor)
            .to(FunctionExpressionCalleeDataExtractor)
            .whenTargetTagged(calleeDataExtractorsTag, CalleeDataExtractors.FunctionExpressionCalleeDataExtractor);

        bind<ICalleeDataExtractor>(ServiceIdentifiers.ICalleeDataExtractor)
            .to(ObjectExpressionCalleeDataExtractor)
            .whenTargetTagged(calleeDataExtractorsTag, CalleeDataExtractors.ObjectExpressionCalleeDataExtractor);

        // node transformers factory
        bind<ICalleeDataExtractor>(ServiceIdentifiers['Factory<ICalleeDataExtractor>'])
            .toFactory<ICalleeDataExtractor>((context: interfaces.Context) => {
                const cache: Map <CalleeDataExtractors, ICalleeDataExtractor> = new Map <CalleeDataExtractors, ICalleeDataExtractor> ();

                return (calleeDataExtractorName: CalleeDataExtractors) => {
                    if (cache.has(calleeDataExtractorName)) {
                        return <ICalleeDataExtractor>cache.get(calleeDataExtractorName);
                    }

                    const calleeDataExtractor: ICalleeDataExtractor = context.container.getTagged<ICalleeDataExtractor>(
                        ServiceIdentifiers.ICalleeDataExtractor,
                        calleeDataExtractorsTag,
                        calleeDataExtractorName
                    );

                    cache.set(calleeDataExtractorName, calleeDataExtractor);

                    return calleeDataExtractor;
                };
            });
    });