Bläddra i källkod

Use of `eslint-scope` data to rename identifiers #2: refactoring

sanex3339 5 år sedan
förälder
incheckning
102b4cdd58
98 ändrade filer med 695 tillägg och 25699 borttagningar
  1. 0 0
      dist/index.browser.js
  2. 0 12280
      dist/index.cli.js
  3. 0 11687
      dist/index.js
  4. 1 6
      src/JavaScriptObfuscator.ts
  5. 127 0
      src/analyzers/scope-analyzer/ScopeAnalyzer.ts
  6. 1 0
      src/container/ServiceIdentifiers.ts
  7. 7 0
      src/container/modules/analyzers/AnalyzersModule.ts
  8. 3 28
      src/container/modules/node-transformers/ObfuscatingTransformersModule.ts
  9. 0 8
      src/declarations/ESTree.d.ts
  10. 15 0
      src/declarations/eslint-scope.d.ts
  11. 2 7
      src/enums/node-transformers/NodeTransformer.ts
  12. 17 0
      src/interfaces/analyzers/scope-analyzer/IScopeAnalyzer.d.ts
  13. 1 5
      src/node-transformers/dead-code-injection-transformers/DeadCodeInjectionTransformer.ts
  14. 0 131
      src/node-transformers/obfuscating-transformers/CatchClauseTransformer.ts
  15. 0 202
      src/node-transformers/obfuscating-transformers/ClassDeclarationTransformer.ts
  16. 0 203
      src/node-transformers/obfuscating-transformers/FunctionDeclarationTransformer.ts
  17. 0 228
      src/node-transformers/obfuscating-transformers/FunctionTransformer.ts
  18. 0 180
      src/node-transformers/obfuscating-transformers/ImportDeclarationTransformer.ts
  19. 397 0
      src/node-transformers/obfuscating-transformers/ScopeIdentifiersTransformer.ts
  20. 0 351
      src/node-transformers/obfuscating-transformers/VariableDeclarationTransformer.ts
  21. 0 3
      src/node-transformers/obfuscating-transformers/obfuscating-replacers/literal-obfuscating-replacers/StringLiteralObfuscatingReplacer.ts
  22. 0 4
      src/node-transformers/preparing-transformers/MetadataTransformer.ts
  23. 0 57
      src/node/NodeBlockLexicalScopeUtils.ts
  24. 0 63
      src/node/NodeGuards.ts
  25. 0 8
      src/node/NodeMetadata.ts
  26. 6 4
      test/dev/dev.ts
  27. 47 6
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/catch-clause/CatchClause.spec.ts
  28. 5 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/catch-clause/fixtures/global-variable-scope.js
  29. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/catch-clause/fixtures/input.js
  30. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/catch-clause/fixtures/object-pattern-as-parameter.js
  31. 6 6
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/ClassDeclaration.spec.ts
  32. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/fixtures/default-export-inline.js
  33. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/fixtures/default-export.js
  34. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/fixtures/input.js
  35. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/fixtures/named-export.js
  36. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/fixtures/parent-block-scope-is-program-node.js
  37. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/fixtures/prevent-renaming-of-renamed-identifiers.js
  38. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/fixtures/rename-globals-identifier-transformation.js
  39. 6 6
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/FunctionDeclaration.spec.ts
  40. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/fixtures/async-function.js
  41. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/fixtures/default-export-inline.js
  42. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/fixtures/default-export.js
  43. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/fixtures/generator-function.js
  44. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/fixtures/input.js
  45. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/fixtures/named-export.js
  46. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/fixtures/parent-block-scope-is-program-node.js
  47. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/fixtures/prevent-renaming-of-renamed-identifiers-1.js
  48. 25 5
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/Function.spec.ts
  49. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/array-pattern-as-parameter.js
  50. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/array-rest-parameter.js
  51. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/arrow-function-with-expression-body-block-scope-detection-1.js
  52. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/arrow-function-with-expression-body-block-scope-detection-2.js
  53. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/assignment-pattern-as-parameter-1.js
  54. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/assignment-pattern-as-parameter-2.js
  55. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/assignment-pattern-as-parameter-3.js
  56. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/function-id-name-1.js
  57. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/function-id-name-2.js
  58. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/function-id-name-3.js
  59. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/identifier-names-set-object-pattern.js
  60. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/input.js
  61. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/object-pattern-as-parameter-1.js
  62. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/object-pattern-as-parameter-2.js
  63. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/object-pattern-as-parameter-3.js
  64. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/object-pattern-as-parameter-4.js
  65. 3 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/object-pattern-as-parameter-5.js
  66. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/object-rest-parameter.js
  67. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/rest-parameter.js
  68. 5 5
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/import-declaration/ImportDeclaration.spec.ts
  69. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/import-declaration/fixtures/default-import.js
  70. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/import-declaration/fixtures/named-import-1.js
  71. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/import-declaration/fixtures/named-import-2.js
  72. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/import-declaration/fixtures/namespace-import.js
  73. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/import-declaration/fixtures/no-invalid-mark-as-renamed-identifier.js
  74. 6 6
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/VariableDeclaration.spec.ts
  75. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/array-pattern.js
  76. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/array-rest.js
  77. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/computed-object-expression-identifier.js
  78. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/default-export.js
  79. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/destructing-assignment-without-declaration-1.js
  80. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/destructing-assignment-without-declaration-2.js
  81. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/let-kind.js
  82. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/member-expression-identifier.js
  83. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/method-definition-identifier.js
  84. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/named-export.js
  85. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/object-pattern.js
  86. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/object-rest.js
  87. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/parent-block-scope-is-program-node.js
  88. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/prevent-renaming-of-renamed-identifiers-1.js
  89. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/prevent-renaming-of-renamed-identifiers-2.js
  90. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/property-identifier.js
  91. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/simple-declaration.js
  92. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/var-kind.js
  93. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/variable-call-before-variable-declaration-1.js
  94. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/variable-call-before-variable-declaration-2.js
  95. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/variable-call-before-variable-declaration-3.js
  96. 6 6
      test/index.spec.ts
  97. 0 177
      test/unit-tests/node/node-guards/NodeGuards.spec.ts
  98. 9 27
      test/unit-tests/node/node-metadata/NodeMetadata.spec.ts

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
dist/index.browser.js


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 12280
dist/index.cli.js


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 11687
dist/index.js


+ 1 - 6
src/JavaScriptObfuscator.ts

@@ -50,16 +50,11 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
      */
     private static readonly transformersList: NodeTransformer[] = [
         NodeTransformer.BlockStatementControlFlowTransformer,
-        //NodeTransformer.ClassDeclarationTransformer,
         NodeTransformer.CommentsTransformer,
         NodeTransformer.CustomNodesTransformer,
         NodeTransformer.DeadCodeInjectionTransformer,
         NodeTransformer.EvalCallExpressionTransformer,
         NodeTransformer.FunctionControlFlowTransformer,
-        //NodeTransformer.CatchClauseTransformer,
-        //NodeTransformer.FunctionDeclarationTransformer,
-        //NodeTransformer.FunctionTransformer,
-        //NodeTransformer.ImportDeclarationTransformer,
         NodeTransformer.LabeledStatementTransformer,
         NodeTransformer.LiteralTransformer,
         NodeTransformer.MemberExpressionTransformer,
@@ -69,9 +64,9 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
         NodeTransformer.ObjectExpressionKeysTransformer,
         NodeTransformer.ObjectExpressionTransformer,
         NodeTransformer.ParentificationTransformer,
+        NodeTransformer.ScopeIdentifiersTransformer,
         NodeTransformer.SplitStringTransformer,
         NodeTransformer.TemplateLiteralTransformer,
-        NodeTransformer.VariableDeclarationTransformer,
         NodeTransformer.VariablePreserveTransformer
     ];
 

+ 127 - 0
src/analyzers/scope-analyzer/ScopeAnalyzer.ts

@@ -0,0 +1,127 @@
+import { inject, injectable, } from 'inversify';
+import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
+
+import * as eslintScope from 'eslint-scope';
+import * as estraverse from 'estraverse';
+import * as ESTree from 'estree';
+
+import { IOptions } from '../../interfaces/options/IOptions';
+import { IScopeAnalyzer } from '../../interfaces/analyzers/scope-analyzer/IScopeAnalyzer';
+
+import { ObfuscationTarget } from '../../enums/ObfuscationTarget';
+
+import { NodeGuards } from '../../node/NodeGuards';
+
+@injectable()
+export class ScopeAnalyzer implements IScopeAnalyzer {
+    /**
+     * @type {eslintScope.AnalysisOptions}
+     */
+    private static readonly eslintScopeOptions: eslintScope.AnalysisOptions = {
+        ecmaVersion: 10,
+        optimistic: true
+    };
+
+    /**
+     * @type {acorn.Options['sourceType'][]}
+     */
+    private static readonly sourceTypes: acorn.Options['sourceType'][] = [
+        'script',
+        'module'
+    ];
+
+    /**
+     * @type {IOptions}
+     */
+    private readonly options: IOptions;
+
+    /**
+     * @type {eslintScope.ScopeManager | null}
+     */
+    private scopeManager: eslintScope.ScopeManager | null = null;
+
+    /**
+     * @param {IOptions} options
+     */
+    constructor (
+        @inject(ServiceIdentifiers.IOptions) options: IOptions
+    ) {
+        this.options = options;
+    }
+
+    /**
+     * `eslint-scope` reads `ranges` property of a nodes
+     * Should attach that property to the some custom nodes
+     *
+     * @param {Node} astTree
+     */
+    private static attachMissingRanges (astTree: ESTree.Node): void {
+        estraverse.replace(astTree, {
+            enter: (node: ESTree.Node): ESTree.Node => {
+                if (!node.range) {
+                    node.range = [0, 0];
+                }
+
+                return node;
+            }
+        });
+    }
+
+    /**
+     * @param {Node} node
+     * @returns {boolean}
+     */
+    private static isRootNode (node: ESTree.Node): boolean {
+        return NodeGuards.isProgramNode(node) || node.parentNode === node;
+    }
+
+    /**
+     * @param {Program} astTree
+     */
+    public analyze (astTree: ESTree.Program): void {
+        const sourceTypeLength: number = ScopeAnalyzer.sourceTypes.length;
+
+        ScopeAnalyzer.attachMissingRanges(astTree);
+
+        for (let i: number = 0; i < sourceTypeLength; i++) {
+            try {
+                this.scopeManager = eslintScope.analyze(astTree, {
+                    ...ScopeAnalyzer.eslintScopeOptions,
+                    nodejsScope: this.options.target === ObfuscationTarget.Node,
+                    sourceType: ScopeAnalyzer.sourceTypes[i]
+                });
+
+                return;
+            } catch (error) {
+                if (i < sourceTypeLength - 1) {
+                    continue;
+                }
+
+                throw new Error(error);
+            }
+        }
+
+        throw new Error(`Scope analyzing error`);
+    }
+
+    /**
+     * @param {Node} node
+     * @returns {Scope}
+     */
+    public acquireScope (node: ESTree.Node): eslintScope.Scope {
+        if (!this.scopeManager) {
+            throw new Error('Scope manager is not defined');
+        }
+
+        const scope: eslintScope.Scope | null = this.scopeManager.acquire(
+            node,
+            ScopeAnalyzer.isRootNode(node)
+        );
+
+        if (!scope) {
+            throw new Error('Cannot acquire scope for node');
+        }
+
+        return scope;
+    }
+}

+ 1 - 0
src/container/ServiceIdentifiers.ts

@@ -41,6 +41,7 @@ export enum ServiceIdentifiers {
     IRandomGenerator = 'IRandomGenerator',
     ISourceCode = 'ISourceCode',
     ISourceMapCorrector = 'ISourceMapCorrector',
+    IScopeAnalyzer = 'IScopeAnalyzer',
     IStringArrayStorageAnalyzer = 'IStringArrayStorageAnalyzer',
     ITransformersRunner = 'ITransformersRunner',
     Newable__ICustomNode = 'Newable<ICustomNode>',

+ 7 - 0
src/container/modules/analyzers/AnalyzersModule.ts

@@ -5,6 +5,7 @@ import { ServiceIdentifiers } from '../../ServiceIdentifiers';
 import { ICalleeDataExtractor } from '../../../interfaces/analyzers/calls-graph-analyzer/ICalleeDataExtractor';
 import { ICallsGraphAnalyzer } from '../../../interfaces/analyzers/calls-graph-analyzer/ICallsGraphAnalyzer';
 import { IPrevailingKindOfVariablesAnalyzer } from '../../../interfaces/analyzers/calls-graph-analyzer/IPrevailingKindOfVariablesAnalyzer';
+import { IScopeAnalyzer } from '../../../interfaces/analyzers/scope-analyzer/IScopeAnalyzer';
 import { IStringArrayStorageAnalyzer } from '../../../interfaces/analyzers/string-array-storage-analyzer/IStringArrayStorageAnalyzer';
 
 import { CalleeDataExtractor } from '../../../enums/analyzers/calls-graph-analyzer/CalleeDataExtractor';
@@ -13,6 +14,7 @@ import { FunctionDeclarationCalleeDataExtractor } from '../../../analyzers/calls
 import { FunctionExpressionCalleeDataExtractor } from '../../../analyzers/calls-graph-analyzer/callee-data-extractors/FunctionExpressionCalleeDataExtractor';
 import { ObjectExpressionCalleeDataExtractor } from '../../../analyzers/calls-graph-analyzer/callee-data-extractors/ObjectExpressionCalleeDataExtractor';
 import { PrevailingKindOfVariablesAnalyzer } from '../../../analyzers/prevailing-kind-of-variables-analyzer/PrevailingKindOfVariablesAnalyzer';
+import { ScopeAnalyzer } from '../../../analyzers/scope-analyzer/ScopeAnalyzer';
 import { StringArrayStorageAnalyzer } from '../../../analyzers/string-array-storage-analyzer/StringArrayStorageAnalyzer';
 
 export const analyzersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
@@ -26,6 +28,11 @@ export const analyzersModule: interfaces.ContainerModule = new ContainerModule((
         .to(PrevailingKindOfVariablesAnalyzer)
         .inSingletonScope();
 
+    // scope analyzer
+    bind<IScopeAnalyzer>(ServiceIdentifiers.IScopeAnalyzer)
+        .to(ScopeAnalyzer)
+        .inSingletonScope();
+
     // string array storage analyzer
     bind<IStringArrayStorageAnalyzer>(ServiceIdentifiers.IStringArrayStorageAnalyzer)
         .to(StringArrayStorageAnalyzer)

+ 3 - 28
src/container/modules/node-transformers/ObfuscatingTransformersModule.ts

@@ -12,39 +12,14 @@ import { NodeTransformer } from '../../../enums/node-transformers/NodeTransforme
 
 import { BaseIdentifierObfuscatingReplacer } from '../../../node-transformers/obfuscating-transformers/obfuscating-replacers/identifier-obfuscating-replacers/BaseIdentifierObfuscatingReplacer';
 import { BooleanLiteralObfuscatingReplacer } from '../../../node-transformers/obfuscating-transformers/obfuscating-replacers/literal-obfuscating-replacers/BooleanLiteralObfuscatingReplacer';
-import { CatchClauseTransformer } from '../../../node-transformers/obfuscating-transformers/CatchClauseTransformer';
-import { ClassDeclarationTransformer } from '../../../node-transformers/obfuscating-transformers/ClassDeclarationTransformer';
-import { FunctionDeclarationTransformer } from '../../../node-transformers/obfuscating-transformers/FunctionDeclarationTransformer';
-import { FunctionTransformer } from '../../../node-transformers/obfuscating-transformers/FunctionTransformer';
-import { ImportDeclarationTransformer } from '../../../node-transformers/obfuscating-transformers/ImportDeclarationTransformer';
 import { LabeledStatementTransformer } from '../../../node-transformers/obfuscating-transformers/LabeledStatementTransformer';
 import { LiteralTransformer } from '../../../node-transformers/obfuscating-transformers/LiteralTransformer';
 import { NumberLiteralObfuscatingReplacer } from '../../../node-transformers/obfuscating-transformers/obfuscating-replacers/literal-obfuscating-replacers/NumberLiteralObfuscatingReplacer';
 import { StringLiteralObfuscatingReplacer } from '../../../node-transformers/obfuscating-transformers/obfuscating-replacers/literal-obfuscating-replacers/StringLiteralObfuscatingReplacer';
-import { VariableDeclarationTransformer } from '../../../node-transformers/obfuscating-transformers/VariableDeclarationTransformer';
+import { ScopeIdentifiersTransformer } from '../../../node-transformers/obfuscating-transformers/ScopeIdentifiersTransformer';
 
 export const obfuscatingTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
     // obfuscating transformers
-    bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
-        .to(CatchClauseTransformer)
-        .whenTargetNamed(NodeTransformer.CatchClauseTransformer);
-
-    bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
-        .to(ClassDeclarationTransformer)
-        .whenTargetNamed(NodeTransformer.ClassDeclarationTransformer);
-
-    bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
-        .to(FunctionDeclarationTransformer)
-        .whenTargetNamed(NodeTransformer.FunctionDeclarationTransformer);
-
-    bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
-        .to(FunctionTransformer)
-        .whenTargetNamed(NodeTransformer.FunctionTransformer);
-
-    bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
-        .to(ImportDeclarationTransformer)
-        .whenTargetNamed(NodeTransformer.ImportDeclarationTransformer);
-
     bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
         .to(LabeledStatementTransformer)
         .whenTargetNamed(NodeTransformer.LabeledStatementTransformer);
@@ -54,8 +29,8 @@ export const obfuscatingTransformersModule: interfaces.ContainerModule = new Con
         .whenTargetNamed(NodeTransformer.LiteralTransformer);
 
     bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
-        .to(VariableDeclarationTransformer)
-        .whenTargetNamed(NodeTransformer.VariableDeclarationTransformer);
+        .to(ScopeIdentifiersTransformer)
+        .whenTargetNamed(NodeTransformer.ScopeIdentifiersTransformer);
 
     // literal obfuscating replacers
     bind<IObfuscatingReplacer>(ServiceIdentifiers.IObfuscatingReplacer)

+ 0 - 8
src/declarations/ESTree.d.ts

@@ -15,10 +15,6 @@ declare module 'estree' {
         loc?: acorn.SourceLocation;
     }
 
-    export interface IdentifierNodeMetadata extends BaseNodeMetadata {
-        renamedIdentifier?: boolean;
-    }
-
     export interface LiteralNodeMetadata extends BaseNodeMetadata {
         replacedLiteral?: boolean;
     }
@@ -28,10 +24,6 @@ declare module 'estree' {
         parentNode?: Node;
     }
 
-    interface Identifier extends BaseNode {
-        metadata?: IdentifierNodeMetadata;
-    }
-
     interface Program extends BaseNode {
         scope?: eslintScope.Scope | null;
     }

+ 15 - 0
src/declarations/eslint-scope.d.ts

@@ -0,0 +1,15 @@
+/* tslint:disable:interface-name */
+/* tslint:disable:no-empty-interface */
+
+import * as eslint from 'eslint';
+import * as eslintScope from 'eslint-scope';
+
+declare module 'eslint-scope' {
+    interface Variable {
+        scope: Scope;
+    }
+
+    interface Definition {
+        type: eslint.Scope.Definition['type'];
+    }
+}

+ 2 - 7
src/enums/node-transformers/NodeTransformer.ts

@@ -1,15 +1,10 @@
 export enum NodeTransformer {
     BlockStatementControlFlowTransformer = 'BlockStatementControlFlowTransformer',
-    ClassDeclarationTransformer = 'ClassDeclarationTransformer',
     CommentsTransformer = 'CommentsTransformer',
     CustomNodesTransformer = 'CustomNodesTransformer',
     DeadCodeInjectionTransformer = 'DeadCodeInjectionTransformer',
     EvalCallExpressionTransformer = 'EvalCallExpressionTransformer',
     FunctionControlFlowTransformer = 'FunctionControlFlowTransformer',
-    CatchClauseTransformer = 'CatchClauseTransformer',
-    FunctionDeclarationTransformer = 'FunctionDeclarationTransformer',
-    FunctionTransformer = 'FunctionTransformer',
-    ImportDeclarationTransformer = 'ImportDeclarationTransformer',
     LabeledStatementTransformer = 'LabeledStatementTransformer',
     LiteralTransformer = 'LiteralTransformer',
     MemberExpressionTransformer = 'MemberExpressionTransformer',
@@ -19,8 +14,8 @@ export enum NodeTransformer {
     ObjectExpressionKeysTransformer = 'ObjectExpressionKeysTransformer',
     ObjectExpressionTransformer = 'ObjectExpressionTransformer',
     ParentificationTransformer = 'ParentificationTransformer',
+    ScopeIdentifiersTransformer = 'ScopeIdentifiersTransformer',
     SplitStringTransformer = 'SplitStringTransformer',
     TemplateLiteralTransformer = 'TemplateLiteralTransformer',
-    VariableDeclarationTransformer = 'VariableDeclarationTransformer',
-    VariablePreserveTransformer = 'VariablePreserveTransformer',
+    VariablePreserveTransformer = 'VariablePreserveTransformer'
 }

+ 17 - 0
src/interfaces/analyzers/scope-analyzer/IScopeAnalyzer.d.ts

@@ -0,0 +1,17 @@
+import * as eslintScope from 'eslint-scope';
+import * as ESTree from 'estree';
+
+import { IAnalyzer } from '../IAnalyzer';
+
+export interface IScopeAnalyzer extends IAnalyzer<void> {
+    /**
+     * @param {Program} astTree
+     */
+    analyze (astTree: ESTree.Program): void;
+
+    /**
+     * @param {Node} node
+     * @returns {Scope}
+     */
+    acquireScope (node: ESTree.Node): eslintScope.Scope;
+}

+ 1 - 5
src/node-transformers/dead-code-injection-transformers/DeadCodeInjectionTransformer.ts

@@ -47,12 +47,8 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer {
      * @type {NodeTransformer[]}
      */
     private static readonly transformersToRenameBlockScopeIdentifiers: NodeTransformer[] = [
-        NodeTransformer.CatchClauseTransformer,
-        NodeTransformer.ClassDeclarationTransformer,
-        NodeTransformer.FunctionDeclarationTransformer,
-        NodeTransformer.FunctionTransformer,
         NodeTransformer.LabeledStatementTransformer,
-        NodeTransformer.VariableDeclarationTransformer
+        NodeTransformer.ScopeIdentifiersTransformer
     ];
 
     /**

+ 0 - 131
src/node-transformers/obfuscating-transformers/CatchClauseTransformer.ts

@@ -1,131 +0,0 @@
-import { inject, injectable, } from 'inversify';
-import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
-
-import * as estraverse from 'estraverse';
-import * as ESTree from 'estree';
-
-import { TIdentifierObfuscatingReplacerFactory } from '../../types/container/node-transformers/TIdentifierObfuscatingReplacerFactory';
-import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope';
-
-import { IIdentifierObfuscatingReplacer } from '../../interfaces/node-transformers/obfuscating-transformers/obfuscating-replacers/IIdentifierObfuscatingReplacer';
-import { IOptions } from '../../interfaces/options/IOptions';
-import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { IVisitor } from '../../interfaces/node-transformers/IVisitor';
-
-import { IdentifierObfuscatingReplacer } from '../../enums/node-transformers/obfuscating-transformers/obfuscating-replacers/IdentifierObfuscatingReplacer';
-import { TransformationStage } from '../../enums/node-transformers/TransformationStage';
-
-import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
-import { NodeGuards } from '../../node/NodeGuards';
-import { NodeLexicalScopeUtils } from '../../node/NodeLexicalScopeUtils';
-import { NodeMetadata } from '../../node/NodeMetadata';
-
-/**
- * replaces:
- *     try {} catch (e) { console.log(e); };
- *
- * on:
- *     try {} catch (_0x12d45f) { console.log(_0x12d45f); };
- *
- */
-@injectable()
-export class CatchClauseTransformer extends AbstractNodeTransformer {
-    /**
-     * @type {IIdentifierObfuscatingReplacer}
-     */
-    private readonly identifierObfuscatingReplacer: IIdentifierObfuscatingReplacer;
-
-    /**
-     * @param {TIdentifierObfuscatingReplacerFactory} identifierObfuscatingReplacerFactory
-     * @param {IRandomGenerator} randomGenerator
-     * @param {IOptions} options
-     */
-    constructor (
-        @inject(ServiceIdentifiers.Factory__IIdentifierObfuscatingReplacer)
-            identifierObfuscatingReplacerFactory: TIdentifierObfuscatingReplacerFactory,
-        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
-        @inject(ServiceIdentifiers.IOptions) options: IOptions
-    ) {
-        super(randomGenerator, options);
-
-        this.identifierObfuscatingReplacer = identifierObfuscatingReplacerFactory(
-            IdentifierObfuscatingReplacer.BaseIdentifierObfuscatingReplacer
-        );
-    }
-
-    /**
-     * @param {TransformationStage} transformationStage
-     * @returns {IVisitor | null}
-     */
-    public getVisitor (transformationStage: TransformationStage): IVisitor | null {
-        switch (transformationStage) {
-            case TransformationStage.Obfuscating:
-                return {
-                    enter: (node: ESTree.Node, parentNode: ESTree.Node | null) => {
-                        if (parentNode && NodeGuards.isCatchClauseNode(node)) {
-                            return this.transformNode(node, parentNode);
-                        }
-                    }
-                };
-
-            default:
-                return null;
-        }
-    }
-
-    /**
-     * @param {CatchClause} catchClauseNode
-     * @param {NodeGuards} parentNode
-     * @returns {NodeGuards}
-     */
-    public transformNode (catchClauseNode: ESTree.CatchClause, parentNode: ESTree.Node): ESTree.Node {
-        const lexicalScopeNode: TNodeWithLexicalScope | undefined = NodeLexicalScopeUtils.getLexicalScope(catchClauseNode);
-
-        if (!lexicalScopeNode) {
-            return catchClauseNode;
-        }
-
-        this.storeCatchClauseParam(catchClauseNode, lexicalScopeNode);
-        this.replaceCatchClauseParam(catchClauseNode, lexicalScopeNode);
-
-        return catchClauseNode;
-    }
-
-    /**
-     * @param {CatchClause} catchClauseNode
-     * @param {TNodeWithLexicalScope} lexicalScopeNode
-     */
-    private storeCatchClauseParam (
-        catchClauseNode: ESTree.CatchClause,
-        lexicalScopeNode: TNodeWithLexicalScope
-    ): void {
-        if (catchClauseNode.param && NodeGuards.isIdentifierNode(catchClauseNode.param)) {
-            this.identifierObfuscatingReplacer.storeLocalName(catchClauseNode.param, lexicalScopeNode);
-        }
-    }
-
-    /**
-     * @param {CatchClause} catchClauseNode
-     * @param {TNodeWithLexicalScope} lexicalScopeNode
-     */
-    private replaceCatchClauseParam (
-        catchClauseNode: ESTree.CatchClause,
-        lexicalScopeNode: TNodeWithLexicalScope
-    ): void {
-        estraverse.replace(catchClauseNode, {
-            enter: (node: ESTree.Node, parentNode: ESTree.Node | null): void => {
-                if (parentNode && NodeGuards.isReplaceableIdentifierNode(node, parentNode)) {
-                    const newIdentifier: ESTree.Identifier = this.identifierObfuscatingReplacer
-                        .replace(node, lexicalScopeNode);
-                    const newIdentifierName: string = newIdentifier.name;
-
-                    if (node.name !== newIdentifierName) {
-                        node.name = newIdentifierName;
-
-                        NodeMetadata.set(node, { renamedIdentifier: true });
-                    }
-                }
-            }
-        });
-    }
-}

+ 0 - 202
src/node-transformers/obfuscating-transformers/ClassDeclarationTransformer.ts

@@ -1,202 +0,0 @@
-import { inject, injectable, } from 'inversify';
-import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
-
-import * as estraverse from 'estraverse';
-import * as ESTree from 'estree';
-
-import { TIdentifierObfuscatingReplacerFactory } from "../../types/container/node-transformers/TIdentifierObfuscatingReplacerFactory";
-import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope';
-import { TReplaceableIdentifiers } from '../../types/node-transformers/TReplaceableIdentifiers';
-import { TReplaceableIdentifiersNames } from '../../types/node-transformers/TReplaceableIdentifiersNames';
-
-import { IIdentifierObfuscatingReplacer } from '../../interfaces/node-transformers/obfuscating-transformers/obfuscating-replacers/IIdentifierObfuscatingReplacer';
-import { IOptions } from '../../interfaces/options/IOptions';
-import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { IVisitor } from '../../interfaces/node-transformers/IVisitor';
-
-import { IdentifierObfuscatingReplacer } from "../../enums/node-transformers/obfuscating-transformers/obfuscating-replacers/IdentifierObfuscatingReplacer";
-import { NodeType } from '../../enums/node/NodeType';
-import { TransformationStage } from '../../enums/node-transformers/TransformationStage';
-
-import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
-import { NodeGuards } from '../../node/NodeGuards';
-import { NodeLexicalScopeUtils } from '../../node/NodeLexicalScopeUtils';
-import { NodeMetadata } from '../../node/NodeMetadata';
-
-/**
- * replaces:
- *     class Foo { //... };
- *     new Foo();
- *
- * on:
- *     class _0x12d45f { //... };
- *     new _0x12d45f();
- */
-@injectable()
-export class ClassDeclarationTransformer extends AbstractNodeTransformer {
-    /**
-     * @type {IIdentifierObfuscatingReplacer}
-     */
-    private readonly identifierObfuscatingReplacer: IIdentifierObfuscatingReplacer;
-
-    /**
-     * @type {Map<ESTree.Node, ESTree.Identifier[]>}
-     */
-    private readonly replaceableIdentifiers: TReplaceableIdentifiers = new Map();
-
-    /**
-     * @param {TIdentifierObfuscatingReplacerFactory} identifierObfuscatingReplacerFactory
-     * @param {IRandomGenerator} randomGenerator
-     * @param {IOptions} options
-     */
-    constructor (
-        @inject(ServiceIdentifiers.Factory__IIdentifierObfuscatingReplacer)
-            identifierObfuscatingReplacerFactory: TIdentifierObfuscatingReplacerFactory,
-        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
-        @inject(ServiceIdentifiers.IOptions) options: IOptions
-    ) {
-        super(randomGenerator, options);
-
-        this.identifierObfuscatingReplacer = identifierObfuscatingReplacerFactory(
-            IdentifierObfuscatingReplacer.BaseIdentifierObfuscatingReplacer
-        );
-    }
-
-    /**
-     * @param {TransformationStage} transformationStage
-     * @returns {IVisitor | null}
-     */
-    public getVisitor (transformationStage: TransformationStage): IVisitor | null {
-        switch (transformationStage) {
-            case TransformationStage.Obfuscating:
-                return {
-                    enter: (node: ESTree.Node, parentNode: ESTree.Node | null) => {
-                        if (
-                            parentNode
-                            && NodeGuards.isClassDeclarationNode(node)
-                            && !NodeGuards.isExportNamedDeclarationNode(parentNode)
-                        ) {
-                            return this.transformNode(node, parentNode);
-                        }
-                    }
-                };
-
-            default:
-                return null;
-        }
-    }
-
-    /**
-     * @param {ClassDeclaration} classDeclarationNode
-     * @param {NodeGuards} parentNode
-     * @returns {NodeGuards}
-     */
-    public transformNode (
-        classDeclarationNode: ESTree.ClassDeclaration & { id: ESTree.Identifier },
-        parentNode: ESTree.Node
-    ): ESTree.Node {
-        const lexicalScopeNode: TNodeWithLexicalScope | undefined = NodeLexicalScopeUtils.getLexicalScope(classDeclarationNode);
-
-        if (!lexicalScopeNode) {
-            return classDeclarationNode;
-        }
-
-        const isGlobalDeclaration: boolean = lexicalScopeNode.type === NodeType.Program;
-
-        if (!this.options.renameGlobals && isGlobalDeclaration) {
-            return classDeclarationNode;
-        }
-
-        this.storeClassName(classDeclarationNode, lexicalScopeNode, isGlobalDeclaration);
-
-        // check for cached identifiers for current scope node. If exist - loop through them.
-        if (this.replaceableIdentifiers.has(lexicalScopeNode)) {
-            this.replaceScopeCachedIdentifiers(classDeclarationNode, lexicalScopeNode);
-        } else {
-            this.replaceScopeIdentifiers(lexicalScopeNode);
-        }
-
-        return classDeclarationNode;
-    }
-
-    /**
-     * @param {ClassDeclaration} classDeclarationNode
-     * @param {TNodeWithLexicalScope} lexicalScopeNode
-     * @param {boolean} isGlobalDeclaration
-     */
-    private storeClassName (
-        classDeclarationNode: ESTree.ClassDeclaration & { id: ESTree.Identifier },
-        lexicalScopeNode: TNodeWithLexicalScope,
-        isGlobalDeclaration: boolean
-    ): void {
-        if (isGlobalDeclaration) {
-            this.identifierObfuscatingReplacer.storeGlobalName(classDeclarationNode.id, lexicalScopeNode);
-        } else {
-            this.identifierObfuscatingReplacer.storeLocalName(classDeclarationNode.id, lexicalScopeNode);
-        }
-    }
-
-    /**
-     * @param {ClassDeclaration} classDeclarationNode
-     * @param {TNodeWithLexicalScope} lexicalScopeNode
-     */
-    private replaceScopeCachedIdentifiers (
-        classDeclarationNode: ESTree.ClassDeclaration & { id: ESTree.Identifier },
-        lexicalScopeNode: TNodeWithLexicalScope
-    ): void {
-        const cachedReplaceableIdentifiersNamesMap: TReplaceableIdentifiersNames =
-            <TReplaceableIdentifiersNames>this.replaceableIdentifiers.get(lexicalScopeNode);
-
-        const cachedReplaceableIdentifiers: ESTree.Identifier[] | undefined = cachedReplaceableIdentifiersNamesMap
-            .get(classDeclarationNode.id.name);
-
-        if (!cachedReplaceableIdentifiers) {
-            return;
-        }
-
-        const cachedReplaceableIdentifierLength: number = cachedReplaceableIdentifiers.length;
-
-        for (let i: number = 0; i < cachedReplaceableIdentifierLength; i++) {
-            const replaceableIdentifier: ESTree.Identifier = cachedReplaceableIdentifiers[i];
-            const newReplaceableIdentifier: ESTree.Identifier = this.identifierObfuscatingReplacer
-                .replace(replaceableIdentifier, lexicalScopeNode);
-
-            replaceableIdentifier.name = newReplaceableIdentifier.name;
-            NodeMetadata.set(replaceableIdentifier, { renamedIdentifier: true });
-        }
-    }
-
-    /**
-     * @param {TNodeWithLexicalScope} lexicalScopeNode
-     */
-    private replaceScopeIdentifiers (lexicalScopeNode: TNodeWithLexicalScope): void {
-        const storedReplaceableIdentifiersNamesMap: TReplaceableIdentifiersNames = new Map();
-
-        estraverse.replace(lexicalScopeNode, {
-            enter: (node: ESTree.Node, parentNode: ESTree.Node | null): void => {
-                if (
-                    parentNode
-                    && NodeGuards.isReplaceableIdentifierNode(node, parentNode)
-                    && !NodeMetadata.isRenamedIdentifier(node)
-                ) {
-                    const newIdentifier: ESTree.Identifier = this.identifierObfuscatingReplacer
-                        .replace(node, lexicalScopeNode);
-                    const newIdentifierName: string = newIdentifier.name;
-
-                    if (node.name !== newIdentifierName) {
-                        node.name = newIdentifierName;
-                        NodeMetadata.set(node, { renamedIdentifier: true });
-                    } else {
-                        const storedReplaceableIdentifiers: ESTree.Identifier[] =
-                            storedReplaceableIdentifiersNamesMap.get(node.name) || [];
-
-                        storedReplaceableIdentifiers.push(node);
-                        storedReplaceableIdentifiersNamesMap.set(node.name, storedReplaceableIdentifiers);
-                    }
-                }
-            }
-        });
-
-        this.replaceableIdentifiers.set(lexicalScopeNode, storedReplaceableIdentifiersNamesMap);
-    }
-}

+ 0 - 203
src/node-transformers/obfuscating-transformers/FunctionDeclarationTransformer.ts

@@ -1,203 +0,0 @@
-import { inject, injectable, } from 'inversify';
-import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
-
-import * as estraverse from 'estraverse';
-import * as ESTree from 'estree';
-
-import { TIdentifierObfuscatingReplacerFactory } from "../../types/container/node-transformers/TIdentifierObfuscatingReplacerFactory";
-import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope';
-import { TReplaceableIdentifiers } from '../../types/node-transformers/TReplaceableIdentifiers';
-import { TReplaceableIdentifiersNames } from '../../types/node-transformers/TReplaceableIdentifiersNames';
-
-import { IIdentifierObfuscatingReplacer } from '../../interfaces/node-transformers/obfuscating-transformers/obfuscating-replacers/IIdentifierObfuscatingReplacer';
-import { IOptions } from '../../interfaces/options/IOptions';
-import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { IVisitor } from '../../interfaces/node-transformers/IVisitor';
-
-import { IdentifierObfuscatingReplacer } from "../../enums/node-transformers/obfuscating-transformers/obfuscating-replacers/IdentifierObfuscatingReplacer";
-import { NodeType } from '../../enums/node/NodeType';
-import { TransformationStage } from '../../enums/node-transformers/TransformationStage';
-
-import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
-import { NodeGuards } from '../../node/NodeGuards';
-import { NodeLexicalScopeUtils } from '../../node/NodeLexicalScopeUtils';
-import { NodeMetadata } from '../../node/NodeMetadata';
-
-/**
- * replaces:
- *     function foo () { //... };
- *     foo();
- *
- * on:
- *     function _0x12d45f () { //... };
- *     _0x12d45f();
- */
-@injectable()
-export class FunctionDeclarationTransformer extends AbstractNodeTransformer {
-    /**
-     * @type {IIdentifierObfuscatingReplacer}
-     */
-    private readonly identifierObfuscatingReplacer: IIdentifierObfuscatingReplacer;
-
-    /**
-     * @type {Map<ESTree.Node, ESTree.Identifier[]>}
-     */
-    private readonly replaceableIdentifiers: TReplaceableIdentifiers = new Map();
-
-    /**
-     * @param {TIdentifierObfuscatingReplacerFactory} identifierObfuscatingReplacerFactory
-     * @param {IRandomGenerator} randomGenerator
-     * @param {IOptions} options
-     */
-    constructor (
-        @inject(ServiceIdentifiers.Factory__IIdentifierObfuscatingReplacer)
-            identifierObfuscatingReplacerFactory: TIdentifierObfuscatingReplacerFactory,
-        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
-        @inject(ServiceIdentifiers.IOptions) options: IOptions
-    ) {
-        super(randomGenerator, options);
-
-        this.identifierObfuscatingReplacer = identifierObfuscatingReplacerFactory(
-            IdentifierObfuscatingReplacer.BaseIdentifierObfuscatingReplacer
-        );
-    }
-
-    /**
-     * @param {TransformationStage} transformationStage
-     * @returns {IVisitor | null}
-     */
-    public getVisitor (transformationStage: TransformationStage): IVisitor | null {
-        switch (transformationStage) {
-            case TransformationStage.Obfuscating:
-                return {
-                    enter: (node: ESTree.Node, parentNode: ESTree.Node | null) => {
-                        if (
-                            parentNode
-                            && NodeGuards.isFunctionDeclarationNode(node)
-                            && !NodeGuards.isExportNamedDeclarationNode(parentNode)
-                        ) {
-                            return this.transformNode(node, parentNode);
-                        }
-                    }
-                };
-
-            default:
-                return null;
-        }
-    }
-
-    /**
-     * @param {FunctionDeclaration} functionDeclarationNode
-     * @param {NodeGuards} parentNode
-     * @returns {NodeGuards}
-     */
-    public transformNode (
-        functionDeclarationNode: ESTree.FunctionDeclaration & { id: ESTree.Identifier },
-        parentNode: ESTree.Node
-    ): ESTree.Node {
-        const lexicalScopeNode: TNodeWithLexicalScope | undefined = NodeLexicalScopeUtils.getLexicalScope(parentNode);
-
-        if (!lexicalScopeNode) {
-            return functionDeclarationNode;
-        }
-
-        const isGlobalDeclaration: boolean = lexicalScopeNode.type === NodeType.Program;
-
-        if (!this.options.renameGlobals && isGlobalDeclaration) {
-            return functionDeclarationNode;
-        }
-
-        this.storeFunctionName(functionDeclarationNode, lexicalScopeNode, isGlobalDeclaration);
-
-        // check for cached identifiers for current scope node. If exist - loop through them.
-        if (this.replaceableIdentifiers.has(lexicalScopeNode)) {
-            this.replaceScopeCachedIdentifiers(functionDeclarationNode, lexicalScopeNode);
-        } else {
-            this.replaceScopeIdentifiers(lexicalScopeNode);
-        }
-
-        return functionDeclarationNode;
-    }
-
-    /**
-     * @param {FunctionDeclaration} functionDeclarationNode
-     * @param {TNodeWithLexicalScope} lexicalScopeNode
-     * @param {boolean} isGlobalDeclaration
-     */
-    private storeFunctionName (
-        functionDeclarationNode: ESTree.FunctionDeclaration & { id: ESTree.Identifier },
-        lexicalScopeNode: TNodeWithLexicalScope,
-        isGlobalDeclaration: boolean
-    ): void {
-        if (isGlobalDeclaration) {
-            this.identifierObfuscatingReplacer.storeGlobalName(functionDeclarationNode.id, lexicalScopeNode);
-        } else {
-            this.identifierObfuscatingReplacer.storeLocalName(functionDeclarationNode.id, lexicalScopeNode);
-        }
-    }
-
-    /**
-     * @param {FunctionDeclaration} functionDeclarationNode
-     * @param {TNodeWithLexicalScope} lexicalScopeNode
-     */
-    private replaceScopeCachedIdentifiers (
-        functionDeclarationNode: ESTree.FunctionDeclaration & { id: ESTree.Identifier },
-        lexicalScopeNode: TNodeWithLexicalScope
-    ): void {
-        const cachedReplaceableIdentifiersNamesMap: TReplaceableIdentifiersNames =
-            <TReplaceableIdentifiersNames>this.replaceableIdentifiers.get(lexicalScopeNode);
-
-        const cachedReplaceableIdentifiers: ESTree.Identifier[] | undefined = cachedReplaceableIdentifiersNamesMap
-            .get(functionDeclarationNode.id.name);
-
-        if (!cachedReplaceableIdentifiers) {
-            return;
-        }
-
-        const cachedReplaceableIdentifierLength: number = cachedReplaceableIdentifiers.length;
-
-        for (let i: number = 0; i < cachedReplaceableIdentifierLength; i++) {
-            const replaceableIdentifier: ESTree.Identifier = cachedReplaceableIdentifiers[i];
-            const newReplaceableIdentifier: ESTree.Identifier = this.identifierObfuscatingReplacer
-                .replace(replaceableIdentifier, lexicalScopeNode);
-
-            replaceableIdentifier.name = newReplaceableIdentifier.name;
-            NodeMetadata.set(replaceableIdentifier, { renamedIdentifier: true });
-        }
-    }
-
-    /**
-     * @param {TNodeWithLexicalScope} lexicalScopeNode
-     */
-    private replaceScopeIdentifiers (lexicalScopeNode: TNodeWithLexicalScope): void {
-        const storedReplaceableIdentifiersNamesMap: TReplaceableIdentifiersNames = new Map();
-
-        estraverse.replace(lexicalScopeNode, {
-            enter: (node: ESTree.Node, parentNode: ESTree.Node | null): void => {
-                if (
-                    parentNode
-                    && (parentNode !== lexicalScopeNode)
-                    && NodeGuards.isReplaceableIdentifierNode(node, parentNode)
-                    && !NodeMetadata.isRenamedIdentifier(node)
-                ) {
-                    const newIdentifier: ESTree.Identifier = this.identifierObfuscatingReplacer
-                        .replace(node, lexicalScopeNode);
-                    const newIdentifierName: string = newIdentifier.name;
-
-                    if (node.name !== newIdentifierName) {
-                        node.name = newIdentifierName;
-                        NodeMetadata.set(node, { renamedIdentifier: true });
-                    } else {
-                        const storedReplaceableIdentifiers: ESTree.Identifier[] =
-                            storedReplaceableIdentifiersNamesMap.get(node.name) || [];
-
-                        storedReplaceableIdentifiers.push(node);
-                        storedReplaceableIdentifiersNamesMap.set(node.name, storedReplaceableIdentifiers);
-                    }
-                }
-            }
-        });
-
-        this.replaceableIdentifiers.set(lexicalScopeNode, storedReplaceableIdentifiersNamesMap);
-    }
-}

+ 0 - 228
src/node-transformers/obfuscating-transformers/FunctionTransformer.ts

@@ -1,228 +0,0 @@
-import { inject, injectable, } from 'inversify';
-import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
-
-import * as estraverse from 'estraverse';
-import * as ESTree from 'estree';
-
-import { TIdentifierObfuscatingReplacerFactory } from '../../types/container/node-transformers/TIdentifierObfuscatingReplacerFactory';
-import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope';
-
-import { IIdentifierObfuscatingReplacer } from '../../interfaces/node-transformers/obfuscating-transformers/obfuscating-replacers/IIdentifierObfuscatingReplacer';
-import { IOptions } from '../../interfaces/options/IOptions';
-import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { IVisitor } from '../../interfaces/node-transformers/IVisitor';
-
-import { IdentifierObfuscatingReplacer } from '../../enums/node-transformers/obfuscating-transformers/obfuscating-replacers/IdentifierObfuscatingReplacer';
-import { TransformationStage } from '../../enums/node-transformers/TransformationStage';
-
-import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
-import { NodeGuards } from '../../node/NodeGuards';
-import { NodeLexicalScopeUtils } from '../../node/NodeLexicalScopeUtils';
-import { NodeMetadata } from '../../node/NodeMetadata';
-import { NodeType } from '../../enums/node/NodeType';
-
-/**
- * replaces:
- *     function foo (argument1) { return argument1; };
- *
- * on:
- *     function foo (_0x12d45f) { return _0x12d45f; };
- *
- */
-@injectable()
-export class FunctionTransformer extends AbstractNodeTransformer {
-    /**
-     * @type {IIdentifierObfuscatingReplacer}
-     */
-    private readonly identifierObfuscatingReplacer: IIdentifierObfuscatingReplacer;
-
-    /**
-     * @param {TIdentifierObfuscatingReplacerFactory} identifierObfuscatingReplacerFactory
-     * @param {IRandomGenerator} randomGenerator
-     * @param {IOptions} options
-     */
-    constructor (
-        @inject(ServiceIdentifiers.Factory__IIdentifierObfuscatingReplacer)
-            identifierObfuscatingReplacerFactory: TIdentifierObfuscatingReplacerFactory,
-        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
-        @inject(ServiceIdentifiers.IOptions) options: IOptions
-    ) {
-        super(randomGenerator, options);
-
-        this.identifierObfuscatingReplacer = identifierObfuscatingReplacerFactory(
-            IdentifierObfuscatingReplacer.BaseIdentifierObfuscatingReplacer
-        );
-    }
-
-    /**
-     * @param {Node} node
-     * @param {Node} parentNode
-     * @returns {boolean}
-     */
-    private static isProhibitedIdentifierOfPropertyNode (
-        node: ESTree.Node,
-        parentNode: ESTree.Node | null
-    ): node is ESTree.Identifier {
-        return NodeGuards.isIdentifierNode(node)
-            && !!parentNode
-            && NodeGuards.isPropertyNode(parentNode)
-            && parentNode.key === node;
-    }
-
-    /**
-     * @param {Node} node
-     * @returns {boolean}
-     */
-    private static isProhibitedIdentifierOfShorthandPropertyNode (
-        node: ESTree.Node,
-    ): node is ESTree.Property & {key: ESTree.Identifier} {
-        return NodeGuards.isPropertyNode(node)
-            && node.shorthand
-            && NodeGuards.isIdentifierNode(node.key);
-    }
-
-    /**
-     * @param {TransformationStage} transformationStage
-     * @returns {IVisitor | null}
-     */
-    public getVisitor (transformationStage: TransformationStage): IVisitor | null {
-        switch (transformationStage) {
-            case TransformationStage.Obfuscating:
-                return {
-                    enter: (node: ESTree.Node, parentNode: ESTree.Node | null) => {
-                        if (parentNode && NodeGuards.isFunctionNode(node)) {
-                            return this.transformNode(node, parentNode);
-                        }
-                    }
-                };
-
-            default:
-                return null;
-        }
-    }
-
-    /**
-     * @param {Function} functionNode
-     * @param {NodeGuards} parentNode
-     * @returns {NodeGuards}
-     */
-    public transformNode (functionNode: ESTree.Function, parentNode: ESTree.Node): ESTree.Node {
-        const lexicalScopeNode: TNodeWithLexicalScope | undefined = NodeLexicalScopeUtils.getLexicalScope(functionNode);
-
-        if (!lexicalScopeNode) {
-            return functionNode;
-        }
-
-        this.storeFunctionParams(functionNode, lexicalScopeNode);
-        this.replaceFunctionParams(functionNode, lexicalScopeNode);
-
-        return functionNode;
-    }
-
-    /**
-     * @param {Identifier} node
-     * @param {Node} parentNode
-     * @returns {boolean}
-     */
-    private isGlobalFunctionDeclarationIdentifier (node: ESTree.Identifier, parentNode: ESTree.Node): boolean {
-        if (!NodeGuards.isFunctionDeclarationNode(parentNode) || parentNode.id !== node) {
-            return false;
-        }
-
-        const lexicalScopeNode: TNodeWithLexicalScope | undefined = NodeLexicalScopeUtils.getLexicalScopes(parentNode)[1];
-
-        if (!lexicalScopeNode) {
-            return false;
-        }
-
-        const isGlobalDeclaration: boolean = lexicalScopeNode.type === NodeType.Program;
-
-        return !this.options.renameGlobals && isGlobalDeclaration;
-    }
-
-    /**
-     * @param {Function} functionNode
-     * @param {TNodeWithLexicalScope} lexicalScopeNode
-     */
-    private storeFunctionParams (functionNode: ESTree.Function, lexicalScopeNode: TNodeWithLexicalScope): void {
-        const visitor: estraverse.Visitor = {
-            enter: (node: ESTree.Node, parentNode: ESTree.Node | null): estraverse.VisitorOption | void => {
-                // should check with identifier as first argument,
-                // because prohibited identifier can be easily ignored
-                if (FunctionTransformer.isProhibitedIdentifierOfPropertyNode(node, parentNode)) {
-                    return;
-                }
-
-                if (NodeGuards.isAssignmentPatternNode(node) && NodeGuards.isIdentifierNode(node.left)) {
-                    this.identifierObfuscatingReplacer.storeLocalName(node.left, lexicalScopeNode);
-
-                    return estraverse.VisitorOption.Skip;
-                }
-
-                if (NodeGuards.isIdentifierNode(node)) {
-                    this.identifierObfuscatingReplacer.storeLocalName(node, lexicalScopeNode);
-                }
-            }
-        };
-
-        functionNode.params.forEach((paramsNode: ESTree.Node) => {
-            estraverse.traverse(paramsNode, visitor);
-        });
-    }
-
-    /**
-     * @param {Function} functionNode
-     * @param {TNodeWithLexicalScope} lexicalScopeNode
-     * @param {Set<string>} ignoredIdentifierNamesSet
-     */
-    private replaceFunctionParams (
-        functionNode: ESTree.Function,
-        lexicalScopeNode: TNodeWithLexicalScope,
-        ignoredIdentifierNamesSet: Set <string> = new Set()
-    ): void {
-        const visitor: estraverse.Visitor = {
-            enter: (node: ESTree.Node, parentNode: ESTree.Node | null): void | estraverse.VisitorOption => {
-                /**
-                 * should process nested functions in different traverse loop to avoid wrong code generation
-                 */
-                if (NodeGuards.isFunctionNode(node) && node !== functionNode) {
-                    this.replaceFunctionParams(node, lexicalScopeNode, new Set(ignoredIdentifierNamesSet));
-
-                    return estraverse.VisitorOption.Skip;
-                }
-
-                /**
-                 * should ignore all shorthand `key` identifiers of the `PropertyNode`
-                 */
-                if (FunctionTransformer.isProhibitedIdentifierOfShorthandPropertyNode(node)) {
-                    ignoredIdentifierNamesSet.add(node.key.name);
-
-                    return;
-                }
-
-                if (
-                    parentNode
-                    && NodeGuards.isReplaceableIdentifierNode(node, parentNode)
-                    && !NodeMetadata.isRenamedIdentifier(node)
-                    && !ignoredIdentifierNamesSet.has(node.name)
-                ) {
-                    // should ignore identifiers of global function declarations
-                    if (this.isGlobalFunctionDeclarationIdentifier(node, parentNode)) {
-                        return;
-                    }
-
-                    const newIdentifier: ESTree.Identifier = this.identifierObfuscatingReplacer
-                        .replace(node, lexicalScopeNode);
-                    const newIdentifierName: string = newIdentifier.name;
-
-                    if (node.name !== newIdentifierName) {
-                        node.name = newIdentifierName;
-                        NodeMetadata.set(node, { renamedIdentifier: true });
-                    }
-                }
-            }
-        };
-
-        estraverse.replace(functionNode, visitor);
-    }
-}

+ 0 - 180
src/node-transformers/obfuscating-transformers/ImportDeclarationTransformer.ts

@@ -1,180 +0,0 @@
-import { inject, injectable, } from 'inversify';
-import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
-
-import * as estraverse from 'estraverse';
-import * as ESTree from 'estree';
-
-import { TIdentifierObfuscatingReplacerFactory } from "../../types/container/node-transformers/TIdentifierObfuscatingReplacerFactory";
-import { TImportSpecifier } from '../../types/node/TimportSpecifier';
-import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope';
-
-import { IIdentifierObfuscatingReplacer } from '../../interfaces/node-transformers/obfuscating-transformers/obfuscating-replacers/IIdentifierObfuscatingReplacer';
-import { IOptions } from '../../interfaces/options/IOptions';
-import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { IVisitor } from '../../interfaces/node-transformers/IVisitor';
-
-import { IdentifierObfuscatingReplacer } from "../../enums/node-transformers/obfuscating-transformers/obfuscating-replacers/IdentifierObfuscatingReplacer";
-import { TransformationStage } from '../../enums/node-transformers/TransformationStage';
-
-import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
-import { NodeGuards } from '../../node/NodeGuards';
-import { NodeLexicalScopeUtils } from '../../node/NodeLexicalScopeUtils';
-import { NodeMetadata } from '../../node/NodeMetadata';
-
-/**
- * replaces:
- *     import foo from './foo';
- *     import * as bar from './bar';
- *
- * on:
- *     import _0x12d45f from './foo';
- *     import * as _0x12d45f from './bar';
- */
-@injectable()
-export class ImportDeclarationTransformer extends AbstractNodeTransformer {
-    /**
-     * @type {IIdentifierObfuscatingReplacer}
-     */
-    private readonly identifierObfuscatingReplacer: IIdentifierObfuscatingReplacer;
-
-    /**
-     * @type {Map<ESTree.Node, ESTree.Identifier[]>}
-     */
-    private readonly replaceableIdentifiers: Map <ESTree.Node, ESTree.Identifier[]> = new Map();
-
-    /**
-     * @param {TIdentifierObfuscatingReplacerFactory} identifierObfuscatingReplacerFactory
-     * @param {IRandomGenerator} randomGenerator
-     * @param {IOptions} options
-     */
-    constructor (
-        @inject(ServiceIdentifiers.Factory__IIdentifierObfuscatingReplacer)
-            identifierObfuscatingReplacerFactory: TIdentifierObfuscatingReplacerFactory,
-        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
-        @inject(ServiceIdentifiers.IOptions) options: IOptions
-    ) {
-        super(randomGenerator, options);
-
-        this.identifierObfuscatingReplacer = identifierObfuscatingReplacerFactory(
-            IdentifierObfuscatingReplacer.BaseIdentifierObfuscatingReplacer
-        );
-    }
-
-    /**
-     * @param {TImportSpecifier} importSpecifierNode
-     * @returns {boolean}
-     */
-    private static isProhibitedImportSpecifierNode (importSpecifierNode: TImportSpecifier): boolean {
-        return NodeGuards.isImportSpecifierNode(importSpecifierNode)
-            && importSpecifierNode.imported.name === importSpecifierNode.local.name;
-    }
-
-    /**
-     * @param {TransformationStage} transformationStage
-     * @returns {IVisitor | null}
-     */
-    public getVisitor (transformationStage: TransformationStage): IVisitor | null {
-        switch (transformationStage) {
-            case TransformationStage.Obfuscating:
-                return {
-                    enter: (node: ESTree.Node, parentNode: ESTree.Node | null) => {
-                        if (parentNode && NodeGuards.isImportDeclarationNode(node)) {
-                            return this.transformNode(node, parentNode);
-                        }
-                    }
-                };
-
-            default:
-                return null;
-        }
-    }
-
-    /**
-     * @param {ImportDeclaration} importDeclarationNode
-     * @param {Node} parentNode
-     * @returns {Node}
-     */
-    public transformNode (importDeclarationNode: ESTree.ImportDeclaration, parentNode: ESTree.Node): ESTree.Node {
-        const lexicalScopeNode: TNodeWithLexicalScope | undefined = NodeLexicalScopeUtils.getLexicalScope(importDeclarationNode);
-
-        if (!lexicalScopeNode) {
-            return importDeclarationNode;
-        }
-
-        this.storeImportSpecifierNames(importDeclarationNode, lexicalScopeNode);
-
-        // check for cached identifiers for current scope node. If exist - loop through them.
-        if (this.replaceableIdentifiers.has(lexicalScopeNode)) {
-            this.replaceScopeCachedIdentifiers(lexicalScopeNode);
-        } else {
-            this.replaceScopeIdentifiers(lexicalScopeNode);
-        }
-
-        return importDeclarationNode;
-    }
-
-    /**
-     * @param {ImportDeclaration} importDeclarationNode
-     * @param {TNodeWithLexicalScope} lexicalScopeNode
-     */
-    private storeImportSpecifierNames (
-        importDeclarationNode: ESTree.ImportDeclaration,
-        lexicalScopeNode: TNodeWithLexicalScope
-    ): void {
-        importDeclarationNode.specifiers.forEach((importSpecifierNode: TImportSpecifier) => {
-            if (ImportDeclarationTransformer.isProhibitedImportSpecifierNode(importSpecifierNode)) {
-                return;
-            }
-
-            this.identifierObfuscatingReplacer.storeGlobalName(importSpecifierNode.local, lexicalScopeNode);
-        });
-    }
-
-    /**
-     * @param {TNodeWithLexicalScope} lexicalScopeNode
-     */
-    private replaceScopeCachedIdentifiers (lexicalScopeNode: TNodeWithLexicalScope): void {
-        const cachedReplaceableIdentifiers: ESTree.Identifier[] =
-            <ESTree.Identifier[]>this.replaceableIdentifiers.get(lexicalScopeNode);
-
-        cachedReplaceableIdentifiers.forEach((replaceableIdentifier: ESTree.Identifier) => {
-            const newReplaceableIdentifier: ESTree.Identifier = this.identifierObfuscatingReplacer
-                .replace(replaceableIdentifier, lexicalScopeNode);
-
-            if (replaceableIdentifier.name !== newReplaceableIdentifier.name) {
-                replaceableIdentifier.name = newReplaceableIdentifier.name;
-                NodeMetadata.set(replaceableIdentifier, { renamedIdentifier: true });
-            }
-        });
-    }
-
-    /**
-     * @param {TNodeWithLexicalScope} lexicalScopeNode
-     */
-    private replaceScopeIdentifiers (lexicalScopeNode: TNodeWithLexicalScope): void {
-        const storedReplaceableIdentifiers: ESTree.Identifier[] = [];
-
-        estraverse.replace(lexicalScopeNode, {
-            enter: (node: ESTree.Node, parentNode: ESTree.Node | null): void => {
-                if (
-                    parentNode
-                    && NodeGuards.isReplaceableIdentifierNode(node, parentNode)
-                    && !NodeMetadata.isRenamedIdentifier(node)
-                ) {
-                    const newIdentifier: ESTree.Identifier = this.identifierObfuscatingReplacer
-                        .replace(node, lexicalScopeNode);
-                    const newIdentifierName: string = newIdentifier.name;
-
-                    if (node.name !== newIdentifierName) {
-                        node.name = newIdentifierName;
-                        NodeMetadata.set(node, { renamedIdentifier: true });
-                    } else {
-                        storedReplaceableIdentifiers.push(node);
-                    }
-                }
-            }
-        });
-
-        this.replaceableIdentifiers.set(lexicalScopeNode, storedReplaceableIdentifiers);
-    }
-}

+ 397 - 0
src/node-transformers/obfuscating-transformers/ScopeIdentifiersTransformer.ts

@@ -0,0 +1,397 @@
+import { inject, injectable, } from 'inversify';
+import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
+
+import * as eslintScope from 'eslint-scope';
+import * as ESTree from 'estree';
+import * as estraverse from 'estraverse';
+
+import { TIdentifierObfuscatingReplacerFactory } from '../../types/container/node-transformers/TIdentifierObfuscatingReplacerFactory';
+
+import { IIdentifierObfuscatingReplacer } from '../../interfaces/node-transformers/obfuscating-transformers/obfuscating-replacers/IIdentifierObfuscatingReplacer';
+import { IOptions } from '../../interfaces/options/IOptions';
+import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
+import { IScopeAnalyzer } from '../../interfaces/analyzers/scope-analyzer/IScopeAnalyzer';
+import { IVisitor } from '../../interfaces/node-transformers/IVisitor';
+
+import { IdentifierObfuscatingReplacer } from '../../enums/node-transformers/obfuscating-transformers/obfuscating-replacers/IdentifierObfuscatingReplacer';
+import { TransformationStage } from '../../enums/node-transformers/TransformationStage';
+
+import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
+import { NodeGuards } from '../../node/NodeGuards';
+import { NodeMetadata } from '../../node/NodeMetadata';
+
+/**
+ * Replaces all replaceable identifiers in scope
+ */
+@injectable()
+export class ScopeIdentifiersTransformer extends AbstractNodeTransformer {
+    /**
+     * @type {string}
+     */
+    private static readonly argumentsVariableName: string = 'arguments';
+
+    /**
+     * @type {string[]}
+     */
+    private static readonly globalScopeNames: string[] = [
+        'global',
+        'module'
+    ];
+
+    /**
+     * @type {IIdentifierObfuscatingReplacer}
+     */
+    private readonly identifierObfuscatingReplacer: IIdentifierObfuscatingReplacer;
+
+    /**
+     * @type {Map<eslintScope.Scope['block'], boolean>}
+     */
+    private readonly lexicalScopesWithObjectPatternWithoutDeclarationMap: Map<eslintScope.Scope['block'], boolean> = new Map();
+
+    /**
+     * @type {IScopeAnalyzer}
+     */
+    private readonly scopeAnalyzer: IScopeAnalyzer;
+
+    /**
+     * @param {TIdentifierObfuscatingReplacerFactory} identifierObfuscatingReplacerFactory
+     * @param {IRandomGenerator} randomGenerator
+     * @param {IOptions} options
+     * @param {IScopeAnalyzer} scopeAnalyzer
+     */
+    constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierObfuscatingReplacer)
+            identifierObfuscatingReplacerFactory: TIdentifierObfuscatingReplacerFactory,
+        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
+        @inject(ServiceIdentifiers.IOptions) options: IOptions,
+        @inject(ServiceIdentifiers.IScopeAnalyzer) scopeAnalyzer: IScopeAnalyzer
+    ) {
+        super(randomGenerator, options);
+
+        this.identifierObfuscatingReplacer = identifierObfuscatingReplacerFactory(
+            IdentifierObfuscatingReplacer.BaseIdentifierObfuscatingReplacer
+        );
+        this.scopeAnalyzer = scopeAnalyzer;
+    }
+
+    /**
+     * @param {TransformationStage} transformationStage
+     * @returns {IVisitor | null}
+     */
+    public getVisitor (transformationStage: TransformationStage): IVisitor | null {
+        switch (transformationStage) {
+            case TransformationStage.Obfuscating:
+                return {
+                    enter: (node: ESTree.Node, parentNode: ESTree.Node | null) => {
+                        if (parentNode && NodeGuards.isProgramNode(node)) {
+                            this.analyzeNode(node, parentNode);
+
+                            return this.transformNode(node, parentNode);
+                        }
+                    }
+                };
+
+            default:
+                return null;
+        }
+    }
+
+    /**
+     * @param {Program} programNode
+     * @param {Node | null} parentNode
+     * @returns {Node}
+     */
+    public analyzeNode (programNode: ESTree.Program, parentNode: ESTree.Node | null): void {
+        this.scopeAnalyzer.analyze(programNode);
+    }
+
+    /**
+     * @param {VariableDeclaration} programNode
+     * @param {NodeGuards} parentNode
+     * @returns {NodeGuards}
+     */
+    public transformNode (programNode: ESTree.Program, parentNode: ESTree.Node): ESTree.Node {
+        const globalScope: eslintScope.Scope = this.scopeAnalyzer.acquireScope(programNode);
+
+        this.traverseScopeVariables(globalScope);
+
+        return programNode;
+    }
+
+    /**
+     * @param {Scope} scope
+     */
+    private traverseScopeVariables (scope: eslintScope.Scope): void {
+        const variableScope: eslintScope.Scope = scope.variableScope;
+        const isGlobalVariableScope: boolean = ScopeIdentifiersTransformer.globalScopeNames.includes(variableScope.type);
+
+        scope.variables.forEach((variable: eslintScope.Variable) => {
+            this.processScopeVariableIdentifiers(variable, scope, variableScope, isGlobalVariableScope);
+        });
+
+        for (const childScope of scope.childScopes) {
+            this.traverseScopeVariables(childScope);
+        }
+    }
+
+    /**
+     * @param {Variable} variable
+     * @param {Scope} scope
+     * @param {Scope} variableScope
+     * @param {boolean} isGlobalVariableScope
+     */
+    private processScopeVariableIdentifiers (
+        variable: eslintScope.Variable,
+        scope: eslintScope.Scope,
+        variableScope: eslintScope.Scope,
+        isGlobalVariableScope: boolean
+    ): void {
+        if (variable.name === ScopeIdentifiersTransformer.argumentsVariableName) {
+            return;
+        }
+
+        if (!this.options.renameGlobals && isGlobalVariableScope) {
+            const isImportBindingOrCatchClauseIdentifier: boolean = variable.defs
+                .every((definition: eslintScope.Definition) =>
+                    definition.type === 'ImportBinding'
+                    || definition.type === 'CatchClause'
+                );
+
+            // skip all global identifiers except import statement and catch clause identifiers
+            if (!isImportBindingOrCatchClauseIdentifier) {
+                return;
+            }
+        }
+
+        for (const identifier of variable.identifiers) {
+            if (!this.isReplaceableIdentifierNode(variable, identifier, variableScope.block)) {
+                continue;
+            }
+
+            identifier.name = this.getNewIdentifierName(
+                identifier,
+                scope,
+                variableScope,
+                isGlobalVariableScope
+            );
+
+            // rename of references
+            variable.references.forEach((reference: eslintScope.Reference) => {
+                reference.identifier.name = identifier.name;
+            });
+
+            // rename of function default parameter identifiers if exists
+            (<any>variable.scope.block).defaults?.forEach((node: ESTree.Node) => {
+                if (NodeGuards.isIdentifierNode(node) && node.name === variable.name) {
+                    node.name = identifier.name;
+                }
+            });
+        }
+    }
+
+    /**
+     * @param {Identifier} identifierNode
+     * @param {Scope} scope
+     * @param {Scope} variableScope
+     * @param {boolean} isGlobalVariableScope
+     * @returns {string}
+     */
+    private getNewIdentifierName (
+        identifierNode: ESTree.Identifier,
+        scope: eslintScope.Scope,
+        variableScope: eslintScope.Scope,
+        isGlobalVariableScope: boolean
+    ): string {
+        if (!identifierNode.parentNode || !NodeGuards.isNodeWithBlockLexicalScope(variableScope.block)) {
+            return identifierNode.name;
+        }
+
+        // prevent class name renaming twice for outer scope and for class scope
+        if (scope.type === 'class' && this.isClassDeclarationNameIdentifierNode(identifierNode, identifierNode.parentNode)) {
+            return identifierNode.name;
+        }
+
+        isGlobalVariableScope
+            ? this.identifierObfuscatingReplacer.storeGlobalName(identifierNode, variableScope.block)
+            : this.identifierObfuscatingReplacer.storeLocalName(identifierNode, variableScope.block);
+
+        return this.identifierObfuscatingReplacer.replace(identifierNode, variableScope.block).name;
+    }
+
+    /**
+     * @param {Identifier} identifierNode
+     * @param {Node} parentNode
+     * @returns {identifierNode is Identifier}
+     */
+    private isClassDeclarationNameIdentifierNode (
+        identifierNode: ESTree.Identifier,
+        parentNode: ESTree.Node
+    ): identifierNode is ESTree.Identifier {
+        return NodeGuards.isClassDeclarationNode(parentNode)
+            && parentNode.id === identifierNode;
+    }
+
+    /**
+     * @param {Variable} variable
+     * @param {Identifier} identifierNode
+     * @param {Scope["block"]} lexicalScopeNode
+     * @returns {boolean}
+     */
+    private isReplaceableIdentifierNode (
+        variable: eslintScope.Variable,
+        identifierNode: ESTree.Identifier,
+        lexicalScopeNode: eslintScope.Scope['block']
+    ): boolean {
+        const parentNode: ESTree.Node | undefined = identifierNode.parentNode;
+
+        return !!parentNode
+            && !NodeMetadata.isIgnoredNode(identifierNode)
+            && !this.isProhibitedPropertyNode(identifierNode, parentNode)
+            && !this.isProhibitedExportNamedClassDeclarationIdentifierNode(identifierNode, parentNode)
+            && !this.isProhibitedExportNamedFunctionDeclarationIdentifierNode(identifierNode, parentNode)
+            && !this.isProhibitedExportNamedVariableDeclarationIdentifierNode(identifierNode, parentNode)
+            && !this.isProhibitedImportSpecifierNode(identifierNode, parentNode)
+            && !this.isProhibitedVariableNameUsedInObjectPatternNode(variable, identifierNode, lexicalScopeNode)
+            && !NodeGuards.isLabelIdentifierNode(identifierNode, parentNode);
+    }
+
+    /**
+     * @param {Identifier} identifierNode
+     * @param {Node} parentNode
+     * @returns {identifierNode is Identifier}
+     */
+    private isProhibitedExportNamedClassDeclarationIdentifierNode (
+        identifierNode: ESTree.Identifier,
+        parentNode: ESTree.Node
+    ): identifierNode is ESTree.Identifier {
+        return NodeGuards.isClassDeclarationNode(parentNode)
+            && parentNode.id === identifierNode
+            && !!parentNode.parentNode
+            && NodeGuards.isExportNamedDeclarationNode(parentNode.parentNode);
+    }
+
+    /**
+     * @param {Identifier} identifierNode
+     * @param {Node} parentNode
+     * @returns {identifierNode is Identifier}
+     */
+    private isProhibitedExportNamedFunctionDeclarationIdentifierNode (
+        identifierNode: ESTree.Identifier,
+        parentNode: ESTree.Node
+    ): identifierNode is ESTree.Identifier {
+        return NodeGuards.isFunctionDeclarationNode(parentNode)
+            && parentNode.id === identifierNode
+            && !!parentNode.parentNode
+            && NodeGuards.isExportNamedDeclarationNode(parentNode.parentNode);
+    }
+
+    /**
+     * @param {Identifier} identifierNode
+     * @param {Node} parentNode
+     * @returns {identifierNode is Identifier}
+     */
+    private isProhibitedExportNamedVariableDeclarationIdentifierNode (
+        identifierNode: ESTree.Identifier,
+        parentNode: ESTree.Node
+    ): identifierNode is ESTree.Identifier {
+        return NodeGuards.isVariableDeclaratorNode(parentNode)
+            && parentNode.id === identifierNode
+            && !!parentNode.parentNode
+            && NodeGuards.isVariableDeclarationNode(parentNode.parentNode)
+            && !!parentNode.parentNode.parentNode
+            && NodeGuards.isExportNamedDeclarationNode(parentNode.parentNode.parentNode);
+    }
+
+    /**
+     * @param {Identifier} identifierNode
+     * @param {Node} parentNode
+     * @returns {boolean}
+     */
+    private isProhibitedImportSpecifierNode (identifierNode: ESTree.Identifier, parentNode: ESTree.Node): boolean {
+        return NodeGuards.isImportSpecifierNode(parentNode)
+            && parentNode.imported.name === parentNode.local.name;
+    }
+
+    /**
+     * @param {Node} node
+     * @param {Node} parentNode
+     * @returns {boolean}
+     */
+    private isProhibitedPropertyNode (node: ESTree.Node, parentNode: ESTree.Node): node is ESTree.Identifier {
+        return NodeGuards.isPropertyNode(parentNode)
+            && !parentNode.computed
+            && parentNode.key === node;
+    }
+
+    /**
+     * Should not rename identifiers that used inside destructing assignment without declaration
+     *
+     * var a, b; // should not be renamed
+     * ({a, b} = {a: 1, b: 2});
+     *
+     * @param {Variable} variable
+     * @param {Identifier} identifierNode
+     * @param {eslintScope.Scope['block']} lexicalScopeNode
+     * @returns {boolean}
+     */
+    private isProhibitedVariableNameUsedInObjectPatternNode (
+        variable: eslintScope.Variable,
+        identifierNode: ESTree.Identifier,
+        lexicalScopeNode: eslintScope.Scope['block']
+    ): boolean {
+        let isLexicalScopeHasObjectPatternWithoutDeclaration: boolean | undefined =
+            this.lexicalScopesWithObjectPatternWithoutDeclarationMap.get(lexicalScopeNode);
+
+        // lexical scope was traversed before and object pattern without declaration was not found
+        if (isLexicalScopeHasObjectPatternWithoutDeclaration === false) {
+            return false;
+        }
+
+        const hasVarDefinitions: boolean = variable.defs.some((definition: eslintScope.Definition) => (<any>definition).kind === 'var');
+
+        if (!hasVarDefinitions) {
+            return false;
+        }
+
+        let isProhibitedVariableDeclaration: boolean = false;
+
+        estraverse.traverse(lexicalScopeNode, {
+            enter: (node: ESTree.Node, parentNode: ESTree.Node | null): void | estraverse.VisitorOption => {
+                if (
+                    NodeGuards.isObjectPatternNode(node)
+                    && parentNode
+                    && NodeGuards.isAssignmentExpressionNode(parentNode)
+                ) {
+                    isLexicalScopeHasObjectPatternWithoutDeclaration = true;
+
+                    const properties: ESTree.Property[] = node.properties;
+
+                    for (const property of properties) {
+                        if (property.computed || !property.shorthand) {
+                            continue;
+                        }
+
+                        if (!NodeGuards.isIdentifierNode(property.key)) {
+                            continue;
+                        }
+
+                        if (identifierNode.name !== property.key.name) {
+                            continue;
+                        }
+
+                        isProhibitedVariableDeclaration = true;
+
+                        return estraverse.VisitorOption.Break;
+                    }
+                }
+            }
+        });
+
+        this.lexicalScopesWithObjectPatternWithoutDeclarationMap.set(
+            lexicalScopeNode,
+            isLexicalScopeHasObjectPatternWithoutDeclaration ?? false
+        );
+
+        return isProhibitedVariableDeclaration;
+    }
+}

+ 0 - 351
src/node-transformers/obfuscating-transformers/VariableDeclarationTransformer.ts

@@ -1,351 +0,0 @@
-import { inject, injectable, } from 'inversify';
-import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
-
-import * as eslintScope from 'eslint-scope';
-import * as ESTree from 'estree';
-import * as estraverse from 'estraverse';
-
-import { IOptions } from '../../interfaces/options/IOptions';
-import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { IVisitor } from '../../interfaces/node-transformers/IVisitor';
-
-import { TransformationStage } from '../../enums/node-transformers/TransformationStage';
-
-import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
-import { NodeGuards } from '../../node/NodeGuards';
-import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope';
-import { ObfuscationTarget } from '../../enums/ObfuscationTarget';
-import { NodeMetadata } from '../../node/NodeMetadata';
-import { IdentifierObfuscatingReplacer } from '../../enums/node-transformers/obfuscating-transformers/obfuscating-replacers/IdentifierObfuscatingReplacer';
-import { IIdentifierObfuscatingReplacer } from '../../interfaces/node-transformers/obfuscating-transformers/obfuscating-replacers/IIdentifierObfuscatingReplacer';
-import { TIdentifierObfuscatingReplacerFactory } from '../../types/container/node-transformers/TIdentifierObfuscatingReplacerFactory';
-
-/**
- * replaces:
- *     var variable = 1;
- *     variable++;
- *
- * on:
- *     var _0x12d45f = 1;
- *     _0x12d45f++;
- *
- */
-@injectable()
-export class VariableDeclarationTransformer extends AbstractNodeTransformer {
-    /**
-     * @type {eslintScope.AnalysisOptions}
-     */
-    private static readonly eslintScopeOptions: eslintScope.AnalysisOptions = {
-        ecmaVersion: 10,
-        optimistic: true
-    };
-
-    /**
-     * @type {acorn.Options['sourceType'][]}
-     */
-    private static readonly sourceTypes: acorn.Options['sourceType'][] = [
-        'script',
-        'module'
-    ];
-
-    /**
-     * @type {eslintScope.ScopeManager | null}
-     */
-    private scopeManager: eslintScope.ScopeManager | null = null;
-
-    private readonly identifierObfuscatingReplacer: IIdentifierObfuscatingReplacer;
-
-    private readonly lexicalScopesWithObjectPatternWithoutDeclarationMap: Map<TNodeWithLexicalScope, boolean> = new Map();
-
-    /**
-     * @param {TIdentifierObfuscatingReplacerFactory} identifierObfuscatingReplacerFactory
-     * @param {IRandomGenerator} randomGenerator
-     * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
-     * @param {IOptions} options
-     */
-    constructor (
-        @inject(ServiceIdentifiers.Factory__IIdentifierObfuscatingReplacer)
-            identifierObfuscatingReplacerFactory: TIdentifierObfuscatingReplacerFactory,
-        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
-        @inject(ServiceIdentifiers.IOptions) options: IOptions
-    ) {
-        super(randomGenerator, options);
-
-        this.identifierObfuscatingReplacer = identifierObfuscatingReplacerFactory(
-            IdentifierObfuscatingReplacer.BaseIdentifierObfuscatingReplacer
-        );
-    }
-
-    /**
-     * @param {ESTree.Node} node
-     * @returns {boolean}
-     */
-    private static isProhibitedImportSpecifierNode (node: ESTree.Node): boolean {
-        return NodeGuards.isImportSpecifierNode(node)
-            && node.imported.name === node.local.name;
-    }
-
-    /**
-     * @param {TransformationStage} transformationStage
-     * @returns {IVisitor | null}
-     */
-    public getVisitor (transformationStage: TransformationStage): IVisitor | null {
-        switch (transformationStage) {
-            case TransformationStage.Obfuscating:
-                return {
-                    enter: (node: ESTree.Node, parentNode: ESTree.Node | null) => {
-                        if (parentNode && NodeGuards.isProgramNode(node)) {
-                            this.analyzeNode(node, parentNode);
-
-                            return this.transformNode(node, parentNode);
-                        }
-                    }
-                };
-
-            default:
-                return null;
-        }
-    }
-
-    /**
-     * @param {Node} node
-     * @param {Node | null} parentNode
-     * @returns {Node}
-     */
-    public analyzeNode (node: ESTree.Node, parentNode: ESTree.Node | null): void | never {
-        const sourceTypeLength: number = VariableDeclarationTransformer.sourceTypes.length;
-
-        estraverse.replace(node, {
-            enter: (node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node => {
-                if (node.range) {
-                    return node;
-                }
-
-                node.range = [0, 0];
-
-                return node;
-            }
-        });
-
-        for (let i: number = 0; i < sourceTypeLength; i++) {
-            try {
-                this.scopeManager = eslintScope.analyze(node, {
-                    ...VariableDeclarationTransformer.eslintScopeOptions,
-                    nodejsScope: this.options.target === ObfuscationTarget.Node,
-                    sourceType: VariableDeclarationTransformer.sourceTypes[i]
-                });
-
-                return;
-            } catch (error) {
-                if (i < sourceTypeLength - 1) {
-                    continue;
-                }
-
-                throw new Error(error);
-            }
-        }
-
-        throw new Error(`Scope analyzing error`);
-    }
-
-    /**
-     * @param {VariableDeclaration} programNode
-     * @param {NodeGuards} parentNode
-     * @returns {NodeGuards}
-     */
-    public transformNode (programNode: ESTree.Program, parentNode: ESTree.Node): ESTree.Node {
-        if (!this.scopeManager) {
-            return programNode;
-        }
-
-        const scope: eslintScope.Scope | null = this.scopeManager.acquire(
-            programNode,
-            true
-        );
-
-        if (scope) {
-            this.processScope(scope);
-        }
-
-        return programNode;
-    }
-
-    private processScope(scope: eslintScope.Scope): void {
-        scope?.variables.forEach((variable: eslintScope.Variable) => {
-            if (variable.name === 'arguments') {
-                return;
-            }
-
-            const scope: eslintScope.Scope = (<any>variable).scope;
-            const variableScope: eslintScope.Scope = (<any>variable).scope.variableScope;
-            const isGlobalScope: boolean = variableScope.type === 'global'
-                || variableScope.type === 'module';
-
-            if (!this.options.renameGlobals && isGlobalScope) {
-                const isImportBindingIdentifier: boolean = variable.defs.every((definition) => definition.type === 'ImportBinding');
-                const isCatchClauseIdentifier: boolean = variable.defs.every((definition) => definition.type === 'CatchClause');
-
-                // prevent renaming of import statement and catch clause global identifiers
-                if (!isImportBindingIdentifier && !isCatchClauseIdentifier) {
-                    return;
-                }
-            }
-
-            variable.identifiers.forEach((identifier: ESTree.Identifier) => {
-                if (NodeMetadata.isIgnoredNode(identifier)) {
-                    return;
-                }
-
-                if (this.isReservedName(identifier.name)) {
-                    return;
-                }
-
-                if (identifier.parentNode && !NodeGuards.isReplaceableIdentifierNode(identifier, identifier.parentNode)) {
-                    return;
-                }
-
-                if (identifier.parentNode && VariableDeclarationTransformer.isProhibitedImportSpecifierNode(identifier.parentNode)) {
-                    return;
-                }
-
-                if (this.isProhibitedVariableNameUsedInObjectPatternNode(variable, identifier, <any>scope.variableScope.block)) {
-                    return;
-                }
-
-                let identifierName: string;
-
-                if (
-                    // prevent class name renaming twice for outer scope and for class scope
-                    scope.type === 'class'
-                    && identifier.parentNode
-                    && NodeGuards.isClassDeclarationNode(identifier.parentNode)
-                    && identifier.parentNode.id === identifier
-                ) {
-                    // keep class declaration name
-                    identifierName = identifier.name;
-                } else {
-                    isGlobalScope
-                        ? this.identifierObfuscatingReplacer.storeGlobalName(
-                            identifier,
-                            <TNodeWithLexicalScope>variableScope.block
-                        )
-                        : this.identifierObfuscatingReplacer.storeLocalName(
-                            identifier,
-                            <TNodeWithLexicalScope>variableScope.block
-                        );
-
-                    const newIdentifierNode: ESTree.Identifier = this.identifierObfuscatingReplacer.replace(
-                        identifier,
-                        <TNodeWithLexicalScope>variableScope.block
-                    );
-
-                    identifier.name = newIdentifierNode.name;
-                    identifierName = identifier.name;
-                }
-
-                // rename of function default parameter identifiers
-                (<any>variable).scope.block.defaults?.forEach((node: ESTree.Node) => {
-                    if (NodeGuards.isIdentifierNode(node) && node.name === variable.name) {
-                        node.name = identifierName;
-                    }
-                });
-
-                // rename of references
-                variable.references.forEach((reference: eslintScope.Reference) => {
-                    reference.identifier.name = identifierName;
-                });
-            });
-        });
-
-        for (const childScope of scope.childScopes) {
-            this.processScope(childScope);
-        }
-    }
-
-    /**
-     * Should not rename identifiers that used inside destructing assignment without declaration
-     *
-     * var a, b; // should not be renamed
-     * ({a, b} = {a: 1, b: 2});
-     *
-     * @param {Identifier} identifierNode
-     * @param {TNodeWithLexicalScope} lexicalScopeNode
-     * @param {VariableDeclaration} hostVariableDeclarationNode
-     * @returns {boolean}
-     */
-    private isProhibitedVariableNameUsedInObjectPatternNode (
-        variable: eslintScope.Variable,
-        identifierNode: ESTree.Identifier,
-        lexicalScopeNode: TNodeWithLexicalScope
-    ): boolean {
-        const hasVarDefinitions: boolean = variable.defs.some((definition) => (<any>definition).kind === 'var');
-
-        if (!hasVarDefinitions) {
-            return false;
-        }
-
-        let isLexicalScopeHasObjectPatternWithoutDeclaration: boolean | undefined =
-            this.lexicalScopesWithObjectPatternWithoutDeclarationMap.get(lexicalScopeNode);
-
-        // lexical scope was traversed before and object pattern without declaration was not found
-        if (isLexicalScopeHasObjectPatternWithoutDeclaration === false) {
-            return false;
-        }
-
-        let isProhibitedVariableDeclaration: boolean = false;
-
-        estraverse.traverse(lexicalScopeNode, {
-            enter: (node: ESTree.Node, parentNode: ESTree.Node | null): void | estraverse.VisitorOption => {
-                if (
-                    NodeGuards.isObjectPatternNode(node)
-                    && parentNode
-                    && NodeGuards.isAssignmentExpressionNode(parentNode)
-                ) {
-                    isLexicalScopeHasObjectPatternWithoutDeclaration = true;
-
-                    const properties: ESTree.Property[] = node.properties;
-
-                    for (const property of properties) {
-                        if (property.computed || !property.shorthand) {
-                            continue;
-                        }
-
-                        if (!NodeGuards.isIdentifierNode(property.key)) {
-                            continue;
-                        }
-
-                        if (identifierNode.name !== property.key.name) {
-                            continue;
-                        }
-
-                        isProhibitedVariableDeclaration = true;
-
-                        return estraverse.VisitorOption.Break;
-                    }
-                }
-            }
-        });
-
-        this.lexicalScopesWithObjectPatternWithoutDeclarationMap.set(
-            lexicalScopeNode,
-            isLexicalScopeHasObjectPatternWithoutDeclaration ?? false
-        );
-
-        return isProhibitedVariableDeclaration;
-    }
-
-    /**
-     * @param {string} name
-     * @returns {boolean}
-     */
-    private isReservedName (name: string): boolean {
-        if (!this.options.reservedNames.length) {
-            return false;
-        }
-
-        return this.options.reservedNames
-            .some((reservedName: string) => {
-                return new RegExp(reservedName, 'g').exec(name) !== null;
-            });
-    }
-}

+ 0 - 3
src/node-transformers/obfuscating-transformers/obfuscating-replacers/literal-obfuscating-replacers/StringLiteralObfuscatingReplacer.ts

@@ -163,9 +163,6 @@ export class StringLiteralObfuscatingReplacer extends AbstractObfuscatingReplace
 
         const stringArrayIdentifierNode: ESTree.Identifier = NodeFactory.identifierNode(this.stringArrayStorageCallsWrapperName);
 
-        // prevent obfuscation of this identifier
-        NodeMetadata.set(stringArrayIdentifierNode, { renamedIdentifier: true });
-
         return NodeFactory.callExpressionNode(
             stringArrayIdentifierNode,
             callExpressionArgs

+ 0 - 4
src/node-transformers/preparing-transformers/MetadataTransformer.ts

@@ -55,10 +55,6 @@ export class MetadataTransformer extends AbstractNodeTransformer {
     public transformNode (node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node {
         NodeMetadata.set(node, { ignoredNode: false });
 
-        if (NodeGuards.isIdentifierNode(node)) {
-            NodeMetadata.set(node, { renamedIdentifier: false });
-        }
-
         if (NodeGuards.isLiteralNode(node)) {
             NodeMetadata.set(node, { replacedLiteral: false });
         }

+ 0 - 57
src/node/NodeBlockLexicalScopeUtils.ts

@@ -1,57 +0,0 @@
-import * as ESTree from 'estree';
-
-import { TNodeWithLexicalScope } from '../types/node/TNodeWithLexicalScope';
-
-import { NodeGuards } from './NodeGuards';
-
-export class NodeBlockLexicalScopeUtils {
-    /**
-     * @param {Node} node
-     * @returns {TNodeWithLexicalScope}
-     */
-    public static getLexicalScope (node: ESTree.Node): TNodeWithLexicalScope | undefined {
-        return NodeBlockLexicalScopeUtils.getLexicalScopesRecursive(node, 1)[0];
-    }
-
-    /**
-     * @param {Node} node
-     * @returns {TNodeWithLexicalScope[]}
-     */
-    public static getLexicalScopes (node: ESTree.Node): TNodeWithLexicalScope[] {
-        return NodeBlockLexicalScopeUtils.getLexicalScopesRecursive(node);
-    }
-
-    /***
-     * @param {Node} node
-     * @param {number} maxSize
-     * @param {TNodeWithLexicalScope[]} nodesWithLexicalScope
-     * @param {number} depth
-     * @returns {TNodeWithLexicalScope[]}
-     */
-    private static getLexicalScopesRecursive (
-        node: ESTree.Node,
-        maxSize: number = Infinity,
-        nodesWithLexicalScope: TNodeWithLexicalScope[] = [],
-        depth: number = 0
-    ): TNodeWithLexicalScope[] {
-        if (nodesWithLexicalScope.length >= maxSize) {
-            return nodesWithLexicalScope;
-        }
-
-        const parentNode: ESTree.Node | undefined = node.parentNode;
-
-        if (!parentNode) {
-            throw new ReferenceError('`parentNode` property of given node is `undefined`');
-        }
-
-        if (NodeGuards.isNodeWithBlockLexicalScope(node)) {
-            nodesWithLexicalScope.push(node);
-        }
-
-        if (node !== parentNode) {
-            return NodeBlockLexicalScopeUtils.getLexicalScopesRecursive(parentNode, maxSize, nodesWithLexicalScope, ++depth);
-        }
-
-        return nodesWithLexicalScope;
-    }
-}

+ 0 - 63
src/node/NodeGuards.ts

@@ -123,53 +123,6 @@ export class NodeGuards {
         return node.type === NodeType.ExportNamedDeclaration;
     }
 
-    /**
-     * @param {Identifier} identifierNode
-     * @param {Node} parentNode
-     * @returns {identifierNode is Identifier}
-     */
-    public static isExportNamedClassDeclarationIdentifierNode (
-        identifierNode: ESTree.Identifier,
-        parentNode: ESTree.Node
-    ): identifierNode is ESTree.Identifier {
-        return NodeGuards.isClassDeclarationNode(parentNode)
-            && parentNode.id === identifierNode
-            && !!parentNode.parentNode
-            && NodeGuards.isExportNamedDeclarationNode(parentNode.parentNode);
-    }
-
-    /**
-     * @param {Identifier} identifierNode
-     * @param {Node} parentNode
-     * @returns {identifierNode is Identifier}
-     */
-    public static isExportNamedFunctionDeclarationIdentifierNode (
-        identifierNode: ESTree.Identifier,
-        parentNode: ESTree.Node
-    ): identifierNode is ESTree.Identifier {
-        return NodeGuards.isFunctionDeclarationNode(parentNode)
-            && parentNode.id === identifierNode
-            && !!parentNode.parentNode
-            && NodeGuards.isExportNamedDeclarationNode(parentNode.parentNode);
-    }
-
-    /**
-     * @param {Identifier} identifierNode
-     * @param {Node} parentNode
-     * @returns {identifierNode is Identifier}
-     */
-    public static isExportNamedVariableDeclarationIdentifierNode (
-        identifierNode: ESTree.Identifier,
-        parentNode: ESTree.Node
-    ): identifierNode is ESTree.Identifier {
-        return NodeGuards.isVariableDeclaratorNode(parentNode)
-            && parentNode.id === identifierNode
-            && !!parentNode.parentNode
-            && NodeGuards.isVariableDeclarationNode(parentNode.parentNode)
-            && !!parentNode.parentNode.parentNode
-            && NodeGuards.isExportNamedDeclarationNode(parentNode.parentNode.parentNode);
-    }
-
     /**
      * @param {Node} node
      * @returns {boolean}
@@ -441,22 +394,6 @@ export class NodeGuards {
             && !parentNode.computed;
     }
 
-    /**
-     * @param {Node} node
-     * @param {Node} parentNode
-     * @returns {boolean}
-     */
-    public static isReplaceableIdentifierNode (node: ESTree.Node, parentNode: ESTree.Node): node is ESTree.Identifier {
-        return NodeGuards.isIdentifierNode(node)
-            && !NodeGuards.parentNodeIsPropertyNode(node, parentNode)
-            && !NodeGuards.parentNodeIsMemberExpressionNode(node, parentNode)
-            && !NodeGuards.parentNodeIsMethodDefinitionNode(node, parentNode)
-            && !NodeGuards.isLabelIdentifierNode(node, parentNode)
-            && !NodeGuards.isExportNamedClassDeclarationIdentifierNode(node, parentNode)
-            && !NodeGuards.isExportNamedFunctionDeclarationIdentifierNode(node, parentNode)
-            && !NodeGuards.isExportNamedVariableDeclarationIdentifierNode(node, parentNode);
-    }
-
     /**
      * @param {Node} node
      * @returns {boolean}

+ 0 - 8
src/node/NodeMetadata.ts

@@ -28,14 +28,6 @@ export class NodeMetadata {
         return NodeMetadata.get(node, 'ignoredNode') === true;
     }
 
-    /**
-     * @param {Node} identifierNode
-     * @returns {boolean}
-     */
-    public static isRenamedIdentifier (identifierNode: ESTree.Identifier): boolean {
-        return NodeMetadata.get<ESTree.IdentifierNodeMetadata>(identifierNode, 'renamedIdentifier') === true;
-    }
-
     /**
      * @param {Node} literalNode
      * @returns {boolean}

+ 6 - 4
test/dev/dev.ts

@@ -1,20 +1,22 @@
 'use strict';
 
 import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNodes';
+import { IdentifierNamesGenerator } from '../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
 
 (function () {
     const JavaScriptObfuscator: any = require('../../index');
 
     let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
         `
-            function foo (label) {
-                label:
-                    var s = 1;
+            function f(obj) {
+                const {c} = obj;
             }
         `,
         {
             ...NO_ADDITIONAL_NODES_PRESET,
-            compact: false
+            compact: false,
+            renameGlobals: true,
+            identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator
         }
     ).getObfuscatedCode();
 

+ 47 - 6
test/functional-tests/node-transformers/obfuscating-transformers/catch-clause-transformer/CatchClauseTransformer.spec.ts → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/catch-clause/CatchClause.spec.ts

@@ -1,16 +1,16 @@
 import { assert } from 'chai';
 
-import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
+import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
 
-import { getRegExpMatch } from '../../../../helpers/getRegExpMatch';
-import { readFileAsString } from '../../../../helpers/readFileAsString';
+import { getRegExpMatch } from '../../../../../helpers/getRegExpMatch';
+import { readFileAsString } from '../../../../../helpers/readFileAsString';
 
-import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
+import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscatorFacade';
 
-describe('CatchClauseTransformer', () => {
+describe('ScopeIdentifiersTransformer CatchClause identifiers', () => {
     let obfuscatedCode: string;
 
-    describe('transformNode', () => {
+    describe('transform identifiers', () => {
         const paramNameRegExp: RegExp = /catch *\((_0x([a-f0-9]){4,6})\) *\{/;
         const bodyParamNameRegExp: RegExp = /console\['log'\]\((_0x([a-f0-9]){4,6})\);/;
 
@@ -66,4 +66,45 @@ describe('CatchClauseTransformer', () => {
             assert.match(obfuscatedCode, functionBodyMatch);
         });
     });
+
+    describe('Global variable scope', () => {
+        describe('`renameGlobals` is disabled', () => {
+            const globalVariableRegExp: RegExp = /var test *= *0x1;/;
+
+            before(() => {
+                const code: string = readFileAsString(__dirname + '/fixtures/global-variable-scope.js');
+
+                obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                    code,
+                    {
+                        ...NO_ADDITIONAL_NODES_PRESET
+                    }
+                ).getObfuscatedCode();
+            });
+
+            it('match #1: shouldn\'t transform variable identifier if `renameGlobals` option is disabled', () => {
+                assert.match(obfuscatedCode, globalVariableRegExp);
+            });
+        });
+
+        describe('`renameGlobals` is enabled', () => {
+            const globalVariableRegExp: RegExp = /var _0x([a-f0-9]){4,6} *= *0x1;/;
+
+            before(() => {
+                const code: string = readFileAsString(__dirname + '/fixtures/global-variable-scope.js');
+
+                obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                    code,
+                    {
+                        ...NO_ADDITIONAL_NODES_PRESET,
+                        renameGlobals: true
+                    }
+                ).getObfuscatedCode();
+            });
+
+            it('match #1: should transform variable identifier if `renameGlobals` option is enabled', () => {
+                assert.match(obfuscatedCode, globalVariableRegExp);
+            });
+        });
+    });
 });

+ 5 - 0
test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/catch-clause/fixtures/global-variable-scope.js

@@ -0,0 +1,5 @@
+try {
+
+} catch (e) {
+    var test = 1;
+}

+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/catch-clause-transformer/fixtures/input.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/catch-clause/fixtures/input.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/catch-clause-transformer/fixtures/object-pattern-as-parameter.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/catch-clause/fixtures/object-pattern-as-parameter.js


+ 6 - 6
test/functional-tests/node-transformers/obfuscating-transformers/class-declaration-transformer/ClassDeclarationTransformer.spec.ts → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/ClassDeclaration.spec.ts

@@ -1,14 +1,14 @@
 import { assert } from 'chai';
 
-import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
+import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
 
-import { getRegExpMatch } from '../../../../helpers/getRegExpMatch';
-import { readFileAsString } from '../../../../helpers/readFileAsString';
+import { getRegExpMatch } from '../../../../../helpers/getRegExpMatch';
+import { readFileAsString } from '../../../../../helpers/readFileAsString';
 
-import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
-import { IdentifierNamesGenerator } from '../../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
+import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscatorFacade';
+import { IdentifierNamesGenerator } from '../../../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
 
-describe('ClassDeclarationTransformer', () => {
+describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => {
     describe('transformation of `classDeclaration` node names', () => {
         describe('Variant #1: `classDeclaration` parent block scope is not a `ProgramNode`', () => {
             const classNameIdentifierRegExp: RegExp = /class *(_0x[a-f0-9]{4,6}) *\{/;

+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/class-declaration-transformer/fixtures/default-export-inline.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/fixtures/default-export-inline.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/class-declaration-transformer/fixtures/default-export.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/fixtures/default-export.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/class-declaration-transformer/fixtures/input.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/fixtures/input.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/class-declaration-transformer/fixtures/named-export.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/fixtures/named-export.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/class-declaration-transformer/fixtures/parent-block-scope-is-program-node.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/fixtures/parent-block-scope-is-program-node.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/class-declaration-transformer/fixtures/prevent-renaming-of-renamed-identifiers.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/fixtures/prevent-renaming-of-renamed-identifiers.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/class-declaration-transformer/fixtures/rename-globals-identifier-transformation.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/fixtures/rename-globals-identifier-transformation.js


+ 6 - 6
test/functional-tests/node-transformers/obfuscating-transformers/function-declaration-transformer/FunctionDeclarationTransformer.spec.ts → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/FunctionDeclaration.spec.ts

@@ -1,14 +1,14 @@
 import { assert } from 'chai';
 
-import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
+import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
 
-import { getRegExpMatch } from '../../../../helpers/getRegExpMatch';
-import { readFileAsString } from '../../../../helpers/readFileAsString';
+import { getRegExpMatch } from '../../../../../helpers/getRegExpMatch';
+import { readFileAsString } from '../../../../../helpers/readFileAsString';
 
-import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
-import { IdentifierNamesGenerator } from '../../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
+import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscatorFacade';
+import { IdentifierNamesGenerator } from '../../../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
 
-describe('FunctionDeclarationTransformer', () => {
+describe('ScopeIdentifiersTransformer FunctionDeclaration identifiers', () => {
     describe('transformation of `functionDeclaration` node names', () => {
         describe('Variant #1: `functionDeclaration` parent block scope is not a `ProgramNode`', () => {
             const functionNameIdentifierRegExp: RegExp = /function *(_0x[a-f0-9]{4,6}) *\(\) *\{/;

+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-declaration-transformer/fixtures/async-function.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/fixtures/async-function.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-declaration-transformer/fixtures/default-export-inline.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/fixtures/default-export-inline.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-declaration-transformer/fixtures/default-export.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/fixtures/default-export.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-declaration-transformer/fixtures/generator-function.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/fixtures/generator-function.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-declaration-transformer/fixtures/input.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/fixtures/input.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-declaration-transformer/fixtures/named-export.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/fixtures/named-export.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-declaration-transformer/fixtures/parent-block-scope-is-program-node.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/fixtures/parent-block-scope-is-program-node.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-declaration-transformer/fixtures/prevent-renaming-of-renamed-identifiers-1.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/fixtures/prevent-renaming-of-renamed-identifiers-1.js


+ 25 - 5
test/functional-tests/node-transformers/obfuscating-transformers/function-transformer/FunctionTransformer.spec.ts → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/Function.spec.ts

@@ -1,13 +1,13 @@
 import { assert } from 'chai';
 
-import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
+import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
 
-import { readFileAsString } from '../../../../helpers/readFileAsString';
+import { readFileAsString } from '../../../../../helpers/readFileAsString';
 
-import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
-import { getRegExpMatch } from '../../../../helpers/getRegExpMatch';
+import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscatorFacade';
+import { getRegExpMatch } from '../../../../../helpers/getRegExpMatch';
 
-describe('FunctionTransformer', () => {
+describe('ScopeIdentifiersTransformer Function identifiers', () => {
     describe('identifiers transformation inside `FunctionDeclaration` and `FunctionExpression` node body', () => {
         const functionParamIdentifierRegExp: RegExp = /var _0x[a-f0-9]{4,6} *= *function *\((_0x[a-f0-9]{4,6})\) *\{/;
         const functionBodyIdentifierRegExp: RegExp = /console\['log'\]\((_0x[a-f0-9]{4,6})\)/;
@@ -406,6 +406,26 @@ describe('FunctionTransformer', () => {
                 assert.match(obfuscatedCode, returnRegExp);
             });
         });
+
+        describe('Variant #5: skip rename of object pattern referenced identifier', () => {
+            const objectPatternRegExp: RegExp = /const _0x[a-f0-9]{4,6} *= *\[]\['map']\(\({ *foo *}\) *=> *foo\);/;
+            let obfuscatedCode: string;
+
+            before(() => {
+                const code: string = readFileAsString(__dirname + '/fixtures/object-pattern-as-parameter-5.js');
+
+                obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                    code,
+                    {
+                        ...NO_ADDITIONAL_NODES_PRESET
+                    }
+                ).getObfuscatedCode();
+            });
+
+            it('match #1: shouldn\'t transform function parameter identifier and reference identifier', () => {
+                assert.match(obfuscatedCode, objectPatternRegExp);
+            });
+        });
     });
 
     describe('assignment pattern as parameter', () => {

+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-transformer/fixtures/array-pattern-as-parameter.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/array-pattern-as-parameter.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-transformer/fixtures/array-rest-parameter.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/array-rest-parameter.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-transformer/fixtures/arrow-function-with-expression-body-block-scope-detection-1.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/arrow-function-with-expression-body-block-scope-detection-1.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-transformer/fixtures/arrow-function-with-expression-body-block-scope-detection-2.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/arrow-function-with-expression-body-block-scope-detection-2.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-transformer/fixtures/assignment-pattern-as-parameter-1.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/assignment-pattern-as-parameter-1.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-transformer/fixtures/assignment-pattern-as-parameter-2.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/assignment-pattern-as-parameter-2.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-transformer/fixtures/assignment-pattern-as-parameter-3.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/assignment-pattern-as-parameter-3.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-transformer/fixtures/function-id-name-1.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/function-id-name-1.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-transformer/fixtures/function-id-name-2.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/function-id-name-2.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-transformer/fixtures/function-id-name-3.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/function-id-name-3.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-transformer/fixtures/identifier-names-set-object-pattern.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/identifier-names-set-object-pattern.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-transformer/fixtures/input.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/input.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-transformer/fixtures/object-pattern-as-parameter-1.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/object-pattern-as-parameter-1.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-transformer/fixtures/object-pattern-as-parameter-2.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/object-pattern-as-parameter-2.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-transformer/fixtures/object-pattern-as-parameter-3.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/object-pattern-as-parameter-3.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-transformer/fixtures/object-pattern-as-parameter-4.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/object-pattern-as-parameter-4.js


+ 3 - 0
test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/object-pattern-as-parameter-5.js

@@ -0,0 +1,3 @@
+(function(){
+    const foo = [].map(({ foo }) => foo);
+})();

+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-transformer/fixtures/object-rest-parameter.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/object-rest-parameter.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/function-transformer/fixtures/rest-parameter.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/fixtures/rest-parameter.js


+ 5 - 5
test/functional-tests/node-transformers/obfuscating-transformers/impot-declaration-transformer/ImportDeclarationTransformer.spec.ts → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/import-declaration/ImportDeclaration.spec.ts

@@ -1,13 +1,13 @@
 import { assert } from 'chai';
 
-import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
+import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
 
-import { getRegExpMatch } from '../../../../helpers/getRegExpMatch';
-import { readFileAsString } from '../../../../helpers/readFileAsString';
+import { getRegExpMatch } from '../../../../../helpers/getRegExpMatch';
+import { readFileAsString } from '../../../../../helpers/readFileAsString';
 
-import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
+import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscatorFacade';
 
-describe('ImportDeclarationTransformer', () => {
+describe('ScopeIdentifiersTransformer ImportDeclaration identifiers', () => {
     describe('transformation of `importSpecifier` node identifiers', () => {
         describe('Variant #1: `defaultImportSpecifier` node', () => {
             const importSpecifierRegExp: RegExp = /import (_0x[a-f0-9]{4,6}) from *'\.\/foo';/;

+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/impot-declaration-transformer/fixtures/default-import.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/import-declaration/fixtures/default-import.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/impot-declaration-transformer/fixtures/named-import-1.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/import-declaration/fixtures/named-import-1.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/impot-declaration-transformer/fixtures/named-import-2.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/import-declaration/fixtures/named-import-2.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/impot-declaration-transformer/fixtures/namespace-import.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/import-declaration/fixtures/namespace-import.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/impot-declaration-transformer/fixtures/no-invalid-mark-as-renamed-identifier.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/import-declaration/fixtures/no-invalid-mark-as-renamed-identifier.js


+ 6 - 6
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/VariableDeclarationTransformer.spec.ts → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/VariableDeclaration.spec.ts

@@ -1,15 +1,15 @@
 import { assert } from 'chai';
 
-import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
+import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
 
-import { getRegExpMatch } from '../../../../helpers/getRegExpMatch';
-import { readFileAsString } from '../../../../helpers/readFileAsString';
+import { getRegExpMatch } from '../../../../../helpers/getRegExpMatch';
+import { readFileAsString } from '../../../../../helpers/readFileAsString';
 
-import { IdentifierNamesGenerator } from '../../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
+import { IdentifierNamesGenerator } from '../../../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
 
-import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
+import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscatorFacade';
 
-describe('VariableDeclarationTransformer', () => {
+describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => {
     describe('Variant #1: default behaviour', () => {
         const variableDeclarationRegExp: RegExp = /var *_0x([a-f0-9]){4,6} *= *'abc';/;
         const variableCallRegExp: RegExp = /console\['log'\]\(_0x([a-f0-9]){4,6}\);/;

+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/array-pattern.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/array-pattern.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/array-rest.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/array-rest.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/computed-object-expression-identifier.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/computed-object-expression-identifier.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/default-export.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/default-export.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/destructing-assignment-without-declaration-1.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/destructing-assignment-without-declaration-1.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/destructing-assignment-without-declaration-2.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/destructing-assignment-without-declaration-2.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/let-kind.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/let-kind.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/member-expression-identifier.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/member-expression-identifier.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/method-definition-identifier.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/method-definition-identifier.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/named-export.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/named-export.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/object-pattern.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/object-pattern.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/object-rest.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/object-rest.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/parent-block-scope-is-program-node.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/parent-block-scope-is-program-node.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/prevent-renaming-of-renamed-identifiers-1.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/prevent-renaming-of-renamed-identifiers-1.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/prevent-renaming-of-renamed-identifiers-2.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/prevent-renaming-of-renamed-identifiers-2.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/property-identifier.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/property-identifier.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/simple-declaration.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/simple-declaration.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/var-kind.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/var-kind.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/variable-call-before-variable-declaration-1.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/variable-call-before-variable-declaration-1.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/variable-call-before-variable-declaration-2.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/variable-call-before-variable-declaration-2.js


+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/fixtures/variable-call-before-variable-declaration-3.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/fixtures/variable-call-before-variable-declaration-3.js


+ 6 - 6
test/index.spec.ts

@@ -73,15 +73,15 @@ import './functional-tests/node-transformers/converting-transformers/object-expr
 import './functional-tests/node-transformers/converting-transformers/split-string-transformer/SplitStringTransformer.spec';
 import './functional-tests/node-transformers/converting-transformers/template-literal-transformer/TemplateLiteralTransformer.spec';
 import './functional-tests/node-transformers/dead-code-injection-transformers/DeadCodeInjectionTransformer.spec';
-import './functional-tests/node-transformers/obfuscating-transformers/catch-clause-transformer/CatchClauseTransformer.spec';
-import './functional-tests/node-transformers/obfuscating-transformers/class-declaration-transformer/ClassDeclarationTransformer.spec';
-import './functional-tests/node-transformers/obfuscating-transformers/function-declaration-transformer/FunctionDeclarationTransformer.spec';
-import './functional-tests/node-transformers/obfuscating-transformers/function-transformer/FunctionTransformer.spec';
-import './functional-tests/node-transformers/obfuscating-transformers/impot-declaration-transformer/ImportDeclarationTransformer.spec';
 import './functional-tests/node-transformers/obfuscating-transformers/labeled-statement-transformer/LabeledStatementTransformer.spec';
 import './functional-tests/node-transformers/obfuscating-transformers/literal-transformer/LiteralTransformer.spec';
+import './functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/catch-clause/CatchClause.spec';
+import './functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/ClassDeclaration.spec';
+import './functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/FunctionDeclaration.spec';
+import './functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/Function.spec';
+import './functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/import-declaration/ImportDeclaration.spec';
+import './functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/VariableDeclaration.spec';
 import './functional-tests/node-transformers/obfuscating-transformers/obfuscating-replacers/identifier-obfuscating-replacers/BaseIdentifierObfuscatingReplacer.spec';
-import './functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/VariableDeclarationTransformer.spec';
 import './functional-tests/node-transformers/preparing-transformers/eval-call-expression-transformer/EvalCallExpressionTransformer.spec';
 import './functional-tests/node-transformers/preparing-transformers/comments-transformer/CommentsTransformer.spec';
 import './functional-tests/node-transformers/preparing-transformers/obfuscating-guards/black-list-obfuscating-guard/BlackListObfuscatingGuard.spec';

+ 0 - 177
test/unit-tests/node/node-guards/NodeGuards.spec.ts

@@ -257,181 +257,4 @@ describe('NodeGuards', () => {
             });
         });
     });
-
-    describe('isReplaceableIdentifierNode', () => {
-        describe('truthful checks', () => {
-            describe('Variant #1: parent node is function declaration node', () => {
-                const expectedResult: boolean = true;
-                const identifier: ESTree.Identifier = NodeFactory.identifierNode('foo');
-                const parentNode: ESTree.Node = NodeFactory.functionDeclarationNode(
-                    'bar',
-                    [identifier],
-                    NodeFactory.blockStatementNode()
-                );
-
-                let result: boolean;
-
-                before(() => {
-                    NodeUtils.parentizeAst(parentNode);
-                    result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
-                });
-
-                it('should check if input identifier can be replaced by obfuscated one', () => {
-                    assert.equal(result, expectedResult);
-                });
-            });
-
-            describe('Variant #2: parent node is computed property node', () => {
-                const expectedResult: boolean = true;
-                const identifier: ESTree.Identifier = NodeFactory.identifierNode('foo');
-                const parentNode: ESTree.Node = NodeFactory.propertyNode(
-                    identifier,
-                    NodeFactory.literalNode('bar'),
-                    true
-                );
-
-                let result: boolean;
-
-                before(() => {
-                    NodeUtils.parentizeAst(parentNode);
-                    result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
-                });
-
-                it('should check if input identifier can be replaced by obfuscated one', () => {
-                    assert.equal(result, expectedResult);
-                });
-            });
-
-            describe('Variant #4: parent node is computed member expression node', () => {
-                const expectedResult: boolean = true;
-                const identifier: ESTree.Identifier = NodeFactory.identifierNode('foo');
-                const parentNode: ESTree.Node = NodeFactory.memberExpressionNode(
-                    NodeFactory.identifierNode('bar'),
-                    identifier,
-                    true
-                );
-
-                let result: boolean;
-
-                before(() => {
-                    NodeUtils.parentizeAst(parentNode);
-                    result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
-                });
-
-                it('should check if input identifier can be replaced by obfuscated one', () => {
-                    assert.equal(result, expectedResult);
-                });
-            });
-
-            describe('Variant #4: parent node is computed method definition node', () => {
-                const expectedResult: boolean = true;
-                const identifier: ESTree.Identifier = NodeFactory.identifierNode('foo');
-                const parentNode: ESTree.Node = NodeFactory.methodDefinitionNode(
-                    identifier,
-                    NodeFactory.functionExpressionNode([], NodeFactory.blockStatementNode()),
-                    'method',
-                    true
-                );
-
-                let result: boolean;
-
-                before(() => {
-                    NodeUtils.parentizeAst(parentNode);
-                    result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
-                });
-
-                it('should check if input identifier can be replaced by obfuscated one', () => {
-                    assert.equal(result, expectedResult);
-                });
-            });
-        });
-
-        describe('false checks', () => {
-            describe('Variant #1: node isn\'t an identifier', () => {
-                const expectedResult: boolean = false;
-                const literal: ESTree.Literal = NodeFactory.literalNode(1);
-                const parentNode: ESTree.Node = NodeFactory.expressionStatementNode(
-                    NodeFactory.callExpressionNode(
-                        NodeFactory.identifierNode('foo'),
-                        [literal]
-                    )
-                );
-
-                let result: boolean;
-
-                before(() => {
-                    NodeUtils.parentizeAst(parentNode);
-                    result = NodeGuards.isReplaceableIdentifierNode(literal, parentNode);
-                });
-
-                it('should check if input identifier can be replaced by obfuscated one', () => {
-                    assert.equal(result, expectedResult);
-                });
-            });
-
-            describe('Variant #2: parent node isn\'t computed property node', () => {
-                const expectedResult: boolean = false;
-                const identifier: ESTree.Identifier = NodeFactory.identifierNode('foo');
-                const parentNode: ESTree.Node = NodeFactory.propertyNode(
-                    identifier,
-                    NodeFactory.literalNode('bar'),
-                    false
-                );
-
-                let result: boolean;
-
-                before(() => {
-                    NodeUtils.parentizeAst(parentNode);
-                    result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
-                });
-
-                it('should check if input identifier can be replaced by obfuscated one', () => {
-                    assert.equal(result, expectedResult);
-                });
-            });
-
-            describe('Variant #3: parent node isn\'t computed member expression node', () => {
-                const expectedResult: boolean = false;
-                const identifier: ESTree.Identifier = NodeFactory.identifierNode('foo');
-                const parentNode: ESTree.Node = NodeFactory.memberExpressionNode(
-                    NodeFactory.identifierNode('bar'),
-                    identifier,
-                    false
-                );
-
-                let result: boolean;
-
-                before(() => {
-                    NodeUtils.parentizeAst(parentNode);
-                    result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
-                });
-
-                it('should check if input identifier can be replaced by obfuscated one', () => {
-                    assert.equal(result, expectedResult);
-                });
-            });
-
-            describe('Variant #4: parent node isn\'t computed method definition node', () => {
-                const expectedResult: boolean = false;
-                const identifier: ESTree.Identifier = NodeFactory.identifierNode('foo');
-                const parentNode: ESTree.Node = NodeFactory.methodDefinitionNode(
-                    identifier,
-                    NodeFactory.functionExpressionNode([], NodeFactory.blockStatementNode()),
-                    'method',
-                    false
-                );
-
-                let result: boolean;
-
-                before(() => {
-                    NodeUtils.parentizeAst(parentNode);
-                    result = NodeGuards.isReplaceableIdentifierNode(identifier, parentNode);
-                });
-
-                it('should check if input identifier can be replaced by obfuscated one', () => {
-                    assert.equal(result, expectedResult);
-                });
-            });
-        });
-    });
 });

+ 9 - 27
test/unit-tests/node/node-metadata/NodeMetadata.spec.ts

@@ -9,18 +9,18 @@ import { NodeFactory } from '../../../../src/node/NodeFactory';
 
 describe('NodeMetadata', () => {
     describe('set', () => {
-        const expectedMetadata: ESTree.IdentifierNodeMetadata = {
+        const expectedMetadata: ESTree.LiteralNodeMetadata = {
             ignoredNode: true,
-            renamedIdentifier: true
+            replacedLiteral: true
         };
 
-        let node: ESTree.Identifier;
+        let node: ESTree.Literal;
 
         before(() => {
-            node = NodeFactory.identifierNode('foo');
+            node = NodeFactory.literalNode('foo');
             NodeMetadata.set(node, {
                 ignoredNode: true,
-                renamedIdentifier: true
+                replacedLiteral: true
             })
         });
 
@@ -32,14 +32,14 @@ describe('NodeMetadata', () => {
     describe('get', () => {
         const expectedValue: boolean = true;
 
-        let node: ESTree.Identifier,
+        let node: ESTree.Literal,
             value: boolean | undefined;
 
         before(() => {
-            node = NodeFactory.identifierNode('foo');
+            node = NodeFactory.literalNode('foo');
             node.metadata = {};
-            node.metadata.renamedIdentifier = true;
-            value = NodeMetadata.get<ESTree.IdentifierNodeMetadata>(node, 'renamedIdentifier');
+            node.metadata.replacedLiteral = true;
+            value = NodeMetadata.get<ESTree.LiteralNodeMetadata>(node, 'replacedLiteral');
         });
 
         it('should get metadata value of the node', () => {
@@ -65,24 +65,6 @@ describe('NodeMetadata', () => {
         });
     });
 
-    describe('isRenamedIdentifier', () => {
-        const expectedValue: boolean = true;
-
-        let node: ESTree.Identifier,
-            value: boolean | undefined;
-
-        before(() => {
-            node = NodeFactory.identifierNode('foo');
-            node.metadata = {};
-            node.metadata.renamedIdentifier = true;
-            value = NodeMetadata.isRenamedIdentifier(node);
-        });
-
-        it('should return metadata value', () => {
-            assert.equal(value, expectedValue);
-        });
-    });
-
     describe('isReplacedLiteral', () => {
         const expectedValue: boolean = true;
 

Vissa filer visades inte eftersom för många filer har ändrats