浏览代码

`unicodeEscapeSequence` logic moved to the `EscapeSequenceTransformer`

sanex 4 年之前
父节点
当前提交
4c1bae0527
共有 47 个文件被更改,包括 394 次插入265 次删除
  1. 0 0
      dist/index.browser.js
  2. 0 0
      dist/index.cli.js
  3. 0 0
      dist/index.js
  4. 2 1
      src/JavaScriptObfuscator.ts
  5. 2 2
      src/container/InversifyContainerFacade.ts
  6. 1 1
      src/container/ServiceIdentifiers.ts
  7. 8 8
      src/container/modules/custom-nodes/CustomNodesModule.ts
  8. 9 4
      src/container/modules/node-transformers/StringsTransformersModule.ts
  9. 1 1
      src/enums/custom-nodes/StringArrayCustomNode.ts
  10. 1 1
      src/enums/node-transformers/NodeTransformationStage.ts
  11. 1 0
      src/enums/node-transformers/NodeTransformer.ts
  12. 91 0
      src/node-transformers/strings-transformers/EscapeSequenceTransformer.ts
  13. 11 11
      src/node-transformers/strings-transformers/StringArrayScopeCallsWrapperTransformer.ts
  14. 9 44
      src/node-transformers/strings-transformers/StringArrayTransformer.ts
  15. 7 0
      src/types/container/custom-nodes/TStringArrayCustomNodeFactory.ts
  16. 0 7
      src/types/container/custom-nodes/TStringArrayTransformerCustomNodeFactory.ts
  17. 3 7
      test/dev/dev.ts
  18. 206 0
      test/functional-tests/node-transformers/strings-transformers/escape-sequence-transformer/EscapeSequenceTransformer.spec.ts
  19. 0 0
      test/functional-tests/node-transformers/strings-transformers/escape-sequence-transformer/fixtures/error-when-non-latin.js
  20. 0 0
      test/functional-tests/node-transformers/strings-transformers/escape-sequence-transformer/fixtures/force-transformed-strings-option.js
  21. 0 0
      test/functional-tests/node-transformers/strings-transformers/escape-sequence-transformer/fixtures/reserved-strings-option-1.js
  22. 0 0
      test/functional-tests/node-transformers/strings-transformers/escape-sequence-transformer/fixtures/reserved-strings-option-2.js
  23. 0 0
      test/functional-tests/node-transformers/strings-transformers/escape-sequence-transformer/fixtures/simple-input.js
  24. 0 0
      test/functional-tests/node-transformers/strings-transformers/escape-sequence-transformer/fixtures/wrappers-count.js
  25. 0 0
      test/functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/StringArrayScopeCallsWrapperTransformer.spec.ts
  26. 0 0
      test/functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/fixtures/chained-calls-1.js
  27. 0 0
      test/functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/fixtures/chained-calls-2.js
  28. 0 0
      test/functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/fixtures/prohibited-scope-1.js
  29. 0 0
      test/functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/fixtures/prohibited-scope-2.js
  30. 0 0
      test/functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/fixtures/wrapper-for-the-function-default-parameter.js
  31. 0 0
      test/functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/fixtures/wrappers-count-const-no-root-wrappers.js
  32. 9 0
      test/functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/fixtures/wrappers-count-const.js
  33. 0 0
      test/functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/fixtures/wrappers-count-eval.js
  34. 0 0
      test/functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/fixtures/wrappers-count-var.js
  35. 25 176
      test/functional-tests/node-transformers/strings-transformers/string-array-transformer/StringArrayTransformer.spec.ts
  36. 0 0
      test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/export-all-declaration-source.js
  37. 0 0
      test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/export-named-declaration-source.js
  38. 2 0
      test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/force-transformed-strings-option.js
  39. 0 0
      test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/import-declaration-source.js
  40. 0 0
      test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/object-expression-computed-key-literal.js
  41. 0 0
      test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/object-expression-key-literal.js
  42. 2 0
      test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/reserved-strings-option.js
  43. 0 0
      test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/same-literal-values.js
  44. 0 0
      test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/short-literal-value.js
  45. 1 0
      test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/simple-input.js
  46. 0 0
      test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/string-array-calls-wrapper-name.js
  47. 3 2
      test/index.spec.ts

文件差异内容过多而无法显示
+ 0 - 0
dist/index.browser.js


文件差异内容过多而无法显示
+ 0 - 0
dist/index.cli.js


文件差异内容过多而无法显示
+ 0 - 0
dist/index.js


+ 2 - 1
src/JavaScriptObfuscator.ts

@@ -68,6 +68,7 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
         NodeTransformer.CommentsTransformer,
         NodeTransformer.CustomCodeHelpersTransformer,
         NodeTransformer.DeadCodeInjectionTransformer,
+        NodeTransformer.EscapeSequenceTransformer,
         NodeTransformer.EvalCallExpressionTransformer,
         NodeTransformer.ExpressionStatementsMergeTransformer,
         NodeTransformer.FunctionControlFlowTransformer,
@@ -224,7 +225,7 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
 
         astTree = this.runNodeTransformationStage(astTree, NodeTransformationStage.Converting);
         astTree = this.runNodeTransformationStage(astTree, NodeTransformationStage.RenameIdentifiers);
-        astTree = this.runNodeTransformationStage(astTree, NodeTransformationStage.StringArray);
+        astTree = this.runNodeTransformationStage(astTree, NodeTransformationStage.Strings);
 
         if (this.options.simplify) {
             astTree = this.runNodeTransformationStage(astTree, NodeTransformationStage.Simplifying);

+ 2 - 2
src/container/InversifyContainerFacade.ts

@@ -19,7 +19,7 @@ import { renameIdentifiersTransformersModule } from './modules/node-transformers
 import { renamePropertiesTransformersModule } from './modules/node-transformers/RenamePropertiesTransformersModule';
 import { simplifyingTransformersModule } from './modules/node-transformers/SimplifyingTransformersModule';
 import { storagesModule } from './modules/storages/StoragesModule';
-import { stringArrayTransformersModule } from './modules/node-transformers/StringArrayTransformersModule';
+import { stringsTransformersModule } from './modules/node-transformers/StringsTransformersModule';
 import { utilsModule } from './modules/utils/UtilsModule';
 
 import { TInputOptions } from '../types/options/TInputOptions';
@@ -223,7 +223,7 @@ export class InversifyContainerFacade implements IInversifyContainerFacade {
         this.container.load(renamePropertiesTransformersModule);
         this.container.load(simplifyingTransformersModule);
         this.container.load(storagesModule);
-        this.container.load(stringArrayTransformersModule);
+        this.container.load(stringsTransformersModule);
         this.container.load(utilsModule);
     }
 

+ 1 - 1
src/container/ServiceIdentifiers.ts

@@ -12,7 +12,7 @@ export enum ServiceIdentifiers {
     Factory__IObfuscatedCode = 'Factory<IObfuscatedCode>',
     Factory__IObjectExpressionKeysTransformerCustomNode = 'Factory<IObjectExpressionKeysTransformerCustomNode>',
     Factory__IObjectExpressionExtractor = 'Factory<IObjectExpressionExtractor>',
-    Factory__IStringArrayTransformerCustomNode = 'Factory<IStringArrayTransformerCustomNode>',
+    Factory__IStringArrayCustomNode = 'Factory<IStringArrayCustomNode>',
     Factory__TControlFlowStorage = 'Factory<TControlFlowStorage>',
     IArrayUtils = 'IArrayUtils',
     ICalleeDataExtractor = 'ICalleeDataExtractor',

+ 8 - 8
src/container/modules/custom-nodes/CustomNodesModule.ts

@@ -7,7 +7,7 @@ import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
 import { ControlFlowCustomNode } from '../../../enums/custom-nodes/ControlFlowCustomNode';
 import { DeadCodeInjectionCustomNode } from '../../../enums/custom-nodes/DeadCodeInjectionCustomNode';
 import { ObjectExpressionKeysTransformerCustomNode } from '../../../enums/custom-nodes/ObjectExpressionKeysTransformerCustomNode';
-import { StringArrayTransformerCustomNode } from '../../../enums/custom-nodes/StringArrayTransformerCustomNode';
+import { StringArrayCustomNode } from '../../../enums/custom-nodes/StringArrayCustomNode';
 
 import { ObjectExpressionVariableDeclarationHostNode } from '../../../custom-nodes/object-expression-keys-transformer-nodes/ObjectExpressionVariableDeclarationHostNode';
 import { BinaryExpressionFunctionNode } from '../../../custom-nodes/control-flow-flattening-nodes/BinaryExpressionFunctionNode';
@@ -72,18 +72,18 @@ export const customNodesModule: interfaces.ContainerModule = new ContainerModule
         .toConstructor(ObjectExpressionVariableDeclarationHostNode)
         .whenTargetNamed(ObjectExpressionKeysTransformerCustomNode.ObjectExpressionVariableDeclarationHostNode);
 
-    // string array transformer nodes
+    // string array nodes
     bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
         .toConstructor(StringArrayCallNode)
-        .whenTargetNamed(StringArrayTransformerCustomNode.StringArrayCallNode);
+        .whenTargetNamed(StringArrayCustomNode.StringArrayCallNode);
 
     bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
         .toConstructor(StringArrayScopeCallsWrapperFunctionNode)
-        .whenTargetNamed(StringArrayTransformerCustomNode.StringArrayScopeCallsWrapperFunctionNode);
+        .whenTargetNamed(StringArrayCustomNode.StringArrayScopeCallsWrapperFunctionNode);
 
     bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
         .toConstructor(StringArrayScopeCallsWrapperVariableNode)
-        .whenTargetNamed(StringArrayTransformerCustomNode.StringArrayScopeCallsWrapperVariableNode);
+        .whenTargetNamed(StringArrayCustomNode.StringArrayScopeCallsWrapperVariableNode);
 
     // control flow customNode constructor factory
     bind<ICustomNode>(ServiceIdentifiers.Factory__IControlFlowCustomNode)
@@ -118,10 +118,10 @@ export const customNodesModule: interfaces.ContainerModule = new ContainerModule
                 ServiceIdentifiers.IOptions
             ));
 
-    // string array transformer customNode constructor factory
-    bind<ICustomNode>(ServiceIdentifiers.Factory__IStringArrayTransformerCustomNode)
+    // string array customNode constructor factory
+    bind<ICustomNode>(ServiceIdentifiers.Factory__IStringArrayCustomNode)
         .toFactory<ICustomNode>(InversifyContainerFacade
-            .getConstructorFactory<StringArrayTransformerCustomNode, ICustomNode>(
+            .getConstructorFactory<StringArrayCustomNode, ICustomNode>(
                 ServiceIdentifiers.Newable__ICustomNode,
                 ServiceIdentifiers.Factory__IIdentifierNamesGenerator,
                 ServiceIdentifiers.ICustomCodeHelperFormatter,

+ 9 - 4
src/container/modules/node-transformers/StringArrayTransformersModule.ts → src/container/modules/node-transformers/StringsTransformersModule.ts

@@ -5,11 +5,16 @@ import { INodeTransformer } from '../../../interfaces/node-transformers/INodeTra
 
 import { NodeTransformer } from '../../../enums/node-transformers/NodeTransformer';
 
-import { StringArrayScopeCallsWrapperTransformer } from '../../../node-transformers/string-array-transformers/StringArrayScopeCallsWrapperTransformer';
-import { StringArrayTransformer } from '../../../node-transformers/string-array-transformers/StringArrayTransformer';
+import { EscapeSequenceTransformer } from '../../../node-transformers/strings-transformers/EscapeSequenceTransformer';
+import { StringArrayScopeCallsWrapperTransformer } from '../../../node-transformers/strings-transformers/StringArrayScopeCallsWrapperTransformer';
+import { StringArrayTransformer } from '../../../node-transformers/strings-transformers/StringArrayTransformer';
+
+export const stringsTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
+    // strings transformers
+    bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
+        .to(EscapeSequenceTransformer)
+        .whenTargetNamed(NodeTransformer.EscapeSequenceTransformer);
 
-export const stringArrayTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
-    // string array transformers
     bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
         .to(StringArrayScopeCallsWrapperTransformer)
         .whenTargetNamed(NodeTransformer.StringArrayScopeCallsWrapperTransformer);

+ 1 - 1
src/enums/custom-nodes/StringArrayTransformerCustomNode.ts → src/enums/custom-nodes/StringArrayCustomNode.ts

@@ -1,4 +1,4 @@
-export enum StringArrayTransformerCustomNode {
+export enum StringArrayCustomNode {
     StringArrayCallNode = 'StringArrayCallNode',
     StringArrayScopeCallsWrapperFunctionNode = 'StringArrayScopeCallsWrapperFunctionNode',
     StringArrayScopeCallsWrapperVariableNode = 'StringArrayScopeCallsWrapperVariableNode'

+ 1 - 1
src/enums/node-transformers/NodeTransformationStage.ts

@@ -8,5 +8,5 @@ export enum NodeTransformationStage {
     RenameIdentifiers = 'RenameIdentifiers',
     RenameProperties = 'RenameProperties',
     Simplifying = 'Simplifying',
-    StringArray = 'StringArray'
+    Strings = 'Strings'
 }

+ 1 - 0
src/enums/node-transformers/NodeTransformer.ts

@@ -5,6 +5,7 @@ export enum NodeTransformer {
     CommentsTransformer = 'CommentsTransformer',
     CustomCodeHelpersTransformer = 'CustomCodeHelpersTransformer',
     DeadCodeInjectionTransformer = 'DeadCodeInjectionTransformer',
+    EscapeSequenceTransformer = 'EscapeSequenceTransformer',
     EvalCallExpressionTransformer = 'EvalCallExpressionTransformer',
     ExpressionStatementsMergeTransformer = 'ExpressionStatementsMergeTransformer',
     FunctionControlFlowTransformer = 'FunctionControlFlowTransformer',

+ 91 - 0
src/node-transformers/strings-transformers/EscapeSequenceTransformer.ts

@@ -0,0 +1,91 @@
+import { inject, injectable, } from 'inversify';
+import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
+
+import * as ESTree from 'estree';
+
+import { IEscapeSequenceEncoder } from '../../interfaces/utils/IEscapeSequenceEncoder';
+import { IOptions } from '../../interfaces/options/IOptions';
+import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
+import { IVisitor } from '../../interfaces/node-transformers/IVisitor';
+
+import { NodeTransformationStage } from '../../enums/node-transformers/NodeTransformationStage';
+import { NodeTransformer } from '../../enums/node-transformers/NodeTransformer';
+
+import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
+import { NodeGuards } from '../../node/NodeGuards';
+import { NodeLiteralUtils } from '../../node/NodeLiteralUtils';
+import { NodeFactory } from '../../node/NodeFactory';
+import { NodeUtils } from '../../node/NodeUtils';
+
+@injectable()
+export class EscapeSequenceTransformer extends AbstractNodeTransformer {
+    /**
+     * @type {NodeTransformer[]}
+     */
+    public readonly runAfter: NodeTransformer[] = [
+        NodeTransformer.StringArrayScopeCallsWrapperTransformer,
+        NodeTransformer.StringArrayTransformer
+    ];
+
+    /**
+     * @type {IEscapeSequenceEncoder}
+     */
+    private readonly escapeSequenceEncoder: IEscapeSequenceEncoder;
+
+    /**
+     * @param {IRandomGenerator} randomGenerator
+     * @param {IOptions} options
+     * @param {IEscapeSequenceEncoder} escapeSequenceEncoder
+     */
+    public constructor (
+        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
+        @inject(ServiceIdentifiers.IOptions) options: IOptions,
+        @inject(ServiceIdentifiers.IEscapeSequenceEncoder) escapeSequenceEncoder: IEscapeSequenceEncoder
+    ) {
+        super(randomGenerator, options);
+
+        this.escapeSequenceEncoder = escapeSequenceEncoder;
+    }
+
+    /**
+     * @param {NodeTransformationStage} nodeTransformationStage
+     * @returns {IVisitor | null}
+     */
+    public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null {
+        switch (nodeTransformationStage) {
+            case NodeTransformationStage.Strings:
+                return {
+                    enter: (node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node | undefined => {
+                        if (NodeGuards.isLiteralNode(node)) {
+                            return this.transformNode(node, parentNode);
+                        }
+                    }
+                };
+
+            default:
+                return null;
+        }
+    }
+
+    /**
+     * @param {Literal} literalNode
+     * @param {Node | null} parentNode
+     * @returns {Literal}
+     */
+    public transformNode (literalNode: ESTree.Literal, parentNode: ESTree.Node | null): ESTree.Literal {
+        if (!NodeLiteralUtils.isStringLiteralNode(literalNode)) {
+            return literalNode;
+        }
+
+        const newLiteralNode: ESTree.Literal = NodeFactory.literalNode(
+            this.escapeSequenceEncoder.encode(
+                literalNode.value,
+                this.options.unicodeEscapeSequence
+            )
+        );
+
+        NodeUtils.parentizeNode(newLiteralNode, parentNode);
+
+        return newLiteralNode;
+    }
+}

+ 11 - 11
src/node-transformers/string-array-transformers/StringArrayScopeCallsWrapperTransformer.ts → src/node-transformers/strings-transformers/StringArrayScopeCallsWrapperTransformer.ts

@@ -7,7 +7,7 @@ import { TInitialData } from '../../types/TInitialData';
 import { TNodeWithLexicalScopeStatements } from '../../types/node/TNodeWithLexicalScopeStatements';
 import { TStatement } from '../../types/node/TStatement';
 import { TStringArrayScopeCallsWrapperNamesDataByEncoding } from '../../types/node-transformers/string-array-transformers/TStringArrayScopeCallsWrapperNamesDataByEncoding';
-import { TStringArrayTransformerCustomNodeFactory } from '../../types/container/custom-nodes/TStringArrayTransformerCustomNodeFactory';
+import { TStringArrayCustomNodeFactory } from '../../types/container/custom-nodes/TStringArrayCustomNodeFactory';
 
 import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode';
 import { IOptions } from '../../interfaces/options/IOptions';
@@ -21,14 +21,14 @@ import { IVisitedLexicalScopeNodesStackStorage } from '../../interfaces/storages
 import { IVisitor } from '../../interfaces/node-transformers/IVisitor';
 
 import { NodeTransformationStage } from '../../enums/node-transformers/NodeTransformationStage';
-import { StringArrayTransformerCustomNode } from '../../enums/custom-nodes/StringArrayTransformerCustomNode';
+import { StringArrayCustomNode } from '../../enums/custom-nodes/StringArrayCustomNode';
 import { StringArrayWrappersType } from '../../enums/node-transformers/string-array-transformers/StringArrayWrappersType';
 
 import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
 import { NodeAppender } from '../../node/NodeAppender';
 import { NodeGuards } from '../../node/NodeGuards';
-import { StringArrayScopeCallsWrapperVariableNode } from '../../custom-nodes/string-array-nodes/StringArrayScopeCallsWrapperVariableNode';
 import { StringArrayScopeCallsWrapperFunctionNode } from '../../custom-nodes/string-array-nodes/StringArrayScopeCallsWrapperFunctionNode';
+import { StringArrayScopeCallsWrapperVariableNode } from '../../custom-nodes/string-array-nodes/StringArrayScopeCallsWrapperVariableNode';
 
 @injectable()
 export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransformer {
@@ -48,9 +48,9 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo
     private readonly stringArrayScopeCallsWrapperNamesDataStorage: IStringArrayScopeCallsWrapperNamesDataStorage;
 
     /**
-     * @type {TStringArrayTransformerCustomNodeFactory}
+     * @type {TStringArrayCustomNodeFactory}
      */
-    private readonly stringArrayTransformerCustomNodeFactory: TStringArrayTransformerCustomNodeFactory;
+    private readonly stringArrayTransformerCustomNodeFactory: TStringArrayCustomNodeFactory;
 
     /**
      * @type {IVisitedLexicalScopeNodesStackStorage}
@@ -64,7 +64,7 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo
      * @param {IStringArrayStorage} stringArrayStorage
      * @param {IStringArrayScopeCallsWrapperNamesDataStorage} stringArrayScopeCallsWrapperNamesDataStorage
      * @param {IStringArrayScopeCallsWrapperLexicalScopeDataStorage} stringArrayScopeCallsWrapperLexicalScopeDataStorage
-     * @param {TStringArrayTransformerCustomNodeFactory} stringArrayTransformerCustomNodeFactory
+     * @param {TStringArrayCustomNodeFactory} stringArrayTransformerCustomNodeFactory
      */
     public constructor (
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
@@ -73,8 +73,8 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo
         @inject(ServiceIdentifiers.IStringArrayStorage) stringArrayStorage: IStringArrayStorage,
         @inject(ServiceIdentifiers.IStringArrayScopeCallsWrapperNamesDataStorage) stringArrayScopeCallsWrapperNamesDataStorage: IStringArrayScopeCallsWrapperNamesDataStorage,
         @inject(ServiceIdentifiers.IStringArrayScopeCallsWrapperLexicalScopeDataStorage) stringArrayScopeCallsWrapperLexicalScopeDataStorage: IStringArrayScopeCallsWrapperLexicalScopeDataStorage,
-        @inject(ServiceIdentifiers.Factory__IStringArrayTransformerCustomNode)
-            stringArrayTransformerCustomNodeFactory: TStringArrayTransformerCustomNodeFactory
+        @inject(ServiceIdentifiers.Factory__IStringArrayCustomNode)
+            stringArrayTransformerCustomNodeFactory: TStringArrayCustomNodeFactory
     ) {
         super(randomGenerator, options);
 
@@ -95,7 +95,7 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo
         }
 
         switch (nodeTransformationStage) {
-            case NodeTransformationStage.StringArray:
+            case NodeTransformationStage.Strings:
                 return {
                     enter: (node: ESTree.Node, parentNode: ESTree.Node | null): void => {
                         if (parentNode && NodeGuards.isNodeWithLexicalScopeStatements(node, parentNode)) {
@@ -278,7 +278,7 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo
     ): TStatement[] {
         const stringArrayScopeCallsWrapperVariableNode: ICustomNode<TInitialData<StringArrayScopeCallsWrapperVariableNode>> =
             this.stringArrayTransformerCustomNodeFactory(
-                StringArrayTransformerCustomNode.StringArrayScopeCallsWrapperVariableNode
+                StringArrayCustomNode.StringArrayScopeCallsWrapperVariableNode
             );
 
         stringArrayScopeCallsWrapperVariableNode.initialize(
@@ -302,7 +302,7 @@ export class StringArrayScopeCallsWrapperTransformer extends AbstractNodeTransfo
     ): TStatement[] {
         const stringArrayScopeCallsWrapperFunctionNode: ICustomNode<TInitialData<StringArrayScopeCallsWrapperFunctionNode>> =
             this.stringArrayTransformerCustomNodeFactory(
-                StringArrayTransformerCustomNode.StringArrayScopeCallsWrapperFunctionNode
+                StringArrayCustomNode.StringArrayScopeCallsWrapperFunctionNode
             );
 
         stringArrayScopeCallsWrapperFunctionNode.initialize(

+ 9 - 44
src/node-transformers/string-array-transformers/StringArrayTransformer.ts → src/node-transformers/strings-transformers/StringArrayTransformer.ts

@@ -8,10 +8,9 @@ import { TInitialData } from '../../types/TInitialData';
 import { TNodeWithLexicalScopeStatements } from '../../types/node/TNodeWithLexicalScopeStatements';
 import { TStatement } from '../../types/node/TStatement';
 import { TStringArrayScopeCallsWrapperNamesDataByEncoding } from '../../types/node-transformers/string-array-transformers/TStringArrayScopeCallsWrapperNamesDataByEncoding';
-import { TStringArrayTransformerCustomNodeFactory } from '../../types/container/custom-nodes/TStringArrayTransformerCustomNodeFactory';
+import { TStringArrayCustomNodeFactory } from '../../types/container/custom-nodes/TStringArrayCustomNodeFactory';
 
 import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode';
-import { IEscapeSequenceEncoder } from '../../interfaces/utils/IEscapeSequenceEncoder';
 import { IIdentifierNamesGenerator } from '../../interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator';
 import { ILiteralNodesCacheStorage } from '../../interfaces/storages/string-array-transformers/ILiteralNodesCacheStorage';
 import { IOptions } from '../../interfaces/options/IOptions';
@@ -26,7 +25,7 @@ import { IVisitedLexicalScopeNodesStackStorage } from '../../interfaces/storages
 import { IVisitor } from '../../interfaces/node-transformers/IVisitor';
 
 import { NodeTransformationStage } from '../../enums/node-transformers/NodeTransformationStage';
-import { StringArrayTransformerCustomNode } from '../../enums/custom-nodes/StringArrayTransformerCustomNode';
+import { StringArrayCustomNode } from '../../enums/custom-nodes/StringArrayCustomNode';
 import { StringArrayWrappersType } from '../../enums/node-transformers/string-array-transformers/StringArrayWrappersType';
 
 import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
@@ -49,10 +48,6 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
      */
     private static readonly maxShiftedIndexValue: number = 1000;
 
-    /**
-     * @type {IEscapeSequenceEncoder}
-     */
-    private readonly escapeSequenceEncoder: IEscapeSequenceEncoder;
 
     /**
      * @type {IIdentifierNamesGenerator}
@@ -85,9 +80,9 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
     private readonly stringArrayScopeCallsWrapperNamesDataStorage: IStringArrayScopeCallsWrapperNamesDataStorage;
 
     /**
-     * @type {TStringArrayTransformerCustomNodeFactory}
+     * @type {TStringArrayCustomNodeFactory}
      */
-    private readonly stringArrayTransformerCustomNodeFactory: TStringArrayTransformerCustomNodeFactory;
+    private readonly stringArrayTransformerCustomNodeFactory: TStringArrayCustomNodeFactory;
 
     /**
      * @type {IVisitedLexicalScopeNodesStackStorage}
@@ -97,7 +92,6 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
     /**
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
-     * @param {IEscapeSequenceEncoder} escapeSequenceEncoder
      * @param {ILiteralNodesCacheStorage} literalNodesCacheStorage
      * @param {IVisitedLexicalScopeNodesStackStorage} visitedLexicalScopeNodesStackStorage
      * @param {IStringArrayStorage} stringArrayStorage
@@ -105,12 +99,11 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
      * @param {IStringArrayScopeCallsWrapperLexicalScopeDataStorage} stringArrayScopeCallsWrapperLexicalScopeDataStorage
      * @param {IStringArrayStorageAnalyzer} stringArrayStorageAnalyzer
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
-     * @param {TStringArrayTransformerCustomNodeFactory} stringArrayTransformerCustomNodeFactory
+     * @param {TStringArrayCustomNodeFactory} stringArrayTransformerCustomNodeFactory
      */
     public constructor (
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions,
-        @inject(ServiceIdentifiers.IEscapeSequenceEncoder) escapeSequenceEncoder: IEscapeSequenceEncoder,
         @inject(ServiceIdentifiers.ILiteralNodesCacheStorage) literalNodesCacheStorage: ILiteralNodesCacheStorage,
         @inject(ServiceIdentifiers.IVisitedLexicalScopeNodesStackStorage) visitedLexicalScopeNodesStackStorage: IVisitedLexicalScopeNodesStackStorage,
         @inject(ServiceIdentifiers.IStringArrayStorage) stringArrayStorage: IStringArrayStorage,
@@ -121,12 +114,11 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
         @inject(ServiceIdentifiers.IStringArrayStorageAnalyzer) stringArrayStorageAnalyzer: IStringArrayStorageAnalyzer,
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
-        @inject(ServiceIdentifiers.Factory__IStringArrayTransformerCustomNode)
-            stringArrayTransformerCustomNodeFactory: TStringArrayTransformerCustomNodeFactory
+        @inject(ServiceIdentifiers.Factory__IStringArrayCustomNode)
+            stringArrayTransformerCustomNodeFactory: TStringArrayCustomNodeFactory
     ) {
         super(randomGenerator, options);
 
-        this.escapeSequenceEncoder = escapeSequenceEncoder;
         this.literalNodesCacheStorage = literalNodesCacheStorage;
         this.visitedLexicalScopeNodesStackStorage = visitedLexicalScopeNodesStackStorage;
         this.stringArrayStorage = stringArrayStorage;
@@ -143,7 +135,7 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
      */
     public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null {
         switch (nodeTransformationStage) {
-            case NodeTransformationStage.StringArray:
+            case NodeTransformationStage.Strings:
                 return {
                     enter: (node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node | undefined => {
                         if (NodeGuards.isProgramNode(node)) {
@@ -156,15 +148,6 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
                     }
                 };
 
-            case NodeTransformationStage.Finalizing:
-                return {
-                    enter: (node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node | undefined => {
-                        if (parentNode && NodeGuards.isLiteralNode(node)) {
-                            return this.encodeLiteralNodeToEscapeSequence(node, parentNode);
-                        }
-                    }
-                };
-
             default:
                 return null;
         }
@@ -237,7 +220,7 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
         const {decodeKey } = stringArrayStorageItemData;
 
         const stringArrayCallCustomNode: ICustomNode<TInitialData<StringArrayCallNode>> =
-            this.stringArrayTransformerCustomNodeFactory(StringArrayTransformerCustomNode.StringArrayCallNode);
+            this.stringArrayTransformerCustomNodeFactory(StringArrayCustomNode.StringArrayCallNode);
 
         stringArrayCallCustomNode.initialize(stringArrayCallsWrapperName, index, decodeKey);
 
@@ -406,22 +389,4 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
 
         return lexicalScopeData;
     }
-
-    /**
-     * @param {Literal} literalNode
-     * @param {Node} parentNode
-     * @returns {Literal}
-     */
-    private encodeLiteralNodeToEscapeSequence (
-        literalNode: ESTree.Literal,
-        parentNode: ESTree.Node
-    ): ESTree.Literal {
-        if (!NodeLiteralUtils.isStringLiteralNode(literalNode)) {
-            return literalNode;
-        }
-
-        return NodeFactory.literalNode(
-            this.escapeSequenceEncoder.encode(literalNode.value, this.options.unicodeEscapeSequence)
-        );
-    }
 }

+ 7 - 0
src/types/container/custom-nodes/TStringArrayCustomNodeFactory.ts

@@ -0,0 +1,7 @@
+import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
+
+import { StringArrayCustomNode } from '../../../enums/custom-nodes/StringArrayCustomNode';
+
+export type TStringArrayCustomNodeFactory = <
+    TInitialData extends unknown[] = unknown[]
+> (stringArrayCustomNodeName: StringArrayCustomNode) => ICustomNode <TInitialData>;

+ 0 - 7
src/types/container/custom-nodes/TStringArrayTransformerCustomNodeFactory.ts

@@ -1,7 +0,0 @@
-import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
-
-import { StringArrayTransformerCustomNode } from '../../../enums/custom-nodes/StringArrayTransformerCustomNode';
-
-export type TStringArrayTransformerCustomNodeFactory = <
-    TInitialData extends unknown[] = unknown[]
-> (stringArrayTransformerCustomNodeName: StringArrayTransformerCustomNode) => ICustomNode <TInitialData>;

+ 3 - 7
test/dev/dev.ts

@@ -2,14 +2,13 @@
 
 import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNodes';
 import { IdentifierNamesGenerator } from '../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
-import { StringArrayWrappersType } from '../../src/enums/node-transformers/string-array-transformers/StringArrayWrappersType';
 
 (function () {
     const JavaScriptObfuscator: any = require('../../index');
 
     let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
         `
-            const foo = 'foo';
+            const foo = 'foo test';
 
             function test () {
                 const bar = 'bar';
@@ -18,13 +17,10 @@ import { StringArrayWrappersType } from '../../src/enums/node-transformers/strin
         {
             ...NO_ADDITIONAL_NODES_PRESET,
             compact: false,
-            forceTransformedStrings: ['foo'],
             identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
             stringArray: true,
-            stringArrayThreshold: 0,
-            stringArrayWrappersChainedCalls: true,
-            stringArrayWrappersCount: 1,
-            stringArrayWrappersType: StringArrayWrappersType.Function
+            stringArrayThreshold: 1,
+            unicodeEscapeSequence: false
         }
     ).getObfuscatedCode();
 

+ 206 - 0
test/functional-tests/node-transformers/strings-transformers/escape-sequence-transformer/EscapeSequenceTransformer.spec.ts

@@ -0,0 +1,206 @@
+import { assert } from 'chai';
+
+import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
+
+import { IdentifierNamesGenerator } from '../../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
+
+import { readFileAsString } from '../../../../helpers/readFileAsString';
+
+import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
+
+describe('EscapeSequenceTransformer', function () {
+    this.timeout(120000);
+
+    describe('Variant #1: string contains non-latin and non-digit characters and `unicodeEscapeSequence` is disabled', () => {
+        let testFunc: () => void;
+
+        before(() => {
+            const code: string = readFileAsString(__dirname + '/fixtures/error-when-non-latin.js');
+
+            testFunc = () => JavaScriptObfuscator.obfuscate(
+                code,
+                {
+                    ...NO_ADDITIONAL_NODES_PRESET,
+                    stringArray: true,
+                    stringArrayThreshold: 1
+                }
+            );
+        });
+
+        it('should\'t throw an error', () => {
+            assert.doesNotThrow(testFunc);
+        });
+    });
+
+    describe('Variant #2: `unicodeEscapeSequence` option is enabled', () => {
+        const regExp: RegExp = /^var test *= *'\\x74\\x65\\x73\\x74';$/;
+
+        let obfuscatedCode: string;
+
+        before(() => {
+            const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
+
+            obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                code,
+                {
+                    ...NO_ADDITIONAL_NODES_PRESET,
+                    unicodeEscapeSequence: true
+
+                }
+            ).getObfuscatedCode();
+        });
+
+        it('should replace literal node value with unicode escape sequence', () => {
+            assert.match(obfuscatedCode, regExp);
+        });
+    });
+
+    describe('Variant #3: `unicodeEscapeSequence` and `stringArray` options are enabled', () => {
+        const stringArrayRegExp: RegExp = /^var _0x([a-f0-9]){4} *= *\['\\x74\\x65\\x73\\x74'\];/;
+        const stringArrayCallRegExp: RegExp = /var test *= *_0x([a-f0-9]){4}\('\\x30\\x78\\x30'\);/;
+
+        let obfuscatedCode: string;
+
+        before(() => {
+            const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
+
+            obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                code,
+                {
+                    ...NO_ADDITIONAL_NODES_PRESET,
+                    stringArray: true,
+                    stringArrayThreshold: 1,
+                    unicodeEscapeSequence: true
+                }
+            ).getObfuscatedCode();
+        });
+
+        it('match #1: should replace literal node value with unicode escape sequence from string array', () => {
+            assert.match(obfuscatedCode, stringArrayRegExp);
+        });
+
+        it('match #2: should replace literal node value with unicode escape sequence from string array', () => {
+            assert.match(obfuscatedCode, stringArrayCallRegExp);
+        });
+    });
+
+    describe('Variant #4: `reservedStrings` option is enabled', () => {
+        describe('Variant #1: base', () => {
+            const stringLiteralRegExp1: RegExp = /const foo *= *'foo';/;
+            const stringLiteralRegExp2: RegExp = /const bar *= *'\\x62\\x61\\x72';/;
+
+            let obfuscatedCode: string;
+
+            before(() => {
+                const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-1.js');
+
+                obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                    code,
+                    {
+                        ...NO_ADDITIONAL_NODES_PRESET,
+                        reservedStrings: ['foo'],
+                        unicodeEscapeSequence: true
+                    }
+                ).getObfuscatedCode();
+            });
+
+            it('match #1: should ignore reserved strings', () => {
+                assert.match(obfuscatedCode, stringLiteralRegExp1);
+            });
+
+            it('match #2: should transform non-reserved strings', () => {
+                assert.match(obfuscatedCode, stringLiteralRegExp2);
+            });
+        });
+
+        describe('Variant #2: correct escape of special characters', () => {
+            const stringLiteralRegExp: RegExp = /var baz *= *'Cannot find module \\'' *\+ *foo *\+ *'\\x27';/;
+
+            let obfuscatedCode: string;
+
+            before(() => {
+                const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-2.js');
+
+                obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                    code,
+                    {
+                        ...NO_ADDITIONAL_NODES_PRESET,
+                        reservedStrings: ['a']
+                    }
+                ).getObfuscatedCode();
+            });
+
+            it('match #1: should ignore reserved strings', () => {
+                assert.match(obfuscatedCode, stringLiteralRegExp);
+            });
+        });
+    });
+
+    describe('Variant #5: `forceTransformedStrings` option is enabled', () => {
+        const stringLiteralRegExp1: RegExp = /const foo *= *'foo';/;
+        const stringLiteralRegExp2: RegExp = /const bar *= *'bar';/;
+
+        let obfuscatedCode: string;
+
+        before(() => {
+            const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option.js');
+
+            obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                code,
+                {
+                    ...NO_ADDITIONAL_NODES_PRESET,
+                    forceTransformedStrings: ['bar'],
+                    unicodeEscapeSequence: false
+                }
+            ).getObfuscatedCode();
+        });
+
+        it('match #1: should not encode force transformed string with unicode escape sequence', () => {
+            assert.match(obfuscatedCode, stringLiteralRegExp1);
+        });
+
+        it('match #2: should not encode force transformed string with unicode escape sequence', () => {
+            assert.match(obfuscatedCode, stringLiteralRegExp2);
+        });
+    });
+
+    describe('Variant #6: `stringArrayWrappersCount` option enabled', () => {
+        const stringArrayCallRegExp: RegExp = new RegExp(
+                'return e;' +
+            '};' +
+            'const f *= *b;' +
+            'const foo *= *f\\(\'\\\\x30\\\\x78\\\\x30\'\\);' +
+            'const bar *= *f\\(\'\\\\x30\\\\x78\\\\x31\'\\);' +
+            'const baz *= *f\\(\'\\\\x30\\\\x78\\\\x32\'\\);' +
+            'function test\\( *\\) *{' +
+                'const g *= *f;' +
+                'const c *= *g\\(\'\\\\x30\\\\x78\\\\x33\'\\);' +
+                'const d *= *g\\(\'\\\\x30\\\\x78\\\\x34\'\\);' +
+                'const e *= *g\\(\'\\\\x30\\\\x78\\\\x35\'\\);' +
+            '}'
+        );
+
+        let obfuscatedCode: string;
+
+        before(() => {
+            const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count.js');
+
+            obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                code,
+                {
+                    ...NO_ADDITIONAL_NODES_PRESET,
+                    identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
+                    stringArray: true,
+                    stringArrayThreshold: 1,
+                    stringArrayWrappersChainedCalls: true,
+                    stringArrayWrappersCount: 1,
+                    unicodeEscapeSequence: true
+                }
+            ).getObfuscatedCode();
+        });
+
+        it('should encode calls to the string array wrappers', () => {
+            assert.match(obfuscatedCode, stringArrayCallRegExp);
+        });
+    });
+});

+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/fixtures/error-when-non-latin.js → test/functional-tests/node-transformers/strings-transformers/escape-sequence-transformer/fixtures/error-when-non-latin.js


+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/fixtures/force-transformed-strings-option-1.js → test/functional-tests/node-transformers/strings-transformers/escape-sequence-transformer/fixtures/force-transformed-strings-option.js


+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/fixtures/reserved-strings-option-1.js → test/functional-tests/node-transformers/strings-transformers/escape-sequence-transformer/fixtures/reserved-strings-option-1.js


+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/fixtures/reserved-strings-option-2.js → test/functional-tests/node-transformers/strings-transformers/escape-sequence-transformer/fixtures/reserved-strings-option-2.js


+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/fixtures/simple-input.js → test/functional-tests/node-transformers/strings-transformers/escape-sequence-transformer/fixtures/simple-input.js


+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-scope-calls-wrapper-transformer/fixtures/wrappers-count-const.js → test/functional-tests/node-transformers/strings-transformers/escape-sequence-transformer/fixtures/wrappers-count.js


+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-scope-calls-wrapper-transformer/StringArrayScopeCallsWrapperTransformer.spec.ts → test/functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/StringArrayScopeCallsWrapperTransformer.spec.ts


+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-scope-calls-wrapper-transformer/fixtures/chained-calls-1.js → test/functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/fixtures/chained-calls-1.js


+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-scope-calls-wrapper-transformer/fixtures/chained-calls-2.js → test/functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/fixtures/chained-calls-2.js


+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-scope-calls-wrapper-transformer/fixtures/prohibited-scope-1.js → test/functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/fixtures/prohibited-scope-1.js


+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-scope-calls-wrapper-transformer/fixtures/prohibited-scope-2.js → test/functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/fixtures/prohibited-scope-2.js


+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-scope-calls-wrapper-transformer/fixtures/wrapper-for-the-function-default-parameter.js → test/functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/fixtures/wrapper-for-the-function-default-parameter.js


+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-scope-calls-wrapper-transformer/fixtures/wrappers-count-const-no-root-wrappers.js → test/functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/fixtures/wrappers-count-const-no-root-wrappers.js


+ 9 - 0
test/functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/fixtures/wrappers-count-const.js

@@ -0,0 +1,9 @@
+const foo = 'foo'
+const bar = 'bar';
+const baz = 'baz';
+
+function test () {
+    const bark = 'bark'
+    const hawk = 'hawk';
+    const eagle = 'eagle';
+}

+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-scope-calls-wrapper-transformer/fixtures/wrappers-count-eval.js → test/functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/fixtures/wrappers-count-eval.js


+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-scope-calls-wrapper-transformer/fixtures/wrappers-count-var.js → test/functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/fixtures/wrappers-count-var.js


+ 25 - 176
test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/StringArrayTransformer.spec.ts → test/functional-tests/node-transformers/strings-transformers/string-array-transformer/StringArrayTransformer.spec.ts

@@ -63,28 +63,7 @@ describe('StringArrayTransformer', function () {
         });
     });
 
-    describe('Variant #3: string contains non-latin and non-digit characters and `unicodeEscapeSequence` is disabled', () => {
-        let testFunc: () => void;
-
-        before(() => {
-            const code: string = readFileAsString(__dirname + '/fixtures/error-when-non-latin.js');
-
-            testFunc = () => JavaScriptObfuscator.obfuscate(
-                code,
-                {
-                    ...NO_ADDITIONAL_NODES_PRESET,
-                    stringArray: true,
-                    stringArrayThreshold: 1
-                }
-            );
-        });
-
-        it('should\'t throw an error', () => {
-            assert.doesNotThrow(testFunc);
-        });
-    });
-
-    describe('Variant #4: same literal node values', () => {
+    describe('Variant #3: same literal node values', () => {
         const stringArrayRegExp: RegExp = /^var _0x([a-f0-9]){4} *= *\['test'\];/;
         const stringArrayCallRegExp: RegExp = /var test *= *_0x([a-f0-9]){4}\('0x0'\);/;
 
@@ -112,59 +91,7 @@ describe('StringArrayTransformer', function () {
         });
     });
 
-    describe('Variant #5: `unicodeEscapeSequence` option is enabled', () => {
-        const regExp: RegExp = /^var test *= *'\\x74\\x65\\x73\\x74';$/;
-
-        let obfuscatedCode: string;
-
-        before(() => {
-            const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
-
-            obfuscatedCode = JavaScriptObfuscator.obfuscate(
-                code,
-                {
-                    ...NO_ADDITIONAL_NODES_PRESET,
-                    unicodeEscapeSequence: true
-
-                }
-            ).getObfuscatedCode();
-        });
-
-        it('should replace literal node value with unicode escape sequence', () => {
-            assert.match(obfuscatedCode, regExp);
-        });
-    });
-
-    describe('Variant #6: `unicodeEscapeSequence` and `stringArray` options are enabled', () => {
-        const stringArrayRegExp: RegExp = /^var _0x([a-f0-9]){4} *= *\['\\x74\\x65\\x73\\x74'\];/;
-        const stringArrayCallRegExp: RegExp = /var test *= *_0x([a-f0-9]){4}\('\\x30\\x78\\x30'\);/;
-
-        let obfuscatedCode: string;
-
-        before(() => {
-            const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
-
-            obfuscatedCode = JavaScriptObfuscator.obfuscate(
-                code,
-                {
-                    ...NO_ADDITIONAL_NODES_PRESET,
-                    stringArray: true,
-                    stringArrayThreshold: 1,
-                    unicodeEscapeSequence: true
-                }
-            ).getObfuscatedCode();
-        });
-
-        it('match #1: should replace literal node value with unicode escape sequence from string array', () => {
-            assert.match(obfuscatedCode, stringArrayRegExp);
-        });
-
-        it('match #2: should replace literal node value with unicode escape sequence from string array', () => {
-            assert.match(obfuscatedCode, stringArrayCallRegExp);
-        });
-    });
-
-    describe('Variant #7: short literal node value', () => {
+    describe('Variant #4: short literal node value', () => {
         const regExp: RegExp = /var test *= *'te';/;
 
         let obfuscatedCode: string;
@@ -187,7 +114,7 @@ describe('StringArrayTransformer', function () {
         });
     });
 
-    describe('Variant #8: base64 encoding', () => {
+    describe('Variant #5: base64 encoding', () => {
         const stringArrayRegExp: RegExp = new RegExp(`^var _0x([a-f0-9]){4} *= *\\['${swapLettersCase('dGVzdA==')}'];`);
         const stringArrayCallRegExp: RegExp = /var test *= *_0x([a-f0-9]){4}\('0x0'\);/;
 
@@ -216,7 +143,7 @@ describe('StringArrayTransformer', function () {
         });
     });
 
-    describe('Variant #9: rc4 encoding', () => {
+    describe('Variant #6: rc4 encoding', () => {
         describe('Variant #1: single string literal', () => {
             const regExp: RegExp = /var test *= *_0x([a-f0-9]){4}\('0x0', *'.{4}'\);/;
 
@@ -282,7 +209,7 @@ describe('StringArrayTransformer', function () {
         });
     });
 
-    describe('Variant #10: none and base64 encoding', () => {
+    describe('Variant #7: none and base64 encoding', () => {
         describe('Variant #1: string array values', () => {
             const samplesCount: number = 300;
             const expectedMatchesChance: number = 0.5;
@@ -338,7 +265,7 @@ describe('StringArrayTransformer', function () {
         });
     });
 
-    describe('Variant #11: none and rc4 encoding', () => {
+    describe('Variant #8: none and rc4 encoding', () => {
         describe('Variant #1: string array calls wrapper call', () => {
             const samplesCount: number = 300;
             const expectedMatchesChance: number = 0.5;
@@ -394,7 +321,7 @@ describe('StringArrayTransformer', function () {
         });
     });
 
-    describe('Variant #12: base64 and rc4 encoding', () => {
+    describe('Variant #9: base64 and rc4 encoding', () => {
         describe('Variant #1: single string literal', () => {
             const samplesCount: number = 300;
             const expectedMatchesChance: number = 0.5;
@@ -450,7 +377,7 @@ describe('StringArrayTransformer', function () {
         });
     });
 
-    describe('Variant #13: `stringArrayThreshold` option value', () => {
+    describe('Variant #10: `stringArrayThreshold` option value', () => {
         const samples: number = 1000;
         const stringArrayThreshold: number = 0.5;
         const delta: number = 0.1;
@@ -493,7 +420,7 @@ describe('StringArrayTransformer', function () {
         });
     });
 
-    describe('Variant #14: string array calls wrapper name', () => {
+    describe('Variant #11: string array calls wrapper name', () => {
         const regExp: RegExp = /console\[b\('0x0'\)]\('a'\);/;
 
         let obfuscatedCode: string;
@@ -517,7 +444,7 @@ describe('StringArrayTransformer', function () {
         });
     });
 
-    describe('Variant #15: `reservedStrings` option is enabled', () => {
+    describe('Variant #12: `reservedStrings` option is enabled', () => {
         describe('Variant #1: base `reservedStrings` values', () => {
             describe('Variant #1: single reserved string value', () => {
                 const stringLiteralRegExp1: RegExp = /const foo *= *'foo';/;
@@ -526,7 +453,7 @@ describe('StringArrayTransformer', function () {
                 let obfuscatedCode: string;
 
                 before(() => {
-                    const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-1.js');
+                    const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option.js');
 
                     obfuscatedCode = JavaScriptObfuscator.obfuscate(
                         code,
@@ -555,7 +482,7 @@ describe('StringArrayTransformer', function () {
                 let obfuscatedCode: string;
 
                 before(() => {
-                    const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-1.js');
+                    const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option.js');
 
                     obfuscatedCode = JavaScriptObfuscator.obfuscate(
                         code,
@@ -586,7 +513,7 @@ describe('StringArrayTransformer', function () {
                 let obfuscatedCode: string;
 
                 before(() => {
-                    const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-1.js');
+                    const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option.js');
 
                     obfuscatedCode = JavaScriptObfuscator.obfuscate(
                         code,
@@ -615,7 +542,7 @@ describe('StringArrayTransformer', function () {
                 let obfuscatedCode: string;
 
                 before(() => {
-                    const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-1.js');
+                    const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option.js');
 
                     obfuscatedCode = JavaScriptObfuscator.obfuscate(
                         code,
@@ -637,59 +564,9 @@ describe('StringArrayTransformer', function () {
                 });
             });
         });
-
-        describe('Variant #3: `unicodeEscapeSequence` option is enabled', () => {
-            const stringLiteralRegExp1: RegExp = /const foo *= *'foo';/;
-            const stringLiteralRegExp2: RegExp = /const bar *= *'\\x62\\x61\\x72';/;
-
-            let obfuscatedCode: string;
-
-            before(() => {
-                const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-1.js');
-
-                obfuscatedCode = JavaScriptObfuscator.obfuscate(
-                    code,
-                    {
-                        ...NO_ADDITIONAL_NODES_PRESET,
-                        reservedStrings: ['foo'],
-                        unicodeEscapeSequence: true
-                    }
-                ).getObfuscatedCode();
-            });
-
-            it('match #1: should ignore reserved strings', () => {
-                assert.match(obfuscatedCode, stringLiteralRegExp1);
-            });
-
-            it('match #2: should transform non-reserved strings', () => {
-                assert.match(obfuscatedCode, stringLiteralRegExp2);
-            });
-        });
-
-        describe('Variant #4: correct escape of special characters', () => {
-            const stringLiteralRegExp: RegExp = /var baz *= *'Cannot find module \\'' *\+ *foo *\+ *'\\x27';/;
-
-            let obfuscatedCode: string;
-
-            before(() => {
-                const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-2.js');
-
-                obfuscatedCode = JavaScriptObfuscator.obfuscate(
-                    code,
-                    {
-                        ...NO_ADDITIONAL_NODES_PRESET,
-                        reservedStrings: ['a']
-                    }
-                ).getObfuscatedCode();
-            });
-
-            it('match #1: should ignore reserved strings', () => {
-                assert.match(obfuscatedCode, stringLiteralRegExp);
-            });
-        });
     });
 
-    describe('Variant #16: `forceTransformedStrings` option is enabled', () => {
+    describe('Variant #13: `forceTransformedStrings` option is enabled', () => {
         describe('Variant #1: base `forceTransformedStrings` values', () => {
             describe('Variant #1: single force transformed string value', () => {
                 const stringLiteralRegExp1: RegExp = /const foo *= *'foo';/;
@@ -698,7 +575,7 @@ describe('StringArrayTransformer', function () {
                 let obfuscatedCode: string;
 
                 before(() => {
-                    const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option-1.js');
+                    const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option.js');
 
                     obfuscatedCode = JavaScriptObfuscator.obfuscate(
                         code,
@@ -727,7 +604,7 @@ describe('StringArrayTransformer', function () {
                 let obfuscatedCode: string;
 
                 before(() => {
-                    const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option-1.js');
+                    const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option.js');
 
                     obfuscatedCode = JavaScriptObfuscator.obfuscate(
                         code,
@@ -758,7 +635,7 @@ describe('StringArrayTransformer', function () {
                 let obfuscatedCode: string;
 
                 before(() => {
-                    const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option-1.js');
+                    const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option.js');
 
                     obfuscatedCode = JavaScriptObfuscator.obfuscate(
                         code,
@@ -787,7 +664,7 @@ describe('StringArrayTransformer', function () {
                 let obfuscatedCode: string;
 
                 before(() => {
-                    const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option-1.js');
+                    const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option.js');
 
                     obfuscatedCode = JavaScriptObfuscator.obfuscate(
                         code,
@@ -810,35 +687,7 @@ describe('StringArrayTransformer', function () {
             });
         });
 
-        describe('Variant #3: `unicodeEscapeSequence` option is disabled', () => {
-            const stringLiteralRegExp1: RegExp = /const foo *= *'foo';/;
-            const stringLiteralRegExp2: RegExp = /const bar *= *'bar';/;
-
-            let obfuscatedCode: string;
-
-            before(() => {
-                const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option-1.js');
-
-                obfuscatedCode = JavaScriptObfuscator.obfuscate(
-                    code,
-                    {
-                        ...NO_ADDITIONAL_NODES_PRESET,
-                        forceTransformedStrings: ['bar'],
-                        unicodeEscapeSequence: false
-                    }
-                ).getObfuscatedCode();
-            });
-
-            it('match #1: should not encode force transformed string with unicode escape sequence', () => {
-                assert.match(obfuscatedCode, stringLiteralRegExp1);
-            });
-
-            it('match #2: should not encode force transformed string with unicode escape sequence', () => {
-                assert.match(obfuscatedCode, stringLiteralRegExp2);
-            });
-        });
-
-        describe('Variant #4: `stringArray` option is disabled', () => {
+        describe('Variant #3: `stringArray` option is disabled', () => {
             describe('Variant #1: base case', () => {
                 const stringLiteralRegExp1: RegExp = /const foo *= *'foo';/;
                 const stringLiteralRegExp2: RegExp = /const bar *= *'bar';/;
@@ -846,7 +695,7 @@ describe('StringArrayTransformer', function () {
                 let obfuscatedCode: string;
 
                 before(() => {
-                    const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option-1.js');
+                    const code: string = readFileAsString(__dirname + '/fixtures/force-transformed-strings-option.js');
 
                     obfuscatedCode = JavaScriptObfuscator.obfuscate(
                         code,
@@ -870,7 +719,7 @@ describe('StringArrayTransformer', function () {
         });
     });
 
-    describe('Variant #17: object expression key literal', () => {
+    describe('Variant #14: object expression key literal', () => {
         describe('Variant #1: base key literal', () => {
             const stringArrayRegExp: RegExp = /^var _0x([a-f0-9]){4} *= *\['bar'];/;
             const objectExpressionRegExp: RegExp = /var test *= *{'foo' *: *_0x([a-f0-9]){4}\('0x0'\)};/;
@@ -928,7 +777,7 @@ describe('StringArrayTransformer', function () {
         });
     });
 
-    describe('Variant #18: import declaration source literal', () => {
+    describe('Variant #15: import declaration source literal', () => {
         const importDeclarationRegExp: RegExp = /import *{ *bar *} *from *'foo';/;
 
         let obfuscatedCode: string;
@@ -951,7 +800,7 @@ describe('StringArrayTransformer', function () {
         });
     });
 
-    describe('Variant #19: export all declaration source literal', () => {
+    describe('Variant #16: export all declaration source literal', () => {
         const exportAllDeclarationRegExp: RegExp = /export *\* *from *'foo';/;
 
         let obfuscatedCode: string;
@@ -974,7 +823,7 @@ describe('StringArrayTransformer', function () {
         });
     });
 
-    describe('Variant #20: export named declaration source literal', () => {
+    describe('Variant #17: export named declaration source literal', () => {
         const exportNamedDeclarationRegExp: RegExp = /export *{ *bar *} *from *'foo';/;
 
         let obfuscatedCode: string;

+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/fixtures/export-all-declaration-source.js → test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/export-all-declaration-source.js


+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/fixtures/export-named-declaration-source.js → test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/export-named-declaration-source.js


+ 2 - 0
test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/force-transformed-strings-option.js

@@ -0,0 +1,2 @@
+const foo = 'foo';
+const bar = 'bar';

+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/fixtures/import-declaration-source.js → test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/import-declaration-source.js


+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/fixtures/object-expression-computed-key-literal.js → test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/object-expression-computed-key-literal.js


+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/fixtures/object-expression-key-literal.js → test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/object-expression-key-literal.js


+ 2 - 0
test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/reserved-strings-option.js

@@ -0,0 +1,2 @@
+const foo = 'foo';
+const bar = 'bar';

+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/fixtures/same-literal-values.js → test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/same-literal-values.js


+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/fixtures/short-literal-value.js → test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/short-literal-value.js


+ 1 - 0
test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/simple-input.js

@@ -0,0 +1 @@
+var test = 'test';

+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/fixtures/string-array-calls-wrapper-name.js → test/functional-tests/node-transformers/strings-transformers/string-array-transformer/fixtures/string-array-calls-wrapper-name.js


+ 3 - 2
test/index.spec.ts

@@ -115,8 +115,9 @@ import './functional-tests/node-transformers/simplifying-transformers/block-stat
 import './functional-tests/node-transformers/simplifying-transformers/expression-statements-merge-transformer/ExpressionStatementsMergeTransformer.spec';
 import './functional-tests/node-transformers/simplifying-transformers/if-statement-simplify-transformer/IfStatementSimplifyTransformer.spec';
 import './functional-tests/node-transformers/simplifying-transformers/variable-declarations-merge-transformer/VariableDeclarationsMergeTransformer.spec';
-import './functional-tests/node-transformers/string-array-transformers/string-array-transformer/StringArrayTransformer.spec';
-import './functional-tests/node-transformers/string-array-transformers/string-array-scope-calls-wrapper-transformer/StringArrayScopeCallsWrapperTransformer.spec';
+import './functional-tests/node-transformers/strings-transformers/escape-sequence-transformer/EscapeSequenceTransformer.spec';
+import './functional-tests/node-transformers/strings-transformers/string-array-transformer/StringArrayTransformer.spec';
+import './functional-tests/node-transformers/strings-transformers/string-array-scope-calls-wrapper-transformer/StringArrayScopeCallsWrapperTransformer.spec';
 import './functional-tests/options/OptionsNormalizer.spec';
 import './functional-tests/options/domain-lock/Validation.spec';
 import './functional-tests/storages/string-array-transformers/string-array-storage/StringArrayStorage.spec';

部分文件因为文件数量过多而无法显示