Ver código fonte

replaced `let` on `const`, added `readonly` keywords

sanex3339 8 anos atrás
pai
commit
e8fcbdf315
28 arquivos alterados com 120 adições e 127 exclusões
  1. 27 27
      dist/index.js
  2. 1 1
      src/Utils.ts
  3. 2 2
      src/cli/CLIUtils.ts
  4. 8 8
      src/cli/JavaScriptObfuscatorCLI.ts
  5. 1 1
      src/custom-nodes/AbstractCustomNode.ts
  6. 0 4
      src/interfaces/INodeTransformer.d.ts
  7. 3 3
      src/node-groups/AbstractNodesGroup.ts
  8. 3 3
      src/node-transformers/AbstractNodeTransformer.ts
  9. 1 1
      src/node-transformers/AbstractNodeTransformersFactory.ts
  10. 6 5
      src/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.ts
  11. 2 2
      src/node-transformers/node-control-flow-transformers/control-flow-replacers/AbstractControlFlowReplacer.ts
  12. 2 2
      src/node-transformers/node-obfuscators/CatchClauseObfuscator.ts
  13. 2 2
      src/node-transformers/node-obfuscators/FunctionDeclarationObfuscator.ts
  14. 5 8
      src/node-transformers/node-obfuscators/FunctionObfuscator.ts
  15. 2 2
      src/node-transformers/node-obfuscators/LabeledStatementObfuscator.ts
  16. 1 1
      src/node-transformers/node-obfuscators/LiteralObfuscator.ts
  17. 11 11
      src/node-transformers/node-obfuscators/MemberExpressionObfuscator.ts
  18. 1 1
      src/node-transformers/node-obfuscators/MethodDefinitionObfuscator.ts
  19. 11 11
      src/node-transformers/node-obfuscators/ObjectExpressionObfuscator.ts
  20. 2 2
      src/node-transformers/node-obfuscators/VariableDeclarationObfuscator.ts
  21. 2 2
      src/node-transformers/node-obfuscators/replacers/AbstractReplacer.ts
  22. 1 1
      src/node-transformers/node-obfuscators/replacers/IdentifierReplacer.ts
  23. 7 9
      src/node-transformers/node-obfuscators/replacers/StringLiteralReplacer.ts
  24. 4 4
      src/node/NodeUtils.ts
  25. 1 1
      src/options/Options.ts
  26. 6 6
      src/options/OptionsNormalizer.ts
  27. 4 3
      src/options/ValidationErrorsFormatter.ts
  28. 4 4
      src/stack-trace-analyzer/StackTraceAnalyzer.ts

+ 27 - 27
dist/index.js

@@ -88,7 +88,7 @@ module.exports =
 /******/ 	__webpack_require__.p = "";
 /******/
 /******/ 	// Load entry module and return exports
-/******/ 	return __webpack_require__(__webpack_require__.s = 104);
+/******/ 	return __webpack_require__(__webpack_require__.s = 105);
 /******/ })
 /************************************************************************/
 /******/ ([
@@ -1240,18 +1240,17 @@ var StringLiteralReplacer = function (_AbstractReplacer_1$A) {
             if (this.options.unicodeEscapeSequence) {
                 value = Utils_1.Utils.stringToUnicodeEscapeSequence(value);
             }
-            var stringArray = stringArrayNode.getNodeData(),
-                indexOfExistingValue = stringArray.getKeyOf(value),
-                indexOfValue = void 0,
-                hexadecimalIndex = void 0;
+            var stringArray = stringArrayNode.getNodeData();
+            var indexOfExistingValue = stringArray.getKeyOf(value);
+            var indexOfValue = void 0;
             if (indexOfExistingValue >= 0) {
                 indexOfValue = indexOfExistingValue;
             } else {
                 indexOfValue = stringArray.getLength();
                 stringArray.set(null, value);
             }
-            hexadecimalIndex = new NumberLiteralReplacer_1.NumberLiteralReplacer(this.nodes, this.options).replace(indexOfValue);
             var stringArrayCallsWrapper = this.nodes.get('stringArrayCallsWrapper');
+            var hexadecimalIndex = new NumberLiteralReplacer_1.NumberLiteralReplacer(this.nodes, this.options).replace(indexOfValue);
             if (!stringArrayCallsWrapper) {
                 throw new ReferenceError('`stringArrayCallsWrapper` node is not found in Map with custom node.');
             }
@@ -1879,8 +1878,8 @@ var JavaScriptObfuscatorCLI = function () {
     }, {
         key: 'buildOptions',
         value: function buildOptions() {
-            var obfuscatorOptions = {},
-                availableOptions = Object.keys(DefaultPreset_1.DEFAULT_PRESET);
+            var obfuscatorOptions = {};
+            var availableOptions = Object.keys(DefaultPreset_1.DEFAULT_PRESET);
             for (var option in this.commands) {
                 if (!this.commands.hasOwnProperty(option)) {
                     continue;
@@ -1915,8 +1914,8 @@ var JavaScriptObfuscatorCLI = function () {
     }, {
         key: 'processData',
         value: function processData() {
-            var options = this.buildOptions(),
-                outputCodePath = CLIUtils_1.CLIUtils.getOutputCodePath(this.commands.output, this.inputPath);
+            var options = this.buildOptions();
+            var outputCodePath = CLIUtils_1.CLIUtils.getOutputCodePath(this.commands.output, this.inputPath);
             if (options.sourceMap) {
                 this.processDataWithSourceMap(outputCodePath, options);
             } else {
@@ -3277,7 +3276,7 @@ var CatchClauseObfuscator = function (_AbstractNodeTransfor) {
         value: function storeCatchClauseParam(catchClauseNode) {
             var _this2 = this;
 
-            NodeUtils_1.NodeUtils.typedReplace(catchClauseNode.param, NodeType_1.NodeType.Identifier, {
+            NodeUtils_1.NodeUtils.typedTraverse(catchClauseNode.param, NodeType_1.NodeType.Identifier, {
                 enter: function enter(node) {
                     return _this2.identifierReplacer.storeNames(node.name);
                 }
@@ -3352,7 +3351,7 @@ var FunctionDeclarationObfuscator = function (_AbstractNodeTransfor) {
         value: function storeFunctionName(functionDeclarationNode) {
             var _this2 = this;
 
-            NodeUtils_1.NodeUtils.typedReplace(functionDeclarationNode.id, NodeType_1.NodeType.Identifier, {
+            NodeUtils_1.NodeUtils.typedTraverse(functionDeclarationNode.id, NodeType_1.NodeType.Identifier, {
                 enter: function enter(node) {
                     return _this2.identifierReplacer.storeNames(node.name);
                 }
@@ -3424,7 +3423,7 @@ var FunctionObfuscator = function (_AbstractNodeTransfor) {
             var _this2 = this;
 
             functionNode.params.forEach(function (paramsNode) {
-                NodeUtils_1.NodeUtils.typedReplace(paramsNode, NodeType_1.NodeType.Identifier, {
+                NodeUtils_1.NodeUtils.typedTraverse(paramsNode, NodeType_1.NodeType.Identifier, {
                     enter: function enter(node) {
                         return _this2.identifierReplacer.storeNames(node.name);
                     }
@@ -3436,7 +3435,7 @@ var FunctionObfuscator = function (_AbstractNodeTransfor) {
         value: function replaceFunctionParams(functionNode) {
             var _this3 = this;
 
-            var replaceVisitor = {
+            var traverseVisitor = {
                 enter: function enter(node, parentNode) {
                     if (Node_1.Node.isReplaceableIdentifierNode(node, parentNode)) {
                         var newNodeName = _this3.identifierReplacer.replace(node.name);
@@ -3448,9 +3447,9 @@ var FunctionObfuscator = function (_AbstractNodeTransfor) {
                 }
             };
             functionNode.params.forEach(function (paramsNode) {
-                estraverse.replace(paramsNode, replaceVisitor);
+                return estraverse.replace(paramsNode, traverseVisitor);
             });
-            estraverse.replace(functionNode.body, replaceVisitor);
+            estraverse.replace(functionNode.body, traverseVisitor);
         }
     }]);
 
@@ -3504,7 +3503,7 @@ var LabeledStatementObfuscator = function (_AbstractNodeTransfor) {
         value: function storeLabeledStatementName(labeledStatementNode) {
             var _this2 = this;
 
-            NodeUtils_1.NodeUtils.typedReplace(labeledStatementNode.label, NodeType_1.NodeType.Identifier, {
+            NodeUtils_1.NodeUtils.typedTraverse(labeledStatementNode.label, NodeType_1.NodeType.Identifier, {
                 enter: function enter(node) {
                     return _this2.identifierReplacer.storeNames(node.name);
                 }
@@ -3631,7 +3630,7 @@ var MemberExpressionObfuscator = function (_AbstractNodeTransfor) {
         value: function transformNode(memberExpressionNode) {
             var _this2 = this;
 
-            estraverse.replace(memberExpressionNode.property, {
+            estraverse.traverse(memberExpressionNode.property, {
                 enter: function enter(node, parentNode) {
                     if (Node_1.Node.isLiteralNode(node)) {
                         _this2.obfuscateLiteralProperty(node);
@@ -3650,8 +3649,8 @@ var MemberExpressionObfuscator = function (_AbstractNodeTransfor) {
     }, {
         key: 'obfuscateIdentifierProperty',
         value: function obfuscateIdentifierProperty(node) {
-            var nodeValue = node.name,
-                literalNode = {
+            var nodeValue = node.name;
+            var literalNode = {
                 raw: '\'' + nodeValue + '\'',
                 'x-verbatim-property': {
                     content: new StringLiteralReplacer_1.StringLiteralReplacer(this.nodes, this.options).replace(nodeValue),
@@ -3779,7 +3778,7 @@ var ObjectExpressionObfuscator = function (_AbstractNodeTransfor) {
                 if (property.shorthand) {
                     property.shorthand = false;
                 }
-                estraverse.replace(property.key, {
+                estraverse.traverse(property.key, {
                     enter: function enter(node, parentNode) {
                         if (Node_1.Node.isLiteralNode(node)) {
                             _this2.obfuscateLiteralPropertyKey(node);
@@ -3805,8 +3804,8 @@ var ObjectExpressionObfuscator = function (_AbstractNodeTransfor) {
     }, {
         key: 'obfuscateIdentifierPropertyKey',
         value: function obfuscateIdentifierPropertyKey(node) {
-            var nodeValue = node.name,
-                literalNode = {
+            var nodeValue = node.name;
+            var literalNode = {
                 raw: '\'' + nodeValue + '\'',
                 'x-verbatim-property': {
                     content: '\'' + Utils_1.Utils.stringToUnicodeEscapeSequence(nodeValue) + '\'',
@@ -3876,7 +3875,7 @@ var VariableDeclarationObfuscator = function (_AbstractNodeTransfor) {
             var _this2 = this;
 
             variableDeclarationNode.declarations.forEach(function (declarationNode) {
-                NodeUtils_1.NodeUtils.typedReplace(declarationNode.id, NodeType_1.NodeType.Identifier, {
+                NodeUtils_1.NodeUtils.typedTraverse(declarationNode.id, NodeType_1.NodeType.Identifier, {
                     enter: function enter(node) {
                         return _this2.identifierReplacer.storeNames(node.name);
                     }
@@ -4276,8 +4275,8 @@ var ValidationErrorsFormatter = function () {
     }, {
         key: "formatError",
         value: function formatError(validationError) {
-            var errorString = "`" + validationError.property + "` errors:\n",
-                constraints = validationError.constraints;
+            var constraints = validationError.constraints;
+            var errorString = "`" + validationError.property + "` errors:\n";
             for (var constraint in constraints) {
                 if (!constraints.hasOwnProperty(constraint)) {
                     continue;
@@ -5117,7 +5116,8 @@ module.exports = require("is-equal");
 module.exports = require("mkdirp");
 
 /***/ },
-/* 104 */
+/* 104 */,
+/* 105 */
 /***/ function(module, exports, __webpack_require__) {
 
 "use strict";

+ 1 - 1
src/Utils.ts

@@ -8,7 +8,7 @@ export class Utils {
     /**
      * @type {string}
      */
-    public static randomGeneratorPool: string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+    public static readonly randomGeneratorPool: string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
 
     /**
      * @type {Chance.Chance | Chance.SeededChance}

+ 2 - 2
src/cli/CLIUtils.ts

@@ -10,14 +10,14 @@ export class CLIUtils {
     /**
      * @type {string[]}
      */
-    private static availableInputExtensions: string[] = [
+    private static readonly availableInputExtensions: string[] = [
         '.js'
     ];
 
     /**
      * @type {BufferEncoding}
      */
-    private static encoding: BufferEncoding = 'utf8';
+    private static readonly encoding: BufferEncoding = 'utf8';
 
     /**
      * @param outputPath

+ 8 - 8
src/cli/JavaScriptObfuscatorCLI.ts

@@ -19,7 +19,7 @@ export class JavaScriptObfuscatorCLI {
     /**
      * @type {string[]}
      */
-    private arguments: string[];
+    private readonly arguments: string[];
 
     /**
      * @type {commander.ICommand}
@@ -69,7 +69,7 @@ export class JavaScriptObfuscatorCLI {
      * @returns {string}
      */
     private static parseSourceMapMode (value: string): string {
-        let availableMode: boolean = Object
+        const availableMode: boolean = Object
             .keys(SourceMapMode)
             .some((key: string): boolean => {
                 return SourceMapMode[key] === value;
@@ -121,8 +121,8 @@ export class JavaScriptObfuscatorCLI {
      * @returns {IObfuscatorOptions}
      */
     private buildOptions (): IObfuscatorOptions {
-        let obfuscatorOptions: IObfuscatorOptions = {},
-            availableOptions: string[] = Object.keys(DEFAULT_PRESET);
+        const obfuscatorOptions: IObfuscatorOptions = {};
+        const availableOptions: string[] = Object.keys(DEFAULT_PRESET);
 
         for (const option in this.commands) {
             if (!this.commands.hasOwnProperty(option)) {
@@ -181,8 +181,8 @@ export class JavaScriptObfuscatorCLI {
     }
 
     private processData (): void {
-        let options: IObfuscatorOptions = this.buildOptions(),
-            outputCodePath: string = CLIUtils.getOutputCodePath((<any>this.commands).output, this.inputPath);
+        const options: IObfuscatorOptions = this.buildOptions();
+        const outputCodePath: string = CLIUtils.getOutputCodePath((<any>this.commands).output, this.inputPath);
 
         if (options.sourceMap) {
             this.processDataWithSourceMap(outputCodePath, options);
@@ -196,7 +196,7 @@ export class JavaScriptObfuscatorCLI {
      * @param options
      */
     private processDataWithoutSourceMap (outputCodePath: string, options: IObfuscatorOptions): void {
-        let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(this.data, options).getObfuscatedCode();
+        const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(this.data, options).getObfuscatedCode();
 
         CLIUtils.writeFile(outputCodePath, obfuscatedCode);
     }
@@ -206,7 +206,7 @@ export class JavaScriptObfuscatorCLI {
      * @param options
      */
     private processDataWithSourceMap (outputCodePath: string, options: IObfuscatorOptions): void {
-        let outputSourceMapPath: string = CLIUtils.getOutputSourceMapPath(
+        const outputSourceMapPath: string = CLIUtils.getOutputSourceMapPath(
             outputCodePath,
             options.sourceMapFileName || ''
         );

+ 1 - 1
src/custom-nodes/AbstractCustomNode.ts

@@ -16,7 +16,7 @@ export abstract class AbstractCustomNode implements ICustomNode {
     /**
      * @type {IOptions}
      */
-    protected options: IOptions;
+    protected readonly options: IOptions;
 
     /**
      * @param options

+ 0 - 4
src/interfaces/INodeTransformer.d.ts

@@ -1,9 +1,5 @@
 import * as ESTree from 'estree';
 
 export interface INodeTransformer {
-    /**
-     * @param node
-     * @param parentNode
-     */
     transformNode (node: ESTree.Node, parentNode?: ESTree.Node): void;
 }

+ 3 - 3
src/node-groups/AbstractNodesGroup.ts

@@ -9,17 +9,17 @@ export abstract class AbstractNodesGroup implements INodesGroup {
     /**
      * @type {AppendState}
      */
-    protected appendState: AppendState = AppendState.BeforeObfuscation;
+    protected readonly appendState: AppendState = AppendState.BeforeObfuscation;
 
     /**
      * @type {IStackTraceData[]}
      */
-    protected stackTraceData: IStackTraceData[];
+    protected readonly stackTraceData: IStackTraceData[];
 
     /**
      * @type {IOptions}
      */
-    protected options: IOptions;
+    protected readonly options: IOptions;
 
     /**
      * @param stackTraceData

+ 3 - 3
src/node-transformers/AbstractNodeTransformer.ts

@@ -8,18 +8,18 @@ export abstract class AbstractNodeTransformer implements INodeTransformer {
     /**
      * @type Map <string, AbstractCustomNode>
      */
-    protected nodes: Map <string, ICustomNode>;
+    protected readonly nodes: Map <string, ICustomNode>;
 
     /**
      * @type {IOptions}
      */
-    protected options: IOptions;
+    protected readonly options: IOptions;
 
     /**
      * @param nodes
      * @param options
      */
-    constructor(nodes: Map <string, ICustomNode>, options: IOptions) {
+    constructor (nodes: Map <string, ICustomNode>, options: IOptions) {
         this.nodes = nodes;
         this.options = options;
     }

+ 1 - 1
src/node-transformers/AbstractNodeTransformersFactory.ts

@@ -25,7 +25,7 @@ export abstract class AbstractNodeTransformersFactory implements INodeTransforme
      * @param customNodes
      * @param options
      */
-    constructor(customNodes: Map <string, ICustomNode>, options: IOptions) {
+    constructor (customNodes: Map <string, ICustomNode>, options: IOptions) {
         this.customNodes = customNodes;
         this.options = options;
     }

+ 6 - 5
src/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.ts

@@ -6,6 +6,7 @@ import { TStatement } from '../../types/TStatement';
 
 import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode';
 import { IOptions } from '../../interfaces/IOptions';
+import { IStorage } from '../../interfaces/IStorage';
 
 import { NodeType } from '../../enums/NodeType';
 
@@ -17,13 +18,12 @@ import { Node } from '../../node/Node';
 import { NodeAppender } from '../../node/NodeAppender';
 import { Utils } from '../../Utils';
 import { NodeUtils } from '../../node/NodeUtils';
-import { IStorage } from '../../interfaces/IStorage';
 
 export class FunctionControlFlowTransformer extends AbstractNodeTransformer {
     /**
      * @type {Map <string, IReplacer>}
      */
-    private static controlFlowReplacers: Map <string, TControlFlowReplacer> = new Map <string, TControlFlowReplacer> ([
+    private static readonly controlFlowReplacers: Map <string, TControlFlowReplacer> = new Map <string, TControlFlowReplacer> ([
         [NodeType.BinaryExpression, BinaryExpressionControlFlowReplacer]
     ]);
 
@@ -31,7 +31,7 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer {
      * @param nodes
      * @param options
      */
-    constructor(nodes: Map <string, ICustomNode>, options: IOptions) {
+    constructor (nodes: Map <string, ICustomNode>, options: IOptions) {
         super(nodes, options);
     }
 
@@ -65,7 +65,8 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer {
                 }
 
                 const controlFlowStorageCallCustomNode: ICustomNode | undefined = new controlFlowReplacer(
-                    this.nodes, this.options
+                    this.nodes,
+                    this.options
                 ).replace(node, parentNode, controlFlowStorage, controlFlowStorageCustomNodeName);
 
                 if (!controlFlowStorageCallCustomNode) {
@@ -86,7 +87,7 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer {
             }
         });
 
-        const controlFlowStorageCustomNode: ControlFlowStorageNode = new ControlFlowStorageNode(
+        const controlFlowStorageCustomNode: ICustomNode = new ControlFlowStorageNode(
             controlFlowStorage,
             controlFlowStorageCustomNodeName,
             this.options

+ 2 - 2
src/node-transformers/node-control-flow-transformers/control-flow-replacers/AbstractControlFlowReplacer.ts

@@ -11,12 +11,12 @@ export abstract class AbstractControlFlowReplacer implements IControlFlowReplace
     /**
      * @type Map <string, AbstractCustomNode>
      */
-    protected nodes: Map <string, ICustomNode>;
+    protected readonly nodes: Map <string, ICustomNode>;
 
     /**
      * @type {IOptions}
      */
-    protected options : IOptions;
+    protected readonly options : IOptions;
 
     /**
      * @param nodes

+ 2 - 2
src/node-transformers/node-obfuscators/CatchClauseObfuscator.ts

@@ -23,7 +23,7 @@ export class CatchClauseObfuscator extends AbstractNodeTransformer {
     /**
      * @type {IdentifierReplacer}
      */
-    private identifierReplacer: IdentifierReplacer;
+    private readonly identifierReplacer: IdentifierReplacer;
 
     /**
      * @param nodes
@@ -47,7 +47,7 @@ export class CatchClauseObfuscator extends AbstractNodeTransformer {
      * @param catchClauseNode
      */
     private storeCatchClauseParam (catchClauseNode: ESTree.CatchClause): void {
-        NodeUtils.typedReplace(catchClauseNode.param, NodeType.Identifier, {
+        NodeUtils.typedTraverse(catchClauseNode.param, NodeType.Identifier, {
             enter: (node: ESTree.Identifier) => this.identifierReplacer.storeNames(node.name)
         });
     }

+ 2 - 2
src/node-transformers/node-obfuscators/FunctionDeclarationObfuscator.ts

@@ -26,7 +26,7 @@ export class FunctionDeclarationObfuscator extends AbstractNodeTransformer {
     /**
      * @type {IdentifierReplacer}
      */
-    private identifierReplacer: IdentifierReplacer;
+    private readonly identifierReplacer: IdentifierReplacer;
 
     /**
      * @param nodes
@@ -58,7 +58,7 @@ export class FunctionDeclarationObfuscator extends AbstractNodeTransformer {
      * @param functionDeclarationNode
      */
     private storeFunctionName (functionDeclarationNode: ESTree.FunctionDeclaration): void {
-        NodeUtils.typedReplace(functionDeclarationNode.id, NodeType.Identifier, {
+        NodeUtils.typedTraverse(functionDeclarationNode.id, NodeType.Identifier, {
             enter: (node: ESTree.Identifier) => this.identifierReplacer.storeNames(node.name)
         });
     }

+ 5 - 8
src/node-transformers/node-obfuscators/FunctionObfuscator.ts

@@ -23,7 +23,7 @@ export class FunctionObfuscator extends AbstractNodeTransformer {
     /**
      * @type {IdentifierReplacer}
      */
-    private identifierReplacer: IdentifierReplacer;
+    private readonly identifierReplacer: IdentifierReplacer;
 
     /**
      * @param nodes
@@ -49,7 +49,7 @@ export class FunctionObfuscator extends AbstractNodeTransformer {
     private storeFunctionParams (functionNode: ESTree.Function): void {
         functionNode.params
             .forEach((paramsNode: ESTree.Node) => {
-                NodeUtils.typedReplace(paramsNode, NodeType.Identifier, {
+                NodeUtils.typedTraverse(paramsNode, NodeType.Identifier, {
                     enter: (node: ESTree.Identifier) => this.identifierReplacer.storeNames(node.name)
                 });
             });
@@ -59,7 +59,7 @@ export class FunctionObfuscator extends AbstractNodeTransformer {
      * @param functionNode
      */
     private replaceFunctionParams (functionNode: ESTree.Function): void {
-        let replaceVisitor: estraverse.Visitor = {
+        let traverseVisitor: estraverse.Visitor = {
             enter: (node: ESTree.Node, parentNode: ESTree.Node): any => {
                 if (Node.isReplaceableIdentifierNode(node, parentNode)) {
                     const newNodeName: string = this.identifierReplacer.replace(node.name);
@@ -72,11 +72,8 @@ export class FunctionObfuscator extends AbstractNodeTransformer {
             }
         };
 
-        functionNode.params
-            .forEach((paramsNode: ESTree.Node) => {
-                estraverse.replace(paramsNode, replaceVisitor);
-            });
+        functionNode.params.forEach((paramsNode: ESTree.Node) => estraverse.replace(paramsNode, traverseVisitor));
 
-        estraverse.replace(functionNode.body, replaceVisitor);
+        estraverse.replace(functionNode.body, traverseVisitor);
     }
 }

+ 2 - 2
src/node-transformers/node-obfuscators/LabeledStatementObfuscator.ts

@@ -31,7 +31,7 @@ export class LabeledStatementObfuscator extends AbstractNodeTransformer {
     /**
      * @type {IdentifierReplacer}
      */
-    private identifierReplacer: IdentifierReplacer;
+    private readonly identifierReplacer: IdentifierReplacer;
 
     /**
      * @param nodes
@@ -55,7 +55,7 @@ export class LabeledStatementObfuscator extends AbstractNodeTransformer {
      * @param labeledStatementNode
      */
     private storeLabeledStatementName (labeledStatementNode: ESTree.LabeledStatement): void {
-        NodeUtils.typedReplace(labeledStatementNode.label, NodeType.Identifier, {
+        NodeUtils.typedTraverse(labeledStatementNode.label, NodeType.Identifier, {
             enter: (node: ESTree.Identifier) => this.identifierReplacer.storeNames(node.name)
         });
     }

+ 1 - 1
src/node-transformers/node-obfuscators/LiteralObfuscator.ts

@@ -34,7 +34,7 @@ export class LiteralObfuscator extends AbstractNodeTransformer {
 
             case 'string':
                 content = new StringLiteralReplacer(this.nodes, this.options)
-                        .replace(<string>literalNode.value);
+                    .replace(<string>literalNode.value);
 
                 break;
 

+ 11 - 11
src/node-transformers/node-obfuscators/MemberExpressionObfuscator.ts

@@ -13,7 +13,7 @@ export class MemberExpressionObfuscator extends AbstractNodeTransformer {
      * @param memberExpressionNode
      */
     public transformNode (memberExpressionNode: ESTree.MemberExpression): void {
-        estraverse.replace(memberExpressionNode.property, {
+        estraverse.traverse(memberExpressionNode.property, {
             enter: (node: ESTree.Node, parentNode: ESTree.Node): any => {
                 if (Node.isLiteralNode(node)) {
                     this.obfuscateLiteralProperty(node);
@@ -46,16 +46,16 @@ export class MemberExpressionObfuscator extends AbstractNodeTransformer {
      * @param node
      */
     private obfuscateIdentifierProperty (node: ESTree.Identifier): void {
-        let nodeValue: string = node.name,
-            literalNode: ESTree.Literal = {
-                raw: `'${nodeValue}'`,
-                'x-verbatim-property': {
-                    content : new StringLiteralReplacer(this.nodes, this.options).replace(nodeValue),
-                    precedence: escodegen.Precedence.Primary
-                },
-                type: NodeType.Literal,
-                value: nodeValue
-            };
+        const nodeValue: string = node.name;
+        const literalNode: ESTree.Literal = {
+            raw: `'${nodeValue}'`,
+            'x-verbatim-property': {
+                content : new StringLiteralReplacer(this.nodes, this.options).replace(nodeValue),
+                precedence: escodegen.Precedence.Primary
+            },
+            type: NodeType.Literal,
+            value: nodeValue
+        };
 
         delete node.name;
 

+ 1 - 1
src/node-transformers/node-obfuscators/MethodDefinitionObfuscator.ts

@@ -17,7 +17,7 @@ export class MethodDefinitionObfuscator extends AbstractNodeTransformer {
     /**
      * @type {string[]}
      */
-    private static ignoredNames: string[] = ['constructor'];
+    private static readonly ignoredNames: string[] = ['constructor'];
 
     /**
      * @param methodDefinitionNode

+ 11 - 11
src/node-transformers/node-obfuscators/ObjectExpressionObfuscator.ts

@@ -29,7 +29,7 @@ export class ObjectExpressionObfuscator extends AbstractNodeTransformer {
                     property.shorthand = false;
                 }
 
-                estraverse.replace(property.key, {
+                estraverse.traverse(property.key, {
                     enter: (node: ESTree.Node, parentNode: ESTree.Node): any => {
                         if (Node.isLiteralNode(node)) {
                             this.obfuscateLiteralPropertyKey(node);
@@ -61,16 +61,16 @@ export class ObjectExpressionObfuscator extends AbstractNodeTransformer {
      * @param node
      */
     private obfuscateIdentifierPropertyKey (node: ESTree.Identifier): void {
-        let nodeValue: string = node.name,
-            literalNode: ESTree.Literal = {
-                raw: `'${nodeValue}'`,
-                'x-verbatim-property': {
-                    content : `'${Utils.stringToUnicodeEscapeSequence(nodeValue)}'`,
-                    precedence: escodegen.Precedence.Primary
-                },
-                type: NodeType.Literal,
-                value: nodeValue
-            };
+        const nodeValue: string = node.name;
+        const literalNode: ESTree.Literal = {
+            raw: `'${nodeValue}'`,
+            'x-verbatim-property': {
+                content : `'${Utils.stringToUnicodeEscapeSequence(nodeValue)}'`,
+                precedence: escodegen.Precedence.Primary
+            },
+            type: NodeType.Literal,
+            value: nodeValue
+        };
 
         delete node.name;
 

+ 2 - 2
src/node-transformers/node-obfuscators/VariableDeclarationObfuscator.ts

@@ -27,7 +27,7 @@ export class VariableDeclarationObfuscator extends AbstractNodeTransformer {
     /**
      * @type {IdentifierReplacer}
      */
-    private identifierReplacer: IdentifierReplacer;
+    private readonly identifierReplacer: IdentifierReplacer;
 
     /**
      * @param nodes
@@ -65,7 +65,7 @@ export class VariableDeclarationObfuscator extends AbstractNodeTransformer {
     private storeVariableNames (variableDeclarationNode: ESTree.VariableDeclaration): void {
         variableDeclarationNode.declarations
             .forEach((declarationNode: ESTree.VariableDeclarator) => {
-                NodeUtils.typedReplace(declarationNode.id, NodeType.Identifier, {
+                NodeUtils.typedTraverse(declarationNode.id, NodeType.Identifier, {
                     enter: (node: ESTree.Identifier) => this.identifierReplacer.storeNames(node.name)
                 });
             });

+ 2 - 2
src/node-transformers/node-obfuscators/replacers/AbstractReplacer.ts

@@ -6,12 +6,12 @@ export abstract class AbstractReplacer implements IReplacer {
     /**
      * @type Map <string, AbstractCustomNode>
      */
-    protected nodes: Map <string, ICustomNode>;
+    protected readonly nodes: Map <string, ICustomNode>;
 
     /**
      * @type {IOptions}
      */
-    protected options : IOptions;
+    protected readonly options : IOptions;
 
     /**
      * @param nodes

+ 1 - 1
src/node-transformers/node-obfuscators/replacers/IdentifierReplacer.ts

@@ -5,7 +5,7 @@ export class IdentifierReplacer extends AbstractReplacer {
     /**
      * @type {Map<string, string>}
      */
-    private namesMap: Map<string, string> = new Map<string, string>();
+    private readonly namesMap: Map<string, string> = new Map<string, string>();
 
     /**
      * @param nodeValue

+ 7 - 9
src/node-transformers/node-obfuscators/replacers/StringLiteralReplacer.ts

@@ -12,12 +12,12 @@ export class StringLiteralReplacer extends AbstractReplacer {
     /**
      * @type {number}
      */
-    private static minimumLengthForStringArray: number = 3;
+    private static readonly minimumLengthForStringArray: number = 3;
 
     /**
      * @type {string[]}
      */
-    private static rc4Keys: string[] = Utils.getRandomGenerator()
+    private static readonly rc4Keys: string[] = Utils.getRandomGenerator()
         .n(() => Utils.getRandomGenerator().string({length: 4}), 50);
 
     /**
@@ -67,10 +67,10 @@ export class StringLiteralReplacer extends AbstractReplacer {
             value = Utils.stringToUnicodeEscapeSequence(value);
         }
 
-        let stringArray: IStorage <string> = stringArrayNode.getNodeData(),
-            indexOfExistingValue: number = <number>stringArray.getKeyOf(value),
-            indexOfValue: number,
-            hexadecimalIndex: string;
+        const stringArray: IStorage <string> = stringArrayNode.getNodeData();
+        const indexOfExistingValue: number = <number>stringArray.getKeyOf(value);
+
+        let indexOfValue: number;
 
         if (indexOfExistingValue >= 0) {
             indexOfValue = indexOfExistingValue;
@@ -79,10 +79,8 @@ export class StringLiteralReplacer extends AbstractReplacer {
             stringArray.set(null, value);
         }
 
-        hexadecimalIndex = new NumberLiteralReplacer(this.nodes, this.options)
-            .replace(indexOfValue);
-
         const stringArrayCallsWrapper: ICustomNodeWithIdentifier = <ICustomNodeWithIdentifier>this.nodes.get('stringArrayCallsWrapper');
+        const hexadecimalIndex: string = new NumberLiteralReplacer(this.nodes, this.options).replace(indexOfValue);
 
         if (!stringArrayCallsWrapper) {
             throw new ReferenceError('`stringArrayCallsWrapper` node is not found in Map with custom node.');

+ 4 - 4
src/node/NodeUtils.ts

@@ -15,7 +15,7 @@ export class NodeUtils {
     /**
      * @type {string[]}
      */
-    private static nodesWithBlockScope: string[] = [
+    private static readonly nodesWithBlockScope: string[] = [
         NodeType.ArrowFunctionExpression,
         NodeType.FunctionDeclaration,
         NodeType.FunctionExpression,
@@ -42,7 +42,7 @@ export class NodeUtils {
      * @returns {TStatement[]}
      */
     public static convertCodeToStructure (code: string): TStatement[] {
-        let structure: ESTree.Program = esprima.parse(code);
+        const structure: ESTree.Program = esprima.parse(code);
 
         NodeUtils.addXVerbatimPropertyToLiterals(structure);
         NodeUtils.parentize(structure);
@@ -73,7 +73,7 @@ export class NodeUtils {
      * @returns {ESTree.Node}
      */
     public static getBlockScopeOfNode (node: ESTree.Node, depth: number = 0): TNodeWithBlockStatement {
-        let parentNode: ESTree.Node | undefined = node.parentNode;
+        const parentNode: ESTree.Node | undefined = node.parentNode;
 
         if (!parentNode) {
             throw new ReferenceError('`parentNode` property of given node is `undefined`');
@@ -106,7 +106,7 @@ export class NodeUtils {
      * @returns {number}
      */
     public static getNodeBlockScopeDepth (node: ESTree.Node, depth: number = 0): number {
-        let parentNode: ESTree.Node | undefined = node.parentNode;
+        const parentNode: ESTree.Node | undefined = node.parentNode;
 
         if (!parentNode) {
             throw new ReferenceError('`parentNode` property of given node is `undefined`');

+ 1 - 1
src/options/Options.ts

@@ -164,7 +164,7 @@ export class Options implements IOptions {
     constructor (obfuscatorOptions: IObfuscatorOptions) {
         Object.assign(this, DEFAULT_PRESET, obfuscatorOptions);
 
-        let errors: ValidationError[] = validateSync(this, Options.validatorOptions);
+        const errors: ValidationError[] = validateSync(this, Options.validatorOptions);
 
         if (errors.length) {
             throw new ReferenceError(`Validation failed. errors:\n${ValidationErrorsFormatter.format(errors)}`);

+ 6 - 6
src/options/OptionsNormalizer.ts

@@ -9,7 +9,7 @@ export class OptionsNormalizer {
     /**
      * @type {IObfuscatorOptions}
      */
-    private static DISABLED_UNICODE_ARRAY_OPTIONS: IObfuscatorOptions = {
+    private static readonly DISABLED_UNICODE_ARRAY_OPTIONS: IObfuscatorOptions = {
         rotateStringArray: false,
         stringArray: false,
         stringArrayEncoding: false,
@@ -19,7 +19,7 @@ export class OptionsNormalizer {
     /**
      * @type {IObfuscatorOptions}
      */
-    private static SELF_DEFENDING_OPTIONS: IObfuscatorOptions = {
+    private static readonly SELF_DEFENDING_OPTIONS: IObfuscatorOptions = {
         compact: true,
         selfDefending: true
     };
@@ -27,14 +27,14 @@ export class OptionsNormalizer {
     /**
      * @type {IObfuscatorOptions}
      */
-    private static UNICODE_ARRAY_ENCODING_OPTIONS: IObfuscatorOptions = {
+    private static readonly UNICODE_ARRAY_ENCODING_OPTIONS: IObfuscatorOptions = {
         stringArrayEncoding: 'base64'
     };
 
     /**
      * @type {TOptionsNormalizerRule[]}
      */
-    private static normalizerRules: TOptionsNormalizerRule[] = [
+    private static readonly normalizerRules: TOptionsNormalizerRule[] = [
         OptionsNormalizer.domainLockRule,
         OptionsNormalizer.selfDefendingRule,
         OptionsNormalizer.sourceMapBaseUrlRule,
@@ -64,7 +64,7 @@ export class OptionsNormalizer {
      */
     private static domainLockRule (options: IOptions): IOptions {
         if (options.domainLock.length) {
-            let normalizedDomains: string[] = [];
+            const normalizedDomains: string[] = [];
 
             for (const domain of options.domainLock) {
                 normalizedDomains.push(Utils.extractDomainFromUrl(domain));
@@ -95,7 +95,7 @@ export class OptionsNormalizer {
      * @returns {IOptions}
      */
     private static sourceMapBaseUrlRule (options: IOptions): IOptions {
-        let sourceMapBaseUrl: string = options.sourceMapBaseUrl;
+        const sourceMapBaseUrl: string = options.sourceMapBaseUrl;
 
         if (!options.sourceMapFileName) {
             Object.assign(options, {

+ 4 - 3
src/options/ValidationErrorsFormatter.ts

@@ -6,7 +6,7 @@ export class ValidationErrorsFormatter {
      * @returns {string}
      */
     public static format (validationErrors: ValidationError[]): string {
-        let errorsArray: string[] = [];
+        const errorsArray: string[] = [];
 
         for (const error of validationErrors) {
             errorsArray.push(ValidationErrorsFormatter.formatError(error));
@@ -20,8 +20,9 @@ export class ValidationErrorsFormatter {
      * @returns {string}
      */
     private static formatError (validationError: ValidationError): string {
-        let errorString: string = `\`${validationError.property}\` errors:\n`,
-            constraints: {[type: string]: string} = validationError.constraints;
+        const constraints: {[type: string]: string} = validationError.constraints;
+
+        let errorString: string = `\`${validationError.property}\` errors:\n`;
 
         for (const constraint in constraints) {
             if (!constraints.hasOwnProperty(constraint)) {

+ 4 - 4
src/stack-trace-analyzer/StackTraceAnalyzer.ts

@@ -51,17 +51,17 @@ export class StackTraceAnalyzer implements IStackTraceAnalyzer {
     /**
      * @type {number}
      */
-    private static limitThresholdActivationLength: number = 25;
+    private static readonly limitThresholdActivationLength: number = 25;
 
     /**
      * @type {number}
      */
-    private static limitThreshold: number = 0.002;
+    private static readonly limitThreshold: number = 0.002;
 
     /**
      * @type {Map<string, TCalleeDataExtractor>}
      */
-    private calleeDataExtractors: Map <string, TCalleeDataExtractor> = new Map <string, TCalleeDataExtractor> ([
+    private readonly calleeDataExtractors: Map <string, TCalleeDataExtractor> = new Map <string, TCalleeDataExtractor> ([
         [NodeType.FunctionDeclaration, FunctionDeclarationCalleeDataExtractor],
         [NodeType.FunctionExpression, FunctionExpressionCalleeDataExtractor],
         [NodeType.ObjectExpression, ObjectExpressionCalleeDataExtractor]
@@ -111,7 +111,7 @@ export class StackTraceAnalyzer implements IStackTraceAnalyzer {
             index < blockScopeBodyLength;
             index++
         ) {
-            let rootNode: ESTree.Node = blockScopeBody[index];
+            const rootNode: ESTree.Node = blockScopeBody[index];
 
             if (index > limitIndex) {
                 break;