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

95.45% Statements 21/22
90.91% Branches 10/11
100% Functions 1/1
95.24% Lines 20/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
    1x
    1x
    1x
    1x
    1x

    102x
    102x

    150x
    76x
    76x

    74x
    50x
    14x

    36x
    36x

    36x

    36x
    36x

    76x

    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");
    class MemberExpressionObfuscator extends NodeObfuscator_1.NodeObfuscator {
        obfuscateNode(memberExpressionNode) {
            estraverse.replace(memberExpressionNode.property, {
                leave: (node, parentNode) => {
                    if (Nodes_1.Nodes.isLiteralNode(node)) {
                        this.obfuscateLiteralProperty(node);
                        return;
                    }
                    if (Nodes_1.Nodes.isIdentifierNode(node)) {
                        if (memberExpressionNode.computed) {
                            return;
                        }
                        memberExpressionNode.computed = true;
                        this.obfuscateIdentifierProperty(node);
                    }
                }
            });
        }
        obfuscateIdentifierProperty(node) {
            let nodeValue = node.name, literalNode = {
                raw: `'${nodeValue}'`,
                'x-verbatim-property': {
                    content: this.replaceLiteralValueWithUnicodeValue(nodeValue),
                    precedence: escodegen.Precedence.Primary
                },
                type: NodeType_1.NodeType.Literal,
                value: nodeValue
            };
            delete node.name;
            Object.assign(node, literalNode);
        }
        obfuscateLiteralProperty(node) {
            if (typeof node.value === 'string' && !node['x-verbatim-property']) I{
                node['x-verbatim-property'] = {
                    content: this.replaceLiteralValueWithUnicodeValue(node.value),
                    precedence: escodegen.Precedence.Primary
                };
            }
        }
    }
    exports.MemberExpressionObfuscator = MemberExpressionObfuscator;
    //# sourceMappingURL=MemberExpressionObfuscator.js.map