Переглянути джерело

Changed identifier names cache structure to store multiple identifier caches

sanex 4 роки тому
батько
коміт
f32bcf29a8
21 змінених файлів з 264 додано та 148 видалено
  1. 0 0
      dist/index.browser.js
  2. 0 0
      dist/index.cli.js
  3. 0 0
      dist/index.js
  4. 5 2
      src/cli/utils/IdentifierNamesCacheUtils.ts
  5. 1 1
      src/interfaces/options/IOptions.ts
  6. 1 1
      src/interfaces/source-code/IObfuscationResult.ts
  7. 2 8
      src/interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage.ts
  8. 3 3
      src/options/Options.ts
  9. 41 16
      src/options/validators/IsIdentifierNamesCache.ts
  10. 9 2
      src/source-code/ObfuscationResult.ts
  11. 1 14
      src/storages/identifier-names-cache/IdentifierNamesCacheStorage.ts
  12. 7 0
      src/types/TIdentifierNamesCache.ts
  13. 3 0
      src/types/TIdentifierNamesCacheDictionary.ts
  14. 0 3
      src/types/storages/TIdentifierNamesCache.ts
  15. 4 1
      test/dev/dev.ts
  16. 28 10
      test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts
  17. 12 3
      test/functional-tests/node-transformers/rename-identifiers-transformers/scope-through-identifiers-transformer/class-declaration/ClassDeclaration.spec.ts
  18. 12 3
      test/functional-tests/node-transformers/rename-identifiers-transformers/scope-through-identifiers-transformer/function-declaration/FunctionDeclaration.spec.ts
  19. 28 7
      test/functional-tests/node-transformers/rename-identifiers-transformers/scope-through-identifiers-transformer/variable-declaration/VariableDeclaration.spec.ts
  20. 99 12
      test/functional-tests/options/identifier-names-cache/Validation.spec.ts
  21. 8 62
      test/unit-tests/storages/identifier-names-cache/IdentifierNamesCacheStorage.spec.ts

Різницю між файлами не показано, бо вона завелика
+ 0 - 0
dist/index.browser.js


Різницю між файлами не показано, бо вона завелика
+ 0 - 0
dist/index.cli.js


Різницю між файлами не показано, бо вона завелика
+ 0 - 0
dist/index.js


+ 5 - 2
src/cli/utils/IdentifierNamesCacheUtils.ts

@@ -1,7 +1,7 @@
 import * as fs from 'fs';
 import * as path from 'path';
 
-import { TIdentifierNamesCache } from '../../types/storages/TIdentifierNamesCache';
+import { TIdentifierNamesCache } from '../../types/TIdentifierNamesCache';
 
 import { IFileData } from '../../interfaces/cli/IFileData';
 
@@ -70,7 +70,10 @@ export class IdentifierNamesCacheUtils {
 
         if (!fileData.content) {
             // Initial state of identifier names cache file
-            return {};
+            return {
+                globalIdentifiers: {},
+                propertyIdentifiers: {}
+            };
         }
 
         try {

+ 1 - 1
src/interfaces/options/IOptions.ts

@@ -1,4 +1,4 @@
-import { TIdentifierNamesCache } from '../../types/storages/TIdentifierNamesCache';
+import { TIdentifierNamesCache } from '../../types/TIdentifierNamesCache';
 import { TOptionsPreset } from '../../types/options/TOptionsPreset';
 import { TStringArrayIndexesType } from '../../types/options/TStringArrayIndexesType';
 import { TStringArrayEncoding } from '../../types/options/TStringArrayEncoding';

+ 1 - 1
src/interfaces/source-code/IObfuscationResult.ts

@@ -1,4 +1,4 @@
-import { TIdentifierNamesCache } from '../../types/storages/TIdentifierNamesCache';
+import { TIdentifierNamesCache } from '../../types/TIdentifierNamesCache';
 import { IInitializable } from '../IInitializable';
 
 export interface IObfuscationResult extends IInitializable <[string, string]> {

+ 2 - 8
src/interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage.ts

@@ -1,10 +1,4 @@
-import { TIdentifierNamesCache } from '../../../types/storages/TIdentifierNamesCache';
-
 import { IMapStorage } from '../IMapStorage';
 
-export interface IIdentifierNamesCacheStorage extends Omit<IMapStorage <string, string>, 'getStorage'> {
-    /**
-     * @returns {TIdentifierNamesCache}
-     */
-    getCache (): TIdentifierNamesCache;
-}
+// eslint-disable-next-line
+export interface IIdentifierNamesCacheStorage extends IMapStorage <string, string> {}

+ 3 - 3
src/options/Options.ts

@@ -18,7 +18,7 @@ import {
     ValidatorOptions
 } from 'class-validator';
 
-import { TIdentifierNamesCache } from '../types/storages/TIdentifierNamesCache';
+import { TIdentifierNamesCache } from '../types/TIdentifierNamesCache';
 import { TInputOptions } from '../types/options/TInputOptions';
 import { TOptionsPreset } from '../types/options/TOptionsPreset';
 import { TRenamePropertiesMode } from '../types/options/TRenamePropertiesMode';
@@ -46,7 +46,7 @@ import { HIGH_OBFUSCATION_PRESET } from './presets/HighObfuscation';
 
 import { ValidationErrorsFormatter } from './ValidationErrorsFormatter';
 import { IsAllowedForObfuscationTargets } from './validators/IsAllowedForObfuscationTargets';
-import { IsPrimitiveDictionary } from './validators/IsPrimitiveDictionary';
+import { IsIdentifierNamesCache } from './validators/IsIdentifierNamesCache';
 
 @injectable()
 export class Options implements IOptions {
@@ -147,7 +147,7 @@ export class Options implements IOptions {
     /**
      * @type {TIdentifierNamesCache}
      */
-    @IsPrimitiveDictionary('string')
+    @IsIdentifierNamesCache()
     public readonly identifierNamesCache!: TIdentifierNamesCache;
 
     /**

+ 41 - 16
src/options/validators/IsPrimitiveDictionary.ts → src/options/validators/IsIdentifierNamesCache.ts

@@ -1,24 +1,53 @@
 import equal from 'fast-deep-equal';
 import { registerDecorator, ValidationArguments, ValidationOptions } from 'class-validator';
 
+import { TIdentifierNamesCache } from '../../types/TIdentifierNamesCache';
+import { TIdentifierNamesCacheDictionary } from '../../types/TIdentifierNamesCacheDictionary';
+
 import { IOptions } from '../../interfaces/options/IOptions';
 
 import { DEFAULT_PRESET } from '../presets/Default';
 
 /**
- * @param {"string" | "number"} valuesType
+ * @param value
+ * @returns {boolean}
+ */
+const validateDictionary = (value: unknown | TIdentifierNamesCacheDictionary): boolean => {
+    if (typeof value !== 'object') {
+        return false;
+    }
+
+    if (value === null) {
+        return false;
+    }
+
+    const objectValues: unknown[] = Object.values(value);
+
+    if (!objectValues.length) {
+        return true;
+    }
+
+    for (const objectValue of objectValues) {
+        if (typeof objectValue !== 'string') {
+            return false;
+        }
+    }
+
+    return true;
+};
+
+/**
  * @param {ValidationOptions} validationOptions
  * @returns {(options: IOptions, propertyName: keyof IOptions) => void}
  */
-export function IsPrimitiveDictionary (
-    valuesType: 'string' | 'number',
+export function IsIdentifierNamesCache (
     validationOptions?: ValidationOptions
 ): (options: IOptions, propertyName: keyof IOptions) => void {
     return (optionsObject: IOptions, propertyName: keyof IOptions): void => {
         registerDecorator({
             propertyName,
-            constraints: [valuesType],
-            name: 'IsPrimitiveDictionary',
+            constraints: [],
+            name: 'IsIdentifierNamesCache',
             options: validationOptions,
             target: optionsObject.constructor,
             validator: {
@@ -27,7 +56,7 @@ export function IsPrimitiveDictionary (
                  * @param {ValidationArguments} validationArguments
                  * @returns {boolean}
                  */
-                validate (value: IOptions[keyof IOptions], validationArguments: ValidationArguments): boolean {
+                validate (value: unknown, validationArguments: ValidationArguments): boolean {
                     const defaultValue: IOptions[keyof IOptions] | undefined = DEFAULT_PRESET[propertyName];
                     const isDefaultValue: boolean = equal(value, defaultValue);
 
@@ -39,26 +68,22 @@ export function IsPrimitiveDictionary (
                         return false;
                     }
 
-                    const objectValues: unknown[] = Object.values<unknown>(value);
-
-                    if (!objectValues.length) {
-                        return true;
+                    if (value === null) {
+                        return false;
                     }
 
-                    for (const objectValue of objectValues) {
-                        if (typeof objectValue !== 'string') {
-                            return false;
-                        }
+                    if (!validateDictionary((<TIdentifierNamesCache>value)?.globalIdentifiers)) {
+                        return false;
                     }
 
-                    return true;
+                    return validateDictionary((<TIdentifierNamesCache>value)?.propertyIdentifiers);
                 },
 
                 /**
                  * @returns {string}
                  */
                 defaultMessage (): string {
-                    return `Passed value must be a dictionary with \`${valuesType}\` values or \`null\` value`;
+                    return 'Passed value must be an identifier names cache object or `null` value';
                 }
             }
         });

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

@@ -1,7 +1,7 @@
 import { inject, injectable } from 'inversify';
 import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
 
-import { TIdentifierNamesCache } from '../types/storages/TIdentifierNamesCache';
+import { TIdentifierNamesCache } from '../types/TIdentifierNamesCache';
 
 import { ICryptUtils } from '../interfaces/utils/ICryptUtils';
 import { IIdentifierNamesCacheStorage } from '../interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage';
@@ -69,7 +69,14 @@ export class ObfuscationResult implements IObfuscationResult {
      * @returns {string}
      */
     public getIdentifierNamesCache (): TIdentifierNamesCache {
-        return this.identifierNamesCacheStorage.getCache();
+        if (!this.options.identifierNamesCache) {
+            return null;
+        }
+
+        return {
+            globalIdentifiers: this.identifierNamesCacheStorage.getStorageAsDictionary(),
+            propertyIdentifiers: {}
+        };
     }
 
     /**

+ 1 - 14
src/storages/identifier-names-cache/IdentifierNamesCacheStorage.ts

@@ -1,8 +1,6 @@
 import { inject, injectable, postConstruct } from 'inversify';
 import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
-import { TIdentifierNamesCache } from '../../types/storages/TIdentifierNamesCache';
-
 import { IIdentifierNamesCacheStorage } from '../../interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
@@ -26,17 +24,6 @@ export class IdentifierNamesCacheStorage extends MapStorage <string, string> imp
     public override initialize (): void {
        super.initialize();
 
-        this.storage = new Map(Object.entries(this.options.identifierNamesCache ?? {}));
-    }
-
-    /**
-     * @returns {TIdentifierNamesCache}
-     */
-    public getCache (): TIdentifierNamesCache {
-        if (!this.options.identifierNamesCache) {
-            return null;
-        }
-
-        return this.getStorageAsDictionary();
+        this.storage = new Map(Object.entries(this.options.identifierNamesCache?.globalIdentifiers ?? {}));
     }
 }

+ 7 - 0
src/types/TIdentifierNamesCache.ts

@@ -0,0 +1,7 @@
+import { TIdentifierNamesCacheDictionary } from './TIdentifierNamesCacheDictionary';
+
+export type TIdentifierNamesCache = {
+    globalIdentifiers: TIdentifierNamesCacheDictionary;
+    propertyIdentifiers: TIdentifierNamesCacheDictionary;
+} | null;
+

+ 3 - 0
src/types/TIdentifierNamesCacheDictionary.ts

@@ -0,0 +1,3 @@
+import { TDictionary } from './TDictionary';
+
+export type TIdentifierNamesCacheDictionary = TDictionary<string>;

+ 0 - 3
src/types/storages/TIdentifierNamesCache.ts

@@ -1,3 +0,0 @@
-import { TDictionary } from '../TDictionary';
-
-export type TIdentifierNamesCache = TDictionary<string> | null;

+ 4 - 1
test/dev/dev.ts

@@ -15,7 +15,10 @@
         `,
         {
             compact: false,
-            identifierNamesCache: { foo: '_0x5de86d', bar: '_0x2a943b' },
+            identifierNamesCache: {
+                globalIdentifiers: { foo: '_0x5de86d', bar: '_0x2a943b' },
+                propertyIdentifiers: {}
+            },
             renameGlobals: true
         }
     );

+ 28 - 10
test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts

@@ -1,6 +1,7 @@
 import { assert } from 'chai';
 
 import { TDictionary } from '../../../src/types/TDictionary';
+import { TIdentifierNamesCache } from '../../../src/types/TIdentifierNamesCache';
 import { TInputOptions } from '../../../src/types/options/TInputOptions';
 import { TOptionsPreset } from '../../../src/types/options/TOptionsPreset';
 import { TTypeFromEnum } from '../../../src/types/utils/TTypeFromEnum';
@@ -23,7 +24,6 @@ import { OptionsPreset } from '../../../src/enums/options/presets/OptionsPreset'
 import { buildLargeCode } from '../../helpers/buildLargeCode';
 import { getRegExpMatch } from '../../helpers/getRegExpMatch';
 import { readFileAsString } from '../../helpers/readFileAsString';
-import { TIdentifierNamesCache } from '../../../src/types/storages/TIdentifierNamesCache';
 
 describe('JavaScriptObfuscator', () => {
     describe('obfuscate', () => {
@@ -916,9 +916,12 @@ describe('JavaScriptObfuscator', () => {
         describe('identifier names cache generation', () => {
             describe('Variant #1: `identifierNamesCache` and `renameGlobal` options are enabled. Existing cache is passed', () => {
                 const expectedIdentifierNamesCache: TIdentifierNamesCache = {
-                    foo: 'a',
-                    bar: 'b',
-                    baz: 'baz_value_from_cache'
+                    globalIdentifiers: {
+                        foo: 'a',
+                        bar: 'b',
+                        baz: 'baz_value_from_cache'
+                    },
+                    propertyIdentifiers: {}
                 };
 
                 let identifierNamesCache: TIdentifierNamesCache;
@@ -932,7 +935,10 @@ describe('JavaScriptObfuscator', () => {
                             ...NO_ADDITIONAL_NODES_PRESET,
                             renameGlobals: true,
                             identifierNamesCache: {
-                                baz: 'baz_value_from_cache'
+                                globalIdentifiers: {
+                                    baz: 'baz_value_from_cache'
+                                },
+                                propertyIdentifiers: {}
                             },
                             identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator
                         }
@@ -946,8 +952,11 @@ describe('JavaScriptObfuscator', () => {
 
             describe('Variant #2: `identifierNamesCache` and `renameGlobal` options are enabled', () => {
                 const expectedIdentifierNamesCache: TIdentifierNamesCache = {
-                    foo: 'a',
-                    bar: 'b'
+                    globalIdentifiers: {
+                        foo: 'a',
+                        bar: 'b'
+                    },
+                    propertyIdentifiers: {}
                 };
 
                 let identifierNamesCache: TIdentifierNamesCache;
@@ -960,7 +969,10 @@ describe('JavaScriptObfuscator', () => {
                         {
                             ...NO_ADDITIONAL_NODES_PRESET,
                             renameGlobals: true,
-                            identifierNamesCache: {},
+                            identifierNamesCache: {
+                                globalIdentifiers: {},
+                                propertyIdentifiers: {}
+                            },
                             identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator
                         }
                     ).getIdentifierNamesCache();
@@ -972,7 +984,10 @@ describe('JavaScriptObfuscator', () => {
             });
 
             describe('Variant #3: `identifierNamesCache` and `renameGlobal` options are enabled. Source code without global variables', () => {
-                const expectedIdentifierNamesCache: TIdentifierNamesCache = {};
+                const expectedIdentifierNamesCache: TIdentifierNamesCache = {
+                    globalIdentifiers: {},
+                    propertyIdentifiers: {}
+                };
 
                 let identifierNamesCache: TIdentifierNamesCache;
 
@@ -984,7 +999,10 @@ describe('JavaScriptObfuscator', () => {
                         {
                             ...NO_ADDITIONAL_NODES_PRESET,
                             renameGlobals: true,
-                            identifierNamesCache: {},
+                            identifierNamesCache: {
+                                globalIdentifiers: {},
+                                propertyIdentifiers: {}
+                            },
                             identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator
                         }
                     ).getIdentifierNamesCache();

+ 12 - 3
test/functional-tests/node-transformers/rename-identifiers-transformers/scope-through-identifiers-transformer/class-declaration/ClassDeclaration.spec.ts

@@ -22,7 +22,10 @@ describe('ScopeThroughIdentifiersTransformer ClassDeclaration identifiers', () =
                     ...NO_ADDITIONAL_NODES_PRESET,
                     renameGlobals: true,
                     identifierNamesCache: {
-                        'Foo': 'Foo_from_cache'
+                        globalIdentifiers: {
+                            'Foo': 'Foo_from_cache'
+                        },
+                        propertyIdentifiers: {}
                     }
                 }
             ).getObfuscatedCode();
@@ -52,7 +55,10 @@ describe('ScopeThroughIdentifiersTransformer ClassDeclaration identifiers', () =
                         ...NO_ADDITIONAL_NODES_PRESET,
                         renameGlobals: true,
                         identifierNamesCache: {
-                            'Foo': 'Foo_from_cache'
+                            globalIdentifiers: {
+                                'Foo': 'Foo_from_cache'
+                            },
+                            propertyIdentifiers: {}
                         }
                     }
                 ).getObfuscatedCode();
@@ -76,7 +82,10 @@ describe('ScopeThroughIdentifiersTransformer ClassDeclaration identifiers', () =
                     {
                         ...NO_ADDITIONAL_NODES_PRESET,
                         renameGlobals: true,
-                        identifierNamesCache: {}
+                        identifierNamesCache: {
+                            globalIdentifiers: {},
+                            propertyIdentifiers: {}
+                        }
                     }
                 ).getObfuscatedCode();
             });

+ 12 - 3
test/functional-tests/node-transformers/rename-identifiers-transformers/scope-through-identifiers-transformer/function-declaration/FunctionDeclaration.spec.ts

@@ -22,7 +22,10 @@ describe('ScopeThroughIdentifiersTransformer FunctionDeclaration identifiers', (
                     ...NO_ADDITIONAL_NODES_PRESET,
                     renameGlobals: true,
                     identifierNamesCache: {
-                        'foo': 'foo_from_cache'
+                        globalIdentifiers: {
+                            'foo': 'foo_from_cache'
+                        },
+                        propertyIdentifiers: {}
                     }
                 }
             ).getObfuscatedCode();
@@ -52,7 +55,10 @@ describe('ScopeThroughIdentifiersTransformer FunctionDeclaration identifiers', (
                         ...NO_ADDITIONAL_NODES_PRESET,
                         renameGlobals: true,
                         identifierNamesCache: {
-                            'foo': 'foo_from_cache'
+                            globalIdentifiers: {
+                                'foo': 'foo_from_cache'
+                            },
+                            propertyIdentifiers: {}
                         }
                     }
                 ).getObfuscatedCode();
@@ -76,7 +82,10 @@ describe('ScopeThroughIdentifiersTransformer FunctionDeclaration identifiers', (
                     {
                         ...NO_ADDITIONAL_NODES_PRESET,
                         renameGlobals: true,
-                        identifierNamesCache: {}
+                        identifierNamesCache: {
+                            globalIdentifiers: {},
+                            propertyIdentifiers: {}
+                        }
                     }
                 ).getObfuscatedCode();
             });

+ 28 - 7
test/functional-tests/node-transformers/rename-identifiers-transformers/scope-through-identifiers-transformer/variable-declaration/VariableDeclaration.spec.ts

@@ -22,7 +22,10 @@ describe('ScopeThroughIdentifiersTransformer VariableDeclaration identifiers', (
                     ...NO_ADDITIONAL_NODES_PRESET,
                     renameGlobals: true,
                     identifierNamesCache: {
-                        'foo': 'foo_from_cache'
+                        globalIdentifiers: {
+                            'foo': 'foo_from_cache'
+                        },
+                        propertyIdentifiers: {}
                     }
                 }
             ).getObfuscatedCode();
@@ -53,7 +56,10 @@ describe('ScopeThroughIdentifiersTransformer VariableDeclaration identifiers', (
                             ...NO_ADDITIONAL_NODES_PRESET,
                             renameGlobals: true,
                             identifierNamesCache: {
-                                'foo': 'foo_from_cache'
+                                globalIdentifiers: {
+                                    'foo': 'foo_from_cache'
+                                },
+                                propertyIdentifiers: {}
                             }
                         }
                     ).getObfuscatedCode();
@@ -77,7 +83,10 @@ describe('ScopeThroughIdentifiersTransformer VariableDeclaration identifiers', (
                         {
                             ...NO_ADDITIONAL_NODES_PRESET,
                             renameGlobals: true,
-                            identifierNamesCache: {}
+                            identifierNamesCache: {
+                                globalIdentifiers: {},
+                                propertyIdentifiers: {}
+                            }
                         }
                     ).getObfuscatedCode();
                 });
@@ -101,7 +110,10 @@ describe('ScopeThroughIdentifiersTransformer VariableDeclaration identifiers', (
                             ...NO_ADDITIONAL_NODES_PRESET,
                             renameGlobals: true,
                             identifierNamesCache: {
-                                'foo': 'foo_from_cache'
+                                globalIdentifiers: {
+                                    'foo': 'foo_from_cache'
+                                },
+                                propertyIdentifiers: {}
                             },
                             reservedNames: ['^foo$']
                         }
@@ -129,7 +141,10 @@ describe('ScopeThroughIdentifiersTransformer VariableDeclaration identifiers', (
                             ...NO_ADDITIONAL_NODES_PRESET,
                             renameGlobals: true,
                             identifierNamesCache: {
-                                'foo': 'foo_from_cache'
+                                globalIdentifiers: {
+                                    'foo': 'foo_from_cache'
+                                },
+                                propertyIdentifiers: {}
                             }
                         }
                     ).getObfuscatedCode();
@@ -153,7 +168,10 @@ describe('ScopeThroughIdentifiersTransformer VariableDeclaration identifiers', (
                         {
                             ...NO_ADDITIONAL_NODES_PRESET,
                             renameGlobals: true,
-                            identifierNamesCache: {}
+                            identifierNamesCache: {
+                                globalIdentifiers: {},
+                                propertyIdentifiers: {}
+                            }
                         }
                     ).getObfuscatedCode();
                 });
@@ -177,7 +195,10 @@ describe('ScopeThroughIdentifiersTransformer VariableDeclaration identifiers', (
                             ...NO_ADDITIONAL_NODES_PRESET,
                             renameGlobals: true,
                             identifierNamesCache: {
-                                'foo': 'foo_from_cache'
+                                globalIdentifiers: {
+                                    'foo': 'foo_from_cache'
+                                },
+                                propertyIdentifiers: {}
                             },
                             reservedNames: ['^foo$']
                         }

+ 99 - 12
test/functional-tests/options/identifier-names-cache/Validation.spec.ts

@@ -5,9 +5,9 @@ import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscatorFacade
 import { NO_ADDITIONAL_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
 
 describe('`identifierNamesCache` validation', () => {
-    describe('IsPrimitiveDictionary', () => {
+    describe('IsIdentifierNamesCache', () => {
         describe('Variant #1: positive validation', () => {
-            describe('Variant #1: object with existing identifier names cache', () => {
+            describe('Variant #1: object with existing identifier names cached', () => {
                 let testFunc: () => string;
 
                 beforeEach(() => {
@@ -16,7 +16,12 @@ describe('`identifierNamesCache` validation', () => {
                         {
                             ...NO_ADDITIONAL_NODES_PRESET,
                             identifierNamesCache: {
-                                foo: '_0x123456'
+                                globalIdentifiers: {
+                                    foo: '_0x123456'
+                                },
+                                propertyIdentifiers: {
+                                    bar: '_0x654321'
+                                }
                             }
                         }
                     ).getObfuscatedCode();
@@ -35,7 +40,33 @@ describe('`identifierNamesCache` validation', () => {
                         '',
                         {
                             ...NO_ADDITIONAL_NODES_PRESET,
-                            identifierNamesCache: {}
+                            identifierNamesCache: {
+                                globalIdentifiers: {
+                                    foo: '_0x123456'
+                                },
+                                propertyIdentifiers: {}
+                            }
+                        }
+                    ).getObfuscatedCode();
+                });
+
+                it('should pass validation', () => {
+                    assert.doesNotThrow(testFunc);
+                });
+            });
+
+            describe('Variant #3: object with empty identifier names caches', () => {
+                let testFunc: () => string;
+
+                beforeEach(() => {
+                    testFunc = () => JavaScriptObfuscator.obfuscate(
+                        '',
+                        {
+                            ...NO_ADDITIONAL_NODES_PRESET,
+                            identifierNamesCache: {
+                                globalIdentifiers: {},
+                                propertyIdentifiers: {}
+                            }
                         }
                     ).getObfuscatedCode();
                 });
@@ -45,7 +76,7 @@ describe('`identifierNamesCache` validation', () => {
                 });
             });
 
-            describe('Variant #3: `null` value', () => {
+            describe('Variant #4: `null` value', () => {
                 let testFunc: () => string;
 
                 beforeEach(() => {
@@ -65,7 +96,7 @@ describe('`identifierNamesCache` validation', () => {
         });
 
         describe('Variant #2: negative validation', () => {
-            const expectedError: string = 'Passed value must be a dictionary with `string` values or `null` value';
+            const expectedError: string = 'Passed value must be an identifier names cache object or `null` value';
 
             describe('Variant #1: string value', () => {
                 let testFunc: () => string;
@@ -85,7 +116,58 @@ describe('`identifierNamesCache` validation', () => {
                 });
             });
 
-            describe('Variant #2: object with number values', () => {
+            describe('Variant #2: cache with number values inside single cache', () => {
+                let testFunc: () => string;
+
+                beforeEach(() => {
+                    testFunc = () => JavaScriptObfuscator.obfuscate(
+                        '',
+                        {
+                            ...NO_ADDITIONAL_NODES_PRESET,
+                            identifierNamesCache: {
+                                globalIdentifiers: {
+                                    foo: <any>1,
+                                    bar: <any>2,
+                                },
+                                propertyIdentifiers: {}
+                            }
+                        }
+                    ).getObfuscatedCode();
+                });
+
+                it('should not pass validation', () => {
+                    assert.throws(testFunc, expectedError);
+                });
+            });
+
+            describe('Variant #3: cache with number values inside both caches', () => {
+                let testFunc: () => string;
+
+                beforeEach(() => {
+                    testFunc = () => JavaScriptObfuscator.obfuscate(
+                        '',
+                        {
+                            ...NO_ADDITIONAL_NODES_PRESET,
+                            identifierNamesCache: {
+                                globalIdentifiers: {
+                                    foo: <any>1,
+                                    bar: <any>2,
+                                },
+                                propertyIdentifiers: {
+                                    baz: <any>3,
+                                    bark: <any>4,
+                                }
+                            }
+                        }
+                    ).getObfuscatedCode();
+                });
+
+                it('should not pass validation', () => {
+                    assert.throws(testFunc, expectedError);
+                });
+            });
+
+            describe('Variant #4: cache with mixed values', () => {
                 let testFunc: () => string;
 
                 beforeEach(() => {
@@ -94,8 +176,13 @@ describe('`identifierNamesCache` validation', () => {
                         {
                             ...NO_ADDITIONAL_NODES_PRESET,
                             identifierNamesCache: {
-                                foo: <any>1,
-                                bar: <any>2,
+                                globalIdentifiers: {
+                                    foo: <any>1,
+                                    bar: '_0x1234567',
+                                },
+                                propertyIdentifiers: {
+                                    foo: '_0x123456'
+                                }
                             }
                         }
                     ).getObfuscatedCode();
@@ -106,7 +193,7 @@ describe('`identifierNamesCache` validation', () => {
                 });
             });
 
-            describe('Variant #3: object with mixed values', () => {
+            describe('Variant #4: cache with nullable dictionary fields', () => {
                 let testFunc: () => string;
 
                 beforeEach(() => {
@@ -115,8 +202,8 @@ describe('`identifierNamesCache` validation', () => {
                         {
                             ...NO_ADDITIONAL_NODES_PRESET,
                             identifierNamesCache: {
-                                foo: <any>1,
-                                bar: '_0x1234567',
+                                globalIdentifiers: <any>null,
+                                propertyIdentifiers: <any>null
                             }
                         }
                     ).getObfuscatedCode();

+ 8 - 62
test/unit-tests/storages/identifier-names-cache/IdentifierNamesCacheStorage.spec.ts

@@ -5,7 +5,6 @@ import { assert } from 'chai';
 import { ServiceIdentifiers } from '../../../../src/container/ServiceIdentifiers';
 
 import { TDictionary } from '../../../../src/types/TDictionary';
-import { TIdentifierNamesCache } from '../../../../src/types/storages/TIdentifierNamesCache';
 
 import { IIdentifierNamesCacheStorage } from '../../../../src/interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage';
 import { IInversifyContainerFacade } from '../../../../src/interfaces/container/IInversifyContainerFacade';
@@ -54,7 +53,10 @@ describe('IdentifierNamesCacheStorage', () => {
             before(() => {
                 storage = getStorageInstance({
                     identifierNamesCache: {
-                        [storageKey]: storageValue
+                        globalIdentifiers: {
+                            [storageKey]: storageValue
+                        },
+                        propertyIdentifiers: {}
                     }
                 });
 
@@ -73,7 +75,10 @@ describe('IdentifierNamesCacheStorage', () => {
 
             before(() => {
                 storage = getStorageInstance({
-                    identifierNamesCache: {}
+                    identifierNamesCache: {
+                        globalIdentifiers: {},
+                        propertyIdentifiers: {}
+                    }
                 });
 
                 dictionary = storage.getStorageAsDictionary();
@@ -102,63 +107,4 @@ describe('IdentifierNamesCacheStorage', () => {
             });
         });
     });
-
-    describe('getCache', () => {
-        describe('Variant #1: `identifierNamesCache` option values is object', () => {
-            const expectedIdentifierNamesCache: TIdentifierNamesCache = {
-                [storageKey]: storageValue
-            };
-
-            let identifierNamesCache: TIdentifierNamesCache;
-
-            before(() => {
-                storage = getStorageInstance({
-                    identifierNamesCache: {
-                        [storageKey]: storageValue
-                    }
-                });
-
-                identifierNamesCache = storage.getCache();
-            });
-
-            it('should return cache object', () => {
-                assert.deepEqual(identifierNamesCache, expectedIdentifierNamesCache);
-            });
-        });
-
-        describe('Variant #2: `identifierNamesCache` option values is empty object', () => {
-            const expectedIdentifierNamesCache: TIdentifierNamesCache = {};
-
-            let identifierNamesCache: TIdentifierNamesCache;
-
-            before(() => {
-                storage = getStorageInstance({
-                    identifierNamesCache: {}
-                });
-
-                identifierNamesCache = storage.getCache();
-            });
-
-            it('should return empty cache object', () => {
-                assert.deepEqual(identifierNamesCache, expectedIdentifierNamesCache);
-            });
-        });
-
-        describe('Variant #3: `identifierNamesCache` option values is `null`', () => {
-            let identifierNamesCache: TIdentifierNamesCache;
-
-            before(() => {
-                storage = getStorageInstance({
-                    identifierNamesCache: null
-                });
-                storage.set(storageKey, storageValue);
-
-                identifierNamesCache = storage.getCache();
-            });
-
-            it('should return `null`', () => {
-                assert.isNull(identifierNamesCache);
-            });
-        });
-    });
 });

Деякі файли не було показано, через те що забагато файлів було змінено