All files / src/custom-nodes/unicode-array-nodes UnicodeArrayNode.js

96% Statements 24/25
71.43% Branches 5/7
100% Functions 2/2
96% Lines 24/25
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  1x 1x 1x 1x 1x 1x   20x   4x 4x 4x 4x 4x     4x     2x     63x     4x     4x 4x 4x     45x     8x                       45x                                 1x 1x  
"use strict";
const escodegen = require('escodegen');
const AppendState_1 = require('../../enums/AppendState');
const NodeType_1 = require("../../enums/NodeType");
const Node_1 = require('../Node');
const NodeUtils_1 = require("../../NodeUtils");
const Utils_1 = require('../../Utils');
class UnicodeArrayNode extends Node_1.Node {
    constructor(unicodeArrayName, unicodeArrayRotateValue = 0, options) {
        super(options);
        this.appendState = AppendState_1.AppendState.AfterObfuscation;
        this.unicodeArray = [];
        this.unicodeArrayName = unicodeArrayName;
        this.unicodeArrayRotateValue = unicodeArrayRotateValue;
        this.node = this.getNodeStructure();
    }
    appendNode(blockScopeNode) {
        NodeUtils_1.NodeUtils.prependNode(blockScopeNode.body, this.getNode());
    }
    getNodeIdentifier() {
        return this.unicodeArrayName;
    }
    getNodeData() {
        return this.unicodeArray;
    }
    getNode() {
        if (!this.unicodeArray.length) I{
            return;
        }
        Utils_1.Utils.arrayRotate(this.unicodeArray, this.unicodeArrayRotateValue);
        this.updateNode();
        return super.getNode();
    }
    updateNodeData(data) {
        this.unicodeArray.push(data);
    }
    getNodeStructure() {
        return {
            'type': NodeType_1.NodeType.VariableDeclaration,
            'declarations': [
                {
                    'type': NodeType_1.NodeType.VariableDeclarator,
                    'id': {
                        'type': NodeType_1.NodeType.Identifier,
                        'name': this.unicodeArrayName
                    },
                    'init': {
                        'type': NodeType_1.NodeType.ArrayExpression,
                        'elements': this.unicodeArray.map((value) => {
                            return {
                                'type': NodeType_1.NodeType.Literal,
                                'value': value,
                                'raw': `'${value}'`,
                                'x-verbatim-property': {
                                    'content': value,
                                    precedence: escodegen.Precedence.Primary
                                }
                            };
                        })
                    }
                }
            ],
            'kind': 'var'
        };
    }
}
UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH = 4;
exports.UnicodeArrayNode = UnicodeArrayNode;
//# sourceMappingURL=UnicodeArrayNode.js.map