Bladeren bron

Slightly simplified validation of identifier names cache. Updated README.md

sanex 4 jaren geleden
bovenliggende
commit
9b3b1644ce
6 gewijzigde bestanden met toevoegingen van 23 en 12 verwijderingen
  1. 2 2
      CHANGELOG.md
  2. 21 6
      README.md
  3. 0 0
      dist/index.browser.js
  4. 0 0
      dist/index.cli.js
  5. 0 0
      dist/index.js
  6. 0 4
      src/options/validators/IsIdentifierNamesCache.ts

+ 2 - 2
CHANGELOG.md

@@ -2,8 +2,8 @@ Change Log
 
 
 v2.14.0
 v2.14.0
 ---
 ---
-* Added `identifierNamesCache` option for reading and writing global obfuscated identifier names cache. See `README.md`.
-* **CLI**:  Added `--identifier-names-cache-path` option for reading and writing global obfuscated identifier names cache. See `README.md`.
+* Added `identifierNamesCache` option for reading and writing identifier names cache. See `README.md`.
+* **CLI**:  Added `--identifier-names-cache-path` option for reading and writing identifier names cache. See `README.md`.
 
 
 v2.13.0
 v2.13.0
 ---
 ---

+ 21 - 6
README.md

@@ -718,14 +718,22 @@ Example:
 ### `identifierNamesCache`
 ### `identifierNamesCache`
 Type: `Object | null` Default: `null`
 Type: `Object | null` Default: `null`
 
 
-The main goal for this option is the ability to use the same global identifier names during obfuscation of multiple sources/files.
+The main goal for this option is the ability to use the same identifier names during obfuscation of multiple sources/files.
+
+Currently the two types of the identifiers are supported:
+- Global identifiers:
+    * All global identifiers will be written to the cache;
+    * All matched **undeclared** global identifiers will be replaced by the values from the cache.
+- Property identifiers, only when `renameProperties` option is enabled:
+    * All property identifiers will be written to the cache;
+    * All matched property identifiers will be replaced by the values from the cache.
 
 
 #### Node.js API
 #### Node.js API
 If a `null` value is passed, completely disables the cache.
 If a `null` value is passed, completely disables the cache.
 
 
-If an empty object (`{}`) is passed, enables the writing dictionary of all global original and obfuscated names to the object. This object will be accessed through the `getIdentifierNamesCache` method call of `ObfuscationResult` object.
+If an empty object (`{}`) is passed, enables the writing identifier names to the cache-object (`TIdentifierNamesCache` type). This cache-object will be accessed through the `getIdentifierNamesCache` method call of `ObfuscationResult` object.
 
 
-The result of `getIdentifierNamesCache` call could be next used as `identifierNamesGenerator` option value for using these names during obfuscation of all matched **undeclared** global identifier names of next sources.
+The resulting cache-object can be next used as `identifierNamesGenerator` option value for using these names during obfuscation of all matched identifier names of next sources.
 
 
 Example:
 Example:
 ```
 ```
@@ -747,7 +755,12 @@ const source1ObfuscationResult = JavaScriptObfuscator.obfuscate(
 )
 )
 
 
 console.log(source1ObfuscationResult.getIdentifierNamesCache());
 console.log(source1ObfuscationResult.getIdentifierNamesCache());
-// { foo: '_0x5de86d', bar: '_0x2a943b' }
+/*{ 
+    globalIdentifiers: {
+        foo: '_0x5de86d',
+        bar: '_0x2a943b'
+    }
+}*/
 
 
 
 
 
 
@@ -774,11 +787,11 @@ console.log(source2ObfuscationResult.getObfuscatedCode());
 ```
 ```
 
 
 #### CLI
 #### CLI
-CLI has a different option `--identifier-names-cache-path` that allows defining a path to the existing `.json` file that will be used to read and write global identifier names cache.
+CLI has a different option `--identifier-names-cache-path` that allows defining a path to the existing `.json` file that will be used to read and write identifier names cache.
 
 
 If a path to the empty file will be passed - identifier names cache will be written to that file.
 If a path to the empty file will be passed - identifier names cache will be written to that file.
 
 
-This file with existing cache can be used again as `--identifier-names-cache-path` option value for using these names during obfuscation of all matched **undeclared** global identifier names of the next files.
+This file with existing cache can be used again as `--identifier-names-cache-path` option value for using these names during obfuscation of all matched identifier names of the next files.
 
 
 ### `identifierNamesGenerator`
 ### `identifierNamesGenerator`
 Type: `string` Default: `hexadecimal`
 Type: `string` Default: `hexadecimal`
@@ -902,6 +915,8 @@ Specifies `renameProperties` option mode:
 * `safe` - default behaviour after `2.11.0` release. Trying to rename properties in a more safe way to prevent runtime errors. With this mode some properties will be excluded from renaming.
 * `safe` - default behaviour after `2.11.0` release. Trying to rename properties in a more safe way to prevent runtime errors. With this mode some properties will be excluded from renaming.
 * `unsafe` - default behaviour before `2.11.0` release. Renames properties in an unsafe way without any restrictions.
 * `unsafe` - default behaviour before `2.11.0` release. Renames properties in an unsafe way without any restrictions.
 
 
+If one file is using properties from other file, use [`identifierNamesCache`](#identifiernamescache) option to keep the same property names between these files.
+
 ### `reservedNames`
 ### `reservedNames`
 Type: `string[]` Default: `[]`
 Type: `string[]` Default: `[]`
 
 

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


+ 0 - 4
src/options/validators/IsIdentifierNamesCache.ts

@@ -68,10 +68,6 @@ export function IsIdentifierNamesCache (
                         return false;
                         return false;
                     }
                     }
 
 
-                    if (value === null) {
-                        return false;
-                    }
-
                     if (!validateDictionary((<TIdentifierNamesCache>value)?.globalIdentifiers)) {
                     if (!validateDictionary((<TIdentifierNamesCache>value)?.globalIdentifiers)) {
                         return false;
                         return false;
                     }
                     }

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