sanex3339 %!s(int64=9) %!d(string=hai) anos
pai
achega
dde53c79bf

+ 14 - 13
src/NodeUtils.js

@@ -1,8 +1,9 @@
 "use strict";
 "use strict";
+const NodeType_1 = require("./enums/NodeType");
 const Utils_1 = require("./Utils");
 const Utils_1 = require("./Utils");
 class NodeUtils {
 class NodeUtils {
     static getScopeOfNode(node, depth = 0) {
     static getScopeOfNode(node, depth = 0) {
-        if (node.parentNode.type === 'Program') {
+        if (node.parentNode.type === NodeType_1.NodeType.Program) {
             return node.parentNode;
             return node.parentNode;
         }
         }
         if (!Utils_1.Utils.arrayContains(NodeUtils.scopeNodes, node.parentNode.type)) {
         if (!Utils_1.Utils.arrayContains(NodeUtils.scopeNodes, node.parentNode.type)) {
@@ -11,13 +12,13 @@ class NodeUtils {
         if (depth > 0) {
         if (depth > 0) {
             return NodeUtils.getScopeOfNode(node.parentNode, --depth);
             return NodeUtils.getScopeOfNode(node.parentNode, --depth);
         }
         }
-        if (node.type !== 'BlockStatement') {
+        if (node.type !== NodeType_1.NodeType.BlockStatement) {
             return NodeUtils.getScopeOfNode(node.parentNode);
             return NodeUtils.getScopeOfNode(node.parentNode);
         }
         }
         return node;
         return node;
     }
     }
     static getParentNodeWithType(node, types, limitNodeTypes = [], depth = 0) {
     static getParentNodeWithType(node, types, limitNodeTypes = [], depth = 0) {
-        if (node.parentNode.type === 'Program' || Utils_1.Utils.arrayContains(limitNodeTypes, node.parentNode.type)) {
+        if (node.parentNode.type === NodeType_1.NodeType.Program || Utils_1.Utils.arrayContains(limitNodeTypes, node.parentNode.type)) {
             return node.parentNode;
             return node.parentNode;
         }
         }
         if (!Utils_1.Utils.arrayContains(types, node.parentNode.type)) {
         if (!Utils_1.Utils.arrayContains(types, node.parentNode.type)) {
@@ -29,28 +30,28 @@ class NodeUtils {
         return node.parentNode;
         return node.parentNode;
     }
     }
     static isBlockStatementNode(node) {
     static isBlockStatementNode(node) {
-        return node.type === 'BlockStatement';
+        return node.type === NodeType_1.NodeType.BlockStatement;
     }
     }
     static isIdentifierNode(node) {
     static isIdentifierNode(node) {
-        return node.type === 'Identifier';
+        return node.type === NodeType_1.NodeType.Identifier;
     }
     }
     static isLiteralNode(node) {
     static isLiteralNode(node) {
-        return node.type === 'Literal';
+        return node.type === NodeType_1.NodeType.Literal;
     }
     }
     static isMemberExpressionNode(node) {
     static isMemberExpressionNode(node) {
-        return node.type === 'MemberExpression';
+        return node.type === NodeType_1.NodeType.MemberExpression;
     }
     }
     static isPropertyNode(node) {
     static isPropertyNode(node) {
-        return node.type === 'Property';
+        return node.type === NodeType_1.NodeType.Property;
     }
     }
     static isVariableDeclaratorNode(node) {
     static isVariableDeclaratorNode(node) {
-        return node.type === 'VariableDeclarator';
+        return node.type === NodeType_1.NodeType.VariableDeclarator;
     }
     }
 }
 }
 NodeUtils.scopeNodes = [
 NodeUtils.scopeNodes = [
-    'ArrowFunctionExpression',
-    'FunctionDeclaration',
-    'FunctionExpression',
-    'MethodDefinition'
+    NodeType_1.NodeType.ArrowFunctionExpression,
+    NodeType_1.NodeType.FunctionDeclaration,
+    NodeType_1.NodeType.FunctionExpression,
+    NodeType_1.NodeType.MethodDefinition
 ];
 ];
 exports.NodeUtils = NodeUtils;
 exports.NodeUtils = NodeUtils;

+ 15 - 13
src/NodeUtils.ts

@@ -6,6 +6,8 @@ import { IPropertyNode } from "./interfaces/nodes/IPropertyNode";
 import { ITreeNode } from './interfaces/nodes/ITreeNode';
 import { ITreeNode } from './interfaces/nodes/ITreeNode';
 import { IVariableDeclaratorNode } from "./interfaces/nodes/IVariableDeclaratorNode";
 import { IVariableDeclaratorNode } from "./interfaces/nodes/IVariableDeclaratorNode";
 
 
+import { NodeType } from "./enums/NodeType";
+
 import { Utils } from "./Utils";
 import { Utils } from "./Utils";
 
 
 export class NodeUtils {
 export class NodeUtils {
@@ -13,10 +15,10 @@ export class NodeUtils {
      * @type {string[]}
      * @type {string[]}
      */
      */
     private static scopeNodes: string[] = [
     private static scopeNodes: string[] = [
-        'ArrowFunctionExpression',
-        'FunctionDeclaration',
-        'FunctionExpression',
-        'MethodDefinition'
+        NodeType.ArrowFunctionExpression,
+        NodeType.FunctionDeclaration,
+        NodeType.FunctionExpression,
+        NodeType.MethodDefinition
     ];
     ];
 
 
     /**
     /**
@@ -25,7 +27,7 @@ export class NodeUtils {
      * @returns {ITreeNode}
      * @returns {ITreeNode}
      */
      */
     public static getScopeOfNode (node: ITreeNode, depth: number = 0): ITreeNode {
     public static getScopeOfNode (node: ITreeNode, depth: number = 0): ITreeNode {
-        if (node.parentNode.type === 'Program') {
+        if (node.parentNode.type === NodeType.Program) {
             return node.parentNode;
             return node.parentNode;
         }
         }
 
 
@@ -37,7 +39,7 @@ export class NodeUtils {
             return NodeUtils.getScopeOfNode(node.parentNode, --depth);
             return NodeUtils.getScopeOfNode(node.parentNode, --depth);
         }
         }
 
 
-        if (node.type !== 'BlockStatement') {
+        if (node.type !== NodeType.BlockStatement) {
             return NodeUtils.getScopeOfNode(node.parentNode);
             return NodeUtils.getScopeOfNode(node.parentNode);
         }
         }
 
 
@@ -57,7 +59,7 @@ export class NodeUtils {
         limitNodeTypes: string[] = [],
         limitNodeTypes: string[] = [],
         depth: number = 0
         depth: number = 0
     ): ITreeNode {
     ): ITreeNode {
-        if (node.parentNode.type === 'Program' || Utils.arrayContains(limitNodeTypes, node.parentNode.type)) {
+        if (node.parentNode.type === NodeType.Program || Utils.arrayContains(limitNodeTypes, node.parentNode.type)) {
             return node.parentNode;
             return node.parentNode;
         }
         }
 
 
@@ -77,7 +79,7 @@ export class NodeUtils {
      * @returns {boolean}
      * @returns {boolean}
      */
      */
     public static isBlockStatementNode (node: ITreeNode): node is IBlockStatementNode {
     public static isBlockStatementNode (node: ITreeNode): node is IBlockStatementNode {
-        return node.type === 'BlockStatement';
+        return node.type === NodeType.BlockStatement;
     }
     }
 
 
     /**
     /**
@@ -85,7 +87,7 @@ export class NodeUtils {
      * @returns {boolean}
      * @returns {boolean}
      */
      */
     public static isIdentifierNode (node: ITreeNode): node is IIdentifierNode {
     public static isIdentifierNode (node: ITreeNode): node is IIdentifierNode {
-        return node.type === 'Identifier';
+        return node.type === NodeType.Identifier;
     }
     }
 
 
     /**
     /**
@@ -93,7 +95,7 @@ export class NodeUtils {
      * @returns {boolean}
      * @returns {boolean}
      */
      */
     public static isLiteralNode (node: ITreeNode): node is ILiteralNode {
     public static isLiteralNode (node: ITreeNode): node is ILiteralNode {
-        return node.type === 'Literal';
+        return node.type === NodeType.Literal;
     }
     }
 
 
     /**
     /**
@@ -101,7 +103,7 @@ export class NodeUtils {
      * @returns {boolean}
      * @returns {boolean}
      */
      */
     public static isMemberExpressionNode (node: ITreeNode): node is IMemberExpressionNode {
     public static isMemberExpressionNode (node: ITreeNode): node is IMemberExpressionNode {
-        return node.type === 'MemberExpression';
+        return node.type === NodeType.MemberExpression;
     }
     }
 
 
 
 
@@ -111,7 +113,7 @@ export class NodeUtils {
      * @returns {boolean}
      * @returns {boolean}
      */
      */
     public static isPropertyNode (node: ITreeNode): node is IPropertyNode {
     public static isPropertyNode (node: ITreeNode): node is IPropertyNode {
-        return node.type === 'Property';
+        return node.type === NodeType.Property;
     }
     }
 
 
     /**
     /**
@@ -120,6 +122,6 @@ export class NodeUtils {
      * @returns {boolean}
      * @returns {boolean}
      */
      */
     public static isVariableDeclaratorNode (node: ITreeNode): node is IVariableDeclaratorNode {
     public static isVariableDeclaratorNode (node: ITreeNode): node is IVariableDeclaratorNode {
-        return node.type === 'VariableDeclarator';
+        return node.type === NodeType.VariableDeclarator;
     }
     }
 }
 }

+ 11 - 10
src/Obfuscator.js

@@ -1,6 +1,7 @@
 "use strict";
 "use strict";
 const estraverse = require('estraverse');
 const estraverse = require('estraverse');
 const AppendState_1 = require('./enums/AppendState');
 const AppendState_1 = require('./enums/AppendState');
+const NodeType_1 = require("./enums/NodeType");
 const CatchClauseObfuscator_1 = require("./node-obfuscators/CatchClauseObfuscator");
 const CatchClauseObfuscator_1 = require("./node-obfuscators/CatchClauseObfuscator");
 const FunctionDeclarationObfuscator_1 = require('./node-obfuscators/FunctionDeclarationObfuscator');
 const FunctionDeclarationObfuscator_1 = require('./node-obfuscators/FunctionDeclarationObfuscator');
 const FunctionObfuscator_1 = require('./node-obfuscators/FunctionObfuscator');
 const FunctionObfuscator_1 = require('./node-obfuscators/FunctionObfuscator');
@@ -16,19 +17,19 @@ class Obfuscator {
     constructor(options = {}) {
     constructor(options = {}) {
         this.nodes = new Map();
         this.nodes = new Map();
         this.nodeObfuscators = new Map([
         this.nodeObfuscators = new Map([
-            ['ClassDeclaration', [FunctionDeclarationObfuscator_1.FunctionDeclarationObfuscator]],
-            ['CatchClause', [CatchClauseObfuscator_1.CatchClauseObfuscator]],
-            ['FunctionDeclaration', [
+            [NodeType_1.NodeType.ArrowFunctionExpression, [FunctionObfuscator_1.FunctionObfuscator]],
+            [NodeType_1.NodeType.ClassDeclaration, [FunctionDeclarationObfuscator_1.FunctionDeclarationObfuscator]],
+            [NodeType_1.NodeType.CatchClause, [CatchClauseObfuscator_1.CatchClauseObfuscator]],
+            [NodeType_1.NodeType.FunctionDeclaration, [
                     FunctionDeclarationObfuscator_1.FunctionDeclarationObfuscator,
                     FunctionDeclarationObfuscator_1.FunctionDeclarationObfuscator,
                     FunctionObfuscator_1.FunctionObfuscator
                     FunctionObfuscator_1.FunctionObfuscator
                 ]],
                 ]],
-            ['ArrowFunctionExpression', [FunctionObfuscator_1.FunctionObfuscator]],
-            ['FunctionExpression', [FunctionObfuscator_1.FunctionObfuscator]],
-            ['MethodDefinition', [MethodDefinitionObfuscator_1.MethodDefinitionObfuscator]],
-            ['VariableDeclaration', [VariableDeclarationObfuscator_1.VariableDeclarationObfuscator]],
-            ['ObjectExpression', [ObjectExpressionObfuscator_1.ObjectExpressionObfuscator]],
-            ['MemberExpression', [MemberExpressionObfuscator_1.MemberExpressionObfuscator]],
-            ['Literal', [LiteralObfuscator_1.LiteralObfuscator]]
+            [NodeType_1.NodeType.FunctionExpression, [FunctionObfuscator_1.FunctionObfuscator]],
+            [NodeType_1.NodeType.MemberExpression, [MemberExpressionObfuscator_1.MemberExpressionObfuscator]],
+            [NodeType_1.NodeType.MethodDefinition, [MethodDefinitionObfuscator_1.MethodDefinitionObfuscator]],
+            [NodeType_1.NodeType.ObjectExpression, [ObjectExpressionObfuscator_1.ObjectExpressionObfuscator]],
+            [NodeType_1.NodeType.VariableDeclaration, [VariableDeclarationObfuscator_1.VariableDeclarationObfuscator]],
+            [NodeType_1.NodeType.Literal, [LiteralObfuscator_1.LiteralObfuscator]]
         ]);
         ]);
         this.options = options;
         this.options = options;
     }
     }

+ 11 - 10
src/Obfuscator.ts

@@ -6,6 +6,7 @@ import { INodesGroup } from './interfaces/INodesGroup';
 import { ITreeNode } from './interfaces/nodes/ITreeNode';
 import { ITreeNode } from './interfaces/nodes/ITreeNode';
 
 
 import { AppendState } from './enums/AppendState';
 import { AppendState } from './enums/AppendState';
+import { NodeType } from "./enums/NodeType";
 
 
 import { CatchClauseObfuscator } from "./node-obfuscators/CatchClauseObfuscator";
 import { CatchClauseObfuscator } from "./node-obfuscators/CatchClauseObfuscator";
 import { FunctionDeclarationObfuscator } from './node-obfuscators/FunctionDeclarationObfuscator';
 import { FunctionDeclarationObfuscator } from './node-obfuscators/FunctionDeclarationObfuscator';
@@ -29,19 +30,19 @@ export class Obfuscator {
      * @type {Map<string, Function[]>}
      * @type {Map<string, Function[]>}
      */
      */
     private nodeObfuscators: Map <string, Function[]> = new Map <string, Function[]> ([
     private nodeObfuscators: Map <string, Function[]> = new Map <string, Function[]> ([
-        ['ClassDeclaration', [FunctionDeclarationObfuscator]],
-        ['CatchClause', [CatchClauseObfuscator]],
-        ['FunctionDeclaration', [
+        [NodeType.ArrowFunctionExpression, [FunctionObfuscator]],
+        [NodeType.ClassDeclaration, [FunctionDeclarationObfuscator]],
+        [NodeType.CatchClause, [CatchClauseObfuscator]],
+        [NodeType.FunctionDeclaration, [
             FunctionDeclarationObfuscator,
             FunctionDeclarationObfuscator,
             FunctionObfuscator
             FunctionObfuscator
         ]],
         ]],
-        ['ArrowFunctionExpression', [FunctionObfuscator]],
-        ['FunctionExpression', [FunctionObfuscator]],
-        ['MethodDefinition', [MethodDefinitionObfuscator]],
-        ['VariableDeclaration', [VariableDeclarationObfuscator]],
-        ['ObjectExpression', [ObjectExpressionObfuscator]],
-        ['MemberExpression', [MemberExpressionObfuscator]],
-        ['Literal', [LiteralObfuscator]]
+        [NodeType.FunctionExpression, [FunctionObfuscator]],
+        [NodeType.MemberExpression, [MemberExpressionObfuscator]],
+        [NodeType.MethodDefinition, [MethodDefinitionObfuscator]],
+        [NodeType.ObjectExpression, [ObjectExpressionObfuscator]],
+        [NodeType.VariableDeclaration, [VariableDeclarationObfuscator]],
+        [NodeType.Literal, [LiteralObfuscator]]
     ]);
     ]);
 
 
     /**
     /**

+ 3 - 0
src/Utils.js

@@ -30,6 +30,9 @@ class Utils {
         const rangeMinInteger = 10000, rangeMaxInteger = 99999999, prefix = '_0x';
         const rangeMinInteger = 10000, rangeMaxInteger = 99999999, prefix = '_0x';
         return `${prefix}${(Utils.decToHex(Utils.getRandomInteger(rangeMinInteger, rangeMaxInteger))).substr(0, length)}`;
         return `${prefix}${(Utils.decToHex(Utils.getRandomInteger(rangeMinInteger, rangeMaxInteger))).substr(0, length)}`;
     }
     }
+    static strEnumify(obj) {
+        return obj;
+    }
     static stringToUnicode(string) {
     static stringToUnicode(string) {
         return `'${string.replace(/[\s\S]/g, (escape) => {
         return `'${string.replace(/[\s\S]/g, (escape) => {
             return `\\u${('0000' + escape.charCodeAt(0).toString(16)).slice(-4)}`;
             return `\\u${('0000' + escape.charCodeAt(0).toString(16)).slice(-4)}`;

+ 8 - 0
src/Utils.ts

@@ -64,6 +64,14 @@ export class Utils {
         return `${prefix}${(Utils.decToHex(Utils.getRandomInteger(rangeMinInteger, rangeMaxInteger))).substr(0, length)}`;
         return `${prefix}${(Utils.decToHex(Utils.getRandomInteger(rangeMinInteger, rangeMaxInteger))).substr(0, length)}`;
     }
     }
 
 
+    /**
+     * @param obj
+     * @returns {T}
+     */
+    public static strEnumify <T extends { [prop: string]: '' | string }> (obj: T): T {
+        return obj;
+    }
+
     /**
     /**
      * @param string
      * @param string
      * @returns {string}
      * @returns {string}

+ 30 - 0
src/enums/NodeType.js

@@ -0,0 +1,30 @@
+"use strict";
+const Utils_1 = require("../Utils");
+exports.NodeType = Utils_1.Utils.strEnumify({
+    ArrayExpression: 'ArrayExpression',
+    ArrowFunctionExpression: 'ArrowFunctionExpression',
+    AssignmentExpression: 'AssignmentExpression',
+    BinaryExpression: 'BinaryExpression',
+    BlockStatement: 'BlockStatement',
+    CallExpression: 'CallExpression',
+    CatchClause: 'CatchClause',
+    ClassDeclaration: 'ClassDeclaration',
+    ExpressionStatement: 'ExpressionStatement',
+    FunctionDeclaration: 'FunctionDeclaration',
+    FunctionExpression: 'FunctionExpression',
+    Identifier: 'Identifier',
+    IfStatement: 'IfStatement',
+    Literal: 'Literal',
+    LogicalExpression: 'LogicalExpression',
+    MemberExpression: 'MemberExpression',
+    MethodDefinition: 'MethodDefinition',
+    ObjectExpression: 'ObjectExpression',
+    Program: 'Program',
+    Property: 'Property',
+    ReturnStatement: 'ReturnStatement',
+    UnaryExpression: 'UnaryExpression',
+    UpdateExpression: 'UpdateExpression',
+    VariableDeclaration: 'VariableDeclaration',
+    VariableDeclarator: 'VariableDeclarator',
+    WhileStatement: 'WhileStatement'
+});

+ 30 - 0
src/enums/NodeType.ts

@@ -0,0 +1,30 @@
+import { Utils } from "../Utils";
+
+export const NodeType: any = Utils.strEnumify({
+    ArrayExpression: 'ArrayExpression',
+    ArrowFunctionExpression: 'ArrowFunctionExpression',
+    AssignmentExpression: 'AssignmentExpression',
+    BinaryExpression: 'BinaryExpression',
+    BlockStatement: 'BlockStatement',
+    CallExpression: 'CallExpression',
+    CatchClause: 'CatchClause',
+    ClassDeclaration: 'ClassDeclaration',
+    ExpressionStatement: 'ExpressionStatement',
+    FunctionDeclaration: 'FunctionDeclaration',
+    FunctionExpression: 'FunctionExpression',
+    Identifier:  'Identifier',
+    IfStatement:  'IfStatement',
+    Literal: 'Literal',
+    LogicalExpression: 'LogicalExpression',
+    MemberExpression: 'MemberExpression',
+    MethodDefinition: 'MethodDefinition',
+    ObjectExpression: 'ObjectExpression',
+    Program: 'Program',
+    Property: 'Property',
+    ReturnStatement: 'ReturnStatement',
+    UnaryExpression: 'UnaryExpression',
+    UpdateExpression: 'UpdateExpression',
+    VariableDeclaration: 'VariableDeclaration',
+    VariableDeclarator: 'VariableDeclarator',
+    WhileStatement: 'WhileStatement'
+});

+ 2 - 1
src/node-obfuscators/FunctionDeclarationObfuscator.js

@@ -1,5 +1,6 @@
 "use strict";
 "use strict";
 const estraverse = require('estraverse');
 const estraverse = require('estraverse');
+const NodeType_1 = require("../enums/NodeType");
 const NodeObfuscator_1 = require('./NodeObfuscator');
 const NodeObfuscator_1 = require('./NodeObfuscator');
 const NodeUtils_1 = require("../NodeUtils");
 const NodeUtils_1 = require("../NodeUtils");
 const Utils_1 = require('../Utils');
 const Utils_1 = require('../Utils');
@@ -9,7 +10,7 @@ class FunctionDeclarationObfuscator extends NodeObfuscator_1.NodeObfuscator {
         this.functionName = new Map();
         this.functionName = new Map();
     }
     }
     obfuscateNode(functionDeclarationNode, parentNode) {
     obfuscateNode(functionDeclarationNode, parentNode) {
-        if (parentNode.type === 'Program') {
+        if (parentNode.type === NodeType_1.NodeType.Program) {
             return;
             return;
         }
         }
         this.replaceFunctionName(functionDeclarationNode);
         this.replaceFunctionName(functionDeclarationNode);

+ 3 - 1
src/node-obfuscators/FunctionDeclarationObfuscator.ts

@@ -3,6 +3,8 @@ import * as estraverse from 'estraverse';
 import { IFunctionDeclarationNode } from "../interfaces/nodes/IFunctionDeclarationNode";
 import { IFunctionDeclarationNode } from "../interfaces/nodes/IFunctionDeclarationNode";
 import { ITreeNode } from "../interfaces/nodes/ITreeNode";
 import { ITreeNode } from "../interfaces/nodes/ITreeNode";
 
 
+import { NodeType } from "../enums/NodeType";
+
 import { NodeObfuscator } from './NodeObfuscator';
 import { NodeObfuscator } from './NodeObfuscator';
 import { NodeUtils } from "../NodeUtils";
 import { NodeUtils } from "../NodeUtils";
 import { Utils } from '../Utils';
 import { Utils } from '../Utils';
@@ -27,7 +29,7 @@ export class FunctionDeclarationObfuscator extends NodeObfuscator {
      * @param parentNode
      * @param parentNode
      */
      */
     public obfuscateNode (functionDeclarationNode: IFunctionDeclarationNode, parentNode: ITreeNode): void {
     public obfuscateNode (functionDeclarationNode: IFunctionDeclarationNode, parentNode: ITreeNode): void {
-        if (parentNode.type === 'Program') {
+        if (parentNode.type === NodeType.Program) {
             return;
             return;
         }
         }
 
 

+ 2 - 1
src/node-obfuscators/MemberExpressionObfuscator.js

@@ -1,6 +1,7 @@
 "use strict";
 "use strict";
 const escodegen = require('escodegen');
 const escodegen = require('escodegen');
 const estraverse = require('estraverse');
 const estraverse = require('estraverse');
+const NodeType_1 = require("../enums/NodeType");
 const NodeObfuscator_1 = require('./NodeObfuscator');
 const NodeObfuscator_1 = require('./NodeObfuscator');
 const NodeUtils_1 = require("../NodeUtils");
 const NodeUtils_1 = require("../NodeUtils");
 class MemberExpressionObfuscator extends NodeObfuscator_1.NodeObfuscator {
 class MemberExpressionObfuscator extends NodeObfuscator_1.NodeObfuscator {
@@ -28,7 +29,7 @@ class MemberExpressionObfuscator extends NodeObfuscator_1.NodeObfuscator {
                 content: this.replaceLiteralStringByArrayElement(nodeValue),
                 content: this.replaceLiteralStringByArrayElement(nodeValue),
                 precedence: escodegen.Precedence.Primary
                 precedence: escodegen.Precedence.Primary
             },
             },
-            type: 'Literal',
+            type: NodeType_1.NodeType.Literal,
             value: nodeValue
             value: nodeValue
         };
         };
         delete node.name;
         delete node.name;

+ 3 - 1
src/node-obfuscators/MemberExpressionObfuscator.ts

@@ -6,6 +6,8 @@ import { ILiteralNode } from "../interfaces/nodes/ILiteralNode";
 import { IMemberExpressionNode } from "../interfaces/nodes/IMemberExpressionNode";
 import { IMemberExpressionNode } from "../interfaces/nodes/IMemberExpressionNode";
 import { ITreeNode } from "../interfaces/nodes/ITreeNode";
 import { ITreeNode } from "../interfaces/nodes/ITreeNode";
 
 
+import { NodeType } from "../enums/NodeType";
+
 import { NodeObfuscator } from './NodeObfuscator';
 import { NodeObfuscator } from './NodeObfuscator';
 import { NodeUtils } from "../NodeUtils";
 import { NodeUtils } from "../NodeUtils";
 
 
@@ -54,7 +56,7 @@ export class MemberExpressionObfuscator extends NodeObfuscator {
                     content : this.replaceLiteralStringByArrayElement(nodeValue),
                     content : this.replaceLiteralStringByArrayElement(nodeValue),
                     precedence: escodegen.Precedence.Primary
                     precedence: escodegen.Precedence.Primary
                 },
                 },
-                type: 'Literal',
+                type: NodeType.Literal,
                 value: nodeValue
                 value: nodeValue
             };
             };
 
 

+ 2 - 1
src/node-obfuscators/ObjectExpressionObfuscator.js

@@ -1,6 +1,7 @@
 "use strict";
 "use strict";
 const escodegen = require('escodegen');
 const escodegen = require('escodegen');
 const estraverse = require('estraverse');
 const estraverse = require('estraverse');
+const NodeType_1 = require("../enums/NodeType");
 const NodeObfuscator_1 = require('./NodeObfuscator');
 const NodeObfuscator_1 = require('./NodeObfuscator');
 const NodeUtils_1 = require("../NodeUtils");
 const NodeUtils_1 = require("../NodeUtils");
 const Utils_1 = require('../Utils');
 const Utils_1 = require('../Utils');
@@ -42,7 +43,7 @@ class ObjectExpressionObfuscator extends NodeObfuscator_1.NodeObfuscator {
                 content: Utils_1.Utils.stringToUnicode(nodeValue),
                 content: Utils_1.Utils.stringToUnicode(nodeValue),
                 precedence: escodegen.Precedence.Primary
                 precedence: escodegen.Precedence.Primary
             },
             },
-            type: 'Literal',
+            type: NodeType_1.NodeType.Literal,
             value: nodeValue
             value: nodeValue
         };
         };
         delete node.name;
         delete node.name;

+ 4 - 2
src/node-obfuscators/ObjectExpressionObfuscator.ts

@@ -4,12 +4,14 @@ import * as estraverse from 'estraverse';
 import { IIdentifierNode } from "../interfaces/nodes/IIdentifierNode";
 import { IIdentifierNode } from "../interfaces/nodes/IIdentifierNode";
 import { ILiteralNode } from "../interfaces/nodes/ILiteralNode";
 import { ILiteralNode } from "../interfaces/nodes/ILiteralNode";
 import { IObjectExpressionNode } from "../interfaces/nodes/IObjectExpressionNode";
 import { IObjectExpressionNode } from "../interfaces/nodes/IObjectExpressionNode";
+import { IPropertyNode } from "../interfaces/nodes/IPropertyNode";
 import { ITreeNode } from "../interfaces/nodes/ITreeNode";
 import { ITreeNode } from "../interfaces/nodes/ITreeNode";
 
 
+import { NodeType } from "../enums/NodeType";
+
 import { NodeObfuscator } from './NodeObfuscator';
 import { NodeObfuscator } from './NodeObfuscator';
 import { NodeUtils } from "../NodeUtils";
 import { NodeUtils } from "../NodeUtils";
 import { Utils } from '../Utils';
 import { Utils } from '../Utils';
-import {IPropertyNode} from "../interfaces/nodes/IPropertyNode";
 
 
 /**
 /**
  * replaces:
  * replaces:
@@ -76,7 +78,7 @@ export class ObjectExpressionObfuscator extends NodeObfuscator {
                     content : Utils.stringToUnicode(nodeValue),
                     content : Utils.stringToUnicode(nodeValue),
                     precedence: escodegen.Precedence.Primary
                     precedence: escodegen.Precedence.Primary
                 },
                 },
-                type: 'Literal',
+                type: NodeType.Literal,
                 value: nodeValue
                 value: nodeValue
             };
             };
 
 

+ 5 - 4
src/node-obfuscators/VariableDeclarationObfuscator.js

@@ -1,5 +1,6 @@
 "use strict";
 "use strict";
 const estraverse = require('estraverse');
 const estraverse = require('estraverse');
+const NodeType_1 = require("../enums/NodeType");
 const NodeObfuscator_1 = require('./NodeObfuscator');
 const NodeObfuscator_1 = require('./NodeObfuscator');
 const NodeUtils_1 = require("../NodeUtils");
 const NodeUtils_1 = require("../NodeUtils");
 const Utils_1 = require('../Utils');
 const Utils_1 = require('../Utils');
@@ -9,7 +10,7 @@ class VariableDeclarationObfuscator extends NodeObfuscator_1.NodeObfuscator {
         this.variableNames = new Map();
         this.variableNames = new Map();
     }
     }
     obfuscateNode(variableDeclarationNode, parentNode) {
     obfuscateNode(variableDeclarationNode, parentNode) {
-        if (parentNode.type === 'Program') {
+        if (parentNode.type === NodeType_1.NodeType.Program) {
             return;
             return;
         }
         }
         this.replaceVariableName(variableDeclarationNode);
         this.replaceVariableName(variableDeclarationNode);
@@ -36,9 +37,9 @@ class VariableDeclarationObfuscator extends NodeObfuscator_1.NodeObfuscator {
         estraverse.replace(scopeNode, {
         estraverse.replace(scopeNode, {
             enter: (node, parentNode) => {
             enter: (node, parentNode) => {
                 const functionNodes = [
                 const functionNodes = [
-                    'ArrowFunctionExpression',
-                    'FunctionDeclaration',
-                    'FunctionExpression'
+                    NodeType_1.NodeType.ArrowFunctionExpression,
+                    NodeType_1.NodeType.FunctionDeclaration,
+                    NodeType_1.NodeType.FunctionExpression
                 ];
                 ];
                 if (Utils_1.Utils.arrayContains(functionNodes, node.type)) {
                 if (Utils_1.Utils.arrayContains(functionNodes, node.type)) {
                     estraverse.replace(node, {
                     estraverse.replace(node, {

+ 7 - 5
src/node-obfuscators/VariableDeclarationObfuscator.ts

@@ -2,11 +2,13 @@ import * as estraverse from 'estraverse';
 
 
 import { ITreeNode } from "../interfaces/nodes/ITreeNode";
 import { ITreeNode } from "../interfaces/nodes/ITreeNode";
 import { IVariableDeclarationNode } from "../interfaces/nodes/IVariableDeclarationNode";
 import { IVariableDeclarationNode } from "../interfaces/nodes/IVariableDeclarationNode";
+import { IVariableDeclaratorNode } from "../interfaces/nodes/IVariableDeclaratorNode";
+
+import { NodeType } from "../enums/NodeType";
 
 
 import { NodeObfuscator } from './NodeObfuscator';
 import { NodeObfuscator } from './NodeObfuscator';
 import { NodeUtils } from "../NodeUtils";
 import { NodeUtils } from "../NodeUtils";
 import { Utils } from '../Utils';
 import { Utils } from '../Utils';
-import {IVariableDeclaratorNode} from "../interfaces/nodes/IVariableDeclaratorNode";
 
 
 /**
 /**
  * replaces:
  * replaces:
@@ -29,7 +31,7 @@ export class VariableDeclarationObfuscator extends NodeObfuscator {
      * @param parentNode
      * @param parentNode
      */
      */
     public obfuscateNode (variableDeclarationNode: IVariableDeclarationNode, parentNode: ITreeNode): void {
     public obfuscateNode (variableDeclarationNode: IVariableDeclarationNode, parentNode: ITreeNode): void {
-        if (parentNode.type === 'Program') {
+        if (parentNode.type === NodeType.Program) {
             return;
             return;
         }
         }
 
 
@@ -73,9 +75,9 @@ export class VariableDeclarationObfuscator extends NodeObfuscator {
         estraverse.replace(scopeNode, {
         estraverse.replace(scopeNode, {
             enter: (node: ITreeNode, parentNode: ITreeNode): any => {
             enter: (node: ITreeNode, parentNode: ITreeNode): any => {
                 const functionNodes: string[] = [
                 const functionNodes: string[] = [
-                    'ArrowFunctionExpression',
-                    'FunctionDeclaration',
-                    'FunctionExpression'
+                    NodeType.ArrowFunctionExpression,
+                    NodeType.FunctionDeclaration,
+                    NodeType.FunctionExpression
                 ];
                 ];
 
 
                 if (Utils.arrayContains(functionNodes, node.type)) {
                 if (Utils.arrayContains(functionNodes, node.type)) {

+ 8 - 7
src/nodes/UnicodeArrayNode.js

@@ -1,9 +1,10 @@
 "use strict";
 "use strict";
 const escodegen = require('escodegen');
 const escodegen = require('escodegen');
 const estraverse = require('estraverse');
 const estraverse = require('estraverse');
+const AppendState_1 = require('../enums/AppendState');
+const NodeType_1 = require("../enums/NodeType");
 const Node_1 = require('./Node');
 const Node_1 = require('./Node');
 const Utils_1 = require('../Utils');
 const Utils_1 = require('../Utils');
-const AppendState_1 = require('../enums/AppendState');
 class UnicodeArrayNode extends Node_1.Node {
 class UnicodeArrayNode extends Node_1.Node {
     constructor(astTree, unicodeArrayName, unicodeArrayRotateValue = 0) {
     constructor(astTree, unicodeArrayName, unicodeArrayRotateValue = 0) {
         super();
         super();
@@ -18,7 +19,7 @@ class UnicodeArrayNode extends Node_1.Node {
         estraverse.replace(this.astTree, {
         estraverse.replace(this.astTree, {
             leave: (node, parent) => {
             leave: (node, parent) => {
                 switch (node.type) {
                 switch (node.type) {
-                    case 'Program':
+                    case NodeType_1.NodeType.Program:
                         node.body.unshift(this.getNode());
                         node.body.unshift(this.getNode());
                         break;
                         break;
                     default:
                     default:
@@ -40,19 +41,19 @@ class UnicodeArrayNode extends Node_1.Node {
     }
     }
     getNodeStructure() {
     getNodeStructure() {
         return {
         return {
-            'type': 'VariableDeclaration',
+            'type': NodeType_1.NodeType.VariableDeclaration,
             'declarations': [
             'declarations': [
                 {
                 {
-                    'type': 'VariableDeclarator',
+                    'type': NodeType_1.NodeType.VariableDeclarator,
                     'id': {
                     'id': {
-                        'type': 'Identifier',
+                        'type': NodeType_1.NodeType.Identifier,
                         'name': this.unicodeArrayName
                         'name': this.unicodeArrayName
                     },
                     },
                     'init': {
                     'init': {
-                        'type': 'ArrayExpression',
+                        'type': NodeType_1.NodeType.ArrayExpression,
                         'elements': this.unicodeArray.map((value) => {
                         'elements': this.unicodeArray.map((value) => {
                             return {
                             return {
-                                'type': 'Literal',
+                                'type': NodeType_1.NodeType.Literal,
                                 'value': value,
                                 'value': value,
                                 'raw': `'${value}'`,
                                 'raw': `'${value}'`,
                                 'x-verbatim-property': {
                                 'x-verbatim-property': {

+ 9 - 8
src/nodes/UnicodeArrayNode.ts

@@ -4,11 +4,12 @@ import * as estraverse from 'estraverse';
 import { IProgramNode } from '../interfaces/nodes/IProgramNode';
 import { IProgramNode } from '../interfaces/nodes/IProgramNode';
 import { ITreeNode } from '../interfaces/nodes/ITreeNode';
 import { ITreeNode } from '../interfaces/nodes/ITreeNode';
 
 
+import { AppendState } from '../enums/AppendState';
+import { NodeType } from "../enums/NodeType";
+
 import { Node } from './Node';
 import { Node } from './Node';
 import { Utils } from '../Utils';
 import { Utils } from '../Utils';
 
 
-import { AppendState } from '../enums/AppendState';
-
 export class UnicodeArrayNode extends Node {
 export class UnicodeArrayNode extends Node {
     /**
     /**
      * @type {number}
      * @type {number}
@@ -63,7 +64,7 @@ export class UnicodeArrayNode extends Node {
         estraverse.replace(this.astTree, {
         estraverse.replace(this.astTree, {
             leave: (node: ITreeNode, parent: ITreeNode): any => {
             leave: (node: ITreeNode, parent: ITreeNode): any => {
                 switch (node.type) {
                 switch (node.type) {
-                    case 'Program':
+                    case NodeType.Program:
                         (<IProgramNode>node).body.unshift(this.getNode());
                         (<IProgramNode>node).body.unshift(this.getNode());
 
 
                         break;
                         break;
@@ -105,19 +106,19 @@ export class UnicodeArrayNode extends Node {
      */
      */
     protected getNodeStructure (): any {
     protected getNodeStructure (): any {
         return {
         return {
-            'type': 'VariableDeclaration',
+            'type': NodeType.VariableDeclaration,
             'declarations': [
             'declarations': [
                 {
                 {
-                    'type': 'VariableDeclarator',
+                    'type': NodeType.VariableDeclarator,
                     'id': {
                     'id': {
-                        'type': 'Identifier',
+                        'type': NodeType.Identifier,
                         'name': this.unicodeArrayName
                         'name': this.unicodeArrayName
                     },
                     },
                     'init': {
                     'init': {
-                        'type': 'ArrayExpression',
+                        'type': NodeType.ArrayExpression,
                         'elements': this.unicodeArray.map((value: string) => {
                         'elements': this.unicodeArray.map((value: string) => {
                             return {
                             return {
-                                'type': 'Literal',
+                                'type': NodeType.Literal,
                                 'value': value,
                                 'value': value,
                                 'raw': `'${value}'`,
                                 'raw': `'${value}'`,
                                 'x-verbatim-property': {
                                 'x-verbatim-property': {

+ 8 - 7
src/nodes/UnicodeArrayRotateFunctionCallNode.js

@@ -1,5 +1,6 @@
 "use strict";
 "use strict";
 const estraverse = require('estraverse');
 const estraverse = require('estraverse');
+const NodeType_1 = require("../enums/NodeType");
 const Node_1 = require('./Node');
 const Node_1 = require('./Node');
 class UnicodeArrayRotateFunctionCallNode extends Node_1.Node {
 class UnicodeArrayRotateFunctionCallNode extends Node_1.Node {
     constructor(astTree, unicodeArrayRotateFunctionName, unicodeArrayName, unicodeArrayRotateValue) {
     constructor(astTree, unicodeArrayRotateFunctionName, unicodeArrayName, unicodeArrayRotateValue) {
@@ -14,7 +15,7 @@ class UnicodeArrayRotateFunctionCallNode extends Node_1.Node {
         estraverse.replace(this.astTree, {
         estraverse.replace(this.astTree, {
             leave: (node, parent) => {
             leave: (node, parent) => {
                 switch (node.type) {
                 switch (node.type) {
-                    case 'Program':
+                    case NodeType_1.NodeType.Program:
                         node.body.unshift(this.getNode());
                         node.body.unshift(this.getNode());
                         break;
                         break;
                     default:
                     default:
@@ -25,25 +26,25 @@ class UnicodeArrayRotateFunctionCallNode extends Node_1.Node {
     }
     }
     getNodeStructure() {
     getNodeStructure() {
         return {
         return {
-            'type': 'ExpressionStatement',
+            'type': NodeType_1.NodeType.ExpressionStatement,
             'expression': {
             'expression': {
-                'type': 'CallExpression',
+                'type': NodeType_1.NodeType.CallExpression,
                 'callee': {
                 'callee': {
-                    'type': 'Identifier',
+                    'type': NodeType_1.NodeType.Identifier,
                     'name': this.unicodeArrayRotateFunctionName
                     'name': this.unicodeArrayRotateFunctionName
                 },
                 },
                 'arguments': [
                 'arguments': [
                     {
                     {
-                        'type': 'Identifier',
+                        'type': NodeType_1.NodeType.Identifier,
                         'name': this.unicodeArrayName
                         'name': this.unicodeArrayName
                     },
                     },
                     {
                     {
-                        'type': 'Literal',
+                        'type': NodeType_1.NodeType.Literal,
                         'value': this.unicodeArrayRotateValue,
                         'value': this.unicodeArrayRotateValue,
                         'raw': `'${this.unicodeArrayRotateValue}'`
                         'raw': `'${this.unicodeArrayRotateValue}'`
                     },
                     },
                     {
                     {
-                        'type': 'Literal',
+                        'type': NodeType_1.NodeType.Literal,
                         'value': true,
                         'value': true,
                         'raw': 'true'
                         'raw': 'true'
                     }
                     }

+ 9 - 7
src/nodes/UnicodeArrayRotateFunctionCallNode.ts

@@ -3,6 +3,8 @@ import * as estraverse from 'estraverse';
 import { IProgramNode } from "../interfaces/nodes/IProgramNode";
 import { IProgramNode } from "../interfaces/nodes/IProgramNode";
 import { ITreeNode } from "../interfaces/nodes/ITreeNode";
 import { ITreeNode } from "../interfaces/nodes/ITreeNode";
 
 
+import { NodeType } from "../enums/NodeType";
+
 import { Node } from './Node';
 import { Node } from './Node';
 
 
 export class UnicodeArrayRotateFunctionCallNode extends Node {
 export class UnicodeArrayRotateFunctionCallNode extends Node {
@@ -56,7 +58,7 @@ export class UnicodeArrayRotateFunctionCallNode extends Node {
         estraverse.replace(this.astTree, {
         estraverse.replace(this.astTree, {
             leave: (node: ITreeNode, parent: ITreeNode): any => {
             leave: (node: ITreeNode, parent: ITreeNode): any => {
                 switch (node.type) {
                 switch (node.type) {
-                    case 'Program':
+                    case NodeType.Program:
                         (<IProgramNode>node).body.unshift(this.getNode());
                         (<IProgramNode>node).body.unshift(this.getNode());
 
 
                         break;
                         break;
@@ -73,25 +75,25 @@ export class UnicodeArrayRotateFunctionCallNode extends Node {
      */
      */
     protected getNodeStructure (): any {
     protected getNodeStructure (): any {
         return {
         return {
-            'type': 'ExpressionStatement',
+            'type': NodeType.ExpressionStatement,
             'expression': {
             'expression': {
-                'type': 'CallExpression',
+                'type': NodeType.CallExpression,
                 'callee': {
                 'callee': {
-                    'type': 'Identifier',
+                    'type': NodeType.Identifier,
                     'name': this.unicodeArrayRotateFunctionName
                     'name': this.unicodeArrayRotateFunctionName
                 },
                 },
                 'arguments': [
                 'arguments': [
                     {
                     {
-                        'type': 'Identifier',
+                        'type': NodeType.Identifier,
                         'name': this.unicodeArrayName
                         'name': this.unicodeArrayName
                     },
                     },
                     {
                     {
-                        'type': 'Literal',
+                        'type': NodeType.Literal,
                         'value': this.unicodeArrayRotateValue,
                         'value': this.unicodeArrayRotateValue,
                         'raw': `'${this.unicodeArrayRotateValue}'`
                         'raw': `'${this.unicodeArrayRotateValue}'`
                     },
                     },
                     {
                     {
-                        'type': 'Literal',
+                        'type': NodeType.Literal,
                         'value': true,
                         'value': true,
                         'raw': 'true'
                         'raw': 'true'
                     }
                     }

+ 58 - 57
src/nodes/UnicodeArrayRotateFunctionNode.js

@@ -1,5 +1,6 @@
 "use strict";
 "use strict";
 const estraverse = require('estraverse');
 const estraverse = require('estraverse');
+const NodeType_1 = require("../enums/NodeType");
 const Node_1 = require('./Node');
 const Node_1 = require('./Node');
 const Utils_1 = require('../Utils');
 const Utils_1 = require('../Utils');
 class UnicodeArrayRotateFunctionNode extends Node_1.Node {
 class UnicodeArrayRotateFunctionNode extends Node_1.Node {
@@ -14,7 +15,7 @@ class UnicodeArrayRotateFunctionNode extends Node_1.Node {
         estraverse.replace(this.astTree, {
         estraverse.replace(this.astTree, {
             leave: (node, parent) => {
             leave: (node, parent) => {
                 switch (node.type) {
                 switch (node.type) {
-                    case 'Program':
+                    case NodeType_1.NodeType.Program:
                         node.body.push(this.getNode());
                         node.body.push(this.getNode());
                         break;
                         break;
                     default:
                     default:
@@ -28,49 +29,49 @@ class UnicodeArrayRotateFunctionNode extends Node_1.Node {
     }
     }
     getNodeStructure() {
     getNodeStructure() {
         return {
         return {
-            'type': 'FunctionExpression',
+            'type': NodeType_1.NodeType.FunctionExpression,
             'id': {
             'id': {
-                'type': 'Identifier',
+                'type': NodeType_1.NodeType.Identifier,
                 'name': this.unicodeArrayRotateFunctionName
                 'name': this.unicodeArrayRotateFunctionName
             },
             },
             'params': [
             'params': [
                 {
                 {
-                    'type': 'Identifier',
+                    'type': NodeType_1.NodeType.Identifier,
                     'name': 'array'
                     'name': 'array'
                 },
                 },
                 {
                 {
-                    'type': 'Identifier',
+                    'type': NodeType_1.NodeType.Identifier,
                     'name': 'times'
                     'name': 'times'
                 },
                 },
                 {
                 {
-                    'type': 'Identifier',
+                    'type': NodeType_1.NodeType.Identifier,
                     'name': 'reverse'
                     'name': 'reverse'
                 }
                 }
             ],
             ],
             'defaults': [],
             'defaults': [],
             'body': {
             'body': {
-                'type': 'BlockStatement',
+                'type': NodeType_1.NodeType.BlockStatement,
                 'body': [
                 'body': [
                     {
                     {
-                        'type': 'IfStatement',
+                        'type': NodeType_1.NodeType.IfStatement,
                         'test': {
                         'test': {
-                            'type': 'BinaryExpression',
+                            'type': NodeType_1.NodeType.BinaryExpression,
                             'operator': '<',
                             'operator': '<',
                             'left': {
                             'left': {
-                                'type': 'Identifier',
+                                'type': NodeType_1.NodeType.Identifier,
                                 'name': 'times'
                                 'name': 'times'
                             },
                             },
                             'right': {
                             'right': {
-                                'type': 'Literal',
+                                'type': NodeType_1.NodeType.Literal,
                                 'value': 0,
                                 'value': 0,
                                 'raw': '0'
                                 'raw': '0'
                             }
                             }
                         },
                         },
                         'consequent': {
                         'consequent': {
-                            'type': 'BlockStatement',
+                            'type': NodeType_1.NodeType.BlockStatement,
                             'body': [
                             'body': [
                                 {
                                 {
-                                    'type': 'ReturnStatement',
+                                    'type': NodeType_1.NodeType.ReturnStatement,
                                     'argument': null
                                     'argument': null
                                 }
                                 }
                             ]
                             ]
@@ -78,23 +79,23 @@ class UnicodeArrayRotateFunctionNode extends Node_1.Node {
                         'alternate': null
                         'alternate': null
                     },
                     },
                     {
                     {
-                        'type': 'ExpressionStatement',
+                        'type': NodeType_1.NodeType.ExpressionStatement,
                         'expression': {
                         'expression': {
-                            'type': 'AssignmentExpression',
+                            'type': NodeType_1.NodeType.AssignmentExpression,
                             'operator': '=',
                             'operator': '=',
                             'left': {
                             'left': {
-                                'type': 'Identifier',
+                                'type': NodeType_1.NodeType.Identifier,
                                 'name': 'reverse'
                                 'name': 'reverse'
                             },
                             },
                             'right': {
                             'right': {
-                                'type': 'LogicalExpression',
+                                'type': NodeType_1.NodeType.LogicalExpression,
                                 'operator': '||',
                                 'operator': '||',
                                 'left': {
                                 'left': {
-                                    'type': 'Identifier',
+                                    'type': NodeType_1.NodeType.Identifier,
                                     'name': 'reverse'
                                     'name': 'reverse'
                                 },
                                 },
                                 'right': {
                                 'right': {
-                                    'type': 'Literal',
+                                    'type': NodeType_1.NodeType.Literal,
                                     'value': false,
                                     'value': false,
                                     'raw': 'false'
                                     'raw': 'false'
                                 }
                                 }
@@ -102,12 +103,12 @@ class UnicodeArrayRotateFunctionNode extends Node_1.Node {
                         }
                         }
                     },
                     },
                     {
                     {
-                        'type': 'VariableDeclaration',
+                        'type': NodeType_1.NodeType.VariableDeclaration,
                         'declarations': [
                         'declarations': [
                             {
                             {
-                                'type': 'VariableDeclarator',
+                                'type': NodeType_1.NodeType.VariableDeclarator,
                                 'id': {
                                 'id': {
-                                    'type': 'Identifier',
+                                    'type': NodeType_1.NodeType.Identifier,
                                     'name': 'temp'
                                     'name': 'temp'
                                 },
                                 },
                                 'init': null
                                 'init': null
@@ -116,53 +117,53 @@ class UnicodeArrayRotateFunctionNode extends Node_1.Node {
                         'kind': 'var'
                         'kind': 'var'
                     },
                     },
                     {
                     {
-                        'type': 'WhileStatement',
+                        'type': NodeType_1.NodeType.WhileStatement,
                         'test': {
                         'test': {
-                            'type': 'UpdateExpression',
+                            'type': NodeType_1.NodeType.UpdateExpression,
                             'operator': '--',
                             'operator': '--',
                             'argument': {
                             'argument': {
-                                'type': 'Identifier',
+                                'type': NodeType_1.NodeType.Identifier,
                                 'name': 'times'
                                 'name': 'times'
                             },
                             },
                             'prefix': false
                             'prefix': false
                         },
                         },
                         'body': {
                         'body': {
-                            'type': 'BlockStatement',
+                            'type': NodeType_1.NodeType.BlockStatement,
                             'body': [
                             'body': [
                                 {
                                 {
-                                    'type': 'IfStatement',
+                                    'type': NodeType_1.NodeType.IfStatement,
                                     'test': {
                                     'test': {
-                                        'type': 'UnaryExpression',
+                                        'type': NodeType_1.NodeType.UnaryExpression,
                                         'operator': '!',
                                         'operator': '!',
                                         'argument': {
                                         'argument': {
-                                            'type': 'Identifier',
+                                            'type': NodeType_1.NodeType.Identifier,
                                             'name': 'reverse'
                                             'name': 'reverse'
                                         },
                                         },
                                         'prefix': true
                                         'prefix': true
                                     },
                                     },
                                     'consequent': {
                                     'consequent': {
-                                        'type': 'BlockStatement',
+                                        'type': NodeType_1.NodeType.BlockStatement,
                                         'body': [
                                         'body': [
                                             {
                                             {
-                                                'type': 'ExpressionStatement',
+                                                'type': NodeType_1.NodeType.ExpressionStatement,
                                                 'expression': {
                                                 'expression': {
-                                                    'type': 'AssignmentExpression',
+                                                    'type': NodeType_1.NodeType.AssignmentExpression,
                                                     'operator': '=',
                                                     'operator': '=',
                                                     'left': {
                                                     'left': {
-                                                        'type': 'Identifier',
+                                                        'type': NodeType_1.NodeType.Identifier,
                                                         'name': 'temp'
                                                         'name': 'temp'
                                                     },
                                                     },
                                                     'right': {
                                                     'right': {
-                                                        'type': 'CallExpression',
+                                                        'type': NodeType_1.NodeType.CallExpression,
                                                         'callee': {
                                                         'callee': {
-                                                            'type': 'MemberExpression',
+                                                            'type': NodeType_1.NodeType.MemberExpression,
                                                             'computed': true,
                                                             'computed': true,
                                                             'object': {
                                                             'object': {
-                                                                'type': 'Identifier',
+                                                                'type': NodeType_1.NodeType.Identifier,
                                                                 'name': 'array'
                                                                 'name': 'array'
                                                             },
                                                             },
                                                             'property': {
                                                             'property': {
-                                                                'type': 'Literal',
+                                                                'type': NodeType_1.NodeType.Literal,
                                                                 'name': 'pop',
                                                                 'name': 'pop',
                                                                 'x-verbatim-property': Utils_1.Utils.stringToUnicode('pop')
                                                                 'x-verbatim-property': Utils_1.Utils.stringToUnicode('pop')
                                                             }
                                                             }
@@ -172,25 +173,25 @@ class UnicodeArrayRotateFunctionNode extends Node_1.Node {
                                                 }
                                                 }
                                             },
                                             },
                                             {
                                             {
-                                                'type': 'ExpressionStatement',
+                                                'type': NodeType_1.NodeType.ExpressionStatement,
                                                 'expression': {
                                                 'expression': {
-                                                    'type': 'CallExpression',
+                                                    'type': NodeType_1.NodeType.CallExpression,
                                                     'callee': {
                                                     'callee': {
-                                                        'type': 'MemberExpression',
+                                                        'type': NodeType_1.NodeType.MemberExpression,
                                                         'computed': true,
                                                         'computed': true,
                                                         'object': {
                                                         'object': {
-                                                            'type': 'Identifier',
+                                                            'type': NodeType_1.NodeType.Identifier,
                                                             'name': 'array'
                                                             'name': 'array'
                                                         },
                                                         },
                                                         'property': {
                                                         'property': {
-                                                            'type': 'Literal',
+                                                            'type': NodeType_1.NodeType.Literal,
                                                             'name': 'unshift',
                                                             'name': 'unshift',
                                                             'x-verbatim-property': Utils_1.Utils.stringToUnicode('unshift')
                                                             'x-verbatim-property': Utils_1.Utils.stringToUnicode('unshift')
                                                         }
                                                         }
                                                     },
                                                     },
                                                     'arguments': [
                                                     'arguments': [
                                                         {
                                                         {
-                                                            'type': 'Identifier',
+                                                            'type': NodeType_1.NodeType.Identifier,
                                                             'name': 'temp'
                                                             'name': 'temp'
                                                         }
                                                         }
                                                     ]
                                                     ]
@@ -199,28 +200,28 @@ class UnicodeArrayRotateFunctionNode extends Node_1.Node {
                                         ]
                                         ]
                                     },
                                     },
                                     'alternate': {
                                     'alternate': {
-                                        'type': 'BlockStatement',
+                                        'type': NodeType_1.NodeType.BlockStatement,
                                         'body': [
                                         'body': [
                                             {
                                             {
-                                                'type': 'ExpressionStatement',
+                                                'type': NodeType_1.NodeType.ExpressionStatement,
                                                 'expression': {
                                                 'expression': {
-                                                    'type': 'AssignmentExpression',
+                                                    'type': NodeType_1.NodeType.AssignmentExpression,
                                                     'operator': '=',
                                                     'operator': '=',
                                                     'left': {
                                                     'left': {
-                                                        'type': 'Identifier',
+                                                        'type': NodeType_1.NodeType.Identifier,
                                                         'name': 'temp'
                                                         'name': 'temp'
                                                     },
                                                     },
                                                     'right': {
                                                     'right': {
-                                                        'type': 'CallExpression',
+                                                        'type': NodeType_1.NodeType.CallExpression,
                                                         'callee': {
                                                         'callee': {
-                                                            'type': 'MemberExpression',
+                                                            'type': NodeType_1.NodeType.MemberExpression,
                                                             'computed': true,
                                                             'computed': true,
                                                             'object': {
                                                             'object': {
-                                                                'type': 'Identifier',
+                                                                'type': NodeType_1.NodeType.Identifier,
                                                                 'name': 'array'
                                                                 'name': 'array'
                                                             },
                                                             },
                                                             'property': {
                                                             'property': {
-                                                                'type': 'Literal',
+                                                                'type': NodeType_1.NodeType.Literal,
                                                                 'name': 'shift',
                                                                 'name': 'shift',
                                                                 'x-verbatim-property': Utils_1.Utils.stringToUnicode('shift')
                                                                 'x-verbatim-property': Utils_1.Utils.stringToUnicode('shift')
                                                             }
                                                             }
@@ -230,25 +231,25 @@ class UnicodeArrayRotateFunctionNode extends Node_1.Node {
                                                 }
                                                 }
                                             },
                                             },
                                             {
                                             {
-                                                'type': 'ExpressionStatement',
+                                                'type': NodeType_1.NodeType.ExpressionStatement,
                                                 'expression': {
                                                 'expression': {
-                                                    'type': 'CallExpression',
+                                                    'type': NodeType_1.NodeType.CallExpression,
                                                     'callee': {
                                                     'callee': {
-                                                        'type': 'MemberExpression',
+                                                        'type': NodeType_1.NodeType.MemberExpression,
                                                         'computed': true,
                                                         'computed': true,
                                                         'object': {
                                                         'object': {
-                                                            'type': 'Identifier',
+                                                            'type': NodeType_1.NodeType.Identifier,
                                                             'name': 'array'
                                                             'name': 'array'
                                                         },
                                                         },
                                                         'property': {
                                                         'property': {
-                                                            'type': 'Literal',
+                                                            'type': NodeType_1.NodeType.Literal,
                                                             'name': 'push',
                                                             'name': 'push',
                                                             'x-verbatim-property': Utils_1.Utils.stringToUnicode('push')
                                                             'x-verbatim-property': Utils_1.Utils.stringToUnicode('push')
                                                         }
                                                         }
                                                     },
                                                     },
                                                     'arguments': [
                                                     'arguments': [
                                                         {
                                                         {
-                                                            'type': 'Identifier',
+                                                            'type': NodeType_1.NodeType.Identifier,
                                                             'name': 'temp'
                                                             'name': 'temp'
                                                         }
                                                         }
                                                     ]
                                                     ]

+ 59 - 57
src/nodes/UnicodeArrayRotateFunctionNode.ts

@@ -3,6 +3,8 @@ import * as estraverse from 'estraverse';
 import { IProgramNode } from '../interfaces/nodes/IProgramNode';
 import { IProgramNode } from '../interfaces/nodes/IProgramNode';
 import { ITreeNode } from '../interfaces/nodes/ITreeNode';
 import { ITreeNode } from '../interfaces/nodes/ITreeNode';
 
 
+import { NodeType } from "../enums/NodeType";
+
 import { Node } from './Node';
 import { Node } from './Node';
 import { Utils } from '../Utils';
 import { Utils } from '../Utils';
 
 
@@ -48,7 +50,7 @@ export class UnicodeArrayRotateFunctionNode extends Node {
         estraverse.replace(this.astTree, {
         estraverse.replace(this.astTree, {
             leave: (node: ITreeNode, parent: ITreeNode): any => {
             leave: (node: ITreeNode, parent: ITreeNode): any => {
                 switch (node.type) {
                 switch (node.type) {
-                    case 'Program':
+                    case NodeType.Program:
                         (<IProgramNode>node).body.push(this.getNode());
                         (<IProgramNode>node).body.push(this.getNode());
 
 
                         break;
                         break;
@@ -72,49 +74,49 @@ export class UnicodeArrayRotateFunctionNode extends Node {
      */
      */
     protected getNodeStructure (): any {
     protected getNodeStructure (): any {
         return {
         return {
-            'type': 'FunctionExpression',
+            'type': NodeType.FunctionExpression,
             'id': {
             'id': {
-                'type': 'Identifier',
+                'type': NodeType.Identifier,
                 'name': this.unicodeArrayRotateFunctionName
                 'name': this.unicodeArrayRotateFunctionName
             },
             },
             'params': [
             'params': [
                 {
                 {
-                    'type': 'Identifier',
+                    'type': NodeType.Identifier,
                     'name': 'array'
                     'name': 'array'
                 },
                 },
                 {
                 {
-                    'type': 'Identifier',
+                    'type': NodeType.Identifier,
                     'name': 'times'
                     'name': 'times'
                 },
                 },
                 {
                 {
-                    'type': 'Identifier',
+                    'type': NodeType.Identifier,
                     'name': 'reverse'
                     'name': 'reverse'
                 }
                 }
             ],
             ],
             'defaults': [],
             'defaults': [],
             'body': {
             'body': {
-                'type': 'BlockStatement',
+                'type': NodeType.BlockStatement,
                 'body': [
                 'body': [
                     {
                     {
-                        'type': 'IfStatement',
+                        'type': NodeType.IfStatement,
                         'test': {
                         'test': {
-                            'type': 'BinaryExpression',
+                            'type': NodeType.BinaryExpression,
                             'operator': '<',
                             'operator': '<',
                             'left': {
                             'left': {
-                                'type': 'Identifier',
+                                'type': NodeType.Identifier,
                                 'name': 'times'
                                 'name': 'times'
                             },
                             },
                             'right': {
                             'right': {
-                                'type': 'Literal',
+                                'type': NodeType.Literal,
                                 'value': 0,
                                 'value': 0,
                                 'raw': '0'
                                 'raw': '0'
                             }
                             }
                         },
                         },
                         'consequent': {
                         'consequent': {
-                            'type': 'BlockStatement',
+                            'type': NodeType.BlockStatement,
                             'body': [
                             'body': [
                                 {
                                 {
-                                    'type': 'ReturnStatement',
+                                    'type': NodeType.ReturnStatement,
                                     'argument': null
                                     'argument': null
                                 }
                                 }
                             ]
                             ]
@@ -122,23 +124,23 @@ export class UnicodeArrayRotateFunctionNode extends Node {
                         'alternate': null
                         'alternate': null
                     },
                     },
                     {
                     {
-                        'type': 'ExpressionStatement',
+                        'type': NodeType.ExpressionStatement,
                         'expression': {
                         'expression': {
-                            'type': 'AssignmentExpression',
+                            'type': NodeType.AssignmentExpression,
                             'operator': '=',
                             'operator': '=',
                             'left': {
                             'left': {
-                                'type': 'Identifier',
+                                'type': NodeType.Identifier,
                                 'name': 'reverse'
                                 'name': 'reverse'
                             },
                             },
                             'right': {
                             'right': {
-                                'type': 'LogicalExpression',
+                                'type': NodeType.LogicalExpression,
                                 'operator': '||',
                                 'operator': '||',
                                 'left': {
                                 'left': {
-                                    'type': 'Identifier',
+                                    'type': NodeType.Identifier,
                                     'name': 'reverse'
                                     'name': 'reverse'
                                 },
                                 },
                                 'right': {
                                 'right': {
-                                    'type': 'Literal',
+                                    'type': NodeType.Literal,
                                     'value': false,
                                     'value': false,
                                     'raw': 'false'
                                     'raw': 'false'
                                 }
                                 }
@@ -146,12 +148,12 @@ export class UnicodeArrayRotateFunctionNode extends Node {
                         }
                         }
                     },
                     },
                     {
                     {
-                        'type': 'VariableDeclaration',
+                        'type': NodeType.VariableDeclaration,
                         'declarations': [
                         'declarations': [
                             {
                             {
-                                'type': 'VariableDeclarator',
+                                'type': NodeType.VariableDeclarator,
                                 'id': {
                                 'id': {
-                                    'type': 'Identifier',
+                                    'type': NodeType.Identifier,
                                     'name': 'temp'
                                     'name': 'temp'
                                 },
                                 },
                                 'init': null
                                 'init': null
@@ -160,53 +162,53 @@ export class UnicodeArrayRotateFunctionNode extends Node {
                         'kind': 'var'
                         'kind': 'var'
                     },
                     },
                     {
                     {
-                        'type': 'WhileStatement',
+                        'type': NodeType.WhileStatement,
                         'test': {
                         'test': {
-                            'type': 'UpdateExpression',
+                            'type': NodeType.UpdateExpression,
                             'operator': '--',
                             'operator': '--',
                             'argument': {
                             'argument': {
-                                'type': 'Identifier',
+                                'type': NodeType.Identifier,
                                 'name': 'times'
                                 'name': 'times'
                             },
                             },
                             'prefix': false
                             'prefix': false
                         },
                         },
                         'body': {
                         'body': {
-                            'type': 'BlockStatement',
+                            'type': NodeType.BlockStatement,
                             'body': [
                             'body': [
                                 {
                                 {
-                                    'type': 'IfStatement',
+                                    'type': NodeType.IfStatement,
                                     'test': {
                                     'test': {
-                                        'type': 'UnaryExpression',
+                                        'type': NodeType.UnaryExpression,
                                         'operator': '!',
                                         'operator': '!',
                                         'argument': {
                                         'argument': {
-                                            'type': 'Identifier',
+                                            'type': NodeType.Identifier,
                                             'name': 'reverse'
                                             'name': 'reverse'
                                         },
                                         },
                                         'prefix': true
                                         'prefix': true
                                     },
                                     },
                                     'consequent': {
                                     'consequent': {
-                                        'type': 'BlockStatement',
+                                        'type': NodeType.BlockStatement,
                                         'body': [
                                         'body': [
                                             {
                                             {
-                                                'type': 'ExpressionStatement',
+                                                'type': NodeType.ExpressionStatement,
                                                 'expression': {
                                                 'expression': {
-                                                    'type': 'AssignmentExpression',
+                                                    'type': NodeType.AssignmentExpression,
                                                     'operator': '=',
                                                     'operator': '=',
                                                     'left': {
                                                     'left': {
-                                                        'type': 'Identifier',
+                                                        'type': NodeType.Identifier,
                                                         'name': 'temp'
                                                         'name': 'temp'
                                                     },
                                                     },
                                                     'right': {
                                                     'right': {
-                                                        'type': 'CallExpression',
+                                                        'type': NodeType.CallExpression,
                                                         'callee': {
                                                         'callee': {
-                                                            'type': 'MemberExpression',
+                                                            'type': NodeType.MemberExpression,
                                                             'computed': true,
                                                             'computed': true,
                                                             'object': {
                                                             'object': {
-                                                                'type': 'Identifier',
+                                                                'type': NodeType.Identifier,
                                                                 'name': 'array'
                                                                 'name': 'array'
                                                             },
                                                             },
                                                             'property': {
                                                             'property': {
-                                                                'type': 'Literal',
+                                                                'type': NodeType.Literal,
                                                                 'name': 'pop',
                                                                 'name': 'pop',
                                                                 'x-verbatim-property': Utils.stringToUnicode('pop')
                                                                 'x-verbatim-property': Utils.stringToUnicode('pop')
                                                             }
                                                             }
@@ -216,25 +218,25 @@ export class UnicodeArrayRotateFunctionNode extends Node {
                                                 }
                                                 }
                                             },
                                             },
                                             {
                                             {
-                                                'type': 'ExpressionStatement',
+                                                'type': NodeType.ExpressionStatement,
                                                 'expression': {
                                                 'expression': {
-                                                    'type': 'CallExpression',
+                                                    'type': NodeType.CallExpression,
                                                     'callee': {
                                                     'callee': {
-                                                        'type': 'MemberExpression',
+                                                        'type': NodeType.MemberExpression,
                                                         'computed': true,
                                                         'computed': true,
                                                         'object': {
                                                         'object': {
-                                                            'type': 'Identifier',
+                                                            'type': NodeType.Identifier,
                                                             'name': 'array'
                                                             'name': 'array'
                                                         },
                                                         },
                                                         'property': {
                                                         'property': {
-                                                            'type': 'Literal',
+                                                            'type': NodeType.Literal,
                                                             'name': 'unshift',
                                                             'name': 'unshift',
                                                             'x-verbatim-property': Utils.stringToUnicode('unshift')
                                                             'x-verbatim-property': Utils.stringToUnicode('unshift')
                                                         }
                                                         }
                                                     },
                                                     },
                                                     'arguments': [
                                                     'arguments': [
                                                         {
                                                         {
-                                                            'type': 'Identifier',
+                                                            'type': NodeType.Identifier,
                                                             'name': 'temp'
                                                             'name': 'temp'
                                                         }
                                                         }
                                                     ]
                                                     ]
@@ -243,28 +245,28 @@ export class UnicodeArrayRotateFunctionNode extends Node {
                                         ]
                                         ]
                                     },
                                     },
                                     'alternate': {
                                     'alternate': {
-                                        'type': 'BlockStatement',
+                                        'type': NodeType.BlockStatement,
                                         'body': [
                                         'body': [
                                             {
                                             {
-                                                'type': 'ExpressionStatement',
+                                                'type': NodeType.ExpressionStatement,
                                                 'expression': {
                                                 'expression': {
-                                                    'type': 'AssignmentExpression',
+                                                    'type': NodeType.AssignmentExpression,
                                                     'operator': '=',
                                                     'operator': '=',
                                                     'left': {
                                                     'left': {
-                                                        'type': 'Identifier',
+                                                        'type': NodeType.Identifier,
                                                         'name': 'temp'
                                                         'name': 'temp'
                                                     },
                                                     },
                                                     'right': {
                                                     'right': {
-                                                        'type': 'CallExpression',
+                                                        'type': NodeType.CallExpression,
                                                         'callee': {
                                                         'callee': {
-                                                            'type': 'MemberExpression',
+                                                            'type': NodeType.MemberExpression,
                                                             'computed': true,
                                                             'computed': true,
                                                             'object': {
                                                             'object': {
-                                                                'type': 'Identifier',
+                                                                'type': NodeType.Identifier,
                                                                 'name': 'array'
                                                                 'name': 'array'
                                                             },
                                                             },
                                                             'property': {
                                                             'property': {
-                                                                'type': 'Literal',
+                                                                'type': NodeType.Literal,
                                                                 'name': 'shift',
                                                                 'name': 'shift',
                                                                 'x-verbatim-property': Utils.stringToUnicode('shift')
                                                                 'x-verbatim-property': Utils.stringToUnicode('shift')
                                                             }
                                                             }
@@ -274,25 +276,25 @@ export class UnicodeArrayRotateFunctionNode extends Node {
                                                 }
                                                 }
                                             },
                                             },
                                             {
                                             {
-                                                'type': 'ExpressionStatement',
+                                                'type': NodeType.ExpressionStatement,
                                                 'expression': {
                                                 'expression': {
-                                                    'type': 'CallExpression',
+                                                    'type': NodeType.CallExpression,
                                                     'callee': {
                                                     'callee': {
-                                                        'type': 'MemberExpression',
+                                                        'type': NodeType.MemberExpression,
                                                         'computed': true,
                                                         'computed': true,
                                                         'object': {
                                                         'object': {
-                                                            'type': 'Identifier',
+                                                            'type': NodeType.Identifier,
                                                             'name': 'array'
                                                             'name': 'array'
                                                         },
                                                         },
                                                         'property': {
                                                         'property': {
-                                                            'type': 'Literal',
+                                                            'type': NodeType.Literal,
                                                             'name': 'push',
                                                             'name': 'push',
                                                             'x-verbatim-property': Utils.stringToUnicode('push')
                                                             'x-verbatim-property': Utils.stringToUnicode('push')
                                                         }
                                                         }
                                                     },
                                                     },
                                                     'arguments': [
                                                     'arguments': [
                                                         {
                                                         {
-                                                            'type': 'Identifier',
+                                                            'type': NodeType.Identifier,
                                                             'name': 'temp'
                                                             'name': 'temp'
                                                         }
                                                         }
                                                     ]
                                                     ]

+ 1 - 5
tslint.json

@@ -136,11 +136,7 @@
       "check-module",
       "check-module",
       "check-function"
       "check-function"
     ],
     ],
-    "variable-name": [
-      true,
-      "check-format",
-      "allow-leading-underscore"
-    ],
+    "variable-name": false,
     "whitespace": [
     "whitespace": [
       true,
       true,
       "check-branch",
       "check-branch",