Code coverage report for src/node-obfuscators/ObjectExpressionObfuscator.js

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

36% Statements 9/25
11.11% Branches 1/9
0% Functions 0/2
37.5% Lines 9/24

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

    1x
    1x

    1x
     "use strict";
    const escodegen = require('escodegen');
    const estraverse = require('estraverse');
    const NodeType_1 = require("../enums/NodeType");
    const NodeObfuscator_1 = require('./NodeObfuscator');
    const Nodes_1 = require("../Nodes");
    const Utils_1 = require('../Utils');
    class ObjectExpressionObfuscator extends NodeObfuscator_1.NodeObfuscator {
        obfuscateNode(objectExpressionNode) {
            objectExpressionNode.properties
                .forEach((property) => {
                estraverse.replace(property.key, {
                    leave: (node, parentNode) => {
                        if (Nodes_1.Nodes.isLiteralNode(node)) {
                            this.obfuscateLiteralPropertyKey(node);
                            return;
                        }
                        if (Nodes_1.Nodes.isIdentifierNode(node)) {
                            this.obfuscateIdentifierPropertyKey(node);
                        }
                    }
                });
            });
        }
        obfuscateLiteralPropertyKey(node) {
            switch (typeof node.value) {
                case 'string':
                    if (node['x-verbatim-property']) {
                        break;
                    }
                    node['x-verbatim-property'] = {
                        content: Utils_1.Utils.stringToUnicode(node.value),
                        precedence: escodegen.Precedence.Primary
                    };
                    break;
                default:
                    break;
            }
        }
        obfuscateIdentifierPropertyKey(node) {
            let nodeValue = node.name, literalNode = {
                raw: `'${nodeValue}'`,
                'x-verbatim-property': {
                    content: Utils_1.Utils.stringToUnicode(nodeValue),
                    precedence: escodegen.Precedence.Primary
                },
                type: NodeType_1.NodeType.Literal,
                value: nodeValue
            };
            delete node.name;
            Object.assign(node, literalNode);
        }
    }
    exports.ObjectExpressionObfuscator = ObjectExpressionObfuscator;
    //# sourceMappingURL=ObjectExpressionObfuscator.js.map