Browse Source

Added property cache implementation

sanex 4 years ago
parent
commit
4be162a24b

File diff suppressed because it is too large
+ 0 - 0
dist/index.browser.js


File diff suppressed because it is too large
+ 0 - 0
dist/index.cli.js


File diff suppressed because it is too large
+ 0 - 0
dist/index.js


+ 2 - 1
src/container/ServiceIdentifiers.ts

@@ -29,7 +29,7 @@ export enum ServiceIdentifiers {
     ICustomCodeHelperFormatter = 'ICustomCodeHelperFormatter',
     ICustomCodeHelperFormatter = 'ICustomCodeHelperFormatter',
     ICustomCodeHelperObfuscator = 'ICustomCodeHelperObfuscator',
     ICustomCodeHelperObfuscator = 'ICustomCodeHelperObfuscator',
     IEscapeSequenceEncoder = 'IEscapeSequenceEncoder',
     IEscapeSequenceEncoder = 'IEscapeSequenceEncoder',
-    IIdentifierNamesCacheStorage = 'IIdentifierNamesCacheStorage',
+    IGlobalIdentifierNamesCacheStorage = 'IGlobalIdentifierNamesCacheStorage',
     IIdentifierNamesGenerator = 'IIdentifierNamesGenerator',
     IIdentifierNamesGenerator = 'IIdentifierNamesGenerator',
     IIdentifierReplacer = 'IIdentifierReplacer',
     IIdentifierReplacer = 'IIdentifierReplacer',
     IJavaScriptObfuscator = 'IJavaScriptObfuscator',
     IJavaScriptObfuscator = 'IJavaScriptObfuscator',
@@ -45,6 +45,7 @@ export enum ServiceIdentifiers {
     IOptions = 'IOptions',
     IOptions = 'IOptions',
     IOptionsNormalizer = 'IOptionsNormalizer',
     IOptionsNormalizer = 'IOptionsNormalizer',
     IPrevailingKindOfVariablesAnalyzer = 'IPrevailingKindOfVariablesAnalyzer',
     IPrevailingKindOfVariablesAnalyzer = 'IPrevailingKindOfVariablesAnalyzer',
+    IPropertyIdentifierNamesCacheStorage = 'IPropertyIdentifierNamesCacheStorage',
     IObjectExpressionExtractor = 'IObjectExpressionExtractor',
     IObjectExpressionExtractor = 'IObjectExpressionExtractor',
     IRandomGenerator = 'IRandomGenerator',
     IRandomGenerator = 'IRandomGenerator',
     IRenamePropertiesReplacer = 'IRenamePropertiesReplacer',
     IRenamePropertiesReplacer = 'IRenamePropertiesReplacer',

+ 10 - 4
src/container/modules/storages/StoragesModule.ts

@@ -4,9 +4,10 @@ import { ServiceIdentifiers } from '../../ServiceIdentifiers';
 import { TControlFlowStorage } from '../../../types/storages/TControlFlowStorage';
 import { TControlFlowStorage } from '../../../types/storages/TControlFlowStorage';
 import { TCustomCodeHelperGroupStorage } from '../../../types/storages/TCustomCodeHelperGroupStorage';
 import { TCustomCodeHelperGroupStorage } from '../../../types/storages/TCustomCodeHelperGroupStorage';
 
 
-import { IIdentifierNamesCacheStorage } from '../../../interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage';
+import { IGlobalIdentifierNamesCacheStorage } from '../../../interfaces/storages/identifier-names-cache/IGlobalIdentifierNamesCacheStorage';
 import { ILiteralNodesCacheStorage } from '../../../interfaces/storages/string-array-transformers/ILiteralNodesCacheStorage';
 import { ILiteralNodesCacheStorage } from '../../../interfaces/storages/string-array-transformers/ILiteralNodesCacheStorage';
 import { IOptions } from '../../../interfaces/options/IOptions';
 import { IOptions } from '../../../interfaces/options/IOptions';
+import { IPropertyIdentifierNamesCacheStorage } from '../../../interfaces/storages/identifier-names-cache/IPropertyIdentifierNamesCacheStorage';
 import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
 import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
 import { IStringArrayScopeCallsWrapperLexicalScopeDataStorage } from '../../../interfaces/storages/string-array-transformers/IStringArrayScopeCallsWrapperLexicalScopeDataStorage';
 import { IStringArrayScopeCallsWrapperLexicalScopeDataStorage } from '../../../interfaces/storages/string-array-transformers/IStringArrayScopeCallsWrapperLexicalScopeDataStorage';
 import { IStringArrayScopeCallsWrapperNamesDataStorage } from '../../../interfaces/storages/string-array-transformers/IStringArrayScopeCallsWrapperNamesDataStorage';
 import { IStringArrayScopeCallsWrapperNamesDataStorage } from '../../../interfaces/storages/string-array-transformers/IStringArrayScopeCallsWrapperNamesDataStorage';
@@ -15,8 +16,9 @@ import { IVisitedLexicalScopeNodesStackStorage } from '../../../interfaces/stora
 
 
 import { ControlFlowStorage } from '../../../storages/custom-nodes/ControlFlowStorage';
 import { ControlFlowStorage } from '../../../storages/custom-nodes/ControlFlowStorage';
 import { CustomCodeHelperGroupStorage } from '../../../storages/custom-code-helpers/CustomCodeHelperGroupStorage';
 import { CustomCodeHelperGroupStorage } from '../../../storages/custom-code-helpers/CustomCodeHelperGroupStorage';
-import { IdentifierNamesCacheStorage } from '../../../storages/identifier-names-cache/IdentifierNamesCacheStorage';
+import { GlobalIdentifierNamesCacheStorage } from '../../../storages/identifier-names-cache/GlobalIdentifierNamesCacheStorage';
 import { LiteralNodesCacheStorage } from '../../../storages/string-array-transformers/LiteralNodesCacheStorage';
 import { LiteralNodesCacheStorage } from '../../../storages/string-array-transformers/LiteralNodesCacheStorage';
+import { PropertyIdentifierNamesCacheStorage } from '../../../storages/identifier-names-cache/PropertyIdentifierNamesCacheStorage';
 import { StringArrayScopeCallsWrapperLexicalScopeDataStorage } from '../../../storages/string-array-transformers/StringArrayScopeCallsWrapperLexicalScopeDataStorage';
 import { StringArrayScopeCallsWrapperLexicalScopeDataStorage } from '../../../storages/string-array-transformers/StringArrayScopeCallsWrapperLexicalScopeDataStorage';
 import { StringArrayScopeCallsWrapperNamesDataStorage } from '../../../storages/string-array-transformers/StringArrayScopeCallsWrapperNamesDataStorage';
 import { StringArrayScopeCallsWrapperNamesDataStorage } from '../../../storages/string-array-transformers/StringArrayScopeCallsWrapperNamesDataStorage';
 import { StringArrayStorage } from '../../../storages/string-array-transformers/StringArrayStorage';
 import { StringArrayStorage } from '../../../storages/string-array-transformers/StringArrayStorage';
@@ -28,14 +30,18 @@ export const storagesModule: interfaces.ContainerModule = new ContainerModule((b
         .to(CustomCodeHelperGroupStorage)
         .to(CustomCodeHelperGroupStorage)
         .inSingletonScope();
         .inSingletonScope();
 
 
-    bind<IIdentifierNamesCacheStorage>(ServiceIdentifiers.IIdentifierNamesCacheStorage)
-        .to(IdentifierNamesCacheStorage)
+    bind<IGlobalIdentifierNamesCacheStorage>(ServiceIdentifiers.IGlobalIdentifierNamesCacheStorage)
+        .to(GlobalIdentifierNamesCacheStorage)
         .inSingletonScope();
         .inSingletonScope();
 
 
     bind<ILiteralNodesCacheStorage>(ServiceIdentifiers.ILiteralNodesCacheStorage)
     bind<ILiteralNodesCacheStorage>(ServiceIdentifiers.ILiteralNodesCacheStorage)
         .to(LiteralNodesCacheStorage)
         .to(LiteralNodesCacheStorage)
         .inSingletonScope();
         .inSingletonScope();
 
 
+    bind<IPropertyIdentifierNamesCacheStorage>(ServiceIdentifiers.IPropertyIdentifierNamesCacheStorage)
+        .to(PropertyIdentifierNamesCacheStorage)
+        .inSingletonScope();
+
     bind<IStringArrayStorage>(ServiceIdentifiers.IStringArrayStorage)
     bind<IStringArrayStorage>(ServiceIdentifiers.IStringArrayStorage)
         .to(StringArrayStorage)
         .to(StringArrayStorage)
         .inSingletonScope();
         .inSingletonScope();

+ 4 - 0
src/interfaces/storages/identifier-names-cache/IGlobalIdentifierNamesCacheStorage.ts

@@ -0,0 +1,4 @@
+import { IMapStorage } from '../IMapStorage';
+
+// eslint-disable-next-line
+export interface IGlobalIdentifierNamesCacheStorage extends IMapStorage <string, string> {}

+ 0 - 4
src/interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage.ts

@@ -1,4 +0,0 @@
-import { IMapStorage } from '../IMapStorage';
-
-// eslint-disable-next-line
-export interface IIdentifierNamesCacheStorage extends IMapStorage <string, string> {}

+ 4 - 0
src/interfaces/storages/identifier-names-cache/IPropertyIdentifierNamesCacheStorage.ts

@@ -0,0 +1,4 @@
+import { IMapStorage } from '../IMapStorage';
+
+// eslint-disable-next-line
+export interface IPropertyIdentifierNamesCacheStorage extends IMapStorage <string, string> {}

+ 6 - 6
src/node-transformers/rename-identifiers-transformers/replacer/IdentifierReplacer.ts

@@ -6,7 +6,7 @@ import * as ESTree from 'estree';
 import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TNodeWithLexicalScope } from '../../../types/node/TNodeWithLexicalScope';
 import { TNodeWithLexicalScope } from '../../../types/node/TNodeWithLexicalScope';
 
 
-import { IIdentifierNamesCacheStorage } from '../../../interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage';
+import { IGlobalIdentifierNamesCacheStorage } from '../../../interfaces/storages/identifier-names-cache/IGlobalIdentifierNamesCacheStorage';
 import { IIdentifierNamesGenerator } from '../../../interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator';
 import { IIdentifierNamesGenerator } from '../../../interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator';
 import { IIdentifierReplacer } from '../../../interfaces/node-transformers/rename-identifiers-transformers/replacer/IIdentifierReplacer';
 import { IIdentifierReplacer } from '../../../interfaces/node-transformers/rename-identifiers-transformers/replacer/IIdentifierReplacer';
 import { IOptions } from '../../../interfaces/options/IOptions';
 import { IOptions } from '../../../interfaces/options/IOptions';
@@ -16,9 +16,9 @@ import { NodeFactory } from '../../../node/NodeFactory';
 @injectable()
 @injectable()
 export class IdentifierReplacer implements IIdentifierReplacer {
 export class IdentifierReplacer implements IIdentifierReplacer {
     /**
     /**
-     * @type {IIdentifierNamesCacheStorage}
+     * @type {IGlobalIdentifierNamesCacheStorage}
      */
      */
-    private readonly identifierNamesCacheStorage: IIdentifierNamesCacheStorage;
+    private readonly identifierNamesCacheStorage: IGlobalIdentifierNamesCacheStorage;
 
 
     /**
     /**
      * @type {IIdentifierNamesGenerator}
      * @type {IIdentifierNamesGenerator}
@@ -37,14 +37,14 @@ export class IdentifierReplacer implements IIdentifierReplacer {
 
 
     /**
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
-     * @param {IIdentifierNamesCacheStorage} identifierNamesCacheStorage
+     * @param {IGlobalIdentifierNamesCacheStorage} identifierNamesCacheStorage
      * @param {IOptions} options
      * @param {IOptions} options
      */
      */
     public constructor (
     public constructor (
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
-        @inject(ServiceIdentifiers.IIdentifierNamesCacheStorage)
-            identifierNamesCacheStorage: IIdentifierNamesCacheStorage,
+        @inject(ServiceIdentifiers.IGlobalIdentifierNamesCacheStorage)
+            identifierNamesCacheStorage: IGlobalIdentifierNamesCacheStorage,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
     ) {
         this.options = options;
         this.options = options;

+ 6 - 6
src/node-transformers/rename-identifiers-transformers/through-replacer/ThroughIdentifierReplacer.ts

@@ -3,7 +3,7 @@ import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
 
 
 import * as ESTree from 'estree';
 import * as ESTree from 'estree';
 
 
-import { IIdentifierNamesCacheStorage } from '../../../interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage';
+import { IGlobalIdentifierNamesCacheStorage } from '../../../interfaces/storages/identifier-names-cache/IGlobalIdentifierNamesCacheStorage';
 import { IOptions } from '../../../interfaces/options/IOptions';
 import { IOptions } from '../../../interfaces/options/IOptions';
 import { IThroughIdentifierReplacer } from '../../../interfaces/node-transformers/rename-identifiers-transformers/replacer/IThroughIdentifierReplacer';
 import { IThroughIdentifierReplacer } from '../../../interfaces/node-transformers/rename-identifiers-transformers/replacer/IThroughIdentifierReplacer';
 
 
@@ -12,9 +12,9 @@ import { NodeFactory } from '../../../node/NodeFactory';
 @injectable()
 @injectable()
 export class ThroughIdentifierReplacer implements IThroughIdentifierReplacer {
 export class ThroughIdentifierReplacer implements IThroughIdentifierReplacer {
     /**
     /**
-     * @type {IIdentifierNamesCacheStorage}
+     * @type {IGlobalIdentifierNamesCacheStorage}
      */
      */
-    private readonly identifierNamesCacheStorage: IIdentifierNamesCacheStorage;
+    private readonly identifierNamesCacheStorage: IGlobalIdentifierNamesCacheStorage;
 
 
     /**
     /**
      * @type {IOptions}
      * @type {IOptions}
@@ -22,12 +22,12 @@ export class ThroughIdentifierReplacer implements IThroughIdentifierReplacer {
     private readonly options: IOptions;
     private readonly options: IOptions;
 
 
     /**
     /**
-     * @param {IIdentifierNamesCacheStorage} identifierNamesCacheStorage
+     * @param {IGlobalIdentifierNamesCacheStorage} identifierNamesCacheStorage
      * @param {IOptions} options
      * @param {IOptions} options
      */
      */
     public constructor (
     public constructor (
-        @inject(ServiceIdentifiers.IIdentifierNamesCacheStorage)
-            identifierNamesCacheStorage: IIdentifierNamesCacheStorage,
+        @inject(ServiceIdentifiers.IGlobalIdentifierNamesCacheStorage)
+            identifierNamesCacheStorage: IGlobalIdentifierNamesCacheStorage,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
     ) {
         this.identifierNamesCacheStorage = identifierNamesCacheStorage;
         this.identifierNamesCacheStorage = identifierNamesCacheStorage;

+ 22 - 2
src/node-transformers/rename-properties-transformers/replacer/RenamePropertiesReplacer.ts

@@ -7,8 +7,9 @@ import * as ESTree from 'estree';
 import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory';
 
 
 import { IIdentifierNamesGenerator } from '../../../interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator';
 import { IIdentifierNamesGenerator } from '../../../interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator';
-import { IRenamePropertiesReplacer } from '../../../interfaces/node-transformers/rename-properties-transformers/replacer/IRenamePropertiesReplacer';
 import { IOptions } from '../../../interfaces/options/IOptions';
 import { IOptions } from '../../../interfaces/options/IOptions';
+import { IPropertyIdentifierNamesCacheStorage } from '../../../interfaces/storages/identifier-names-cache/IPropertyIdentifierNamesCacheStorage';
+import { IRenamePropertiesReplacer } from '../../../interfaces/node-transformers/rename-properties-transformers/replacer/IRenamePropertiesReplacer';
 
 
 // eslint-disable-next-line import/no-internal-modules
 // eslint-disable-next-line import/no-internal-modules
 import ReservedDomProperties from './ReservedDomProperties.json';
 import ReservedDomProperties from './ReservedDomProperties.json';
@@ -38,6 +39,11 @@ export class RenamePropertiesReplacer implements IRenamePropertiesReplacer {
      */
      */
     private readonly excludedPropertyNames: Set<string> = new Set();
     private readonly excludedPropertyNames: Set<string> = new Set();
 
 
+    /**
+     * @type {IPropertyIdentifierNamesCacheStorage}
+     */
+    private readonly propertyIdentifierNamesCacheStorage: IPropertyIdentifierNamesCacheStorage;
+
     /**
     /**
      * @type {Map<string, string>}
      * @type {Map<string, string>}
      * @private
      * @private
@@ -51,14 +57,18 @@ export class RenamePropertiesReplacer implements IRenamePropertiesReplacer {
 
 
     /**
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
+     * @param {IPropertyIdentifierNamesCacheStorage} propertyIdentifierNamesCacheStorage
      * @param {IOptions} options
      * @param {IOptions} options
      */
      */
     public constructor (
     public constructor (
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
+        @inject(ServiceIdentifiers.IPropertyIdentifierNamesCacheStorage)
+            propertyIdentifierNamesCacheStorage: IPropertyIdentifierNamesCacheStorage,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
     ) {
         this.identifierNamesGenerator = identifierNamesGeneratorFactory(options);
         this.identifierNamesGenerator = identifierNamesGeneratorFactory(options);
+        this.propertyIdentifierNamesCacheStorage = propertyIdentifierNamesCacheStorage;
         this.options = options;
         this.options = options;
     }
     }
 
 
@@ -99,7 +109,13 @@ export class RenamePropertiesReplacer implements IRenamePropertiesReplacer {
             return propertyName;
             return propertyName;
         }
         }
 
 
-        let renamedPropertyName: string | null = this.propertyNamesMap.get(propertyName) ?? null;
+        let renamedPropertyName: string | null = this.options.identifierNamesCache
+            ? this.propertyIdentifierNamesCacheStorage.get(propertyName) ?? null
+            : null;
+
+        renamedPropertyName = renamedPropertyName
+            ?? this.propertyNamesMap.get(propertyName)
+            ?? null;
 
 
         if (renamedPropertyName !== null) {
         if (renamedPropertyName !== null) {
             return renamedPropertyName;
             return renamedPropertyName;
@@ -108,6 +124,10 @@ export class RenamePropertiesReplacer implements IRenamePropertiesReplacer {
         renamedPropertyName = this.identifierNamesGenerator.generateNext();
         renamedPropertyName = this.identifierNamesGenerator.generateNext();
         this.propertyNamesMap.set(propertyName, renamedPropertyName);
         this.propertyNamesMap.set(propertyName, renamedPropertyName);
 
 
+        if (this.options.identifierNamesCache) {
+            this.propertyIdentifierNamesCacheStorage.set(propertyName, renamedPropertyName);
+        }
+
         return renamedPropertyName;
         return renamedPropertyName;
     }
     }
 
 

+ 19 - 9
src/source-code/ObfuscationResult.ts

@@ -4,8 +4,9 @@ import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
 import { TIdentifierNamesCache } from '../types/TIdentifierNamesCache';
 import { TIdentifierNamesCache } from '../types/TIdentifierNamesCache';
 
 
 import { ICryptUtils } from '../interfaces/utils/ICryptUtils';
 import { ICryptUtils } from '../interfaces/utils/ICryptUtils';
-import { IIdentifierNamesCacheStorage } from '../interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage';
+import { IGlobalIdentifierNamesCacheStorage } from '../interfaces/storages/identifier-names-cache/IGlobalIdentifierNamesCacheStorage';
 import { IObfuscationResult } from '../interfaces/source-code/IObfuscationResult';
 import { IObfuscationResult } from '../interfaces/source-code/IObfuscationResult';
+import { IPropertyIdentifierNamesCacheStorage } from '../interfaces/storages/identifier-names-cache/IPropertyIdentifierNamesCacheStorage';
 import { IOptions } from '../interfaces/options/IOptions';
 import { IOptions } from '../interfaces/options/IOptions';
 
 
 import { initializable } from '../decorators/Initializable';
 import { initializable } from '../decorators/Initializable';
@@ -31,9 +32,14 @@ export class ObfuscationResult implements IObfuscationResult {
     private readonly cryptUtils: ICryptUtils;
     private readonly cryptUtils: ICryptUtils;
 
 
     /**
     /**
-     * @type {IIdentifierNamesCacheStorage}
+     * @type {IGlobalIdentifierNamesCacheStorage}
      */
      */
-    private readonly identifierNamesCacheStorage: IIdentifierNamesCacheStorage;
+    private readonly globalIdentifierNamesCacheStorage: IGlobalIdentifierNamesCacheStorage;
+
+    /**
+     * @type {IPropertyIdentifierNamesCacheStorage}
+     */
+    private readonly propertyIdentifierNamesCacheStorage: IPropertyIdentifierNamesCacheStorage;
 
 
     /**
     /**
      * @type {IOptions}
      * @type {IOptions}
@@ -42,17 +48,21 @@ export class ObfuscationResult implements IObfuscationResult {
 
 
     /**
     /**
      * @param {ICryptUtils} cryptUtils
      * @param {ICryptUtils} cryptUtils
-     * @param {IIdentifierNamesCacheStorage} identifierNamesCacheStorage
+     * @param {IGlobalIdentifierNamesCacheStorage} globalIdentifierNamesCacheStorage
+     * @param {IPropertyIdentifierNamesCacheStorage} propertyIdentifierNamesCacheStorage
      * @param {IOptions} options
      * @param {IOptions} options
      */
      */
     public constructor (
     public constructor (
         @inject(ServiceIdentifiers.ICryptUtils) cryptUtils: ICryptUtils,
         @inject(ServiceIdentifiers.ICryptUtils) cryptUtils: ICryptUtils,
-        @inject(ServiceIdentifiers.IIdentifierNamesCacheStorage)
-            identifierNamesCacheStorage: IIdentifierNamesCacheStorage,
+        @inject(ServiceIdentifiers.IGlobalIdentifierNamesCacheStorage)
+            globalIdentifierNamesCacheStorage: IGlobalIdentifierNamesCacheStorage,
+        @inject(ServiceIdentifiers.IPropertyIdentifierNamesCacheStorage)
+            propertyIdentifierNamesCacheStorage: IPropertyIdentifierNamesCacheStorage,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
     ) {
         this.cryptUtils = cryptUtils;
         this.cryptUtils = cryptUtils;
-        this.identifierNamesCacheStorage = identifierNamesCacheStorage;
+        this.globalIdentifierNamesCacheStorage = globalIdentifierNamesCacheStorage;
+        this.propertyIdentifierNamesCacheStorage = propertyIdentifierNamesCacheStorage;
         this.options = options;
         this.options = options;
     }
     }
 
 
@@ -74,8 +84,8 @@ export class ObfuscationResult implements IObfuscationResult {
         }
         }
 
 
         return {
         return {
-            globalIdentifiers: this.identifierNamesCacheStorage.getStorageAsDictionary(),
-            propertyIdentifiers: {}
+            globalIdentifiers: this.globalIdentifierNamesCacheStorage.getStorageAsDictionary(),
+            propertyIdentifiers: this.propertyIdentifierNamesCacheStorage.getStorageAsDictionary()
         };
         };
     }
     }
 
 

+ 2 - 2
src/storages/identifier-names-cache/IdentifierNamesCacheStorage.ts → src/storages/identifier-names-cache/GlobalIdentifierNamesCacheStorage.ts

@@ -1,14 +1,14 @@
 import { inject, injectable, postConstruct } from 'inversify';
 import { inject, injectable, postConstruct } from 'inversify';
 import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
 
-import { IIdentifierNamesCacheStorage } from '../../interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage';
+import { IGlobalIdentifierNamesCacheStorage } from '../../interfaces/storages/identifier-names-cache/IGlobalIdentifierNamesCacheStorage';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
 
 
 import { MapStorage } from '../MapStorage';
 import { MapStorage } from '../MapStorage';
 
 
 @injectable()
 @injectable()
-export class IdentifierNamesCacheStorage extends MapStorage <string, string> implements IIdentifierNamesCacheStorage {
+export class GlobalIdentifierNamesCacheStorage extends MapStorage <string, string> implements IGlobalIdentifierNamesCacheStorage {
    /**
    /**
      * @param {IRandomGenerator} randomGenerator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      * @param {IOptions} options

+ 29 - 0
src/storages/identifier-names-cache/PropertyIdentifierNamesCacheStorage.ts

@@ -0,0 +1,29 @@
+import { inject, injectable, postConstruct } from 'inversify';
+import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
+
+import { IOptions } from '../../interfaces/options/IOptions';
+import { IPropertyIdentifierNamesCacheStorage } from '../../interfaces/storages/identifier-names-cache/IPropertyIdentifierNamesCacheStorage';
+import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
+
+import { MapStorage } from '../MapStorage';
+
+@injectable()
+export class PropertyIdentifierNamesCacheStorage extends MapStorage <string, string> implements IPropertyIdentifierNamesCacheStorage {
+   /**
+     * @param {IRandomGenerator} randomGenerator
+     * @param {IOptions} options
+     */
+    public constructor (
+        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
+        @inject(ServiceIdentifiers.IOptions) options: IOptions
+    ) {
+        super(randomGenerator, options);
+    }
+
+    @postConstruct()
+    public override initialize (): void {
+       super.initialize();
+
+        this.storage = new Map(Object.entries(this.options.identifierNamesCache?.propertyIdentifiers ?? {}));
+    }
+}

+ 5 - 4
test/dev/dev.ts

@@ -6,20 +6,21 @@
     let obfuscationResult = JavaScriptObfuscator.obfuscate(
     let obfuscationResult = JavaScriptObfuscator.obfuscate(
         `
         `
             function foo() {
             function foo() {
-               var baz = 1; 
+               global.baz = 3;
             }
             }
             
             
             function bar(...args) {
             function bar(...args) {
-                var bark = 2;
+                console.log(2);
             }
             }
         `,
         `,
         {
         {
             compact: false,
             compact: false,
             identifierNamesCache: {
             identifierNamesCache: {
-                globalIdentifiers: { foo: '_0x5de86d', bar: '_0x2a943b' },
+                globalIdentifiers: {},
                 propertyIdentifiers: {}
                 propertyIdentifiers: {}
             },
             },
-            renameGlobals: true
+            renameGlobals: true,
+            renameProperties: true
         }
         }
     );
     );
 
 

+ 2 - 1
test/index.spec.ts

@@ -36,7 +36,8 @@ import './unit-tests/source-code/ObfuscationResult.spec';
 import './unit-tests/source-code/SourceCode.spec';
 import './unit-tests/source-code/SourceCode.spec';
 import './unit-tests/storages/ArrayStorage.spec';
 import './unit-tests/storages/ArrayStorage.spec';
 import './unit-tests/storages/MapStorage.spec';
 import './unit-tests/storages/MapStorage.spec';
-import './unit-tests/storages/identifier-names-cache/IdentifierNamesCacheStorage.spec';
+import './unit-tests/storages/identifier-names-cache/GlobalIdentifierNamesCacheStorage.spec';
+import './unit-tests/storages/identifier-names-cache/PropertyIdentifierNamesCacheStorage.spec';
 import './unit-tests/storages/string-array-transformers/literal-nodes-cache/LiteralNodesCacheStorage.spec';
 import './unit-tests/storages/string-array-transformers/literal-nodes-cache/LiteralNodesCacheStorage.spec';
 import './unit-tests/storages/string-array-transformers/string-array/StringArrayStorage.spec';
 import './unit-tests/storages/string-array-transformers/string-array/StringArrayStorage.spec';
 import './unit-tests/storages/string-array-transformers/visited-lexical-scope-nodes-stack/VisitedLexicalScopeNodesStackStorage.spec';
 import './unit-tests/storages/string-array-transformers/visited-lexical-scope-nodes-stack/VisitedLexicalScopeNodesStackStorage.spec';

+ 7 - 7
test/unit-tests/storages/identifier-names-cache/IdentifierNamesCacheStorage.spec.ts → test/unit-tests/storages/identifier-names-cache/GlobalIdentifierNamesCacheStorage.spec.ts

@@ -6,24 +6,24 @@ import { ServiceIdentifiers } from '../../../../src/container/ServiceIdentifiers
 
 
 import { TDictionary } from '../../../../src/types/TDictionary';
 import { TDictionary } from '../../../../src/types/TDictionary';
 
 
-import { IIdentifierNamesCacheStorage } from '../../../../src/interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage';
+import { IGlobalIdentifierNamesCacheStorage } from '../../../../src/interfaces/storages/identifier-names-cache/IGlobalIdentifierNamesCacheStorage';
 import { IInversifyContainerFacade } from '../../../../src/interfaces/container/IInversifyContainerFacade';
 import { IInversifyContainerFacade } from '../../../../src/interfaces/container/IInversifyContainerFacade';
 import { IOptions } from '../../../../src/interfaces/options/IOptions';
 import { IOptions } from '../../../../src/interfaces/options/IOptions';
 import { IRandomGenerator } from '../../../../src/interfaces/utils/IRandomGenerator';
 import { IRandomGenerator } from '../../../../src/interfaces/utils/IRandomGenerator';
 
 
 import { DEFAULT_PRESET } from '../../../../src/options/presets/Default';
 import { DEFAULT_PRESET } from '../../../../src/options/presets/Default';
 
 
-import { IdentifierNamesCacheStorage } from '../../../../src/storages/identifier-names-cache/IdentifierNamesCacheStorage';
+import { GlobalIdentifierNamesCacheStorage } from '../../../../src/storages/identifier-names-cache/GlobalIdentifierNamesCacheStorage';
 import { InversifyContainerFacade } from '../../../../src/container/InversifyContainerFacade';
 import { InversifyContainerFacade } from '../../../../src/container/InversifyContainerFacade';
 
 
 /**
 /**
- * @returns {IIdentifierNamesCacheStorage}
+ * @returns {IGlobalIdentifierNamesCacheStorage}
  */
  */
-const getStorageInstance = <V>(options: Partial<IOptions> = DEFAULT_PRESET): IIdentifierNamesCacheStorage => {
+const getStorageInstance = <V>(options: Partial<IOptions> = DEFAULT_PRESET): IGlobalIdentifierNamesCacheStorage => {
     const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
     const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
     inversifyContainerFacade.load('', '', {});
     inversifyContainerFacade.load('', '', {});
 
 
-    const storage: IIdentifierNamesCacheStorage = new IdentifierNamesCacheStorage (
+    const storage: IGlobalIdentifierNamesCacheStorage = new GlobalIdentifierNamesCacheStorage (
         inversifyContainerFacade.get<IRandomGenerator>(ServiceIdentifiers.IRandomGenerator),
         inversifyContainerFacade.get<IRandomGenerator>(ServiceIdentifiers.IRandomGenerator),
         {
         {
             ...DEFAULT_PRESET,
             ...DEFAULT_PRESET,
@@ -36,11 +36,11 @@ const getStorageInstance = <V>(options: Partial<IOptions> = DEFAULT_PRESET): IId
     return storage;
     return storage;
 };
 };
 
 
-describe('IdentifierNamesCacheStorage', () => {
+describe('GlobalIdentifierNamesCacheStorage', () => {
     const storageKey: string = 'foo';
     const storageKey: string = 'foo';
     const storageValue: string = 'bar';
     const storageValue: string = 'bar';
 
 
-    let storage: IIdentifierNamesCacheStorage;
+    let storage: IGlobalIdentifierNamesCacheStorage;
 
 
     describe('initialize', () => {
     describe('initialize', () => {
         describe('Variant #1: `identifierNamesCache` option values is object', () => {
         describe('Variant #1: `identifierNamesCache` option values is object', () => {

+ 110 - 0
test/unit-tests/storages/identifier-names-cache/PropertyIdentifierNamesCacheStorage.spec.ts

@@ -0,0 +1,110 @@
+import 'reflect-metadata';
+
+import { assert } from 'chai';
+
+import { ServiceIdentifiers } from '../../../../src/container/ServiceIdentifiers';
+
+import { TDictionary } from '../../../../src/types/TDictionary';
+
+import { IPropertyIdentifierNamesCacheStorage } from '../../../../src/interfaces/storages/identifier-names-cache/IPropertyIdentifierNamesCacheStorage';
+import { IInversifyContainerFacade } from '../../../../src/interfaces/container/IInversifyContainerFacade';
+import { IOptions } from '../../../../src/interfaces/options/IOptions';
+import { IRandomGenerator } from '../../../../src/interfaces/utils/IRandomGenerator';
+
+import { DEFAULT_PRESET } from '../../../../src/options/presets/Default';
+
+import { InversifyContainerFacade } from '../../../../src/container/InversifyContainerFacade';
+import { PropertyIdentifierNamesCacheStorage } from '../../../../src/storages/identifier-names-cache/PropertyIdentifierNamesCacheStorage';
+
+/**
+ * @returns {IPropertyIdentifierNamesCacheStorage}
+ */
+const getStorageInstance = <V>(options: Partial<IOptions> = DEFAULT_PRESET): IPropertyIdentifierNamesCacheStorage => {
+    const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
+    inversifyContainerFacade.load('', '', {});
+
+    const storage: IPropertyIdentifierNamesCacheStorage = new PropertyIdentifierNamesCacheStorage(
+        inversifyContainerFacade.get<IRandomGenerator>(ServiceIdentifiers.IRandomGenerator),
+        {
+            ...DEFAULT_PRESET,
+            ...options as IOptions
+        }
+    );
+
+    storage.initialize();
+
+    return storage;
+};
+
+describe('PropertyIdentifierNamesCacheStorage', () => {
+    const storageKey: string = 'foo';
+    const storageValue: string = 'bar';
+
+    let storage: IPropertyIdentifierNamesCacheStorage;
+
+    describe('initialize', () => {
+        describe('Variant #1: `identifierNamesCache` option values is object', () => {
+            const expectedDictionary: TDictionary<string> = {
+                [storageKey]: storageValue
+            };
+
+            let dictionary: TDictionary<string>;
+
+            before(() => {
+                storage = getStorageInstance({
+                    identifierNamesCache: {
+                        globalIdentifiers: {},
+                        propertyIdentifiers: {
+                            [storageKey]: storageValue
+                        }
+                    }
+                });
+
+                dictionary = storage.getStorageAsDictionary();
+            });
+
+            it('should initialize storage with `identifierNamesStorage` option object', () => {
+                assert.deepEqual(dictionary, expectedDictionary);
+            });
+        });
+
+        describe('Variant #2: `identifierNamesCache` option values is empty object', () => {
+            const expectedDictionary: TDictionary<string> = {};
+
+            let dictionary: TDictionary<string>;
+
+            before(() => {
+                storage = getStorageInstance({
+                    identifierNamesCache: {
+                        globalIdentifiers: {},
+                        propertyIdentifiers: {}
+                    }
+                });
+
+                dictionary = storage.getStorageAsDictionary();
+            });
+
+            it('should initialize storage with `identifierNamesStorage` option object', () => {
+                assert.deepEqual(dictionary, expectedDictionary);
+            });
+        });
+
+        describe('Variant #3: `identifierNamesCache` option values is `null`', () => {
+            const expectedDictionary: TDictionary<string> = {};
+
+            let dictionary: TDictionary<string>;
+
+            before(() => {
+                storage = getStorageInstance({
+                    identifierNamesCache: null
+                });
+
+                dictionary = storage.getStorageAsDictionary();
+            });
+
+            it('should initialize storage with `identifierNamesStorage` option object', () => {
+                assert.deepEqual(dictionary, expectedDictionary);
+            });
+        });
+    });
+});

Some files were not shown because too many files changed in this diff