Explorar o código

`stringArrayIntermediateVariablesCount` option rework

sanex %!s(int64=4) %!d(string=hai) anos
pai
achega
5bbbc901d4

+ 68 - 129
dist/index.cli.js

@@ -293,7 +293,7 @@ let JavaScriptObfuscator = JavaScriptObfuscator_1 = class JavaScriptObfuscator {
             sourceCode = '';
         }
         const timeStart = Date.now();
-        this.logger.info(LoggingMessage_1.LoggingMessage.Version, Utils_1.Utils.buildVersionMessage("2.2.0", 1599686797505));
+        this.logger.info(LoggingMessage_1.LoggingMessage.Version, Utils_1.Utils.buildVersionMessage("2.2.0", 1599726508600));
         this.logger.info(LoggingMessage_1.LoggingMessage.ObfuscationStarted);
         this.logger.info(LoggingMessage_1.LoggingMessage.RandomGeneratorSeed, this.randomGenerator.getInputSeed());
         sourceCode = this.runCodeTransformationStage(sourceCode, CodeTransformationStage_1.CodeTransformationStage.PreparingTransformers);
@@ -1475,7 +1475,7 @@ class JavaScriptObfuscatorCLI {
     configureCommands() {
         this.commands
             .usage('<inputPath> [options]')
-            .version(Utils_1.Utils.buildVersionMessage("2.2.0", 1599686797505), '-v, --version')
+            .version(Utils_1.Utils.buildVersionMessage("2.2.0", 1599726508600), '-v, --version')
             .option('-o, --output <path>', 'Output path for obfuscated code')
             .option('--compact <boolean>', 'Disable one line output code compacting', BooleanSanitizer_1.BooleanSanitizer)
             .option('--config <boolean>', 'Name of js / json config file')
@@ -5168,7 +5168,7 @@ let StringArrayCallsWrapperBase64CodeHelper = class StringArrayCallsWrapperBase6
             atobPolyfill,
             atobFunctionName,
             selfDefendingCode,
-            stringArrayCallsWrapperName: this.stringArrayCallsWrapperNames.name
+            stringArrayCallsWrapperName: this.stringArrayCallsWrapperName
         });
     }
 };
@@ -5201,7 +5201,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
 var __param = (this && this.__param) || function (paramIndex, decorator) {
     return function (target, key) { decorator(target, key, paramIndex); }
 };
-var _a, _b, _c, _d, _e, _f, _g;
+var _a, _b, _c, _d, _e, _f;
 Object.defineProperty(exports, "__esModule", { value: true });
 exports.StringArrayCallsWrapperCodeHelper = void 0;
 const inversify_1 = __webpack_require__(/*! inversify */ "inversify");
@@ -5212,11 +5212,9 @@ const ICustomCodeHelperObfuscator_1 = __webpack_require__(/*! ../../interfaces/c
 const IEscapeSequenceEncoder_1 = __webpack_require__(/*! ../../interfaces/utils/IEscapeSequenceEncoder */ "./src/interfaces/utils/IEscapeSequenceEncoder.ts");
 const IOptions_1 = __webpack_require__(/*! ../../interfaces/options/IOptions */ "./src/interfaces/options/IOptions.ts");
 const IRandomGenerator_1 = __webpack_require__(/*! ../../interfaces/utils/IRandomGenerator */ "./src/interfaces/utils/IRandomGenerator.ts");
-const IStringArrayCallsWrapperNames_1 = __webpack_require__(/*! ../../interfaces/node-transformers/string-array-transformers/IStringArrayCallsWrapperNames */ "./src/interfaces/node-transformers/string-array-transformers/IStringArrayCallsWrapperNames.ts");
 const Initializable_1 = __webpack_require__(/*! ../../decorators/Initializable */ "./src/decorators/Initializable.ts");
 const SelfDefendingTemplate_1 = __webpack_require__(/*! ./templates/string-array-calls-wrapper/SelfDefendingTemplate */ "./src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/SelfDefendingTemplate.ts");
 const StringArrayCallsWrapperTemplate_1 = __webpack_require__(/*! ./templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate */ "./src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts");
-const StringArrayCallsWrapperIntermediateTemplate_1 = __webpack_require__(/*! ./templates/string-array-calls-wrapper/StringArrayCallsWrapperIntermediateTemplate */ "./src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperIntermediateTemplate.ts");
 const AbstractCustomCodeHelper_1 = __webpack_require__(/*! ../AbstractCustomCodeHelper */ "./src/custom-code-helpers/AbstractCustomCodeHelper.ts");
 const NodeUtils_1 = __webpack_require__(/*! ../../node/NodeUtils */ "./src/node/NodeUtils.ts");
 let StringArrayCallsWrapperCodeHelper = class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper_1.AbstractCustomCodeHelper {
@@ -5224,21 +5222,19 @@ let StringArrayCallsWrapperCodeHelper = class StringArrayCallsWrapperCodeHelper
         super(identifierNamesGeneratorFactory, customCodeHelperFormatter, customCodeHelperObfuscator, randomGenerator, options);
         this.escapeSequenceEncoder = escapeSequenceEncoder;
     }
-    initialize(stringArrayName, stringArrayCallsWrapperNames) {
+    initialize(stringArrayName, stringArrayCallsWrapperName) {
         this.stringArrayName = stringArrayName;
-        this.stringArrayCallsWrapperNames = stringArrayCallsWrapperNames;
+        this.stringArrayCallsWrapperName = stringArrayCallsWrapperName;
     }
     getNodeStructure(codeHelperTemplate) {
         return NodeUtils_1.NodeUtils.convertCodeToStructure(codeHelperTemplate);
     }
     getCodeHelperTemplate() {
         const decodeCodeHelperTemplate = this.getDecodeStringArrayTemplate();
-        const intermediateTemplate = this.getIntermediateTemplate();
         const preservedNames = [`^${this.stringArrayName}$`];
         return this.customCodeHelperObfuscator.obfuscateTemplate(this.customCodeHelperFormatter.formatTemplate(StringArrayCallsWrapperTemplate_1.StringArrayCallsWrapperTemplate(), {
             decodeCodeHelperTemplate,
-            intermediateTemplate,
-            stringArrayCallsWrapperName: this.stringArrayCallsWrapperNames.name,
+            stringArrayCallsWrapperName: this.stringArrayCallsWrapperName,
             stringArrayName: this.stringArrayName
         }), {
             reservedNames: preservedNames
@@ -5252,24 +5248,10 @@ let StringArrayCallsWrapperCodeHelper = class StringArrayCallsWrapperCodeHelper
             return '';
         }
         return this.customCodeHelperFormatter.formatTemplate(SelfDefendingTemplate_1.SelfDefendingTemplate(this.randomGenerator, this.escapeSequenceEncoder), {
-            stringArrayCallsWrapperName: this.stringArrayCallsWrapperNames.name,
+            stringArrayCallsWrapperName: this.stringArrayCallsWrapperName,
             stringArrayName: this.stringArrayName
         });
     }
-    getIntermediateTemplate() {
-        const stringArrayCallsWrapperIntermediateNamesLength = this.stringArrayCallsWrapperNames
-            .intermediateNames
-            .length;
-        let intermediateTemplate = '';
-        for (let i = 0; i < stringArrayCallsWrapperIntermediateNamesLength; i++) {
-            const intermediateName = this.stringArrayCallsWrapperNames.intermediateNames[i];
-            intermediateTemplate += this.customCodeHelperFormatter.formatTemplate(StringArrayCallsWrapperIntermediateTemplate_1.StringArrayCallsWrapperIntermediateTemplate(), {
-                intermediateName,
-                stringArrayCallsWrapperName: this.stringArrayCallsWrapperNames.name
-            });
-        }
-        return intermediateTemplate;
-    }
 };
 __decorate([
     Initializable_1.initializable(),
@@ -5277,8 +5259,8 @@ __decorate([
 ], StringArrayCallsWrapperCodeHelper.prototype, "stringArrayName", void 0);
 __decorate([
     Initializable_1.initializable(),
-    __metadata("design:type", typeof (_a = typeof IStringArrayCallsWrapperNames_1.IStringArrayCallsWrapperNames !== "undefined" && IStringArrayCallsWrapperNames_1.IStringArrayCallsWrapperNames) === "function" ? _a : Object)
-], StringArrayCallsWrapperCodeHelper.prototype, "stringArrayCallsWrapperNames", void 0);
+    __metadata("design:type", String)
+], StringArrayCallsWrapperCodeHelper.prototype, "stringArrayCallsWrapperName", void 0);
 StringArrayCallsWrapperCodeHelper = __decorate([
     inversify_1.injectable(),
     __param(0, inversify_1.inject(ServiceIdentifiers_1.ServiceIdentifiers.Factory__IIdentifierNamesGenerator)),
@@ -5287,7 +5269,7 @@ StringArrayCallsWrapperCodeHelper = __decorate([
     __param(3, inversify_1.inject(ServiceIdentifiers_1.ServiceIdentifiers.IRandomGenerator)),
     __param(4, inversify_1.inject(ServiceIdentifiers_1.ServiceIdentifiers.IOptions)),
     __param(5, inversify_1.inject(ServiceIdentifiers_1.ServiceIdentifiers.IEscapeSequenceEncoder)),
-    __metadata("design:paramtypes", [typeof (_b = typeof TIdentifierNamesGeneratorFactory_1.TIdentifierNamesGeneratorFactory !== "undefined" && TIdentifierNamesGeneratorFactory_1.TIdentifierNamesGeneratorFactory) === "function" ? _b : Object, typeof (_c = typeof ICustomCodeHelperFormatter_1.ICustomCodeHelperFormatter !== "undefined" && ICustomCodeHelperFormatter_1.ICustomCodeHelperFormatter) === "function" ? _c : Object, typeof (_d = typeof ICustomCodeHelperObfuscator_1.ICustomCodeHelperObfuscator !== "undefined" && ICustomCodeHelperObfuscator_1.ICustomCodeHelperObfuscator) === "function" ? _d : Object, typeof (_e = typeof IRandomGenerator_1.IRandomGenerator !== "undefined" && IRandomGenerator_1.IRandomGenerator) === "function" ? _e : Object, typeof (_f = typeof IOptions_1.IOptions !== "undefined" && IOptions_1.IOptions) === "function" ? _f : Object, typeof (_g = typeof IEscapeSequenceEncoder_1.IEscapeSequenceEncoder !== "undefined" && IEscapeSequenceEncoder_1.IEscapeSequenceEncoder) === "function" ? _g : Object])
+    __metadata("design:paramtypes", [typeof (_a = typeof TIdentifierNamesGeneratorFactory_1.TIdentifierNamesGeneratorFactory !== "undefined" && TIdentifierNamesGeneratorFactory_1.TIdentifierNamesGeneratorFactory) === "function" ? _a : Object, typeof (_b = typeof ICustomCodeHelperFormatter_1.ICustomCodeHelperFormatter !== "undefined" && ICustomCodeHelperFormatter_1.ICustomCodeHelperFormatter) === "function" ? _b : Object, typeof (_c = typeof ICustomCodeHelperObfuscator_1.ICustomCodeHelperObfuscator !== "undefined" && ICustomCodeHelperObfuscator_1.ICustomCodeHelperObfuscator) === "function" ? _c : Object, typeof (_d = typeof IRandomGenerator_1.IRandomGenerator !== "undefined" && IRandomGenerator_1.IRandomGenerator) === "function" ? _d : Object, typeof (_e = typeof IOptions_1.IOptions !== "undefined" && IOptions_1.IOptions) === "function" ? _e : Object, typeof (_f = typeof IEscapeSequenceEncoder_1.IEscapeSequenceEncoder !== "undefined" && IEscapeSequenceEncoder_1.IEscapeSequenceEncoder) === "function" ? _f : Object])
 ], StringArrayCallsWrapperCodeHelper);
 exports.StringArrayCallsWrapperCodeHelper = StringArrayCallsWrapperCodeHelper;
 
@@ -5330,7 +5312,7 @@ let StringArrayCallsWrapperRc4CodeHelper = class StringArrayCallsWrapperRc4CodeH
             atobPolyfill,
             rc4Polyfill,
             selfDefendingCode,
-            stringArrayCallsWrapperName: this.stringArrayCallsWrapperNames.name
+            stringArrayCallsWrapperName: this.stringArrayCallsWrapperName
         });
     }
 };
@@ -5591,8 +5573,8 @@ let StringArrayCodeHelperGroup = StringArrayCodeHelperGroup_1 = class StringArra
         for (const stringArrayEncoding of this.options.stringArrayEncoding) {
             const stringArrayCallsWrapperCodeHelperName = this.getStringArrayCallsWrapperCodeHelperName(stringArrayEncoding);
             const stringArrayCallsWrapperCodeHelper = this.customCodeHelperFactory(stringArrayCallsWrapperCodeHelperName);
-            const stringArrayCallsWrapperNames = this.stringArrayStorage.getStorageCallsWrapperNames(stringArrayEncoding);
-            stringArrayCallsWrapperCodeHelper.initialize(stringArrayName, stringArrayCallsWrapperNames);
+            const stringArrayCallsWrapperName = this.stringArrayStorage.getStorageCallsWrapperName(stringArrayEncoding);
+            stringArrayCallsWrapperCodeHelper.initialize(stringArrayName, stringArrayCallsWrapperName);
             this.customCodeHelpers.set(stringArrayCallsWrapperCodeHelperName, stringArrayCallsWrapperCodeHelper);
         }
         const stringArrayRotateFunctionCodeHelper = this.customCodeHelperFactory(CustomCodeHelper_1.CustomCodeHelper.StringArrayRotateFunction);
@@ -5841,27 +5823,6 @@ function StringArrayBase64DecodeTemplate(randomGenerator) {
 exports.StringArrayBase64DecodeTemplate = StringArrayBase64DecodeTemplate;
 
 
-/***/ }),
-
-/***/ "./src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperIntermediateTemplate.ts":
-/*!**********************************************************************************************************************************!*\
-  !*** ./src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperIntermediateTemplate.ts ***!
-  \**********************************************************************************************************************************/
-/*! no static exports found */
-/***/ (function(module, exports, __webpack_require__) {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.StringArrayCallsWrapperIntermediateTemplate = void 0;
-function StringArrayCallsWrapperIntermediateTemplate() {
-    return `
-        const {intermediateName} = {stringArrayCallsWrapperName};
-    `;
-}
-exports.StringArrayCallsWrapperIntermediateTemplate = StringArrayCallsWrapperIntermediateTemplate;
-
-
 /***/ }),
 
 /***/ "./src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts":
@@ -5886,8 +5847,6 @@ function StringArrayCallsWrapperTemplate() {
         
             return value;
         };
-        
-        {intermediateTemplate}
     `;
 }
 exports.StringArrayCallsWrapperTemplate = StringArrayCallsWrapperTemplate;
@@ -8370,20 +8329,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
 Object.defineProperty(exports, "__esModule", { value: true });
 
 
-/***/ }),
-
-/***/ "./src/interfaces/node-transformers/string-array-transformers/IStringArrayCallsWrapperNames.ts":
-/*!*****************************************************************************************************!*\
-  !*** ./src/interfaces/node-transformers/string-array-transformers/IStringArrayCallsWrapperNames.ts ***!
-  \*****************************************************************************************************/
-/*! no static exports found */
-/***/ (function(module, exports, __webpack_require__) {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", { value: true });
-
-
 /***/ }),
 
 /***/ "./src/interfaces/node/IScopeIdentifiersTraverser.ts":
@@ -13293,8 +13238,8 @@ const NumberUtils_1 = __webpack_require__(/*! ../../utils/NumberUtils */ "./src/
 let StringArrayTransformer = StringArrayTransformer_1 = class StringArrayTransformer extends AbstractNodeTransformer_1.AbstractNodeTransformer {
     constructor(randomGenerator, options, literalNodesCacheStorage, stringArrayStorage, stringArrayStorageAnalyzer, arrayUtils, escapeSequenceEncoder, identifierNamesGeneratorFactory) {
         super(randomGenerator, options);
-        this.stringArrayFunctionsCallsWrapperNamesMap = new Map();
-        this.visitedFunctionNodesStack = [];
+        this.stringArrayIntermediateCallsWrapperDataByEncodingMap = new Map();
+        this.visitedLexicalScopeNodesStack = [];
         this.literalNodesCacheStorage = literalNodesCacheStorage;
         this.stringArrayStorage = stringArrayStorage;
         this.stringArrayStorageAnalyzer = stringArrayStorageAnalyzer;
@@ -13320,17 +13265,17 @@ let StringArrayTransformer = StringArrayTransformer_1 = class StringArrayTransfo
                         if (NodeGuards_1.NodeGuards.isProgramNode(node)) {
                             this.prepareNode(node);
                         }
-                        if (NodeGuards_1.NodeGuards.isFunctionNode(node)) {
-                            this.onFunctionNodeEnter(node);
+                        if (NodeGuards_1.NodeGuards.isNodeWithLexicalScope(node)) {
+                            this.onLexicalScopeNodeEnter(node);
                         }
                         if (parentNode && NodeGuards_1.NodeGuards.isLiteralNode(node) && !NodeMetadata_1.NodeMetadata.isReplacedLiteral(node)) {
                             return this.transformNode(node, parentNode);
                         }
                     },
                     leave: (node) => {
-                        if (NodeGuards_1.NodeGuards.isFunctionNode(node)) {
-                            this.onFunctionNodeLeave();
-                            return this.transformFunctionNode(node);
+                        if (NodeGuards_1.NodeGuards.isNodeWithLexicalScope(node)) {
+                            this.onLexicalScopeNodeLeave();
+                            return this.transformLexicalScopeNode(node);
                         }
                     }
                 };
@@ -13392,67 +13337,66 @@ let StringArrayTransformer = StringArrayTransformer_1 = class StringArrayTransfo
     getStringArrayCallsWrapperName(stringArrayStorageItemData) {
         var _a, _b, _c;
         const { encoding } = stringArrayStorageItemData;
-        const stringArrayCallsWrapperNames = this.stringArrayStorage.getStorageCallsWrapperNames(encoding);
+        const stringArrayCallsWrapperName = this.stringArrayStorage.getStorageCallsWrapperName(encoding);
         if (!this.options.stringArrayIntermediateVariablesCount) {
-            return stringArrayCallsWrapperNames.name;
-        }
-        const currentFunctionNode = this.arrayUtils.getLastElement(this.visitedFunctionNodesStack);
-        if (!currentFunctionNode) {
-            return this.getStringArrayIntermediateCallsWrapperName(encoding);
-        }
-        const stringArrayIntermediateCallsWrapperNames = currentFunctionNode
-            ? (_a = this.stringArrayFunctionsCallsWrapperNamesMap.get(currentFunctionNode)) !== null && _a !== void 0 ? _a : {} : {};
-        let stringArrayIntermediateCallsWrapperName = (_c = (_b = stringArrayIntermediateCallsWrapperNames[encoding]) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : '';
-        if (currentFunctionNode && !stringArrayIntermediateCallsWrapperName) {
-            stringArrayIntermediateCallsWrapperName = this.identifierNamesGenerator.generateForLexicalScope(currentFunctionNode);
-            stringArrayIntermediateCallsWrapperNames[encoding] = {
+            return stringArrayCallsWrapperName;
+        }
+        const currentLexicalScopeNode = this.arrayUtils.getLastElement(this.visitedLexicalScopeNodesStack);
+        if (!currentLexicalScopeNode) {
+            throw new Error('Cannot find current lexical scope node');
+        }
+        const stringArrayIntermediateCallsWrapperDataByEncoding = currentLexicalScopeNode
+            ? (_a = this.stringArrayIntermediateCallsWrapperDataByEncodingMap.get(currentLexicalScopeNode)) !== null && _a !== void 0 ? _a : {} : {};
+        let stringArrayIntermediateCallsWrapperName = (_c = (_b = stringArrayIntermediateCallsWrapperDataByEncoding[encoding]) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : '';
+        if (currentLexicalScopeNode && !stringArrayIntermediateCallsWrapperName) {
+            stringArrayIntermediateCallsWrapperName = this.identifierNamesGenerator.generateForLexicalScope(currentLexicalScopeNode);
+            stringArrayIntermediateCallsWrapperDataByEncoding[encoding] = {
                 encoding,
                 name: stringArrayIntermediateCallsWrapperName
             };
-            this.stringArrayFunctionsCallsWrapperNamesMap.set(currentFunctionNode, stringArrayIntermediateCallsWrapperNames);
+            this.stringArrayIntermediateCallsWrapperDataByEncodingMap.set(currentLexicalScopeNode, stringArrayIntermediateCallsWrapperDataByEncoding);
         }
         return stringArrayIntermediateCallsWrapperName;
     }
-    getStringArrayIntermediateCallsWrapperName(encoding) {
-        const stringArrayCallsWrapperNames = this.stringArrayStorage.getStorageCallsWrapperNames(encoding);
-        return stringArrayCallsWrapperNames.intermediateNames.length
-            ? this.randomGenerator
-                .getRandomGenerator()
-                .pickone(stringArrayCallsWrapperNames.intermediateNames)
-            : stringArrayCallsWrapperNames.name;
+    getStringArrayRootCallsWrapperName(encoding) {
+        return this.stringArrayStorage.getStorageCallsWrapperName(encoding);
     }
-    onFunctionNodeEnter(functionNode) {
-        this.visitedFunctionNodesStack.push(functionNode);
+    onLexicalScopeNodeEnter(lexicalScopeNode) {
+        this.visitedLexicalScopeNodesStack.push(lexicalScopeNode);
     }
-    onFunctionNodeLeave() {
-        this.visitedFunctionNodesStack.pop();
+    onLexicalScopeNodeLeave() {
+        this.visitedLexicalScopeNodesStack.pop();
     }
-    transformFunctionNode(functionNode) {
+    transformLexicalScopeNode(lexicalScopeNode) {
         var _a;
         if (!this.options.stringArrayIntermediateVariablesCount) {
-            return functionNode;
-        }
-        if (!NodeGuards_1.NodeGuards.isBlockStatementNode(functionNode.body)) {
-            return functionNode;
-        }
-        const stringArrayFunctionCallsWrapperNamesMap = (_a = this.stringArrayFunctionsCallsWrapperNamesMap.get(functionNode)) !== null && _a !== void 0 ? _a : null;
-        if (!stringArrayFunctionCallsWrapperNamesMap) {
-            return functionNode;
-        }
-        const stringArrayFunctionCallsWrapperNames = Object.values(stringArrayFunctionCallsWrapperNamesMap);
-        for (const stringArrayFunctionCallsWrapperName of stringArrayFunctionCallsWrapperNames) {
-            if (!stringArrayFunctionCallsWrapperName) {
+            return lexicalScopeNode;
+        }
+        const lexicalScopeBodyNode = NodeGuards_1.NodeGuards.isProgramNode(lexicalScopeNode)
+            ? lexicalScopeNode
+            : lexicalScopeNode.body;
+        if (!lexicalScopeBodyNode.parentNode
+            || !NodeGuards_1.NodeGuards.isNodeWithLexicalScopeStatements(lexicalScopeBodyNode, lexicalScopeBodyNode.parentNode)) {
+            return lexicalScopeNode;
+        }
+        const stringArrayIntermediateCallsWrapperDataByEncoding = (_a = this.stringArrayIntermediateCallsWrapperDataByEncodingMap.get(lexicalScopeNode)) !== null && _a !== void 0 ? _a : null;
+        if (!stringArrayIntermediateCallsWrapperDataByEncoding) {
+            return lexicalScopeNode;
+        }
+        const stringArrayIntermediateCallsWrapperDataList = Object.values(stringArrayIntermediateCallsWrapperDataByEncoding);
+        for (const stringArrayIntermediateCallsWrapperData of stringArrayIntermediateCallsWrapperDataList) {
+            if (!stringArrayIntermediateCallsWrapperData) {
                 continue;
             }
-            const { encoding, name } = stringArrayFunctionCallsWrapperName;
-            const stringArrayCallsWrapperName = this.getStringArrayIntermediateCallsWrapperName(encoding);
-            NodeAppender_1.NodeAppender.prepend(functionNode.body, [
+            const { encoding, name } = stringArrayIntermediateCallsWrapperData;
+            const stringArrayRootCallsWrapperName = this.getStringArrayRootCallsWrapperName(encoding);
+            NodeAppender_1.NodeAppender.prepend(lexicalScopeBodyNode, [
                 NodeFactory_1.NodeFactory.variableDeclarationNode([
-                    NodeFactory_1.NodeFactory.variableDeclaratorNode(NodeFactory_1.NodeFactory.identifierNode(name), NodeFactory_1.NodeFactory.identifierNode(stringArrayCallsWrapperName))
+                    NodeFactory_1.NodeFactory.variableDeclaratorNode(NodeFactory_1.NodeFactory.identifierNode(name), NodeFactory_1.NodeFactory.identifierNode(stringArrayRootCallsWrapperName))
                 ], 'var')
             ]);
         }
-        return functionNode;
+        return lexicalScopeNode;
     }
     encodeLiteralNodeToEscapeSequence(literalNode, parentNode) {
         if (typeof literalNode.value !== 'string') {
@@ -15883,16 +15827,17 @@ let StringArrayStorage = StringArrayStorage_1 = class StringArrayStorage extends
         }
         return this.stringArrayStorageName;
     }
-    getStorageCallsWrapperNames(stringArrayEncoding) {
+    getStorageCallsWrapperName(stringArrayEncoding) {
         var _a;
         const storageCallsWrapperName = (_a = this.stringArrayStorageCallsWrapperNamesMap
             .get(stringArrayEncoding)) !== null && _a !== void 0 ? _a : null;
         if (storageCallsWrapperName) {
             return storageCallsWrapperName;
         }
-        const newStorageCallsWrapperNames = this.getStringArrayCallsWrapperNames();
-        this.stringArrayStorageCallsWrapperNamesMap.set(stringArrayEncoding, newStorageCallsWrapperNames);
-        return newStorageCallsWrapperNames;
+        const newStorageCallsWrapperName = this.identifierNamesGenerator
+            .generateForGlobalScope(StringArrayStorage_1.stringArrayNameLength);
+        this.stringArrayStorageCallsWrapperNamesMap.set(stringArrayEncoding, newStorageCallsWrapperName);
+        return newStorageCallsWrapperName;
     }
     rotateStorage() {
         if (!this.getLength()) {
@@ -15971,12 +15916,6 @@ let StringArrayStorage = StringArrayStorage_1 = class StringArrayStorage extends
             }
         }
     }
-    getStringArrayCallsWrapperNames() {
-        return {
-            name: this.identifierNamesGenerator.generateForGlobalScope(StringArrayStorage_1.stringArrayNameLength),
-            intermediateNames: Array.from({ length: this.options.stringArrayIntermediateVariablesCount }, () => this.identifierNamesGenerator.generateForGlobalScope(StringArrayStorage_1.stringArrayNameLength))
-        };
-    }
 };
 StringArrayStorage.minimumRotationAmount = 100;
 StringArrayStorage.maximumRotationAmount = 500;

+ 67 - 128
dist/index.js

@@ -293,7 +293,7 @@ let JavaScriptObfuscator = JavaScriptObfuscator_1 = class JavaScriptObfuscator {
             sourceCode = '';
         }
         const timeStart = Date.now();
-        this.logger.info(LoggingMessage_1.LoggingMessage.Version, Utils_1.Utils.buildVersionMessage("2.2.0", 1599686797505));
+        this.logger.info(LoggingMessage_1.LoggingMessage.Version, Utils_1.Utils.buildVersionMessage("2.2.0", 1599726508600));
         this.logger.info(LoggingMessage_1.LoggingMessage.ObfuscationStarted);
         this.logger.info(LoggingMessage_1.LoggingMessage.RandomGeneratorSeed, this.randomGenerator.getInputSeed());
         sourceCode = this.runCodeTransformationStage(sourceCode, CodeTransformationStage_1.CodeTransformationStage.PreparingTransformers);
@@ -4564,7 +4564,7 @@ let StringArrayCallsWrapperBase64CodeHelper = class StringArrayCallsWrapperBase6
             atobPolyfill,
             atobFunctionName,
             selfDefendingCode,
-            stringArrayCallsWrapperName: this.stringArrayCallsWrapperNames.name
+            stringArrayCallsWrapperName: this.stringArrayCallsWrapperName
         });
     }
 };
@@ -4597,7 +4597,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
 var __param = (this && this.__param) || function (paramIndex, decorator) {
     return function (target, key) { decorator(target, key, paramIndex); }
 };
-var _a, _b, _c, _d, _e, _f, _g;
+var _a, _b, _c, _d, _e, _f;
 Object.defineProperty(exports, "__esModule", { value: true });
 exports.StringArrayCallsWrapperCodeHelper = void 0;
 const inversify_1 = __webpack_require__(/*! inversify */ "inversify");
@@ -4608,11 +4608,9 @@ const ICustomCodeHelperObfuscator_1 = __webpack_require__(/*! ../../interfaces/c
 const IEscapeSequenceEncoder_1 = __webpack_require__(/*! ../../interfaces/utils/IEscapeSequenceEncoder */ "./src/interfaces/utils/IEscapeSequenceEncoder.ts");
 const IOptions_1 = __webpack_require__(/*! ../../interfaces/options/IOptions */ "./src/interfaces/options/IOptions.ts");
 const IRandomGenerator_1 = __webpack_require__(/*! ../../interfaces/utils/IRandomGenerator */ "./src/interfaces/utils/IRandomGenerator.ts");
-const IStringArrayCallsWrapperNames_1 = __webpack_require__(/*! ../../interfaces/node-transformers/string-array-transformers/IStringArrayCallsWrapperNames */ "./src/interfaces/node-transformers/string-array-transformers/IStringArrayCallsWrapperNames.ts");
 const Initializable_1 = __webpack_require__(/*! ../../decorators/Initializable */ "./src/decorators/Initializable.ts");
 const SelfDefendingTemplate_1 = __webpack_require__(/*! ./templates/string-array-calls-wrapper/SelfDefendingTemplate */ "./src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/SelfDefendingTemplate.ts");
 const StringArrayCallsWrapperTemplate_1 = __webpack_require__(/*! ./templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate */ "./src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts");
-const StringArrayCallsWrapperIntermediateTemplate_1 = __webpack_require__(/*! ./templates/string-array-calls-wrapper/StringArrayCallsWrapperIntermediateTemplate */ "./src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperIntermediateTemplate.ts");
 const AbstractCustomCodeHelper_1 = __webpack_require__(/*! ../AbstractCustomCodeHelper */ "./src/custom-code-helpers/AbstractCustomCodeHelper.ts");
 const NodeUtils_1 = __webpack_require__(/*! ../../node/NodeUtils */ "./src/node/NodeUtils.ts");
 let StringArrayCallsWrapperCodeHelper = class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper_1.AbstractCustomCodeHelper {
@@ -4620,21 +4618,19 @@ let StringArrayCallsWrapperCodeHelper = class StringArrayCallsWrapperCodeHelper
         super(identifierNamesGeneratorFactory, customCodeHelperFormatter, customCodeHelperObfuscator, randomGenerator, options);
         this.escapeSequenceEncoder = escapeSequenceEncoder;
     }
-    initialize(stringArrayName, stringArrayCallsWrapperNames) {
+    initialize(stringArrayName, stringArrayCallsWrapperName) {
         this.stringArrayName = stringArrayName;
-        this.stringArrayCallsWrapperNames = stringArrayCallsWrapperNames;
+        this.stringArrayCallsWrapperName = stringArrayCallsWrapperName;
     }
     getNodeStructure(codeHelperTemplate) {
         return NodeUtils_1.NodeUtils.convertCodeToStructure(codeHelperTemplate);
     }
     getCodeHelperTemplate() {
         const decodeCodeHelperTemplate = this.getDecodeStringArrayTemplate();
-        const intermediateTemplate = this.getIntermediateTemplate();
         const preservedNames = [`^${this.stringArrayName}$`];
         return this.customCodeHelperObfuscator.obfuscateTemplate(this.customCodeHelperFormatter.formatTemplate(StringArrayCallsWrapperTemplate_1.StringArrayCallsWrapperTemplate(), {
             decodeCodeHelperTemplate,
-            intermediateTemplate,
-            stringArrayCallsWrapperName: this.stringArrayCallsWrapperNames.name,
+            stringArrayCallsWrapperName: this.stringArrayCallsWrapperName,
             stringArrayName: this.stringArrayName
         }), {
             reservedNames: preservedNames
@@ -4648,24 +4644,10 @@ let StringArrayCallsWrapperCodeHelper = class StringArrayCallsWrapperCodeHelper
             return '';
         }
         return this.customCodeHelperFormatter.formatTemplate(SelfDefendingTemplate_1.SelfDefendingTemplate(this.randomGenerator, this.escapeSequenceEncoder), {
-            stringArrayCallsWrapperName: this.stringArrayCallsWrapperNames.name,
+            stringArrayCallsWrapperName: this.stringArrayCallsWrapperName,
             stringArrayName: this.stringArrayName
         });
     }
-    getIntermediateTemplate() {
-        const stringArrayCallsWrapperIntermediateNamesLength = this.stringArrayCallsWrapperNames
-            .intermediateNames
-            .length;
-        let intermediateTemplate = '';
-        for (let i = 0; i < stringArrayCallsWrapperIntermediateNamesLength; i++) {
-            const intermediateName = this.stringArrayCallsWrapperNames.intermediateNames[i];
-            intermediateTemplate += this.customCodeHelperFormatter.formatTemplate(StringArrayCallsWrapperIntermediateTemplate_1.StringArrayCallsWrapperIntermediateTemplate(), {
-                intermediateName,
-                stringArrayCallsWrapperName: this.stringArrayCallsWrapperNames.name
-            });
-        }
-        return intermediateTemplate;
-    }
 };
 __decorate([
     Initializable_1.initializable(),
@@ -4673,8 +4655,8 @@ __decorate([
 ], StringArrayCallsWrapperCodeHelper.prototype, "stringArrayName", void 0);
 __decorate([
     Initializable_1.initializable(),
-    __metadata("design:type", typeof (_a = typeof IStringArrayCallsWrapperNames_1.IStringArrayCallsWrapperNames !== "undefined" && IStringArrayCallsWrapperNames_1.IStringArrayCallsWrapperNames) === "function" ? _a : Object)
-], StringArrayCallsWrapperCodeHelper.prototype, "stringArrayCallsWrapperNames", void 0);
+    __metadata("design:type", String)
+], StringArrayCallsWrapperCodeHelper.prototype, "stringArrayCallsWrapperName", void 0);
 StringArrayCallsWrapperCodeHelper = __decorate([
     inversify_1.injectable(),
     __param(0, inversify_1.inject(ServiceIdentifiers_1.ServiceIdentifiers.Factory__IIdentifierNamesGenerator)),
@@ -4683,7 +4665,7 @@ StringArrayCallsWrapperCodeHelper = __decorate([
     __param(3, inversify_1.inject(ServiceIdentifiers_1.ServiceIdentifiers.IRandomGenerator)),
     __param(4, inversify_1.inject(ServiceIdentifiers_1.ServiceIdentifiers.IOptions)),
     __param(5, inversify_1.inject(ServiceIdentifiers_1.ServiceIdentifiers.IEscapeSequenceEncoder)),
-    __metadata("design:paramtypes", [typeof (_b = typeof TIdentifierNamesGeneratorFactory_1.TIdentifierNamesGeneratorFactory !== "undefined" && TIdentifierNamesGeneratorFactory_1.TIdentifierNamesGeneratorFactory) === "function" ? _b : Object, typeof (_c = typeof ICustomCodeHelperFormatter_1.ICustomCodeHelperFormatter !== "undefined" && ICustomCodeHelperFormatter_1.ICustomCodeHelperFormatter) === "function" ? _c : Object, typeof (_d = typeof ICustomCodeHelperObfuscator_1.ICustomCodeHelperObfuscator !== "undefined" && ICustomCodeHelperObfuscator_1.ICustomCodeHelperObfuscator) === "function" ? _d : Object, typeof (_e = typeof IRandomGenerator_1.IRandomGenerator !== "undefined" && IRandomGenerator_1.IRandomGenerator) === "function" ? _e : Object, typeof (_f = typeof IOptions_1.IOptions !== "undefined" && IOptions_1.IOptions) === "function" ? _f : Object, typeof (_g = typeof IEscapeSequenceEncoder_1.IEscapeSequenceEncoder !== "undefined" && IEscapeSequenceEncoder_1.IEscapeSequenceEncoder) === "function" ? _g : Object])
+    __metadata("design:paramtypes", [typeof (_a = typeof TIdentifierNamesGeneratorFactory_1.TIdentifierNamesGeneratorFactory !== "undefined" && TIdentifierNamesGeneratorFactory_1.TIdentifierNamesGeneratorFactory) === "function" ? _a : Object, typeof (_b = typeof ICustomCodeHelperFormatter_1.ICustomCodeHelperFormatter !== "undefined" && ICustomCodeHelperFormatter_1.ICustomCodeHelperFormatter) === "function" ? _b : Object, typeof (_c = typeof ICustomCodeHelperObfuscator_1.ICustomCodeHelperObfuscator !== "undefined" && ICustomCodeHelperObfuscator_1.ICustomCodeHelperObfuscator) === "function" ? _c : Object, typeof (_d = typeof IRandomGenerator_1.IRandomGenerator !== "undefined" && IRandomGenerator_1.IRandomGenerator) === "function" ? _d : Object, typeof (_e = typeof IOptions_1.IOptions !== "undefined" && IOptions_1.IOptions) === "function" ? _e : Object, typeof (_f = typeof IEscapeSequenceEncoder_1.IEscapeSequenceEncoder !== "undefined" && IEscapeSequenceEncoder_1.IEscapeSequenceEncoder) === "function" ? _f : Object])
 ], StringArrayCallsWrapperCodeHelper);
 exports.StringArrayCallsWrapperCodeHelper = StringArrayCallsWrapperCodeHelper;
 
@@ -4726,7 +4708,7 @@ let StringArrayCallsWrapperRc4CodeHelper = class StringArrayCallsWrapperRc4CodeH
             atobPolyfill,
             rc4Polyfill,
             selfDefendingCode,
-            stringArrayCallsWrapperName: this.stringArrayCallsWrapperNames.name
+            stringArrayCallsWrapperName: this.stringArrayCallsWrapperName
         });
     }
 };
@@ -4987,8 +4969,8 @@ let StringArrayCodeHelperGroup = StringArrayCodeHelperGroup_1 = class StringArra
         for (const stringArrayEncoding of this.options.stringArrayEncoding) {
             const stringArrayCallsWrapperCodeHelperName = this.getStringArrayCallsWrapperCodeHelperName(stringArrayEncoding);
             const stringArrayCallsWrapperCodeHelper = this.customCodeHelperFactory(stringArrayCallsWrapperCodeHelperName);
-            const stringArrayCallsWrapperNames = this.stringArrayStorage.getStorageCallsWrapperNames(stringArrayEncoding);
-            stringArrayCallsWrapperCodeHelper.initialize(stringArrayName, stringArrayCallsWrapperNames);
+            const stringArrayCallsWrapperName = this.stringArrayStorage.getStorageCallsWrapperName(stringArrayEncoding);
+            stringArrayCallsWrapperCodeHelper.initialize(stringArrayName, stringArrayCallsWrapperName);
             this.customCodeHelpers.set(stringArrayCallsWrapperCodeHelperName, stringArrayCallsWrapperCodeHelper);
         }
         const stringArrayRotateFunctionCodeHelper = this.customCodeHelperFactory(CustomCodeHelper_1.CustomCodeHelper.StringArrayRotateFunction);
@@ -5237,27 +5219,6 @@ function StringArrayBase64DecodeTemplate(randomGenerator) {
 exports.StringArrayBase64DecodeTemplate = StringArrayBase64DecodeTemplate;
 
 
-/***/ }),
-
-/***/ "./src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperIntermediateTemplate.ts":
-/*!**********************************************************************************************************************************!*\
-  !*** ./src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperIntermediateTemplate.ts ***!
-  \**********************************************************************************************************************************/
-/*! no static exports found */
-/***/ (function(module, exports, __webpack_require__) {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.StringArrayCallsWrapperIntermediateTemplate = void 0;
-function StringArrayCallsWrapperIntermediateTemplate() {
-    return `
-        const {intermediateName} = {stringArrayCallsWrapperName};
-    `;
-}
-exports.StringArrayCallsWrapperIntermediateTemplate = StringArrayCallsWrapperIntermediateTemplate;
-
-
 /***/ }),
 
 /***/ "./src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts":
@@ -5282,8 +5243,6 @@ function StringArrayCallsWrapperTemplate() {
         
             return value;
         };
-        
-        {intermediateTemplate}
     `;
 }
 exports.StringArrayCallsWrapperTemplate = StringArrayCallsWrapperTemplate;
@@ -7766,20 +7725,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
 Object.defineProperty(exports, "__esModule", { value: true });
 
 
-/***/ }),
-
-/***/ "./src/interfaces/node-transformers/string-array-transformers/IStringArrayCallsWrapperNames.ts":
-/*!*****************************************************************************************************!*\
-  !*** ./src/interfaces/node-transformers/string-array-transformers/IStringArrayCallsWrapperNames.ts ***!
-  \*****************************************************************************************************/
-/*! no static exports found */
-/***/ (function(module, exports, __webpack_require__) {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", { value: true });
-
-
 /***/ }),
 
 /***/ "./src/interfaces/node/IScopeIdentifiersTraverser.ts":
@@ -12689,8 +12634,8 @@ const NumberUtils_1 = __webpack_require__(/*! ../../utils/NumberUtils */ "./src/
 let StringArrayTransformer = StringArrayTransformer_1 = class StringArrayTransformer extends AbstractNodeTransformer_1.AbstractNodeTransformer {
     constructor(randomGenerator, options, literalNodesCacheStorage, stringArrayStorage, stringArrayStorageAnalyzer, arrayUtils, escapeSequenceEncoder, identifierNamesGeneratorFactory) {
         super(randomGenerator, options);
-        this.stringArrayFunctionsCallsWrapperNamesMap = new Map();
-        this.visitedFunctionNodesStack = [];
+        this.stringArrayIntermediateCallsWrapperDataByEncodingMap = new Map();
+        this.visitedLexicalScopeNodesStack = [];
         this.literalNodesCacheStorage = literalNodesCacheStorage;
         this.stringArrayStorage = stringArrayStorage;
         this.stringArrayStorageAnalyzer = stringArrayStorageAnalyzer;
@@ -12716,17 +12661,17 @@ let StringArrayTransformer = StringArrayTransformer_1 = class StringArrayTransfo
                         if (NodeGuards_1.NodeGuards.isProgramNode(node)) {
                             this.prepareNode(node);
                         }
-                        if (NodeGuards_1.NodeGuards.isFunctionNode(node)) {
-                            this.onFunctionNodeEnter(node);
+                        if (NodeGuards_1.NodeGuards.isNodeWithLexicalScope(node)) {
+                            this.onLexicalScopeNodeEnter(node);
                         }
                         if (parentNode && NodeGuards_1.NodeGuards.isLiteralNode(node) && !NodeMetadata_1.NodeMetadata.isReplacedLiteral(node)) {
                             return this.transformNode(node, parentNode);
                         }
                     },
                     leave: (node) => {
-                        if (NodeGuards_1.NodeGuards.isFunctionNode(node)) {
-                            this.onFunctionNodeLeave();
-                            return this.transformFunctionNode(node);
+                        if (NodeGuards_1.NodeGuards.isNodeWithLexicalScope(node)) {
+                            this.onLexicalScopeNodeLeave();
+                            return this.transformLexicalScopeNode(node);
                         }
                     }
                 };
@@ -12788,67 +12733,66 @@ let StringArrayTransformer = StringArrayTransformer_1 = class StringArrayTransfo
     getStringArrayCallsWrapperName(stringArrayStorageItemData) {
         var _a, _b, _c;
         const { encoding } = stringArrayStorageItemData;
-        const stringArrayCallsWrapperNames = this.stringArrayStorage.getStorageCallsWrapperNames(encoding);
+        const stringArrayCallsWrapperName = this.stringArrayStorage.getStorageCallsWrapperName(encoding);
         if (!this.options.stringArrayIntermediateVariablesCount) {
-            return stringArrayCallsWrapperNames.name;
-        }
-        const currentFunctionNode = this.arrayUtils.getLastElement(this.visitedFunctionNodesStack);
-        if (!currentFunctionNode) {
-            return this.getStringArrayIntermediateCallsWrapperName(encoding);
-        }
-        const stringArrayIntermediateCallsWrapperNames = currentFunctionNode
-            ? (_a = this.stringArrayFunctionsCallsWrapperNamesMap.get(currentFunctionNode)) !== null && _a !== void 0 ? _a : {} : {};
-        let stringArrayIntermediateCallsWrapperName = (_c = (_b = stringArrayIntermediateCallsWrapperNames[encoding]) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : '';
-        if (currentFunctionNode && !stringArrayIntermediateCallsWrapperName) {
-            stringArrayIntermediateCallsWrapperName = this.identifierNamesGenerator.generateForLexicalScope(currentFunctionNode);
-            stringArrayIntermediateCallsWrapperNames[encoding] = {
+            return stringArrayCallsWrapperName;
+        }
+        const currentLexicalScopeNode = this.arrayUtils.getLastElement(this.visitedLexicalScopeNodesStack);
+        if (!currentLexicalScopeNode) {
+            throw new Error('Cannot find current lexical scope node');
+        }
+        const stringArrayIntermediateCallsWrapperDataByEncoding = currentLexicalScopeNode
+            ? (_a = this.stringArrayIntermediateCallsWrapperDataByEncodingMap.get(currentLexicalScopeNode)) !== null && _a !== void 0 ? _a : {} : {};
+        let stringArrayIntermediateCallsWrapperName = (_c = (_b = stringArrayIntermediateCallsWrapperDataByEncoding[encoding]) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : '';
+        if (currentLexicalScopeNode && !stringArrayIntermediateCallsWrapperName) {
+            stringArrayIntermediateCallsWrapperName = this.identifierNamesGenerator.generateForLexicalScope(currentLexicalScopeNode);
+            stringArrayIntermediateCallsWrapperDataByEncoding[encoding] = {
                 encoding,
                 name: stringArrayIntermediateCallsWrapperName
             };
-            this.stringArrayFunctionsCallsWrapperNamesMap.set(currentFunctionNode, stringArrayIntermediateCallsWrapperNames);
+            this.stringArrayIntermediateCallsWrapperDataByEncodingMap.set(currentLexicalScopeNode, stringArrayIntermediateCallsWrapperDataByEncoding);
         }
         return stringArrayIntermediateCallsWrapperName;
     }
-    getStringArrayIntermediateCallsWrapperName(encoding) {
-        const stringArrayCallsWrapperNames = this.stringArrayStorage.getStorageCallsWrapperNames(encoding);
-        return stringArrayCallsWrapperNames.intermediateNames.length
-            ? this.randomGenerator
-                .getRandomGenerator()
-                .pickone(stringArrayCallsWrapperNames.intermediateNames)
-            : stringArrayCallsWrapperNames.name;
+    getStringArrayRootCallsWrapperName(encoding) {
+        return this.stringArrayStorage.getStorageCallsWrapperName(encoding);
     }
-    onFunctionNodeEnter(functionNode) {
-        this.visitedFunctionNodesStack.push(functionNode);
+    onLexicalScopeNodeEnter(lexicalScopeNode) {
+        this.visitedLexicalScopeNodesStack.push(lexicalScopeNode);
     }
-    onFunctionNodeLeave() {
-        this.visitedFunctionNodesStack.pop();
+    onLexicalScopeNodeLeave() {
+        this.visitedLexicalScopeNodesStack.pop();
     }
-    transformFunctionNode(functionNode) {
+    transformLexicalScopeNode(lexicalScopeNode) {
         var _a;
         if (!this.options.stringArrayIntermediateVariablesCount) {
-            return functionNode;
-        }
-        if (!NodeGuards_1.NodeGuards.isBlockStatementNode(functionNode.body)) {
-            return functionNode;
-        }
-        const stringArrayFunctionCallsWrapperNamesMap = (_a = this.stringArrayFunctionsCallsWrapperNamesMap.get(functionNode)) !== null && _a !== void 0 ? _a : null;
-        if (!stringArrayFunctionCallsWrapperNamesMap) {
-            return functionNode;
-        }
-        const stringArrayFunctionCallsWrapperNames = Object.values(stringArrayFunctionCallsWrapperNamesMap);
-        for (const stringArrayFunctionCallsWrapperName of stringArrayFunctionCallsWrapperNames) {
-            if (!stringArrayFunctionCallsWrapperName) {
+            return lexicalScopeNode;
+        }
+        const lexicalScopeBodyNode = NodeGuards_1.NodeGuards.isProgramNode(lexicalScopeNode)
+            ? lexicalScopeNode
+            : lexicalScopeNode.body;
+        if (!lexicalScopeBodyNode.parentNode
+            || !NodeGuards_1.NodeGuards.isNodeWithLexicalScopeStatements(lexicalScopeBodyNode, lexicalScopeBodyNode.parentNode)) {
+            return lexicalScopeNode;
+        }
+        const stringArrayIntermediateCallsWrapperDataByEncoding = (_a = this.stringArrayIntermediateCallsWrapperDataByEncodingMap.get(lexicalScopeNode)) !== null && _a !== void 0 ? _a : null;
+        if (!stringArrayIntermediateCallsWrapperDataByEncoding) {
+            return lexicalScopeNode;
+        }
+        const stringArrayIntermediateCallsWrapperDataList = Object.values(stringArrayIntermediateCallsWrapperDataByEncoding);
+        for (const stringArrayIntermediateCallsWrapperData of stringArrayIntermediateCallsWrapperDataList) {
+            if (!stringArrayIntermediateCallsWrapperData) {
                 continue;
             }
-            const { encoding, name } = stringArrayFunctionCallsWrapperName;
-            const stringArrayCallsWrapperName = this.getStringArrayIntermediateCallsWrapperName(encoding);
-            NodeAppender_1.NodeAppender.prepend(functionNode.body, [
+            const { encoding, name } = stringArrayIntermediateCallsWrapperData;
+            const stringArrayRootCallsWrapperName = this.getStringArrayRootCallsWrapperName(encoding);
+            NodeAppender_1.NodeAppender.prepend(lexicalScopeBodyNode, [
                 NodeFactory_1.NodeFactory.variableDeclarationNode([
-                    NodeFactory_1.NodeFactory.variableDeclaratorNode(NodeFactory_1.NodeFactory.identifierNode(name), NodeFactory_1.NodeFactory.identifierNode(stringArrayCallsWrapperName))
+                    NodeFactory_1.NodeFactory.variableDeclaratorNode(NodeFactory_1.NodeFactory.identifierNode(name), NodeFactory_1.NodeFactory.identifierNode(stringArrayRootCallsWrapperName))
                 ], 'var')
             ]);
         }
-        return functionNode;
+        return lexicalScopeNode;
     }
     encodeLiteralNodeToEscapeSequence(literalNode, parentNode) {
         if (typeof literalNode.value !== 'string') {
@@ -15279,16 +15223,17 @@ let StringArrayStorage = StringArrayStorage_1 = class StringArrayStorage extends
         }
         return this.stringArrayStorageName;
     }
-    getStorageCallsWrapperNames(stringArrayEncoding) {
+    getStorageCallsWrapperName(stringArrayEncoding) {
         var _a;
         const storageCallsWrapperName = (_a = this.stringArrayStorageCallsWrapperNamesMap
             .get(stringArrayEncoding)) !== null && _a !== void 0 ? _a : null;
         if (storageCallsWrapperName) {
             return storageCallsWrapperName;
         }
-        const newStorageCallsWrapperNames = this.getStringArrayCallsWrapperNames();
-        this.stringArrayStorageCallsWrapperNamesMap.set(stringArrayEncoding, newStorageCallsWrapperNames);
-        return newStorageCallsWrapperNames;
+        const newStorageCallsWrapperName = this.identifierNamesGenerator
+            .generateForGlobalScope(StringArrayStorage_1.stringArrayNameLength);
+        this.stringArrayStorageCallsWrapperNamesMap.set(stringArrayEncoding, newStorageCallsWrapperName);
+        return newStorageCallsWrapperName;
     }
     rotateStorage() {
         if (!this.getLength()) {
@@ -15367,12 +15312,6 @@ let StringArrayStorage = StringArrayStorage_1 = class StringArrayStorage extends
             }
         }
     }
-    getStringArrayCallsWrapperNames() {
-        return {
-            name: this.identifierNamesGenerator.generateForGlobalScope(StringArrayStorage_1.stringArrayNameLength),
-            intermediateNames: Array.from({ length: this.options.stringArrayIntermediateVariablesCount }, () => this.identifierNamesGenerator.generateForGlobalScope(StringArrayStorage_1.stringArrayNameLength))
-        };
-    }
 };
 StringArrayStorage.minimumRotationAmount = 100;
 StringArrayStorage.maximumRotationAmount = 500;

+ 1 - 1
src/custom-code-helpers/string-array/StringArrayCallsWrapperBase64CodeHelper.ts

@@ -25,7 +25,7 @@ export class StringArrayCallsWrapperBase64CodeHelper extends StringArrayCallsWra
                 atobPolyfill,
                 atobFunctionName,
                 selfDefendingCode,
-                stringArrayCallsWrapperName: this.stringArrayCallsWrapperNames.name
+                stringArrayCallsWrapperName: this.stringArrayCallsWrapperName
             }
         );
     }

+ 7 - 36
src/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.ts

@@ -9,13 +9,11 @@ import { ICustomCodeHelperObfuscator } from '../../interfaces/custom-code-helper
 import { IEscapeSequenceEncoder } from '../../interfaces/utils/IEscapeSequenceEncoder';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { IStringArrayCallsWrapperNames } from '../../interfaces/node-transformers/string-array-transformers/IStringArrayCallsWrapperNames';
 
 import { initializable } from '../../decorators/Initializable';
 
 import { SelfDefendingTemplate } from './templates/string-array-calls-wrapper/SelfDefendingTemplate';
 import { StringArrayCallsWrapperTemplate } from './templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate';
-import { StringArrayCallsWrapperIntermediateTemplate } from './templates/string-array-calls-wrapper/StringArrayCallsWrapperIntermediateTemplate';
 
 import { AbstractCustomCodeHelper } from '../AbstractCustomCodeHelper';
 import { NodeUtils } from '../../node/NodeUtils';
@@ -29,10 +27,10 @@ export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper
     protected stringArrayName!: string;
 
     /**
-     * @type {IStringArrayCallsWrapperNames}
+     * @type {string}
      */
     @initializable()
-    protected stringArrayCallsWrapperNames!: IStringArrayCallsWrapperNames;
+    protected stringArrayCallsWrapperName!: string;
 
     /**
      * @type {IEscapeSequenceEncoder}
@@ -69,14 +67,14 @@ export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper
 
     /**
      * @param {string} stringArrayName
-     * @param {IStringArrayCallsWrapperNames} stringArrayCallsWrapperNames
+     * @param {string} stringArrayCallsWrapperName
      */
     public initialize (
         stringArrayName: string,
-        stringArrayCallsWrapperNames: IStringArrayCallsWrapperNames
+        stringArrayCallsWrapperName: string
     ): void {
         this.stringArrayName = stringArrayName;
-        this.stringArrayCallsWrapperNames = stringArrayCallsWrapperNames;
+        this.stringArrayCallsWrapperName = stringArrayCallsWrapperName;
     }
 
     /**
@@ -92,15 +90,13 @@ export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper
      */
     protected getCodeHelperTemplate (): string {
         const decodeCodeHelperTemplate: string = this.getDecodeStringArrayTemplate();
-        const intermediateTemplate: string = this.getIntermediateTemplate();
 
         const preservedNames: string[] = [`^${this.stringArrayName}$`];
 
         return this.customCodeHelperObfuscator.obfuscateTemplate(
             this.customCodeHelperFormatter.formatTemplate(StringArrayCallsWrapperTemplate(), {
                 decodeCodeHelperTemplate,
-                intermediateTemplate,
-                stringArrayCallsWrapperName: this.stringArrayCallsWrapperNames.name,
+                stringArrayCallsWrapperName: this.stringArrayCallsWrapperName,
                 stringArrayName: this.stringArrayName
             }),
             {
@@ -130,34 +126,9 @@ export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper
                 this.escapeSequenceEncoder
             ),
             {
-                stringArrayCallsWrapperName: this.stringArrayCallsWrapperNames.name,
+                stringArrayCallsWrapperName: this.stringArrayCallsWrapperName,
                 stringArrayName: this.stringArrayName
             }
         );
     }
-
-    /**
-     * @returns {string}
-     */
-    private getIntermediateTemplate (): string {
-        const stringArrayCallsWrapperIntermediateNamesLength: number = this.stringArrayCallsWrapperNames
-            .intermediateNames
-            .length;
-
-        let intermediateTemplate: string = '';
-
-        for (let i = 0; i < stringArrayCallsWrapperIntermediateNamesLength; i++) {
-            const intermediateName: string = this.stringArrayCallsWrapperNames.intermediateNames[i];
-
-            intermediateTemplate += this.customCodeHelperFormatter.formatTemplate(
-                StringArrayCallsWrapperIntermediateTemplate(),
-                {
-                    intermediateName,
-                    stringArrayCallsWrapperName: this.stringArrayCallsWrapperNames.name
-                }
-            );
-        }
-
-        return intermediateTemplate;
-    }
 }

+ 1 - 1
src/custom-code-helpers/string-array/StringArrayCallsWrapperRc4CodeHelper.ts

@@ -29,7 +29,7 @@ export class StringArrayCallsWrapperRc4CodeHelper extends StringArrayCallsWrappe
                 atobPolyfill,
                 rc4Polyfill,
                 selfDefendingCode,
-                stringArrayCallsWrapperName: this.stringArrayCallsWrapperNames.name
+                stringArrayCallsWrapperName: this.stringArrayCallsWrapperName
             }
         );
     }

+ 2 - 4
src/custom-code-helpers/string-array/group/StringArrayCodeHelperGroup.ts

@@ -11,7 +11,6 @@ import { ICallsGraphData } from '../../../interfaces/analyzers/calls-graph-analy
 import { ICustomCodeHelper } from '../../../interfaces/custom-code-helpers/ICustomCodeHelper';
 import { IOptions } from '../../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
-import { IStringArrayCallsWrapperNames } from '../../../interfaces/node-transformers/string-array-transformers/IStringArrayCallsWrapperNames';
 import { IStringArrayStorage } from '../../../interfaces/storages/string-array-transformers/IStringArrayStorage';
 
 import { initializable } from '../../../decorators/Initializable';
@@ -139,12 +138,11 @@ export class StringArrayCodeHelperGroup extends AbstractCustomCodeHelperGroup {
             const stringArrayCallsWrapperCodeHelperName: CustomCodeHelper = this.getStringArrayCallsWrapperCodeHelperName(stringArrayEncoding);
             const stringArrayCallsWrapperCodeHelper: ICustomCodeHelper<TInitialData<StringArrayCallsWrapperCodeHelper>> =
                 this.customCodeHelperFactory(stringArrayCallsWrapperCodeHelperName);
-            const stringArrayCallsWrapperNames: IStringArrayCallsWrapperNames =
-                this.stringArrayStorage.getStorageCallsWrapperNames(stringArrayEncoding);
+            const stringArrayCallsWrapperName: string = this.stringArrayStorage.getStorageCallsWrapperName(stringArrayEncoding);
 
             stringArrayCallsWrapperCodeHelper.initialize(
                 stringArrayName,
-                stringArrayCallsWrapperNames
+                stringArrayCallsWrapperName
             );
 
             this.customCodeHelpers.set(stringArrayCallsWrapperCodeHelperName, stringArrayCallsWrapperCodeHelper);

+ 0 - 2
src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts

@@ -12,7 +12,5 @@ export function StringArrayCallsWrapperTemplate (): string {
         
             return value;
         };
-        
-        {intermediateTemplate}
     `;
 }

+ 0 - 11
src/interfaces/node-transformers/string-array-transformers/IStringArrayCallsWrapperNames.ts

@@ -1,11 +0,0 @@
-export interface IStringArrayCallsWrapperNames {
-    /**
-     * @type {string}
-     */
-    name: string;
-
-    /**
-     * @type {string[]}
-     */
-    intermediateNames: string[];
-}

+ 1 - 1
src/interfaces/node-transformers/string-array-transformers/IStringArrayFunctionCallsWrapperName.ts → src/interfaces/node-transformers/string-array-transformers/IStringArrayIntermediateCallsWrapperData.ts

@@ -1,6 +1,6 @@
 import { TStringArrayEncoding } from '../../../types/options/TStringArrayEncoding';
 
-export interface IStringArrayFunctionCallsWrapperName {
+export interface IStringArrayIntermediateCallsWrapperData {
     /**
      * @type {TStringArrayEncoding}
      */

+ 2 - 3
src/interfaces/storages/string-array-transformers/IStringArrayStorage.ts

@@ -1,7 +1,6 @@
 import { TStringArrayEncoding } from '../../../types/options/TStringArrayEncoding';
 
 import { IMapStorage } from '../IMapStorage';
-import { IStringArrayCallsWrapperNames } from '../../node-transformers/string-array-transformers/IStringArrayCallsWrapperNames';
 import { IStringArrayStorageItemData } from './IStringArrayStorageItem';
 
 export interface IStringArrayStorage extends IMapStorage <string, IStringArrayStorageItemData> {
@@ -17,9 +16,9 @@ export interface IStringArrayStorage extends IMapStorage <string, IStringArraySt
 
     /**
      * @param {TStringArrayEncoding | null} stringArrayEncoding
-     * @returns {IStringArrayCallsWrapperNames}
+     * @returns {string}
      */
-    getStorageCallsWrapperNames (stringArrayEncoding: TStringArrayEncoding | null): IStringArrayCallsWrapperNames;
+    getStorageCallsWrapperName (stringArrayEncoding: TStringArrayEncoding | null): string;
 
     rotateStorage (): void;
 

+ 62 - 61
src/node-transformers/string-array-transformers/StringArrayTransformer.ts

@@ -3,8 +3,9 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
 import * as ESTree from 'estree';
 
+import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope';
 import { TStringArrayEncoding } from '../../types/options/TStringArrayEncoding';
-import { TStringArrayFunctionCallsWrapperNamesMap } from '../../types/node-transformers/string-array-transformers/TStringArrayFunctionCallsWrapperNamesMap';
+import { TStringArrayIntermediateCallsWrapperDataByEncoding } from '../../types/node-transformers/string-array-transformers/TStringArrayIntermediateCallsWrapperDataByEncoding';
 
 import { IArrayUtils } from '../../interfaces/utils/IArrayUtils';
 import { IEscapeSequenceEncoder } from '../../interfaces/utils/IEscapeSequenceEncoder';
@@ -13,7 +14,6 @@ import { TIdentifierNamesGeneratorFactory } from '../../types/container/generato
 import { ILiteralNodesCacheStorage } from '../../interfaces/storages/string-array-transformers/ILiteralNodesCacheStorage';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { IStringArrayCallsWrapperNames } from '../../interfaces/node-transformers/string-array-transformers/IStringArrayCallsWrapperNames';
 import { IStringArrayStorage } from '../../interfaces/storages/string-array-transformers/IStringArrayStorage';
 import { IStringArrayStorageAnalyzer } from '../../interfaces/analyzers/string-array-storage-analyzer/IStringArrayStorageAnalyzer';
 import { IStringArrayStorageItemData } from '../../interfaces/storages/string-array-transformers/IStringArrayStorageItem';
@@ -53,10 +53,12 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
     private readonly literalNodesCacheStorage: ILiteralNodesCacheStorage;
 
     /**
-     * @type {Map<ESTree.Function, TStringArrayFunctionCallsWrapperNamesMap>}
+     * @type {Map<TNodeWithLexicalScope, TStringArrayIntermediateCallsWrapperDataByEncoding>}
      */
-    private readonly stringArrayFunctionsCallsWrapperNamesMap:
-        Map<ESTree.Function, TStringArrayFunctionCallsWrapperNamesMap> = new Map();
+    private readonly stringArrayIntermediateCallsWrapperDataByEncodingMap: Map<
+        TNodeWithLexicalScope,
+        TStringArrayIntermediateCallsWrapperDataByEncoding
+    > = new Map();
 
     /**
      * @type {IStringArrayStorage}
@@ -69,9 +71,9 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
     private readonly stringArrayStorageAnalyzer: IStringArrayStorageAnalyzer;
 
     /**
-     * @type {ESTree.Function[]}
+     * @type {TNodeWithLexicalScope[]}
      */
-    private readonly visitedFunctionNodesStack: ESTree.Function[] = [];
+    private readonly visitedLexicalScopeNodesStack: TNodeWithLexicalScope[] = [];
 
     /**
      * @param {IRandomGenerator} randomGenerator
@@ -141,8 +143,8 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
                             this.prepareNode(node);
                         }
 
-                        if (NodeGuards.isFunctionNode(node)) {
-                            this.onFunctionNodeEnter(node);
+                        if (NodeGuards.isNodeWithLexicalScope(node)) {
+                            this.onLexicalScopeNodeEnter(node);
                         }
 
                         if (parentNode && NodeGuards.isLiteralNode(node) && !NodeMetadata.isReplacedLiteral(node)) {
@@ -150,10 +152,10 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
                         }
                     },
                     leave: (node: ESTree.Node): ESTree.Node | undefined => {
-                        if (NodeGuards.isFunctionNode(node)) {
-                            this.onFunctionNodeLeave();
+                        if (NodeGuards.isNodeWithLexicalScope(node)) {
+                            this.onLexicalScopeNodeLeave();
 
-                            return this.transformFunctionNode(node);
+                            return this.transformLexicalScopeNode(node);
                         }
                     }
                 };
@@ -262,37 +264,34 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
     private getStringArrayCallsWrapperName (stringArrayStorageItemData: IStringArrayStorageItemData): string {
         const {encoding} = stringArrayStorageItemData;
 
-        const stringArrayCallsWrapperNames: IStringArrayCallsWrapperNames =
-            this.stringArrayStorage.getStorageCallsWrapperNames(encoding);
+        const stringArrayCallsWrapperName: string = this.stringArrayStorage.getStorageCallsWrapperName(encoding);
 
         // Name of the string array calls wrapper itself
         if (!this.options.stringArrayIntermediateVariablesCount) {
-            return stringArrayCallsWrapperNames.name;
+            return stringArrayCallsWrapperName;
         }
 
-        const currentFunctionNode: ESTree.Function | null = this.arrayUtils.getLastElement(this.visitedFunctionNodesStack);
+        const currentLexicalScopeNode: TNodeWithLexicalScope | null = this.arrayUtils.getLastElement(this.visitedLexicalScopeNodesStack);
 
-        // Variant #1: inside `Program` scope, return name of root calls wrapper
-        if (!currentFunctionNode) {
-            return this.getStringArrayIntermediateCallsWrapperName(encoding);
+        if (!currentLexicalScopeNode) {
+            throw new Error('Cannot find current lexical scope node');
         }
 
-        // Variant #2: inside `Function` scope, return name of function calls wrapper
-        const stringArrayIntermediateCallsWrapperNames: TStringArrayFunctionCallsWrapperNamesMap = currentFunctionNode
-            ? this.stringArrayFunctionsCallsWrapperNamesMap.get(currentFunctionNode) ?? {}
+        const stringArrayIntermediateCallsWrapperDataByEncoding: TStringArrayIntermediateCallsWrapperDataByEncoding = currentLexicalScopeNode
+            ? this.stringArrayIntermediateCallsWrapperDataByEncodingMap.get(currentLexicalScopeNode) ?? {}
             : {};
-        let stringArrayIntermediateCallsWrapperName: string = stringArrayIntermediateCallsWrapperNames[encoding]?.name ?? '';
+        let stringArrayIntermediateCallsWrapperName: string = stringArrayIntermediateCallsWrapperDataByEncoding[encoding]?.name ?? '';
 
-        if (currentFunctionNode && !stringArrayIntermediateCallsWrapperName) {
-            stringArrayIntermediateCallsWrapperName = this.identifierNamesGenerator.generateForLexicalScope(currentFunctionNode);
-            stringArrayIntermediateCallsWrapperNames[encoding] = {
+        if (currentLexicalScopeNode && !stringArrayIntermediateCallsWrapperName) {
+            stringArrayIntermediateCallsWrapperName = this.identifierNamesGenerator.generateForLexicalScope(currentLexicalScopeNode);
+            stringArrayIntermediateCallsWrapperDataByEncoding[encoding] = {
                 encoding,
                 name: stringArrayIntermediateCallsWrapperName
             };
 
-            this.stringArrayFunctionsCallsWrapperNamesMap.set(
-                currentFunctionNode,
-                stringArrayIntermediateCallsWrapperNames
+            this.stringArrayIntermediateCallsWrapperDataByEncodingMap.set(
+                currentLexicalScopeNode,
+                stringArrayIntermediateCallsWrapperDataByEncoding
             );
         }
 
@@ -303,66 +302,68 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
      * @param {TStringArrayEncoding} encoding
      * @returns {string}
      */
-    private getStringArrayIntermediateCallsWrapperName (encoding: TStringArrayEncoding): string {
-        const stringArrayCallsWrapperNames: IStringArrayCallsWrapperNames =
-            this.stringArrayStorage.getStorageCallsWrapperNames(encoding);
-
-        return stringArrayCallsWrapperNames.intermediateNames.length
-            ? this.randomGenerator
-                .getRandomGenerator()
-                .pickone(stringArrayCallsWrapperNames.intermediateNames)
-            : stringArrayCallsWrapperNames.name;
+    private getStringArrayRootCallsWrapperName (encoding: TStringArrayEncoding): string {
+        return this.stringArrayStorage.getStorageCallsWrapperName(encoding);
     }
 
     /**
-     * @param {Function} functionNode
+     * @param {TNodeWithLexicalScope} lexicalScopeNode
      */
-    private onFunctionNodeEnter (functionNode: ESTree.Function): void {
-        this.visitedFunctionNodesStack.push(functionNode);
+    private onLexicalScopeNodeEnter (lexicalScopeNode: TNodeWithLexicalScope): void {
+        this.visitedLexicalScopeNodesStack.push(lexicalScopeNode);
     }
 
-    private onFunctionNodeLeave (): void {
-        this.visitedFunctionNodesStack.pop();
+    private onLexicalScopeNodeLeave (): void {
+        this.visitedLexicalScopeNodesStack.pop();
     }
 
     /**
-     * @param {Function} functionNode
-     * @returns {Function}
+     * @param {TNodeWithLexicalScope} lexicalScopeNode
+     * @returns {TNodeWithLexicalScope}
      */
-    private transformFunctionNode (functionNode: ESTree.Function): ESTree.Function {
+    private transformLexicalScopeNode (lexicalScopeNode: TNodeWithLexicalScope): TNodeWithLexicalScope {
         if (!this.options.stringArrayIntermediateVariablesCount) {
-            return functionNode;
+            return lexicalScopeNode;
         }
 
-        if (!NodeGuards.isBlockStatementNode(functionNode.body)) {
-            return functionNode;
+        const lexicalScopeBodyNode: ESTree.Program | ESTree.BlockStatement | ESTree.Expression =
+            NodeGuards.isProgramNode(lexicalScopeNode)
+                ? lexicalScopeNode
+                : lexicalScopeNode.body;
+
+        if (
+            !lexicalScopeBodyNode.parentNode
+            || !NodeGuards.isNodeWithLexicalScopeStatements(lexicalScopeBodyNode, lexicalScopeBodyNode.parentNode)
+        ) {
+            return lexicalScopeNode;
         }
 
-        const stringArrayFunctionCallsWrapperNamesMap: TStringArrayFunctionCallsWrapperNamesMap | null =
-            this.stringArrayFunctionsCallsWrapperNamesMap.get(functionNode) ?? null;
+        const stringArrayIntermediateCallsWrapperDataByEncoding: TStringArrayIntermediateCallsWrapperDataByEncoding | null =
+            this.stringArrayIntermediateCallsWrapperDataByEncodingMap.get(lexicalScopeNode) ?? null;
 
-        if (!stringArrayFunctionCallsWrapperNamesMap) {
-            return functionNode;
+        if (!stringArrayIntermediateCallsWrapperDataByEncoding) {
+            return lexicalScopeNode;
         }
 
-        const stringArrayFunctionCallsWrapperNames = Object.values(stringArrayFunctionCallsWrapperNamesMap);
+        const stringArrayIntermediateCallsWrapperDataList =
+            Object.values(stringArrayIntermediateCallsWrapperDataByEncoding);
 
-        for (const stringArrayFunctionCallsWrapperName of stringArrayFunctionCallsWrapperNames) {
-            if (!stringArrayFunctionCallsWrapperName) {
+        for (const stringArrayIntermediateCallsWrapperData of stringArrayIntermediateCallsWrapperDataList) {
+            if (!stringArrayIntermediateCallsWrapperData) {
                 continue;
             }
 
-            const {encoding, name} = stringArrayFunctionCallsWrapperName;
-            const stringArrayCallsWrapperName: string = this.getStringArrayIntermediateCallsWrapperName(encoding);
+            const {encoding, name} = stringArrayIntermediateCallsWrapperData;
+            const stringArrayRootCallsWrapperName: string = this.getStringArrayRootCallsWrapperName(encoding);
 
             NodeAppender.prepend(
-                functionNode.body,
+                lexicalScopeBodyNode,
                 [
                     NodeFactory.variableDeclarationNode(
                         [
                             NodeFactory.variableDeclaratorNode(
                                 NodeFactory.identifierNode(name),
-                                NodeFactory.identifierNode(stringArrayCallsWrapperName)
+                                NodeFactory.identifierNode(stringArrayRootCallsWrapperName)
                             )
                         ],
                         'var',
@@ -371,7 +372,7 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
             );
         }
 
-        return functionNode;
+        return lexicalScopeNode;
     }
 
     /**

+ 8 - 21
src/storages/string-array-transformers/StringArrayStorage.ts

@@ -11,7 +11,6 @@ import { IEscapeSequenceEncoder } from '../../interfaces/utils/IEscapeSequenceEn
 import { IIdentifierNamesGenerator } from '../../interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { IStringArrayCallsWrapperNames } from '../../interfaces/node-transformers/string-array-transformers/IStringArrayCallsWrapperNames';
 import { IStringArrayStorage } from '../../interfaces/storages/string-array-transformers/IStringArrayStorage';
 import { IStringArrayStorageItemData } from '../../interfaces/storages/string-array-transformers/IStringArrayStorageItem';
 
@@ -87,9 +86,9 @@ export class StringArrayStorage extends MapStorage <string, IStringArrayStorageI
     private stringArrayStorageName!: string;
 
     /**
-     * @type {Map<TStringArrayEncoding | null, IStringArrayCallsWrapperNames>}
+     * @type {Map<TStringArrayEncoding | null, string>}
      */
-    private readonly stringArrayStorageCallsWrapperNamesMap: Map<TStringArrayEncoding | null, IStringArrayCallsWrapperNames> = new Map();
+    private readonly stringArrayStorageCallsWrapperNamesMap: Map<TStringArrayEncoding | null, string> = new Map();
 
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
@@ -173,22 +172,23 @@ export class StringArrayStorage extends MapStorage <string, IStringArrayStorageI
      * @param {TStringArrayEncoding | null} stringArrayEncoding
      * @returns {IStringArrayCallsWrapperNames}
      */
-    public getStorageCallsWrapperNames (stringArrayEncoding: TStringArrayEncoding | null): IStringArrayCallsWrapperNames {
-        const storageCallsWrapperName: IStringArrayCallsWrapperNames | null = this.stringArrayStorageCallsWrapperNamesMap
+    public getStorageCallsWrapperName (stringArrayEncoding: TStringArrayEncoding | null): string {
+        const storageCallsWrapperName: string | null = this.stringArrayStorageCallsWrapperNamesMap
             .get(stringArrayEncoding) ?? null;
 
         if (storageCallsWrapperName) {
             return storageCallsWrapperName;
         }
 
-        const newStorageCallsWrapperNames: IStringArrayCallsWrapperNames = this.getStringArrayCallsWrapperNames();
+        const newStorageCallsWrapperName: string = this.identifierNamesGenerator
+            .generateForGlobalScope(StringArrayStorage.stringArrayNameLength);
 
         this.stringArrayStorageCallsWrapperNamesMap.set(
             stringArrayEncoding,
-            newStorageCallsWrapperNames
+            newStorageCallsWrapperName
         );
 
-        return newStorageCallsWrapperNames;
+        return newStorageCallsWrapperName;
     }
 
     public rotateStorage (): void {
@@ -333,17 +333,4 @@ export class StringArrayStorage extends MapStorage <string, IStringArrayStorageI
             }
         }
     }
-
-    /**
-     * @returns {IStringArrayCallsWrapperNames}
-     */
-    private getStringArrayCallsWrapperNames (): IStringArrayCallsWrapperNames {
-        return {
-            name: this.identifierNamesGenerator.generateForGlobalScope(StringArrayStorage.stringArrayNameLength),
-            intermediateNames: Array.from(
-                {length: this.options.stringArrayIntermediateVariablesCount},
-                () => this.identifierNamesGenerator.generateForGlobalScope(StringArrayStorage.stringArrayNameLength)
-            )
-        };
-    }
 }

+ 0 - 7
src/types/node-transformers/string-array-transformers/TStringArrayFunctionCallsWrapperNamesMap.ts

@@ -1,7 +0,0 @@
-import { TStringArrayEncoding } from '../../options/TStringArrayEncoding';
-
-import { IStringArrayFunctionCallsWrapperName } from '../../../interfaces/node-transformers/string-array-transformers/IStringArrayFunctionCallsWrapperName';
-
-export type TStringArrayFunctionCallsWrapperNamesMap = Partial<{
-    [key in TStringArrayEncoding]: IStringArrayFunctionCallsWrapperName;
-}>;

+ 7 - 0
src/types/node-transformers/string-array-transformers/TStringArrayIntermediateCallsWrapperDataByEncoding.ts

@@ -0,0 +1,7 @@
+import { TStringArrayEncoding } from '../../options/TStringArrayEncoding';
+
+import { IStringArrayIntermediateCallsWrapperData } from '../../../interfaces/node-transformers/string-array-transformers/IStringArrayIntermediateCallsWrapperData';
+
+export type TStringArrayIntermediateCallsWrapperDataByEncoding = Partial<{
+    [key in TStringArrayEncoding]: IStringArrayIntermediateCallsWrapperData;
+}>;

+ 14 - 4
test/dev/dev.ts

@@ -8,17 +8,27 @@ import { StringArrayEncoding } from '../../src/enums/StringArrayEncoding';
 
     let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
         `
-            const foo = 'foo';
-            const bar = 'foo';
+            function test () {
+                const foo = 'foo';
+                const bar = 'bar';
+                const baz = 'baz';
+            }
+            
+            console.log('ddd');
+            console.log('eee');
+            console.log('yyy');
+            
+            test();
         `,
         {
             ...NO_ADDITIONAL_NODES_PRESET,
             compact: false,
             stringArray: true,
             stringArrayThreshold: 1,
-            stringArrayIntermediateVariablesCount: 0,
+            stringArrayIntermediateVariablesCount: 5,
             stringArrayEncoding: [
-                StringArrayEncoding.None
+                StringArrayEncoding.None,
+                StringArrayEncoding.Rc4
             ]
         }
     ).getObfuscatedCode();