# All files / src/custom-nodes AbstractCustomNodeGroup.ts

90.91% Statements 10/11
100% Branches 2/2
100% Functions 1/1
90% Lines 9/10

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

    1x

    9060x

    9045x

    17862x

    17862x
    15257x

    2605x

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

    import { TNodeWithBlockStatement } from '../types/node/TNodeWithBlockStatement';
    import { TObfuscationEvent } from '../types/event-emitters/TObfuscationEvent';

    import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode';
    import { ICustomNodeGroup } from '../interfaces/custom-nodes/ICustomNodeGroup';
    import { IOptions } from '../interfaces/options/IOptions';
    import { IStackTraceData } from '../interfaces/stack-trace-analyzer/IStackTraceData';

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

    @injectable()
    export abstract class AbstractCustomNodeGroup implements ICustomNodeGroup {
        /**
         * @type {TObfuscationEvent}
         */
        protected abstract readonly appendEvent: TObfuscationEvent;

        /**
         * @type {Map<CustomNodes, ICustomNode>}
         */
        protected abstract customNodes: Map <CustomNodes, ICustomNode>;

        /**
         * @type {IStackTraceData[]}
         */
        protected readonly stackTraceData: IStackTraceData[];

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

        /**
         * @param options
         */
        constructor (
            @inject(ServiceIdentifiers.IOptions) options: IOptions
        ) {
            this.options = options;
        }

        /**
         * @param blockScopeNode
         * @param stackTraceData
         */
        public abstract appendCustomNodes (blockScopeNode: TNodeWithBlockStatement, stackTraceData: IStackTraceData[]): void;

        /**
         * @returns {TObfuscationEvent}
         */
        public getAppendEvent (): TObfuscationEvent {
            return this.appendEvent;
        }

        /**
         * @returns {Map<CustomNodes, ICustomNode>}
         */
        public getCustomNodes (): Map <CustomNodes, ICustomNode> {
            return this.customNodes;
        }

        public abstract initialize (): void;

        /**
         * @param customNodeName
         * @param callback
         */
        protected appendCustomNodeIfExist (customNodeName: CustomNodes, callback: (customNode: ICustomNode) => void): void {
            const customNode: ICustomNode | undefined = this.customNodes.get(customNodeName);

            if (!customNode) {
                return;
            }

            callback(customNode);
        }
    }