# All files / src/node-obfuscators FunctionDeclarationObfuscator.js

94.74% Statements 18/19
66.67% Branches 2/3
100% Functions 3/3
94.44% Lines 17/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
    1x
    1x
    1x
    1x

    16x

    4x

    4x

    4x
    4x

    4x
    4x
    4x

    4x
    4x
    4x

    378x

    1x
     "use strict";
    const estraverse = require('estraverse');
    const NodeType_1 = require("../enums/NodeType");
    const NodeObfuscator_1 = require('./NodeObfuscator');
    const NodeUtils_1 = require("../NodeUtils");
    class FunctionDeclarationObfuscator extends NodeObfuscator_1.NodeObfuscator {
        constructor(...args) {
            super(...args);
            this.functionName = new Map();
        }
        obfuscateNode(functionDeclarationNode, parentNode) {
            if (parentNode.type === NodeType_1.NodeType.Program) I{
                return;
            }
            this.storeFunctionName(functionDeclarationNode);
            this.replaceFunctionName(functionDeclarationNode);
        }
        storeFunctionName(functionDeclarationNode) {
            estraverse.traverse(functionDeclarationNode.id, {
                leave: (node) => this.storeIdentifiersNames(node, this.functionName)
            });
        }
        replaceFunctionName(functionDeclarationNode) {
            let scopeNode = NodeUtils_1.NodeUtils.getBlockScopeOfNode(functionDeclarationNode);
            estraverse.replace(scopeNode, {
                enter: (node, parentNode) => {
                    this.replaceIdentifiersWithRandomNames(node, parentNode, this.functionName);
                }
            });
        }
    }
    exports.FunctionDeclarationObfuscator = FunctionDeclarationObfuscator;
    //# sourceMappingURL=FunctionDeclarationObfuscator.js.map